Exemplo n.º 1
0
 public static function get_all($start, $end, $filter = null)
 {
     if ($filter === null) {
         $filter = self::$filter;
     }
     $custom_handlers = DB::GetAssoc('SELECT id, handler_callback FROM crm_calendar_custom_events_handlers');
     $result = array();
     if (self::$events_handlers === null) {
         self::$events_handlers = array_keys($custom_handlers);
     }
     $count = 0;
     foreach (self::$events_handlers as $handler) {
         $callback = explode('::', $custom_handlers[$handler]);
         $result_ext = call_user_func($callback, 'get_all', $start, $end, $filter);
         foreach ($result_ext as $v) {
             if ($v !== null) {
                 $v['id'] = $handler . '#' . $v['id'];
                 $v['custom_agenda_col_0'] = isset($v['type']) ? $v['type'] : '---';
                 if (isset($v['description'])) {
                     $v['custom_agenda_col_1'] = $v['description'];
                 }
                 if (isset($v['employees'])) {
                     $emps = array();
                     if (is_array($v['employees'])) {
                         foreach ($v['employees'] as $e) {
                             $emps[] = CRM_ContactsCommon::contact_format_no_company($e);
                         }
                     }
                     $v['custom_agenda_col_2'] = implode('<br>', $emps);
                 }
                 if (isset($v['customers'])) {
                     $cuss = array();
                     if (is_array($v['customers'])) {
                         foreach ($v['customers'] as $c) {
                             $cuss[] = CRM_ContactsCommon::display_company_contact(array('customers' => $c), true, array('id' => 'customers'));
                         }
                     }
                     $v['custom_agenda_col_3'] = implode('<br>', $cuss);
                 }
                 $result[] = $v;
                 $count++;
                 if ($count == CRM_CalendarCommon::$events_limit) {
                     break;
                 }
             }
         }
         if ($count == CRM_CalendarCommon::$events_limit) {
             break;
         }
     }
     if ($count == CRM_CalendarCommon::$events_limit) {
         print '<b>There were too many events to display on the Calendar, please change CRM Filter</b>';
     }
     return $result;
 }
Exemplo n.º 2
0
 public static function crm_event_get($id)
 {
     if (!is_array($id)) {
         $r = Utils_RecordBrowserCommon::get_record('task', $id);
     } else {
         $r = $id;
         $id = $r['id'];
     }
     $r = Utils_RecordBrowserCommon::filter_record_by_access('task', $r);
     if (!$r) {
         return null;
     }
     $next = array('type' => __('Task'));
     $day = $r['deadline'];
     $iday = strtotime($day);
     $next['id'] = $r['id'];
     $base_unix_time = strtotime(date('1970-01-01 00:00:00'));
     $next['start'] = $iday;
     $next['timeless'] = $day;
     $next['duration'] = -1;
     $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';
     }
     $next['view_action'] = Utils_RecordBrowserCommon::create_record_href('task', $r['id'], 'view');
     if (Utils_RecordBrowserCommon::get_access('task', 'edit', $r) !== false) {
         $next['edit_action'] = Utils_RecordBrowserCommon::create_record_href('task', $r['id'], 'edit');
     } else {
         $next['edit_action'] = false;
         $next['move_action'] = false;
     }
     if (Utils_RecordBrowserCommon::get_access('task', 'delete', $r) == false) {
         $next['delete_action'] = false;
     }
     /*		$r_new = $r;
     		if ($r['status']==0) $r_new['status'] = 1;
     		if ($r['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')))
     		);*/
     $start_time = Base_RegionalSettingsCommon::time2reg($next['start'], 2, false, false);
     $event_date = Base_RegionalSettingsCommon::time2reg($next['start'], false, 3, false);
     $inf2 = array(__('Date') => '<b>' . $event_date . '</b>');
     $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(__('Task') => '<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('task/' . $r['id']));
     $next['employees'] = $r['employees'];
     $next['customers'] = $r['customers'];
     $next['status'] = $r['status'] <= 2 ? 'active' : 'closed';
     $next['custom_tooltip'] = '<center><b>' . __('Task') . '</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;
 }
Exemplo n.º 3
0
 public function display_activities($events, $tasks, $phonecalls)
 {
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), 'activities', 'activities');
     $gb->set_table_columns(array(array('name' => __('Type'), 'wrapmode' => 'nowrap', 'width' => 8), array('name' => __('Subject'), 'width' => 20), array('name' => __('Date/Deadline'), 'wrapmode' => 'nowrap', 'width' => 8), array('name' => __('Employees'), 'width' => 11), array('name' => __('Customers'), 'width' => 11), array('name' => __('Attachments'), 'width' => 4)));
     $amount = 0;
     if ($this->display['events']) {
         $amount += count($events);
     }
     if ($this->display['tasks']) {
         $amount += count($tasks);
     }
     if ($this->display['phonecalls']) {
         $amount += count($phonecalls);
     }
     $limit = $gb->get_limit($amount);
     for ($i = 0; $i < $limit['offset'] + $limit['numrows'] && $i < $amount; $i++) {
         if ($this->display['events'] && count($events)) {
             $ev = current($events);
         } else {
             $ev = array('start' => -1);
         }
         if ($this->display['tasks'] && count($tasks)) {
             $t = current($tasks);
             if (!$t['deadline']) {
                 $t['deadline'] = 0;
             } else {
                 $t['deadline'] = strtotime($t['deadline']);
             }
         } else {
             $t = array('deadline' => -1);
         }
         if ($this->display['phonecalls'] && count($phonecalls)) {
             $ph = current($phonecalls);
             $ph['date_and_time'] = strtotime($ph['date_and_time']);
         } else {
             $ph = array('date_and_time' => -1);
         }
         $maxt = max($ev['start'], $t['deadline'], $ph['date_and_time']);
         $gb_row = $gb->get_new_row();
         if ($ev['start'] == $maxt) {
             $v = array_shift($events);
             if ($i >= $limit['offset'] && $v) {
                 if (isset($v['view_action'])) {
                     $view_href = $v['view_action'];
                 } else {
                     $view_href = $this->create_callback_href(array($this, 'view_event'), array($v['id']));
                 }
                 $title = '<a ' . $view_href . '>' . $v['title'] . '</a>';
                 if (isset($v['description']) && $v['description'] != '') {
                     $title = '<span ' . Utils_TooltipCommon::open_tag_attrs($v['description'], false) . '>' . $title . '</span>';
                 }
                 $gb_row->add_info(Utils_RecordBrowserCommon::get_html_record_info('crm_meeting', $v['id']));
                 $gb_row->add_data(__('Meeting'), $title, Base_RegionalSettingsCommon::time2reg($v['start'], $v['duration'] == -1 ? false : 2), CRM_ContactsCommon::display_contact(array('employees' => $v['employees']), false, array('id' => 'employees', 'param' => ';CRM_ContactsCommon::contact_format_no_company')), CRM_ContactsCommon::display_company_contact(array('customers' => $v['customers']), false, array('id' => 'customers', 'param' => ';::')), Utils_AttachmentCommon::count('crm_meeting/' . $v['id']));
             }
         } elseif ($t['deadline'] == $maxt) {
             $v = array_shift($tasks);
             $v = Utils_RecordBrowserCommon::filter_record_by_access('task', $v);
             if ($i >= $limit['offset'] && $v) {
                 $gb_row->add_info(Utils_RecordBrowserCommon::get_html_record_info('task', $v['id']));
                 $gb_row->add_data(__('Task'), CRM_TasksCommon::display_title($v, false), !isset($v['deadline']) || !$v['deadline'] ? __('No deadline') : Base_RegionalSettingsCommon::time2reg($v['deadline'], false, true, false), CRM_ContactsCommon::display_contact($v, false, array('id' => 'employees', 'param' => ';CRM_ContactsCommon::contact_format_no_company')), CRM_ContactsCommon::display_company_contact($v, false, array('id' => 'customers')), Utils_AttachmentCommon::count('task/' . $v['id']));
             }
         } else {
             $v = array_shift($phonecalls);
             $v = Utils_RecordBrowserCommon::filter_record_by_access('phonecall', $v);
             if ($i >= $limit['offset'] && $v) {
                 $gb_row->add_info(Utils_RecordBrowserCommon::get_html_record_info('phonecall', $v['id']));
                 $gb_row->add_data(__('Phonecall'), CRM_PhoneCallCommon::display_subject($v), Base_RegionalSettingsCommon::time2reg($v['date_and_time'], 2), CRM_ContactsCommon::display_contact($v, false, array('id' => 'employees', 'param' => ';CRM_ContactsCommon::contact_format_no_company')), CRM_PhoneCallCommon::display_contact_name($v, false), Utils_AttachmentCommon::count('phonecall/' . $v['id']));
             }
         }
     }
     $this->display_module($gb);
 }
Exemplo n.º 4
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;
 }