Ejemplo n.º 1
3
 /**
  * @deprecated for public use
  * get timezone start & end
  */
 public function getDSTRange($year, $zone)
 {
     $year_date = SugarDateTime::createFromFormat("Y", $year, self::$gmtTimezone);
     $year_end = clone $year_date;
     $year_end->setDate((int) $year, 12, 31);
     $year_end->setTime(23, 59, 59);
     $year_date->setDate((int) $year, 1, 1);
     $year_date->setTime(0, 0, 0);
     $tz = $this->_getUserTZ();
     $transitions = $tz->getTransitions($year_date->getTimestamp(), $year_end->getTimestamp());
     $idx = 0;
     while (!$transitions[$idx]["isdst"]) {
         $idx++;
     }
     $startdate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
     while ($transitions[$idx]["isdst"]) {
         $idx++;
     }
     $enddate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
     return array("start" => $this->asDb($startdate), "end" => $this->asDb($enddate));
 }
Ejemplo n.º 2
0
 public function getAgenda($api, $args)
 {
     // Fetch the next 14 days worth of meetings (limited to 20)
     $end_time = new SugarDateTime("+14 days");
     $start_time = new SugarDateTime("-1 hour");
     $meeting = BeanFactory::newBean('Meetings');
     $meetingList = $meeting->get_list('date_start', "date_start > " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($start_time->asDb()), 'datetime') . " AND date_start < " . $GLOBALS['db']->convert($GLOBALS['db']->quoted($end_time->asDb()), 'datetime'));
     // Setup the breaks for the various time periods
     $datetime = new SugarDateTime();
     $today_stamp = $datetime->get_day_end()->getTimestamp();
     $tomorrow_stamp = $datetime->setDate($datetime->year, $datetime->month, $datetime->day + 1)->get_day_end()->getTimestamp();
     $timeDate = TimeDate::getInstance();
     $returnedMeetings = array('today' => array(), 'tomorrow' => array(), 'upcoming' => array());
     foreach ($meetingList['list'] as $meetingBean) {
         $meetingStamp = $timeDate->fromUser($meetingBean->date_start)->getTimestamp();
         $meetingData = $this->formatBean($api, $args, $meetingBean);
         if ($meetingStamp < $today_stamp) {
             $returnedMeetings['today'][] = $meetingData;
         } else {
             if ($meetingStamp < $tomorrow_stamp) {
                 $returnedMeetings['tomorrow'][] = $meetingData;
             } else {
                 $returnedMeetings['upcoming'][] = $meetingData;
             }
         }
     }
     return $returnedMeetings;
 }
Ejemplo n.º 3
0
 /**
  * Get array of needed time data
  * @param SugarBean $bean 
  * @return array
  */
 static function get_time_data($bean)
 {
     $arr = array();
     $date_field = "date_start";
     if ($bean->object_name == 'Task') {
         $date_field = "date_due";
     }
     $timestamp = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $bean->{$date_field}, new DateTimeZone('UTC'))->format('U');
     $arr['timestamp'] = $timestamp;
     $arr['time_start'] = $GLOBALS['timedate']->fromTimestamp($arr['timestamp'])->format($GLOBALS['timedate']->get_time_format());
     return $arr;
 }
Ejemplo n.º 4
0
 /**
  * DateTime homebrew parser
  *
  * Since some OSes and PHP versions (please upgrade to 5.3!) do not support built-in parsing functions,
  * we have to restort to this ugliness.
  * @internal
  * @param string $time  Time formatted string
  * @param string $format Format, as accepted by strptime()
  * @return array Parsed parts
  */
 protected function _strptime($time, $format)
 {
     $data = self::$data_init;
     if (empty(self::$strptime_short_mon)) {
         self::$strptime_short_mon = array_flip($this->_getStrings('dom_cal_month'));
         unset(self::$strptime_short_mon[""]);
     }
     if (empty(self::$strptime_long_mon)) {
         self::$strptime_long_mon = array_flip($this->_getStrings('dom_cal_month_long'));
         unset(self::$strptime_long_mon[""]);
     }
     $regexp = TimeDate::get_regular_expression($format);
     if (!preg_match('@' . $regexp['format'] . '@', $time, $dateparts)) {
         return false;
     }
     foreach (self::$parts_match as $part => $datapart) {
         if (isset($regexp['positions'][$part]) && isset($dateparts[$regexp['positions'][$part]])) {
             $data[$datapart] = (int) $dateparts[$regexp['positions'][$part]];
         }
     }
     // now process non-numeric ones
     if (isset($regexp['positions']['F']) && !empty($dateparts[$regexp['positions']['F']])) {
         // FIXME: locale?
         $mon = $dateparts[$regexp['positions']['F']];
         if (isset(self::$sugar_strptime_long_mon[$mon])) {
             $data["tm_mon"] = self::$sugar_strptime_long_mon[$mon];
         } else {
             return false;
         }
     }
     if (isset($regexp['positions']['M']) && !empty($dateparts[$regexp['positions']['M']])) {
         // FIXME: locale?
         $mon = $dateparts[$regexp['positions']['M']];
         if (isset(self::$sugar_strptime_short_mon[$mon])) {
             $data["tm_mon"] = self::$sugar_strptime_short_mon[$mon];
         } else {
             return false;
         }
     }
     if (isset($regexp['positions']['a']) && !empty($dateparts[$regexp['positions']['a']])) {
         $ampm = trim($dateparts[$regexp['positions']['a']]);
         if ($ampm == 'pm') {
             if ($data["tm_hour"] != 12) {
                 $data["tm_hour"] += 12;
             }
         } else {
             if ($ampm == 'am') {
                 if ($data["tm_hour"] == 12) {
                     // 12:00am is 00:00
                     $data["tm_hour"] = 0;
                 }
             } else {
                 return false;
             }
         }
     }
     if (isset($regexp['positions']['A']) && !empty($dateparts[$regexp['positions']['A']])) {
         $ampm = trim($dateparts[$regexp['positions']['A']]);
         if ($ampm == 'PM') {
             if ($data["tm_hour"] != 12) {
                 $data["tm_hour"] += 12;
             }
         } else {
             if ($ampm == 'AM') {
                 if ($data["tm_hour"] == 12) {
                     // 12:00am is 00:00
                     $data["tm_hour"] = 0;
                 }
             } else {
                 return false;
             }
         }
     }
     return $data;
 }
Ejemplo n.º 5
0
 /**
  * Set the DateTime Search Data based on Current User TimeZone
  *
  * @param  string $userSearchDateTime  - user Search Datetime
  * @return string $dbSearchDateTime    - database Search Datetime
  */
 public function toDatabaseSearchDateTime($userSearchDateTime)
 {
     global $timedate;
     global $current_user;
     $usertimezone = $current_user->getPreference('timezone');
     if (empty($usertimezone)) {
         $usertimezone = "UTC";
     }
     $tz = new DateTimeZone($usertimezone);
     $sugarDateTime = new SugarDateTime($userSearchDateTime);
     $sugarDateTime->setTimezone($tz);
     $dbSearchDateTime = $timedate->asDb($sugarDateTime);
     return $dbSearchDateTime;
 }
Ejemplo n.º 6
0
 /**
  * @see SugarFieldBase::importSanitize()
  */
 public function importSanitize($value, $vardef, $focus, ImportFieldSanitize $settings)
 {
     global $timedate;
     $format = $timedate->merge_date_time($settings->dateformat, $settings->timeformat);
     if (!$timedate->check_matching_format($value, $format)) {
         $parts = $timedate->split_date_time($value);
         if (empty($parts[0])) {
             $datepart = $timedate->getNow()->format($settings->dateformat);
         } else {
             $datepart = $parts[0];
         }
         if (empty($parts[1])) {
             $timepart = $timedate->fromTimestamp(0)->format($settings->timeformat);
         } else {
             $timepart = $parts[1];
             // see if we can get by stripping the seconds
             if (strpos($settings->timeformat, 's') === false) {
                 $sep = $timedate->timeSeparatorFormat($settings->timeformat);
                 // We are assuming here seconds are the last component, which
                 // is kind of reasonable - no sane time format puts seconds first
                 $timeparts = explode($sep, $timepart);
                 if (!empty($timeparts[2])) {
                     $timepart = join($sep, array($timeparts[0], $timeparts[1]));
                 }
             }
         }
         $value = $timedate->merge_date_time($datepart, $timepart);
         if (!$timedate->check_matching_format($value, $format)) {
             return false;
         }
     }
     try {
         $date = SugarDateTime::createFromFormat($format, $value, new DateTimeZone($settings->timezone));
     } catch (Exception $e) {
         return false;
     }
     return $date->asDb();
 }
Ejemplo n.º 7
0
 /**
  * Save repeat activities
  * @param SugarBean $bean
  * @param array $timeArray array of datetimes
  * @return array
  */
 static function saveRecurring(SugarBean $bean, $timeArray)
 {
     // Here we will create single big inserting query for each invitee relationship
     // rather than using relationships framework due to performance issues.
     // Relationship framework runs very slowly
     $db = $GLOBALS['db'];
     $id = $bean->id;
     $date_modified = $GLOBALS['timedate']->nowDb();
     $lower_name = strtolower($bean->object_name);
     $qu = "SELECT * FROM {$bean->rel_users_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $users_rel_arr = array();
     // If the bean has a users_arr then related records for those ids will have
     // already been created. This prevents duplicates of those records for
     // users, contacts and leads (handled below)
     $exclude_users = empty($bean->users_arr) ? array() : array_flip($bean->users_arr);
     while ($ro = $db->fetchByAssoc($re)) {
         if (!isset($exclude_users[$ro['user_id']])) {
             $users_rel_arr[] = $ro['user_id'];
         }
     }
     $qu = "SELECT * FROM {$bean->rel_contacts_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $contacts_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $contacts_rel_arr[] = $ro['contact_id'];
     }
     $qu = "SELECT * FROM {$bean->rel_leads_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $leads_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $leads_rel_arr[] = $ro['lead_id'];
     }
     $qu_contacts = array();
     $qu_users = array();
     $qu_leads = array();
     $arr = array();
     $i = 0;
     Activity::disable();
     $clone = clone $bean;
     //this is a new bean being created - so throw away cloned fetched_row
     //attribute that incorrectly makes it look like an existing bean
     $clone->fetched_row = false;
     foreach ($timeArray as $date_start) {
         $clone->id = "";
         $clone->date_start = $date_start;
         // TODO CHECK DATETIME VARIABLE
         $date = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $date_start);
         $date = $date->get("+{$bean->duration_hours} Hours")->get("+{$bean->duration_minutes} Minutes");
         $date_end = $date->format($GLOBALS['timedate']->get_date_time_format());
         $clone->date_end = $date_end;
         $clone->recurring_source = "Sugar";
         $clone->repeat_parent_id = $id;
         $clone->update_vcal = false;
         $clone->save(false);
         if ($clone->id) {
             foreach ($users_rel_arr as $user_id) {
                 $qu_users[] = array('id' => create_guid(), 'user_id' => $user_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             foreach ($contacts_rel_arr as $contact_id) {
                 $qu_contacts[] = array('id' => create_guid(), 'contact_id' => $contact_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             foreach ($leads_rel_arr as $lead_id) {
                 $qu_leads[] = array('id' => create_guid(), 'lead_id' => $lead_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             if ($i < 44) {
                 $clone->date_start = $date_start;
                 $clone->date_end = $date_end;
                 $arr[] = array_merge(array('id' => $clone->id), CalendarUtils::get_time_data($clone));
             }
             $i++;
         }
     }
     Activity::enable();
     if (!empty($qu_users)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'user_id' => array('name' => 'user_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_users as $qu_user) {
             $db->insertParams($bean->rel_users_table, $fields, $qu_user);
         }
     }
     if (!empty($qu_contacts)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'contact_id' => array('name' => 'contact_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_contacts as $qu_contact) {
             $db->insertParams($bean->rel_contacts_table, $fields, $qu_contact);
         }
     }
     if (!empty($qu_leads)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'lead_id' => array('name' => 'lead_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_leads as $qu_lead) {
             $db->insertParams($bean->rel_leads_table, $fields, $qu_lead);
         }
     }
     vCal::cache_sugar_vcal($GLOBALS['current_user']);
     return $arr;
 }
Ejemplo n.º 8
0
 function fill_in_additional_detail_fields()
 {
     global $locale;
     // Fill in the assigned_user_name
     $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
     if (!empty($this->contact_id)) {
         $query = "SELECT first_name, last_name FROM contacts ";
         $query .= "WHERE id='{$this->contact_id}' AND deleted=0";
         $result = $this->db->limitQuery($query, 0, 1, true, " Error filling in additional detail fields: ");
         // Get the contact name.
         $row = $this->db->fetchByAssoc($result);
         $GLOBALS['log']->info("additional call fields {$query}");
         if ($row != null) {
             $this->contact_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], '', '');
             $GLOBALS['log']->debug("Call({$this->id}): contact_name = {$this->contact_name}");
             $GLOBALS['log']->debug("Call({$this->id}): contact_id = {$this->contact_id}");
         }
     }
     $this->created_by_name = get_assigned_user_name($this->created_by);
     $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
     $this->fill_in_additional_parent_fields();
     if (!isset($this->time_hour_start)) {
         $this->time_start_hour = intval(substr($this->time_start, 0, 2));
     }
     //if-else
     if (isset($this->time_minute_start)) {
         $time_start_minutes = $this->time_minute_start;
     } else {
         $time_start_minutes = substr($this->time_start, 3, 5);
         if ($time_start_minutes > 0 && $time_start_minutes < 15) {
             $time_start_minutes = "15";
         } else {
             if ($time_start_minutes > 15 && $time_start_minutes < 30) {
                 $time_start_minutes = "30";
             } else {
                 if ($time_start_minutes > 30 && $time_start_minutes < 45) {
                     $time_start_minutes = "45";
                 } else {
                     if ($time_start_minutes > 45) {
                         $this->time_start_hour += 1;
                         $time_start_minutes = "00";
                     }
                 }
             }
         }
         //if-else
     }
     //if-else
     if (isset($this->time_hour_start)) {
         $time_start_hour = $this->time_hour_start;
     } else {
         $time_start_hour = intval(substr($this->time_start, 0, 2));
     }
     global $timedate;
     $this->time_meridiem = $timedate->AMPMMenu('', $this->time_start, 'onchange="SugarWidgetScheduler.update_time();"');
     $hours_arr = array();
     $num_of_hours = 13;
     $start_at = 1;
     if (empty($time_meridiem)) {
         $num_of_hours = 24;
         $start_at = 0;
     }
     //if
     for ($i = $start_at; $i < $num_of_hours; $i++) {
         $i = $i . "";
         if (strlen($i) == 1) {
             $i = "0" . $i;
         }
         $hours_arr[$i] = $i;
     }
     //for
     if (!isset($this->duration_minutes)) {
         $this->duration_minutes = $this->minutes_value_default;
     }
     //setting default date and time
     if (is_null($this->date_start)) {
         $this->date_start = $timedate->now();
     }
     if (is_null($this->time_start)) {
         $this->time_start = $timedate->to_display_time(TimeDate::getInstance()->nowDb(), true);
     }
     if (is_null($this->duration_hours)) {
         $this->duration_hours = "0";
     }
     if (is_null($this->duration_minutes)) {
         $this->duration_minutes = "1";
     }
     if (empty($this->id) && !empty($_REQUEST['date_start'])) {
         $this->date_start = $_REQUEST['date_start'];
     }
     if (!empty($this->date_start)) {
         $start = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $this->date_start);
         if (!empty($start)) {
             if (!empty($this->duration_hours) || !empty($this->duration_minutes)) {
                 $this->date_end = $start->modify("+{$this->duration_hours} Hours +{$this->duration_minutes} Minutes")->format($GLOBALS['timedate']->get_date_time_format());
             }
         } else {
             $GLOBALS['log']->fatal("Meeting::save: Bad date {$this->date_start} for format " . $GLOBALS['timedate']->get_date_time_format());
         }
     }
     global $app_list_strings;
     $parent_types = $app_list_strings['record_type_display'];
     $disabled_parent_types = ACLController::disabledModuleList($parent_types, false, 'list');
     foreach ($disabled_parent_types as $disabled_parent_type) {
         if ($disabled_parent_type != $this->parent_type) {
             unset($parent_types[$disabled_parent_type]);
         }
     }
     $this->parent_type_options = get_select_options_with_id($parent_types, $this->parent_type);
     if (empty($this->reminder_time)) {
         $this->reminder_time = -1;
     }
     if (empty($this->id)) {
         $reminder_t = $GLOBALS['current_user']->getPreference('reminder_time');
         if (isset($reminder_t)) {
             $this->reminder_time = $reminder_t;
         }
     }
     $this->reminder_checked = $this->reminder_time == -1 ? false : true;
     if (empty($this->email_reminder_time)) {
         $this->email_reminder_time = -1;
     }
     if (empty($this->id)) {
         $reminder_t = $GLOBALS['current_user']->getPreference('email_reminder_time');
         if (isset($reminder_t)) {
             $this->email_reminder_time = $reminder_t;
         }
     }
     $this->email_reminder_checked = $this->email_reminder_time == -1 ? false : true;
     if (isset($_REQUEST['parent_type'])) {
         $this->parent_type = $_REQUEST['parent_type'];
     } elseif (is_null($this->parent_type)) {
         $this->parent_type = $app_list_strings['record_type_default_key'];
     }
 }
Ejemplo n.º 9
0
 /**
  * get ics file content for meeting invite email
  */
 public static function get_ical_event(SugarBean $bean, User $user)
 {
     $str = "";
     $str .= "BEGIN:VCALENDAR\n";
     $str .= "VERSION:2.0\n";
     $str .= "PRODID:-//SugarCRM//SugarCRM Calendar//EN\n";
     $str .= "BEGIN:VEVENT\n";
     $str .= "UID:" . $bean->id . "\n";
     $str .= "ORGANIZER;CN=" . $user->full_name . ":" . $user->email1 . "\n";
     $str .= "DTSTART:" . SugarDateTime::createFromFormat($GLOBALS['timedate']->get_db_date_time_format(), $bean->date_start)->format(self::UTC_FORMAT) . "\n";
     $str .= "DTEND:" . SugarDateTime::createFromFormat($GLOBALS['timedate']->get_db_date_time_format(), $bean->date_end)->format(self::UTC_FORMAT) . "\n";
     $str .= "DTSTAMP:" . $GLOBALS['timedate']->getNow(false)->format(self::UTC_FORMAT) . "\n";
     $str .= "SUMMARY:" . $bean->name . "\n";
     $str .= "DESCRIPTION:" . $bean->description . "\n";
     $str .= "END:VEVENT\n";
     $str .= "END:VCALENDAR\n";
     return $str;
 }
Ejemplo n.º 10
0
 /**
  * Formats a DateTime object as string for given widget
  *
  * @param SugarDateTime $date - Date to be formatted for widget
  * @return string date formatted for widget type
  */
 protected function formatDate($date)
 {
     return $date->asDbDate(false);
 }
Ejemplo n.º 11
0
 /**
  * @param integer $duration
  * @param string|null $start_date The starting date in format of Y-m-d
  * @return array
  */
 public function getGenericStartEndByDuration($duration, $start_date = null)
 {
     $mapping = array('current' => 0, 'next' => 3, 'year' => 12);
     if (array_key_exists($duration, $mapping)) {
         $duration = $mapping[$duration];
     } elseif (!is_numeric($duration)) {
         $duration = 0;
     }
     $start = false;
     if (!is_null($start_date)) {
         $start = SugarDateTime::createFromFormat('Y-m-d', $start_date);
         $end = SugarDateTime::createFromFormat('Y-m-d', $start_date);
     }
     if ($start === false) {
         $start = new SugarDateTime();
         $end = new SugarDateTime();
     }
     // since we subtract one from the month, we need to add one to the duration since php is
     // not zero 0 based for months
     // figure out what the starting month is.
     $startMonth = floor(($start->month - 1) / 3) * 3 + $duration + 1;
     $year = $start->year;
     $endYear = $year;
     $endMonth = $startMonth + 3;
     // if the end month is dec, we put it to Jan and increase the end year as well so it goes back to the last
     // day of dec
     if ($endMonth == 12) {
         $endYear++;
         $endMonth = 1;
     }
     if ($duration == 12) {
         $endYear++;
         $startMonth = 1;
         $endMonth = 1;
     }
     $start->setDate($year, $startMonth, 1);
     $end->setDate($endYear, $endMonth, 0);
     // since we are using timestamp, we need to convert this into UTC since that is
     // what the DB is storing as
     $tz = new DateTimeZone("UTC");
     return array('start_date' => $start->asDbDate(false), 'start_date_timestamp' => $start->setTimezone($tz)->setTime(0, 0, 0)->format('U'), 'end_date' => $end->asDbDate(false), 'end_date_timestamp' => $end->setTimezone($tz)->setTime(0, 0, 0)->format('U'));
 }
Ejemplo n.º 12
0
 protected static function addTrackerFilter(SugarQuery $q, SugarQuery_Builder_Where $where, $interval)
 {
     global $db;
     $td = new SugarDateTime();
     $td->modify($interval);
     $min_date = $td->asDb();
     // Have to do a subselect because MAX() and GROUP BY don't get along with
     // databases other than MySQL
     $q->joinRaw(" INNER JOIN ( SELECT t.item_id item_id, MAX(t.date_modified) track_max " . " FROM tracker t " . " WHERE t.module_name = '" . $db->quote($q->from->module_name) . "' " . " AND t.user_id = '" . $db->quote($GLOBALS['current_user']->id) . "' " . " AND t.date_modified >= " . $db->convert("'" . $min_date . "'", 'datetime') . " " . " GROUP BY t.item_id " . " ) tracker ON tracker.item_id = " . $q->from->getTableName() . ".id ", array('alias' => 'tracker'));
     // Now, if they want tracker records, so let's order it by the tracker date_modified
     $q->order_by = array();
     $q->orderByRaw('tracker.track_max', 'DESC');
     $q->distinct(false);
 }
 /**
  * Formats a DateTime object as string for given widget
  *
  * @param SugarDateTime $date - Date to be formatted for widget
  * @return string date formatted for widget type
  */
 protected function formatDate($date)
 {
     return $date->asDb();
 }
Ejemplo n.º 14
0
 /**
  * @deprecated for public use
  * get timezone start & end
  */
 public function getDSTRange($year, $zone)
 {
     $tz = $this->_getUserTZ();
     if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
         $year_date = SugarDateTime::createFromFormat("Y", $year, self::$gmtTimezone);
         $year_end = clone $year_date;
         $year_end->setDate((int) $year, 12, 31);
         $year_end->setTime(23, 59, 59);
         $year_date->setDate((int) $year, 1, 1);
         $year_date->setTime(0, 0, 0);
         $transitions = $tz->getTransitions($year_date->getTimestamp(), $year_end->getTimestamp());
         $idx = 0;
         while (!$transitions[$idx]["isdst"]) {
             $idx++;
         }
         $startdate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
         while ($transitions[$idx]["isdst"]) {
             $idx++;
         }
         $enddate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
     } else {
         $transitions = $tz->getTransitions();
         $idx = 0;
         while (!$transitions[$idx]["isdst"] || intval(substr($transitions[$idx]["time"], 0, 4)) < intval(date("Y"))) {
             $idx++;
         }
         $startdate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
         while ($transitions[$idx]["isdst"] || intval(substr($transitions[$idx]["time"], 0, 4)) < intval(date("Y"))) {
             $idx++;
         }
         $enddate = new DateTime("@" . $transitions[$idx]["ts"], self::$gmtTimezone);
     }
     return array("start" => $this->asDb($startdate), "end" => $this->asDb($enddate));
 }
Ejemplo n.º 15
0
 public function getDSTRange($current_user, $year)
 {
     $tz = $this->getUserTimezone($current_user);
     if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
         $year_date = SugarDateTime::createFromFormat("Y", $year, $tz);
         $year_end = clone $year_date;
         $year_end->setDate((int) $year, 12, 31);
         $year_end->setTime(23, 59, 59);
         $year_date->setDate((int) $year, 1, 1);
         $year_date->setTime(0, 0, 0);
         $transitions = $tz->getTransitions($year_date->getTimestamp(), $year_end->getTimestamp());
         $idx = 0;
         while (!$transitions[$idx]["isdst"] && $idx < count($transitions)) {
             $idx++;
         }
         if (!$transitions[$idx]["isdst"]) {
             // No DST transitions found
             return array();
         }
         $startTransition = $transitions[$idx];
         while ($transitions[$idx]["isdst"]) {
             $idx++;
         }
         $endTransition = $transitions[$idx];
     } else {
         $transitions = $tz->getTransitions();
         $idx = 0;
         while (!$transitions[$idx]["isdst"] || intval(substr($transitions[$idx]["time"], 0, 4)) < intval(date("Y"))) {
             $idx++;
         }
         $startTransition = $transitions[$idx];
         while ($transitions[$idx]["isdst"] || intval(substr($transitions[$idx]["time"], 0, 4)) < intval(date("Y"))) {
             $idx++;
         }
         $endTransition = $transitions[$idx];
     }
     return array("start" => $startTransition, "end" => $endTransition);
 }
Ejemplo n.º 16
0
 /**
  * Save repeat activities
  * @param SugarBean $bean
  * @param array $time_arr array of datetimes
  * @return array
  */
 static function save_repeat_activities(SugarBean $bean, $time_arr)
 {
     // Here we will create single big inserting query for each invitee relationship
     // rather than using relationships framework due to performance issues.
     // Relationship framework runs very slowly
     global $db;
     $id = $bean->id;
     $date_modified = $GLOBALS['timedate']->nowDb();
     $lower_name = strtolower($bean->object_name);
     $qu = "SELECT * FROM {$bean->rel_users_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $users_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $users_rel_arr[] = $ro['user_id'];
     }
     $qu_users = "\n\t\t\t\tINSERT INTO {$bean->rel_users_table}\n\t\t\t\t(id,user_id,{$lower_name}_id,date_modified)\n\t\t\t\tVALUES\n\t\t";
     $users_filled = false;
     $qu = "SELECT * FROM {$bean->rel_contacts_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $contacts_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $contacts_rel_arr[] = $ro['contact_id'];
     }
     $qu_contacts = "\n\t\t\t\tINSERT INTO {$bean->rel_contacts_table}\n\t\t\t\t(id,contact_id,{$lower_name}_id,date_modified)\n\t\t\t\tVALUES\n\t\t";
     $contacts_filled = false;
     $qu = "SELECT * FROM {$bean->rel_leads_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $leads_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $leads_rel_arr[] = $ro['lead_id'];
     }
     $qu_leads = "\n\t\t\t\tINSERT INTO {$bean->rel_leads_table}\n\t\t\t\t(id,lead_id,{$lower_name}_id,date_modified)\n\t\t\t\tVALUES\n\t\t";
     $leads_filled = false;
     $arr = array();
     $i = 0;
     foreach ($time_arr as $date_start) {
         $clone = $bean;
         // we don't use clone keyword cause not necessary
         $clone->id = "";
         $clone->date_start = $date_start;
         // TODO CHECK DATETIME VARIABLE
         $date = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $date_start);
         $date = $date->get("+{$bean->duration_hours} Hours")->get("+{$bean->duration_minutes} Minutes");
         $date_end = $date->format($GLOBALS['timedate']->get_date_time_format());
         $clone->date_end = $date_end;
         $clone->recurring_source = "Sugar";
         $clone->repeat_parent_id = $id;
         $clone->update_vcal = false;
         $clone->save(false);
         if ($clone->id) {
             foreach ($users_rel_arr as $user_id) {
                 if ($users_filled) {
                     $qu_users .= "," . PHP_EOL;
                 }
                 $qu_users .= "('" . create_guid() . "','{$user_id}','{$clone->id}','{$date_modified}')";
                 $users_filled = true;
             }
             foreach ($contacts_rel_arr as $contact_id) {
                 if ($contacts_filled) {
                     $qu_contacts .= "," . PHP_EOL;
                 }
                 $qu_contacts .= "('" . create_guid() . "','{$contact_id}','{$clone->id}','{$date_modified}')";
                 $contacts_filled = true;
             }
             foreach ($leads_rel_arr as $lead_id) {
                 if ($leads_filled) {
                     $qu_leads .= "," . PHP_EOL;
                 }
                 $qu_leads .= "('" . create_guid() . "','{$lead_id}','{$clone->id}','{$date_modified}')";
                 $leads_filled = true;
             }
             if ($i < 44) {
                 $clone->date_start = $date_start;
                 $clone->date_end = $date_end;
                 $arr[] = array_merge(array('id' => $clone->id), CalendarUtils::get_time_data($clone));
             }
             $i++;
         }
     }
     if ($users_filled) {
         $db->query($qu_users);
     }
     if ($contacts_filled) {
         $db->query($qu_contacts);
     }
     if ($leads_filled) {
         $db->query($qu_leads);
     }
     vCal::cache_sugar_vcal($GLOBALS['current_user']);
     return $arr;
 }
Ejemplo n.º 17
0
 function get_freebusy_activities($user_focus, $start_date_time, $end_date_time)
 {
     $act_list = array();
     $vcal_focus = new vCal();
     $vcal_str = $vcal_focus->get_vcal_freebusy($user_focus);
     $lines = explode("\n", $vcal_str);
     $utc = new DateTimeZone("UTC");
     foreach ($lines as $line) {
         if (preg_match('/^FREEBUSY.*?:([^\\/]+)\\/([^\\/]+)/i', $line, $matches)) {
             $dates_arr = array(SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[1], $utc), SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[2], $utc));
             $act_list[] = new CalendarActivity($dates_arr);
         }
     }
     return $act_list;
 }
Ejemplo n.º 18
0
 function fill_in_additional_detail_fields()
 {
     global $locale;
     parent::fill_in_additional_detail_fields();
     if (!empty($this->contact_id)) {
         $query = "SELECT first_name, last_name FROM contacts ";
         $query .= "WHERE id='{$this->contact_id}' AND deleted=0";
         $result = $this->db->limitQuery($query, 0, 1, true, " Error filling in additional detail fields: ");
         // Get the contact name.
         $row = $this->db->fetchByAssoc($result);
         $GLOBALS['log']->info("additional call fields {$query}");
         if ($row != null) {
             $this->contact_name = $locale->formatName('Contacts', $row);
             $GLOBALS['log']->debug("Call({$this->id}): contact_name = {$this->contact_name}");
             $GLOBALS['log']->debug("Call({$this->id}): contact_id = {$this->contact_id}");
         }
     }
     if (!isset($this->time_hour_start)) {
         $this->time_start_hour = intval(substr($this->time_start, 0, 2));
     }
     //if-else
     if (isset($this->time_minute_start)) {
         $time_start_minutes = $this->time_minute_start;
     } else {
         $time_start_minutes = substr($this->time_start, 3, 5);
         if ($time_start_minutes > 0 && $time_start_minutes < 15) {
             $time_start_minutes = "15";
         } else {
             if ($time_start_minutes > 15 && $time_start_minutes < 30) {
                 $time_start_minutes = "30";
             } else {
                 if ($time_start_minutes > 30 && $time_start_minutes < 45) {
                     $time_start_minutes = "45";
                 } else {
                     if ($time_start_minutes > 45) {
                         $this->time_start_hour += 1;
                         $time_start_minutes = "00";
                     }
                 }
             }
         }
         //if-else
     }
     //if-else
     if (isset($this->time_hour_start)) {
         $time_start_hour = $this->time_hour_start;
     } else {
         $time_start_hour = intval(substr($this->time_start, 0, 2));
     }
     global $timedate;
     $this->time_meridiem = $timedate->AMPMMenu('', $this->time_start, 'onchange="SugarWidgetScheduler.update_time();"');
     $hours_arr = array();
     $num_of_hours = 13;
     $start_at = 1;
     if (empty($time_meridiem)) {
         $num_of_hours = 24;
         $start_at = 0;
     }
     //if
     for ($i = $start_at; $i < $num_of_hours; $i++) {
         $i = $i . "";
         if (strlen($i) == 1) {
             $i = "0" . $i;
         }
         $hours_arr[$i] = $i;
     }
     //for
     if (!isset($this->duration_minutes)) {
         $this->duration_minutes = $this->minutes_value_default;
     }
     //setting default date and time
     if (is_null($this->date_start)) {
         $this->date_start = $timedate->now();
     }
     if (is_null($this->time_start)) {
         $this->time_start = $timedate->to_display_time(TimeDate::getInstance()->nowDb(), true);
     }
     if (is_null($this->duration_hours)) {
         $this->duration_hours = "0";
     }
     if (is_null($this->duration_minutes)) {
         $this->duration_minutes = "1";
     }
     if (empty($this->id) && !empty($_REQUEST['date_start'])) {
         $this->date_start = $_REQUEST['date_start'];
     }
     if (!empty($this->date_start)) {
         $td = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $this->date_start);
         if (!empty($td)) {
             if (!empty($this->duration_hours) && $this->duration_hours != '') {
                 $td = $td->modify("+{$this->duration_hours} hours");
             }
             if (!empty($this->duration_minutes) && $this->duration_minutes != '') {
                 $td = $td->modify("+{$this->duration_minutes} mins");
             }
             $this->date_end = $td->format($GLOBALS['timedate']->get_date_time_format());
         } else {
             $GLOBALS['log']->fatal("Meeting::save: Bad date {$this->date_start} for format " . $GLOBALS['timedate']->get_date_time_format());
         }
     }
     global $app_list_strings;
     if (empty($this->reminder_time)) {
         $this->reminder_time = -1;
     }
     if (empty($this->id)) {
         $reminder_t = $GLOBALS['current_user']->getPreference('reminder_time');
         if (isset($reminder_t)) {
             $this->reminder_time = $reminder_t;
         }
     }
     $this->reminder_checked = $this->reminder_time == -1 ? false : true;
     if (empty($this->email_reminder_time)) {
         $this->email_reminder_time = -1;
     }
     if (empty($this->id)) {
         $reminder_t = $GLOBALS['current_user']->getPreference('email_reminder_time');
         if (isset($reminder_t)) {
             $this->email_reminder_time = $reminder_t;
         }
     }
     $this->email_reminder_checked = $this->email_reminder_time == -1 ? false : true;
     if (isset($_REQUEST['parent_type']) && empty($this->parent_type)) {
         $this->parent_type = $_REQUEST['parent_type'];
     } elseif (is_null($this->parent_type)) {
         $this->parent_type = $app_list_strings['record_type_default_key'];
     }
     // Fill in the meeting url for external account types
     if (!empty($this->id) && !empty($this->type) && $this->type != 'Sugar' && !empty($this->join_url)) {
         // It's an external meeting
         global $mod_strings;
         $meetingLink = '';
         if ($GLOBALS['current_user']->id == $this->assigned_user_id) {
             $meetingLink .= '<a href="index.php?module=Meetings&action=JoinExternalMeeting&meeting_id=' . $this->id . '&host_meeting=1" target="_blank">' . SugarThemeRegistry::current()->getImage("start_meeting_inline", 'border="0" ', 18, 19, ".png", translate('LBL_HOST_EXT_MEETING', $this->module_dir)) . '</a>';
         }
         $meetingLink .= '<a href="index.php?module=Meetings&action=JoinExternalMeeting&meeting_id=' . $this->id . '" target="_blank">' . SugarThemeRegistry::current()->getImage("join_meeting_inline", 'border="0" ', 18, 19, ".png", translate('LBL_JOIN_EXT_MEETING', $this->module_dir)) . '</a>';
         $this->displayed_url = $meetingLink;
     }
 }
Ejemplo n.º 19
0
 /**
  * Returns query object to retrieve list of recently viewed records by
  * module.
  *
  * @param SugarBean $seed Instance of current bean.
  * @param array $options Prepared options.
  * @return SugarQuery query to execute.
  */
 protected function getRecentlyViewedQueryObject($seed, $options)
 {
     $currentUser = $this->getUserBean();
     $query = new SugarQuery();
     $query->from($seed);
     // FIXME: FRM-226, logic for these needs to be moved to SugarQuery
     // Since tracker relationships don't actually exist, we're gonna have to add a direct join
     $query->joinRaw(sprintf(" JOIN tracker ON tracker.item_id=%s.id AND tracker.module_name='%s' AND tracker.user_id='%s' ", $query->from->getTableName(), $query->from->module_name, $currentUser->id), array('alias' => 'tracker'));
     // we need to set the linkName to hack around tracker not having real relationships
     /* TODO think about how to fix this so we can be less restrictive to raw joins that don't have a relationship */
     $query->join['tracker']->linkName = 'tracker';
     $query->select(array('id', array('tracker.module_name', 'module_name')));
     if (!empty($options['date'])) {
         $td = new SugarDateTime();
         $td->modify($options['date']);
         $query->where()->queryAnd()->gte('tracker.date_modified', $td->asDb());
     }
     foreach ($query->select()->select as $v) {
         $query->groupBy($v->table . '.' . $v->field);
     }
     $query->select()->fieldRaw('MAX(tracker.date_modified)', 'last_viewed_date');
     return $query;
 }
Ejemplo n.º 20
0
 /**
  * @dataProvider dateRanges
  */
 public function testparseDateRange($range, $start, $end)
 {
     $this->time_date->setNow(SugarDateTime::createFromFormat(TimeDate::DB_DATETIME_FORMAT, "2011-08-30 12:01:02", new DateTimeZone($this->time_date->userTimezone())));
     $this->time_date->allow_cache = true;
     $daterage = $this->time_date->parseDateRange($range);
     $this->assertEquals($start, $daterage[0]->format(TimeDate::DB_DATETIME_FORMAT), 'Start date is wrong');
     $this->assertEquals($end, $daterage[1]->format(TimeDate::DB_DATETIME_FORMAT), 'End date is wrong');
 }
Ejemplo n.º 21
0
 /**
  * @deprecated for public use
  * get timezone start & end
  * @param $year
  * @param string $zone
  * @return array
  */
 public function getDSTRange($year, $zone = null)
 {
     if (!empty($zone)) {
         $tz = timezone_open($zone);
     }
     if (empty($tz)) {
         $tz = $this->_getUserTZ();
     }
     $year_date = SugarDateTime::createFromFormat("Y", $year, self::$gmtTimezone);
     $year_end = clone $year_date;
     $year_end->setDate((int) $year, 12, 31);
     $year_end->setTime(23, 59, 59);
     $year_date->setDate((int) $year, 1, 1);
     $year_date->setTime(0, 0, 0);
     $result = array();
     $transitions = $tz->getTransitions($year_date->ts, $year_end->ts);
     $idx = 0;
     if (version_compare(PHP_VERSION, '5.3.0', '<')) {
         // <5.3.0 ignores parameters, advance manually to current year
         $start_ts = $year_date->ts;
         while (isset($transitions[$idx]) && $transitions[$idx]["ts"] < $start_ts) {
             $idx++;
         }
     }
     // get DST start
     while (isset($transitions[$idx]) && !$transitions[$idx]["isdst"]) {
         $idx++;
     }
     if (isset($transitions[$idx])) {
         $result["start"] = $this->fromTimestamp($transitions[$idx]["ts"])->asDb();
     }
     // get DST end
     while (isset($transitions[$idx]) && $transitions[$idx]["isdst"]) {
         $idx++;
     }
     if (isset($transitions[$idx])) {
         $result["end"] = $this->fromTimestamp($transitions[$idx]["ts"])->asDb();
     }
     return $result;
 }
Ejemplo n.º 22
0
 /**
  * @dataProvider stringFormats
  * @param string $format
  * @param string $string
  * @param string $result
  */
 public function testCreateFromString($format, $string, $result)
 {
     $this->_setPrefs("Y-m-d", $format, "GMT");
     $tz = new DateTimeZone("GMT");
     SugarDateTime::$use_php_parser = true;
     $date = SugarDateTime::createFromFormat($format, $string, $tz);
     $this->assertInstanceOf("SugarDateTime", $date, "Parsing {$string} failed with PHP parser");
     $this->assertEquals($result, $this->time_date->getTimePart($date->asDb()));
     SugarDateTime::$use_php_parser = false;
     $date = SugarDateTime::createFromFormat($format, $string, $tz);
     $this->assertInstanceOf("SugarDateTime", $date, "Parsing {$string} failed with strptime");
     $this->assertEquals($result, $this->time_date->getTimePart($date->asDb()));
     SugarDateTime::$use_strptime = false;
     $date = SugarDateTime::createFromFormat($format, $string, $tz);
     $this->assertInstanceOf("SugarDateTime", $date, "Parsing {$string} failed with manual parser");
     $this->assertEquals($result, $this->time_date->getTimePart($date->asDb()));
     SugarDateTime::$use_php_parser = true;
     SugarDateTime::$use_strptime = true;
 }
 /**
  * Create query from the beginning to the end of certain month
  * @param array $layout_def
  * @param SugarDateTime $month
  */
 protected function queryMonth($layout_def, $month)
 {
     $begin = $month->setTime(0, 0, 0);
     $end = clone $begin;
     $end->setDate($begin->year, $begin->month, $begin->days_in_month)->setTime(23, 59, 59);
     return $this->get_start_end_date_filter($layout_def, $begin->asDb(), $end->asDb());
 }
Ejemplo n.º 24
0
 /**
  * Retrieve a list of this person's calendar event start and end times ordered by start datetime
  * @return array
  */
 public function getFreeBusySchedule(array $options = array())
 {
     global $timedate;
     global $sugar_config;
     //--- Explicit config can be used to force use of vCal Cache instead of RealTime Search
     $useFreeBusyCache = !empty($sugar_config['freebusy_use_vcal_cache']);
     $vcalBean = BeanFactory::getBean('vCals');
     if (!$useFreeBusyCache && !empty($options['start']) && !empty($options['end'])) {
         $sugarDateTimeStart = $timedate->fromIso($options['start']);
         $sugarDateTimeEnd = $timedate->fromIso($options['end']);
         $vcalData = $vcalBean->get_vcal_freebusy($this, false, $sugarDateTimeStart, $sugarDateTimeEnd);
     } else {
         $vcalData = $vcalBean->get_vcal_freebusy($this, true);
     }
     $vcalData = str_replace("\r\n", "\n", $vcalData);
     $lines = explode("\n", $vcalData);
     $utc = new DateTimeZone("UTC");
     $activities = array();
     foreach ($lines as $line) {
         if (preg_match('/^FREEBUSY.*?:([^\\/]+)\\/([^\\/]+)/i', $line, $matches)) {
             $datesArray = array(SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[1], $utc), SugarDateTime::createFromFormat(vCal::UTC_FORMAT, $matches[2], $utc));
             $act = new CalendarActivity($datesArray);
             $startTime = $timedate->asIso($act->start_time);
             $endTime = $timedate->asIso($act->end_time);
             $activities[$startTime] = array("start" => $startTime, "end" => $endTime);
         }
     }
     ksort($activities);
     // order by start date
     $freeBusySchedule = array();
     foreach ($activities as $startDate => $act) {
         $freeBusySchedule[] = $act;
     }
     return $freeBusySchedule;
 }
Ejemplo n.º 25
0
 /**
  * Gets the daylight savings range for the given user.
  *
  * @param User $current_user the user
  * @param integer $year the year
  * @return array the start and end transitions of daylight savings
  */
 protected function getDSTRange($current_user, $year)
 {
     $tz = $this->getUserTimezone($current_user);
     $idx = 0;
     $result = array();
     if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
         $year_date = SugarDateTime::createFromFormat("Y", $year, new DateTimeZone("UTC"));
         $year_end = clone $year_date;
         $year_end->setDate((int) $year, 12, 31);
         $year_end->setTime(23, 59, 59);
         $year_date->setDate((int) $year, 1, 1);
         $year_date->setTime(0, 0, 0);
         $transitions = $tz->getTransitions($year_date->getTimestamp(), $year_end->getTimestamp());
         foreach ($transitions as $transition) {
             if ($transition['isdst']) {
                 break;
             }
             $idx++;
         }
     } else {
         $transitions = $tz->getTransitions();
         $idx = 0;
         foreach ($transitions as $transition) {
             if ($transition['isdst'] && intval(substr($transition["time"], 0, 4)) == intval(date("Y"))) {
                 break;
             }
             $idx++;
         }
     }
     if (empty($transitions[$idx]["isdst"])) {
         // No DST transitions found
         return $result;
     }
     $result["start"] = $transitions[$idx];
     // DST begins here
     // scan till DST ends
     while (isset($transitions[$idx]) && $transitions[$idx]["isdst"]) {
         $idx++;
     }
     if (isset($transitions[$idx])) {
         $result["end"] = $transitions[$idx];
     }
     return $result;
 }
 function display()
 {
     require_once "modules/Calendar/CalendarUtils.php";
     $field_list = CalendarUtils::get_fields();
     global $beanFiles, $beanList;
     $module = $_REQUEST['current_module'];
     require_once $beanFiles[$beanList[$module]];
     $bean = new $beanList[$module]();
     $type = strtolower($beanList[$module]);
     $table_name = $bean->table_name;
     if (!empty($_REQUEST['record'])) {
         $bean->retrieve($_REQUEST['record']);
     }
     if (!$bean->ACLAccess('Save')) {
         $json_arr = array('success' => 'no');
         echo json_encode($json_arr);
         die;
     }
     require_once 'include/formbase.php';
     $bean = populateFromPost("", $bean);
     if (!$_REQUEST['reminder_checked']) {
         $bean->reminder_time = -1;
     }
     if (empty($_REQUEST['record']) && strpos($_POST['user_invitees'], $bean->assigned_user_id) === false) {
         $_POST['user_invitees'] .= "," . $bean->assigned_user_id;
     }
     // fill invites and save the entry
     $this->save_activity($bean);
     if ($r_id = $bean->id) {
         $u = new User();
         $u->retrieve($bean->assigned_user_id);
         $arr_rec = array();
         $bean->retrieve($r_id);
         if (isset($bean->parent_name)) {
             $bean->parent_name = $_REQUEST['parent_name'];
         }
         $bean->fill_in_additional_parent_fields();
         global $timedate;
         $date_field = "date_start";
         if ($_REQUEST['current_module'] == "Tasks") {
             $date_field = "date_due";
         }
         $timestamp = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $bean->{$date_field}, new DateTimeZone('UTC'))->format('U');
         if ($_REQUEST['current_module'] == 'Calls') {
             $users = $bean->get_call_users();
         }
         if ($_REQUEST['current_module'] == 'Meetings') {
             $users = $bean->get_meeting_users();
         }
         $user_ids = array();
         foreach ($users as $u) {
             $user_ids[] = $u->id;
         }
         $field_arr = array();
         foreach ($field_list[$_REQUEST['current_module']] as $field) {
             $field_arr[$field] = $bean->{$field};
             if ($bean->field_defs[$field]['type'] == 'text') {
                 $t = $field_arr[$field];
                 if (strlen($t) > 300) {
                     $t = substr($t, 0, 300);
                     $t .= "...";
                 }
                 $t = str_replace("\r\n", "<br>", $t);
                 $t = str_replace("\r", "<br>", $t);
                 $t = str_replace("\n", "<br>", $t);
                 $t = html_entity_decode($t, ENT_QUOTES);
                 $field_arr[$field] = $t;
             }
         }
         $json_arr = array('success' => 'yes', 'type' => $type, 'module_name' => $bean->module_dir, 'user_id' => $GLOBALS['current_user']->id, 'detail' => 1, 'edit' => 1, 'record_name' => html_entity_decode($bean->name, ENT_QUOTES), 'record' => $bean->id, 'users' => $user_ids);
         $json_arr = array_merge($json_arr, $field_arr);
         $json_arr = array_merge($json_arr, CalendarUtils::get_time_data($bean));
     } else {
         $json_arr = array('success' => 'no');
     }
     ob_clean();
     echo json_encode($json_arr);
 }