Ejemplo n.º 1
0
	public function edit($row) {
		if($this->is_back())
			$this->pop_box0();

		$f = $this->init_module('Libs/QuickForm');
		
		if($row) {
			$a = Base_RegionalSettingsCommon::time2reg($row['alert_on'],true,true,true,false);
			$f->setDefaults(array_merge($row,array('alert_date'=>$a,'alert_time'=>$a)));
		} else {
			$tt = $this->def_date;
			$tt = $tt-$tt%300;
			$f->setDefaults(array('alert_date'=>$tt,'alert_time'=>$tt));
		}

		$f->addElement('textarea', 'message', __('Message'));
		$f->addElement('datepicker', 'alert_date', __('Alert date'));
		$lang_code = Base_LangCommon::get_lang_code();
		$time_format = Base_RegionalSettingsCommon::time_12h()?'h:i a':'H:i';
		$f->addElement('date', 'alert_time', __('Alert time'), array('format'=>$time_format, 'optionIncrement'  => array('i' => 5), 'language'=>$lang_code));
		
		if(is_array($this->users)) {
			foreach($this->users as $k=>$r) {
				if(!Base_User_SettingsCommon::get($this->get_type(),'allow_other',$k) && Acl::get_user()!=$k)
					unset($this->users[$k]);
			}
			$f->addElement('multiselect', 'users', __('Assigned users'), $this->users);
			$f->addRule('users', __('At least one user must be assigned to an alarm.'), 'required');
			$f->setDefaults(array('users'=>array_keys($this->users)));
		}

		if($f->validate()) {
			$ret = $f->exportValues();
			if($row)
				$ret = array_merge($row,$ret);
			if(Base_RegionalSettingsCommon::time_12h())
				$ret['alert_on'] = strtotime($ret['alert_date'])+($ret['alert_time']['h']%12)*3600+(($ret['alert_time']['a']=='pm')?(3600*12):0)+$ret['alert_time']['i']*60;
			else
				$ret['alert_on'] = strtotime($ret['alert_date'])+$ret['alert_time']['H']*3600+$ret['alert_time']['i']*60;
			$ret['alert_on'] = Base_RegionalSettingsCommon::reg2time(date('Y-m-d H:i:s',$ret['alert_on']));
			if($row) {
				DB::Execute('UPDATE utils_messenger_message SET message=%s,alert_on=%T WHERE page_id=\''.$this->mid.'\' AND id=%d',array($ret['message'],$ret['alert_on'],$row['id']));
				$id = $row['id'];
				DB::Execute('DELETE FROM utils_messenger_users WHERE message_id=%d',array($id));
			} else {
				DB::Execute('INSERT INTO utils_messenger_message(page_id,parent_module,message,callback_method,callback_args,created_on,created_by,alert_on) VALUES(%s,%s,%s,%s,%s,%T,%d,%T)',array($this->mid,$this->parent_type,$ret['message'],serialize($this->callback_method),serialize($this->callback_args),time(),Acl::get_user(),$ret['alert_on']));
				$id = DB::Insert_ID('utils_messenger_message','id');
			}
			if(is_array($this->users)) {
				foreach($ret['users'] as $r)
					DB::Execute('INSERT INTO utils_messenger_users(message_id,user_login_id) VALUES (%d,%d)',array($id,$r));
			} else
				DB::Execute('INSERT INTO utils_messenger_users(message_id,user_login_id) VALUES (%d,%d)',array($id,$this->users));
			$this->pop_box0();
		}
		
		Base_ActionBarCommon::add('save',__('Save'),$f->get_submit_form_href());
		Base_ActionBarCommon::add('back',__('Back'),$this->create_back_href());
		$f->display_as_column();
	}
Ejemplo n.º 2
0
 public function init()
 {
     $d = getcwd();
     chdir('../../../../');
     require_once 'include/epesi.php';
     require_once 'include/cache.php';
     require_once 'include/variables.php';
     require_once 'include/misc.php';
     require_once 'include/module_primitive.php';
     require_once 'include/module_install.php';
     require_once 'include/module_common.php';
     require_once 'include/module.php';
     require_once 'include/module_manager.php';
     require_once 'include/autoloader.php';
     ModuleManager::load_modules();
     chdir($d);
     global $E_SESSION;
     $_SESSION['user'] = $E_SESSION['user'];
     if (Base_RegionalSettingsCommon::time_12h()) {
         $time = 'h:i a';
     } else {
         $time = 'H:i';
     }
     $date = Base_RegionalSettingsCommon::date_format();
     switch ($date) {
         case '%Y-%m-%d':
             $date = 'Y-m-d';
             break;
         case '%m/%d/%Y':
             $date = 'm/d/Y';
             break;
         case '%d %B %Y':
             $date = 'd F Y';
             break;
         case '%d %b %Y':
             $date = 'd M Y';
             break;
         case '%b %d, %Y':
             $date = 'M d, Y';
             break;
     }
     rcmail::get_instance()->config->set('date_short', 'D ' . $time);
     rcmail::get_instance()->config->set('date_long', $date . ' ' . $time);
     rcmail::get_instance()->config->set('date_today', $time);
     $this->add_hook('message_outgoing_body', array($this, 'add_signature'));
     $this->add_hook('user_create', array($this, 'lookup_user_name'));
 }
Ejemplo n.º 3
0
 function _createElements()
 {
     $time_format = Base_RegionalSettingsCommon::time_12h() ? 'h:i a' : 'H:i';
     $lang_code = Base_LangCommon::get_lang_code();
     $this->_options['format'] = $time_format;
     if (!isset($this->_options['optionIncrement'])) {
         $this->_options['optionIncrement'] = array('i' => 5);
     }
     $this->_options['language'] = $lang_code;
     if (!isset($this->_options['date'])) {
         $this->_options['date'] = true;
     }
     $this->_elements['__date'] = new HTML_QuickForm_date('__date', null, $this->_options, $this->getAttributes());
     if ($this->_options['date']) {
         $this->_elements['__datepicker'] = new HTML_QuickForm_datepicker('__datepicker', null, $this->getAttributes());
     }
 }
Ejemplo n.º 4
0
 public static function QFfield_time(&$form, $field, $label, $mode, $default, $desc, $rb_obj)
 {
     if (self::QFfield_static_display($form, $field, $label, $mode, $default, $desc, $rb_obj)) {
         return;
     }
     $time_format = Base_RegionalSettingsCommon::time_12h() ? 'h:i a' : 'H:i';
     $lang_code = Base_LangCommon::get_lang_code();
     $label = Utils_RecordBrowserCommon::get_field_tooltip($label, $desc['type']);
     $minute_increment = 5;
     if ($desc['param']) {
         $minute_increment = $desc['param'];
     }
     $form->addElement('timestamp', $field, $label, array('date' => false, 'format' => $time_format, 'optionIncrement' => array('i' => $minute_increment), 'language' => $lang_code, 'id' => $field));
     if ($mode !== 'add' && $default) {
         $form->setDefaults(array($field => $default));
     }
 }
Ejemplo n.º 5
0
 public static function QFfield_duration(&$form, $field, $label, $mode, $default, $desc)
 {
     if ($mode == 'add' || $mode == 'edit') {
         $dur = array(-1 => '---', 300 => __('5 minutes'), 900 => __('15 minutes'), 1800 => __('30 minutes'), 2700 => __('45 minutes'), 3600 => __('1 hour'), 7200 => __('2 hours'), 14400 => __('4 hours'), 28800 => __('8 hours'));
         if (isset($dur[$default])) {
             $duration_switch = '1';
         } else {
             $duration_switch = '0';
         }
         $form->addElement('select', $field, $label, $dur, array('id' => $field));
         $time_format = Base_RegionalSettingsCommon::time_12h() ? 'h:i a' : 'H:i';
         $lang_code = Base_LangCommon::get_lang_code();
         $form->addElement('timestamp', 'end_time', __('End Time'), array('date' => false, 'format' => $time_format, 'optionIncrement' => array('i' => 5), 'language' => $lang_code, 'id' => 'end_time'));
         $form->addElement('hidden', 'duration_switch', $duration_switch, array('id' => 'duration_switch'));
         eval_js_once('crm_calendar_duration_switcher = function(x) {' . 'var sw = $(\'duration_switch\');' . 'if((!x && sw.value==\'0\') || (x && sw.value==\'1\')) {' . 'var end_b=$(\'crm_calendar_event_end_block\');if(end_b)end_b.hide();' . 'var dur_b=$(\'crm_calendar_duration_block\');if(dur_b)dur_b.show();' . 'sw.value=\'1\';' . '} else {' . 'var end_b=$(\'crm_calendar_event_end_block\');if(end_b)end_b.show();' . 'var dur_b=$(\'crm_calendar_duration_block\');if(dur_b)dur_b.hide();' . 'sw.value=\'0\';' . '}}');
         eval_js_once('crm_calendar_event_timeless = function(val) {' . 'var cal_style;' . 'var tdb=$(\'toggle_duration_button\');' . 'if(tdb==null) return;' . 'if(val){' . 'cal_style = \'none\';' . '}else{' . 'cal_style = \'\';' . '}' . 'var db = $(\'duration_end_date__data_\');' . 'if(db) db.style.display = cal_style;' . 'var ts = $(\'time_s\');' . 'if(ts) ts.style.display = cal_style;' . '}');
         $form->addElement('button', 'toggle', __('Toggle'), array('onclick' => 'crm_calendar_duration_switcher()', 'id' => 'toggle_duration_button', 'class' => 'button'));
         $form->addElement('checkbox', 'timeless', __('Timeless'), null, array('onClick' => 'crm_calendar_event_timeless(this.checked)', 'id' => 'timeless'));
         eval_js('crm_calendar_event_timeless($("timeless").checked)');
         eval_js('crm_calendar_duration_switcher(1)');
         $form->setDefaults(array('duration_switch' => $duration_switch));
         $form->setDefaults(array($field => $default));
         $form->setDefaults(array('timeless' => $default == -1 ? 1 : 0));
         if (class_exists('Utils_RecordBrowser') && isset(Utils_RecordBrowser::$last_record['time'])) {
             $form->setDefaults(array('end_time' => strtotime('+' . $default . ' seconds', Utils_RecordBrowser::$last_record['time'])));
         }
         $form->addFormRule(array('CRM_MeetingCommon', 'check_date_and_time'));
     } else {
         $form->addElement('checkbox', 'timeless', __('Timeless'));
         $form->setDefaults(array('timeless' => $default == -1 ? 1 : 0));
     }
     //messanger
     if ($mode == 'add') {
         eval_js_once('crm_calendar_event_messenger = function(v) {var mb=$("messenger_block");if(!mb)return;if(v)mb.show();else mb.hide();}');
         $form->addElement('select', 'messenger_before', __('Popup alert'), array(0 => __('on event start'), 900 => __('15 minutes before event'), 1800 => __('30 minutes before event'), 2700 => __('45 minutes before event'), 3600 => __('1 hour before event'), 2 * 3600 => __('2 hours before event'), 3 * 3600 => __('3 hours before event'), 4 * 3600 => __('4 hours before event'), 8 * 3600 => __('8 hours before event'), 12 * 3600 => __('12 hours before event'), 24 * 3600 => __('24 hours before event')));
         $form->addElement('textarea', 'messenger_message', __('Popup message'), array('id' => 'messenger_message'));
         $form->addElement('select', 'messenger_on', __('Alert'), array('none' => __('None'), 'me' => __('me'), 'all' => __('all selected employees')), array('onChange' => 'crm_calendar_event_messenger(this.value!="none");$("messenger_message").value=$("title").value;'));
         //			$form->addElement('checkbox','messenger_on',__('Alert me'),null,array('onClick'=>'crm_calendar_event_messenger(this.checked);$("messenger_message").value=$("event_title").value;'));
         eval_js('crm_calendar_event_messenger(' . ($form->exportValue('messenger_on') != 'none' && $form->exportValue('messenger_on') != '' ? 1 : 0) . ')');
         $form->registerRule('check_my_user', 'callback', array('CRM_MeetingCommon', 'check_my_user'));
         $form->addRule(array('messenger_on', 'emp_id'), __('You have to select your contact to set alarm on it'), 'check_my_user');
     }
 }