Ejemplo n.º 1
0
 /**
  * Class constructor
  *
  * @param string $elementName Element's name
  * @param mixed $elementLabel Label(s) for an element
  * @param array $options Options to control the element's display
  * @param mixed $attributes Either a typical HTML attribute string or an associative array
  */
 function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
 {
     $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
     $this->_persistantFreeze = true;
     $this->_appendName = true;
     $this->_type = 'date_time_selector';
     // set the options, do not bother setting bogus ones
     if (is_array($options)) {
         foreach ($options as $name => $value) {
             if (isset($this->_options[$name])) {
                 if (is_array($value) && is_array($this->_options[$name])) {
                     $this->_options[$name] = @array_merge($this->_options[$name], $value);
                 } else {
                     $this->_options[$name] = $value;
                 }
             }
         }
     }
     form_init_date_js();
 }
Ejemplo n.º 2
0
 function display()
 {
     parent::display();
     form_init_date_js();
 }
Ejemplo n.º 3
0
 protected function get_javascript_init_params($course, \cm_info $cm = null, \section_info $section = null)
 {
     global $CFG, $OUTPUT;
     require_once $CFG->libdir . '/formslib.php';
     // Support internationalised calendars.
     $calendartype = \core_calendar\type_factory::get_calendar_instance();
     // Get current date, but set time to 00:00 (to make it easier to
     // specify whole days) and change name of mday field to match below.
     $wrongfields = $calendartype->timestamp_to_date_array(time());
     $current = array('day' => $wrongfields['mday'], 'month' => $wrongfields['mon'], 'year' => $wrongfields['year'], 'hour' => 0, 'minute' => 0);
     // Time part is handled the same everywhere.
     $hours = array();
     for ($i = 0; $i <= 23; $i++) {
         $hours[$i] = sprintf("%02d", $i);
     }
     $minutes = array();
     for ($i = 0; $i < 60; $i += 5) {
         $minutes[$i] = sprintf("%02d", $i);
     }
     // List date fields.
     $fields = $calendartype->get_date_order($calendartype->get_min_year(), $calendartype->get_max_year());
     // Add time fields - in RTL mode these are switched.
     $fields['split'] = '/';
     if (right_to_left()) {
         $fields['minute'] = $minutes;
         $fields['colon'] = ':';
         $fields['hour'] = $hours;
     } else {
         $fields['hour'] = $hours;
         $fields['colon'] = ':';
         $fields['minute'] = $minutes;
     }
     // Output all date fields.
     $html = '<span class="availability-group">';
     foreach ($fields as $field => $options) {
         if ($options === '/') {
             $html = rtrim($html);
             // In Gregorian calendar mode only, we support a date selector popup, reusing
             // code from form to ensure consistency.
             if ($calendartype->get_name() === 'gregorian' && self::DATE_SELECTOR_SUPPORTED) {
                 $image = $OUTPUT->pix_icon('i/calendar', get_string('calendar', 'calendar'), 'moodle');
                 $html .= ' ' . \html_writer::link('#', $image, array('name' => 'x[calendar]'));
                 form_init_date_js();
             }
             $html .= '</span> <span class="availability-group">';
             continue;
         }
         if ($options === ':') {
             $html .= ': ';
             continue;
         }
         $html .= \html_writer::start_tag('label');
         $html .= \html_writer::span(get_string($field) . ' ', 'accesshide');
         // NOTE: The fields need to have these weird names in order that they
         // match the standard Moodle form control, otherwise the date selector
         // won't find them.
         $html .= \html_writer::start_tag('select', array('name' => 'x[' . $field . ']', 'class' => 'custom-select'));
         foreach ($options as $key => $value) {
             $params = array('value' => $key);
             if ($current[$field] == $key) {
                 $params['selected'] = 'selected';
             }
             $html .= \html_writer::tag('option', s($value), $params);
         }
         $html .= \html_writer::end_tag('select');
         $html .= \html_writer::end_tag('label');
         $html .= ' ';
     }
     $html = rtrim($html) . '</span>';
     // Also get the time that corresponds to this default date.
     $time = self::get_time_from_fields($current['year'], $current['month'], $current['day'], $current['hour'], $current['minute']);
     return array($html, $time);
 }
Ejemplo n.º 4
0
 /**
  * constructor
  *
  * @param string $elementName Element's name
  * @param mixed $elementLabel Label(s) for an element
  * @param array $options Options to control the element's display
  * @param mixed $attributes Either a typical HTML attribute string or an associative array
  */
 function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null)
 {
     // Get the calendar type used - see MDL-18375.
     $calendartype = \core_calendar\type_factory::get_calendar_instance();
     $this->_options = array('startyear' => $calendartype->get_min_year(), 'stopyear' => $calendartype->get_max_year(), 'defaulttime' => 0, 'timezone' => 99, 'step' => 5, 'optional' => false);
     $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
     $this->_persistantFreeze = true;
     $this->_appendName = true;
     $this->_type = 'date_selector';
     // set the options, do not bother setting bogus ones
     if (is_array($options)) {
         foreach ($options as $name => $value) {
             if (isset($this->_options[$name])) {
                 if (is_array($value) && is_array($this->_options[$name])) {
                     $this->_options[$name] = @array_merge($this->_options[$name], $value);
                 } else {
                     $this->_options[$name] = $value;
                 }
             }
         }
     }
     // The YUI2 calendar only supports the gregorian calendar type.
     if ($calendartype->get_name() === 'gregorian') {
         form_init_date_js();
     }
 }
Ejemplo n.º 5
0
 function toHtml()
 {
     form_init_date_js();
     include_once 'HTML/QuickForm/Renderer/Default.php';
     $renderer =& new HTML_QuickForm_Renderer_Default();
     $renderer->setElementTemplate('{element}');
     parent::accept($renderer);
     return $this->_wrap[0] . $renderer->toHtml() . $this->_wrap[1];
 }
Ejemplo n.º 6
0
                        if (in_array($message->id(), $msgs)) {
                            $message->set_unread($USER->id, $unread);
                        }
                    }
                    redirect($url);
                }
                // Perpage
                if ($perpage) {
                    require_sesskey();
                    if (in_array($perpage, array(5, 10, 20, 50, 100))) {
                        set_user_preference('local_mail_mailsperpage', $perpage);
                    }
                    redirect($url);
                }
                $jslabels = local_mail_js_labels();
                // Display page
                $PAGE->requires->data_for_js('M.local_mail_lang', current_language(), true);
                $PAGE->requires->js('/local/mail/mail.js');
                $PAGE->requires->strings_for_js(array('delete', 'editlabel', 'erroremptylabelname', 'labeldeleteconfirm', 'newlabel', 'starred', 'undodelete', 'undorestore', 'unstarred'), 'local_mail');
                $PAGE->requires->string_for_js('submit', 'moodle');
                $PAGE->requires->string_for_js('cancel', 'moodle');
                form_init_date_js();
                $PAGE->requires->js_init_code($jslabels);
                $mailoutput = $PAGE->get_renderer('local_mail');
                echo $OUTPUT->header();
                echo $mailoutput->view(array('type' => $type, 'labelid' => $labelid, 'itemid' => $itemid, 'courseid' => $courseid, 'userid' => $USER->id, 'messages' => $messages, 'totalcount' => $totalcount, 'offset' => $offset));
                echo $OUTPUT->footer();
            }
        }
    }
}