function get_selection_data($ufiltering) { global $SESSION; // get the SQL filter $guest = get_guest(); $sqlwhere = $ufiltering->get_sql_filter("id<>{$guest->id} AND deleted <> 1"); $total = count_records_select('user', "id<>{$guest->id} AND deleted <> 1"); $acount = count_records_select('user', $sqlwhere); $scount = count($SESSION->bulk_users); $userlist = array('acount' => $acount, 'scount' => $scount, 'ausers' => false, 'susers' => false, 'total' => $total); $userlist['ausers'] = get_records_select_menu('user', $sqlwhere, 'fullname', 'id,' . sql_fullname() . ' AS fullname', 0, MAX_BULK_USERS); if ($scount) { if ($scount < MAX_BULK_USERS) { $in = implode(',', $SESSION->bulk_users); } else { $bulkusers = array_slice($SESSION->bulk_users, 0, MAX_BULK_USERS, true); $in = implode(',', $bulkusers); } $userlist['susers'] = get_records_select_menu('user', "id IN ({$in})", 'fullname', 'id,' . sql_fullname() . ' AS fullname'); } return $userlist; }
/** * Retrieve a list of categories and ids suitable for use in a form * @return array */ function profile_list_categories() { if (!($categories = get_records_select_menu('user_info_category', '', 'sortorder ASC', 'id, name'))) { $categories = array(); } return $categories; }
function xmldb_attforblock_upgrade($oldversion = 0) { global $CFG, $THEME, $db; $result = true; /// And upgrade begins here. For each one, you'll need one /// block of code similar to the next one. Please, delete /// this comment lines once this file start handling proper /// upgrade code. if ($result && $oldversion < 2008021904) { //New version in version.php global $USER; if ($sessions = get_records('attendance_sessions', 'takenby', 0)) { foreach ($sessions as $sess) { if (count_records('attendance_log', 'attsid', $sess->id) > 0) { $sess->takenby = $USER->id; $sess->timetaken = $sess->timemodified ? $sess->timemodified : time(); $sess->description = addslashes($sess->description); $result = update_record('attendance_sessions', $sess) and $result; } } } } if ($oldversion < 2008102401 and $result) { $table = new XMLDBTable('attforblock'); $field = new XMLDBField('grade'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, '100', 'name'); $result = $result && add_field($table, $field); $table = new XMLDBTable('attendance_sessions'); $field = new XMLDBField('courseid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); $result = $result && change_field_unsigned($table, $field); // $field = new XMLDBField('creator'); // $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid'); // $result = $result && change_field_unsigned($table, $field); $field = new XMLDBField('sessdate'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'creator'); $result = $result && change_field_unsigned($table, $field); $field = new XMLDBField('duration'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'sessdate'); $result = $result && add_field($table, $field); $field = new XMLDBField('timetaken'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'takenby'); $result = $result && change_field_unsigned($table, $field); $result = $result && rename_field($table, $field, 'lasttaken'); $field = new XMLDBField('takenby'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'lasttaken'); $result = $result && change_field_unsigned($table, $field); $result = $result && rename_field($table, $field, 'lasttakenby'); $field = new XMLDBField('timemodified'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'lasttaken'); $result = $result && change_field_unsigned($table, $field); $table = new XMLDBTable('attendance_log'); $field = new XMLDBField('attsid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); $result = $result && change_field_unsigned($table, $field); $field = new XMLDBField('studentid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'attsid'); $result = $result && change_field_unsigned($table, $field); $field = new XMLDBField('statusid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'status'); $result = $result && add_field($table, $field); $field = new XMLDBField('statusset'); $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'statusid'); $result = $result && add_field($table, $field); $field = new XMLDBField('timetaken'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'statusid'); $result = $result && add_field($table, $field); $field = new XMLDBField('takenby'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'timetaken'); $result = $result && add_field($table, $field); //Indexes $index = new XMLDBIndex('statusid'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('statusid')); $result = $result && add_index($table, $index); $index = new XMLDBIndex('attsid'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('attsid')); $result = $result && drop_index($table, $index); $field = new XMLDBField('attsid'); //Rename field $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); $result = $result && rename_field($table, $field, 'sessionid'); $index = new XMLDBIndex('sessionid'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('sessionid')); $result = $result && add_index($table, $index); $table = new XMLDBTable('attendance_settings'); $field = new XMLDBField('courseid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'id'); $result = $result && change_field_unsigned($table, $field); $field = new XMLDBField('visible'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '1', 'grade'); $result = $result && add_field($table, $field); $field = new XMLDBField('deleted'); $field->setAttributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'visible'); $result = $result && add_field($table, $field); //Indexes $index = new XMLDBIndex('visible'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('visible')); $result = $result && add_index($table, $index); $index = new XMLDBIndex('deleted'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('deleted')); $result = $result && add_index($table, $index); $result = $result && rename_table($table, 'attendance_statuses'); } if ($oldversion < 2008102406 and $result) { if ($courses = get_records_sql("SELECT courseid FROM {$CFG->prefix}attendance_sessions GROUP BY courseid")) { foreach ($courses as $c) { //Adding own status for course (now it must have own) if (!count_records('attendance_statuses', 'courseid', $c->courseid)) { $statuses = get_records('attendance_statuses', 'courseid', 0); foreach ($statuses as $stat) { $rec = $stat; $rec->courseid = $c->courseid; insert_record('attendance_statuses', $rec); } } $statuses = get_records('attendance_statuses', 'courseid', $c->courseid); $statlist = implode(',', array_keys($statuses)); $sess = get_records_select_menu('attendance_sessions', "courseid = {$c->courseid} AND lasttakenby > 0"); $sesslist = implode(',', array_keys($sess)); foreach ($statuses as $stat) { execute_sql("UPDATE {$CFG->prefix}attendance_log\n\t\t\t\t\t\t\t\t\t\tSET statusid = {$stat->id}, statusset = '{$statlist}'\n\t\t\t\t\t\t\t\t\t WHERE sessionid IN ({$sesslist}) AND status = '{$stat->status}'"); } $sessions = get_records_list('attendance_sessions', 'id', $sesslist); foreach ($sessions as $sess) { execute_sql("UPDATE {$CFG->prefix}attendance_log\n\t\t\t\t\t\t\t\t\t\tSET timetaken = {$sess->lasttaken}, \n\t\t\t\t\t\t\t\t\t\t\ttakenby = {$sess->lasttakenby}\n\t\t\t\t\t\t\t\t\t WHERE sessionid = {$sess->id}"); } } } } if ($oldversion < 2008102409 and $result) { $table = new XMLDBTable('attendance_statuses'); $field = new XMLDBField('status'); $result = $result && drop_field($table, $field); $index = new XMLDBIndex('status'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status')); $result = $result && drop_index($table, $index); $table = new XMLDBTable('attendance_log'); $field = new XMLDBField('status'); $result = $result && drop_field($table, $field); $index = new XMLDBIndex('status'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status')); $result = $result && drop_index($table, $index); $table = new XMLDBTable('attendance_sessions'); $field = new XMLDBField('creator'); $result = $result && drop_field($table, $field); } return $result; }
/** * Get the keypair. If it doesn't exist, create it. If it's out of date, * archive it and create a fresh pair. * * @param bool True if you want to force fresh keys to be generated * @return bool * @access private */ public function get_keypair($regenerate = null) { $this->keypair = array(); $records = null; if ($records = get_records_select_menu('config', "field IN ('openssl_keypair', 'openssl_keypair_expires')", 'field', 'field, value')) { list($this->keypair['certificate'], $this->keypair['keypair_PEM']) = explode('@@@@@@@@', $records['openssl_keypair']); $this->keypair['expires'] = $records['openssl_keypair_expires']; if (empty($regenerate) && $this->keypair['expires'] > time()) { return true; } } // Save out the old key $openssl_history = $this->get_history(); array_unshift($openssl_history, $this->keypair); $this->save_history($openssl_history); // Initialize a new set of SSL keys $this->keypair = array(); $this->generate_keypair(); // A record for the keys $keyrecord = new stdClass(); $keyrecord->field = 'openssl_keypair'; $keyrecord->value = implode('@@@@@@@@', $this->keypair); // A convenience record for the keys' expire time (UNIX timestamp) $expiresrecord = new stdClass(); $expiresrecord->field = 'openssl_keypair_expires'; // Getting the expire timestamp is convoluted, but required: $credentials = openssl_x509_parse($this->keypair['certificate']); if (is_array($credentials) && isset($credentials['validTo_time_t'])) { $expiresrecord->value = $credentials['validTo_time_t']; $this->keypair['expires'] = $credentials['validTo_time_t']; } if (empty($records)) { db_begin(); insert_record('config', $keyrecord); insert_record('config', $expiresrecord); db_commit(); } else { db_begin(); update_record('config', $keyrecord, array('field' => 'openssl_keypair')); update_record('config', $expiresrecord, array('field' => 'openssl_keypair_expires')); db_commit(); } log_info("New public key has been generated. It expires " . date('Y/m/d h:i:s', $credentials['validTo_time_t'])); return true; }
function move_questions($oldcat, $newcat) { $questionids = get_records_select_menu('question', "category = {$oldcat} AND (parent = 0 OR parent = id)", '', 'id,1'); if (!question_move_questions_to_category(implode(',', array_keys($questionids)), $newcat)) { print_error('errormovingquestions', 'question', $returnurl, $ids); } }
function definition() { global $CFG, $COURSE, $ESPCONFIG, $questionnaire, $QUESTIONNAIRE_REALMS, $SESSION; $mform =& $this->_form; $mform->addElement('html', '<div class="qcontainer">'); //------------------------------------------------------------------------------- $mform->addElement('header', 'questionhdr', get_string('questions', 'questionnaire')); $mform->setHelpButton('questionhdr', array('questiontypes', get_string('questiontypes', 'questionnaire'), 'questionnaire')); $stredit = get_string('edit', 'questionnaire'); $strremove = get_string('remove', 'questionnaire'); $stryes = get_string('yes'); $strno = get_string('no'); /// Set up question positions. if (!isset($questionnaire->questions)) { $questionnaire->questions = array(); } $quespos = array(); $max = count($questionnaire->questions); $sec = 0; for ($i = 1; $i <= $max; $i++) { $quespos[$i] = "{$i}"; } $pos = 0; $numq = count($questionnaire->questions); $attributes = 'onChange="this.form.submit()"'; $select = ''; if (!($qtypes = get_records_select_menu('questionnaire_question_type', $select, '', 'typeid,type'))) { $qtypes = array(); } // needed for non-English languages JR foreach ($qtypes as $key => $qtype) { $qtypes[$key] = questionnaire_get_type($key); } natsort($qtypes); $addqgroup = array(); $addqgroup[] =& $mform->createElement('select', 'type_id', '', $qtypes); // 'sticky' type_id value for further new questions if (isset($SESSION->questionnaire->type_id)) { $mform->setDefault('type_id', $SESSION->questionnaire->type_id); } $addqgroup[] =& $mform->createElement('submit', 'addqbutton', get_string('addselqtype', 'questionnaire')); $mform->addGroup($addqgroup, 'addqgroup', '', '', false); $mform->addElement('html', '<div class="qheader">'); $quesgroup = array(); $quesgroup[] =& $mform->createElement('static', 'opentagt', '', '<div class="qicons">' . get_string('action', 'questionnaire') . '</div>'); $quesgroup[] =& $mform->createElement('static', 'qnamet', '', '<div class="qtype">' . get_string('questiontypes', 'questionnaire') . '</div>'); $quesgroup[] =& $mform->createElement('static', 'qreqt', '', '<div class="qreq">' . get_string('required') . '</div>'); $quesgroup[] =& $mform->createElement('static', 'qtypet', '', '<div class="qname">' . get_string('optionalname', 'questionnaire') . '</div>'); $mform->addGroup($quesgroup, 'questgroupt', '', '', false); $mform->addElement('html', '</div>'); foreach ($questionnaire->questions as $question) { /// Skip displaying this question if we are moving this question. if ($this->moveq && $this->moveq == $question->id) { continue; } $required = ''; $qid = $question->id; $tid = $question->type_id; $qtype = $question->type; $required = $question->required; $pos = $question->position; // needed for non-English languages JR $qtype = '[' . questionnaire_get_type($tid) . ']'; $content = ''; if ($tid == 99) { $sec++; $content .= '<b>' . get_string('sectionbreak', 'questionnaire') . '</b>'; } else { $content = $question->content; } $quesgroup = 'quesgroup_' . $pos; ${$quesgroup} = array(); // ${$quesgroup}[] =& $mform->createElement('select', 'pos['.$question->id.']', '', $quespos, $attributes); // $mform->setDefault('pos['.$question->id.']', $pos); // if ($question->type_id == QUESPAGEBREAK) { // ${$quesgroup}[] =& $mform->createElement('submit', 'editbutton['.$question->id.']', $stredit, array('disabled' => 'disabled')); // } else { // ${$quesgroup}[] =& $mform->createElement('submit', 'editbutton['.$question->id.']', $stredit); // } // ${$quesgroup}[] =& $mform->createElement('submit', 'removebutton['.$question->id.']', $strremove); $butclass = array('class' => 'questionnaire_qbut'); if (!$this->moveq) { $uextra = array('value' => $question->id, 'alt' => get_string('moveup', 'questionnaire'), 'title' => get_string('moveup', 'questionnaire')) + $butclass; $dextra = array('value' => $question->id, 'alt' => get_string('movedn', 'questionnaire'), 'title' => get_string('movedn', 'questionnaire')) + $butclass; $mextra = array('value' => $question->id, 'alt' => get_string('move', 'questionnaire'), 'title' => get_string('move', 'questionnaire')) + $butclass; $eextra = array('value' => $question->id, 'alt' => get_string('edit', 'questionnaire'), 'title' => get_string('edit', 'questionnaire')) + $butclass; $rextra = array('value' => $question->id, 'alt' => get_string('remove', 'questionnaire'), 'title' => get_string('remove', 'questionnaire')) + $butclass; if ($pos == 1) { $usrc = $CFG->wwwroot . '/mod/questionnaire/images/upd.gif'; $uextra += array('disabled' => 'disabled'); } else { $usrc = $CFG->wwwroot . '/mod/questionnaire/images/up.gif'; } if ($pos == $numq) { $dsrc = $CFG->wwwroot . '/mod/questionnaire/images/downd.gif'; $dextra += array('disabled' => 'disabled'); } else { $dsrc = $CFG->wwwroot . '/mod/questionnaire/images/down.gif'; } if ($question->type_id == QUESPAGEBREAK) { $esrc = $CFG->wwwroot . '/mod/questionnaire/images/editd.gif'; $eextra += array('disabled' => 'disabled'); } else { $esrc = $CFG->wwwroot . '/mod/questionnaire/images/edit.gif'; } $rsrc = $CFG->wwwroot . '/mod/questionnaire/images/delete.gif'; /// Need to index by 'id' since IE doesn't return assigned 'values' for image inputs. ${$quesgroup}[] =& $mform->createElement('static', 'opentag_' . $question->id, '', '<div class="qicons">'); ${$quesgroup}[] =& $mform->createElement('image', 'moveupbutton[' . $question->id . ']', $usrc, $uextra); ${$quesgroup}[] =& $mform->createElement('image', 'movednbutton[' . $question->id . ']', $dsrc, $dextra); ${$quesgroup}[] =& $mform->createElement('image', 'movebutton[' . $question->id . ']', $CFG->wwwroot . '/mod/questionnaire/images/move.gif', $mextra); ${$quesgroup}[] =& $mform->createElement('image', 'editbutton[' . $question->id . ']', $esrc, $eextra); ${$quesgroup}[] =& $mform->createElement('image', 'removebutton[' . $question->id . ']', $rsrc, $rextra); ${$quesgroup}[] =& $mform->createElement('static', 'closetag_' . $question->id, '', '</div>'); } else { $mextra = array('value' => $question->id, 'alt' => get_string('movehere', 'questionnaire'), 'title' => get_string('movehere', 'questionnaire')) + $butclass; $msrc = $CFG->wwwroot . '/mod/questionnaire/images/movehere.gif'; ${$quesgroup}[] =& $mform->createElement('static', 'opentag_' . $question->id, '', '<div class="qicons">'); ${$quesgroup}[] =& $mform->createElement('image', 'moveherebutton[' . $pos . ']', $msrc, $mextra); ${$quesgroup}[] =& $mform->createElement('static', 'closetag_' . $question->id, '', '</div>'); } ${$quesgroup}[] =& $mform->createElement('static', 'qtype_' . $question->id, '', '<div class="qtype">' . $qtype . '</div>'); $qreq = ''; if ($question->type_id != QUESPAGEBREAK && $question->type_id != QUESSECTIONTEXT) { if ($required == 'y') { $qreq = $stryes; } else { $qreq = $strno; } } ${$quesgroup}[] =& $mform->createElement('static', 'qreq_' . $question->id, '', '<div class="qreq">' . $qreq . '</div>'); $qname = $question->name; ${$quesgroup}[] =& $mform->createElement('static', 'qname_' . $question->id, '', '<div class="qname">' . $qname . '</div>'); $mform->addGroup(${$quesgroup}, 'questgroup', '', '', false); $mform->addElement('static', 'qcontent_' . $question->id, '', '<div class="qcontent">' . $content . '</div>'); $pos++; } /// If we are moving a question, display one more line for the end. if ($this->moveq) { $quesgroup = 'quesgroup_' . $numq; ${$quesgroup} = array(); /// use '0' to indicate at the end. $mextra = array('value' => 0, 'alt' => get_string('movehere', 'questionnaire'), 'title' => get_string('movehere', 'questionnaire')) + $butclass; $msrc = $CFG->wwwroot . '/mod/questionnaire/images/movehere.gif'; ${$quesgroup}[] =& $mform->createElement('static', 'opentag_end', '', '<div class="qicons">'); ${$quesgroup}[] =& $mform->createElement('image', 'moveherebutton[0]', $msrc, $mextra); ${$quesgroup}[] =& $mform->createElement('static', 'closetag_end', '', '</div>'); ${$quesgroup}[] =& $mform->createElement('static', 'qtype_end', '', '<div class="qtype"> </div>'); ${$quesgroup}[] =& $mform->createElement('static', 'qreq_end', '', '<div class="qreq"> </div>'); ${$quesgroup}[] =& $mform->createElement('static', 'qname_end', '', '<div class="qname"> </div>'); $mform->addGroup(${$quesgroup}, 'questgroup', '', '', false); $mform->addElement('static', 'qcontent_end', '', '<div class="qcontent"> </div>'); /// Need to remember what we are moving... $mform->addElement('hidden', 'moveq', $this->moveq); } //------------------------------------------------------------------------------- // Hidden fields $mform->addElement('hidden', 'id', 0); $mform->addElement('hidden', 'sid', 0); $mform->addElement('hidden', 'action', 'main'); //------------------------------------------------------------------------------- // buttons $mform->addElement('html', '</div>'); }
/** * Returns information about the users. * @param string $sqlwhere filter for the users */ function getUserData($sqlwhere) { return get_records_select_menu('user', $sqlwhere, 'fullname', 'id,' . sql_fullname() . ' AS fullname'); }
/** * Category is about to be deleted, * 1/ All question categories and their questions are deleted for this course category. * 2/ All questions are moved to new category * * @param object $category course category object * @param object $newcategory empty means everything deleted, otherwise id of category where content moved * @param boolean $feedback to specify if the process must output a summary of its work * @return boolean */ function question_delete_course_category($category, $newcategory, $feedback = true) { $context = get_context_instance(CONTEXT_COURSECAT, $category->id); if (empty($newcategory)) { $feedbackdata = array(); // To store feedback to be showed at the end of the process $rescueqcategory = null; // See the code around the call to question_save_from_deletion. $strcatdeleted = get_string('unusedcategorydeleted', 'quiz'); // Loop over question categories. if ($categories = get_records('question_categories', 'contextid', $context->id, 'parent', 'id, parent, name')) { foreach ($categories as $category) { // Deal with any questions in the category. if ($questions = get_records('question', 'category', $category->id)) { // Try to delete each question. foreach ($questions as $question) { delete_question($question->id); } // Check to see if there were any questions that were kept because they are // still in use somehow, even though quizzes in courses in this category will // already have been deteted. This could happen, for example, if questions are // added to a course, and then that course is moved to another category (MDL-14802). $questionids = get_records_select_menu('question', 'category = ' . $category->id, '', 'id,1'); if (!empty($questionids)) { if (!($rescueqcategory = question_save_from_deletion(implode(',', array_keys($questionids)), get_parent_contextid($context), print_context_name($context), $rescueqcategory))) { return false; } $feedbackdata[] = array($category->name, get_string('questionsmovedto', 'question', $rescueqcategory->name)); } } // Now delete the category. if (!delete_records('question_categories', 'id', $category->id)) { return false; } $feedbackdata[] = array($category->name, $strcatdeleted); } // End loop over categories. } // Output feedback if requested. if ($feedback and $feedbackdata) { $table = new stdClass(); $table->head = array(get_string('questioncategory', 'question'), get_string('action')); $table->data = $feedbackdata; print_table($table); } } else { // Move question categories ot the new context. if (!($newcontext = get_context_instance(CONTEXT_COURSECAT, $newcategory->id))) { return false; } if (!set_field('question_categories', 'contextid', $newcontext->id, 'contextid', $context->id)) { return false; } if ($feedback) { $a = new stdClass(); $a->oldplace = print_context_name($context); $a->newplace = print_context_name($newcontext); notify(get_string('movedquestionsandcategories', 'question', $a), 'notifysuccess'); } } return true; }
protected function load_current_permissions() { /// Load the overrides/definition in this context. if ($this->roleid) { $this->permissions = get_records_select_menu('role_capabilities', "roleid = {$this->roleid} AND contextid = " . $this->context->id, '', 'capability,permission'); } else { $this->permissions = array(); } }
case QUESTION_FILEMOVELINKSONLY: $url = $flipurls[$key]; $questionids = array_unique($urls[$url]); foreach ($questionids as $questionid) { $question = $questions[$questionid]; $QTYPES[$question->qtype]->replace_file_links($question, $fromcoursefilesid, $tocoursefilesid, $url, $destination); } break; case QUESTION_FILEDONOTHING: default: break; } } } //adjust sortorder before we make the cat a peer of it's new peers $peers = get_records_select_menu('question_categories', "contextid = {$toparent->contextid} AND " . "parent = {$toparent->id}", "sortorder ASC", "id, id"); $peers = array_keys($peers); if ($totop) { array_unshift($peers, $cattomove->id); } else { $peers[] = $cattomove->id; } $sortorder = 0; foreach ($peers as $peer) { if (!set_field('question_categories', "sortorder", $sortorder, "id", $peer)) { print_error('listupdatefail', '', $onerrorurl); } $sortorder++; } //now move category $cat = new object();
} redirect($return, ' Finished successfully :-) ', 5); } $msgform = new user_courselist_form('user_bulk_enroll.php'); if ($msgform->is_cancelled()) { redirect($return); } else { if ($formdata = $msgform->get_data(false)) { $options = new object(); $options->para = false; $options->newlines = true; $options->smiley = false; $inu = implode(',', $SESSION->bulk_users); $userlist = get_records_select_menu('user', "id IN ({$inu})", 'fullname', 'id,' . sql_fullname() . ' AS fullname'); $inc = implode(',', $formdata->courses); $courselist = get_records_select_menu('course', "id IN ({$inc})", 'shortname', 'id,shortname'); $optionsyes = array(); $optionsyes['confirm'] = 1; $optionsyes['sesskey'] = sesskey(); //$optionsyes['msg'] = $msg; $optionsyes['courses'] = implode(',', $formdata->courses); $optionsyes['roleid'] = $formdata->role; admin_externalpage_print_header(); print_heading(get_string('confirmation', 'admin')); print_box('רישום המשתמשים:<br/>' . implode(',', $userlist) . '<br/><br/>בתפקיד "' . $allroles[$formdata->role] . '"<br/><br/> לקורסים הבאים:<br/>' . implode(',', $courselist), 'boxwidthnarrow boxaligncenter generalbox', 'preview'); notice_yesno('האם אתם מאשרים?', 'user_bulk_enroll.php', 'user_bulk.php', $optionsyes, NULL, 'post', 'get'); admin_externalpage_print_footer(); die; } } admin_externalpage_print_header();
function instance_config_print() { global $CFG; if (!isset($this->config)) { // ... teacher has not yet configured the block, let's put some default values here to explain things $this->config->title = get_string('blockname', 'block_glossary_random'); $this->config->refresh = 0; $this->config->showconcept = 1; $this->config->cache = get_string('notyetconfigured', 'block_glossary_random'); $this->config->addentry = get_string('addentry', 'block_glossary_random'); $this->config->viewglossary = get_string('viewglossary', 'block_glossary_random'); $this->config->invisible = get_string('invisible', 'block_glossary_random'); } // select glossaries to put in dropdown box ... $glossaries = get_records_select_menu('glossary', 'course=' . $this->course->id, 'name', 'id,name'); //format menu texts to avoid html and to filter multilang values if (!empty($glossaries)) { foreach ($glossaries as $key => $value) { $glossaries[$key] = strip_tags(format_string($value, true)); } } // and select quotetypes to put in dropdown box $type[0] = get_string('random', 'block_glossary_random'); $type[1] = get_string('lastmodified', 'block_glossary_random'); $type[2] = get_string('nextone', 'block_glossary_random'); $this->config->nexttime = usergetmidnight(time()) + DAYSECS * $this->config->refresh; // display the form if (is_file($CFG->dirroot . '/blocks/' . $this->name() . '/config_instance.html')) { print_simple_box_start('center', '', '', 5, 'blockconfigglobal'); include $CFG->dirroot . '/blocks/' . $this->name() . '/config_instance.html'; print_simple_box_end(); } else { notice(get_string('blockconfigbad'), str_replace('blockaction=', 'dummy=', qualified_me())); } return true; }
function upgrade_to_new_roles_ui() { global $CFG; /// New table for storing which roles can be assigned in which contexts. /// Define table role_context_levels to be created $table = new XMLDBTable('role_context_levels'); /// Adding fields to table role_context_levels $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); $table->addFieldInfo('roleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('contextlevel', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); /// Adding keys to table role_context_levels $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); $table->addKeyInfo('contextlevel-roleid', XMLDB_KEY_UNIQUE, array('contextlevel', 'roleid')); $table->addKeyInfo('roleid', XMLDB_KEY_FOREIGN, array('roleid'), 'role', array('id')); /// Conditionally launch create table for role_context_levels if (!table_exists($table)) { create_table($table); } /// Now populate the role_context_levels table with the defaults that match /// moodle_install_roles, and any other combinations that exist in this system. $roleids = get_records_menu('role', '', '', '', 'shortname,id'); /// Defaults, should match moodle_install_roles. $rolecontextlevels = array(); if (isset($roleids['admin'])) { $rolecontextlevels[$roleids['admin']] = get_default_contextlevels('admin'); } if (isset($roleids['coursecreator'])) { $rolecontextlevels[$roleids['coursecreator']] = get_default_contextlevels('coursecreator'); } if (isset($roleids['editingteacher'])) { $rolecontextlevels[$roleids['editingteacher']] = get_default_contextlevels('editingteacher'); } if (isset($roleids['teacher'])) { $rolecontextlevels[$roleids['teacher']] = get_default_contextlevels('teacher'); } if (isset($roleids['student'])) { $rolecontextlevels[$roleids['student']] = get_default_contextlevels('student'); } if (isset($roleids['guest'])) { $rolecontextlevels[$roleids['guest']] = get_default_contextlevels('guest'); } if (isset($roleids['user'])) { $rolecontextlevels[$roleids['user']] = get_default_contextlevels('user'); } /// See what other role assignments are in this database, extend the allowed /// lists to allow them too. $existingrolecontextlevels = get_recordset_sql('SELECT DISTINCT ra.roleid, con.contextlevel FROM {role_assignments} ra JOIN {context} con ON ra.contextid = con.id'); foreach ($existingrolecontextlevels as $rcl) { $rcl = (object) $rcl; if (!isset($rolecontextlevels[$rcl->roleid])) { $rolecontextlevels[$rcl->roleid] = array($rcl->contextlevel); } else { if (!in_array($rcl->contextlevel, $rolecontextlevels[$rcl->roleid])) { $rolecontextlevels[$rcl->roleid][] = $rcl->contextlevel; } } } /// Put the data into the database. foreach ($rolecontextlevels as $roleid => $contextlevels) { set_role_contextlevels($roleid, $contextlevels); } /// Remove any role overrides for moodle/site:doanything, or any permissions /// for it in a role without legacy:admin. $systemcontext = get_context_instance(CONTEXT_SYSTEM); // Remove all overrides. delete_records_select('role_capabilities', "capability = 'moodle/site:doanything'\n AND contextid <> {$systemcontext->id}"); $roletest = ''; // Get the ids of all the roles that are moodle/legacy:admin. if ($adminroleids = get_records_select_menu('role_capabilities', "capability = 'moodle/legacy:admin' AND permission = 1 AND contextid = {$systemcontext->id}", '', 'id, roleid')) { $roletest = 'IN ( ' . implode(',', $adminroleids) . ')'; } else { $adminroleids = array(); } delete_records_select('role_capabilities', "roleid NOT {$roletest}\n AND capability = 'moodle/site:doanything'AND contextid = {$systemcontext->id}"); set_field_select('role_capabilities', 'permission', 1, "roleid {$roletest} AND capability = 'moodle/site:doanything' AND contextid = {$systemcontext->id}"); // And for any admin-y roles where moodle/site:doanything is not set, set it. $doanythingroleids = get_records_select_menu('role_capabilities', "capability = 'moodle/site:doanything' AND permission = 1 AND contextid = {$systemcontext->id}", '', 'id, roleid'); foreach ($adminroleids as $roleid) { if (!in_array($roleid, $doanythingroleids)) { $rc = new stdClass(); $rc->contextid = $systemcontext->id; $rc->roleid = $roleid; $rc->capability = 'moodle/site:doanything'; $rc->permission = 1; $rc->timemodified = time(); insert_record('role_capabilities', $rc); } } set_config('roles_ui_backport_upgraded', 1); }
function questionnaire_get_active_surveys_menu() { global $QUESTIONNAIRE_ACTIVE1; global $QUESTIONNAIRE_ACTIVE2; $select = "status in ({$QUESTIONNAIRE_ACTIVE1},{$QUESTIONNAIRE_ACTIVE2})"; return get_records_select_menu('questionnaire_survey', $select); }
case QUESTION_FILEMOVELINKSONLY: $url = $flipurls[$key]; $questionids = array_unique($urls[$url]); foreach ($questionids as $questionid) { $question = $questions[$questionid]; $QTYPES[$question->qtype]->replace_file_links($question, $fromcoursefilesid, $tocoursefilesid, $url, $destination); } break; case QUESTION_FILEDONOTHING: default: break; } } } //adjust sortorder before we make the cat a peer of it's new peers $peers = get_records_select_menu('question_categories', "contextid = {$toparent->contextid} AND parent = {$toparent->id}", 'sortorder ASC', 'id, 1'); $peers = array_keys($peers); if ($totop) { array_unshift($peers, $cattomove->id); } else { $peers[] = $cattomove->id; } $sortorder = 0; foreach ($peers as $peer) { if (!set_field('question_categories', "sortorder", $sortorder, "id", $peer)) { print_error('listupdatefail', '', $onerrorurl); } $sortorder++; } //now move category $cat = new object();
$return = $CFG->wwwroot . '/' . $CFG->admin . '/user/user_bulk.php'; if (empty($SESSION->bulk_users)) { redirect($return); } admin_externalpage_print_header(); //TODO: add support for large number of users if ($confirm and confirm_sesskey()) { $primaryadmin = get_admin(); $in = implode(',', $SESSION->bulk_users); if ($rs = get_recordset_select('user', "id IN ({$in})")) { while ($user = rs_fetch_next_record($rs)) { if ($primaryadmin->id != $user->id and $USER->id != $user->id and delete_user($user)) { unset($SESSION->bulk_users[$user->id]); } else { notify(get_string('deletednot', '', fullname($user, true))); } } rs_close($rs); } redirect($return, get_string('changessaved')); } else { $in = implode(',', $SESSION->bulk_users); $userlist = get_records_select_menu('user', "id IN ({$in})", 'fullname', 'id,' . sql_fullname() . ' AS fullname'); $usernames = implode(', ', $userlist); $optionsyes = array(); $optionsyes['confirm'] = 1; $optionsyes['sesskey'] = sesskey(); print_heading(get_string('confirmation', 'admin')); notice_yesno(get_string('deletecheckfull', '', $usernames), 'user_bulk_delete.php', 'user_bulk.php', $optionsyes, NULL, 'post', 'get'); } admin_externalpage_print_footer();
/** * check for multiple_submit = false. * if the feedback is global so the courseid must be given * @param int $feedbackid * @param int $courseid * @return boolean true if the feedback already is submitted otherwise false */ function feedback_is_already_submitted($feedbackid, $courseid = false) { global $USER; $select = 'userid = ' . $USER->id . ' AND feedback = ' . $feedbackid; if (!($trackings = get_records_select_menu('feedback_tracking', $select, '', 'id, completed'))) { return false; } if ($courseid) { $select = 'completed IN (' . implode(',', $trackings) . ') AND course_id = ' . $courseid; if (!($values = get_records_select('feedback_value', $select))) { return false; } } return true; }
/** * Format Upgrade Path * * @version $Id: upgrade.php,v 1.1 2009/12/21 01:00:29 michaelpenne Exp $ * @package format_page **/ function xmldb_format_page_upgrade($oldversion = 0) { global $CFG, $db; include_once $CFG->dirroot . '/course/format/page/lib.php'; $result = true; if ($result && $oldversion < 2007041202) { /// Define field id to be added to block_course_menu $table = new XMLDBTable('format_page'); /// Add field showbuttons $field = new XMLDBField('showbuttons'); $field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, null, null, 0, 'template'); $result = $result && add_field($table, $field); } if ($result && $oldversion < 2007042500) { // update showbuttons settings to allow for indedependent bitwise previous & next if (defined('BUTTON_BOTH')) { $result = set_field('format_page', 'showbuttons', BUTTON_BOTH, 'showbuttons', 1); } else { $result = false; notify('BUTTON_BOTH constant not set', 'notifyfailure'); } } if ($result && $oldversion < 2007042503) { /// Define index index (not unique) to be added to format_page $table = new XMLDBTable('format_page'); $index = new XMLDBIndex('parentpageindex'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('parent')); if (!index_exists($table, $index)) { $result = $result && add_index($table, $index); } $index = new XMLDBIndex('sortorderpageindex'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('sortorder')); if (!index_exists($table, $index)) { $result = $result && add_index($table, $index); } // now add indexes for format_page_items tables $table = new XMLDBTable('format_page_items'); $index = new XMLDBIndex('format_page_items_sortorder_index'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('sortorder')); if (!index_exists($table, $index)) { $result = $result && add_index($table, $index); } $index = new XMLDBIndex('format_page_items_pageid_index'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('pageid')); if (!index_exists($table, $index)) { $result = $result && add_index($table, $index); } } if ($result && $oldversion < 2007071800) { $validcourses = get_records_menu('course', '', '', '', 'id, shortname'); if (!empty($validcourses)) { $keys = array_keys($validcourses); $invalidpages = get_records_select_menu('format_page', 'courseid NOT IN(' . implode(', ', $keys) . ')', '', 'id, nameone'); if (!empty($invalidpages)) { $pagekeys = array_keys($invalidpages); delete_records_select('format_page_items', 'pageid IN (' . implode(', ', $pagekeys) . ')'); delete_records_select('format_page', 'id IN (' . implode(', ', $pagekeys) . ')'); } } else { delete_records('format_page'); delete_records('format_page_items'); } } if ($result && $oldversion < 2007071801) { /// Define field width to be dropped from format_page_items $table = new XMLDBTable('format_page_items'); $field = new XMLDBField('width'); /// Launch drop field width $result = $result && drop_field($table, $field); } if ($result && $oldversion < 2007071802) { /// Changing logic for sortorder field to more closely resemble block weight // This could be huge, do not output everything $olddebug = $db->debug; $db->debug = false; // Setup some values $result = true; $i = 0; if ($rs = get_recordset('format_page', '1', '1', '', 'id')) { if ($rs->RecordCount() > 0) { echo 'Processing page item sortorder field....'; while ($page = rs_fetch_next_record($rs)) { if ($pageitems = get_records('format_page_items', 'pageid', $page->id, 'sortorder', 'id, position')) { // Organize by position $organized = array('l' => array(), 'c' => array(), 'r' => array()); foreach ($pageitems as $pageitem) { $organized[$pageitem->position][] = $pageitem->id; } // Now - reset sortorder value foreach ($organized as $position => $pageitemids) { $sortorder = 0; foreach ($pageitemids as $pageitemid) { $result = $result and set_field('format_page_items', 'sortorder', $sortorder, 'id', $pageitemid); $sortorder++; } } } if ($i % 50 == 0) { echo '.'; flush(); } $i++; } if ($result) { notify('SUCCESSFULLY fixed page item sort order field', 'notifysuccess'); } else { notify('FAILED! An error occured during upgrade'); } } rs_close($rs); } // Restore $db->debug = $olddebug; } if ($result && $oldversion < 2007071803) { // This could be huge, do not output everything $olddebug = $db->debug; $db->debug = false; $result = true; // Make sure all block weights are set properly (before this was never really managed properly) if ($courses = get_records('course', 'format', 'page', '', 'id')) { echo 'Fixing block weights in courses with format = \'page\'....'; $i = 0; foreach ($courses as $course) { page_fix_block_weights($course->id); if ($i % 5 == 0) { echo '.'; flush(); } $i++; } } // Restore $db->debug = $olddebug; } if ($result && $oldversion < 2007071804) { /// Changing the default of field sortorder on table format_page_items to 0 $table = new XMLDBTable('format_page_items'); $field = new XMLDBField('sortorder'); $field->setAttributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'position'); /// Launch change of default for field sortorder $result = $result && change_field_default($table, $field); } if ($result && $oldversion < 2007071805) { // This could be huge, do not output everything $olddebug = $db->debug; $db->debug = false; $result = true; // Make sure all page sortorder values are set properly (before this was never really managed properly) if ($courses = get_records('course', 'format', 'page', '', 'id')) { echo 'Fixing page sort orders in courses with format = \'page\'....'; $i = 0; foreach ($courses as $course) { page_fix_page_sortorder($course->id); if ($i % 5 == 0) { echo '.'; flush(); } $i++; } } // Restore $db->debug = $olddebug; } if ($result && $oldversion < 2007071806) { // Remove old setting if (record_exists('config', 'name', 'pageformatusedefault')) { unset_config('pageformatusedefault'); } } if ($result && $oldversion < 2007071807) { $site = get_site(); if ($site->format == 'page') { $result = ($result and set_field('course', 'format', 'site', 'id', $site->id)); $result = ($result and set_config('pageformatonfrontpage', 1)); } } if ($result && $oldversion < 2008082100) { $site = get_site(); if ($CFG->pageformatonfrontpage == 1) { // Turns out having this set is very important - EG: backup/restore $result = set_field('course', 'format', 'page', 'id', $site->id); } } if ($result && $oldversion < 2008121000) { /// Define field locks to be added to format_page $table = new XMLDBTable('format_page'); $field = new XMLDBField('locks'); $field->setAttributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null, null, 'showbuttons'); /// Launch add field locks $result = $result && add_field($table, $field); } if ($result && $oldversion < 2009060200) { //MR-263 column widths to strings to allow for px, % and em etc. $table = new XMLDBTable('format_page'); $field = new XMLDBField('prefleftwidth'); $field->setType(XMLDB_TYPE_CHAR); $result = $result && change_field_type($table, $field); $field = new XMLDBField('prefcenterwidth'); $field->setType(XMLDB_TYPE_CHAR); $result = $result && change_field_type($table, $field); $field = new XMLDBField('prefrightwidth'); $field->setType(XMLDB_TYPE_CHAR); $result = $result && change_field_type($table, $field); // XMLDB_TYPE_CHAR isn't the same as varchar??? //$alter = "ALTER TABLE {$CFG->prefix}format_page CHANGE prefleftwidth prefleftwidth varchar(8)"; } return $result; }
function scorm_view_display($user, $scorm, $action, $cm, $boxwidth = '') { global $CFG; if ($scorm->updatefreq == UPDATE_EVERYTIME) { require_once $CFG->dirroot . '/mod/scorm/lib.php'; $scorm->instance = $scorm->id; scorm_update_instance($scorm); } $organization = optional_param('organization', '', PARAM_INT); print_simple_box_start('center', $boxwidth); ?> <div class="structurehead"><?php print_string('contents', 'scorm'); ?> </div> <?php if (empty($organization)) { $organization = $scorm->launch; } if ($orgs = get_records_select_menu('scorm_scoes', "scorm='{$scorm->id}' AND organization='' AND launch=''", 'id', 'id,title')) { if (count($orgs) > 1) { ?> <div class='scorm-center'> <?php print_string('organizations', 'scorm'); ?> <form id='changeorg' method='post' action='<?php echo $action; ?> '> <?php choose_from_menu($orgs, 'organization', "{$organization}", '', 'submit()'); ?> </form> </div> <?php } } $orgidentifier = ''; if ($sco = scorm_get_sco($organization, SCO_ONLY)) { if ($sco->organization == '' && $sco->launch == '') { $orgidentifier = $sco->identifier; } else { $orgidentifier = $sco->organization; } } /* $orgidentifier = ''; if ($org = get_record('scorm_scoes','id',$organization)) { if (($org->organization == '') && ($org->launch == '')) { $orgidentifier = $org->identifier; } else { $orgidentifier = $org->organization; } }*/ $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe if (!file_exists($CFG->dirroot . '/mod/scorm/datamodels/' . $scorm->version . 'lib.php')) { $scorm->version = 'scorm_12'; } require_once $CFG->dirroot . '/mod/scorm/datamodels/' . $scorm->version . 'lib.php'; $result = scorm_get_toc($user, $scorm, 'structlist', $orgidentifier); $incomplete = $result->incomplete; echo $result->toc; print_simple_box_end(); ?> <div class="scorm-center"> <form id="theform" method="post" action="<?php echo $CFG->wwwroot; ?> /mod/scorm/player.php"> <?php if ($scorm->hidebrowse == 0) { print_string('mode', 'scorm'); echo ': <input type="radio" id="b" name="mode" value="browse" /><label for="b">' . get_string('browse', 'scorm') . '</label>' . "\n"; echo '<input type="radio" id="n" name="mode" value="normal" checked="checked" /><label for="n">' . get_string('normal', 'scorm') . "</label>\n"; } else { echo '<input type="hidden" name="mode" value="normal" />' . "\n"; } if ($incomplete === false && ($result->attemptleft > 0 || $scorm->maxattempt == 0)) { ?> <br /> <input type="checkbox" id="a" name="newattempt" /> <label for="a"><?php print_string('newattempt', 'scorm'); ?> </label> <?php } ?> <br /> <input type="hidden" name="scoid"/> <input type="hidden" name="id" value="<?php echo $cm->id; ?> "/> <input type="hidden" name="currentorg" value="<?php echo $orgidentifier; ?> " /> <input type="submit" value="<?php print_string('enter', 'scorm'); ?> " /> </form> </div> <?php }
function get_records_select_menu($table, $select = '', $sort = '', $fields = '*', $limitfrom = '', $limitnum = '') { global $CFG; $CFG->prefix = $this->prefix; $records = get_records_select_menu($table, $select, $sort, $fields, $limitfrom, $limitnum); $CFG->prefix = $this->newmoodleprefix; return $records; }