/** * Add new task * * @access public * @param void * @return null */ function add_task() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $notAllowedMember = ''; if (!ProjectTask::canAdd(logged_user(), active_context(), $notAllowedMember)) { if (str_starts_with($notAllowedMember, '-- req dim --')) { flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in))); } else { flash_error(lang('no context permissions to add', lang("tasks"), $notAllowedMember)); } ajx_current("empty"); return; } // if $task = new ProjectTask(); $task_data = array_var($_POST, 'task'); if (!is_array($task_data)) { $dd = getDateValue(array_var($_POST, 'task_due_date', '')); if ($dd instanceof DateTimeValue) { $duetime = getTimeValue(array_var($_POST, 'task_due_time')); if (is_array($duetime)) { $dd->setHour(array_var($duetime, 'hours')); $dd->setMinute(array_var($duetime, 'mins')); } $task->setUseDueTime(is_array($duetime)); } $sd = getDateValue(array_var($_POST, 'task_start_date', '')); if ($sd instanceof DateTimeValue) { $starttime = getTimeValue(array_var($_POST, 'task_start_time')); if (is_array($starttime)) { $sd->setHour(array_var($starttime, 'hours')); $sd->setMinute(array_var($starttime, 'mins')); } $task->setUseStartTime(is_array($starttime)); } $time_estimate = array_var($_POST, 'hours', 0) * 60 + array_var($_POST, 'minutes', 0); $task_data = array('milestone_id' => array_var($_POST, 'milestone_id', 0), 'project_id' => 1, 'name' => array_var($_POST, 'name', ''), 'assigned_to_contact_id' => array_var($_POST, 'assigned_to_contact_id', '0'), 'parent_id' => array_var($_POST, 'parent_id', 0), 'priority' => array_var($_POST, 'priority', ProjectTasks::PRIORITY_NORMAL), 'text' => array_var($_POST, 'text', ''), 'start_date' => $sd, 'due_date' => $dd, 'time_estimate' => $time_estimate, 'is_template' => array_var($_POST, "is_template", array_var($_GET, "is_template", false)), 'percent_completed' => array_var($_POST, "percent_completed", ''), 'object_subtype' => array_var($_POST, "object_subtype", config_option('default task co type')), 'send_notification' => array_var($_POST, 'notify') && array_var($_POST, 'notify') == 'true'); // array if (Plugins::instance()->isActivePlugin('mail')) { $from_email = array_var($_GET, 'from_email'); $email = MailContents::findById($from_email); if ($email instanceof MailContent) { $task_data['name'] = $email->getSubject(); $task_data['text'] = lang('create task from email description', $email->getSubject(), $email->getFrom(), $email->getTextBody()); tpl_assign('from_email', $email); } } } // if if (array_var($_GET, 'replace')) { ajx_replace(true); } tpl_assign('task_data', $task_data); tpl_assign('task', $task); tpl_assign('pending_task_id', 0); $subtasks = array(); if (array_var($_POST, 'multi_assignment')) { $json_subtasks = json_decode(array_var($_POST, 'multi_assignment')); $line = 0; if (count($json_subtasks) > 0) { foreach ($json_subtasks as $json_subtask) { $subtasks[$line]['assigned_to_contact_id'] = $json_subtask->assigned_to_contact_id; $subtasks[$line]['name'] = $json_subtask->name; $subtasks[$line]['time_estimate_hours'] = $json_subtask->time_estimate_hours; $subtasks[$line]['time_estimate_minutes'] = $json_subtask->time_estimate_minutes; $line++; } } } tpl_assign('multi_assignment', $subtasks); if (is_array(array_var($_POST, 'task'))) { // order $task->setOrder(ProjectTasks::maxOrder(array_var($task_data, "parent_id", 0), array_var($task_data, "milestone_id", 0))); $task_data['due_date'] = getDateValue(array_var($_POST, 'task_due_date')); $task_data['start_date'] = getDateValue(array_var($_POST, 'task_start_date')); if ($task_data['due_date'] instanceof DateTimeValue) { $duetime = getTimeValue(array_var($_POST, 'task_due_time')); if (is_array($duetime)) { $task_data['due_date']->setHour(array_var($duetime, 'hours')); $task_data['due_date']->setMinute(array_var($duetime, 'mins')); } $task_data['due_date']->advance(logged_user()->getTimezone() * -3600); $task_data['use_due_time'] = is_array($duetime); } if ($task_data['start_date'] instanceof DateTimeValue) { $starttime = getTimeValue(array_var($_POST, 'task_start_time')); if (is_array($starttime)) { $task_data['start_date']->setHour(array_var($starttime, 'hours')); $task_data['start_date']->setMinute(array_var($starttime, 'mins')); } $task_data['start_date']->advance(logged_user()->getTimezone() * -3600); $task_data['use_start_time'] = is_array($starttime); } try { $err_msg = $this->setRepeatOptions($task_data); if ($err_msg) { flash_error($err_msg); ajx_current("empty"); return; } if (config_option("wysiwyg_tasks")) { $task_data['type_content'] = "html"; $task_data['text'] = preg_replace("/[\n|\r|\n\r]/", '', array_var($task_data, 'text')); } else { $task_data['type_content'] = "text"; } $task_data['object_type_id'] = $task->getObjectTypeId(); $member_ids = json_decode(array_var($_POST, 'members')); $task->setFromAttributes($task_data); if (!can_task_assignee(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $totalMinutes = array_var($task_data, 'time_estimate_hours', 0) * 60 + array_var($task_data, 'time_estimate_minutes', 0); $task->setTimeEstimate($totalMinutes); $id = array_var($_GET, 'id', 0); $parent = ProjectTasks::findById($id); if ($parent instanceof ProjectTask) { $task->setParentId($id); $member_ids = $parent->getMemberIds(); if ($parent->getIsTemplate()) { $task->setIsTemplate(true); } } if ($task->getParentId() > 0 && $task->hasChild($task->getParentId())) { flash_error(lang('task child of child error')); ajx_current("empty"); return; } DB::beginWork(); $task->save(); // dependencies if (config_option('use tasks dependencies')) { $previous_tasks = array_var($task_data, 'previous'); if (is_array($previous_tasks)) { foreach ($previous_tasks as $ptask) { if ($ptask == $task->getId()) { continue; } $dep = ProjectTaskDependencies::findById(array('previous_task_id' => $ptask, 'task_id' => $task->getId())); if (!$dep instanceof ProjectTaskDependency) { $dep = new ProjectTaskDependency(); $dep->setPreviousTaskId($ptask); $dep->setTaskId($task->getId()); $dep->save(); } } } } if (array_var($_GET, 'copyId', 0) > 0) { // copy remaining stuff from the task with id copyId $toCopy = ProjectTasks::findById(array_var($_GET, 'copyId')); if ($toCopy instanceof ProjectTask) { ProjectTasks::copySubTasks($toCopy, $task, array_var($task_data, 'is_template', false)); } } // if task is added from task view -> add subscribers if (array_var($task_data, 'inputtype') == 'taskview') { if (!isset($_POST['subscribers'])) { $_POST['subscribers'] = array(); } $_POST['subscribers']['user_' . logged_user()->getId()] = 'checked'; if ($task->getAssignedToContactId() > 0 && Contacts::instance()->findById($task->getAssignedToContactId())->getUserType()) { $_POST['subscribers']['user_' . $task->getAssignedToContactId()] = 'checked'; } } // Add assigned user to the subscibers list if (isset($_POST['subscribers']) && $task->getAssignedToContactId() > 0 && Contacts::instance()->findById($task->getAssignedToContactId())) { $_POST['subscribers']['user_' . $task->getAssignedToContactId()] = 'checked'; } //Link objects $object_controller = new ObjectController(); $object_controller->add_to_members($task, $member_ids); $object_controller->add_subscribers($task); $object_controller->link_to_new_object($task); $object_controller->add_custom_properties($task); $object_controller->add_reminders($task); ApplicationLogs::createLog($task, ApplicationLogs::ACTION_ADD); if (config_option('repeating_task') == 1) { $opt_rep_day['saturday'] = false; $opt_rep_day['sunday'] = false; if (array_var($task_data, 'repeat_saturdays', false)) { $opt_rep_day['saturday'] = true; } if (array_var($task_data, 'repeat_sundays', false)) { $opt_rep_day['sunday'] = true; } $this->repetitive_task($task, $opt_rep_day); } if (config_option('multi_assignment') && Plugins::instance()->isActivePlugin('crpm')) { $subtasks = array_var($_POST, 'multi_assignment'); Hook::fire('save_subtasks', $task, $subtasks); } DB::commit(); // notify asignee if (array_var($task_data, 'send_notification') == 'checked') { try { Notifier::taskAssigned($task); } catch (Exception $e) { evt_add("debug", $e->getMessage()); } // try } if ($task->getIsTemplate()) { flash_success(lang('success add template', $task->getObjectName())); } else { flash_success(lang('success add task list', $task->getObjectName())); } if (array_var($task_data, 'inputtype') != 'taskview') { ajx_current("back"); } else { ajx_current("reload"); } } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } // try } // if }
function download() { $this->setTemplate(get_template_path('back')); $id = array_var($_GET, 'id'); $email = MailContents::findById($id); if (!$email instanceof MailContent) { flash_error(lang('email dnx')); return; } if (!$email->canView(logged_user())) { flash_error(lang('no access permissions')); return; } if ($email->getContent()) { download_contents($email->getContent(), 'message/rfc822', $email->getSubject() . ".eml", strlen($email->getContent()), true); die; } else { download_from_repository($email->getContentFileId(), 'message/rfc822', $email->getSubject() . ".eml", true); die; } }
function list_objects() { //alert("debugging. remove this line");ajx_current('empty'); return array() ; //TODO remove this line /* get query parameters */ $filesPerPage = config_option('files_per_page'); $start = array_var($_GET, 'start') ? (int) array_var($_GET, 'start') : 0; $limit = array_var($_GET, 'limit') ? array_var($_GET, 'limit') : $filesPerPage; $order = array_var($_GET, 'sort'); $ignore_context = (bool) array_var($_GET, 'ignore_context'); if ($order == "dateUpdated") { $order = "updated_on"; } elseif ($order == "dateArchived") { $order = "archived_on"; } elseif ($order == "dateDeleted") { $order = "trashed_on"; } $orderdir = array_var($_GET, 'dir'); $page = (int) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); $typeCSV = array_var($_GET, 'type'); $types = null; if ($typeCSV) { $types = explode(",", $typeCSV); } $name_filter = mysql_escape_string(array_var($_GET, 'name')); $linked_obj_filter = array_var($_GET, 'linkedobject'); $object_ids_filter = ''; if (!is_null($linked_obj_filter)) { $linkedObject = Objects::findObject($linked_obj_filter); $objs = $linkedObject->getLinkedObjects(); foreach ($objs as $obj) { $object_ids_filter .= ($object_ids_filter == '' ? '' : ',') . $obj->getId(); } } $filters = array(); if (!is_null($types)) { $filters['types'] = $types; } if (!is_null($name_filter)) { $filters['name'] = $name_filter; } if ($object_ids_filter != '') { $filters['object_ids'] = $object_ids_filter; } $user = array_var($_GET, 'user'); $trashed = array_var($_GET, 'trashed', false); $archived = array_var($_GET, 'archived', false); /* if there's an action to execute, do so */ if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); $result = ContentDataObjects::listing(array("extra_conditions" => " AND o.id IN (" . implode(",", $ids) . ") ", "include_deleted" => true)); $objects = $result->objects; list($succ, $err) = $this->do_delete_objects($objects); if ($err > 0) { flash_error(lang('error delete objects', $err)); } else { Hook::fire('after_object_delete_permanently', $ids, $ignored); flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'delete_permanently') { $ids = explode(',', array_var($_GET, 'objects')); //$result = Objects::getObjectsFromContext(active_context(), null, null, true, false, array('object_ids' => implode(",",$ids))); $objects = Objects::instance()->findAll(array("conditions" => "id IN (" . implode(",", $ids) . ")")); list($succ, $err) = $this->do_delete_objects($objects, true); if ($err > 0) { flash_error(lang('error delete objects', $err)); } if ($succ > 0) { Hook::fire('after_object_delete_permanently', $ids, $ignored); flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, true); } else { if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, false); } else { if (array_var($_GET, 'action') == 'empty_trash_can') { $result = Objects::getObjectsFromContext(active_context(), 'trashed_on', 'desc', true); $objects = $result->objects; list($succ, $err) = $this->do_delete_objects($objects, true); if ($err > 0) { flash_error(lang('error delete objects', $err)); } if ($succ > 0) { flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_archive_unarchive_objects($ids, 'archive'); if ($err > 0) { flash_error(lang('error archive objects', $err)); } else { flash_success(lang('success archive objects', $succ)); } } else { if (array_var($_GET, 'action') == 'unarchive') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_archive_unarchive_objects($ids, 'unarchive'); if ($err > 0) { flash_error(lang('error unarchive objects', $err)); } else { flash_success(lang('success unarchive objects', $succ)); } } else { if (array_var($_GET, 'action') == 'unclassify') { $ids = explode(',', array_var($_GET, 'objects')); $err = 0; $succ = 0; foreach ($ids as $id) { $split = explode(":", $id); $type = $split[0]; if (Plugins::instance()->isActivePlugin('mail') && $type == 'MailContents') { $email = MailContents::findById($split[1]); if (isset($email) && !$email->isDeleted() && $email->canEdit(logged_user())) { if (MailController::do_unclassify($email)) { $succ++; } else { $err++; } } else { $err++; } } } if ($err > 0) { flash_error(lang('error unclassify emails', $err)); } else { flash_success(lang('success unclassify emails', $succ)); } } else { if (array_var($_GET, 'action') == 'restore') { $errorMessage = null; $ids = explode(',', array_var($_GET, 'objects')); $success = 0; $error = 0; foreach ($ids as $id) { $obj = Objects::findObject($id); if ($obj->canDelete(logged_user())) { try { $obj->untrash($errorMessage); if ($obj->getObjectTypeId() == 11) { $event = ProjectEvents::findById($obj->getId()); if ($event->getExtCalId() != "") { $this->created_event_google_calendar($obj, $event); } } ApplicationLogs::createLog($obj, ApplicationLogs::ACTION_UNTRASH); $success++; } catch (Exception $e) { $error++; } } else { $error++; } } if ($success > 0) { flash_success(lang("success untrash objects", $success)); } if ($error > 0) { $errorString = is_null($errorMessage) ? lang("error untrash objects", $error) : $errorMessage; flash_error($errorString); } } } } } } } } } } $filterName = array_var($_GET, 'name'); $result = null; $context = active_context(); $obj_type_types = array('content_object', 'dimension_object'); if (array_var($_GET, 'include_comments')) { $obj_type_types[] = 'comment'; } $type_condition = ""; if ($types) { $type_condition = " AND name IN ('" . implode("','", $types) . "')"; } $res = DB::executeAll("SELECT id from " . TABLE_PREFIX . "object_types WHERE type IN ('" . implode("','", $obj_type_types) . "') AND name <> 'file revision' {$type_condition} "); $type_ids = array(); foreach ($res as $row) { if (ObjectTypes::isListableObjectType($row['id'])) { $types_ids[] = $row['id']; } } //Hook::fire('list_objects_type_ids', null, $types_ids); $type_ids_csv = implode(',', $types_ids); $extra_conditions = array(); $extra_conditions[] = "object_type_id in ({$type_ids_csv})"; if ($name_filter) { $extra_conditions[] = "name LIKE '%{$name_filter}%'"; } //$pagination = Objects::getObjects($context,$start,$limit,$order,$orderdir,$trashed,$archived, $filters,$start, $limit, $obj_type_types); $pagination = ContentDataObjects::listing(array("start" => $start, "limit" => $limit, "order" => $order, "order_dir" => $orderdir, "trashed" => $trashed, "archived" => $archived, "types" => $types, "count_results" => false, "extra_conditions" => " AND " . implode(" AND ", $extra_conditions), "ignore_context" => $ignore_context)); $result = $pagination->objects; $total_items = $pagination->total; if (!$result) { $result = array(); } /* prepare response object */ $info = array(); foreach ($result as $obj) { $info_elem = $obj->getArrayInfo($trashed, $archived); $instance = Objects::instance()->findObject($info_elem['object_id']); $info_elem['url'] = $instance->getViewUrl(); /* @var $instance Contact */ if ($instance instanceof Contact) { if ($instance->isCompany()) { $info_elem['icon'] = 'ico-company'; $info_elem['type'] = 'company'; } } else { if ($instance instanceof ProjectFile) { $info_elem['mimeType'] = $instance->getTypeString(); } } $info_elem['isRead'] = $instance->getIsRead(logged_user()->getId()); $info_elem['manager'] = get_class($instance->manager()); $info_elem['memPath'] = json_encode($instance->getMembersToDisplayPath()); $info[] = $info_elem; } $listing = array("totalCount" => $total_items, "start" => $start, "objects" => $info); ajx_extra_data($listing); tpl_assign("listing", $listing); if (isset($reload) && $reload) { ajx_current("reload"); } else { ajx_current("empty"); } }
/** * Add new task * * @access public * @param void * @return null */ function add_task() { //is template task? $isTemplateTask = false; if (array_var($_REQUEST, 'template_task') == true) { $isTemplateTask = true; if (array_var($_REQUEST, 'template_id')) { $template_id = array_var($_REQUEST, 'template_id'); } else { $template_id = 0; } tpl_assign('template_id', $template_id); tpl_assign('additional_tt_params', array_var($_REQUEST, 'additional_tt_params')); } if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $email = null; $context = active_context(); $member_ids = json_decode(array_var($_POST, 'members', null)); if (is_array($member_ids) && count($member_ids) > 0) { $context = Members::findAll(array('conditions' => 'id IN (' . implode(',', $member_ids) . ')')); } $notAllowedMember = ''; if (!ProjectTask::canAdd(logged_user(), $context, $notAllowedMember) && !$isTemplateTask && is_array(array_var($_POST, 'task'))) { if (str_starts_with($notAllowedMember, '-- req dim --')) { $msg = lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)); } else { trim($notAllowedMember) == "" ? $msg = lang('you must select where to keep', lang('the task')) : ($msg = lang('no context permissions to add', lang("tasks"), $notAllowedMember)); } if (array_var($_REQUEST, 'modal')) { $this->setLayout("json"); $this->setTemplate(get_template_path("empty")); $params = array('errorMessage' => $msg, 'errorCode' => 1, 'showMessage' => 1, 'reload' => array_var($_REQUEST, 'reload')); print_modal_json_response($params, true, array_var($_REQUEST, 'use_ajx')); } else { flash_success($msg); } ajx_current("empty"); return; } //is template task? if (array_var($_REQUEST, 'template_task') == true) { $task = new TemplateTask(); $this->setTemplate(get_template_path('add_template_task', 'template_task')); } else { $task = new ProjectTask(); } $task_data = array_var($_POST, 'task'); if (is_array($task_data)) { foreach ($task_data as $k => &$v) { $v = remove_scripts($v); } } if (!is_array($task_data)) { // set layout for modal form if (array_var($_REQUEST, 'modal')) { $this->setLayout("json"); tpl_assign('modal', true); } $dd = getDateValue(array_var($_POST, 'task_due_date', '')); if ($dd instanceof DateTimeValue) { $duetime = getTimeValue(array_var($_POST, 'task_due_time')); if (is_array($duetime)) { $dd->setHour(array_var($duetime, 'hours')); $dd->setMinute(array_var($duetime, 'mins')); } $task->setUseDueTime(is_array($duetime)); } $sd = getDateValue(array_var($_POST, 'task_start_date', '')); if ($sd instanceof DateTimeValue) { $starttime = getTimeValue(array_var($_POST, 'task_start_time')); if (is_array($starttime)) { $sd->setHour(array_var($starttime, 'hours')); $sd->setMinute(array_var($starttime, 'mins')); } $task->setUseStartTime(is_array($starttime)); } $time_estimate = array_var($_POST, 'hours', 0) * 60 + array_var($_POST, 'minutes', 0); if (config_option("wysiwyg_tasks")) { $text_post = preg_replace("/[\n|\r|\n\r]/", '', array_var($_POST, 'text', '')); } else { $text_post = array_var($_POST, 'text', ''); } $task_data = array('milestone_id' => array_var($_REQUEST, 'milestone_id', 0), 'project_id' => 1, 'name' => array_var($_REQUEST, 'name', ''), 'assigned_to_contact_id' => array_var($_REQUEST, 'assigned_to_contact_id', '0'), 'selected_members_ids' => json_decode(array_var($_POST, 'members', null)), 'parent_id' => array_var($_REQUEST, 'parent_id', 0), 'priority' => array_var($_POST, 'priority', ProjectTasks::PRIORITY_NORMAL), 'text' => $text_post, 'start_date' => $sd, 'due_date' => $dd, 'time_estimate' => $time_estimate, 'is_template' => array_var($_POST, "is_template", array_var($_GET, "is_template", false)), 'percent_completed' => array_var($_POST, "percent_completed", ''), 'object_subtype' => array_var($_POST, "object_subtype", config_option('default task co type')), 'send_notification_subscribers' => user_config_option("can notify subscribers")); // array if (Plugins::instance()->isActivePlugin('mail')) { $from_email = array_var($_GET, 'from_email'); $email = MailContents::findById($from_email); if ($email instanceof MailContent) { $task_data['name'] = $email->getSubject(); $task_data['text'] = lang('create task from email description', $email->getSubject(), $email->getFrom(), $email->getTextBody()); $task_data['selected_members_ids'] = $email->getMemberIds(); tpl_assign('from_email', $email); } } tpl_assign('additional_onsubmit', array_var($_REQUEST, 'additional_onsubmit')); } // if if (array_var($_GET, 'replace')) { ajx_replace(true); } tpl_assign('task_data', $task_data); tpl_assign('task', $task); tpl_assign('pending_task_id', 0); $subtasks = array(); if (array_var($_POST, 'multi_assignment')) { $subtasks = json_decode(array_var($_POST, 'multi_assignment'), true); } tpl_assign('multi_assignment', $subtasks); if (is_array(array_var($_POST, 'task'))) { try { // order $task->setOrder(ProjectTasks::maxOrder(array_var($task_data, "parent_id", 0), array_var($task_data, "milestone_id", 0))); try { $task_data['due_date'] = getDateValue(array_var($_POST, 'task_due_date')); $task_data['start_date'] = getDateValue(array_var($_POST, 'task_start_date')); } catch (Exception $e) { throw new Exception(lang('date format error', date_format_tip(user_config_option('date_format')))); } if ($task_data['due_date'] instanceof DateTimeValue) { $duetime = getTimeValue(array_var($_POST, 'task_due_time')); if (is_array($duetime)) { $task_data['due_date']->setHour(array_var($duetime, 'hours')); $task_data['due_date']->setMinute(array_var($duetime, 'mins')); $task_data['due_date']->advance(logged_user()->getTimezone() * -3600); } $task_data['use_due_time'] = is_array($duetime); } if ($task_data['start_date'] instanceof DateTimeValue) { $starttime = getTimeValue(array_var($_POST, 'task_start_time')); if (is_array($starttime)) { $task_data['start_date']->setHour(array_var($starttime, 'hours')); $task_data['start_date']->setMinute(array_var($starttime, 'mins')); $task_data['start_date']->advance(logged_user()->getTimezone() * -3600); } $task_data['use_start_time'] = is_array($starttime); } $err_msg = $this->setRepeatOptions($task_data); if ($err_msg) { throw new Exception($err_msg); } if (config_option("wysiwyg_tasks")) { $task_data['type_content'] = "html"; $task_data['text'] = str_replace(array("\r", "\n", "\r\n"), array('', '', ''), array_var($task_data, 'text')); } else { $task_data['type_content'] = "text"; } $task_data['object_type_id'] = $task->getObjectTypeId(); $member_ids = json_decode(array_var($_POST, 'members')); $task->setFromAttributes($task_data); if (!can_task_assignee(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $totalMinutes = array_var($task_data, 'time_estimate_hours', 0) * 60 + array_var($task_data, 'time_estimate_minutes', 0); $task->setTimeEstimate($totalMinutes); $id = array_var($_GET, 'id', 0); if ($task instanceof TemplateTask) { //evt_add("template task added", array("id_template_task" => $file->getId())); $parent = TemplateTasks::findById($id); if ($parent instanceof TemplateTask) { $task->setParentId($id); $member_ids = $parent->getMemberIds(); } //template id $task->setTemplateId($template_id); } else { $parent = ProjectTasks::findById($id); if ($parent instanceof ProjectTask) { $task->setParentId($id); $member_ids = $parent->getMemberIds(); } } if ($task->getParentId() > 0 && $task->hasChild($task->getParentId())) { flash_error(lang('task child of child error')); ajx_current("empty"); return; } if ($task instanceof TemplateTask) { $task->setSessionId(logged_user()->getId()); } DB::beginWork(); $task->save(); // dependencies if (config_option('use tasks dependencies')) { $previous_tasks = array_var($task_data, 'previous'); if (is_array($previous_tasks)) { foreach ($previous_tasks as $ptask) { if ($ptask == $task->getId()) { continue; } $dep = ProjectTaskDependencies::findById(array('previous_task_id' => $ptask, 'task_id' => $task->getId())); if (!$dep instanceof ProjectTaskDependency) { $dep = new ProjectTaskDependency(); $dep->setPreviousTaskId($ptask); $dep->setTaskId($task->getId()); $dep->save(); } } } } if (array_var($_GET, 'copyId', 0) > 0) { // copy remaining stuff from the task with id copyId $toCopy = ProjectTasks::findById(array_var($_GET, 'copyId')); if ($toCopy instanceof ProjectTask) { ProjectTasks::copySubTasks($toCopy, $task, array_var($task_data, 'is_template', false)); } } // if task is added from task view -> add subscribers if (array_var($task_data, 'inputtype') == 'taskview') { if (!isset($_POST['subscribers'])) { $_POST['subscribers'] = array(); } $_POST['subscribers']['user_' . logged_user()->getId()] = '1'; if ($task->getAssignedToContactId() > 0 && Contacts::instance()->findById($task->getAssignedToContactId())->getUserType()) { $_POST['subscribers']['user_' . $task->getAssignedToContactId()] = '1'; } } // Add assigned user to the subscibers list if (isset($_POST['subscribers']) && $task->getAssignedToContactId() > 0 && Contacts::instance()->findById($task->getAssignedToContactId())) { $_POST['subscribers']['user_' . $task->getAssignedToContactId()] = '1'; } //Link objects $object_controller = new ObjectController(); if ($task instanceof TemplateTask) { //if(!empty($member_ids)){ $object_controller->add_to_members($task, $member_ids, null, false); //} } else { $object_controller->add_to_members($task, $member_ids); } $is_template = $task instanceof TemplateTask; $object_controller->add_subscribers($task, null, !$is_template); $object_controller->link_to_new_object($task); $object_controller->add_custom_properties($task); $object_controller->add_reminders($task); if (config_option('repeating_task') == 1) { $opt_rep_day['saturday'] = false; $opt_rep_day['sunday'] = false; if (array_var($task_data, 'repeat_saturdays', false)) { $opt_rep_day['saturday'] = true; } if (array_var($task_data, 'repeat_sundays', false)) { $opt_rep_day['sunday'] = true; } $this->repetitive_task($task, $opt_rep_day); } if (config_option('multi_assignment') && Plugins::instance()->isActivePlugin('crpm')) { $subtasks = array_var($_POST, 'multi_assignment'); Hook::fire('save_subtasks', $task, $subtasks); } //for calculate member status we save de task again after the object have the members $task->save(); DB::commit(); // save subtasks added in 'subtasks' tab DB::beginWork(); $sub_tasks_to_log = $this->saveSubtasks($task, array_var($task_data, 'subtasks'), $member_ids); DB::commit(); foreach ($sub_tasks_to_log['add'] as $st_to_log) { ApplicationLogs::createLog($st_to_log, ApplicationLogs::ACTION_ADD); } foreach ($sub_tasks_to_log['edit'] as $st_to_log) { ApplicationLogs::createLog($st_to_log, ApplicationLogs::ACTION_EDIT); } foreach ($sub_tasks_to_log['trash'] as $st_to_log) { ApplicationLogs::createLog($st_to_log, ApplicationLogs::ACTION_TRASH); } //Send Template task to view if ($task instanceof TemplateTask) { $objectId = $task->getObjectId(); $id = $task->getId(); $objectTypeName = $task->getObjectTypeName(); $objectName = $task->getObjectName(); $manager = get_class($task->manager()); $milestoneId = $task instanceof TemplateTask ? $task->getMilestoneId() : '0'; $subTasks = array(); $parentId = $task->getParentId(); $ico = "ico-task"; $action = "add"; $object = TemplateController::prepareObject($objectId, $id, $objectName, $objectTypeName, $manager, $action, $milestoneId, $subTasks, $parentId, $ico); $template_task_data = array('object' => $object); if (array_var($_REQUEST, 'additional_tt_params')) { $additional_tt_params = json_decode(str_replace("'", '"', array_var($_REQUEST, 'additional_tt_params')), true); foreach ($additional_tt_params as $k => $v) { $template_task_data[$k] = $v; } } if (!array_var($_REQUEST, 'modal')) { evt_add("template object added", $template_task_data); } } // notify asignee if (array_var($task_data, 'send_notification')) { if ($task instanceof ProjectTask && $task->getAssignedToContactId() != $task->getAssignedById()) { try { Notifier::taskAssigned($task); } catch (Exception $e) { evt_add("debug", $e->getMessage()); } // try } // notify asignee for subtasks foreach ($sub_tasks_to_log['assigned'] as $st_to_log) { if ($st_to_log instanceof ProjectTask && $st_to_log->getAssignedToContactId() != $st_to_log->getAssignedById()) { try { Notifier::taskAssigned($st_to_log); } catch (Exception $e) { evt_add("debug", $e->getMessage()); } // try } } } //notify subscribers $isSilent = true; if (array_var($task_data, 'send_notification_subscribers')) { $isSilent = false; } ApplicationLogs::createLog($task, ApplicationLogs::ACTION_ADD, null, $isSilent); if (array_var($_REQUEST, 'modal')) { ajx_current("empty"); $this->setLayout("json"); $this->setTemplate(get_template_path("empty")); // reload task info because plugins may have updated some task info (for example: name prefix) if ($is_template) { $task = TemplateTasks::findById($task->getId()); } else { $task = ProjectTasks::findById($task->getId()); } $params = array('msg' => lang('success add task list', $task->getObjectName()), 'task' => $task->getArrayInfo(), 'reload' => array_var($_REQUEST, 'reload')); if ($task instanceof TemplateTask) { $params['msg'] = lang('success add template', $task->getObjectName()); $params['object'] = $template_task_data['object']; } print_modal_json_response($params, true, array_var($_REQUEST, 'use_ajx')); } else { if ($task instanceof TemplateTask) { flash_success(lang('success add template', $task->getObjectName())); } else { flash_success(lang('success add task list', $task->getObjectName())); } if (array_var($task_data, 'inputtype') != 'taskview') { ajx_current("back"); } else { ajx_current("reload"); } } } catch (Exception $e) { DB::rollback(); if (array_var($_REQUEST, 'modal')) { $this->setLayout("json"); $this->setTemplate(get_template_path("empty")); print_modal_json_response(array('errorCode' => 1, 'errorMessage' => $e->getMessage(), 'showMessage' => 1), true, array_var($_REQUEST, 'use_ajx')); } else { flash_error($e->getMessage()); } ajx_current("empty"); } // try } // if }
/** * Add new task * * @access public * @param void * @return null */ function add_task() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $project = active_or_personal_project(); if (!ProjectTask::canAdd(logged_user(), $project)) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $task = new ProjectTask(); $task_data = array_var($_POST, 'task'); if (!is_array($task_data)) { $task_data = array('milestone_id' => array_var($_POST, 'milestone_id', 0), 'project_id' => array_var($_POST, 'project_id', active_or_personal_project()->getId()), 'title' => array_var($_POST, 'title', ''), 'assigned_to' => array_var($_POST, 'assigned_to', '0:0'), 'parent_id' => array_var($_POST, 'parent_id', 0), 'priority' => array_var($_POST, 'priority', ProjectTasks::PRIORITY_NORMAL), 'text' => array_var($_POST, 'text', ''), 'start_date' => getDateValue(array_var($_POST, 'task_start_date', '')), 'due_date' => getDateValue(array_var($_POST, 'task_due_date', '')), 'is_template' => array_var($_POST, "is_template", array_var($_GET, "is_template", false)), 'tags' => array_var($_POST, "tags", ''), 'object_subtype' => array_var($_POST, "object_subtype", config_option('default task co type')), 'send_notification' => array_var($_POST, 'notify') && array_var($_POST, 'notify') == 'true'); // array $from_email = array_var($_GET, 'from_email'); $email = MailContents::findById($from_email); if ($email instanceof MailContent) { $task_data['title'] = $email->getSubject(); $task_data['text'] = lang('create task from email description', $email->getSubject(), $email->getFrom(), $email->getTextBody()); $task_data['tags'] = implode(", ", $email->getTagNames()); tpl_assign('from_email', $email); } } // if if (array_var($_GET, 'replace')) { ajx_replace(true); } tpl_assign('task_data', $task_data); tpl_assign('task', $task); if (is_array(array_var($_POST, 'task'))) { $proj = Projects::findById(array_var($task_data, 'project_id')); if ($proj instanceof Project) { $project = $proj; } // order $task->setOrder(ProjectTasks::maxOrder(array_var($task_data, "parent_id", 0), array_var($task_data, "milestone_id", 0))); $task_data['due_date'] = getDateValue(array_var($_POST, 'task_due_date')); $task_data['start_date'] = getDateValue(array_var($_POST, 'task_start_date')); try { $err_msg = $this->setRepeatOptions($task_data); if ($err_msg) { flash_error($err_msg); ajx_current("empty"); return; } $task->setFromAttributes($task_data); $totalMinutes = array_var($task_data, 'time_estimate_hours', 0) * 60 + array_var($task_data, 'time_estimate_minutes', 0); $task->setTimeEstimate($totalMinutes); $task->setIsPrivate(false); // Not used, but defined as not null. // Set assigned to $assigned_to = explode(':', array_var($task_data, 'assigned_to', '')); $company_id = array_var($assigned_to, 0, 0); $user_id = array_var($assigned_to, 1, 0); $can_assign = can_assign_task_to_company_user(logged_user(), $task, $company_id, $user_id); if ($can_assign !== true) { flash_error($can_assign); ajx_current("empty"); return; } $task->setAssignedToCompanyId($company_id); $task->setAssignedToUserId($user_id); $id = array_var($_GET, 'id', 0); $parent = ProjectTasks::findById($id); if ($parent instanceof ProjectTask) { $task->setParentId($id); if ($parent->getIsTemplate()) { $task->setIsTemplate(true); } } if ($task->getParentId() > 0 && $task->hasChild($task->getParentId())) { flash_error(lang('task child of child error')); ajx_current("empty"); return; } //Add handins $handins = array(); for ($i = 0; $i < 4; $i++) { if (isset($task_data["handin{$i}"]) && is_array($task_data["handin{$i}"]) && trim(array_var($task_data["handin{$i}"], 'title')) != '') { $assigned_to = explode(':', array_var($task_data["handin{$i}"], 'assigned_to', '')); $handins[] = array('title' => array_var($task_data["handin{$i}"], 'title'), 'responsible_company_id' => array_var($assigned_to, 0, 0), 'responsible_user_id' => array_var($assigned_to, 1, 0)); // array } // if } // for DB::beginWork(); $task->save(); //$task->setProject($project); //echo 'pepe'; DB::rollback(); die(); $task->setTagsFromCSV(array_var($task_data, 'tags')); foreach ($handins as $handin_data) { $handin = new ObjectHandin(); $handin->setFromAttributes($handin_data); $handin->setObjectId($task->getId()); $handin->setObjectManager(get_class($task->manager())); $handin->save(); } // foreach*/ if (array_var($_GET, 'copyId', 0) > 0) { // copy remaining stuff from the task with id copyId $toCopy = ProjectTasks::findById(array_var($_GET, 'copyId')); if ($toCopy instanceof ProjectTask) { ProjectTasks::copySubTasks($toCopy, $task, array_var($task_data, 'is_template', false)); } } //Link objects $object_controller = new ObjectController(); if ($parent instanceof ProjectTask) { // task is being added as subtask of another, so place in same workspace $task->addToWorkspace($parent->getProject()); } else { $object_controller->add_to_workspaces($task); } $object_controller->link_to_new_object($task); $object_controller->add_subscribers($task); $object_controller->add_custom_properties($task); $object_controller->add_reminders($task); ApplicationLogs::createLog($task, $task->getWorkspaces(), ApplicationLogs::ACTION_ADD); DB::commit(); // notify asignee if (array_var($task_data, 'send_notification') == 'checked') { try { Notifier::taskAssigned($task); } catch (Exception $e) { evt_add("debug", $e->getMessage()); } // try } if ($task->getIsTemplate()) { flash_success(lang('success add template', $task->getTitle())); } else { flash_success(lang('success add task list', $task->getTitle())); } if (array_var($task_data, 'inputtype') != 'taskview') { ajx_current("back"); } else { ajx_current("reload"); } } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } // try } // if }
/** * * */ public function activity_feed() { ajx_set_no_back(true); require_javascript("og/modules/dashboardComments.js"); require_javascript("jquery/jquery.scrollTo-min.js"); /* get query parameters */ $filesPerPage = config_option('files_per_page'); $start = array_var($_GET, 'start') ? (int) array_var($_GET, 'start') : 0; $limit = array_var($_GET, 'limit') ? array_var($_GET, 'limit') : $filesPerPage; $order = array_var($_GET, 'sort'); $orderdir = array_var($_GET, 'dir'); $page = (int) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); $typeCSV = array_var($_GET, 'type'); $types = null; if ($typeCSV) { $types = explode(",", $typeCSV); } $name_filter = array_var($_GET, 'name'); $linked_obj_filter = array_var($_GET, 'linkedobject'); $object_ids_filter = ''; if (!is_null($linked_obj_filter)) { $linkedObject = Objects::findObject($linked_obj_filter); $objs = $linkedObject->getLinkedObjects(); foreach ($objs as $obj) { $object_ids_filter .= ($object_ids_filter == '' ? '' : ',') . $obj->getId(); } } $filters = array(); if (!is_null($types)) { $filters['types'] = $types; } if (!is_null($name_filter)) { $filters['name'] = $name_filter; } if ($object_ids_filter != '') { $filters['object_ids'] = $object_ids_filter; } $user = array_var($_GET, 'user'); $trashed = array_var($_GET, 'trashed', false); $archived = array_var($_GET, 'archived', false); /* if there's an action to execute, do so */ if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); $result = Objects::getObjectsFromContext(active_context(), null, null, false, false, array('object_ids' => implode(",", $ids))); $objects = $result->objects; list($succ, $err) = $this->do_delete_objects($objects); if ($err > 0) { flash_error(lang('error delete objects', $err)); } else { flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'delete_permanently') { $ids = explode(',', array_var($_GET, 'objects')); $result = Objects::getObjectsFromContext(active_context(), null, null, true, false, array('object_ids' => implode(",", $ids))); $objects = $result->objects; list($succ, $err) = $this->do_delete_objects($objects, true); if ($err > 0) { flash_error(lang('error delete objects', $err)); } if ($succ > 0) { flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, true); } else { if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, false); } else { if (array_var($_GET, 'action') == 'empty_trash_can') { $result = Objects::getObjectsFromContext(active_context(), 'trashed_on', 'desc', true); $objects = $result->objects; list($succ, $err) = $this->do_delete_objects($objects, true); if ($err > 0) { flash_error(lang('error delete objects', $err)); } if ($succ > 0) { flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_archive_unarchive_objects($ids, 'archive'); if ($err > 0) { flash_error(lang('error archive objects', $err)); } else { flash_success(lang('success archive objects', $succ)); } } else { if (array_var($_GET, 'action') == 'unarchive') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_archive_unarchive_objects($ids, 'unarchive'); if ($err > 0) { flash_error(lang('error unarchive objects', $err)); } else { flash_success(lang('success unarchive objects', $succ)); } } else { if (array_var($_GET, 'action') == 'unclassify') { $ids = explode(',', array_var($_GET, 'objects')); $err = 0; $succ = 0; foreach ($ids as $id) { $split = explode(":", $id); $type = $split[0]; if ($type == 'MailContents') { $email = MailContents::findById($split[1]); if (isset($email) && !$email->isDeleted() && $email->canEdit(logged_user())) { if (MailController::do_unclassify($email)) { $succ++; } else { $err++; } } else { $err++; } } } if ($err > 0) { flash_error(lang('error unclassify emails', $err)); } else { flash_success(lang('success unclassify emails', $succ)); } } else { if (array_var($_GET, 'action') == 'restore') { $errorMessage = null; $ids = explode(',', array_var($_GET, 'objects')); $success = 0; $error = 0; foreach ($ids as $id) { $obj = Objects::findObject($id); if ($obj->canDelete(logged_user())) { try { $obj->untrash($errorMessage); ApplicationLogs::createLog($obj, ApplicationLogs::ACTION_UNTRASH); $success++; } catch (Exception $e) { $error++; } } else { $error++; } } if ($success > 0) { flash_success(lang("success untrash objects", $success)); } if ($error > 0) { $errorString = is_null($errorMessage) ? lang("error untrash objects", $error) : $errorMessage; flash_error($errorString); } } } } } } } } } } /*FIXME else if (array_var($_GET, 'action') == 'move') { $wsid = array_var($_GET, "moveTo"); $destination = Projects::findById($wsid); if (!$destination instanceof Project) { $resultMessage = lang('project dnx'); $resultCode = 1; } else if (!can_add(logged_user(), $destination, 'ProjectMessages')) { $resultMessage = lang('no access permissions'); $resultCode = 1; } else { $ids = explode(',', array_var($_GET, 'objects')); $count = 0; DB::beginWork(); foreach ($ids as $id) { $split = explode(":", $id); $type = $split[0]; $obj = Objects::findObject($split[1]); $mantainWs = array_var($_GET, "mantainWs"); if ($type != 'Projects' && $obj->canEdit(logged_user())) { if ($type == 'MailContents') { $email = MailContents::findById($split[1]); $conversation = MailContents::getMailsFromConversation($email); foreach ($conversation as $conv_email) { $count += MailController::addEmailToWorkspace($conv_email->getId(), $destination, $mantainWs); if (array_var($_GET, 'classify_atts') && $conv_email->getHasAttachments()) { MailUtilities::parseMail($conv_email->getContent(), $decoded, $parsedEmail, $warnings); $classification_data = array(); for ($j=0; $j < count(array_var($parsedEmail, "Attachments", array())); $j++) { $classification_data["att_".$j] = true; } $tags = implode(",", $conv_email->getTagNames()); MailController::classifyFile($classification_data, $conv_email, $parsedEmail, array($destination), $mantainWs, $tags); } } $count++; } else { if (!$mantainWs || $type == 'ProjectTasks' || $type == 'ProjectMilestones') { $removed = ""; $ws = $obj->getWorkspaces(); foreach ($ws as $w) { if (can_add(logged_user(), $w, $type)) { $obj->removeFromWorkspace($w); $removed .= $w->getId() . ","; } } $removed = substr($removed, 0, -1); $log_action = ApplicationLogs::ACTION_MOVE; $log_data = ($removed == "" ? "" : "from:$removed;") . "to:$wsid"; } else { $log_action = ApplicationLogs::ACTION_COPY; $log_data = "to:$wsid"; } $obj->addToWorkspace($destination); ApplicationLogs::createLog($obj, $log_action, false, null, true, $log_data); $count++; } } } if ($count > 0) { $reload = true; DB::commit(); flash_success(lang("success move objects", $count)); } else { DB::rollback(); } } }*/ $filterName = array_var($_GET, 'name'); $result = null; $context = active_context(); $obj_type_types = array('content_object'); if (array_var($_GET, 'include_comments')) { $obj_type_types[] = 'comment'; } $pagination = Objects::getObjects($context, $start, $limit, $order, $orderdir, $trashed, $archived, $filters, $start, $limit, $obj_type_types); $result = $pagination->objects; $total_items = $pagination->total; if (!$result) { $result = array(); } /* prepare response object */ $info = array(); foreach ($result as $obj) { $info_elem = $obj->getArrayInfo($trashed, $archived); $instance = Objects::instance()->findObject($info_elem['object_id']); $info_elem['url'] = $instance->getViewUrl(); if (method_exists($instance, "getText")) { $info_elem['content'] = $instance->getText(); } $info_elem['picture'] = $instance->getCreatedBy()->getPictureUrl(); $info_elem['friendly_date'] = friendly_date($instance->getCreatedOn()); $info_elem['comment'] = $instance->getComments(); /* @var $instance Contact */ if ($instance instanceof Contact) { if ($instance->isCompany()) { $info_elem['icon'] = 'ico-company'; $info_elem['type'] = 'company'; } } $info_elem['isRead'] = $instance->getIsRead(logged_user()->getId()); $info_elem['manager'] = get_class($instance->manager()); $info[] = $info_elem; } $listing = array("totalCount" => $total_items, "start" => $start, "objects" => $info); tpl_assign("feeds", $listing); }
/** * * */ function addToSharingTable() { // if classified or not belongs to an email $member_ids = array(); $members = $this->getMembers(); foreach ($members as $m) { $d = $m->getDimension(); if ($d instanceof Dimension && $d->getIsManageable()) { $member_ids[] = $m->getId(); } } if ($this->getMailId() == 0 || count($member_ids) > 0) { $revisions = $this->getRevisions(); if (is_array($revisions)) { foreach ($revisions as $revision) { $revision->addToSharingTable(); } } parent::addToSharingTable(); } else { // if not classified and belongs to an email $mail = MailContents::findById($this->getMailId()); if ($mail instanceof MailContent) { DB::execute("DELETE FROM " . TABLE_PREFIX . "sharing_table WHERE object_id=" . $this->getId()); $macs = MailAccountContacts::findAll(array('conditions' => array('`account_id` = ?', $mail->getAccountId()))); foreach ($macs as $mac) { $c = Contacts::findById($mac->getContactId()); if ($c instanceof Contact) { $values = "(" . $c->getPermissionGroupId() . "," . $this->getId() . ")"; DB::execute("INSERT INTO " . TABLE_PREFIX . "sharing_table (group_id, object_id) VALUES {$values} ON DUPLICATE KEY UPDATE group_id=group_id;"); } } } } }
function list_objects() { /* get query parameters */ $filesPerPage = config_option('files_per_page'); $start = array_var($_GET, 'start') ? (int) array_var($_GET, 'start') : 0; $limit = array_var($_GET, 'limit') ? array_var($_GET, 'limit') : $filesPerPage; $order = array_var($_GET, 'sort'); $orderdir = array_var($_GET, 'dir'); $page = (int) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); $tag = array_var($_GET, 'tag'); $typeCSV = array_var($_GET, 'type'); $types = null; if ($typeCSV) { $types = explode(",", $typeCSV); } $objid = array_var($_GET, 'linkedobject'); $mangr = array_var($_GET, 'linkedmanager'); $filterManager = array_var($_GET, 'filtermanager', ''); if ($mangr != null && $objid != null) { $linkedObject = get_object_by_manager_and_id($objid, $mangr); } else { $linkedObject = null; } $user = array_var($_GET, 'user'); $trashed = array_var($_GET, 'trashed', false); $archived = array_var($_GET, 'archived', false); /* if there's an action to execute, do so */ if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_delete_objects($ids); if ($err > 0) { flash_error(lang('error delete objects', $err)); } else { flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'delete_permanently') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_delete_objects($ids, null, true); if ($err > 0) { flash_error(lang('error delete objects', $err)); } if ($succ > 0) { flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, true); } else { if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, false); } else { if (array_var($_GET, 'action') == 'empty_trash_can') { $Allitems = $this->getDashboardObjects(null, null, null, null, null, null, active_project(), true); $ids = array(); for ($i = 0; $i < count($Allitems); $i++) { $id = $Allitems[$i]['object_id']; $manager = $Allitems[$i]['manager']; $ids[] = $manager . ':' . $id; } list($succ, $err) = $this->do_delete_objects($ids, null, true); if ($err > 0) { flash_error(lang('error delete objects', $err)); } if ($succ > 0) { flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_archive_unarchive_objects($ids, null, 'archive'); if ($err > 0) { flash_error(lang('error archive objects', $err)); } else { flash_success(lang('success archive objects', $succ)); } } else { if (array_var($_GET, 'action') == 'unarchive') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_archive_unarchive_objects($ids, null, 'unarchive'); if ($err > 0) { flash_error(lang('error unarchive objects', $err)); } else { flash_success(lang('success unarchive objects', $succ)); } } else { if (array_var($_GET, 'action') == 'unclassify') { $ids = explode(',', array_var($_GET, 'objects')); $err = 0; $succ = 0; foreach ($ids as $id) { $split = explode(":", $id); $type = $split[0]; if ($type == 'MailContents') { $email = MailContents::findById($split[1]); if (isset($email) && !$email->isDeleted() && $email->canEdit(logged_user())) { if (MailController::do_unclassify($email)) { $succ++; } else { $err++; } } else { $err++; } } } if ($err > 0) { flash_error(lang('error unclassify emails', $err)); } else { flash_success(lang('success unclassify emails', $succ)); } } else { if (array_var($_GET, 'action') == 'tag') { $ids = explode(',', array_var($_GET, 'objects')); $tagTag = array_var($_GET, 'tagTag'); list($succ, $err) = $this->do_tag_object($tagTag, $ids); if ($err > 0) { flash_error(lang('error tag objects', $err)); } else { flash_success(lang('success tag objects', $succ)); } } else { if (array_var($_GET, 'action') == 'untag') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_untag_object(array_var($_GET, 'tagTag'), $ids); if ($err > 0) { flash_error(lang('error untag objects', $err)); } else { flash_success(lang('success untag objects', $succ)); } } else { if (array_var($_GET, 'action') == 'restore') { $ids = explode(',', array_var($_GET, 'objects')); $success = 0; $error = 0; foreach ($ids as $id) { $split = explode(":", $id); $obj = get_object_by_manager_and_id($split[1], $split[0]); if ($obj->canDelete(logged_user())) { try { $obj->untrash(); ApplicationLogs::createLog($obj, $obj->getWorkspaces(), ApplicationLogs::ACTION_UNTRASH); if ($obj->getObjectManagerName() == 'ProjectTasks') { $subtasks = $obj->getAllSubtasks(); foreach ($subtasks as $st) { ApplicationLogs::createLog($st, $st->getWorkspaces(), ApplicationLogs::ACTION_UNTRASH); $success++; } } $success++; } catch (Exception $e) { $error++; } } else { $error++; } } if ($success > 0) { flash_success(lang("success untrash objects", $success)); } if ($error > 0) { flash_error(lang("error untrash objects", $error)); } } else { if (array_var($_GET, 'action') == 'move') { $wsid = array_var($_GET, "moveTo"); $destination = Projects::findById($wsid); if (!$destination instanceof Project) { $resultMessage = lang('project dnx'); $resultCode = 1; } else { if (!can_add(logged_user(), $destination, 'ProjectMessages')) { $resultMessage = lang('no access permissions'); $resultCode = 1; } else { $ids = explode(',', array_var($_GET, 'objects')); $count = 0; DB::beginWork(); foreach ($ids as $id) { $split = explode(":", $id); $type = $split[0]; $obj = get_object_by_manager_and_id($split[1], $type); $mantainWs = array_var($_GET, "mantainWs"); if ($type != 'Projects' && $obj->canEdit(logged_user())) { if ($type == 'MailContents') { $email = MailContents::findById($split[1]); $conversation = MailContents::getMailsFromConversation($email); foreach ($conversation as $conv_email) { $count += MailController::addEmailToWorkspace($conv_email->getId(), $destination, $mantainWs); if (array_var($_GET, 'classify_atts') && $conv_email->getHasAttachments()) { MailUtilities::parseMail($conv_email->getContent(), $decoded, $parsedEmail, $warnings); $classification_data = array(); for ($j = 0; $j < count(array_var($parsedEmail, "Attachments", array())); $j++) { $classification_data["att_" . $j] = true; } $tags = implode(",", $conv_email->getTagNames()); MailController::classifyFile($classification_data, $conv_email, $parsedEmail, array($destination), $mantainWs, $tags); } } $count++; } else { if (!$mantainWs || $type == 'ProjectTasks' || $type == 'ProjectMilestones') { $removed = ""; $ws = $obj->getWorkspaces(); foreach ($ws as $w) { if (can_add(logged_user(), $w, $type)) { $obj->removeFromWorkspace($w); $removed .= $w->getId() . ","; } } $removed = substr($removed, 0, -1); $log_action = ApplicationLogs::ACTION_MOVE; $log_data = ($removed == "" ? "" : "from:{$removed};") . "to:{$wsid}"; } else { $log_action = ApplicationLogs::ACTION_COPY; $log_data = "to:{$wsid}"; } $obj->addToWorkspace($destination); ApplicationLogs::createLog($obj, $obj->getWorkspaces(), $log_action, false, null, true, $log_data); $count++; } } } if ($count > 0) { $reload = true; DB::commit(); flash_success(lang("success move objects", $count)); } else { DB::rollback(); } } } } } } } } } } } } } } } $filterName = array_var($_GET, 'name'); $result = null; /* perform queries according to type*/ $project = active_project(); $total_items = $this->countDashboardObjects($tag, $types, $project, $trashed, $linkedObject, $filterName, $archived, $filterManager); if ($total_items < ($page - 1) * $limit) { $page = 1; $start = 0; } $result = $this->getDashboardObjects($page, $filesPerPage, $tag, $order, $orderdir, $types, $project, $trashed, $linkedObject, $filterName, $archived, $filterManager); if (!$result) { $result = array(); } /* prepare response object */ $listing = array("totalCount" => $total_items, "start" => $start, "objects" => $result); ajx_extra_data($listing); tpl_assign("listing", $listing); if (isset($reload) && $reload) { ajx_current("reload"); } else { ajx_current("empty"); } }
?> <select name="<?php echo 'parameterValues[' . $parameter['name'] . ']'; ?> "> <?php $context = active_context(); if (isset($member_id) && $member_id > 0) { // filter by context passed by parameter $additional_member = Members::findById($member_id); if ($additional_member instanceof Member) { $context = array($additional_member); } } if (array_var($_REQUEST, 'from_email')) { $from_email = MailContents::findById(array_var($_REQUEST, 'from_email')); if ($from_email instanceof MailContent) { $context = $from_email->getMembers(); } } $companies = allowed_users_to_assign($context); foreach ($companies as $c) { if (config_option('can_assign_tasks_to_companies')) { ?> <option value="<?php echo $c['id']; ?> "> <?php echo $c['name']; ?> </option>
private function processListActions() { $linkedObject = null; if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); $result = ContentDataObjects::listing(array("extra_conditions" => " AND o.id IN (" . implode(",", $ids) . ") ", "include_deleted" => true)); $objects = $result->objects; foreach ($objects as $object) { $object->setDontMakeCalculations(true); } $real_deleted_ids = array(); list($succ, $err) = $this->do_delete_objects($objects, false, $real_deleted_ids); if ($err > 0) { flash_error(lang('error delete objects', $err)); } else { Hook::fire('after_object_delete_permanently', $real_deleted_ids, $ignored); flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'delete_permanently') { $ids = explode(',', array_var($_GET, 'objects')); $objects = Objects::instance()->findAll(array("conditions" => "id IN (" . implode(",", $ids) . ")")); $real_deleted_ids = array(); list($succ, $err) = $this->do_delete_objects($objects, true, $real_deleted_ids); if ($err > 0) { flash_error(lang('error delete objects', $err)); } if ($succ > 0) { Hook::fire('after_object_delete_permanently', $real_deleted_ids, $ignored); flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, true); } else { if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, false); } else { if (array_var($_GET, 'action') == 'empty_trash_can') { $result = ContentDataObjects::listing(array("select_columns" => array('id'), "raw_data" => true, "trashed" => true)); $objects = $result->objects; foreach ($objects as $object) { $object->setDontMakeCalculations(true); } if (count($objects) > 0) { $obj_ids_str = implode(',', array_flat($objects)); $extra_conds = "AND o.id IN ({$obj_ids_str})"; $count = Trash::purge_trash(0, 1000, $extra_conds); flash_success(lang('success delete objects', $count)); } } else { if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_archive_unarchive_objects($ids, 'archive'); if ($err > 0) { flash_error(lang('error archive objects', $err)); } else { flash_success(lang('success archive objects', $succ)); } } else { if (array_var($_GET, 'action') == 'unarchive') { $ids = explode(',', array_var($_GET, 'objects')); list($succ, $err) = $this->do_archive_unarchive_objects($ids, 'unarchive'); if ($err > 0) { flash_error(lang('error unarchive objects', $err)); } else { flash_success(lang('success unarchive objects', $succ)); } } else { if (array_var($_GET, 'action') == 'unclassify') { $ids = explode(',', array_var($_GET, 'objects')); $err = 0; $succ = 0; foreach ($ids as $id) { $split = explode(":", $id); $type = $split[0]; if (Plugins::instance()->isActivePlugin('mail') && $type == 'MailContents') { $email = MailContents::findById($split[1]); if (isset($email) && !$email->isDeleted() && $email->canEdit(logged_user())) { if (MailController::do_unclassify($email)) { $succ++; } else { $err++; } } else { $err++; } } } if ($err > 0) { flash_error(lang('error unclassify emails', $err)); } else { flash_success(lang('success unclassify emails', $succ)); } } else { if (array_var($_GET, 'action') == 'restore') { $errorMessage = null; $ids = explode(',', array_var($_GET, 'objects')); $success = 0; $error = 0; foreach ($ids as $id) { $obj = Objects::findObject($id); $obj->setDontMakeCalculations(true); if ($obj->canDelete(logged_user())) { try { $obj->untrash($errorMessage); if ($obj->getObjectTypeId() == 11) { $event = ProjectEvents::findById($obj->getId()); if ($event->getExtCalId() != "") { $this->created_event_google_calendar($obj, $event); } } ApplicationLogs::createLog($obj, ApplicationLogs::ACTION_UNTRASH); $success++; } catch (Exception $e) { $error++; } } else { $error++; } } if ($success > 0) { flash_success(lang("success untrash objects", $success)); } if ($error > 0) { $errorString = is_null($errorMessage) ? lang("error untrash objects", $error) : $errorMessage; flash_error($errorString); } } } } } } } } } } if (!array_var($_GET, 'only_result')) { $ignored = null; Hook::fire('after_multi_object_action', array('object_ids' => explode(',', array_var($_GET, 'objects')), 'action' => array_var($_GET, 'action')), $ignored); } }