예제 #1
0
 /**
  * Delete Group form (use Ajax)
  *
  * @param   integer $id Group ID
  * @return  void
  */
 public function delete($id)
 {
     // load dictionaries
     $this->dict->get_wordarray(array('form', 'groups'));
     // build the form
     $fields = array();
     $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id, 'name' => 'id');
     // if submitted
     if (X4Route_core::$post) {
         $this->deleting($_POST);
         die;
     }
     // get object
     $group = new Group_model();
     $obj = $group->get_by_id($id, 'groups', 'name');
     // contents
     $view = new X4View_core('delete');
     $view->title = _DELETE_GROUP;
     $view->item = $obj->name;
     // form builder
     $view->form = X4Form_helper::doform('delete', $_SERVER["REQUEST_URI"], $fields, array(null, _YES, 'buttons'), 'post', '', 'onclick="setForm(\'delete\');"');
     $view->render(TRUE);
 }
예제 #2
0
 /**
  * New / Edit user form (use Ajax)
  *
  * @param   integer  $id User ID (if 0 then is a new item)
  * @param   integer  $id_group Group ID (if 0 then is a new item)
  * @return  void
  */
 public function edit($id, $id_group = 0)
 {
     // load dictionaries
     $this->dict->get_wordarray(array('form', 'login', 'users'));
     $lang = X4Route_core::$lang;
     // get object
     $user = new User_model();
     $u = $id ? $user->get_by_id($id) : new User_obj($id_group, $lang);
     // get group
     $group = new Group_model();
     $g = $group->get_by_id($u->id_group, 'groups', 'id_area, name');
     // build the form
     $fields = array();
     $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $u->id_group, 'name' => 'id_group');
     $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $g->id_area, 'name' => 'id_area');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4>' . _GROUP . ': ' . $g->name . '</h4>');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     // languages
     $lmod = new Language_model();
     $fields[] = array('label' => ucfirst(_LANGUAGE), 'type' => 'select', 'value' => $u->lang, 'options' => array($lmod->get_languages(), 'code', 'language'), 'name' => 'lang', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _USERNAME, 'type' => 'text', 'value' => $u->username, 'name' => 'username', 'suggestion' => _USERNAME_RULE, 'rule' => 'required|minlength§6|alphanumeric', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
     // password
     if ($id) {
         $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4 class="acenter zerom">' . _PASSWORD_CHANGE_MSG . '</h4>');
         $rule = '';
     } else {
         // for a new user you must insert a password
         $rule = 'required|';
     }
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _PASSWORD, 'type' => 'password', 'value' => '', 'name' => 'password', 'suggestion' => _PASSWORD_RULE, 'rule' => $rule . 'minlength§6|alphanumeric', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _REPEAT_PASSWORD, 'type' => 'password', 'value' => '', 'name' => 'password2', 'rule' => $rule . 'equal-password', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
     $fields[] = array('label' => _DESCRIPTION, 'type' => 'textarea', 'value' => $u->description, 'name' => 'description', 'sanitize' => 'string', 'rule' => 'required');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _EMAIL, 'type' => 'text', 'value' => $u->mail, 'name' => 'mail', 'rule' => 'required|mail', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _PHONE, 'type' => 'text', 'value' => $u->phone, 'name' => 'phone', 'rule' => 'phone', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div><div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _LEVEL, 'type' => 'select', 'value' => $u->level, 'options' => array($user->get_levels(), 'id', 'name'), 'name' => 'level', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     // permissions on areas
     $perm = new Permission_model();
     $area = new Area_model();
     $fields[] = array('label' => _DOMAIN, 'type' => 'select', 'value' => X4Utils_helper::obj2array($perm->get_aprivs($id), null, 'id_area'), 'options' => array($area->get_areas($g->id_area, false), 'id', 'name'), 'multiple' => 4, 'name' => 'domain', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
     // if submitted
     if (X4Route_core::$post) {
         $e = X4Validation_helper::form($fields, 'editor');
         if ($e) {
             $this->editing($id, $_POST);
         } else {
             $this->notice($fields);
         }
         die;
     }
     // contents
     $view = new X4View_core('editor');
     $view->title = $id ? _EDIT_USER : _ADD_USER;
     // form builder
     $view->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"');
     $view->render(TRUE);
 }