Exemple #1
0
 public function __construct($params = null)
 {
     parent::__construct($params);
     //URL parameter specifies the report instance
     $this->report_shortname = $this->required_param('report');
     //convert shortname to report instance
     $this->report_instance = php_report::get_default_instance($this->report_shortname);
 }
Exemple #2
0
 /**
  * Constructor
  * @param  string   $name      the name of the filter instance
  * @param  string   $label     the label of the filter instance
  * @param  boolean  $advanced  advanced form element flag
  * @param  string   $field     user table filed name
  * @param  array    $options   select options
  */
 public function __construct($uniqueid, $alias, $name, $label, $advanced, $field, $options = array())
 {
     parent::generalized_filter_type($uniqueid, $alias, $name, $label, $advanced, !empty($options['help']) ? $options['help'] : array('simpleselect', $label, 'filters'));
     $this->_field = $field;
     if (!isset($options['report'])) {
         print_error('autocomplete_noreport', 'local_eliscore');
     }
     $this->_parent_report = $options['report'];
     $this->parent_report_instance = php_report::get_default_instance($options['report']);
     if (isset($options['ui']) && in_array($options['ui'], array('inline', 'popup'), true)) {
         $this->_ui = $options['ui'];
     }
     if (!empty($options['restriction_sql']) && is_string($options['restriction_sql'])) {
         $this->_restriction_sql = $options['restriction_sql'];
     }
     if (!empty($options['popup_title'])) {
         $this->_popup_title = $options['popup_title'];
     }
     if (isset($options['label_template'])) {
         $this->_label_template = $options['label_template'];
     } else {
         $this->_label_template = !empty($this->_fields[0]) ? $this->_fields[0] : '';
     }
     if (isset($options['selection_enabled']) && is_bool($options['selection_enabled'])) {
         $this->_selection_enabled = $options['selection_enabled'];
     }
     if (!empty($options['defaults']['id'])) {
         $this->_default_id = $options['defaults']['id'];
     }
     if (!empty($options['defaults']['label'])) {
         $this->_default_label = $options['defaults']['label'];
     }
     if (!empty($options['required'])) {
         $this->_required = $options['required'];
     }
     $this->_useid = $field == 'id';
     $this->load_options($options);
 }
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    elis
 * @subpackage curriculummanagement
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/blocks/php_report/lib/filtering.php';
//report instance id can be a block instance id
//or a general report shortname
$id = required_param('id', PARAM_CLEAN);
//selected export format
$format = required_param('format', PARAM_CLEAN);
//load filter classes
php_report_filtering_require_dependencies();
$report = php_report::get_default_instance($id);
//permissions checking
if ($report->can_view_report()) {
    //NOTE: this is fast because it will not populate filter values
    $report->init_all($id);
    //require any necessary report-specific dependencies
    $report->require_dependencies();
    //make sure we have enough resources to export our report
    php_report::allocate_extra_resources();
    //initiate download using sql query without paging
    $report->download($format, $report->get_complete_sql_query(false));
}
 /**
  * API call for exporting a report execution
  *
  * @param   string    $shortname       Shortname of the report to be executed (should be
  *                                     one of the folder names found in the "instances" directory)
  * @param   string    $format          The export format (one of the EXPORT_FORMAT_... constants)
  * @param   string    $filename        Name of the file to write to (including extension)
  * @param   stdClass  $parameter_data  Submitted parameter form data (in format directly returned by get_data)
  * @param   int|NULL  $userid          Id of the Moodle user who this report is being
  *                                     for
  * @param   int       $execution_mode  The mode in which this report is being executed
  *
  * @return  boolean                    true on success, otherwise false
  */
 static function export_default_instance($shortname, $format, $filename, $parameter_data, $userid = NULL, $execution_mode = php_report::EXECUTION_MODE_INTERACTIVE)
 {
     //allocate some extra resources
     php_report::allocate_extra_resources();
     //get a default instance
     $report_instance = php_report::get_default_instance($shortname, $userid, $execution_mode);
     if ($report_instance == false) {
         //user no longer has access, so signal failure
         return false;
     }
     $allowable_formats = $report_instance->get_export_formats();
     if (!in_array($format, $allowable_formats)) {
         //specified format is not allowed
         return;
     }
     //make sure all dependencies are loaded
     $report_instance->require_dependencies();
     //initialize all necessary data
     $report_instance->init_all($shortname, $parameter_data);
     //run the export
     $report_instance->download($format, $report_instance->get_complete_sql_query(FALSE), $filename);
     return true;
 }
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
require_once dirname(__FILE__) . '/../../config.php';
require_once $CFG->dirroot . '/blocks/php_report/parameter_form.class.php';
require_once $CFG->dirroot . '/curriculum/lib/filtering/lib.php';
require_once $CFG->libdir . '/formslib.php';
require_once $CFG->dirroot . '/blocks/php_report/lib/filtering.php';
//report shortname
$report_shortname = required_param('id', PARAM_CLEAN);
//optional action url for form
$action = optional_param('url', null);
//require dependencies for filters
php_report_filtering_require_dependencies();
//key report data
$instance = php_report::get_default_instance($report_shortname);
//NOTE: this is slow because it populates filter values
$filters = $instance->get_filters();
//obtain any necessary information regarding secondary filterings
$dynamic_report_filter_url = $CFG->wwwroot . '/blocks/php_report/dynamicreport.php?id=' . $report_shortname;
$secondary_filterings = $instance->get_secondary_filterings($dynamic_report_filter_url, $report_shortname, $report_shortname);
//when set, show the cancel button
$showcancel = optional_param('showcancel', 0, PARAM_INT);
//create the form, whose contents depend on on the current report's available filters
if (!empty($filters)) {
    //report has filters
    $dynamic_report_filter_url = $CFG->wwwroot . '/blocks/php_report/dynamicreport.php?id=' . $report_shortname;
    $filter_object = new php_report_default_capable_filtering($filters, $dynamic_report_filter_url, null, $report_shortname, $report_shortname, $secondary_filterings);
    $params = array('filterobject' => $filter_object, 'showcancel' => $showcancel);
    $parameter_form = new parameter_form($action, $params);
} else {
Exemple #6
0
 function definition()
 {
     require_js_files();
     $mform =& $this->_form;
     $page = $this->_customdata;
     $workflow = $page->workflow;
     $mform->addElement('hidden', '_wfid', $workflow->id);
     $mform->setType('_wfid', PARAM_INT);
     $mform->addElement('hidden', '_step', scheduling_workflow::STEP_FORMAT);
     $mform->setType('_step', PARAM_TEXT);
     $mform->addElement('hidden', 'action', 'save');
     $mform->setType('action', PARAM_TEXT);
     $mform->addElement('html', '<h2>' . htmlspecialchars(get_string('format_description', 'local_elisreports')) . '</h2>');
     $radioarray = array();
     //obtain the actual report instance so we can check its export formats
     $data = unserialize($workflow->data);
     $report_shortname = $data['report'];
     $report_instance = php_report::get_default_instance($report_shortname, NULL, php_report::EXECUTION_MODE_SCHEDULED);
     //global list of all available export formats
     $allowable_export_formats = php_report::get_allowable_export_formats();
     //export formats supported by the report we are scheduling
     $export_formats = $report_instance->get_export_formats();
     //add an export option for each applicable format
     if ($report_instance->can_view_report()) {
         foreach ($allowable_export_formats as $allowable_export_format) {
             if (in_array($allowable_export_format, $export_formats)) {
                 $radioarray[] = $mform->createElement('radio', 'format', '', get_string($allowable_export_format, 'local_elisreports'), $allowable_export_format);
             }
         }
     }
     $mform->addGroup($radioarray, 'format', get_string('format'), '', false);
     $mform->addRule('format', get_string('required_field', 'local_elisreports', get_string('format')), 'required', null, 'client');
     $mform->setDefault('format', 'csv');
     workflowpage::add_navigation_buttons($mform, scheduling_workflow::STEP_PARAMETERS);
 }
 /**
  * Get the block content
  *
  * @return  object  content items and icons arrays of what is to be displayed in this block
  */
 function get_content()
 {
     global $CFG, $COURSE, $USER;
     if (!isloggedin() || isguestuser()) {
         //user is not properly logged in
         return '';
     }
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     $siteContext = get_context_instance(CONTEXT_SYSTEM);
     if ($COURSE->id == SITEID) {
         $context = $siteContext;
     } else {
         $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     }
     // make sure the user has the required role
     if (!empty($this->config->role)) {
         $sql = "SELECT r.id, r.name\n                      FROM {$CFG->prefix}role r\n                      JOIN {$CFG->prefix}role_assignments ra ON ra.roleid = r.id\n                      JOIN {$CFG->prefix}user u ON u.id = ra.userid\n                     WHERE ra.contextid = {$context->id}\n                           AND u.id = {$USER->id}\n                           AND ra.roleid = {$this->config->role}";
         if (!record_exists_sql($sql)) {
             $this->content->items = array();
             $this->content->icons = array();
             return $this->content;
         }
     }
     $items = array();
     $icons = array();
     $categories = array();
     if (isset($this->config->reports)) {
         // Require the php_report class
         require_once $CFG->dirroot . '/blocks/php_report/php_report_base.php';
         $params = array();
         // set the parameters that we can get from the environment
         // (currently only the course ID)
         if ($this->instance->pagetype == PAGE_COURSE_VIEW) {
             if ($this->instance->pageid != SITEID) {
                 $params['courseid'] = $this->instance->pageid;
             }
         }
         // TODO: figure out capability for showing scheduling icon
         $isediting = isediting($this->instance->pageid);
         // && has_capability('block/php_report:manageactivities', $context);
         $count = 0;
         // create links to the reports
         foreach ($this->config->reports as $report) {
             if (isset(block_elis_reports::$reports_map[$report->id])) {
                 $report->id = block_elis_reports::$reports_map[$report->id];
             }
             $report_instance = php_report::get_default_instance($report->id);
             //make sure the report shortname is valid
             if ($report_instance !== FALSE) {
                 if ($report_instance->is_available() && $report_instance->can_view_report()) {
                     $category = $report_instance->get_category();
                     if (!isset($categories[$category])) {
                         $categories[$category] = array();
                     }
                     $name = $report_instance->get_display_name();
                     $report_link = new moodle_url($CFG->wwwroot . '/blocks/php_report/render_report_page.php', $params + $report->params + array('report' => $report->id));
                     $categories[$category][$count]['item'] = '<a href="' . $report_link->out() . '">' . $name . '</a>';
                     //create an instance specifically for testing scheduling permissions
                     $test_scheduling_permissions_instance = php_report::get_default_instance($report->id, NULL, php_report::EXECUTION_MODE_SCHEDULED);
                     //get_default instance will return FALSE if we are not allowed access to scheduling
                     $can_schedule = $test_scheduling_permissions_instance !== FALSE;
                     if ($isediting && $can_schedule) {
                         // TODO: add permissions to this url
                         $link = new moodle_url('/blocks/php_report/schedule.php?report=' . $report->id . '&action=listinstancejobs&createifnone=1');
                         $image_link = '<a href="#" alt=\'' . get_string('schedule_this_report', 'block_php_report') . '\'  title=\'' . get_string('schedule_this_report', 'block_php_report') . '\' onclick="openpopup(\'' . $link->out() . '\', \'php_report_param_popup\', \'menubar=0,location=0,scrollbars,status,resizable,width=1600,height=600\');return false;">
                                         &nbsp;<img src="' . $CFG->wwwroot . '/blocks/php_report/pix/schedule.png"/>
                                         </a>';
                         $categories[$category][$count]['sched_icon'] = $image_link;
                     }
                     $categories[$category][$count]['icon'] = '<img src="' . $CFG->wwwroot . '/blocks/elis_reports/pix/report.png" />';
                     $count++;
                 }
             }
         }
         // Generates items and icons array
         $this->generate_content($categories, $this->content->items, $this->content->icons);
     }
     return $this->content;
 }
Exemple #8
0
/**
 * Specifies the tree entries used to represent links to PHP reports
 *
 * @return  menuitem array  List of menu items to add (including report categories
 *                          but excluding the top-level report entry)
 */
function block_elisadmin_get_report_tree_items()
{
    global $CFG, $DB;
    // If the reports block is not installed, no entries will be displayed.
    if (file_exists($CFG->dirroot . '/local/elisreports/version.php') !== true) {
        return array();
    }
    //get the category-level links
    $items = block_elisadmin_get_report_category_items();
    //path to library file for scheduling classes
    $schedulelib_path = $CFG->dirroot . '/local/elisreports/lib/schedulelib.php';
    //check to make sure the required functionality is there
    //todo: remove this check when it's safe to do so
    if (file_exists($schedulelib_path)) {
        //reporting base class
        require_once $schedulelib_path;
        //schedule report entry
        //make sure we are using a "clean" page to check global permissions
        $test_permissions_page = new scheduling_page(array());
        //make sure we can access the report listing
        if ($test_permissions_page->can_do('list')) {
            //create a direct url to the list page
            $schedule_reports_page = new menuitempage('url_page', 'lib/menuitem.class.php', $CFG->wwwroot . '/local/elisreports/schedule.php?action=list');
            //convert to a menu item
            $css_class = block_elisadmin_get_item_css_class('schedulereports');
            $schedule_reports_item = new menuitem('schedule_reports', $schedule_reports_page, 'rept', get_string('schedule_reports', 'local_elisreports'), $css_class, '', FALSE, 'rept');
            //merge in with the current result
            $items = array_merge(array($schedule_reports_item), $items);
        }
    }
    //for storing the items bucketed by category
    $buckets = array();
    //look for all report instances
    if (file_exists($CFG->dirroot . '/local/elisreports/instances') && ($handle = opendir($CFG->dirroot . '/local/elisreports/instances'))) {
        while (FALSE !== ($report_shortname = readdir($handle))) {
            //grab a test instance of the report in question
            $default_instance = php_report::get_default_instance($report_shortname);
            //make sure the report shortname is valid
            if ($default_instance !== FALSE) {
                //make sure the current user can access this report
                if ($default_instance->is_available() && $default_instance->can_view_report()) {
                    //user-friendly report name
                    $displayname = $default_instance->get_display_name();
                    //add the item to the necessary bucket
                    $item_category = $default_instance->get_category();
                    if (!isset($buckets[$item_category])) {
                        $buckets[$item_category] = array();
                    }
                    //obtain the page specific to this report
                    $report_page_classpath = $CFG->dirroot . '/local/elisreports/lib/reportpage.class.php';
                    $report_page_params = array('report' => $report_shortname);
                    $page = new generic_menuitempage('report_page', $report_page_classpath, $report_page_params);
                    //retrieve the actual menuitem
                    $page_css_class = block_elisadmin_get_item_css_class('reportinstance');
                    $category_path = 'rept/' . $item_category;
                    $buckets[$item_category][$displayname] = new menuitem($report_shortname, $page, $item_category, $displayname, $page_css_class, '', FALSE, $category_path);
                }
            }
        }
    }
    //retrieve the items representing the reports themselves from the bucketed listings
    $report_instance_items = block_elisadmin_get_report_bucket_items($buckets);
    //merge the flat listings of category items and report instance items
    $items = array_merge($items, $report_instance_items);
    //return the flat listing
    return $items;
}
/**
 * Obtains a listing of report display names, grouped by category
 *
 * @param   boolean       $require_exportable  If true, only include reports that are considered to be exportable
 *                                             in the context of scheduling
 * @param  int|NULL       $userid              Id of the Moodle user who this report is being
 *                                             for
 * @param  int            $execution_mode      The mode in which this report is being executed
 *
 * @return  string array                       Mapping of category shortname to mappings of
 *                                             report shortnames to display names (category entries
 *                                             will exist but be empty if no reports are in that category)
 */
function block_php_report_get_names_by_category($require_exportable = false, $userid = NULL, $execution_mode = php_report::EXECUTION_MODE_INTERACTIVE)
{
    global $CFG;
    $category_members = array();
    //get a listing of the different categories
    $categories = block_php_report_get_category_mapping();
    //initialize a bucket to store a category's reports where applicable
    foreach ($categories as $category_key => $category_display) {
        $category_members[$category_key] = array();
    }
    //go through the directories
    if ($handle = opendir($CFG->dirroot . '/blocks/php_report/instances')) {
        while (false !== ($report_shortname = readdir($handle))) {
            //get the report instance (this inherently checks permissions and report availability)
            if ($instance = php_report::get_default_instance($report_shortname, $userid, $execution_mode)) {
                //determine if the export action is available in the context of scheduling
                $export_available = true;
                //check permissions and make sure access is not explicitly disallowed in the current execution mode
                if (!$instance->can_view_report()) {
                    $export_available = false;
                }
                //make sure there is at least one available export format
                $export_formats = $instance->get_export_formats();
                if (count($export_formats) == 0) {
                    $export_available = false;
                }
                if (!$require_exportable || $export_available) {
                    $category_shortname = $instance->get_category();
                    $report_shortname = $instance->get_report_shortname();
                    $category_members[$category_shortname][$report_shortname] = $instance->get_display_name();
                }
            }
        }
        //sort reports by display name within each category
        foreach ($category_members as $category_shortname => $bucket) {
            sort($bucket);
            $category_members[$category_shortname];
        }
    }
    return $category_members;
}
Exemple #10
0
 * @package    local_eliscore
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */
require_once dirname(__FILE__) . '/../../../../config.php';
require_once $CFG->dirroot . '/local/elisreports/php_report_base.php';
require_once dirname(__FILE__) . '/autocompletelib.php';
//require a report and a filter
$requested_report = required_param('report', PARAM_CLEAN);
$requested_filter = required_param('filter', PARAM_CLEAN);
$q = trim(optional_param('q', '', PARAM_CLEAN));
$mode = optional_param('mode', 'ui', PARAM_CLEAN);
//instantiate the report
$report = php_report::get_default_instance($requested_report);
if (empty($report)) {
    echo get_string('autocomplete_noreport', 'local_eliscore'), ' (Error0)';
    die;
}
//authenticate ability to view this report
if (!$report->is_available() || !$report->can_view_report()) {
    echo get_string('autocomplete_reportunavail', 'local_eliscore'), ' (Error1)';
    die;
}
//get the requested filter
$filters = $report->get_filters(false);
$found_filter = null;
foreach ($filters as $i => $filter) {
    if ($filter->uniqueid === $requested_filter) {
        $found_filter = $filter;
Exemple #11
0
 /**
  * Renders a header entry for when viewing the scheduled instances of
  * a particular report
  *
  * @param  $have_jobs  true if the current report has at leeast one
  *                     scheduled job instance, otherwise false
  *
  * @uses   $OUTPUT
  */
 function render_listinstancejobs_header($have_jobs, $userid = NULL, $execmode = php_report::EXECUTION_MODE_INTERACTIVE)
 {
     global $OUTPUT;
     //get the current report shortname
     $report = $this->required_param('report', PARAM_ALPHAEXT);
     //get the current report's display name
     $instance = php_report::get_default_instance($report, $userid, $execmode);
     $display_name = $instance->get_display_name();
     //determine the appropriate display strings
     $report_text = '';
     $instructions_text = '';
     if ($have_jobs) {
         $report_text = get_string('listinstancejobs_heading_report', 'local_elisreports', $display_name);
         $instructions_text = get_string('listinstancejobs_heading_instructions', 'local_elisreports');
     } else {
         $report_text = get_string('listinstancejobs_heading_report_nojobs', 'local_elisreports', $display_name);
         $instructions_text = get_string('listinstancejobs_heading_instructions_nojobs', 'local_elisreports');
     }
     //display the appropriate display strings
     notify($report_text, 'php_report_bold_header', 'left');
     notify($instructions_text, 'php_report_italic_header', 'left');
     echo $OUTPUT->spacer();
 }