static function getChartsAtProject($project = null, $tag = null, $order = '`updated_on` DESC', $limit = 5) { if ($project instanceof Project) { $ws = ProjectCharts::getWorkspaceString($project->getAllSubWorkspacesQuery()) . ' AND `show_in_parents` = 1 OR '; $ws .= ProjectCharts::getWorkspaceString($project->getId()) . ' AND `show_in_project` = 1'; } else { $ws = "`show_in_parents` = 1"; } if ($tag) { $tagstr = " AND `id` IN (SELECT `rel_object_id` FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag` = " . DB::escape($tag) . " AND `t`.`rel_object_manager` = 'ProjectCharts')"; } else { $tagstr = ""; } return self::findAll(array('conditions' => "{$ws} {$tagstr}", 'order' => $order, 'limit' => $limit)); }
/** * Returns a new chart object given the specified chart id * * @param integer $chartId * @return ProjectChart */ function loadChart($chartId){ $chart = ProjectCharts::findById($chartId); $res = $this->getChart($chart->getTypeId()); $res->setFromAttributes($chart->getAcceptableAttributes()); $res->setDisplayId($chart->getDisplayId()); $res->setTypeId($chart->getTypeId()); $res->setTitle($chart->getTitle()); $res->setNew(false); $res->setId($chart->getId()); $res->setProject($chart->getProject()); $res->setCreatedById($chart->getCreatedById()); $res->setCreatedOn($chart->getCreatedOn()); $res->setDeleted($chart->isDeleted()); $res->setTags($chart->getTags()); $res->setUpdatedById($chart->getUpdatedById()); $res->setUpdatedOn($chart->getUpdatedOn()); return $res; }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'ProjectCharts')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return ProjectCharts::instance()->paginate($arguments, $items_per_page, $current_page); //$instance =& ProjectCharts::instance(); //return $instance->paginate($arguments, $items_per_page, $current_page); } // if }
function list_all() { ajx_current("empty"); $project = active_project(); $isProjectView = $project instanceof Project; $start = array_var($_GET, 'start'); $limit = array_var($_GET, 'limit'); if (!$start) { $start = 0; } if (!$limit) { $limit = config_option('files_per_page'); } $order = array_var($_GET, 'sort'); $orderdir = array_var($_GET, 'dir'); $tag = array_var($_GET, 'tag'); $page = (int) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'charts')); list($succ, $err) = ObjectController::do_delete_objects($ids, 'ProjectCharts'); if ($err > 0) { flash_error(lang('error delete objects', $err)); } else { flash_success(lang('success delete objects', $succ)); } } else { if (array_var($_GET, 'action') == 'tag') { $ids = explode(',', array_var($_GET, 'charts')); $tagTag = array_var($_GET, 'tagTag'); list($succ, $err) = ObjectController::do_tag_object($tagTag, $ids, 'ProjectCharts'); if ($err > 0) { flash_error(lang('error tag objects', $err)); } else { flash_success(lang('success tag objects', $succ)); } } } if ($page < 0) { $page = 1; } //$conditions = logged_user()->isMemberOfOwnerCompany() ? '' : ' `is_private` = 0'; if ($tag == '' || $tag == null) { $tagstr = " 1=1"; // dummy condition } else { $tagstr = "(select count(*) from " . TABLE_PREFIX . "tags where " . TABLE_PREFIX . "project_charts.id = " . TABLE_PREFIX . "tags.rel_object_id and " . TABLE_PREFIX . "tags.tag = '" . $tag . "' and " . TABLE_PREFIX . "tags.rel_object_manager ='ProjectCharts' ) > 0 "; } /* TODO: handle with permissions_sql_for_listings */ //$permission_str = ' AND (' . permissions_sql_for_listings(ProjectCharts::instance(), ACCESS_LEVEL_READ, logged_user()) . ')'; $permission_str = " AND " . ProjectCharts::getWorkspaceString(logged_user()->getWorkspacesQuery(true)); if ($isProjectView) { $pids = $project->getAllSubWorkspacesQuery(true); $project_str = " AND " . ProjectCharts::getWorkspaceString($pids); } else { $project_str = ""; } list($charts, $pagination) = ProjectCharts::paginate(array("conditions" => '`trashed_by_id` = 0 AND `archived_by_id` = 0 AND ' . $tagstr . $permission_str . $project_str, 'order' => '`title` ASC'), config_option('files_per_page', 10), $page); // paginate tpl_assign('totalCount', $pagination->getTotalItems()); tpl_assign('charts', $charts); tpl_assign('pagination', $pagination); tpl_assign('tags', Tags::getTagNames()); $object = array("totalCount" => $pagination->getTotalItems(), "charts" => array()); $factory = new ProjectChartFactory(); $types = $factory->getChartDisplays(); if (isset($charts)) { foreach ($charts as $c) { if ($c->getProject() instanceof Project) { $tags = project_object_tags($c); } else { $tags = ""; } $object["charts"][] = array("id" => $c->getId(), "name" => $c->getTitle(), "type" => $types[$c->getDisplayId()], "tags" => $tags, "project" => $c->getProject() ? $c->getProject()->getName() : '', "projectId" => $c->getProjectId()); } } ajx_extra_data($object); tpl_assign("listing", $object); }
function delete_chart() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $chart = ProjectCharts::findById(get_id()); if (!$chart instanceof ProjectChart) { flash_error(lang('chart dnx')); ajx_current("empty"); return; } // if if (!$chart->canDelete(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if try { DB::beginWork(); $chart->trash(); ApplicationLogs::createLog($chart, ApplicationLogs::ACTION_TRASH); DB::commit(); flash_success(lang('success deleted chart', $chart->getTitle())); ajx_current("back"); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete chart')); ajx_current("empty"); } // try }
/** * Return manager instance * * @access protected * @param void * @return ProjectCharts */ function manager() { if (!$this->manager instanceof ProjectCharts) { $this->manager = ProjectCharts::instance(); } return $this->manager; }
/** * 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; }
/** * Return manager instance * * @access protected * @param void * @return ProjectCharts */ function manager() { if(!($this->manager instanceof ProjectCharts)) $this->manager = ProjectCharts::instance(); return $this->manager; } // manager
/** * Show dashboard index page * * @param void * @return null */ function index() { $this->setHelp('dashboard'); $tag = array_var($_GET, 'active_tag'); $logged_user = logged_user(); if (active_project() instanceof Project) { $wscsv = active_project()->getAllSubWorkspacesQuery(true); } else { $wscsv = null; } $activity_log = null; $include_private = $logged_user->isMemberOfOwnerCompany(); $include_silent = $logged_user->isAdministrator(); $activity_log = ApplicationLogs::getOverallLogs($include_private, $include_silent, $wscsv, config_option('dashboard_logs_count', 15)); if (user_config_option('show charts widget') && module_enabled('reporting')) { $charts = ProjectCharts::getChartsAtProject(active_project(), active_tag()); tpl_assign('charts', $charts); if (BillingCategories::count() > 0 && active_project() instanceof Project) { tpl_assign('billing_chart_data', active_project()->getBillingTotalByUsers(logged_user())); } } if (user_config_option('show messages widget') && module_enabled('notes')) { list($messages, $pagination) = ProjectMessages::getMessages(active_tag(), active_project(), 0, 10, '`updated_on`', 'DESC', false); tpl_assign('messages', $messages); } if (user_config_option('show comments widget')) { $comments = Comments::getSubscriberComments(active_project(), $tag); tpl_assign('comments', $comments); } if (user_config_option('show documents widget') && module_enabled('documents')) { list($documents, $pagination) = ProjectFiles::getProjectFiles(active_project(), null, false, ProjectFiles::ORDER_BY_MODIFYTIME, 'DESC', 1, 10, false, active_tag(), null); tpl_assign('documents', $documents); } if (user_config_option('show emails widget') && module_enabled('email')) { $activeWs = active_project(); list($unread_emails, $pagination) = MailContents::getEmails($tag, null, 'received', 'unread', '', $activeWs, 0, 10); if ($activeWs && user_config_option('always show unread mail in dashboard')) { // add unread unclassified emails list($all_unread, $pagination) = MailContents::getEmails($tag, null, 'received', 'unread', 'unclassified', null, 0, 10); $unread_emails = array_merge($unread_emails, $all_unread); } tpl_assign('unread_emails', $unread_emails); } //Tasks widgets $show_pending = user_config_option('show pending tasks widget') && module_enabled('tasks'); $show_in_progress = user_config_option('show tasks in progress widget') && module_enabled('tasks'); $show_late = user_config_option('show late tasks and milestones widget') && module_enabled('tasks'); if ($show_pending || $show_in_progress || $show_late) { $assigned_to = explode(':', user_config_option('pending tasks widget assigned to filter')); $to_company = array_var($assigned_to, 0, 0); $to_user = array_var($assigned_to, 1, 0); tpl_assign('assigned_to_user_filter', $to_user); tpl_assign('assigned_to_company_filter', $to_company); } if ($show_pending) { $tasks = ProjectTasks::getProjectTasks(active_project(), ProjectTasks::ORDER_BY_DUEDATE, 'ASC', null, null, $tag, $to_company, $to_user, null, true, 'all', false, false, false, 10); tpl_assign('dashtasks', $tasks); } if ($show_in_progress) { $tasks_in_progress = ProjectTasks::getOpenTimeslotTasks(logged_user(), logged_user(), active_project(), $tag, $to_company, $to_user); tpl_assign('tasks_in_progress', $tasks_in_progress); } if ($show_late) { tpl_assign('today_milestones', $logged_user->getTodayMilestones(active_project(), $tag, 10)); tpl_assign('late_milestones', $logged_user->getLateMilestones(active_project(), $tag, 10)); tpl_assign('today_tasks', ProjectTasks::getDayTasksByUser(DateTimeValueLib::now(), $logged_user, active_project(), $tag, $to_company, $to_user, 10)); tpl_assign('late_tasks', ProjectTasks::getLateTasksByUser($logged_user, active_project(), $tag, $to_company, $to_user, 10)); } tpl_assign('activity_log', $activity_log); $usu = logged_user(); $conditions = array("conditions" => array("`state` >= 200 AND (`state`%2 = 0) AND `trashed_by_id`=0 AND `created_by_id` =" . $usu->getId())); $outbox_mails = MailContents::findAll($conditions); if ($outbox_mails != null) { if (count($outbox_mails) == 1) { flash_error(lang('outbox mail not sent', 1)); } else { if (count($outbox_mails) > 1) { flash_error(lang('outbox mails not sent', count($outbox_mails))); } } } ajx_set_no_toolbar(true); }