Skip to content

Commit

Permalink
MDL-14679 towards /admin conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed May 30, 2008
1 parent 953d72d commit 1d8bf5f
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 53 deletions.
4 changes: 2 additions & 2 deletions admin/enrol_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

/// If data submitted, then process and store.

if ($frm = data_submitted()) {
if ($frm = data_submitted(false)) {
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
print_error('confirmsesskeybad', 'error');
}
if ($enrolment->process_config($frm)) {
redirect("enrol.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
Expand Down
12 changes: 6 additions & 6 deletions admin/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require_once($CFG->libdir.'/tablelib.php');

$filterfull = required_param('filter', PARAM_PATH);
$forcereset = optional_param('reset', 0, PARAM_BOOL);
$forcereset = optional_param('reset', 0, PARAM_BOOL);

$filtername = substr($filterfull, strpos( $filterfull, '/' )+1 ) ;

Expand All @@ -17,17 +17,17 @@


// get translated strings for use on page
$txt = new Object;
$txt->managefilters = get_string( 'managefilters' );
$txt = new object();
$txt->managefilters = get_string( 'managefilters' );
$txt->administration = get_string( 'administration' );
$txt->configuration = get_string( 'configuration' );
$txt->configuration = get_string( 'configuration' );

//======================
// Process Actions
//======================

// if reset pressed let filter config page handle it
if ($config = data_submitted() and !$forcereset) {
if ($config = data_submitted(false) and !$forcereset) {

// check session key
if (!confirm_sesskey()) {
Expand All @@ -48,7 +48,7 @@
// run through submitted data
// reject if does not start with filter_
foreach ($config as $name => $value) {
set_config($name, stripslashes($value));
set_config($name, $value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions admin/handlevirus.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
$action = clam_handle_infected_file($file,$log->userid,true);
clam_replace_infected_file($file);

$user = get_record("user","id",$log->userid);
$course = get_record("course","id",$log->course);
$user = $DB->get_record("user", array("id"=>$log->userid));
$course = $DB->get_record("course", array("id"=>$log->course));
$subject = get_string('virusfoundsubject','moodle',format_string($site->fullname));
$a->date = userdate($log->time);

Expand Down
4 changes: 2 additions & 2 deletions admin/health.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ function title() {
return 'cron.php is not set up to run automatically';
}
function exists() {
global $CFG;
$lastcron = get_field_sql('SELECT max(lastcron) FROM '.$CFG->prefix.'modules');
global $DB;
$lastcron = $DB->get_field_sql('SELECT max(lastcron) FROM {modules}');
return (time() - $lastcron > 3600 * 24);
}
function severity() {
Expand Down
4 changes: 2 additions & 2 deletions admin/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

$filename = $CFG->dataroot.'/'.SITEID.'/maintenance.html';

if ($form = data_submitted()) {
if ($form = data_submitted(false)) {
if (confirm_sesskey()) {
if ($form->action == "disable") {
unlink($filename);
redirect('maintenance.php', get_string('sitemaintenanceoff','admin'));
} else {
$file = fopen($filename, 'w');
fwrite($file, stripslashes($form->text));
fwrite($file, $form->text);
fclose($file);
redirect('maintenance.php', get_string('sitemaintenanceon', 'admin'));
}
Expand Down
2 changes: 1 addition & 1 deletion admin/multilangupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
}
$fulltable = $DB->get_prefix().$table;
if ($columns = $DB->get_columns($table)) {
if (!array_key_exists('id', $columns) and !array_key_exists('ID', $columns)) {
if (!array_key_exists('id', $columns)) {
continue; // moodle tables have id
}
foreach ($columns as $column => $data) {
Expand Down
41 changes: 21 additions & 20 deletions admin/oacleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


function online_assignment_cleanup($output=false) {
global $CFG;
global $CFG, $DB;

if ($output) {
print_heading('Online Assignment Cleanup');
Expand All @@ -27,7 +27,7 @@ function online_assignment_cleanup($output=false) {
/// We don't want to run this code if we are doing an upgrade from an assignment
/// version earlier than 2005041400
/// because the assignment type field will not exist
$amv = get_field('modules', 'version', 'name', 'assignment');
$amv = $DB->get_field('modules', 'version', array('name'=>'assignment'));
if ((int)$amv < 2005041400) {
if ($output) {
echo '</center>';
Expand All @@ -37,12 +37,12 @@ function online_assignment_cleanup($output=false) {


/// get the module id for assignments from db
$arecord = get_record('modules', 'name', 'assignment');
$arecord = $DB->get_record('modules', array('name', 'assignment'));
$aid = $arecord->id;


/// get a list of all courses on this site
$courses = get_records('course');
$courses = $DB->get_records('course');

/// cycle through each course
foreach ($courses as $course) {
Expand All @@ -51,8 +51,12 @@ function online_assignment_cleanup($output=false) {
if ($output) print_heading($fullname);

/// retrieve a list of sections beyond what is currently being shown
$sql = 'SELECT * FROM '.$CFG->prefix.'course_sections WHERE course='.$course->id.' AND section>'.$course->numsections.' ORDER BY section ASC';
if (!($xsections = get_records_sql($sql))) {
$sql = "SELECT *
FROM {course_sections}
WHERE course=? AND section>?
ORDER BY section ASC";
$params = array($course->id, $course->numsections);
if (!($xsections = $DB->get_records_sql($sql, $params))) {
if ($output) echo 'No extra sections<br />';
continue;
}
Expand All @@ -70,31 +74,28 @@ function online_assignment_cleanup($output=false) {
foreach ($instances as $instance) {
/// is this an instance of an online assignment
$sql = "SELECT a.id
FROM {$CFG->prefix}course_modules cm,
{$CFG->prefix}assignment a
WHERE cm.id = '$instance' AND
cm.module = '$aid' AND
cm.instance = a.id AND
a.assignmenttype = 'online'";

FROM {course_modules} cm, {assignment} a
WHERE cm.id = ? AND cm.module = ? AND
cm.instance = a.id AND a.assignmenttype = 'online'";
$params = array($instance, $aid);

/// if record exists then we need to move instance to it's correct section
if (record_exists_sql($sql)) {
if ($DB->record_exists_sql($sql, $params)) {

/// check the new section id
/// the journal update erroneously stored it in course_sections->section
$newsection = $xsection->section;
/// double check the new section
if ($newsection > $course->numsections) {
/// get the record for section 0 for this course
if (!($zerosection = get_record('course_sections', 'course', $course->id, 'section', '0'))) {
if (!($zerosection = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>'0')))) {
continue;
}
$newsection = $zerosection->id;
}

/// grab the section record
if (!($section = get_record('course_sections', 'id', $newsection))) {
if (!($section = $DB->get_record('course_sections', array('id'=>$newsection)))) {
if ($output) echo 'Serious error: Cannot retrieve section: '.$newsection.' for course: '. format_string($course->fullname) .'<br />';
continue;
}
Expand All @@ -110,12 +111,12 @@ function online_assignment_cleanup($output=false) {
/// implode the sequence
$section->sequence = implode(',', $sequence);

set_field('course_sections', 'sequence', $section->sequence, 'id', $section->id);
$DB->set_field('course_sections', 'sequence', $section->sequence, array('id'=>$section->id));

/// now we need to remove the instance from the old sequence

/// grab the old section record
if (!($section = get_record('course_sections', 'id', $xsection->id))) {
if (!($section = $DB->get_record('course_sections', array('id'=>$xsection->id)))) {
if ($output) echo 'Serious error: Cannot retrieve old section: '.$xsection->id.' for course: '.$course->fullname.'<br />';
continue;
}
Expand All @@ -132,7 +133,7 @@ function online_assignment_cleanup($output=false) {
/// implode the sequence
$section->sequence = implode(',', $sequence);

set_field('course_sections', 'sequence', $section->sequence, 'id', $section->id);
$DB->set_field('course_sections', 'sequence', $section->sequence, array('id'=>$section->id));


if ($output) echo 'Online Assignment (instance '.$instance.') moved from section '.$section->id.': to section '.$newsection.'<br />';
Expand All @@ -143,7 +144,7 @@ function online_assignment_cleanup($output=false) {

/// if the summary and sequence are empty then remove this section
if (empty($xsection->summary) and empty($xsection->sequence)) {
delete_records('course_sections', 'id', $xsection->id);
$DB->delete_records('course_sections', array('id'=>$xsection->id));
if ($output) echo 'Deleting empty section '.$xsection->section.'<br />';
}
}
Expand Down
3 changes: 2 additions & 1 deletion admin/process_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// BOUNCE EMAILS TO NOREPLY
if ($_ENV['RECIPIENT'] == $CFG->noreplyaddress) {
$user = new pbject();
$user->email = $_ENV['SENDER'];

if (!validate_email($user->email)) {
Expand Down Expand Up @@ -53,7 +54,7 @@
$modname = 'moodle';
}
else {
$modname = get_field("modules","name","id",$modid);
$modname = $DB->get_field("modules", "name", array("id"=>$modid));
include_once('mod/'.$modname.'/lib.php');
}
$function = $modname.'_process_email';
Expand Down
5 changes: 4 additions & 1 deletion admin/replace.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
$search = optional_param('search', '', PARAM_RAW);
$replace = optional_param('replace', '', PARAM_RAW);

$search = stripslashes($search); // TODO: remove soon
$replace = stripslashes($replace); // TODO: remove soon

###################################################################
admin_externalpage_print_header();

Expand All @@ -34,7 +37,7 @@

print_simple_box_start('center');

if (!db_replace(stripslashes($search), stripslashes($replace))) {
if (!db_replace($search, $replace)) {
print_error('erroroccur', debug);
}

Expand Down
6 changes: 4 additions & 2 deletions admin/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
require_once('../config.php');
require_once($CFG->libdir.'/adminlib.php');

$query = trim(stripslashes(optional_param('query', '', PARAM_NOTAGS))); // Search string
$query = trim(optional_param('query', '', PARAM_NOTAGS)); // Search string

$query = stripslashes($query); // TODO: remove soon

$adminroot =& admin_get_root(); // need all settings here
$adminroot->search = $query; // So we can reference it in search boxes later in this invocation
Expand All @@ -16,7 +18,7 @@
admin_externalpage_setup('search'); // now hidden page

// now we'll deal with the case that the admin has submitted the form with changed settings
if ($data = data_submitted() and confirm_sesskey()) {
if ($data = data_submitted(false) and confirm_sesskey()) {
if (admin_write_settings($data)) {
$statusmsg = get_string('changessaved');
}
Expand Down
6 changes: 3 additions & 3 deletions admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
$page =& $adminroot->locate($section);

if (empty($page) or !is_a($page, 'admin_settingpage')) {
error(get_string('sectionerror', 'admin'), "$CFG->wwwroot/$CFG->admin/");
print_error('sectionerror', 'admin', "$CFG->wwwroot/$CFG->admin/");
die;
}

if (!($page->check_access())) {
error(get_string('accessdenied', 'admin'));
print_error('accessdenied', 'admin');
die;
}

Expand All @@ -31,7 +31,7 @@
$errormsg = '';
$focus = '';

if ($data = data_submitted() and confirm_sesskey()) {
if ($data = data_submitted(false) and confirm_sesskey()) {
if (admin_write_settings($data)) {
$statusmsg = get_string('changessaved');
}
Expand Down
2 changes: 1 addition & 1 deletion admin/upgradesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
admin_externalpage_setup('upgradesettings'); // now hidden page

// now we'll deal with the case that the admin has submitted the form with new settings
if ($data = data_submitted() and confirm_sesskey()) {
if ($data = data_submitted(false) and confirm_sesskey()) {
$count = admin_write_settings($data);
$adminroot =& admin_get_root(true); //reload tree
}
Expand Down
Loading

0 comments on commit 1d8bf5f

Please sign in to comment.