Example #1
0
 /**
  * Testing the get/set methods.
  *
  * @since 2.0
  */
 public function testSetGet()
 {
     $viewState1 = ViewState::getInstance();
     $viewState1->set('selectedTab', 'test');
     $this->assertEquals('test', $viewState1->get('selectedTab'), 'Testing the get/set methods');
     $viewState2 = ViewState::getInstance();
     $this->assertEquals('test', $viewState2->get('selectedTab'), 'Testing the get/set methods');
 }
 /**
  * the constructor.
  *
  * @since 1.0
  */
 public function __construct()
 {
     self::$logger = new Logger('ListActiveRecordsController');
     self::$logger->debug('>>__construct()');
     $config = ConfigProvider::getInstance();
     // ensure that the super class constructor is called, indicating the rights group
     parent::__construct('Admin');
     // set up the title and meta details
     $this->setTitle('Listing all active records in the system');
     $this->setDescription('Page to list all active records.');
     $this->setKeywords('list,all,active,records');
     $viewState = ViewState::getInstance();
     $viewState->set('renderAdminMenu', true);
     self::$logger->debug('<<__construct');
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function renderTextField($name, $label, $mode, $value = '')
 {
     self::$logger->debug('>>renderTextField(name=[' . $name . '], label=[' . $label . '], mode=[' . $mode . '], value=[' . $value . '])');
     $config = ConfigProvider::getInstance();
     $html = '';
     if ($mode == 'create') {
         // give 10 rows for content fields (other 5 by default)
         if ($name == 'content') {
             $text = new TextBox($this->BO->getPropObject($name), $label, $name, 10);
         } else {
             $text = new TextBox($this->BO->getPropObject($name), $label, $name);
         }
         $html .= $text->render();
     }
     if ($mode == 'edit') {
         // give 10 rows for content fields (other 5 by default)
         if ($name == 'content') {
             $viewState = ViewState::getInstance();
             if ($viewState->get('markdownTextBoxRows') == '') {
                 $text = new TextBox($this->BO->getPropObject($name), $label, $name, 10);
             } else {
                 $text = new TextBox($this->BO->getPropObject($name), $label, $name, (int) $viewState->get('markdownTextBoxRows'));
             }
             $html .= $text->render();
         } else {
             $text = new TextBox($this->BO->getPropObject($name), $label, $name);
             $html .= $text->render();
         }
     }
     if ($mode == 'view') {
         $html .= '<p><strong>';
         $html .= $label;
         $html .= ':</strong>';
         // filter ouput to prevent malicious injection
         $value = InputFilter::encode($value);
         // ensures that line returns are rendered
         $value = str_replace("\n", '<br>', $value);
         $html .= '&nbsp;';
         $html .= $value;
         $html .= '</p>';
     }
     self::$logger->debug('<<renderTextField [' . $html . ']');
     return $html;
 }
 /**
  * Sets up the pagination start point and limit.
  *
  * @since 2.0
  */
 public function after_displayPageHead_callback()
 {
     $body = parent::after_displayPageHead_callback();
     // set the start point for the list pagination
     if ($this->request->getParam('start') != null) {
         $this->start = $this->request->getParam('start');
         $viewState = ViewState::getInstance();
         $viewState->set('selectedStart', $this->start);
         if ($this->request->getParam('limit') != null) {
             $this->limit = $this->request->getParam('limit');
         } else {
             $config = ConfigProvider::getInstance();
             $this->limit = $config->get('app.list.page.amount');
         }
         $accept = $this->request->getAccept();
         if ($accept == 'application/json') {
             $body .= '[';
         }
     }
     return $body;
 }
Example #5
0
 /**
  * Use this callback to inject in the admin menu template fragment.
  *
  * @return string
  *
  * @since 1.2
  */
 public function after_displayPageHead_callback()
 {
     $accept = $this->request->getAccept();
     if ($accept != 'application/json' && $this->checkIfAccessingFromSecureURL()) {
         $viewState = ViewState::getInstance();
         if ($viewState->get('renderAdminMenu') === true) {
             $config = ConfigProvider::getInstance();
             $sessionProvider = $config->get('session.provider.name');
             $session = SessionProviderFactory::getInstance($sessionProvider);
             if ($session->get('currentUser') !== false) {
                 $passwordResetRequired = SecurityUtils::checkAdminPasswordIsDefault($session->get('currentUser')->get('password'));
                 $menu = View::loadTemplateFragment('html', 'adminmenu.phtml', array('passwordResetRequired' => $passwordResetRequired));
             } else {
                 $menu = '';
             }
             return $menu;
         }
     } else {
         return '';
     }
 }
Example #6
0
 /**
  * Method to handle PUT requests.
  *
  * @param Alpha\Util\Http\Request
  *
  * @return Alpha\Util\Http\Response
  *
  * @since 1.0
  */
 public function doPUT($request)
 {
     self::$logger->debug('>>doPUT($request=[' . var_export($request, true) . '])');
     $config = ConfigProvider::getInstance();
     $params = $request->getParams();
     try {
         // check the hidden security fields before accepting the form POST data
         if (!$this->checkSecurityFields()) {
             throw new SecurityException('This page cannot accept post data from remote servers!');
             self::$logger->debug('<<doPUT');
         }
         if (isset($params['markdownTextBoxRows']) && $params['markdownTextBoxRows'] != '') {
             $viewState = ViewState::getInstance();
             $viewState->set('markdownTextBoxRows', $params['markdownTextBoxRows']);
         }
         if (isset($params['title']) || isset($params['ActiveRecordOID'])) {
             if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) {
                 $record = new $params['ActiveRecordType']();
             } else {
                 $record = new Article();
             }
             if (isset($params['title'])) {
                 $title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']);
                 $record->loadByAttribute('title', $title, false, array('OID', 'version_num', 'created_ts', 'updated_ts', 'title', 'author', 'published', 'content', 'headerContent'));
             } else {
                 $record->load($params['ActiveRecordOID']);
             }
             // uploading an article attachment
             if (isset($params['uploadBut'])) {
                 $source = $request->getFile('userfile')['tmp_name'];
                 $dest = $record->getAttachmentsLocation() . '/' . $request->getFile('userfile')['name'];
                 // upload the file to the attachments directory
                 FileUtils::copy($source, $dest);
                 if (!file_exists($dest)) {
                     throw new AlphaException('Could not move the uploaded file [' . $request->getFile('userfile')['name'] . ']');
                 }
                 // set read/write permissions on the file
                 $success = chmod($dest, 0666);
                 if (!$success) {
                     throw new AlphaException('Unable to set read/write permissions on the uploaded file [' . $dest . '].');
                 }
                 if ($success) {
                     self::$logger->action('File ' . $source . ' uploaded to ' . $dest);
                     $this->setStatusMessage(View::displayUpdateMessage('File ' . $source . ' uploaded to ' . $dest));
                 }
             } elseif (isset($params['deletefile']) && $params['deletefile'] != '') {
                 $success = unlink($record->getAttachmentsLocation() . '/' . $params['deletefile']);
                 if (!$success) {
                     throw new AlphaException('Could not delete the file [' . $params['deletefile'] . ']');
                 }
                 if ($success) {
                     self::$logger->action('File ' . $record->getAttachmentsLocation() . '/' . $params['deletefile'] . ' deleted');
                     $this->setStatusMessage(View::displayUpdateMessage('File ' . $record->getAttachmentsLocation() . '/' . $params['deletefile'] . ' deleted'));
                 }
             } else {
                 self::$logger->debug('<<doPUT');
                 return parent::doPUT($request);
             }
         } else {
             throw new IllegalArguementException('No valid article ID provided!');
         }
     } catch (SecurityException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->warn($e->getMessage());
     } catch (IllegalArguementException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->error($e->getMessage());
     } catch (RecordNotFoundException $e) {
         self::$logger->warn($e->getMessage());
         $this->setStatusMessage(View::displayErrorMessage('Failed to load the requested article from the database!'));
     } catch (AlphaException $e) {
         $this->setStatusMessage(View::displayErrorMessage($e->getMessage()));
         self::$logger->error($e->getMessage());
     }
     $response = new Response(301);
     if ($this->getNextJob() != '') {
         $response->redirect($this->getNextJob());
     } else {
         if ($this->request->isSecureURI()) {
             $response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\\Model\\Article&ActiveRecordOID=' . $record->getOID() . '&view=edit'));
         } else {
             $title = str_replace(' ', $config->get('cms.url.title.separator'), $record->get('title'));
             $response->redirect($config->get('app.url') . '/a/' . $title . '/edit');
         }
     }
     self::$logger->debug('<<doPUT');
     return $response;
 }