示例#1
0
 public function applet($conf, &$opts)
 {
     $opts['go'] = false;
     $this->date = $this->get_module_variable_or_unique_href_variable('date');
     if ($this->date == null) {
         $this->date = date('Y-m-15');
     }
     $this->set_module_variable('date', $this->date);
     $this->date = strtotime($this->date);
     $theme = $this->pack_module('Base/Theme');
     $theme->assign('nextyear_href', $this->create_unique_href(array('date' => date('Y-m-15', $this->date + 30 * 24 * 60 * 60))));
     $theme->assign('today_href', $this->create_unique_href(array('date' => date('Y-m-d'))));
     $theme->assign('prevyear_href', $this->create_unique_href(array('date' => date('Y-m-15', $this->date - 30 * 24 * 60 * 60))));
     $link_text = $this->create_unique_href_js(array('date' => '__YEAR__-__MONTH__-__DAY__'));
     $theme->assign('popup_calendar', Utils_PopupCalendarCommon::show('week_selector', $link_text, 'month', null, null, ''));
     $day_headers = array();
     $day = strtotime('Sun');
     $day = strtotime('+' . Utils_PopupCalendarCommon::get_first_day_of_week() . ' days', $day);
     for ($i = 0; $i < 7; $i++) {
         $day_headers[] = __date('D', $day);
         $day = strtotime('+1 day', $day);
     }
     $year = array();
     $me = CRM_ContactsCommon::get_my_record();
     CRM_Calendar_EventCommon::$filter = '(' . $me['id'] . ')';
     $ret = call_user_func(array('CRM_Calendar_EventCommon', 'get_event_days'), date('Y-m-01', $this->date), date('Y-m-d', strtotime(date('Y-m-t', $this->date)) + 86400));
     $month = $this->month_array($this->date, $ret);
     $year[] = array('month' => $month, 'month_link' => Base_BoxCommon::create_href($this, 'CRM_Calendar', null, null, null, array('jump_to_date' => $this->date, 'switch_to_tab' => 'Month')), 'month_label' => __date('F', $this->date), 'year_label' => date('Y', $this->date));
     $theme->assign('year', $year);
     $theme->assign('day_headers', $day_headers);
     $theme->display('year');
 }
示例#2
0
 public function week()
 {
     $theme = $this->pack_module(Base_Theme::module_name());
     Base_ThemeCommon::load_css('Utils_CalendarBusyReport', 'common');
     $theme->assign('next7_href', $this->create_unique_href(array('date' => date('Y-m-d', $this->date + 604800))));
     $theme->assign('next7_label', __('Next week'));
     $theme->assign('next_href', $this->create_unique_href(array('shift_week_day' => 1)));
     $theme->assign('next_label', __('Next day'));
     $theme->assign('today_href', $this->create_unique_href(array('date' => date('Y-m-d'))));
     $theme->assign('today_label', __('Today'));
     $theme->assign('prev_href', $this->create_unique_href(array('shift_week_day' => 0)));
     $theme->assign('prev_label', __('Previous day'));
     $theme->assign('prev7_href', $this->create_unique_href(array('date' => date('Y-m-d', $this->date - 604800))));
     $theme->assign('prev7_label', __('Previous week'));
     $link_text = $this->create_unique_href_js(array('week_date' => '__YEAR__-__MONTH__-__DAY__'));
     $theme->assign('popup_calendar', Utils_PopupCalendarCommon::show('week_selector', $link_text, 'day', $this->settings['first_day_of_week']));
     $week_shift = $this->get_module_variable('week_shift', 0);
     $first_day_of_displayed_week = date('w', $this->date) - $this->settings['first_day_of_week'];
     if ($first_day_of_displayed_week < 0) {
         $first_day_of_displayed_week += 7;
     }
     $diff = $week_shift - $first_day_of_displayed_week;
     $dis_week_from = strtotime(($diff < 0 ? $diff : '+' . $diff) . ' days', $this->date);
     //headers
     $day_headers = array();
     $today = Base_RegionalSettingsCommon::time2reg(null, false, true, true, false);
     if (date('m', $dis_week_from) != date('m', $dis_week_from + 518400)) {
         $second_span_width = date('d', $dis_week_from + 518400);
         $header_month = array('first_span' => array('colspan' => 7 - $second_span_width, 'month' => __date('M', $dis_week_from), 'month_link' => $this->create_unique_href(array('action' => 'switch', 'time' => $dis_week_from, 'tab' => 'Month')), 'year' => date('Y', $dis_week_from), 'year_link' => $this->create_unique_href(array('action' => 'switch', 'time' => $dis_week_from, 'tab' => 'Year'))), 'second_span' => array('colspan' => $second_span_width, 'month' => __date('M', $dis_week_from + 518400), 'month_link' => $this->create_unique_href(array('action' => 'switch', 'time' => $dis_week_from + 518400, 'tab' => 'Month')), 'year' => date('Y', $dis_week_from + 518400), 'year_link' => $this->create_unique_href(array('action' => 'switch', 'time' => $dis_week_from + 518400, 'tab' => 'Year'))));
     } else {
         $header_month = array('first_span' => array('colspan' => 7, 'month' => __date('M', $dis_week_from), 'month_link' => $this->create_unique_href(array('action' => 'switch', 'time' => $dis_week_from, 'tab' => 'Month')), 'year' => date('Y', $dis_week_from), 'year_link' => $this->create_unique_href(array('action' => 'switch', 'time' => $dis_week_from, 'tab' => 'Year'))));
     }
     for ($i = 0; $i < 7; $i++) {
         $that_day = strtotime(date('Y-m-d', strtotime(date('Y-m-d 12:00:00', $dis_week_from)) + 3600 * 24 * $i) . ' ' . date('H:i:s', $dis_week_from));
         $day_headers[] = array('date' => date('d', $that_day) . ' ' . __date('D', $that_day), 'style' => (date('Y-m-d', $that_day) == $today ? 'today' : 'other') . (date('N', $that_day) >= 6 ? '_weekend' : ''), 'link' => $this->create_unique_href(array('action' => 'switch', 'time' => $that_day, 'tab' => 'Day')));
     }
     $theme->assign('header_month', $header_month);
     $theme->assign('day_headers', $day_headers);
     $theme->assign('head_col_width', $this->settings['head_col_width']);
     $report = array();
     //timeline and ids
     $time_ids = array();
     $timeline = array();
     for ($i = 0; $i < 7; $i++) {
         $time_ids[$i] = array();
         $today_t_timeless = strtotime(date('Y-m-d', strtotime(date('Y-m-d 12:00:00', $dis_week_from)) + 3600 * 24 * $i) . ' ' . date('H:i:s', $dis_week_from));
         $today_t = Base_RegionalSettingsCommon::reg2time(date('Y-m-d', $today_t_timeless));
         $today_date = date('Y-m-d', $today_t_timeless);
         $timeline[$today_date] = $this->get_timeline($today_date);
         $prev = null;
         foreach ($timeline[$today_date] as &$v) {
             if ($v['time'] === false) {
                 $time_ids[$i][] = false;
             } elseif (is_string($v['time'])) {
                 $ii = $today_t_timeless . '_' . $v['time'];
                 $time_ids[$i][] = $ii;
                 $report[$ii] = array();
                 //					eval_js('$("UCcell_'.$ii.'").innerHTML="'.$ii.'";'); // *DEBUG*
             } else {
                 $ii = $today_t + $v['time'];
                 $time_ids[$i][] = $ii;
                 $report[$ii] = array();
                 //					eval_js('$("UCcell_'.$ii.'").innerHTML="'.Base_RegionalSettingsCommon::time2reg($ii).'";'); // *DEBUG*
             }
             $prev = $v;
         }
     }
     $navigation_bar_additions = '';
     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);
     $theme->assign('time_ids', $time_ids);
     $theme->assign('timeline', reset($timeline));
     $theme->assign('week_view_label', __('Week calendar'));
     //data
     //$dis_week_from = Base_RegionalSettingsCommon::reg2time($dis_week_from);
     //$dis_week_to = $dis_week_from+7*86400-1;
     $dis_week_to = date('Y-m-d', $dis_week_from + 7.5 * 86400);
     $dis_week_from = date('Y-m-d', $dis_week_from);
     $ret = $this->get_events($dis_week_from, $dis_week_to);
     $this->displayed_events = array('start' => $dis_week_from, 'end' => $dis_week_to, 'events' => $ret);
     $custom_keys = $this->settings['custom_rows'];
     $busy_labels = $this->settings['busy_labels'];
     foreach ($ret as $k => $ev) {
         if (!isset($ev['busy_label'])) {
             continue;
         }
         if (!is_array($ev['busy_label'])) {
             $ev['busy_label'] = array($ev['busy_label']);
         }
         ob_start();
         Utils_CalendarBusyReportCommon::print_event($ev);
         $ev_print = ob_get_clean();
         $day_start = explode(':', $this->settings['start_day']);
         $day_start = ($day_start[0] * 60 + $day_start[1]) * 60;
         if (!isset($ev['start'])) {
             $diff = 1;
         } else {
             $diff = ($day_start - ($ev['start'] - $today_t)) / 3600;
         }
         $dur = ceil($ev['duration'] / (strtotime($this->settings['interval']) - strtotime('0:00')));
         if (isset($ev['timeless']) && $ev['timeless']) {
             if (!isset($ev['custom_row_key'])) {
                 $ev['custom_row_key'] = 'timeless';
             }
             $today_t_timeless = strtotime($ev['timeless']);
             if (isset($custom_keys[$ev['custom_row_key']])) {
                 $dest_id = $today_t_timeless . '_' . $ev['custom_row_key'];
                 if (isset($report[$dest_id])) {
                     foreach ($ev['busy_label'] as $busy_label) {
                         if (!isset($busy_labels[$busy_label])) {
                             $busy_labels[$busy_label] = $busy_label;
                         }
                         if (!isset($report[$dest_id][$busy_label])) {
                             $report[$dest_id][$busy_label] = '';
                         }
                         $report[$dest_id][$busy_label] .= $ev_print;
                     }
                 }
             } else {
                 //					trigger_error('Invalid custom_row_key:'.$ev['custom_row_key'],E_USER_ERROR);
                 continue;
             }
         } else {
             $today_t = Base_RegionalSettingsCommon::time2reg($ev['start'], true, true, true, false);
             $today_date = date('Y-m-d', strtotime($today_t));
             $today_t = strtotime(date('Y-m-d H:i:s', Base_RegionalSettingsCommon::reg2time($today_date)));
             $ev_start = $ev['start'] - $today_t;
             if (!isset($timeline[$today_date])) {
                 continue;
             }
             $ct = count($timeline[$today_date]);
             for ($i = 1, $j = 2; $j < $ct; $i++, $j++) {
                 while ($timeline[$today_date][$i]['time'] === false) {
                     $i++;
                 }
                 while (($timeline[$today_date][$j]['time'] === false || $i >= $j) && $j < $ct) {
                     $j++;
                 }
                 if ($j == $ct) {
                     break;
                 }
                 if ($timeline[$today_date][$i]['time'] <= $ev_start && $ev_start < $timeline[$today_date][$j]['time']) {
                     break;
                 }
             }
             for ($k = $i; $k < $i + $dur; $k++) {
                 $dest_id = $today_t + $timeline[$today_date][$k]['time'];
                 if (isset($report[$dest_id])) {
                     foreach ($ev['busy_label'] as $busy_label) {
                         if (!isset($busy_labels[$busy_label])) {
                             $busy_labels[$busy_label] = $busy_label;
                         }
                         if (!isset($report[$dest_id][$busy_label])) {
                             $report[$dest_id][$busy_label] = '';
                         }
                         $report[$dest_id][$busy_label] .= $ev_print;
                     }
                 }
             }
         }
     }
     $theme->assign('report', $report);
     $theme->assign('busy_labels', $busy_labels);
     //ok, display
     $theme->display('week');
     if ($this->custom_new_event_href_js !== null) {
         $jshref = call_user_func($this->custom_new_event_href_js, '__TIME__', '__TIMELESS__', '__OBJECT__');
     } else {
         $jshref = $this->create_unique_href_js(array('action' => 'add', 'time' => '__TIME__', 'timeless' => '__TIMELESS__', 'object' => '__OBJECT__'));
     }
     eval_js('Utils_CalendarBusyReport.activate_dclick(\'' . Epesi::escapeJS($jshref, false) . '\')');
 }
示例#3
0
	public function body(){
		if (empty($this->grid)) {
			print('Time grid not defined, aborting');
			return;
		}
		load_js('modules/Utils/Planner/planner.js');
		eval_js('disableSelection($("Utils_Planner__grid"))');
		eval_js('Event.observe(window,"mouseup",time_grid_mouse_up)');
		$theme = $this->init_module('Base/Theme');

		/* HEADERS */
		$fdow = Utils_PopupCalendarCommon::get_first_day_of_week();
		$headers = array();
		$select_all = array();
		if ($this->date===null) {
			$days_of_week = array(0=>__('Sunday'), 1=>__('Monday'), 2=>__('Tuesday'), 3=>__('Wednesday'), 4=>__('Thursday'), 5=>__('Friday'), 6=>__('Saturday'));
			while (count($headers)<7) {
				$headers[$fdow] = $days_of_week[$fdow];
				$fdow++;
				if ($fdow>6) $fdow -= 7;
			}
		} else {
//			while (date('w',$this->date)!=$fdow) $this->date = strtotime('-1 day', $this->date);
			$_SESSION['client']['utils_planner']['date'] = $this->date;
			$days_of_week = array(0=>__('Sun'), 1=>__('Mon'), 2=>__('Tue'), 3=>__('Wed'), 4=>__('Thu'), 5=>__('Fri'), 6=>__('Sat'));
			$curr = $this->date;
			while (count($headers)<7) {
				$headers[$curr] = Base_RegionalSettingsCommon::time2reg($curr, false, true, false).' '.$days_of_week[date('w',$curr)];
				$curr = strtotime('+1 day', $curr);
			}
		}
		$theme->assign('headers',$headers);

		foreach ($headers as $k1=>$v1)
			$select_all[$k1] = '';
		/* GRID LEGEND */
		$grid_legend = array();
		$grid_attrs = array();
		foreach ($this->grid as $k=>$v) {
			if (!isset($this->grid[$k+1])) break;
			foreach ($headers as $k1=>$v1)
				$select_all[$k1] .= ($select_all[$k1]?'time_grid_mouse_move':'time_grid_mouse_down').'('.$v.','.$k1.');';
			$grid_legend[$v] = Utils_PlannerCommon::format_time($v*60);
			$grid_legend[$v] .= ' - '.Utils_PlannerCommon::format_time($this->grid[$k+1]*60);
			$grid_attrs[$v] = array(); 
			foreach ($headers as $k2=>$v2) $grid_attrs[$v][$k2] = 'class="noconflict unused" id="'.$k2.'__'.$v.'" onmousedown="time_grid_mouse_down('.$v.','.$k2.')" onmousemove="if(typeof(time_grid_mouse_move)!=\'undefined\')time_grid_mouse_move('.$v.','.$k2.')"';
		}
		foreach ($headers as $k1=>$v1)
			$select_all[$k1] .= 'time_grid_mouse_up();';
		/* GRID LEGEND END */
		
		$theme->assign('select_all',$select_all);
		$theme->assign('select_all_label',__('Select all'));

		$theme->assign('grid_legend',$grid_legend);
		$theme->assign('grid_attrs',$grid_attrs);
		$theme->assign('time_frames',array('label'=>__('Time frames'), 'html'=>'<div id="Utils_Planner__time_frames" />'));
		$_SESSION['client']['utils_planner']['grid']=array(
			'timetable'=>$this->grid,
			'days'=>$headers,
			);
		if ($this->date!==null) {
			$this->form->addElement('submit', 'next_day', __('Next day'), array('onclick'=>'$("planner_navigation").value="next_day";'));
			$this->form->addElement('submit', 'prev_day', __('Previous day'), array('onclick'=>'$("planner_navigation").value="prev_day";'));
			$this->form->addElement('submit', 'next_week', __('Next week'), array('onclick'=>'$("planner_navigation").value="next_week";'));
			$this->form->addElement('submit', 'prev_week', __('Previous week'), array('onclick'=>'$("planner_navigation").value="prev_week";'));
			$this->form->addElement('submit', 'today', __('Today'), array('onclick'=>'$("planner_navigation").value="today";'));
			$this->form->addElement('hidden', 'navigation', '', array('id'=>'planner_navigation'));
			$link_text = '$(\'planner_navigation\').value=\'__YEAR__-__MONTH__-__DAY__\';'.$this->form->get_submit_form_js().';';
			$theme->assign('popup_calendar', Utils_PopupCalendarCommon::show('week_selector', $link_text,'day',$fdow,null,null,$this->date));
			eval_js('$("planner_navigation").value="";');
		}

		$values = $this->get_module_variable('preserve_values', null);
		if ($values===null)
			$values = $this->form->exportValues();
		else
			$this->unset_module_variable('preserve_values');
		$this->form->setDefaults($values);

		$validate = false;
		if ($this->form->validate()) {
			$validate = true;
			foreach ($values as $k=>$v)
				$this->values[$k] = $v;
		}
			
		$this->form->assign_theme('form', $theme);
		$theme->display();
		Base_ActionBarCommon::add('save',__('Save'),$this->form->get_submit_form_href());
		Base_ActionBarCommon::add('back',__('Back'),$this->create_back_href());
		
		$time_frames = explode(';',$values['grid_selected_frames']);
		if (!empty($time_frames) && $time_frames[0]) {
			foreach ($time_frames as $k=>$v) {
				$x = explode('::',$v);
				if (!isset($x[2])) trigger_error(print_r($time_frames, true));
				list($day, $s, $e) = explode('::',$v);
				foreach ($this->grid as $v) {
					if ($v>=$s && $v<$e) {
						eval_js('time_grid_mouse_down('.$v.','.$day.',"used");');
					}
				}
			}
			eval_js('time_grid_mouse_up();');
		}
		if (isset($values['navigation']) && $values['navigation']) {
			switch ($values['navigation']) {
				case 'next_day': $ch = strtotime('+1 day', $this->date); break;
				case 'prev_day': $ch = strtotime('-1 day', $this->date); break;
				case 'next_week': $ch = strtotime('+7 days', $this->date); break;
				case 'prev_week': $ch = strtotime('-7 days', $this->date); break;
				case 'today': $ch = strtotime(date('Y-m-d')); break;
				default: $ch = strtotime($values['navigation']);
			}
			if ($ch) {
				$values['navigation'] = '';
				$this->set_module_variable('fixed_date', $ch);
				$this->set_module_variable('preserve_values', $values);
				location(array());
				return;
			}
		}
		if ($validate) {
			unset($values['grid_selected_frames']);
			foreach ($time_frames as $k=>$v) {
				if (!$v) {
					unset($time_frames[$k]);
					break;
				}
				list($day, $s, $e) = explode('::',$v);
				$time_frames[$k] = array('day'=>$day, 'start'=>$s, 'end'=>$e);
			}
			call_user_func($_SESSION['client']['utils_planner']['processing_callback'], $values, $time_frames);
			$this->set_back_location();
			location(array());
		}
		foreach ($this->values as $k=>$v) {
			$_SESSION['client']['utils_planner']['resources'][$k]['value'] = $v;
			$_SESSION['client']['utils_planner']['resources'][$k]['in_use'] = array();
		}
		foreach ($this->values as $k=>$v) {
			eval_js(Utils_PlannerCommon::resource_changed($k, $v));
		}
	}
示例#4
0
	public function year() {
		$theme = $this->pack_module('Base/Theme');
		Base_ThemeCommon::load_css('Utils_Calendar', 'common');

		$theme->assign('nextyear_href', $this->create_unique_href(array('date'=>(date('Y',$this->date)+1).date('-m-d',$this->date))));
		$theme->assign('nextyear_label',__('Next year'));
		$theme->assign('today_href', $this->create_unique_href(array('date'=>date('Y-m-d'))));
		$theme->assign('today_label', __('Today'));
		$theme->assign('prevyear_href', $this->create_unique_href(array('date'=>(date('Y',$this->date)-1).date('-m-d',$this->date))));
		$theme->assign('prevyear_label', __('Previous year'));
		$theme->assign('info', __('Double&nbsp;click&nbsp;on&nbsp;cell&nbsp;to&nbsp;add&nbsp;event'));

		$link_text = $this->create_unique_href_js(array('date'=>'__YEAR__-__MONTH__-__DAY__'));
		$theme->assign('popup_calendar', Utils_PopupCalendarCommon::show('week_selector', $link_text,'year'));


		$day_headers = array();
		$day = strtotime('Sun');
		$day = strtotime('+'.Utils_PopupCalendarCommon::get_first_day_of_week().' days', $day);
		for ($i=0; $i<7; $i++) {
			$day_headers[] = __date('D', $day);
			$day = strtotime('+1 day', $day);
		}

		$theme->assign('month_view_label', __('Year calendar'));

		$year = array();

		$ret = call_user_func(array($this->event_module.'Common','get_event_days'),date('Y-01-01',$this->date),(date('Y',$this->date)+1).'-01-01');

		for ($i=1; $i<=12; $i++) {
			$date = strtotime(date('Y',$this->date).'-'.str_pad($i, 2, '0', STR_PAD_LEFT).'-15');
			$month = $this->month_array($date, $ret);
			$year[] = array('month' => $month,
							'month_link' => $this->create_unique_href(array('action'=>'switch','time'=>$date, 'tab'=>'Month')),
							'month_label' => __date('F', $date),
							'year_label' => date('Y', $date)
							);
		}
		$theme->assign('year', $year);
		$theme->assign('day_headers', $day_headers);

		$navigation_bar_additions = '';
		$theme->assign('navigation_bar_additions', $navigation_bar_additions);

		$theme->display('year');
	}