| 19 | | foreach(self::$fields[$this->table] as $field => $meta) |
|---|
| | 19 | $this->form->input('username')->label(TRUE)->rules('required|length[5,32]')->value($this->object->username); |
|---|
| | 20 | $this->form->input('email')->label(TRUE)->rules('required|length[5,127]|valid_email')->value($this->object->email); |
|---|
| | 21 | $this->form->password('password')->label(TRUE)->rules('length[5,64]'); |
|---|
| | 22 | $this->form->password('confirm')->label(TRUE)->matches($this->form->password); |
|---|
| | 23 | |
|---|
| | 24 | // Make sure that the username does not already exist |
|---|
| | 25 | $this->form->username->callback(array($this, 'is_existing_user')); |
|---|
| | 26 | |
|---|
| | 27 | if ($this->object->id == 0) |
|---|
| 21 | | // User id and login data is not editable |
|---|
| 22 | | if (substr($field, -2) == 'id' or $field == 'logins') |
|---|
| 23 | | continue; |
|---|
| 24 | | |
|---|
| 25 | | if ($field == 'password') |
|---|
| 26 | | { |
|---|
| 27 | | // Add password and confirm password fields |
|---|
| 28 | | $this->form->password($field)->label(TRUE)->rules('length[5,32]'); |
|---|
| 29 | | $this->form->password('confirm')->label(TRUE)->matches($this->form->password); |
|---|
| 30 | | |
|---|
| 31 | | if ($this->object->id == 0) |
|---|
| 32 | | { |
|---|
| 33 | | // Password fields are required for new users |
|---|
| 34 | | $this->form->password->rules('+required'); |
|---|
| 35 | | } |
|---|
| 36 | | } |
|---|
| 37 | | else |
|---|
| 38 | | { |
|---|
| 39 | | // All fields are required by default |
|---|
| 40 | | $rules = 'required'; |
|---|
| 41 | | |
|---|
| 42 | | if (isset($meta['length'])) |
|---|
| 43 | | { |
|---|
| 44 | | $rules .= '|length['.(empty($meta['exact']) ? '1,' : '').$meta['length'].']'; |
|---|
| 45 | | } |
|---|
| 46 | | |
|---|
| 47 | | if ($field == 'email') |
|---|
| 48 | | { |
|---|
| 49 | | $rules .= '|valid_email'; |
|---|
| 50 | | } |
|---|
| 51 | | |
|---|
| 52 | | // Add an input for this field with the value of the field |
|---|
| 53 | | $this->form->input($field)->label(TRUE)->rules($rules)->value($this->object->$field); |
|---|
| 54 | | } |
|---|
| | 29 | // Password fields are required for new users |
|---|
| | 30 | $this->form->password->rules('+required'); |
|---|
| 57 | | // Find all roles |
|---|
| 58 | | $roles = new Role_Model(); |
|---|
| 59 | | $roles = $roles->find(ALL); |
|---|
| 60 | | |
|---|
| 61 | | $options = array(); |
|---|
| 62 | | foreach($roles as $role) |
|---|
| 63 | | { |
|---|
| 64 | | // Add each role to the options |
|---|
| 65 | | $options[$role->name] = isset($this->roles[$role->id]); |
|---|
| 66 | | } |
|---|
| 67 | | |
|---|
| 68 | | // Create a checklist of roles |
|---|
| 69 | | $this->form->checklist('roles')->options($options)->label(TRUE); |
|---|
| | 33 | // // Find all roles |
|---|
| | 34 | // $roles = new Role_Model(); |
|---|
| | 35 | // $roles = $roles->find(ALL); |
|---|
| | 36 | // |
|---|
| | 37 | // $options = array(); |
|---|
| | 38 | // foreach($roles as $role) |
|---|
| | 39 | // { |
|---|
| | 40 | // // Add each role to the options |
|---|
| | 41 | // $options[$role->name] = isset($this->roles[$role->id]); |
|---|
| | 42 | // } |
|---|
| | 43 | // |
|---|
| | 44 | // // Create a checklist of roles |
|---|
| | 45 | // $this->form->checklist('roles')->options($options)->label(TRUE); |
|---|
| 99 | | if ($new_user) |
|---|
| 100 | | { |
|---|
| 101 | | foreach($roles as $role) |
|---|
| 102 | | { |
|---|
| 103 | | // Add the user roles |
|---|
| 104 | | $this->add_role($role); |
|---|
| 105 | | } |
|---|
| 106 | | } |
|---|
| 107 | | else |
|---|
| 108 | | { |
|---|
| 109 | | foreach(array_diff($this->roles, $roles) as $role) |
|---|
| 110 | | { |
|---|
| 111 | | // Remove roles that were deactivated |
|---|
| 112 | | $this->remove_role($role); |
|---|
| 113 | | } |
|---|
| 114 | | |
|---|
| 115 | | foreach(array_diff($roles, $this->roles) as $role) |
|---|
| 116 | | { |
|---|
| 117 | | // Add new roles |
|---|
| 118 | | $this->add_role($role); |
|---|
| 119 | | } |
|---|
| 120 | | } |
|---|
| | 89 | // if ($new_user) |
|---|
| | 90 | // { |
|---|
| | 91 | // foreach($roles as $role) |
|---|
| | 92 | // { |
|---|
| | 93 | // // Add the user roles |
|---|
| | 94 | // $this->add_role($role); |
|---|
| | 95 | // } |
|---|
| | 96 | // } |
|---|
| | 97 | // else |
|---|
| | 98 | // { |
|---|
| | 99 | // foreach(array_diff($this->roles, $roles) as $role) |
|---|
| | 100 | // { |
|---|
| | 101 | // // Remove roles that were deactivated |
|---|
| | 102 | // $this->remove_role($role); |
|---|
| | 103 | // } |
|---|
| | 104 | // |
|---|
| | 105 | // foreach(array_diff($roles, $this->roles) as $role) |
|---|
| | 106 | // { |
|---|
| | 107 | // // Add new roles |
|---|
| | 108 | // $this->add_role($role); |
|---|
| | 109 | // } |
|---|
| | 110 | // } |
|---|