/** * Handle POST requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @since 1.0 */ public function doPOST($request) { self::$logger->debug('>>doPOST($request=[' . var_export($request, true) . '])'); $config = ConfigProvider::getInstance(); $params = $request->getParams(); $body = View::displayPageHead($this); $body .= '<p class="alert alert-success">'; if (isset($params['QS'])) { $body .= FrontController::generateSecureURL($params['QS']); self::$logger->action('Generated the secure URL in admin: ' . FrontController::generateSecureURL($params['QS'])); } $body .= '</p>'; $body .= $this->renderForm(); $body .= View::displayPageFoot($this); self::$logger->debug('<<doPOST'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * Custom edit view. * * @param array $fields Hash array of HTML fields to pass to the template. * * @since 1.0 * * @return string */ public function editView($fields = array()) { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $html = '<table cols="2" class="edit_view" style="width:100%; margin:0px">'; $html .= '<form action="' . $fields['formAction'] . '" method="POST" accept-charset="UTF-8">'; $textBox = new TextBox($this->BO->getPropObject('content'), $this->BO->getDataLabel('content'), 'content', '', 5, $this->BO->getID()); $html .= $textBox->render(); $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $this->BO->getVersion() . '"/>'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $this->BO->getID() . '"/>'; // render special buttons for admins only if ($session->get('currentUser')->inGroup('Admin') && strpos($fields['formAction'], '/tk/') !== false) { $html .= '<tr><td colspan="2">'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('saveBut')) : 'saveBut'; $temp = new Button('submit', 'Save', $fieldname); $html .= $temp->render(); $html .= ' '; $js = "\$('#dialogDiv').text('Are you sure you wish to delete this item?');\n \$('#dialogDiv').dialog({\n buttons: {\n 'OK': function(event, ui) {\n \$('[id=\"" . ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID') . "\"]').attr('value', '" . $this->BO->getOID() . "');\n \$('#deleteForm').submit();\n },\n 'Cancel': function(event, ui) {\n \$(this).dialog('close');\n }\n }\n })\n \$('#dialogDiv').dialog('open');\n return false;"; $temp = new Button($js, 'Delete', 'deleteBut'); $html .= $temp->render(); $html .= ' '; $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . get_class($this->BO)) . "'", 'Back to List', 'cancelBut'); $html .= $temp->render(); $html .= '</td></tr>'; $html .= View::renderSecurityFields(); $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD'; $html .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '" value="PUT"/>'; $html .= '</form></table>'; } else { $html .= '</table>'; $html .= '<div align="center">'; $temp = new Button('submit', 'Update Your Comment', 'saveBut' . $this->BO->getID()); $html .= $temp->render(); $html .= '</div>'; $html .= View::renderSecurityFields(); $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD'; $html .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '" value="PUT"/>'; $html .= '</form>'; } return $html; }
/** * Method to render the reset password HTML form. * * @return string * * @since 1.0 */ public function displayResetForm() { $config = ConfigProvider::getInstance(); $html = '<div class="bordered padded">'; $html .= '<h1>Password reset</h1>'; $html .= '<p>If you have forgotten your password, you can use this form to have a new password automatically generated and sent to your e-mail address.</p>'; $html .= '<form action="' . FrontController::generateSecureURL('act=Alpha\\Controller\\LoginController&reset=true') . '" method="POST" id="resetForm" accept-charset="UTF-8">'; $request = new Request(array('method' => 'GET')); $email = new String($request->getParam('email', '')); $email->setRule(Validator::REQUIRED_EMAIL); $email->setSize(70); $email->setHelper('Please provide a valid e-mail address!'); $stringBox = new StringBox($email, $this->BO->getDataLabel('email'), 'email', 'resetForm', '50'); $html .= $stringBox->render(); $html .= '<div class="form-group lower spread">'; $temp = new Button('submit', 'Reset Password', 'resetBut'); $html .= $temp->render(); $temp = new Button("document.location.replace('" . $config->get('app.url') . "')", 'Cancel', 'cancelBut'); $html .= $temp->render(); $html .= '</div>'; $html .= $this->renderSecurityFields(); $html .= '</form>'; $html .= '</div>'; return $html; }
/** * Method for rendering the pagination links. * * @return string * * @since 1.0 */ protected function renderPageLinks() { $config = ConfigProvider::getInstance(); $params = $this->request->getParams(); $body = ''; $end = $this->startPoint + $config->get('app.list.page.amount'); if ($end > $this->resultCount) { $end = $this->resultCount; } if ($this->resultCount > 0) { $body .= '<p align="center">Displaying ' . ($this->startPoint + 1) . ' to ' . $end . ' of <strong>' . $this->resultCount . '</strong>. '; } else { if (!empty($this->query)) { $body .= View::displayUpdateMessage('There were no search results for your query.'); } } $body .= '<ul class="pagination">'; if ($this->startPoint > 0) { // handle secure URLs if (isset($params['tk'])) { $body .= '<li><a href="' . FrontController::generateSecureURL('act=Search&q=' . $this->query . '&start=' . ($this->startPoint - $config->get('app.list.page.amount'))) . '">«</a></li>'; } else { $body .= '<li><a href="' . $config->get('app.url') . '/search/' . $this->query . '/' . ($this->startPoint - $config->get('app.list.page.amount')) . '">«</a></li>'; } } elseif ($this->resultCount > $config->get('app.list.page.amount')) { $body .= '<li class="disabled"><a href="#">«</a></li>'; } $page = 1; for ($i = 0; $i < $this->resultCount; $i += $config->get('app.list.page.amount')) { if ($i != $this->startPoint) { // handle secure URLs if (isset($params['tk'])) { $body .= '<li><a href="' . FrontController::generateSecureURL('act=Search&q=' . $this->query . '&start=' . $i) . '">' . $page . '</a></li>'; } else { $body .= '<li><a href="' . $config->get('app.url') . '/search/' . $this->query . '/' . $i . '">' . $page . '</a></li>'; } } elseif ($this->resultCount > $config->get('app.list.page.amount')) { $body .= '<li class="active"><a href="#">' . $page . '</a></li>'; } ++$page; } if ($this->resultCount > $end) { // handle secure URLs if (isset($params['tk'])) { $body .= '<li><a href="' . FrontController::generateSecureURL('act=Search&q=' . $this->query . '&start=' . ($this->startPoint + $config->get('app.list.page.amount'))) . '">Next->></a></li>'; } else { $body .= '<li><a href="' . $config->get('app.url') . '/search/' . $this->query . '/' . ($this->startPoint + $config->get('app.list.page.amount')) . '">»</a></li>'; } } elseif ($this->resultCount > $config->get('app.list.page.amount')) { $body .= '<li class="disabled"><a href="#">»</a></li>'; } $body .= '</ul>'; $body .= '</p>'; return $body; }
/** * {@inheritdoc} */ public function adminView($fields = array()) { self::$logger->debug('>>adminView(fields=[' . var_export($fields, true) . '])'); $config = ConfigProvider::getInstance(); // the class name of the BO $fields['fullClassName'] = stripslashes(get_class($this->BO)); // the table name in the DB for the BO $fields['tableName'] = $this->BO->getTableName(); // record count for the BO in the DB $fields['count'] = $this->BO->checkTableExists() ? $this->BO->getCount() : '<span class="warning">unavailable</span>'; // table exists in the DB? $fields['tableExists'] = $this->BO->checkTableExists() ? '<span class="success">Yes</span>' : '<span class="warning">No</span>'; if ($this->BO->getMaintainHistory()) { $fields['tableExists'] = $this->BO->checkTableExists(true) ? '<span class="success">Yes</span>' : '<span class="warning">No history table</span>'; } // table schema needs to be updated in the DB? $fields['tableNeedsUpdate'] = $this->BO->checkTableNeedsUpdate() ? '<span class="warning">Yes</span>' : '<span class="success">No</span>'; // create button if ($this->BO->checkTableExists()) { if (isset($fields['createButtonURL'])) { $button = new Button("document.location = '" . $fields['createButtonURL'] . "'", 'Create New', 'create' . stripslashes(get_class($this->BO)) . 'But'); } else { $button = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . get_class($this->BO)) . "'", 'Create New', 'create' . stripslashes(get_class($this->BO)) . 'But'); } $fields['createButton'] = $button->render(); } else { $fields['createButton'] = ''; } // list all button if ($this->BO->checkTableExists()) { $button = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . get_class($this->BO) . '&start=0&limit=' . $config->get('app.list.page.amount')) . "'", 'List All', 'list' . stripslashes(get_class($this->BO)) . 'But'); $fields['listButton'] = $button->render(); } else { $fields['listButton'] = ''; } // the create table button (if required) $html = ''; if (!$this->BO->checkTableExists()) { $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('createTableBut')) : 'createTableBut'; $button = new Button('submit', 'Create Table', $fieldname); $html .= $button->render(); // hidden field so that we know which class to create the table for $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('createTableClass')) : 'createTableClass'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . get_class($this->BO) . '"/>'; } if ($html == '' && $this->BO->getMaintainHistory() && !$this->BO->checkTableExists(true)) { $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('createHistoryTableBut')) : 'createHistoryTableBut'; $button = new Button('submit', 'Create History Table', $fieldname); $html .= $button->render(); // hidden field so that we know which class to create the table for $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('createTableClass')) : 'createTableClass'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . get_class($this->BO) . '"/>'; } $fields['createTableButton'] = $html; // recreate and update table buttons (if required) $html = ''; if ($this->BO->checkTableNeedsUpdate() && $this->BO->checkTableExists()) { $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Confirmation',\n message: 'Are you sure you wish to recreate this class table (all data will be lost)?',\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n },\n {\n icon: 'glyphicon glyphicon-ok',\n label: 'Okay',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself) {\n \$('[Id=\"" . ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('admin_' . stripslashes(get_class($this->BO)) . '_button_pressed')) : 'admin_' . stripslashes(get_class($this->BO)) . '_button_pressed') . "\"]').attr('value', 'recreateTableBut');\n \$('#admin_" . stripslashes(get_class($this->BO)) . "').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Recreate Table', 'recreateTableBut'); $html .= $button->render(); // hidden field so that we know which class to recreate the table for $html .= '<input type="hidden" name="recreateTableClass" value="' . get_class($this->BO) . '"/>'; $html .= ' '; $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Confirmation',\n message: 'Are you sure you wish to attempt to modify this class table by adding new attributes?',\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n },\n {\n icon: 'glyphicon glyphicon-ok',\n label: 'Okay',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself) {\n \$('[Id=\"" . ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('admin_' . stripslashes(get_class($this->BO)) . '_button_pressed')) : 'admin_' . stripslashes(get_class($this->BO)) . '_button_pressed') . "\"]').attr('value', 'updateTableBut');\n \$('#admin_" . stripslashes(get_class($this->BO)) . "').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Update Table', 'updateTableBut'); $html .= $button->render(); // hidden field so that we know which class to update the table for $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('updateTableClass')) : 'updateTableClass'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . get_class($this->BO) . '"/>'; // hidden field to tell us which button was pressed $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('admin_' . stripslashes(get_class($this->BO)) . '_button_pressed')) : 'admin_' . stripslashes(get_class($this->BO)) . '_button_pressed'; $html .= '<input type="hidden" id="' . $fieldname . '" name="' . $fieldname . '" value=""/>'; } $fields['recreateOrUpdateButtons'] = $html; // buffer security fields to $formSecurityFields variable $fields['formSecurityFields'] = self::renderSecurityFields(); self::$logger->debug('<<adminView [HTML]'); return View::loadTemplate($this->BO, 'admin', $fields); }
/** * Method for displaying the user comments for the article. * * @return string * * @since 1.0 */ private function renderComments() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $html = ''; $comments = $this->record->getArticleComments(); $commentsCount = count($comments); $URL = FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\\Model\\ArticleComment'); $fields = array('formAction' => $URL); if ($config->get('cms.display.comments') && $commentsCount > 0) { $html .= '<h2>There are [' . $commentsCount . '] user comments for this article</h2>'; for ($i = 0; $i < $commentsCount; ++$i) { $view = View::getInstance($comments[$i]); $html .= $view->markdownView($fields); } } if ($session->get('currentUser') != null && $config->get('cms.comments.allowed')) { $comment = new ArticleComment(); $comment->set('articleOID', $this->record->getID()); $view = View::getInstance($comment); $html .= $view->createView($fields); } return $html; }
/** * Testing the generateSecureURL method. * * @since 1.2.1 */ public function testGenerateSecureURL() { $config = ConfigProvider::getInstance(); $oldKey = $config->get('security.encryption.key'); $oldRewriteSetting = $config->get('app.use.mod.rewrite'); $config->set('security.encryption.key', 'testkey12345678901234567'); $params = 'act=ViewArticleTitle&title=Test_Title'; $config->set('app.use.mod.rewrite', true); $this->assertEquals($config->get('app.url') . '/tk/7eYCDOP1AFAv2Kc45D2eSgFM1dJ2mboM4fMMMjs3PP6cb8Qafsv0L06zZjWeIWRH', FrontController::generateSecureURL($params), 'Testing the generateSecureURL() returns the correct URL with mod_rewrite style URLs enabled'); $config->set('app.use.mod.rewrite', false); $this->assertEquals($config->get('app.url') . '?tk=7eYCDOP1AFAv2Kc45D2eSgFM1dJ2mboM4fMMMjs3PP6cb8Qafsv0L06zZjWeIWRH', FrontController::generateSecureURL($params), 'Testing the generateSecureURL() returns the correct URL with mod_rewrite style URLs disabled'); $config->set('security.encryption.key', $oldKey); $config->set('app.use.mod.rewrite', $oldRewriteSetting); }
/** * Custom list view. * * @param array $fields Hash array of HTML fields to pass to the template. * * @since 1.0 */ public function listView($fields = array()) { self::$logger->debug('>>listView(fields=[' . var_export($fields, true) . '])'); if (method_exists($this, 'before_listView_callback')) { $this->before_listView_callback(); } $config = ConfigProvider::getInstance(); // the form action $fields['formAction'] = $fields['URI']; // work out how many columns will be in the table $reflection = new \ReflectionClass(get_class($this->BO)); $properties = array_keys($reflection->getDefaultProperties()); $fields['colCount'] = 1 + count(array_diff($properties, $this->BO->getDefaultAttributes(), $this->BO->getTransientAttributes())); // get the class attributes $properties = $reflection->getProperties(); $html = ''; $html .= '<tr>'; foreach ($properties as $propObj) { $propName = $propObj->name; // skip over password fields $property = $this->BO->getPropObject($propName); if (!($property instanceof String && $property->checkIsPassword())) { if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) { $html .= ' <th>' . $this->BO->getDataLabel($propName) . '</th>'; } if ($propName == 'OID') { $html .= ' <th>' . $this->BO->getDataLabel($propName) . '</th>'; } } else { $fields['colCount'] = $fields['colCount'] - 1; } } $html .= '</tr><tr>'; $fields['formHeadings'] = $html; $html = ''; // and now the values foreach ($properties as $propObj) { $propName = $propObj->name; $property = $this->BO->getPropObject($propName); if (!($property instanceof String && $property->checkIsPassword())) { if (!in_array($propName, $this->BO->getDefaultAttributes()) && !in_array($propName, $this->BO->getTransientAttributes())) { $propClass = get_class($this->BO->getPropObject($propName)); if ($propClass == 'Alpha\\Model\\Type\\Text') { $text = htmlentities($this->BO->get($propName), ENT_COMPAT, 'utf-8'); if (mb_strlen($text) > 70) { $html .= ' <td> ' . mb_substr($text, 0, 70) . '...</td>'; } else { $html .= ' <td> ' . $text . '</td>'; } } elseif ($propClass == 'Alpha\\Model\\Type\\DEnum') { $html .= ' <td> ' . $this->BO->getPropObject($propName)->getDisplayValue() . '</td>'; } else { $html .= ' <td> ' . $this->BO->get($propName) . '</td>'; } } if ($propName == 'OID') { $html .= ' <td> ' . $this->BO->getOID() . '</td>'; } } } $html .= '</tr>'; $fields['formFields'] = $html; $button = new Button("document.location = '" . FrontController::generateSecureURL('act=Detail&bo=' . get_class($this->BO) . '&oid=' . $this->BO->getOID()) . "';", 'View', 'viewBut'); $fields['viewButton'] = $button->render(); // supressing the edit/delete buttons for Sequences $fields['adminButtons'] = ''; // buffer security fields to $formSecurityFields variable $fields['formSecurityFields'] = $this->renderSecurityFields(); $html = $this->loadTemplate($this->BO, 'list', $fields); if (method_exists($this, 'after_listView_callback')) { $this->after_listView_callback(); } self::$logger->debug('<<listView'); return $html; }
/** * Method for rendering the pagination links. * * @return string * * @since 2.0 */ protected function renderPageLinks() { $config = ConfigProvider::getInstance(); $body = ''; // the index of the last record displayed on this page $last = $this->start + $config->get('app.list.page.amount'); // ensure that the last index never overruns the total record count if ($last > $this->recordCount) { $last = $this->recordCount; } // render a message for an empty list if ($this->recordCount > 0) { $body .= '<ul class="pagination">'; } else { $body .= '<p align="center">The list is empty. </p>'; return $body; } // render "Previous" link if ($this->start > 0) { // handle secure URLs if ($this->request->getParam('token', null) != null) { $body .= '<li><a href="' . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . $this->request->getParam('ActiveRecordType') . '&start=' . ($this->start - $this->limit) . '&limit=' . $this->limit) . '"><<-Previous</a></li>'; } else { $body .= '<li><a href="/records/' . urlencode($this->request->getParam('ActiveRecordType')) . '/' . ($this->start - $this->limit) . '/' . $this->limit . '"><<-Previous</a></li>'; } } elseif ($this->recordCount > $this->limit) { $body .= '<li class="disabled"><a href="#"><<-Previous</a></li>'; } // render the page index links if ($this->recordCount > $this->limit) { $page = 1; for ($i = 0; $i < $this->recordCount; $i += $this->limit) { if ($i != $this->start) { // handle secure URLs if ($this->request->getParam('token', null) != null) { $body .= '<li><a href="' . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . $this->request->getParam('ActiveRecordType') . '&start=' . $i . '&limit=' . $this->limit) . '">' . $page . '</a></li>'; } else { $body .= '<li><a href="/records/' . urlencode($this->request->getParam('ActiveRecordType')) . '/' . $i . '/' . $this->limit . '">' . $page . '</a></li>'; } } elseif ($this->recordCount > $this->limit) { // render an anchor for the current page $body .= '<li class="active"><a href="#">' . $page . '</a></li>'; } ++$page; } } // render "Next" link if ($this->recordCount > $last) { // handle secure URLs if ($this->request->getParam('token', null) != null) { $body .= '<li><a href="' . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . $this->request->getParam('ActiveRecordType') . '&start=' . ($this->start + $this->limit) . '&limit=' . $this->limit) . '">Next->></a></li>'; } else { $body .= '<li><a href="/records/' . urlencode($this->request->getParam('ActiveRecordType')) . '/' . ($this->start + $this->limit . '/' . $this->limit) . '">Next->></a></li>'; } } elseif ($this->recordCount > $this->limit) { $body .= '<li class="disabled"><a href="#">Next->></a></li>'; } $body .= '</ul>'; return $body; }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @since 2.0.3 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); if ($request->getParam('displayphpinfo') != null) { ob_start(); phpinfo(); $body = ob_get_contents(); } else { $body = View::displayPageHead($this); $url = FrontController::generateSecureURL('act=Alpha\\Controller\\PhpinfoController&displayphpinfo=true'); $body .= '<iframe src="' . $url . '" style="border:none; overflow-x: scroll; overflow-y: scroll; width:100%; height:100vh;"></iframe>'; $body .= View::displayPageFoot($this); } self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html', 'X-Frame-Options' => 'SAMEORIGIN')); }
/** * Renders the HTML <img> tag to the ViewImage controller, with all of the correct params to render the source * image in the desired resolution. * * @param $altText Set this value to render alternate text as part of the HTML link (defaults to no alternate text) * * @return string * * @since 1.0 */ public function renderHTMLLink($altText = '') { $config = ConfigProvider::getInstance(); if ($this->secure->getBooleanValue()) { $params = Controller::generateSecurityFields(); return '<img src="' . FrontController::generateSecureURL('act=Alpha\\Controller\\ImageController&source=' . $this->source . '&width=' . $this->width->getValue() . '&height=' . $this->height->getValue() . '&type=' . $this->sourceType->getValue() . '&quality=' . $this->quality->getValue() . '&scale=' . $this->scale->getValue() . '&secure=' . $this->secure->getValue() . '&var1=' . $params[0] . '&var2=' . $params[1]) . '"' . (empty($altText) ? '' : ' alt="' . $altText . '"') . ($config->get('cms.images.widget.bootstrap.responsive') ? ' class="img-responsive"' : '') . '/>'; } else { return '<img src="' . FrontController::generateSecureURL('act=Alpha\\Controller\\ImageController&source=' . $this->source . '&width=' . $this->width->getValue() . '&height=' . $this->height->getValue() . '&type=' . $this->sourceType->getValue() . '&quality=' . $this->quality->getValue() . '&scale=' . $this->scale->getValue() . '&secure=' . $this->secure->getValue()) . '"' . (empty($altText) ? '' : ' alt="' . $altText . '"') . ($config->get('cms.images.widget.bootstrap.responsive') ? ' class="img-responsive"' : '') . '/>'; } }
/** * Login the user and re-direct to the defined destination. * * @param string $password The password supplied by the user logging in * * @throws Alpha\Exception\ValidationException * * @return Alpha\Util\Http\Response * * @since 1.0 */ protected function doLoginAndRedirect($password) { self::$logger->debug('>>doLoginAndRedirect(password=[' . $password . '])'); $config = ConfigProvider::getInstance(); if (!$this->personObject->isTransient() && $this->personObject->get('state') == 'Active') { if (password_verify($password, $this->personObject->get('password'))) { $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $session->set('currentUser', $this->personObject); self::$logger->debug('Logging in [' . $this->personObject->get('email') . '] at [' . date('Y-m-d H:i:s') . ']'); self::$logger->action('Login'); $response = new Response(301); if ($this->getNextJob() != '') { $response->redirect(FrontController::generateSecureURL('act=' . $this->getNextJob())); $this->clearUnitOfWorkAttributes(); } else { $response->redirect($config->get('app.url')); } return $response; } else { throw new ValidationException('Failed to login user ' . $this->personObject->get('email') . ', the password is incorrect!'); self::$logger->debug('<<doLoginAndRedirect'); } } }
/** * Renders the text boxes and buttons for the widget, that will appear in user forms. * * @param bool $expanded Render the related fields in expanded format or not (optional) * @param bool $buttons Render buttons for expanding/contacting the related fields (optional) * * @return string * * @since 1.0 */ public function render($expanded = false, $buttons = true) { self::$logger->debug('>>render(expanded=[' . $expanded . '], buttons=[' . $buttons . '])'); $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt($this->name)) : $this->name; $html = ''; // render text-box for many-to-one relations if ($this->relationObject->getRelationType() == 'MANY-TO-ONE') { // value to appear in the text-box $inputBoxValue = $this->relationObject->getRelatedClassDisplayFieldValue(); $html .= '<div class="form-group">'; $html .= '<label for="' . $this->name . '_display">' . $this->label . '</label>'; $html .= '<input type="text" size="70" class="form-control" name="' . $this->name . '_display" id="' . $this->name . '_display" value="' . $inputBoxValue . '" disabled/>'; $js = " if(window.jQuery) {\n window.jQuery.dialog = new BootstrapDialog({\n title: 'Please select',\n message: 'Loading...',\n onshow: function(dialogRef){\n dialogRef.getModalBody().load('" . $config->get('app.url') . "/recordselector/12m/'+document.getElementById('" . $fieldname . "').value+'/" . $this->name . '/' . urlencode($this->relationObject->getRelatedClass()) . '/' . $this->relationObject->getRelatedClassField() . '/' . $this->relationObject->getRelatedClassDisplayField() . "');\n },\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n }\n ]\n });\n window.jQuery.dialog.open();\n }"; $tmp = new Button($js, 'Select', 'relBut', '', 'glyphicon-check'); $html .= '<div class="centered lower">' . $tmp->render() . '</div>'; // hidden field to store the actual value of the relation $html .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '" value="' . $this->relationObject->getValue() . '"/>'; if ($this->relationObject->getRule() != '') { $html .= '<input type="hidden" id="' . $fieldname . '_msg" value="' . $this->relationObject->getHelper() . '"/>'; $html .= '<input type="hidden" id="' . $fieldname . '_rule" value="' . $this->relationObject->getRule() . '"/>'; } $html .= '</div>'; } // render read-only list for one-to-many relations if ($this->relationObject->getRelationType() == 'ONE-TO-MANY') { $objects = $this->relationObject->getRelatedObjects(); if (count($objects) > 0) { // render tags differently if ($this->name == 'tags' && $this->relationObject->getRelatedClass() == 'TagObject') { $html .= '<p><strong>' . $this->label . ':</strong>'; foreach ($objects as $tag) { $html .= ' <a href="' . $config->get('app.url') . '/search/' . $tag->get('content') . '">' . $tag->get('content') . '</a>'; } $html .= '</p>'; } else { $html .= '<div><strong>' . $this->label . ':</strong>'; if ($buttons) { $html .= '<div class="spread">'; $tmp = new Button("document.getElementById('relation_field_" . $this->name . "').style.display = '';", 'Show', $this->name . 'DisBut', '', 'glyphicon-list'); $html .= $tmp->render(); $tmp = new Button("document.getElementById('relation_field_" . $this->name . "').style.display = 'none';", 'Hide', $this->name . 'HidBut', '', 'glyphicon-minus'); $html .= $tmp->render(); $html .= '</div>'; } $html .= '</div>'; $html .= '<div id="relation_field_' . $this->name . '" style="display:' . ($expanded ? '' : 'none') . ';">'; $customViewControllerName = Controller::getCustomControllerName(get_class($objects[0]), 'view'); $customEditControllerName = Controller::getCustomControllerName(get_class($objects[0]), 'edit'); $request = new Request(array('method' => 'GET')); $URI = $request->getURI(); foreach ($objects as $obj) { // check to see if we are in the admin back-end if (mb_strpos($URI, '/tk/') !== false) { $viewURL = FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . get_class($obj) . '&ActiveRecordOID=' . $obj->getOID()); $editURL = FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . get_class($obj) . '&ActiveRecordOID=' . $obj->getOID() . '&view=edit'); } else { if (isset($customViewControllerName)) { if ($config->get('app.use.mod.rewrite')) { $viewURL = $config->get('app.url') . $customViewControllerName . '/oid/' . $obj->getOID(); } else { $viewURL = $config->get('app.url') . 'controller/' . $customViewControllerName . '.php?oid=' . $obj->getOID(); } } else { $viewURL = $config->get('app.url') . 'alpha/controller/Detail.php?bo=' . get_class($obj) . '&oid=' . $obj->getOID(); } if (isset($customEditControllerName)) { if ($config->get('app.use.mod.rewrite')) { $editURL = $config->get('app.url') . $customEditControllerName . '/oid/' . $obj->getOID(); } else { $editURL = $config->get('app.url') . 'controller/' . $customEditControllerName . '.php?oid=' . $obj->getOID(); } } else { $editURL = $config->get('app.url') . 'alpha/controller/Edit.php?bo=' . get_class($obj) . '&oid=' . $obj->getOID(); } } /* * If any display headers were set with setRelatedClassHeaderFields, use them otherwise * use the OID of the related class as the only header. */ $headerFields = $this->relationObject->getRelatedClassHeaderFields(); if (count($headerFields) > 0) { foreach ($headerFields as $field) { $label = $obj->getDataLabel($field); $value = $obj->get($field); if ($field == 'created_by' || $field == 'updated_by') { $person = new PersonObject(); $person->load($value); $value = $person->getDisplayName(); } $html .= '<em>' . $label . ': </em>' . $value . ' '; } // if the related BO has been updated, render the update time if ($obj->getCreateTS() != $obj->getUpdateTS()) { try { $html .= '<em>' . $obj->getDataLabel('updated_ts') . ': </em>' . $obj->get('updated_ts'); } catch (IllegalArguementException $e) { $html .= '<em>Updated: </em>' . $obj->get('updated_ts'); } } } else { $html .= '<em>' . $obj->getDataLabel('OID') . ': </em>' . $obj->get('OID'); } // ensures that line returns are rendered $value = str_replace("\n", '<br>', $obj->get($this->relationObject->getRelatedClassDisplayField())); $html .= '<p>' . $value . '</p>'; $html .= '<div class="centered">'; $html .= '<a href="' . $viewURL . '">View</a>'; // if the current user owns it, they get the edit link if ($session->get('currentUser') != null && $session->get('currentUser')->getOID() == $obj->getCreatorId()) { $html .= ' <a href="' . $editURL . '">Edit</a>'; } $html .= '</div>'; } $html .= '</div>'; } } } // render text-box for many-to-many relations if ($this->relationObject->getRelationType() == 'MANY-TO-MANY') { // value to appear in the text-box $inputBoxValue = $this->relationObject->getRelatedClassDisplayFieldValue($this->accessingClassName); // replace commas with line returns $inputBoxValue = str_replace(',', "\n", $inputBoxValue); $html .= '<div class="form-group">'; $html .= '<label for="' . $this->name . '_display">' . $this->label . '</label>'; $html .= '<textarea id="' . $this->name . '_display" class="form-control" rows="5" readonly>'; $html .= $inputBoxValue; $html .= '</textarea>'; $fieldname1 = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt($this->name)) : $this->name; $fieldname2 = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt($this->name . '_OID')) : $this->name . '_OID'; $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Please select',\n message: 'Loading...',\n onshow: function(dialogRef){\n dialogRef.getModalBody().load('" . $config->get('app.url') . "/recordselector/m2m/'+document.getElementById('" . $fieldname2 . "').value+'/" . $this->name . '/' . urlencode($this->relationObject->getRelatedClass('left')) . '/' . $this->relationObject->getRelatedClassDisplayField('left') . '/' . urlencode($this->relationObject->getRelatedClass('right')) . '/' . $this->relationObject->getRelatedClassDisplayField('right') . '/' . urlencode($this->accessingClassName) . "/'+document.getElementById('" . $fieldname1 . "').value);\n },\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n },\n {\n icon: 'glyphicon glyphicon-ok',\n label: 'Okay',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself) {\n setParentFieldValues();\n \$('[id=\\'" . $this->name . "_display\\']').blur();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $tmp = new Button($js, 'Select', 'relBut', '', 'glyphicon-check'); $html .= '<div class="centered lower">' . $tmp->render() . '</div>'; $html .= '</div>'; // hidden field to store the OID of the current BO $html .= '<input type="hidden" name="' . $fieldname2 . '" id="' . $fieldname2 . '" value="' . $this->relationObject->getValue() . '"/>'; // hidden field to store the OIDs of the related BOs on the other side of the rel (this is what we check for when saving) if ($this->relationObject->getSide($this->accessingClassName) == 'left') { $lookupOIDs = $this->relationObject->getLookup()->loadAllFieldValuesByAttribute('leftID', $this->relationObject->getValue(), 'rightID', 'DESC'); } else { $lookupOIDs = $this->relationObject->getLookup()->loadAllFieldValuesByAttribute('rightID', $this->relationObject->getValue(), 'leftID', 'DESC'); } $html .= '<input type="hidden" name="' . $fieldname1 . '" id="' . $fieldname1 . '" value="' . implode(',', $lookupOIDs) . '"/>'; } self::$logger->debug('<<__render [html]'); return $html; }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @throws Alpha\Exception\IllegalArguementException * @throws Alpha\Exception\FileNotFoundException * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $params = $request->getParams(); $config = ConfigProvider::getInstance(); $body = ''; // render the tag manager screen if (!isset($params['ActiveRecordType']) && !isset($params['ActiveRecordOID'])) { $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $body .= '<h3>Listing active record which are tagged</h3>'; $ActiveRecordTypes = ActiveRecord::getBOClassNames(); foreach ($ActiveRecordTypes as $ActiveRecordType) { $record = new $ActiveRecordType(); if ($record->isTagged()) { $tag = new Tag(); $count = count($tag->loadAllByAttribute('taggedClass', $ActiveRecordType)); $body .= '<h4>' . $record->getFriendlyClassName() . ' record type is tagged (' . $count . ' tags found)</h4>'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('clearTaggedClass')) : 'clearTaggedClass'; $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Confirmation',\n message: 'Are you sure you want to delete all tags attached to the " . $record->getFriendlyClassName() . " class, and have them re-created?',\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n },\n {\n icon: 'glyphicon glyphicon-ok',\n label: 'Okay',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself) {\n \$('[id=\"" . $fieldname . "\"]').attr('value', '" . addslashes($ActiveRecordType) . "');\n \$('#clearForm').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Re-create tags', 'clearBut' . stripslashes($ActiveRecordType)); $body .= $button->render(); } } ActiveRecord::disconnect(); $body .= '<form action="' . $request->getURI() . '" method="POST" id="clearForm">'; $body .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '"/>'; $body .= View::renderSecurityFields(); $body .= '</form>'; } elseif (isset($params['ActiveRecordType']) && $params['ActiveRecordType'] != 'Alpha\\Model\\Tag' && isset($params['ActiveRecordOID'])) { // render screen for managing individual tags on a given active record $body .= View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $ActiveRecordType = urldecode($params['ActiveRecordType']); $ActiveRecordOID = $params['ActiveRecordOID']; if (class_exists($ActiveRecordType)) { $record = new $ActiveRecordType(); } else { throw new IllegalArguementException('No ActiveRecord available to display tags for!'); } try { $record->load($ActiveRecordOID); $tags = $record->getPropObject('tags')->getRelatedObjects(); ActiveRecord::disconnect(); $body .= '<form action="' . $request->getURI() . '" method="POST" accept-charset="UTF-8">'; $body .= '<h3>The following tags were found:</h3>'; foreach ($tags as $tag) { $labels = $tag->getDataLabels(); $temp = new StringBox($tag->getPropObject('content'), $labels['content'], 'content_' . $tag->getID(), ''); $body .= $temp->render(false); $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Confirmation',\n message: 'Are you sure you wish to delete this tag?',\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n },\n {\n icon: 'glyphicon glyphicon-ok',\n label: 'Okay',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself) {\n \$('[id=\"" . ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID') . "\"]').attr('value', '" . $tag->getID() . "');\n \$('#deleteForm').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Delete', 'delete' . $tag->getID() . 'But'); $body .= $button->render(); } $body .= '<h3>Add a new tag:</h3>'; $temp = new StringBox(new String(), 'New tag', 'NewTagValue', ''); $body .= $temp->render(false); $temp = new Button('submit', 'Save', 'saveBut'); $body .= $temp->render(); $body .= ' '; if ($params['ActiveRecordType'] = 'Alpha\\Model\\Article') { $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ArticleController&ActiveRecordType=' . $params['ActiveRecordType'] . '&ActiveRecordOID=' . $params['ActiveRecordOID'] . '&view=edit') . "'", 'Back to record', 'cancelBut'); } else { $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . $params['ActiveRecordType'] . '&ActiveRecordOID=' . $params['ActiveRecordOID'] . '&view=edit') . "'", 'Back to record', 'cancelBut'); } $body .= $temp->render(); $body .= View::renderSecurityFields(); $body .= '</form>'; $body .= View::renderDeleteForm($request->getURI()); } catch (RecordNotFoundException $e) { $msg = 'Unable to load the ActiveRecord of id [' . $params['ActiveRecordOID'] . '], error was [' . $e->getMessage() . ']'; self::$logger->error($msg); throw new FileNotFoundException($msg); } } else { return parent::doGET($request); } $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * Generates a secure URL for downloading an attachment file via the ViewAttachment controller. * * @param string $filename * * @since 1.0 */ public function getAttachmentSecureURL($filename) { $config = ConfigProvider::getInstance(); return FrontController::generateSecureURL('act=Alpha\\Controller\\AttachmentController&articleOID=' . $this->getOID() . '&filename=' . $filename); }
/** * Handle GET requests. * * @param Alpha\Util\Http\Request $request * * @return Alpha\Util\Http\Response * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); // if there is nobody logged in, we will send them off to the Login controller to do so before coming back here if ($session->get('currentUser') === false) { self::$logger->info('Nobody logged in, invoking Login controller...'); $controller = new LoginController(); $controller->setName('LoginController'); $controller->setRequest($request); $controller->setUnitOfWork(array('Alpha\\Controller\\LoginController', 'Alpha\\Controller\\InstallController')); self::$logger->debug('<<__construct'); return $controller->doGET($request); } $params = $request->getParams(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $body = View::displayPageHead($this); $body .= '<h1>Installing the ' . $config->get('app.title') . ' application</h1>'; try { $body .= $this->createApplicationDirs(); } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); return new Response(500, $body, array('Content-Type' => 'text/html')); } // start a new database transaction ActiveRecord::begin(); /* * Create DEnum tables */ $DEnum = new DEnum(); $DEnumItem = new DEnumItem(); try { $body .= '<p>Attempting to create the DEnum tables...'; if (!$DEnum->checkTableExists()) { $DEnum->makeTable(); } self::$logger->info('Created the [' . $DEnum->getTableName() . '] table successfully'); if (!$DEnumItem->checkTableExists()) { $DEnumItem->makeTable(); } self::$logger->info('Created the [' . $DEnumItem->getTableName() . '] table successfully'); // create a default article DEnum category $DEnum = new DEnum('Alpha\\Model\\Article::section'); $DEnumItem = new DEnumItem(); $DEnumItem->set('value', 'Main'); $DEnumItem->set('DEnumID', $DEnum->getID()); $DEnumItem->save(); $body .= View::displayUpdateMessage('DEnums set up successfully.'); } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); self::$logger->error($e->getMessage()); ActiveRecord::rollback(); return new Response(500, $body, array('Content-Type' => 'text/html')); } /* * Loop over each business object in the system, and create a table for it */ $classNames = ActiveRecord::getBOClassNames(); $loadedClasses = array(); foreach ($classNames as $classname) { array_push($loadedClasses, $classname); } foreach ($loadedClasses as $classname) { try { $body .= '<p>Attempting to create the table for the class [' . $classname . ']...'; try { $BO = new $classname(); if (!$BO->checkTableExists()) { $BO->makeTable(); } else { if ($BO->checkTableNeedsUpdate()) { $missingFields = $BO->findMissingFields(); $count = count($missingFields); for ($i = 0; $i < $count; ++$i) { $BO->addProperty($missingFields[$i]); } } } } catch (FailedIndexCreateException $eice) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($eice->getMessage()); } catch (FailedLookupCreateException $elce) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($elce->getMessage()); } self::$logger->info('Created the [' . $BO->getTableName() . '] table successfully'); $body .= View::displayUpdateMessage('Created the [' . $BO->getTableName() . '] table successfully'); } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); self::$logger->error($e->getMessage()); ActiveRecord::rollback(); return new Response(500, $body, array('Content-Type' => 'text/html')); } } $body .= View::displayUpdateMessage('All business object tables created successfully!'); /* * Create the Admin and Standard groups */ $adminGroup = new Rights(); $adminGroup->set('name', 'Admin'); $standardGroup = new Rights(); $standardGroup->set('name', 'Standard'); try { try { $body .= '<p>Attempting to create the Admin and Standard groups...'; $adminGroup->save(); $standardGroup->save(); self::$logger->info('Created the Admin and Standard rights groups successfully'); $body .= View::displayUpdateMessage('Created the Admin and Standard rights groups successfully'); } catch (FailedIndexCreateException $eice) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($eice->getMessage()); } catch (FailedLookupCreateException $elce) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($elce->getMessage()); } } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); self::$logger->error($e->getMessage()); ActiveRecord::rollback(); return new Response(500, $body, array('Content-Type' => 'text/html')); } /* * Save the admin user to the database in the right group */ try { try { $body .= '<p>Attempting to save the Admin account...'; $admin = new Person(); $admin->set('displayName', 'Admin'); $admin->set('email', $session->get('currentUser')->get('email')); $admin->set('password', $session->get('currentUser')->get('password')); $admin->save(); self::$logger->info('Created the admin user account [' . $session->get('currentUser')->get('email') . '] successfully'); $adminGroup->loadByAttribute('name', 'Admin'); $lookup = $adminGroup->getMembers()->getLookup(); $lookup->setValue(array($admin->getID(), $adminGroup->getID())); $lookup->save(); self::$logger->info('Added the admin account to the Admin group successfully'); $body .= View::displayUpdateMessage('Added the admin account to the Admin group successfully'); } catch (FailedIndexCreateException $eice) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($eice->getMessage()); } catch (FailedLookupCreateException $elce) { // this are safe to ignore for now as they will be auto-created later once all of the tables are in place self::$logger->warn($elce->getMessage()); } } catch (\Exception $e) { $body .= View::displayErrorMessage($e->getMessage()); $body .= View::displayErrorMessage('Aborting.'); self::$logger->error($e->getMessage()); ActiveRecord::rollback(); return new Response(500, $body, array('Content-Type' => 'text/html')); } $body .= '<br><p align="center"><a href="' . FrontController::generateSecureURL('act=Alpha\\Controller\\ListActiveRecordsController') . '">Administration Home Page</a></p><br>'; $body .= View::displayPageFoot($this); // commit ActiveRecord::commit(); self::$logger->info('Finished installation!'); self::$logger->action('Installed the application'); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * Renders a form to enable article editing with attachments options. * * @param array $fields hash array of HTML fields to pass to the template * * @since 1.0 * * @return string */ public function editView($fields = array()) { if (method_exists($this, 'before_editView_callback')) { $this->before_editView_callback(); } $config = ConfigProvider::getInstance(); // the form action if (isset($fields['URI'])) { $fields['formAction'] = $fields['URI']; } // the form ID $fields['formID'] = stripslashes(get_class($this->BO)) . '_' . $this->BO->getID(); // buffer form fields to $formFields $fields['formFields'] = $this->renderAllFields('edit'); // buffer HTML output for Create and Cancel buttons $button = new Button('submit', 'Save', 'saveBut'); $fields['saveButton'] = $button->render(); $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Confirmation',\n message: 'Are you sure you wish to delete this item?',\n buttons: [\n {\n icon: 'glyphicon glyphicon-remove',\n label: 'Cancel',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself){\n dialogItself.close();\n }\n },\n {\n icon: 'glyphicon glyphicon-ok',\n label: 'Okay',\n cssClass: 'btn btn-default btn-xs',\n action: function(dialogItself) {\n \$('[id=\"" . ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID') . "\"]').attr('value', '" . $this->BO->getOID() . "');\n \$('#deleteForm').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Delete', 'deleteBut'); $fields['deleteButton'] = $button->render(); $button = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=' . get_class($this->BO) . '&start=0&limit=' . $config->get('app.list.page.amount')) . "'", 'Back to List', 'cancelBut'); $fields['cancelButton'] = $button->render(); $tags = array(); if (is_object($this->BO->getPropObject('tags'))) { $tags = $this->BO->getPropObject('tags')->getRelatedObjects(); } if (count($tags) > 0) { $button = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\TagController&ActiveRecordType=' . get_class($this->BO) . '&ActiveRecordOID=' . $this->BO->getOID()) . "'", 'Edit Tags', 'tagsBut'); $fields['tagsButton'] = $button->render(); } // buffer security fields to $formSecurityFields variable $fields['formSecurityFields'] = $this->renderSecurityFields(); // OID will need to be posted for optimistic lock checking $fields['version_num'] = $this->BO->getVersionNumber(); // file attachments section $fields['fileAttachments'] = $this->renderFileUploadSection(); if (method_exists($this, 'after_editView_callback')) { $this->after_editView_callback(); } return $this->loadTemplate($this->BO, 'edit', $fields); }
/** * Custom edit view. * * @return string * * @since 1.0 */ public function editView($fields = array()) { $config = ConfigProvider::getInstance(); $labels = $this->BO->getDataLabels(); $obj_type = ''; $html = '<form action="' . $fields['URI'] . '" method="POST" accept-charset="UTF-8">'; $temp = new StringBox($this->BO->getPropObject('name'), $labels['name'], 'name', '', 0, true, true); $html .= $temp->render(); $html .= '<h3>DEnum display values:</h3>'; // now get all of the options for the enum and render $denum = $this->BO; $tmp = new DEnumItem(); $denumItems = $tmp->loadItems($denum->getID()); foreach ($denumItems as $item) { $labels = $item->getDataLabels(); $temp = new StringBox($item->getPropObject('value'), $labels['value'], 'value_' . $item->getID(), ''); $html .= $temp->render(); } $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $this->BO->getVersion() . '"/>'; $html .= '<h3>Add a new value to the DEnum dropdown list:</h3>'; $temp = new StringBox(new String(), 'Dropdown value', 'new_value', ''); $html .= $temp->render(); $temp = new Button('submit', 'Save', 'saveBut'); $html .= $temp->render(); $html .= ' '; $temp = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\DEnumController') . "'", 'Back to List', 'cancelBut'); $html .= $temp->render(); $html .= ''; $html .= View::renderSecurityFields(); $html .= '</form>'; return $html; }