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-2012 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 ********************************************************************************/
41 require_once('include/utils/activity_utils.php');
43 class CalendarActivity {
48 function __construct($args){
49 // if we've passed in an array, then this is a free/busy slot
50 // and does not have a sugarbean associated to it
53 if ( is_array ( $args )){
54 $this->start_time = clone $args[0];
55 $this->end_time = clone $args[1];
56 $this->sugar_bean = null;
57 $timedate->tzGMT($this->start_time);
58 $timedate->tzGMT($this->end_time);
62 // else do regular constructor..
65 $this->sugar_bean = $sugar_bean;
68 if ($sugar_bean->object_name == 'Task'){
69 $this->start_time = $timedate->fromUser($this->sugar_bean->date_due);
70 if ( empty($this->start_time)){
73 $this->end_time = $timedate->fromUser($this->sugar_bean->date_due);
75 $this->start_time = $timedate->fromUser($this->sugar_bean->date_start);
76 if ( empty($this->start_time)){
79 $hours = $this->sugar_bean->duration_hours;
83 $mins = $this->sugar_bean->duration_minutes;
87 $this->end_time = $this->start_time->get("+$hours hours $mins minutes");
89 // Convert it back to database time so we can properly manage it for getting the proper start and end dates
90 $timedate->tzGMT($this->start_time);
91 $timedate->tzGMT($this->end_time);
95 * Get where clause for fetching entried from DB
96 * @param string $table_name t
97 * @param string $rel_table table for accept status, not used in Tasks
98 * @param SugarDateTime $start_ts_obj start date
99 * @param SugarDateTime $end_ts_obj end date
100 * @param string $field_name date field in table
101 * @param string $view view; not used for now, left for compatibility
104 function get_occurs_within_where_clause($table_name, $rel_table, $start_ts_obj, $end_ts_obj, $field_name='date_start', $view){
107 $start = clone $start_ts_obj;
108 $end = clone $end_ts_obj;
110 $field_date = $table_name.'.'.$field_name;
111 $start_day = $GLOBALS['db']->convert("'{$start->asDb()}'",'datetime');
112 $end_day = $GLOBALS['db']->convert("'{$end->asDb()}'",'datetime');
114 $where = "($field_date >= $start_day AND $field_date < $end_day";
115 if($rel_table != ''){
116 $where .= " AND $rel_table.accept_status != 'decline'";
123 function get_freebusy_activities($user_focus, $start_date_time, $end_date_time){
125 $vcal_focus = new vCal();
126 $vcal_str = $vcal_focus->get_vcal_freebusy($user_focus);
128 $lines = explode("\n",$vcal_str);
129 $utc = new DateTimeZone("UTC");
130 foreach ($lines as $line){
131 if ( preg_match('/^FREEBUSY.*?:([^\/]+)\/([^\/]+)/i',$line,$matches)){
132 $dates_arr = array(SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[1], $utc),
133 SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[2], $utc));
134 $act_list[] = new CalendarActivity($dates_arr);
141 * Get array of activities
142 * @param string $user_id
143 * @param boolean $show_tasks
144 * @param SugarDateTime $view_start_time start date
145 * @param SugarDateTime $view_end_time end date
146 * @param string $view view; not used for now, left for compatibility
147 * @param boolean $show_calls
150 function get_activities($user_id, $show_tasks, $view_start_time, $view_end_time, $view, $show_calls = true){
151 global $current_user;
156 // get all upcoming meetings, tasks due, and calls for a user
157 if(ACLController::checkAccess('Meetings', 'list', $current_user->id == $user_id)) {
158 $meeting = new Meeting();
160 if($current_user->id == $user_id) {
161 $meeting->disable_row_level_security = true;
164 $where = CalendarActivity::get_occurs_within_where_clause($meeting->table_name, $meeting->rel_users_table, $view_start_time, $view_end_time, 'date_start', $view);
165 $focus_meetings_list = build_related_list_by_user_id($meeting,$user_id,$where);
166 foreach($focus_meetings_list as $meeting) {
167 if(isset($seen_ids[$meeting->id])) {
171 $seen_ids[$meeting->id] = 1;
172 $act = new CalendarActivity($meeting);
181 if(ACLController::checkAccess('Calls', 'list',$current_user->id == $user_id)) {
184 if($current_user->id == $user_id) {
185 $call->disable_row_level_security = true;
188 $where = CalendarActivity::get_occurs_within_where_clause($call->table_name, $call->rel_users_table, $view_start_time, $view_end_time, 'date_start', $view);
189 $focus_calls_list = build_related_list_by_user_id($call,$user_id,$where);
191 foreach($focus_calls_list as $call) {
192 if(isset($seen_ids[$call->id])) {
195 $seen_ids[$call->id] = 1;
197 $act = new CalendarActivity($call);
207 if(ACLController::checkAccess('Tasks', 'list',$current_user->id == $user_id)) {
210 $where = CalendarActivity::get_occurs_within_where_clause('tasks', '', $view_start_time, $view_end_time, 'date_due', $view);
211 $where .= " AND tasks.assigned_user_id='$user_id' ";
213 $focus_tasks_list = $task->get_full_list("", $where,true);
215 if(!isset($focus_tasks_list)) {
216 $focus_tasks_list = array();
219 foreach($focus_tasks_list as $task) {
220 $act = new CalendarActivity($task);