function form_process_data(&$cform) {
     global $DB;
     if ($this->form) {
         $data = $cform->get_data();
         $components = cr_unserialize($this->config->components);
         $components['timeline']['config'] = $data;
         $this->config->components = cr_serialize($components);
         $DB->update_record('block_cobalt_reports', $this->config);
     }
 }
 function form_process_data($cform)
 {
     if ($this->form) {
         $data = $cform->get_data();
         $components = cr_unserialize($this->config->components);
         $components['timeline']['config'] = $data;
         $this->config->components = cr_serialize($components);
         update_record('block_configurable_reports_report', $this->config);
     }
 }
 function form_process_data(&$cform)
 {
     if ($this->form) {
         $data = $cform->get_data();
         // cr_serialize() will add slashes
         $components = cr_unserialize($this->config->components);
         $components['columns']['config'] = $data;
         $this->config->components = cr_serialize($components);
         $DB->update_record('report_configreports', $this->config);
     }
 }
 function form_process_data(&$cform)
 {
     global $DB;
     if ($this->form) {
         $data = $cform->get_data();
         // cr_serialize() will add slashes
         $components = cr_unserialize($this->config->components);
         $components['template']['config'] = $data;
         $this->config->components = cr_serialize($components);
         $DB->update_record('block_configurable_reports', $this->config);
     }
 }
 function form_process_data($cform)
 {
     if ($this->form) {
         $data = $cform->get_data();
         // cr_serialize() will add slashes
         $data = stripslashes_recursive($data);
         $components = cr_unserialize($this->config->components);
         $components['columns']['config'] = $data;
         $this->config->components = cr_serialize($components);
         update_record('block_configurable_reports_report', $this->config);
     }
 }
Esempio n. 6
0
                } else {
                    redirect(new moodle_url('/blocks/configurable_reports/editcomp.php', array('id' => $id, 'comp' => $comp)));
                    exit;
                }
            }
        }
    }
} else {
    $allelements = cr_unserialize($report->components);
    $uniqueid = random_string(15);
    while (strpos($report->components, $uniqueid) !== false) {
        $uniqueid = random_string(15);
    }
    $cdata = array('id' => $uniqueid, 'formdata' => new stdclass(), 'pluginname' => $pname, 'pluginfullname' => $pluginclass->fullname, 'summary' => $pluginclass->summary(new stdclass()));
    $allelements[$comp]['elements'][] = $cdata;
    $report->components = cr_serialize($allelements);
    if (!$DB->update_record('block_configurable_reports', $report)) {
        print_error('errorsaving');
    } else {
        redirect(new moodle_url('/blocks/configurable_reports/editcomp.php', array('id' => $id, 'comp' => $comp)));
        exit;
    }
}
$title = format_string($report->name) . ' ' . get_string($comp, 'block_configurable_reports');
$navlinks = array();
$navlinks[] = array('name' => get_string('managereports', 'block_configurable_reports'), 'link' => $CFG->wwwroot . '/blocks/configurable_reports/managereport.php?courseid=' . $report->courseid, 'type' => 'title');
$navlinks[] = array('name' => $title, 'link' => $CFG->wwwroot . '/blocks/configurable_reports/editcomp.php?id=' . $id . '&comp=' . $comp, 'type' => 'title');
$navlinks[] = array('name' => get_string($pname, 'block_configurable_reports'), 'link' => null, 'type' => 'title');
$navigation = build_navigation($navlinks);
$PAGE->set_title($title);
$PAGE->set_heading($title);
    function execute($data, $row, $user, $courseid, $starttime = 0, $endtime = 0) {
        global $DB, $CFG;

        if (!$report = $DB->get_record('block_cobalt_reports', array('id' => $data->reportid)))
            print_error('reportdoesnotexists', 'block_cobalt_reports');

        require_once($CFG->dirroot . '/blocks/cobalt_reports/report.class.php');
        require_once($CFG->dirroot . '/blocks/cobalt_reports/reports/' . $report->type . '/report.class.php');

        if (!isset($this->reportcache[$row->id])) {

            $reportclassname = 'report_' . $report->type;
            $reportclass = new $reportclassname($report);

            // Delete conditions - TODO
            // Add new condition
            // User report -> New condition "User courses"
            // Course report -> New condition "Course users"
            if ($this->report->type == 'users') {
                $reportclass->currentuser = $row;
                $reportclass->starttime = $starttime;
                $reportclass->endtime = $endtime;

                if ($report->type == 'courses') {
                    $components = cr_unserialize($reportclass->config->components);
                    $newplugin = array('pluginname' => 'currentusercourses', 'fullname' => 'currentusercourses', 'formdata' => new stdclass);

                    $components['conditions']['elements'][] = $newplugin;
                    $components['conditions']['config']->conditionexpr = $this->fix_condition_expr($components['conditions']['config']->conditionexpr, count($components['conditions']['elements']));
                    $reportclass->config->components = cr_serialize($components);
                }
            } else if ($this->report->type == 'courses') {
                $reportclass->currentcourseid = $row->id;
                $reportclass->starttime = $starttime;
                $reportclass->endtime = $endtime;

                if ($report->type == 'users') {
                    $components = cr_unserialize($reportclass->config->components);

                    $roles = $DB->get_records('role');
                    $rolesid = array_keys($roles);

                    $formdata = new stdclass;
                    $formdata->roles = $rolesid;
                    $newplugin = array('pluginname' => 'usersincurrentcourse', 'fullname' => 'usersincurrentcourse', 'formdata' => $formdata);

                    $components['conditions']['elements'][] = $newplugin;
                    if (!empty($components['conditions']['config'])) {
                        $components['conditions']['config']->conditionexpr = $this->fix_condition_expr($components['conditions']['config']->conditionexpr, count($components['conditions']['elements']));
                    }
                    $reportclass->config->components = cr_serialize($components);
                }
            } else if ($this->report->type == 'timeline') {
                $reportclass->starttime = $row->starttime;
                $reportclass->endtime = $row->endtime;
            } else if ($this->report->type == 'categories') {
                $reportclass->starttime = $starttime;
                $reportclass->endtime = $endtime;

                if ($report->type == 'courses') {
                    $components = cr_unserialize($reportclass->config->components);

                    $formdata = new stdclass;
                    $formdata->categoryid = $row->id;
                    $newplugin = array('pluginname' => 'coursecategory', 'fullname' => 'coursecategory', 'formdata' => $formdata);

                    $components['conditions']['elements'][] = $newplugin;
                    $components['conditions']['config']->conditionexpr = $this->fix_condition_expr($components['conditions']['config']->conditionexpr, count($components['conditions']['elements']));
                    $reportclass->config->components = cr_serialize($components);
                }
            }

            $reportclass->create_report();
            $this->reportcache[$row->id] = $reportclass->finalreport->table->data;
        }

        if (!empty($this->reportcache[$row->id])) {
            $subtable = array();
            foreach ($this->reportcache[$row->id] as $r) {
                $subtable[] = $r[$data->column];
            }
            return $subtable;
        }

        return '';
    }
 function form_set_data($cform)
 {
     if ($this->form) {
         $fdata = new stdclass();
         $components = cr_unserialize($this->config->components);
         //print_r($components);exit;
         $conditionsconfig = isset($components['permissions']['config']) ? $components['permissions']['config'] : new stdclass();
         if (!isset($conditionsconfig->conditionexpr)) {
             $fdata->conditionexpr = '';
             $conditionsconfig->conditionexpr = '';
         }
         $conditionsconfig->conditionexpr = $this->add_missing_conditions($conditionsconfig->conditionexpr);
         $fdata->conditionexpr = $conditionsconfig->conditionexpr;
         $components['permissions']['config']->conditionexpr = $fdata->conditionexpr;
         $this->config->components = cr_serialize($components);
         update_record('block_configurable_reports_report', $this->config);
         $cform->set_data($fdata);
     }
 }
    function form_set_data(&$cform) {
        global $DB;

        if ($this->form) {
            $fdata = new stdclass;
            $components = cr_unserialize($this->config->components);
            //print_r($components);exit;
            $conditionsconfig = (isset($components['permissions']['config'])) ? $components['permissions']['config'] : new stdclass;

            if (!isset($conditionsconfig->conditionexpr)) {
                $fdata->conditionexpr = '';
                $conditionsconfig->conditionexpr = '';
            }
            $conditionsconfig->conditionexpr = $this->add_missing_conditions($conditionsconfig->conditionexpr);
            $fdata->conditionexpr = $conditionsconfig->conditionexpr;

            if (empty($components['permissions'])) {
                $components['permissions'] = array();
            }

            if (!array_key_exists('config', $components['permissions'])) {
                $components['permissions']['config'] = new StdClass;
            }

            $components['permissions']['config']->conditionexpr = $fdata->conditionexpr;
            $this->config->components = cr_serialize($components);
            $DB->update_record('block_cobalt_reports', $this->config);


            $cform->set_data($fdata);
        }
    }
Esempio n. 10
0
function cr_import_xml($xml, $course)
{
    global $CFG, $DB, $USER;
    require_once $CFG->dirroot . '/lib/xmlize.php';
    $data = xmlize($xml, 1, 'UTF-8');
    if (isset($data['report']['@']['version'])) {
        $newreport = new stdclass();
        foreach ($data['report']['#'] as $key => $val) {
            if ($key == 'components') {
                $val[0]['#'] = base64_decode(trim($val[0]['#']));
                // fix url_encode " and ' when importing SQL queries
                $temp_components = cr_unserialize($val[0]['#']);
                $temp_components['customsql']['config']->querysql = str_replace("\\'", "'", $temp_components['customsql']['config']->querysql);
                $temp_components['customsql']['config']->querysql = str_replace('\\"', '"', $temp_components['customsql']['config']->querysql);
                $val[0]['#'] = cr_serialize($temp_components);
            }
            $newreport->{$key} = trim($val[0]['#']);
        }
        $newreport->courseid = $course->id;
        $newreport->ownerid = $USER->id;
        $newreport->name .= " (" . userdate(time()) . ")";
        if (!$DB->insert_record('block_configurable_reports', $newreport)) {
            return false;
        }
        return true;
    }
    return false;
}
 function form_set_data(&$cform)
 {
     global $DB;
     if ($this->form) {
         $fdata = new stdclass();
         $components = cr_unserialize($this->config->components);
         //print_r($components);exit;
         $conditionsconfig = isset($components['conditions']['config']) ? $components['conditions']['config'] : new stdclass();
         if (!isset($conditionsconfig->conditionexpr)) {
             $conditionsconfig->conditionexpr = '';
             $conditionsconfig->conditionexpr = '';
         }
         $conditionsconfig->conditionexpr = $this->add_missing_conditions($conditionsconfig->conditionexpr);
         $fdata->conditionexpr = $conditionsconfig->conditionexpr;
         $components['conditions']['config']->conditionexpr = $fdata->conditionexpr;
         $this->config->components = cr_serialize($components);
         $DB->update_record('report_configreports', $this->config);
         $cform->set_data($fdata);
     }
 }