Exemplo n.º 1
0
 /**
  * Builds the form view for adding or editing a contact form
  *
  * @param string $name
  * @param string $email
  * @param string $body
  * @param int $id
  * @return string
  */
 protected function buildFormView($name = null, $email = null, $body = null, $id = null)
 {
     if (is_null($id)) {
         $op = 'add';
         $resource = 'contact-form';
     } else {
         $op = 'edit';
         $resource = 'contact-form-' . $id;
         // Add JS for DnD ordering
         $this->_theme->addJsFile('jQuery/plugins/dnd.js');
         $this->addAsset('js/dnd_order.js');
     }
     $viewForm = new View_form('config/form_view.html', 'contact', is_null($id));
     $viewForm->action($this->_router->makeUrl('contact', 'config', $op, null, array('id' => $id)));
     $viewForm->addElement('contact/name', $name, t('Name'), new Validator_Length(1, 255));
     $viewForm->addElement('contact/email', $email, t('Email'), new Validator_Email());
     $viewForm->addElement('contact/body', $body, t('Body'), new Validator_Length(0, 50000), $id != null);
     // Assign some more data to use
     $viewForm->assign(array('ID' => $id, 'OP' => $op, 'FIELDS' => $id === null ? null : $this->_model()->getFormFields($id)));
     $viewForm->assignHtml(array('ACL_FORM' => $this->_acl->buildForm(array(t('View contact form') => $resource))));
     return $viewForm;
 }
Exemplo n.º 2
0
 /**
  * Builds the form for adding or editing a poll
  *
  * @param int $pid
  * @param string $title
  * @param int $duration
  * @param string $status
  * @param array $options
  * @return object
  */
 protected function buildPollForm($pid = null, $title = null, $duration = 1, $status = 'active', $options = array())
 {
     $op = $pid === null ? 'add' : 'edit';
     $form = new View_form('config/form_poll.html', 'poll');
     $form->addElement('poll/title', $title, t('Title'), new Validator_Length(1, 255));
     $form->addElement('poll/duration', $duration, t('Duration'), new Validator_Between(0, 29030400));
     $form->addElement('poll/status', $status, t('Status'), new Validator_InArray(array('active', 'closed')));
     if ($op == 'add') {
         $form->addElement('poll/options', $options, t('Options'), new Validator_Between(2, 100));
         try {
             foreach ($this->_input->post('poll/options') as $key => $tmpOpt) {
                 $form->addElement('poll/options/' . $key, $key, sprintf(t('Option %1$d'), $key + 1), new Validator_Length(1, 255));
             }
         } catch (Input_KeyNoExist $e) {
         }
     } else {
         $form->assign(array('poll' => array('options' => $options)));
     }
     $form->assign(array('OP' => $op, 'ID' => $pid));
     $form->assignHtml(array('ACL_FORM' => $this->_acl->buildForm(array(t('View poll') => 'poll-' . $pid))));
     return $form;
 }
Exemplo n.º 3
0
 /**
  * Allows the user to configure the module that is attached to a
  * sector. This, however, currently depends on JavaScript enabled.
  *
  * @return string
  */
 public function indexSection($layoutName = null)
 {
     $this->setTitle(t('Edit module'));
     $this->setOutputType(self::_OT_CONFIG);
     // Check permission and if a layout has been provided
     if (!$this->_acl->check('content_layout_config_module')) {
         throw new Module_NoPermission();
     } else {
         if ($layoutName === null) {
             $this->_event->error(t('Unable to edit attached module, no layout given'));
             return zula_redirect($this->_router->makeUrl('content_layout'));
         }
     }
     // Get correct cntrlr ID that is to be edited
     try {
         $cntrlrId = $this->_router->getArgument('id');
     } catch (Router_ArgNoExist $e) {
         try {
             $cntrlrId = $this->_input->post('content_layout/cid');
         } catch (Input_KeyNoExist $e) {
             $this->_event->error(t('Unable to edit attached module, no ID given'));
             return zula_redirect($this->_router->makeUrl('content_layout'));
         }
     }
     // Create the correct layout and ensure cntrlr exists
     $layout = new Layout($layoutName);
     try {
         $cntrlr = $layout->getControllerDetails($cntrlrId);
         $module = new Module($cntrlr['mod']);
         $this->setTitle(sprintf(t('Configure attached module "%1$s"'), $module->title));
         if (!isset($cntrlr['config']['clDescription'])) {
             $cntrlr['config']['clDescription'] = '';
         }
     } catch (Layout_ControllerNoExist $e) {
         $this->_event->error(sprintf(t('Unable to edit controller "%1$d" as it does not exist'), $cntrlrId));
         return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName));
     } catch (Module_NoExist $e) {
         $this->_event->error(sprintf(t('Unable to edit attached module "%1$s" as it does not exist'), $cntrlr['mod']));
         return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName));
     }
     /**
      * Prepare form validation
      */
     $form = new View_form('edit/module.html', $this->getDetail('name'), false);
     $form->addElement('content_layout/config/displayTitle', $cntrlr['config']['displayTitle'], t('Display Title'), new Validator_InArray(array('true', 'false', 'custom')));
     $form->addElement('content_layout/config/customTitle', $cntrlr['config']['customTitle'], t('Custom title'), new Validator_Length(0, 255));
     $form->addElement('content_layout/config/htmlWrapClass', $cntrlr['config']['htmlWrapClass'], t('HTML class'), new Validator_Length(0, 500), $cntrlr['sector'] != 'SC');
     $form->addElement('content_layout/config/clDescription', $cntrlr['config']['clDescription'], t('Description'), new Validator_Length(0, 255), $cntrlr['sector'] != 'SC');
     $form->addElement('content_layout/cntrlr', null, t('Controller'), new Validator_Alphanumeric('_-.!+'));
     $form->addElement('content_layout/section', null, t('Section'), new Validator_Alphanumeric('_-.!+'));
     $form->addElement('content_layout/config', null, t('Config'), new Validator_Is('array'), false);
     if ($form->hasInput() && $form->isValid()) {
         $fd = $form->getValues('content_layout');
         try {
             $layout->editController($cntrlr['id'], array('con' => $fd['cntrlr'], 'sec' => $fd['section'], 'order' => $cntrlr['order'], 'config' => isset($fd['config']) ? $fd['config'] : array()));
             try {
                 $roles = $this->_input->post('acl_resources/layout_controller_' . $cntrlr['id']);
             } catch (Input_ValueNoExist $e) {
                 $roles = array();
             }
             $this->_acl->allowOnly('layout_controller_' . $cntrlr['id'], $roles);
             if ($layout->save()) {
                 $this->_event->success(sprintf(t('Configured attached module ID "%d"'), $cntrlr['id']));
             } else {
                 $this->_event->error(t('Unable to save layout, ensure file is writable'));
             }
         } catch (Layout_ControllerNoExist $e) {
             $this->_event->error(sprintf(t('Unable to edit attached module ID "%d" as it does not exist'), $cntrlr['id']));
         } catch (Theme_SectorMapNotWriteable $e) {
             $this->_event->error(sprintf(t('Unable to edit module in sector map: $s'), $e->getMessage()));
         }
         // Redirect back to correct location, FPSC layouts go back to index
         $url = new Router_Url('content_layout');
         $url->siteType($this->_router->getSiteType());
         if (strpos($layoutName, 'fpsc-') === 0) {
             $url->queryArgs(array('type' => substr($layoutName, 5)));
         } else {
             $url->controller('manage')->section($layoutName);
         }
         return zula_redirect($url);
     }
     /**
      * Gets all displays modes that this module offers, the current display
      * mode being used - once done start building up the form.
      */
     $displayModes = Hooks::notifyAll($module->name . '_display_modes');
     $currentMode = Hooks::notifyAll($module->name . '_resolve_mode', $cntrlr['con'], $cntrlr['sec'], $cntrlr['config']);
     $this->addAsset('js/edit.js');
     $form->assign(array('CID' => $cntrlr['id'], 'LAYOUT_NAME' => $layoutName, 'SECTOR' => $cntrlr['sector'], 'MODULE' => $module->getDetails(), 'DISPLAY_MODES' => empty($displayModes) ? array('default' => t('Default')) : $displayModes, 'CURRENT_MODE' => empty($currentMode) ? 'default' : $currentMode[0]));
     $jsConfig = array_merge($cntrlr, $cntrlr['config']);
     unset($jsConfig['config']);
     $form->assignHtml(array('JS_CONFIG' => zula_array_js_string($jsConfig), 'ACL_FORM' => $this->_acl->buildForm(array(t('View attached module') => 'layout_controller_' . $cntrlr['id']))));
     return $form->getOutput();
 }