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();
 }
 function definition()
 {
     global $CFG;
     $mform =& $this->_form;
     $mform->addElement('text', 'displayname', get_string('displayname', 'report_customsql'), array('size' => '40'));
     $mform->addRule('displayname', get_string('displaynamerequired', 'report_customsql'), 'required', null, 'client');
     $mform->setType('displayname', PARAM_MULTILANG);
     $mform->addElement('htmleditor', 'description', get_string('description', 'report_customsql'), array('rows' => '15'));
     $mform->setType('description', PARAM_RAW);
     $mform->addElement('textarea', 'querysql', get_string('querysql', 'report_customsql'), 'rows="35" cols="60"');
     $mform->addRule('querysql', get_string('querysqlrequried', 'report_customsql'), 'required', null, 'client');
     $mform->setType('querysql', PARAM_RAW);
     $mform->addElement('static', 'note', get_string('note', 'report_customsql'), get_string('querynote', 'report_customsql', $CFG->wwwroot));
     $mform->addElement('select', 'capability', get_string('whocanaccess', 'report_customsql'), report_customsql_capability_options());
     $mform->addElement('select', 'runable', get_string('runable', 'report_customsql'), report_customsql_runable_options());
     $mform->addElement('checkbox', 'singlerow', get_string('typeofresult', 'report_customsql'), get_string('onerow', 'report_customsql'));
     $mform->disabledIf('singlerow', 'runable', 'eq', 'manual');
     $this->add_action_buttons();
 }
 public function test_report_customsql_runable_options()
 {
     $options = array('manual' => get_string('manual', 'report_customsql'), 'daily' => get_string('automaticallydaily', 'report_customsql'), 'weekly' => get_string('automaticallyweekly', 'report_customsql'), 'monthly' => get_string('automaticallymonthly', 'report_customsql'));
     $this->assertEquals($options, report_customsql_runable_options());
 }
 */
require_once dirname(__FILE__) . '/../../../config.php';
require_once dirname(__FILE__) . '/locallib.php';
require_once $CFG->libdir . '/adminlib.php';
$id = required_param('id', PARAM_INT);
$report = get_record('report_customsql_queries', 'id', $id);
if (!$report) {
    print_error('invalidreportid', 'report_customsql', report_customsql_url('index.php'), $id);
}
require_login();
$context = get_context_instance(CONTEXT_SYSTEM);
require_capability('report/customsql:definequeries', $context);
if (optional_param('confirm', false, PARAM_BOOL)) {
    $ok = delete_records('report_customsql_queries', 'id', $id);
    if (!$ok) {
        print_error('errordeletingreport', 'report_customsql', report_customsql_url('index.php'));
    }
    report_customsql_log_delete($id);
    redirect(report_customsql_url('index.php'));
}
$runnableoptions = report_customsql_runable_options();
// Start the page.
admin_externalpage_setup('reportcustomsql');
admin_externalpage_print_header();
print_heading(get_string('deleteareyousure', 'report_customsql'));
echo '<p>' . get_string('displaynamex', 'report_customsql', '<b>' . format_string($report->displayname) . '</b>') . '</p>';
echo '<p>' . get_string('querysql', 'report_customsql') . '</p>';
echo '<pre>' . htmlspecialchars($report->querysql) . '</pre>';
echo '<p>' . get_string('runablex', 'report_customsql', $runnableoptions[$report->runable]) . '</p>';
notice_yesno(get_string('deleteareyousure', 'report_customsql'), report_customsql_url('delete.php'), report_customsql_url('index.php'), array('id' => $id, 'confirm' => 1), null, 'post', 'get');
admin_externalpage_print_footer();