Esempio n. 1
0
 /**
  * Adds the specified component to the IComponentContainer.
  * @param  IComponent
  * @param  string
  * @param  string
  * @return void
  * @throws InvalidStateException
  */
 public function addComponent(IComponent $component, $name, $insertBefore = NULL)
 {
     parent::addComponent($component, $name, $insertBefore);
     if ($this->currentGroup !== NULL && $component instanceof IFormControl) {
         $this->currentGroup->add($component);
     }
 }
Esempio n. 2
0
function display_form()
{
    global $phpc_script, $phpc_year, $phpc_month, $phpc_day, $vars, $phpcdb, $phpc_cal, $phpc_token;
    $hour24 = $phpc_cal->hours_24;
    $date_format = $phpc_cal->date_format;
    $form = new Form($phpc_script, __('Occurrence Form'));
    $when_group = new FormGroup(__('When'));
    $when_group->add_part(new FormDateTimeQuestion('start', __('From'), $hour24, $date_format));
    $when_group->add_part(new FormDateTimeQuestion('end', __('To'), $hour24, $date_format));
    $time_type = new FormDropDownQuestion('time-type', __('Time Type'));
    $time_type->add_option('normal', __('Normal'));
    $time_type->add_option('full', __('Full Day'));
    $time_type->add_option('tba', __('To Be Announced'));
    $when_group->add_part($time_type);
    $form->add_part($when_group);
    if (isset($vars['phpcid'])) {
        $form->add_hidden('phpcid', $vars['phpcid']);
    }
    if (isset($vars['oid'])) {
        $form->add_hidden('oid', $vars['oid']);
        $occ = $phpcdb->get_occurrence_by_oid($vars['oid']);
        $datefmt = $phpc_cal->date_format;
        $start_date = format_short_date_string($occ->get_start_year(), $occ->get_start_month(), $occ->get_start_day(), $datefmt);
        $end_date = format_short_date_string($occ->get_end_year(), $occ->get_end_month(), $occ->get_end_day(), $datefmt);
        $start_time = $occ->get_start_time();
        if ($start_time == NULL) {
            $start_time = format_time_string(17, 0, $hour24);
        }
        $end_time = $occ->get_end_time();
        if ($end_time == NULL) {
            $end_time = format_time_string(18, 0, $hour24);
        }
        $defaults = array('start-date' => $start_date, 'end-date' => $end_date, 'start-time' => $start_time, 'end-time' => $end_time);
        switch ($occ->get_time_type()) {
            case 0:
                $defaults['time-type'] = 'normal';
                break;
            case 1:
                $defaults['time-type'] = 'full';
                break;
            case 2:
                $defaults['time-type'] = 'tba';
                break;
        }
    } else {
        $form->add_hidden('eid', $vars['eid']);
        $defaults = array('start-date' => "{$phpc_month}/{$phpc_day}/{$phpc_year}", 'end-date' => "{$phpc_month}/{$phpc_day}/{$phpc_year}", 'start-time' => format_time_string(17, 0, $hour24), 'end-time' => format_time_string(18, 0, $hour24));
    }
    $form->add_hidden('phpc_token', $phpc_token);
    $form->add_hidden('action', 'occur_form');
    $form->add_hidden('submit_form', 'submit_form');
    $form->add_part(new FormSubmitButton(__("Submit Occurrence")));
    return $form->get_form($defaults);
}
Esempio n. 3
0
function display_form()
{
    global $phpc_script, $year, $month, $day, $vars, $phpcdb, $phpc_cal, $phpc_user, $phpc_token;
    $hour24 = $phpc_cal->hours_24;
    $date_format = $phpc_cal->date_format;
    $form = new Form($phpc_script, __('Event Form'));
    $form->add_part(new FormFreeQuestion('subject', __('Subject'), false, $phpc_cal->subject_max, true));
    $form->add_part(new FormLongFreeQuestion('description', __('Description')));
    $when_group = new FormGroup(__('When'), 'phpc-when');
    if (isset($vars['eid'])) {
        $when_group->add_part(new FormCheckBoxQuestion('phpc-modify', false, __('Change the event date and time')));
    }
    $when_group->add_part(new FormDateTimeQuestion('start', __('From'), $hour24, $date_format));
    $when_group->add_part(new FormDateTimeQuestion('end', __('To'), $hour24, $date_format));
    $time_type = new FormDropDownQuestion('time-type', __('Time Type'));
    $time_type->add_option('normal', __('Normal'));
    $time_type->add_option('full', __('Full Day'));
    $time_type->add_option('tba', __('To Be Announced'));
    $when_group->add_part($time_type);
    $form->add_part($when_group);
    $repeat_type = new FormDropdownQuestion('repeats', __('Repeats'), array(), true, 'never');
    $repeat_type->add_option('never', __('Never'));
    $daily_group = new FormGroup();
    $repeat_type->add_option('daily', __('Daily'), NULL, $daily_group);
    $weekly_group = new FormGroup();
    $repeat_type->add_option('weekly', __('Weekly'), NULL, $weekly_group);
    $monthly_group = new FormGroup();
    $repeat_type->add_option('monthly', __('Monthly'), NULL, $monthly_group);
    $yearly_group = new FormGroup();
    $repeat_type->add_option('yearly', __('Yearly'), NULL, $yearly_group);
    $every_day = new FormDropdownQuestion('every-day', __('Every'), __('Repeat every how many days?'));
    $every_day->add_options(create_sequence(1, 30));
    $daily_group->add_part($every_day);
    $daily_group->add_part(new FormDateQuestion('daily-until', __('Until'), $date_format));
    $every_week = new FormDropdownQuestion('every-week', __('Every'), __('Repeat every how many weeks?'));
    $every_week->add_options(create_sequence(1, 30));
    $weekly_group->add_part($every_week);
    $weekly_group->add_part(new FormDateQuestion('weekly-until', __('Until'), $date_format));
    $every_month = new FormDropdownQuestion('every-month', __('Every'), __('Repeat every how many months?'));
    $every_month->add_options(create_sequence(1, 30));
    $monthly_group->add_part($every_month);
    $monthly_group->add_part(new FormDateQuestion('monthly-until', __('Until'), $date_format));
    $every_year = new FormDropdownQuestion('every-year', __('Every'), __('Repeat every how many years?'));
    $every_year->add_options(create_sequence(1, 30));
    $yearly_group->add_part($every_year);
    $yearly_group->add_part(new FormDateQuestion('yearly-until', __('Until'), $date_format));
    $when_group->add_part($repeat_type);
    if ($phpc_cal->can_create_readonly()) {
        $form->add_part(new FormCheckBoxQuestion('readonly', false, __('Read-only')));
    }
    $categories = new FormDropdownQuestion('catid', __('Category'));
    $categories->add_option('', __('None'));
    $have_categories = false;
    foreach ($phpc_cal->get_visible_categories($phpc_user->get_uid()) as $category) {
        $categories->add_option($category['catid'], $category['name']);
        $have_categories = true;
    }
    if ($have_categories) {
        $form->add_part($categories);
    }
    if (isset($vars['phpcid'])) {
        $form->add_hidden('phpcid', $vars['phpcid']);
    }
    $form->add_hidden('phpc_token', $phpc_token);
    $form->add_hidden('action', 'event_form');
    $form->add_hidden('submit_form', 'submit_form');
    $form->add_part(new FormSubmitButton(__("Submit Event")));
    if (isset($vars['eid'])) {
        $form->add_hidden('eid', $vars['eid']);
        $occs = $phpcdb->get_occurrences_by_eid($vars['eid']);
        $event = $occs[0];
        $defaults = array('subject' => $event->get_raw_subject(), 'description' => $event->get_raw_desc(), 'start-date' => $event->get_short_start_date(), 'end-date' => $event->get_short_end_date(), 'start-time' => $event->get_start_time(), 'end-time' => $event->get_end_time(), 'readonly' => $event->is_readonly());
        if (!empty($event->catid)) {
            $defaults['catid'] = $event->catid;
        }
        switch ($event->get_time_type()) {
            case 0:
                $defaults['time-type'] = 'normal';
                break;
            case 1:
                $defaults['time-type'] = 'full';
                break;
            case 2:
                $defaults['time-type'] = 'tba';
                break;
        }
        add_repeat_defaults($occs, $defaults);
    } else {
        $hour24 = $phpc_cal->hours_24;
        $datefmt = $phpc_cal->date_format;
        $date_string = format_short_date_string($year, $month, $day, $datefmt);
        $defaults = array('start-date' => $date_string, 'end-date' => $date_string, 'start-time' => format_time_string(17, 0, $hour24), 'end-time' => format_time_string(18, 0, $hour24), 'daily-until-date' => $date_string, 'weekly-until-date' => $date_string, 'monthly-until-date' => $date_string, 'yearly-until-date' => $date_string);
    }
    return $form->get_form($defaults);
}
Esempio n. 4
0
 /**
  * Adds fieldset group to the form.
  * @param  string  caption
  * @param  bool    set this group as current
  * @return FormGroup
  */
 public function addGroup($caption = NULL, $setAsCurrent = TRUE)
 {
     $group = new FormGroup();
     $group->setOption('label', $caption);
     $group->setOption('visual', TRUE);
     if ($setAsCurrent) {
         $this->setCurrentGroup($group);
     }
     if (isset($this->groups[$caption])) {
         return $this->groups[] = $group;
     } else {
         return $this->groups[$caption] = $group;
     }
 }
Esempio n. 5
0
	public function  __construct($atts = null) {
		error_log(__CLASS__ . ' is candidate for immediate removal, please change this code!', E_USER_DEPRECATED);

		// Defaults
		$this->_attributes['name']    = 'page';

		if ($atts instanceof PageModel) {
			parent::__construct(array('name' => 'page'));

			$page = $atts;
		}
		else {
			if(isset($atts['model']) && $atts['model'] instanceof PageModel){
				// Everything is based off the page.
				$page = $atts['model'];
				unset($atts['model']);

				parent::__construct($atts);
			}
			else{
				parent::__construct($atts);

				// BaseURL needs to be set for this to work.
				//if(!$this->get('baseurl')) return null;

				// Everything is based off the page.
				$page = new PageModel($this->get('baseurl'));
			}
		}

		$this->_attributes['baseurl'] = $page->get('baseurl');
		$name = $this->_attributes['name'];

		// I need to get a list of pages to offer as a dropdown for selecting the "parent" page.
		$f = new ModelFactory('PageModel');
		if ($this->get('baseurl')) $f->where('baseurl != ' . $this->get('baseurl'));
		$opts = PageModel::GetPagesAsOptions($f, '-- No Parent Page --');

		$this->addElement(
			'pageparentselect',
			array(
				'name'    => $name . "[parenturl]",
				'title'   => 'Parent Page',
				'value'   => strtolower($page->get('parenturl')),
				'options' => $opts
			)
		);

		// Title
		$this->addElement(
			'text', array(
				      'name'        => $name . "[title]",
				      'title'       => 'Title',
				      'value'       => $page->get('title'),
				      'description' => 'Every page needs a title to accompany it, this should be short but meaningful.',
				      'required'    => true
			      )
		);

		// Rewrite url.
		$this->addElement(
			'pagerewriteurl', array(
				                'name'        => $name . "[rewriteurl]",
				                'title'       => 'Page URL',
				                'value'       => $page->get('rewriteurl'),
				                'description' => 'Starts with a "/", omit ' . ROOT_URL,
				                'required'    => true
			                )
		);

		$this->addElement(
			'access', array(
				        'name'  => $name . "[access]",
				        'title' => 'Access Permissions',
				        'value' => $page->get('access')
			        )
		);

		$this->addElement(
			'pagemetas',
			array(
				'name' => $name . '_meta',
				'model' => $page,
			)
		);

		// Give me all the skins available on the current theme.
		$skins = array('' => '-- Site Default Skin --');
		foreach(ThemeHandler::GetTheme(null)->getSkins() as $s){
			$n = ($s['title']) ? $s['title'] : $s['file'];
			if($s['default']) $n .= ' (default)';
			$skins[$s['file']] = $n;
		}
		if(sizeof($skins) > 2){
			$this->addElement(
				'select', array(
					        'name'    => $name . "[theme_template]",
					        'title'   => 'Theme Skin',
					        'value'   => $page->get('theme_template'),
					        'options' => $skins
				        )
			);
		}
	}
Esempio n. 6
0
 function get_results($vars = false)
 {
     global $form_error_func;
     if ($vars === false) {
         if ($this->vars === false) {
             $this->error('No vars');
         }
         $vars = $this->vars;
     }
     return parent::get_results($vars);
 }
Esempio n. 7
0
	/**
	 * Add a given element to this form, (or group in this form).
	 * If the element as the "group" property, it will automatically be added to that respective group.
	 *
	 * @param       $element
	 * @param array $atts
	 */
	public function addElement($element, $atts = []){
		// Group support! :)
		if(isset($atts['group'])){
			$grouptype = isset($atts['grouptype']) ? $atts['grouptype'] : 'default';

			$this->getGroup( $atts['group'], $grouptype )->addElement($element, $atts);
		}
		elseif($element instanceof FormElement && $element->get('group')){
			$grouptype = $element->get('grouptype') ? $element->get('grouptype') : 'default';

			$this->getGroup( $element->get('group'), $grouptype )->addElement($element, $atts);
		}
		else{
			parent::addElement($element, $atts);
		}
	}
Esempio n. 8
0
	public function render(){
		//$out = '';
		$prefix = $this->get('name');
		if(!$this->get('title')) $this->set('title', 'Meta Information (SEO)');

		foreach($this->_getMetas() as $name => $dat){

			// The options will start as the array of data.
			$opts = $dat;
			// Don't need this guy
			unset($opts['type']);
			// The name gets updated slightly
			$opts['name'] = $prefix . '[' . $name . ']';

			if(!$this->getElement($opts['name'])){
				$this->addElement( $dat['type'], $opts );
			}

			/*
			$el = FormElement::Factory($dat['type'], array(
				'name'        => ($prefix . '[' . $name . ']'),
				'title'       => $dat['title'],
				'description' => $dat['description'],
				'value'       => $dat['value']
			));
			$out .= $el->render();
			*/
		}
		return parent::render();
	}