function definition()
 {
     $mform =& $this->_form;
     $mform->addElement('header', 'general', get_string('message', 'message'));
     //$mform->addElement('htmleditor', 'messagebody', get_string('messagebody'), array('rows'=>15, 'cols'=>60));
     //$mform->addRule('messagebody', '', 'required', null, 'client');
     //$mform->setHelpButton('messagebody', array('writing', 'reading', 'questions', 'richtext'), false, 'editorhelpbutton');
     //$mform->addElement('format', 'format', get_string('format'));
     $courses = get_courses();
     foreach ($courses as $course) {
         //$mform->addElement('checkbox','courseid',get_string('course')." ".$course->shortname);
         $courselist[$course->id] = $course->shortname;
     }
     //$select = &$mform->addElement('select', 'colors', get_string('colors'), array('red', 'blue', 'green'), $attributes);
     //$select->setMultiple(true);
     $select =& $mform->addElement('select', 'courses', get_string('courses'), $courselist, 'size="15"');
     $select->setMultiple(true);
     //$mform->addElement('group', 'coursesgrp', get_string('courses'), $select , ' ', false);
     $allroles = array();
     if ($roles = get_all_roles()) {
         foreach ($roles as $role) {
             $rolename = strip_tags(format_string($role->name, true));
             $allroles[$role->id] = $rolename;
         }
     }
     $mform->addElement('select', 'role', get_string('roles'), $allroles);
     $mform->setDefault('role', 'Student');
     $this->add_action_buttons();
 }
Example #2
0
 function fill_table()
 {
     global $CFG;
     $numusers = $this->get_numusers();
     if ($courses = get_courses('all', null, 'c.id, c.shortname')) {
         foreach ($courses as $course) {
             // Get course grade_item
             $grade_item = grade_item::fetch(array('itemtype' => 'course', 'courseid' => $course->id));
             // Get the grade
             $finalgrade = get_field('grade_grades', 'finalgrade', 'itemid', $grade_item->id, 'userid', $this->user->id);
             /// prints rank
             if ($finalgrade) {
                 /// find the number of users with a higher grade
                 $sql = "SELECT COUNT(DISTINCT(userid))\n                            FROM {$CFG->prefix}grade_grades\n                            WHERE finalgrade > {$finalgrade}\n                            AND itemid = {$grade_item->id}";
                 $rank = count_records_sql($sql) + 1;
                 $rankdata = "{$rank}/{$numusers}";
             } else {
                 // no grade, no rank
                 $rankdata = "-";
             }
             $courselink = '<a href="' . $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id . '">' . $course->shortname . '</a>';
             $this->table->add_data(array($courselink, round(grade_to_percentage($finalgrade, $grade_item->grademin, $grade_item->grademax), 1) . '%', $rankdata));
         }
         return true;
     } else {
         notify(get_string('nocourses', 'grades'));
         return false;
     }
 }
Example #3
0
 public function execute()
 {
     $setting = trim($this->arguments[2]);
     $value = trim($this->arguments[3]);
     switch ($this->arguments[0]) {
         case 'course':
             if (!self::setCourseSetting($this->arguments[1], $setting, $value)) {
                 // the setting was not applied, exit with a non-zero exit code
                 cli_error('');
             }
             break;
         case 'category':
             //get all courses in category (recursive)
             $courselist = get_courses($this->arguments[1], '', 'c.id');
             $succeeded = 0;
             $failed = 0;
             foreach ($courselist as $course) {
                 if (self::setCourseSetting($course->id, $setting, $value)) {
                     $succeeded++;
                 } else {
                     $failed++;
                 }
             }
             if ($failed == 0) {
                 echo "OK - successfully modified {$succeeded} courses\n";
             } else {
                 echo "WARNING - failed to mofify {$failed} courses (successfully modified {$succeeded})\n";
             }
             break;
     }
 }
/**
* This function generates the list of courses for <select> control
* using the specified string filter and/or course id's filter
*
* @param string $strfilter The course name filter
* @param array $arrayfilter Course ID's filter, NULL by default, which means not to use id filter
* @return string
*/
function gen_course_list($strfilter = '', $arrayfilter = NULL)
{
    $courselist = array();
    $catcnt = 0;
    // get the list of course categories
    $categories = get_categories();
    foreach ($categories as $cat) {
        // for each category, add the <optgroup> to the string array first
        $courselist[$catcnt] = '<optgroup label="' . htmlspecialchars($cat->name) . '">';
        // get the course list in that category
        $courses = get_courses($cat->id, 'c.sortorder ASC', 'c.fullname, c.id');
        $coursecnt = 0;
        // for each course, check the specified filter
        foreach ($courses as $course) {
            if (!empty($strfilter) && strripos($course->fullname, $strfilter) === false || $arrayfilter !== NULL && in_array($course->id, $arrayfilter) === false) {
                continue;
            }
            // if we pass the filter, add the option to the current string
            $courselist[$catcnt] .= '<option value="' . $course->id . '">' . $course->fullname . '</option>';
            $coursecnt++;
        }
        // if no courses pass the filter in that category, delete the current string
        if ($coursecnt == 0) {
            unset($courselist[$catcnt]);
        } else {
            $courselist[$catcnt] .= '</optgroup>';
            $catcnt++;
        }
    }
    // return the html code with categorized courses
    return implode(' ', $courselist);
}
Example #5
0
function getStudentsByCourse($courseId)
{

$courses = get_courses();
            $context = context_course::instance($courseId);//course id
   
            $students = get_role_users(5, $context); //student context
                  return   $students ;

}
Example #6
0
 /**
  * Gets the list of courses that can be used used to generate a test.
  *
  * @return array The list of options as courseid => name
  */
 public static function get_course_options()
 {
     $courses = get_courses('all', 'c.sortorder ASC', 'c.id, c.shortname, c.fullname');
     if (!$courses) {
         print_error('error_nocourses', 'tool_generator');
     }
     $options = array();
     unset($courses[1]);
     foreach ($courses as $course) {
         $options[$course->id] = $course->fullname . '(' . $course->shortname . ')';
     }
     return $options;
 }
Example #7
0
function get_moodle_courses()
{
    $moodle_courses = array();
    foreach (get_courses() as $course) {
        if (isset($config->moodlecoursefieldid) && $config->moodlecoursefieldid == 'idnumber') {
            $course_identify = $course->idnumber;
        } else {
            $course_identify = $course->shortname;
        }
        $moodle_courses[] = $course_identify;
    }
    return $moodle_courses;
}
 function definition()
 {
     $mform = $this->_form;
     // course
     $courses = array();
     $dbcourses = get_courses();
     foreach ($dbcourses as $dbcourseid => $dbcourse) {
         if ($dbcourse->id > 1) {
             // 1 = system course, ala front-page. probably don't want it there!
             $courses[$dbcourseid] = $dbcourse->fullname;
         }
     }
     $mform->addElement('select', 'course', get_string('promptcourse', 'block_enrol_token_manager'), $courses);
     $mform->addHelpButton('course', 'promptcourse', 'block_enrol_token_manager');
     // cohorts
     $context = context_system::instance();
     $cohorts = array();
     $dbcohorts = cohort_get_cohorts($context->id);
     foreach ($dbcohorts['cohorts'] as $dbcohort) {
         $cohorts[$dbcohort->id] = $dbcohort->name;
     }
     // cohort selection
     $mform->addElement('header', 'cohorts', get_string('cohort_selection', 'block_enrol_token_manager'));
     $mform->addElement('select', 'cohortexisting', get_string('promptcohortexisting', 'block_enrol_token_manager'), $cohorts);
     $mform->addElement('static', 'cohortor', '', 'OR');
     $mform->addHelpButton('cohortor', 'cohortor', 'block_enrol_token_manager');
     $mform->addElement('text', 'cohortnew', get_string('promptcohortnew', 'block_enrol_token_manager'), 'maxlength="253" size="25"');
     $mform->setType('cohortnew', PARAM_CLEANHTML);
     // token prefix
     $mform->addElement('header', 'tokens', get_string('token_generation', 'block_enrol_token_manager'));
     $mform->addElement('text', 'prefix', get_string('promptprefix', 'block_enrol_token_manager'), 'maxlength="4" size="4"');
     $mform->addHelpButton('prefix', 'promptprefix_help', 'block_enrol_token_manager');
     // $mform->addElement('static', 'prefixinstructions', get_string('prefixinstructions', 'block_enrol_token_manager'));
     $mform->setType('prefix', PARAM_ALPHANUMEXT);
     // seats per token
     $mform->addElement('text', 'seatspertoken', get_string('promptseats', 'block_enrol_token_manager'), 'maxlength="3" size="3"');
     $mform->addHelpButton('seatspertoken', 'promptseats', 'block_enrol_token_manager');
     $mform->setType('seatspertoken', PARAM_INT);
     // number of tokens
     $mform->addElement('text', 'tokennumber', get_string('prompttokennum', 'block_enrol_token_manager'), 'maxlength="3" size="3"');
     $mform->addHelpButton('tokennumber', 'prompttokennum', 'block_enrol_token_manager');
     $mform->setType('tokennumber', PARAM_INT);
     // expiry date
     $mform->addElement('date_selector', 'expirydate', get_string('promptexpirydate', 'block_enrol_token_manager'), array('optional' => true));
     // email to
     $mform->addElement('text', 'emailaddress', get_string('emailaddressprompt', 'block_enrol_token_manager'), 'maxlength="128" size="50"');
     $mform->setType('emailaddress', PARAM_EMAIL);
     // buttons
     $this->add_action_buttons(false, get_string('createtokens', 'block_enrol_token_manager'));
 }
Example #9
0
/**
 * Function to check if a semester is already known in the MUMIE
 * 
 * @param object $semester - the semester to be checked
 */
function check_semester($semester)
{
    global $CFG;
    $delimiter = 'moodle-' . $CFG->prefix . 'course_categories-';
    $sync_id_parts = explode($delimiter, $semester->syncid);
    $sort = 'c.sortorder ASC';
    $cat_classes = get_courses($sync_id_parts[1], $sort, $fields = 'c.id');
    //TODO: isn't this deprecated???
    foreach ($cat_classes as $cat_class) {
        if (record_exists('mumiemodule', 'course', $cat_class->id)) {
            return true;
            break;
        }
    }
    return false;
}
Example #10
0
 public function execute()
 {
     global $CFG, $DB;
     //require_once($CFG->dirroot . '/lib/accesslib.php');
     $mode = $this->arguments[0];
     $id = $this->arguments[1];
     $blocktype = $this->arguments[2];
     // name of the block (in English)
     $pagetypepattern = $this->arguments[3];
     // in which page types it will be available ('course-*' , 'mod-*' ...)
     $region = $this->arguments[4];
     // into which page region it will be inserted ('side-pre' , 'side-post' ...)
     $weight = $this->arguments[5];
     // sort/insert order
     //$showinsubcontexts = $this->arguments[6]; // show block in sub context?
     if ($this->expandedOptions['showinsubcontexts']) {
         $showinsubcontexts = true;
     } else {
         $showinsubcontexts = false;
     }
     switch ($mode) {
         case 'category':
             $context = context_coursecat::instance($id, MUST_EXIST);
             self::blockAdd($context->id, $blocktype, $pagetypepattern, $region, $weight, $showinsubcontexts);
             break;
         case 'course':
             $context = context_course::instance($id, MUST_EXIST);
             self::blockAdd($context->id, $blocktype, $pagetypepattern, $region, $weight, $showinsubcontexts);
             break;
         case 'categorycourses':
             //get all courses in category (recursive)
             $courselist = get_courses($id, '', 'c.id');
             foreach ($courselist as $course) {
                 $context = context_course::instance($course->id, MUST_EXIST);
                 self::blockAdd($context->id, $blocktype, $pagetypepattern, $region, $weight, $showinsubcontexts);
                 echo "debug: courseid={$course->id} \n";
             }
             break;
     }
 }
Example #11
0
function print_log_ods($course, $user, $date, $order = 'l.time DESC', $modname, $modid, $modaction, $groupid)
{
    global $CFG, $DB;
    require_once "{$CFG->libdir}/odslib.class.php";
    if (!($logs = build_logs_array($course, $user, $date, $order, '', '', $modname, $modid, $modaction, $groupid))) {
        return false;
    }
    $courses = array();
    if ($course->id == SITEID) {
        $courses[0] = '';
        if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
            foreach ($ccc as $cc) {
                $courses[$cc->id] = $cc->shortname;
            }
        }
    } else {
        $courses[$course->id] = $course->shortname;
    }
    $count = 0;
    $ldcache = array();
    $tt = getdate(time());
    $today = mktime(0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
    $strftimedatetime = get_string("strftimedatetime");
    $nroPages = ceil(count($logs) / (EXCELROWS - FIRSTUSEDEXCELROW + 1));
    $filename = 'logs_' . userdate(time(), get_string('backupnameformat', 'langconfig'), 99, false);
    $filename .= '.ods';
    $workbook = new MoodleODSWorkbook('-');
    $workbook->send($filename);
    $worksheet = array();
    $headers = array(get_string('course'), get_string('time'), get_string('ip_address'), get_string('fullnameuser'), get_string('action'), get_string('info'));
    // Creating worksheets
    for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
        $sheettitle = get_string('logs') . ' ' . $wsnumber . '-' . $nroPages;
        $worksheet[$wsnumber] = $workbook->add_worksheet($sheettitle);
        $worksheet[$wsnumber]->set_column(1, 1, 30);
        $worksheet[$wsnumber]->write_string(0, 0, get_string('savedat') . userdate(time(), $strftimedatetime));
        $col = 0;
        foreach ($headers as $item) {
            $worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW - 1, $col, $item, '');
            $col++;
        }
    }
    if (empty($logs['logs'])) {
        $workbook->close();
        return true;
    }
    $formatDate =& $workbook->add_format();
    $formatDate->set_num_format(get_string('log_excel_date_format'));
    $row = FIRSTUSEDEXCELROW;
    $wsnumber = 1;
    $myxls =& $worksheet[$wsnumber];
    foreach ($logs['logs'] as $log) {
        if (isset($ldcache[$log->module][$log->action])) {
            $ld = $ldcache[$log->module][$log->action];
        } else {
            $ld = $DB->get_record('log_display', array('module' => $log->module, 'action' => $log->action));
            $ldcache[$log->module][$log->action] = $ld;
        }
        if ($ld && is_numeric($log->info)) {
            // ugly hack to make sure fullname is shown correctly
            if ($ld->mtable == 'user' and $ld->field == $DB->sql_concat('firstname', "' '", 'lastname')) {
                $log->info = fullname($DB->get_record($ld->mtable, array('id' => $log->info)), true);
            } else {
                $log->info = $DB->get_field($ld->mtable, $ld->field, array('id' => $log->info));
            }
        }
        // Filter log->info
        $log->info = format_string($log->info);
        $log->info = strip_tags(urldecode($log->info));
        // Some XSS protection
        if ($nroPages > 1) {
            if ($row > EXCELROWS) {
                $wsnumber++;
                $myxls =& $worksheet[$wsnumber];
                $row = FIRSTUSEDEXCELROW;
            }
        }
        $coursecontext = context_course::instance($course->id);
        $myxls->write_string($row, 0, format_string($courses[$log->course], true, array('context' => $coursecontext)));
        $myxls->write_date($row, 1, $log->time);
        $myxls->write_string($row, 2, $log->ip);
        $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
        $myxls->write_string($row, 3, $fullname);
        $actionurl = $CFG->wwwroot . make_log_url($log->module, $log->url);
        $myxls->write_string($row, 4, $log->module . ' ' . $log->action . ' (' . $actionurl . ')');
        $myxls->write_string($row, 5, $log->info);
        $row++;
    }
    $workbook->close();
    return true;
}
Example #12
0
/**
 * This function returns the number of activities using scaleid in the entire site
 *
 * @deprecated since Moodle 3.1
 * @param int $scaleid
 * @param array $courses
 * @return int
 */
function site_scale_used($scaleid, &$courses)
{
    $return = 0;
    debugging('site_scale_used() is deprecated and never used, plugins can implement <modname>_scale_used_anywhere, ' . 'all implementations of <modname>_scale_used are now ignored', DEBUG_DEVELOPER);
    if (!is_array($courses) || count($courses) == 0) {
        $courses = get_courses("all", false, "c.id, c.shortname");
    }
    if (!empty($scaleid)) {
        if (is_array($courses) && count($courses) > 0) {
            foreach ($courses as $course) {
                $return += course_scale_used($course->id, $scaleid);
            }
        }
    }
    return $return;
}
             notify(get_string('missingfield', 'error', $key));
             $headersOk = false;
         }
     }
 }
 if ($headersOk) {
     $usersnew = 0;
     $usersupdated = 0;
     $userserrors = 0;
     $usersdeleted = 0;
     $renames = 0;
     $renameerrors = 0;
     $deleteerrors = 0;
     $newusernames = array();
     // We'll need courses a lot, so fetch it early and keep it in memory, indexed by their shortname
     $tmp =& get_courses('all', '', 'id,shortname,visible');
     $courses = array();
     foreach ($tmp as $c) {
         $courses[$c->shortname] = $c;
     }
     unset($tmp);
     echo '<p id="results">';
     while (!feof($fp)) {
         $errors = '';
         $user = new object();
         // by default, use the local mnet id (this may be changed in the file)
         $user->mnethostid = $CFG->mnet_localhost_id;
         $line = explode($csv_delimiter, fgets($fp, LINE_MAX_SIZE));
         ++$linenum;
         // add fields to user object
         foreach ($line as $key => $value) {
Example #14
0
        }
    }
    if ($swapcategory and $movecategory) {
        $DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id' => $movecategory->id));
        $DB->set_field('course_categories', 'sortorder', $movecategory->sortorder, array('id' => $swapcategory->id));
        cache_helper::purge_by_event('changesincoursecat');
        add_to_log(SITEID, "category", "move", "editcategory.php?id=$movecategory->id", $movecategory->id);
    }

    // Finally reorder courses.
    fix_course_sortorder();
}

if ($coursecat->id && $canmanage && $resort && confirm_sesskey()) {
    // Resort the category.
    if ($courses = get_courses($coursecat->id, '', 'c.id,c.fullname,c.sortorder')) {
        core_collator::asort_objects_by_property($courses, 'fullname', core_collator::SORT_NATURAL);
        $i = 1;
        foreach ($courses as $course) {
            $DB->set_field('course', 'sortorder', $coursecat->sortorder + $i, array('id' => $course->id));
            $i++;
        }
        // This should not be needed but we do it just to be safe.
        fix_course_sortorder();
        cache_helper::purge_by_event('changesincourse');
    }
}

if (!empty($moveto) && ($data = data_submitted()) && confirm_sesskey()) {
    // Move a specified course to a new category.
    // User must have category update in both cats to perform this.
Example #15
0
function calendar_course_filter_selector($getvars = '')
{
    global $USER, $SESSION;
    if (empty($USER->id) or isguest()) {
        return '';
    }
    if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM)) && !empty($CFG->calendar_adminseesall)) {
        $courses = get_courses('all', 'c.shortname', 'c.id,c.shortname');
    } else {
        $courses = get_my_courses($USER->id, 'shortname');
    }
    unset($courses[SITEID]);
    $courseoptions[SITEID] = get_string('fulllistofcourses');
    foreach ($courses as $course) {
        $courseoptions[$course->id] = format_string($course->shortname);
    }
    if (is_numeric($SESSION->cal_courses_shown)) {
        $selected = $SESSION->cal_courses_shown;
    } else {
        $selected = '';
    }
    return popup_form(CALENDAR_URL . 'set.php?var=setcourse&amp;' . $getvars . '&amp;id=', $courseoptions, 'cal_course_flt', $selected, '', '', '', true);
}
function bigbluebuttonbn_import_get_courses_for_select(array $bbbsession)
{
    if ($bbbsession['administrator']) {
        $courses = get_courses('all', 'c.id ASC', 'c.id,c.shortname,c.fullname');
        //It includes the name of the site as a course (category 0), so remove the first one
        unset($courses["1"]);
    } else {
        $courses = enrol_get_users_courses($bbbsession['userID'], false, 'id,shortname,fullname');
    }
    $courses_for_select = [];
    foreach ($courses as $course) {
        if ($course->id != $bbbsession['course']->id) {
            $courses_for_select[$course->id] = $course->fullname;
        }
    }
    return $courses_for_select;
}
Example #17
0
/**
 * Prints the category info in indented fashion
 * This function is only used by print_whole_category_list() above
 */
function print_category_info($category, $depth = 0, $showcourses = false)
{
    global $CFG, $DB, $OUTPUT;
    $strsummary = get_string('summary');
    $catlinkcss = null;
    if (!$category->visible) {
        $catlinkcss = array('class' => 'dimmed');
    }
    static $coursecount = null;
    if (null === $coursecount) {
        // only need to check this once
        $coursecount = $DB->count_records('course') <= FRONTPAGECOURSELIMIT;
    }
    if ($showcourses and $coursecount) {
        $catimage = '<img src="' . $OUTPUT->pix_url('i/course') . '" alt="" />';
    } else {
        $catimage = "&nbsp;";
    }
    $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary');
    $context = get_context_instance(CONTEXT_COURSECAT, $category->id);
    $fullname = format_string($category->name, true, array('context' => $context));
    if ($showcourses and $coursecount) {
        echo '<div class="categorylist clearfix">';
        $cat = '';
        $cat .= html_writer::tag('div', $catimage, array('class' => 'image'));
        $catlink = html_writer::link(new moodle_url('/course/category.php', array('id' => $category->id)), $fullname, $catlinkcss);
        $cat .= html_writer::tag('div', $catlink, array('class' => 'name'));
        $html = '';
        if ($depth > 0) {
            for ($i = 0; $i < $depth; $i++) {
                $html = html_writer::tag('div', $html . $cat, array('class' => 'indentation'));
                $cat = '';
            }
        } else {
            $html = $cat;
        }
        echo html_writer::tag('div', $html, array('class' => 'category'));
        echo html_writer::tag('div', '', array('class' => 'clearfloat'));
        // does the depth exceed maxcategorydepth
        // maxcategorydepth == 0 or unset meant no limit
        $limit = !(isset($CFG->maxcategorydepth) && $depth >= $CFG->maxcategorydepth - 1);
        if ($courses && ($limit || $CFG->maxcategorydepth == 0)) {
            foreach ($courses as $course) {
                $linkcss = null;
                if (!$course->visible) {
                    $linkcss = array('class' => 'dimmed');
                }
                $coursename = get_course_display_name_for_list($course);
                $courselink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), format_string($coursename), $linkcss);
                // print enrol info
                $courseicon = '';
                if ($icons = enrol_get_course_info_icons($course)) {
                    foreach ($icons as $pix_icon) {
                        $courseicon = $OUTPUT->render($pix_icon) . ' ';
                    }
                }
                $coursecontent = html_writer::tag('div', $courseicon . $courselink, array('class' => 'name'));
                if ($course->summary) {
                    $link = new moodle_url('/course/info.php?id=' . $course->id);
                    $actionlink = $OUTPUT->action_link($link, '<img alt="' . $strsummary . '" src="' . $OUTPUT->pix_url('i/info') . '" />', new popup_action('click', $link, 'courseinfo', array('height' => 400, 'width' => 500)), array('title' => $strsummary));
                    $coursecontent .= html_writer::tag('div', $actionlink, array('class' => 'info'));
                }
                $html = '';
                for ($i = 0; $i <= $depth; $i++) {
                    $html = html_writer::tag('div', $html . $coursecontent, array('class' => 'indentation'));
                    $coursecontent = '';
                }
                echo html_writer::tag('div', $html, array('class' => 'course clearfloat'));
            }
        }
        echo '</div>';
    } else {
        echo '<div class="categorylist">';
        $html = '';
        $cat = html_writer::link(new moodle_url('/course/category.php', array('id' => $category->id)), $fullname, $catlinkcss);
        if (count($courses) > 0) {
            $cat .= html_writer::tag('span', ' (' . count($courses) . ')', array('title' => get_string('numberofcourses'), 'class' => 'numberofcourse'));
        }
        if ($depth > 0) {
            for ($i = 0; $i < $depth; $i++) {
                $html = html_writer::tag('div', $html . $cat, array('class' => 'indentation'));
                $cat = '';
            }
        } else {
            $html = $cat;
        }
        echo html_writer::tag('div', $html, array('class' => 'category'));
        echo html_writer::tag('div', '', array('class' => 'clearfloat'));
        echo '</div>';
    }
}
//$courseid = required_param('id', PARAM_INTEGER);
//$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = get_context_instance(CONTEXT_COURSECAT, $catid);
$PAGE->set_context($context);
if (!has_capability('block/timetracker:manageworkers', $context)) {
    print_error('You do not have permission to run this report.');
}
$categoryinfo = $DB->get_record('course_categories', array('id' => $catid));
$catname = str_replace(' ', '', $categoryinfo->name);
$filename = date("Y_m_d") . '_' . $catname . '_Earnings.csv';
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename=' . $filename);
//$headers = "Department,Last Name,First Name,Email,Earnings,Max Term Earnings,Remaining \n";
$headers = "DET,DETCode,ID,Hours,Amount,Budget,Department,Last Name,First Name,Max Term Earnings,Remaining \n";
echo $headers;
$courses = get_courses($catid, 'fullname ASC', 'c.id, c.shortname');
foreach ($courses as $course) {
    if ($active) {
        //find all active workers
        $workers = $DB->get_records('block_timetracker_workerinfo', array('active' => 1, 'courseid' => $course->id));
    } else {
        //find all workers
        $workers = $DB->get_records('block_timetracker_workerinfo', array('courseid' => $course->id));
    }
    foreach ($workers as $worker) {
        $units = get_split_units($start, $end, $worker->id, $course->id);
        //don't include the ones that aren't between $start and $end
        foreach ($units as $key => $unit) {
            if (!($unit->timein >= $start && $unit->timeout <= $end)) {
                unset($units[$key]);
            }
     $rolename->roleid = $roleid;
     $rolename->name = $value;
     $newrolenames[] = $rolename;
 }
 // This is for updating all categories and courses.
 $cats = array(coursecat::get($id));
 $courses = array();
 if ($categories = coursecat::get($id)->get_children()) {
     foreach ($categories as $cat) {
         array_push($cats, $cat);
         $cats = array_merge($cats, coursecat::get($cat->id)->get_children());
     }
 }
 // Update all the category's.
 foreach ($cats as $coursecat) {
     $courses = array_merge($courses, get_courses($coursecat->id));
     foreach ($newrolenames as $role) {
         if (!$role->name) {
             $DB->delete_records('cat_role_names', array('catid' => $coursecat->id, 'roleid' => $role->roleid));
         } else {
             if ($rolename = $DB->get_record('cat_role_names', array('catid' => $coursecat->id, 'roleid' => $role->roleid))) {
                 $rolename->name = $role->name;
                 $DB->update_record('cat_role_names', $rolename);
             } else {
                 $rolename = new stdClass();
                 $rolename->catid = $coursecat->id;
                 $rolename->roleid = $role->roleid;
                 $rolename->name = $role->name;
                 $DB->insert_record('cat_role_names', $rolename);
             }
         }
function allmetadata_print_big_search_form($course)
{
    global $CFG;
    global $words, $subject, $searchcourseid, $phrase, $user, $userid, $modname, $fullwords, $notwords, $datefrom, $dateto;
    print_simple_box(get_string('searchallmetadataintro', 'allmetadata'), 'center', '', '', 'searchbox', 'intro');
    print_simple_box_start("center");
    echo "<script type=\"text/javascript\" language=\"javascript\">\n";
    echo "var timefromitems = ['fromday','frommonth','fromyear','fromhour', 'fromminute'];\n";
    echo "var timetoitems = ['today','tomonth','toyear','tohour','tominute'];\n";
    echo "</script>\n";
    echo '<form name="search" action="search_allmetadata.php" method="get">';
    echo '<input type="hidden" value="' . $course->id . '" name="id" alt="">';
    echo '<table cellpadding="10" class="searchbox" id="form">';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchwords', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="words" value="' . s($words) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchphrase', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="phrase" value="' . s($phrase) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchnotwords', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="notwords" value="' . s($notwords) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchfullwords', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="fullwords" value="' . s($fullwords) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchdatefrom', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    echo '<input name="timefromrestrict" type="checkbox" value="1" alt="' . get_string('searchdatefrom', 'allmetadata') . '" onclick="return lockoptions(\'search\', \'timefromrestrict\', timefromitems)" /> ';
    if (empty($dateto)) {
        $datefrom = make_timestamp(2000, 1, 1, 0, 0, 0);
    }
    print_date_selector('fromday', 'frommonth', 'fromyear', $datefrom);
    print_time_selector('fromhour', 'fromminute', $datefrom);
    echo '<input type="hidden" name="hfromday" value="0" />';
    echo '<input type="hidden" name="hfrommonth" value="0" />';
    echo '<input type="hidden" name="hfromyear" value="0" />';
    echo '<input type="hidden" name="hfromhour" value="0" />';
    echo '<input type="hidden" name="hfromminute" value="0" />';
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchdateto', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    echo '<input name="timetorestrict" type="checkbox" value="1" alt="' . get_string('searchdateto', 'allmetadata') . '" onclick="return lockoptions(\'search\', \'timetorestrict\', timetoitems)" /> ';
    if (empty($dateto)) {
        $dateto = time() + 3600;
    }
    print_date_selector('today', 'tomonth', 'toyear', $dateto);
    print_time_selector('tohour', 'tominute', $dateto);
    echo '<input type="hidden" name="htoday" value="0" />';
    echo '<input type="hidden" name="htomonth" value="0" />';
    echo '<input type="hidden" name="htoyear" value="0" />';
    echo '<input type="hidden" name="htohour" value="0" />';
    echo '<input type="hidden" name="htominute" value="0" />';
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchsubject', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="subject" value="' . s($subject) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchuser', 'allmetadata') . ':</td>';
    echo '<td class="c1"><input type="text" size="35" name="user" value="' . s($user) . '" alt=""></td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchwhichmetadatas', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    //Metadata Modules available
    //function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused)
    $allmods = get_all_mods($course->id, &$mods, &$modnames, &$modnamesplural, &$modnamesused);
    $metamods = array();
    if (array_key_exists("metadatadc", $modnamesplural)) {
        $metamods = array_merge(array("metadatadc" => get_string('modulenameplural', 'metadatadc')), $metamods);
        //array_unshift($metamods, get_string('modulenameplural', 'metadatadc'));
    }
    if (array_key_exists("metadatalom", $modnamesplural)) {
        $metamods = array_merge(array("metadatalom" => get_string('modulenameplural', 'metadatalom')), $metamods);
        //array_unshift($metamods, get_string('modulenameplural', 'metadatalom'));
    }
    if (count($metamods) == 1) {
        //choose_from_menu($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0)
        choose_from_menu($metamods, 'metamodname', '', 'choose', '');
    } elseif (count($metamods) > 1) {
        array_unshift($metamods, get_string('allmetadata', 'allmetadata'));
        choose_from_menu($metamods, 'metamodname', '', 'choose', '');
    } else {
        echo '<strong>' . get_string('nometadata', 'allmetadata') . '</strong>';
    }
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchwhichcourse', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    //Courses available
    //get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
    $allcourses = array();
    if ($allcs = get_courses("all", "c.id ASC", "c.id,c.fullname")) {
        foreach ($allcs as $allc) {
            $namec = $allc->fullname;
            $idc = $allc->id;
            $onecourse = array($idc => $namec);
            array_push_associative($allcourses, $onecourse);
        }
    }
    if (count($allcourses) == 1) {
        //choose_from_menu($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0)
        choose_from_menu($allcourses, 'searchcourseid', '', get_string('allcourses', 'allmetadata'), '');
    } elseif (count($allcourses) > 1) {
        //array_unshift($allcourses, get_string('allcourses', 'allmetadata'));
        //array_push($allcourses, get_string('mycourses', 'allmetadata'));
        $mycourse = array("9999" => get_string('mycourses', 'allmetadata'));
        array_push_associative($allcourses, $mycourse);
        choose_from_menu($allcourses, 'searchcourseid', '', get_string('allcourses', 'allmetadata'), '');
    } else {
        echo '<strong>' . get_string('nocourses', 'allmetadata') . '</strong>';
    }
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="c0">' . get_string('searchwhichmods', 'allmetadata') . ':</td>';
    echo '<td class="c1">';
    //Resources-Activities Modules available
    $modsmetadata = array("metadatadc" => get_string('modulenameplural', 'metadatadc'), "metadatalom" => get_string('modulenameplural', 'metadatalom'));
    $modsra = array();
    //Don't show the metadatalom/metadatadc mods
    $modsra = array_diff($modnamesplural, $modsmetadata);
    if (count($modsra) == 1) {
        //choose_from_menu($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0)
        choose_from_menu($modsra, 'modname', '', 'choose', '');
    } elseif (count($modsra) > 1) {
        array_unshift($modsra, get_string('allmods', 'allmetadata'));
        choose_from_menu($modsra, 'modname', '', 'choose', '');
    } else {
        echo '<strong>' . get_string('nomodules', 'allmetadata') . '</strong>';
    }
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td class="submit" colspan="2" align="center">';
    echo '<input type="submit" value="' . get_string('searchallmetadatas', 'allmetadata') . '" alt=""></td>';
    echo '</tr>';
    echo '</table>';
    echo '</form>';
    echo "<script type=\"text/javascript\">";
    echo "lockoptions('search','timefromrestrict', timefromitems);";
    echo "lockoptions('search','timetorestrict', timetoitems);";
    echo "</script>\n";
    print_simple_box_end();
}
Example #21
0
            $new_category = array();
            $new_category["id"] = $each_category->id;
            $new_category["name"] = $each_category->name;
            $new_category["description"] = $each_category->description;
            $new_category["parent"] = $each_category->parent;
            $new_category["course_count"] = $each_category->coursecount;
            $new_category["depth"] = $each_category->depth;
            $categories[] = $new_category;
        }
    }
    $json_output["course_categories"] = $categories;
}
if (isset($_GET['course_list']) || $update_all) {
    $course_list = array();
    include_once '../lib/datalib.php';
    $courses = get_courses("all", "c.sortorder ASC", "c.id, c.fullname, c.shortname, c.summary, c.category, c.format, c.startdate, c.enrollable, c.enrolstartdate, c.enrolenddate, c.visible, c.password, c.guest");
    foreach ($courses as $course) {
        $is_admin = FALSE;
        if ($CFG->rolesactive) {
        } else {
            $is_admin = isadmin();
        }
        $show_course = $course->visible or $is_admin;
        if ($course->visible) {
            if (function_exists(course_setup)) {
                // Doesn't exist in older versions of Moodle.
                course_setup($course->id);
            }
            $new_course = array();
            $new_course["id"] = $course->id;
            $new_course["fullname"] = $course->fullname;
Example #22
0
function print_category_info($category, $depth, $showcourses = false)
{
    /// Prints the category info in indented fashion
    /// This function is only used by print_whole_category_list() above
    global $CFG;
    static $strallowguests, $strrequireskey, $strsummary;
    if (empty($strsummary)) {
        $strallowguests = get_string('allowguests');
        $strrequireskey = get_string('requireskey');
        $strsummary = get_string('summary');
    }
    $catlinkcss = $category->visible ? '' : ' class="dimmed" ';
    $coursecount = count_records('course') <= FRONTPAGECOURSELIMIT;
    if ($showcourses and $coursecount) {
        $catimage = '<img src="' . $CFG->pixpath . '/i/course.gif" alt="" />';
    } else {
        $catimage = "&nbsp;";
    }
    echo "\n\n" . '<table class="categorylist">';
    $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.guest,c.cost,c.currency');
    if ($showcourses and $coursecount) {
        echo '<tr>';
        if ($depth) {
            $indent = $depth * 30;
            $rows = count($courses) + 1;
            echo '<td class="category indentation" rowspan="' . $rows . '" valign="top">';
            print_spacer(10, $indent);
            echo '</td>';
        }
        echo '<td valign="top" class="category image">' . $catimage . '</td>';
        echo '<td valign="top" class="category name">';
        echo '<a ' . $catlinkcss . ' href="' . $CFG->wwwroot . '/course/category.php?id=' . $category->id . '">' . format_string($category->name) . '</a>';
        echo '</td>';
        echo '<td class="category info">&nbsp;</td>';
        echo '</tr>';
        // does the depth exceed maxcategorydepth
        // maxcategorydepth == 0 or unset meant no limit
        $limit = !(isset($CFG->maxcategorydepth) && $depth >= $CFG->maxcategorydepth - 1);
        if ($courses && ($limit || $CFG->maxcategorydepth == 0)) {
            foreach ($courses as $course) {
                $linkcss = $course->visible ? '' : ' class="dimmed" ';
                echo '<tr><td valign="top">&nbsp;';
                echo '</td><td valign="top" class="course name">';
                echo '<a ' . $linkcss . ' href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">' . format_string($course->fullname) . '</a>';
                echo '</td><td align="right" valign="top" class="course info">';
                if ($course->guest) {
                    echo '<a title="' . $strallowguests . '" href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">';
                    echo '<img alt="' . $strallowguests . '" src="' . $CFG->pixpath . '/i/guest.gif" /></a>';
                } else {
                    echo '<img alt="" style="width:18px;height:16px;" src="' . $CFG->pixpath . '/spacer.gif" />';
                }
                if ($course->password) {
                    echo '<a title="' . $strrequireskey . '" href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">';
                    echo '<img alt="' . $strrequireskey . '" src="' . $CFG->pixpath . '/i/key.gif" /></a>';
                } else {
                    echo '<img alt="" style="width:18px;height:16px;" src="' . $CFG->pixpath . '/spacer.gif" />';
                }
                if ($course->summary) {
                    link_to_popup_window('/course/info.php?id=' . $course->id, 'courseinfo', '<img alt="' . $strsummary . '" src="' . $CFG->pixpath . '/i/info.gif" />', 400, 500, $strsummary);
                } else {
                    echo '<img alt="" style="width:18px;height:16px;" src="' . $CFG->pixpath . '/spacer.gif" />';
                }
                echo '</td></tr>';
            }
        }
    } else {
        echo '<tr>';
        if ($depth) {
            $indent = $depth * 20;
            echo '<td class="category indentation" valign="top">';
            print_spacer(10, $indent);
            echo '</td>';
        }
        echo '<td valign="top" class="category name">';
        echo '<a ' . $catlinkcss . ' href="' . $CFG->wwwroot . '/course/category.php?id=' . $category->id . '">' . format_string($category->name) . '</a>';
        echo '</td>';
        echo '<td valign="top" class="category number">';
        if (count($courses)) {
            echo count($courses);
        }
        echo '</td></tr>';
    }
    echo '</table>';
}
Example #23
0
/**
 * This function returns the number of activities using scaleid in the entire site
 *
 * @param int $scaleid
 * @param array $courses
 * @return int
 */
function site_scale_used($scaleid, &$courses)
{
    $return = 0;
    if (!is_array($courses) || count($courses) == 0) {
        $courses = get_courses("all", false, "c.id, c.shortname");
    }
    if (!empty($scaleid)) {
        if (is_array($courses) && count($courses) > 0) {
            foreach ($courses as $course) {
                $return += course_scale_used($course->id, $scaleid);
            }
        }
    }
    return $return;
}
Example #24
0
$strimport = get_string("importdata");
$tcourseids = '';
if ($teachers = get_user_capability_course('moodle/course:update')) {
    foreach ($teachers as $teacher) {
        if ($teacher->id != $course->id && $teacher->id != SITEID) {
            $tcourseids .= $teacher->id . ',';
        }
    }
}
$taught_courses = array();
if (!empty($tcourseids)) {
    $tcourseids = substr($tcourseids, 0, -1);
    $taught_courses = get_records_list('course', 'id', $tcourseids, 'sortorder');
}
if (!empty($creator)) {
    $cat_courses = get_courses($course->category, $sort = "c.sortorder ASC", $fields = "c.id, c.fullname");
} else {
    $cat_courses = array();
}
print_heading(get_string("importactivities"));
$options = array();
foreach ($taught_courses as $tcourse) {
    if ($tcourse->id != $course->id && $tcourse->id != SITEID) {
        $options[$tcourse->id] = format_string($tcourse->fullname);
    }
}
if (empty($options) && empty($creator)) {
    notify(get_string('courseimportnotaught'));
    return;
    // yay , this will pass control back to the file that included or required us.
}
Example #25
0
 /**
  * Displays a course filter selector
  *
  * @param moodle_url $returnurl The URL that the user should be taken too upon selecting a course.
  * @param string $label The label to use for the course select.
  * @return string
  */
 protected function course_filter_selector(moodle_url $returnurl, $label = null)
 {
     global $USER, $SESSION, $CFG;
     if (!isloggedin() or isguestuser()) {
         return '';
     }
     if (has_capability('moodle/calendar:manageentries', context_system::instance()) && !empty($CFG->calendar_adminseesall)) {
         $courses = get_courses('all', 'c.shortname', 'c.id,c.shortname');
     } else {
         $courses = enrol_get_my_courses();
     }
     unset($courses[SITEID]);
     $courseoptions = array();
     $courseoptions[SITEID] = get_string('fulllistofcourses');
     foreach ($courses as $course) {
         $coursecontext = context_course::instance($course->id);
         $courseoptions[$course->id] = format_string($course->shortname, true, array('context' => $coursecontext));
     }
     if ($this->page->course->id !== SITEID) {
         $selected = $this->page->course->id;
     } else {
         $selected = '';
     }
     $courseurl = new moodle_url($returnurl);
     $courseurl->remove_params('course');
     $select = new single_select($courseurl, 'course', $courseoptions, $selected, null);
     $select->class = 'cal_courses_flt';
     if ($label !== null) {
         $select->set_label($label);
     } else {
         $select->set_label(get_string('listofcourses'), array('class' => 'accesshide'));
     }
     return $this->output->render($select);
 }
Example #26
0
 function get_content()
 {
     global $THEME, $CFG, $USER;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $icon = "<img src=\"{$CFG->pixpath}/i/course.gif\"" . " class=\"icon\" alt=\"" . get_string("course") . "\" />";
     $adminseesall = true;
     if (isset($CFG->block_course_list_adminview)) {
         if ($CFG->block_course_list_adminview == 'own') {
             $adminseesall = false;
         }
     }
     if (empty($CFG->disablemycourses) and !empty($USER->id) and !(has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) and $adminseesall) and !isguest()) {
         // Just print My Courses
         if ($courses = get_my_courses($USER->id)) {
             foreach ($courses as $course) {
                 if ($course->id == SITEID) {
                     continue;
                 }
                 $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
                 $this->content->items[] = "<a {$linkcss} title=\"" . format_string($course->shortname) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . format_string($course->fullname) . "</a>";
                 $this->content->icons[] = $icon;
             }
             $this->title = get_string('mycourses');
             /// If we can update any course of the view all isn't hidden, show the view all courses link
             if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
                 $this->content->footer = "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string("fulllistofcourses") . "</a> ...";
             }
             $this->get_remote_courses();
             if ($this->content->items) {
                 // make sure we don't return an empty list
                 return $this->content;
             }
         }
     }
     $categories = get_categories("0");
     // Parent = 0   ie top-level categories only
     if ($categories) {
         //Check we have categories
         if (count($categories) > 1 || count($categories) == 1 && count_records('course') > 200) {
             // Just print top level category links
             foreach ($categories as $category) {
                 $linkcss = $category->visible ? "" : " class=\"dimmed\" ";
                 $this->content->items[] = "<a {$linkcss} href=\"{$CFG->wwwroot}/course/category.php?id={$category->id}\">" . format_string($category->name) . "</a>";
                 $this->content->icons[] = $icon;
             }
             /// If we can update any course of the view all isn't hidden, show the view all courses link
             if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
                 $this->content->footer .= "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string('fulllistofcourses') . '</a> ...';
             }
             $this->title = get_string('categories');
         } else {
             // Just print course names of single category
             $category = array_shift($categories);
             $courses = get_courses($category->id);
             if ($courses) {
                 foreach ($courses as $course) {
                     $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
                     $this->content->items[] = "<a {$linkcss} title=\"" . format_string($course->shortname) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . format_string($course->fullname) . "</a>";
                     $this->content->icons[] = $icon;
                 }
                 /// If we can update any course of the view all isn't hidden, show the view all courses link
                 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM)) || empty($CFG->block_course_list_hideallcourseslink)) {
                     $this->content->footer .= "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string('fulllistofcourses') . '</a> ...';
                 }
                 $this->get_remote_courses();
             } else {
                 $this->content->icons[] = '';
                 $this->content->items[] = get_string('nocoursesyet');
                 if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id))) {
                     $this->content->footer = '<a href="' . $CFG->wwwroot . '/course/edit.php?category=' . $category->id . '">' . get_string("addnewcourse") . '</a> ...';
                 }
                 $this->get_remote_courses();
             }
             $this->title = get_string('courses');
         }
     }
     return $this->content;
 }
Example #27
0
    require_login();
    $editingon = $PAGE->user_is_editing();
} else {
    if ($CFG->forcelogin) {
        require_login();
    }
    $editingon = false;
}
if (!$category->visible) {
    require_capability('moodle/category:viewhiddencategories', $context);
}
// Process any category actions.
if (has_capability('moodle/category:manage', $context)) {
    /// Resort the category if requested
    if ($resort and confirm_sesskey()) {
        if ($courses = get_courses($category->id, "fullname ASC", 'c.id,c.fullname,c.sortorder')) {
            $i = 1;
            foreach ($courses as $course) {
                $DB->set_field('course', 'sortorder', $category->sortorder + $i, array('id' => $course->id));
                $i++;
            }
            fix_course_sortorder();
            // should not be needed
        }
    }
}
// Process any course actions.
if ($editingon) {
    /// Move a specified course to a new category
    if (!empty($moveto) and $data = data_submitted() and confirm_sesskey()) {
        // Some courses are being moved
Example #28
0
function report_stats_report($course, $report, $mode, $user, $roleid, $time) {
    global $CFG, $DB, $OUTPUT;

    if ($user) {
        $userid = $user->id;
    } else {
        $userid = 0;
    }

    $courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname');
    $courseoptions = array();

    foreach ($courses as $c) {
        $context = context_course::instance($c->id);

        if (has_capability('report/stats:view', $context)) {
            $courseoptions[$c->id] = format_string($c->shortname, true, array('context' => $context));
        }
    }

    $reportoptions = stats_get_report_options($course->id, $mode);
    $timeoptions = report_stats_timeoptions($mode);
    if (empty($timeoptions)) {
        print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
    }

    $users = array();
    $table = new html_table();
    $table->width = 'auto';

    if ($mode == STATS_MODE_DETAILED) {
        $param = stats_get_parameters($time,null,$course->id,$mode); // we only care about the table and the time string (if we have time)

        //TODO: lceanup this ugly mess
        $sql = 'SELECT DISTINCT s.userid, u.firstname, u.lastname, u.idnumber
                     FROM {stats_user_'.$param->table.'} s
                     JOIN {user} u ON u.id = s.userid
                     WHERE courseid = '.$course->id
            . ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '')
            . ((!empty($time)) ? ' AND timeend >= '.$param->timeafter : '')
            .' ORDER BY u.lastname, u.firstname ASC';

        if (!$us = $DB->get_records_sql($sql, $param->params)) {
            print_error('nousers');
        }

        foreach ($us as $u) {
            $users[$u->userid] = fullname($u, true);
        }

        $table->align = array('left','left','left','left','left','left','left','left');
        $table->data[] = array(get_string('course'),html_writer::select($courseoptions,'course',$course->id,false),
                               get_string('users'),html_writer::select($users,'userid',$userid,false),
                               get_string('statsreporttype'),html_writer::select($reportoptions,'report',($report == 5) ? $report.$roleid : $report,false),
                               get_string('statstimeperiod'),html_writer::select($timeoptions,'time',$time,false),
                               '<input type="submit" value="'.get_string('view').'" />') ;
    } else if ($mode == STATS_MODE_RANKED) {
        $table->align = array('left','left','left','left','left','left');
        $table->data[] = array(get_string('statsreporttype'),html_writer::select($reportoptions,'report',($report == 5) ? $report.$roleid : $report,false),
                               get_string('statstimeperiod'),html_writer::select($timeoptions,'time',$time,false),
                               '<input type="submit" value="'.get_string('view').'" />') ;
    } else if ($mode == STATS_MODE_GENERAL) {
        $table->align = array('left','left','left','left','left','left','left');
        $table->data[] = array(get_string('course'),html_writer::select($courseoptions,'course',$course->id,false),
                               get_string('statsreporttype'),html_writer::select($reportoptions,'report',($report == 5) ? $report.$roleid : $report,false),
                               get_string('statstimeperiod'),html_writer::select($timeoptions,'time',$time,false),
                               '<input type="submit" value="'.get_string('view').'" />') ;
    }

    echo '<form action="index.php" method="post">'."\n"
        .'<div>'."\n"
        .'<input type="hidden" name="mode" value="'.$mode.'" />'."\n";

    echo html_writer::table($table);

    echo '</div>';
    echo '</form>';

    if (!empty($report) && !empty($time)) {
        if ($report == STATS_REPORT_LOGINS && $course->id != SITEID) {
            print_error('reportnotavailable');
        }

        $param = stats_get_parameters($time,$report,$course->id,$mode);

        if ($mode == STATS_MODE_DETAILED) {
            $param->table = 'user_'.$param->table;
        }

        if (!empty($param->sql)) {
            $sql = $param->sql;
        } else {
            //TODO: lceanup this ugly mess
            $sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields
                .' FROM {stats_'.$param->table.'} WHERE '
                .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
                .((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
                .((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '')
                . ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '')
                .' timeend >= '.$param->timeafter
                .' '.$param->extras
                .' ORDER BY timeend DESC';
        }

        $stats = $DB->get_records_sql($sql);

        if (empty($stats)) {
            echo $OUTPUT->notification(get_string('statsnodata'));

        } else {

            $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)));

            echo $OUTPUT->heading(format_string($course->shortname).' - '.get_string('statsreport'.$report)
                    .((!empty($user)) ? ' '.get_string('statsreportforuser').' ' .fullname($user,true) : '')
                    .((!empty($roleid)) ? ' '.$DB->get_field('role','name', array('id'=>$roleid)) : ''));


            if (empty($CFG->gdversion)) {
                echo "(".get_string("gdneed").")";
            } else {
                if ($mode == STATS_MODE_DETAILED) {
                    echo '<div class="graph"><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.$mode.'&amp;course='.$course->id.'&amp;time='.$time.'&amp;report='.$report.'&amp;userid='.$userid.'" alt="'.get_string('statisticsgraph').'" /></div';
                } else {
                    echo '<div class="graph"><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.$mode.'&amp;course='.$course->id.'&amp;time='.$time.'&amp;report='.$report.'&amp;roleid='.$roleid.'" alt="'.get_string('statisticsgraph').'" /></div>';
                }
            }

            $table = new html_table();
            $table->align = array('left','center','center','center');
            $param->table = str_replace('user_','',$param->table);
            switch ($param->table) {
                case 'daily'  : $period = get_string('day'); break;
                case 'weekly' : $period = get_string('week'); break;
                case 'monthly': $period = get_string('month', 'form'); break;
                default : $period = '';
            }
            $table->head = array(get_string('periodending','moodle',$period));
            if (empty($param->crosstab)) {
                $table->head[] = $param->line1;
                if (!empty($param->line2)) {
                    $table->head[] = $param->line2;
                }
            }
            if (!file_exists($CFG->dirroot.'/report/log/index.php')) {
                // bad luck, we can not link other report
            } else if (empty($param->crosstab)) {
                foreach  ($stats as $stat) {
                    $a = array(userdate($stat->timeend-(60*60*24),get_string('strftimedate'),$CFG->timezone),$stat->line1);
                    if (isset($stat->line2)) {
                        $a[] = $stat->line2;
                    }
                    if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) {
                        if (has_capability('report/log:view', context_course::instance($course->id))) {
                            $a[] = '<a href="'.$CFG->wwwroot.'/report/log/index.php?id='.
                                $course->id.'&amp;chooselog=1&amp;showusers=1&amp;showcourses=1&amp;user='******'&amp;date='.usergetmidnight($stat->timeend-(60*60*24)).'">'
                                .get_string('course').' ' .get_string('logs').'</a>&nbsp;';
                        } else {
                            $a[] = '';
                        }
                    }
                    $table->data[] = $a;
                }
            } else {
                $data = array();
                $roles = array();
                $times = array();
                $missedlines = array();
                $coursecontext = context_course::instance($course->id);
                $rolenames = role_fix_names(get_all_roles($coursecontext), $coursecontext, ROLENAME_ALIAS, true);
                foreach ($stats as $stat) {
                    if (!empty($stat->zerofixed)) {
                        $missedlines[] = $stat->timeend;
                    }
                    $data[$stat->timeend][$stat->roleid] = $stat->line1;
                    if ($stat->roleid != 0) {
                        if (!array_key_exists($stat->roleid,$roles)) {
                            $roles[$stat->roleid] = $rolenames[$stat->roleid];
                        }
                    } else {
                        if (!array_key_exists($stat->roleid,$roles)) {
                            $roles[$stat->roleid] = get_string('all');
                        }
                    }
                    if (!array_key_exists($stat->timeend,$times)) {
                        $times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
                    }
                }

                foreach ($data as $time => $rolesdata) {
                    if (in_array($time,$missedlines)) {
                        $rolesdata = array();
                        foreach ($roles as $roleid => $guff) {
                            $rolesdata[$roleid] = 0;
                        }
                    }
                    else {
                        foreach (array_keys($roles) as $r) {
                            if (!array_key_exists($r, $rolesdata)) {
                                $rolesdata[$r] = 0;
                            }
                        }
                    }
                    krsort($rolesdata);
                    $row = array_merge(array($times[$time]),$rolesdata);
                    if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) {
                        if (has_capability('report/log:view', context_course::instance($course->id))) {
                            $row[] = '<a href="'.$CFG->wwwroot.'/report/log/index.php?id='
                                .$course->id.'&amp;chooselog=1&amp;showusers=1&amp;showcourses=1&amp;user='******'&amp;date='.usergetmidnight($time-(60*60*24)).'">'
                                .get_string('course').' ' .get_string('logs').'</a>&nbsp;';
                        } else {
                            $row[] = '';
                        }
                    }
                    $table->data[] = $row;
                }
                krsort($roles);
                $table->head = array_merge($table->head,$roles);
            }
            $table->head[] = get_string('logs');
            //if (!empty($lastrecord)) {
                //$lastrecord[] = $lastlink;
                //$table->data[] = $lastrecord;
            //}
            echo html_writer::table($table);
        }
    }
}
 function get_content()
 {
     global $CFG, $USER, $DB, $OUTPUT;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $icon = '<img src="' . $OUTPUT->pix_url('i/course') . '" class="icon" alt="" />';
     $adminseesall = true;
     if (isset($CFG->block_course_list_adminview)) {
         if ($CFG->block_course_list_adminview == 'own') {
             $adminseesall = false;
         }
     }
     if (empty($CFG->disablemycourses) and isloggedin() and !isguestuser() and !(has_capability('moodle/course:update', context_system::instance()) and $adminseesall)) {
         // Just print My Courses
         if ($courses = enrol_get_my_courses(NULL, 'visible DESC, fullname ASC')) {
             foreach ($courses as $course) {
                 $coursecontext = context_course::instance($course->id);
                 $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
                 $this->content->items[] = "<a {$linkcss} title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . $icon . format_string(get_course_display_name_for_list($course)) . "</a>";
             }
             $this->title = get_string('mycourses');
             /// If we can update any course of the view all isn't hidden, show the view all courses link
             if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
                 $this->content->footer = "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string("fulllistofcourses") . "</a> ...";
             }
         }
         $this->get_remote_courses();
         if ($this->content->items) {
             // make sure we don't return an empty list
             return $this->content;
         }
     }
     $categories = coursecat::get(0)->get_children();
     // Parent = 0   ie top-level categories only
     if ($categories) {
         //Check we have categories
         if (count($categories) > 1 || count($categories) == 1 && $DB->count_records('course') > 200) {
             // Just print top level category links
             foreach ($categories as $category) {
                 $categoryname = $category->get_formatted_name();
                 $linkcss = $category->visible ? "" : " class=\"dimmed\" ";
                 $this->content->items[] = "<a {$linkcss} href=\"{$CFG->wwwroot}/course/index.php?categoryid={$category->id}\">" . $icon . $categoryname . "</a>";
             }
             /// If we can update any course of the view all isn't hidden, show the view all courses link
             if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
                 $this->content->footer .= "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string('fulllistofcourses') . '</a> ...';
             }
             $this->title = get_string('categories');
         } else {
             // Just print course names of single category
             $category = array_shift($categories);
             $courses = get_courses($category->id);
             if ($courses) {
                 foreach ($courses as $course) {
                     $coursecontext = context_course::instance($course->id);
                     $linkcss = $course->visible ? "" : " class=\"dimmed\" ";
                     $this->content->items[] = "<a {$linkcss} title=\"" . format_string($course->shortname, true, array('context' => $coursecontext)) . "\" " . "href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">" . $icon . format_string(get_course_display_name_for_list($course), true, array('context' => context_course::instance($course->id))) . "</a>";
                 }
                 /// If we can update any course of the view all isn't hidden, show the view all courses link
                 if (has_capability('moodle/course:update', context_system::instance()) || empty($CFG->block_course_list_hideallcourseslink)) {
                     $this->content->footer .= "<a href=\"{$CFG->wwwroot}/course/index.php\">" . get_string('fulllistofcourses') . '</a> ...';
                 }
                 $this->get_remote_courses();
             } else {
                 $this->content->icons[] = '';
                 $this->content->items[] = get_string('nocoursesyet');
                 if (has_capability('moodle/course:create', context_coursecat::instance($category->id))) {
                     $this->content->footer = '<a href="' . $CFG->wwwroot . '/course/edit.php?category=' . $category->id . '">' . get_string("addnewcourse") . '</a> ...';
                 }
                 $this->get_remote_courses();
             }
             $this->title = get_string('courses');
         }
     }
     return $this->content;
 }
Example #30
0
        //Course page
    } else {
        $redirecto = $CFG->wwwroot . '/';
    }
    redirect($redirecto, get_string('backupcancelled'));
    //Site page
    exit;
}
//If no course has been selected, show a list of available courses
$navlinks = array();
if (!$id) {
    $navlinks[] = array('name' => $stradministration, 'link' => "{$CFG->wwwroot}/{$CFG->admin}/index.php", 'type' => 'misc');
    $navlinks[] = array('name' => $strcoursebackup, 'link' => null, 'type' => 'misc');
    $navigation = build_navigation($navlinks);
    print_header("{$site->shortname}: {$strcoursebackup}", $site->fullname, $navigation);
    if ($courses = get_courses('all', 'c.shortname', 'c.id,c.shortname,c.fullname')) {
        print_heading(get_string("choosecourse"));
        print_simple_box_start("center");
        foreach ($courses as $course) {
            echo '<a href="backup.php?id=' . $course->id . '">' . format_string($course->fullname) . ' (' . format_string($course->shortname) . ')</a><br />' . "\n";
        }
        print_simple_box_end();
    } else {
        print_heading(get_string("nocoursesyet"));
        print_continue("{$CFG->wwwroot}/{$CFG->admin}/index.php");
    }
    print_footer();
    exit;
}
//Get and check course
if (!($course = get_record("course", "id", $id))) {