Example #1
0
function options_form()
{
    global $config, $phpc_script, $config_form;
    $tbody = tag('tbody');
    foreach ($config_form as $element) {
        $name = $element[0];
        $text = $element[1];
        $type = $element[2];
        switch ($type) {
            case CHECK:
                $input = create_checkbox($name, '1', $config[$name]);
                break;
            case TEXT:
                $input = create_text($name, $config[$name]);
                break;
            case DROPDOWN:
                $sequence = create_sequence(0, count($element[3]) - 1);
                $input = create_select($name, $element[3], $config[$name], $sequence);
                break;
            default:
                soft_error(_('Unsupported config type') . ": {$type}");
        }
        $tbody->add(tag('tr', tag('th', $text . ':'), tag('td', $input)));
    }
    return tag('form', attributes("action=\"{$phpc_script}\"", 'method="post"'), tag('table', attributes('class="phpc-main"'), tag('caption', _('Options')), tag('tfoot', tag('tr', tag('td', attributes('colspan="2"'), create_hidden('action', 'options_submit'), create_submit(_('Submit'))))), $tbody));
}
Example #2
0
function search_form()
{
    global $day, $month, $year, $phpc_script, $month_names, $sort_options, $order_options;
    $day_sequence = create_sequence(1, 31);
    $month_sequence = create_sequence(1, 12);
    $year_sequence = create_sequence(1970, 2037);
    $html_table = tag('table', attributes('class="phpc-main"'), tag('caption', _('Search')), tag('tfoot', tag('tr', tag('td', attributes('colspan="2"'), create_submit(_('Submit'))))), tag('tr', tag('td', _('Phrase') . ': '), tag('td', tag('input', attributes('type="text"', 'name="searchstring"', 'size="32"')), create_hidden('action', 'search'))), tag('tr', tag('td', _('From') . ': '), tag('td', create_select('sday', $day_sequence, $day), create_select('smonth', $month_names, $month), create_select('syear', $year_sequence, $year))), tag('tr', tag('td', _('To') . ': '), tag('td', create_select('eday', $day_sequence, $day), create_select('emonth', $month_names, $month), create_select('eyear', $year_sequence, $year))), tag('tr', tag('td', _('Sort By') . ': '), tag('td', create_select('sort', $sort_options, false))), tag('tr', tag('td', _('Order') . ': '), tag('td', create_select('order', $order_options, false))));
    return tag('form', attributes("action=\"{$phpc_script}\"", 'method="post"'), $html_table);
}
Example #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);
}
Example #4
0
function event_form()
{
    global $vars, $day, $month, $year, $db, $config, $phpc_script, $month_names, $event_types;
    if (isset($vars['id'])) {
        // modifying
        $id = $vars['id'];
        $title = sprintf(_('Editing Event #%d'), $id);
        $row = get_event_by_id($id);
        $subject = htmlspecialchars(stripslashes($row['subject']));
        $desc = htmlspecialchars(stripslashes($row['description']));
        $year = $row['year'];
        $month = $row['month'];
        $day = $row['day'];
        $hour = date('H', strtotime($row['starttime']));
        $minute = date('i', strtotime($row['starttime']));
        $end_year = $row['end_year'];
        $end_month = $row['end_month'];
        $end_day = $row['end_day'];
        $durmin = $row['duration'] % 60;
        $durhr = floor($row['duration'] / 60);
        if (!$config['hours_24']) {
            if ($hour > 12) {
                $pm = true;
                $hour = $hour - 12;
            } elseif ($hour == 12) {
                $pm = true;
            } else {
                $pm = false;
            }
        }
        $typeofevent = $row['eventtype'];
        $multiday = $year != $end_year || $month != $end_month || $day != $end_day;
    } else {
        // case "add":
        $title = _('Adding event to calendar');
        $subject = '';
        $desc = '';
        if ($day == date('j') && $month == date('n') && $year == date('Y')) {
            if ($config['hours_24']) {
                $hour = date('G');
            } else {
                $hour = date('g');
                if (date('a') == 'pm') {
                    $pm = true;
                } else {
                    $pm = false;
                }
            }
        } else {
            $hour = 6;
            $pm = true;
        }
        $minute = 0;
        $end_day = $day;
        $end_month = $month;
        $end_year = $year;
        $durhr = 1;
        $durmin = 0;
        $typeofevent = 1;
        $multiday = false;
    }
    if ($config['hours_24']) {
        $hour_sequence = create_sequence(0, 23);
    } else {
        $hour_sequence = create_sequence(1, 12);
    }
    $minute_sequence = create_sequence(0, 59, 5, 'minute_pad');
    $year_sequence = create_sequence(1970, 2037);
    $html_time = tag('td', create_select('hour', $hour_sequence, $hour), tag('b', ':'), create_select('minute', $minute_sequence, $minute));
    if (!$config['hours_24']) {
        if ($pm) {
            $value = 1;
        } else {
            $value = 0;
        }
        $html_time->add(create_select('pm', array(_('AM'), _('PM')), $value));
    }
    if (isset($id)) {
        $input = create_hidden('id', $id);
    } else {
        $input = '';
    }
    $attributes = attributes('class="phpc-main"');
    $day_of_month_sequence = create_sequence(1, 31);
    return tag('form', attributes("action=\"{$phpc_script}\""), tag('table', $attributes, tag('caption', $title), tag('tfoot', tag('tr', tag('td', attributes('colspan="2"'), $input, create_submit(_("Submit Event")), create_hidden('action', 'event_submit')))), tag('tbody', tag('tr', tag('th', _('Date of event')), tag('td', create_select('day', $day_of_month_sequence, $day), create_select('month', $month_names, $month), create_select('year', $year_sequence, $year))), tag('tr', tag('th', _('Multiple day event')), tag('td', create_checkbox('multiday', '1', $multiday))), tag('tr', tag('th', _('End date (Multiple day events only)')), tag('td', create_select('endday', $day_of_month_sequence, $end_day), create_select('endmonth', $month_names, $end_month), create_select('endyear', $year_sequence, $end_year))), tag('tr', tag('th', _('Event type')), tag('td', create_select('typeofevent', $event_types, $typeofevent))), tag('tr', tag('th', _('Time')), $html_time), tag('tr', tag('th', _('Duration')), tag('td', create_select('durationhour', create_sequence(0, 23), $durhr), _('hour(s)') . "\n", create_select('durationmin', $minute_sequence, $durmin), _('minutes') . "\n")), tag('tr', tag('th', _('Subject') . ' (' . $config['subject_max'] . ' ' . _('chars max') . ')'), tag('td', tag('input', attributes('type="text"', "size=\"{$config['subject_max']}\"", "maxlength=\"{$config['subject_max']}\"", 'name="subject"', "value=\"{$subject}\"")))), tag('tr', tag('th', _('Description')), tag('td', tag('textarea', attributes('rows="5"', 'cols="50"', 'name="description"'), $desc))))));
}