コード例 #1
0
 /**
  * [edit description]
  * @param  [type] $gid [description]
  * @return [type]      [description]
  */
 public function edit($gid)
 {
     $view['group'] = $group = $this->doctrine->em->getRepository('Entity\\Groups')->findOneBy(array('id' => $gid));
     //Validations
     $this->form_validation->set_rules('title', 'Group name', 'trim|required');
     $this->form_validation->set_rules('visibility', 'Group visibility', 'required');
     $this->form_validation->set_rules('type', 'Group type', 'required');
     if (!$this->form_validation->run()) {
         $data['content'] = $this->load->view('admin/edit_group', $view, TRUE);
     } else {
         $now = date_create(date('Y-m-d H:i:s'));
         //Update subscriptions, if the group visibility is being changed
         //@TODO - Take into account user profile settings.
         if ($group->getVisibility() == 'public' && $this->input->post('visibility') == 'private') {
             //From public to private
             $subscriptions = $this->doctrine->em->getRepository('Entity\\Subscription')->findBy(array('group' => $group));
             foreach ($subscriptions as $subscription) {
                 $this->doctrine->em->remove($subscription);
             }
             $this->session->set_flashdata('warning', 'Group subscription has been revoked');
         }
         if ($group->getVisibility() == 'private' && $this->input->post('visibility') == 'public') {
             //From private to public
             $users = $this->doctrine->em->getRepository('Entity\\Users')->findAll();
             foreach ($users as $user) {
                 $subscription = new Entity\Subscription();
                 $subscription->setGroup($group);
                 $subscription->setUser($user);
                 $subscription->setCreatedOn($now);
                 $this->doctrine->em->persist($subscription);
             }
             $this->session->set_flashdata('warning', 'Group subscription has been updated');
         }
         //Update Groups
         $group->setTitle($this->input->post('title'));
         $group->setDescription($this->input->post('description'));
         $status = $this->input->post('status') ? $this->input->post('status') : '0';
         $group->setStatus($status);
         $group->setType($this->input->post('type'));
         $group->setVisibility($this->input->post('visibility'));
         $group->setUpdatedOn($now);
         try {
             $this->doctrine->em->persist($group);
             $this->doctrine->em->flush();
             $this->session->set_flashdata('success', 'Group has been successfully updated.');
             redirect('admin/groups');
         } catch (Exception $err) {
             $this->session->set_flashdata('warning', 'Some error occured while saving the values, please try again later.');
             redirect('admin/groups');
         }
     }
     $data['title'] = 'Edit Terms';
     return $this->load->view('html', $data);
 }
コード例 #2
0
 /**
  * [add description]
  */
 public function add()
 {
     $this->is_logged_in();
     if (!$this->require_min_level(9)) {
         show_error("You are not authorized to access this page", '403');
     }
     $data['title'] = 'Add User';
     $em = $this->doctrine->em;
     $this->load->model('user_model');
     $view['department'] = $this->user_model->getMasterTerms(array('department'))['department'];
     //Validate
     $this->form_validation->set_rules('username', 'Username', 'required|callback__username_check');
     $this->form_validation->set_rules('email', 'Email', 'required|valid_email|callback__email_check');
     $this->form_validation->set_rules('password', 'Password', 'trim|required|external_callbacks[model,formval_callbacks,_check_password_strength,TRUE]');
     $this->form_validation->set_rules('confirm_pass', 'Password Confirmation', 'required|matches[password]');
     $this->form_validation->set_rules('department', 'Department', 'required');
     if (!$this->form_validation->run()) {
         $data['content'] = $this->load->view('admin/add_user', $view, TRUE);
     } else {
         //Save user
         $user = new Entity\Users();
         $user->setUserName($this->input->post('username'));
         $user->setUserEmail($this->input->post('email'));
         $user->setUserLevel($this->input->post('role'));
         $salt = $this->authentication->random_salt();
         $pass = $this->authentication->hash_passwd($this->input->post('password'), $salt);
         $now = date_create(date('Y-m-d H:i:s'));
         $user->setUserPass($pass);
         $user->setUserSalt($salt);
         $user->setUserDate($now);
         $user->setUserModified($now);
         $user->setUserBanned(0);
         try {
             //save to database
             $em->persist($user);
             //Add user department
             $profile = new Entity\Profiles();
             $department = $em->getReference('Entity\\Terms', $this->input->post('department'));
             $profile->setUser($user);
             $profile->setDepartment($department);
             $profile->setCreatedOn($now);
             $em->persist($profile);
             //Subscribe user to the public groups
             $groups = $em->getRepository('Entity\\Groups')->findBy(array('type' => 'organic', 'visibility' => 'public'));
             foreach ($groups as $group) {
                 $subscription = new Entity\Subscription();
                 $subscription->setGroup($group);
                 $subscription->setUser($user);
                 $subscription->setCreatedOn($now);
                 $em->persist($subscription);
             }
             $em->flush();
             if ($this->input->post('notify')) {
                 //Notify user of account creation
                 $this->email->from('*****@*****.**', 'No Reply');
                 $this->email->subject('[' . $this->config->item('site_name') . '] - Account created');
                 $this->email->to($this->input->post('email'));
                 $data['name'] = $this->input->post('username');
                 $data['header'] = 'User account created on portal';
                 //Send mail to the assigned users
                 $data['text'] = sprintf('A user account has been created for you on the portal. You can now login using the login credentials created for you. It is advisable to update your password on your first login, you can find the password update page in your profile page.<br/><br/><b>Username:</b>%s<br/><b>Password:</b> %s', $this->input->post('username'), $this->input->post('password'));
                 $data['cta_url'] = base_url();
                 $data['call_to_action'] = "Login Now";
                 $message = $this->load->view('emails/mail', $data, TRUE);
                 $this->email->message($message);
                 $this->email->send();
                 $this->email->clear();
             }
             $this->session->set_flashdata('success', 'User account has been successfully created.');
             redirect('admin/users');
         } catch (Exception $err) {
             die($err->getMessage());
         }
     }
     return $this->load->view('html', $data);
 }