]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Activities/OpenListView.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Activities / OpenListView.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition 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 require_once('include/json_config.php');
44 $json_config = new json_config();
45
46 // cn:
47 global $currentModule, $theme, $focus, $action, $open_status;
48 global $app_strings;
49 global $current_language;
50 global $odd_bg;
51 global $even_bg;
52 global $hilite_bg;
53 global $click_bg;
54 global $sugar_version, $sugar_config;
55
56 $focus_meetings_list = array();
57 $focus_calls_list = array();
58 $focus_tasks_list = array();
59 global $timedate;
60 //we don't want the parent module's string file, but rather the string file specifc to this subpanel
61 $current_module_strings = return_module_language($current_language, 'Activities');
62
63
64
65 ///////////////////////////////////////////////////////////////////////////////
66 ////    START LOGIC
67 if (empty($_REQUEST['appointment_filter'])) {
68         if ($current_user->getPreference('appointment_filter') == '') {
69                 $appointment_filter = 'today';
70         } else {
71                 $appointment_filter = $current_user->getPreference('appointment_filter');
72         }
73 } else {
74         $appointment_filter = $_REQUEST['appointment_filter'];
75         $current_user->setPreference('appointment_filter', $_REQUEST['appointment_filter']);
76 }
77
78 if ($appointment_filter == 'last this_month') {
79     $laterDate = $timedate->getNow(true)->get("last day of this month");
80 } elseif ($appointment_filter == 'last next_month') {
81     $laterDate = $timedate->getNow(true)->get("last day of next month");
82 } else {
83         $laterDate = $timedate->fromString($appointment_filter);
84 }
85
86 $dayEnd = $timedate->asDb($laterDate->get_day_end_time());
87 $GLOBALS['log']->debug("filter $appointment_filter date $dayEnd");
88
89 if(ACLController::checkAccess('Meetings', 'list', true)){
90         $meeting = new Meeting();
91         $where = '(';
92         $or = false;
93         foreach ($open_status as $status) {
94                 if ($or) $where .= ' OR ';
95                 $or = true;
96                 $where .= " meetings.status = '$status' ";
97         }
98         $where .= ") ";
99         $where .= " AND meetings_users.user_id='$current_user->id' ";
100         $where .= " AND meetings_users.accept_status != 'decline'";
101
102         // allow for differences between MySQL and Oracle 9
103         if($sugar_config["dbconfig"]["db_type"] == "mysql") {
104                 $where .= " HAVING datetime <= '$dayEnd' ";
105         } elseif ($sugar_config["dbconfig"]["db_type"] == "oci8") {
106         }
107         else if ($sugar_config["dbconfig"]["db_type"] == "mssql")
108         {
109                 $where .= " AND meetings.date_start + ' ' +  meetings.time_start <= '$dayEnd' ";
110         }
111         else {
112                 $GLOBALS['log']->fatal("No database type identified.");
113         }
114
115         $meeting->disable_row_level_security = true;
116         $focus_meetings_list = $meeting->get_full_list("time_start", $where);
117 }
118
119 if(ACLController::checkAccess('Calls', 'list', true)) {
120         $call = new Call();
121         $where = '(';
122         $or = false;
123
124         foreach ($open_status as $status) {
125                 if ($or) $where .= ' OR ';
126                 $or = true;
127                 $where .= " calls.status = '$status' ";
128         }
129
130         $where .= ") ";
131         $where .= " AND calls_users.user_id='$current_user->id' ";
132         $where .= " AND calls_users.accept_status != 'decline'";
133
134         // allow for differences between MySQL and Oracle 9
135         if($sugar_config["dbconfig"]["db_type"] == "mysql") {
136                 $where .= " HAVING datetime <= '$dayEnd' ";
137         } elseif ($sugar_config["dbconfig"]["db_type"] == "oci8") {
138         }else if ($sugar_config["dbconfig"]["db_type"] == "mssql")
139         {
140                 //add condition for MS Sql server.
141                 $where .= " AND calls.date_start + ' ' + calls.time_start <= '$dayEnd' ";
142         } else {
143                 $GLOBALS['log']->fatal("No database type identified.");
144         }
145
146         $call->disable_row_level_security = true;
147         $focus_calls_list = $call->get_full_list("time_start", $where);
148 }
149
150 $open_activity_list = array();
151 if(count($focus_meetings_list)>0) {
152         foreach ($focus_meetings_list as $meeting) {
153                 $td     = $timedate->merge_date_time(from_db_convert($meeting->date_start,'date'),from_db_convert($meeting->time_start, 'time'));
154                 $tag = 'span';
155
156                 if($meeting->ACLAccess('view', $meeting->isOwner($current_user->id))){
157                         $tag = 'a';
158                 }
159
160                 $open_activity_list[] = array(
161                         'name'                          => $meeting->name,
162                         'id'                            => $meeting->id,
163                         'type'                          => 'Meeting',
164                         'module'                        => 'Meetings',
165                         'status'                        => $meeting->status,
166                         'parent_id'                     => $meeting->parent_id,
167                         'parent_type'           => $meeting->parent_type,
168                         'parent_name'           => $meeting->parent_name,
169                         'contact_id'            => $meeting->contact_id,
170                         'contact_name'          => $meeting->contact_name,
171                         'normal_date_start'     => $meeting->date_start,
172                         'date_start'            => $timedate->to_display_date($td),
173                         'normal_time_start'     => $meeting->time_start,
174                         'time_start'            => $timedate->to_display_time($td,true),
175                         'required'                      => $meeting->required,
176                         'accept_status'         => $meeting->accept_status,
177                         'tag'                           => $tag,
178                 );
179         }
180 }
181
182 if (count($focus_calls_list)>0) {
183         foreach ($focus_calls_list as $call) {
184
185                 $td = $timedate->merge_date_time(from_db_convert($call->date_start,'date'),from_db_convert($call->time_start, 'time'));
186                 $tag = 'span';
187
188                 if($call->ACLAccess('view', $call->isOwner($current_user->id))) {
189                         $tag = 'a';
190                 }
191
192                 $open_activity_list[] = array(
193                         'name'                          => $call->name,
194                         'id'                            => $call->id,
195                         'type'                          => 'Call',
196                         'module'                        => 'Calls',
197                         'status'                        => $call->status,
198                         'parent_id'                     => $call->parent_id,
199                         'parent_type'           => $call->parent_type,
200                         'parent_name'           => $call->parent_name,
201                         'contact_id'            => $call->contact_id,
202                         'contact_name'          => $call->contact_name,
203                         'date_start'            => $timedate->to_display_date($td),
204                         'normal_date_start'     => $call->date_start,
205                         'normal_time_start'     => $call->time_start,
206                         'time_start'            => $timedate->to_display_time($td,true),
207                         'required'                      => $call->required,
208                         'accept_status'         => $call->accept_status,
209                         'tag'                           => $tag,
210                 );
211         }
212 }
213
214 ///////////////////////////////////////////////////////////////////////////////
215 ////    START OUTPUT
216
217 $xtpl=new XTemplate ('modules/Activities/OpenListView.html');
218 $xtpl->assign("MOD", $current_module_strings);
219 $xtpl->assign("APP", $app_strings);
220 $xtpl->assign('JSON_CONFIG_JAVASCRIPT', $json_config->get_static_json_server());
221 $xtpl->assign("SUGAR_VERSION", $sugar_version);
222 $xtpl->assign("JS_CUSTOM_VERSION", $sugar_config['js_custom_version']);
223
224 // Stick the form header out there.
225 $filter = get_select_options_with_id($current_module_strings['appointment_filter_dom'], $appointment_filter );
226 echo "<form method='POST' action='index.php'>\n";
227 echo "<input type='hidden' name='module' value='Home'>\n";
228 echo "<input type='hidden' name='action' value='index'>\n";
229 $day_filter = "<select name='appointment_filter' language='JavaScript' onchange='this.form.submit();'>$filter</select>";
230
231 echo get_form_header($current_module_strings['LBL_UPCOMING'], $current_module_strings['LBL_TODAY'].$day_filter.' ('.$timedate->to_display_date($later, false).') ', false);
232 echo "</form>\n";
233
234 $xtpl->assign("RETURN_URL", "&return_module=$currentModule&return_action=DetailView&return_id=" . ((is_object($focus) && ! empty($focus->id)) ? $focus->id : ""));
235
236 $oddRow = true;
237 if(count($open_activity_list) > 0) {
238         $open_activity_list = array_csort($open_activity_list, 'normal_date_start', 'normal_time_start', SORT_ASC);
239 }
240
241 $today = $timedate->handle_offset('today', $timedate->dbDayFormat.' '.$timedate->dbTimeFormat, false);
242 $todayOffset = $timedate->handleOffsetMax('today', $timedate->dbDayFormat.' '.$timedate->dbTimeFormat, true);
243
244 foreach($open_activity_list as $activity) {
245         $concatActDate = $activity['normal_date_start'].' '.$activity['normal_time_start'];
246
247         if($concatActDate < $today) {
248                 $time = "<font class='overdueTask'>".$activity['date_start'].' '.$activity['time_start']."</font>";
249         } elseif(($concatActDate >= $todayOffset['min']) && ($concatActDate <= $todayOffset['max'])) {
250                 $time = "<font class='todaysTask'>".$activity['date_start'].' '.$activity['time_start']."</font>";
251         } else {
252                 $time = "<font class='futureTask'>".$activity['date_start'].' '.$activity['time_start']."</font>";
253         }
254
255         $activity_fields = array(
256                 'ID'                    => $activity['id'],
257                 'NAME'                  => $activity['name'],
258                 'TYPE'                  => $activity['type'],
259                 'MODULE'                => $activity['module'],
260                 'STATUS'                => $activity['status'],
261                 'CONTACT_NAME'  => $activity['contact_name'],
262                 'CONTACT_ID'    => $activity['contact_id'],
263                 'PARENT_TYPE'   => $activity['parent_type'],
264                 'PARENT_NAME'   => $activity['parent_name'],
265                 'PARENT_ID'             => $activity['parent_id'],
266                 'TIME'                  => $time,
267                 'TAG'                   => $activity['tag'],
268         );
269
270         switch ($activity['parent_type']) {
271                 case 'Accounts':
272                         $activity_fields['PARENT_MODULE'] = 'Accounts';
273                         break;
274                 case 'Cases':
275                         $activity_fields['PARENT_MODULE'] = 'Cases';
276                         break;
277                 case 'Opportunities':
278                         $activity_fields['PARENT_MODULE'] = 'Opportunities';
279                         break;
280                 case 'Quotes':
281                         $activity_fields['PARENT_MODULE'] = 'Quotes';
282                         break;
283         }
284         switch ($activity['type']) {
285                 case 'Call':
286                         $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'", null, null, '.gif', $mod_strings['LBL_LIST_CLOSE'])."</a>";
287                         break;
288                 case 'Meeting':
289                         $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'",null,null,'.gif',$mod_strings['LBL_LIST_CLOSE'])."</a>";
290                         break;
291         }
292
293         if (! empty($activity['accept_status'])) {
294                 if ( $activity['accept_status'] == 'none') {
295                         $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'", null,null,'.gif',$mod_strings['LBL_ACCEPT']). "</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'", null,null,'.gif',$mod_strings['LBL_ACCEPT'])."</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'", null,null,'.gif',$mod_strings['LBL_ACCEPT'])."</a></div>";
296                 } else {
297                         $activity_fields['SET_ACCEPT_LINKS'] = $app_list_strings['dom_meeting_accept_status'][$activity['accept_status']];
298                 }
299         }
300
301         $activity_fields['TITLE'] = '';
302         if (!empty($activity['contact_name'])) {
303                 $activity_fields['TITLE'] .= $current_module_strings['LBL_LIST_CONTACT'].": ".$activity['contact_name'];
304         }
305         if (!empty($activity['parent_name'])) {
306                 $activity_fields['TITLE'] .= "\n".$app_list_strings['record_type_display'][$activity['parent_type']].": ".$activity['parent_name'];
307         }
308
309         $xtpl->assign("ACTIVITY_MODULE_PNG", SugarThemeRegistry::current()->getImage($activity_fields['MODULE'].'','border="0"', null,null,'.gif',$activity_fields['NAME']));
310         $xtpl->assign("ACTIVITY", $activity_fields);
311         $xtpl->assign("BG_HILITE", $hilite_bg);
312         $xtpl->assign("BG_CLICK", $click_bg);
313
314         if($oddRow) {
315                 $xtpl->assign("ROW_COLOR", 'oddListRow');
316                 $xtpl->assign("BG_COLOR", $odd_bg);
317         } else {
318                 $xtpl->assign("ROW_COLOR", 'evenListRow');
319                 $xtpl->assign("BG_COLOR", $even_bg);
320         }
321         $oddRow = !$oddRow;
322         $xtpl->parse("open_activity.row");
323 } // END FOREACH()
324
325 $xtpl->parse("open_activity");
326 if (count($open_activity_list)>0) $xtpl->out("open_activity");
327 else echo "<i>".$current_module_strings['NTC_NONE_SCHEDULED']."</i>";
328 ?>