]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Trackers/Tracker.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Trackers / Tracker.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 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
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
51     var $column_fields = Array(
52         "id",
53         "monitor_id",
54         "user_id",
55         "module_name",
56         "item_id",
57         "item_summary",
58         "date_modified",
59                 "action",
60         "session_id",
61         "visible"
62     );
63
64     function Tracker()
65     {
66         global $dictionary;
67         if(isset($this->module_dir) && isset($this->object_name) && !isset($GLOBALS['dictionary'][$this->object_name])){
68             $path = 'modules/Trackers/vardefs.php';
69                         if(defined('TEMPLATE_URL'))$path = SugarTemplateUtilities::getFilePath($path);
70                 require_once($path);
71         }
72         parent::SugarBean();
73     }
74         
75     /*
76      * Return the most recently viewed items for this user.
77      * The number of items to return is specified in sugar_config['history_max_viewed']
78      * @param uid user_id
79      * @param mixed module_name Optional - return only items from this module, a string of the module or array of modules
80      * @return array list
81      */
82         function get_recently_viewed($user_id, $modules = '')
83     {
84         $path = 'modules/Trackers/BreadCrumbStack.php';
85                 if(defined('TEMPLATE_URL'))$path = SugarTemplateUtilities::getFilePath($path);
86         require_once($path);
87         if(empty($_SESSION['breadCrumbs'])) { 
88             $breadCrumb = new BreadCrumbStack($user_id, $modules);
89             $_SESSION['breadCrumbs'] = $breadCrumb;
90             $GLOBALS['log']->info(string_format($GLOBALS['app_strings']['LBL_BREADCRUMBSTACK_CREATED'], array($user_id)));
91         } else {
92                 $breadCrumb = $_SESSION['breadCrumbs'];
93                 $module_query = '';
94                 if(!empty($modules)) {
95                    $history_max_viewed = 10;
96                    $module_query = is_array($modules) ? ' AND module_name IN (\'' . implode("','" , $modules) . '\')' :  ' AND module_name = \'' . $modules . '\'';
97                 } else {
98                    $history_max_viewed = (!empty($GLOBALS['sugar_config']['history_max_viewed']))? $GLOBALS['sugar_config']['history_max_viewed'] : 50;
99                 }
100                  
101                 $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 visible = 1' . $module_query . ')';
102                 $result = $this->db->limitQuery($query,0,$history_max_viewed,true,$query);
103                 while(($row = $this->db->fetchByAssoc($result))) {
104                        $breadCrumb->push($row);
105                 }
106         }     
107         $list = $breadCrumb->getBreadCrumbList($modules);
108         $GLOBALS['log']->info("Tracker: retrieving ".count($list)." items");    
109         return $list;
110     }
111
112         function makeInvisibleForAll($item_id)
113     {
114         $query = "UPDATE $this->table_name SET visible = 0 WHERE item_id = '$item_id' AND visible = 1";
115         $this->db->query($query, true);
116         $path = 'modules/Trackers/BreadCrumbStack.php';
117                 if(defined('TEMPLATE_URL'))$path = SugarTemplateUtilities::getFilePath($path);
118         require_once($path);
119         if(!empty($_SESSION['breadCrumbs'])){
120                 $breadCrumbs = $_SESSION['breadCrumbs'];
121                 $breadCrumbs->popItem($item_id);
122         }
123     }
124
125     function logPage(){
126         $time_on_last_page = 0;
127         //no need to calculate it if it is a redirection page
128         if(empty($GLOBALS['app']->headerDisplayed ))return;
129         if(!empty($_SESSION['lpage']))$time_on_last_page = time() - $_SESSION['lpage'];
130         $_SESSION['lpage']=time();
131         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";
132     }
133
134         
135     /**
136      * bean_implements
137      * Override method to support ACL roles
138      */
139         function bean_implements($interface){
140                 return false;
141         }
142 }
143 }