Exemple #1
0
 public function __construct($module)
 {
     parent::__construct();
     $this->assign('__action', 'add');
     $tpl = Mreg::get('tpl');
     $tpl->concat('adminTitle', ' :: ' . $this->moduloptions['title'] . ' :: ' . __('Add record'));
     $mopts = PEAR::getStaticProperty('m_office', 'options');
     $mopt = $mopts['modules'][$module];
     $table = $mopt['table'];
     $do = M_Office_Util::doForModule($module);
     $this->append('subActions', '<a href="' . M_Office_Util::getQueryParams(array(), array('record', 'doSingleAction')) . '">' . __('Go to the %s list', array($mopt['title'])) . '</a>');
     $formBuilder =& MyFB::create($do);
     //	linkNewValue creates an issue if some linked elements are put in predefgroups
     //        $formBuilder->linkNewValue = true;
     $form = new MyQuickForm('editRecord', 'POST', M_Office_Util::getQueryParams(array(), array(), false), '_self', null, true);
     $form->addElement('hidden', 'submittedNewRecord', 1);
     if (isset($_REQUEST['filterField'])) {
         $form->addElement('hidden', 'filterField', $_REQUEST['filterField']);
         $form->addElement('hidden', 'filterValue', $_REQUEST['filterValue']);
         $do->{$_REQUEST['filterField']} = $_REQUEST['filterValue'];
     }
     $links = $do->links();
     if (key_exists($_REQUEST['filterField'], $links)) {
         $linfo = explode(':', $links[$_REQUEST['filterField']]);
         $form->addElement('static', 'mod', '', __('Add record with %s = %s', array($_REQUEST['filterField'], $_REQUEST['filterValue'])) . '. ' . '<a href="' . M_Office_Util::getQueryParams(array('table' => $linfo[0], 'record' => $_REQUEST['filterValue']), array('addRecord', 'filterField', 'filterValue')) . '">' . __('Back to main record') . '</a>');
     }
     $formBuilder->useForm($form);
     $formBuilder->getForm();
     if ($this->getOption('createAnother', $table)) {
         $form->addElement('static', '&nbsp;', '&nbsp;');
         $form->addElement('checkbox', 'returnHere', __('Create another record'));
         if (isset($_REQUEST['returnHere']) && $_REQUEST['returnHere']) {
             $form->setDefaults(array('returnHere' => true));
         }
     }
     M_Office_Util::addHiddenFields($form);
     if ($form->validate()) {
         if (PEAR::isError($ret = $form->process(array(&$formBuilder, 'processForm'), false))) {
             $this->append('error', __('An error occured while inserting record') . ' : ' . $ret->getMessage());
         } else {
             $pk = DB_DataObject_FormBuilder::_getPrimaryKey($do);
             $this->say(__('New record was successfully created. Its identifier is : %s', array($do->{$pk})));
             if ($this->getOption('createAnother', $table) && isset($_REQUEST['returnHere']) && $_REQUEST['returnHere']) {
                 M_Office_Util::refresh(M_Office_Util::getQueryParams(array('returnHere' => $_REQUEST['returnHere']), array(), false));
             } else {
                 $pk = DB_DataObject_FormBuilder::_getPrimaryKey($do);
                 M_Office_Util::refresh(M_Office_Util::getQueryParams(array('record' => $do->{$pk}), array('returnHere', 'addRecord'), false));
             }
         }
     } elseif ($form->isSubmitted()) {
     }
     $this->assign('addForm', $form);
     $this->assign('do', $do);
 }
Exemple #2
0
 public function doExecApplier()
 {
     $form = new MyQuickForm('applyform', 'POST', M_Office::URL());
     $opts = M::tablesWithPlugin('tag');
     $opts = array_combine($opts, $opts);
     $form->addElement('select', 'table', 'Table', $opts);
     $form->addElement('textarea', 'clause', 'clause', 'rows="4" cols="60"');
     $form->addElement('text', 'tagname', 'tagname');
     $form->addElement('text', 'tagdel', 'tagdel');
     $form->addElement('checkbox', 'distinct', 'distinct');
     $form->addElement('submit', '__submit__', 'Apply');
     $form->addFormRule(array($this, 'checkApplier'));
     if ($form->validate()) {
         @set_time_limit(0);
         ini_set('memory_limit', '1024M');
         $values = $form->exportValues();
         $t = DB_DataObject::factory($values['table']);
         $query = 'SELECT ' . ($values['distinct'] ? 'DISTINCT ' : ' ') . $values['table'] . '.* FROM ' . $values['table'] . ' ' . $values['clause'];
         $t->query($query);
         while ($t->fetch()) {
             if ($values['tagname']) {
                 $t->addTag($values['tagname']);
             }
             if ($values['tagdel']) {
                 $t->removeTag($values['tagdel']);
             }
             $applied++;
         }
         $this->assign('success', 1);
         $this->assign('applied', $applied);
     }
     $this->assign('form', $form);
 }
Exemple #3
0
 public static function &getSearchForm($do, $module)
 {
     MyQuickForm::registerElementType('advandate', 'HTML/QuickForm/advandate.php', 'HTML_QuickForm_advandate');
     $form = new MyQuickForm('formSearch', 'GET', self::getQueryParams(array(), array('page', '_c_'), false));
     $fields = $_GET;
     unset($fields['_c_']);
     unset($fields['page']);
     unset($fields['module']);
     unset($fields['action']);
     unset($fields['filterField']);
     unset($fields['filterValue']);
     if (count($fields) == 0) {
         Log::info('caching search form');
         $cache = true;
     } else {
         Log::info('NO SEARCH FORM CACHING');
         $cache = false;
     }
     $cacheName = 'searchform_' . $module;
     $options = array('caching' => $cache, 'cacheDir' => APP_ROOT . 'app/' . APP_NAME . '/cache/forms/', 'lifeTime' => 3600, 'fileNameProtection' => false);
     $cache = new Cache_Lite($options);
     if ($_cachedData = $cache->get($cacheName)) {
         Mreg::append('autoloadcallback', array(array('MyQuickForm', 'autoloadElements')));
         $_cachedData = unserialize($_cachedData);
         foreach ($_cachedData as $element) {
             $form->addElement($element);
         }
     } else {
         $do->fb_selectAddEmpty = array();
         if (is_array($do->links())) {
             foreach ($do->links() as $field => $link) {
                 $do->fb_selectAddEmpty[] = $field;
             }
         }
         if (is_array($do->fb_enumFields)) {
             foreach ($do->fb_enumFields as $field) {
                 $do->fb_selectAddEmpty[] = $field;
             }
         }
         $do->fb_formHeaderText = __('Search');
         $do->fb_submitText = '>>';
         $do->fb_linkNewValue = false;
         $formBuilder =& MyFB::create($do);
         $formBuilder->_cacheOptions = array('name' => 'office_searchform', 'cacheDir' => APP_ROOT . 'app/' . APP_NAME . '/cache/forms/');
         $formBuilder->preGenerateFormCallback = array($do, 'prepareSearchForm');
         $do->prepareSearchForm($fb);
         $do->fb_userEditableFields = $do->fb_fieldsToRender;
         $table = $do->table();
         foreach ($do->fb_fieldsToRender as $field) {
             if ($table[$field] & DB_DATAOBJECT_DATE || $table[$field] & DB_DATAOBJECT_TIME) {
                 $label = $do->fb_fieldLabels[$field] ? $do->fb_fieldLabels[$field] : $field;
                 $do->fb_preDefElements[$field] = MyQuickForm::createElement('advandate', $field, $label, array("language" => T::getLang()));
             }
         }
         $formBuilder->postGenerateFormCallback = array($do, 'postPrepareSearchForm');
         $formBuilder->useForm($form);
         $formBuilder->getForm();
         foreach ($form->_elements as $elem) {
             $cached[] = $elem;
         }
         if ($cache) {
             $cache->save(serialize($cached));
         }
     }
     $form->_rules = array();
     $form->_formRules = array();
     $form->_required = array();
     self::addHiddenFields($form, array('search', 'page', '__dontpaginate', '_c_'), true);
     $form->addElement('checkbox', '__dontpaginate', 'Afficher les résultats sur une seule page');
     return $form;
 }
Exemple #4
0
 /**
  * Creates the form for action parameters, if params are required for the current action
  * @return null if no param
  * @return HTML_QuickForm if params
  */
 public function createParamsForm()
 {
     $tpl = Mreg::get('tpl');
     $tpl->concat('adminTitle', ' :: ' . $this->getActionTitle());
     if ($this->actiondo instanceof M_Plugin) {
         $tpl->addPath('M/DB/DataObject/Plugin/' . $this->actiondo->getFolderName() . '/templates/', 'before');
     }
     $prepareMethod = 'prepare' . $this->actionName;
     if (method_exists($this->actiondo, $prepareMethod) || is_array($this->_actionInfo['chainable'])) {
         $qfAction = new MyQuickForm('actionparamsForm', 'POST', M_Office_Util::getQueryParams(array(), array('selected', 'doaction', 'glaction', 'doSingleAction'), false), '_self', null, true);
         Mreg::get('tpl')->addJSinline('$("input[type=text],textarea","form[name=actionparamsForm]").eq(0).focus()', 'ready');
         Mreg::get('tpl')->assign('do', $do);
         $qfAction->addElement('header', 'qfActionHeader', $this->getActionTitle());
         $qfAction->addElement('hidden', $this->typeval, $this->actionName);
         $qfAction->addElement('hidden', '__actionscope', $this->scope);
         if ($this->scope == 'selected') {
             M_Office_Util::addHiddenField($qfAction, 'selected', $this->getSelectedIds());
         }
         $selectedDo = $this->getSelected(true);
         if ('single' == $this->type) {
             $selectedDo->fetch();
         }
         if (method_exists($this->actiondo, $prepareMethod)) {
             if (is_a($this->actiondo, 'M_Plugin')) {
                 call_user_func(array($this->actiondo, $prepareMethod), $qfAction, $selectedDo);
             } else {
                 call_user_func(array($selectedDo, $prepareMethod), $qfAction);
             }
         }
         if ($this->_actionInfo['chainable'] && count($this->nextactions) == 0) {
             $qfAction->addElement('select', '__nextaction', __('Execute this action then ...'), array_merge(array('' => ''), $this->getNextActions()));
         }
         if (count($this->nextactions) > 0) {
             $qfAction->addElement('hidden', '__actionchain', implode(',', $this->nextactions));
         }
         $qfAction->addElement('submit', '__submit__', __('Execute'));
         return $qfAction;
     } else {
         return null;
     }
 }