Ejemplo n.º 1
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);
 }