Ejemplo n.º 1
0
 public static function crm_event_get($id, $day = null)
 {
     if (!is_array($id)) {
         $id = explode('_', $id);
         if (isset($id[1]) && $day === null) {
             $day = $id[1];
         }
         $id = reset($id);
         $r = Utils_RecordBrowserCommon::get_record('crm_meeting', $id);
     } else {
         $r = $id;
         $id = $r['id'];
     }
     $r = Utils_RecordBrowserCommon::filter_record_by_access('crm_meeting', $r);
     if ($r === false) {
         return null;
     }
     $next = array('type' => __('Meeting'));
     //		if ($r['duration']!=-1) {
     //			$r['date'] = Base_RegionalSettingsCommon::time2reg($r['date'].' '.date('H:i:s', strtotime($r['time'])),false,true,true,false);
     //			$r['recurrence_end'] = Base_RegionalSettingsCommon::time2reg($r['recurrence_end'].' '.date('H:i:s', strtotime($r['time'])),false,true,true,false);
     //		}
     if ($day === null) {
         $day = $r['date'];
         $iday = strtotime($day);
         $next['id'] = $r['id'];
     } else {
         $iday = strtotime($day);
         if ($day < $r['date']) {
             return null;
         }
         if ($r['recurrence_end'] && $day > $r['recurrence_end']) {
             return null;
         }
         if ($r['recurrence_type'] <= 7 && $r['recurrence_type'] > 0) {
             $diff = round(($iday - strtotime($r['date'])) / (3600 * 24));
             if ($diff < 0 || $diff % $r['recurrence_type'] != 0) {
                 return null;
             }
         }
         if ($r['recurrence_type'] == 8) {
             if (isset($r['recurrence_hash'][date('N', $iday) - 1]) && !$r['recurrence_hash'][date('N', $iday) - 1]) {
                 return null;
             }
         }
         if ($r['recurrence_type'] == 9) {
             $diff = round(($iday - strtotime($r['date'])) / (3600 * 24));
             if ($diff < 0 || $diff % 14 != 0) {
                 return null;
             }
         }
         if ($r['recurrence_type'] == 10) {
             $numdays = date('t', $iday);
             $cday = date('d', $iday);
             $tday = date('d', strtotime($r['date']));
             if ($cday != $tday && ($tday <= $numdays || $numdays != $cday)) {
                 return null;
             }
         }
         if ($r['recurrence_type'] == 11) {
             $cmonth = date('m', $iday);
             $tmonth = date('m', strtotime($r['date']));
             if ($cmonth != $tmonth) {
                 return null;
             }
             $numdays = date('t', $iday);
             $cday = date('d', $iday);
             $tday = date('d', strtotime($r['date']));
             if ($cday != $tday && ($tday <= $numdays || $numdays != $cday)) {
                 return null;
             }
         }
         $next['id'] = $r['id'];
     }
     if ($r['recurrence_type'] > 0) {
         $next['id'] = $r['id'] . '_' . $day;
     }
     $base_unix_time = strtotime(date('1970-01-01 00:00:00'));
     //		$next['start'] = Base_RegionalSettingsCommon::reg2time(Base_RegionalSettingsCommon::time2reg(date('Y-m-d',$iday).' '.date('H:i:s',strtotime($r['time'])), true, false, true, false));
     //		$next['end'] = Base_RegionalSettingsCommon::reg2time(date('Y-m-d',$iday).' '.Base_RegionalSettingsCommon::time2reg(date('Y-m-d',$iday).' '.date('H:i:s',strtotime($r['time'])+$r['duration']), true, false, true, false));
     $next['start'] = date('Y-m-d', $iday) . ' ' . date('H:i:s', strtotime($r['time']));
     $next['end'] = date('Y-m-d', $iday) . ' ' . date('H:i:s', strtotime($r['time']) + $r['duration']);
     $next['start'] = strtotime($next['start']);
     $next['end'] = strtotime($next['end']);
     if ($r['duration'] == -1) {
         $next['timeless'] = $day;
     }
     $next['duration'] = intval($r['duration']);
     $next['title'] = (string) $r['title'];
     $next['description'] = (string) $r['description'];
     $next['color'] = 'gray';
     if ($r['status'] == 0 || $r['status'] == 1) {
         switch ($r['priority']) {
             case 0:
                 $next['color'] = 'green';
                 break;
             case 1:
                 $next['color'] = 'yellow';
                 break;
             case 2:
                 $next['color'] = 'red';
                 break;
         }
     }
     if ($r['status'] == 2) {
         $next['color'] = 'blue';
     }
     if ($r['status'] == 3) {
         $next['color'] = 'gray';
     }
     if ($r['recurrence_type']) {
         $next['title'] = '<img src="' . Base_ThemeCommon::get_template_file('CRM_Calendar_Event', 'recurrence.png') . '" border=0 hspace=0 vspace=0 align=left>' . $next['title'];
     }
     $next['view_action'] = Utils_RecordBrowserCommon::create_record_href('crm_meeting', $r['id'], 'view', array('day' => $day));
     if (Utils_RecordBrowserCommon::get_access('crm_meeting', 'edit', $r) !== false) {
         $next['edit_action'] = Utils_RecordBrowserCommon::create_record_href('crm_meeting', $r['id'], 'edit');
         if ($r['status'] <= 1) {
             $r_new = $r;
             if ($r['status'] == 0) {
                 $r_new['status'] = 1;
             }
             $next['actions'] = array(array('icon' => Base_ThemeCommon::get_template_file('CRM/Meeting', 'close_event.png'), 'href' => self::get_status_change_leightbox_href($r_new, false, array('id' => 'status'))));
         }
     } else {
         $next['edit_action'] = false;
         $next['move_action'] = false;
     }
     if (Utils_RecordBrowserCommon::get_access('crm_meeting', 'delete', $r) == false) {
         $next['delete_action'] = false;
     }
     $start_time = Base_RegionalSettingsCommon::time2reg($next['start'], 2, false, $r['duration'] != -1);
     $event_date = Base_RegionalSettingsCommon::time2reg($next['start'], false, 3, $r['duration'] != -1);
     $end_time = Base_RegionalSettingsCommon::time2reg($next['end'], 2, false, $r['duration'] != -1);
     $inf2 = array(__('Date') => '<b>' . $event_date . '</b>');
     if ($r['duration'] == -1) {
         $inf2 += array(__('Time') => __('Timeless event'));
     } else {
         $inf2 += array(__('Time') => $start_time . ' - ' . $end_time, __('Duration') => Base_RegionalSettingsCommon::seconds_to_words($r['duration']));
     }
     $emps = array();
     foreach ($r['employees'] as $e) {
         $e = CRM_ContactsCommon::contact_format_no_company($e, true);
         $e = str_replace('&nbsp;', ' ', $e);
         if (mb_strlen($e, 'UTF-8') > 33) {
             $e = mb_substr($e, 0, 30, 'UTF-8') . '...';
         }
         $emps[] = $e;
     }
     $next['busy_label'] = $r['employees'];
     $cuss = array();
     foreach ($r['customers'] as $c) {
         $c = CRM_ContactsCommon::display_company_contact(array('customers' => $c), true, array('id' => 'customers'));
         $cuss[] = str_replace('&nbsp;', ' ', $c);
     }
     $inf2 += array(__('Event') => '<b>' . $next['title'] . '</b>', __('Description') => $next['description'], __('Assigned to') => implode('<br>', $emps), __('Contacts') => implode('<br>', $cuss), __('Status') => Utils_CommonDataCommon::get_value('CRM/Status/' . $r['status'], true), __('Access') => Utils_CommonDataCommon::get_value('CRM/Access/' . $r['permission'], true), __('Priority') => Utils_CommonDataCommon::get_value('CRM/Priority/' . $r['priority'], true), __('Notes') => Utils_AttachmentCommon::count('crm_meeting/' . $r['id']));
     //		$next['employees'] = implode('<br>',$emps);
     //		$next['customers'] = implode('<br>',$cuss);
     $next['employees'] = $r['employees'];
     $next['customers'] = $r['customers'];
     $next['status'] = $r['status'] <= 2 ? 'active' : 'closed';
     $next['custom_tooltip'] = '<center><b>' . __('Meeting') . '</b></center><br>' . Utils_TooltipCommon::format_info_tooltip($inf2) . '<hr>' . CRM_ContactsCommon::get_html_record_info($r['created_by'], $r['created_on'], null, null);
     return $next;
 }
Ejemplo n.º 2
0
 public static function process_event(&$row)
 {
     if (!isset($row['start']) && !(isset($row['timeless']) && $row['timeless'])) {
         trigger_error('Invalid return of event method: get(_all) (missing field \'start\' or \'timeless\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['duration']) || !is_numeric($row['duration'])) {
         trigger_error('Invalid return of event method: get(_all) (missing or not numeric field \'duration\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['title'])) {
         trigger_error('Invalid return of event method: get(_all) (missing field \'title\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['description'])) {
         trigger_error('Invalid return of event method: get(_all) (missing field \'description\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['id'])) {
         trigger_error('Invalid return of event method: get(_all) (missing field \'id\' in ' . print_r($row, true) . ')', E_USER_ERROR);
     }
     if (!isset($row['additional_info'])) {
         $row['additional_info'] = '';
     }
     if (!isset($row['additional_info2'])) {
         $row['additional_info2'] = '';
     }
     if (!isset($row['actions'])) {
         $row['actions'] = array();
     }
     if (isset($row['timeless']) && $row['timeless']) {
         if (!isset($row['timeless_caption'])) {
             $row['timeless_caption'] = str_replace(' ', '&nbsp;', __('Timeless'));
         }
         $start_time = $row['timeless_caption'];
         $end_time = $start_time;
         $ev_start = strtotime($row['timeless']);
         if (!isset($row['start'])) {
             $start_day = _V(date('D', $ev_start));
         } else {
             $start_day = _V(date('D', $row['start']));
         }
         $start_date = Base_RegionalSettingsCommon::time2reg($ev_start, false, true, false);
         if ($start_date == Base_RegionalSettingsCommon::time2reg(time(), false)) {
             $start_t = __('Today');
         } elseif ($start_date == Base_RegionalSettingsCommon::time2reg(time() + 3600 * 24, false)) {
             $start_t = __('Tomorrow');
         } elseif ($start_date == Base_RegionalSettingsCommon::time2reg(time() - 3600 * 24, false)) {
             $start_t = __('Yesterday');
         } else {
             $start_t = $start_day . ', ' . $start_date;
         }
         $end_date = $start_date;
         $end_day = $start_day;
         $end_t = $start_t;
     } else {
         if (!is_numeric($row['start']) && is_string($row['start'])) {
             $row['start'] = strtotime($row['start']);
         }
         if ($row['start'] === false) {
             trigger_error('Invalid return of event method: get (start equal to null)', E_USER_ERROR);
         }
         $row['end'] = $row['start'] + $row['duration'];
         $ev_start = $row['start'];
         $ev_end = $row['end'];
         Base_RegionalSettingsCommon::set();
         $start_day = __date('D', $ev_start);
         $end_day = __date('D', $ev_end);
         Base_RegionalSettingsCommon::restore();
         $start_date = Base_RegionalSettingsCommon::time2reg($ev_start, false);
         $end_date = Base_RegionalSettingsCommon::time2reg($ev_end, false);
         $oneday = $start_date == $end_date;
         if ($oneday) {
             $end_t = Base_RegionalSettingsCommon::time2reg($ev_end, 2, false);
         }
         $start_time = Base_RegionalSettingsCommon::time2reg($ev_start, 2, false);
         $end_time = Base_RegionalSettingsCommon::time2reg($ev_end, 2, false);
         if ($start_date == Base_RegionalSettingsCommon::time2reg(time(), false)) {
             $start_t = __('Today') . ', ' . $start_time;
         } elseif ($start_date == Base_RegionalSettingsCommon::time2reg(time() + 3600 * 24, false)) {
             $start_t = __('Tomorrow') . ', ' . $start_time;
         } elseif ($start_date == Base_RegionalSettingsCommon::time2reg(time() - 3600 * 24, false)) {
             $start_t = __('Yesterday') . ', ' . $start_time;
         } else {
             $start_t = $start_day . ', ' . $start_date . ' ' . $start_time;
         }
         if (!$oneday) {
             $end_t = $end_day . ', ' . $end_date . ' ' . $end_time;
         }
     }
     if (isset($row['fake_duration'])) {
         $duration_str = Base_RegionalSettingsCommon::seconds_to_words($row['fake_duration']);
     } elseif ($row['duration'] > 0) {
         $duration_str = Base_RegionalSettingsCommon::seconds_to_words($row['duration']);
     } else {
         $duration_str = '---';
     }
     return array('duration' => $duration_str, 'start' => $start_t, 'end' => $end_t, 'start_time' => $start_time, 'end_time' => $end_time, 'start_date' => $start_date, 'end_date' => $end_date, 'start_day' => $start_day, 'end_day' => $end_day);
 }