コード例 #1
0
 public function __form()
 {
     $this->setPageType('form');
     $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL;
     $this->Form->setAttribute('class', 'columns');
     $filename = $this->_existing_file;
     // Handle unknown context
     if (!in_array($this->_context[0], array('new', 'edit'))) {
         Administration::instance()->errorPageNotFound();
     }
     // Edit Utility context
     if ($this->_context[0] == 'edit') {
         $file_abs = UTILITIES . '/' . $this->_existing_file;
         if (!is_file($file_abs)) {
             redirect(SYMPHONY_URL . '/blueprints/utilities/new/');
         }
         $fields['name'] = $filename;
         $fields['body'] = @file_get_contents($file_abs);
         $this->Form->setAttribute('action', SYMPHONY_URL . '/blueprints/utilities/edit/' . $this->_context[1] . '/');
     } else {
         $fields['body'] = file_get_contents(PageManager::getTemplate('blueprints.utility'));
     }
     $formHasErrors = is_array($this->_errors) && !empty($this->_errors);
     if ($formHasErrors) {
         $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR);
     }
     // These alerts are only valid if the form doesn't have errors
     if (isset($this->_context[2])) {
         switch ($this->_context[2]) {
             case 'saved':
                 $this->pageAlert(__('Utility updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/utilities/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/utilities/" accesskey="a">' . __('View all Utilities') . '</a>', Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('Utility created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/utilities/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/utilities/" accesskey="a">' . __('View all Utilities') . '</a>', Alert::SUCCESS);
                 break;
         }
     }
     $this->setTitle(__($this->_context[0] == 'new' ? '%2$s &ndash; %3$s' : '%1$s &ndash; %2$s &ndash; %3$s', array($filename, __('Utilities'), __('Symphony'))));
     $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $filename);
     $this->insertBreadcrumbs(array(Widget::Anchor(__('Utilities'), SYMPHONY_URL . '/blueprints/utilities/')));
     if (!empty($_POST)) {
         $fields = $_POST['fields'];
     }
     $fields['body'] = htmlentities($fields['body'], ENT_COMPAT, 'UTF-8');
     $fields['name'] = isset($fields['name']) ? $fields['name'] : null;
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'primary column');
     $label = Widget::Label(__('Name'));
     $label->appendChild(Widget::Input('fields[name]', $fields['name']));
     $fieldset->appendChild(isset($this->_errors['name']) ? Widget::Error($label, $this->_errors['name']) : $label);
     $label = Widget::Label(__('Body'));
     $label->appendChild(Widget::Textarea('fields[body]', 30, 80, $fields['body'], array('class' => 'code')));
     $fieldset->appendChild(isset($this->_errors['body']) ? Widget::Error($label, $this->_errors['body']) : $label);
     $this->Form->appendChild($fieldset);
     $utilities = General::listStructure(UTILITIES, array('xsl'), false, 'asc', UTILITIES);
     $utilities = $utilities['filelist'];
     if (is_array($utilities) && !empty($utilities)) {
         $this->Form->setAttribute('class', 'two columns');
         $div = new XMLElement('div');
         $div->setAttribute('class', 'secondary column');
         $p = new XMLElement('p', __('Utilities'));
         $p->setAttribute('class', 'label');
         $div->appendChild($p);
         $frame = new XMLElement('div', null, array('class' => 'frame'));
         $ul = new XMLElement('ul');
         $ul->setAttribute('id', 'utilities');
         foreach ($utilities as $util) {
             $li = new XMLElement('li');
             $li->appendChild(Widget::Anchor($util, SYMPHONY_URL . '/blueprints/utilities/edit/' . str_replace('.xsl', '', $util) . '/', NULL));
             $ul->appendChild($li);
         }
         $frame->appendChild($ul);
         $div->appendChild($frame);
         $this->Form->appendChild($div);
     }
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Utility'), 'submit', array('accesskey' => 's')));
     if ($this->_context[0] == 'edit') {
         $button = new XMLElement('button', __('Delete'));
         $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this utility'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this Utility?')));
         $div->appendChild($button);
     }
     $this->Form->appendChild($div);
 }