public function index() { $myID = getUserID(); $id = (int) $this->input->get('id'); if ($id == $myID) { generate_json(array('status' => 0, 'message' => 'You cannot add yourself.')); } else { $query = $this->mdb->get_contact($myID, $id); if ($query->num_rows()) { generate_json(array('status' => 0, 'message' => 'You are already in contact with this user.')); } else { $query = $this->model->getUserInfo(array('id' => $id)); if ($query->num_rows()) { $this->mdb->add_contact($myID, $id); notify('contact_added', $id); // Send mail $myName = $this->session->userdata('display_name'); $redirectLink = base_url('#/app/profile/' . $myID); do_sendmail($id, "New Contact", "{$myName} added you to his/her address book. Visit <a href='{$redirectLink}'>" . $myName . "</a>"); generate_json(array('status' => 1)); } else { generate_json(array('status' => 0, 'message' => 'User not found.')); } } } }
public function do_fpw() { $new_token = random_string('unique'); $email = $this->input->post('email'); $chckEmail = $this->db->get_where('users', array('email_address' => $email)); if ($chckEmail->num_rows()) { $qRow = $chckEmail->row(); $this->db->query("update users set token = ? where id = ?", array($new_token, $qRow->id)); $redirectLink = base_url() . "fpw/verify?token={$new_token}"; do_sendmail($qRow->id, "Somebody requested a new password for your Teamstorm account", "Somebody recently asked to reset your Teamstorm password. <br/> \n\t\t\t\tPlease visit this link: {$redirectLink} to change your password. <br/><br/>\n\t\t\t\tPlease ignore this message if you dont want to reset your password."); redirect("fpw?reason=ok"); } else { redirect("fpw?reason=fail"); } }
public function index() { $myID = getUserID(); $name = trim(jsonInput('name')); $description = jsonInput('description'); $membersPost = jsonInput('members'); $this->np_validations(); $newProjID = $this->mdb->project_add($myID, $name, $description); if ($newProjID) { //add yourself in project members $this->mdb->project_member_add(array('project_id' => $newProjID, 'user_id' => $myID, 'email_address' => getUserEmail(), 'joined_by' => 0, 'date_joined' => today(), 'last_visit' => today(), 'is_accepted' => 1, 'project_role' => 3)); $this->mdb->add_project_settings(array('project_id' => $newProjID, 'task_approval' => 0, 'project_approval' => 1)); //add specified members to project if (is_array($membersPost)) { foreach ($membersPost as $member) { if (filter_var($member, FILTER_VALIDATE_EMAIL)) { $qChkifAlreadyMember = $this->mdb->checkIfAlreadyMember($newProjID, $member); if (!$qChkifAlreadyMember) { $qChkUser = $this->model->getUserInfo(array('email_address' => $member)); if ($qChkUser->num_rows()) { $pmRow = $qChkUser->row(); $this->mdb->project_member_add(array('project_id' => $newProjID, 'user_id' => $pmRow->id, 'email_address' => $pmRow->email_address, 'joined_by' => $myID, 'date_joined' => today(), 'last_visit' => NULL, 'is_accepted' => 0, 'project_role' => $this->siteinfo->config('project_roles_default'))); //notification notify('project_invite', $pmRow->id, array('project_id' => $newProjID)); $qProj = $this->db->get_where('projects', array('id' => $newProjID)); if ($qProj->num_rows()) { $qProjRow = $qProj->row(); $myName = $this->session->userdata('display_name'); $redirectLink = base_url('#/app/projects/' . $newProjID); do_sendmail($pmRow->id, $qProjRow->project_name, "{$myName} invited you to join <a href='{$redirectLink}'>" . $qProjRow->project_name . "</a>"); } } else { $this->mdb->project_member_add(array('project_id' => $newProjID, 'user_id' => 0, 'email_address' => $member, 'joined_by' => $myID, 'date_joined' => today(), 'last_visit' => NULL, 'is_accepted' => 0, 'project_role' => $this->siteinfo->config('project_roles_default'))); } } } } } //add project roles foreach ($this->siteinfo->config('project_roles') as $roleID => $role) { $default = $this->siteinfo->config('project_roles_default') == $roleID ? 1 : 0; $this->mdb->project_roles_add($newProjID, $roleID, $default, $role); } } generate_json(array('status' => 1, 'message' => 'New project has been created.')); }
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)); } }
public function add($pid = 0) { $myID = getUserID(); $members = jsonInput('members'); 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 { if (is_array($members) && count($members) > 0) { $errMsg = array(); $message = ''; foreach ($members as $member) { $query = $this->mmdb->get_member($pid, $member); if ($query->num_rows()) { $row = $query->row(); if ($row->is_accepted == 1) { $errMsg[] = "{$member} is already a member."; } else { if ($row->joined_by > 0) { $errMsg[] = "{$member} is already invited."; } else { $this->mmdb->update_member(array('project_id' => $pid, 'email_address' => $member), array('is_accepted' => 1)); } } } else { $qChkUser = $this->model->getUserInfo(array('email_address' => $member)); if ($qChkUser->num_rows()) { $pmRow = $qChkUser->row(); $this->mmdb->project_member_add(array('project_id' => $pid, 'user_id' => $pmRow->id, 'email_address' => $pmRow->email_address, 'joined_by' => $myID, 'date_joined' => today(), 'last_visit' => NULL, 'is_accepted' => 0, 'project_role' => $this->siteinfo->config('project_roles_default'))); //Notify notify('project_invite', $pmRow->id, array('project_id' => $pid)); $qProj = $this->db->get_where('projects', array('id' => $pid)); if ($qProj->num_rows()) { $qProjRow = $qProj->row(); $myName = $this->session->userdata('display_name'); $redirectLink = base_url('#/app/projects/' . $pid); do_sendmail($pmRow->id, $qProjRow->project_name, "{$myName} invited you to join <a href='{$redirectLink}'>" . $qProjRow->project_name . "</a>"); } } else { $this->mmdb->project_member_add(array('project_id' => $pid, 'user_id' => 0, 'email_address' => $member, 'joined_by' => $myID, 'date_joined' => today(), 'last_visit' => NULL, 'is_accepted' => 0, 'project_role' => $this->siteinfo->config('project_roles_default'))); } } } if (count($errMsg)) { $message = $errMsg[0]; } else { $message = 'Member(s) were successfully invited to this project. It will notify once they accepted it.'; } generate_json(array('status' => count($errMsg) ? 0 : 1, 'message' => $message)); } else { generate_json(array('status' => 0, 'message' => 'Please type a member username / email.')); } } }
public function index() { $myID = getUserID(); $post_id = (int) jsonInput('post_id'); $comment_id = (int) jsonInput('comment_id'); $message = trim(jsonInput('message')); $length = (int) jsonInput('items'); if (empty($message)) { generate_json(array('status' => 0, 'message' => 'Please type a comment.')); } else { $query = $this->mdb->getPostDetails($post_id); if ($query->num_rows() == 0) { generate_json(array('status' => 0, 'message' => 'Post does not exists.')); } else { $row = $query->row(); $validate = validate_access('valid_member', array('project_id' => $row->project_id, 'user_id' => $myID)); if (!$validate) { generate_json(array('status' => 0, 'message' => 'You are not authorized to do this.')); } else { $this->mdb->comment_add(array('post_id' => $post_id, 'comment_id' => $comment_id, 'user_id' => $myID, 'comment' => $message, 'date_posted' => today(), 'params' => '')); if ($comment_id > 0) { //notify commentor $qchkComment = $this->mdb->get_comment_projID($comment_id); if ($qchkComment->num_rows()) { $chkCommentRow = $qchkComment->row(); notify('reply_comment', $chkCommentRow->poster_id, array('post_id' => $row->id, 'poster_id' => $row->poster_id, 'project_id' => $row->project_id, 'task_id' => $row->task_id, 'comment_id' => $comment_id)); } } else { //notify poster if ($row->task_id > 0) { notify('post_comment_task', $row->poster_id, array('post_id' => $row->id, 'project_id' => $row->project_id, 'task_id' => $row->task_id)); $qProj = $this->db->get_where('projects', array('id' => $row->project_id)); if ($qProj->num_rows()) { $qProjRow = $qProj->row(); $myName = $this->session->userdata('display_name'); $taskName = $this->db->get_where('tasks', array('id' => $row->task_id)); $qTaskRow = $taskName->row(); $redirectLink = base_url('#/app/projects/' . $row->project_id . '/task/' . $row->task_id . '/feed/' . $row->id); do_sendmail($row->poster_id, $qProjRow->project_name, "{$myName} commented on your update in task <b><a href='{$redirectLink}'>" . $qTaskRow->title . "</a></b>"); } } else { notify('post_comment', $row->poster_id, array('post_id' => $row->id, 'project_id' => $row->project_id, 'task_id' => $row->task_id)); $qProj = $this->db->get_where('projects', array('id' => $row->project_id)); if ($qProj->num_rows()) { $qProjRow = $qProj->row(); $myName = $this->session->userdata('display_name'); $redirectLink = base_url('#/app/projects/' . $row->project_id . '/feed/' . $row->id); do_sendmail($row->poster_id, $qProjRow->project_name, "{$myName} commented on your post in <a href='{$redirectLink}'>" . $qProjRow->project_name . "</a>"); } } } $length++; $this->mdb->post_setLastupdate($post_id); $query = $this->mdb->get_comment_snippet($post_id, $comment_id, $length); $items = $this->loopComments($row->id, $query); $qNxtChck = $this->mdb->get_comment_snippet($post_id, $comment_id, $length + 1); $adc = $this->mdb->get_adc_counts($post_id, $comment_id); generate_json(array('status' => 1, 'items' => $items, 'adc' => $adc->row(), 'shownextcommentslink' => $qNxtChck->num_rows() > $length ? 1 : 0)); } } } }
public function add_member() { requirelogin(); updateLastActive(); $id = (int) jsonInput('id'); $members = jsonInput('members'); $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) { if (is_array($members) && count($members)) { foreach ($members as $member) { $qChkUser = $this->model->getUserInfo(array('email_address' => $member)); if ($qChkUser->num_rows()) { $memberRow = $qChkUser->row(); $qChkIfMember = $this->mdb->taskMembers_get(array('task_id' => $row->id, 'user_id' => $memberRow->id)); if ($qChkIfMember->num_rows()) { generate_json(array('status' => 0, 'message' => $member . ' is already assigned to this task.')); exit; } else { if (!validate_access('valid_member', array('project_id' => $row->project_id, 'user_id' => $memberRow->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; } } foreach ($members as $member) { $qChkUser = $this->model->getUserInfo(array('email_address' => $member)); if ($qChkUser->num_rows()) { $memberRow = $qChkUser->row(); $this->mdb->taskMembers_add(array('task_id' => $row->id, 'user_id' => $memberRow->id, 'assigned_by' => $myID, 'is_accepted' => $memberRow->id == $myID ? 1 : 0, 'date_joined' => today())); //notification notify('task_invite', $memberRow->id, array('project_id' => $row->project_id, 'task_id' => $row->id)); $qProj = $this->db->get_where('projects', array('id' => $row->project_id)); if ($qProj->num_rows()) { $qProjRow = $qProj->row(); $myName = $this->session->userdata('display_name'); $redirectLink = base_url('#/app/projects/' . $row->project_id . '/task/' . $row->id); do_sendmail($memberRow->id, $qProjRow->project_name, "{$myName} assigned a task for you in <a href='{$redirectLink}'>" . $qProjRow->project_name . "</a>"); } } } generate_json(array('status' => 1, 'message' => 'Member(s) was invited to this task.')); } else { generate_json(array('status' => 0, 'message' => 'No people(s) to add.')); } } 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.')); } }
public function post($pid = 0, $tid = 0) { requirelogin(); updateLastActive(); $myID = getUserID(); $pid = (int) $pid; $tid = (int) $tid; 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 { $content = trim(jsonInput('message')); $tags = jsonInput('tags'); if (empty($content)) { generate_json(array('status' => 0, 'message' => 'Post message is empty.')); } else { /* tags */ $params = ""; $tagged = array(); if (is_array($tags) && count($tags) > 0) { foreach ($tags as $tag) { $tag = (int) $tag; if (validate_access('valid_member', array('project_id' => $pid, 'user_id' => $tag)) && $tag != $myID) { $tagged[] = $tag; } } $params = serialize($tagged); } /* tags end */ $pTypes = array('default', 'idea', 'attention', 'urgent'); $post_type = jsonInput('post_type'); $post_type = in_array($post_type, $pTypes) ? $post_type : 'default'; $items = array(); $newID = $this->mdb->feeds_add(array('poster_id' => $myID, 'project_id' => $pid, 'task_id' => $tid, 'post_message' => $content, 'date_posted' => today(), 'date_modified' => today(), 'params' => $params, 'post_type' => $post_type)); /* notify tag members */ foreach ($tagged as $tagUser) { notify('tagged', $tagUser, array('project_id' => $pid, 'post_id' => $newID)); $qProj = $this->db->get_where('projects', array('id' => $pid)); if ($qProj->num_rows()) { $qProjRow = $qProj->row(); $myName = $this->session->userdata('display_name'); $redirectLink = base_url('#/app/projects/' . $pid . '/feed/' . $newID); do_sendmail($tagUser, $qProjRow->project_name, "{$myName} tagged you in a post in <a href='{$redirectLink}'>" . $qProjRow->project_name . "</a>"); } } $query = $this->mdb->feeds_get($pid, 0, $newID, 10, $tid); $this->mdb->setLastUpdate($pid); $sessIDs = jsonInput('attachment_ids'); if (is_array($sessIDs)) { foreach ($sessIDs as $attachID) { $this->mdb->update_attachment($myID, $pid, $attachID, $newID); } } if ($tid > 0) { //notify to task members $qMembers = $this->mdb->taskMembers_get3($pid, $tid); foreach ($qMembers->result() as $membersRow) { notify('task_new_post', $membersRow->user_id, array('project_id' => $pid, 'task_id' => $tid)); $qProj = $this->db->get_where('projects', array('id' => $pid)); if ($qProj->num_rows()) { $qProjRow = $qProj->row(); $myName = $this->session->userdata('display_name'); $redirectLink = base_url('#/app/projects/' . $pid . '/task/' . $tid); $taskName = $this->db->get_where('tasks', array('id' => $tid)); $qTaskRow = $taskName->row(); do_sendmail($membersRow->user_id, $qProjRow->project_name, "{$myName} posted an update in task <a href='{$redirectLink}'>" . $qTaskRow->title . "</a>"); } } } else { //notify to project members $qMembers = $this->mdb->project_member_get($pid); foreach ($qMembers->result() as $membersRow) { notify('project_new_post', $membersRow->user_id, array('project_id' => $pid)); $qProj = $this->db->get_where('projects', array('id' => $pid)); if ($qProj->num_rows()) { $qProjRow = $qProj->row(); $myName = $this->session->userdata('display_name'); $redirectLink = base_url('#/app/projects/' . $pid); do_sendmail($membersRow->user_id, $qProjRow->project_name, "{$myName} posted on <a href='{$redirectLink}'>" . $qProjRow->project_name . "</a>"); } } } generate_json(array('status' => 1, 'items' => $this->processFeedData($query->result()))); } } }