]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Trackers/Tracker.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Trackers / Tracker.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37
38
39 if(!class_exists('Tracker')){
40
41 require_once 'data/SugarBean.php';
42
43 class Tracker extends SugarBean
44 {
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(
53         "id",
54         "monitor_id",
55         "user_id",
56         "module_name",
57         "item_id",
58         "item_summary",
59         "date_modified",
60         "action",
61         "session_id",
62         "visible"
63     );
64
65     function Tracker()
66     {
67         global $dictionary;
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);
71             require_once($path);
72         }
73         parent::SugarBean();
74     }
75
76     /*
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']
79      * @param uid user_id
80      * @param mixed module_name Optional - return only items from this module, a string of the module or array of modules
81      * @return array list
82      */
83     function get_recently_viewed($user_id, $modules = '')
84     {
85         $path = 'modules/Trackers/BreadCrumbStack.php';
86         if(defined('TEMPLATE_URL'))$path = SugarTemplateUtilities::getFilePath($path);
87         require_once($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)));
92         } else {
93                         $breadCrumb = $_SESSION['breadCrumbs'];
94                 $module_query = '';
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 . '\'';
98                 } else {
99                    $history_max_viewed = (!empty($GLOBALS['sugar_config']['history_max_viewed']))? $GLOBALS['sugar_config']['history_max_viewed'] : 50;
100                 }
101                  
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);
106                 }
107         }     
108
109         $list = $breadCrumb->getBreadCrumbList($modules);
110         $GLOBALS['log']->info("Tracker: retrieving ".count($list)." items");
111         return $list;
112     }
113
114     function makeInvisibleForAll($item_id)
115     {
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);
120         require_once($path);
121         if(!empty($_SESSION['breadCrumbs'])){
122             $breadCrumbs = $_SESSION['breadCrumbs'];
123             $breadCrumbs->popItem($item_id);
124         }
125     }
126
127     function logPage(){
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     }
134
135
136     /**
137      * bean_implements
138      * Override method to support ACL roles
139      */
140     function bean_implements($interface){
141         return false;
142     }
143 }
144 }