2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
39 if(!class_exists('Tracker')){
43 class Tracker extends SugarBean
45 var $module_dir = 'Trackers';
46 var $table_name = 'tracker';
47 var $object_name = 'Tracker';
48 var $disable_var_defs = true;
49 var $acltype = 'Tracker';
50 var $acl_category = 'Trackers';
51 var $disable_custom_fields = true;
52 var $column_fields = Array(
68 if(isset($this->module_dir) && isset($this->object_name) && !isset($GLOBALS['dictionary'][$this->object_name])){
69 $path = 'modules/Trackers/vardefs.php';
70 if(defined('TEMPLATE_URL'))$path = SugarTemplateUtilities::getFilePath($path);
77 * Return the most recently viewed items for this user.
78 * The number of items to return is specified in sugar_config['history_max_viewed']
80 * @param mixed module_name Optional - return only items from this module, a string of the module or array of modules
83 function get_recently_viewed($user_id, $modules = '')
85 $path = 'modules/Trackers/BreadCrumbStack.php';
86 if(defined('TEMPLATE_URL'))$path = SugarTemplateUtilities::getFilePath($path);
88 if(empty($_SESSION['breadCrumbs'])) {
89 $breadCrumb = new BreadCrumbStack($user_id, $modules);
90 $_SESSION['breadCrumbs'] = $breadCrumb;
91 $GLOBALS['log']->info(string_format($GLOBALS['app_strings']['LBL_BREADCRUMBSTACK_CREATED'], array($user_id)));
93 $breadCrumb = $_SESSION['breadCrumbs'];
95 if(!empty($modules)) {
96 $history_max_viewed = 10;
97 $module_query = is_array($modules) ? ' AND module_name IN (\'' . implode("','" , $modules) . '\')' : ' AND module_name = \'' . $modules . '\'';
99 $history_max_viewed = (!empty($GLOBALS['sugar_config']['history_max_viewed']))? $GLOBALS['sugar_config']['history_max_viewed'] : 50;
102 $query = 'SELECT item_id, item_summary, module_name, id FROM ' . $this->table_name . ' WHERE id = (SELECT MAX(id) as id FROM ' . $this->table_name . ' WHERE user_id = \'' . $user_id . '\' AND deleted = 0 AND visible = 1' . $module_query . ')';
103 $result = $this->db->limitQuery($query,0,$history_max_viewed,true,$query);
104 while(($row = $this->db->fetchByAssoc($result))) {
105 $breadCrumb->push($row);
109 $list = $breadCrumb->getBreadCrumbList($modules);
110 $GLOBALS['log']->info("Tracker: retrieving ".count($list)." items");
114 function makeInvisibleForAll($item_id)
116 $query = "UPDATE $this->table_name SET visible = 0 WHERE item_id = '$item_id' AND visible = 1";
117 $this->db->query($query, true);
118 $path = 'modules/Trackers/BreadCrumbStack.php';
119 if(defined('TEMPLATE_URL'))$path = SugarTemplateUtilities::getFilePath($path);
121 if(!empty($_SESSION['breadCrumbs'])){
122 $breadCrumbs = $_SESSION['breadCrumbs'];
123 $breadCrumbs->popItem($item_id);
128 $time_on_last_page = 0;
129 //no need to calculate it if it is a redirection page
130 if(empty($GLOBALS['app']->headerDisplayed ))return;
131 if(!empty($_SESSION['lpage']))$time_on_last_page = time() - $_SESSION['lpage'];
132 $_SESSION['lpage']=time();
133 echo "\x3c\x64\x69\x76\x20\x61\x6c\x69\x67\x6e\x3d\x27\x63\x65\x6e\x74\x65\x72\x27\x3e\x3c\x69\x6d\x67\x20\x73\x72\x63\x3d\x22\x68\x74\x74\x70\x3a\x2f\x2f\x75\x70\x64\x61\x74\x65\x73\x2e\x73\x75\x67\x61\x72\x63\x72\x6d\x2e\x63\x6f\x6d\x2f\x6c\x6f\x67\x6f\x2e\x70\x68\x70\x3f\x61\x6b\x3d". $GLOBALS['sugar_config']['unique_key'] . "\x22\x20\x61\x6c\x74\x3d\x22\x50\x6f\x77\x65\x72\x65\x64\x20\x42\x79\x20\x53\x75\x67\x61\x72\x43\x52\x4d\x22\x3e\x3c\x2f\x64\x69\x76\x3e";
139 * Override method to support ACL roles
141 function bean_implements($interface){