MDL-20353 adding missing data types of hidden form fields
[moodle.git] / user / filters / user_filter_forms.php
1 <?php //$Id$
3 require_once($CFG->libdir.'/formslib.php');
5 class user_add_filter_form extends moodleform {
7     function definition() {
8         $mform       =& $this->_form;
9         $fields      = $this->_customdata['fields'];
10         $extraparams = $this->_customdata['extraparams'];
12         $mform->addElement('header', 'newfilter', get_string('newfilter','filters'));
14         foreach($fields as $ft) {
15             $ft->setupForm($mform);
16         }
18         // in case we wasnt to track some page params
19         if ($extraparams) {
20             foreach ($extraparams as $key=>$value) {
21                 $mform->addElement('hidden', $key, $value);
22                 $mform->setType($key, PARAM_RAW);
23             }
24         }
26         // Add button
27         $mform->addElement('submit', 'addfilter', get_string('addfilter','filters'));
29         // Don't use last advanced state
30         $mform->setShowAdvanced(false);
31     }
32 }
34 class user_active_filter_form extends moodleform {
36     function definition() {
37         global $SESSION; // this is very hacky :-(
39         $mform       =& $this->_form;
40         $fields      = $this->_customdata['fields'];
41         $extraparams = $this->_customdata['extraparams'];
43         if (!empty($SESSION->user_filtering)) {
44             // add controls for each active filter in the active filters group
45             $mform->addElement('header', 'actfilterhdr', get_string('actfilterhdr','filters'));
47             foreach ($SESSION->user_filtering as $fname=>$datas) {
48                 if (!array_key_exists($fname, $fields)) {
49                     continue; // filter not used
50                 }
51                 $field = $fields[$fname];
52                 foreach($datas as $i=>$data) {
53                     $description = $field->get_label($data);
54                     $mform->addElement('checkbox', 'filter['.$fname.']['.$i.']', null, $description);
55                 }
56             }
58             if ($extraparams) {
59                 foreach ($extraparams as $key=>$value) {
60                     $mform->addElement('hidden', $key, $value);
61                     $mform->setType($key, PARAM_RAW);
62                 }
63             }
65             $objs = array();
66             $objs[] = &$mform->createElement('submit', 'removeselected', get_string('removeselected','filters'));
67             $objs[] = &$mform->createElement('submit', 'removeall', get_string('removeall','filters'));
68             $mform->addElement('group', 'actfiltergrp', '', $objs, ' ', false);
69         }
70     }
71 }