Overview

Packages

  • alpha::controller
  • alpha::controller::front
  • alpha::exceptions
  • alpha::model
  • alpha::model::types
  • alpha::tasks
  • alpha::tests
  • alpha::util
  • alpha::util::cache
  • alpha::util::codehighlight
  • alpha::util::convertors
  • alpha::util::feeds
  • alpha::util::filters
  • alpha::util::graphs
  • alpha::util::helpers
  • alpha::util::metrics
  • alpha::view
  • alpha::view::renderers
  • alpha::view::widgets

Classes

  • AlphaController
  • CacheManager
  • Create
  • CreateArticle
  • Detail
  • Edit
  • EditArticle
  • EditDEnum
  • EditTags
  • GenSecureQueryStrings
  • Install
  • ListAll
  • ListBusinessObjects
  • ListDEnums
  • ListSequences
  • Login
  • Logout
  • PreviewArticle
  • Search
  • TagManager
  • ViewArticle
  • ViewArticleFile
  • ViewArticlePDF
  • ViewArticlePrint
  • ViewArticleTitle
  • ViewAttachment
  • ViewExcel
  • ViewFeed
  • ViewImage
  • ViewLog
  • ViewMetrics
  • ViewRecordSelector
  • ViewTestResults

Interfaces

  • AlphaControllerInterface
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: // include the config file
  4: if(!isset($config)) {
  5:     require_once '../util/AlphaConfig.inc';
  6:     $config = AlphaConfig::getInstance();
  7: 
  8:     require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
  9: }
 10: 
 11: /**
 12:  *
 13:  * Controller used to edit an existing article
 14:  *
 15:  * @package alpha::controller
 16:  * @since 1.0
 17:  * @author John Collins <dev@alphaframework.org>
 18:  * @version $Id: EditArticle.php 1647 2013-02-19 16:11:21Z alphadevx $
 19:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 20:  * @copyright Copyright (c) 2013, John Collins (founder of Alpha Framework).
 21:  * All rights reserved.
 22:  *
 23:  * <pre>
 24:  * Redistribution and use in source and binary forms, with or
 25:  * without modification, are permitted provided that the
 26:  * following conditions are met:
 27:  *
 28:  * * Redistributions of source code must retain the above
 29:  *   copyright notice, this list of conditions and the
 30:  *   following disclaimer.
 31:  * * Redistributions in binary form must reproduce the above
 32:  *   copyright notice, this list of conditions and the
 33:  *   following disclaimer in the documentation and/or other
 34:  *   materials provided with the distribution.
 35:  * * Neither the name of the Alpha Framework nor the names
 36:  *   of its contributors may be used to endorse or promote
 37:  *   products derived from this software without specific
 38:  *   prior written permission.
 39:  *
 40:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 41:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 42:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 43:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 44:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 45:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 46:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 47:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 48:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 49:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 50:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 51:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 52:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 53:  * </pre>
 54:  *
 55:  */
 56: class EditArticle extends AlphaController implements AlphaControllerInterface {
 57:     /**
 58:      * The new article to be edited
 59:      *
 60:      * @var ArticleObject
 61:      * @since 1.0
 62:      */
 63:     protected $BO;
 64: 
 65:     /**
 66:      * Trace logger
 67:      *
 68:      * @var Logger
 69:      * @since 1.0
 70:      */
 71:     private static $logger = null;
 72: 
 73:     /**
 74:      * constructor to set up the object
 75:      *
 76:      * @since 1.0
 77:      */
 78:     public function __construct() {
 79:         self::$logger = new Logger('EditArticle');
 80:         self::$logger->debug('>>__construct()');
 81: 
 82:         global $config;
 83: 
 84:         // ensure that the super class constructor is called, indicating the rights group
 85:         parent::__construct('Standard');
 86: 
 87:         $this->BO = new ArticleObject();
 88: 
 89:         self::$logger->debug('<<__construct');
 90:     }
 91: 
 92:     /**
 93:      * Handle GET requests
 94:      *
 95:      * @param array $params
 96:      * @since 1.0
 97:      */
 98:     public function doGET($params) {
 99:         self::$logger->debug('>>doGET(params=['.var_export($params, true).'])');
100: 
101:         try{
102:             // load the business object (BO) definition
103:             if (isset($params['oid'])) {
104:                 if(!AlphaValidator::isInteger($params['oid']))
105:                     throw new IllegalArguementException('Article ID provided ['.$params['oid'].'] is not valid!');
106: 
107:                 $this->BO->load($params['oid']);
108: 
109:                 AlphaDAO::disconnect();
110: 
111:                 $BOView = AlphaView::getInstance($this->BO);
112: 
113:                 // set up the title and meta details
114:                 $this->setTitle($this->BO->get('title').' (editing)');
115:                 $this->setDescription('Page to edit '.$this->BO->get('title').'.');
116:                 $this->setKeywords('edit,article');
117: 
118:                 echo AlphaView::displayPageHead($this);
119: 
120:                 echo $BOView->editView();
121:             }else{
122:                 throw new IllegalArguementException('No valid article ID provided!');
123:             }
124:         }catch(IllegalArguementException $e) {
125:             self::$logger->error($e->getMessage());
126:         }catch(BONotFoundException $e) {
127:             self::$logger->warn($e->getMessage());
128:             echo '<div class="ui-state-error ui-corner-all" style="padding: 0pt 0.7em;">
129:                 <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 0.3em;"></span>
130:                 <strong>Error:</strong> Failed to load the requested article from the database!</p></div>';
131:         }
132: 
133:         echo AlphaView::renderDeleteForm();
134: 
135:         echo AlphaView::displayPageFoot($this);
136: 
137:         self::$logger->debug('<<doGET');
138:     }
139: 
140:     /**
141:      * Method to handle POST requests
142:      *
143:      * @param array $params
144:      * @since 1.0
145:      */
146:     public function doPOST($params) {
147:         self::$logger->debug('>>doPOST(params=['.var_export($params, true).'])');
148: 
149:         global $config;
150: 
151:         try {
152:             // check the hidden security fields before accepting the form POST data
153:             if(!$this->checkSecurityFields()) {
154:                 throw new SecurityException('This page cannot accept post data from remote servers!');
155:                 self::$logger->debug('<<doPOST');
156:             }
157: 
158:             if(isset($params['markdownTextBoxRows']) && $params['markdownTextBoxRows'] != '') {
159:                 $viewState = ViewState::getInstance();
160:                 $viewState->set('markdownTextBoxRows', $params['markdownTextBoxRows']);
161:             }
162: 
163:             if (isset($params['oid'])) {
164:                 if(!AlphaValidator::isInteger($params['oid']))
165:                     throw new IllegalArguementException('Article ID provided ['.$params['oid'].'] is not valid!');
166: 
167:                 $this->BO->load($params['oid']);
168: 
169:                 $BOView = AlphaView::getInstance($this->BO);
170: 
171:                 // set up the title and meta details
172:                 $this->setTitle($this->BO->get('title').' (editing)');
173:                 $this->setDescription('Page to edit '.$this->BO->get('title').'.');
174:                 $this->setKeywords('edit,article');
175: 
176:                 echo AlphaView::displayPageHead($this);
177: 
178:                 if (isset($params['saveBut'])) {
179: 
180:                     // populate the transient object from post data
181:                     $this->BO->populateFromPost();
182: 
183:                     try {
184:                         $success = $this->BO->save();
185:                         self::$logger->action('Article '.$this->BO->getID().' saved');
186:                         echo AlphaView::displayUpdateMessage('Article '.$this->BO->getID().' saved successfully.');
187:                     }catch (LockingException $e) {
188:                         $this->BO->reload();
189:                         echo AlphaView::displayErrorMessage($e->getMessage());
190:                     }
191: 
192:                     AlphaDAO::disconnect();
193:                     echo $BOView->editView();
194:                 }
195: 
196:                 if (!empty($params['deleteOID'])) {
197: 
198:                     $this->BO->load($params['deleteOID']);
199: 
200:                     try {
201:                         $this->BO->delete();
202:                         self::$logger->action('Article '.$params['deleteOID'].' deleted.');
203:                         AlphaDAO::disconnect();
204: 
205:                         echo AlphaView::displayUpdateMessage('Article '.$params['deleteOID'].' deleted successfully.');
206: 
207:                         echo '<center>';
208: 
209:                         $temp = new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'",
210:                             'Back to List','cancelBut');
211:                         echo $temp->render();
212: 
213:                         echo '</center>';
214:                     }catch(AlphaException $e) {
215:                         self::$logger->error($e->getTraceAsString());
216:                         echo AlphaView::displayErrorMessage('Error deleting the article, check the log!');
217:                     }
218:                 }
219: 
220:                 if(isset($params['uploadBut'])) {
221: 
222:                     // upload the file to the attachments directory
223:                     $success = move_uploaded_file($_FILES['userfile']['tmp_name'], $this->BO->getAttachmentsLocation().'/'.$_FILES['userfile']['name']);
224: 
225:                     if(!$success)
226:                         throw new AlphaException('Could not move the uploaded file ['.$_FILES['userfile']['name'].']');
227: 
228:                     // set read/write permissions on the file
229:                     $success = chmod($this->BO->getAttachmentsLocation().'/'.$_FILES['userfile']['name'], 0666);
230: 
231:                     if (!$success)
232:                         throw new AlphaException('Unable to set read/write permissions on the uploaded file ['.$this->BO->getAttachmentsLocation().'/'.$_FILES['userfile']['name'].'].');
233: 
234:                     if($success) {
235:                         echo AlphaView::displayUpdateMessage('File uploaded successfully.');
236:                         self::$logger->action('File '.$_FILES['userfile']['name'].' uploaded to '.$this->BO->getAttachmentsLocation().'/'.$_FILES['userfile']['name']);
237:                     }
238: 
239:                     $view = AlphaView::getInstance($this->BO);
240: 
241:                     echo $view->editView();
242:                 }
243: 
244:                 if (!empty($params['file_to_delete'])) {
245: 
246:                     $success = unlink($this->BO->getAttachmentsLocation().'/'.$params['file_to_delete']);
247: 
248:                     if(!$success)
249:                         throw new AlphaException('Could not delete the file ['.$params['file_to_delete'].']');
250: 
251:                     if($success) {
252:                         echo AlphaView::displayUpdateMessage($params['file_to_delete'].' deleted successfully.');
253:                         self::$logger->action('File '.$this->BO->getAttachmentsLocation().'/'.$params['file_to_delete'].' deleted');
254:                     }
255: 
256:                     $view = AlphaView::getInstance($this->BO);
257: 
258:                     echo $view->editView();
259:                 }
260:             }else{
261:                 throw new IllegalArguementException('No valid article ID provided!');
262:             }
263:         }catch(SecurityException $e) {
264:             echo AlphaView::displayErrorMessage($e->getMessage());
265:             self::$logger->warn($e->getMessage());
266:         }catch(IllegalArguementException $e) {
267:             echo AlphaView::displayErrorMessage($e->getMessage());
268:             self::$logger->error($e->getMessage());
269:         }catch(BONotFoundException $e) {
270:             self::$logger->warn($e->getMessage());
271:             echo AlphaView::displayErrorMessage('Failed to load the requested article from the database!');
272:         }catch(AlphaException $e) {
273:             echo AlphaView::displayErrorMessage($e->getMessage());
274:             self::$logger->error($e->getMessage());
275:         }
276: 
277:         echo AlphaView::renderDeleteForm();
278: 
279:         echo AlphaView::displayPageFoot($this);
280: 
281:         self::$logger->debug('<<doPOST');
282:     }
283: 
284:     /**
285:      * Renders the Javascript required in the header by markItUp!
286:      *
287:      * @return string
288:      * @since 1.0
289:      */
290:     public function during_displayPageHead_callback() {
291:         global $config;
292: 
293:         $html = '
294:             <script type="text/javascript">
295:             var previewURL = "'.FrontController::generateSecureURL('act=PreviewArticle&bo=ArticleObject&oid='.$this->BO->getOID()).'";
296:             </script>
297:             <script type="text/javascript" src="'.$config->get('app.url').'alpha/lib/markitup/jquery.markitup.js"></script>
298:             <script type="text/javascript" src="'.$config->get('app.url').'alpha/lib/markitup/sets/markdown/set.js"></script>
299:             <link rel="stylesheet" type="text/css" href="'.$config->get('app.url').'alpha/lib/markitup/skins/simple/style.css" />
300:             <link rel="stylesheet" type="text/css" href="'.$config->get('app.url').'alpha/lib/markitup/sets/markdown/style.css" />
301:             <script type="text/javascript">
302:             $(document).ready(function() {
303:                 $(\'[id="'.($config->get('security.encrypt.http.fieldnames') ? 'text_field_'.base64_encode(AlphaSecurityUtils::encrypt('content')).'_0' : 'text_field_content_0').'"]\').markItUp(mySettings);
304: 
305:                 var dialogCoords = [(screen.width/2)-400, (screen.height/2)-300];
306: 
307:                 var dialogOpts = {
308:                     title: "Help Page",
309:                     modal: true,
310:                     resizable: false,
311:                     draggable: false,
312:                     autoOpen: false,
313:                     height: 400,
314:                     width: 800,
315:                     position: dialogCoords,
316:                     buttons: {},
317:                     open: function() {
318:                         //display correct dialog content
319:                         $("#helpPage").load("'.FrontController::generateSecureURL('act=ViewArticleFile&file=Markdown_Help.text').'");
320:                     },
321:                     close: function() {
322: 
323:                         $("#helpPage").dialog(dialogOpts);
324: 
325:                         $(".markItUpButton15").click(
326:                             function (){
327:                                 $("#helpPage").dialog("open");
328:                                 return false;
329:                             }
330:                         );
331:                     }
332:                 };
333: 
334:                 $("#helpPage").dialog(dialogOpts);
335: 
336:                 $(".markItUpButton15").click(
337:                     function (){
338:                         $("#helpPage").dialog("open");
339:                         return false;
340:                     }
341:                 );
342:             });
343:             </script>';
344: 
345:         return $html;
346:     }
347: 
348:     /**
349:      * Use this callback to inject in the admin menu template fragment for admin users of
350:      * the backend only.
351:      *
352:      * @since 1.2
353:      */
354:     public function after_displayPageHead_callback() {
355:         $menu = '';
356: 
357:         if (isset($_SESSION['currentUser']) && AlphaDAO::isInstalled() && $_SESSION['currentUser']->inGroup('Admin') && strpos($_SERVER['REQUEST_URI'], '/tk/') !== false) {
358:             $menu .= AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
359:         }
360: 
361:         return $menu;
362:     }
363: }
364: 
365: // now build the new controller
366: if(basename($_SERVER['PHP_SELF']) == 'EditArticle.php') {
367:     $controller = new EditArticle();
368: 
369:     if(!empty($_POST)) {
370:         $controller->doPOST($_REQUEST);
371:     }else{
372:         $controller->doGET($_GET);
373:     }
374: }
375: 
376: ?>
Alpha Framework ${alpha.version.new} API Documentation API documentation generated by ApiGen 2.8.0