exists()) { // Set up some default values: $this->occurs = 'daily'; $this->daily_repeats_type = 'every n'; $this->daily_repeats_every_n = 1; $this->weekly_repeats_every_n = 1; // Suspend this -- this is how Hotmail does it, setting the "weekly repeat" day to the 'today', but I don't think it makes any sense. In fact, I don't think setting a day here makes any sense at all -- surely you'd set the start day to, say, 'Tuesday', and then the event would repeat weekly, every Tuesday? // $this->weekly_repeats_on_day = array(date('l')); $this->monthly_repeats_every_n = 1; $this->monthly_repeats_type = 'fixed'; $this->yearly_repeats_type = 'fixed'; $this->ends_type = 'never'; if (!empty($this->weekly_repeats_on_day)) { $this->weekly_repeats_on_day = explode(',', $this->weekly_repeats_on_day); } else { $this->weekly_repeats_on_day = array(); } } else { $this->weekly_repeats_on_day = array(); } } /* public function load($where = false, $bind = false) { $return = parent::load($where,$bind); // I think we'll need to call synchDates, to check that all the various fields are in synch with each other, and to make sure that we've loaded data [eg, start_date] from the parent Entry where necessary: $this->synchDates(); return $return; } public function loadFromPost($arguments = array()) { parent::loadFromPost($arguments); // Update some of the data properties, based on the data loaded: $this->synchDates(); // Add some post-processing here, to handle the "internal" properties defined above: } */ public function loadFromPost() { $matched = false; foreach ($_POST as $key=>$value) { if (strpos($key,'Recurrence_') === 0) { $property = str_replace('Recurrence_','',$key); if (strpos($property,'ends_on') === 0) { $day = false; $month = false; $year = false; if (!empty($_POST['Recurrence_ends_on-dd'])) { $day = $_POST['Recurrence_ends_on-dd']; } if (!empty($_POST['Recurrence_ends_on-mm'])) { $month = $_POST['Recurrence_ends_on-mm']; } if (!empty($_POST['Recurrence_ends_on'])) { $year = $_POST['Recurrence_ends_on']; } if ($day && $month && $year) { $this->ends_on = $year.'-'.$month.'-'.$day; $matched = true; } } else { $this->$property = $value; if ($value) $matched = true; } } } return $matched; } public function synchDates() { // This function will need updating, I think -- it's been simplified a lot since we extended the number of columns in the database table, but I think it'll need a lot more adding to it. $entry = new Entry(); if ($this->parent_class == 'Entry' && $this->parent_id) { $entry->load($this->parent_id); } if ($this->occurs == 'daily') { } else if ($this->occurs == 'weekly') { } else if ($this->occurs == 'monthly') { if ($entry->start_date) { $this->monthly_repeats_on_n = date("d",strtotime($entry->start_date)); } } else if ($this->occurs == 'yearly') { if ($entry->start_date) { $this->yearly_repeats_on_n = date("d",strtotime($entry->start_date)); } } } public function draw_fieldset() { // Hardcoded for now: return $this->load->view('recurrence/fieldset',array('recurrence'=>$this),true); } public function _drawFieldSet() { $html = ''; $html .= '
'.$this->drawHidden('id').' '.$this->drawHidden('parent_class').' '.$this->drawHidden('parent_id').'
'.$this->drawLabel('occurs',false).'
'.$this->drawField('occurs').'
'.$this->drawField('daily_repeats_type',array('type'=>'radios','template'=>'{field}','key'=>'every n')).' '.$this->drawLabel('daily_repeats_type',"Every",array('key'=>'every n','style'=>'padding-right: 5px')).' '.$this->drawField('daily_repeats_every_n',array('style'=>'width: 20px')).'  day(s)
 
'.$this->drawField('daily_repeats_type',array('type'=>'radios','template'=>'{field}','key'=>'weekday')).' '.$this->drawLabel('daily_repeats_type',"On every weekday",array('key'=>'weekday')).'
'.$this->drawLabel('weekly_repeats_every_n',"And repeats every").'
'.$this->drawField('weekly_repeats_every_n',array('style'=>'width: 20px')).'  week(s)
'.$this->drawField('weekly_repeats_on_day',array('break_every'=>4)).'
'.$this->drawLabel('monthly_repeats_every_n',"And repeats every").'
'.$this->drawField('monthly_repeats_every_n',array('style'=>'width: 20px')).'  months(s)
'.$this->drawField('monthly_repeats_type',array('type'=>'radios','template'=>'{field}','key'=>'fixed')).' '.$this->drawLabel('monthly_repeats_type'," same day of the month",array('key'=>'fixed')).'
 
'.$this->drawField('monthly_repeats_type',array('type'=>'radios','template'=>'{field}','key'=>'flexible')).' '.$this->drawField('monthly_repeats_on_nth').' '.$this->drawField('monthly_repeats_on_day').' of the month
'.$this->drawField('yearly_repeats_type',array('type'=>'radios','template'=>'{field}','key'=>'fixed')).' '.$this->drawLabel('yearly_repeats_type'," same day of the same month",array('key'=>'fixed')).'
 
'.$this->drawField('yearly_repeats_type',array('type'=>'radios','template'=>'{field}','key'=>'flexible')).' '.$this->drawField('yearly_repeats_on_nth').' '.$this->drawField('yearly_repeats_on_day').' of the same month
'.$this->drawField('ends_type',array('type'=>'radios','template'=>'{field}','key'=>'never')).' '.$this->drawLabel('ends_type',"Never ends",array('key'=>'never')).'
 
'.$this->drawField('ends_type',array('type'=>'radios','template'=>'{field}','key'=>'after')).' '.$this->drawLabel('ends_type'," after ",array('key'=>'after')).' '.$this->drawField('ends_after').'  occurence(s)
 
'.$this->drawField('ends_type',array('type'=>'radios','template'=>'{field}','key'=>'on')).' '.$this->drawLabel('ends_type'," on ",array('key'=>'on')).' '.$this->drawField('ends_on').'
'; $html .= " "; return $html; } } ?>