コード例 #1
0
function not_found($courseid)
{
    global $CFG;
    header('HTTP/1.0 404 not found');
    print_error('filenotfound', 'error', $CFG->wwwroot . '/course/view.php?id=' . $courseid);
    //this is not displayed on IIS??
}
コード例 #2
0
ファイル: auth.php プロジェクト: JP-Git/moodle
 /**
  * Sign up a new user ready for confirmation.
  * Password is passed in plaintext.
  *
  * @param object $user new user object
  * @param boolean $notify print notice with link and terminate
  */
 function user_signup($user, $notify = true)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     $user->password = hash_internal_user_password($user->password);
     $user->id = $DB->insert_record('user', $user);
     /// Save any custom profile field information
     profile_save_data($user);
     $user = $DB->get_record('user', array('id' => $user->id));
     events_trigger('user_created', $user);
     if (!send_confirmation_email($user)) {
         print_error('auth_emailnoemail', 'auth_email');
     }
     if ($notify) {
         global $CFG, $PAGE, $OUTPUT;
         $emailconfirm = get_string('emailconfirm');
         $PAGE->navbar->add($emailconfirm);
         $PAGE->set_title($emailconfirm);
         $PAGE->set_heading($PAGE->course->fullname);
         echo $OUTPUT->header();
         notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
     } else {
         return true;
     }
 }
コード例 #3
0
 function moodleform_mod($current, $section, $cm, $course)
 {
     global $CFG;
     $this->current = $current;
     $this->_instance = $current->instance;
     $this->_section = $section;
     $this->_cm = $cm;
     if ($this->_cm) {
         $this->context = context_module::instance($this->_cm->id);
     } else {
         $this->context = context_course::instance($course->id);
     }
     // Set the course format.
     require_once $CFG->dirroot . '/course/format/lib.php';
     $this->courseformat = course_get_format($course);
     // Guess module name
     $matches = array();
     if (!preg_match('/^mod_([^_]+)_mod_form$/', get_class($this), $matches)) {
         debugging('Use $modname parameter or rename form to mod_xx_mod_form, where xx is name of your module');
         print_error('unknownmodulename');
     }
     $this->_modname = $matches[1];
     $this->init_features();
     parent::moodleform('modedit.php');
 }
コード例 #4
0
ファイル: mod_form.php プロジェクト: evltuma/moodle
 function definition()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     $strrequired = get_string('required');
     //-------------------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('name'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEANHTML);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     if (!($options = $DB->get_records_menu("survey", array("template" => 0), "name", "id, name"))) {
         print_error('cannotfindsurveytmpt', 'survey');
     }
     foreach ($options as $id => $name) {
         $options[$id] = get_string($name, "survey");
     }
     $options = array('' => get_string('choose') . '...') + $options;
     $mform->addElement('select', 'template', get_string("surveytype", "survey"), $options);
     $mform->addRule('template', $strrequired, 'required', null, 'client');
     $mform->addHelpButton('template', 'surveytype', 'survey');
     $this->standard_intro_elements(get_string('customintro', 'survey'));
     $this->standard_coursemodule_elements();
     //-------------------------------------------------------------------------------
     // buttons
     $this->add_action_buttons();
 }
コード例 #5
0
ファイル: file.php プロジェクト: nicolasconnault/moodle2.0
function question_attempt_not_found()
{
    global $CFG;
    header('HTTP/1.0 404 not found');
    print_error('filenotfound', 'error', $CFG->wwwroot);
    //this is not displayed on IIS??
}
コード例 #6
0
ファイル: locallib.php プロジェクト: rosenclever/moodle
/**
 * Creates an object to represent a new attempt at a quiz
 *
 * Creates an attempt object to represent an attempt at the quiz by the current
 * user starting at the current time. The ->id field is not set. The object is
 * NOT written to the database.
 *
 * @param object $quiz the quiz to create an attempt for.
 * @param int $attemptnumber the sequence number for the attempt.
 * @param object $lastattempt the previous attempt by this user, if any. Only needed
 *         if $attemptnumber > 1 and $quiz->attemptonlast is true.
 * @param int $timenow the time the attempt was started at.
 * @param bool $ispreview whether this new attempt is a preview.
 *
 * @return object the newly created attempt object.
 */
function quiz_create_attempt($quiz, $attemptnumber, $lastattempt, $timenow, $ispreview = false)
{
    global $USER;
    if ($attemptnumber == 1 || !$quiz->attemptonlast) {
        // We are not building on last attempt so create a new attempt.
        $attempt = new stdClass();
        $attempt->quiz = $quiz->id;
        $attempt->userid = $USER->id;
        $attempt->preview = 0;
        $attempt->layout = quiz_clean_layout($quiz->questions, true);
        if ($quiz->shufflequestions) {
            $attempt->layout = quiz_repaginate($attempt->layout, $quiz->questionsperpage, true);
        }
    } else {
        // Build on last attempt.
        if (empty($lastattempt)) {
            print_error('cannotfindprevattempt', 'quiz');
        }
        $attempt = $lastattempt;
    }
    $attempt->attempt = $attemptnumber;
    $attempt->timestart = $timenow;
    $attempt->timefinish = 0;
    $attempt->timemodified = $timenow;
    // If this is a preview, mark it as such.
    if ($ispreview) {
        $attempt->preview = 1;
    }
    return $attempt;
}
コード例 #7
0
ファイル: fcFPP.php プロジェクト: ajv/Offline-Caching
 function open()
 {
     if ($this->_debug) {
         echo "Connecting to host ";
     }
     $host = $this->_hostname;
     $port = $this->_port;
     if ($this->_debug) {
         echo "[{$host}:{$port}]..";
     }
     // open the connection to the FirstClass server
     $conn = fsockopen($host, $port, $errno, $errstr, 5);
     if (!$conn) {
         print_error('auth_fcconnfail', 'auth_fc', '', array($errno, $errstr));
         return false;
     }
     // We are connected
     if ($this->_debug) {
         echo "connected!";
     }
     // Read connection message.
     $line = fgets($conn);
     //+0
     $line = fgets($conn);
     //new line
     // store the connection in this class, so we can use it later
     $this->_conn =& $conn;
     return true;
 }
コード例 #8
0
/**
 * This page export the game millionaire to html
 * 
 * @author  bdaloukas
 * @version $Id: exporthtml_millionaire.php,v 1.14 2012/07/25 11:16:03 bdaloukas Exp $
 * @package game
 **/
function game_millionaire_html_getquestions($game, $context, &$maxanswers, &$countofquestions, &$retfeedback, $destdir, &$files)
{
    global $CFG, $DB, $USER;
    $maxanswers = 0;
    $countofquestions = 0;
    $files = array();
    if ($game->sourcemodule != 'quiz' and $game->sourcemodule != 'question') {
        print_error(get_string('millionaire_sourcemodule_must_quiz_question', 'game', get_string('modulename', 'quiz')) . ' ' . get_string('modulename', $game->sourcemodule));
    }
    if ($game->sourcemodule == 'quiz') {
        if ($game->quizid == 0) {
            print_error(get_string('must_select_quiz', 'game'));
        }
        $select = "qtype='multichoice' AND quiz='{$game->quizid}' " . " AND qqi.question=q.id";
        $table = "{question} q,{quiz_question_instances} qqi";
    } else {
        if ($game->questioncategoryid == 0) {
            print_error(get_string('must_select_questioncategory', 'game'));
        }
        //include subcategories
        $select = 'category=' . $game->questioncategoryid;
        if ($game->subcategories) {
            $cats = question_categorylist($game->questioncategoryid);
            if (strpos($cats, ',') > 0) {
                $select = 'category in (' . $cats . ')';
            }
        }
        $select .= " AND qtype='multichoice'";
        $table = "{question} q";
    }
    $select .= " AND q.hidden=0";
    $sql = "SELECT q.id as id, q.questiontext FROM {$table} WHERE {$select}";
    $recs = $DB->get_records_sql($sql);
    $ret = '';
    $retfeedback = '';
    foreach ($recs as $rec) {
        $recs2 = $DB->get_records('question_answers', array('question' => $rec->id), 'fraction DESC', 'id,answer,feedback');
        //Must parse the questiontext and get the name of files.
        $line = $rec->questiontext;
        $line = game_export_split_files($game->course, $context, 'questiontext', $rec->id, $rec->questiontext, $destdir, $files);
        $linefeedback = '';
        foreach ($recs2 as $rec2) {
            $line .= '#' . str_replace(array('"', '#'), array("'", ' '), game_export_split_files($game->course, $context, 'answer', $rec2->id, $rec2->answer, $destdir, $files));
            $linefeedback .= '#' . str_replace(array('"', '#'), array("'", ' '), $rec2->feedback);
        }
        if ($ret != '') {
            $ret .= ",\r";
        }
        $ret .= '"' . base64_encode($line) . '"';
        if ($retfeedback != '') {
            $retfeedback .= ",\r";
        }
        $retfeedback .= '"' . base64_encode($linefeedback) . '"';
        if (count($recs2) > $maxanswers) {
            $maxanswers = count($recs2);
        }
        $countofquestions++;
    }
    return $ret;
}
コード例 #9
0
ファイル: auth.php プロジェクト: r007/PMoodle
 /**
  * Returns the user information for 'external' users. In this case the
  * attributes provided by Shibboleth
  *
  * @return array $result Associative array of user data
  */
 function get_userinfo($username)
 {
     // reads user information from shibboleth attributes and return it in array()
     global $CFG;
     // Check whether we have got all the essential attributes
     if (empty($_SERVER[$this->config->user_attribute])) {
         print_error('shib_not_all_attributes_error', 'auth', '', "'" . $this->config->user_attribute . "' ('" . $_SERVER[$this->config->user_attribute] . "'), '" . $this->config->field_map_firstname . "' ('" . $_SERVER[$this->config->field_map_firstname] . "'), '" . $this->config->field_map_lastname . "' ('" . $_SERVER[$this->config->field_map_lastname] . "') and '" . $this->config->field_map_email . "' ('" . $_SERVER[$this->config->field_map_email] . "')");
     }
     $attrmap = $this->get_attributes();
     $result = array();
     $search_attribs = array();
     foreach ($attrmap as $key => $value) {
         // Check if attribute is present
         if (!isset($_SERVER[$value])) {
             $result[$key] = '';
             continue;
         }
         // Make usename lowercase
         if ($key == 'username') {
             $result[$key] = strtolower($this->get_first_string($_SERVER[$value]));
         } else {
             $result[$key] = $this->get_first_string($_SERVER[$value]);
         }
     }
     // Provide an API to modify the information to fit the Moodle internal
     // data representation
     if ($this->config->convert_data && $this->config->convert_data != '' && is_readable($this->config->convert_data)) {
         // Include a custom file outside the Moodle dir to
         // modify the variable $moodleattributes
         include $this->config->convert_data;
     }
     return $result;
 }
コード例 #10
0
ファイル: ModuleManage.php プロジェクト: dariogs/moosh
 public function execute()
 {
     global $DB;
     $action = $this->arguments[0];
     $modulename = $this->arguments[1];
     // name of the module (in English)
     // Does module exists?
     if (!empty($modulename)) {
         if (!($module = $DB->get_record('modules', array('name' => $modulename)))) {
             print_error('moduledoesnotexist', 'error');
         }
     }
     switch ($action) {
         case 'show':
             $DB->set_field('modules', 'visible', '1', array('id' => $module->id));
             // Show module.
             break;
         case 'hide':
             $DB->set_field('modules', 'visible', '0', array('id' => $module->id));
             // Hide module.
             break;
         case 'delete':
             // Delete module from DB. Should we also delete it from disk?
             if ($this->expandedOptions['force']) {
                 // Delete module from disk too!
             }
             break;
     }
 }
コード例 #11
0
ファイル: lib.php プロジェクト: nicolasconnault/moodle2.0
 /**
  * Constructor for the base resource class
  *
  * Constructor for the base resource class.
  * If cmid is set create the cm, course, resource objects.
  * and do some checks to make sure people can be here, and so on.
  *
  * @param cmid   integer, the current course module id - not set for new resources
  */
 function resource_base($cmid = 0)
 {
     global $CFG, $COURSE, $DB;
     $this->navlinks = array();
     if ($cmid) {
         if (!($this->cm = get_coursemodule_from_id('resource', $cmid))) {
             print_error('invalidcoursemodule');
         }
         if (!($this->course = $DB->get_record("course", array("id" => $this->cm->course)))) {
             print_error('coursemisconf');
         }
         if (!($this->resource = $DB->get_record("resource", array("id" => $this->cm->instance)))) {
             print_error('invalidid', 'resource');
         }
         $this->strresource = get_string("modulename", "resource");
         $this->strresources = get_string("modulenameplural", "resource");
         if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) {
             $pagetitle = strip_tags($this->course->shortname . ': ' . $this->strresource);
             $navigation = build_navigation($this->navlinks, $this->cm);
             print_header($pagetitle, $this->course->fullname, $navigation, "", "", true, '', navmenu($this->course, $this->cm));
             notice(get_string("activityiscurrentlyhidden"), "{$CFG->wwwroot}/course/view.php?id={$this->course->id}");
         }
     } else {
         $this->course = $COURSE;
     }
 }
コード例 #12
0
 /**
  * Loads the $options array into class properties
  * Possible options (these options are in addition to the standard autocomplete options
  *
  * contextlevel               The ELIS context level to search.possible values: 1001-1006
  *
  * instance fields            A list of fields from the instance table to search on. This should be an array like
  *                            (fieldname => label). For example array('idnumber'=>'IDNumber','firstname'=>'First Name')
  *
  * forced_custom_field_vals   An array like field_shortname => value that can be used to restrict results to
  *                            ones that have specific values for specific custom fields. Note that any fields
  *                            you enter here MUST be valid fields for the specified context level, and must be
  *                            included in the 'custom_fields' option (or have the 'custom_fields' set to '*')
  *
  * custom_fields              A list of the shortnames of custom fields to allow for searching. Note that this is NOT
  *                            the fields which will end up being searched/displayed - but those available for searching.
  *                            The actual list of fields to search/display is configured by an administration using
  *                            the configuration interface.
  *                            This can be an array of field shortnames, or '*' for all applicable fields.
  *
  * @param  array  $options   The options array passed into the class
  */
 public function load_options($options)
 {
     global $CFG, $DB;
     //instance fields - fields to search from the instance's table
     if (!isset($options['instance_fields'])) {
         print_error('autocomplete_noinstance', 'local_elisprogram');
     }
     $this->instance_fields = $options['instance_fields'];
     //get instance contextid
     if (!isset($options['contextlevel']) || !isset($this->context_level_map[$options['contextlevel']])) {
         print_error('autocomplete_nocontext', 'local_elisprogram');
     }
     $this->instancetable = $this->tablemap[$this->context_level_map[$options['contextlevel']]];
     $this->contextlevel = $options['contextlevel'];
     if (!empty($options['forced_custom_field_vals']) && is_array($options['forced_custom_field_vals'])) {
         $this->forced_custom_vals = $options['forced_custom_field_vals'];
     }
     //fetch info for custom fields
     if (!empty($options['custom_fields']) && (is_array($options['custom_fields']) || $options['custom_fields'] === '*')) {
         $sql = 'SELECT f.id, f.name, f.shortname, f.datatype ' . 'FROM {local_eliscore_field} f' . ' JOIN {local_eliscore_field_clevels} c ON c.fieldid=f.id' . ' WHERE (f.datatype="char" OR f.datatype="text") AND c.contextlevel=' . $options['contextlevel'];
         if (is_array($options['custom_fields'])) {
             $ids = implode('","', $options['custom_fields']);
             $sql .= ' AND f.shortname IN ("' . $ids . '")';
         }
         $custom_fields = $DB->get_records_sql($sql);
         if (is_array($custom_fields)) {
             foreach ($custom_fields as $field) {
                 $field_info = array('fieldid' => $field->id, 'label' => $field->name, 'shortname' => $field->shortname, 'datatype' => $field->datatype);
                 $this->custom_fields[$field->shortname] = $field_info;
             }
         }
     }
 }
コード例 #13
0
ファイル: lib.php プロジェクト: jcharaoui/moodle-cegep
function cegep_sisdb_init()
{
    global $CFG, $enroldb, $sisdb, $sisdbsource;
    // Verify if external database enrolment is enabled
    if (!in_array('database', explode(',', $CFG->enrol_plugins_enabled))) {
        print_error('errorenroldbnotavailable', 'block_cegep');
    }
    // Prepare external enrolment database connection
    if ($enroldb = enroldb_connect()) {
        $enroldb->Execute("SET NAMES 'utf8'");
    } else {
        error_log('[ENROL_DB] Could not make a connection');
        print_error('dbconnectionfailed', 'error');
    }
    // Prepare external SIS database connection
    if ($sisdb = sisdb_connect()) {
        $sisdb->Execute("SET NAMES 'utf8'");
    } else {
        error_log('[SIS_DB] Could not make a connection');
        print_error('dbconnectionfailed', 'error');
    }
    // Prepare external SIS source database connection
    if ($sisdbsource = sisdbsource_connect()) {
        //$sisdbsource->Execute("SET NAMES 'utf8'");
    } else {
        error_log('[SIS_DB_SOURCE] Could not make a connection');
        print_error('dbconnectionfailed', 'error');
    }
}
コード例 #14
0
function organizer_make_infobox($params, $organizer, $context, &$popups)
{
    global $PAGE;
    user_preference_allow_ajax_update('mod_organizer_showpasttimeslots', PARAM_BOOL);
    user_preference_allow_ajax_update('mod_organizer_showmyslotsonly', PARAM_BOOL);
    user_preference_allow_ajax_update('mod_organizer_showfreeslotsonly', PARAM_BOOL);
    $PAGE->requires->js_init_call('M.mod_organizer.init_infobox');
    $output = '';
    if ($organizer->alwaysshowdescription || time() > $organizer->allowregistrationsfromdate) {
        $output = organizer_make_description_section($organizer);
    }
    switch ($params['mode']) {
        case ORGANIZER_TAB_APPOINTMENTS_VIEW:
            break;
        case ORGANIZER_TAB_STUDENT_VIEW:
            $output .= organizer_make_myapp_section($params, $organizer, organizer_get_last_user_appointment($organizer), $popups);
            break;
        case ORGANIZER_TAB_REGISTRATION_STATUS_VIEW:
            $output .= organizer_make_reminder_section($params, $context);
            break;
        default:
            print_error("Wrong view mode: {$params['mode']}");
    }
    $output .= organizer_make_slotoptions_section($params);
    $output .= organizer_make_messages_section($params);
    return $output;
}
コード例 #15
0
 public function execute_query($sql, $cursortype = SQLSRV_CURSOR_FORWARD)
 {
     $sqldirective = strtoupper(substr($sql, 0, strpos($sql, ' ')));
     switch ($sqldirective) {
         case 'SELECT':
             $type = SQL_QUERY_SELECT;
             break;
         case 'INSERT':
             $type = SQL_QUERY_INSERT;
             break;
         case 'UPDATE':
             $type = SQL_QUERY_UPDATE;
             break;
         case 'DELETE':
             $type = SQL_QUERY_UPDATE;
             break;
         default:
             print_error('unknownsqldirective', 'block_vmoodle');
             return false;
     }
     $this->query_start($sql, null, $type);
     $result = sqlsrv_query($this->sqlsrv, $sql, null, array('Scrollable' => $cursortype));
     $this->query_end($result);
     return $result;
 }
コード例 #16
0
function game_importsnakes_do($newrec)
{
    global $DB;
    if (!$DB->insert_record('game_snakes_database', $newrec)) {
        print_error("Can't insert to table game_snakes_database");
    }
}
コード例 #17
0
ファイル: ldap.inc.php プロジェクト: skive/observium
function ldap_init()
{
    global $ds, $config;
    if (!is_resource($ds)) {
        print_debug("LDAP[Connecting to " . implode(",", $config['auth_ldap_server']) . "]");
        $ds = @ldap_connect(implode(",", $config['auth_ldap_server']), $config['auth_ldap_port']);
        print_debug("LDAP[Connected]");
        if ($config['auth_ldap_starttls'] && ($config['auth_ldap_starttls'] == 'optional' || $config['auth_ldap_starttls'] == 'require')) {
            $tls = ldap_start_tls($ds);
            if ($config['auth_ldap_starttls'] == 'require' && $tls == FALSE) {
                session_logout();
                print_error("Fatal error: LDAP TLS required but not successfully negotiated [" . ldap_error($ds) . "]");
                exit;
            }
        }
        if ($config['auth_ldap_referrals']) {
            ldap_set_option($ds, LDAP_OPT_REFERRALS, $config['auth_ldap_referrals']);
            print_debug("LDAP[Referrals][Set to " . $config['auth_ldap_referrals'] . "]");
        } else {
            ldap_set_option($ds, LDAP_OPT_REFERRALS, FALSE);
            print_debug("LDAP[Referrals][Disabled]");
        }
        if ($config['auth_ldap_version']) {
            ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $config['auth_ldap_version']);
            print_debug("LDAP[Version][Set to " . $config['auth_ldap_version'] . "]");
        }
    }
}
コード例 #18
0
ファイル: mailing.php プロジェクト: jerab/moodle-mod-praxe
 /**
  * Builds and returns the body of the email notification in plain text.
  *
  * @param object $post
  * @param object $userto
  * @return string The email body in plain text format.
  */
 public function makeMailText($post, $userto)
 {
     global $CFG, $cm;
     $praxe = praxe_record::getData();
     if (!isset($userto->viewfullnames[$praxe->id])) {
         if (!($cm = get_coursemodule_from_instance('praxe', $praxe->id, $this->course->id))) {
             print_error('Course Module ID was incorrect');
         }
         $modcontext = context_module::instance($cm->id);
         $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
     } else {
         $viewfullnames = $userto->viewfullnames[$praxe->id];
     }
     //$by = New stdClass;
     //$by->name = fullname($userfrom, $viewfullnames);
     //$by->date = userdate($post->modified, "", $userto->timezone);
     //$strbynameondate = get_string('bynameondate', 'forum', $by);
     $strpraxes = get_string('modulenameplural', 'praxe');
     $posttext = '';
     $posttext = $this->course->shortname . " -> " . $strpraxes . " -> " . format_string($praxe->name, true);
     $posttext .= "\n---------------------------------------------------------------------\n";
     $posttext .= format_string($this->subject, true);
     //$posttext .= "\n".$strbynameondate."\n";
     $posttext .= "\n---------------------------------------------------------------------\n";
     $posttext .= format_text_email(trusttext_strip($post), FORMAT_PLAIN);
     $posttext .= "\n\n---------------------------------------------------------------------\n";
     $site = get_site();
     foreach ($this->linkstofoot as $link) {
         $posttext .= $link->text . ": " . $link->link . "\t";
         //$posttext .= get_string('confirmorrefusestudent','praxe').": ".$CFG->wwwroot.'/course/view.php?id='.$cm->id."\n\n";
     }
     $posttext .= "\n\n" . $site->shortname . ": " . $CFG->wwwroot . "\n";
     return $posttext;
 }
コード例 #19
0
 public static function get_jumptooptions($firstpage, lesson $lesson)
 {
     global $DB, $PAGE;
     $jump = array();
     $jump[0] = get_string("thispage", "lesson");
     $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson");
     $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson");
     $jump[LESSON_EOL] = get_string("endoflesson", "lesson");
     $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson");
     $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson");
     $jump[LESSON_RANDOMBRANCH] = get_string("randombranch", "lesson");
     if (!$firstpage) {
         if (!($apageid = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "prevpageid" => 0)))) {
             print_error('cannotfindfirstpage', 'lesson');
         }
         while (true) {
             if ($apageid) {
                 $title = $DB->get_field("lesson_pages", "title", array("id" => $apageid));
                 $jump[$apageid] = $title;
                 $apageid = $DB->get_field("lesson_pages", "nextpageid", array("id" => $apageid));
             } else {
                 // last page reached
                 break;
             }
         }
     }
     return $jump;
 }
コード例 #20
0
ファイル: default.php プロジェクト: nicolasconnault/moodle2.0
 function expand_blocks($tag)
 {
     // get block $names
     //  [1] the full block name (including optional leading 'str' or 'incl')
     //  [2] leading 'incl' or 'str', if any
     //  [3] the real block name ([1] without [2])
     $search = '/\\[\\/((incl|str)?((?:\\w|\\.)+))\\]/';
     preg_match_all($search, $this->{$tag}, $names);
     $i_max = count($names[0]);
     for ($i = 0; $i < $i_max; $i++) {
         $method = $this->parent->template_dir . '_expand_' . str_replace('.', '', $names[3][$i]);
         if (method_exists($this, $method)) {
             eval('$value=$this->' . $method . '();');
             $search = '/\\[' . $names[1][$i] . '\\](.*?)\\[\\/' . $names[1][$i] . '\\]/s';
             preg_match_all($search, $this->{$tag}, $blocks);
             $ii_max = count($blocks[0]);
             for ($ii = 0; $ii < $ii_max; $ii++) {
                 $replace = empty($value) ? '' : $blocks[1][$ii];
                 $this->{$tag} = str_replace($blocks[0][$ii], $replace, $this->{$tag});
             }
         } else {
             print_error('cannotfindmethod', 'hotpot', $this->parent->course_homeurl, $method);
         }
     }
 }
コード例 #21
0
function filter_texwjax_get_executable($debug = false)
{
    global $CFG;
    $error_message1 = "Your system is not configured to run mimeTeX. You need to download the appropriate<br />" . "executable for you " . PHP_OS . " platform from <a href=\"http://moodle.org/download/mimetex/\">" . "http://moodle.org/download/mimetex/</a>, or obtain the C source<br /> " . "from <a href=\"http://www.forkosh.com/mimetex.zip\">" . "http://www.forkosh.com/mimetex.zip</a>, compile it and " . "put the executable into your<br /> moodle/filter/texwjax/ directory.";
    $error_message2 = "Custom mimetex is not executable!<br /><br />";
    if (PHP_OS == "WINNT" || PHP_OS == "WIN32" || PHP_OS == "Windows") {
        return "{$CFG->dirroot}/filter/texwjax/mimetex.exe";
    }
    if ($pathmimetex = get_config('filter_texwjax', 'pathmimetex')) {
        if (is_executable($pathmimetex)) {
            return $pathmimetex;
        } else {
            print_error('mimetexnotexecutable', 'error');
        }
    }
    $custom_commandpath = "{$CFG->dirroot}/filter/texwjax/mimetex";
    if (file_exists($custom_commandpath)) {
        if (is_executable($custom_commandpath)) {
            return $custom_commandpath;
        } else {
            print_error('mimetexnotexecutable', 'error');
        }
    }
    switch (PHP_OS) {
        case "Linux":
            return "{$CFG->dirroot}/filter/texwjax/mimetex.linux";
        case "Darwin":
            return "{$CFG->dirroot}/filter/texwjax/mimetex.darwin";
        case "FreeBSD":
            return "{$CFG->dirroot}/filter/texwjax/mimetex.freebsd";
    }
    print_error('mimetexisnotexist', 'error');
}
コード例 #22
0
 function execute($finalelements, $data)
 {
     if ($this->report->type != 'sql') {
         return $finalelements;
     }
     $filter_starttime = optional_param('filter_starttime', 0, PARAM_RAW);
     $filter_endtime = optional_param('filter_endtime', 0, PARAM_RAW);
     if (!$filter_starttime || !$filter_endtime) {
         return $finalelements;
     }
     $filter_starttime = make_timestamp($filter_starttime['year'], $filter_starttime['month'], $filter_starttime['day']);
     $filter_endtime = make_timestamp($filter_endtime['year'], $filter_endtime['month'], $filter_endtime['day']);
     $operators = array('<', '>', '<=', '>=');
     if (preg_match("/%%FILTER_STARTTIME:([^%]+)%%/i", $finalelements, $output)) {
         list($field, $operator) = split(':', $output[1]);
         if (!in_array($operator, $operators)) {
             print_error('nosuchoperator');
         }
         $replace = ' AND ' . $field . ' ' . $operator . ' ' . $filter_starttime;
         $finalelements = str_replace('%%FILTER_STARTTIME:' . $output[1] . '%%', $replace, $finalelements);
     }
     if (preg_match("/%%FILTER_ENDTIME:([^%]+)%%/i", $finalelements, $output)) {
         list($field, $operator) = split(':', $output[1]);
         if (!in_array($operator, $operators)) {
             print_error('nosuchoperator');
         }
         $replace = ' AND ' . $field . ' ' . $operator . ' ' . $filter_endtime;
         $finalelements = str_replace('%%FILTER_ENDTIME:' . $output[1] . '%%', $replace, $finalelements);
     }
     $finalelements = str_replace('%STARTTIME%%', $filter_starttime, $finalelements);
     $finalelements = str_replace('%ENDTIME%%', $filter_endtime, $finalelements);
     return $finalelements;
 }
コード例 #23
0
ファイル: locallib.php プロジェクト: evltuma/moodle
/**
 * Export one book as IMSCP package
 *
 * @param stdClass $book book instance
 * @param context_module $context
 * @return bool|stored_file
 */
function booktool_exportimscp_build_package($book, $context)
{
    global $DB;
    $fs = get_file_storage();
    if ($packagefile = $fs->get_file($context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip')) {
        return $packagefile;
    }
    // fix structure and test if chapters present
    if (!book_preload_chapters($book)) {
        print_error('nochapters', 'booktool_exportimscp');
    }
    // prepare temp area with package contents
    booktool_exportimscp_prepare_files($book, $context);
    $packer = get_file_packer('application/zip');
    $areafiles = $fs->get_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision, "sortorder, itemid, filepath, filename", false);
    $files = array();
    foreach ($areafiles as $file) {
        $path = $file->get_filepath() . $file->get_filename();
        $path = ltrim($path, '/');
        $files[$path] = $file;
    }
    unset($areafiles);
    $packagefile = $packer->archive_to_storage($files, $context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip');
    // drop temp area
    $fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision);
    // delete older versions
    $sql = "SELECT DISTINCT itemid\n              FROM {files}\n             WHERE contextid = :contextid AND component = 'booktool_exportimscp' AND itemid < :revision";
    $params = array('contextid' => $context->id, 'revision' => $book->revision);
    $revisions = $DB->get_records_sql($sql, $params);
    foreach ($revisions as $rev => $unused) {
        $fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $rev);
        $fs->delete_area_files($context->id, 'booktool_exportimscp', 'package', $rev);
    }
    return $packagefile;
}
コード例 #24
0
ファイル: reportlib.php プロジェクト: JackCanada/moodle-hacks
/**
 * Load the question data necessary in the reports.
 * - Remove description questions.
 * - Order questions in order that they are in the quiz
 * - Add question numbers.
 * - Add grade from quiz_questions_instance
 */
function quiz_report_load_questions($quiz)
{
    global $CFG;
    $questionlist = quiz_questions_in_quiz($quiz->questions);
    //In fact in most cases the id IN $questionlist below is redundant
    //since we are also doing a JOIN on the qqi table. But will leave it in
    //since this double check will probably do no harm.
    if (!($questions = get_records_sql("SELECT q.*, qqi.grade " . "FROM {$CFG->prefix}question q, " . "{$CFG->prefix}quiz_question_instances qqi " . "WHERE q.id IN ({$questionlist}) AND " . "qqi.question = q.id AND " . "qqi.quiz =" . $quiz->id))) {
        print_error('No questions found');
    }
    //Now we have an array of questions from a quiz we work out there question nos and remove
    //questions with zero length ie. description questions etc.
    //also put questions in order.
    $number = 1;
    $realquestions = array();
    $questionids = explode(',', $questionlist);
    foreach ($questionids as $id) {
        if ($questions[$id]->length) {
            // Ignore questions of zero length
            $realquestions[$id] = $questions[$id];
            $realquestions[$id]->number = $number;
            $number += $questions[$id]->length;
        }
    }
    return $realquestions;
}
コード例 #25
0
ファイル: CourseReset.php プロジェクト: dariogs/moosh
 protected function loadDefaults()
 {
     global $DB, $CFG;
     if (!($course = $DB->get_record('course', array('id' => $this->arguments[0])))) {
         print_error("invalidcourseid");
     }
     require_login($course);
     $defaults = array('reset_events' => 1, 'reset_roles_local' => 1, 'reset_gradebook_grades' => 1, 'reset_notes' => 1);
     if ($allmods = $DB->get_records('modules')) {
         foreach ($allmods as $mod) {
             $modname = $mod->name;
             $modfile = $this->topDir . "/mod/{$modname}/lib.php";
             $mod_reset_course_form_defaults = $modname . '_reset_course_form_defaults';
             if (file_exists($modfile)) {
                 //echo "$modfile\n";
                 include_once $modfile;
                 if (function_exists($mod_reset_course_form_defaults)) {
                     if ($moddefs = $mod_reset_course_form_defaults($this->course)) {
                         $defaults = $defaults + $moddefs;
                     }
                 }
             }
         }
     }
     return (object) $defaults;
 }
コード例 #26
0
 function print_filter(&$mform, $data)
 {
     global $DB, $CFG;
     $columns = $DB->get_columns('course');
     $filteroptions = array();
     $filteroptions[''] = get_string('choose');
     $coursecolumns = array();
     foreach ($columns as $c) {
         $coursecolumns[$c->name] = $c->name;
     }
     if (!isset($coursecolumns[$data->field])) {
         print_error('nosuchcolumn');
     }
     $reportclassname = 'report_' . $this->report->type;
     $reportclass = new $reportclassname($this->report);
     $components = cr_unserialize($this->report->components);
     $conditions = $components['conditions'];
     $courselist = $reportclass->elements_by_conditions($conditions);
     if (!empty($courselist)) {
         if ($rs = $DB->get_recordset_sql('SELECT DISTINCT(' . $data->field . ') as ufield FROM {course} WHERE ' . $data->field . ' <> "" ORDER BY ufield ASC', null)) {
             foreach ($rs as $u) {
                 $filteroptions[base64_encode($u->ufield)] = $u->ufield;
             }
             $rs->close();
         }
     }
     $mform->addElement('select', 'filter_fcoursefield_' . $data->field, get_string($data->field), $filteroptions);
     $mform->setType('filter_courses', PARAM_INT);
 }
コード例 #27
0
function block_openshare_updategroup($courseid, $groupid)
{
    $sql = 'SELECT u.id FROM mdl_user u 
	JOIN mdl_role_assignments ra ON ra.userid = u.id 
	JOIN mdl_role r ON ra.roleid = r.id 
	JOIN mdl_context con ON ra.contextid = con.id 
	JOIN mdl_course c ON c.id = con.instanceid AND con.contextlevel = 50 WHERE (r.shortname = \'student\' OR r.shortname = \'teacher\' OR r.shortname = \'editingteacher\' OR r.shortname = \'coursecreator\') AND c.id = ' . $courseid;
    $rs = get_recordset_sql($sql);
    if (!empty($rs)) {
        while ($rec = rs_fetch_next_record($rs)) {
            //prep dataobject for door
            $groupenroll = new object();
            $groupenroll->timeadded = time();
            $groupenroll->groupid = $groupid;
            $groupenroll->userid = $rec->id;
            $ingroup = get_record("groups_members", "groupid", $groupid, "userid", $rec->id);
            if (empty($ingroup)) {
                insert_record("groups_members", $groupenroll);
                print 'updated' . $groupenroll->groupid . $groupenroll->userid . '<br/>';
            }
        }
    } else {
        print_error("No users in this course!");
    }
    // Close the recordset to save memory
    rs_close($rs);
}
コード例 #28
0
    function execute($finalelements, $data) {

        $filter_searchtext = optional_param('filter_searchtext', '', PARAM_RAW);
        $operators = array('=', '<', '>', '<=', '>=', '~');

        if (!$filter_searchtext)
            return $finalelements;

        if ($this->report->type != 'sql') {
            return array($filter_searchtext);
        } else {
            if (preg_match("/%%FILTER_SEARCHTEXT:([^%]+)%%/i", $finalelements, $output)) {
                list($field, $operator) = preg_split('/:/', $output[1]);
                if (!in_array($operator, $operators))
                    print_error('nosuchoperator');
                if ($operator == '~') {
                    $replace = " AND " . $field . " LIKE '%" . $filter_searchtext . "%'";
                } else {
                    $replace = ' AND ' . $field . ' ' . $operator . ' ' . $filter_searchtext;
                }
                return str_replace('%%FILTER_SEARCHTEXT:' . $output[1] . '%%', $replace, $finalelements);
            }
        }
        return $finalelements;
    }
コード例 #29
0
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 function question_dataset_dependent_items_form($submiturl, $question, $regenerate)
 {
     global $QTYPES, $SESSION, $CFG, $DB;
     $this->regenerate = $regenerate;
     $this->question = $question;
     $this->qtypeobj =& $QTYPES[$this->question->qtype];
     // Validate the question category.
     if (!($category = $DB->get_record('question_categories', array('id' => $question->category)))) {
         print_error('categorydoesnotexist', 'question', $returnurl);
     }
     $this->category = $category;
     $this->categorycontext = get_context_instance_by_id($category->contextid);
     //get the dataset defintions for this question
     if (empty($question->id)) {
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, $SESSION->calculated->definitionform->dataset);
     } else {
         if (empty($question->options)) {
             $this->get_question_options($question);
         }
         $this->datasetdefs = $this->qtypeobj->get_dataset_definitions($question->id, array());
     }
     foreach ($this->datasetdefs as $datasetdef) {
         // Get maxnumber
         if ($this->maxnumber == -1 || $datasetdef->itemcount < $this->maxnumber) {
             $this->maxnumber = $datasetdef->itemcount;
         }
     }
     foreach ($this->datasetdefs as $defid => $datasetdef) {
         if (isset($datasetdef->id)) {
             $this->datasetdefs[$defid]->items = $this->qtypeobj->get_database_dataset_items($datasetdef->id);
         }
     }
     parent::moodleform($submiturl);
 }
コード例 #30
0
ファイル: view_headm.php プロジェクト: jerab/moodle-mod-praxe
 function praxe_view_headm()
 {
     global $USER, $cm, $tab, $tab_modes, $CFG, $context;
     //$praxeaction = optional_param('praxeaction', null, PARAM_ALPHAEXT);
     //$school = optional_param('school', null, PARAM_INT);
     switch ($tab) {
         case PRAXE_TAB_HEADM_HOME:
             //$schoolid = optional_param('schoolid', 0, PARAM_INT);
             if ($schools = praxe_get_schools($USER->id)) {
                 $this->content .= self::show_schools($schools, array('mode' => $tab_modes['headm'][PRAXE_TAB_HEADM_EDITSCHOOL]));
             } else {
                 $this->content .= get_string('noschoolsavailable', 'praxe');
             }
             break;
         case PRAXE_TAB_HEADM_ADDSCHOOL:
             self::addschool_form();
             break;
         case PRAXE_TAB_HEADM_TEACHERS:
             $schoolid = optional_param('schoolid', 0, PARAM_INT);
             if ($schoolid > 0) {
                 $this->content .= self::school_teachers_by_schools($USER->id, $schoolid);
             } else {
                 $this->content .= self::school_teachers_by_schools($USER->id);
             }
             break;
         case PRAXE_TAB_HEADM_LOCATIONS:
             $schoolid = optional_param('schoolid', 0, PARAM_INT);
             if ($schoolid > 0) {
                 $this->content .= self::show_locations($schoolid);
             } else {
                 $this->content .= self::show_locations(null, $USER->id);
                 $this->content .= "<p>" . get_string('to_create_location_choose_school', 'praxe') . "</p>";
             }
             break;
         case PRAXE_TAB_HEADM_EDITSCHOOL:
             $schoolid = required_param('schoolid', PARAM_INT);
             $school = praxe_get_school($schoolid);
             if (!praxe_has_capability('editownschool') || !is_object($school) || !$school->headmaster == $USER->id) {
                 print_error('notallowedaction', 'praxe');
             }
             self::addschool_form();
             $this->form->set_form_to_edit($school);
             break;
         case PRAXE_TAB_HEADM_ASSIGNTEACHERS:
             require_capability('mod/praxe:assignteachertoownschool', $context, $USER->id);
             $schoolid = required_param('schoolid', PARAM_INT);
             require_once $CFG->dirroot . '/mod/praxe/c_assignteachers.php';
             $this->form = new praxe_assignteachers($schoolid);
             break;
         case PRAXE_TAB_HEADM_ADDLOCATION:
             require_capability('mod/praxe:createownlocation', $context, $USER->id);
             $schoolid = required_param('schoolid', PARAM_INT);
             require_once $CFG->dirroot . '/mod/praxe/c_addlocation.php';
             $this->form = new praxe_addlocation($schoolid);
             break;
         default:
             redirect($CFG->wwwroot . '/mod/praxe/view.php?id=' . $cm->id);
             break;
     }
 }