Пример #1
0
 public function index()
 {
     $myID = getUserID();
     $myEmail = getUserEmail();
     $pID = (int) $this->input->get('id');
     $visitorType = visitor_type($pID, $myID);
     $query = $this->mdb->project_get($pID);
     if ($query->num_rows()) {
         $row = $query->row();
         switch ($visitorType) {
             case 'member':
                 $this->mdb->project_member_remove($row->id, $myID);
                 projectLogs_add('member_leave', $pID);
                 break;
         }
         generate_json(array('status' => 1));
     } else {
         generate_json(array('status' => 0, 'message' => 'Project does not exists.'));
     }
 }
Пример #2
0
 public function index()
 {
     $myID = getUserID();
     $myEmail = getUserEmail();
     $pID = (int) $this->input->get('id');
     $visitorType = visitor_type($pID, $myID);
     $query = $this->mdb->project_get($pID);
     if ($query->num_rows()) {
         $row = $query->row();
         switch ($visitorType) {
             case 'guest':
                 $is_accepted = 1;
                 $projSett = $this->mdb->projSettings_get($row->id);
                 if ($projSett->num_rows()) {
                     $projSettRow = $projSett->row();
                     $is_accepted = (int) $projSettRow->project_approval ? 0 : 1;
                 }
                 $this->mdb->project_member_add(array('project_id' => $row->id, 'user_id' => $myID, 'email_address' => $myEmail, 'joined_by' => 0, 'date_joined' => today(), 'last_visit' => NULL, 'is_accepted' => $is_accepted, 'project_role' => $this->siteinfo->config('project_roles_default')));
                 generate_json(array('status' => 1));
                 break;
             case 'invited':
                 $this->mdb->project_member_update(array('project_id' => $row->id, 'user_id' => $myID), array('is_accepted' => 1));
                 projectLogs_add('member_new', $pID, array('user_id' => $myID, 'user_name' => $this->session->userdata('display_name')));
                 generate_json(array('status' => 1));
                 break;
             case 'member':
                 generate_json(array('status' => 0, 'message' => 'You are already a member of this project.'));
                 break;
             case 'requesting':
                 generate_json(array('status' => 1));
                 break;
             default:
                 generate_json(array('status' => 1, 'message' => 'Unknown Error.'));
         }
     } else {
         generate_json(array('status' => 0, 'message' => 'Project does not exists.'));
     }
 }
Пример #3
0
 public function kick_member()
 {
     requirelogin();
     updateLastActive();
     $myID = getUserID();
     $id = (int) $this->input->get('id');
     $mID = (int) $this->input->get('userid');
     $query = $this->mdb->project_get($id);
     if ($query->num_rows()) {
         $row = $query->row();
         $isModerator = validate_access('is_moderator', array('project_id' => $row->id, 'user_id' => $mID));
         if ($isModerator || $row->creator_id == $myID) {
             $this->mdb->project_member_remove($id, $mID);
             $sql = $this->model->getUserInfo(array('id' => $mID));
             $data = $sql->row();
             projectLogs_add('member_remove', $id, array('user_id' => $mID, 'user_name' => $data->display_name));
             generate_json(array('status' => 1));
         } else {
             generate_json(array('status' => 0, 'message' => 'You are not allowed to do this.'));
         }
     } else {
         generate_json(array('status' => 0, 'message' => 'Project does not exists.'));
     }
 }
Пример #4
0
 public function create($id = 0)
 {
     requirelogin();
     updateLastActive();
     $id = (int) $id;
     $myID = getUserID();
     if (!validate_access('valid_member', array('project_id' => $id, 'user_id' => $myID))) {
         generate_json(array('status' => 0, 'message' => 'You dont have enough permission to do this.'));
     } else {
         $name = trim(jsonInput('name'));
         $description = jsonInput('description');
         $parentTask = (int) jsonInput('parent_task');
         $priority = (int) jsonInput('priority');
         $dateStart = strtotime(jsonInput('date_start'));
         $dateEnd = strtotime(jsonInput('date_end'));
         $members = jsonInput('members');
         //Form validations
         if (empty($name)) {
             generate_json(array('status' => 0, 'message' => 'Task name is empty.'));
             exit;
         }
         //Check parent task
         if ($parentTask > 0) {
             $query = $this->mdb->task_get($parentTask);
             if ($query->num_rows()) {
                 $row = $query->row();
                 if ($row->project_id != $id) {
                     generate_json(array('status' => 0, 'message' => 'It seems that parent task belongs to another project.'));
                     exit;
                 }
             } else {
                 generate_json(array('status' => 0, 'message' => 'Parent task does not exists.'));
                 exit;
             }
         }
         //Priority check
         $priorities = $this->config->item('priorities');
         if ($priority < 0 || $priority >= count($priorities)) {
             generate_json(array('status' => 0, 'message' => 'Priority error! please refresh the page.'));
             exit;
         }
         //Date validation
         if ($dateStart && $dateEnd) {
             if ($dateStart > $dateEnd) {
                 generate_json(array('status' => 0, 'message' => 'Dates mismatch!'));
                 exit;
             }
         }
         $dateStart = $dateStart ? date("Y-m-d H:i:s", $dateStart) : NULL;
         $dateEnd = $dateEnd ? date("Y-m-d H:i:s", $dateEnd) : NULL;
         //Check members
         if (is_array($members) && count($members)) {
             foreach ($members as $member) {
                 $qChkUser = $this->model->getUserInfo(array('email_address' => $member));
                 if ($qChkUser->num_rows()) {
                     $row = $qChkUser->row();
                     if (!validate_access('valid_member', array('project_id' => $id, 'user_id' => $row->id))) {
                         generate_json(array('status' => 0, 'message' => $member . ' is not a member of this project.'));
                         exit;
                     }
                 } else {
                     generate_json(array('status' => 0, 'message' => $member . ' does not exists.'));
                     exit;
                 }
             }
         }
         $is_accepted = 1;
         $projSett = $this->mdb->projSettings_get($id);
         if ($projSett->num_rows()) {
             $projSettRow = $projSett->row();
             $is_accepted = (int) $projSettRow->task_approval ? 0 : 1;
         }
         //finally create the task
         $result = $this->mdb->task_add(array('project_id' => $id, 'creator_id' => $myID, 'title' => $name, 'description' => $description, 'date_created' => today(), 'date_start' => $dateStart, 'date_end' => $dateEnd, 'date_completed' => null, 'status' => 0, 'parent_task' => $parentTask, 'is_accepted' => $is_accepted, 'priority' => $priority));
         //add members to task
         if (is_array($members) && count($members) && $result > 0) {
             foreach ($members as $member) {
                 $qChkUser = $this->model->getUserInfo(array('email_address' => $member));
                 if ($qChkUser->num_rows()) {
                     $row = $qChkUser->row();
                     $checkIfAlreadyAdded = $this->mdb->taskMembers_get(array('task_id' => $result, 'user_id' => $row->id));
                     if ($checkIfAlreadyAdded->num_rows() == 0) {
                         $this->mdb->taskMembers_add(array('task_id' => $result, 'user_id' => $row->id, 'assigned_by' => $myID, 'is_accepted' => $row->id == $myID ? 1 : 0, 'date_joined' => today()));
                         //notification
                         notify('task_invite', $row->id, array('project_id' => $id, 'task_id' => $result));
                         $qProj = $this->db->get_where('projects', array('id' => $id));
                         if ($qProj->num_rows()) {
                             $qProjRow = $qProj->row();
                             $myName = $this->session->userdata('display_name');
                             $redirectLink = base_url('#/app/projects/' . $id . '/task/' . $result);
                             do_sendmail($row->id, $qProjRow->project_name, "{$myName} assigned a task for you in <a href='{$redirectLink}'>" . $qProjRow->project_name . "</a>");
                         }
                     }
                 }
             }
         }
         projectLogs_add('task_add', $id, array('task_id' => $result, 'task_name' => $name));
         generate_json(array('status' => 1));
     }
 }
Пример #5
0
 public function accept($pid = 0)
 {
     $myID = getUserID();
     $user = (int) $this->input->get('id');
     if (!validate_access('valid_member', array('project_id' => $pid, 'user_id' => $myID))) {
         generate_json(array('status' => 0, 'message' => 'You dont have enough permission to do this.'));
     } else {
         $this->mmdb->update_member(array('project_id' => $pid, 'user_id' => $user), array('is_accepted' => 1));
         $query = $this->model->getUserInfo(array('id' => $user));
         $row = $query->row();
         projectLogs_add('member_new', $pid, array('user_id' => $user, 'user_name' => $row->display_name));
         generate_json(array('status' => 1));
     }
 }
Пример #6
0
 public function uncomplete($id = 0)
 {
     requirelogin();
     updateLastActive();
     $myID = getUserID();
     $query = $this->mdb->task_get($id);
     if ($query->num_rows()) {
         $row = $query->row();
         $isModerator = validate_access('is_moderator', array('project_id' => $row->project_id, 'user_id' => $myID));
         $qMember = $this->mdb->taskMembers_get(array('task_id' => $row->id, 'user_id' => $myID, 'is_accepted' => 1));
         if ($isModerator || $qMember->num_rows() || $myID == $row->creator_id) {
             $this->mdb->task_update(array('id' => $row->id), array('status' => 0, 'date_completed' => null));
             projectLogs_add('task_uncomplete', $row->project_id, array('task_name' => $row->title, 'task_id' => $row->id));
             generate_json(array('status' => 1));
         } else {
             generate_json(array('status' => 0, 'message' => 'You are not allowed to do this.'));
         }
     } else {
         generate_json(array('status' => 0, 'message' => 'Task does not exists.'));
     }
 }