示例#1
0
 /**
  * Build the form and show the template
  *
  * @param array $dirty reference to unverified $_POST
  */
 function formBuild(&$dirty)
 {
     // --------------------------------------------------------------------
     // Get existing user info if available
     // --------------------------------------------------------------------
     // $u = array();
     // Get stuff from the database
     // $this->tpl->assign($u);
     // --------------------------------------------------------------------
     // Form logic
     // --------------------------------------------------------------------
     if (!empty($dirty)) {
         $this->tpl->assign($dirty);
     } else {
         suxValidate::disconnect(true);
     }
     if (empty($dirty['action']) || !suxValidate::is_registered_form($dirty['action'])) {
         suxValidate::connect($this->tpl, true);
         // Reset connection
         // Register additional forms
         suxValidate::register_form('addvec');
         suxValidate::register_form('addcat');
         suxValidate::register_form('adddoc');
         suxValidate::register_form('remcat');
         suxValidate::register_form('remvec');
         suxValidate::register_form('remdoc');
         suxValidate::register_form('sharevec');
         suxValidate::register_form('unsharevec');
         // Register our additional criterias
         suxValidate::register_criteria('invalidShare', 'this->invalidShare', 'sharevec');
         suxValidate::register_criteria('userExists', 'this->userExists', 'sharevec');
         // Register our validators
         // register_validator($id, $field, $criteria, $empty = false, $halt = false, $transform = null, $form = 'default')
         // Add vector
         suxValidate::register_validator('addvec1', 'vector', 'notEmpty', false, false, 'trim', 'addvec');
         suxValidate::register_validator('addvec2', "vector:-1:{$this->nb->getMaxVectorLength()}", 'isLength', false, false, 'trim', 'addvec');
         // Add category
         suxValidate::register_validator('addcat1', 'category', 'notEmpty', false, true, 'trim', 'addcat');
         suxValidate::register_validator('addcat2', 'vector_id', 'isInt', false, true, 'trim', 'addcat');
         suxValidate::register_validator('addcat3', "category:-1:{$this->nb->getMaxCategoryLength()}", 'isLength', false, false, 'trim', 'addcat');
         // Remove category
         suxValidate::register_validator('remcat1', 'category_id', 'isInt', false, false, 'trim', 'remcat');
         // Remove vector
         suxValidate::register_validator('remvec1', 'vector_id', 'isInt', false, false, 'trim', 'remvec');
         // Add document
         suxValidate::register_validator('adddoc1', 'document', 'notEmpty', false, true, 'trim', 'adddoc');
         suxValidate::register_validator('adddoc2', 'category_id', 'isInt', false, false, 'trim', 'adddoc');
         // Remove document
         suxValidate::register_validator('remdoc1', 'document_id', 'isInt', false, false, 'trim', 'remdoc');
         // Share vector
         suxValidate::register_validator('sharevec1', 'vector_id', 'isInt', false, false, 'trim', 'sharevec');
         suxValidate::register_validator('sharevec2', 'users_id', 'isInt', false, false, 'trim', 'sharevec');
         suxValidate::register_validator('sharevec3', 'trainer:1:1', 'isRange', true, false, 'trim', 'sharevec');
         suxValidate::register_validator('sharevec4', 'owner:1:1', 'isRange', true, false, 'trim', 'sharevec');
         suxValidate::register_validator('sharevec5', 'users_id', 'invalidShare', true, false, 'trim', 'sharevec');
         suxValidate::register_validator('sharevec6', 'users_id', 'userExists', true, false, 'trim', 'sharevec');
         // Unshare vector
         suxValidate::register_validator('unsharevec1', 'unshare', 'dummyValid', false, false, null, 'unsharevec');
     }
     // Additional variables
     $this->r->text['form_url'] = suxFunct::makeUrl('/bayes');
     $this->r->title .= " | {$this->r->gtext['edit_bayes']}";
     // Template
     $this->tpl->display('edit.tpl');
 }