/** * The constructor. * * @param string $action The javascript action to be carried out (or set to "submit" to make a submit button, "file" for file uploads). * @param string $title The title to appear on the button. * @param string $id The HTML id attribute for the button. * @param string $imgURL If provided, the button will be a clickable image using this image. * @param string $glyphIcon If provided, the Bootsrap glyphIcon to use for this button. * * @since 1.0 */ public function __construct($action, $title, $id, $imgURL = '', $glyphIcon = '') { $config = ConfigProvider::getInstance(); $this->action = $action; $this->title = $title; $this->id = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt($id)) : $id; $this->imgURL = $imgURL; $this->glyphIcon = $glyphIcon; $this->title = $title; }
/** * Renders the HTML form for generating secure URLs. * * @return string * * @since 1.0 */ private function renderForm() { $config = ConfigProvider::getInstance(); $html = '<p>Use this form to generate secure (encrypted) URLs which make use of the Front Controller. Always be sure to specify an action controller' . ' (act) at a minimum.</p>'; $html .= '<p>Example 1: to generate a secure URL for viewing article object 00000000001, enter <em>act=Alpha\\Controller\\ArticleController&ActiveRecordOID=00000000001</em></p>'; $html .= '<p>Example 2: to generate a secure URL for viewing an Atom news feed of the articles, enter' . ' <em>act=Alpha\\Controller\\FeedController&ActiveRecordType=Alpha\\Model\\Article&type=Atom</em></p>'; $html .= '<form action="' . $this->request->getURI() . '" method="post" accept-charset="UTF-8"><div class="form-group">'; $string = new StringBox(new String(''), 'Parameters', 'QS'); $html .= $string->render(); $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('saveBut')) : 'saveBut'; $temp = new Button('submit', 'Generate', $fieldname); $html .= $temp->render(); $html .= '</div></form>'; return $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 user registration form. * * @return string * * @since 1.0 */ public function displayRegisterForm() { $config = ConfigProvider::getInstance(); $request = new Request(array('method' => 'GET')); $html = '<p>In order to access this site, you will need to create a user account. In order to do so, please provide a valid email address below and a password will be sent to your inbox shortly (you can change your password once you log in).</p>'; $html .= '<table cols="2">'; $html .= '<form action="' . $request->getURI() . '?reset=true" method="POST" accept-charset="UTF-8">'; $html .= '<tr>'; if ($config->get('security.encrypt.http.fieldnames')) { $fieldname = base64_encode(SecurityUtils::encrypt('displayname')); } else { $fieldname = 'displayname'; } $html .= ' <td>Forum name</td> <td><input type="text" name="' . $fieldname . '" size="50" value="' . $request->getParam($fieldname, '') . '"/></td>'; $html .= '</tr>'; $html .= '<tr>'; if ($config->get('security.encrypt.http.fieldnames')) { $fieldname = base64_encode(SecurityUtils::encrypt('email')); } else { $fieldname = 'email'; } $html .= ' <td>E-mail Address</td> <td><input type="text" name="' . $fieldname . '" size="50" value="' . $request->getParam($fieldname, '') . '"/></td>'; $html .= '</tr>'; $html .= '<tr><td colspan="2">'; $temp = new Button('submit', 'Register', 'registerBut'); $html .= $temp->render(); $html .= ' '; $temp = new Button("document.location.replace('" . $config->get('app.url') . "')", 'Cancel', 'cancelBut'); $html .= $temp->render(); $html .= '</td></tr>'; $html .= $this->renderSecurityFields(); $html .= '</form>'; $html .= '</table>'; return $html; }
/** * The constructor. * * @param Alpha\Model\Type\Date or Alpha\Model\Type\Timestamp $object The date or timestamp object that will be edited by this widget. * @param string $label The data label for the object. * @param string $name The name of the HTML input box. * * @since 1.0 * * @throws Alpha\Exception\IllegalArguementException */ public function __construct($object, $label = '', $name = '') { $config = ConfigProvider::getInstance(); // check the type of the object passed if ($object instanceof Date || $object instanceof Timestamp) { $this->dateObject = $object; } else { throw new IllegalArguementException('DateBox widget can only accept a Date or Timestamp object!'); } $this->label = $label; if ($config->get('security.encrypt.http.fieldnames')) { $this->name = base64_encode(SecurityUtils::encrypt($name)); } else { $this->name = $name; } }
/** * The constructor. * * @param Alpha\Model\Type\Text $text The text object that will be edited by this text box. * @param string $label The data label for the text object. * @param string $name The name of the HTML input box. * @param int $rows The display size (rows). * @param int $identifier An additional idenitfier to append to the id of the text box. * * @since 1.0 * * @throws Alpha\Exception\IllegalArguementException */ public function __construct($text, $label, $name, $rows = 5, $identifier = 0) { $config = ConfigProvider::getInstance(); if ($text instanceof Text) { $this->textObject = $text; } else { throw new IllegalArguementException('Text object passed [' . var_export($text, true) . '] is not a valid Text object!'); } $this->label = $label; $this->rows = $rows; $this->identifier = $identifier; if ($config->get('security.encrypt.http.fieldnames')) { $this->name = base64_encode(SecurityUtils::encrypt($name)); } else { $this->name = $name; } }
/** * The constructor. * * @param Alpha\Model\Type\String $string The string object that will be edited by this text box. * @param string $label The data label for the string object. * @param string $name The name of the HTML input box. * @param int $size The display size (characters). * * @since 1.0 * * @throws Alpha\Exception\IllegalArguementException */ public function __construct($string, $label, $name, $size = 0) { $config = ConfigProvider::getInstance(); if ($string instanceof String) { $this->stringObject = $string; } else { throw new IllegalArguementException('String object passed [' . var_export($string, true) . '] is not a valid String object!'); } $this->label = $label; $this->size = $size; if ($config->get('security.encrypt.http.fieldnames')) { $this->name = base64_encode(SecurityUtils::encrypt($name)); } else { $this->name = $name; } }
/** * Callback used to render footer content, including comments, votes and print/PDF buttons when * enabled to do so. * * @return string * * @since 1.0 */ public function before_displayPageFoot_callback() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); $session = SessionProviderFactory::getInstance($sessionProvider); $html = ''; $params = $this->request->getParams(); // this will ensure that direct requests to ActiveRecordController will be re-directed here. if (isset($this->record) && !$this->record->isTransient()) { $this->setName($config->get('app.url') . $this->request->getURI()); $this->setUnitOfWork(array($config->get('app.url') . $this->request->getURI(), $config->get('app.url') . $this->request->getURI())); } else { $this->setUnitOfWork(array()); } if ($this->record != null) { if (isset($params['view']) && $params['view'] == 'detailed') { if ($config->get('cms.display.comments')) { $html .= $this->renderComments(); } if ($config->get('cms.display.tags')) { $tags = $this->record->getPropObject('tags')->getRelatedObjects(); if (count($tags) > 0) { $html .= '<p>Tags:'; foreach ($tags as $tag) { $html .= ' <a href="' . $config->get('app.url') . '/search/' . $tag->get('content') . '">' . $tag->get('content') . '</a>'; } $html .= '</p>'; } } if ($config->get('cms.display.votes')) { $rating = $this->record->getArticleScore(); $votes = $this->record->getArticleVotes(); $html .= '<p>Average Article User Rating: <strong>' . $rating . '</strong> out of 10 (based on <strong>' . count($votes) . '</strong> votes)</p>'; } if (!$this->record->checkUserVoted() && $config->get('cms.voting.allowed')) { $URL = FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\\Model\\ArticleVote'); $html .= '<form action="' . $URL . '" method="post" accept-charset="UTF-8">'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('score')) : 'score'; $html .= '<p>Please rate this article from 1-10 (10 being the best):' . '<select name="' . $fieldname . '">' . '<option value="1">1' . '<option value="2">2' . '<option value="3">3' . '<option value="4">4' . '<option value="5">5' . '<option value="6">6' . '<option value="7">7' . '<option value="8">8' . '<option value="9">9' . '<option value="10">10' . '</select></p> '; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('articleOID')) : 'articleOID'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $this->record->getOID() . '"/>'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('personOID')) : 'personOID'; $html .= '<input type="hidden" name="' . $fieldname . '" value="' . $session->get('currentUser')->getID() . '"/>'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('statusMessage')) : 'statusMessage'; $html .= '<input type="hidden" name="' . $fieldname . '" value="Thank you for rating this article!"/>'; $temp = new Button('submit', 'Vote!', 'voteBut'); $html .= $temp->render(); $html .= View::renderSecurityFields(); $html .= '<form>'; } ActiveRecord::disconnect(); if ($config->get('cms.allow.print.versions')) { $html .= ' '; $temp = new Button("window.open('" . $this->record->get('printURL') . "')", 'Open Printer Version', 'printBut'); $html .= $temp->render(); } $html .= ' '; if ($config->get('cms.allow.pdf.versions')) { $html .= ' '; $temp = new Button("document.location = '" . FrontController::generateSecureURL("act=Alpha\\Controller\\ArticleController&mode=pdf&title=" . $this->record->get('title')) . "';", 'Open PDF Version', 'pdfBut'); $html .= $temp->render(); } // render edit button for admins only if ($session->get('currentUser') instanceof Alpha\Model\Person && $session->get('currentUser')->inGroup('Admin')) { $html .= ' '; $button = new Button("document.location = '" . FrontController::generateSecureURL('act=Alpha\\Controller\\ArticleController&mode=edit&ActiveRecordOID=' . $this->record->getID()) . "'", 'Edit', 'editBut'); $html .= $button->render(); } } if ($config->get('cms.display.standard.footer')) { $html .= '<p>Article URL: <a href="' . $this->record->get('URL') . '">' . $this->record->get('URL') . '</a><br>'; $html .= 'Title: ' . $this->record->get('title') . '<br>'; $html .= 'Author: ' . $this->record->get('author') . '</p>'; } } $html .= $config->get('cms.footer'); return $html; }
/** * Static method to return the decoded GET paramters from an encrytpted tk value as an array of key/value pairs. * * @return array * * @since 1.0 */ public static function getDecodeQueryParams($tk) { $config = ConfigProvider::getInstance(); // replace any troublesome characters from the URL with the original values $token = strtr($tk, '-_', '+/'); $token = base64_decode($token); $params = SecurityUtils::decrypt($token); $pairs = explode('&', $params); $parameters = array(); foreach ($pairs as $pair) { $split = explode('=', $pair); $parameters[$split[0]] = $split[1]; } return $parameters; }
/** * Testing encrypt/decrypt methods. * * @since 2.0.2 */ public function testEncryptDecrypt() { $plain = "test string"; $encrypted = SecurityUtils::encrypt($plain); $this->assertEquals($plain, SecurityUtils::decrypt($encrypted), "Testing encrypt/decrypt methods"); }
/** * 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')); }
/** * 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 ''; } }
/** * Handle GET requests. * * @param Alpha\Util\Http\Response $request * * @throws Alpha\Exception\IllegalArguementException * * @return Alpha\Util\Http\Response * * @since 1.0 */ public function doGET($request) { self::$logger->debug('>>doGET($request=[' . var_export($request, true) . '])'); $params = $request->getParams(); $config = ConfigProvider::getInstance(); if (!is_array($params)) { throw new IllegalArguementException('Bad $params [' . var_export($params, true) . '] passed to doGET method!'); } $body = View::displayPageHead($this); $message = $this->getStatusMessage(); if (!empty($message)) { $body .= $message; } $body .= '<h3>Listing contents of cache directory: ' . $this->dataDir . '</h3>'; $fileList = ''; $fileCount = FileUtils::listDirectoryContents($this->dataDir, $fileList, 0, array('.htaccess')); $body .= $fileList; $body .= '<h3>Total of ' . $fileCount . ' files in the cache.</h3>'; $body .= '<form action="' . $request->getURI() . '" method="post" name="clearForm" id="clearForm">'; $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('clearCache')) : 'clearCache'; $body .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '" value="false"/>'; $js = "if(window.jQuery) {\n BootstrapDialog.show({\n title: 'Confirmation',\n message: 'Are you sure you want to delete all files in the cache?',\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', 'true');\n \$('#clearForm').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Clear cache', 'clearBut'); $body .= $button->render(); $body .= View::renderSecurityFields(); $body .= '</form>'; $body .= View::displayPageFoot($this); self::$logger->debug('<<doGET'); return new Response(200, $body, array('Content-Type' => 'text/html')); }
/** * {@inheritdoc} */ public function renderDefaultField($name, $label, $mode, $value = '') { self::$logger->debug('>>renderDefaultField(name=[' . $name . '], label=[' . $label . '], mode=[' . $mode . '], value=[' . $value . '])'); $config = ConfigProvider::getInstance(); if ($config->get('security.encrypt.http.fieldnames')) { $fieldname = base64_encode(SecurityUtils::encrypt($name)); } else { $fieldname = $name; } $html = ''; $request = new Request(array('method' => 'GET')); if ($mode == 'create') { $html .= '<textarea cols="100" rows="3" name="' . $fieldname . '">' . $request->getParam($name, '') . '</textarea>'; } if ($mode == 'edit') { $html .= '<textarea cols="100" rows="3" name="' . $fieldname . '">' . $value . '</textarea>'; } if ($mode == 'view') { $html .= '<p><strong>' . $label . ':</strong> ' . $value . '</p>'; } self::$logger->debug('<<renderDefaultField [' . $html . ']'); return $html; }
/** * Renders the HTML for the file upload section. * * @return string * * @since 1.0 */ protected function renderFileUploadSection() { $config = ConfigProvider::getInstance(); $html = '<div class="form-group">'; $html .= ' <h3>File Attachments:</h3>'; if (is_dir($this->BO->getAttachmentsLocation())) { $handle = opendir($this->BO->getAttachmentsLocation()); $fileCount = 0; $html .= '<table class="table table-bordered">'; // loop over the attachments directory while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..') { ++$fileCount; $html .= '<tr>'; $html .= '<td>' . $file . ' <em>(' . number_format(filesize($this->BO->getAttachmentsLocation() . '/' . $file) / 1024) . ' KB)</em></td>'; $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('deletefile')) : 'deletefile') . "\"]').attr('value', '" . $file . "');\n \$('[id=\"" . stripslashes(get_class($this->BO)) . '_' . $this->BO->getID() . "\"]').submit();\n dialogItself.close();\n }\n }\n ]\n });\n }"; $button = new Button($js, 'Delete', 'delete' . $fileCount . 'But'); $html .= '<td>' . $button->render() . '</td>'; $html .= '</tr>'; } } $html .= '</table>'; } else { // we will take this opportunity to create the attachments folder is it does // not already exist. $this->BO->createAttachmentsFolder(); } $html .= '<span class="btn btn-default btn-file">'; $html .= '<input name="userfile" type="file" value="Browse..."/>'; $html .= '</span>'; $temp = new Button('submit', 'Upload', 'uploadBut'); $html .= $temp->render(); $fieldname = $config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('deletefile')) : 'deletefile'; $html .= '<input type="hidden" name="' . $fieldname . '" id="' . $fieldname . '" value=""/>'; $html .= '</div>'; return $html; }
/** * 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; }