Example #1
0
 public function testGetAuthGroup()
 {
     $this->User->setAuthGroup(1);
     if ($this->User->getAuthGroup() != 1) {
         $this->fail();
     }
 }
Example #2
0
 public function getUserAddEditForm($target = '/admin/User', $admin = false)
 {
     $form = new Form('user_addedit', 'POST', $target, '', array('class' => 'admin'));
     $form->setConstants(array('section' => 'addedit'));
     $form->addElement('hidden', 'section');
     if (@$_REQUEST['id']) {
         $user = new User($_REQUEST['id']);
         $form->setConstants(array('id' => $_REQUEST['id']));
         $form->addElement('hidden', 'id');
     } else {
         $user = new User();
     }
     $statuses = array(1 => 'Active', 0 => 'Disabled');
     $form->addElement('text', 'a_username', 'Username');
     $form->addElement('password', 'a_password', 'Password');
     $form->addElement('password', 'a_password_confirm', 'Confirm Password');
     $form->addElement('text', 'a_name', 'Full Name');
     $form->addElement('text', 'a_email', 'Email Address');
     if ($admin) {
         $form->addElement('select', 'a_status', 'Active Status', $statuses);
     }
     if (isset($this->user) && $this->user->hasPerm('assigngroups')) {
         $sql = 'SELECT agp_id, agp_name from auth_groups';
         $groups = Database::singleton()->query_fetch_all($sql);
         $assignableGroup = array();
         foreach ($groups as $group) {
             $assignableGroup[$group['agp_id']] = $group['agp_name'];
         }
         if (@$user) {
             $defaultValues['a_group'] = $user->getAuthGroup();
         }
         $form->addElement('select', 'a_group', 'Member Group', $assignableGroup);
     }
     $form->addElement('submit', 'a_submit', 'Save');
     $defaultValues['a_username'] = $user->getUsername();
     $defaultValues['a_name'] = $user->getName();
     $defaultValues['a_email'] = $user->getEmail();
     $defaultValues['a_password'] = null;
     $defaultValues['a_password_confirm'] = null;
     if ($admin) {
         $defaultValues['a_status'] = $user->getActiveStatus();
     }
     $form->setDefaults($defaultValues);
     $form->addRule('a_username', 'Please enter a username', 'required', null);
     $form->addRule('a_name', 'Please enter the user\'s name', 'required', null);
     $form->addRule('a_email', 'Please enter an email address', 'required', null);
     $form->addRule('a_email', 'Please enter a valid email address', 'email', null);
     if (!isset($_REQUEST['id'])) {
         $form->addRule('a_password', 'Please enter a password', 'required', null);
         $form->addRule('a_password_confirm', 'Please confirm the passwords match', 'required', null);
     }
     $form->addRule(array('a_password', 'a_password_confirm'), 'The passwords do not match', 'compare', null);
     if (isset($_REQUEST['a_submit']) && $form->validate()) {
         $this->template = 'admin/user.tpl';
         $this->doUserSubmit();
     }
     return $form;
 }