/** * Return array of milestones that are assigned to specific user or his company * * @param User $user * @return array */ function getUsersMilestones(User $user) { $conditions = DB::prepareString(ProjectTasks::getWorkspaceString() . ' AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?)) AND `completed_on` = ?', array($this->getId(), $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, EMPTY_DATETIME)); if (!$user->isMemberOfOwnerCompany()) { $conditions .= DB::prepareString(' AND `is_private` = ?', array(0)); } // if return ProjectMilestones::findAll(array('conditions' => $conditions, 'order' => '`due_date`')); }
function new_list_tasks() { //load config options into cache for better performance load_user_config_options_by_category_name('task panel'); // get query parameters, save user preferences if necessary $status = array_var($_GET, 'status', null); if (is_null($status) || $status == '') { $status = user_config_option('task panel status', 2); } else { if (user_config_option('task panel status') != $status) { set_user_config_option('task panel status', $status, logged_user()->getId()); } } $previous_filter = user_config_option('task panel filter', 'assigned_to'); $filter = array_var($_GET, 'filter'); if (is_null($filter) || $filter == '') { $filter = user_config_option('task panel filter', 'assigned_to'); } else { if (user_config_option('task panel filter') != $filter) { set_user_config_option('task panel filter', $filter, logged_user()->getId()); } } if ($filter != 'no_filter') { $filter_value = array_var($_GET, 'fval'); if (is_null($filter_value) || $filter_value == '') { $filter_value = user_config_option('task panel filter value', logged_user()->getCompanyId() . ':' . logged_user()->getId()); set_user_config_option('task panel filter value', $filter_value, logged_user()->getId()); $filter = $previous_filter; set_user_config_option('task panel filter', $filter, logged_user()->getId()); } else { if (user_config_option('task panel filter value') != $filter_value) { set_user_config_option('task panel filter value', $filter_value, logged_user()->getId()); } } } $isJson = array_var($_GET, 'isJson', false); if ($isJson) { ajx_current("empty"); } $project = active_project(); $tag = active_tag(); $template_condition = "`is_template` = 0 "; //Get the task query conditions $task_filter_condition = ""; switch ($filter) { case 'assigned_to': $assigned_to = explode(':', $filter_value); $assigned_to_user = array_var($assigned_to, 1, 0); $assigned_to_company = array_var($assigned_to, 0, 0); if ($assigned_to_user > 0) { $task_filter_condition = " AND (`assigned_to_user_id` = " . $assigned_to_user . " OR (`assigned_to_company_id` = " . $assigned_to_company . " AND `assigned_to_user_id` = 0)) "; } else { if ($assigned_to_company > 0) { $task_filter_condition = " AND `assigned_to_company_id` = " . $assigned_to_company . " AND `assigned_to_user_id` = 0"; } else { if ($assigned_to_company == -1 && $assigned_to_user == -1) { $task_filter_condition = " AND `assigned_to_company_id` = 0 AND `assigned_to_user_id` = 0 "; } } } break; case 'assigned_by': if ($filter_value != 0) { $task_filter_condition = " AND `assigned_by_id` = " . $filter_value . " "; } break; case 'created_by': if ($filter_value != 0) { $task_filter_condition = " AND `created_by_id` = " . $filter_value . " "; } break; case 'completed_by': if ($filter_value != 0) { $task_filter_condition = " AND `completed_by_id` = " . $filter_value . " "; } break; case 'milestone': $task_filter_condition = " AND `milestone_id` = " . $filter_value . " "; break; case 'priority': $task_filter_condition = " AND `priority` = " . $filter_value . " "; break; case 'subtype': if ($filter_value != 0) { $task_filter_condition = " AND `object_subtype` = " . $filter_value . " "; } break; case 'no_filter': $task_filter_condition = ""; break; default: flash_error(lang('task filter criteria not recognised', $filter)); } if ($project instanceof Project) { $pids = $project->getAllSubWorkspacesQuery(true); $projectstr = " AND " . ProjectTasks::getWorkspaceString($pids); } else { $pids = ""; $projectstr = ""; } $permissions = " AND " . permissions_sql_for_listings(ProjectTasks::instance(), ACCESS_LEVEL_READ, logged_user()); $task_status_condition = ""; switch ($status) { case 0: // Incomplete tasks $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME); break; case 1: // Complete tasks $task_status_condition = " AND `completed_on` > " . DB::escape(EMPTY_DATETIME); break; case 10: // Active tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}'"; break; case 11: // Overdue tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` < '{$now}'"; break; case 12: // Today tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` = '{$now}'"; break; case 13: // Today + Overdue tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'"; break; case 14: // Today + Overdue tasks $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `due_date` <= '{$now}'"; break; case 20: // Actives task by current user $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `start_date` <= '{$now}' AND `assigned_to_user_id` = " . logged_user()->getId(); break; case 21: // Subscribed tasks by current user $res20 = DB::execute("SELECT object_id FROM " . TABLE_PREFIX . "object_subscriptions WHERE `object_manager` LIKE 'ProjectTasks' AND `user_id` = " . logged_user()->getId()); $subs_rows = $res20->fetchAll($res20); foreach ($subs_rows as $row) { $subs[] = $row['object_id']; } unset($res20, $subs_rows, $row); $now = date('Y-m-j 00:00:00'); $task_status_condition = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " AND `id` IN(" . implode(',', $subs) . ")"; break; case 2: // All tasks break; default: throw new Exception('Task status "' . $status . '" not recognised'); } if (!$tag) { $tagstr = ""; } else { $tagstr = " AND (select count(*) from " . TABLE_PREFIX . "tags where " . TABLE_PREFIX . "project_tasks.id = " . TABLE_PREFIX . "tags.rel_object_id and " . TABLE_PREFIX . "tags.tag = " . DB::escape($tag) . " and " . TABLE_PREFIX . "tags.rel_object_manager ='ProjectTasks' ) > 0 "; } $conditions = $template_condition . $task_filter_condition . $task_status_condition . $permissions . $tagstr . $projectstr . " AND `trashed_by_id` = 0 AND `archived_by_id` = 0"; //Now get the tasks $tasks = ProjectTasks::findAll(array('conditions' => $conditions, 'order' => 'created_on DESC', 'limit' => user_config_option('task_display_limit') > 0 ? user_config_option('task_display_limit') + 1 : null)); ProjectTasks::populateData($tasks); //Find all internal milestones for these tasks $internalMilestones = ProjectMilestones::getProjectMilestones(active_or_personal_project(), null, 'DESC', "", null, null, null, $status == 0, false); ProjectMilestones::populateData($internalMilestones); //Find all external milestones for these tasks $milestone_ids = array(); if ($tasks) { foreach ($tasks as $task) { if ($task->getMilestoneId() != 0) { $milestone_ids[$task->getMilestoneId()] = $task->getMilestoneId(); } } } $milestone_ids_condition = ''; if (count($milestone_ids) > 0) { $milestone_ids_condition = ' OR id in (' . implode(',', $milestone_ids) . ')'; } if ($status == 0) { $pendingstr = " AND `completed_on` = " . DB::escape(EMPTY_DATETIME) . " "; } else { $pendingstr = ""; } if (!$tag) { $tagstr = ""; } else { $tagstr = " AND (select count(*) from " . TABLE_PREFIX . "tags where " . TABLE_PREFIX . "project_milestones.id = " . TABLE_PREFIX . "tags.rel_object_id and " . TABLE_PREFIX . "tags.tag = " . DB::escape($tag) . " and " . TABLE_PREFIX . "tags.rel_object_manager ='ProjectMilestones' ) > 0 "; } $projectstr = " AND (" . ProjectMilestones::getWorkspaceString($pids) . $milestone_ids_condition . ")"; $archivedstr = " AND `archived_by_id` = 0 "; $milestone_conditions = " `is_template` = false " . $archivedstr . $projectstr . $pendingstr; $externalMilestonesTemp = ProjectMilestones::findAll(array('conditions' => $milestone_conditions)); $externalMilestones = array(); if ($externalMilestonesTemp) { foreach ($externalMilestonesTemp as $em) { $found = false; if ($internalMilestones) { foreach ($internalMilestones as $im) { if ($im->getId() == $em->getId()) { $found = true; break; } } } if (!$found) { $externalMilestones[] = $em; } } } ProjectMilestones::populateData($externalMilestones); //Get Users Info if (logged_user()->isMemberOfOwnerCompany()) { $users = Users::getAll(); $allUsers = array(); } else { $users = logged_user()->getAssignableUsers(); $allUsers = Users::getAll(); } //Get Companies Info if (logged_user()->isMemberOfOwnerCompany()) { $companies = Companies::getCompaniesWithUsers(); } else { $companies = logged_user()->getAssignableCompanies(); } if (!$isJson) { if (active_project() instanceof Project) { $task_templates = WorkspaceTemplates::getTemplatesByWorkspace(active_project()->getId()); } else { $task_templates = array(); } tpl_assign('project_templates', $task_templates); tpl_assign('all_templates', COTemplates::findAll()); if (user_config_option('task_display_limit') > 0 && count($tasks) > user_config_option('task_display_limit')) { tpl_assign('displayTooManyTasks', true); array_pop($tasks); } tpl_assign('tasks', $tasks); tpl_assign('object_subtypes', ProjectCoTypes::getObjectTypesByManager('ProjectTasks')); tpl_assign('internalMilestones', $internalMilestones); tpl_assign('externalMilestones', $externalMilestones); tpl_assign('users', $users); tpl_assign('allUsers', $allUsers); tpl_assign('companies', $companies); tpl_assign('userPreferences', array('filterValue' => isset($filter_value) ? $filter_value : '', 'filter' => $filter, 'status' => $status, 'showWorkspaces' => user_config_option('tasksShowWorkspaces', 1), 'showTime' => user_config_option('tasksShowTime', 0), 'showDates' => user_config_option('tasksShowDates', 0), 'showTags' => user_config_option('tasksShowTags', 0), 'showEmptyMilestones' => user_config_option('tasksShowEmptyMilestones', 0), 'groupBy' => user_config_option('tasksGroupBy', 'milestone'), 'orderBy' => user_config_option('tasksOrderBy', 'priority'), 'defaultNotifyValue' => user_config_option('can notify from quick add'))); ajx_set_no_toolbar(true); } }
/** * Returns array of queries that will return Dashboard Objects * * @param string $proj_ids * @param string $tag * @param boolean $count if false the query will return objects, if true it will return object count */ static function getDashboardObjectQueries($project = null, $tag = null, $count = false, $trashed = false, $linkedObject = null, $order = 'updatedOn', $filterName = '', $archived = false, $filterManager = '') { if ($trashed && $trashed !== 'all') { $order = 'trashedOn'; } else { if ($archived) { $order = 'archivedOn'; } } switch ($order) { case 'dateCreated': $order_crit_companies = '`created_on`'; $order_crit_contacts = '`created_on`'; $order_crit_file_revisions = '`created_on`'; $order_crit_calendar = '`created_on`'; $order_crit_tasks = '`created_on`'; $order_crit_milestones = '`created_on`'; $order_crit_webpages = '`created_on`'; $order_crit_files = '`created_on`'; $order_crit_emails = '`received_date`'; $order_crit_comments = '`created_on`'; $order_crit_messages = '`created_on`'; $order_crit_workspaces = '`created_on`'; break; case 'trashedOn': $order_crit_companies = '`trashed_on`'; $order_crit_contacts = '`trashed_on`'; $order_crit_file_revisions = '`trashed_on`'; $order_crit_calendar = '`trashed_on`'; $order_crit_tasks = '`trashed_on`'; $order_crit_milestones = '`trashed_on`'; $order_crit_webpages = '`trashed_on`'; $order_crit_files = '`trashed_on`'; $order_crit_emails = '`trashed_on`'; $order_crit_comments = '`trashed_on`'; $order_crit_messages = '`trashed_on`'; $order_crit_workspaces = '`updated_on`'; break; case 'archivedOn': $order_crit_companies = '`archived_on`'; $order_crit_contacts = '`archived_on`'; $order_crit_file_revisions = '`updated_on`'; $order_crit_calendar = '`archived_on`'; $order_crit_tasks = '`archived_on`'; $order_crit_milestones = '`archived_on`'; $order_crit_webpages = '`archived_on`'; $order_crit_files = '`archived_on`'; $order_crit_emails = '`archived_on`'; $order_crit_comments = '`updated_on`'; $order_crit_messages = '`archived_on`'; $order_crit_workspaces = '`completed_on`'; break; case 'name': $order_crit_companies = '`name`'; $order_crit_contacts = "TRIM(CONCAT(' ', `lastname`, `firstname`, `middlename`))"; $order_crit_file_revisions = "'zzzzzzzzzzzzzz'"; //Revisar $order_crit_calendar = '`subject`'; $order_crit_tasks = '`title`'; $order_crit_milestones = '`name`'; $order_crit_webpages = '`title`'; $order_crit_files = '`filename`'; $order_crit_emails = '`subject`'; $order_crit_comments = '`text`'; $order_crit_messages = '`title`'; $order_crit_workspaces = '`name`'; break; default: $order_crit_companies = '`updated_on`'; $order_crit_contacts = '`updated_on`'; $order_crit_file_revisions = '`updated_on`'; $order_crit_calendar = '`updated_on`'; $order_crit_tasks = '`updated_on`'; $order_crit_milestones = '`updated_on`'; $order_crit_webpages = '`updated_on`'; $order_crit_files = '`updated_on`'; $order_crit_emails = '`received_date`'; $order_crit_comments = '`updated_on`'; $order_crit_messages = '`updated_on`'; $order_crit_workspaces = '`updated_on`'; break; } if ($project instanceof Project) { $proj_ids = $project->getAllSubWorkspacesQuery(true); $proj_cond_companies = Companies::getWorkspaceString($proj_ids); $proj_cond_messages = ProjectMessages::getWorkspaceString($proj_ids); $proj_cond_documents = ProjectFiles::getWorkspaceString($proj_ids); $proj_cond_emails = MailContents::getWorkspaceString($proj_ids); $proj_cond_events = ProjectEvents::getWorkspaceString($proj_ids); $proj_cond_tasks = ProjectTasks::getWorkspaceString($proj_ids); $proj_cond_charts = ProjectCharts::getWorkspaceString($proj_ids); $proj_cond_milestones = ProjectMilestones::getWorkspaceString($proj_ids); $proj_cond_weblinks = ProjectWebpages::getWorkspaceString($proj_ids); $proj_cond_contacts = Contacts::getWorkspaceString($proj_ids); } else { $proj_cond_companies = "true"; $proj_cond_messages = "true"; $proj_cond_documents = "true"; $proj_cond_emails = "true"; $proj_cond_events = "true"; $proj_cond_tasks = "true"; $proj_cond_charts = "true"; $proj_cond_milestones = "true"; $proj_cond_weblinks = "true"; $proj_cond_contacts = "true"; } if ($trashed) { if ($trashed === 'all') { $trashed_cond = '`trashed_on` >= ' . DB::escape(EMPTY_DATETIME); } else { $trashed_cond = '`trashed_on` > ' . DB::escape(EMPTY_DATETIME); } $archived_cond = '1 = 1'; // Show all objects in trash $comments_arch_cond = "1 = 1"; } else { $trashed_cond = '`trashed_on` = ' . DB::escape(EMPTY_DATETIME); if ($archived) { $archived_cond = "`archived_by_id` > 0"; $comments_arch_cond = "1 = 0"; // Don't show comments in archived objects listings } else { $archived_cond = "`archived_by_id` = 0"; $comments_arch_cond = "1 = 1"; } } if (isset($tag) && $tag && $tag != '') { $tag_str = " AND EXISTS (SELECT * FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag`= " . DB::escape($tag) . " AND `co`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = `object_manager_value`) "; } else { $tag_str = ' '; } if ($linkedObject instanceof ProjectDataObject) { $link_id = $linkedObject->getId(); $link_mgr = get_class($linkedObject->manager()); $link_str = " AND EXISTS (SELECT * FROM `" . TABLE_PREFIX . "linked_objects` `t` WHERE\n\t\t\t(`t`.`object_id`=" . DB::escape($link_id) . " AND `t`.object_manager = " . DB::escape($link_mgr) . " AND `co`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = `object_manager_value`) OR\n\t\t\t(`t`.`rel_object_id`=" . DB::escape($link_id) . " AND `t`.rel_object_manager = " . DB::escape($link_mgr) . " AND `co`.`id` = `t`.`object_id` AND `t`.`object_manager` = `object_manager_value`)) "; } else { $link_str = ' '; } $tag_str .= $link_str; $res = array(); /** If the name of the query ends with Comments it is assumed to be a list of Comments **/ $cfn = ''; if ($filterName != '') { $cfn = " AND text LIKE '%" . $filterName . "%'"; } // Notes if (module_enabled('notes')) { $fn = ''; if ($filterName != '') { $fn = " AND title LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectMessages::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectMessages") { $res['ProjectMessages'] = "SELECT 'ProjectMessages' AS `object_manager_value`, `id` AS `oid`, {$order_crit_messages} AS `order_value` FROM `" . TABLE_PREFIX . "project_messages` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_messages . str_replace('= `object_manager_value`', "= 'ProjectMessages'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectMessagesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectMessages' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_messages` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_messages . str_replace('= `object_manager_value`', "= 'ProjectMessages'", $tag_str) . $permissions . $cfn . ")"; } } // Events if (module_enabled("calendar")) { $fn = ''; if ($filterName != '') { $fn = " AND subject LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectEvents::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectEvents") { $res['ProjectEvents'] = "SELECT 'ProjectEvents' AS `object_manager_value`, `id` AS `oid`, {$order_crit_calendar} AS `order_value` FROM `" . TABLE_PREFIX . "project_events` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_events . str_replace('= `object_manager_value`', "= 'ProjectEvents'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectEventsComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectEvents' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_events` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_events . str_replace('= `object_manager_value`', "= 'ProjectEvents'", $tag_str) . $permissions . $cfn . ")"; } } // Documents if (module_enabled("documents")) { $fn = ''; if ($filterName != '') { $fn = " AND filename LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectFiles::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; $typestring = array_var($_GET, "typestring"); if ($typestring) { $typecond = " AND ((SELECT count(*) FROM `" . TABLE_PREFIX . "project_file_revisions` `pfr` WHERE `" . "pfr`.`type_string` LIKE " . DB::escape($typestring) . " AND `" . "co`.`id` = `pfr`.`file_id`) > 0)"; } else { $typecond = ""; } if ($filterManager == '' || $filterManager == "ProjectFiles") { $res['ProjectFiles'] = "SELECT 'ProjectFiles' AS `object_manager_value`, `id` as `oid`, {$order_crit_files} AS `order_value` FROM `" . TABLE_PREFIX . "project_files` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'ProjectFiles'", $tag_str) . $permissions . $typecond . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectFilesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectFiles' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_files` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'ProjectFiles'", $tag_str) . $permissions . $cfn . ")"; } if ($trashed) { $file_rev_docs = "SELECT `id` FROM `" . TABLE_PREFIX . "project_files` `co` WHERE `trashed_by_id` = 0 AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'ProjectFiles'", $tag_str) . $permissions . $typecond; $res['FileRevisions'] = "SELECT 'ProjectFileRevisions' AS `object_manager_value`, `id` AS `oid`, {$order_crit_file_revisions} AS `order_value` FROM `" . TABLE_PREFIX . "project_file_revisions` `co` WHERE {$trashed_cond} AND `file_id` IN (" . $file_rev_docs . ")"; } } // Tasks and Milestones if (module_enabled("tasks")) { $fn = ''; if ($filterName != '') { $fn = " AND title LIKE '%" . $filterName . "%'"; } $completed = $trashed || $archived ? '' : 'AND `completed_on` = ' . DB::escape(EMPTY_DATETIME); $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectTasks::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectTasks") { $res['ProjectTasks'] = "SELECT 'ProjectTasks' AS `object_manager_value`, `id` AS `oid`, {$order_crit_tasks} AS `order_value` FROM `" . TABLE_PREFIX . "project_tasks` `co` WHERE `is_template` = false {$completed} AND " . $trashed_cond . " AND {$archived_cond} AND `is_template` = false AND " . $proj_cond_tasks . str_replace('= `object_manager_value`', "= 'ProjectTasks'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectTasksComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectTasks' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_tasks` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND `is_template` = false AND " . $proj_cond_tasks . str_replace('= `object_manager_value`', "= 'ProjectTasks'", $tag_str) . $permissions . $cfn . ")"; } $fn = ''; if ($filterName != '') { $fn = " AND name LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectMilestones::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectMilestones") { $res['ProjectMilestones'] = "SELECT 'ProjectMilestones' AS `object_manager_value`, `id` AS `oid`, {$order_crit_milestones} AS `order_value` FROM `" . TABLE_PREFIX . "project_milestones` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND `is_template` = false AND " . $proj_cond_milestones . str_replace('= `object_manager_value`', "= 'ProjectMilestones'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectMilestonesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectMilestones' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_milestones` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND `is_template` = false AND " . $proj_cond_milestones . str_replace('= `object_manager_value`', "= 'ProjectMilestones'", $tag_str) . $permissions . $cfn . ")"; } } // Weblinks if (module_enabled("weblinks")) { $fn = ''; if ($filterName != '') { $fn = " AND title LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectWebpages::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectWebpages") { $res['ProjectWebPages'] = "SELECT 'ProjectWebPages' AS `object_manager_value`, `id` AS `oid`, {$order_crit_webpages} AS `order_value` FROM `" . TABLE_PREFIX . "project_webpages` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_weblinks . str_replace('= `object_manager_value`', "= 'ProjectWebpages'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectWebPagesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectWebpages' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_webpages` `co` WHERE " . $trashed_cond . " AND {$comments_arch_cond} AND " . $proj_cond_weblinks . str_replace('= `object_manager_value`', "= 'ProjectWebpages'", $tag_str) . $permissions . $cfn . ")"; } } // Email if (module_enabled("email")) { $fn = ''; if ($filterName != '') { $fn = " AND subject LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(MailContents::instance(), ACCESS_LEVEL_READ, logged_user(), $project instanceof Project ? $project->getId() : 0, '`co`') . ')'; if ($filterManager == '' || $filterManager == "MailContents") { $res['MailContents'] = "SELECT 'MailContents' AS `object_manager_value`, `id` AS `oid`, {$order_crit_emails} AS `order_value` FROM `" . TABLE_PREFIX . "mail_contents` `co` WHERE (" . $trashed_cond . " AND {$archived_cond} AND `is_deleted` = 0 AND " . $proj_cond_emails . str_replace('= `object_manager_value`', "= 'MailContents'", $tag_str) . $permissions . ") {$fn}"; } if ($filterManager == '' || $filterManager == "Comments") { $res['MailContentsComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'MailContents' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "mail_contents` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_emails . str_replace('= `object_manager_value`', "= 'MailContents'", $tag_str) . $permissions . $cfn . ")"; } } // Conacts and Companies if (module_enabled("contacts")) { $fn = ''; $fn2 = ''; if ($filterName != '') { $fn = " AND firstname LIKE '%" . $filterName . "%'"; $fn2 = " AND name LIKE '%" . $filterName . "%'"; } // companies $permissions = ' AND ( ' . permissions_sql_for_listings(Companies::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "Companies") { $res['Companies'] = "SELECT 'Companies' AS `object_manager_value`, `id` as `oid`, {$order_crit_companies} AS `order_value` FROM `" . TABLE_PREFIX . "companies` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_companies . str_replace('= `object_manager_value`', "= 'Companies'", $tag_str) . $permissions . $fn2; } $res['CompaniesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'Companies' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "companies` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'Companies'", $tag_str) . $permissions . $cfn . ")"; // contacts $permissions = ' AND ( ' . permissions_sql_for_listings(Contacts::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "Contacts") { $res['Contacts'] = "SELECT 'Contacts' AS `object_manager_value`, `id` AS `oid`, {$order_crit_contacts} AS `order_value` FROM `" . TABLE_PREFIX . "contacts` `co` WHERE {$trashed_cond} AND {$archived_cond} AND {$proj_cond_contacts} " . str_replace('= `object_manager_value`', "= 'Contacts'", $tag_str) . $permissions . $fn; } $res['ContactsComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'Contacts' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "contacts` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'Contacts'", $tag_str) . $permissions . $cfn . ")"; } // Workspaces (only for archived objects view) if ($archived) { if ($filterManager == '' || $filterManager == "Projects") { $res['Projects'] = "SELECT 'Projects' AS `object_manager_value`, `id` AS `oid`, {$order_crit_workspaces} AS `order_value` FROM `" . TABLE_PREFIX . "projects` `co` WHERE `completed_on` <> " . DB::escape(EMPTY_DATETIME) . " AND `id` IN (" . logged_user()->getWorkspacesQuery() . ")"; } } if ($count) { foreach ($res as $p => $q) { $res[$p] = "SELECT count(*) AS `quantity`, '{$p}' AS `objectName` FROM ( {$q} ) `table_alias`"; } } return $res; }