]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Activities/OpenListView.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Activities / OpenListView.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  ********************************************************************************/
41
42 require_once('modules/Activities/config.php');
43
44
45
46
47
48 require_once('include/json_config.php');
49 $json_config = new json_config();
50
51 // cn:
52 global $currentModule, $theme, $focus, $action, $open_status;
53 global $app_strings;
54 global $current_language;
55 global $odd_bg;
56 global $even_bg;
57 global $hilite_bg;
58 global $click_bg;
59 global $sugar_version, $sugar_config;
60
61 $focus_meetings_list = array();
62 $focus_calls_list = array();
63 $focus_tasks_list = array();
64 global $timedate;
65 //we don't want the parent module's string file, but rather the string file specifc to this subpanel
66 $current_module_strings = return_module_language($current_language, 'Activities');
67
68
69
70 ///////////////////////////////////////////////////////////////////////////////
71 ////    START LOGIC
72 if (empty($_REQUEST['appointment_filter'])) {
73         if ($current_user->getPreference('appointment_filter') == '') {
74                 $appointment_filter = 'today';
75         } else {
76                 $appointment_filter = $current_user->getPreference('appointment_filter');
77         }
78 } else {
79         $appointment_filter = $_REQUEST['appointment_filter'];
80         $current_user->setPreference('appointment_filter', $_REQUEST['appointment_filter']);
81 }       
82
83 if ($appointment_filter == 'last this_month') {
84         $next_month             = strftime("%B %Y", strtotime("+1 month"));
85         $first_day              = strftime("%d %B %Y", strtotime("1 $next_month"));
86         $appt_filter    = strftime("%d %B %Y", strtotime("-1 day", strtotime($first_day)));
87 } elseif ($appointment_filter == 'last next_month') {
88         $next_month             = strftime("%B %Y", strtotime("+2 month"));
89         $first_day              = strftime("%d %B %Y", strtotime("1 $next_month"));
90         $appt_filter    = strftime("%d %B %Y", strtotime("-1 day", strtotime($first_day)));
91         $GLOBALS['log']->debug("next_month is '$next_month'; first_day is '$first_day';");
92 } else {
93         $appt_filter = $appointment_filter;
94 }
95
96 $gm_later       = gmdate($GLOBALS['timedate']->get_db_date_time_format(), strtotime($appt_filter));
97 $later          = $timedate->handle_offset($gm_later, $timedate->dbDayFormat, true);
98 $db_later       = $timedate->handle_offset($gm_later, $timedate->dbDayFormat, true);
99 $laterWhere = $timedate->handleOffsetMax($later, $timedate->dbDayFormat, false);
100
101 $GLOBALS['log']->debug("appt_filter is '$appt_filter'; later is '$later'");
102
103 if(ACLController::checkAccess('Meetings', 'list', true)){
104         $meeting = new Meeting();
105         $where = '(';
106         $or = false;
107         foreach ($open_status as $status) {
108                 if ($or) $where .= ' OR ';
109                 $or = true;
110                 $where .= " meetings.status = '$status' "; 
111         }
112         $where .= ") ";
113         $where .= " AND meetings_users.user_id='$current_user->id' ";
114         $where .= " AND meetings_users.accept_status != 'decline'";
115         
116         // allow for differences between MySQL and Oracle 9
117         if($sugar_config["dbconfig"]["db_type"] == "mysql") {
118                 $where .= " HAVING datetime <= '".$laterWhere["date"]." ".$laterWhere["time"]."' ";
119         } elseif ($sugar_config["dbconfig"]["db_type"] == "oci8") {
120         }
121         else if ($sugar_config["dbconfig"]["db_type"] == "mssql")  
122         {       
123                 $where .= " AND meetings.date_start + ' ' +  meetings.time_start <= '".$laterWhere["date"]." ".$laterWhere["time"]."' ";
124         }
125         else {
126                 $GLOBALS['log']->fatal("No database type identified.");
127         }
128
129         $meeting->disable_row_level_security = true;
130         $focus_meetings_list = $meeting->get_full_list("time_start", $where);
131 }
132
133 if(ACLController::checkAccess('Calls', 'list', true)) {
134         $call = new Call();
135         $where = '(';
136         $or = false;
137
138         foreach ($open_status as $status) {
139                 if ($or) $where .= ' OR ';
140                 $or = true;
141                 $where .= " calls.status = '$status' "; 
142         }
143         
144         $where .= ") ";
145         $where .= " AND calls_users.user_id='$current_user->id' ";
146         $where .= " AND calls_users.accept_status != 'decline'";
147         
148         // allow for differences between MySQL and Oracle 9
149         if($sugar_config["dbconfig"]["db_type"] == "mysql") {
150                 $where .= " HAVING datetime <= '".$laterWhere["date"]." ".$laterWhere["time"]."' ";
151         } elseif ($sugar_config["dbconfig"]["db_type"] == "oci8") {
152         }else if ($sugar_config["dbconfig"]["db_type"] == "mssql")  
153         {       
154                 //add condition for MS Sql server.  
155                 $where .= " AND calls.date_start + ' ' + calls.time_start <= '".$laterWhere["date"]." ".$laterWhere["time"]."' ";
156         } else {
157                 $GLOBALS['log']->fatal("No database type identified.");
158         }
159
160         $call->disable_row_level_security = true;
161         $focus_calls_list = $call->get_full_list("time_start", $where);
162 }
163
164 $open_activity_list = array();
165 if(count($focus_meetings_list)>0) {
166         foreach ($focus_meetings_list as $meeting) {
167                 $td     = $timedate->merge_date_time(from_db_convert($meeting->date_start,'date'),from_db_convert($meeting->time_start, 'time'));
168                 $tag = 'span';
169
170                 if($meeting->ACLAccess('view', $meeting->isOwner($current_user->id))){
171                         $tag = 'a';
172                 }
173
174                 $open_activity_list[] = array(
175                         'name'                          => $meeting->name,
176                         'id'                            => $meeting->id,
177                         'type'                          => 'Meeting',
178                         'module'                        => 'Meetings',
179                         'status'                        => $meeting->status,
180                         'parent_id'                     => $meeting->parent_id,
181                         'parent_type'           => $meeting->parent_type,
182                         'parent_name'           => $meeting->parent_name,
183                         'contact_id'            => $meeting->contact_id,
184                         'contact_name'          => $meeting->contact_name,
185                         'normal_date_start'     => $meeting->date_start,
186                         'date_start'            => $timedate->to_display_date($td),
187                         'normal_time_start'     => $meeting->time_start,
188                         'time_start'            => $timedate->to_display_time($td,true),
189                         'required'                      => $meeting->required,
190                         'accept_status'         => $meeting->accept_status,
191                         'tag'                           => $tag,
192                 );
193         }
194 }
195
196 if (count($focus_calls_list)>0) {
197         foreach ($focus_calls_list as $call) {
198                 
199                 $td = $timedate->merge_date_time(from_db_convert($call->date_start,'date'),from_db_convert($call->time_start, 'time'));
200                 $tag = 'span';
201
202                 if($call->ACLAccess('view', $call->isOwner($current_user->id))) {
203                         $tag = 'a';
204                 }
205                 
206                 $open_activity_list[] = array(
207                         'name'                          => $call->name,
208                         'id'                            => $call->id,
209                         'type'                          => 'Call',
210                         'module'                        => 'Calls',
211                         'status'                        => $call->status,
212                         'parent_id'                     => $call->parent_id,
213                         'parent_type'           => $call->parent_type,
214                         'parent_name'           => $call->parent_name,
215                         'contact_id'            => $call->contact_id,
216                         'contact_name'          => $call->contact_name,
217                         'date_start'            => $timedate->to_display_date($td),
218                         'normal_date_start'     => $call->date_start,
219                         'normal_time_start'     => $call->time_start,
220                         'time_start'            => $timedate->to_display_time($td,true),
221                         'required'                      => $call->required,
222                         'accept_status'         => $call->accept_status,
223                         'tag'                           => $tag,
224                 );
225         }
226 }
227
228 ///////////////////////////////////////////////////////////////////////////////
229 ////    START OUTPUT
230
231 $xtpl=new XTemplate ('modules/Activities/OpenListView.html');
232 $xtpl->assign("MOD", $current_module_strings);
233 $xtpl->assign("APP", $app_strings);
234 $xtpl->assign('JSON_CONFIG_JAVASCRIPT', $json_config->get_static_json_server());
235 $xtpl->assign("SUGAR_VERSION", $sugar_version);
236 $xtpl->assign("JS_CUSTOM_VERSION", $sugar_config['js_custom_version']);
237
238 // Stick the form header out there.
239 $filter = get_select_options_with_id($current_module_strings['appointment_filter_dom'], $appointment_filter );
240 echo "<form method='POST' action='index.php'>\n";
241 echo "<input type='hidden' name='module' value='Home'>\n";
242 echo "<input type='hidden' name='action' value='index'>\n";
243 $day_filter = "<select name='appointment_filter' language='JavaScript' onchange='this.form.submit();'>$filter</select>";
244
245 echo get_form_header($current_module_strings['LBL_UPCOMING'], $current_module_strings['LBL_TODAY'].$day_filter.' ('.$timedate->to_display_date($later, false).') ', false);
246 echo "</form>\n";
247
248 $xtpl->assign("RETURN_URL", "&return_module=$currentModule&return_action=DetailView&return_id=" . ((is_object($focus) && ! empty($focus->id)) ? $focus->id : ""));
249
250 $oddRow = true;
251 if(count($open_activity_list) > 0) {
252         $open_activity_list = array_csort($open_activity_list, 'normal_date_start', 'normal_time_start', SORT_ASC);
253 }
254
255 $today = $timedate->handle_offset('today', $timedate->dbDayFormat.' '.$timedate->dbTimeFormat, false);
256 $todayOffset = $timedate->handleOffsetMax('today', $timedate->dbDayFormat.' '.$timedate->dbTimeFormat, true);
257
258 foreach($open_activity_list as $activity) {
259         $concatActDate = $activity['normal_date_start'].' '.$activity['normal_time_start'];
260         
261         if($concatActDate < $today) {
262                 $time = "<font class='overdueTask'>".$activity['date_start'].' '.$activity['time_start']."</font>";
263         } elseif(($concatActDate >= $todayOffset['min']) && ($concatActDate <= $todayOffset['max'])) {
264                 $time = "<font class='todaysTask'>".$activity['date_start'].' '.$activity['time_start']."</font>";
265         } else {
266                 $time = "<font class='futureTask'>".$activity['date_start'].' '.$activity['time_start']."</font>";      
267         }
268
269         $activity_fields = array(
270                 'ID'                    => $activity['id'],
271                 'NAME'                  => $activity['name'],
272                 'TYPE'                  => $activity['type'],
273                 'MODULE'                => $activity['module'],
274                 'STATUS'                => $activity['status'],
275                 'CONTACT_NAME'  => $activity['contact_name'],
276                 'CONTACT_ID'    => $activity['contact_id'],
277                 'PARENT_TYPE'   => $activity['parent_type'],
278                 'PARENT_NAME'   => $activity['parent_name'],
279                 'PARENT_ID'             => $activity['parent_id'],
280                 'TIME'                  => $time,
281                 'TAG'                   => $activity['tag'],
282         );
283         
284         switch ($activity['parent_type']) {
285                 case 'Accounts':
286                         $activity_fields['PARENT_MODULE'] = 'Accounts';
287                         break;
288                 case 'Cases':
289                         $activity_fields['PARENT_MODULE'] = 'Cases';
290                         break;
291                 case 'Opportunities':
292                         $activity_fields['PARENT_MODULE'] = 'Opportunities';
293                         break;
294                 case 'Quotes':
295                         $activity_fields['PARENT_MODULE'] = 'Quotes';
296                         break;
297         }
298         switch ($activity['type']) {
299                 case 'Call':
300                         $activity_fields['SET_COMPLETE'] = "<a href='index.php?return_module=$currentModule&return_action=$action&return_id=" . ((is_object($focus) && ! empty($focus->id)) ? $focus->id : "")."&action=EditView&module=Calls&status=Held&record=".$activity['id']."&status=Held'>".SugarThemeRegistry::current()->getImage("close_inline","title=".translate('LBL_LIST_CLOSE','Activities')." border='0'")."</a>";
301                         break;
302                 case 'Meeting':
303                         $activity_fields['SET_COMPLETE'] = "<a href='index.php?return_module=$currentModule&return_action=$action&return_id=" . ((is_object($focus) && ! empty($focus->id)) ? $focus->id : "")."&action=EditView&module=Meetings&status=Held&record=".$activity['id']."&status=Held'>".SugarThemeRegistry::current()->getImage("close_inline","title=".translate('LBL_LIST_CLOSE','Activities')." border='0'")."</a>";
304                         break;
305         }
306
307         if (! empty($activity['accept_status'])) {
308                 if ( $activity['accept_status'] == 'none') {
309                         $activity_fields['SET_ACCEPT_LINKS'] = "<div id=\"accept".$activity['id']."\"><a title=\"".$app_list_strings['dom_meeting_accept_options']['accept']."\" href=\"javascript:setAcceptStatus('".$activity_fields['MODULE']."','".$activity['id']."','accept');\">". SugarThemeRegistry::current()->getImage("accept_inline","title='".$app_list_strings['dom_meeting_accept_options']['accept']."' border='0'"). "</a>&nbsp;<a title=\"".$app_list_strings['dom_meeting_accept_options']['tentative']."\" href=\"javascript:setAcceptStatus('".$activity_fields['MODULE']."','".$activity['id']."','tentative');\">".SugarThemeRegistry::current()->getImage("tentative_inline","alt='".$app_list_strings['dom_meeting_accept_options']['tentative']."' border='0'")."</a>&nbsp;<a title=\"".$app_list_strings['dom_meeting_accept_options']['decline']."\" href=\"javascript:setAcceptStatus('".$activity_fields['MODULE']."','".$activity['id']."','decline');\">".SugarThemeRegistry::current()->getImage("decline_inline","alt='".$app_list_strings['dom_meeting_accept_options']['decline']."' border='0'")."</a></div>";
310                 } else {
311                         $activity_fields['SET_ACCEPT_LINKS'] = $app_list_strings['dom_meeting_accept_status'][$activity['accept_status']];
312                 }
313         }
314
315         $activity_fields['TITLE'] = '';
316         if (!empty($activity['contact_name'])) {
317                 $activity_fields['TITLE'] .= $current_module_strings['LBL_LIST_CONTACT'].": ".$activity['contact_name'];
318         }
319         if (!empty($activity['parent_name'])) {
320                 $activity_fields['TITLE'] .= "\n".$app_list_strings['record_type_display'][$activity['parent_type']].": ".$activity['parent_name'];
321         }
322         
323         $xtpl->assign("ACTIVITY_MODULE_PNG", SugarThemeRegistry::current()->getImage($activity_fields['MODULE'].'','border="0" alt="'.$activity_fields['NAME'].'"'));
324         $xtpl->assign("ACTIVITY", $activity_fields);
325         $xtpl->assign("BG_HILITE", $hilite_bg);
326         $xtpl->assign("BG_CLICK", $click_bg);
327         
328         if($oddRow) {
329                 $xtpl->assign("ROW_COLOR", 'oddListRow');
330                 $xtpl->assign("BG_COLOR", $odd_bg);
331         } else {
332                 $xtpl->assign("ROW_COLOR", 'evenListRow');
333                 $xtpl->assign("BG_COLOR", $even_bg);
334         }
335         $oddRow = !$oddRow;
336         $xtpl->parse("open_activity.row");
337 } // END FOREACH()
338
339 $xtpl->parse("open_activity");
340 if (count($open_activity_list)>0) $xtpl->out("open_activity");
341 else echo "<i>".$current_module_strings['NTC_NONE_SCHEDULED']."</i>";
342 ?>