public function definition()
 {
     global $CFG;
     $mform = $this->_form;
     $mform->addElement('text', 'displayname', get_string('displayname', 'report_customsql'));
     $mform->addRule('displayname', get_string('displaynamerequired', 'report_customsql'), 'required', null, 'client');
     $mform->setType('displayname', PARAM_MULTILANG);
     $mform->addElement('editor', 'description', get_string('description', 'report_customsql'));
     $mform->setType('description', PARAM_RAW);
     $mform->addElement('textarea', 'querysql', get_string('querysql', 'report_customsql'), 'rows="25" cols="50"');
     $mform->addRule('querysql', get_string('querysqlrequried', 'report_customsql'), 'required', null, 'client');
     $mform->setType('querysql', PARAM_RAW);
     $mform->addElement('submit', 'verify', get_string('verifyqueryandupdate', 'report_customsql'));
     $mform->registerNoSubmitButton('verify');
     $hasparameters = 0;
     if (count($this->_customdata)) {
         $mform->addElement('static', 'params', '', get_string('queryparams', 'report_customsql'));
         foreach ($this->_customdata as $queryparam => $formparam) {
             $type = report_customsql_get_element_type($queryparam);
             $mform->addElement($type, $formparam, $queryparam);
             if ($type == 'text') {
                 $mform->setType($formparam, PARAM_RAW);
             }
             $hasparameters++;
         }
         $mform->addElement('static', 'spacer', '', '');
     }
     $mform->addElement('static', 'note', get_string('note', 'report_customsql'), get_string('querynote', 'report_customsql', $CFG->wwwroot));
     $capabilityoptions = report_customsql_capability_options();
     $mform->addElement('select', 'capability', get_string('whocanaccess', 'report_customsql'), $capabilityoptions);
     end($capabilityoptions);
     $mform->setDefault('capability', key($capabilityoptions));
     $mform->addElement('text', 'querylimit', get_string('querylimit', 'report_customsql'));
     $mform->setType('querylimit', PARAM_INT);
     $mform->setDefault('querylimit', REPORT_CUSTOMSQL_MAX_RECORDS);
     $mform->addRule('querylimit', get_string('requireint', 'report_customsql'), 'numeric', null, 'client');
     $runat = array();
     if ($hasparameters) {
         $runat[] = $mform->createElement('select', 'runable', null, report_customsql_runable_options('manual'));
     } else {
         $runat[] = $mform->createElement('select', 'runable', null, report_customsql_runable_options());
     }
     $runat[] = $mform->createElement('select', 'at', null, report_customsql_daily_at_options());
     $mform->addGroup($runat, 'runablegroup', get_string('runable', 'report_customsql'), get_string('at', 'report_customsql'), false);
     $mform->addElement('checkbox', 'singlerow', get_string('typeofresult', 'report_customsql'), get_string('onerow', 'report_customsql'));
     $mform->addElement('text', 'emailto', get_string('emailto', 'report_customsql'), 'size = 70');
     $mform->addElement('select', 'emailwhat', get_string('emailwhat', 'report_customsql'), report_customsql_email_options());
     $mform->disabledIf('singlerow', 'runable', 'eq', 'manual');
     $mform->disabledIf('at', 'runable', 'ne', 'daily');
     $mform->disabledIf('emailto', 'runable', 'eq', 'manual');
     $mform->disabledIf('emailwhat', 'runable', 'eq', 'manual');
     $mform->setType('emailto', PARAM_RAW);
     // Add new category selection.
     $categoryoptions = report_customsql_category_options();
     $mform->addElement('select', 'categoryid', get_string('selectcategory', 'report_customsql'), $categoryoptions);
     $catdefault = isset($categoryoptions[1]) ? 1 : key($categoryoptions);
     $mform->setDefault('categoryid', $catdefault);
     $this->add_action_buttons();
 }
 public function test_report_customsql_email_options()
 {
     $options = array('emailnumberofrows' => get_string('emailnumberofrows', 'report_customsql'), 'emailresults' => get_string('emailresults', 'report_customsql'));
     $this->assertEquals($options, report_customsql_email_options());
 }