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.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
40 ********************************************************************************/
42 require_once('modules/Activities/config.php');
48 require_once('include/json_config.php');
49 $json_config = new json_config();
52 global $currentModule, $theme, $focus, $action, $open_status;
54 global $current_language;
59 global $sugar_version, $sugar_config;
61 $focus_meetings_list = array();
62 $focus_calls_list = array();
63 $focus_tasks_list = array();
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');
70 ///////////////////////////////////////////////////////////////////////////////
72 if (empty($_REQUEST['appointment_filter'])) {
73 if ($current_user->getPreference('appointment_filter') == '') {
74 $appointment_filter = 'today';
76 $appointment_filter = $current_user->getPreference('appointment_filter');
79 $appointment_filter = $_REQUEST['appointment_filter'];
80 $current_user->setPreference('appointment_filter', $_REQUEST['appointment_filter']);
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';");
93 $appt_filter = $appointment_filter;
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);
101 $GLOBALS['log']->debug("appt_filter is '$appt_filter'; later is '$later'");
103 if(ACLController::checkAccess('Meetings', 'list', true)){
104 $meeting = new Meeting();
107 foreach ($open_status as $status) {
108 if ($or) $where .= ' OR ';
110 $where .= " meetings.status = '$status' ";
113 $where .= " AND meetings_users.user_id='$current_user->id' ";
114 $where .= " AND meetings_users.accept_status != 'decline'";
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") {
121 else if ($sugar_config["dbconfig"]["db_type"] == "mssql")
123 $where .= " AND meetings.date_start + ' ' + meetings.time_start <= '".$laterWhere["date"]." ".$laterWhere["time"]."' ";
126 $GLOBALS['log']->fatal("No database type identified.");
129 $meeting->disable_row_level_security = true;
130 $focus_meetings_list = $meeting->get_full_list("time_start", $where);
133 if(ACLController::checkAccess('Calls', 'list', true)) {
138 foreach ($open_status as $status) {
139 if ($or) $where .= ' OR ';
141 $where .= " calls.status = '$status' ";
145 $where .= " AND calls_users.user_id='$current_user->id' ";
146 $where .= " AND calls_users.accept_status != 'decline'";
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")
154 //add condition for MS Sql server.
155 $where .= " AND calls.date_start + ' ' + calls.time_start <= '".$laterWhere["date"]." ".$laterWhere["time"]."' ";
157 $GLOBALS['log']->fatal("No database type identified.");
160 $call->disable_row_level_security = true;
161 $focus_calls_list = $call->get_full_list("time_start", $where);
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'));
170 if($meeting->ACLAccess('view', $meeting->isOwner($current_user->id))){
174 $open_activity_list[] = array(
175 'name' => $meeting->name,
176 'id' => $meeting->id,
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,
196 if (count($focus_calls_list)>0) {
197 foreach ($focus_calls_list as $call) {
199 $td = $timedate->merge_date_time(from_db_convert($call->date_start,'date'),from_db_convert($call->time_start, 'time'));
202 if($call->ACLAccess('view', $call->isOwner($current_user->id))) {
206 $open_activity_list[] = array(
207 'name' => $call->name,
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,
228 ///////////////////////////////////////////////////////////////////////////////
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']);
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>";
245 echo get_form_header($current_module_strings['LBL_UPCOMING'], $current_module_strings['LBL_TODAY'].$day_filter.' ('.$timedate->to_display_date($later, false).') ', false);
248 $xtpl->assign("RETURN_URL", "&return_module=$currentModule&return_action=DetailView&return_id=" . ((is_object($focus) && ! empty($focus->id)) ? $focus->id : ""));
251 if(count($open_activity_list) > 0) {
252 $open_activity_list = array_csort($open_activity_list, 'normal_date_start', 'normal_time_start', SORT_ASC);
255 $today = $timedate->handle_offset('today', $timedate->dbDayFormat.' '.$timedate->dbTimeFormat, false);
256 $todayOffset = $timedate->handleOffsetMax('today', $timedate->dbDayFormat.' '.$timedate->dbTimeFormat, true);
258 foreach($open_activity_list as $activity) {
259 $concatActDate = $activity['normal_date_start'].' '.$activity['normal_time_start'];
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>";
266 $time = "<font class='futureTask'>".$activity['date_start'].' '.$activity['time_start']."</font>";
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'],
281 'TAG' => $activity['tag'],
284 switch ($activity['parent_type']) {
286 $activity_fields['PARENT_MODULE'] = 'Accounts';
289 $activity_fields['PARENT_MODULE'] = 'Cases';
291 case 'Opportunities':
292 $activity_fields['PARENT_MODULE'] = 'Opportunities';
295 $activity_fields['PARENT_MODULE'] = 'Quotes';
298 switch ($activity['type']) {
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>";
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>";
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> <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> <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>";
311 $activity_fields['SET_ACCEPT_LINKS'] = $app_list_strings['dom_meeting_accept_status'][$activity['accept_status']];
315 $activity_fields['TITLE'] = '';
316 if (!empty($activity['contact_name'])) {
317 $activity_fields['TITLE'] .= $current_module_strings['LBL_LIST_CONTACT'].": ".$activity['contact_name'];
319 if (!empty($activity['parent_name'])) {
320 $activity_fields['TITLE'] .= "\n".$app_list_strings['record_type_display'][$activity['parent_type']].": ".$activity['parent_name'];
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);
329 $xtpl->assign("ROW_COLOR", 'oddListRow');
330 $xtpl->assign("BG_COLOR", $odd_bg);
332 $xtpl->assign("ROW_COLOR", 'evenListRow');
333 $xtpl->assign("BG_COLOR", $even_bg);
336 $xtpl->parse("open_activity.row");
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>";