예제 #1
0
 /**
  * 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;
 }
 /**
  * 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&amp;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&amp;ActiveRecordType=Alpha\\Model\\Article&amp;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;
 }
예제 #3
0
 /**
  * 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'));
 }
예제 #4
0
 /**
  * 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 .= '&nbsp;&nbsp;';
         $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 .= '&nbsp;&nbsp;';
         $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;
 }
예제 #5
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;
 }
예제 #6
0
 /**
  * Displays a search form on the top of the page.
  *
  * @return string
  *
  * @since 1.0
  */
 public function after_displayPageHead_callback()
 {
     $config = ConfigProvider::getInstance();
     $body = parent::after_displayPageHead_callback();
     $body .= '<div align="center" class="form-group"><form class="form-inline" method="GET" id="search_form" onsubmit="document.location = \'' . $config->get('app.url') . 'search/\'+document.getElementById(\'q\').value; return false;">';
     $body .= '<label for="q">Search for</label><input type="text" name="q" id="q" class="form-control" style="width:50%; margin:10px;"/>';
     $button = new Button('document.location = \'' . $config->get('app.url') . '/search/\'+document.getElementById(\'q\').value', 'Search', 'searchButton');
     $body .= $button->render();
     $body .= '</p></form></div>';
     return $body;
 }
예제 #7
0
 /**
  * {@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 .= '&nbsp;&nbsp;';
         $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);
 }
예제 #8
0
 /**
  * Custom display view.
  *
  * @param array $fields Hash array of HTML fields to pass to the template.
  *
  * @since 1.0
  */
 public function detailedView($fields = array())
 {
     self::$logger->debug('>>detailedView(fields=[' . var_export($fields, true) . '])');
     if (method_exists($this, 'before_detailedView_callback')) {
         $this->before_detailedView_callback();
     }
     $config = ConfigProvider::getInstance();
     // we may want to display the OID regardless of class
     $fields['OIDLabel'] = $this->BO->getDataLabel('OID');
     $fields['OID'] = $this->BO->getOID();
     // buffer form fields to $formFields
     $fields['formFields'] = $this->renderAllFields('view');
     // Back button
     $button = new Button('history.back()', 'Back', 'backBut');
     $fields['backButton'] = $button->render();
     $fields['adminButtons'] = '';
     $html = $this->loadTemplate($this->BO, 'detail', $fields);
     if (method_exists($this, 'after_detailedView_callback')) {
         $this->after_detailedView_callback();
     }
     self::$logger->debug('<<detailedView');
     return $html;
 }
예제 #9
0
    /**
     * Returns the HTML for the record selector that will appear in a pop-up window.
     *
     * @param string $fieldname  The hidden HTML form field in the parent to pass values back to.
     * @param array  $lookupOIDs An optional array of related look-up OIDs, only required for rendering MANY-TO-MANY rels
     *
     * @since 1.0
     *
     * @return string
     */
    public function renderSelector($fieldname, $lookupOIDs = array())
    {
        self::$logger->debug('>>renderSelector(fieldname=[' . $fieldname . '], lookupOIDs=[' . var_export($lookupOIDs, true) . '])');
        $config = ConfigProvider::getInstance();
        $html = '<script language="JavaScript">
            var selectedOIDs = new Object();

            function toggelOID(oid, displayValue, isSelected) {
                if(isSelected)
                    selectedOIDs[oid] = displayValue;
                else
                    delete selectedOIDs[oid];
            }

            function setParentFieldValues() {
                var OIDs;
                var displayValues;

                for(key in selectedOIDs) {
                    if(OIDs == null)
                        OIDs = key;
                    else
                        OIDs = OIDs + \',\' + key;

                    if(displayValues == null)
                        displayValues = selectedOIDs[key];
                    else
                        displayValues = displayValues + \'\\n\' + selectedOIDs[key];
                }

                if(OIDs == null) {
                    document.getElementById(\'' . $fieldname . '\').value = "00000000000";
                    document.getElementById(\'' . $fieldname . '_display\').value = "";
                }else{
                    document.getElementById(\'' . $fieldname . '\').value = OIDs;
                    document.getElementById(\'' . $fieldname . '_display\').value = displayValues;
                }
            }

            </script>';
        if ($this->relationObject->getRelationType() == 'MANY-TO-MANY') {
            $classNameLeft = $this->relationObject->getRelatedClass('left');
            $classNameRight = $this->relationObject->getRelatedClass('right');
            if ($this->accessingClassName == $classNameLeft) {
                $tmpObject = new $classNameRight();
                $fieldName = $this->relationObject->getRelatedClassDisplayField('right');
                $fieldLabel = $tmpObject->getDataLabel($fieldName);
                $oidLabel = $tmpObject->getDataLabel('OID');
                $objects = $tmpObject->loadAll(0, 0, 'OID', 'ASC', true);
                self::$logger->debug('[' . count($objects) . '] related [' . $classNameLeft . '] objects loaded');
            } else {
                $tmpObject = new $classNameLeft();
                $fieldName = $this->relationObject->getRelatedClassDisplayField('left');
                $fieldLabel = $tmpObject->getDataLabel($fieldName);
                $oidLabel = $tmpObject->getDataLabel('OID');
                $objects = $tmpObject->loadAll(0, 0, 'OID', 'ASC', true);
                self::$logger->debug('[' . count($objects) . '] related [' . $classNameLeft . '] objects loaded');
            }
            $html .= '<table cols="3" class="table table-bordered">';
            $html .= '<tr>';
            $html .= '<th>' . $oidLabel . '</th>';
            $html .= '<th>' . $fieldLabel . '</th>';
            $html .= '<th>Connect?</th>';
            $html .= '</tr>';
            foreach ($objects as $obj) {
                $html .= '<tr>';
                $html .= '<td width="20%">';
                $html .= $obj->getOID();
                $html .= '</td>';
                $html .= '<td width="60%">';
                $html .= $obj->get($fieldName);
                $html .= '</td>';
                $html .= '<td width="20%">';
                if (in_array($obj->getOID(), $lookupOIDs)) {
                    $this->onloadJS .= 'toggelOID(\'' . $obj->getOID() . '\',\'' . $obj->get($fieldName) . '\',true);';
                    $html .= '<input name = "' . $obj->getOID() . '" type="checkbox" checked onclick="toggelOID(\'' . $obj->getOID() . '\',\'' . $obj->get($fieldName) . '\',this.checked);"/>';
                } else {
                    $html .= '<input name = "' . $obj->getOID() . '" type="checkbox" onclick="toggelOID(\'' . $obj->getOID() . '\',\'' . $obj->get($fieldName) . '\',this.checked);"/>';
                }
                $html .= '</td>';
                $html .= '</tr>';
            }
            $html .= '</table>';
        } else {
            $className = $this->relationObject->getRelatedClass();
            $tmpObject = new $className();
            $label = $tmpObject->getDataLabel($this->relationObject->getRelatedClassDisplayField());
            $oidLabel = $tmpObject->getDataLabel('OID');
            $objects = $tmpObject->loadAll(0, 0, 'OID', 'DESC');
            $html = '<table cols="3" width="100%" class="bordered">';
            $html .= '<tr>';
            $html .= '<th>' . $oidLabel . '</th>';
            $html .= '<th>' . $label . '</th>';
            $html .= '<th>Connect?</th>';
            $html .= '</tr>';
            foreach ($objects as $obj) {
                $html .= '<tr>';
                $html .= '<td width="20%">';
                $html .= $obj->getOID();
                $html .= '</td>';
                $html .= '<td width="60%">';
                $html .= $obj->get($this->relationObject->getRelatedClassDisplayField());
                $html .= '</td>';
                $html .= '<td width="20%">';
                if ($obj->getOID() == $this->relationObject->getValue()) {
                    $html .= '<img src="' . $config->get('app.url') . '/images/icons/accept_ghost.png"/>';
                } else {
                    $tmp = new Button("document.getElementById('" . $fieldname . "').value = '" . $obj->getOID() . "'; document.getElementById('" . $fieldname . "_display').value = '" . $obj->get($this->relationObject->getRelatedClassDisplayField()) . "'; \$('[Id=" . $fieldname . "_display]').blur(); window.jQuery.dialog.close();", '', 'selBut', $config->get('app.url') . '/images/icons/accept.png');
                    $html .= $tmp->render();
                }
                $html .= '</td>';
                $html .= '</tr>';
            }
            $html .= '</table>';
        }
        $html .= '<script type="text/javascript">' . '$(document).ready(function() {';
        $html .= $this->onloadJS;
        $html .= '});</script>';
        self::$logger->debug('<<renderSelector[html]');
        return $html;
    }
예제 #10
0
 /**
  * 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 .= '&nbsp;&nbsp;';
             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'));
 }
예제 #11
0
 /**
  * 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>&nbsp;&nbsp;';
                 $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 .= '&nbsp;&nbsp;';
                 $temp = new Button("window.open('" . $this->record->get('printURL') . "')", 'Open Printer Version', 'printBut');
                 $html .= $temp->render();
             }
             $html .= '&nbsp;&nbsp;';
             if ($config->get('cms.allow.pdf.versions')) {
                 $html .= '&nbsp;&nbsp;';
                 $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 .= '&nbsp;&nbsp;';
                 $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;
 }
예제 #12
0
 /**
  * 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 .= '&nbsp;&nbsp;';
     $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;
 }