예제 #1
0
파일: Login.php 프로젝트: nuxwin/i-PMS
 /**
  * Form initialization
  *
  * @return void
  */
 public function init()
 {
     $this->setName('loginForm');
     $this->setElementsBelongTo('loginForm');
     $element = new Zend_Form_Element_Text('username');
     $element->setLabel('Username')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim');
     $this->addElement($element);
     $element = new Zend_Form_Element_Password('password');
     $element->setLabel('Password')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim');
     $this->addElement($element);
     $element = new Zend_Form_Element_Checkbox('rememberMe');
     $element->setLabel('Remember me');
     $this->addElement($element);
     /**
      * @var $request Zend_Controller_Request_Http
      */
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $element = new Zend_Form_Element_Hidden('redirect');
     $element->setValue($request->getParam('from', '/'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim');
     $element->getDecorator('HtmlTag')->setOption('class', 'hidden');
     $element->getDecorator('Label')->setOption('tagClass', 'hidden');
     $this->addElement($element);
     $element = new Zend_Form_Element_Submit('submit');
     $element->setLabel('Connection');
     $this->addElement($element);
 }
예제 #2
0
파일: MailForm.php 프로젝트: alexukua/opus4
 /**
  * Build easy mail form
  *
  * @return void
  */
 public function init()
 {
     // Create and configure query field elements:
     $recipient = new Zend_Form_Element_Text('recipient');
     $recipient->setRequired(false);
     $recipient->setLabel('frontdoor_recipientname');
     $recipient_mail = new Zend_Form_Element_Text('recipient_mail');
     $recipient_mail->setRequired(true);
     $recipient_mail->setLabel('frontdoor_recipientmail');
     $sender = new Zend_Form_Element_Text('sender');
     $sender->setRequired(false);
     $sender->setLabel('frontdoor_sendername');
     $sender_mail = new Zend_Form_Element_Text('sender_mail');
     $sender_mail->setRequired(false);
     $sender_mail->setLabel('frontdoor_sendermail');
     $message = new Zend_Form_Element_Textarea('message');
     $message->setRequired(false);
     $message->setLabel('frontdoor_messagetext');
     $title = new Zend_Form_Element_Hidden('title');
     $htmlTag = $title->getDecorator('htmlTag');
     $htmlTag->setOption('tag', 'div');
     $title->removeDecorator('label');
     $doc_id = new Zend_Form_Element_Hidden('doc_id');
     $htmlTag = $doc_id->getDecorator('htmlTag');
     $htmlTag->setOption('tag', 'div');
     $doc_id->removeDecorator('label');
     $doc_type = new Zend_Form_Element_Hidden('doc_type');
     $htmlTag = $doc_type->getDecorator('htmlTag');
     $htmlTag->setOption('tag', 'div');
     $doc_type->removeDecorator('label');
     $submit = new Zend_Form_Element_Submit('frontdoor_send_recommendation');
     $submit->setLabel('frontdoor_sendrecommendation');
     // Add elements to form:
     $this->addElements(array($recipient, $recipient_mail, $sender, $sender_mail, $message, $title, $doc_id, $doc_type, $submit));
 }
예제 #3
0
파일: Widget.php 프로젝트: nuxwin/i-PMS
 /**
  * Returns a Form builds from widget's form definition or instanciated from given classname
  *
  * Form definition:
  *
  * A widget can define one or more Form in its xml description file. A Form can be used, either as main output of
  * the widget, or on the dashboard screen for setting purpose. When you pass a Form name as argument, this method
  * will try to retrieve the associated Form definition and build the Form from it.
  *
  * Form class:
  *
  * It's also possible to pass an associative array where the key is a Form classname and the value, the path where
  * to find the file that contains the class. It this case, An instance of the class will be created and returned.
  *
  * Common treatment:
  *
  * In all cases, if the Form's target is the dashboard screen, a specific hidden field is added to it. Also, if the
  * Form has not submit element, it's automatically generated and added to it.
  *
  * Alternative way:
  *
  * The alternative way is to override this method in subclass and build your Form into it directly. Note that the
  * {@link iPMS_Widget::getForm()} method is used both to retrieve Form for main output of the widget, and the
  * dashboard screen.
  *
  * @throws iPMS_Widgets_Exception if form definition was not found
  * @throws iPMS_Widgets_Exception if form class was not found
  * @param string|array $form Either a Form name to build from  a Form's definition, or an array where the key is the
  * Form classname and the value, the path where to find it
  * @return Zend_Form a Zend_Form object
  */
 public function getForm($form)
 {
     if (is_string($form)) {
         // Form generated from Form definition
         if (isset($this->_formInstances[$form])) {
             return $this->_formInstances[$form];
         }
         $formDef = $this->getFormDefinition($form);
         if (!array_key_exists('type', $formDef['element'])) {
             $formDef = $formDef['element'];
         }
         $elementStack = array();
         foreach ($formDef as $elementDef) {
             /**
              * @var $element Zend_Form_Element|Zend_Form_Element_Select
              */
             $className = 'Zend_Form_Element_' . ucfirst($elementDef['type']);
             $element = new $className($elementDef['name'], array('label' => isset($elementDef['label']) ? $elementDef['label'] : '', 'value' => isset($elementDef['val']) ? $elementDef['val'] : '', 'helper' => 'form' . ucfirst($elementDef['type']), 'required' => isset($elementDef['required']) ? (int) $elementDef['required'] : 0));
             if ($elementDef['type'] == 'select') {
                 if (isset($elementDef['option'])) {
                     foreach ($elementDef['option'] as $option) {
                         $element->addMultiOptions(array($option['val'] => $option['label']));
                         if (isset($option['selected'])) {
                             $element->setValue($option['val']);
                         }
                     }
                 } elseif (isset($elementDef['callback'])) {
                     if (isset($elementDef['callback']['function'])) {
                         $options = call_user_func_array($elementDef['callback']['function'], (array) isset($elementDef['callback']['argument']) ? $elementDef['callback']['argument'] : array());
                         if ($elementDef['callback']['function'] == 'range') {
                             $options = array_combine($options, $options);
                         }
                         $element->addMultiOptions($options);
                         if (isset($elementDef['callback']['selected'])) {
                             $element->setValue($elementDef['callback']['selected']);
                         }
                     } else {
                         require_once 'iPMS/Widgets/Exception.php';
                         throw new iPMS_Widgets_Exception('Unable to generate element options from callback: function name not found');
                     }
                 } else {
                     require_once 'iPMS/Widgets/Exception.php';
                     throw new iPMS_Widgets_Exception('All select elements must have options');
                 }
             }
             if (isset($elementDef['id'])) {
                 // Optional CSS id for element
                 $element->setAttrib('id', $elementDef['id']);
             }
             if (isset($elementDef['class'])) {
                 // Optional CSS class for element
                 $element->setAttrib('class', $elementDef['class']);
             }
             if (isset($elementDef['filter'])) {
                 // Optional filter(s) for element
                 $element->addFilters((array) $elementDef['filter']);
             }
             // Optional validator for element
             if (isset($elementDef['validator'])) {
                 // Optional validator for element
                 $element->addValidators((array) $elementDef['validator']);
             }
             $elementStack[] = $element;
         }
         // Creating new form instance
         $formInstance = new Zend_Form();
         $formInstance->setName($form)->setElementsBelongTo($form)->addElements($elementStack);
         // Optional description for the Form
         if (isset($formDef['description'])) {
             $formInstance->setDescription($formDef['description'])->addDecorator('Description', array('placement' => 'prepend'));
         }
     } elseif (is_array($form) && isset($form['clasname'])) {
         // Form generated from specific class
         $className = $form['clasname'];
         if (isset($this->_formInstances[$className])) {
             return $this->_formInstances[$className];
         }
         if (!class_exists($className)) {
             require_once 'Zend/Loader.php';
             Zend_Loader::loadClass($className, isset($form['path']) ? isset($form['path']) : null);
         }
         $formInstance = new $className();
         if (!$formInstance instanceof Zend_Form) {
             require_once 'iPMS/Widgets/Exception.php';
             throw new iPMS_Widgets_Exception(sprintf('Invalid argument: Detected class "%s", which is not an instance of Zend_Form', $className));
         }
     } else {
         require_once 'iPMS/Widgets/Exception.php';
         throw new iPMS_Widgets_Exception('Invalid argument $form');
     }
     // Common treatment
     if ($form !== 'dashboard') {
         $hidden = new Zend_Form_Element_Hidden('widgetUpdate');
         $hidden->setValue($this . '_' . $this->_id)->setRequired(true);
         $hidden->getDecorator('HtmlTag')->setOption('class', 'hidden');
         $hidden->getDecorator('Label')->setOption('tagClass', 'hidden');
         $formInstance->addElement($hidden);
     }
     // Add a submit element if it doesn't already defined
     if (null === $formInstance->getElement('submit')) {
         $submit = new Zend_Form_Element_Submit('submit');
         $submit->setLabel('submit');
         $formInstance->addElement($submit);
     }
     return $this->_formInstances[isset($className) ? $className : $form] = $formInstance;
 }
예제 #4
0
 /**
  * Cria a toolbar.
  * @param Boolean $save define se irá aparecer o botão padrão Salvar.
  * @param Boolean $saveClose Botão para salvar e fechar
  * @param Boolean $printForm Botão para imprimir
  * @param Boolean $deleteForm Botão para deletar
  * @param Boolean $clearForm Botão limpar dados de um formulário
  * @param Boolean $includeForm Botão para incluir
  * @param Boolean $editForm Botão para editar
  * @param Boolean $backForm Botão para voltar
  * @param Boolean $execute Botão para executar processo [GAMBI]
  * @param Boolean $returnPendency Botão para processar dados [GAMBI]
  * @param Boolean $processData Botão para processar dados [GAMBI]
  * @param Boolean $block Botão para bloquear recursos [GAMBI]
  * @param Boolean $disable Botão para desativar recursos [GAMBI]
  */
 public function createToolbar($save = false, $saveClose = false, $printForm = false, $deleteForm = false, $clearForm = false, $includeForm = false, $editForm = false, $backForm = false, $execute = false, $returnPendency = false, $processData = false, $block = false, $disable = false, array $params = null)
 {
     $elementsList = array();
     $elementsNameList = array();
     if ($save) {
         $saveForm = new Zend_Form_Element_Submit('saveForm');
         $saveForm->setLabel('Salvar');
         $saveForm->setAttrib('class', 'save');
         $saveForm->setDecorators(array(array('ViewHelper'), array('description'), array('HtmlTag', array('tag' => 'li'))));
         $elementsList[] = $saveForm;
         $elementsNameList[] = "saveForm";
     }
     if ($saveClose) {
         $saveCloseForm = new Zend_Form_Element_Submit('saveCloseForm');
         // $saveCloseForm = new Zend_Form_Element_Hidden('saveCloseForm');
         $saveCloseForm->setLabel('Salvar/Fechar');
         $saveCloseForm->setAttrib('class', 'save_close');
         // $saveCloseForm->setDescription('<a href="" class="save_close" id="save_close">Salvar/Fechar</a>');
         $saveCloseForm->setDecorators(array(array('ViewHelper'), array('description'), array('HtmlTag', array('tag' => 'li'))));
         $saveCloseForm->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $saveCloseForm;
         $elementsNameList[] = "saveCloseForm";
     }
     if ($execute) {
         $execute = new Zend_Form_Element_Hidden('execute');
         $execute->setDescription('<a href="" id="execute" class="execute">Executar</a>');
         $execute->setDecorators(array(array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'execute'))));
         $execute->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $execute;
         $elementsNameList[] = "execute";
     }
     if ($returnPendency) {
         $returnPendency = new Zend_Form_Element_Hidden('returnPendency');
         $returnPendency->setDescription('<a href="" id="rtPendency" class="back">Retornar pendência</a>');
         $returnPendency->setDecorators(array(array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'back'))));
         $returnPendency->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $returnPendency;
         $elementsNameList[] = "returnPendency";
     }
     if ($processData) {
         $processData = new Zend_Form_Element_Hidden('processData');
         $processData->setDescription('<a href="" id="processData" class="process">Dados do processo</a>');
         $processData->setDecorators(array(array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'process'))));
         $processData->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $processData;
         $elementsNameList[] = "processData";
     }
     if ($clearForm) {
         $clearForm = new Zend_Form_Element_Hidden('clearForm');
         $clearForm->setDescription('<a href="" id="clear_btn" class="clean">Limpar</a>');
         $clearForm->setDecorators(array(array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'clear'))));
         $clearForm->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $clearForm;
         $elementsNameList[] = "clearForm";
     }
     if ($includeForm) {
         $includeForm = new Zend_Form_Element_Hidden('includeForm');
         $includeForm->setDescription('<a href="#" id="include_btn" class="include">Incluir</a>');
         $includeForm->setDecorators(array(array('ViewHelper'), array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'include'))));
         $includeForm->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $includeForm;
         $elementsNameList[] = "includeForm";
     }
     if ($editForm) {
         $editForm = new Zend_Form_Element_Hidden('editForm');
         $editForm->setDescription('<a href="#" id="edit_btn" class="edit">Editar</a>');
         $editForm->setDecorators(array(array('ViewHelper'), array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'edit'))));
         $editForm->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $editForm;
         $elementsNameList[] = "editForm";
     }
     if ($deleteForm) {
         $deleteForm = new Zend_Form_Element_Hidden('deleteForm');
         $deleteForm->setDescription('<a href="" id="delete_btn" class="delete">Excluir</a>');
         $deleteForm->setDecorators(array(array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'delete'))));
         $deleteForm->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $deleteForm;
         $elementsNameList[] = "deleteForm";
     }
     if ($block) {
         $block = new Zend_Form_Element_Hidden('blockForm');
         $block->setDescription('<a href="" id="block_btn" class="block">Bloquear/Desbloquear</a>');
         $block->setDecorators(array(array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'block'))));
         $block->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $block;
         $elementsNameList[] = "blockForm";
     }
     if ($disable) {
         $disable = new Zend_Form_Element_Hidden('disableForm');
         $disable->setDescription('<a href="" id="disable_btn" class="disable">Ativar/Desativar</a>');
         $disable->setDecorators(array(array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'disable'))));
         $disable->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $disable;
         $elementsNameList[] = "disableForm";
     }
     if ($printForm) {
         $printForm = new Zend_Form_Element_Hidden('printForm');
         $printForm->setDescription('<a href="" id="print_btn" class="prints">Impressões</a>');
         $printForm->setDecorators(array(array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'prints'))));
         $printForm->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $printForm;
         $elementsNameList[] = "printForm";
     }
     if ($backForm) {
         $backForm = new Zend_Form_Element_Hidden('backForm');
         $backForm->setDescription('<a href="' . $_SERVER['HTTP_REFERER'] . '" id="back_btn" class="back">Voltar</a>');
         $backForm->setDecorators(array(array('ViewHelper'), array('description'), array('HtmlTag', array('tag' => 'li', 'class' => 'back'))));
         $backForm->getDecorator('description')->setOption('escape', false);
         $elementsList[] = $backForm;
         $elementsNameList[] = "backForm";
     }
     if (isset($params)) {
         foreach ($params as $idParam => $valueParam) {
             $objectZendForm = "Zend_Form_Element_" . $valueParam["typeButton"];
             $idParam = new $objectZendForm($valueParam["name"]);
             if ($valueParam["typeButton"] == "Hidden") {
                 $idParam->setDescription('<a href="' . $valueParam["href"] . '" id="' . $valueParam["name"] . '" class="' . $valueParam["class"] . '">' . $valueParam["label"] . '</a>');
                 $idParam->setDecorators(array(array('description'), array('HtmlTag', array('tag' => 'li'))));
                 $idParam->getDecorator('description')->setOption('escape', false);
             } else {
                 if ($valueParam["typeButton"] == "Submit") {
                     $idParam->setLabel($valueParam["label"]);
                     $idParam->setAttrib('class', $valueParam["class"]);
                     $idParam->setDecorators(array(array('ViewHelper'), array('description'), array('HtmlTag', array('tag' => 'li'))));
                 }
             }
             $elementsList[] = $idParam;
             $elementsNameList[] = $valueParam["name"];
         }
     }
     $this->clearDecorators();
     $this->addDecorator('FormElements')->addDecorator('HtmlTag', array('tag' => '<ul>'))->addDecorator('Form');
     $this->addElements($elementsList);
     $this->addDisplayGroup($elementsNameList, 'toolbar', array('legend' => ''));
     $toolbar = $this->getDisplayGroup('toolbar');
     $toolbar->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'ul', 'id' => 'toolbar'))));
 }
예제 #5
0
파일: Post.php 프로젝트: nuxwin/i-PMS
 /**
  * Form initialization
  *
  * @return void
  */
 public function init()
 {
     $this->setName('postForm')->setAction('/post/add')->setElementsBelongTo('postForm')->setMethod('post')->setEnctype('application/x-www-form-urlencoded');
     $element = new Zend_Form_Element_Text('title');
     $element->setLabel('Title')->setAttrib('class', 'inputTitle')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
     $this->addElement($element);
     $element = new Zend_Form_Element_Textarea('teaser');
     $element->setLabel('Teaser')->setAttrib('class', 'inputSummary')->setAttrib('rows', '5')->setRequired(true)->addFilter('StripTags', array('allowTags' => $this->_allowedXhtmlTags, 'allowAttribs' => $this->_allowedXhtmlAttributes))->addFilter('StringTrim');
     $this->addElement($element);
     $element = clone $element;
     $element = new Zend_Form_Element_Textarea('body');
     $element->setLabel('Content')->setAttrib('class', 'input-body')->setAttrib('rows', '25')->setRequired(true)->addFilter('StripTags', array('allowTags' => $this->_allowedXhtmlTags, 'allowAttribs' => $this->_allowedXhtmlAttributes))->addFilter('StringTrim');
     $this->addElement($element);
     $element = new Zend_Form_Element_Checkbox('allow_comments');
     $element->setLabel('Open for new comments ?')->setValue('1');
     $this->addElement($element);
     $element = new Zend_Form_Element_Hidden('pid');
     $element->getDecorator('Label')->setOption('tagClass', 'hidden');
     $element->getDecorator('HtmlTag')->setOption('class', 'hidden');
     $this->addElement($element);
     $element = new Zend_Form_Element_Hidden('categorie');
     $element->setValue('home');
     $element->getDecorator('Label')->setOption('tagClass', 'hidden');
     $element->getDecorator('HtmlTag')->setOption('class', 'hidden');
     $this->addElement($element);
     $element = new Zend_Form_Element_Submit('postSubmit');
     $element->setLabel('Submit');
     $this->addElement($element);
     $this->_setRequiredSuffix();
 }