示例#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 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);
     }
 }
示例#3
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);
         }
     }
 }
示例#4
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));
		}
	}
示例#5
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');
	}
示例#6
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;
        }