public static function print_event($ev, $mode = '', $with_div = true)
 {
     $th = Base_ThemeCommon::init_smarty();
     $ex = Utils_CalendarCommon::process_event($ev);
     $th->assign('event_id', $ev['id']);
     $th->assign('draggable', false);
     $title = $ev['title'];
     $title_st = strip_tags($ev['title']);
     $title_s = $title;
     $th->assign('with_div', $with_div);
     $th->assign('title', $title);
     $th->assign('title_s', $title_s);
     $th->assign('description', $ev['description']);
     $th->assign('color', $ev['color']);
     $th->assign('start', $ex['start']);
     $th->assign('start_time', $ex['start_time']);
     $th->assign('end_time', $ex['end_time']);
     $th->assign('start_date', $ex['start_date']);
     $th->assign('end_date', $ex['end_date']);
     $th->assign('start_day', $ex['start_day']);
     $th->assign('end_day', $ex['end_day']);
     $th->assign('end', $ex['end']);
     $th->assign('duration', $ex['duration']);
     $th->assign('show_hide_info', __('Click to show / hide menu'));
     $th->assign('additional_info', $ev['additional_info']);
     $th->assign('additional_info2', $ev['additional_info2']);
     if (isset($ev['custom_tooltip'])) {
         $th->assign('custom_tooltip', $ev['custom_tooltip']);
     }
     ob_start();
     Base_ThemeCommon::display_smarty($th, 'Utils_CalendarBusyReport', 'event_tip');
     $tip = ob_get_clean();
     $th->assign('tip_tag_attrs', Utils_TooltipCommon::open_tag_attrs($tip, false));
     if (!isset($ev['view_action']) || $ev['view_action'] === true) {
         $th->assign('view_href', Module::create_href(array('UCev_id' => $ev['id'], 'UCaction' => 'view')));
     } elseif ($ev['view_action'] !== false) {
         $th->assign('view_href', $ev['view_action']);
     }
     if (!isset($ev['edit_action']) || $ev['edit_action'] === true) {
         $th->assign('edit_href', Module::create_href(array('UCev_id' => $ev['id'], 'UCaction' => 'edit')));
     } elseif ($ev['edit_action'] !== false) {
         $th->assign('edit_href', $ev['edit_action']);
     }
     $link_text = Module::create_href_js(array('UCev_id' => $ev['id'], 'UCaction' => 'move', 'UCdate' => '__YEAR__-__MONTH__-__DAY__'));
     if (!isset($ev['move_action']) || $ev['move_action'] === true) {
         $th->assign('move_href', Utils_PopupCalendarCommon::create_href('move_event' . str_replace(array('#', '-'), '_', $ev['id']), $link_text, null, null, 'popup.clonePosition(\'utils_calendar_event:' . $ev['id'] . '\',{setWidth:false,setHeight:false,offsetTop:$(\'utils_calendar_event:' . $ev['id'] . '\').getHeight()})'));
     }
     if (!isset($ev['delete_action']) || $ev['delete_action'] === true) {
         $th->assign('delete_href', Module::create_confirm_href(__('Delete this event?'), array('UCev_id' => $ev['id'], 'UCaction' => 'delete')));
     } elseif ($ev['delete_action'] !== false) {
         $th->assign('delete_href', $ev['delete_action']);
     }
     $th->assign('handle_class', 'handle');
     $th->assign('custom_actions', $ev['actions']);
     Base_ThemeCommon::display_smarty($th, 'Utils_CalendarBusyReport', 'event' . ($mode ? '_' . $mode : ''));
 }
Example #2
0
 public function applet($conf, &$opts)
 {
     $opts['go'] = true;
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'agendaX');
     $columns = array(array('name' => __('Start'), 'order' => 'e.starts', 'width' => 25, 'wrapmode' => 'nowrap'), array('name' => __('Title'), 'order' => 'e.title', 'width' => 50));
     $gb->set_table_columns($columns);
     $start = date('Y-m-d', time());
     $end = date('Y-m-d', time() + $conf['days'] * 24 * 60 * 60);
     $gb->set_default_order(array(__('Start') => 'ASC'));
     CRM_Calendar_EventCommon::$filter = '(' . CRM_FiltersCommon::get_my_profile() . ')';
     $data = array();
     Base_ThemeCommon::load_css('CRM_Calendar', 'agenda');
     $custom_events = DB::GetAssoc('SELECT id, handler_callback FROM crm_calendar_custom_events_handlers ORDER BY group_name');
     $ret = array();
     if (!empty($custom_events)) {
         $c = 0;
         foreach ($custom_events as $id => $cb) {
             if ($conf['events_handlers__' . $id]) {
                 $cb = explode('::', $cb);
                 if (!is_callable($cb)) {
                     continue;
                 }
                 $add = call_user_func($cb, 'get_all', $start, $end, CRM_Calendar_EventCommon::$filter);
                 foreach ($add as $v) {
                     $ret[str_pad($v['start'], 16, '0', STR_PAD_LEFT) . '__' . $c] = $v;
                     $c++;
                 }
             }
         }
     }
     ksort($ret);
     foreach ($ret as $row) {
         if (isset($row['status']) && $row['status'] == 'closed') {
             continue;
         }
         if (!isset($row['view_action'])) {
             $ex = Utils_CalendarCommon::process_event($row);
             $view_action = '<a ' . $this->create_callback_href(array($this, 'view_event'), $row['id']) . '>';
             $ev_id = explode('_', $row['id'], 2);
             $ev_id = $ev_id[0];
         } else {
             $tmp = Utils_CalendarCommon::process_event($row);
             $ex = $row;
             $ex['start'] = $tmp['start'];
             $view_action = '<a ' . $row['view_action'] . '>';
         }
         //////////////////////////
         // left column
         $date = $ex['start'];
         ///////////////////
         // right column
         $title = Utils_TooltipCommon::create($row['title'], $row['custom_tooltip']);
         $day = isset($row['timeless']) && $row['timeless'] ? $row['timeless'] : Base_RegionalSettingsCommon::time2reg($row['start'], false, true, true, false);
         if ($day < date('Y-m-d')) {
             $class = 'past';
         } elseif ($day == date('Y-m-d')) {
             $class = 'today';
         } elseif ($day == date('Y-m-d', strtotime('+1 day'))) {
             $class = 'tomorrow';
         } else {
             $class = 'other';
         }
         $gb_row = $gb->get_new_row();
         $gb_row->set_attrs('class="CRM_Calendar_applet__' . $class . '"');
         $gb_row->add_data(array('value' => $date, 'order_value' => isset($row['timeless']) && $row['timeless'] ? strtotime($row['timeless']) : $row['start']), array('value' => $view_action . $title . '</a>'));
     }
     $this->display_module($gb, array(false), 'automatic_display');
 }
Example #3
0
	public function agenda() {
		$theme = $this->pack_module('Base/Theme');
		Base_ThemeCommon::load_css('Utils_Calendar', 'common');

		/////////////// controls ////////////////////////
		$start = & $this->get_module_variable('agenda_start',date('Y-m-d',$this->date));
		$end = & $this->get_module_variable('agenda_end',date('Y-m-d',$this->date + (7 * 24 * 60 * 60)));

		$form = $this->init_module('Libs/QuickForm',null,'agenda_frm');

		$form->addElement('datepicker', 'start', __('From'));
		$form->addElement('datepicker', 'end', __('To'));
		$form->addElement('submit', 'submit_button', __('Show'));
		$form->addRule('start', 'Field required', 'required');
		$form->addRule('end', 'Field required', 'required');
		$form->setDefaults(array('start'=>$start,'end'=>$end));

		if($form->validate()) {
			$data = $form->exportValues();
			$start = $data['start'];
			$end = $data['end'];
			$end = date('Y-m-d',strtotime($end)+86400);
		}
		$form->assign_theme('form', $theme, new HTML_QuickForm_Renderer_TCMSArraySmarty());

		if (is_callable(array($this->event_module, 'get_navigation_bar_additions'))) {
			$event_module_instance = $this->init_module($this->event_module);
			$navigation_bar_additions = call_user_func(array($event_module_instance,'get_navigation_bar_additions'), '', '');
		}
		$theme->assign('navigation_bar_additions', $navigation_bar_additions);

		//////////////// data ////////////////////////
		$gb = $this->init_module('Utils/GenericBrowser', null, 'agenda');
		$columns = array(
			array('name'=>__('Start'), 'order'=>'start', 'width'=>10),
			array('name'=>__('Duration'), 'order'=>'end', 'width'=>5),
			array('name'=>__('Title'), 'order'=>'title','width'=>10));
		$add_cols = array();
		if(is_array($this->settings['custom_agenda_cols'])) {
			$w = 50/count($this->settings['custom_agenda_cols']);
			foreach($this->settings['custom_agenda_cols'] as $k=>$col) {
				if (!is_array($col)) $col = array('name'=>$col, 'order'=>'cus_col_'.$k,'width'=>$w);
				$columns[] = $col;
				$add_cols[] = $k;
			}
		}
		$gb->set_table_columns( $columns );
		$gb->set_default_order(array(__('Start')=>'ASC'));

		//add data
		$ret = $this->get_events($start,$end);
		$this->displayed_events = array('start'=>$start, 'end'=>$end,'events'=>$ret);
		foreach($ret as $row) {
			$r = $gb->get_new_row();
			if (isset($row['status']) && $row['status']=='closed') continue;
			$view_h = $this->create_callback_href(array($this,'push_event_action'),array('view',$row['id']));
			$edit_h = $this->create_callback_href(array($this,'push_event_action'),array('edit',$row['id']));
			$del_h = $this->create_confirm_callback_href(__('Delete this event?'),array($this,'delete_event'),$row['id']);
			if (isset($row['view_action'])) $view_h = $row['view_action'];
			if (isset($row['edit_action'])) $edit_h = $row['edit_action'];
			if (isset($row['delete_action'])) $del_h = $row['delete_action'];

			$ex = Utils_CalendarCommon::process_event($row);

			$rrr = array(array('value'=>$ex['start'],'order_value'=>$row['start']),Utils_TooltipCommon::create($ex['duration'],$ex['end'],false),'<a '.$view_h.'>'.$row['title'].'</a>');
			foreach($add_cols as $a)
				if (isset($row['custom_agenda_col_'.$a]))
					$rrr[] = $row['custom_agenda_col_'.$a];
				else
					$rrr[] = '';

			$r->add_data_array($rrr);

			if($row['additional_info']!=='' || $row['additional_info2'])
				$r->add_info($row['additional_info'].(($row['additional_info']!=='' && $row['additional_info2']!=='')?'<hr>':'').$row['additional_info2']);

			$r->add_action($del_h,'Delete');
			$r->add_action($edit_h,'Edit');
			$r->add_action($view_h,'View');
		}

		$theme->assign('agenda',$this->get_html_of_module($gb,array(false),'automatic_display'));

		//////////////// display ///////////////
		$theme->display('agenda');
	}
Example #4
0
        if (isset($ev['timeless'])) {
            $cc[1] = isset($ev['custom_row_key']) ? $ev['custom_row_key'] : 'timeless';
        } else {
            $cc[0] = strtotime(Base_RegionalSettingsCommon::time2reg($cc[0], true, true, true, false)) + $ev['start'] - strtotime(Base_RegionalSettingsCommon::time2reg($ev['start'], false, true, true, false));
        }
        //	} else { //this code breaks calendar with interval less than 1 hour so commented this out
        //		$cc[0] += $ev['start']-strtotime(date('Y-m-d H:00:00',$ev['start']));
    }
    $ret = call_user_func_array(array($mod . 'Common', 'update'), array(&$ev_id, $cc[0], $ev['duration'], isset($cc[1]) ? $cc[1] : null));
    if (!$ret) {
        print 'reject=true;';
        exit;
    }
    //update content of event on page in client browser
    ob_start();
    $ev = call_user_func(array($mod . 'Common', 'get'), $ev_id);
    $ret_ev = ob_get_clean();
    if (!$ev) {
        exit;
    }
    if (isset($ev['title'])) {
        $ev = array($ev);
    }
    foreach ($ev as $e) {
        ob_start();
        Utils_CalendarCommon::print_event($e, $_POST['page_type'] == 'day' ? 'day' : null, false);
        $ret = ob_get_clean();
        print 'document.getElementById(\'utils_calendar_event:' . $ev_id . '\').innerHTML=\'' . Epesi::escapeJS($ret_ev . $ret, false) . '\';';
    }
    exit;
}
Example #5
0
 public static function mobile_view_event($id)
 {
     $row = CRM_Calendar_EventCommon::get($id);
     $ex = Utils_CalendarCommon::process_event($row);
     print '<ul class="field">';
     print '<li>' . __('Title') . ': ' . $row['title'] . '</li>';
     print '<li>' . __('Starts') . ': ' . $ex['start'] . '</li>';
     print '<li>' . __('Duration') . ': ' . $ex['duration'] . '</li>';
     print '<li>' . __('Ends') . ': ' . $ex['end'] . '</li>';
     print '<li>' . __('Description') . ': ' . $row['description'] . '</li>';
     print '</ul>';
 }
Example #6
0
 public static function mobile_agenda($evmod, $extra_settings = array(), $time_shift = 0, $view_func = null)
 {
     $settings = array('custom_agenda_cols' => null);
     $settings = array_merge($settings, $extra_settings);
     $start = time() + $time_shift;
     $end = $start + 7 * 24 * 60 * 60 + $time_shift;
     if (!IPHONE) {
         $columns = array(array('name' => __('Start'), 'order' => 'start', 'width' => 10), array('name' => __('Duration'), 'order' => 'end', 'width' => 5), array('name' => __('Title'), 'order' => 'title', 'width' => 10));
     }
     //add data
     ob_start();
     $ret_raw = call_user_func(array(str_replace('/', '_', $evmod) . 'Common', 'get_all'), date('Y-m-d', $start), date('Y-m-d', $end));
     ob_get_clean();
     if (!is_array($ret_raw)) {
         trigger_error('Invalid return of event method: get_all (not an array)', E_USER_ERROR);
     }
     if (IPHONE) {
         print '<ul>';
         $date = null;
     } else {
         $data = array();
     }
     $ret = array();
     $i = 0;
     foreach ($ret_raw as $row) {
         $ret[$row['start'] . '_' . $i] = $row;
         $i++;
     }
     ksort($ret);
     foreach ($ret as $row) {
         $ex = Utils_CalendarCommon::process_event($row);
         if ($view_func) {
             $h = mobile_stack_href($view_func, array($row['id']), __('View event'));
         } else {
             $h = '';
         }
         if (IPHONE) {
             if ($date !== $ex['start_date']) {
                 $date = $ex['start_date'];
                 print '</ul><h4>' . $date . '</h4><ul>';
             }
             $start = '<a ' . $h . '>' . $ex['start'] . '</a>';
             $duration = '<a ' . $h . '>' . $ex['duration'] . '</a>';
             $title = '<a ' . $h . '>' . $row['title'] . '</a>';
             print '<li class="arrow">' . $start . $duration . $title . '</li>';
         } else {
             $rrr = array(array('label' => '<a ' . $h . '>' . $ex['start'] . '</a>', 'order_value' => isset($row['timeless']) ? strtotime($row['timeless']) : $row['start']), '<a ' . $h . '>' . $ex['duration'] . '</a>', '<a ' . $h . '>' . $row['title'] . '</a>');
             //				foreach($add_cols as $a)
             //					$rrr[] = $row['custom_agenda_col_'.$a];
             $data[] = $rrr;
         }
     }
     if (IPHONE) {
         print '</ul>';
     } else {
         Utils_GenericBrowserCommon::mobile_table($columns, $data, 'start');
     }
 }