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 function get_navigation_bar_additions()
 {
     $custom_handlers = CRM_CalendarCommon::get_event_handlers();
     if (empty($custom_handlers)) {
         return '';
     }
     $form = $this->init_module('Libs/QuickForm');
     $elements_name = array();
     $default = array();
     foreach ($custom_handlers as $k => $v) {
         $form->addElement('checkbox', 'events_handlers__' . $k, $v, null, array('onclick' => 'calendar_event_handlers_changed=1;'));
         $elements_name[$k] = 'events_handlers__' . $k;
         $default[] = $k;
     }
     $form->addElement('hidden', 'event_handlers_changed', '', array('id' => 'event_handlers_changed'));
     eval_js('calendar_event_handlers_changed=0;');
     eval_js('hide_calendar_event_handlers_popup = function() {' . 'if(var_hide_calendar_event_handlers_popup==1){' . '$("calendar_event_handlers_popup").style.display="none";' . '$("calendar_event_handlers_trigger").innerHTML=calendar_event_handlers_message_default;' . 'if(calendar_event_handlers_changed==1){' . $form->get_submit_form_js() . '$("calendar_event_handlers_trigger").innerHTML=calendar_event_handlers_message_processing;' . '}' . '}' . '}');
     eval_js('show_calendar_event_handlers_popup = function() {' . '$("calendar_event_handlers_popup").style.display="";' . '$("calendar_event_handlers_trigger").innerHTML=calendar_event_handlers_message_confirm;' . '}');
     $selected = $this->get_module_variable('events_handlers', $default);
     if ($form->validate()) {
         $vals = $form->exportValues();
         $selected = array();
         foreach ($elements_name as $k => $e) {
             if (isset($vals[$e]) && $vals[$e]) {
                 $selected[] = $k;
             }
         }
         $this->set_module_variable('events_handlers', $selected);
     }
     CRM_Calendar_EventCommon::$events_handlers = $selected;
     foreach ($selected as $k => $e) {
         if (isset($elements_name[$e])) {
             $form->setDefaults(array($elements_name[$e] => true));
         }
     }
     $label = 'Filter: Error';
     $select_count = count($selected);
     if ($select_count == count($custom_handlers)) {
         $label = __('All');
     } else {
         $label = __('Selection (%d)', array($select_count));
     }
     if ($select_count == 1) {
         $label = $custom_handlers[reset($selected)];
     }
     if ($select_count == 0) {
         $label = __('None');
     }
     $theme = $this->init_module('Base/Theme');
     $theme->assign('elements_name', $elements_name);
     $theme->assign('label', $label);
     eval_js('calendar_event_handlers_message_default="' . $label . '";');
     eval_js('calendar_event_handlers_message_processing="' . __('Processing...') . '";');
     eval_js('calendar_event_handlers_message_confirm="' . __('Save selection') . '";');
     $form->assign_theme('form', $theme);
     ob_start();
     $theme->display('custom_event_handlers_form');
     $handlers_form = ob_get_clean();
     return $handlers_form;
 }