示例#1
0
 /**
  * Log a SQL queries.
  *
  * @param string $message
  *
  * @since 1.1
  */
 public function sql($message)
 {
     if ($this->level == 'SQL') {
         $dateTime = date('Y-m-d H:i:s');
         $line = array($dateTime, 'SQL', $this->classname, $message, $this->request->getUserAgent(), $this->request->getIP(), gethostname(), $this->request->getURI());
         $this->logProvider->writeLine($line);
     }
 }
示例#2
0
 /**
  * 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 .= '&nbsp;&nbsp;';
     $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;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public static function displayPageHead($controller)
 {
     if (self::$logger == null) {
         self::$logger = new Logger('RendererProviderHTML');
     }
     self::$logger->debug('>>displayPageHead(controller=[' . var_export($controller, true) . '])');
     $config = ConfigProvider::getInstance();
     $sessionProvider = $config->get('session.provider.name');
     $session = SessionProviderFactory::getInstance($sessionProvider);
     if (!class_exists(get_class($controller))) {
         throw new IllegalArguementException('The controller provided [' . get_class($controller) . '] is not defined anywhere!');
     }
     $allowCSSOverrides = true;
     $request = new Request(array('method' => 'GET'));
     if ($session->get('currentUser') != null && ActiveRecord::isInstalled() && $session->get('currentUser')->inGroup('Admin') && mb_strpos($request->getURI(), '/tk/') !== false) {
         $allowCSSOverrides = false;
     }
     $html = View::loadTemplateFragment('html', 'head.phtml', array('title' => $controller->getTitle(), 'description' => $controller->getDescription(), 'allowCSSOverrides' => $allowCSSOverrides));
     if (method_exists($controller, 'during_displayPageHead_callback')) {
         $html .= $controller->during_displayPageHead_callback();
     }
     $html .= '</head>';
     try {
         if ($controller->getRecord() != null) {
             $html .= '<body' . ($controller->getRecord()->get('bodyOnload') != '' ? ' onload="' . $controller->getRecord()->get('bodyOnload') . '"' : '') . '>';
         } else {
             $html .= '<body>';
         }
     } catch (AlphaException $e) {
         $html .= '<body>';
     }
     $html .= '<div class="container">';
     if (method_exists($controller, 'insert_CMSDisplayStandardHeader_callback')) {
         $html .= $controller->insert_CMSDisplayStandardHeader_callback();
     }
     self::$logger->debug('<<displayPageHead [HTML]');
     return $html;
 }
示例#4
0
 /**
  * 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 . '&nbsp;&nbsp;&nbsp;&nbsp;';
                         }
                         // 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 .= '&nbsp;&nbsp;&nbsp;&nbsp;<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;
 }
示例#5
0
 /**
  * Method for determining if the current request URL is a secure one (has a tk string or not).
  *
  * @return bool True if the current URL contains a tk value, false otherwise
  *
  * @since 1.0
  */
 public function checkIfAccessingFromSecureURL()
 {
     if ($this->request->getParam('tk') != null || mb_strpos($this->request->getURI(), '/tk/') !== false) {
         return true;
     } else {
         return false;
     }
 }
示例#6
0
 /**
  * Testing that the URI can be set from overrides or super-globals during object construction.
  */
 public function testSetURI()
 {
     $request = new Request(array('method' => 'GET', 'URI' => '/controller/param'));
     $this->assertEquals('/controller/param', $request->getURI(), 'Testing that the URI can be set from overrides or super-globals during object construction');
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['REQUEST_URI'] = '/controller/param';
     $request = new Request();
     $this->assertEquals('/controller/param', $request->getURI(), 'Testing that URI can be set from overrides or super-globals during object construction');
 }