예제 #1
0
파일: iCal.php 프로젝트: MexinaD/SuiteCRM
 /**
  * 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;
 }
예제 #2
0
파일: iCal.php 프로젝트: omusico/sugar_work
 /**
  * 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;
 }
예제 #3
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;
 }
예제 #4
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;
 }