Ejemplo n.º 1
0
 function toHtml()
 {
     $str = "";
     if ($this->_flagFrozen) {
         $str .= $this->getFrozenHtml();
     } else {
         $value = $this->getAttribute('value');
         if (is_numeric($value)) {
             $value = date('Y-m-d', $value);
         }
         $id = $this->getAttribute('id');
         $name = $this->getAttribute('name');
         if ($value) {
             $this->setAttribute('value', Base_RegionalSettingsCommon::time2reg($value, false, true, false));
         }
         if (!isset($id)) {
             $id = 'datepicker_field_' . $name;
             $this->updateAttributes(array('id' => $id));
         }
         $ex_date = Base_RegionalSettingsCommon::time2reg(null, false, true, false);
         $date_format = Base_RegionalSettingsCommon::date_format();
         $this->setType('text');
         if (!$this->getAttribute('placeholder')) {
             $this->setAttribute('placeholder', __('Click to select date'));
         }
         $js = Utils_PopupCalendarCommon::create_href(md5($id), 'new Ajax.Request(\'modules/Utils/PopupCalendar/up.php\',' . '{method:\'post\', parameters:{date: __YEAR__+\'-\'+__MONTH__+\'-\'+__DAY__},' . 'onSuccess:function(t){e=$(\'' . Epesi::escapeJS($id, false) . '\');if(e) {e.value=t.responseText;jq(e).change();}}})', null, null, 'popup.clonePosition(\'' . $id . '\',{setWidth:false,setHeight:false,offsetTop:$(\'' . $id . '\').getHeight()})', $value, $id);
         $str .= $this->_getTabs() . '<input ' . $js . ' ' . $this->_getAttrString($this->_attributes) . ' ' . Utils_TooltipCommon::open_tag_attrs(__('Example date: %s', array($ex_date)), false) . ' />';
         eval_js('Event.observe(\'' . $id . '\',\'keypress\',Utils_PopupCalendarDatePicker.validate.bindAsEventListener(Utils_PopupCalendarDatePicker,\'' . Epesi::escapeJS($date_format, false) . '\'))');
         eval_js('Event.observe(\'' . $id . '\',\'blur\',Utils_PopupCalendarDatePicker.validate_blur.bindAsEventListener(Utils_PopupCalendarDatePicker,\'' . Epesi::escapeJS($date_format, false) . '\'))');
     }
     return $str;
 }
Ejemplo n.º 2
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');
 }
Ejemplo n.º 3
0
 public static function print_event($ev, $mode = '', $with_div = true)
 {
     $th = Base_ThemeCommon::init_smarty();
     $ex = self::process_event($ev);
     $th->assign('event_id', $ev['id']);
     $th->assign('draggable', !isset($ev['draggable']) || $ev['draggable'] === true);
     $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_Calendar', '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_Calendar', 'event' . ($mode ? '_' . $mode : ''));
 }
Ejemplo n.º 4
0
 public function display_date_picker($datepicker_defaults = array(), $form = null, $show_dates = true)
 {
     if ($form === null) {
         $form = $this->init_module(Libs_QuickForm::module_name());
     }
     $theme = $this->init_module(Base_Theme::module_name());
     $minyear = date('Y', strtotime('-5 years'));
     $maxyear = date('Y', strtotime('+5 years'));
     if ($show_dates) {
         $display_stuff_js = 'document.getElementById(\'day_elements\').style.display=\'none\';document.getElementById(\'month_elements\').style.display=\'none\';document.getElementById(\'week_elements\').style.display=\'none\';document.getElementById(\'year_elements\').style.display=\'none\';document.getElementById(this.value+\'_elements\').style.display=\'block\';';
         $form->addElement('select', 'date_range_type', __('Display report'), array('day' => __('Days'), 'week' => __('Weeks'), 'month' => __('Months'), 'year' => __('Years')), array('onChange' => $display_stuff_js, 'onKeyUp' => $display_stuff_js));
         $form->addElement('datepicker', 'from_day', __('From Date'));
         $form->addElement('datepicker', 'to_day', __('To Date'));
         $form->addElement('date', 'from_week', __('From week'), array('format' => 'Y W', 'language' => Base_LangCommon::get_lang_code(), 'minYear' => $minyear, 'maxYear' => $maxyear));
         $form->addElement('date', 'to_week', __('To week'), array('format' => 'Y W', 'language' => Base_LangCommon::get_lang_code(), 'minYear' => $minyear, 'maxYear' => $maxyear));
         $form->addElement('date', 'from_month', __('From month'), array('format' => 'Y m', 'language' => Base_LangCommon::get_lang_code(), 'minYear' => $minyear, 'maxYear' => $maxyear));
         $form->addElement('date', 'to_month', __('To month'), array('format' => 'Y m', 'language' => Base_LangCommon::get_lang_code(), 'minYear' => $minyear, 'maxYear' => $maxyear));
         $form->addElement('date', 'from_year', __('From year'), array('format' => 'Y', 'language' => Base_LangCommon::get_lang_code(), 'minYear' => $minyear, 'maxYear' => $maxyear));
         $form->addElement('date', 'to_year', __('To year'), array('format' => 'Y', 'language' => Base_LangCommon::get_lang_code(), 'minYear' => $minyear, 'maxYear' => $maxyear));
         $form->registerRule('check_dates', 'callback', 'check_dates', $this);
         $form->addRule(array('date_range_type', 'from_day', 'to_day', 'from_week', 'to_week', 'from_month', 'to_month', 'from_year', 'to_year'), __('\'From\' date must be earlier than \'To\' date'), 'check_dates');
     }
     if ($this->isset_module_variable('vals')) {
         $vals = $this->get_module_variable('vals');
         unset($vals['submited']);
         $form->setDefaults($vals);
     } else {
         foreach (array('week' => 3, 'day' => 13, 'month' => 5, 'year' => 5) as $v => $k) {
             $form->setDefaults(array('from_' . $v => date('Y-m-d H:i:s', strtotime('-' . $k . ' ' . $v))));
             $form->setDefaults(array('to_' . $v => date('Y-m-d H:i:s')));
         }
         $form->setDefaults(array('date_range_type' => 'month'));
         $form->setDefaults($datepicker_defaults);
     }
     $form->addElement('submit', 'submit', __('Show'));
     //		$failed = false;
     $other = $vals = $form->exportValues();
     $this->set_module_variable('vals', $vals);
     //		if ($vals['submited'] && !$form->validate()) {
     //			$this->date_range = 'error';
     //			$failed = true;
     //		}
     $theme->assign('show_dates', $show_dates);
     $form->assign_theme('form', $theme);
     $theme->display('date_picker');
     if ($show_dates) {
         $type = $vals['date_range_type'];
         foreach (array('week', 'day', 'year', 'month') as $v) {
             if ($v != $type) {
                 eval_js('document.getElementById(\'' . $v . '_elements\').style.display=\'none\';');
             }
         }
         //		if ($failed) {
         //			return array('type'=>'day', 'dates'=>array());
         //		}
         $this->date_range = array();
         foreach (array('date_range_type', 'from_' . $type, 'to_' . $type) as $v) {
             $this->date_range[$v] = $vals[$v];
         }
         $header = array();
         $start_p = $start = $this->get_date($type, $this->date_range['from_' . $type]);
         $end_p = $end = $this->get_date($type, $this->date_range['to_' . $type]);
         $header[] = $start;
         while (true) {
             switch ($type) {
                 case 'day':
                     $start = strtotime(date('Y-m-d 12:00:00', $start + 86400));
                     $start_format = 'Y-m-d';
                     $end_format = 'Y-m-d';
                     break;
                 case 'week':
                     $start = strtotime(date('Y-m-d 12:00:00', $start + 604800));
                     $start_format = 'Y-m-d';
                     $end_format = 'Y-m-d';
                     $fdow = Utils_PopupCalendarCommon::get_first_day_of_week();
                     $start_p -= (4 - $fdow) * 24 * 60 * 60;
                     $end_p += (2 + $fdow) * 24 * 60 * 60;
                     break;
                 case 'month':
                     $start = strtotime(date('Y-m-15 12:00:00', $start + 2592000));
                     $start_format = 'Y-m-01';
                     $end_format = 'Y-m-t';
                     break;
                 case 'year':
                     $start = strtotime(date('Y-06-15 12:00:00', $start + 2592000 * 12));
                     $start_format = 'Y-01-01';
                     $end_format = 'Y-12-31';
                     break;
             }
             if ($start > $end) {
                 break;
             }
             $header[] = $start;
         }
         return array('type' => $type, 'dates' => $header, 'start' => date($start_format, $start_p), 'end' => date($end_format, $end), 'other' => $other);
     } else {
         return array('other' => $other);
     }
 }
Ejemplo n.º 5
0
 public function body($args = array())
 {
     $ev_mod = $this->init_module(CRM_Calendar_Event::module_name());
     $ev_mod->help('Calendar Help', 'main');
     if (isset($_REQUEST['search_date']) && is_numeric($_REQUEST['search_date']) && isset($_REQUEST['ev_id']) && is_numeric($_REQUEST['ev_id'])) {
         $default_date = intval($_REQUEST['search_date']);
         $this->view_event(intval($_REQUEST['ev_id']));
     } else {
         $default_date = null;
     }
     $handlers = DB::GetAll('SELECT id, group_name, handler_callback FROM crm_calendar_custom_events_handlers');
     $this->lp = $this->init_module('Utils_LeightboxPrompt');
     $count = 0;
     foreach ($handlers as $v) {
         $callback = explode('::', $v['handler_callback']);
         if (!is_callable($callback)) {
             continue;
         }
         $new_events = call_user_func($callback, 'new_event_types');
         if ($new_events !== null) {
             foreach ($new_events as $k => $w) {
                 if (!is_array($w)) {
                     $w = array('label' => $w, 'icon' => null);
                 }
                 $this->lp->add_option('new_event__' . $v['id'] . '__' . $k, $w['label'], $w['icon'], null);
                 $count++;
             }
         }
     }
     if ($count < 2) {
         $this->lp = null;
     } else {
         $this->display_module($this->lp, array(__('New Event'), array('timestamp', 'timeless'), '', false));
         $vals = $this->lp->export_values();
         if ($vals) {
             $this->jump_to_new_event($vals['option'], $vals['params']['timestamp'], $vals['params']['timeless']);
             return;
         }
     }
     CRM_Calendar_EventCommon::$filter = CRM_FiltersCommon::get();
     $args_defaults = array('default_view' => Base_User_SettingsCommon::get('CRM_Calendar', 'default_view'), 'first_day_of_week' => Utils_PopupCalendarCommon::get_first_day_of_week(), 'start_day' => Base_User_SettingsCommon::get('CRM_Calendar', 'start_day'), 'end_day' => Base_User_SettingsCommon::get('CRM_Calendar', 'end_day'), 'interval' => Base_User_SettingsCommon::get('CRM_Calendar', 'interval'), 'default_date' => $default_date, 'custom_agenda_cols' => array(array('name' => __('Type'), 'order' => 'cus_col_0', 'width' => 6, 'wrapmode' => 'nowrap'), __('Description'), __('Assigned to'), __('Related with')));
     foreach ($args_defaults as $k => $v) {
         if (!isset($args[$k])) {
             $args[$k] = $args_defaults[$k];
         }
     }
     if (isset($_REQUEST['jump_to_date']) && is_numeric($_REQUEST['jump_to_date']) && isset($_REQUEST['switch_to_tab']) && is_string($_REQUEST['switch_to_tab'])) {
         $args['default_date'] = $_REQUEST['jump_to_date'];
         $args['default_view'] = $_REQUEST['switch_to_tab'];
     }
     $theme = $this->init_module(Base_Theme::module_name());
     $c = $this->init_module(Utils_Calendar::module_name(), array(CRM_Calendar_Event::module_name(), $args, array($this, 'get_new_event_href_js')));
     $view_type = $c->get_current_view();
     CRM_CalendarCommon::$mode = $view_type;
     $theme->assign('calendar', $this->get_html_of_module($c));
     $theme->display();
     $events = $c->get_displayed_events();
     if (!empty($events['events'])) {
         switch ($view_type) {
             case 'Day':
                 $view = __('Daily agenda');
                 break;
             case 'Month':
                 $view = __('Monthly agenda');
                 break;
             case 'Week':
                 $view = __('Weekly agenda');
                 break;
             case 'Agenda':
                 $view = __('Agenda');
                 break;
         }
         if (isset($view)) {
             $pdf = $this->pack_module(Libs_TCPDF::module_name(), null, null, 'L');
             if ($pdf->prepare()) {
                 set_time_limit(0);
                 $start = date('d F Y', Base_RegionalSettingsCommon::reg2time($events['start']));
                 $end = date('d F Y', Base_RegionalSettingsCommon::reg2time($events['end']));
                 $pdf->set_title($view . ', ' . $start . ($view_type != 'Day' ? ' - ' . $end : ''));
                 $filter = CRM_FiltersCommon::get();
                 $me = CRM_ContactsCommon::get_my_record();
                 if (trim($filter, '()') == $me['id']) {
                     $desc = $me['last_name'] . ' ' . $me['first_name'];
                 } else {
                     $desc = CRM_FiltersCommon::get_profile_desc();
                 }
                 $pdf->set_subject(__('CRM Filters: %s', array($desc)));
                 $pdf->prepare_header();
                 $pdf->AddPage();
                 foreach ($events['events'] as $v) {
                     $ev_mod->make_event_PDF($pdf, $v, true, $view_type);
                 }
             }
             $pdf->add_actionbar_icon($view);
         }
     }
 }
Ejemplo n.º 6
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));
		}
	}
Ejemplo n.º 7
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) . '\')');
 }
Ejemplo n.º 8
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');
	}
Ejemplo n.º 9
0
            if ($min || !$duration) {
                $duration .= $min . __('min');
            }
            $next = '<tr>' . '<td style="width:90px">' . $headers[$day] . '</td>' . '<td>' . Utils_PlannerCommon::format_time($start * 60) . '</td>' . '<td>' . Utils_PlannerCommon::format_time($t * 60) . '</td>' . '<td>' . $duration . '</td>' . '</tr>';
            $selected_frames[] = $day . '::' . $start . '::' . $t;
            $timeframe[$day][] = $next;
            $start = null;
        }
    }
}
$js .= '$("grid_selected_frames").value="' . implode(';', $selected_frames) . '";';
$timeframe_string = '<table class="time_frames">';
if (isset($_SESSION['client']['utils_planner']['date'])) {
    $day = $_SESSION['client']['utils_planner']['date'];
} else {
    $day = Utils_PopupCalendarCommon::get_first_day_of_week();
}
$count = 0;
do {
    if (isset($timeframe[$day])) {
        foreach ($timeframe[$day] as $v) {
            $timeframe_string .= $v;
        }
    }
    if (isset($_SESSION['client']['utils_planner']['date'])) {
        $day = strtotime('+1 day', $day);
    } else {
        $day++;
        if ($day == 7) {
            $day = 0;
        }