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_capability_options()
 {
     $capoptions = array('report/customsql:view' => get_string('anyonewhocanveiwthisreport', 'report_customsql'), 'moodle/site:viewreports' => get_string('userswhocanviewsitereports', 'report_customsql'), 'moodle/site:config' => get_string('userswhocanconfig', 'report_customsql'));
     $this->assertEquals($capoptions, report_customsql_capability_options());
 }
function report_customsql_print_reports($reports, $courseid = null)
{
    global $CFG, $OUTPUT;
    // DWE Edited By David Elliott on 27-4-2015
    // to view assigned reports to teachers
    // check admin or not - start
    if (is_siteadmin()) {
        $context = context_system::instance();
        $canedit = has_capability('report/customsql:definequeries', $context);
        $capabilities = report_customsql_capability_options();
    } else {
        // Set context for teachers
        $context = get_context_instance(CONTEXT_COURSE, $courseid);
        $canedit = '';
        $capabilities = '';
    }
    // End
    foreach ($reports as $report) {
        if (!empty($report->capability) && !has_capability($report->capability, $context)) {
            continue;
        }
        echo html_writer::start_tag('p');
        // DWE - David Elliott - passing course id with the url for checking context of the teacher - 27-4-2015
        echo html_writer::tag('a', format_string($report->displayname), array('href' => report_customsql_url('view.php?id=' . $report->id . '&cid=' . $courseid))) . ' ' . report_customsql_time_note($report, 'span');
        if ($canedit) {
            $imgedit = html_writer::tag('img', '', array('src' => $OUTPUT->pix_url('t/edit'), 'class' => 'iconsmall', 'alt' => get_string('edit')));
            $imgdelete = html_writer::tag('img', '', array('src' => $OUTPUT->pix_url('t/delete'), 'class' => 'iconsmall', 'alt' => get_string('delete')));
            echo ' ' . html_writer::tag('span', get_string('availableto', 'report_customsql', $capabilities[$report->capability]), array('class' => 'admin_note')) . ' ' . html_writer::tag('a', $imgedit, array('title' => get_string('editthisreport', 'report_customsql'), 'href' => report_customsql_url('edit.php?id=' . $report->id))) . ' ' . html_writer::tag('a', $imgdelete, array('title' => get_string('deletethisreport', 'report_customsql'), 'href' => report_customsql_url('delete.php?id=' . $report->id)));
        }
        echo html_writer::end_tag('p');
        echo "\n";
    }
}
/**
 * display the rports
 * @param object $reports, the result of DB query
 * @param string $type, type of report (manual, daily, weekly or monthly)
 */
function report_customsql_print_reports_for($reports, $type)
{
    global $OUTPUT;
    if (empty($reports)) {
        return;
    }
    if (!empty($type)) {
        $help = html_writer::tag('span', $OUTPUT->help_icon($type . 'header', 'report_customsql'));
        echo $OUTPUT->heading(get_string($type . 'header', 'report_customsql') . $help, 3);
    }
    $context = context_system::instance();
    $canedit = has_capability('report/customsql:definequeries', $context);
    $capabilities = report_customsql_capability_options();
    foreach ($reports as $report) {
        if (!empty($report->capability) && !has_capability($report->capability, $context)) {
            continue;
        }
        echo html_writer::start_tag('p');
        echo html_writer::tag('a', format_string($report->displayname), array('href' => report_customsql_url('view.php?id=' . $report->id))) . ' ' . report_customsql_time_note($report, 'span');
        if ($canedit) {
            $imgedit = html_writer::tag('img', '', array('src' => $OUTPUT->pix_url('t/edit'), 'class' => 'iconsmall', 'alt' => get_string('edit')));
            $imgdelete = html_writer::tag('img', '', array('src' => $OUTPUT->pix_url('t/delete'), 'class' => 'iconsmall', 'alt' => get_string('delete')));
            echo ' ' . html_writer::tag('span', get_string('availableto', 'report_customsql', $capabilities[$report->capability]), array('class' => 'admin_note')) . ' ' . html_writer::tag('a', $imgedit, array('title' => get_string('editthisreport', 'report_customsql'), 'href' => report_customsql_url('edit.php?id=' . $report->id))) . ' ' . html_writer::tag('a', $imgdelete, array('title' => get_string('deletethisreport', 'report_customsql'), 'href' => report_customsql_url('delete.php?id=' . $report->id)));
        }
        echo html_writer::end_tag('p');
        echo "\n";
    }
}
function report_customsql_print_reports($reports)
{
    global $CFG;
    $context = get_context_instance(CONTEXT_SYSTEM);
    $canedit = has_capability('report/customsql:definequeries', $context);
    $capabilities = report_customsql_capability_options();
    foreach ($reports as $report) {
        if (!empty($report->capability) && !has_capability($report->capability, $context)) {
            continue;
        }
        echo '<p><span class="reporttitle" style="background-color:HoneyDew;font-size:1.3em;"><a href="' . report_customsql_url('view.php?id=' . $report->id) . '">' . format_string($report->displayname) . '</a></span> ';
        if ($canedit) {
            echo ' <a title="' . get_string('editthisreport', 'report_customsql') . '" href="' . report_customsql_url('edit.php?id=' . $report->id) . '"><img src="' . $CFG->pixpath . '/t/edit.gif" class="iconsmall" alt="' . get_string('edit') . '" /></a>';
            echo ' <a title="' . get_string('deletethisreport', 'report_customsql') . '" href="' . report_customsql_url('delete.php?id=' . $report->id) . '"><img src="' . $CFG->pixpath . '/t/delete.gif" class="iconsmall" alt="' . get_string('delete') . '" /></a>';
            echo ' <br/><span class="admin_note">' . get_string('availableto', 'report_customsql', $capabilities[$report->capability]) . '</span>';
        }
        echo '<br/>' . report_customsql_time_note($report, 'span');
        echo "</p>\n";
    }
}