Example #1
0
 /**
  * @group 63403
  */
 public function testBug63403()
 {
     $meeting = SugarTestMeetingUtilities::createMeeting();
     SugarTestMeetingUtilities::addMeetingUserRelation($meeting->id, $GLOBALS['current_user']->id);
     $meeting->date_start = $GLOBALS['timedate']->getNow()->asDb();
     $meeting->date_end = $GLOBALS['timedate']->getNow()->modify("+25 days")->asDb();
     $meeting->duration_hours = 720;
     $meeting->save();
     $calendar = new CalendarActivity($meeting);
     $start_date_time = $GLOBALS['timedate']->fromString($GLOBALS['timedate']->nowDb());
     $result = $calendar->get_activities($GLOBALS['current_user']->id, false, $start_date_time->get("+7 days"), $start_date_time->get("+14 days"), false);
     $this->assertNotEmpty($result);
     $this->assertEquals($meeting->id, $result[0]->sugar_bean->id, 'We should get current test Meeting');
 }
Example #2
0
 public function testCallAppearsWithinMonthView()
 {
     global $timedate, $sugar_config, $DO_USER_TIME_OFFSET, $current_user;
     $DO_USER_TIME_OFFSET = true;
     $timedate = TimeDate::getInstance();
     $format = $current_user->getUserDateTimePreferences();
     $name = 'Bug37953Test' . $timedate->nowDb();
     $this->call->name = $name;
     $this->call->date_start = $timedate->swap_formats("2011-09-29 11:00pm", 'Y-m-d h:ia', $format['date'] . ' ' . $format['time']);
     $this->call->time_start = "";
     $this->call->object_name = "Call";
     $this->call->duration_hours = 99;
     $ca = new CalendarActivity($this->call);
     $where = $ca->get_occurs_within_where_clause($this->call->table_name, $this->call->rel_users_table, $ca->start_time, $ca->end_time, 'date_start', 'month');
     $this->assertRegExp('/2011\\-09\\-23 00:00:00/', $where, 'Assert that we go back 6 days from the date_start value');
     $this->assertRegExp('/2011\\-11\\-01 00:00:00/', $where, 'Assert that we go to the end of next month');
 }
Example #3
0
 /**
  * Creates the string for the user's events and todos between the given start
  * and end times
  *
  * @param UserBean $user_bean the current UserBean
  * @param DateTime $start_date_time the start date to search from
  * @param DateTime $end_date_time the end date to search to
  * @param string $dtstamp the current timestamp
  * @return string the entries for events and todos
  */
 protected function createSugarIcal(&$user_bean, &$start_date_time, &$end_date_time, $dtstamp)
 {
     $ical_array = array();
     global $DO_USER_TIME_OFFSET, $sugar_config, $current_user, $timedate;
     $hide_calls = false;
     if (!empty($_REQUEST['hide_calls']) && $_REQUEST['hide_calls'] == "true") {
         $hide_calls = true;
     }
     $taskAsVTODO = true;
     if (!empty($_REQUEST['show_tasks_as_events']) && ($_REQUEST['show_tasks_as_events'] == "1" || $_REQUEST['show_tasks_as_events'] == "true")) {
         $taskAsVTODO = false;
     }
     $acts_arr = CalendarActivity::get_activities($user_bean->id, !$taskAsVTODO, $start_date_time, $end_date_time, 'month', !$hide_calls);
     // loop thru each activity, get start/end time in UTC, and return iCal strings
     foreach ($acts_arr as $act) {
         $event = $act->sugar_bean;
         if (!$hide_calls || $hide_calls && $event->object_name != "Call") {
             $ical_array[] = array("BEGIN", "VEVENT");
             $ical_array[] = array("SUMMARY", $event->name);
             $ical_array[] = array("DTSTART;TZID=" . $user_bean->getPreference('timezone'), str_replace("Z", "", $timedate->tzUser($act->start_time, $current_user)->format(self::UTC_FORMAT)));
             $ical_array[] = array("DTEND;TZID=" . $user_bean->getPreference('timezone'), str_replace("Z", "", $timedate->tzUser($act->end_time, $current_user)->format(self::UTC_FORMAT)));
             $ical_array[] = array("DTSTAMP", $dtstamp);
             $ical_array[] = array("DESCRIPTION", $event->description);
             $ical_array[] = array("URL;VALUE=URI", $sugar_config['site_url'] . "/index.php?module=" . $event->module_dir . "&action=DetailView&record=" . $event->id);
             $ical_array[] = array("UID", $event->id);
             if ($event->object_name == "Meeting") {
                 $ical_array[] = array("LOCATION", $event->location);
                 $eventUsers = $event->get_meeting_users();
                 $query = "SELECT contact_id as id from meetings_contacts where meeting_id='{$event->id}' AND deleted=0";
                 $eventContacts = $event->build_related_list($query, new Contact());
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             // Define the participant status
                             $participant_status = '';
                             if (!empty($attendee->accept_status)) {
                                 switch ($attendee->accept_status) {
                                     case 'accept':
                                         $participant_status = ';PARTSTAT=ACCEPTED';
                                         break;
                                     case 'decline':
                                         $participant_status = ';PARTSTAT=DECLINED';
                                         break;
                                     case 'tentative':
                                         $participant_status = ';PARTSTAT=TENTATIVE';
                                         break;
                                 }
                             }
                             $ical_array[] = array('ATTENDEE' . $participant_status . ';CN="' . $attendee->get_summary_text() . '"', 'mailto:' . (!empty($attendee->email1) ? $attendee->email1 : '*****@*****.**'));
                         }
                     }
                 }
             }
             if ($event->object_name == "Call") {
                 $eventUsers = $event->get_call_users();
                 $eventContacts = $event->get_contacts();
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             // Define the participant status
                             $participant_status = '';
                             if (!empty($attendee->accept_status)) {
                                 switch ($attendee->accept_status) {
                                     case 'accept':
                                         $participant_status = ';PARTSTAT=ACCEPTED';
                                         break;
                                     case 'decline':
                                         $participant_status = ';PARTSTAT=DECLINED';
                                         break;
                                     case 'tentative':
                                         $participant_status = ';PARTSTAT=TENTATIVE';
                                         break;
                                 }
                             }
                             $ical_array[] = array('ATTENDEE' . $participant_status . ';CN="' . $attendee->get_summary_text() . '"', 'mailto:' . (!empty($attendee->email1) ? $attendee->email1 : '*****@*****.**'));
                         }
                     }
                 }
             }
             if (isset($event->reminder_time) && $event->reminder_time > 0 && $event->status != "Held") {
                 $ical_array[] = array("BEGIN", "VALARM");
                 $ical_array[] = array("TRIGGER", "-PT");
                 $ical_array[] = array("ACTION", "DISPLAY");
                 $ical_array[] = array("DESCRIPTION", $event->name);
                 $ical_array[] = array("END", "VALARM");
             }
             $ical_array[] = array("END", "VEVENT");
         }
     }
     $str = vCal::create_ical_string_from_array($ical_array, true);
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $today = gmdate("Y-m-d");
     $today = $timedate->handle_offset($today, $timedate->dbDayFormat, false);
     require_once 'modules/ProjectTask/ProjectTask.php';
     $where = "project_task.assigned_user_id='{$user_bean->id}' " . "AND (project_task.status IS NULL OR (project_task.status!='Deferred')) " . "AND (project_task.date_start IS NULL OR " . CalendarActivity::get_occurs_within_where_clause('project_task', '', $start_date_time, $end_date_time, 'date_start', 'month') . ")";
     $seedProjectTask = new ProjectTask();
     $projectTaskList = $seedProjectTask->get_full_list("", $where);
     if (is_array($projectTaskList)) {
         foreach ($projectTaskList as $projectTask) {
             $str .= $this->createSugarIcalTodo($user_bean, $projectTask, "ProjectTask", $dtstamp);
         }
     }
     if ($taskAsVTODO) {
         require_once 'modules/Tasks/Task.php';
         $where = "tasks.assigned_user_id='{$user_bean->id}' " . "AND (tasks.status IS NULL OR (tasks.status!='Deferred')) " . "AND (tasks.date_start IS NULL OR " . CalendarActivity::get_occurs_within_where_clause('tasks', '', $start_date_time, $end_date_time, 'date_start', 'month') . ")";
         $seedTask = new Task();
         $taskList = $seedTask->get_full_list("", $where);
         if (is_array($taskList)) {
             foreach ($taskList as $task) {
                 $str .= $this->createSugarIcalTodo($user_bean, $task, "Tasks", $dtstamp);
             }
         }
     }
     return $str;
 }
Example #4
0
	function create_sugar_freebusy($user_bean, $start_date_time, $end_date_time)
	{
        $ical_array = array();
		global $DO_USER_TIME_OFFSET,$timedate;

		$DO_USER_TIME_OFFSET = true;
		if(empty($GLOBALS['current_user']) || empty($GLOBALS['current_user']->id)) {
		    $GLOBALS['current_user'] = $user_bean;
		}
		// get activities.. queries Meetings and Calls
		$acts_arr =
		CalendarActivity::get_activities($user_bean->id,
			false,
			$start_date_time,
			$end_date_time,
			'freebusy');

		// loop thru each activity, get start/end time in UTC, and return FREEBUSY strings
		foreach($acts_arr as $act)
		{
            $ID = $act->sugar_bean->id;
			$startTimeUTC = $act->start_time->format(self::UTC_FORMAT);
			$endTimeUTC = $act->end_time->format(self::UTC_FORMAT);
            $ical_array[] = array("FREEBUSY", $startTimeUTC ."/". $endTimeUTC);
            $ical_array[] = array("X-FREEBUSY-ID", $ID);
            $ical_array[] = array("X-FREEBUSY-TYPE", get_class($act->sugar_bean));
            //$ical_array[] = array(array("X-FREEBUSYID", $ID), array("FREEBUSY", $startTimeUTC ."/". $endTimeUTC));
		}
        return self::create_ical_string_from_array($ical_array);
//        return $ical_array;

	}
Example #5
0
 function create_sugar_freebusy($user_bean, $start_date_time, $end_date_time)
 {
     $str = '';
     global $DO_USER_TIME_OFFSET, $timedate;
     $DO_USER_TIME_OFFSET = true;
     // get activities.. queries Meetings and Calls
     $acts_arr = CalendarActivity::get_activities($user_bean->id, array("show_calls" => true), $start_date_time, $end_date_time, 'freebusy');
     // loop thru each activity, get start/end time in UTC, and return FREEBUSY strings
     foreach ($acts_arr as $act) {
         $startTimeUTC = $act->start_time->format(self::UTC_FORMAT);
         $endTimeUTC = $act->end_time->format(self::UTC_FORMAT);
         $str .= "FREEBUSY:" . $startTimeUTC . "/" . $endTimeUTC . "\n";
     }
     return $str;
 }
Example #6
0
 /**
  * Get array of activities
  * @param string $user_id
  * @param boolean $show_tasks
  * @param SugarDateTime $view_start_time start date
  * @param SugarDateTime $view_end_time end date
  * @param string $view view; not used for now, left for compatibility
  * @param boolean $show_calls
  * @param boolean $show_completed use to allow filtering completed events 
  * @return array
  */
 function get_activities($user_id, $show_tasks, $view_start_time, $view_end_time, $view, $show_calls = true, $show_completed = true)
 {
     global $current_user;
     $act_list = array();
     $seen_ids = array();
     $completedCalls = '';
     $completedMeetings = '';
     $completedTasks = '';
     if (!$show_completed) {
         $completedCalls = " AND calls.status = 'Planned' ";
         $completedMeetings = " AND meetings.status = 'Planned' ";
         $completedTasks = " AND tasks.status != 'Completed' ";
     }
     // get all upcoming meetings, tasks due, and calls for a user
     if (ACLController::checkAccess('Meetings', 'list', $current_user->id == $user_id)) {
         $meeting = new Meeting();
         if ($current_user->id == $user_id) {
             $meeting->disable_row_level_security = true;
         }
         $where = self::get_occurs_until_where_clause($meeting->table_name, $meeting->rel_users_table, $view_start_time, $view_end_time, 'date_start', $view);
         $where .= $completedMeetings;
         $focus_meetings_list = build_related_list_by_user_id($meeting, $user_id, $where);
         foreach ($focus_meetings_list as $meeting) {
             if (isset($seen_ids[$meeting->id])) {
                 continue;
             }
             $seen_ids[$meeting->id] = 1;
             $act = new CalendarActivity($meeting);
             if (!empty($act)) {
                 $act_list[] = $act;
             }
         }
     }
     if ($show_calls) {
         if (ACLController::checkAccess('Calls', 'list', $current_user->id == $user_id)) {
             $call = new Call();
             if ($current_user->id == $user_id) {
                 $call->disable_row_level_security = true;
             }
             $where = CalendarActivity::get_occurs_within_where_clause($call->table_name, $call->rel_users_table, $view_start_time, $view_end_time, 'date_start', $view);
             $where .= $completedCalls;
             $focus_calls_list = build_related_list_by_user_id($call, $user_id, $where);
             foreach ($focus_calls_list as $call) {
                 if (isset($seen_ids[$call->id])) {
                     continue;
                 }
                 $seen_ids[$call->id] = 1;
                 $act = new CalendarActivity($call);
                 if (!empty($act)) {
                     $act_list[] = $act;
                 }
             }
         }
     }
     if ($show_tasks) {
         if (ACLController::checkAccess('Tasks', 'list', $current_user->id == $user_id)) {
             $task = new Task();
             $where = CalendarActivity::get_occurs_within_where_clause('tasks', '', $view_start_time, $view_end_time, 'date_due', $view);
             $where .= " AND tasks.assigned_user_id='{$user_id}' ";
             $where .= $completedTasks;
             $focus_tasks_list = $task->get_full_list("", $where, true);
             if (!isset($focus_tasks_list)) {
                 $focus_tasks_list = array();
             }
             foreach ($focus_tasks_list as $task) {
                 $act = new CalendarActivity($task);
                 if (!empty($act)) {
                     $act_list[] = $act;
                 }
             }
         }
     }
     return $act_list;
 }
Example #7
0
 /**
  * loads array of objects
  * @param User $user user object
  * @param string $type
  */
 public function add_activities($user, $type = 'sugar')
 {
     global $timedate;
     $start_date_time = $this->date_time;
     if ($this->view == 'week' || $this->view == 'shared' || $this->view == 'mobile') {
         $start_date_time = CalendarUtils::get_first_day_of_week($this->date_time);
         $end_date_time = $start_date_time->get("+7 days");
     } else {
         if ($this->view == 'month') {
             $start_date_time = $this->date_time->get_day_by_index_this_month(0);
             $end_date_time = $start_date_time->get("+" . $start_date_time->format('t') . " days");
             $start_date_time = CalendarUtils::get_first_day_of_week($start_date_time);
             $end_date_time = CalendarUtils::get_first_day_of_week($end_date_time)->get("+7 days");
         } else {
             $end_date_time = $this->date_time->get("+1 day");
         }
     }
     $start_date_time = $start_date_time->get("-5 days");
     // 5 days step back to fetch multi-day activities that
     $acts_arr = array();
     if ($type == 'vfb') {
         $acts_arr = CalendarActivity::get_freebusy_activities($user, $start_date_time, $end_date_time);
     } else {
         $acts_arr = CalendarActivity::get_activities($user->id, $this->show_tasks, $start_date_time, $end_date_time, $this->view, $this->show_calls, $this->show_completed);
     }
     $this->acts_arr[$user->id] = $acts_arr;
 }
Example #8
0
 function create_sugar_freebusy($user_bean, $start_date_time, $end_date_time)
 {
     $str = '';
     global $DO_USER_TIME_OFFSET, $timedate;
     $DO_USER_TIME_OFFSET = true;
     // get activities.. queries Meetings and Calls
     $acts_arr = CalendarActivity::get_activities($user_bean->id, false, $start_date_time, $end_date_time, 'week');
     // loop thru each activity, get start/end time in UTC, and return FREEBUSY strings
     for ($i = 0; $i < count($acts_arr); $i++) {
         $act = $acts_arr[$i];
         $utcFormat = 'Ymd\\THi';
         $startTimeUTC = gmdate($utcFormat, $act->start_time->ts) . "00Z";
         $endTimeUTC = gmdate($utcFormat, $act->end_time->ts) . "00Z";
         $str .= "FREEBUSY:" . $startTimeUTC . "/" . $endTimeUTC . "\n";
     }
     return $str;
 }
Example #9
0
 function create_sugar_freebusy(&$user_bean, &$start_date_time, &$end_date_time)
 {
     $str = '';
     global $DO_USER_TIME_OFFSET;
     $DO_USER_TIME_OFFSET = true;
     // get activities.. queries Meetings and Calls
     $acts_arr = CalendarActivity::get_activities($user_bean->id, false, $start_date_time, $end_date_time, 'week');
     // loop thru each activity, get start/end time in UTC, and return FREEBUSY strings
     for ($i = 0; $i < count($acts_arr); $i++) {
         $act = $acts_arr[$i];
         $date_arr = array('ts' => $act->start_time->ts);
         $start_time = new DateTimeUtil($date_arr, true);
         $date_arr = array('ts' => $act->end_time->ts);
         $end_time = new DateTimeUtil($date_arr, true);
         $str .= "FREEBUSY:" . $start_time->get_utc_date_time() . "/" . $end_time->get_utc_date_time() . "\n";
     }
     return $str;
 }
Example #10
0
 /**
  * Creates the string for the user's events and todos between the given start
  * and end times
  *
  * @param UserBean $user_bean the current UserBean
  * @param DateTime $start_date_time the start date to search from
  * @param DateTime $end_date_time the end date to search to
  * @param string $dtstamp the current timestamp
  * @return string the entries for events and todos
  */
 protected function createSugarIcal(&$user_bean, &$start_date_time, &$end_date_time, $dtstamp)
 {
     $str = '';
     global $DO_USER_TIME_OFFSET, $sugar_config, $current_user, $timedate;
     $acts_arr = CalendarActivity::get_activities($user_bean->id, false, $start_date_time, $end_date_time, 'month');
     $hide_calls = false;
     if (!empty($_REQUEST['hide_calls']) && $_REQUEST['hide_calls'] == "true") {
         $hide_calls = true;
     }
     // loop thru each activity, get start/end time in UTC, and return iCal strings
     foreach ($acts_arr as $act) {
         $event = $act->sugar_bean;
         if (!$hide_calls || $hide_calls && $event->object_name != "Call") {
             $str .= "BEGIN:VEVENT\n";
             $str .= "SUMMARY:" . $event->name . "\n";
             $str .= "DTSTART;TZID=" . $user_bean->getPreference('timezone') . ":" . str_replace("Z", "", $timedate->tzUser($act->start_time, $current_user)->format(self::UTC_FORMAT)) . "\n";
             $str .= "DTEND;TZID=" . $user_bean->getPreference('timezone') . ":" . str_replace("Z", "", $timedate->tzUser($act->end_time, $current_user)->format(self::UTC_FORMAT)) . "\n";
             $str .= "DTSTAMP:" . $dtstamp . "\n";
             $str .= "DESCRIPTION:" . $this->escapeNls($event->description) . "\n";
             $str .= "URL;VALUE=URI:" . $sugar_config['site_url'] . "/index.php?module=" . $event->module_dir . "&action=DetailView&record=" . $event->id . "\n";
             $str .= "UID:" . $event->id . "\n";
             if ($event->object_name == "Meeting") {
                 $str .= "LOCATION:" . $event->location . "\n";
                 $eventUsers = $event->get_meeting_users();
                 $query = "SELECT contact_id as id from meetings_contacts where meeting_id='{$event->id}' AND deleted=0";
                 $eventContacts = $event->build_related_list($query, new Contact());
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             $str .= 'ATTENDEE;CN="' . $attendee->get_summary_text() . '":mailto:' . $attendee->email1 . "\n";
                         }
                     }
                 }
             }
             if ($event->object_name == "Call") {
                 $eventUsers = $event->get_call_users();
                 $eventContacts = $event->get_contacts();
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             $str .= 'ATTENDEE;CN="' . $attendee->get_summary_text() . '":mailto:' . $attendee->email1 . "\n";
                         }
                     }
                 }
             }
             if ($event->reminder_time > 0 && $event->status != "Held") {
                 $str .= "BEGIN:VALARM\n";
                 $str .= "TRIGGER:-PT" . $event->reminder_time / 60 . "M\n";
                 $str .= "ACTION:DISPLAY\n";
                 $str .= "DESCRIPTION:" . $event->name . "\n";
                 $str .= "END:VALARM\n";
             }
             $str .= "END:VEVENT\n";
         }
     }
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $today = gmdate("Y-m-d");
     $today = $timedate->handle_offset($today, $timedate->dbDayFormat, false);
     require_once 'modules/ProjectTask/ProjectTask.php';
     $where = "project_task.assigned_user_id='{$user_bean->id}' " . "AND (project_task.status IS NULL OR (project_task.status!='Deferred')) " . "AND (project_task.date_start IS NULL OR project_task.date_start <= '{$today}')";
     $seedProjectTask = new ProjectTask();
     $projectTaskList = $seedProjectTask->get_full_list("", $where);
     if (is_array($projectTaskList)) {
         foreach ($projectTaskList as $projectTask) {
             $str .= $this->createSugarIcalTodo($user_bean, $projectTask, "ProjectTask", $dtstamp);
         }
     }
     require_once 'modules/Tasks/Task.php';
     $where = "tasks.assigned_user_id='{$user_bean->id}' " . "AND (tasks.status IS NULL OR (tasks.status!='Deferred')) " . "AND (tasks.date_start IS NULL OR tasks.date_start <= '{$today}')";
     $seedTask = new Task();
     $taskList = $seedTask->get_full_list("", $where);
     if (is_array($taskList)) {
         foreach ($taskList as $task) {
             $str .= $this->createSugarIcalTodo($user_bean, $task, "Tasks", $dtstamp);
         }
     }
     return $str;
 }
Example #11
0
 /**
  * @group 58702
  * Test if Meetings/Calls/Tasks are shown properly when
  * show completed flag is set
  *
  * @dataProvider dataProvider
  */
 public function testShowCompleted($showCompleted)
 {
     // Create Held Meeting
     $meeting = SugarTestMeetingUtilities::createMeeting();
     $meeting->date_start = $GLOBALS['timedate']->nowDb();
     $meeting->date_end = $GLOBALS['timedate']->nowDb();
     $meeting->status = 'Held';
     $meeting->save();
     $meeting->set_accept_status($GLOBALS['current_user'], 'accept');
     // Create Held Call
     $call = SugarTestCallUtilities::createCall();
     $call->date_start = $GLOBALS['timedate']->nowDb();
     $call->date_end = $GLOBALS['timedate']->nowDb();
     $call->status = 'Held';
     $call->save();
     $call->set_accept_status($GLOBALS['current_user'], 'accept');
     // Create Completed Task
     $task = SugarTestTaskUtilities::createTask();
     $task->date_due = $GLOBALS['timedate']->nowDb();
     $task->status = 'Completed';
     $task->assigned_user_id = $GLOBALS['current_user']->id;
     $task->save();
     // Set query dates
     $start_date_time = $GLOBALS['timedate']->fromString(date("Y-m-d"));
     $end_date_time = $start_date_time->get("+7 days");
     $start_date_time = $start_date_time->get("-7 days");
     // Get all activities for the user
     $result = CalendarActivity::get_activities($GLOBALS['current_user']->id, true, $start_date_time, $end_date_time, 'month', true, $showCompleted);
     // Depending on show completed, get_activities should return 3 entries, the ones we created above
     if ($showCompleted) {
         $this->assertEquals(3, sizeof($result), 'get_activities did not return the Metting, Call and Task as it should have');
         $this->assertEquals($result[0]->sugar_bean->id, $meeting->id, 'Meeting not returned properly');
         $this->assertEquals($result[1]->sugar_bean->id, $call->id, 'Call not returned properly');
         $this->assertEquals($result[2]->sugar_bean->id, $task->id, 'Task not returned properly');
     } else {
         $this->assertEquals(0, sizeof($result), 'get_activities should be empty');
     }
 }
Example #12
0
 function get_activities($user_id, $show_tasks, $view_start_time, $view_end_time, $view)
 {
     global $current_user;
     $act_list = array();
     $seen_ids = array();
     // get all upcoming meetings, tasks due, and calls for a user
     /* BEGIN - SECURITY GROUPS */
     /**
     if(ACLController::checkAccess('Meetings', 'list', $current_user->id == $user_id)) {
     */
     if (ACLController::checkAccess('Meetings', 'list', true)) {
         //$current_user->id == $user_id)) {
         /* END - SECURITY GROUPS */
         $meeting = new Meeting();
         if ($current_user->id == $user_id) {
             $meeting->disable_row_level_security = true;
         }
         $where = CalendarActivity::get_occurs_within_where_clause($meeting->table_name, $meeting->rel_users_table, $view_start_time, $view_end_time, 'date_start', $view);
         $focus_meetings_list = build_related_list_by_user_id($meeting, $user_id, $where);
         foreach ($focus_meetings_list as $meeting) {
             if (isset($seen_ids[$meeting->id])) {
                 continue;
             }
             /* BEGIN - SECURITY GROUPS */
             require_once "modules/SecurityGroups/SecurityGroup.php";
             $in_group = SecurityGroup::groupHasAccess('Meetings', $meeting->id, 'list');
             $show_as_busy = !ACLController::checkAccess('Meetings', 'list', $current_user->id == $user_id, 'module', $in_group);
             $meeting->show_as_busy = $show_as_busy;
             /* END - SECURITY GROUPS */
             $seen_ids[$meeting->id] = 1;
             $act = new CalendarActivity($meeting);
             if (!empty($act)) {
                 $act_list[] = $act;
             }
         }
     }
     /* BEGIN - SECURITY GROUPS */
     // get all upcoming meetings, tasks due, and calls for a user
     /**
     if(ACLController::checkAccess('Calls', 'list',$current_user->id  == $user_id)) {
     */
     if (ACLController::checkAccess('Calls', 'list', true)) {
         //$current_user->id == $user_id)) {
         $show_as_busy = !ACLController::checkAccess('Calls', 'list', $current_user->id == $user_id);
         /* END - SECURITY GROUPS */
         $call = new Call();
         if ($current_user->id == $user_id) {
             $call->disable_row_level_security = true;
         }
         $where = CalendarActivity::get_occurs_within_where_clause($call->table_name, $call->rel_users_table, $view_start_time, $view_end_time, 'date_start', $view);
         $focus_calls_list = build_related_list_by_user_id($call, $user_id, $where);
         foreach ($focus_calls_list as $call) {
             if (isset($seen_ids[$call->id])) {
                 continue;
             }
             /* BEGIN - SECURITY GROUPS */
             require_once "modules/SecurityGroups/SecurityGroup.php";
             $in_group = SecurityGroup::groupHasAccess('Calls', $call->id, 'list');
             $show_as_busy = !ACLController::checkAccess('Calls', 'list', $current_user->id == $user_id, 'module', $in_group);
             $call->show_as_busy = $show_as_busy;
             /* END - SECURITY GROUPS */
             $seen_ids[$call->id] = 1;
             $act = new CalendarActivity($call);
             if (!empty($act)) {
                 $act_list[] = $act;
             }
         }
     }
     if ($show_tasks) {
         /* BEGIN - SECURITY GROUPS */
         // get all upcoming meetings, tasks due, and calls for a user
         /**
         if(ACLController::checkAccess('Tasks', 'list',$current_user->id == $user_id)) {
         */
         if (ACLController::checkAccess('Tasks', 'list', true)) {
             //$current_user->id == $user_id)) {
             $show_as_busy = !ACLController::checkAccess('Tasks', 'list', $current_user->id == $user_id);
             /* END - SECURITY GROUPS */
             $task = new Task();
             $where = CalendarActivity::get_occurs_within_where_clause('tasks', '', $view_start_time, $view_end_time, 'date_due', $view);
             $where .= " AND tasks.assigned_user_id='{$user_id}' ";
             $focus_tasks_list = $task->get_full_list("", $where, true);
             if (!isset($focus_tasks_list)) {
                 $focus_tasks_list = array();
             }
             foreach ($focus_tasks_list as $task) {
                 /* BEGIN - SECURITY GROUPS */
                 require_once "modules/SecurityGroups/SecurityGroup.php";
                 $in_group = SecurityGroup::groupHasAccess('Tasks', $task->id, 'list');
                 $show_as_busy = !ACLController::checkAccess('Tasks', 'list', $current_user->id == $user_id, 'module', $in_group);
                 $task->show_as_busy = $show_as_busy;
                 /* END - SECURITY GROUPS */
                 $act = new CalendarActivity($task);
                 if (!empty($act)) {
                     $act_list[] = $act;
                 }
             }
         }
     }
     usort($act_list, 'sort_func_by_act_date');
     return $act_list;
 }
Example #13
0
 function create_sugar_freebusy($user_bean, $start_date_time, $end_date_time)
 {
     $ical_array = [];
     global $DO_USER_TIME_OFFSET, $timedate;
     $DO_USER_TIME_OFFSET = true;
     if (empty($GLOBALS['current_user']) || empty($GLOBALS['current_user']->id)) {
         $GLOBALS['current_user'] = $user_bean;
     }
     // get activities.. queries Meetings and Calls
     $acts_arr = CalendarActivity::get_activities($user_bean->id, ["show_calls" => true], $start_date_time, $end_date_time, 'freebusy');
     // loop thru each activity, get start/end time in UTC, and return FREEBUSY strings
     foreach ($acts_arr as $act) {
         $startTimeUTC = $act->start_time->format(self::UTC_FORMAT);
         $endTimeUTC = $act->end_time->format(self::UTC_FORMAT);
         $ical_array[] = ["FREEBUSY", $startTimeUTC . "/" . $endTimeUTC];
     }
     return self::create_ical_string_from_array($ical_array);
 }
Example #14
0
 function create_sugar_freebusy($user_bean, $start_date_time, $end_date_time)
 {
     $str = '';
     global $DO_USER_TIME_OFFSET, $timedate;
     $DO_USER_TIME_OFFSET = true;
     if (empty($GLOBALS['current_user']) || empty($GLOBALS['current_user']->id)) {
         $GLOBALS['current_user'] = $user_bean;
     }
     // get activities.. queries Meetings and Calls
     $acts_arr = CalendarActivity::get_activities($user_bean->id, false, $start_date_time, $end_date_time, 'freebusy');
     // loop thru each activity, get start/end time in UTC, and return FREEBUSY strings
     foreach ($acts_arr as $act) {
         if (empty($act->start_time) || empty($act->end_time)) {
             //create error message
             $errMSG = "ERROR in Vcal::create_sugar_freebusy.  Calendar Activity was not created because of missing start or end time";
             if (!empty($act->sugar_bean->id)) {
                 $errMSG .= ", id is " . $act->sugar_bean->id;
             }
             if (!empty($act->sugar_bean->name)) {
                 $errMSG .= ", name is: " . $act->sugar_bean->name;
             }
             //log message and continue
             $GLOBALS['log']->fatal($errMSG);
             continue;
         }
         $startTimeUTC = $act->start_time->format(self::UTC_FORMAT);
         $endTimeUTC = $act->end_time->format(self::UTC_FORMAT);
         $str .= "FREEBUSY:" . $startTimeUTC . "/" . $endTimeUTC . "\n";
     }
     return $str;
 }