Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 575eba292a | |||
| 0a2294525c | |||
| 4b685ab2a3 | |||
| 00231a7498 | |||
| ad6c367583 | |||
| 7ffa4254e2 | |||
| 86fb51fe69 | |||
| bc05b1544d | |||
| e2d3d77173 | |||
| 6b63e94a29 | |||
| 350e44bf21 | |||
| f97355847a | |||
| ee84cd6c76 | |||
| 14824286cb | |||
| 3f4e0d9d6a | |||
| 2b8fb55a4d | |||
| aa55bb6666 | |||
| 90c644a587 | |||
| 30772a2aaf | |||
| 4287e72159 | |||
| 79b71ea0cd | |||
| 5180efaa90 | |||
| 1a55aa43a2 | |||
| eb34e77f15 | |||
| 935ba6ed19 | |||
| ea944efe7f | |||
| 4f8442c56d | |||
| fe544ceab4 | |||
| b65fdd3b54 | |||
| 6478428784 | |||
| 660381d2b0 | |||
| 65aede08b6 | |||
| cc1ec30e2d | |||
| 5f90f9fad6 | |||
| 60d17e47a0 | |||
| 94826e8e57 | |||
| ae39746289 | |||
| 49fe4f99e1 | |||
| 4997042474 | |||
| 1194026729 | |||
| 20761eb71d | |||
| 734bdb63bf | |||
| e0dd8f3260 | |||
| 578ba7762e | |||
| e044b5a536 | |||
| 63f6422df2 | |||
| 8097f8d7c7 | |||
| ac90c4a264 | |||
| 345692a64d | |||
| 86a8e9070b | |||
| 6555eabb0c | |||
| dcc6326eb9 | |||
| e8fb94a3cd | |||
| 79dd6106dd | |||
| 031dd5f017 | |||
| 507ee65e59 | |||
| 56b19c309e | |||
| 99dac04aeb | |||
| 12f18ea1ab | |||
| 1626376373 | |||
| 7729acff90 | |||
| b35cd9c592 | |||
| a69a278684 | |||
| 61cc70ae45 |
+51
-36
@@ -1,36 +1,51 @@
|
||||
README $Id$
|
||||
------
|
||||
|
||||
QUICK INSTALL
|
||||
=============
|
||||
|
||||
For the impatient, here is a basic outline of the
|
||||
installation process, which normally takes me only
|
||||
a few minutes:
|
||||
|
||||
1) Move the Moodle files into your web directory.
|
||||
|
||||
2) Create a single database for Moodle to store all
|
||||
it's tables in (or choose an existing database).
|
||||
|
||||
3) Visit your Moodle site with a browser, you should
|
||||
be taken to the install.php script, which will lead
|
||||
you through creating a config.php file and then
|
||||
setting up Moodle, creating an admin account etc.
|
||||
|
||||
4) Set up a cron task to call the file admin/cron.php
|
||||
every five minutes or so.
|
||||
|
||||
|
||||
For more information, see the INSTALL DOCUMENTATION:
|
||||
|
||||
http://docs.moodle.org/en/Installing_Moodle
|
||||
|
||||
A local copy can also be found in
|
||||
|
||||
lang/en_utf8/help/install.html (or your language)
|
||||
|
||||
|
||||
Good luck and have fun!
|
||||
Martin Dougiamas, Lead Developer
|
||||
|
||||
README $Id$
|
||||
------
|
||||
|
||||
If you are installing the first time, then you
|
||||
should read the installation guide which is
|
||||
part of the Moodle documentation (along with
|
||||
information about upgrading etc):
|
||||
|
||||
http://moodle.com/doc/
|
||||
|
||||
There is a copy of all this documentation as part of
|
||||
this Moodle distribution. You can access your local
|
||||
copy of the installation guide here:
|
||||
|
||||
lang/en/docs/install.html
|
||||
|
||||
Once Moodle is installed on your machine, then
|
||||
you can also access a local copy of all this
|
||||
documentation (localised to your language) at:
|
||||
|
||||
http://yourmoodlesite.com/doc/
|
||||
|
||||
|
||||
For the impatient, here is a basic outline of the
|
||||
installation process, which normally takes me only
|
||||
a few minutes:
|
||||
|
||||
1) Move the Moodle files into your web directory.
|
||||
|
||||
2) Create an empty directory somewhere to store
|
||||
uploaded files (NOT accessible via the web).
|
||||
This directory must be writeable by the web server
|
||||
process.
|
||||
|
||||
3) Create a single database for Moodle to store all
|
||||
it's tables in (or choose an existing database).
|
||||
|
||||
4) Copy the file config-dist.php to config.php, and
|
||||
edit it with all your own settings.
|
||||
|
||||
5) Visit your new home page with a web browser. Moodle
|
||||
will lead you through the rest of the setup,
|
||||
creating an admin account and so on.
|
||||
|
||||
6) Set up a cron task to call the file admin/cron.php
|
||||
every five minutes or so.
|
||||
|
||||
|
||||
Cheers!
|
||||
Martin Dougiamas
|
||||
|
||||
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
<?PHP // $Id$
|
||||
// Admin-only script to assign administrative rights to users
|
||||
|
||||
require_once("../config.php");
|
||||
|
||||
define("MAX_USERS_PER_PAGE", 50);
|
||||
|
||||
optional_variable($add, "");
|
||||
optional_variable($remove, "");
|
||||
optional_variable($search, "");
|
||||
|
||||
if (! $site = get_site()) {
|
||||
redirect("$CFG->wwwroot/$CFG->admin/index.php");
|
||||
}
|
||||
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("You must be an administrator to use this page.");
|
||||
}
|
||||
|
||||
$primaryadmin = get_admin();
|
||||
|
||||
/// If you want any administrator to have the ability to assign admin
|
||||
/// rights, then comment out the following if statement
|
||||
if ($primaryadmin->id != $USER->id) {
|
||||
error("You must be the primary administrator to use this page.");
|
||||
}
|
||||
|
||||
/// assign all of the configurable language strings
|
||||
$stringstoload = array (
|
||||
"assignadmins",
|
||||
"administration",
|
||||
"existingadmins",
|
||||
"noexistingadmins",
|
||||
"potentialadmins",
|
||||
"nopotentialadmins",
|
||||
"addadmin",
|
||||
"removeadmin",
|
||||
"search",
|
||||
"searchagain",
|
||||
"toomanytoshow",
|
||||
"users",
|
||||
"searchresults"
|
||||
);
|
||||
|
||||
foreach ($stringstoload as $stringtoload){
|
||||
$strstringtoload = "str" . $stringtoload;
|
||||
$$strstringtoload = get_string($stringtoload);
|
||||
}
|
||||
|
||||
if ($search) {
|
||||
$searchstring = $strsearchagain;
|
||||
} else {
|
||||
$searchstring = $strsearch;
|
||||
}
|
||||
|
||||
print_header("$site->shortname: $strassignadmins",
|
||||
"$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> -> $strassignadmins", "");
|
||||
|
||||
/// Add an admin if one is specified
|
||||
if (!empty($_GET['add'])) {
|
||||
if (! add_admin($add)) {
|
||||
error("Could not add that admin!");
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove an admin if one is specified.
|
||||
if (!empty($_GET['remove'])) {
|
||||
if (! remove_admin($remove)) {
|
||||
error("Could not remove that admin!");
|
||||
}
|
||||
}
|
||||
|
||||
/// Print a help notice about this page
|
||||
if (empty($add) and empty($remove) and empty($search)) {
|
||||
print_simple_box("<center>".get_string("adminhelpassignadmins")."</center>", "center", "50%");
|
||||
}
|
||||
|
||||
/// Get all existing admins
|
||||
$admins = get_admins();
|
||||
|
||||
/// Print the lists of existing and potential admins
|
||||
echo "<table cellpadding=2 cellspacing=10 align=center>";
|
||||
echo "<tr><th width=50%>$strexistingadmins</th><th width=50%>$strpotentialadmins</th></tr>";
|
||||
echo "<tr><td width=50% nowrap valign=top>";
|
||||
|
||||
/// First, show existing admins
|
||||
|
||||
if (! $admins) {
|
||||
echo "<p align=center>$strnoexistingadmins</p>";
|
||||
$adminlist = "";
|
||||
|
||||
} else {
|
||||
$adminarray = array();
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
$adminarray[] = $admin->id;
|
||||
echo "<p align=right>".fullname($admin, true).",
|
||||
$admin->email ";
|
||||
if ($primaryadmin->id == $admin->id){
|
||||
print_spacer(10, 9, false);
|
||||
} else {
|
||||
echo "<a href=\"admin.php?remove=$admin->id\"
|
||||
title=\"$strremoveadmin\"><img src=\"../pix/t/right.gif\"
|
||||
border=0></A>";
|
||||
}
|
||||
echo "</p>";
|
||||
}
|
||||
|
||||
$adminlist = implode(",",$adminarray);
|
||||
unset($adminarray);
|
||||
}
|
||||
|
||||
echo "<td width=50% nowrap valign=top>";
|
||||
|
||||
/// Print list of potential admins
|
||||
|
||||
$usercount = get_users(false, $search, true, $adminlist);
|
||||
|
||||
if ($usercount == 0) {
|
||||
echo "<p align=center>$strnopotentialadmins</p>";
|
||||
|
||||
} else if ($usercount > MAX_USERS_PER_PAGE) {
|
||||
echo "<p align=center>$strtoomanytoshow ($usercount) </p>";
|
||||
|
||||
} else {
|
||||
|
||||
if ($search) {
|
||||
echo "<p align=center>($strsearchresults : $search)</p>";
|
||||
}
|
||||
|
||||
if (!$users = get_users(true, $search, true, $adminlist)) {
|
||||
error("Could not get users!");
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
echo "<p align=left><a href=\"admin.php?add=$user->id\"".
|
||||
"title=\"$straddadmin\"><img src=\"../pix/t/left.gif\"".
|
||||
"border=0></a> ".fullname($user).", $user->email";
|
||||
}
|
||||
}
|
||||
|
||||
if ($search or $usercount > MAX_USERS_PER_PAGE) {
|
||||
echo "<form action=admin.php method=post>";
|
||||
echo "<input type=text name=search size=20>";
|
||||
echo "<input type=submit value=\"$searchstring\">";
|
||||
echo "</form>";
|
||||
}
|
||||
|
||||
echo "</tr></table>";
|
||||
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
+72
-227
@@ -1,59 +1,33 @@
|
||||
<?PHP // $Id$
|
||||
// config.php - allows admin to edit all configuration variables
|
||||
|
||||
require_once('../config.php');
|
||||
include("../config.php");
|
||||
require_login();
|
||||
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
if (!$site = get_site()) {
|
||||
redirect("index.php");
|
||||
}
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('userauthentication', $adminroot);
|
||||
if (!isadmin()) {
|
||||
error("Only the admin can use this page");
|
||||
}
|
||||
|
||||
$auth = optional_param('auth', '', PARAM_SAFEDIR);
|
||||
|
||||
|
||||
$focus = '';
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($config = data_submitted()) {
|
||||
|
||||
if (!confirm_sesskey()) {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
if ($config = data_submitted()) {
|
||||
|
||||
$config = (array)$config;
|
||||
|
||||
// extract and sanitize the auth key explicitly
|
||||
$modules = get_list_of_plugins("auth");
|
||||
if (in_array($config['auth'], $modules)) {
|
||||
$auth = $config['auth'];
|
||||
} else {
|
||||
notify("Error defining the authentication method");
|
||||
}
|
||||
|
||||
// load the auth plugin library
|
||||
require_once("{$CFG->dirroot}/auth/$auth/lib.php");
|
||||
|
||||
$err = array();
|
||||
if (function_exists('auth_validate_form')) {
|
||||
auth_validate_form($config, $err);
|
||||
}
|
||||
validate_form($config, $err);
|
||||
|
||||
if (count($err) == 0) {
|
||||
print_header();
|
||||
foreach ($config as $name => $value) {
|
||||
if (preg_match('/^pluginconfig_(.+?)$/', $name, $matches)) {
|
||||
$plugin = "auth/$auth";
|
||||
$name = $matches[1];
|
||||
if (! set_config($name, $value, $plugin)) {
|
||||
notify("Problem saving config $name as $value for plugin $plugin");
|
||||
}
|
||||
} else { // normal handling for
|
||||
if (! set_config($name, $value)) {
|
||||
notify("Problem saving config $name as $value");
|
||||
}
|
||||
if (! set_config($name, $value)) {
|
||||
notify("Problem saving config $name as $value");
|
||||
}
|
||||
}
|
||||
redirect("auth.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
|
||||
redirect("auth.php", get_string("changessaved"), 1);
|
||||
exit;
|
||||
|
||||
} else {
|
||||
@@ -61,7 +35,7 @@
|
||||
$focus = "form.$key";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Otherwise fill and print the form.
|
||||
|
||||
@@ -70,261 +44,132 @@
|
||||
}
|
||||
|
||||
$modules = get_list_of_plugins("auth");
|
||||
$options = array();
|
||||
foreach ($modules as $module) {
|
||||
$options[$module] = get_string("auth_$module"."title", "auth");
|
||||
}
|
||||
asort($options);
|
||||
if (!empty($auth) && in_array($auth, $modules)) {
|
||||
} else {
|
||||
if (isset($_GET['auth'])) {
|
||||
$auth = $_GET['auth'];
|
||||
} else {
|
||||
$auth = $config->auth;
|
||||
}
|
||||
|
||||
// changepassword link replaced by individual auth setting
|
||||
if (!empty($config->changepassword)) {
|
||||
if (empty($config->{'auth_'.$auth.'_changepasswordurl'})) {
|
||||
$config->{'auth_'.$auth.'_changepasswordurl'} = $config->changepassword;
|
||||
}
|
||||
set_config('changepassword','');
|
||||
}
|
||||
|
||||
$auth = clean_param($auth,PARAM_SAFEDIR);
|
||||
}
|
||||
require_once("$CFG->dirroot/auth/$auth/lib.php"); //just to make sure that current authentication functions are loaded
|
||||
if (! isset($config->guestloginbutton)) {
|
||||
$config->guestloginbutton = 1;
|
||||
}
|
||||
if (! isset($config->alternateloginurl)) {
|
||||
$config->alternateloginurl = '';
|
||||
}
|
||||
if (! isset($config->auth_instructions)) {
|
||||
$config->auth_instructions = "";
|
||||
}
|
||||
if (! isset($config->changepassword)) {
|
||||
$config->changepassword = "";
|
||||
}
|
||||
if (! isset($config->{'auth_'.$auth.'_changepasswordurl'})) {
|
||||
$config->{'auth_'.$auth.'_changepasswordurl'} = '';
|
||||
}
|
||||
if (! isset($config->{'auth_'.$auth.'_changepasswordhelp'})) {
|
||||
$config->{'auth_'.$auth.'_changepasswordhelp'} = '';
|
||||
}
|
||||
$user_fields = array("firstname", "lastname", "email", "phone1", "phone2", "department", "address", "city", "country", "description", "idnumber", "lang");
|
||||
|
||||
foreach ($user_fields as $user_field) {
|
||||
$user_field = "auth_user_$user_field";
|
||||
if (! isset($config->$user_field)) {
|
||||
$config->$user_field = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($focus)) {
|
||||
$focus = "";
|
||||
}
|
||||
|
||||
$guestoptions[0] = get_string("hide");
|
||||
$guestoptions[1] = get_string("show");
|
||||
|
||||
$createoptions[0] = get_string("no");
|
||||
$createoptions[1] = get_string("yes");
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strauthentication = get_string("authentication");
|
||||
$strauthenticationoptions = get_string("authenticationoptions","auth");
|
||||
$strsettings = get_string("settings");
|
||||
$strusers = get_string("users");
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_header("$site->shortname: $strauthenticationoptions", "$site->fullname",
|
||||
"<A HREF=\"index.php\">$stradministration</A> -> <a href=\"users.php\">$strusers</a> -> $strauthenticationoptions", "$focus");
|
||||
|
||||
echo "<center><b>";
|
||||
echo "<form target=\"{$CFG->framename}\" name=\"authmenu\" method=\"post\" action=\"auth.php\">";
|
||||
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\" />";
|
||||
echo "<CENTER><P><B>";
|
||||
echo "<form TARGET=\"{$CFG->framename}\" NAME=\"authmenu\" method=\"post\" action=\"auth.php\">";
|
||||
print_string("chooseauthmethod","auth");
|
||||
|
||||
echo ' ';
|
||||
choose_from_menu ($options, "auth", $auth, "","document.location='auth.php?auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", "");
|
||||
|
||||
choose_from_menu ($options, "auth", $auth, "","document.location='auth.php?sesskey=$USER->sesskey&auth='+document.authmenu.auth.options[document.authmenu.auth.selectedIndex].value", "");
|
||||
|
||||
echo "</b></center><br />";
|
||||
|
||||
print_simple_box_start("center", "100%");
|
||||
echo "</B></P></CENTER>";
|
||||
|
||||
print_simple_box_start("center", "100%", "$THEME->cellheading");
|
||||
print_heading($options[$auth]);
|
||||
|
||||
print_simple_box_start("center", "60%", '', 5, 'informationbox');
|
||||
print_simple_box_start("center", "60%", "$THEME->cellcontent");
|
||||
print_string("auth_$auth"."description", "auth");
|
||||
print_simple_box_end();
|
||||
|
||||
echo "<hr />";
|
||||
echo "<hr>";
|
||||
|
||||
print_heading($strsettings);
|
||||
|
||||
echo "<table border=\"0\" width=\"100%\" cellpadding=\"4\">";
|
||||
|
||||
require_once("$CFG->dirroot/auth/$auth/config.html");
|
||||
$CFG->pagepath = 'auth/' . $auth;
|
||||
|
||||
echo '<tr><td colspan="3">';
|
||||
print_heading(get_string('auth_common_settings', 'auth'));
|
||||
echo '<td/></tr>';
|
||||
|
||||
if ($auth != "email" and $auth != "none" and $auth != "manual") {
|
||||
// display box for URL to change password. NB now on a per-method basis (multiple auth)
|
||||
echo "<tr valign=\"top\">";
|
||||
echo "<td align=\"right\" nowrap=\"nowrap\">";
|
||||
echo "<td align=right nowrap><p>";
|
||||
print_string("changepassword", "auth");
|
||||
echo ":</td>";
|
||||
echo "<td>";
|
||||
$passurl = $config->{'auth_'.$auth.'_changepasswordurl'};
|
||||
echo "<input type=\"text\" name=\"auth_{$auth}_changepasswordurl\" size=\"40\" value=\"$passurl\" />";
|
||||
echo ":</p></td>";
|
||||
echo "<td>";
|
||||
echo "<input type=\"text\" name=\"changepassword\" size=40 value=\"$config->changepassword\">";
|
||||
echo "</td>";
|
||||
echo "<td>";
|
||||
print_string("auth_changepasswordurl_expl","auth",$auth);
|
||||
echo "</td></tr>";
|
||||
|
||||
// display textbox for lost password help. NB now on a per-method basis (multiple auth)
|
||||
echo "<tr valign=\"top\">";
|
||||
echo "<td align=\"right\" nowrap=\"nowrap\">";
|
||||
print_string("auth_changepasswordhelp", "auth");
|
||||
echo ":</td>";
|
||||
echo "<td>";
|
||||
$passhelp = $config->{'auth_'.$auth.'_changepasswordhelp'};
|
||||
echo "<textarea name=\"auth_{$auth}_changepasswordhelp\" cols=\"30\" rows=\"10\" wrap=\"virtual\">";
|
||||
echo $passhelp;
|
||||
echo "</textarea>\n";
|
||||
echo "</td>";
|
||||
echo "<td>";
|
||||
print_string("auth_changepasswordhelp_expl","auth",$auth);
|
||||
print_string("changepasswordhelp","auth");
|
||||
echo "</td></tr>";
|
||||
|
||||
}
|
||||
|
||||
echo "<tr valign=\"top\">";
|
||||
echo "<td align=\"right\" nowrap=\"nowrap\">";
|
||||
echo "<td align=right nowrap><p>";
|
||||
print_string("guestloginbutton", "auth");
|
||||
echo ":</td>";
|
||||
echo "<td>";
|
||||
echo ":</p></td>";
|
||||
echo "<td>";
|
||||
choose_from_menu($guestoptions, "guestloginbutton", $config->guestloginbutton, "");
|
||||
echo "</td>";
|
||||
echo "<td>";
|
||||
print_string("showguestlogin","auth");
|
||||
echo "</td></tr>";
|
||||
|
||||
if (function_exists('auth_user_create')){
|
||||
echo "<tr valign=\"top\">";
|
||||
echo "<td align=\"right\" nowrap=\"nowrap\">";
|
||||
print_string("auth_user_create", "auth");
|
||||
echo ":</td>";
|
||||
echo "<td>";
|
||||
choose_from_menu($createoptions, "auth_user_create", $config->auth_user_create, "");
|
||||
echo "</td>";
|
||||
echo "<td>";
|
||||
print_string("auth_user_creation","auth");
|
||||
echo "</td></tr>";
|
||||
}
|
||||
if (function_exists('auth_user_create')){
|
||||
echo "<tr valign=\"top\">";
|
||||
echo "<td align=right nowrap><p>";
|
||||
print_string("auth_user_create", "auth");
|
||||
echo ":</p></td>";
|
||||
echo "<td>";
|
||||
choose_from_menu($createoptions, "auth_user_create", $config->auth_user_create, "");
|
||||
echo "</td>";
|
||||
echo "<td>";
|
||||
print_string("auth_user_creation","auth");
|
||||
echo "</td></tr>";
|
||||
}
|
||||
|
||||
echo "</table><center><p><input type=\"submit\" value=\"";
|
||||
print_string("savechanges");
|
||||
echo "\"></p></center></form>";
|
||||
|
||||
/// An alternate url for the login form. It means we can use login forms that are integrated
|
||||
/// into non-moodle pages
|
||||
echo '<tr valign="top">';
|
||||
echo '<td algin="right" nowrap="nowrap">';
|
||||
print_string('alternateloginurl', 'auth');
|
||||
echo '</td>';
|
||||
echo '<td>';
|
||||
echo '<input type="text" size="40" name="alternateloginurl" alt="'.get_string('alternateloginurl', 'auth').'" value="'.$config->alternateloginurl.'" />';
|
||||
echo '</td>';
|
||||
echo '<td>';
|
||||
print_string('alternatelogin', 'auth', htmlspecialchars($CFG->wwwroot.'/login/index.php'));
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
print_simple_box_end();
|
||||
|
||||
|
||||
echo '</table>';
|
||||
echo '<p align="center"><input type="submit" value="'.get_string('savechanges').'"></p>';
|
||||
echo '</form>';
|
||||
|
||||
print_simple_box_end();
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
exit;
|
||||
print_footer();
|
||||
exit;
|
||||
|
||||
/// Functions /////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Good enough for most auth plugins
|
||||
// but some may want a custom one if they are offering
|
||||
// other options
|
||||
// Note: pluginconfig_ fields have special handling.
|
||||
function print_auth_lock_options ($auth, $user_fields, $helptext, $retrieveopts, $updateopts) {
|
||||
function validate_form(&$form, &$err) {
|
||||
|
||||
echo '<tr><td colspan="3">';
|
||||
if ($retrieveopts) {
|
||||
print_heading(get_string('auth_data_mapping', 'auth'));
|
||||
} else {
|
||||
print_heading(get_string('auth_fieldlocks', 'auth'));
|
||||
}
|
||||
echo '<td/></tr>';
|
||||
// if (empty($form->fullname))
|
||||
// $err["fullname"] = get_string("missingsitename");
|
||||
|
||||
$lockoptions = array ('unlocked' => get_string('unlocked', 'auth'),
|
||||
'unlockedifempty' => get_string('unlockedifempty', 'auth'),
|
||||
'locked' => get_string('locked', 'auth'));
|
||||
$updatelocaloptions = array('oncreate' => get_string('update_oncreate', 'auth'),
|
||||
'onlogin' => get_string('update_onlogin', 'auth'));
|
||||
$updateextoptions = array('0' => get_string('update_never', 'auth'),
|
||||
'1' => get_string('update_onupdate', 'auth'));
|
||||
|
||||
$pluginconfig = get_config("auth/$auth");
|
||||
|
||||
// helptext is on a field with rowspan
|
||||
if (empty($helptext)) {
|
||||
$helptext = ' ';
|
||||
}
|
||||
|
||||
foreach ($user_fields as $field) {
|
||||
|
||||
// Define some vars we'll work with
|
||||
if(empty($pluginconfig->{"field_map_$field"})) {
|
||||
$pluginconfig->{"field_map_$field"} = '';
|
||||
}
|
||||
if(empty($pluginconfig->{"field_updatelocal_$field"})) {
|
||||
$pluginconfig->{"field_updatelocal_$field"} = '';
|
||||
}
|
||||
if (empty($pluginconfig->{"field_updateremote_$field"})) {
|
||||
$pluginconfig->{"field_updateremote_$field"} = '';
|
||||
}
|
||||
if (empty($pluginconfig->{"field_lock_$field"})) {
|
||||
$pluginconfig->{"field_lock_$field"} = '';
|
||||
}
|
||||
|
||||
// define the fieldname we display to the user
|
||||
$fieldname = $field;
|
||||
if ($fieldname === 'lang') {
|
||||
$fieldname = get_string('language');
|
||||
} elseif (preg_match('/^(.+?)(\d+)$/', $fieldname, $matches)) {
|
||||
$fieldname = get_string($matches[1]) . ' ' . $matches[2];
|
||||
} else {
|
||||
$fieldname = get_string($fieldname);
|
||||
}
|
||||
|
||||
echo '<tr valign="top"><td align="right">';
|
||||
echo $fieldname;
|
||||
echo '</td><td>';
|
||||
|
||||
if ($retrieveopts) {
|
||||
$varname = 'field_map_' . $field;
|
||||
|
||||
echo "<input name=\"pluginconfig_{$varname}\" type=\"text\" size=\"30\" value=\"{$pluginconfig->$varname}\">";
|
||||
echo '<div align="right">';
|
||||
echo get_string('auth_updatelocal', 'auth') . ' ';
|
||||
choose_from_menu($updatelocaloptions, "pluginconfig_field_updatelocal_{$field}", $pluginconfig->{"field_updatelocal_$field"}, "");
|
||||
echo '<br />';
|
||||
if ($updateopts) {
|
||||
echo get_string('auth_updateremote', 'auth') . ' ';
|
||||
' ';
|
||||
choose_from_menu($updateextoptions, "pluginconfig_field_updateremote_{$field}", $pluginconfig->{"field_updateremote_$field"}, "");
|
||||
echo '<br />';
|
||||
|
||||
|
||||
}
|
||||
echo get_string('auth_fieldlock', 'auth') . ' ';
|
||||
choose_from_menu($lockoptions, "pluginconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
|
||||
echo '</div>';
|
||||
} else {
|
||||
choose_from_menu($lockoptions, "pluginconfig_field_lock_{$field}", $pluginconfig->{"field_lock_$field"}, "");
|
||||
}
|
||||
echo '</td>';
|
||||
if (!empty($helptext)) {
|
||||
echo '<td rowspan="' . count($user_fields) . '">' . $helptext . '</td>';
|
||||
$helptext = '';
|
||||
}
|
||||
echo '</tr>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<?PHP // $Id$
|
||||
// backup.php - allows admin to edit all configuration variables for scheduled backups
|
||||
|
||||
require_once("../config.php");
|
||||
require_once("../backup/lib.php");
|
||||
require_once("../backup/backup_scheduled.php");
|
||||
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("Only an admin can use this page");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
error("Site isn't defined!");
|
||||
}
|
||||
|
||||
//Initialise error variables
|
||||
$error = false;
|
||||
$sche_destination_error = "";
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($config = data_submitted()) {
|
||||
|
||||
//First of all we check that everything is correct
|
||||
//Check for trailing slash and backslash in backup_sche_destination
|
||||
if (!empty($backup_sche_destination) and
|
||||
(substr($backup_sche_destination,-1) == "/" or substr($backup_sche_destination,-1) == "\\")) {
|
||||
$error = true;
|
||||
$sche_destination_error = get_string("pathslasherror");
|
||||
//Now check that backup_sche_destination dir exists
|
||||
} else if (!empty($backup_sche_destination) and
|
||||
!is_dir($backup_sche_destination)) {
|
||||
$error = true;
|
||||
$sche_destination_error = get_string("pathnotexists");
|
||||
}
|
||||
|
||||
//We need to do some weekdays conversions prior to continue
|
||||
$i = 0;
|
||||
$temp = "";
|
||||
$a_config = (array)$config;
|
||||
while ($i<7) {
|
||||
$tocheck = "dayofweek_".$i;
|
||||
if (isset($a_config[$tocheck])) {
|
||||
$temp .= "1";
|
||||
} else {
|
||||
$temp .= "0";
|
||||
}
|
||||
unset($a_config[$tocheck]);
|
||||
$i++;
|
||||
}
|
||||
$a_config['backup_sche_weekdays'] = $temp;
|
||||
$config = (object)$a_config;
|
||||
//weekdays conversions done. Continue
|
||||
|
||||
print_header();
|
||||
foreach ($config as $name => $value) {
|
||||
backup_set_config($name, $value);
|
||||
}
|
||||
|
||||
//And now, we execute schedule_backup_next_execution() for each course in the server to have the next
|
||||
//execution time updated automatically everytime it's changed.
|
||||
$status = true;
|
||||
//get admin
|
||||
$admin = get_admin();
|
||||
if (!$admin) {
|
||||
$status = false;
|
||||
}
|
||||
//get backup config
|
||||
if (! $backup_config = backup_get_config()) {
|
||||
$status = false;
|
||||
}
|
||||
if ($status) {
|
||||
//get courses
|
||||
if ($courses = get_records("course")) {
|
||||
//For each course, we check (insert, update) the backup_course table
|
||||
//with needed data
|
||||
foreach ($courses as $course) {
|
||||
//We check if the course exists in backup_course
|
||||
$backup_course = get_record("backup_courses","courseid",$course->id);
|
||||
//If it doesn't exist, create
|
||||
if (!$backup_course) {
|
||||
$temp_backup_course->courseid = $course->id;
|
||||
$newid = insert_record("backup_courses",$temp_backup_course);
|
||||
//And get it from db
|
||||
$backup_course = get_record("backup_courses","id",$newid);
|
||||
}
|
||||
//Now, calculate next execution of the course
|
||||
$nextstarttime = schedule_backup_next_execution ($backup_course,$backup_config,time(),$admin->timezone);
|
||||
//Save it to db
|
||||
set_field("backup_courses","nextstarttime",$nextstarttime,"courseid",$backup_course->courseid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/// Otherwise print the form.
|
||||
|
||||
$stradmin = get_string("administration");
|
||||
$strconfiguration = get_string("configuration");
|
||||
$strbackup = get_string("backup");
|
||||
|
||||
print_header("$site->shortname: $strconfiguration: $strbackup", $site->fullname,
|
||||
"<a href=\"index.php\">$stradmin</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> -> ".
|
||||
$strbackup);
|
||||
|
||||
echo "<p align=right><a href=\"../backup/log.php\">".get_string("logs")."</a></p>";
|
||||
|
||||
print_heading($strbackup);
|
||||
|
||||
print_simple_box("<center>".get_string("adminhelpbackup")."</center>", "center", "50%");
|
||||
echo "<br />";
|
||||
|
||||
print_simple_box_start("center", "", "$THEME->cellheading");
|
||||
|
||||
//Check for required functions...
|
||||
if(!function_exists('utf8_encode')) {
|
||||
print_simple_box("<font color=\"red\">You need to add XML support to your PHP installation</font>", "center", "70%", "$THEME->cellheading", "20", "noticebox");
|
||||
}
|
||||
include ("$CFG->dirroot/backup/config.html");
|
||||
|
||||
print_simple_box_end();
|
||||
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
+30
-45
@@ -3,73 +3,58 @@
|
||||
// block.php - allows admin to edit all local configuration variables for a block
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('manageblocks', $adminroot);
|
||||
require_once($CFG->libdir.'/blocklib.php');
|
||||
|
||||
$blockid = required_param('block', PARAM_INT);
|
||||
require_login();
|
||||
|
||||
if(($blockrecord = blocks_get_record($blockid)) === false) {
|
||||
if (!isadmin()) {
|
||||
error('Only an admin can use this page');
|
||||
}
|
||||
if (!$site = get_site()) {
|
||||
error("Site isn't defined!");
|
||||
}
|
||||
|
||||
require_variable($_REQUEST['block']);
|
||||
$blockid = intval($_REQUEST['block']);
|
||||
|
||||
if(($blockrecord = get_record('blocks', 'id', $blockid)) === false) {
|
||||
error('This block does not exist');
|
||||
}
|
||||
|
||||
$block = block_instance($blockrecord->name);
|
||||
$block = block_instance($blockrecord->name, NULL);
|
||||
if($block === false) {
|
||||
error('Problem in instantiating block object');
|
||||
}
|
||||
|
||||
// Define the data we're going to silently include in the instance config form here,
|
||||
// so we can strip them from the submitted data BEFORE handling it.
|
||||
$hiddendata = array(
|
||||
'block' => $blockid,
|
||||
'sesskey' => $USER->sesskey
|
||||
);
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($config = data_submitted()) {
|
||||
|
||||
if (!confirm_sesskey()) {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
if(!$block->has_config()) {
|
||||
error('This block does not support global configuration');
|
||||
}
|
||||
$remove = array_keys($hiddendata);
|
||||
foreach($remove as $item) {
|
||||
unset($config->$item);
|
||||
}
|
||||
$block->config_save($config);
|
||||
if ($config = data_submitted()) {
|
||||
unset($config['block']); // This will always be set if we have reached this point
|
||||
$block->handle_config($config);
|
||||
print_header();
|
||||
redirect("$CFG->wwwroot/$CFG->admin/blocks.php", get_string("changessaved"), 1);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/// Otherwise print the form.
|
||||
/// Otherwise print the form.
|
||||
|
||||
$stradmin = get_string('administration');
|
||||
$strconfiguration = get_string('configuration');
|
||||
$strmanageblocks = get_string('manageblocks');
|
||||
$strblockname = $block->get_title();
|
||||
|
||||
// $CFG->pagepath is used to generate the body and id attributes for the body tag
|
||||
// of the page. It is also used to generate the link to the Moodle Docs for this view.
|
||||
$CFG->pagepath = 'block/' . $block->name() . '/config';
|
||||
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_header($site->shortname.': '.$strblockname.": $strconfiguration", $site->fullname,
|
||||
"<a href=\"index.php\">$stradmin</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> -> ".
|
||||
"<a href=\"blocks.php\">$strmanageblocks</a> -> ".$strblockname);
|
||||
|
||||
print_heading($strblockname);
|
||||
|
||||
print_simple_box('<center>'.get_string('configwarning', 'admin').'</center>', 'center', '50%');
|
||||
print_simple_box('<center>'.get_string('configwarning').'</center>', 'center', '50%');
|
||||
echo '<br />';
|
||||
|
||||
echo '<form method="post" action="block.php">';
|
||||
echo '<p>';
|
||||
foreach($hiddendata as $name => $val) {
|
||||
echo '<input type="hidden" name="'. $name .'" value="'. $val .'" />';
|
||||
}
|
||||
echo '</p>';
|
||||
$block->config_print();
|
||||
echo '</form>';
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
$block->print_config();
|
||||
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
|
||||
+69
-145
@@ -3,124 +3,97 @@
|
||||
// Allows the admin to configure blocks (hide/show, delete and configure)
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/blocklib.php');
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
require_once($CFG->libdir.'/ddllib.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('manageblocks', $adminroot);
|
||||
optional_variable($_GET['hide']);
|
||||
optional_variable($_GET['show']);
|
||||
optional_variable($_GET['delete']);
|
||||
optional_variable($_GET['confirm'], 0);
|
||||
$delete = $_GET['delete']; // Dependency remover
|
||||
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
$hide = optional_param('hide', 0, PARAM_INT);
|
||||
$show = optional_param('show', 0, PARAM_INT);
|
||||
$delete = optional_param('delete', 0, PARAM_INT);
|
||||
$multiple = optional_param('multiple', 0, PARAM_INT);
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("Only administrators can use this page!");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
error("Site isn't defined!");
|
||||
}
|
||||
|
||||
|
||||
/// Print headings
|
||||
|
||||
$stradministration = get_string('administration');
|
||||
$strconfiguration = get_string('configuration');
|
||||
$strmanageblocks = get_string('manageblocks');
|
||||
$strdelete = get_string('delete');
|
||||
$strversion = get_string('version');
|
||||
$strhide = get_string('hide');
|
||||
$strshow = get_string('show');
|
||||
$strsettings = get_string('settings');
|
||||
$strcourses = get_string('blockinstances', 'admin');
|
||||
$strcourses = get_string('courses');
|
||||
$strname = get_string('name');
|
||||
$strmultiple = get_string('blockmultiple', 'admin');
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_header("$site->shortname: $strmanageblocks", "$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> -> $strmanageblocks");
|
||||
|
||||
print_heading($strmanageblocks);
|
||||
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if (!empty($hide) && confirm_sesskey()) {
|
||||
if (!$block = get_record('block', 'id', $hide)) {
|
||||
if (!empty($_GET['hide'])) {
|
||||
if (!$block = get_record('blocks', 'id', $_GET['hide'])) {
|
||||
error("Block doesn't exist!");
|
||||
}
|
||||
set_field('block', 'visible', '0', 'id', $block->id); // Hide block
|
||||
set_field('blocks', 'visible', '0', 'id', $block->id); // Hide block
|
||||
}
|
||||
|
||||
if (!empty($show) && confirm_sesskey() ) {
|
||||
if (!$block = get_record('block', 'id', $show)) {
|
||||
if (!empty($_GET['show'])) {
|
||||
if (!$block = get_record('blocks', 'id', $_GET['show'])) {
|
||||
error("Block doesn't exist!");
|
||||
}
|
||||
set_field('block', 'visible', '1', 'id', $block->id); // Show block
|
||||
set_field('blocks', 'visible', '1', 'id', $block->id); // Show block
|
||||
}
|
||||
|
||||
if (!empty($multiple) && confirm_sesskey()) {
|
||||
if (!$block = blocks_get_record($multiple)) {
|
||||
error("Block doesn't exist!");
|
||||
}
|
||||
$block->multiple = !$block->multiple;
|
||||
update_record('block', $block);
|
||||
}
|
||||
if (!empty($delete)) {
|
||||
|
||||
if (!empty($delete) && confirm_sesskey()) {
|
||||
|
||||
if (!$block = blocks_get_record($delete)) {
|
||||
if (!$block = get_record('blocks', 'id', $delete)) {
|
||||
error("Block doesn't exist!");
|
||||
}
|
||||
|
||||
if (!block_is_compatible($block->name)) {
|
||||
$strblockname = $block->name;
|
||||
}
|
||||
else {
|
||||
$blockobject = block_instance($block->name);
|
||||
$strblockname = $blockobject->get_title();
|
||||
}
|
||||
$blockobject = block_instance($block->name, $site);
|
||||
$strblockname = $blockobject->get_title();
|
||||
|
||||
if (!$confirm) {
|
||||
if (!$_GET['confirm']) {
|
||||
notice_yesno(get_string('blockdeleteconfirm', '', $strblockname),
|
||||
'blocks.php?delete='.$block->id.'&confirm=1&sesskey='.$USER->sesskey,
|
||||
'blocks.php?delete='.$block->id.'&confirm=1',
|
||||
'blocks.php');
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_footer();
|
||||
exit;
|
||||
|
||||
} else {
|
||||
// Inform block it's about to be deleted
|
||||
$blockobject = block_instance($block->name);
|
||||
if ($blockobject) {
|
||||
$blockobject->before_delete(); //only if we can create instance, block might have been already removed
|
||||
}
|
||||
|
||||
// First delete instances and then block
|
||||
$instances = get_records('block_instance', 'blockid', $block->id);
|
||||
if(!empty($instances)) {
|
||||
foreach($instances as $instance) {
|
||||
blocks_delete_instance($instance);
|
||||
blocks_delete_instance($instance, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete block
|
||||
if (!delete_records('block', 'id', $block->id)) {
|
||||
if (!delete_records('blocks', 'id', $block->id)) {
|
||||
notify("Error occurred while deleting the $strblockname record from blocks table");
|
||||
}
|
||||
|
||||
blocks_update_every_block_by_id($block->id, 'delete'); // Delete blocks in all courses by id
|
||||
|
||||
// Then the tables themselves
|
||||
|
||||
if ($tables = $db->Metatables()) {
|
||||
$prefix = $CFG->prefix.$block->name;
|
||||
$prefix2 = $CFG->prefix.'block_'.$block->name;
|
||||
foreach ($tables as $table) {
|
||||
if (strpos($table, $prefix) === 0 || strpos($table, $prefix2) === 0) {
|
||||
/// If the match has been due to the 1st condition, debug to developers
|
||||
if (strpos($table, $prefix) === 0) {
|
||||
debugging('This block has some wrongly named tables. See Moodle Docs coding guidelines (and MDL-6786)', DEBUG_DEVELOPER);
|
||||
}
|
||||
/// Strip prefix from $table
|
||||
$table = preg_replace("/^{$CFG->prefix}/", '', $table);
|
||||
$xmldb_table = new XMLDBTable($table);
|
||||
if (!drop_table($xmldb_table, true, false)) {
|
||||
if (strpos($table, $prefix) === 0) {
|
||||
if (!execute_sql("DROP TABLE $table", false)) {
|
||||
notify("ERROR: while trying to drop table $table");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Delete the capabilities that were defined by this block
|
||||
capabilities_cleanup('block/'.$block->name);
|
||||
|
||||
$a->block = $strblockname;
|
||||
$a->directory = $CFG->dirroot.'/blocks/'.$block->name;
|
||||
@@ -132,117 +105,68 @@
|
||||
|
||||
/// Get and sort the existing blocks
|
||||
|
||||
if (false === ($blocks = get_records('block'))) {
|
||||
if (!$blocks = get_records('blocks')) {
|
||||
error('No blocks found!'); // Should never happen
|
||||
}
|
||||
|
||||
$incompatible = array();
|
||||
|
||||
foreach ($blocks as $block) {
|
||||
if(!block_is_compatible($block->name)) {
|
||||
notify('Block '. $block->name .' is not compatible with the current version of Moodle and needs to be updated by a programmer.');
|
||||
$incompatible[] = $block;
|
||||
continue;
|
||||
}
|
||||
if(($blockobject = block_instance($block->name)) === false) {
|
||||
if(($blockobject = block_instance($block->name, NULL)) === false) {
|
||||
// Failed to load
|
||||
continue;
|
||||
}
|
||||
$blockbyname[$blockobject->get_title()] = $block->id;
|
||||
$blockobjects[$block->id] = $blockobject;
|
||||
}
|
||||
|
||||
if(empty($blockbyname)) {
|
||||
error('One or more blocks are registered in the database, but they all failed to load!');
|
||||
}
|
||||
|
||||
ksort($blockbyname);
|
||||
|
||||
/// Print the table of all blocks
|
||||
|
||||
$table = new flexible_table('admin-blocks-compatible');
|
||||
if (empty($THEME->custompix)) {
|
||||
$pixpath = '../pix';
|
||||
// [pj] This is not used anywhere, but I'm leaving it in for the future
|
||||
//$modpixpath = '../mod';
|
||||
} else {
|
||||
$pixpath = '../theme/'.$CFG->theme.'/pix';
|
||||
// [pj] This is not used anywhere, but I'm leaving it in for the future
|
||||
//$modpixpath = '../theme/'.$CFG->theme.'/pix/mod';
|
||||
}
|
||||
|
||||
$table->define_columns(array('name', 'instances', 'version', 'hideshow', 'multiple', 'delete', 'settings'));
|
||||
$table->define_headers(array($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strmultiple, $strdelete, $strsettings));
|
||||
$table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php');
|
||||
|
||||
$table->set_attribute('cellspacing', '0');
|
||||
$table->set_attribute('id', 'blocks');
|
||||
$table->set_attribute('class', 'generaltable generalbox');
|
||||
|
||||
$table->setup();
|
||||
$table->head = array ($strname, $strcourses, $strversion, $strhide.'/'.$strshow, $strdelete, $strsettings);
|
||||
$table->align = array ('LEFT', 'RIGHT', 'LEFT', 'CENTER', 'CENTER', 'CENTER');
|
||||
$table->wrap = array ("NOWRAP", "", "", "", "","");
|
||||
$table->size = array ("100%", "10", "10", "10", "10","12");
|
||||
$table->width = "100";
|
||||
|
||||
foreach ($blockbyname as $blockname => $blockid) {
|
||||
|
||||
// [pj] This is not used anywhere, but I'm leaving it in for the future
|
||||
//$icon = "<img src=\"$modpixpath/$block->name/icon.gif\" hspace=10 height=16 width=16 border=0>";
|
||||
$blockobject = $blockobjects[$blockid];
|
||||
|
||||
$delete = '<a href="blocks.php?delete='.$blockid.'&sesskey='.$USER->sesskey.'">'.$strdelete.'</a>';
|
||||
$delete = '<a href="blocks.php?delete='.$blockid.'">'.$strdelete.'</a>';
|
||||
|
||||
$settings = ''; // By default, no configuration
|
||||
if($blockobject->has_config()) {
|
||||
$settings = '<a href="block.php?block='.$blockid.'">'.$strsettings.'</a>';
|
||||
}
|
||||
|
||||
$count = count_records('block_instance', 'blockid', $blockid);
|
||||
$count = blocks_get_courses_using_block_by_id($blockid);
|
||||
$class = ''; // Nothing fancy, by default
|
||||
|
||||
if ($blocks[$blockid]->visible) {
|
||||
$visible = '<a href="blocks.php?hide='.$blockid.'&sesskey='.$USER->sesskey.'" title="'.$strhide.'">'.
|
||||
'<img src="'.$CFG->pixpath.'/i/hide.gif" height="16" width="16" alt="" /></a>';
|
||||
$visible = '<a href="blocks.php?hide='.$blockid.'" title="'.$strhide.'">'.
|
||||
'<img src="'.$pixpath.'/i/hide.gif" style="height: 16px; width: 16px;" /></a>';
|
||||
} else {
|
||||
$visible = '<a href="blocks.php?show='.$blockid.'&sesskey='.$USER->sesskey.'" title="'.$strshow.'">'.
|
||||
'<img src="'.$CFG->pixpath.'/i/show.gif" height="16" width="16" alt="" /></a>';
|
||||
$visible = '<a href="blocks.php?show='.$blockid.'" title="'.$strshow.'">'.
|
||||
'<img src="'.$pixpath.'/i/show.gif" style="height: 16px; width: 16px;" /></a>';
|
||||
$class = ' class="dimmed_text"'; // Leading space required!
|
||||
}
|
||||
if ($blockobject->instance_allow_multiple()) {
|
||||
if($blocks[$blockid]->multiple) {
|
||||
$multiple = '<span style="white-space: nowrap;">'.get_string('yes').' (<a href="blocks.php?multiple='.$blockid.'&sesskey='.$USER->sesskey.'">'.get_string('change', 'admin').'</a>)</span>';
|
||||
}
|
||||
else {
|
||||
$multiple = '<span style="white-space: nowrap;">'.get_string('no').' (<a href="blocks.php?multiple='.$blockid.'&sesskey='.$USER->sesskey.'">'.get_string('change', 'admin').'</a>)</span>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$multiple = '';
|
||||
}
|
||||
|
||||
$table->add_data(array(
|
||||
'<span'.$class.'>'.$blockobject->get_title().'</span>',
|
||||
$count,
|
||||
$blockobject->get_version(),
|
||||
$visible,
|
||||
$multiple,
|
||||
$delete,
|
||||
$settings
|
||||
));
|
||||
$table->data[] = array ('<p'.$class.'>'.$blockobject->get_title().'</p>', $count, $blockobject->get_version(), $visible, $delete, $settings);
|
||||
}
|
||||
|
||||
$table->print_html();
|
||||
|
||||
if(!empty($incompatible)) {
|
||||
print_heading(get_string('incompatibleblocks', 'admin'));
|
||||
|
||||
$table = new flexible_table('admin-blocks-incompatible');
|
||||
|
||||
$table->define_columns(array('block', 'delete'));
|
||||
$table->define_headers(array($strname, $strdelete));
|
||||
$table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/blocks.php');
|
||||
|
||||
$table->set_attribute('cellspacing', '0');
|
||||
$table->set_attribute('id', 'incompatible');
|
||||
$table->set_attribute('class', 'generaltable generalbox');
|
||||
|
||||
$table->setup();
|
||||
|
||||
foreach ($incompatible as $block) {
|
||||
$table->add_data(array(
|
||||
$block->name,
|
||||
'<a href="blocks.php?delete='.$block->id.'&sesskey='.$USER->sesskey.'">'.$strdelete.'</a>',
|
||||
));
|
||||
}
|
||||
$table->print_html();
|
||||
}
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
echo '<p>';
|
||||
print_table($table);
|
||||
echo '</p>';
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,496 @@
|
||||
<form method="post" action="config.php" name="form">
|
||||
|
||||
<table cellpadding=9 cellspacing=0 >
|
||||
<tr valign=top>
|
||||
<td align=right><p>lang:</td>
|
||||
<td>
|
||||
<?php choose_from_menu (get_list_of_languages(), "lang", $config->lang, "", "", ""); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configlang") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>langmenu:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("no");
|
||||
$options[1] = get_string("yes");
|
||||
|
||||
choose_from_menu ($options, "langmenu", $config->langmenu, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configlangmenu") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>langlist:</td>
|
||||
<td>
|
||||
<input name=langlist type=text size=40 value="<?php p($config->langlist) ?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configlanglist") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>locale:</td>
|
||||
<td>
|
||||
<input name=locale type=text size=10 value="<?php p($config->locale) ?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configlocale") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>timezone:</td>
|
||||
<td><?php
|
||||
if (abs($config->timezone) > 13) {
|
||||
$config->timezone = 99;
|
||||
}
|
||||
$timenow = time();
|
||||
|
||||
for ($tz = -26; $tz <= 26; $tz++) {
|
||||
$zone = (float)$tz/2.0;
|
||||
$usertime = $timenow + ($tz * 1800);
|
||||
if ($tz == 0) {
|
||||
$timezones["$zone"] = gmstrftime("%a, %I:%M %p", $usertime)." (GMT)";
|
||||
} else if ($tz < 0) {
|
||||
$timezones["$zone"] = gmstrftime("%a, %I:%M %p", $usertime)." (GMT$zone)";
|
||||
} else {
|
||||
$timezones["$zone"] = gmstrftime("%a, %I:%M %p", $usertime)." (GMT+$zone)";
|
||||
}
|
||||
}
|
||||
|
||||
choose_from_menu ($timezones, "timezone", $config->timezone, get_string("serverlocaltime"), "", "99");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configtimezone") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>country:</td>
|
||||
<td><?php choose_from_menu (get_list_of_countries(), "country", $config->country, get_string("selectacountry"), "") ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configcountry") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>smtphosts:</td>
|
||||
<td>
|
||||
<input name=smtphosts type=text size=30 value="<?php p($config->smtphosts)?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configsmtphosts") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>smtpuser:</td>
|
||||
<td>
|
||||
<input name=smtpuser type=text size=10 value="<?php p($config->smtpuser)?>">
|
||||
</td>
|
||||
<td rowspan=2>
|
||||
<?php print_string("configsmtpuser") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>smtppass:</td>
|
||||
<td>
|
||||
<input name=smtppass type=text size=10 value="<?php p($config->smtppass)?>">
|
||||
</td>
|
||||
</TR>
|
||||
<tr valign=top>
|
||||
<td align=right><p>gdversion:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("gdnot");
|
||||
$options[1] = get_string("gd1");
|
||||
$options[2] = get_string("gd2");
|
||||
|
||||
$installed = check_gd_version();
|
||||
|
||||
choose_from_menu ($options, "gdversion", $installed, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configgdversion") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>htmleditor:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("allownot");
|
||||
$options[1] = get_string("allow");
|
||||
choose_from_menu ($options, "htmleditor", $config->htmleditor, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("confightmleditor") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>maxeditingtime:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[3600] = get_string("numminutes", "", 60);
|
||||
$options[2700] = get_string("numminutes", "", 45);
|
||||
$options[1800] = get_string("numminutes", "", 30);
|
||||
$options[900] = get_string("numminutes", "", 15);
|
||||
$options[300] = get_string("numminutes", "", 5);
|
||||
$options[60] = get_string("numminutes", "", 1);
|
||||
|
||||
choose_from_menu ($options, "maxeditingtime", $config->maxeditingtime, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configmaxeditingtime") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>longtimenosee:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[1000] = get_string("numdays", "", 1000);
|
||||
$options[365] = get_string("numdays", "", 365);
|
||||
$options[180] = get_string("numdays", "", 180);
|
||||
$options[150] = get_string("numdays", "", 150);
|
||||
$options[120] = get_string("numdays", "", 120);
|
||||
$options[90] = get_string("numdays", "", 90);
|
||||
$options[60] = get_string("numdays", "", 60);
|
||||
$options[30] = get_string("numdays", "", 30);
|
||||
$options[21] = get_string("numdays", "", 21);
|
||||
$options[14] = get_string("numdays", "", 14);
|
||||
$options[7] = get_string("numdays", "", 7);
|
||||
|
||||
choose_from_menu ($options, "longtimenosee", $config->longtimenosee, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configlongtimenosee") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>deleteunconfirmed:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("never");
|
||||
$options[168] = get_string("numdays", "", 7);
|
||||
$options[144] = get_string("numdays", "", 6);
|
||||
$options[120] = get_string("numdays", "", 5);
|
||||
$options[96] = get_string("numdays", "", 4);
|
||||
$options[72] = get_string("numdays", "", 3);
|
||||
$options[48] = get_string("numdays", "", 2);
|
||||
$options[24] = get_string("numdays", "", 1);
|
||||
$options[12] = get_string("numhours", "", 12);
|
||||
$options[6] = get_string("numhours", "", 6);
|
||||
$options[1] = get_string("numhours", "", 1);
|
||||
|
||||
choose_from_menu ($options, "deleteunconfirmed", $config->deleteunconfirmed, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configdeleteunconfirmed") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>loglifetime:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("neverdeletelogs");
|
||||
$options[1000] = get_string("numdays", "", 1000);
|
||||
$options[365] = get_string("numdays", "", 365);
|
||||
$options[180] = get_string("numdays", "", 180);
|
||||
$options[150] = get_string("numdays", "", 150);
|
||||
$options[120] = get_string("numdays", "", 120);
|
||||
$options[90] = get_string("numdays", "", 90);
|
||||
$options[60] = get_string("numdays", "", 60);
|
||||
$options[30] = get_string("numdays", "", 30);
|
||||
|
||||
choose_from_menu ($options, "loglifetime", $config->loglifetime, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configloglifetime") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>sessiontimeout:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[14400] = get_string("numhours", "", 4);
|
||||
$options[10800] = get_string("numhours", "", 3);
|
||||
$options[7200] = get_string("numhours", "", 2);
|
||||
$options[5400] = get_string("numhours", "", "1.5");
|
||||
$options[3600] = get_string("numminutes", "", 60);
|
||||
$options[2700] = get_string("numminutes", "", 45);
|
||||
$options[1800] = get_string("numminutes", "", 30);
|
||||
$options[900] = get_string("numminutes", "", 15);
|
||||
$options[300] = get_string("numminutes", "", 5);
|
||||
|
||||
choose_from_menu ($options, "sessiontimeout", $config->sessiontimeout, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configsessiontimeout") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>sessioncookie:</td>
|
||||
<td>
|
||||
<input name=sessioncookie type=text size=10 value="<?php p($config->sessioncookie)?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configsessioncookie") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>zip:</td>
|
||||
<td>
|
||||
<input name=zip type=text size=30 value="<?php p($config->zip) ?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configzip") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>unzip:</td>
|
||||
<td>
|
||||
<input name=unzip type=text size=30 value="<?php p($config->unzip) ?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configunzip") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>slasharguments:</td>
|
||||
<td>
|
||||
<?php unset($options);
|
||||
$options[0] = "file.php?file=/pic.jpg";
|
||||
$options[1] = "file.php/pic.jpg";
|
||||
|
||||
choose_from_menu ($options, "slasharguments", $config->slasharguments, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configslasharguments") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>proxyhost:</td>
|
||||
<td>
|
||||
<input name=proxyhost type=text size=30 value="<?php p($config->proxyhost) ?>">
|
||||
</td>
|
||||
<td rowspan=2>
|
||||
<?php print_string("configproxyhost") ?>
|
||||
</td>
|
||||
</TR>
|
||||
<tr valign=top>
|
||||
<td align=right><p>proxyport:</td>
|
||||
<td>
|
||||
<input name=proxyport type=text size=5 value="<?php p($config->proxyport) ?>">
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>debug:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[7] = get_string("no");
|
||||
$options[15] = get_string("yes");
|
||||
|
||||
choose_from_menu ($options, "debug", $config->debug, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configdebug") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>framename:</td>
|
||||
<td>
|
||||
<?php
|
||||
if (empty($config->framename)) {
|
||||
$config->framename = "_top";
|
||||
}
|
||||
?>
|
||||
<input name=framename type=text size=15 value="<?php p($config->framename)?>">
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configframename") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>secureforms:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("no");
|
||||
$options[1] = get_string("yes");
|
||||
|
||||
choose_from_menu ($options, "secureforms", $config->secureforms, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configsecureforms") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>teacherassignteachers:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("no");
|
||||
$options[1] = get_string("yes");
|
||||
|
||||
choose_from_menu ($options, "teacherassignteachers", $config->teacherassignteachers, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configteacherassignteachers") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>allowunenroll:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("no");
|
||||
$options[1] = get_string("yes");
|
||||
|
||||
choose_from_menu ($options, "allowunenroll", $config->allowunenroll, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configallowunenroll") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>maxbytes:</td>
|
||||
<td>
|
||||
<?php
|
||||
$options = get_max_upload_sizes();
|
||||
choose_from_menu ($options, "maxbytes", $config->maxbytes, "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configmaxbytes") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>fullnamedisplay:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options['language'] = get_string('language');
|
||||
$options['firstname lastname'] = get_string('firstname') . ' + ' . get_string('lastname');
|
||||
$options['lastname firstname'] = get_string('lastname') . ' + ' . get_string('firstname');
|
||||
$options['firstname'] = get_string('firstname');
|
||||
|
||||
choose_from_menu ($options, "fullnamedisplay", $config->fullnamedisplay, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configfullnamedisplay") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>extendedusernamechars:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("no");
|
||||
$options[1] = get_string("yes");
|
||||
|
||||
choose_from_menu ($options, "extendedusernamechars", $config->extendedusernamechars, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configextendedusernamechars") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>forcelogin:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string('no');
|
||||
$options[1] = get_string('yes');
|
||||
|
||||
choose_from_menu ($options, "forcelogin", $config->forcelogin, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configforcelogin") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>forceloginforprofiles:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string('no');
|
||||
$options[1] = get_string('yes');
|
||||
|
||||
choose_from_menu ($options, "forceloginforprofiles", $config->forceloginforprofiles, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configforceloginforprofiles") ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p>opentogoogle:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("no");
|
||||
$options[1] = get_string("yes");
|
||||
|
||||
choose_from_menu ($options, "opentogoogle", $config->opentogoogle, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php print_string("configopentogoogle") ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr valign=top>
|
||||
<td align=right><p>enablerssfeeds:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string("no");
|
||||
$options[1] = get_string("yes");
|
||||
|
||||
choose_from_menu ($options, "enablerssfeeds", $config->enablerssfeeds, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
print_string("configenablerssfeeds");
|
||||
//Check for required functions...
|
||||
if(!function_exists('utf8_encode')) {
|
||||
echo "<font color=\"red\"> You need to add XML support to your PHP installation.</font>";
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan=3 align=center>
|
||||
<input type="submit" value="<?php print_string("savechanges") ?>"></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</form>
|
||||
+36
-115
@@ -1,67 +1,50 @@
|
||||
<?php // $Id$
|
||||
<?PHP // $Id$
|
||||
// config.php - allows admin to edit all configuration variables
|
||||
|
||||
require_once('../config.php');
|
||||
require_once("../config.php");
|
||||
|
||||
$focus = '';
|
||||
|
||||
if ($site = get_site()) { // If false then this is a new installation
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
if (!isadmin()) {
|
||||
error("Only the admin can use this page");
|
||||
}
|
||||
}
|
||||
|
||||
/// This is to overcome the "insecure forms paradox"
|
||||
if (isset($secureforms) and $secureforms == 0) {
|
||||
$match = 'nomatch';
|
||||
$match = "nomatch";
|
||||
} else {
|
||||
$match = '';
|
||||
$match = "";
|
||||
}
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($config = data_submitted($match)) {
|
||||
|
||||
if (!empty($USER->id)) { // Additional identity check
|
||||
if (!confirm_sesskey()) {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
}
|
||||
if ($config = data_submitted($match)) {
|
||||
|
||||
validate_form($config, $err);
|
||||
|
||||
if (count($err) == 0) {
|
||||
print_header();
|
||||
foreach ($config as $name => $value) {
|
||||
if ($name == "sessioncookie") {
|
||||
$value = eregi_replace("[^a-zA-Z0-9_]", "", $value);
|
||||
$value = eregi_replace("[^a-zA-Z]", "", $value);
|
||||
}
|
||||
if ($name == "defaultallowedmodules") {
|
||||
$value = implode(',',$value);
|
||||
}
|
||||
if ($name == 'hiddenuserfields') {
|
||||
if (in_array('none', $value)) {
|
||||
$value = '';
|
||||
} else {
|
||||
$value = implode(',',$value);
|
||||
}
|
||||
}
|
||||
if ($name == "locale") {
|
||||
$value = trim($value);
|
||||
}
|
||||
$conf = new object();
|
||||
unset($conf);
|
||||
$conf->name = $name;
|
||||
$conf->value = $value;
|
||||
if ($current = get_record('config', 'name', $name)) {
|
||||
if ($current = get_record("config", "name", $name)) {
|
||||
$conf->id = $current->id;
|
||||
if (! update_record('config', $conf)) {
|
||||
error("Error: Could not update $name to $value");
|
||||
if (! update_record("config", $conf)) {
|
||||
notify("Could not update $name to $value");
|
||||
}
|
||||
} else {
|
||||
if (! insert_record('config', $conf)) {
|
||||
error("Error: could not add new variable $name !");
|
||||
if (! insert_record("config", $conf)) {
|
||||
notify("Error: could not add new variable $name !");
|
||||
}
|
||||
}
|
||||
}
|
||||
redirect('index.php');
|
||||
redirect("index.php", get_string("changessaved"), 1);
|
||||
exit;
|
||||
|
||||
} else {
|
||||
@@ -69,20 +52,23 @@
|
||||
$focus = "form.$key";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Otherwise fill and print the form.
|
||||
|
||||
if (empty($config)) {
|
||||
$config = $CFG;
|
||||
if (!$config->locale = get_field("config", "value", "name", "locale")) {
|
||||
$config->locale = $CFG->lang;
|
||||
}
|
||||
}
|
||||
if (empty($focus)) {
|
||||
$focus = "";
|
||||
}
|
||||
|
||||
$sesskey = !empty($USER->id) ? $USER->sesskey : '';
|
||||
|
||||
|
||||
$stradmin = get_string('administration');
|
||||
$strconfiguration = get_string('configuration');
|
||||
$strconfigvariables = get_string('configvariables', 'admin');
|
||||
$stradmin = get_string("administration");
|
||||
$strconfiguration = get_string("configuration");
|
||||
$strconfigvariables = get_string("configvariables");
|
||||
|
||||
if ($site) {
|
||||
print_header("$site->shortname: $strconfigvariables", $site->fullname,
|
||||
@@ -92,80 +78,13 @@
|
||||
} else {
|
||||
print_header();
|
||||
print_heading($strconfigvariables);
|
||||
print_simple_box(get_string('configintro', 'admin'), 'center', "50%");
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Get all the configuration fields and helptext
|
||||
require('configvars.php');
|
||||
|
||||
/// Cycle through the sections to get the sectionnames
|
||||
$linktext = '';
|
||||
foreach($configvars as $sectionname=>$section) {
|
||||
if ($linktext !== '') {
|
||||
$linktext .= ' | ';
|
||||
}
|
||||
$linktext .= '<a href="#configsection'.$sectionname.'">'.get_string('configsection'.$sectionname, 'admin').'</a>';
|
||||
}
|
||||
|
||||
echo "<center>$linktext</center>\n";
|
||||
|
||||
|
||||
echo '<form method="post" action="config.php" name="form">';
|
||||
echo '<center><input type="submit" value="'.get_string('savechanges').'" /></center>';
|
||||
|
||||
/// Cycle through each section of the configuration
|
||||
foreach ($configvars as $sectionname=>$section) {
|
||||
|
||||
print_heading('<a name="configsection'.$sectionname.'"></a>'.get_string('configsection'.$sectionname, 'admin'));
|
||||
|
||||
$table = NULL;
|
||||
$table->data = array();
|
||||
foreach ($section as $configvariable=>$configobject) {
|
||||
$table->data[] = array ( $configvariable.': ',
|
||||
$configobject->field
|
||||
);
|
||||
if ($configobject->display_warning()) {
|
||||
$table->data[] = array ( ' ',
|
||||
'<span class="configwarning">'.$configobject->warning.'</span>'
|
||||
);
|
||||
}
|
||||
$table->data[] = array ( ' ',
|
||||
'<span class="confighelp">'.$configobject->help.'</span>'
|
||||
);
|
||||
$table->align = array ('right', 'left');
|
||||
}
|
||||
print_table($table);
|
||||
|
||||
}
|
||||
echo '<center>';
|
||||
echo '<input type="hidden" name="sesskey" value="'.$sesskey.'" />';
|
||||
echo '<input type="submit" value="'.get_string('savechanges').'" />';
|
||||
echo '</center>';
|
||||
|
||||
echo '</form>';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// Lock some options
|
||||
|
||||
$httpsurl = str_replace('http://', 'https://', $CFG->wwwroot);
|
||||
if ($httpsurl != $CFG->wwwroot) {
|
||||
if (ini_get('allow_url_fopen')) {
|
||||
if ((($fh = @fopen($httpsurl, 'r')) == false) and ($config->loginhttps == 0)) {
|
||||
echo '<script type="text/javascript">'."\n";
|
||||
echo '<!--'."\n";
|
||||
echo "eval('document.form.loginhttps.disabled=true');\n";
|
||||
echo '-->'."\n";
|
||||
echo '</script>'."\n";
|
||||
}
|
||||
}
|
||||
print_simple_box(get_string("configintro"), "center", "50%");
|
||||
echo "<br />";
|
||||
}
|
||||
|
||||
print_simple_box_start("center", "", "$THEME->cellheading");
|
||||
include("config.html");
|
||||
print_simple_box_end();
|
||||
|
||||
if ($site) {
|
||||
print_footer();
|
||||
@@ -177,9 +96,11 @@
|
||||
|
||||
function validate_form(&$form, &$err) {
|
||||
|
||||
// Currently no checks are needed ...
|
||||
// if (empty($form->fullname))
|
||||
// $err["fullname"] = get_string("missingsitename");
|
||||
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
require_once("../config.php");
|
||||
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("Only admins can access this page");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
redirect("index.php");
|
||||
}
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strconfiguration = get_string("configuration");
|
||||
|
||||
print_header("$site->shortname: $stradministration: $strconfiguration", "$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> $strconfiguration");
|
||||
|
||||
print_heading($strconfiguration);
|
||||
|
||||
$table->align = array ("right", "left");
|
||||
|
||||
$table->data[] = array("<b><a href=\"config.php\">".get_string("configvariables")."</a></b>",
|
||||
get_string("adminhelpconfigvariables"));
|
||||
$table->data[] = array("<b><a href=\"site.php\">".get_string("sitesettings")."</a></b>",
|
||||
get_string("adminhelpsitesettings"));
|
||||
$table->data[] = array("<b><a href=\"../theme/index.php\">".get_string("themes")."</a></b>",
|
||||
get_string("adminhelpthemes"));
|
||||
$table->data[] = array("<b><a href=\"lang.php\">".get_string("language")."</a></b>",
|
||||
get_string("adminhelplanguage"));
|
||||
$table->data[] = array("<b><a href=\"modules.php\">".get_string("managemodules")."</a></b>",
|
||||
get_string("adminhelpmanagemodules"));
|
||||
$table->data[] = array("<b><a href=\"blocks.php\">".get_string("manageblocks")."</a></b>",
|
||||
get_string("adminhelpmanageblocks"));
|
||||
$table->data[] = array("<b><a href=\"filters.php\">".get_string("managefilters")."</a></b>",
|
||||
get_string("adminhelpmanagefilters"));
|
||||
if (!isset($CFG->disablescheduledbackups)) {
|
||||
$table->data[] = array("<b><a href=\"backup.php\">".get_string("backup")."</a></b>",
|
||||
get_string("adminhelpbackup"));
|
||||
}
|
||||
|
||||
print_table($table);
|
||||
|
||||
print_footer($site);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -1,660 +0,0 @@
|
||||
<?php // $Id$
|
||||
// Shane Elliott
|
||||
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
|
||||
|
||||
/// Add new sitewide configuration variables to this file.
|
||||
|
||||
|
||||
/// $configvars is parsed by config.php
|
||||
/// It is an array of arrays of objects
|
||||
/// $configvars[sectionname][configvariablename] = configvar object
|
||||
$configvars = array();
|
||||
|
||||
|
||||
/// no, yes strings and menu options are used in a number of places
|
||||
/// so we define them here to save time on repeatedly calling
|
||||
/// get_string()
|
||||
$stryes = get_string('yes');
|
||||
$strno = get_string('no');
|
||||
|
||||
$noyesoptions[0] = $strno;
|
||||
$noyesoptions[1] = $stryes;
|
||||
|
||||
|
||||
|
||||
/// A class to hold the configurable information
|
||||
/// $field - the html code for the form field
|
||||
/// $help - help text for the field
|
||||
/// $warning - optional warning text to be displayed
|
||||
/// method display_warning() - a generic function that can be used in an extended class
|
||||
/// e.g. enablerssfeeds
|
||||
class configvar {
|
||||
|
||||
var $field;
|
||||
var $help;
|
||||
var $warning;
|
||||
|
||||
function configvar($help, $field, $warning='') {
|
||||
$this->help = $help;
|
||||
$this->field = $field;
|
||||
$this->warning = $warning;
|
||||
}
|
||||
|
||||
function display_warning() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// Miscellaneous config variables
|
||||
////////////////////////////////////////////////////////////////////
|
||||
$misc = array();
|
||||
|
||||
|
||||
/// maxeditingtime
|
||||
unset($options);
|
||||
$options[3600] = get_string('numminutes', '', 60);
|
||||
$options[2700] = get_string('numminutes', '', 45);
|
||||
$options[1800] = get_string('numminutes', '', 30);
|
||||
$options[900] = get_string('numminutes', '', 15);
|
||||
$options[300] = get_string('numminutes', '', 5);
|
||||
$options[60] = get_string('numminutes', '', 1);
|
||||
|
||||
$misc['maxeditingtime'] = new configvar (get_string('configmaxeditingtime', 'admin'),
|
||||
choose_from_menu ($options, 'maxeditingtime', $config->maxeditingtime, '', '', '', true) );
|
||||
|
||||
/// debug
|
||||
unset($options);
|
||||
$options[5] = $strno;
|
||||
$options[15] = $stryes;
|
||||
|
||||
$misc['debug'] = new configvar (get_string('configdebug', 'admin'),
|
||||
choose_from_menu ($options, 'debug', $config->debug, '', '', '', true) );
|
||||
|
||||
$misc['perfdebug'] = new configvar (get_string('configperfdebug', 'admin'),
|
||||
choose_from_menu ($options, 'perfdebug', $config->perfdebug, '', '', '', true) );
|
||||
|
||||
/// enablerssfeeds
|
||||
class configvarrss extends configvar {
|
||||
function display_warning() {
|
||||
return (!function_exists('utf8_encode'));
|
||||
}
|
||||
}
|
||||
|
||||
$misc['enablerssfeeds'] = new configvarrss (get_string('configenablerssfeeds', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'enablerssfeeds', $config->enablerssfeeds, '', '', '', true),
|
||||
'<font color="red"> You need to add XML support to your PHP installation.</font>' );
|
||||
|
||||
$misc['mymoodleredirect'] = new configvar (get_string('configmymoodleredirect','admin'),
|
||||
choose_from_menu($noyesoptions,'mymoodleredirect',$config->mymoodleredirect,'','','',true));
|
||||
|
||||
unset($options);
|
||||
$options[5] = get_string('worldblogs','blog');
|
||||
$options[4] = get_string('siteblogs','blog');
|
||||
$options[3] = get_string('courseblogs','blog');
|
||||
$options[2] = get_string('groupblogs','blog');
|
||||
$options[1] = get_string('personalblogs','blog');
|
||||
$options[0] = get_string('disableblogs','blog');
|
||||
|
||||
$misc['bloglevel'] = new configvar (get_string('configbloglevel', 'admin'),
|
||||
choose_from_menu ($options, 'bloglevel', $config->bloglevel,'','','',true));
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// OPERATING SYSTEM config variables
|
||||
////////////////////////////////////////////////////////////////////
|
||||
$operatingsystem = array();
|
||||
|
||||
/// gdversion
|
||||
unset($options);
|
||||
$options[0] = get_string('gdnot');
|
||||
$options[1] = get_string('gd1');
|
||||
$options[2] = get_string('gd2');
|
||||
|
||||
$installed = check_gd_version();
|
||||
|
||||
$operatingsystem['gdversion'] = new configvar (get_string('configgdversion', 'admin'),
|
||||
choose_from_menu ($options, 'gdversion', $installed, '', '', '', true) );
|
||||
|
||||
/// dbsessions
|
||||
$operatingsystem['dbsessions'] = new configvar (get_string('configdbsessions', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'dbsessions', $config->dbsessions, '', '', '', true) );
|
||||
|
||||
/// sessiontimeout
|
||||
unset($options);
|
||||
$options[14400] = get_string('numhours', '', 4);
|
||||
$options[10800] = get_string('numhours', '', 3);
|
||||
$options[7200] = get_string('numhours', '', 2);
|
||||
$options[5400] = get_string('numhours', '', '1.5');
|
||||
$options[3600] = get_string('numminutes', '', 60);
|
||||
$options[2700] = get_string('numminutes', '', 45);
|
||||
$options[1800] = get_string('numminutes', '', 30);
|
||||
$options[900] = get_string('numminutes', '', 15);
|
||||
$options[300] = get_string('numminutes', '', 5);
|
||||
|
||||
$operatingsystem['sessiontimeout'] = new configvar (get_string('configsessiontimeout', 'admin'),
|
||||
choose_from_menu ($options, 'sessiontimeout', $config->sessiontimeout, '', '', '', true) );
|
||||
|
||||
/// sessioncookie
|
||||
$operatingsystem['sessioncookie'] = new configvar (get_string('configsessioncookie', 'admin'),
|
||||
'<input name="sessioncookie" type="text" size="10" value="'.s($config->sessioncookie).'" alt="sessioncookie" />' );
|
||||
$operatingsystem['sessioncookiepath'] = new configvar (get_string('configsessioncookiepath', 'admin'),
|
||||
'<input name="sessioncookiepath" type="text" size="10" value="'.s($config->sessioncookiepath).'" alt="sessioncookiepath" />' );
|
||||
|
||||
/// zip
|
||||
$operatingsystem['zip'] = new configvar (get_string('configzip', 'admin'),
|
||||
'<input name="zip" type="text" size="30" value="'.s($config->zip).'" alt="zip" />' );
|
||||
|
||||
/// unzip
|
||||
$operatingsystem['unzip'] = new configvar (get_string('configunzip', 'admin'),
|
||||
'<input name="unzip" type="text" size="30" value="'.s($config->unzip).'" alt="unzip" />' );
|
||||
|
||||
$operatingsystem['pathtodu'] = new configvar(get_string('configpathtodu', 'admin'),
|
||||
'<input name="pathtodu" type="text" size="30" value="'.s($config->pathtodu).'" alt="pathtodu" />');
|
||||
|
||||
/// slasharguments
|
||||
unset($options);
|
||||
$options[0] = "file.php?file=/1/pic.jpg";
|
||||
$options[1] = "file.php/1/pic.jpg";
|
||||
|
||||
$operatingsystem['slasharguments'] = new configvar (get_string('configslasharguments', 'admin'),
|
||||
choose_from_menu ($options, 'slasharguments', $config->slasharguments, '', '', '', true) );
|
||||
|
||||
/// proxyhost
|
||||
$operatingsystem['proxyhost'] = new configvar (get_string('configproxyhost', 'admin'),
|
||||
'<input name="proxyhost" type="text" size="30" value="'.s($config->proxyhost).'" alt="proxyhost" />' );
|
||||
|
||||
/// proxyport
|
||||
$operatingsystem['proxyport'] = new configvar ('',
|
||||
'<input name="proxyport" type="text" size="5" value="'.s($config->proxyport).'" alt="proxyport" />' );
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// PERMISSIONS config variables
|
||||
////////////////////////////////////////////////////////////////////
|
||||
$permissions = array();
|
||||
|
||||
/// teacherassignteachers
|
||||
$permissions['teacherassignteachers'] = new configvar (get_string('configteacherassignteachers', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'teacherassignteachers', $config->teacherassignteachers, '', '', '', true) );
|
||||
|
||||
/// allowunenroll
|
||||
$permissions['allowunenroll'] = new configvar (get_string('configallowunenroll', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'allowunenroll', $config->allowunenroll, '', '', '', true) );
|
||||
|
||||
/// allusersaresitestudents
|
||||
$permissions['allusersaresitestudents'] = new configvar (get_string('configallusersaresitestudents', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'allusersaresitestudents', $config->allusersaresitestudents, '', '', '', true) );
|
||||
|
||||
/// showsiteparticipantslist
|
||||
unset($options);
|
||||
$options[0] = get_string('siteteachers');
|
||||
$options[1] = get_string('allteachers');
|
||||
$options[2] = get_string('studentsandteachers');
|
||||
|
||||
$permissions['showsiteparticipantslist'] = new configvar (get_string('configshowsiteparticipantslist', 'admin'),
|
||||
choose_from_menu ($options, 'showsiteparticipantslist', $config->showsiteparticipantslist, '', '', '', true) );
|
||||
|
||||
/// forcelogin
|
||||
$permissions['forcelogin'] = new configvar (get_string('configforcelogin', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'forcelogin', $config->forcelogin, '', '', '', true) );
|
||||
|
||||
/// forceloginforprofiles
|
||||
$permissions['forceloginforprofiles'] = new configvar (get_string('configforceloginforprofiles', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'forceloginforprofiles', $config->forceloginforprofiles, '', '', '', true) );
|
||||
|
||||
/// opentogoogle
|
||||
$permissions['opentogoogle'] = new configvar (get_string('configopentogoogle', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'opentogoogle', $config->opentogoogle, '', '', '', true) );
|
||||
|
||||
/// maxbytes
|
||||
$options = get_max_upload_sizes();
|
||||
|
||||
$permissions['maxbytes'] = new configvar (get_string('configmaxbytes', 'admin'),
|
||||
choose_from_menu ($options, 'maxbytes', $config->maxbytes, '', '', 0, true) );
|
||||
|
||||
/// messaging
|
||||
$permissions['messaging'] = new configvar (get_string('configmessaging', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'messaging', $config->messaging, '', '', '', true) );
|
||||
|
||||
/// allowobjectembed
|
||||
$permissions['allowobjectembed'] = new configvar (get_string('configallowobjectembed', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'allowobjectembed', $config->allowobjectembed, '', '', '', true) );
|
||||
|
||||
/// enabletrusttext
|
||||
$permissions['enabletrusttext'] = new configvar (get_string('configenabletrusttext', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'enabletrusttext', $config->enabletrusttext, '', '', '', true) );
|
||||
|
||||
unset($options);
|
||||
$options['none'] = 'No courses';
|
||||
$options['all'] = 'All courses';
|
||||
$options['requested'] = 'Requested courses';
|
||||
|
||||
$permissions['restrictmodulesfor'] = new configvar (get_string('configrestrictmodulesfor','admin'),
|
||||
' <script language="JavaScript">
|
||||
function togglemodules(index) {
|
||||
if (index == 0) {
|
||||
document.getElementById(\'allowedmodules\').disabled=true;
|
||||
}
|
||||
else {
|
||||
document.getElementById(\'allowedmodules\').disabled=false;
|
||||
}
|
||||
}
|
||||
</script>'.
|
||||
choose_from_menu($options,'restrictmodulesfor',$config->restrictmodulesfor,'','togglemodules(this.selectedIndex);','',true) );
|
||||
|
||||
$permissions['restrictbydefault'] = new configvar (get_string('configrestrictbydefault','admin'),
|
||||
choose_from_menu($noyesoptions, 'restrictbydefault',$config->restrictbydefault,'','','',true) );
|
||||
|
||||
$allowstr = '<select name="defaultallowedmodules[]" id="allowedmodules" multiple="multiple" size="10"'.((empty($config->restrictmodulesfor)) ? "disabled=\"disabled\"" : "").'>';
|
||||
|
||||
$allowedmodules = array();
|
||||
if (!empty($config->defaultallowedmodules)) {
|
||||
$allowedmodules = explode(',',$config->defaultallowedmodules);
|
||||
}
|
||||
|
||||
// On a fresh install of Moodle, this could be empty; prevent a warning on the following loop.
|
||||
if (!$mods = get_records("modules")) {
|
||||
$mods = array();
|
||||
}
|
||||
$s = "selected=\"selected\"";
|
||||
$allowstr .= '<option value="0" '.((empty($allowedmodules)) ? $s : '').'>'.get_string('allownone').'</option>'."\n";
|
||||
foreach ($mods as $mod) {
|
||||
$selected = "";
|
||||
if (in_array($mod->id,$allowedmodules))
|
||||
$selected = $s;
|
||||
$allowstr .= '<option '.$selected.' value="'.$mod->id.'">'.$mod->name.'</option>'."\n";
|
||||
}
|
||||
$allowstr .= '</select>';
|
||||
|
||||
$permissions['defaultallowedmodules'] = new configvar (get_string('configdefaultallowedmodules','admin'),$allowstr);
|
||||
|
||||
|
||||
/// course requests
|
||||
$reqcourse['enablecourserequests'] = new configvar (get_string('configenablecourserequests', 'admin'),
|
||||
choose_from_menu ($noyesoptions,'enablecourserequests',$config->enablecourserequests,'','','',true) );
|
||||
|
||||
/// default category for course requests
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
$reqcourse['defaultrequestedcategory'] = new configvar (get_string('configdefaultrequestedcategory', 'admin'),
|
||||
choose_from_menu (make_categories_options(), 'defaultrequestedcategory',$config->defaultrequestedcategory,'','','',true) );
|
||||
|
||||
$reqcourse['requestedteachername'] = new configvar (get_string('configrequestedteachername','admin'),
|
||||
'<input type="text" name="requestedteachername" size="20" maxlength="100" value="'.s($config->requestedteachername).'" />');
|
||||
|
||||
$reqcourse['requestedteachersname'] = new configvar (get_string('configrequestedteachersname','admin'),
|
||||
'<input type="text" name="requestedteachersname" size="20" maxlength="100" value="'.s($config->requestedteachersname).'" />');
|
||||
|
||||
$reqcourse['requestedstudentname'] = new configvar (get_string('configrequestedstudentname','admin'),
|
||||
'<input type="text" name="requestedstudentname" size="20" maxlength="100" value="'.s($config->requestedstudentname).'" />');
|
||||
|
||||
$reqcourse['requestedstudentsname'] = new configvar (get_string('configrequestedstudentsname','admin'),
|
||||
'<input type="text" name="requestedstudentsname" size="20" maxlength="100" value="'.s($config->requestedstudentsname).'" />');
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// INTERFACE config variables
|
||||
////////////////////////////////////////////////////////////////////
|
||||
$interface = array();
|
||||
|
||||
/// language settings
|
||||
$interface['lang'] = new configvar ( get_string('configlang', 'admin'),
|
||||
choose_from_menu(get_list_of_languages(), 'lang', $config->lang, '', '', '', true) );
|
||||
|
||||
/// language menu
|
||||
$interface['langmenu'] = new configvar ( get_string('configlangmenu', 'admin'),
|
||||
choose_from_menu($noyesoptions, 'langmenu', $config->langmenu, '', '', '', true) );
|
||||
|
||||
/// language list
|
||||
$interface['langlist'] = new configvar ( get_string('configlanglist', 'admin'),
|
||||
'<input name="langlist" type="text" size="60" value="'.s($config->langlist).'" alt="langlist" />' );
|
||||
|
||||
/// language menu
|
||||
$interface['langcache'] = new configvar ( get_string('configlangcache', 'admin'),
|
||||
choose_from_menu($noyesoptions, 'langcache', $config->langcache, '', '', '', true) );
|
||||
|
||||
/// locale
|
||||
$interface['locale'] = new configvar ( get_string('configlocale', 'admin'),
|
||||
'<input name="locale" type="text" size="15" value="'.s($config->locale).'" alt="locale" />' );
|
||||
|
||||
/// docroot
|
||||
$interface['docroot'] = new configvar ( get_string('configdocroot', 'admin'),
|
||||
'<input name="docroot" type="text" size="60" value="'.s($config->docroot).'" alt="docroot" />' );
|
||||
|
||||
/// doctonewwindow
|
||||
$interface['doctonewwindow'] = new configvar ( get_string('configdoctonewwindow', 'admin'),
|
||||
choose_from_menu($noyesoptions, 'doctonewwindow', $config->doctonewwindow, '', '', '', true) );
|
||||
|
||||
/// timezone
|
||||
$interface['timezone'] = new configvar ( get_string('configtimezone', 'admin'),
|
||||
choose_from_menu (get_list_of_timezones(), 'timezone', $config->timezone, get_string('serverlocaltime'), '', '99', true ) );
|
||||
|
||||
/// country
|
||||
$interface['country'] = new configvar ( get_string('configcountry', 'admin'),
|
||||
choose_from_menu (get_list_of_countries(), 'country', $config->country, get_string('selectacountry'), '', 0, true) );
|
||||
|
||||
/// framename
|
||||
if (empty($config->framename)) {
|
||||
$config->framename = "_top";
|
||||
}
|
||||
|
||||
$interface['framename'] = new configvar (get_string('configframename', 'admin'),
|
||||
'<input name="framename" type="text" size="15" value="'.s($config->framename).'" alt="framename" />' );
|
||||
|
||||
/// language list
|
||||
$interface['themelist'] = new configvar ( get_string('configthemelist', 'admin'),
|
||||
'<input name="themelist" type="text" size="60" value="'.s($config->themelist).'" alt="themelist" />' );
|
||||
|
||||
/// user themes
|
||||
$interface['allowuserthemes'] = new configvar (get_string('configallowuserthemes', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'allowuserthemes', $config->allowuserthemes, '', '', '', true) );
|
||||
|
||||
/// course themes
|
||||
$interface['allowcoursethemes'] = new configvar (get_string('configallowcoursethemes', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'allowcoursethemes', $config->allowcoursethemes, '', '', '', true) );
|
||||
|
||||
/// allowuserblockhiding
|
||||
$interface['allowuserblockhiding'] = new configvar (get_string('configallowuserblockhiding', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'allowuserblockhiding', $config->allowuserblockhiding, '', '', '', true) );
|
||||
|
||||
/// showblocksonmodpages
|
||||
$interface['showblocksonmodpages'] = new configvar (get_string('configshowblocksonmodpages', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'showblocksonmodpages', $config->showblocksonmodpages, '', '', '', true) );
|
||||
|
||||
|
||||
/// tabselectedtofront
|
||||
$interface['tabselectedtofront'] = new configvar (get_string('tabselectedtofront', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'tabselectedtofront', $config->tabselectedtofront, '', '', '', true) );
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// USER config variables
|
||||
////////////////////////////////////////////////////////////////////
|
||||
$user = array();
|
||||
|
||||
/// sitepolicy
|
||||
$user['sitepolicy'] = new configvar (get_string('configsitepolicy', 'admin'),
|
||||
'<input type="text" name="sitepolicy" size="60" value="'.$config->sitepolicy.'" alt="sitepolicy" />' );
|
||||
|
||||
|
||||
/// fullnamedisplay
|
||||
unset($options);
|
||||
$options['language'] = get_string('language');
|
||||
$options['firstname lastname'] = get_string('firstname') . ' + ' . get_string('lastname');
|
||||
$options['lastname firstname'] = get_string('lastname') . ' + ' . get_string('firstname');
|
||||
$options['firstname'] = get_string('firstname');
|
||||
|
||||
$user['fullnamedisplay'] = new configvar (get_string('configfullnamedisplay', 'admin'),
|
||||
choose_from_menu ($options, 'fullnamedisplay', $config->fullnamedisplay, '', '', '', true) );
|
||||
|
||||
/// extendedusernamechars
|
||||
$user['extendedusernamechars'] = new configvar (get_string('configextendedusernamechars', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'extendedusernamechars', $config->extendedusernamechars, '', '', '', true) );
|
||||
|
||||
/// autologinguests
|
||||
$user['autologinguests'] = new configvar (get_string('configautologinguests', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'autologinguests', $config->autologinguests, '', '', '', true) );
|
||||
|
||||
/// hiddenuserfields
|
||||
$fields = array('none', 'description', 'city', 'country', 'webpage', 'icqnumber', 'skypeid', 'yahooid', 'aimid', 'msnid', 'lastaccess');
|
||||
if (empty($config->hiddenuserfields)) {
|
||||
$config->hiddenuserfields = 'none';
|
||||
}
|
||||
$configfields = array_flip(explode(',', $config->hiddenuserfields));
|
||||
$fieldoptions = '';
|
||||
foreach ($fields as $value) {
|
||||
$fieldoptions .= '<option value="'.$value.'"';
|
||||
if (isset($configfields[$value])) {
|
||||
$fieldoptions .= ' selected="selected"';
|
||||
}
|
||||
$fieldoptions .= '>'.get_string($value).'</option>';
|
||||
}
|
||||
|
||||
$user['hiddenuserfields'] = new configvar (get_string('confighiddenuserfields', 'admin'),
|
||||
'<select id="menuhiddenuserfields" name="hiddenuserfields[]" size="10" multiple="multiple">'.$fieldoptions.'</select>' );
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// SECURITY config variables
|
||||
////////////////////////////////////////////////////////////////////
|
||||
$security = array();
|
||||
|
||||
/// displayloginfailures
|
||||
unset($options);
|
||||
$options[''] = get_string('nobody');
|
||||
$options['admin'] = get_string('administrators');
|
||||
$options['teacher'] = get_string('administratorsandteachers');
|
||||
$options['everybody'] = get_string('everybody');
|
||||
|
||||
$security['displayloginfailures'] = new configvar (get_string('configdisplayloginfailures', 'admin'),
|
||||
choose_from_menu($options, 'displayloginfailures', $config->displayloginfailures, '', '', '', true) );
|
||||
|
||||
/// notifyloginfailures
|
||||
unset($options);
|
||||
$options[''] = get_string('nobody');
|
||||
$options['mainadmin'] = get_string('administrator');
|
||||
$options['alladmins'] = get_string('administratorsall');
|
||||
|
||||
$security['notifyloginfailures'] = new configvar (get_string('confignotifyloginfailures', 'admin'),
|
||||
choose_from_menu($options, 'notifyloginfailures', $config->notifyloginfailures, '', '', '', true) );
|
||||
|
||||
/// notifyloginthreshold
|
||||
unset($options);
|
||||
for ($i=1; $i<=100; $i++) {
|
||||
$options[$i] = "$i";
|
||||
}
|
||||
|
||||
$security['notifyloginthreshold'] = new configvar (get_string('confignotifyloginthreshold', 'admin'),
|
||||
choose_from_menu($options, 'notifyloginthreshold', $config->notifyloginthreshold, '', '', '', true) );
|
||||
|
||||
/// secureforms
|
||||
$security['secureforms'] = new configvar (get_string('configsecureforms', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'secureforms', $config->secureforms, '', '', '', true) );
|
||||
|
||||
/// loginhttps
|
||||
$security['loginhttps'] = new configvar (get_string('configloginhttps', 'admin'),
|
||||
choose_from_menu ($noyesoptions, 'loginhttps', $config->loginhttps, '', '', '', true) );
|
||||
|
||||
/// runclamonupload
|
||||
$security['runclamonupload'] = new configvar (get_string('configrunclamonupload', 'admin'),
|
||||
choose_from_menu($noyesoptions, 'runclamonupload', $config->runclamonupload, '', '', '', true) );
|
||||
|
||||
/// pathtoclam
|
||||
$security['pathtoclam'] = new configvar (get_string('configpathtoclam', 'admin'),
|
||||
'<input type="text" name="pathtoclam" size="30" value="'.$config->pathtoclam.'" alt="pathtoclam" />' );
|
||||
|
||||
/// quarantinedir
|
||||
$security['quarantinedir'] = new configvar (get_string('configquarantinedir', 'admin'),
|
||||
'<input type="text" name="quarantinedir" size="30" value="'.$config->quarantinedir.'" alt="quarantinedir" />' );
|
||||
|
||||
/// clamfailureonupload
|
||||
unset($options);
|
||||
$options['donothing'] = get_string('configclamdonothing', 'admin');
|
||||
$options['actlikevirus'] = get_string('configclamactlikevirus', 'admin');
|
||||
|
||||
$security['clamfailureonupload'] = new configvar (get_string('configclamfailureonupload', 'admin'),
|
||||
choose_from_menu($options, 'clamfailureonupload', $config->clamfailureonupload, '', '', '', true) );
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// MAINTENANCE config variables
|
||||
////////////////////////////////////////////////////////////////////
|
||||
$maintenance = array();
|
||||
|
||||
/// longtimenosee
|
||||
unset($options);
|
||||
$options[0] = get_string('never');
|
||||
$options[1000] = get_string('numdays', '', 1000);
|
||||
$options[365] = get_string('numdays', '', 365);
|
||||
$options[180] = get_string('numdays', '', 180);
|
||||
$options[150] = get_string('numdays', '', 150);
|
||||
$options[120] = get_string('numdays', '', 120);
|
||||
$options[90] = get_string('numdays', '', 90);
|
||||
$options[60] = get_string('numdays', '', 60);
|
||||
$options[30] = get_string('numdays', '', 30);
|
||||
$options[21] = get_string('numdays', '', 21);
|
||||
$options[14] = get_string('numdays', '', 14);
|
||||
$options[7] = get_string('numdays', '', 7);
|
||||
|
||||
$maintenance['longtimenosee'] = new configvar (get_string('configlongtimenosee', 'admin'),
|
||||
choose_from_menu ($options, 'longtimenosee', $config->longtimenosee, '', '', '', true) );
|
||||
|
||||
/// deleteunconfirmed
|
||||
unset($options);
|
||||
$options[0] = get_string('never');
|
||||
$options[168] = get_string('numdays', '', 7);
|
||||
$options[144] = get_string('numdays', '', 6);
|
||||
$options[120] = get_string('numdays', '', 5);
|
||||
$options[96] = get_string('numdays', '', 4);
|
||||
$options[72] = get_string('numdays', '', 3);
|
||||
$options[48] = get_string('numdays', '', 2);
|
||||
$options[24] = get_string('numdays', '', 1);
|
||||
$options[12] = get_string('numhours', '', 12);
|
||||
$options[6] = get_string('numhours', '', 6);
|
||||
$options[1] = get_string('numhours', '', 1);
|
||||
|
||||
$maintenance['deleteunconfirmed'] = new configvar (get_string('configdeleteunconfirmed', 'admin'),
|
||||
choose_from_menu ($options, 'deleteunconfirmed', $config->deleteunconfirmed, '', '', '', true) );
|
||||
|
||||
/// loglifetime
|
||||
unset($options);
|
||||
$options[0] = get_string('neverdeletelogs');
|
||||
$options[1000] = get_string('numdays', '', 1000);
|
||||
$options[365] = get_string('numdays', '', 365);
|
||||
$options[180] = get_string('numdays', '', 180);
|
||||
$options[150] = get_string('numdays', '', 150);
|
||||
$options[120] = get_string('numdays', '', 120);
|
||||
$options[90] = get_string('numdays', '', 90);
|
||||
$options[60] = get_string('numdays', '', 60);
|
||||
$options[30] = get_string('numdays', '', 30);
|
||||
|
||||
$maintenance['loglifetime'] = new configvar (get_string('configloglifetime', 'admin'),
|
||||
choose_from_menu ($options, 'loglifetime', $config->loglifetime, '', '', '', true) );
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// MAIL config variables
|
||||
////////////////////////////////////////////////////////////////////
|
||||
$mail = array();
|
||||
|
||||
/// smtphosts
|
||||
$mail['smtphosts'] = new configvar (get_string('configsmtphosts', 'admin'),
|
||||
'<input name="smtphosts" type="text" size="30" value="'.s($config->smtphosts).'" alt="smtphosts" />' );
|
||||
|
||||
/// smtpuser
|
||||
$mail['smtpuser'] = new configvar (get_string('configsmtpuser', 'admin'),
|
||||
'<input name="smtpuser" type="text" size="10" value="'.s($config->smtpuser).'" alt="smtpuser" />' );
|
||||
|
||||
/// smtppass
|
||||
$mail['smtppass'] = new configvar ('',
|
||||
'<input name="smtppass" type="password" size="10" value="'.s($config->smtppass).'" alt="smtppass" />' );
|
||||
|
||||
/// noreplyaddress
|
||||
$mail['noreplyaddress'] = new configvar (get_string('confignoreplyaddress', 'admin'),
|
||||
'<input name="noreplyaddress" type="text" size="30" value="'.s($config->noreplyaddress).'" alt="noreplyaddress" />' );
|
||||
|
||||
/// digestmailtime
|
||||
$hours = array();
|
||||
for ($i=0; $i<=23; $i++) {
|
||||
$hours[$i] = sprintf("%02d",$i);
|
||||
}
|
||||
|
||||
$mail['digestmailtime'] = new configvar (get_string('configdigestmailtime', 'admin'),
|
||||
choose_from_menu($hours, 'digestmailtime', $config->digestmailtime, '', '', 0, true) );
|
||||
|
||||
/// allowemailaddresses
|
||||
$mail['allowemailaddresses'] = new configvar (get_string('configallowemailaddresses', 'admin'),
|
||||
'<input name="allowemailaddresses" type="text" size="60" value="'.s($config->allowemailaddresses).'" alt="allowemailaddresses" />' );
|
||||
|
||||
/// denyemailaddresses
|
||||
$mail['denyemailaddresses'] = new configvar (get_string('configdenyemailaddresses', 'admin'),
|
||||
'<input name="denyemailaddresses" type="text" size="60" value="'.s($config->denyemailaddresses).'" alt="denyemailaddresses" />' );
|
||||
|
||||
if (!empty($CFG->unicodedb)) { ///These options are only available if running under unicodedb
|
||||
/// sitemailcharset
|
||||
unset($options);
|
||||
unset($charsets);
|
||||
$charsets = get_list_of_charsets();
|
||||
$options['0'] = get_string('none');
|
||||
$options = array_merge($options, $charsets);
|
||||
$mail['sitemailcharset'] = new configvar (get_string('configsitemailcharset', 'admin'),
|
||||
choose_from_menu($options, 'sitemailcharset', $config->sitemailcharset, '', '', '', true));
|
||||
|
||||
/// allowusermailcharset
|
||||
$mail['allowusermailcharset'] = new configvar (get_string('configallowusermailcharset', 'admin'),
|
||||
choose_from_menu($noyesoptions, 'allowusermailcharset', $config->allowusermailcharset, '', '', '', true));
|
||||
}
|
||||
|
||||
/// enable stats
|
||||
if (empty($CFG->disablestatsprocessing)) {
|
||||
$stats['enablestats'] = new configvar (get_string('configenablestats','admin'),
|
||||
choose_from_menu($noyesoptions, 'enablestats', $config->enablestats, '', '', '', true) );
|
||||
|
||||
unset($options);
|
||||
$options['none'] = get_string('none');
|
||||
$options[60*60*24*7] = get_string('numweeks','moodle',1);
|
||||
$options[60*60*24*14] = get_string('numweeks','moodle',2);
|
||||
$options[60*60*24*21] = get_string('numweeks','moodle',3);
|
||||
$options[60*60*24*28] = get_string('nummonths','moodle',1);
|
||||
$options[60*60*24*56] = get_string('nummonths','moodle',2);
|
||||
$options[60*60*24*84] = get_string('nummonths','moodle',3);
|
||||
$options[60*60*24*112] = get_string('nummonths','moodle',4);
|
||||
$options[60*60*24*140] = get_string('nummonths','moodle',5);
|
||||
$options[60*60*24*168] = get_string('nummonths','moodle',6);
|
||||
$options['all'] = get_string('all');
|
||||
|
||||
$stats['statsfirstrun'] = new configvar (get_string('configstatsfirstrun','admin'),
|
||||
choose_from_menu($options,'statsfirstrun',$config->statsfirstrun,'','','',true) );
|
||||
|
||||
unset($options);
|
||||
$options[0] = get_string('untilcomplete');
|
||||
$options[60*60] = '1 '.get_string('hour');
|
||||
$options[60*60*2] = '2 '.get_string('hours');
|
||||
$options[60*60*3] = '3 '.get_string('hours');
|
||||
$options[60*60*4] = '4 '.get_string('hours');
|
||||
$options[60*60*5] = '5 '.get_string('hours');
|
||||
$options[60*60*6] = '6 '.get_string('hours');
|
||||
$options[60*60*7] = '7 '.get_string('hours');
|
||||
$options[60*60*8] = '8 '.get_string('hours');
|
||||
|
||||
if (empty($config->statsruntimestarthour)) {
|
||||
$config->statsruntimestarthour = 0;
|
||||
}
|
||||
if (empty($config->statsruntimestartminute)) {
|
||||
$config->statsruntimestartminute = 0;
|
||||
}
|
||||
|
||||
$stats['statsmaxruntime'] = new configvar (get_string('configstatsmaxruntime','admin'),
|
||||
choose_from_menu($options,'statsmaxruntime',$config->statsmaxruntime,'','','',true) );
|
||||
|
||||
$stats['statsruntimestart'] = new configvar (get_string('configstatsruntimestart','admin'),
|
||||
print_time_selector("statsruntimestarthour","statsruntimestartminute",make_timestamp(2000,1,1,$config->statsruntimestarthour,$config->statsruntimestartminute),5,true) );
|
||||
|
||||
$stats['statsuserthreshold'] = new configvar (get_string('configstatsuserthreshold','admin'),
|
||||
'<input type="text" name="statsuserthreshold" size="4" value="'.$config->statsuserthreshold.'" />');
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
$configvars['interface'] = $interface;
|
||||
$configvars['security'] = $security;
|
||||
$configvars['operatingsystem'] = $operatingsystem;
|
||||
$configvars['maintenance'] = $maintenance;
|
||||
$configvars['mail'] = $mail;
|
||||
$configvars['user'] = $user;
|
||||
$configvars['permissions'] = $permissions;
|
||||
$configvars['requestedcourse'] = $reqcourse;
|
||||
$configvars['misc'] = $misc;
|
||||
if (empty($CFG->disablestatsprocessing)) {
|
||||
$configvars['stats'] = $stats;
|
||||
}
|
||||
|
||||
?>
|
||||
Executable
+148
@@ -0,0 +1,148 @@
|
||||
<?PHP // $Id$
|
||||
// Admin only script to assign course creator rights to users
|
||||
|
||||
require_once("../config.php");
|
||||
|
||||
define("MAX_USERS_PER_PAGE", 50);
|
||||
|
||||
optional_variable($search, "");
|
||||
optional_variable($add, "");
|
||||
optional_variable($remove, "");
|
||||
|
||||
if (! $site = get_site()) {
|
||||
redirect("$CFG->wwwroot/$CFG->admin/index.php");
|
||||
}
|
||||
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("You must be an administrator to use this page.");
|
||||
}
|
||||
|
||||
$primaryadmin = get_admin();
|
||||
|
||||
/// assign all of the configurable language strings
|
||||
$stringstoload = array (
|
||||
"assigncreators",
|
||||
"administration",
|
||||
"existingcreators",
|
||||
"noexistingcreators",
|
||||
"potentialcreators",
|
||||
"nopotentialcreators",
|
||||
"addcreator",
|
||||
"removecreator",
|
||||
"search",
|
||||
"searchagain",
|
||||
"users",
|
||||
"toomanytoshow",
|
||||
"searchresults"
|
||||
);
|
||||
|
||||
foreach ($stringstoload as $stringtoload){
|
||||
$strstringtoload = "str" . $stringtoload;
|
||||
$$strstringtoload = get_string($stringtoload);
|
||||
}
|
||||
|
||||
if ($search) {
|
||||
$searchstring = $strsearchagain;
|
||||
} else {
|
||||
$searchstring = $strsearch;
|
||||
}
|
||||
|
||||
print_header("$site->shortname: $strassigncreators",
|
||||
"$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> <a href=\"users.php\">$strusers</a> ->
|
||||
$strassigncreators", "");
|
||||
|
||||
/// Add a creator if one is specified
|
||||
|
||||
if (!empty($_GET['add'])) {
|
||||
if (! add_creator($add)) {
|
||||
error("Could not add that creator!");
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove a creator if one is specified.
|
||||
|
||||
if (!empty($_GET['remove'])) {
|
||||
if (! remove_creator($remove)) {
|
||||
error("Could not remove that creator!");
|
||||
}
|
||||
}
|
||||
|
||||
/// Print a help notice about this page
|
||||
if (empty($add) and empty($remove) and empty($search)) {
|
||||
print_simple_box("<center>".get_string("adminhelpassigncreators")."</center>", "center", "50%");
|
||||
}
|
||||
|
||||
/// Get all existing creators
|
||||
$creators = get_creators();
|
||||
|
||||
/// Print the lists of existing and potential creators
|
||||
echo "<table cellpadding=2 cellspacing=10 align=center>";
|
||||
echo "<tr><th width=50%>$strexistingcreators</th><th width=50%>$strpotentialcreators</th></tr>";
|
||||
echo "<tr><td width=50% nowrap valign=top>";
|
||||
|
||||
/// First, show existing creators
|
||||
|
||||
if (! $creators) {
|
||||
echo "<p align=center>$strnoexistingcreators</a>";
|
||||
|
||||
$creatorlist = "";
|
||||
|
||||
} else {
|
||||
$creatorarray = array();
|
||||
foreach ($creators as $creator) {
|
||||
$creatorarray[] = $creator->id;
|
||||
echo "<p align=right>".fullname($creator, true).", $creator->email ";
|
||||
echo "<a href=\"creators.php?remove=$creator->id\"
|
||||
title=\"$strremovecreator\"><img src=\"../pix/t/right.gif\"
|
||||
border=0></a>";
|
||||
echo "</p>";
|
||||
}
|
||||
$creatorlist = implode(",",$creatorarray);
|
||||
unset($creatorarray);
|
||||
}
|
||||
|
||||
echo "<td width=50% nowrap valign=top>";
|
||||
|
||||
/// Print list of potential creators
|
||||
|
||||
$usercount = get_users(false, $search, true, $creatorlist);
|
||||
|
||||
if ($usercount == 0) {
|
||||
echo "<p align=center>$strnopotentialcreators</p>";
|
||||
|
||||
} else if ($usercount > MAX_USERS_PER_PAGE) {
|
||||
echo "<p align=center>$strtoomanytoshow ($usercount) </p>";
|
||||
|
||||
} else {
|
||||
|
||||
if ($search) {
|
||||
echo "<p align=center>($strsearchresults : $search)</p>";
|
||||
}
|
||||
|
||||
if (!$users = get_users(true, $search, true, $creatorlist)) {
|
||||
error("Could not get users!");
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
$fullname = fullname($user, TRUE);
|
||||
echo "<p align=left><a href=\"creators.php?add=$user->id\"".
|
||||
"title=\"$straddcreator\"><img src=\"../pix/t/left.gif\"".
|
||||
"border=0></a> $fullname, $user->email";
|
||||
}
|
||||
}
|
||||
|
||||
if ($search or $usercount > MAX_USERS_PER_PAGE) {
|
||||
echo "<form action=creators.php method=post>";
|
||||
echo "<input type=text name=search size=20>";
|
||||
echo "<input type=submit value=\"$searchstring\">";
|
||||
echo "</form>";
|
||||
}
|
||||
|
||||
echo "</tr></table>";
|
||||
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
+49
-225
@@ -11,12 +11,9 @@
|
||||
/// eg wget -q -O /dev/null 'http://moodle.somewhere.edu/admin/cron.php'
|
||||
/// or php /web/moodle/admin/cron.php
|
||||
|
||||
$FULLME = "cron";
|
||||
|
||||
$starttime = microtime();
|
||||
|
||||
/// The following is a hack necessary to allow this script to work well
|
||||
/// from the command line.
|
||||
|
||||
define('FULLME', 'cron');
|
||||
|
||||
/// The current directory in PHP version 4.3.0 and above isn't necessarily the
|
||||
/// directory of the script when run from the command line. The require_once()
|
||||
@@ -26,51 +23,23 @@
|
||||
chdir(dirname($_SERVER['argv'][0]));
|
||||
}
|
||||
|
||||
require_once(dirname(__FILE__) . '/../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once("../config.php");
|
||||
|
||||
if (!$alreadyadmin = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
||||
if (!$alreadyadmin = isadmin()) {
|
||||
unset($_SESSION['USER']);
|
||||
unset($USER);
|
||||
unset($_SESSION['SESSION']);
|
||||
unset($SESSION);
|
||||
$USER = get_admin(); /// Temporarily, to provide environment for this script
|
||||
// we need to override the admin timezone to the moodle timezone!
|
||||
$USER->timezone = $CFG->timezone;
|
||||
}
|
||||
|
||||
//unset test cookie, user must login again anyway
|
||||
setcookie('MoodleSessionTest'.$CFG->sessioncookie, '', time() - 3600, '/');
|
||||
|
||||
/// switch to site language and locale
|
||||
if (!empty($CFG->courselang)) {
|
||||
unset ($CFG->courselang);
|
||||
}
|
||||
if (!empty($SESSION->lang)) {
|
||||
unset ($SESSION->lang);
|
||||
}
|
||||
$USER->lang = '';
|
||||
moodle_setlocale();
|
||||
|
||||
/// send mime type and encoding
|
||||
if (check_browser_version('MSIE')) {
|
||||
//ugly IE hack to work around downloading instead of viewing
|
||||
@header('Content-Type: text/html; charset='.current_charset());
|
||||
echo "<xmp>"; //<pre> is not good enough for us here
|
||||
} else {
|
||||
//send proper plaintext header
|
||||
@header('Content-Type: text/plain; charset='.current_charset());
|
||||
}
|
||||
|
||||
/// Start output log
|
||||
echo "<pre>\n";
|
||||
|
||||
$timenow = time();
|
||||
|
||||
mtrace("Server Time: ".date('r',$timenow)."\n\n");
|
||||
echo "Server Time: ".date('r',$timenow)."\n\n";
|
||||
|
||||
/// Run all cron jobs for each module
|
||||
|
||||
mtrace("Starting activity modules");
|
||||
if ($mods = get_records_select("modules", "cron > 0 AND (($timenow - lastcron) > cron)")) {
|
||||
foreach ($mods as $mod) {
|
||||
$libfile = "$CFG->dirroot/mod/$mod->name/lib.php";
|
||||
@@ -78,49 +47,15 @@
|
||||
include_once($libfile);
|
||||
$cron_function = $mod->name."_cron";
|
||||
if (function_exists($cron_function)) {
|
||||
mtrace("Processing module function $cron_function ...", '');
|
||||
if ($cron_function()) {
|
||||
if (! set_field("modules", "lastcron", $timenow, "id", $mod->id)) {
|
||||
mtrace("Error: could not update timestamp for $mod->fullname");
|
||||
echo "Error: could not update timestamp for $mod->fullname\n";
|
||||
}
|
||||
}
|
||||
mtrace("done.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mtrace("Finished activity modules");
|
||||
|
||||
mtrace("Starting blocks");
|
||||
if ($blocks = get_records_select("block", "cron > 0 AND (($timenow - lastcron) > cron)")) {
|
||||
// we will need the base class.
|
||||
require_once($CFG->dirroot.'/blocks/moodleblock.class.php');
|
||||
foreach ($blocks as $block) {
|
||||
$blockfile = $CFG->dirroot.'/blocks/'.$block->name.'/block_'.$block->name.'.php';
|
||||
if (file_exists($blockfile)) {
|
||||
require_once($blockfile);
|
||||
$classname = 'block_'.$block->name;
|
||||
$blockobj = new $classname;
|
||||
if (method_exists($blockobj,'cron')) {
|
||||
mtrace("Processing cron function for ".$block->name.'....','');
|
||||
if ($blockobj->cron()) {
|
||||
if (!set_field('block','lastcron',$timenow,'id',$block->id)) {
|
||||
mtrace('Error: could not update timestamp for '.$block->name);
|
||||
}
|
||||
}
|
||||
mtrace('done.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
mtrace("Finished blocks");
|
||||
|
||||
if (!empty($CFG->langcache)) {
|
||||
mtrace('Updating languages cache');
|
||||
get_list_of_languages();
|
||||
}
|
||||
|
||||
|
||||
/// Run all core cron jobs, but not every time since they aren't too important.
|
||||
/// These don't have a timer to reduce load, so we'll use a random number
|
||||
@@ -130,18 +65,16 @@
|
||||
$random100 = rand(0,100);
|
||||
|
||||
if ($random100 < 20) { // Approximately 20% of the time.
|
||||
mtrace("Running clean-up tasks...");
|
||||
echo "Running clean-up tasks...\n";
|
||||
|
||||
/// Unenrol users who haven't logged in for $CFG->longtimenosee
|
||||
|
||||
if ($CFG->longtimenosee) { // value in days
|
||||
$longtime = $timenow - ($CFG->longtimenosee * 3600 * 24);
|
||||
if ($assigns = get_users_longtimenosee($longtime)) {
|
||||
foreach ($assigns as $assign) {
|
||||
if ($context = get_context_instance(CONTEXT_COURSE, $assign->courseid)) {
|
||||
if (role_unassign(0, $assign->id, 0, $context->id)) {
|
||||
mtrace("Deleted student enrolment for user $assign->id from course $assign->courseid");
|
||||
}
|
||||
if ($students = get_users_longtimenosee($longtime)) {
|
||||
foreach ($students as $student) {
|
||||
if (unenrol_student($student->userid, $student->course)) {
|
||||
echo "Deleted student enrolment for user $student->userid from course $student->course\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,35 +83,26 @@
|
||||
|
||||
/// Delete users who haven't confirmed within required period
|
||||
|
||||
if (!empty($CFG->deleteunconfirmed)) {
|
||||
$oneweek = $timenow - ($CFG->deleteunconfirmed * 3600);
|
||||
if ($users = get_users_unconfirmed($oneweek)) {
|
||||
foreach ($users as $user) {
|
||||
if (delete_records('user', 'id', $user->id)) {
|
||||
mtrace("Deleted unconfirmed user for ".fullname($user, true)." ($user->id)");
|
||||
}
|
||||
$oneweek = $timenow - ($CFG->deleteunconfirmed * 3600);
|
||||
if ($users = get_users_unconfirmed($oneweek)) {
|
||||
foreach ($users as $user) {
|
||||
if (delete_records("user", "id", $user->id)) {
|
||||
echo "Deleted unconfirmed user for ".fullname($user, true)." ($user->id)\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
flush();
|
||||
|
||||
|
||||
|
||||
/// Delete users who haven't completed profile within required period
|
||||
|
||||
if (!empty($CFG->deleteunconfirmed)) {
|
||||
$oneweek = $timenow - ($CFG->deleteunconfirmed * 3600);
|
||||
if ($users = get_users_not_fully_set_up($oneweek)) {
|
||||
foreach ($users as $user) {
|
||||
if (delete_records('user', 'id', $user->id)) {
|
||||
mtrace("Deleted not fully setup user $user->username ($user->id)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Delete duplicate enrolments (don't know what causes these yet - expired sessions?)
|
||||
|
||||
if ($users = get_records_select("user_students", "userid > 0 GROUP BY course, userid ".
|
||||
"HAVING count(*) > 1", "", "*,count(*)")) {
|
||||
foreach ($users as $user) {
|
||||
delete_records_select("user_students", "userid = '$user->userid' ".
|
||||
"AND course = '$user->course' AND id <> '$user->id'");
|
||||
}
|
||||
}
|
||||
flush();
|
||||
|
||||
|
||||
|
||||
|
||||
/// Delete old logs to save space (this might need a timer to slow it down...)
|
||||
|
||||
@@ -186,62 +110,24 @@
|
||||
$loglifetime = $timenow - ($CFG->loglifetime * 3600 * 24);
|
||||
delete_records_select("log", "time < '$loglifetime'");
|
||||
}
|
||||
flush();
|
||||
|
||||
/// Delete old cached texts
|
||||
|
||||
if (!empty($CFG->cachetext)) { // Defined in config.php
|
||||
$cachelifetime = time() - $CFG->cachetext - 60; // Add an extra minute to allow for really heavy sites
|
||||
delete_records_select('cache_text', "timemodified < '$cachelifetime'");
|
||||
$cachelifetime = time() - $CFG->cachetext;
|
||||
delete_records_select("cache_text", "timemodified < '$cachelifetime'");
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
if (!empty($CFG->notifyloginfailures)) {
|
||||
notify_login_failures();
|
||||
}
|
||||
flush();
|
||||
if (file_exists("$CFG->dataroot/cronextra.php")) {
|
||||
include("$CFG->dataroot/cronextra.php");
|
||||
}
|
||||
|
||||
sync_metacourses();
|
||||
|
||||
//
|
||||
// generate new password emails for users
|
||||
//
|
||||
mtrace('checking for create_password');
|
||||
if (count_records('user_preferences', 'name', 'create_password', 'value', '1')) {
|
||||
mtrace('creating passwords for new users');
|
||||
$newusers = get_records_sql("SELECT u.id as id, u.email, u.firstname,
|
||||
u.lastname, u.username,
|
||||
p.id as prefid
|
||||
FROM {$CFG->prefix}user u
|
||||
JOIN {$CFG->prefix}user_preferences p ON u.id=p.userid
|
||||
WHERE p.name='create_password' AND p.value=1 AND u.email !='' ");
|
||||
|
||||
foreach ($newusers as $newuserid => $newuser) {
|
||||
$newuser->emailstop = 0; // send email regardless
|
||||
// email user
|
||||
if (setnew_password_and_mail($newuser)) {
|
||||
// remove user pref
|
||||
delete_records('user_preferences', 'id', $newuser->prefid);
|
||||
} else {
|
||||
trigger_error("Could not create and mail new user password!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // End of occasional clean-up tasks
|
||||
|
||||
|
||||
if (empty($CFG->disablescheduledbackups)) { // Defined in config.php
|
||||
if (!isset($CFG->disablescheduledbackups)) { // Defined in config.php
|
||||
//Execute backup's cron
|
||||
//Perhaps a long time and memory could help in large sites
|
||||
@set_time_limit(0);
|
||||
@raise_memory_limit("128M");
|
||||
if (function_exists('apache_child_terminate')) {
|
||||
// if we are running from Apache, give httpd a hint that
|
||||
// it can recycle the process after it's done. Apache's
|
||||
// memory management is truly awful but we can help it.
|
||||
@apache_child_terminate();
|
||||
}
|
||||
ini_set("memory_limit","56M");
|
||||
if (file_exists("$CFG->dirroot/backup/backup_scheduled.php") and
|
||||
file_exists("$CFG->dirroot/backup/backuplib.php") and
|
||||
file_exists("$CFG->dirroot/backup/lib.php") and
|
||||
@@ -250,84 +136,27 @@
|
||||
include_once("$CFG->dirroot/backup/backuplib.php");
|
||||
include_once("$CFG->dirroot/backup/lib.php");
|
||||
require_once ("$CFG->libdir/blocklib.php");
|
||||
mtrace("Running backups if required...");
|
||||
echo "Running backups if required...\n";
|
||||
flush();
|
||||
|
||||
if (! schedule_backup_cron()) {
|
||||
mtrace("ERROR: Something went wrong while performing backup tasks!!!");
|
||||
echo "Something went wrong while performing backup tasks!!!\n";
|
||||
} else {
|
||||
mtrace("Backup tasks finished.");
|
||||
echo "Backup tasks finished\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($CFG->enablerssfeeds)) { //Defined in admin/variables page
|
||||
include_once("$CFG->libdir/rsslib.php");
|
||||
mtrace("Running rssfeeds if required...");
|
||||
if (file_exists("$CFG->dirroot/rss/rsslib.php")) {
|
||||
include_once("$CFG->dirroot/rss/rsslib.php");
|
||||
echo "Running rssfeeds if required...\n";
|
||||
flush();
|
||||
|
||||
if ( ! cron_rss_feeds()) {
|
||||
mtrace("Something went wrong while generating rssfeeds!!!");
|
||||
} else {
|
||||
mtrace("Rssfeeds finished");
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the enrolment cron, if any
|
||||
if (!($plugins = explode(',', $CFG->enrol_plugins_enabled))) {
|
||||
$plugins = array($CFG->enrol);
|
||||
}
|
||||
require_once($CFG->dirroot .'/enrol/enrol.class.php');
|
||||
foreach ($plugins as $p) {
|
||||
$enrol = enrolment_factory::factory($p);
|
||||
if (method_exists($enrol, 'cron')) {
|
||||
$enrol->cron();
|
||||
}
|
||||
if (!empty($enrol->log)) {
|
||||
mtrace($enrol->log);
|
||||
}
|
||||
unset($enrol);
|
||||
}
|
||||
|
||||
if (!empty($CFG->enablestats) and empty($CFG->disablestatsprocessing)) {
|
||||
|
||||
// check we're not before our runtime
|
||||
$timetocheck = strtotime("$CFG->statsruntimestarthour:$CFG->statsruntimestartminute today");
|
||||
|
||||
if (time() > $timetocheck) {
|
||||
$time = 60*60*20; // set it to 20 here for first run... (overridden by $CFG)
|
||||
$clobber = true;
|
||||
if (!empty($CFG->statsmaxruntime)) {
|
||||
$time = $CFG->statsmaxruntime+(60*30); // add on half an hour just to make sure (it could take that long to break out of the loop)
|
||||
}
|
||||
if (!get_field_sql('SELECT id FROM '.$CFG->prefix.'stats_daily')) {
|
||||
// first run, set another lock. we'll check for this in subsequent runs to set the timeout to later for the normal lock.
|
||||
set_cron_lock('statsfirstrunlock',true,$time,true);
|
||||
$firsttime = true;
|
||||
}
|
||||
$time = 60*60*2; // this time set to 2.. (overridden by $CFG)
|
||||
if (!empty($CFG->statsmaxruntime)) {
|
||||
$time = $CFG->statsmaxruntime+(60*30); // add on half an hour to make sure (it could take that long to break out of the loop)
|
||||
}
|
||||
if ($config = get_record('config','name','statsfirstrunlock')) {
|
||||
if (!empty($config->value)) {
|
||||
$clobber = false; // if we're on the first run, just don't clobber it.
|
||||
}
|
||||
}
|
||||
if (set_cron_lock('statsrunning',true,$time, $clobber)) {
|
||||
require_once($CFG->dirroot.'/lib/statslib.php');
|
||||
$return = stats_cron_daily();
|
||||
if (stats_check_runtime() && $return == STATS_RUN_COMPLETE) {
|
||||
stats_cron_weekly();
|
||||
}
|
||||
if (stats_check_runtime() && $return == STATS_RUN_COMPLETE) {
|
||||
$return = $return && stats_cron_monthly();
|
||||
}
|
||||
if (stats_check_runtime() && $return == STATS_RUN_COMPLETE) {
|
||||
stats_clean_old();
|
||||
}
|
||||
set_cron_lock('statsrunning',false);
|
||||
if (!empty($firsttime)) {
|
||||
set_cron_lock('statsfirstrunlock',false);
|
||||
}
|
||||
if ( ! cron_rss_feeds()) {
|
||||
echo "Something went wrong while generating rssfeeds!!!\n";
|
||||
} else {
|
||||
echo "Rssfeeds finished\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,14 +165,9 @@
|
||||
@session_unset();
|
||||
@session_destroy();
|
||||
|
||||
mtrace("Cron script completed correctly");
|
||||
echo "Cron script completed correctly\n";
|
||||
|
||||
$difftime = microtime_diff($starttime, microtime());
|
||||
mtrace("Execution took ".$difftime." seconds");
|
||||
|
||||
/// finishe the IE hack
|
||||
if (check_browser_version('MSIE')) {
|
||||
echo "</xmp>";
|
||||
}
|
||||
echo "Execution took ".$difftime." seconds\n";
|
||||
|
||||
?>
|
||||
|
||||
+7
-12
@@ -1,30 +1,25 @@
|
||||
<?PHP // $Id$
|
||||
// dbperformance.php - shows latest ADOdb stats for the current server
|
||||
|
||||
require_once('../config.php');
|
||||
|
||||
// disable moodle specific debug messages that would be breaking the frames
|
||||
disable_debugging();
|
||||
|
||||
$topframe = optional_param('topframe', 0, PARAM_BOOL);
|
||||
$bottomframe = optional_param('bottomframe', 0, PARAM_BOOL);
|
||||
$do = optional_param('do', '', PARAM_ALPHA);
|
||||
require_once("../config.php");
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
if (!isadmin()) {
|
||||
error("Only the admin can use this page");
|
||||
}
|
||||
|
||||
$strdatabaseperformance = get_string("databaseperformance");
|
||||
$stradministration = get_string("administration");
|
||||
$site = get_site();
|
||||
|
||||
if (!empty($topframe)) {
|
||||
print_header("$site->shortname: $strdatabaseperformance", "$site->fullname",
|
||||
if (isset($topframe)) {
|
||||
print_header("$site->shortname: $strdatabaseperformance", "$site->fullname",
|
||||
"<a target=\"$CFG->framename\" href=\"index.php\">$stradministration</a> -> Database performance");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!empty($bottomframe) or !empty($do)) {
|
||||
if (isset($bottomframe) or isset($_GET['do'])) {
|
||||
$perf =&NewPerfMonitor($db);
|
||||
$perf->UI($pollsecs=5);
|
||||
exit;
|
||||
|
||||
+20
-38
@@ -3,50 +3,32 @@
|
||||
// Deletes the moodledata directory, COMPLETELY!!
|
||||
// BE VERY CAREFUL USING THIS!
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('purgemoodledata', $adminroot);
|
||||
require_once("../config.php");
|
||||
|
||||
require_login();
|
||||
|
||||
$sure = optional_param('sure', 0, PARAM_BOOL);
|
||||
$reallysure = optional_param('reallysure', 0, PARAM_BOOL);
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
if (!isadmin()) {
|
||||
error("You must be admin to use this script!");
|
||||
}
|
||||
|
||||
$deletedir = $CFG->dataroot; // The directory to delete!
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_heading('Purge moodledata');
|
||||
|
||||
if (empty($sure)) {
|
||||
$optionsyes = array('sure'=>'yes', 'sesskey'=>sesskey());
|
||||
notice_yesno ('Are you completely sure you want to delete everything inside the directory '. $deletedir .' ?',
|
||||
'delete.php', 'index.php', $optionsyes, NULL, 'post', 'get');
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
if (!$sure) {
|
||||
notice_yesno ("Are you completely sure you want to delete everything inside the directory $deletedir ?", "delete.php?sure=yes", "index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!data_submitted() or empty($reallysure)) {
|
||||
$optionsyes = array('sure'=>'yes', 'sesskey'=>sesskey(), 'reallysure'=>'yes');
|
||||
notice_yesno ('Are you REALLY REALLY completely sure you want to delete everything inside the directory '. $deletedir .' (this includes all user images, and any other course files that have been created) ?',
|
||||
'delete.php', 'index.php', $optionsyes, NULL, 'post', 'get');
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
if (!$reallysure) {
|
||||
notice_yesno ("Are you REALLY REALLY completely sure you want to delete everything inside the directory $deletedir (this includes all user images, and any other course files that have been created) ?", "delete.php?sure=yes&reallysure=yes", "index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!confirm_sesskey()) {
|
||||
error('This script was called wrongly');
|
||||
}
|
||||
|
||||
/// OK, here goes ...
|
||||
|
||||
delete_subdirectories($deletedir);
|
||||
|
||||
echo '<h1 align="center">Done!</h1>';
|
||||
echo "<H1 align=center>Done!</H1>";
|
||||
print_continue($CFG->wwwroot);
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
exit;
|
||||
|
||||
|
||||
@@ -55,27 +37,27 @@ function delete_subdirectories($rootdir) {
|
||||
$dir = opendir($rootdir);
|
||||
|
||||
while ($file = readdir($dir)) {
|
||||
if ($file != '.' and $file != '..') {
|
||||
$fullfile = $rootdir .'/'. $file;
|
||||
if (filetype($fullfile) == 'dir') {
|
||||
if ($file != "." and $file != "..") {
|
||||
$fullfile = "$rootdir/$file";
|
||||
if (filetype($fullfile) == "dir") {
|
||||
delete_subdirectories($fullfile);
|
||||
echo 'Deleting '. $fullfile .' ... ';
|
||||
echo "Deleting $fullfile ... ";
|
||||
if (rmdir($fullfile)) {
|
||||
echo 'Done.<br />';
|
||||
echo "Done.<BR>";
|
||||
} else {
|
||||
echo 'FAILED.<br />';
|
||||
echo "FAILED.<BR>";
|
||||
}
|
||||
} else {
|
||||
echo 'Deleting '. $fullfile .' ... ';
|
||||
if (unlink($fullfile)) {
|
||||
echo 'Done.<br />';
|
||||
echo "Deleting $fullfile ... ";
|
||||
if (unlink("$fullfile")) {
|
||||
echo "Done.<BR>";
|
||||
} else {
|
||||
echo 'FAILED.<br />';
|
||||
echo "FAILED.<BR>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
-104
@@ -1,104 +0,0 @@
|
||||
<?PHP // $Id$
|
||||
// enrol.php - allows admin to edit all enrollment variables
|
||||
// Yes, enrol is correct English spelling.
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$enrol = optional_param('enrol', $CFG->enrol, PARAM_SAFEDIR);
|
||||
$CFG->pagepath = 'enrol';
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('enrolment', $adminroot);
|
||||
|
||||
|
||||
|
||||
require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
|
||||
|
||||
/// Save settings
|
||||
|
||||
if ($frm = data_submitted()) {
|
||||
if (!confirm_sesskey()) {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
if (empty($frm->enable)) {
|
||||
$frm->enable = array();
|
||||
}
|
||||
if (empty($frm->default)) {
|
||||
$frm->default = '';
|
||||
}
|
||||
if ($frm->default && $frm->default != 'manual' && !in_array($frm->default, $frm->enable)) {
|
||||
$frm->enable[] = $frm->default;
|
||||
}
|
||||
asort($frm->enable);
|
||||
$frm->enable = array_merge(array('manual'), $frm->enable); // make sure manual plugin is called first
|
||||
set_config('enrol_plugins_enabled', implode(',', $frm->enable));
|
||||
set_config('enrol', $frm->default);
|
||||
redirect("enrol.php", get_string("changessaved"), 1);
|
||||
}
|
||||
|
||||
/// Print the form
|
||||
|
||||
$str = get_strings(array('enrolmentplugins', 'users', 'administration', 'settings', 'edit'));
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
$modules = get_list_of_plugins("enrol");
|
||||
$options = array();
|
||||
foreach ($modules as $module) {
|
||||
$options[$module] = get_string("enrolname", "enrol_$module");
|
||||
}
|
||||
asort($options);
|
||||
|
||||
print_simple_box(get_string('configenrolmentplugins', 'admin'), 'center', '700');
|
||||
|
||||
echo "<form target=\"{$CFG->framename}\" name=\"enrolmenu\" method=\"post\" action=\"enrol.php\">";
|
||||
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\">";
|
||||
|
||||
$table = new stdClass();
|
||||
$table->head = array(get_string('name'), get_string('enable'), get_string('default'), $str->settings);
|
||||
$table->align = array('left', 'center', 'center', 'center');
|
||||
$table->size = array('60%', '', '', '15%');
|
||||
$table->width = '700';
|
||||
$table->data = array();
|
||||
|
||||
$modules = get_list_of_plugins("enrol");
|
||||
foreach ($modules as $module) {
|
||||
|
||||
// skip if directory is empty
|
||||
if (!file_exists("$CFG->dirroot/enrol/$module/enrol.php")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = get_string("enrolname", "enrol_$module");
|
||||
$plugin = enrolment_factory::factory($module);
|
||||
$enable = '<input type="checkbox" name="enable[]" value="'.$module.'"';
|
||||
if (stristr($CFG->enrol_plugins_enabled, $module) !== false) {
|
||||
$enable .= ' checked="checked"';
|
||||
}
|
||||
if ($module == 'manual') {
|
||||
$enable .= ' disabled="disabled"';
|
||||
}
|
||||
$enable .= ' />';
|
||||
if (method_exists($plugin, 'print_entry')) {
|
||||
$default = '<input type="radio" name="default" value="'.$module.'"';
|
||||
if ($CFG->enrol == $module) {
|
||||
$default .= ' checked="checked"';
|
||||
}
|
||||
$default .= ' />';
|
||||
} else {
|
||||
$default = '';
|
||||
}
|
||||
$table->data[$name] = array($name, $enable, $default,
|
||||
'<a href="enrol_config.php?enrol='.$module.'">'.$str->edit.'</a>');
|
||||
}
|
||||
asort($table->data);
|
||||
|
||||
print_table($table);
|
||||
|
||||
echo "<center><input type=\"submit\" value=\"".get_string("savechanges")."\"></center>\n";
|
||||
echo "</form>";
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
?>
|
||||
@@ -1,79 +0,0 @@
|
||||
<?PHP // $Id$
|
||||
// enrol_config.php - allows admin to edit all enrollment variables
|
||||
// Yes, enrol is correct English spelling.
|
||||
|
||||
require_once("../config.php");
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('enrolment', $adminroot);
|
||||
|
||||
$enrol = required_param('enrol', PARAM_ALPHA);
|
||||
$CFG->pagepath = 'enrol/' . $enrol;
|
||||
|
||||
|
||||
require_once("$CFG->dirroot/enrol/enrol.class.php"); /// Open the factory class
|
||||
|
||||
$enrolment = enrolment_factory::factory($enrol);
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($frm = data_submitted()) {
|
||||
if (!confirm_sesskey()) {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
if ($enrolment->process_config($frm)) {
|
||||
redirect("enrol.php?sesskey=$USER->sesskey", get_string("changessaved"), 1);
|
||||
}
|
||||
} else {
|
||||
$frm = $CFG;
|
||||
}
|
||||
|
||||
/// Otherwise fill and print the form.
|
||||
|
||||
/// get language strings
|
||||
$str = get_strings(array('enrolmentplugins', 'configuration', 'users', 'administration'));
|
||||
|
||||
unset($options);
|
||||
|
||||
$modules = get_list_of_plugins("enrol");
|
||||
foreach ($modules as $module) {
|
||||
$options[$module] = get_string("enrolname", "enrol_$module");
|
||||
}
|
||||
asort($options);
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
echo "<form target=\"{$CFG->framename}\" name=\"enrolmenu\" method=\"post\" action=\"enrol_config.php\">";
|
||||
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".$USER->sesskey."\">";
|
||||
echo "<div align=\"center\"><p><b>";
|
||||
|
||||
|
||||
/// Choose an enrolment method
|
||||
echo get_string('chooseenrolmethod').': ';
|
||||
choose_from_menu ($options, "enrol", $enrol, "",
|
||||
"document.location='enrol_config.php?enrol='+document.enrolmenu.enrol.options[document.enrolmenu.enrol.selectedIndex].value", "");
|
||||
|
||||
echo "</b></p></div>";
|
||||
|
||||
/// Print current enrolment type description
|
||||
print_simple_box_start("center", "80%");
|
||||
print_heading($options[$enrol]);
|
||||
|
||||
print_simple_box_start("center", "60%", '', 5, 'informationbox');
|
||||
print_string("description", "enrol_$enrol");
|
||||
print_simple_box_end();
|
||||
|
||||
echo "<hr />";
|
||||
|
||||
$enrolment->config_form($frm);
|
||||
|
||||
echo "<center><p><input type=\"submit\" value=\"".get_string("savechanges")."\"></p></center>\n";
|
||||
echo "</form>";
|
||||
|
||||
print_simple_box_end();
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
exit;
|
||||
?>
|
||||
@@ -1,137 +0,0 @@
|
||||
<?php //$Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This file is the admin frontend to execute all the checks available
|
||||
// in the environment.xml file. It includes database, php and
|
||||
// php_extensions. Also, it's possible to update the xml file
|
||||
// from moodle.org be able to check more and more versions.
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
require_once($CFG->libdir.'/componentlib.class.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('environment', $adminroot);
|
||||
|
||||
/// Parameters
|
||||
$action = optional_param('action', '', PARAM_ACTION);
|
||||
$version = optional_param('version', '', PARAM_FILE); //
|
||||
|
||||
|
||||
/// Get some strings
|
||||
$stradmin = get_string('administration');
|
||||
$stradminhelpenvironment = get_string("adminhelpenvironment");
|
||||
$strenvironment = get_string('environment', 'admin');
|
||||
$strerror = get_string('error');
|
||||
$strmoodleversion = get_string('moodleversion');
|
||||
$strupdate = get_string('updatecomponent', 'admin');
|
||||
$strupwards = get_string('upwards', 'admin');
|
||||
$strmisc = get_string('miscellaneous');
|
||||
|
||||
/// Print the header stuff
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
/// Print the component download link
|
||||
echo '<div class="reportlink"><a href="environment.php?action=updatecomponent&sesskey='.$USER->sesskey.'">'.$strupdate.'</a></div>';
|
||||
|
||||
print_heading($strenvironment);
|
||||
|
||||
/// Handle the 'updatecomponent' action
|
||||
if ($action == 'updatecomponent' && confirm_sesskey()) {
|
||||
/// Create component installer and execute it
|
||||
if ($cd = new component_installer('http://download.moodle.org',
|
||||
'environment',
|
||||
'environment.zip')) {
|
||||
$status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
|
||||
switch ($status) {
|
||||
case ERROR:
|
||||
if ($cd->get_error() == 'remotedownloadnotallowed') {
|
||||
$a = new stdClass();
|
||||
$a->url = 'http://download.moodle.org/environment/environment.zip';
|
||||
$a->dest= $CFG->dataroot.'/';
|
||||
print_simple_box(get_string($cd->get_error(), 'error', $a), 'center', '', '', 5, 'errorbox');
|
||||
} else {
|
||||
print_simple_box(get_string($cd->get_error(), 'error'), 'center', '', '', 5, 'errorbox');
|
||||
}
|
||||
break;
|
||||
case UPTODATE:
|
||||
print_simple_box(get_string($cd->get_error(), 'error'), 'center');
|
||||
break;
|
||||
case INSTALLED:
|
||||
print_simple_box(get_string('componentinstalled', 'admin'), 'center');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Start of main box
|
||||
print_simple_box_start('center');
|
||||
|
||||
echo "<center>".$stradminhelpenvironment."</center><br />";
|
||||
|
||||
/// Get current Moodle version
|
||||
$current_version = $CFG->release;
|
||||
|
||||
/// Calculate list of versions
|
||||
$versions = array();
|
||||
if ($contents = load_environment_xml()) {
|
||||
if ($env_versions = get_list_of_environment_versions($contents)) {
|
||||
/// Set the current version at the beginning
|
||||
$env_version = normalize_version($current_version); //We need this later (for the upwards)
|
||||
$versions[$env_version] = $current_version;
|
||||
/// If no version has been previously selected, default to $current_version
|
||||
if (empty($version)) {
|
||||
$version = $env_version;
|
||||
}
|
||||
///Iterate over each version, adding bigged than current
|
||||
foreach ($env_versions as $env_version) {
|
||||
if (version_compare(normalize_version($current_version), $env_version, '<')) {
|
||||
$versions[$env_version] = $env_version;
|
||||
}
|
||||
}
|
||||
/// Add 'upwards' to the last element
|
||||
$versions[$env_version] = $env_version.' '.$strupwards;
|
||||
} else {
|
||||
$versions = array('error' => $strerror);
|
||||
}
|
||||
}
|
||||
|
||||
/// Print form and popup menu
|
||||
echo '<center><form method="post" action="environment.php">';
|
||||
echo $strmoodleversion.' ';
|
||||
choose_from_menu ($versions, 'version', $version, null, 'this.form.submit();' );
|
||||
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
||||
echo '</form></center>';
|
||||
/// End of main box
|
||||
print_simple_box_end();
|
||||
|
||||
/// Gather and show results
|
||||
$status = check_moodle_environment($version, $environment_results);
|
||||
|
||||
/// Print footer
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
?>
|
||||
@@ -1,107 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<COMPATIBILITY_MATRIX>
|
||||
<MOODLE version="1.5">
|
||||
<DATABASE level="required">
|
||||
<VENDOR name="mysql" version="3.23" />
|
||||
<VENDOR name="postgres" version="7.4" />
|
||||
</DATABASE>
|
||||
<PHP version="4.1.0" level="required" />
|
||||
<PHP_EXTENSIONS>
|
||||
<PHP_EXTENSION name="mbstring" level="optional" />
|
||||
</PHP_EXTENSIONS>
|
||||
</MOODLE>
|
||||
<MOODLE version="1.6">
|
||||
<DATABASE level="required">
|
||||
<VENDOR name="mysql" version="4.1.16">
|
||||
<FEEDBACK>
|
||||
<ON_ERROR message="mysql416required" />
|
||||
</FEEDBACK>
|
||||
<BYPASS function="bypass_mysql416_reqs" message="mysql416bypassed" />
|
||||
</VENDOR>
|
||||
<VENDOR name="postgres" version="7.4" />
|
||||
</DATABASE>
|
||||
<PHP version="4.3.0" level="required" />
|
||||
<PHP_EXTENSIONS>
|
||||
<PHP_EXTENSION name="iconv" level="optional">
|
||||
<FEEDBACK>
|
||||
<ON_CHECK message="iconvrecommended" />
|
||||
</FEEDBACK>
|
||||
</PHP_EXTENSION>
|
||||
<PHP_EXTENSION name="mbstring" level="optional">
|
||||
<FEEDBACK>
|
||||
<ON_CHECK message="mbstringrecommended" />
|
||||
</FEEDBACK>
|
||||
</PHP_EXTENSION>
|
||||
</PHP_EXTENSIONS>
|
||||
</MOODLE>
|
||||
<MOODLE version="1.7">
|
||||
<UNICODE level="optional">
|
||||
<FEEDBACK>
|
||||
<ON_CHECK message="unicoderecommended" />
|
||||
</FEEDBACK>
|
||||
</UNICODE>
|
||||
<DATABASE level="required">
|
||||
<VENDOR name="mysql" version="4.1.16">
|
||||
<FEEDBACK>
|
||||
<ON_ERROR message="mysql416required" />
|
||||
</FEEDBACK>
|
||||
<BYPASS function="bypass_mysql416_reqs" message="mysql416bypassed" />
|
||||
</VENDOR>
|
||||
<VENDOR name="postgres" version="7.4" />
|
||||
<VENDOR name="mssql" version="9.0" />
|
||||
<VENDOR name="odbc_mssql" version="9.0" />
|
||||
<VENDOR name="mssql_n" version="9.0" />
|
||||
<VENDOR name="oracle" version="9.0" />
|
||||
</DATABASE>
|
||||
<PHP version="4.3.0" level="required">
|
||||
<RESTRICT function="restrict_php50_version" message="php50restricted" />
|
||||
</PHP>
|
||||
<PHP_EXTENSIONS>
|
||||
<PHP_EXTENSION name="iconv" level="optional">
|
||||
<FEEDBACK>
|
||||
<ON_CHECK message="iconvrecommended" />
|
||||
</FEEDBACK>
|
||||
</PHP_EXTENSION>
|
||||
<PHP_EXTENSION name="mbstring" level="optional">
|
||||
<FEEDBACK>
|
||||
<ON_CHECK message="mbstringrecommended" />
|
||||
</FEEDBACK>
|
||||
</PHP_EXTENSION>
|
||||
</PHP_EXTENSIONS>
|
||||
</MOODLE>
|
||||
<MOODLE version="1.8">
|
||||
<UNICODE level="required">
|
||||
<FEEDBACK>
|
||||
<ON_ERROR message="unicoderequired" />
|
||||
</FEEDBACK>
|
||||
</UNICODE>
|
||||
<DATABASE level="required">
|
||||
<VENDOR name="mysql" version="4.1.16">
|
||||
<FEEDBACK>
|
||||
<ON_ERROR message="mysql416required" />
|
||||
</FEEDBACK>
|
||||
<BYPASS function="bypass_mysql416_reqs" message="mysql416bypassed" />
|
||||
</VENDOR>
|
||||
<VENDOR name="postgres" version="7.4" />
|
||||
<VENDOR name="mssql" version="9.0" />
|
||||
<VENDOR name="odbc_mssql" version="9.0" />
|
||||
<VENDOR name="mssql_n" version="9.0" />
|
||||
<VENDOR name="oracle" version="9.0" />
|
||||
</DATABASE>
|
||||
<PHP version="4.3.0" level="required">
|
||||
<RESTRICT function="restrict_php50_version" message="php50restricted" />
|
||||
</PHP>
|
||||
<PHP_EXTENSIONS>
|
||||
<PHP_EXTENSION name="iconv" level="optional">
|
||||
<FEEDBACK>
|
||||
<ON_CHECK message="iconvrecommended" />
|
||||
</FEEDBACK>
|
||||
</PHP_EXTENSION>
|
||||
<PHP_EXTENSION name="mbstring" level="optional">
|
||||
<FEEDBACK>
|
||||
<ON_CHECK message="mbstringrecommended" />
|
||||
</FEEDBACK>
|
||||
</PHP_EXTENSION>
|
||||
</PHP_EXTENSIONS>
|
||||
</MOODLE>
|
||||
</COMPATIBILITY_MATRIX>
|
||||
@@ -1,100 +0,0 @@
|
||||
<?php // $Id$
|
||||
// filter.php
|
||||
// Edit text filter settings
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('managefilters', $adminroot);
|
||||
|
||||
// get parameters
|
||||
$param = new Object;
|
||||
|
||||
$param->filter = required_param('filter', PARAM_PATH);
|
||||
$param->submit = optional_param('submit', 0, PARAM_BOOL);
|
||||
$param->reset = optional_param('reset', 0, PARAM_BOOL);
|
||||
|
||||
$filtername = substr($param->filter, strpos( $param->filter, '/' )+1 ) ;
|
||||
|
||||
// $CFG->pagepath is used to generate the body and id attributes for the body tag
|
||||
// of the page. It is also used to generate the link to the Moodle Docs for this view.
|
||||
$CFG->pagepath = 'filter/' . $filtername . '/config';
|
||||
|
||||
// get translated strings for use on page
|
||||
$txt = new Object;
|
||||
$txt->managefilters = get_string( 'managefilters' );
|
||||
$txt->administration = get_string( 'administration' );
|
||||
$txt->configuration = get_string( 'configuration' );
|
||||
|
||||
//======================
|
||||
// Process Actions
|
||||
//======================
|
||||
|
||||
// if reset pressed let filter config page handle it
|
||||
$forcereset = false;
|
||||
if (!empty($param->reset)) {
|
||||
$forcereset = true;
|
||||
}
|
||||
else
|
||||
if ($config = data_submitted()) {
|
||||
|
||||
// check session key
|
||||
if (!confirm_sesskey()) {
|
||||
error( get_string('confirmsesskeybad', 'error' ) );
|
||||
}
|
||||
|
||||
$configpath = $CFG->dirroot.'/filter/'.$filtername.'/filterconfig.php';
|
||||
if (file_exists($configpath)) {
|
||||
require_once($configpath);
|
||||
$functionname = $filtername.'_process_config';
|
||||
if (function_exists($functionname)) {
|
||||
$functionname($config);
|
||||
$saved = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($saved)) {
|
||||
// run through submitted data
|
||||
// reject if does not start with filter_
|
||||
foreach ($config as $name => $value) {
|
||||
set_config( $name,$value );
|
||||
}
|
||||
}
|
||||
redirect( "$CFG->wwwroot/$CFG->admin/filters.php", get_string('changessaved'), 1);
|
||||
exit;
|
||||
}
|
||||
|
||||
//==============================
|
||||
// Display logic
|
||||
//==============================
|
||||
|
||||
$filtername = ucfirst($filtername);
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_heading( $filtername );
|
||||
|
||||
print_simple_box("<center>".get_string("configwarning", "admin")."</center>", "center", "50%");
|
||||
echo "<br />";
|
||||
|
||||
print_simple_box_start("center",'');
|
||||
|
||||
?>
|
||||
<form action="filter.php?filter=<?php echo urlencode($param->filter); ?>" method="post">
|
||||
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
|
||||
|
||||
<?php include "$CFG->dirroot/$param->filter/filterconfig.html"; ?>
|
||||
|
||||
<center>
|
||||
<input type="submit" name="submit" value="<?php print_string('savechanges'); ?>" />
|
||||
<input type="submit" name="reset" value="<?php echo print_string('resettodefaults'); ?>" />
|
||||
</center>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
print_simple_box_end();
|
||||
|
||||
print_simple_box_end();
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
?>
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php print_simple_box_start("center", "", "$THEME->cellheading"); ?>
|
||||
|
||||
<form name="filters" id="filters" method="post" action="filters.php">
|
||||
<table align="center" border="0" cellpadding="5" cellspacing="0">
|
||||
<tr>
|
||||
<td valign="top"><div align="right">
|
||||
<br />
|
||||
<input name="up" type="submit" id="up" value="↑" />
|
||||
<br />
|
||||
<input name="down" type="submit" id="down" value="↓" />
|
||||
<br />
|
||||
</div></td>
|
||||
<td valign="top">
|
||||
<?php p($stractive) ?>
|
||||
<br />
|
||||
|
||||
<select name="iselect" size="20" id="iselect"
|
||||
onclick="document.filters.add.disabled=true;
|
||||
document.filters.remove.disabled=false;
|
||||
document.filters.uselect.selectedIndex=-1;">
|
||||
<?php
|
||||
$runscript = "";
|
||||
foreach ($installedfilters as $filter) {
|
||||
if ($selectedfilter == $filter) {
|
||||
$selected = " selected ";
|
||||
$runscript = "eval(\"document.filters.add.disabled=true\");
|
||||
eval(\"document.filters.remove.disabled=false\");
|
||||
eval(\"document.filters.uselect.selectedIndex=-1\");";
|
||||
} else {
|
||||
$selected = "";
|
||||
}
|
||||
echo "<option value=\"$filter\" $selected>".$allfilters[$filter]."</option>";
|
||||
}
|
||||
?>
|
||||
</select></td>
|
||||
<td valign="top">
|
||||
<br />
|
||||
<input name="add" type="submit" id="add" value="←" />
|
||||
<br />
|
||||
<input name="remove" type="submit" id="remove" value="→" />
|
||||
<br />
|
||||
</td>
|
||||
<td valign="top">
|
||||
<?php p($strinactive) ?>
|
||||
<br />
|
||||
<select name="uselect" size="20" id="select"
|
||||
onclick="document.filters.add.disabled=false;
|
||||
document.filters.remove.disabled=true;
|
||||
document.filters.iselect.selectedIndex=-1;">
|
||||
<?php
|
||||
foreach ($uninstalledfilters as $filter) {
|
||||
if ($selectedfilter == $filter) {
|
||||
$selected = " selected ";
|
||||
$runscript = "eval(\"document.filters.add.disabled=false\");
|
||||
eval(\"document.filters.remove.disabled=true\");
|
||||
eval(\"document.filters.iselect.selectedIndex=-1\");";
|
||||
} else {
|
||||
$selected = "";
|
||||
}
|
||||
echo "<option value=\"$filter\" $selected>".$allfilters[$filter]."</option>";
|
||||
}
|
||||
?>
|
||||
</select></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<script language="Javascript">
|
||||
<!--
|
||||
<?php echo $runscript ?>
|
||||
|
||||
-->
|
||||
</script>
|
||||
<?php print_simple_box_end(); ?>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
|
||||
<?php print_simple_box_start("center", "", "$THEME->cellheading"); ?>
|
||||
|
||||
<form name="options" id="options" method="post" action="filters.php">
|
||||
<input type="hidden" name="options" value="1">
|
||||
<table cellpadding="20">
|
||||
<tr valign=top>
|
||||
<td nowrap="nowrap" align="right"><?php p($strcachetext) ?>:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[10800] = get_string('numhours', '', 3);
|
||||
$options[7200] = get_string('numhours', '', 2);
|
||||
$options[3600] = get_string('numhours', '', 1);
|
||||
$options[2700] = get_string('numminutes', '', 45);
|
||||
$options[1800] = get_string('numminutes', '', 30);
|
||||
$options[900] = get_string('numminutes', '', 15);
|
||||
$options[600] = get_string('numminutes', '', 10);
|
||||
$options[540] = get_string('numminutes', '', 9);
|
||||
$options[480] = get_string('numminutes', '', 8);
|
||||
$options[420] = get_string('numminutes', '', 7);
|
||||
$options[360] = get_string('numminutes', '', 6);
|
||||
$options[300] = get_string('numminutes', '', 5);
|
||||
$options[240] = get_string('numminutes', '', 4);
|
||||
$options[180] = get_string('numminutes', '', 3);
|
||||
$options[120] = get_string('numminutes', '', 2);
|
||||
$options[60] = get_string('numminutes', '', 1);
|
||||
$options[30] = get_string('numseconds', '', 30);
|
||||
$options[0] = get_string('no');
|
||||
|
||||
choose_from_menu ($options, "cachetext", $CFG->cachetext, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php p($strconfigcachetext) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td nowrap="nowrap" align="right"><?php p($strfilteruploadedfiles) ?>:</td>
|
||||
<td>
|
||||
<?php
|
||||
unset($options);
|
||||
$options[0] = get_string('no');
|
||||
$options[1] = get_string('yes');
|
||||
|
||||
choose_from_menu ($options, "filteruploadedfiles", $CFG->filteruploadedfiles, "", "", "");
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php p($strconfigfilteruploadedfiles) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td> </td>
|
||||
<td><input type="submit" value="<?php print_string("savechanges") ?>"></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<?php print_simple_box_end(); ?>
|
||||
+142
-254
@@ -1,282 +1,170 @@
|
||||
<?php // $Id$
|
||||
// filters.php
|
||||
// Edit list of available text filters
|
||||
<?PHP // $Id$
|
||||
// Allows the admin to create, delete and rename course categories
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
require_once("../config.php");
|
||||
|
||||
// defines
|
||||
define('FILTER_TABLE','filter_administration_table');
|
||||
optional_variable($iselect);
|
||||
optional_variable($uselect);
|
||||
optional_variable($add);
|
||||
optional_variable($remove);
|
||||
optional_variable($up);
|
||||
optional_variable($down);
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('managefilters', $adminroot);
|
||||
require_login();
|
||||
|
||||
// get values from page
|
||||
$params = new object();
|
||||
$params->action = optional_param('action', '', PARAM_ACTION);
|
||||
$params->filterpath = optional_param('filterpath', '', PARAM_PATH);
|
||||
$params->cachetext = optional_param('cachetext', 0, PARAM_INT);
|
||||
$params->filterall = optional_param('filterall', 0, PARAM_BOOL);
|
||||
$params->filteruploadedfiles = optional_param('filteruploadedfiles', 0, PARAM_INT);
|
||||
$params->filtermatchoneperpage = optional_param('filtermatchoneperpage', 0, PARAM_BOOL);
|
||||
$params->filtermatchonepertext = optional_param('filtermatchonepertext', 0, PARAM_BOOL);
|
||||
if (!isadmin()) {
|
||||
error("Only administrators can use this page!");
|
||||
}
|
||||
|
||||
// some basic information
|
||||
$url = 'filters.php';
|
||||
$myurl = "$url?sesskey=" . sesskey();
|
||||
$img = "$CFG->pixpath/t";
|
||||
if (!$site = get_site()) {
|
||||
error("Site isn't defined!");
|
||||
}
|
||||
|
||||
// get translated strings for use on page
|
||||
$txt = new object();
|
||||
$txt->managefilters = get_string('managefilters');
|
||||
$txt->administration = get_string('administration');
|
||||
$txt->configuration = get_string('configuration');
|
||||
$txt->name = get_string('name');
|
||||
$txt->hide = get_string('hide');
|
||||
$txt->show = get_string('show');
|
||||
$txt->hideshow = "$txt->hide/$txt->show";
|
||||
$txt->settings = get_string('settings');
|
||||
$txt->up = get_string('up');
|
||||
$txt->down = get_string('down');
|
||||
$txt->updown = "$txt->up/$txt->down";
|
||||
$txt->cachetext = get_string('cachetext', 'admin');
|
||||
$txt->configcachetext = get_string('configcachetext', 'admin');
|
||||
$txt->filteruploadedfiles = get_string('filteruploadedfiles','admin');
|
||||
$txt->configfilteruploadedfiles = get_string('configfilteruploadedfiles','admin');
|
||||
$txt->filterall = get_string('filterall','admin');
|
||||
$txt->filtermatchoneperpage = get_string('filtermatchoneperpage','admin');
|
||||
$txt->filtermatchonepertext = get_string('filtermatchonepertext','admin');
|
||||
$txt->configfilterall = get_string('configfilterall','admin');
|
||||
$txt->configfiltermatchoneperpage = get_string('configfiltermatchoneperpage','admin');
|
||||
$txt->configfiltermatchonepertext = get_string('configfiltermatchonepertext','admin');
|
||||
$txt->cachecontrols = get_string('cachecontrols');
|
||||
$txt->yes = get_string('yes');
|
||||
$txt->no = get_string('no');
|
||||
$txt->none = get_string('none');
|
||||
$txt->allfiles = get_string('allfiles');
|
||||
$txt->htmlfilesonly = get_string('htmlfilesonly');
|
||||
/// Print headings
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strconfiguration = get_string("configuration");
|
||||
$strmanagefilters = get_string("managefilters");
|
||||
$strversion = get_string("version");
|
||||
$strsettings = get_string("settings");
|
||||
$strup = get_string("up");
|
||||
$strdown = get_string("down");
|
||||
$stractive = get_string("active");
|
||||
$strinactive = get_string("inactive");
|
||||
$strcachetext = get_string("cachetext", "admin");
|
||||
$strconfigcachetext = get_string("configcachetext");
|
||||
$strfilteruploadedfiles = get_string("filteruploadedfiles", "admin");
|
||||
$strconfigfilteruploadedfiles = get_string("configfilteruploadedfiles");
|
||||
|
||||
print_header("$site->shortname: $strmanagefilters", "$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> -> $strmanagefilters");
|
||||
|
||||
print_heading($strmanagefilters);
|
||||
|
||||
|
||||
/// Make a list of all available filters and the best names for them we can find
|
||||
$allfilters = array();
|
||||
|
||||
$filterlocations = array("mod", "filter");
|
||||
|
||||
// get a list of possible filters (and translate name if possible)
|
||||
// note filters can be in the dedicated filters area OR in their
|
||||
// associated modules
|
||||
$installedfilters = array();
|
||||
$filtersettings = array();
|
||||
$filterlocations = array('mod','filter');
|
||||
foreach ($filterlocations as $filterlocation) {
|
||||
$plugins = get_list_of_plugins($filterlocation);
|
||||
foreach ($plugins as $plugin) {
|
||||
$pluginpath = "$CFG->dirroot/$filterlocation/$plugin/filter.php";
|
||||
$settingspath = "$CFG->dirroot/$filterlocation/$plugin/filterconfig.html";
|
||||
if (is_readable($pluginpath)) {
|
||||
foreach ($plugins as $key => $plugin) {
|
||||
if (is_readable("$CFG->dirroot/$filterlocation/$plugin/filter.php")) {
|
||||
$name = trim(get_string("filtername", $plugin));
|
||||
if (empty($name) or ($name == '[[filtername]]')) {
|
||||
$name = ucfirst($plugin);
|
||||
}
|
||||
$installedfilters["$filterlocation/$plugin"] = $name;
|
||||
if (is_readable($settingspath)) {
|
||||
$filtersettings[] = "$filterlocation/$plugin";
|
||||
if (empty($name) or $name == "[[filtername]]") {
|
||||
$name = $plugin;
|
||||
}
|
||||
$allfilters["$filterlocation/$plugin"] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get all the currently selected filters
|
||||
|
||||
/// Make an array of all the currently installed filters
|
||||
|
||||
$installedfilters = array();
|
||||
if (!empty($CFG->textfilters)) {
|
||||
$oldactivefilters = explode(',', $CFG->textfilters);
|
||||
$oldactivefilters = array_unique($oldactivefilters);
|
||||
} else {
|
||||
$oldactivefilters = array();
|
||||
}
|
||||
$installedfilters = explode(',',$CFG->textfilters);
|
||||
|
||||
// take this opportunity to clean up filters
|
||||
$activefilters = array();
|
||||
foreach ($oldactivefilters as $oldactivefilter) {
|
||||
if (!empty($oldactivefilter) and array_key_exists($oldactivefilter, $installedfilters)) {
|
||||
$activefilters[] = $oldactivefilter;
|
||||
}
|
||||
}
|
||||
|
||||
//======================
|
||||
// Process Actions
|
||||
//======================
|
||||
|
||||
if ($params->action=="") {
|
||||
// store cleaned active filers in db
|
||||
set_config('textfilters', implode(',', $activefilters));
|
||||
} elseif (($params->action=="hide") and confirm_sesskey()) {
|
||||
$key=array_search($params->filterpath, $activefilters);
|
||||
// check filterpath is valid
|
||||
if ($key===false) {
|
||||
// ignore it - doubleclick??
|
||||
} else {
|
||||
// just delete it
|
||||
unset($activefilters[$key]);
|
||||
set_config('textfilters', implode(',', $activefilters));
|
||||
}
|
||||
} elseif (($params->action=="show") and confirm_sesskey()) {
|
||||
// check filterpath is valid
|
||||
if (!array_key_exists($params->filterpath, $installedfilters)) {
|
||||
error("Filter $params->filterpath is not currently installed", $url);
|
||||
} elseif (array_search($params->filterpath,$activefilters)) {
|
||||
// filterpath is already active - doubleclick??
|
||||
} else {
|
||||
// add it to installed filters
|
||||
$activefilters[] = $params->filterpath;
|
||||
$activefilters = array_unique($activefilters);
|
||||
set_config('textfilters', implode(',', $activefilters));
|
||||
}
|
||||
} elseif (($params->action=="down") and confirm_sesskey()) {
|
||||
$key=array_search($params->filterpath, $activefilters);
|
||||
// check filterpath is valid
|
||||
if ($key===false) {
|
||||
error("Filter $params->filterpath is not currently active", $url);
|
||||
} elseif ($key>=(count($activefilters)-1)) {
|
||||
// cannot be moved any further down - doubleclick??
|
||||
} else {
|
||||
// swap with $key+1
|
||||
$fsave = $activefilters[$key];
|
||||
$activefilters[$key] = $activefilters[$key+1];
|
||||
$activefilters[$key+1] = $fsave;
|
||||
set_config('textfilters', implode(',', $activefilters));
|
||||
}
|
||||
} elseif (($params->action=="up") and confirm_sesskey()) {
|
||||
$key=array_search($params->filterpath, $activefilters);
|
||||
// check filterpath is valid
|
||||
if ($key===false) {
|
||||
error("Filter $params->filterpath is not currently active", $url);
|
||||
} elseif ($key<1) {
|
||||
//cannot be moved any further up - doubleclick??
|
||||
} else {
|
||||
// swap with $key-1
|
||||
$fsave = $activefilters[$key];
|
||||
$activefilters[$key] = $activefilters[$key-1];
|
||||
$activefilters[$key-1] = $fsave;
|
||||
set_config('textfilters', implode(',', $activefilters));
|
||||
}
|
||||
} elseif (($params->action=="config") and confirm_sesskey()) {
|
||||
set_config('cachetext', $params->cachetext);
|
||||
set_config('filteruploadedfiles', $params->filteruploadedfiles);
|
||||
set_config('filterall', $params->filterall);
|
||||
set_config('filtermatchoneperpage', $params->filtermatchoneperpage);
|
||||
set_config('filtermatchonepertext', $params->filtermatchonepertext);
|
||||
}
|
||||
|
||||
//======================
|
||||
// Build Display Objects
|
||||
//======================
|
||||
|
||||
// construct the display array with installed filters
|
||||
// at the top in the right order
|
||||
$displayfilters = array();
|
||||
foreach ($activefilters as $activefilter) {
|
||||
$name = $installedfilters[$activefilter];
|
||||
$displayfilters[$activefilter] = $name;
|
||||
}
|
||||
foreach ($installedfilters as $key => $filter) {
|
||||
if (!array_key_exists($key, $displayfilters)) {
|
||||
$displayfilters[$key] = $filter;
|
||||
}
|
||||
}
|
||||
|
||||
// construct the flexible table ready to display
|
||||
$table = new flexible_table(FILTER_TABLE);
|
||||
$table->define_columns(array('name', 'hideshow', 'order', 'settings'));
|
||||
$table->column_style('hideshow', 'text-align', 'center');
|
||||
$table->column_style('order', 'text-align', 'center');
|
||||
$table->column_style('settings', 'text-align', 'center');
|
||||
$table->define_headers(array($txt->name, $txt->hideshow, $txt->updown, $txt->settings));
|
||||
$table->define_baseurl("$CFG->wwwroot/$CFG->admin/filters.php");
|
||||
$table->set_attribute('id', 'blocks');
|
||||
$table->set_attribute('class', 'flexible generaltable generalbox');
|
||||
$table->set_attribute('style', 'margin:auto;');
|
||||
$table->set_attribute('cellpadding', '5');
|
||||
$table->setup();
|
||||
|
||||
// iterate through filters adding to display table
|
||||
$updowncount = 1;
|
||||
$activefilterscount = count($activefilters);
|
||||
foreach ($displayfilters as $path => $name) {
|
||||
$upath = urlencode($path);
|
||||
// get hide/show link
|
||||
if (in_array($path, $activefilters)) {
|
||||
$hideshow = "<a href=\"$myurl&action=hide&filterpath=$upath\">";
|
||||
$hideshow .= "<img src=\"{$CFG->pixpath}/i/hide.gif\" height=\"16\" width=\"16\" alt=\"hide\" /></a>";
|
||||
$hidden = false;
|
||||
$displayname = "<span>$name</span>";
|
||||
}
|
||||
else {
|
||||
$hideshow = "<a href=\"$myurl&action=show&filterpath=$upath\">";
|
||||
$hideshow .= "<img src=\"{$CFG->pixpath}/i/show.gif\" height=\"16\" width=\"16\" alt=\"show\" /></a>";
|
||||
$hidden = true;
|
||||
$displayname = "<span class=\"dimmed_text\">$name</span>";
|
||||
}
|
||||
|
||||
// get up/down link (only if not hidden)
|
||||
$updown = '';
|
||||
if (!$hidden) {
|
||||
if ($updowncount>1) {
|
||||
$updown .= "<a href=\"$myurl&action=up&filterpath=$upath\">";
|
||||
$updown .= "<img src=\"$img/up.gif\" alt=\"up\" /></a> ";
|
||||
// Do a little cleanup for robustness
|
||||
foreach ($installedfilters as $key => $installedfilter) {
|
||||
if (empty($installedfilter)) {
|
||||
unset($installedfilters[$key]);
|
||||
set_config("textfilters", implode(',', $installedfilters));
|
||||
}
|
||||
else {
|
||||
$updown .= "<img src=\"$CFG->pixpath/spacer.gif\" height=\"16\" width=\"16\" alt=\"\" /> ";
|
||||
}
|
||||
if ($updowncount<$activefilterscount) {
|
||||
$updown .= "<a href=\"$myurl&action=down&filterpath=$upath\">";
|
||||
$updown .= "<img src=\"$img/down.gif\" alt=\"down\" /></a>";
|
||||
}
|
||||
else {
|
||||
$updown .= "<img src=\"$CFG->pixpath/spacer.gif\" height=\"16\" width=\"16\" alt=\"\" />";
|
||||
}
|
||||
++$updowncount;
|
||||
}
|
||||
|
||||
// settings link (if defined)
|
||||
$settings = '';
|
||||
if (in_array($path, $filtersettings)) {
|
||||
$settings = "<a href=\"filter.php?filter=" . urlencode($path) . "\">";
|
||||
$settings .= "{$txt->settings}</a>";
|
||||
}
|
||||
|
||||
// write data into the table object
|
||||
$table->add_data(array($displayname, $hideshow, $updown, $settings));
|
||||
}
|
||||
|
||||
// build options list for cache lifetime
|
||||
$seconds = array(604800,86400,43200,10800,7200,3600,2700,1800,900,600,540,480,420,360,300,240,180,120,60,30,0);
|
||||
unset($lifetimeoptions);
|
||||
foreach ($seconds as $second) {
|
||||
if ($second>=86400) {
|
||||
$options[$second] = get_string('numdays','',$second/86400);
|
||||
}
|
||||
elseif ($second>=3600) {
|
||||
$options[$second] = get_string('numhours','',$second/3600);
|
||||
}
|
||||
elseif ($second>=60) {
|
||||
$options[$second] = get_string('numminutes','',$second/60);
|
||||
}
|
||||
elseif ($second>=1) {
|
||||
$options[$second] = get_string('numseconds','',$second);
|
||||
}
|
||||
else {
|
||||
$options[$second] = get_string('no');
|
||||
}
|
||||
}
|
||||
|
||||
//==============================
|
||||
// Display logic
|
||||
//==============================
|
||||
$selectedfilter = "none";
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
print_heading_with_help($txt->managefilters, 'filters');
|
||||
if (!empty($options)) {
|
||||
if ($config = data_submitted()) {
|
||||
unset($config->options);
|
||||
foreach ($config as $name => $value) {
|
||||
set_config($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// print the table of all the filters
|
||||
$table->print_html();
|
||||
if (!empty($add) and !empty($uselect)) {
|
||||
$selectedfilter = $uselect;
|
||||
if (!in_array($selectedfilter, $installedfilters)) {
|
||||
$installedfilters[] = $selectedfilter;
|
||||
set_config("textfilters", implode(',', $installedfilters));
|
||||
}
|
||||
|
||||
// cache control table has been removed
|
||||
} else if (!empty($remove) and !empty($iselect)) {
|
||||
$selectedfilter = $iselect;
|
||||
foreach ($installedfilters as $key => $installedfilter) {
|
||||
if ($installedfilter == $selectedfilter) {
|
||||
unset($installedfilters[$key]);
|
||||
}
|
||||
}
|
||||
set_config("textfilters", implode(',', $installedfilters));
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
} else if ((!empty($up) or !empty($down)) and !empty($iselect)) {
|
||||
|
||||
if (!empty($up)) {
|
||||
if ($allfilters[$iselect]) {
|
||||
foreach ($installedfilters as $key => $installedfilter) {
|
||||
if ($installedfilter == $iselect) {
|
||||
$movefilter = $key;
|
||||
break;
|
||||
}
|
||||
$swapfilter = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($down)) {
|
||||
if ($allfilters[$iselect]) {
|
||||
$choosenext = false;
|
||||
foreach ($installedfilters as $key => $installedfilter) {
|
||||
if ($choosenext) {
|
||||
$swapfilter = $key;
|
||||
break;
|
||||
}
|
||||
if ($installedfilter == $iselect) {
|
||||
$movefilter = $key;
|
||||
$choosenext = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($swapfilter) and isset($movefilter)) {
|
||||
$tempfilter = $installedfilters[$swapfilter];
|
||||
$installedfilters[$swapfilter] = $installedfilters[$movefilter];
|
||||
$installedfilters[$movefilter] = $tempfilter;
|
||||
set_config("textfilters", implode(',', $installedfilters));
|
||||
}
|
||||
$selectedfilter = $iselect;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Make an array of all the currently uninstalled filters
|
||||
|
||||
$uninstalledfilters = array();
|
||||
foreach ($allfilters as $filter => $name) {
|
||||
$installed = false;
|
||||
foreach ($installedfilters as $installedfilter) {
|
||||
if ($installedfilter == $filter) {
|
||||
$installed = true;
|
||||
}
|
||||
}
|
||||
if (!$installed) {
|
||||
$uninstalledfilters[] = $filter;
|
||||
}
|
||||
}
|
||||
|
||||
/// Print the current form
|
||||
|
||||
include("filters.html");
|
||||
|
||||
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
<?php // $Id$
|
||||
/** This expects the output from a command like
|
||||
* clamscan -r --infected --no-summary <files> 2>&1 | php -d error_log=/path/to/log thisfile.php
|
||||
* also it's important that the output of clamscan prints the FULL PATH to each infected file, so use absolute paths for area to scan
|
||||
* also it should be run as root, or whatever the webserver runs as so that it has the right permissions in the quarantine dir etc.
|
||||
* php -d error_log=/path/to/log thisfile.php will override the default error log for php cli, which is stderr, so if you want this script to just print stuff out, use php thisfile.php instead.
|
||||
*/
|
||||
|
||||
|
||||
$fd = fopen('php://stdin','r');
|
||||
if (!$fd) {
|
||||
exit();
|
||||
}
|
||||
|
||||
$FULLME='cron';
|
||||
require_once(dirname(dirname(__FILE__)).'/config.php');
|
||||
require_once($CFG->dirroot.'/lib/uploadlib.php'); // contains virus handling stuff.
|
||||
|
||||
$site = get_site();
|
||||
|
||||
while(!feof($fd)) {
|
||||
$entry = fgets($fd);
|
||||
if (strlen(trim($entry)) == 0) {
|
||||
continue;
|
||||
}
|
||||
if (!$file = validate_line($entry)) {
|
||||
continue;
|
||||
}
|
||||
$bits = explode('/',$file);
|
||||
$a->filename = $bits[count($bits)-1];
|
||||
|
||||
if (!$log = get_record("log","module","upload","info",$file,"action","upload")) {
|
||||
$a->action = clam_handle_infected_file($file,0,false);
|
||||
clam_replace_infected_file($file);
|
||||
notify_admins_unknown($file,$a);
|
||||
continue;
|
||||
}
|
||||
$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);
|
||||
$subject = get_string('virusfoundsubject','moodle',$site->fullname);
|
||||
$a->date = userdate($log->time);
|
||||
|
||||
$a->action = $action;
|
||||
$a->course = $course->fullname;
|
||||
$a->user = fullname($user);
|
||||
|
||||
notify_user($user,$subject,$a);
|
||||
notify_admins($user,$subject,$a);
|
||||
}
|
||||
fclose($fd);
|
||||
|
||||
|
||||
function notify_user($user,$subject,$a) {
|
||||
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
$body = get_string('virusfoundlater','moodle',$a);
|
||||
email_to_user($user,get_admin(),$subject,$body);
|
||||
}
|
||||
|
||||
|
||||
function notify_admins($user,$subject,$a) {
|
||||
|
||||
$admins = get_admins();
|
||||
|
||||
$body = get_string('virusfoundlateradmin','moodle',$a);
|
||||
foreach ($admins as $admin) {
|
||||
email_to_user($admin,$admin,$subject,$body);
|
||||
}
|
||||
}
|
||||
|
||||
function notify_admins_unknown($file,$a) {
|
||||
|
||||
global $site;
|
||||
|
||||
$admins = get_admins();
|
||||
$subject = get_string('virusfoundsubject','moodle',$site->fullname);
|
||||
$body = get_string('virusfoundlateradminnolog','moodle',$a);
|
||||
foreach ($admins as $admin) {
|
||||
email_to_user($admin,$admin,$subject,$body);
|
||||
}
|
||||
}
|
||||
|
||||
function validate_line($line) {
|
||||
global $CFG;
|
||||
if (strpos($line,"FOUND") === false) {
|
||||
return false;
|
||||
}
|
||||
$index = strpos($line,":");
|
||||
$file = substr($line,0,$index);
|
||||
if (!(strpos($file,$CFG->dataroot) === false)) {
|
||||
if (!file_exists($file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($file{0} == "/") {
|
||||
$file = $CFG->dataroot.$file;
|
||||
}
|
||||
else {
|
||||
$file = $CFG->dataroot."/".$file;
|
||||
}
|
||||
if (!file_exists($file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// clean up
|
||||
$file = preg_replace('/\.\//','/',$file);
|
||||
$file = preg_replace('/\/\//','/',$file);
|
||||
return $file;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,562 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
ob_start(); //for whitespace test
|
||||
require_once('../config.php');
|
||||
|
||||
// extra whitespace test - intentionally breaks cookieless mode
|
||||
$extraws = '';
|
||||
while (true) {
|
||||
$extraws .= ob_get_contents();
|
||||
if (!@ob_end_clean()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('healthcenter', $adminroot);
|
||||
|
||||
define('SEVERITY_NOTICE', 'notice');
|
||||
define('SEVERITY_ANNOYANCE', 'annoyance');
|
||||
define('SEVERITY_SIGNIFICANT', 'significant');
|
||||
define('SEVERITY_CRITICAL', 'critical');
|
||||
|
||||
$solution = optional_param('solution', 0, PARAM_SAFEDIR); //in fact it is class name alhanumeric and _
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
|
||||
$site = get_site();
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
echo <<<STYLES
|
||||
<style type="text/css">
|
||||
div#healthnoproblemsfound {
|
||||
width: 60%;
|
||||
margin: auto;
|
||||
padding: 1em;
|
||||
border: 1px black solid;
|
||||
-moz-border-radius: 6px;
|
||||
}
|
||||
dl.healthissues {
|
||||
width: 60%;
|
||||
margin: auto;
|
||||
}
|
||||
dl.critical dt, dl.critical dd {
|
||||
background-color: #a71501;
|
||||
}
|
||||
dl.significant dt, dl.significant dd {
|
||||
background-color: #d36707;
|
||||
}
|
||||
dl.annoyance dt, dl.annoyance dd {
|
||||
background-color: #dba707;
|
||||
}
|
||||
dl.notice dt, dl.notice dd {
|
||||
background-color: #e5db36;
|
||||
}
|
||||
dt.solution, dd.solution, div#healthnoproblemsfound {
|
||||
background-color: #5BB83E !important;
|
||||
}
|
||||
dl.healthissues dt, dl.healthissues dd {
|
||||
margin: 0px;
|
||||
padding: 1em;
|
||||
border: 1px black solid;
|
||||
}
|
||||
dl.healthissues dt {
|
||||
font-weight: bold;
|
||||
border-bottom: none;
|
||||
padding-bottom: 0.5em;
|
||||
}
|
||||
dl.healthissues dd {
|
||||
border-top: none;
|
||||
padding-top: 0.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
dl.healthissues dd form {
|
||||
margin-top: 0.5em;
|
||||
text-align: right;
|
||||
}
|
||||
form#healthformreturn {
|
||||
text-align: center;
|
||||
margin: 2em;
|
||||
}
|
||||
dd.solution p {
|
||||
padding: 0px;
|
||||
margin: 1em 0px;
|
||||
}
|
||||
dd.solution li {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
</style>
|
||||
STYLES;
|
||||
|
||||
if(strpos($solution, 'problem_') === 0 && class_exists($solution)) {
|
||||
health_print_solution($solution);
|
||||
}
|
||||
else {
|
||||
health_find_problems();
|
||||
}
|
||||
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
|
||||
function health_find_problems() {
|
||||
|
||||
print_heading(get_string('healthcenter'));
|
||||
|
||||
$issues = array(
|
||||
SEVERITY_CRITICAL => array(),
|
||||
SEVERITY_SIGNIFICANT => array(),
|
||||
SEVERITY_ANNOYANCE => array(),
|
||||
SEVERITY_NOTICE => array(),
|
||||
);
|
||||
$problems = 0;
|
||||
|
||||
for($i = 1; $i < 1000000; ++$i) {
|
||||
$classname = sprintf('problem_%06d', $i);
|
||||
if(!class_exists($classname)) {
|
||||
break;
|
||||
}
|
||||
$problem = new $classname;
|
||||
if($problem->exists()) {
|
||||
$severity = $problem->severity();
|
||||
$issues[$severity][$classname] = array(
|
||||
'severity' => $severity,
|
||||
'description' => $problem->description(),
|
||||
'title' => $problem->title()
|
||||
);
|
||||
++$problems;
|
||||
}
|
||||
unset($problem);
|
||||
}
|
||||
|
||||
if($problems == 0) {
|
||||
echo '<div id="healthnoproblemsfound">';
|
||||
echo get_string('healthnoproblemsfound');
|
||||
echo '</div>';
|
||||
}
|
||||
else {
|
||||
print_heading(get_string('healthproblemsdetected'));
|
||||
$severities = array(SEVERITY_CRITICAL, SEVERITY_SIGNIFICANT, SEVERITY_ANNOYANCE, SEVERITY_NOTICE);
|
||||
foreach($severities as $severity) {
|
||||
if(!empty($issues[$severity])) {
|
||||
echo '<dl class="healthissues '.$severity.'">';
|
||||
foreach($issues[$severity] as $classname => $data) {
|
||||
echo '<dt id="'.$classname.'">'.$data['title'].'</dt>';
|
||||
echo '<dd>'.$data['description'];
|
||||
echo '<form action="health.php#solution" method="get">';
|
||||
echo '<input type="hidden" name="solution" value="'.$classname.'" /><input type="submit" value="'.get_string('viewsolution').'" />';
|
||||
echo '</form></dd>';
|
||||
}
|
||||
echo '</dl>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function health_print_solution($classname) {
|
||||
$problem = new $classname;
|
||||
$data = array(
|
||||
'title' => $problem->title(),
|
||||
'severity' => $problem->severity(),
|
||||
'description' => $problem->description(),
|
||||
'solution' => $problem->solution()
|
||||
);
|
||||
|
||||
print_heading(get_string('healthcenter'));
|
||||
print_heading(get_string('healthproblemsolution'));
|
||||
echo '<dl class="healthissues '.$data['severity'].'">';
|
||||
echo '<dt>'.$data['title'].'</dt>';
|
||||
echo '<dd>'.$data['description'].'</dd>';
|
||||
echo '<dt id="solution" class="solution">'.get_string('healthsolution').'</dt>';
|
||||
echo '<dd class="solution">'.$data['solution'].'</dd></dl>';
|
||||
echo '<form id="healthformreturn" action="health.php#'.$classname.'" method="get">';
|
||||
echo '<input type="submit" value="'.get_string('healthreturntomain').'" />';
|
||||
echo '</form>';
|
||||
}
|
||||
|
||||
class problem_base {
|
||||
function exists() {
|
||||
return false;
|
||||
}
|
||||
function title() {
|
||||
return '???';
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_NOTICE;
|
||||
}
|
||||
function description() {
|
||||
return '';
|
||||
}
|
||||
function solution() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000001 extends problem_base {
|
||||
function title() {
|
||||
return 'Invalid value for $CFG->dirroot';
|
||||
}
|
||||
function exists() {
|
||||
global $CFG;
|
||||
$dirroot = dirname(realpath('../index.php'));
|
||||
if (!empty($dirroot) && $dirroot != $CFG->dirroot) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_CRITICAL;
|
||||
}
|
||||
function description() {
|
||||
global $CFG;
|
||||
return 'Your <strong>config.php</strong> file contains the setting <strong>$CFG->dirroot = "'.$CFG->dirroot.'"</strong>, which is incorrect. Unless you correct this problem, Moodle will not function correctly, if at all.';
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
$dirroot = dirname(realpath('../index.php'));
|
||||
return 'You need to edit your <strong>config.php</strong> file. Find the line which reads <pre>$CFG->dirroot = \''.$CFG->dirroot.'\';</pre> and change it to read <pre>$CFG->dirroot = \''.$dirroot.'\'</pre>';
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000002 extends problem_base {
|
||||
function title() {
|
||||
return 'Extra characters at the end of config.php or other library function';
|
||||
}
|
||||
function exists() {
|
||||
global $extraws;
|
||||
|
||||
if($extraws === '') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_SIGNIFICANT;
|
||||
}
|
||||
function description() {
|
||||
return 'Your Moodle configuration file config.php or another library file, contains some characters after the closing PHP tag (?>). This causes Moodle to exhibit several kinds of problems (such as broken downloaded files) and must be fixed.';
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
return 'You need to edit <strong>'.$CFG->dirroot.'/config.php</strong> and remove all characters (including spaces and returns) after the ending ?> tag. These two characters should be the very last in that file. The extra trailing whitespace may be also present in other PHP files that are included from lib/setup.php.';
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000003 extends problem_base {
|
||||
function title() {
|
||||
return '$CFG->dataroot does not exist or does not have write permissions';
|
||||
}
|
||||
function exists() {
|
||||
global $CFG;
|
||||
if(!is_dir($CFG->dataroot) || !is_writable($CFG->dataroot)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_SIGNIFICANT;
|
||||
}
|
||||
function description() {
|
||||
global $CFG;
|
||||
return 'Your <strong>config.php</strong> says that your "data root" directory is <strong>'.$CFG->dataroot.'</strong>. However, this directory either does not exist or cannot be written to by Moodle. This means that a variety of problems will be present, such as users not being able to log in and not being able to upload any files. It is imperative that you address this problem for Moodle to work correctly.';
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
return 'First of all, make sure that the directory <strong>'.$CFG->dataroot.'</strong> exists. If the directory does exist, then you must make sure that Moodle is able to write to it. Contact your web server administrator and request that he gives write permissions for that directory to the user that the web server process is running as.';
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000004 extends problem_base {
|
||||
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');
|
||||
return (time() - $lastcron > 3600 * 24);
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_SIGNIFICANT;
|
||||
}
|
||||
function description() {
|
||||
return 'The cron.php mainenance script has not been run in the past 24 hours. This probably means that your server is not configured to automatically run this script in regular time intervals. If this is the case, then Moodle will mostly work as it should but some operations (notably sending email to users) will not be carried out at all.';
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
return 'For detailed instructions on how to enable cron, see <a href="'.$CFG->wwwroot.'/doc/?file=install.html#cron">this section</a> of the installation manual.';
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000005 extends problem_base {
|
||||
function title() {
|
||||
return 'PHP: session.auto_start is enabled';
|
||||
}
|
||||
function exists() {
|
||||
return ini_get_bool('session.auto_start');
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_CRITICAL;
|
||||
}
|
||||
function description() {
|
||||
return 'Your PHP configuration includes an enabled setting, session.auto_start, that <strong>must be disabled</strong> in order for Moodle to work correctly. Notable symptoms arising from this misconfiguration include fatal errors and/or blank pages when trying to log in.';
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
return '<p>There are two ways you can solve this problem:</p><ol><li>If you have access to your main <strong>php.ini</strong> file, then find the line that looks like this: <pre>session.auto_start = 1</pre> and change it to <pre>session.auto_start = 0</pre> and then restart your web server. Be warned that this, as any other PHP setting change, might affect other web applications running on the server.</li><li>Finally, you may be able to change this setting just for your site by creating or editing the file <strong>'.$CFG->dirroot.'/.htaccess</strong> to contain this line: <pre>php_value session.auto_start "0"</pre></li></ol>';
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000006 extends problem_base {
|
||||
function title() {
|
||||
return 'PHP: magic_quotes_runtime is enabled';
|
||||
}
|
||||
function exists() {
|
||||
return (ini_get_bool('magic_quotes_runtime'));
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_SIGNIFICANT;
|
||||
}
|
||||
function description() {
|
||||
return 'Your PHP configuration includes an enabled setting, magic_quotes_runtime, that <strong>must be disabled</strong> in order for Moodle to work correctly. Notable symptoms arising from this misconfiguration include strange display errors whenever a text field that includes single or double quotes is processed.';
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
return '<p>There are two ways you can solve this problem:</p><ol><li>If you have access to your main <strong>php.ini</strong> file, then find the line that looks like this: <pre>magic_quotes_runtime = On</pre> and change it to <pre>magic_quotes_runtime = Off</pre> and then restart your web server. Be warned that this, as any other PHP setting change, might affect other web applications running on the server.</li><li>Finally, you may be able to change this setting just for your site by creating or editing the file <strong>'.$CFG->dirroot.'/.htaccess</strong> to contain this line: <pre>php_value magic_quotes_runtime "Off"</pre></li></ol>';
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000007 extends problem_base {
|
||||
function title() {
|
||||
return 'PHP: file_uploads is disabled';
|
||||
}
|
||||
function exists() {
|
||||
return !ini_get_bool('file_uploads');
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_SIGNIFICANT;
|
||||
}
|
||||
function description() {
|
||||
return 'Your PHP configuration includes a disabled setting, file_uploads, that <strong>must be enabled</strong> to let Moodle offer its full functionality. Until this setting is enabled, it will not be possible to upload any files into Moodle. This includes, for example, course content and user pictures.';
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
return '<p>There are two ways you can solve this problem:</p><ol><li>If you have access to your main <strong>php.ini</strong> file, then find the line that looks like this: <pre>file_uploads = Off</pre> and change it to <pre>file_uploads = On</pre> and then restart your web server. Be warned that this, as any other PHP setting change, might affect other web applications running on the server.</li><li>Finally, you may be able to change this setting just for your site by creating or editing the file <strong>'.$CFG->dirroot.'/.htaccess</strong> to contain this line: <pre>php_value file_uploads "On"</pre></li></ol>';
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000008 extends problem_base {
|
||||
function title() {
|
||||
return 'PHP: memory_limit cannot be controlled by Moodle';
|
||||
}
|
||||
function exists() {
|
||||
$oldmemlimit = @ini_get('memory_limit');
|
||||
if(empty($oldmemlimit)) {
|
||||
// PHP not compiled with memory limits, this means that it's
|
||||
// probably limited to 8M or in case of Windows not at all.
|
||||
// We can ignore it for now - there is not much to test anyway
|
||||
// TODO: add manual test that fills memory??
|
||||
return false;
|
||||
}
|
||||
$oldmemlimit = get_real_size($oldmemlimit);
|
||||
//now lets change the memory limit to something unique below 128M==134217728
|
||||
@ini_set('memory_limit', 134217720);
|
||||
$testmemlimit = get_real_size(@ini_get('memory_limit'));
|
||||
//verify the change had any effect at all
|
||||
if ($oldmemlimit == $testmemlimit) {
|
||||
//memory limit can not be changed - is it big enough then?
|
||||
if ($oldmemlimit < get_real_size('128M')) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ini_set('memory_limit', $oldmemlimit);
|
||||
return false;
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_NOTICE;
|
||||
}
|
||||
function description() {
|
||||
return 'The settings for PHP on your server do not allow a script to request more memory during its execution. '.
|
||||
'This means that there is a hard limit of '.@ini_get('memory_limit').' for each script. '.
|
||||
'It is possible that certain operations within Moodle will require more than this amount in order '.
|
||||
'to complete successfully, especially if there are lots of data to be processed.';
|
||||
}
|
||||
function solution() {
|
||||
return 'It is recommended that you contact your web server administrator to address this issue.';
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000009 extends problem_base {
|
||||
function title() {
|
||||
return 'SQL: using account without password';
|
||||
}
|
||||
function exists() {
|
||||
global $CFG;
|
||||
return empty($CFG->dbpass);
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_CRITICAL;
|
||||
}
|
||||
function description() {
|
||||
global $CFG;
|
||||
return 'The user account your are connecting to the database server with is set up without a password. This is a very big security risk and is only somewhat lessened if your database is configured to not accept connections from any hosts other than the server Moodle is running on. Unless you use a strong password to connect to the database, you risk unauthorized access to and manipulation of your data.'.($CFG->dbuser != 'root'?'':' <strong>This is especially alarming because such access to the database would be as the superuser (root)!</strong>');
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
return 'You should change the password of the user <strong>'.$CFG->dbuser.'</strong> both in your database and in your Moodle <strong>config.php</strong> immediately!'.($CFG->dbuser != 'root'?'':' It would also be a good idea to change the user account from root to something else, because this would lessen the impact in the event that your database is compromised anyway.');
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000010 extends problem_base {
|
||||
function title() {
|
||||
return 'Uploaded files: slasharguments disabled or not working';
|
||||
}
|
||||
function exists() {
|
||||
if (!$this->is_enabled()) {
|
||||
return true;
|
||||
}
|
||||
if ($this->status() < 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function severity() {
|
||||
if ($this->is_enabled() and $this->status() == 0) {
|
||||
return SEVERITY_SIGNIFICANT;
|
||||
} else {
|
||||
return SEVERITY_ANNOYANCE;
|
||||
}
|
||||
}
|
||||
function description() {
|
||||
global $CFG;
|
||||
$desc = 'Slasharguments are needed for relative linking in uploaded resources:<ul>';
|
||||
if (!$this->is_enabled()) {
|
||||
$desc .= '<li>slasharguments are <strong>disabled</strong> in Moodle configuration</li>';
|
||||
} else {
|
||||
$desc .= '<li>slasharguments are enabled in Moodle configuration</li>';
|
||||
}
|
||||
if ($this->status() == -1) {
|
||||
$desc .= '<li>can not run automatic test, you can verify it <a href="'.$CFG->wwwroot.'/file.php/testslasharguments" target="_blank">here</a> manually</li>';
|
||||
} else if ($this->status() == 0) {
|
||||
$desc .= '<li>slashargument test <strong>failed</strong>, please check server configuration</li>';
|
||||
} else {
|
||||
$desc .= '<li>slashargument test passed</li>';
|
||||
}
|
||||
$desc .= '</ul>';
|
||||
return $desc;
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
$enabled = $this->is_enabled();
|
||||
$status = $this->status();
|
||||
$solution = '';
|
||||
if ($enabled and ($status == 0)) {
|
||||
$solution .= 'Slasharguments are enabled, but the test failed. Please disable slasharguments in Moodle configuration or fix the server configuration.<hr />';
|
||||
} else if ((!$enabled) and ($status == 0)) {
|
||||
$solution .= 'Slasharguments are disabled and the test failed. You may try to fix the server configuration.<hr />';
|
||||
} else if ($enabled and ($status == -1)) {
|
||||
$solution .= 'Slasharguments are enabled, <a href="'.$CFG->wwwroot.'/file.php/testslasharguments">automatic testing</a> not possible.<hr />';
|
||||
} else if ((!$enabled) and ($status == -1)) {
|
||||
$solution .= 'Slasharguments are disabled, <a href="'.$CFG->wwwroot.'/file.php/testslasharguments">automatic testing</a> not possible.<hr />';
|
||||
} else if ((!$enabled) and ($status > 0)) {
|
||||
$solution .= 'Slasharguments are disabled though the iternal test is OK. You should enable slasharguments in Moodle configuration.';
|
||||
} else if ($enabled and ($status > 0)) {
|
||||
$solution .= 'Congratulations - everything seems OK now :-D';
|
||||
}
|
||||
if ($status < 1) {
|
||||
$solution .= '<p>IIS:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li><li>do NOT enable AllowPathInfoForScriptMappings !!!</li><li>slasharguments may not work when using ISAPI and PHP 4.3.10 and older</li></ul></p>';
|
||||
$solution .= '<p>Apache 1:<ul><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
|
||||
$solution .= '<p>Apache 2:<ul><li>you must add <code>AcceptPathInfo on</code> to php.ini or .htaccess</li><li>try to add <code>cgi.fix_pathinfo=1</code> to php.ini</li></ul></p>';
|
||||
}
|
||||
return $solution;
|
||||
}
|
||||
function is_enabled() {
|
||||
global $CFG;
|
||||
return !empty($CFG->slasharguments);
|
||||
}
|
||||
function status() {
|
||||
global $CFG;
|
||||
$handle = @fopen($CFG->wwwroot.'/file.php?file=/testslasharguments', "r");
|
||||
$contents = @trim(fread($handle, 10));
|
||||
@fclose($handle);
|
||||
if ($contents != 'test -1') {
|
||||
return -1;
|
||||
}
|
||||
$handle = @fopen($CFG->wwwroot.'/file.php/testslasharguments', "r");
|
||||
$contents = trim(@fread($handle, 10));
|
||||
@fclose($handle);
|
||||
switch ($contents) {
|
||||
case 'test 1': return 1;
|
||||
case 'test 2': return 2;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class problem_000011 extends problem_base {
|
||||
function title() {
|
||||
return 'Session errors detected';
|
||||
}
|
||||
function exists() {
|
||||
global $CFG;
|
||||
return isset($CFG->session_error_counter);
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_ANNOYANCE;
|
||||
}
|
||||
function description() {
|
||||
global $CFG;
|
||||
if (isset($CFG->session_error_counter)) {
|
||||
return 'Session problems were detected. Total count: '.$CFG->session_error_counter;
|
||||
} else {
|
||||
return 'No session errors detected.';
|
||||
}
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
if (optional_param('resetsesserrorcounter', 0, PARAM_BOOL)) {
|
||||
if (get_field('config', 'name', 'name', 'session_error_counter')) {
|
||||
delete_records('config', 'name', 'session_error_counter');
|
||||
}
|
||||
return 'Error counter was cleared.';
|
||||
} else {
|
||||
return '<p>Session errors can be caused by:<ul><li>unresolved problem in server software (aka random switching of users),</li><li>blocked or modified cookies,</li><li>deleting of active session files.</li></ul></p><p><a href="'.me().'&resetsesserrorcounter=1">Reset counter.</a></p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class problem_00000x extends problem_base {
|
||||
function title() {
|
||||
return '';
|
||||
}
|
||||
function exists() {
|
||||
return false;
|
||||
}
|
||||
function severity() {
|
||||
return SEVERITY_SIGNIFICANT;
|
||||
}
|
||||
function description() {
|
||||
return '';
|
||||
}
|
||||
function solution() {
|
||||
global $CFG;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
TODO:
|
||||
|
||||
session.save_path -- it doesn't really matter because we are already IN a session, right?
|
||||
detect unsupported characters in $CFG->wwwroot - see bug Bug #6091 - relative vs absolute path during backup/restore process
|
||||
|
||||
*/
|
||||
|
||||
?>
|
||||
+297
-378
@@ -1,44 +1,27 @@
|
||||
<?php // $Id$
|
||||
<?PHP // $Id$
|
||||
|
||||
/// Check that config.php exists, if not then call the install script
|
||||
if (!file_exists('../config.php')) {
|
||||
header('Location: ../install.php');
|
||||
/// Check that config.php exists
|
||||
if (!file_exists("../config.php")) {
|
||||
echo "<H2 align=center>You need to create a config.php.<BR>
|
||||
See the <A HREF=\"http://moodle.com/doc/?frame=install.html\">installation instructions</A>.</H2>";
|
||||
die;
|
||||
}
|
||||
|
||||
require_once("../config.php");
|
||||
|
||||
|
||||
/// Check that PHP is of a sufficient version
|
||||
/// Moved here because older versions do not allow while(@ob_end_clean());
|
||||
if (version_compare(phpversion(), "4.3.0") < 0) {
|
||||
$phpversion = phpversion();
|
||||
echo "Sorry, Moodle requires PHP 4.3.0 or later (currently using version $phpversion)";
|
||||
|
||||
if (!check_php_version("4.1.0")) {
|
||||
$version = phpversion();
|
||||
print_heading("Sorry, Moodle requires PHP 4.1.0 or later (currently using version $version)");
|
||||
die;
|
||||
}
|
||||
|
||||
/// Turn off time limits and try to flush everything all the time, sometimes upgrades can be slow.
|
||||
|
||||
@set_time_limit(0);
|
||||
@ob_implicit_flush(true);
|
||||
while(@ob_end_clean()); // ob_end_flush prevents sending of headers
|
||||
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php'); // Contains various admin-only functions
|
||||
require_once($CFG->libdir.'/ddllib.php'); // Install/upgrade related db functions
|
||||
|
||||
$id = optional_param('id', '', PARAM_ALPHANUM);
|
||||
$confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
|
||||
$agreelicence = optional_param('agreelicence',0, PARAM_BOOL);
|
||||
$ignoreupgradewarning = optional_param('ignoreupgradewarning', 0, PARAM_BOOL);
|
||||
|
||||
/// check upgrade status first
|
||||
if ($ignoreupgradewarning and !empty($_SESSION['upgraderunning'])) {
|
||||
$_SESSION['upgraderunning'] = 0;
|
||||
}
|
||||
upgrade_check_running("Upgrade already running in this session, please wait!<br />Click on the exclamation marks to ignore this warning (<a href=\"index.php?ignoreupgradewarning=1\">!!!</a>).", 10);
|
||||
|
||||
/// Check some PHP server settings
|
||||
|
||||
$documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
|
||||
$documentationlink = "please read the <A HREF=\"../doc/?frame=install.html&sub=webserver\">install documentation</A>";
|
||||
|
||||
if (ini_get_bool('session.auto_start')) {
|
||||
error("The PHP server variable 'session.auto_start' should be Off - $documentationlink");
|
||||
@@ -52,18 +35,11 @@
|
||||
error("The PHP server variable 'file_uploads' is not turned On - $documentationlink");
|
||||
}
|
||||
|
||||
if (empty($CFG->prefix) && $CFG->dbtype != 'mysql') { //Enforce prefixes for everybody but mysql
|
||||
error('$CFG->prefix can\'t be empty for your target DB (' . $CFG->dbtype . ')');
|
||||
}
|
||||
|
||||
if ($CFG->dbtype == 'oci8po' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc
|
||||
error('$CFG->prefix maximum allowed length for Oracle DBs is 2cc.');
|
||||
}
|
||||
|
||||
/// Check that config.php has been edited
|
||||
|
||||
if ($CFG->wwwroot == "http://example.com/moodle") {
|
||||
error("Moodle has not been configured yet. You need to edit config.php first.");
|
||||
error("Moodle has not been configured yet. You need to to edit config.php first.");
|
||||
}
|
||||
|
||||
|
||||
@@ -72,10 +48,10 @@
|
||||
$dirroot = dirname(realpath("../index.php"));
|
||||
if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
|
||||
error("Please fix your settings in config.php:
|
||||
<p>You have:
|
||||
<p>\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\";
|
||||
<p>but it should be:
|
||||
<p>\$CFG->dirroot = \"".addslashes($dirroot)."\";",
|
||||
<P>You have:
|
||||
<P>\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\";
|
||||
<P>but it should be:
|
||||
<P>\$CFG->dirroot = \"".addslashes($dirroot)."\";",
|
||||
"./");
|
||||
}
|
||||
|
||||
@@ -90,6 +66,10 @@
|
||||
$CFG->version = "";
|
||||
}
|
||||
|
||||
/// Turn off time limits, sometimes upgrades can be slow.
|
||||
|
||||
@set_time_limit(0);
|
||||
|
||||
/// Check if the main tables have been installed yet or not.
|
||||
|
||||
if (! $tables = $db->Metatables() ) { // No tables yet at all.
|
||||
@@ -97,200 +77,101 @@
|
||||
|
||||
} else { // Check for missing main tables
|
||||
$maintables = true;
|
||||
$mtables = array("config", "course", "course_categories", "course_modules",
|
||||
"course_sections", "log", "log_display", "modules",
|
||||
"user");
|
||||
$mtables = array("config", "course", "course_categories", "course_modules",
|
||||
"course_sections", "log", "log_display", "modules",
|
||||
"user", "user_admins", "user_students", "user_teachers");
|
||||
foreach ($mtables as $mtable) {
|
||||
if (!in_array($CFG->prefix.$mtable, $tables)) {
|
||||
if (!in_array($CFG->prefix.$mtable, $tables)) {
|
||||
$maintables = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$linktoscrolltoerrors = '<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>';
|
||||
if (! $maintables) {
|
||||
/// hide errors from headers in case debug enabled in config.php
|
||||
$origdebug = $CFG->debug;
|
||||
$CFG->debug = DEBUG_MINIMAL;
|
||||
error_reporting($CFG->debug);
|
||||
if (empty($agreelicence)) {
|
||||
$strlicense = get_string("license");
|
||||
print_header($strlicense, $strlicense, $strlicense, "", "", false, " ", " ");
|
||||
print_heading("<a href=\"http://moodle.org\">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment");
|
||||
print_heading("<A HREF=\"http://moodle.org\">Moodle</A> - Modular Object-Oriented Dynamic Learning Environment");
|
||||
print_heading(get_string("copyrightnotice"));
|
||||
print_simple_box_start('center');
|
||||
print_simple_box_start("center");
|
||||
echo text_to_html(get_string("gpl"));
|
||||
print_simple_box_end();
|
||||
echo "<br />";
|
||||
notice_yesno(get_string("doyouagree"), "index.php?agreelicence=true",
|
||||
"http://docs.moodle.org/en/License");
|
||||
notice_yesno(get_string("doyouagree"), "index.php?agreelicence=true",
|
||||
"http://moodle.org/doc/?frame=licence.html");
|
||||
exit;
|
||||
}
|
||||
|
||||
$strdatabasesetup = get_string("databasesetup");
|
||||
$strdatabasesuccess = get_string("databasesuccess");
|
||||
print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup,
|
||||
"", $linktoscrolltoerrors, false, " ", " ");
|
||||
/// return to original debugging level
|
||||
$CFG->debug = $origdebug;
|
||||
error_reporting($CFG->debug);
|
||||
upgrade_log_start();
|
||||
$db->debug = true;
|
||||
|
||||
/// Both old .sql files and new install.xml are supported
|
||||
/// But we prioritise install.xml (XMLDB) if present
|
||||
|
||||
change_db_encoding(); // first try to change db encoding to utf8
|
||||
$status = false;
|
||||
if (file_exists("$CFG->libdir/db/install.xml")) {
|
||||
$status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
|
||||
} else if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
|
||||
$status = modify_database("$CFG->libdir/db/$CFG->dbtype.sql"); //Old method
|
||||
print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup, "", "", false, " ", " ");
|
||||
if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
|
||||
$db->debug = true;
|
||||
if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
|
||||
$db->debug = false;
|
||||
notify($strdatabasesuccess, "green");
|
||||
} else {
|
||||
$db->debug = false;
|
||||
error("Error: Main databases NOT set up successfully");
|
||||
}
|
||||
} else {
|
||||
error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory.");
|
||||
error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle. See the lib/db directory.");
|
||||
}
|
||||
|
||||
/// Continue with the instalation
|
||||
$db->debug = false;
|
||||
if ($status) {
|
||||
// Install the roles system.
|
||||
moodle_install_roles();
|
||||
set_config('statsrolesupgraded',time());
|
||||
|
||||
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
|
||||
// (this should only have any effect during initial install).
|
||||
$adminroot = admin_get_root();
|
||||
$adminroot->prune('backups'); // backup settings table not created yet
|
||||
apply_default_settings($adminroot);
|
||||
|
||||
/// This is used to handle any settings that must exist in $CFG but which do not exist in
|
||||
/// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
|
||||
apply_default_exception_settings(array('alternateloginurl' => '',
|
||||
'auth' => 'email',
|
||||
'auth_pop3mailbox' => 'INBOX',
|
||||
'changepassword' => '',
|
||||
'enrol' => 'manual',
|
||||
'enrol_plugins_enabled' => 'manual',
|
||||
'guestloginbutton' => 1,
|
||||
'style' => 'default',
|
||||
'template' => 'default',
|
||||
'theme' => 'standardwhite'));
|
||||
|
||||
notify($strdatabasesuccess, "green");
|
||||
} else {
|
||||
error("Error: Main databases NOT set up successfully");
|
||||
}
|
||||
print_continue('index.php');
|
||||
print_continue("index.php");
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
/// Check version of Moodle code on disk compared with database
|
||||
/// and upgrade if possible.
|
||||
|
||||
if ( is_readable("$CFG->dirroot/version.php")) {
|
||||
include_once("$CFG->dirroot/version.php"); # defines $version
|
||||
}
|
||||
if (!$version) {
|
||||
error('Main version.php was not readable or specified');# without version, stop
|
||||
}
|
||||
include_once("$CFG->dirroot/version.php"); # defines $version
|
||||
include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines upgrades
|
||||
|
||||
if (file_exists("$CFG->dirroot/lib/db/$CFG->dbtype.php")) {
|
||||
include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines old upgrades
|
||||
}
|
||||
if (file_exists("$CFG->dirroot/lib/db/upgrade.php")) {
|
||||
include_once("$CFG->dirroot/lib/db/upgrade.php"); # defines new upgrades
|
||||
}
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
|
||||
if ($CFG->version) {
|
||||
if ($CFG->version) {
|
||||
if ($version > $CFG->version) { // upgrade
|
||||
|
||||
$a->oldversion = "$CFG->release ($CFG->version)";
|
||||
$a->newversion = "$release ($version)";
|
||||
$a->oldversion = $CFG->version;
|
||||
$a->newversion = $version;
|
||||
$strdatabasechecking = get_string("databasechecking", "", $a);
|
||||
|
||||
// hide errors from headers in case debug is enabled
|
||||
$origdebug = $CFG->debug;
|
||||
$CFG->debug = DEBUG_MINIMAL;
|
||||
error_reporting($CFG->debug);
|
||||
|
||||
// logout in case we are upgrading from pre 1.7 version - prevention of weird session problems
|
||||
if ($CFG->version < 2006050600) {
|
||||
require_logout();
|
||||
}
|
||||
|
||||
if (empty($confirmupgrade)) {
|
||||
|
||||
|
||||
print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
|
||||
"", "", false, " ", " ");
|
||||
|
||||
notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=yes', 'index.php');
|
||||
exit;
|
||||
|
||||
} else {
|
||||
$strdatabasesuccess = get_string("databasesuccess");
|
||||
print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
|
||||
"", $linktoscrolltoerrors, false, " ", " ");
|
||||
|
||||
/// return to original debugging level
|
||||
$CFG->debug = $origdebug;
|
||||
error_reporting($CFG->debug);
|
||||
upgrade_log_start();
|
||||
|
||||
/// Upgrade current language pack if we can
|
||||
upgrade_language_pack();
|
||||
|
||||
print_heading($strdatabasechecking);
|
||||
$db->debug=true;
|
||||
/// Launch the old main upgrade (if exists)
|
||||
$status = true;
|
||||
if (function_exists('main_upgrade')) {
|
||||
$status = main_upgrade($CFG->version);
|
||||
}
|
||||
/// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade
|
||||
if ($status && function_exists('xmldb_main_upgrade')) {
|
||||
$status = xmldb_main_upgrade($CFG->version);
|
||||
}
|
||||
$strdatabasesuccess = get_string("databasesuccess");
|
||||
print_header($strdatabasechecking, $strdatabasechecking, $strdatabasechecking,
|
||||
"", "", false, " ", " ");
|
||||
print_heading($strdatabasechecking);
|
||||
$db->debug=true;
|
||||
if (main_upgrade($CFG->version)) {
|
||||
$db->debug=false;
|
||||
/// If successful, continue upgrading roles and setting everything properly
|
||||
if ($status) {
|
||||
if (empty($CFG->rolesactive)) {
|
||||
// Upgrade to the roles system.
|
||||
moodle_install_roles();
|
||||
set_config('rolesactive', 1);
|
||||
} else if (!update_capabilities()) {
|
||||
error('Had trouble upgrading the core capabilities for the Roles System');
|
||||
}
|
||||
require_once($CFG->libdir.'/statslib.php');
|
||||
if (!stats_upgrade_for_roles_wrapper()) {
|
||||
notify('Couldn\'t upgrade the stats tables to use the new roles system');
|
||||
}
|
||||
if (set_config("version", $version)) {
|
||||
remove_dir($CFG->dataroot . '/cache', true); // flush cache
|
||||
notify($strdatabasesuccess, "green");
|
||||
print_continue("upgradesettings.php");
|
||||
exit;
|
||||
} else {
|
||||
notify("Upgrade failed! (Could not update version in config table)");
|
||||
}
|
||||
/// Main upgrade not success
|
||||
if (set_config("version", $version)) {
|
||||
notify($strdatabasesuccess, "green");
|
||||
print_continue("index.php");
|
||||
die;
|
||||
} else {
|
||||
notify("Upgrade failed! See /version.php");
|
||||
notify("Upgrade failed! (Could not update version in config table)");
|
||||
}
|
||||
upgrade_log_finish();
|
||||
} else {
|
||||
$db->debug=false;
|
||||
notify("Upgrade failed! See /version.php");
|
||||
}
|
||||
} else if ($version < $CFG->version) {
|
||||
upgrade_log_start();
|
||||
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
|
||||
upgrade_log_finish();
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!set_config("version", $version)) {
|
||||
error("A problem occurred inserting current version into databases");
|
||||
$strcurrentversion = get_string("currentversion");
|
||||
print_header($strcurrentversion, $strcurrentversion, $strcurrentversion,
|
||||
"", "", false, " ", " ");
|
||||
|
||||
if (set_config("version", $version)) {
|
||||
print_heading("You are currently using Moodle version $version (Release $release)");
|
||||
print_continue("index.php");
|
||||
die;
|
||||
} else {
|
||||
$db->debug=true;
|
||||
if (main_upgrade(0)) {
|
||||
print_continue("index.php");
|
||||
} else {
|
||||
error("A problem occurred inserting current version into databases");
|
||||
}
|
||||
$db->debug=false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,242 +184,280 @@
|
||||
if (!set_config("release", $release)) {
|
||||
notify("ERROR: Could not update release version in database!!");
|
||||
}
|
||||
notice(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'), 'index.php', 'none');
|
||||
print_continue("index.php");
|
||||
print_simple_box_start("CENTER");
|
||||
include("$CFG->dirroot/lang/en/docs/release.html");
|
||||
print_simple_box_end();
|
||||
print_continue("index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
/// Find and check all main modules and load them up or upgrade them if necessary
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
upgrade_activity_modules("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
||||
|
||||
/// Check all questiontype plugins and upgrade if necessary
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
/// It is important that this is done AFTER the quiz module has been upgraded
|
||||
upgrade_plugins('qtype', 'question/type', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
||||
|
||||
/// Upgrade backup/restore system if necessary
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
require_once("$CFG->dirroot/backup/lib.php");
|
||||
upgrade_backup_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
||||
|
||||
/// Upgrade blocks system if necessary
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
require_once("$CFG->dirroot/lib/blocklib.php");
|
||||
upgrade_blocks_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
||||
|
||||
/// Check all blocks and load (or upgrade them if necessary)
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
upgrade_blocks_plugins("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
||||
|
||||
/// Find and check all modules and load them up or upgrade them if necessary
|
||||
|
||||
/// Check all enrolment plugins and upgrade if necessary
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
upgrade_plugins('enrol', 'enrol', "$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
||||
if (!$mods = get_list_of_plugins("mod") ) {
|
||||
error("No modules installed!");
|
||||
}
|
||||
|
||||
/// Check for local database customisations
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
require_once("$CFG->dirroot/lib/locallib.php");
|
||||
upgrade_local_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
|
||||
foreach ($mods as $mod) {
|
||||
|
||||
/// just make sure upgrade logging is properly terminated
|
||||
upgrade_log_finish();
|
||||
if ($mod == "NEWMODULE") { // Someone has unzipped the template, ignore it
|
||||
continue;
|
||||
}
|
||||
|
||||
/// Set up the blank site - to be customized later at the end of install.
|
||||
if (! $site = get_site()) {
|
||||
// We are about to create the site "course"
|
||||
require_once($CFG->libdir.'/blocklib.php');
|
||||
$fullmod = "$CFG->dirroot/mod/$mod";
|
||||
|
||||
$newsite = new Object();
|
||||
$newsite->fullname = "";
|
||||
$newsite->shortname = "";
|
||||
$newsite->summary = "";
|
||||
$newsite->newsitems = 3;
|
||||
$newsite->numsections = 0;
|
||||
$newsite->category = 0;
|
||||
$newsite->format = 'site'; // Only for this course
|
||||
$newsite->teacher = get_string("defaultcourseteacher");
|
||||
$newsite->teachers = get_string("defaultcourseteachers");
|
||||
$newsite->student = get_string("defaultcoursestudent");
|
||||
$newsite->students = get_string("defaultcoursestudents");
|
||||
$newsite->timemodified = time();
|
||||
unset($module);
|
||||
|
||||
if ($newid = insert_record('course', $newsite)) {
|
||||
// Site created, add blocks for it
|
||||
$page = page_create_object(PAGE_COURSE_VIEW, $newid);
|
||||
blocks_repopulate_page($page); // Return value not checked because you can always edit later
|
||||
|
||||
$cat = new Object();
|
||||
$cat->name = get_string('miscellaneous');
|
||||
if (insert_record('course_categories', $cat)) {
|
||||
redirect('index.php');
|
||||
} else {
|
||||
error("Serious Error! Could not set up a default course category!");
|
||||
}
|
||||
if ( is_readable("$fullmod/version.php")) {
|
||||
include_once("$fullmod/version.php"); # defines $module with version etc
|
||||
} else {
|
||||
error("Serious Error! Could not set up the site!");
|
||||
notify("Module $mod: $fullmod/version.php was not readable");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// initialise default blocks on admin and site page if needed
|
||||
if (empty($CFG->adminblocks_initialised)) {
|
||||
require_once("$CFG->dirroot/$CFG->admin/pagelib.php");
|
||||
require_once($CFG->libdir.'/blocklib.php');
|
||||
page_map_class(PAGE_ADMIN, 'page_admin');
|
||||
$page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
|
||||
blocks_repopulate_page($page);
|
||||
if ( is_readable("$fullmod/db/$CFG->dbtype.php")) {
|
||||
include_once("$fullmod/db/$CFG->dbtype.php"); # defines upgrading function
|
||||
} else {
|
||||
notify("Module $mod: $fullmod/db/$CFG->dbtype.php was not readable");
|
||||
continue;
|
||||
}
|
||||
|
||||
//add admin_tree block to site if not already present
|
||||
if ($admintree = get_record('block', 'name', 'admin_tree')) {
|
||||
$page = page_create_object(PAGE_COURSE_VIEW, SITEID);
|
||||
blocks_execute_action($page, blocks_get_by_page($page), 'add', (int)$admintree->id, false, false);
|
||||
if ($admintreeinstance = get_record('block_instance', 'pagetype', $page->type, 'pageid', SITEID, 'blockid', $admintree->id)) {
|
||||
blocks_execute_action($page, blocks_get_by_page($page), 'moveleft', $admintreeinstance, false, false);
|
||||
if (!isset($module)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($module->requires)) {
|
||||
if ($module->requires > $CFG->version) {
|
||||
$info->modulename = $mod;
|
||||
$info->moduleversion = $module->version;
|
||||
$info->currentmoodle = $CFG->version;
|
||||
$info->requiremoodle = $module->requires;
|
||||
notify(get_string('modulerequirementsnotmet', 'error', $info));
|
||||
unset($info);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
set_config('adminblocks_initialised', 1);
|
||||
}
|
||||
|
||||
/// Define the unique site ID code if it isn't already
|
||||
if (empty($CFG->siteidentifier)) { // Unique site identification code
|
||||
set_config('siteidentifier', random_string(32));
|
||||
}
|
||||
|
||||
/// Check if the guest user exists. If not, create one.
|
||||
if (! record_exists("user", "username", "guest")) {
|
||||
$guest->auth = "manual";
|
||||
$guest->username = "guest";
|
||||
$guest->password = md5("guest");
|
||||
$guest->firstname = addslashes(get_string("guestuser"));
|
||||
$guest->lastname = " ";
|
||||
$guest->email = "root@localhost";
|
||||
$guest->description = addslashes(get_string("guestuserinfo"));
|
||||
$guest->confirmed = 1;
|
||||
$guest->lang = $CFG->lang;
|
||||
$guest->timemodified= time();
|
||||
|
||||
if (! $guest->id = insert_record("user", $guest)) {
|
||||
notify("Could not create guest user record !!!");
|
||||
$module->name = $mod; // The name MUST match the directory
|
||||
|
||||
if ($currmodule = get_record("modules", "name", $module->name)) {
|
||||
if ($currmodule->version == $module->version) {
|
||||
// do nothing
|
||||
} else if ($currmodule->version < $module->version) {
|
||||
if (empty($updated_modules)) {
|
||||
$strmodulesetup = get_string("modulesetup");
|
||||
print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, "", "", false, " ", " ");
|
||||
}
|
||||
print_heading("$module->name module needs upgrading");
|
||||
$upgrade_function = $module->name."_upgrade";
|
||||
if (function_exists($upgrade_function)) {
|
||||
$db->debug=true;
|
||||
if ($upgrade_function($currmodule->version, $module)) {
|
||||
$db->debug=false;
|
||||
// OK so far, now update the modules record
|
||||
$module->id = $currmodule->id;
|
||||
if (! update_record("modules", $module)) {
|
||||
error("Could not update $module->name record in modules table!");
|
||||
}
|
||||
notify(get_string("modulesuccess", "", $module->name), "green");
|
||||
echo "<HR>";
|
||||
} else {
|
||||
$db->debug=false;
|
||||
notify("Upgrading $module->name from $currmodule->version to $module->version FAILED!");
|
||||
}
|
||||
}
|
||||
$updated_modules = true;
|
||||
} else {
|
||||
error("Version mismatch: $module->name can't downgrade $currmodule->version -> $module->version !");
|
||||
}
|
||||
|
||||
} else { // module not installed yet, so install it
|
||||
if (empty($updated_modules)) {
|
||||
$strmodulesetup = get_string("modulesetup");
|
||||
print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, "", "", false, " ", " ");
|
||||
}
|
||||
print_heading($module->name);
|
||||
$updated_modules = true;
|
||||
$db->debug = true;
|
||||
@set_time_limit(0); // To allow slow databases to complete the long SQL
|
||||
if (modify_database("$fullmod/db/$CFG->dbtype.sql")) {
|
||||
$db->debug = false;
|
||||
if ($module->id = insert_record("modules", $module)) {
|
||||
notify(get_string("modulesuccess", "", $module->name), "green");
|
||||
echo "<HR>";
|
||||
} else {
|
||||
error("$module->name module could not be added to the module list!");
|
||||
}
|
||||
} else {
|
||||
error("$module->name tables could NOT be set up successfully!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($updated_modules)) {
|
||||
print_continue("index.php");
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
/// Insert default values for any important configuration variables
|
||||
|
||||
include_once("$CFG->dirroot/lib/defaults.php");
|
||||
|
||||
foreach ($defaults as $name => $value) {
|
||||
if (!isset($CFG->$name)) {
|
||||
$CFG->$name = $value;
|
||||
set_config($name, $value);
|
||||
$configchange = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// If any new configurations were found then send to the config page to check
|
||||
|
||||
if (!empty($configchange)) {
|
||||
redirect("config.php");
|
||||
}
|
||||
|
||||
/// Set up the overall site name etc.
|
||||
if (! $site = get_site()) {
|
||||
redirect("site.php");
|
||||
}
|
||||
|
||||
/// Set up the admin user
|
||||
if (empty($CFG->rolesactive)) {
|
||||
redirect('user.php');
|
||||
if (! record_exists("user_admins")) { // No admin user yet
|
||||
redirect("user.php");
|
||||
}
|
||||
|
||||
/// Check for valid admin user
|
||||
require_login();
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
|
||||
require_capability('moodle/site:config', $context);
|
||||
|
||||
/// check that site is properly customized
|
||||
if (empty($site->shortname) or empty($site->shortname)) {
|
||||
redirect('settings.php?section=frontpage&return=site');
|
||||
if (!isadmin()) {
|
||||
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
||||
}
|
||||
|
||||
/// Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders
|
||||
|
||||
if (!empty($id)) {
|
||||
if ($id == $CFG->siteidentifier) {
|
||||
set_config('registered', time());
|
||||
}
|
||||
}
|
||||
/// At this point everything is set up and the user is an admin, so print menu
|
||||
|
||||
/// Everything should now be set up, and the user is an admin
|
||||
$stradministration = get_string("administration");
|
||||
print_header("$site->shortname: $stradministration","$site->fullname", "$stradministration");
|
||||
print_simple_box_start("center", "100%", "$THEME->cellcontent2", 20);
|
||||
print_heading($stradministration);
|
||||
|
||||
/// Print default admin page with notifications.
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('adminnotifications', $adminroot);
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
/// Deprecated database! Warning!!
|
||||
if (!empty($CFG->migrated_to_new_db)) {
|
||||
print_simple_box_start('center','60%');
|
||||
print_string('dbmigrationdeprecateddb','admin');
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
/// Check for any special upgrades that might need to be run
|
||||
if (!empty($CFG->upgrade)) {
|
||||
print_simple_box(get_string("upgrade$CFG->upgrade", "admin",
|
||||
"$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"), "center", '60%');
|
||||
if (!empty($CFG->upgrade)) { // Print notice about extra upgrading that needs to be done
|
||||
print_simple_box(get_string("upgrade$CFG->upgrade", "admin",
|
||||
"$CFG->wwwroot/$CFG->admin/upgrade$CFG->upgrade.php"), "center");
|
||||
print_spacer(10,10);
|
||||
}
|
||||
|
||||
if (ini_get_bool('register_globals') && !ini_get_bool('magic_quotes_gpc')) {
|
||||
print_simple_box(get_string('globalsquoteswarning', 'admin'), 'center', '60%');
|
||||
$table->tablealign = "right";
|
||||
$table->align = array ("right", "left");
|
||||
$table->wrap = array ("nowrap", "nowrap");
|
||||
$table->cellpadding = 4;
|
||||
$table->cellspacing = 3;
|
||||
$table->width = "40%";
|
||||
|
||||
$configdata = "<font size=+1> </font><a href=\"config.php\">".get_string("configvariables")."</a> - <font size=1>".
|
||||
get_string("adminhelpconfigvariables")."</font><br />";
|
||||
$configdata .= "<font size=+1> </font><a href=\"site.php\">".get_string("sitesettings")."</a> - <font size=1>".
|
||||
get_string("adminhelpsitesettings")."</font><br />";
|
||||
$configdata .= "<font size=+1> </font><a href=\"../theme/index.php\">".get_string("themes")."</a> - <font size=1>".
|
||||
get_string("adminhelpthemes")."</font><br />";
|
||||
$configdata .= "<font size=+1> </font><a href=\"lang.php\">".get_string("language")."</a> - <font size=1>".
|
||||
get_string("adminhelplanguage")."</font><br />";
|
||||
$configdata .= "<font size=+1> </font><a href=\"modules.php\">".get_string("managemodules")."</a> - <font size=1>".
|
||||
get_string("adminhelpmanagemodules")."</font><br />";
|
||||
$configdata .= "<font size=+1> </font><a href=\"blocks.php\">".get_string("manageblocks")."</a> - <font size=1>".
|
||||
get_string("adminhelpmanageblocks")."</font><br />";
|
||||
$configdata .= "<font size=+1> </font><a href=\"filters.php\">".get_string("managefilters")."</a> - <font size=1>".
|
||||
get_string("adminhelpmanagefilters")."</font><br />";
|
||||
if (!isset($CFG->disablescheduledbackups)) {
|
||||
$configdata .= "<font size=+1> </font><a href=\"backup.php\">".get_string("backup")."</a> - <font size=1>".
|
||||
get_string("adminhelpbackup")."</font><br />";
|
||||
}
|
||||
|
||||
if (is_dataroot_insecure()) {
|
||||
print_simple_box(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot), 'center', '60%');
|
||||
}
|
||||
|
||||
/// If no recently cron run
|
||||
$lastcron = get_field_sql('SELECT max(lastcron) FROM ' . $CFG->prefix . 'modules');
|
||||
if (time() - $lastcron > 3600 * 24) {
|
||||
$strinstallation = get_string('installation', 'install');
|
||||
$helpbutton = helpbutton('install', $strinstallation, 'moodle', true, false, '', true);
|
||||
print_simple_box(get_string('cronwarning', 'admin')." ".$helpbutton, 'center', '60%');
|
||||
}
|
||||
|
||||
/// Alert if we are currently in maintenance mode
|
||||
if (file_exists($CFG->dataroot.'/1/maintenance.html')) {
|
||||
print_simple_box(get_string('sitemaintenancewarning', 'admin') , 'center', '60%');
|
||||
}
|
||||
|
||||
/// Alert to display the utf-8 migration button (if !unicode yet and DB is MySQL or PG)
|
||||
if (empty($CFG->unicodedb) && in_array($CFG->dbtype, array('mysql', 'postgres7'))) {
|
||||
print_simple_box(get_string('unicodeupgradenotice', 'admin') , 'center', '60%');
|
||||
}
|
||||
|
||||
/// Print slightly annoying registration button every six months ;-)
|
||||
/// You can set the "registered" variable to something far in the future
|
||||
/// if you really want to prevent this. eg 9999999999
|
||||
if (!isset($CFG->registered) || $CFG->registered < (time() - 3600*24*30*6)) {
|
||||
$options = array();
|
||||
$options['sesskey'] = $USER->sesskey;
|
||||
print_simple_box_start('center','60%');
|
||||
echo '<div align="center">';
|
||||
print_string('pleaseregister', 'admin');
|
||||
print_single_button('register.php', $options, get_string('registration'));
|
||||
echo '</div>';
|
||||
print_simple_box_end();
|
||||
$registrationbuttonshown = true;
|
||||
$table->data[] = array("<font size=+1><b><a href=\"configure.php\">".get_string("configuration")."</a></b>",
|
||||
$configdata);
|
||||
|
||||
|
||||
$userdata = "<font size=+1> </font><a href=\"auth.php\">".get_string("authentication")."</a> - <font size=1>".
|
||||
get_string("adminhelpauthentication")."</font><br />";
|
||||
|
||||
if (is_internal_auth()) {
|
||||
$userdata .= "<font size=+1> </font><a href=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true\">".
|
||||
get_string("addnewuser")."</a> - <font size=1>".
|
||||
get_string("adminhelpaddnewuser")."</font><br />";
|
||||
$userdata .= "<font size=+1> </font><a href=\"$CFG->wwwroot/$CFG->admin/uploaduser.php\">".
|
||||
get_string("uploadusers")."</a> - <font size=1>".
|
||||
get_string("adminhelpuploadusers")."</font><br />";
|
||||
}
|
||||
$userdata .= "<font size=+1> </font><a href=\"user.php\">".get_string("edituser")."</a> - <font size=1>".
|
||||
get_string("adminhelpedituser")."</font><br />";
|
||||
$userdata .= "<font size=+1> </font><a href=\"admin.php\">".get_string("assignadmins")."</a> - <font size=1>".
|
||||
get_string("adminhelpassignadmins")."</font><br />";
|
||||
$userdata .= "<font size=+1> </font><a href=\"creators.php\">".get_string("assigncreators")."</a> - <font size=1>".
|
||||
get_string("adminhelpassigncreators")."</font><br />";
|
||||
$userdata .= "<font size=+1> </font><a href=\"../course/index.php?edit=on\">".get_string("assignteachers")."</a> - <font size=1>".
|
||||
get_string("adminhelpassignteachers").
|
||||
" <img src=\"../pix/t/user.gif\" height=11 width=11></font><br />";
|
||||
$userdata .= "<font size=+1> </font><a href=\"../course/index.php?edit=off\">".get_string("assignstudents")."</a> - <font size=1>".
|
||||
get_string("adminhelpassignstudents")."</font>";
|
||||
|
||||
$table->data[] = array("<font size=+1><b><a href=\"users.php\">".get_string("users")."</a></b>", $userdata);
|
||||
|
||||
$table->data[] = array("<font size=+1><b><a href=\"../course/index.php?edit=on\">".get_string("courses")."</a></b>",
|
||||
"<font size=+1> </font>".get_string("adminhelpcourses"));
|
||||
$table->data[] = array("<font size=+1><b><a href=\"../course/log.php?id=$site->id\">".get_string("logs")."</a></b>",
|
||||
"<font size=+1> </font>".get_string("adminhelplogs"));
|
||||
$table->data[] = array("<font size=+1><b><a href=\"../files/index.php?id=$site->id\">".get_string("sitefiles")."</a></b>",
|
||||
"<font size=+1> </font>".get_string("adminhelpsitefiles"));
|
||||
if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
|
||||
$table->data[] = array("<font size=+1><b><a href=\"$CFG->dbtype/frame.php\">".get_string("managedatabase")."</a></b>",
|
||||
"<font size=+1> </font>".get_string("adminhelpmanagedatabase"));
|
||||
}
|
||||
|
||||
print_table($table);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
|
||||
$copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
|
||||
'<a href="http://docs.moodle.org/en/Release">'.$CFG->release.'</a> ('.$CFG->version.')<br />'.
|
||||
'Copyright © 1999 onwards, Martin Dougiamas<br />'.
|
||||
'and <a href="http://docs.moodle.org/en/Credits">many other contributors</a>.<br />'.
|
||||
'<a href="http://docs.moodle.org/en/License">GNU Public License</a>';
|
||||
echo '<p class="copyright">'.$copyrighttext.'</p>';
|
||||
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO REMOVE OR MODIFY THE COPYRIGHT NOTICE BELOW ////
|
||||
$copyrighttext = "<a href=\"http://moodle.org/\">Moodle</a> ".
|
||||
"<a href=\"../doc/?frame=release.html\">$CFG->release</a> ($CFG->version)<br />".
|
||||
"Copyright © 1999-2004 Martin Dougiamas<br />".
|
||||
"<a href=\"../doc/?frame=licence.html\">GNU Public License</a>";
|
||||
echo "<center><p><font size=1>$copyrighttext</font></p></center>";
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
if (empty($registrationbuttonshown)) {
|
||||
echo '<div align="center">';
|
||||
$options = array();
|
||||
$options['sesskey'] = $USER->sesskey;
|
||||
print_single_button('register.php', $options, get_string('registration'));
|
||||
echo '</div>';
|
||||
}
|
||||
echo "<table border=0 align=center width=100%><tr>";
|
||||
echo "<td align=center width=33%>";
|
||||
print_single_button("$CFG->wwwroot/doc", NULL, get_string("documentation"));
|
||||
echo "</td>";
|
||||
|
||||
echo "<td align=center width=33%>";
|
||||
print_single_button("phpinfo.php", NULL, get_string("phpinfo"));
|
||||
echo "</td>";
|
||||
|
||||
if (optional_param('dbmigrate')) { // ??? Is this actually used?
|
||||
print_simple_box_start('center','60%');
|
||||
require_once($CFG->dirroot.'/'.$CFG->admin.'/utfdbmigrate.php');
|
||||
db_migrate2utf8();
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
echo "<td align=center width=33%>";
|
||||
print_single_button("register.php", NULL, get_string("registration"));
|
||||
echo "</td>";
|
||||
echo "<tr></table>";
|
||||
|
||||
print_simple_box_end();
|
||||
|
||||
print_footer($site);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('toinodb', $adminroot);
|
||||
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_heading('Convert all MySQL tables from MYISAM to InnoDB');
|
||||
|
||||
if ($CFG->dbtype != 'mysql') {
|
||||
notice('This function is for MySQL databases only!', 'index.php');
|
||||
}
|
||||
|
||||
if (data_submitted() and $confirm and confirm_sesskey()) {
|
||||
|
||||
notify('Please be patient and wait for this to complete...', 'notifysuccess');
|
||||
|
||||
if ($tables = $db->MetaTables()) {
|
||||
$db->debug = true;
|
||||
foreach ($tables as $table) {
|
||||
execute_sql("ALTER TABLE $table TYPE=INNODB; ");
|
||||
}
|
||||
$db->debug = false;
|
||||
}
|
||||
notify('... done.', 'notifysuccess');
|
||||
print_continue('index.php');
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
} else {
|
||||
$optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
|
||||
notice_yesno('Are you sure you want convert all your tables to the InnoDB format?',
|
||||
'innodb.php', 'index.php', $optionsyes, NULL, 'post', 'get');
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
}
|
||||
|
||||
?>
|
||||
+164
-477
@@ -1,252 +1,134 @@
|
||||
<?PHP // $Id$
|
||||
/**
|
||||
* Display the admin/language menu and process strings translation.
|
||||
*
|
||||
* CHANGES
|
||||
*
|
||||
* 2006/11/07 mudrd8mz
|
||||
* Fixed bug MDL-7361. Thanks to Dan Poltawski for the patch proposal.
|
||||
*
|
||||
* 2006/06/08 mudrd8mz
|
||||
* 1) Fixed bug 5745 reported by Harry Smith so now can edit en_utf8_local pack
|
||||
* 2) More notification messages included
|
||||
*
|
||||
* 2006/05/30 mudrd8mz
|
||||
* Merged with version by Mitsuhiro Yoshida - display icon links instead of text links
|
||||
* (I have changed the position of arrow icons to not to be so close each other)
|
||||
*
|
||||
* 2006/05/19 mudrd8mz
|
||||
* A lot of changes to support translation of *_utf8_local langugage packs. Needs testing
|
||||
*
|
||||
* 2006/05/16 mudrd8mz
|
||||
* 1) LANG_DEFAULT_FILE can be now set. moodle.php used to be opened automatically.
|
||||
* As it was (and still is) one of the biggest files it usually took a long time to load the page
|
||||
* even if you just want to choose the file to translate.
|
||||
* 2) added links from "missing" to "compare" mode page
|
||||
* 3) english strings are now key-sorted in "missing" mode
|
||||
* 4) list of files with missing strings is now displayed at the top of "missing" page
|
||||
*
|
||||
* 2006/05/14 mudrd8mz Improvements of lang.php,v 1.65 2006/04/10 22:15:57 stronk7 Exp
|
||||
* 1) "go to first missing string" link can be displayed (see LANG_DISPLAY_MISSING_LINKS)
|
||||
* 2) "go to next missing" link can be displayed (see LANG_DISPLAY_MISSING_LINKS)
|
||||
* 3) submit button may be repeated (see LANG_SUBMIT_REPEAT*)
|
||||
* 4) added (empty) "summary" attribute for the <table>'s
|
||||
* 5) added error_reporting(E_ALL ^ E_NOTICE); in "compare" mode (even in debug environment
|
||||
* we know that missing keys are missing strings here, not bugs ;-)
|
||||
*/
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('langedit', $adminroot);
|
||||
require_once("../config.php");
|
||||
|
||||
define('LANG_SUBMIT_REPEAT', 1); // repeat displaying submit button?
|
||||
define('LANG_SUBMIT_REPEAT_EVERY', 20); // if so, after how many lines?
|
||||
define('LANG_DISPLAY_MISSING_LINKS', 1); // display "go to first/next missing string" links?
|
||||
define('LANG_DEFAULT_FILE', ''); // default file to translate. Empty allowed
|
||||
define('LANG_LINK_MISSING_STRINGS', 1); // create links from "missing" page to "compare" page?
|
||||
define('LANG_DEFAULT_USELOCAL', 0); // should *_utf8_local be used by default?
|
||||
optional_variable($mode, "");
|
||||
optional_variable($currentfile, "moodle.php");
|
||||
|
||||
$mode = optional_param('mode', '', PARAM_ALPHA);
|
||||
$currentfile = optional_param('currentfile', LANG_DEFAULT_FILE, PARAM_FILE);
|
||||
$uselocal = optional_param('uselocal', -1, PARAM_INT);
|
||||
require_login();
|
||||
|
||||
if ($uselocal == -1) {
|
||||
if (isset($SESSION->langtranslateintolocal)) {
|
||||
$uselocal = $SESSION->langtranslateintolocal;
|
||||
} else {
|
||||
$uselocal = LANG_DEFAULT_USELOCAL;
|
||||
}
|
||||
} else {
|
||||
$SESSION->langtranslateintolocal = $uselocal;
|
||||
if (!isadmin()) {
|
||||
error("You need to be admin to edit this page");
|
||||
}
|
||||
|
||||
if (! $site = get_site()) {
|
||||
error("Site not defined!");
|
||||
}
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strconfiguration = get_string("configuration");
|
||||
$strlanguage = get_string("language");
|
||||
$strcurrentlanguage = get_string("currentlanguage");
|
||||
$strmissingstrings = get_string("missingstrings");
|
||||
$streditstrings = get_string("editstrings", 'admin');
|
||||
$stredithelpdocs = get_string("edithelpdocs", 'admin');
|
||||
$strcomparelanguage = get_string("comparelanguage");
|
||||
$strthislanguage = get_string("thislanguage");
|
||||
$strgotofirst = get_string('gotofirstmissing','admin');
|
||||
$strfilestoredin = get_string('langstorein', 'admin');
|
||||
$strfilestoredinhelp = get_string('langstoreinhelp', 'admin');
|
||||
$strswitchlangdirbtn = get_string('langstoreswitch', 'admin');
|
||||
$strchoosefiletoedit = get_string('langchoosefile', 'admin');
|
||||
$streditennotallowed = get_string('langnoeditenglish', 'admin');
|
||||
$strfilecreated = get_string('langfilecreated', 'admin');
|
||||
|
||||
// FIXME / TODO
|
||||
// remove following lines after adding string into proper english lang pack
|
||||
$strgotofirst = 'go to first missing string';
|
||||
$strfilestoredin = 'Save file into folder :';
|
||||
$strfilestoredinhelp = 'Where the file will be stored';
|
||||
$strswitchlangdirbtn = 'switch';
|
||||
$strchoosefiletoedit = 'Choose file to edit from the box above';
|
||||
$streditennotallowed = 'Language en_utf8 cannot be edited with this page - switch to local';
|
||||
$strfilecreated = 'New file created';
|
||||
|
||||
$currentlang = current_language();
|
||||
|
||||
switch ($mode) {
|
||||
case "missing":
|
||||
// Missing array keys are not bugs here but missing strings
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
$navigation = "<a href=\"lang.php\">$strlanguage</a> -> $strmissingstrings";
|
||||
$navigation = "<A HREF=\"lang.php\">$strlanguage</A> -> $strmissingstrings";
|
||||
$title = $strmissingstrings;
|
||||
$button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/lang.php">'.
|
||||
'<input type="hidden" name="mode" value="compare" />'.
|
||||
'<input type="submit" value="'.$streditstrings.'" /></form>';
|
||||
break;
|
||||
case "compare":
|
||||
$navigation = "<a href=\"lang.php\">$strlanguage</a> -> $streditstrings";
|
||||
$title = $streditstrings;
|
||||
$button = '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/lang.php">'.
|
||||
'<input type="hidden" name="mode" value="missing" />'.
|
||||
'<input type="submit" value="'.$strmissingstrings.'" /></form>';
|
||||
$navigation = "<A HREF=\"lang.php\">$strlanguage</A> -> $strcomparelanguage";
|
||||
$title = $strcomparelanguage;
|
||||
break;
|
||||
default:
|
||||
$title = $strlanguage;
|
||||
$navigation = $strlanguage;
|
||||
$button = '';
|
||||
break;
|
||||
}
|
||||
|
||||
$currentlang = current_language();
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_header("$site->shortname: $title", "$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> -> $navigation");
|
||||
|
||||
if (!$mode) {
|
||||
print_simple_box_start('center','80%');
|
||||
echo '<div align="center">';
|
||||
print_string('editlang','admin');
|
||||
echo '<br />';
|
||||
$currlang = current_language();
|
||||
$langs = get_list_of_languages();
|
||||
echo "<table align=center><tr><td align=\"right\">";
|
||||
echo "<b>$strcurrentlanguage:</b>";
|
||||
echo '<br />';
|
||||
echo popup_form ("$CFG->wwwroot/$CFG->admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
|
||||
$options["lang"] = $currentlang;
|
||||
echo "</td><td>";
|
||||
echo popup_form ("$CFG->wwwroot/admin/lang.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
|
||||
echo "</td></tr></table>";
|
||||
print_heading("<a href=\"lang.php?mode=missing\">$strmissingstrings</a>");
|
||||
print_heading("<a href=\"lang.php?mode=compare\">$streditstrings</a>");
|
||||
print_heading("<a href=\"langdoc.php\">$stredithelpdocs</a>");
|
||||
echo '</div>';
|
||||
print_simple_box_end();
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_heading("<a href=\"lang.php?mode=compare\">$strcomparelanguage</a>");
|
||||
echo "<center><hr noshade size=1>";
|
||||
$options["lang"] = $currentlang;
|
||||
print_single_button("http://moodle.org/download/lang/", $options, get_string("latestlanguagepack"));
|
||||
echo "</center>";
|
||||
print_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Get a list of all the root files in the English directory
|
||||
|
||||
$langbase = $CFG->dataroot . '/lang';
|
||||
$enlangdir = "$CFG->dirroot/lang/en_utf8";
|
||||
if ($currentlang == 'en_utf8') {
|
||||
$langdir = $enlangdir;
|
||||
} else {
|
||||
$langdir = "$langbase/$currentlang";
|
||||
}
|
||||
$locallangdir = "$langbase/{$currentlang}_local";
|
||||
$langdir = "$CFG->dirroot/lang/$currentlang";
|
||||
$enlangdir = "$CFG->dirroot/lang/en";
|
||||
|
||||
if (! $stringfiles = get_directory_list($enlangdir, "", false)) {
|
||||
error("Could not find English language pack!");
|
||||
}
|
||||
|
||||
foreach ($stringfiles as $key => $file) {
|
||||
if (substr($file, -4) != ".php") { //Avoid non php files to be showed
|
||||
unset($stringfiles[$key]);
|
||||
}
|
||||
if ($file == "langconfig.php") { //Avoid langconfig.php to be showed
|
||||
if (substr($file, -4) != ".php") {
|
||||
unset($stringfiles[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($mode == "missing") {
|
||||
if (!file_exists($langdir)) {
|
||||
error ('to edit this language pack, you need to put it in '.$CFG->dataroot.'/lang');
|
||||
}
|
||||
|
||||
// Following variables store the HTML output to be echo-ed
|
||||
$m = '';
|
||||
$o = '';
|
||||
|
||||
// For each file, check that a counterpart exists, then check all the strings
|
||||
|
||||
foreach ($stringfiles as $file) {
|
||||
if (!file_exists("$langdir/$file")) {
|
||||
if (!touch("$langdir/$file")) {
|
||||
echo "<p><font color=red>".get_string("filemissing", "", "$langdir/$file")."</font></p>";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
unset($string);
|
||||
include("$enlangdir/$file");
|
||||
$enstring = $string;
|
||||
|
||||
ksort($enstring);
|
||||
|
||||
|
||||
unset($string);
|
||||
|
||||
if (file_exists("$langdir/$file")) {
|
||||
include("$langdir/$file");
|
||||
$fileismissing = 0;
|
||||
} else {
|
||||
$fileismissing = 1;
|
||||
// notify(get_string("filemissing", "", "$langdir/$file"));
|
||||
$o .= '<div class="notifyproblem" align="center">'.get_string("filemissing", "", "$langdir/$file").'</div><br />';
|
||||
$string = array();
|
||||
}
|
||||
|
||||
$missingcounter = 0;
|
||||
include("$langdir/$file");
|
||||
|
||||
$first = true;
|
||||
foreach ($enstring as $key => $value) {
|
||||
if (empty($string[$key]) and $string[$key] != "0") { //bug fix 4735 mits
|
||||
if (!isset($string[$key]) or $string[$key] == "") {
|
||||
$value = htmlspecialchars($value);
|
||||
$value = str_replace("$"."a", "\\$"."a", $value);
|
||||
$value = str_replace("%%","%",$value);
|
||||
if ($first) {
|
||||
$m .= "<a href=\"lang.php?mode=missing#$file\">$file";
|
||||
$m .= $fileismissing ? '*' : '';
|
||||
$m .= '</a> ';
|
||||
$o .= "<p><a name=\"$file\"></a><b>".get_string("stringsnotset","","$langdir/$file")."</b></p><pre>";
|
||||
echo "</PRE><HR><P><B>".get_string("stringsnotset","","$langdir/$file")."</B></P><PRE>";
|
||||
$first = false;
|
||||
$somethingfound = true;
|
||||
}
|
||||
$missingcounter++;
|
||||
if (LANG_LINK_MISSING_STRINGS) {
|
||||
$missinglinkstart = "<a href=\"lang.php?mode=compare&currentfile=$file#missing$missingcounter\">";
|
||||
$missinglinkend = '</a>';
|
||||
} else {
|
||||
$missinglinkstart = '';
|
||||
$missinglinkend = '';
|
||||
}
|
||||
$o .= "$"."string['".$missinglinkstart.$key.$missinglinkend."'] = \"$value\";<br />";
|
||||
echo "$"."string['$key'] = \"$value\";<BR>";
|
||||
}
|
||||
}
|
||||
if (!$first) {
|
||||
$o .= '</pre><hr />';
|
||||
}
|
||||
}
|
||||
|
||||
if ($m <> '') {
|
||||
echo '<br />';
|
||||
print_simple_box_start("center", "80%");
|
||||
echo '<center><font size="2">';
|
||||
echo $m;
|
||||
echo '</font></center>';
|
||||
print_simple_box_end();
|
||||
}
|
||||
echo $o;
|
||||
|
||||
if (! $files = get_directory_list("$CFG->dirroot/lang/en_utf8/help", "CVS")) {
|
||||
|
||||
if (! $files = get_directory_list("$CFG->dirroot/lang/en/help", "CVS")) {
|
||||
error("Could not find English language help files!");
|
||||
}
|
||||
|
||||
foreach ($files as $filekey => $file) { // check all the help files.
|
||||
if (!file_exists("$langdir/help/$file")) {
|
||||
echo "<p><font color=\"red\">".get_string("filemissing", "", "$langdir/help/$file")."</font></p>";
|
||||
echo "<p><font color=red>".get_string("filemissing", "", "$langdir/help/$file")."</font></p>";
|
||||
$somethingfound = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $files = get_directory_list("$CFG->dirroot/lang/en_utf8/docs", "CVS")) {
|
||||
if (! $files = get_directory_list("$CFG->dirroot/lang/en/docs", "CVS")) {
|
||||
error("Could not find English language docs files!");
|
||||
}
|
||||
foreach ($files as $filekey => $file) { // check all the docs files.
|
||||
if (!file_exists("$langdir/docs/$file")) {
|
||||
echo "<p><font color=\"red\">".get_string("filemissing", "", "$langdir/docs/$file")."</font></p>";
|
||||
echo "<P><FONT COLOR=red>".get_string("filemissing", "", "$langdir/docs/$file")."</FONT></P>";
|
||||
$somethingfound = true;
|
||||
continue;
|
||||
}
|
||||
@@ -259,71 +141,18 @@
|
||||
}
|
||||
|
||||
} else if ($mode == "compare") {
|
||||
|
||||
if (!file_exists($langbase) ){
|
||||
if (!lang_make_directory($langbase) ){
|
||||
error('ERROR: Could not create base lang directory ' . $langbase);
|
||||
} else {
|
||||
echo '<div class="notifysuccess" align="center">Created directory '.
|
||||
$langbase .'</div>'."<br />\n";
|
||||
}
|
||||
}
|
||||
if (!$uselocal && !file_exists($langdir)) {
|
||||
if (!lang_make_directory($langdir)) {
|
||||
error('ERROR: Could not create directory '.$langdir);
|
||||
} else {
|
||||
echo '<div class="notifysuccess" align="center">Created directory '.
|
||||
$langdir .'</div>'."<br />\n";
|
||||
}
|
||||
}
|
||||
if ($uselocal && !file_exists($locallangdir)) {
|
||||
if (!lang_make_directory($locallangdir)) {
|
||||
echo '<div class="notifyproblem" align="center">ERROR: Could not create directory '.
|
||||
$locallangdir .'</div>'."<br />\n";
|
||||
$uselocal = 0;
|
||||
} else {
|
||||
echo '<div class="notifysuccess" align="center">Created directory '.
|
||||
$locallangdir .'</div>'."<br />\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($_POST['currentfile'])){ // Save a file
|
||||
if (!confirm_sesskey()) {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
|
||||
$newstrings = array();
|
||||
|
||||
foreach ($_POST as $postkey => $postval) {
|
||||
$stringkey = lang_file_string_key($postkey);
|
||||
$newstrings[$stringkey] = $postval;
|
||||
}
|
||||
|
||||
$newstrings = $_POST;
|
||||
unset($newstrings['currentfile']);
|
||||
|
||||
if ($uselocal) {
|
||||
include("$langdir/$currentfile");
|
||||
if (isset($string)) {
|
||||
$packstring = $string;
|
||||
} else {
|
||||
$packstring = array();
|
||||
}
|
||||
unset($string);
|
||||
$saveinto = $locallangdir;
|
||||
if (lang_save_file($langdir, $currentfile, $newstrings)) {
|
||||
notify(get_string("changessaved")." ($langdir/$currentfile)", "green");
|
||||
} else {
|
||||
$packstring = array();
|
||||
$saveinto = $langdir;
|
||||
error("Could not save the file '$currentfile'!", "lang.php?mode=compare¤tfile=$currentfile");
|
||||
}
|
||||
|
||||
if (lang_save_file($saveinto, $currentfile, $newstrings, $uselocal, $packstring)) {
|
||||
notify(get_string("changessaved")." ($saveinto/$currentfile)", "green");
|
||||
} else {
|
||||
error("Could not save the file '$saveinto/$currentfile'!", "lang.php?mode=compare&currentfile=$currentfile");
|
||||
}
|
||||
unset($packstring);
|
||||
}
|
||||
}
|
||||
|
||||
print_heading_with_help($streditstrings, "langedit");
|
||||
print_heading_with_help($strcomparelanguage, "langedit");
|
||||
|
||||
print_simple_box_start("center", "80%");
|
||||
echo '<center><font size="2">';
|
||||
@@ -331,219 +160,130 @@
|
||||
if ($file == $currentfile) {
|
||||
echo "<b>$file</b> ";
|
||||
} else {
|
||||
echo "<a href=\"lang.php?mode=compare&currentfile=$file\">$file</a> ";
|
||||
echo "<a href=\"lang.php?mode=compare¤tfile=$file\">$file</a> ";
|
||||
}
|
||||
}
|
||||
echo '</font></center>';
|
||||
print_simple_box_end();
|
||||
|
||||
|
||||
print_simple_box_start("center", "80%");
|
||||
echo '<center>'.$strfilestoredin.' <strong>';
|
||||
echo $uselocal ? "{$currentlang}_local" : $currentlang;
|
||||
echo '</strong> ';
|
||||
helpbutton('langswitchstorage', $strfilestoredinhelp, 'moodle');
|
||||
|
||||
echo '<form target="'.$CFG->framename.'" method="get" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/lang.php">'.
|
||||
'<input type="hidden" name="mode" value="compare" />'.
|
||||
'<input type="hidden" name="currentfile" value="'.$currentfile.'" />'.
|
||||
'<input type="hidden" name="uselocal" value="'.(1 - $uselocal % 2).'" />'.
|
||||
'<input type="submit" value="'.$strswitchlangdirbtn.'" />'.
|
||||
'</form></center>';
|
||||
print_simple_box_end();
|
||||
|
||||
if ($currentfile <> '') {
|
||||
$saveto = $uselocal ? $locallangdir : $langdir;
|
||||
error_reporting(0);
|
||||
if (!file_exists("$saveto/$currentfile")) {
|
||||
if (!@touch("$saveto/$currentfile")) {
|
||||
print_heading(get_string("filemissing", "", "$saveto/$currentfile"), "center", 4, "error");
|
||||
} else {
|
||||
print_heading($strfilecreated, "center", 4, "notifysuccess");
|
||||
}
|
||||
print_heading("$currentfile", "center", 4);
|
||||
|
||||
if (!file_exists("$langdir/$currentfile")) {
|
||||
if (!touch("$langdir/$currentfile")) {
|
||||
echo "<p><font color=red>".get_string("filemissing", "", "$langdir/$currentfile")."</font></p>";
|
||||
continue;
|
||||
}
|
||||
if ($currentlang == "en_utf8" && !$uselocal) {
|
||||
$editable = false;
|
||||
print_heading($streditennotallowed, 'center', 4);
|
||||
} elseif ($f = fopen("$saveto/$currentfile","r+")) {
|
||||
$editable = true;
|
||||
fclose($f);
|
||||
} else {
|
||||
$editable = false;
|
||||
echo "<p><font size=\"1\">".get_string("makeeditable", "", "$saveto/$currentfile")."</font></p>";
|
||||
}
|
||||
error_reporting($CFG->debug);
|
||||
|
||||
print_heading("$currentfile", "center", 4);
|
||||
if (LANG_DISPLAY_MISSING_LINKS && $editable) {
|
||||
print_heading('<a href="#missing1">'.$strgotofirst.'</a>', "center", 4);
|
||||
}
|
||||
|
||||
unset($string);
|
||||
include("$enlangdir/$currentfile");
|
||||
$enstring = $string;
|
||||
if ($currentlang != 'en' and $currentfile == 'moodle.php') {
|
||||
$enstring['thislanguage'] = "<< TRANSLATORS: Specify the name of your language here. If possible use Unicode Numeric Character References >>";
|
||||
$enstring['thischarset'] = "<< TRANSLATORS: Specify the character set of your language here. Note that all text created while this language is active will be stored using this character set, so don't change it once you have set it. Example: iso-8859-1 >>";
|
||||
$enstring['thisdirection'] = "<< TRANSLATORS: This string specifies the direction of your text, either left-to-right or right-to-left. Insert either 'ltr' or 'rtl' here. >>";
|
||||
$enstring['parentlanguage'] = "<< TRANSLATORS: If your language has a Parent Language that Moodle should use when strings are missing from your language pack, then specify the code for it here. If you leave this blank then English will be used. Example: nl >>";
|
||||
}
|
||||
ksort($enstring);
|
||||
|
||||
unset($string);
|
||||
|
||||
@include("$locallangdir/$currentfile");
|
||||
$localstring = isset($string) ? $string : array();
|
||||
unset($string);
|
||||
|
||||
@include("$langdir/$currentfile");
|
||||
|
||||
if ($editable) {
|
||||
echo "<form name=\"$currentfile\" action=\"lang.php\" method=\"post\">";
|
||||
}
|
||||
echo "<table summary=\"\" width=\"100%\" cellpadding=\"2\" cellspacing=\"3\" border=\"0\" class=\"generalbox\">";
|
||||
$linescounter = 0;
|
||||
$missingcounter = 0;
|
||||
foreach ($enstring as $key => $envalue) {
|
||||
$linescounter++ ;
|
||||
if (LANG_SUBMIT_REPEAT && $editable && $linescounter % LANG_SUBMIT_REPEAT_EVERY == 0) {
|
||||
echo '<tr><td colspan="2"> <td><br />';
|
||||
echo ' <input type="submit" name="update" value="'.get_string('savechanges').': '.$currentfile.'" />';
|
||||
echo '<br /> </td></tr>';
|
||||
}
|
||||
$envalue = nl2br(htmlspecialchars($envalue));
|
||||
$envalue = preg_replace('/(\$a\-\>[a-zA-Z0-9]*|\$a)/', '<b>$0</b>', $envalue); // Make variables bold.
|
||||
$envalue = str_replace("%%","%",$envalue);
|
||||
$envalue = str_replace("\\","",$envalue); // Delete all slashes
|
||||
|
||||
echo "\n\n".'<tr>';
|
||||
echo '<td dir="ltr" lang="en" width="20%" nowrap="nowrap" valign="top">'.$key.'</td>'."\n";
|
||||
echo '<td dir="ltr" lang="en" width="40%" valign="top">'.$envalue.'</td>'."\n";
|
||||
|
||||
// Missing array keys are not bugs here but missing strings
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
if ($uselocal) {
|
||||
$value = lang_fix_value_from_file($localstring[$key]);
|
||||
$value2 = lang_fix_value_from_file($string[$key]);
|
||||
if ($value == '') {
|
||||
$value = $value2;
|
||||
}
|
||||
} else {
|
||||
$value = lang_fix_value_from_file($string[$key]);
|
||||
$value2 = lang_fix_value_from_file($localstring[$key]);
|
||||
}
|
||||
error_reporting($CFG->debug);
|
||||
|
||||
// Color highlighting:
|
||||
// red #ef6868 - translation missing in both system and local pack
|
||||
// yellow #feff7f - translation missing in system pack but is translated in local
|
||||
// green #AAFFAA - translation present in both system and local but is different
|
||||
if (!$value) {
|
||||
if (!$value2) {
|
||||
$cellcolour = 'style="background-color: #ef6868"'; // TODO: replace by CSS class
|
||||
} else {
|
||||
$cellcolour = 'style="background-color: #feff7f"'; // TODO: replace by CSS class
|
||||
}
|
||||
$missingcounter++;
|
||||
if (LANG_DISPLAY_MISSING_LINKS) {
|
||||
$missingtarget = '<a name="missing'.$missingcounter.'"></a>';
|
||||
$missingnext = '<a href="#missing'.($missingcounter+1).'">'.
|
||||
'<img src="' . $CFG->pixpath . '/t/down.gif" height="11" width="11" border="0" alt="" /></a>';
|
||||
$missingprev = '<a href="#missing'.($missingcounter-1).'">'.
|
||||
'<img src="' . $CFG->pixpath . '/t/up.gif" height="11" width="11" border="0" alt="" /></a>';
|
||||
} else {
|
||||
$missingtarget = '';
|
||||
$missingnext = '';
|
||||
$missingprev = '';
|
||||
}
|
||||
} else {
|
||||
if ($value <> $value2 && $value2 <> '') {
|
||||
$cellcolour = 'style="background-color: #AAFFAA"'; // TODO: replace by CSS class
|
||||
} else {
|
||||
$cellcolour = '';
|
||||
}
|
||||
$missingtarget = '';
|
||||
$missingnext = '';
|
||||
$missingprev = '';
|
||||
}
|
||||
|
||||
if ($editable) {
|
||||
echo '<td width="40%" '.$cellcolour.' valign="top">'. $missingprev . $missingtarget."\n";
|
||||
if (isset($string[$key])) {
|
||||
$valuelen = strlen($value);
|
||||
} else {
|
||||
$valuelen = strlen($envalue);
|
||||
}
|
||||
$cols=50;
|
||||
if (strstr($value, "\r") or strstr($value, "\n") or $valuelen > $cols) {
|
||||
$rows = ceil($valuelen / $cols);
|
||||
echo '<textarea name="stringXXX'.lang_form_string_key($key).'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>'."\n";
|
||||
} else {
|
||||
if ($valuelen) {
|
||||
$cols = $valuelen + 5;
|
||||
}
|
||||
echo '<input type="text" name="stringXXX'.lang_form_string_key($key).'" value="'.$value.'" size="'.$cols.'" />';
|
||||
}
|
||||
if ($value2 <> '' && $value <> $value2) {
|
||||
echo '<br /><span style="font-size:small">'.$value2.'</span>';
|
||||
}
|
||||
echo $missingnext . '</td>';
|
||||
|
||||
} else {
|
||||
echo '<td width="40%" bgcolor="'.$cellcolour.'" valign="top">'.$value.'</td>';
|
||||
}
|
||||
}
|
||||
if ($editable) {
|
||||
echo '<tr><td colspan="2"> <td><br />';
|
||||
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
||||
echo ' <input type="hidden" name="currentfile" value="'.$currentfile.'" />';
|
||||
echo ' <input type="hidden" name="mode" value="compare" />';
|
||||
echo ' <input type="submit" name="update" value="'.get_string('savechanges').': '.$currentfile.'" />';
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
echo '</form>';
|
||||
|
||||
} else {
|
||||
// no $currentfile specified
|
||||
print_heading($strchoosefiletoedit, "center", 4);
|
||||
}
|
||||
|
||||
error_reporting(0);
|
||||
if ($f = fopen("$langdir/$currentfile","r+")) {
|
||||
$editable = true;
|
||||
fclose($f);
|
||||
} else {
|
||||
$editable = false;
|
||||
echo "<p><font size=1>".get_string("makeeditable", "", "$langdir/$currentfile")."</font></p>";
|
||||
}
|
||||
error_reporting(7);
|
||||
|
||||
|
||||
unset($string);
|
||||
include("$enlangdir/$currentfile");
|
||||
$enstring = $string;
|
||||
ksort($enstring);
|
||||
|
||||
unset($string);
|
||||
include("$langdir/$currentfile");
|
||||
|
||||
if ($editable) {
|
||||
echo "<form name=\"$currentfile\" action=\"lang.php\" method=\"post\">";
|
||||
}
|
||||
echo "<table width=\"100%\" cellpadding=2 cellspacing=3 border=0>";
|
||||
foreach ($enstring as $key => $envalue) {
|
||||
$envalue = nl2br(htmlspecialchars($envalue));
|
||||
$envalue = preg_replace('/(\$a\-\>[a-zA-Z0-9]*|\$a)/', '<b>$0</b>', $envalue); // Make variables bold.
|
||||
$envalue = str_replace("%%","%",$envalue);
|
||||
$envalue = str_replace("\\","",$envalue); // Delete all slashes
|
||||
|
||||
echo "\n\n<tr>";
|
||||
echo "<td dir=ltr lang=en width=20% bgcolor=\"$THEME->cellheading\" nowrap valign=top>$key</td>\n";
|
||||
echo "<td dir=ltr lang=en width=40% bgcolor=\"$THEME->cellheading\" valign=top>$envalue</td>\n";
|
||||
|
||||
$value = $string[$key];
|
||||
$value = str_replace("\r","",$value); // Bad character caused by Windows
|
||||
$value = preg_replace("/\n{3,}/", "\n\n", $value); // Collapse runs of blank lines
|
||||
$value = trim($value, "\n"); // Delete leading/trailing lines
|
||||
$value = str_replace("\\","",$value); // Delete all slashes
|
||||
$value = str_replace("%%","%",$value);
|
||||
$value = str_replace("<","<",$value);
|
||||
$value = str_replace(">",">",$value);
|
||||
$value = str_replace('"',""",$value);
|
||||
|
||||
$cellcolour = $value ? $THEME->cellcontent: $THEME->highlight;
|
||||
|
||||
if ($editable) {
|
||||
echo "<td width=40% bgcolor=\"$cellcolour\" valign=top>\n";
|
||||
if (isset($string[$key])) {
|
||||
$valuelen = strlen($value);
|
||||
} else {
|
||||
$valuelen = strlen($envalue);
|
||||
}
|
||||
$cols=50;
|
||||
if (strstr($value, "\r") or strstr($value, "\n") or $valuelen > $cols) {
|
||||
$rows = ceil($valuelen / $cols);
|
||||
echo "<textarea name=\"string-$key\" cols=\"$cols\" rows=\"$rows\">$value</textarea>\n";
|
||||
} else {
|
||||
if ($valuelen) {
|
||||
$cols = $valuelen + 2;
|
||||
}
|
||||
echo "<input type=\"text\" name=\"string-$key\" value=\"$value\" size=\"$cols\"></td>";
|
||||
}
|
||||
echo "</TD>\n";
|
||||
|
||||
} else {
|
||||
echo "<td width=40% bgcolor=\"$cellcolour\" valign=top>$value</td>\n";
|
||||
}
|
||||
}
|
||||
if ($editable) {
|
||||
echo "<tr><td colspan=2> <td><br />";
|
||||
echo " <input type=\"hidden\" name=\"currentfile\" value=\"$currentfile\">";
|
||||
echo " <input type=\"hidden\" name=\"mode\" value=\"compare\">";
|
||||
echo " <input type=\"submit\" name=\"update\" value=\"".get_string("savechanges").": $currentfile\">";
|
||||
echo "</td></tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
echo "</form>";
|
||||
|
||||
}
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_footer();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Save language translation file.
|
||||
*
|
||||
* Thanks to Petri Asikainen for the original version of code
|
||||
* used to save language files.
|
||||
*
|
||||
* @uses $CFG
|
||||
* @uses $USER
|
||||
* @param string $path Full pathname to the directory to use
|
||||
* @param string $file File to overwrite
|
||||
* @param array $strings Array of strings to write
|
||||
* @param bool $local Should *_local version be saved?
|
||||
* @param array $packstrings Array of default langpack strings (needed if $local)
|
||||
* @return bool Created successfully?
|
||||
*/
|
||||
function lang_save_file($path, $file, $strings, $local, $packstrings) {
|
||||
function lang_save_file($path, $file, $strings) {
|
||||
// Thanks to Petri Asikainen for the original version of code
|
||||
// used to save language files.
|
||||
//
|
||||
// $path is a full pathname to the file
|
||||
// $file is the file to overwrite.
|
||||
// $strings is an array of strings to write
|
||||
|
||||
global $CFG, $USER;
|
||||
if (!$f = @fopen("$path/$file","w")) {
|
||||
|
||||
error_reporting(0);
|
||||
if (!$f = fopen("$path/$file","w")) {
|
||||
return false;
|
||||
}
|
||||
error_reporting(7);
|
||||
|
||||
|
||||
fwrite($f, "<?PHP // \$Id\$ \n");
|
||||
fwrite($f, " // $file - created with Moodle $CFG->release ($CFG->version)\n");
|
||||
if ($local) {
|
||||
fwrite($f, " // local modifications from $CFG->wwwroot\n");
|
||||
}
|
||||
fwrite($f, "\n\n");
|
||||
fwrite($f, " // $file - created with Moodle $CFG->release ($CFG->version)\n\n\n");
|
||||
|
||||
ksort($strings);
|
||||
|
||||
foreach ($strings as $key => $value) {
|
||||
@list($id, $stringname) = explode('XXX',$key);
|
||||
list($id, $stringname) = explode("-",$key);
|
||||
if ($CFG->lang != "zh_hk" and $CFG->lang != "zh_tw") { // Some MB languages include backslash bytes
|
||||
$value = str_replace("\\","",$value); // Delete all slashes
|
||||
}
|
||||
@@ -551,67 +291,14 @@ function lang_save_file($path, $file, $strings, $local, $packstrings) {
|
||||
$value = str_replace('"', "\\\"", $value); // Add slashes for "
|
||||
$value = str_replace("%","%%",$value); // Escape % characters
|
||||
$value = str_replace("\r", "",$value); // Remove linefeed characters
|
||||
$value = trim($value); // Delete leading/trailing white space
|
||||
if ($id == "string" and $value != ""){
|
||||
if ((!$local) || (lang_fix_value_from_file($packstrings[$stringname]) <> lang_fix_value_from_file($value))) {
|
||||
fwrite($f,"\$string['$stringname'] = '$value';\n");
|
||||
}
|
||||
fwrite($f,"\$string['$stringname'] = '$value';\n");
|
||||
}
|
||||
}
|
||||
fwrite($f,"\n?>\n");
|
||||
fclose($f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix value of string to translate.
|
||||
*
|
||||
* @param string $value Original string from the file
|
||||
* @return string Fixed value
|
||||
*/
|
||||
function lang_fix_value_from_file($value='') {
|
||||
$value = str_replace("\r","",$value); // Bad character caused by Windows
|
||||
$value = preg_replace("/\n{3,}/", "\n\n", $value); // Collapse runs of blank lines
|
||||
$value = trim($value); // Delete leading/trailing white space
|
||||
$value = str_replace("\\","",$value); // Delete all slashes
|
||||
$value = str_replace("%%","%",$value);
|
||||
$value = str_replace("<","<",$value);
|
||||
$value = str_replace(">",">",$value);
|
||||
$value = str_replace('"',""",$value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try and create a new language directory.
|
||||
*
|
||||
* @uses $CFG
|
||||
* @param string $directory full path to the directory under $langbase
|
||||
* @return string|false Returns full path to directory if successful, false if not
|
||||
*/
|
||||
function lang_make_directory($dir, $shownotices=true) {
|
||||
global $CFG;
|
||||
umask(0000);
|
||||
if (! file_exists($dir)) {
|
||||
if (! @mkdir($dir, $CFG->directorypermissions)) {
|
||||
return false;
|
||||
}
|
||||
//@chmod($dir, $CFG->directorypermissions); // Just in case mkdir didn't do it
|
||||
}
|
||||
return $dir;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Following functions are required because '.' in form input names
|
||||
/// get replaced by '_' by PHP.
|
||||
|
||||
function lang_form_string_key($keyfromfile) {
|
||||
return str_replace('.', '##46#', $keyfromfile); /// Derived from ., the ascii value for a period.
|
||||
}
|
||||
|
||||
function lang_file_string_key($keyfromform) {
|
||||
return str_replace('##46#', '.', $keyfromform);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,257 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
/**
|
||||
* This script enables Moodle translators to edit /docs and /help language
|
||||
* files directly via WWW interface.
|
||||
*
|
||||
* Author: mudrd8mz@uxit.pedf.cuni.cz (http://moodle.cz)
|
||||
* Based on: lang.php in 1.4.3+ release
|
||||
* Thanks: Jaime Villate for important bug fixing, koen roggemans for his job and all moodlers
|
||||
* for intensive testing of this my first contribution
|
||||
*/
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('langedit', $adminroot);
|
||||
|
||||
//
|
||||
// Some local configuration
|
||||
//
|
||||
$fileeditorrows = 12; // number of textareas' rows
|
||||
$fileeditorcols = 100; // dtto cols
|
||||
$fileeditorinline = 1; // shall be textareas put in one row?
|
||||
$filemissingmark = ' (***)'; // mark to add to non-existing filenames in selection form
|
||||
$fileoldmark = ' (old?)'; // mark to add to filenames in selection form id english version is newer
|
||||
// or to filenames with filesize() == 0
|
||||
$filetemplate = ''; // template for new files, i.e. '$Id$';
|
||||
|
||||
$currentfile = optional_param('currentfile', 'docs/README.txt', PARAM_PATH);
|
||||
|
||||
$strlanguage = get_string("language");
|
||||
$strcurrentlanguage = get_string("currentlanguage");
|
||||
$strthislanguage = get_string("thislanguage");
|
||||
$stredithelpdocs = get_string('edithelpdocs', 'admin');
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
$currentlang = current_language();
|
||||
$langdir = "$CFG->dataroot/lang/$currentlang";
|
||||
$enlangdir = "$CFG->dirroot/lang/en_utf8";
|
||||
|
||||
|
||||
if (!file_exists($langdir)) {
|
||||
error ('to edit this language pack, you need to put it in '.$CFG->dataroot.'/lang');
|
||||
}
|
||||
// Shall I save POSTed data?
|
||||
|
||||
if (isset($_POST['currentfile'])) {
|
||||
if (confirm_sesskey()) {
|
||||
if (langdoc_save_file($langdir, $currentfile, $_POST['filedata'])) {
|
||||
notify(get_string("changessaved")." ($langdir/$currentfile)", "green");
|
||||
} else {
|
||||
error("Could not save the file '$currentfile'!", "langdoc.php?currentfile=$currentfile&sesskey=$USER->sesskey");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error_reporting(0); // Error reporting turned off due to non-existing files
|
||||
|
||||
// Generate selection for all help and documentation files
|
||||
|
||||
// Get all files from /docs directory
|
||||
|
||||
if (! $files = get_directory_list("$CFG->dirroot/lang/en_utf8/docs", "CVS")) {
|
||||
error("Could not find English language docs files!");
|
||||
}
|
||||
|
||||
$options = array();
|
||||
|
||||
foreach ($files as $filekey => $file) { // check all the docs files.
|
||||
$options["docs/$file"] = "docs/$file";
|
||||
// add mark if file doesn't exist or is empty
|
||||
if (( !file_exists("$langdir/docs/$file")) || (filesize("$langdir/docs/$file") == 0)) {
|
||||
$options["docs/$file"] .= "$filemissingmark";
|
||||
} else {
|
||||
if (filemtime("$langdir/docs/$file") < filemtime("$CFG->dirroot/lang/en_utf8/docs/$file")) {
|
||||
$options["docs/$file"] .= "$fileoldmark";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get all files from /help directory
|
||||
|
||||
if (! $files = get_directory_list("$CFG->dirroot/lang/en_utf8/help", "CVS")) {
|
||||
error("Could not find English language help files!");
|
||||
}
|
||||
|
||||
foreach ($files as $filekey => $file) { // check all the help files.
|
||||
$options["help/$file"] = "help/$file";
|
||||
if (( !file_exists("$langdir/help/$file")) || (filesize("$CFG->dirroot/lang/en_utf8/help/$file") == 0)) {
|
||||
$options["help/$file"] .= "$filemissingmark";
|
||||
} else {
|
||||
if (filemtime("$langdir/help/$file") < filemtime("$langdir/help/$file")) {
|
||||
$options["help/$file"] .= "$fileoldmark";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "<table align=\"center\"><tr><td align=\"center\">";
|
||||
echo popup_form ("$CFG->wwwroot/$CFG->admin/langdoc.php?sesskey=$USER->sesskey&currentfile=", $options, "choosefile", $currentfile, "", "", "", true);
|
||||
echo "</td></tr></table>";
|
||||
|
||||
// Generate textareas
|
||||
|
||||
if (!empty($currentfile)) {
|
||||
|
||||
if (!file_exists("$langdir/$currentfile")) {
|
||||
//check if directory exist
|
||||
$pathparts = explode('/',$currentfile);
|
||||
$checkpath = $langdir;
|
||||
for ($a=0; $a < count($pathparts)-1 ; $a++) {
|
||||
$checkpath .= "/".$pathparts[$a];
|
||||
if(!file_exists($checkpath)){
|
||||
if(!mkdir($checkpath)){
|
||||
echo ("Cannot create directory: $checkpath");
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// file doesn't exist - let's check webserver's permission to create it
|
||||
//
|
||||
if (!touch("$langdir/$currentfile")) {
|
||||
//
|
||||
// webserver is unable to create new file
|
||||
//
|
||||
echo "<p align=\"center\"><font color=red>".get_string("filemissing", "", "
|
||||
$langdir/$currentfile")."</font></p>";
|
||||
$editable = false;
|
||||
} else {
|
||||
//
|
||||
// webserver can create new file - we can delete it now and let
|
||||
// the langdoc_save_file() create it again if its filesize() > 0
|
||||
//
|
||||
$editable = true;
|
||||
unlink("$langdir/$currentfile");
|
||||
}
|
||||
} elseif ($f = fopen("$langdir/$currentfile","r+")) {
|
||||
//
|
||||
// file exists and is writeable - good for you, translator ;-)
|
||||
//
|
||||
$editable = true;
|
||||
fclose($f);
|
||||
} else {
|
||||
//
|
||||
// file exists but it is not writeable by web server process :-(
|
||||
//
|
||||
$editable = false;
|
||||
echo "<p><font size=1>".get_string("makeeditable", "", "$langdir/$currentfile")
|
||||
."</font></p>";
|
||||
}
|
||||
|
||||
//en_utf8 in dataroot is not editable
|
||||
if ($currentlang == 'en_utf8') {
|
||||
$editable = false;
|
||||
}
|
||||
|
||||
echo "<table align=\"center\"><tr valign=\"center\"><td align=\"center\">\n";
|
||||
echo "<textarea rows=\"$fileeditorrows\" cols=\"$fileeditorcols\" name=\"\">\n";
|
||||
echo htmlspecialchars(file_get_contents("$enlangdir/$currentfile"));
|
||||
echo "</textarea>\n";
|
||||
//link_to_popup_window("/lang/en_utf8/$currentfile", "popup", get_string("preview"));
|
||||
$preview_url = langdoc_preview_url($currentfile);
|
||||
if ($preview_url) {
|
||||
link_to_popup_window($preview_url.'&forcelang=en_utf8', 'popup', get_string('preview'));
|
||||
}
|
||||
echo "</td>\n";
|
||||
if ($fileeditorinline == 1) {
|
||||
echo "</tr>\n<tr valign=\"center\">\n";
|
||||
}
|
||||
echo "<td align=\"center\">\n";
|
||||
|
||||
if ($editable) {
|
||||
echo "<form name=\"$currentfile\" action=\"langdoc.php\" method=\"post\">";
|
||||
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
|
||||
echo '<input type="hidden" name="currentfile" value="'.$currentfile.'" />';
|
||||
|
||||
echo "<textarea rows=\"$fileeditorrows\" cols=\"$fileeditorcols\" name=\"filedata\">\n";
|
||||
if (file_exists("$langdir/$currentfile")) {
|
||||
echo htmlspecialchars(file_get_contents("$langdir/$currentfile"));
|
||||
} else {
|
||||
echo ($filetemplate);
|
||||
}
|
||||
echo "</textarea>\n";
|
||||
$preview_url = langdoc_preview_url($currentfile);
|
||||
if ($preview_url) {
|
||||
link_to_popup_window($preview_url, 'popup', get_string('preview'));
|
||||
}
|
||||
echo '<div align="center"><input type="submit" value="'.get_string('savechanges').': lang/'.$currentlang.'/'.$currentfile.'" /></div>';
|
||||
echo '</form>';
|
||||
}
|
||||
|
||||
echo "</td>\n</tr>\n</table>";
|
||||
|
||||
|
||||
error_reporting($CFG->debug);
|
||||
}
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
function langdoc_save_file($path, $file, $content) {
|
||||
|
||||
// $path is a full pathname to the file
|
||||
// $file is the file to overwrite.
|
||||
// $content are data to write
|
||||
|
||||
global $CFG, $USER;
|
||||
|
||||
error_reporting(0);
|
||||
|
||||
if (!$f = fopen("$path/$file","w")) {
|
||||
error_reporting($CFG->debug);
|
||||
return false;
|
||||
}
|
||||
|
||||
error_reporting($CFG->debug);
|
||||
|
||||
$content = str_replace("\r", "",$content); // Remove linefeed characters
|
||||
$content = preg_replace("/\n{3,}/", "\n\n", $content); // Collapse runs of blank lines
|
||||
$content = trim($content); // Delete leading/trailing whitespace
|
||||
|
||||
fwrite($f, stripslashes($content));
|
||||
|
||||
fclose($f);
|
||||
|
||||
// Remove file if its empty
|
||||
|
||||
if (filesize("$path/$file") == 0) {
|
||||
unlink("$path/$file");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a preview URL for the file, if available.
|
||||
*
|
||||
* Documentation will be moved into moodle.org wiki and current version 1.6 does not
|
||||
* seem to be able to display local documentation. Thus, return empty URL for doc files.
|
||||
* See lib/moodlelib.php document_file() - it still relies on old pre-UTF8 lang/ location.
|
||||
*/
|
||||
function langdoc_preview_url($currentfile) {
|
||||
if (substr($currentfile, 0, 5) == 'help/') {
|
||||
$currentfile = substr($currentfile, 5);
|
||||
$currentpathexp = explode('/', $currentfile);
|
||||
if (count($currentpathexp) > 1) {
|
||||
$url = '/help.php?module='.$currentpathexp[0].'&file='.$currentpathexp[1];
|
||||
} else {
|
||||
$url = '/help.php?module=moodle&file='.$currentfile;
|
||||
}
|
||||
} else {
|
||||
$url = '';
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,412 +0,0 @@
|
||||
<?php //$Id$
|
||||
///This file only manages the installation of 1.6 lang packs.
|
||||
///in downloads.moodle.org, they are store in separate directory /lang16
|
||||
///in local server, they are stored in $CFG->dataroot/lang
|
||||
///This helps to avoid confusion.
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('langimport', $adminroot);
|
||||
|
||||
$mode = optional_param('mode', 0, PARAM_INT); //phase
|
||||
$pack = optional_param('pack', '', PARAM_FILE); //pack to install
|
||||
$displaylang = $pack;
|
||||
$uninstalllang = optional_param('uninstalllang', '', PARAM_FILE);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
$sitelang = optional_param('sitelangconfig', '', PARAM_FILE);
|
||||
|
||||
define('INSTALLATION_OF_SELECTED_LANG', 2);
|
||||
define('CHANGE_SITE_LANG', 3);
|
||||
define('DELETION_OF_SELECTED_LANG', 4);
|
||||
define('UPDATE_ALL_LANG', 5);
|
||||
|
||||
$strlang = get_string('langimport','admin');
|
||||
|
||||
$strlanguage = get_string("language");
|
||||
$strthislanguage = get_string("thislanguage");
|
||||
$title = $strlang;
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
|
||||
switch ($mode){
|
||||
|
||||
case INSTALLATION_OF_SELECTED_LANG: ///installation of selected language pack
|
||||
|
||||
if (confirm_sesskey()) {
|
||||
@mkdir ($CFG->dataroot.'/temp/'); //make it in case it's a fresh install, it might not be there
|
||||
@mkdir ($CFG->dataroot.'/lang/');
|
||||
|
||||
require_once($CFG->libdir.'/componentlib.class.php');
|
||||
if ($cd = new component_installer('http://download.moodle.org', 'lang16',
|
||||
$pack.'.zip', 'languages.md5', 'lang')) {
|
||||
$status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
|
||||
switch ($status) {
|
||||
|
||||
case ERROR:
|
||||
if ($cd->get_error() == 'remotedownloadnotallowed') {
|
||||
$a = new stdClass();
|
||||
$a->url = 'http://download.moodle.org/lang16/'.$pack.'zip';
|
||||
$a->dest= $CFG->dataroot.'/lang';
|
||||
error(get_string($cd->get_error(), 'error', $a));
|
||||
} else {
|
||||
error(get_string($cd->get_error(), 'error'));
|
||||
}
|
||||
break;
|
||||
|
||||
case INSTALLED:
|
||||
@unlink($CFG->dataroot.'/cache/languages');
|
||||
redirect('langimport.php', get_string('langpackupdated','admin',$pack));
|
||||
break;
|
||||
|
||||
case UPTODATE:
|
||||
break;
|
||||
|
||||
}
|
||||
} else {
|
||||
notify('Had an unspecified error with the component installer, sorry.');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CHANGE_SITE_LANG: //change site language
|
||||
|
||||
if (confirm_sesskey()) {
|
||||
$langconfig = get_record('config','name','lang');
|
||||
$langconfig->value = $sitelang;
|
||||
if (!empty($sitelang) && update_record('config',$langconfig)){
|
||||
redirect('langimport.php', get_string('sitelangchanged','admin'));
|
||||
} else {
|
||||
error('Could not update the default site language!');
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case DELETION_OF_SELECTED_LANG: //delete a directory(ies) containing a lang pack completely
|
||||
|
||||
if (!$confirm && confirm_sesskey()) {
|
||||
notice_yesno(get_string('uninstallconfirm', 'admin', $uninstalllang),
|
||||
'langimport.php?mode=4&uninstalllang='.$uninstalllang.'&confirm=1&sesskey='.sesskey(),
|
||||
'langimport.php');
|
||||
} else if (confirm_sesskey()) {
|
||||
if ($uninstalllang == 'en_utf8') {
|
||||
error ('en_utf8 can not be uninstalled!');
|
||||
}
|
||||
$dest1 = $CFG->dataroot.'/lang/'.$uninstalllang;
|
||||
$dest2 = $CFG->dirroot.'/lang/'.$uninstalllang;
|
||||
$rm1 = false;
|
||||
$rm2 = false;
|
||||
if (file_exists($dest1)){
|
||||
$rm1 = remove_dir($dest1);
|
||||
}
|
||||
if (file_exists($dest2)){
|
||||
$rm2 = remove_dir($dest2);
|
||||
}
|
||||
//delete the direcotries
|
||||
if ($rm1 or $rm2) {
|
||||
redirect('langimport.php', get_string('langpackremoved','admin'));
|
||||
} else { //nothing deleted, possibly due to permission error
|
||||
error('An error has occurred, language pack is not completely uninstalled, please check file permissions');
|
||||
}
|
||||
}
|
||||
@unlink($CFG->dataroot.'/cache/languages');
|
||||
break;
|
||||
|
||||
case UPDATE_ALL_LANG: //1 click update for all updatable language packs
|
||||
|
||||
//0th pull a list from download.moodle.org,
|
||||
//key = langname, value = md5
|
||||
$source = 'http://download.moodle.org/lang16/languages.md5';
|
||||
$md5array = array();
|
||||
$updated = 0; //any packs updated?
|
||||
unset($CFG->langlist); // ignore admin's langlist
|
||||
$alllangs = array_keys(get_list_of_languages());
|
||||
$lang16 = array(); //all the Moodle 1.6 unicode lang packs (updated and not updated)
|
||||
$packs = array(); //all the packs that needs updating
|
||||
|
||||
|
||||
if (!$availablelangs = proxy_url($source)) {
|
||||
error ('can not read from course');
|
||||
}
|
||||
|
||||
//and build an associative array
|
||||
foreach ($availablelangs as $alang) {
|
||||
$md5array[$alang[0]] = $alang[1];
|
||||
}
|
||||
|
||||
//filtering out non-16 packs
|
||||
foreach ($alllangs as $clang) {
|
||||
$dest1 = $CFG->dataroot.'/lang/'.$clang;
|
||||
$dest2 = $CFG->dirroot.'/lang/'.$clang;
|
||||
|
||||
if (file_exists($dest1.'/langconfig.php') || file_exists($dest2.'/langconfig.php')){
|
||||
$lang16[] = $clang;
|
||||
}
|
||||
}
|
||||
|
||||
//then filter out packs that have the same md5 key
|
||||
foreach ($lang16 as $clang) {
|
||||
if (!is_installed_lang($clang, $md5array[$clang])){
|
||||
$packs[] = $clang;
|
||||
}
|
||||
}
|
||||
|
||||
@mkdir ($CFG->dataroot.'/temp/');
|
||||
@mkdir ($CFG->dataroot.'/lang/');
|
||||
foreach ($packs as $pack){ //for each of the remaining in the list, we
|
||||
if ($pack == 'en_utf8') { // no update for en_utf8
|
||||
continue;
|
||||
}
|
||||
//1. delete old director(ies)
|
||||
|
||||
$dest1 = $CFG->dataroot.'/lang/'.$pack;
|
||||
$dest2 = $CFG->dirroot.'/lang/'.$pack;
|
||||
$rm1 = false;
|
||||
$rm2 = false;
|
||||
if (file_exists($dest1)) {
|
||||
$rm1 = remove_dir($dest1);
|
||||
}
|
||||
if (file_exists($dest2)) {
|
||||
$rm2 = remove_dir($dest2);
|
||||
}
|
||||
if (!($rm1 || $rm2)) {
|
||||
error ('could not delete old directory, update failed');
|
||||
}
|
||||
|
||||
//2. copy & unzip into new
|
||||
|
||||
require_once($CFG->libdir.'/componentlib.class.php');
|
||||
if ($cd = new component_installer('http://download.moodle.org', 'lang16',
|
||||
$pack.'.zip', 'languages.md5', 'lang')) {
|
||||
$status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
|
||||
switch ($status) {
|
||||
|
||||
case ERROR:
|
||||
if ($cd->get_error() == 'remotedownloadnotallowed') {
|
||||
$a = new stdClass();
|
||||
$a->url = 'http://download.moodle.org/lang16/'.$pack.'zip';
|
||||
$a->dest= $CFG->dataroot.'/lang';
|
||||
error(get_string($cd->get_error(), 'error', $a));
|
||||
} else {
|
||||
error(get_string($cd->get_error(), 'error'));
|
||||
}
|
||||
break;
|
||||
case UPTODATE:
|
||||
//Print error string or whatever you want to do
|
||||
break;
|
||||
case INSTALLED:
|
||||
notify(get_string('langpackupdated','admin',$pack), 'notifysuccess');
|
||||
$updated = true;
|
||||
//Print/do whatever you want
|
||||
break;
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($updated) {
|
||||
notice(get_string('langupdatecomplete','admin'), 'langimport.php');
|
||||
} else {
|
||||
notice(get_string('nolangupdateneeded','admin'), 'langimport.php');
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default: //display choice mode
|
||||
|
||||
$source = 'http://download.moodle.org/lang16/languages.md5';
|
||||
$remote = 0; //flag for reading from remote or local
|
||||
|
||||
if ($availablelangs = proxy_url($source)) {
|
||||
$remote = 1;
|
||||
} else {
|
||||
$availablelangs = get_local_list_of_languages();
|
||||
}
|
||||
/*
|
||||
if ($fp = fopen($source, 'r')){ /// attempt to get the list from Moodle.org.
|
||||
while(!feof ($fp)) {
|
||||
$availablelangs[] = split(',', fgets($fp,1024));
|
||||
}
|
||||
$remote = 1; //can read from download.moodle.org
|
||||
} else { /// fopen failed, we find local copy of list.
|
||||
$availablelangs = get_local_list_of_languages();
|
||||
}
|
||||
*/
|
||||
if (!$remote) {
|
||||
print_simple_box_start('center','60%');
|
||||
echo '<div align="center">';
|
||||
print_string('remotelangnotavailable','admin',$CFG->dataroot.'/lang/');
|
||||
echo '</div>';
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
print_simple_box_start('center','60%');
|
||||
echo '<table width="100%"><tr><td align="center">';
|
||||
echo get_string('installedlangs','admin');
|
||||
echo '</td><td align="center">';
|
||||
echo get_string('availablelangs','admin');
|
||||
echo '</td></tr>';
|
||||
echo '<tr><td align="center" valign="top">';
|
||||
echo '<form name="uninstallform" action="langimport.php?mode=4" method="POST">';
|
||||
echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
|
||||
unset($CFG->langlist); // ignore admin's langlist
|
||||
$installedlangs = get_list_of_languages();
|
||||
|
||||
/// display installed langs here
|
||||
|
||||
echo '<select name="uninstalllang" size="15">';
|
||||
foreach ($installedlangs as $clang =>$ilang){
|
||||
echo '<option value="'.$clang.'">'.$ilang.'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<br /><input type="submit" value="'.get_string('uninstall','admin').'" />';
|
||||
echo '</form>';
|
||||
echo '<form name="updateform" action="langimport.php?mode=5" method="POST">';
|
||||
echo '<br /><input type="submit" value="'.get_string('updatelangs','admin').'" />';
|
||||
echo '</form>';
|
||||
echo '<p />';
|
||||
|
||||
/// Display option to change site language
|
||||
|
||||
/// Erm... this doesn't seem to work. Plus it's redundant. -vinkmar
|
||||
|
||||
// print_string('changesitelang','admin');
|
||||
// $sitelanguage = get_record('config','name','lang');
|
||||
// echo '<form name="changelangform" action="langimport.php?mode=3" method="POST">';
|
||||
// echo '<select name="sitelangconfig">';
|
||||
//
|
||||
// foreach ($installedlangs as $clang =>$ilang) {
|
||||
// if ($clang == $sitelanguage->value){
|
||||
// echo '<option value="'.$clang.'" selected="selected">'.$ilang.'</option>';
|
||||
// } else {
|
||||
// echo '<option value="'.$clang.'">'.$ilang.'</option>';
|
||||
// }
|
||||
// }
|
||||
// echo '</select>';
|
||||
// echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
// echo '<input type="submit" value="'.get_string('change','admin').'" />';
|
||||
// echo '</form>';
|
||||
|
||||
/// display to be installed langs here
|
||||
|
||||
echo '</td><td align="center" valign="top">';
|
||||
echo '<table><tr><td valign="top" align="center">'; //availabe langs table
|
||||
$empty = 1; //something to pring
|
||||
|
||||
/// if this language pack is not already installed, then we allow installation
|
||||
|
||||
echo '<form name="installform" method="POST" action="langimport.php?mode=2">';
|
||||
echo '<input name="sesskey" type="hidden" value="'.sesskey().'" />';
|
||||
if ($remote) {
|
||||
echo '<select name="pack" size="15">';
|
||||
}
|
||||
|
||||
foreach ($availablelangs as $alang) {
|
||||
if (trim($alang[0]) != "en_utf8") {
|
||||
if ($remote){
|
||||
if (substr($alang[0], -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
|
||||
$shortlang = substr($alang[0], 0, -5);
|
||||
} else {
|
||||
$shortlang = $alang[0];
|
||||
}
|
||||
if (!is_installed_lang($alang[0], $alang[1])){ //if not already installed
|
||||
echo '<option value="'.$alang[0].'">'.$alang[2].' ('.$shortlang.')</option>';
|
||||
}
|
||||
} else { //print list in local format, and instruction to install
|
||||
echo '<tr><td>'.$alang[2].'</td><td><a href="http://download.moodle.org/lang16/'.$alang[0].'.zip">'.get_string('download','admin').'</a>';
|
||||
}
|
||||
$empty = 0;
|
||||
}
|
||||
}
|
||||
if ($remote) {
|
||||
echo '</select>';
|
||||
echo '<br/ ><input type="submit" value="<-- '.get_string('install','admin').'">';
|
||||
}
|
||||
echo '</form>';
|
||||
|
||||
if ($empty) {
|
||||
echo '<tr><td align="center">';
|
||||
print_string('nolanguagetodownload','admin');
|
||||
echo '</td></tr>';
|
||||
}
|
||||
|
||||
echo '</td><tr></table>'; //close available langs table
|
||||
echo '<form>';
|
||||
echo '</td></tr></table>';
|
||||
print_simple_box_end();
|
||||
|
||||
break;
|
||||
|
||||
} //close of main switch
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
/* returns a list of available language packs from a
|
||||
* local copy shipped with standard moodle distro
|
||||
* this is for site that can't perform fopen
|
||||
* @return array
|
||||
*/
|
||||
function get_local_list_of_languages() {
|
||||
global $CFG;
|
||||
$source = $CFG->wwwroot.'/lib/languages.md5';
|
||||
$availablelangs = array();
|
||||
if ($fp = fopen($source, 'r')){
|
||||
while(!feof ($fp)) {
|
||||
$availablelangs[] = split(',', fgets($fp,1024));
|
||||
}
|
||||
}
|
||||
return $availablelangs;
|
||||
}
|
||||
|
||||
/* checks the md5 of the zip file, grabbed from download.moodle.org,
|
||||
* against the md5 of the local language file from last update
|
||||
* @param string $lang
|
||||
* @param string $md5check
|
||||
* @return bool
|
||||
*/
|
||||
function is_installed_lang($lang, $md5check) {
|
||||
global $CFG;
|
||||
$md5file = $CFG->dataroot.'/lang/'.$lang.'/'.$lang.'.md5';
|
||||
if (file_exists($md5file)){
|
||||
return (file_get_contents($md5file) == $md5check);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//returns an array of languages, or false if can not read from source
|
||||
//uses a socket if proxy is set as a config variable
|
||||
function proxy_url($url) {
|
||||
global $CFG;
|
||||
|
||||
if ($CFG->proxyhost && $CFG->proxyport) {
|
||||
|
||||
$proxy_fp = fsockopen($CFG->proxyhost, $CFG->proxyport);
|
||||
if (!$proxy_fp) {
|
||||
return false; //failed
|
||||
}
|
||||
fputs($proxy_fp, "GET $url HTTP/1.0\r\nHost: $CFG->proxyhost\r\n\r\n");
|
||||
$i = 0;
|
||||
while(!feof($proxy_fp)) {
|
||||
$string = fgets($proxy_fp, 1024);
|
||||
if ($i > 11) { //12 lines of info skipped
|
||||
$availablelangs[] = split(',', $string);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
fclose($proxy_fp);
|
||||
|
||||
} else { //proxy not in use
|
||||
if ($fp = fopen($url, 'r')){ /// attempt to get the list from Moodle.org.
|
||||
while(!feof ($fp)) {
|
||||
$availablelangs[] = split(',', fgets($fp,1024));
|
||||
}
|
||||
} else { /// fopen failed, return false.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $availablelangs;
|
||||
}
|
||||
?>
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php // $Id$
|
||||
// Enables/disables maintenance mode
|
||||
|
||||
require('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('maintenancemode', $adminroot);
|
||||
|
||||
//Check folder exists
|
||||
if (! make_upload_directory(SITEID)) { // Site folder
|
||||
error("Could not create site folder. The site administrator needs to fix the file permissions");
|
||||
}
|
||||
|
||||
$filename = $CFG->dataroot.'/'.SITEID.'/maintenance.html';
|
||||
|
||||
if ($form = data_submitted()) {
|
||||
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));
|
||||
fclose($file);
|
||||
redirect('maintenance.php', get_string('sitemaintenanceon', 'admin'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Print the header stuff
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
/// Print the appropriate form
|
||||
|
||||
if (file_exists($filename)) { // We are in maintenance mode
|
||||
echo '<center>';
|
||||
echo '<form action="maintenance.php" method="post">';
|
||||
echo '<input type="hidden" name="action" value="disable">';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'">';
|
||||
echo '<p><input type="submit" value="'.get_string('disable').'"></p>';
|
||||
echo '</form>';
|
||||
echo '</center>';
|
||||
} else { // We are not in maintenance mode
|
||||
$usehtmleditor = can_use_html_editor();
|
||||
|
||||
echo '<center>';
|
||||
echo '<form action="maintenance.php" method="post">';
|
||||
echo '<input type="hidden" name="action" value="enable">';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'">';
|
||||
echo '<p><input type="submit" value="'.get_string('enable').'"></p>';
|
||||
echo '<p>'.get_string('optionalmaintenancemessage', 'admin').':</p>';
|
||||
echo '<table><tr><td>';
|
||||
print_textarea($usehtmleditor, 20, 50, 600, 400, "text");
|
||||
echo '</td></tr></table>';
|
||||
echo '</form>';
|
||||
echo '</center>';
|
||||
|
||||
if ($usehtmleditor) {
|
||||
use_html_editor();
|
||||
}
|
||||
}
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
?>
|
||||
+32
-43
@@ -1,67 +1,56 @@
|
||||
<?PHP // $Id$
|
||||
// module.php - allows admin to edit all local configuration variables for a module
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('managemodules', $adminroot);
|
||||
require_once("../config.php");
|
||||
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("Only an admin can use this page");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
error("Site isn't defined!");
|
||||
}
|
||||
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($config = data_submitted()) {
|
||||
$module = optional_param('module', '', PARAM_SAFEDIR);
|
||||
|
||||
if (!confirm_sesskey()) {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
|
||||
if ($module != '') {
|
||||
require_once("$CFG->dirroot/mod/$module/lib.php");
|
||||
// if the config.html contains a hidden form field giving
|
||||
// the module name then the form does not have to prefix all
|
||||
// its variable names, we will do it here.
|
||||
$moduleprefix = $module.'_';
|
||||
// let the module process the form data if it has to,
|
||||
// $config is passed to this function by reference
|
||||
$moduleconfig = $module.'_process_options';
|
||||
if (function_exists($moduleconfig)) {
|
||||
$moduleconfig($config);
|
||||
}
|
||||
} else {
|
||||
$moduleprefix = '';
|
||||
}
|
||||
|
||||
unset($config->sesskey);
|
||||
unset($config->module);
|
||||
|
||||
if ($config = data_submitted()) {
|
||||
print_header();
|
||||
foreach ($config as $name => $value) {
|
||||
set_config($moduleprefix.$name, $value);
|
||||
set_config($name, $value);
|
||||
}
|
||||
redirect("$CFG->wwwroot/$CFG->admin/modules.php", get_string("changessaved"), 1);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/// Otherwise print the form.
|
||||
$module = required_param('module', PARAM_SAFEDIR);
|
||||
require_once("$CFG->dirroot/mod/$module/lib.php");
|
||||
|
||||
require_variable($module);
|
||||
|
||||
require_once("$CFG->dirroot/mod/$module/lib.php");
|
||||
|
||||
|
||||
$stradmin = get_string("administration");
|
||||
$strconfiguration = get_string("configuration");
|
||||
$strmanagemodules = get_string("managemodules");
|
||||
$strmodulename = get_string("modulename", $module);
|
||||
|
||||
// $CFG->pagepath is used to generate the body and id attributes for the body tag
|
||||
// of the page. It is also used to generate the link to the Moodle Docs for this view.
|
||||
$CFG->pagepath = 'mod/' . $module . '/config';
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_header("$site->shortname: $strmodulename: $strconfiguration", $site->fullname,
|
||||
"<a href=\"index.php\">$stradmin</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> -> ".
|
||||
"<a href=\"modules.php\">$strmanagemodules</a> -> $strmodulename");
|
||||
|
||||
print_heading($strmodulename);
|
||||
|
||||
print_simple_box("<center>".get_string("configwarning", 'admin')."</center>", "center", "60%");
|
||||
print_simple_box("<center>".get_string("configwarning")."</center>", "center", "50%");
|
||||
echo "<br />";
|
||||
|
||||
print_simple_box_start("center", "");
|
||||
include("$CFG->dirroot/mod/$module/config.html");
|
||||
print_simple_box_start("center", "", "$THEME->cellheading");
|
||||
include("$CFG->dirroot/mod/$module/config.html");
|
||||
print_simple_box_end();
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
|
||||
+60
-58
@@ -1,21 +1,30 @@
|
||||
<?PHP // $Id$
|
||||
// Allows the admin to manage activity modules
|
||||
// Allows the admin to create, delete and rename course categories
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('managemodules', $adminroot);
|
||||
require_once('../course/lib.php');
|
||||
require_once("../config.php");
|
||||
require_once("../course/lib.php");
|
||||
|
||||
$show = optional_param('show', '', PARAM_SAFEDIR);
|
||||
$hide = optional_param('hide', '', PARAM_SAFEDIR);
|
||||
$delete = optional_param('delete', '', PARAM_SAFEDIR);
|
||||
$confirm = optional_param('confirm', '', PARAM_BOOL);
|
||||
optional_variable($disable);
|
||||
optional_variable($enable);
|
||||
optional_variable($delete);
|
||||
optional_variable($confirm);
|
||||
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("Only administrators can use this page!");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
error("Site isn't defined!");
|
||||
}
|
||||
|
||||
|
||||
/// Print headings
|
||||
|
||||
$stractivities = get_string("activities");
|
||||
$stradministration = get_string("administration");
|
||||
$strconfiguration = get_string("configuration");
|
||||
$strmanagemodules = get_string("managemodules");
|
||||
$strdelete = get_string("delete");
|
||||
$strversion = get_string("version");
|
||||
$strhide = get_string("hide");
|
||||
@@ -24,44 +33,40 @@
|
||||
$stractivities = get_string("activities");
|
||||
$stractivitymodule = get_string("activitymodule");
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
print_heading($stractivities);
|
||||
|
||||
$coursesaffected = false;
|
||||
print_header("$site->shortname: $strmanagemodules", "$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> -> $strmanagemodules");
|
||||
|
||||
print_heading($strmanagemodules);
|
||||
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if (!empty($hide) and confirm_sesskey()) {
|
||||
if (!empty($hide)) {
|
||||
if (!$module = get_record("modules", "name", $hide)) {
|
||||
error("Module doesn't exist!");
|
||||
}
|
||||
set_field("modules", "visible", "0", "id", $module->id); // Hide main module
|
||||
set_field('course_modules', 'visibleold', '1', 'visible' ,'1', 'module', $module->id); // Remember the previous visible state so we can toggle this back if the module is unhidden.
|
||||
set_field('course_modules', 'visibleold', '0', 'visible' ,'0', 'module', $module->id);
|
||||
set_field("course_modules", "visible", "0", "module", $module->id); // Hide all related activity modules
|
||||
$coursesaffected = true;
|
||||
set_field("modules", "visible", "0", "id", $module->id); // Hide main module
|
||||
set_field("course_modules", "visible", "0", "module", $module->id); // Hide all related activity modules
|
||||
}
|
||||
|
||||
if (!empty($show) and confirm_sesskey()) {
|
||||
if (!empty($show)) {
|
||||
if (!$module = get_record("modules", "name", $show)) {
|
||||
error("Module doesn't exist!");
|
||||
}
|
||||
set_field("modules", "visible", "1", "id", $module->id); // Show main module
|
||||
set_field('course_modules', 'visible', '1', 'visibleold', '1', 'module', $module->id); // Get the previous saved visible state for the course module.
|
||||
$coursesaffected = true;
|
||||
set_field("modules", "visible", "1", "id", $module->id); // Show main module
|
||||
set_field("course_modules", "visible", "1", "module", $module->id); // Show all related activity modules
|
||||
}
|
||||
|
||||
if (!empty($delete) and confirm_sesskey()) {
|
||||
|
||||
if (!empty($delete)) {
|
||||
|
||||
$strmodulename = get_string("modulename", "$delete");
|
||||
|
||||
if (!$confirm) {
|
||||
notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename),
|
||||
"modules.php?delete=$delete&confirm=1&sesskey=$USER->sesskey",
|
||||
if (empty($confirm)) {
|
||||
notice_yesno(get_string("moduledeleteconfirm", "", $strmodulename),
|
||||
"modules.php?delete=$delete&confirm=$delete",
|
||||
"modules.php");
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_footer();
|
||||
exit;
|
||||
|
||||
} else { // Delete everything!!
|
||||
@@ -88,7 +93,7 @@
|
||||
notify("Error occurred while deleting all $strmodulename records in course_modules table");
|
||||
}
|
||||
|
||||
// Then delete all the logs
|
||||
// Then delete all the logs
|
||||
if (!delete_records("log", "module", $module->name)) {
|
||||
notify("Error occurred while deleting all $strmodulename records in log table");
|
||||
}
|
||||
@@ -114,12 +119,10 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Delete the capabilities that were defined by this module
|
||||
capabilities_cleanup('mod/'.$module->name);
|
||||
}
|
||||
|
||||
rebuild_course_cache(); // Because things have changed
|
||||
|
||||
// rebuild_course_cache(); // Because things have changed
|
||||
$coursesaffected = true;
|
||||
|
||||
$a->module = $strmodulename;
|
||||
$a->directory = "$CFG->dirroot/mod/$delete";
|
||||
@@ -127,11 +130,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ($coursesaffected) {
|
||||
rebuild_course_cache(); // Because things have changed
|
||||
}
|
||||
|
||||
|
||||
/// Get and sort the existing modules
|
||||
|
||||
if (!$modules = get_records("modules")) {
|
||||
@@ -140,27 +138,31 @@
|
||||
|
||||
foreach ($modules as $module) {
|
||||
$strmodulename = get_string("modulename", "$module->name");
|
||||
// Deal with modules which are lacking the language string
|
||||
if ($strmodulename == '[[modulename]]') {
|
||||
$strmodulename = $module->name;
|
||||
}
|
||||
$modulebyname[$strmodulename] = $module;
|
||||
}
|
||||
ksort($modulebyname);
|
||||
|
||||
/// Print the table of all modules
|
||||
|
||||
if (empty($THEME->custompix)) {
|
||||
$pixpath = "../pix";
|
||||
$modpixpath = "../mod";
|
||||
} else {
|
||||
$pixpath = "../theme/$CFG->theme/pix";
|
||||
$modpixpath = "../theme/$CFG->theme/pix/mod";
|
||||
}
|
||||
|
||||
$table->head = array ($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strdelete, $strsettings);
|
||||
$table->align = array ("left", "right", "left", "center", "center", "center");
|
||||
$table->wrap = array ("nowrap", "", "", "", "","");
|
||||
$table->size = array ("100%", "10", "10", "10", "10","12");
|
||||
$table->align = array ("LEFT", "RIGHT", "LEFT", "CENTER", "CENTER", "CENTER");
|
||||
$table->wrap = array ("NOWRAP", "", "", "", "","");
|
||||
$table->size = array ("100%", "10", "10", "10", "10","12");
|
||||
$table->width = "100";
|
||||
|
||||
foreach ($modulebyname as $modulename => $module) {
|
||||
|
||||
$icon = "<img src=\"$CFG->modpixpath/$module->name/icon.gif\" hspace=\"10\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" />";
|
||||
$icon = "<img src=\"$modpixpath/$module->name/icon.gif\" hspace=10 height=16 width=16 border=0>";
|
||||
|
||||
$delete = "<a href=\"modules.php?delete=$module->name&sesskey=$USER->sesskey\">$strdelete</a>";
|
||||
$delete = "<a href=\"modules.php?delete=$module->name\">$strdelete</a>";
|
||||
|
||||
if (file_exists("$CFG->dirroot/mod/$module->name/config.html")) {
|
||||
$settings = "<a href=\"module.php?module=$module->name\">$strsettings</a>";
|
||||
@@ -171,12 +173,12 @@
|
||||
$count = count_records("$module->name");
|
||||
|
||||
if ($module->visible) {
|
||||
$visible = "<a href=\"modules.php?hide=$module->name&sesskey=$USER->sesskey\" title=\"$strhide\">".
|
||||
"<img src=\"$CFG->pixpath/i/hide.gif\" align=\"middle\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" /></a>";
|
||||
$visible = "<a href=\"modules.php?hide=$module->name\" title=\"$strhide\">".
|
||||
"<img src=\"$pixpath/i/hide.gif\" align=\"absmiddle\" height=16 width=16 border=0></a>";
|
||||
$class = "";
|
||||
} else {
|
||||
$visible = "<a href=\"modules.php?show=$module->name&sesskey=$USER->sesskey\" title=\"$strshow\">".
|
||||
"<img src=\"$CFG->pixpath/i/show.gif\" align=\"middle\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" /></a>";
|
||||
$visible = "<a href=\"modules.php?show=$module->name\" title=\"$strshow\">".
|
||||
"<img src=\"$pixpath/i/show.gif\" align=\"absmiddle\" height=16 width=16 border=0></a>";
|
||||
$class = "class=\"dimmed_text\"";
|
||||
}
|
||||
if ($module->name == "forum") {
|
||||
@@ -184,12 +186,12 @@
|
||||
$visible = "";
|
||||
$class = "";
|
||||
}
|
||||
$table->data[] = array ("<span $class>$icon $modulename</span>", $count, $module->version, $visible, $delete, $settings);
|
||||
$table->data[] = array ("<p $class>$icon $modulename</p>", $count, $module->version, $visible, $delete, $settings);
|
||||
}
|
||||
print_table($table);
|
||||
|
||||
echo "<br /><br />";
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
if (!isset($CFG)) {
|
||||
|
||||
require('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('oacleanup', $adminroot);
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
online_assignment_cleanup(true);
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function online_assignment_cleanup($output=false) {
|
||||
global $CFG;
|
||||
|
||||
if ($output) {
|
||||
print_heading('Online Assignment Cleanup');
|
||||
echo '<center>';
|
||||
}
|
||||
|
||||
|
||||
/// 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');
|
||||
if ((int)$amv < 2005041400) {
|
||||
if ($output) {
|
||||
echo '</center>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/// get the module id for assignments from db
|
||||
$arecord = get_record('modules', 'name', 'assignment');
|
||||
$aid = $arecord->id;
|
||||
|
||||
|
||||
/// get a list of all courses on this site
|
||||
$courses = get_courses();
|
||||
|
||||
/// cycle through each course
|
||||
foreach ($courses as $course) {
|
||||
|
||||
$fullname = empty($course->fullname) ? 'Course: '.$course->id : $course->fullname;
|
||||
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))) {
|
||||
if ($output) echo 'No extra sections<br />';
|
||||
continue;
|
||||
}
|
||||
|
||||
/// cycle through each of the xtra sections
|
||||
foreach ($xsections as $xsection) {
|
||||
|
||||
if ($output) echo 'Checking Section: '.$xsection->section.'<br />';
|
||||
|
||||
/// grab any module instances from the sequence field
|
||||
if (!empty($xsection->sequence)) {
|
||||
$instances = explode(',', $xsection->sequence);
|
||||
|
||||
/// cycle through the instances
|
||||
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'";
|
||||
|
||||
|
||||
/// if record exists then we need to move instance to it's correct section
|
||||
if (record_exists_sql($sql)) {
|
||||
|
||||
/// 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'))) {
|
||||
continue;
|
||||
}
|
||||
$newsection = $zerosection->id;
|
||||
}
|
||||
|
||||
/// grab the section record
|
||||
if (!($section = get_record('course_sections', 'id', $newsection))) {
|
||||
if ($output) echo 'Serious error: Cannot retrieve section: '.$newsection.' for course: '.$course->fullname.'<br />';
|
||||
continue;
|
||||
}
|
||||
|
||||
/// explode the sequence
|
||||
if (($sequence = explode(',', $section->sequence)) === false) {
|
||||
$sequence = array();
|
||||
}
|
||||
|
||||
/// add instance to correct section
|
||||
array_push($sequence, $instance);
|
||||
|
||||
/// implode the sequence
|
||||
$section->sequence = implode(',', $sequence);
|
||||
|
||||
set_field('course_sections', 'sequence', $section->sequence, '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 ($output) echo 'Serious error: Cannot retrieve old section: '.$xsection->id.' for course: '.$course->fullname.'<br />';
|
||||
continue;
|
||||
}
|
||||
|
||||
/// explode the sequence
|
||||
if (($sequence = explode(',', $section->sequence)) === false) {
|
||||
$sequence = array();
|
||||
}
|
||||
|
||||
/// remove the old value from the array
|
||||
$key = array_search($instance, $sequence);
|
||||
unset($sequence[$key]);
|
||||
|
||||
/// implode the sequence
|
||||
$section->sequence = implode(',', $sequence);
|
||||
|
||||
set_field('course_sections', 'sequence', $section->sequence, 'id', $section->id);
|
||||
|
||||
|
||||
if ($output) echo 'Online Assignment (instance '.$instance.') moved from section '.$section->id.': to section '.$newsection.'<br />';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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);
|
||||
if ($output) echo 'Deleting empty section '.$xsection->section.'<br />';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo '</center>';
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,131 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once($CFG->libdir.'/pagelib.php');
|
||||
|
||||
define('PAGE_ADMIN', 'admin');
|
||||
|
||||
define('BLOCK_L_MIN_WIDTH',0);
|
||||
define('BLOCK_L_MAX_WIDTH',210);
|
||||
define('BLOCK_R_MIN_WIDTH',0);
|
||||
define('BLOCK_R_MAX_WIDTH',210);
|
||||
|
||||
page_map_class(PAGE_ADMIN, 'page_admin');
|
||||
|
||||
class page_admin extends page_base {
|
||||
|
||||
var $section;
|
||||
var $pathtosection;
|
||||
var $visiblepathtosection;
|
||||
|
||||
// hack alert!
|
||||
// this function works around the inability to store the section name
|
||||
// in default block, maybe we should "improve" the blocks a bit?
|
||||
function init_extra($section) {
|
||||
global $CFG;
|
||||
|
||||
if($this->full_init_done) {
|
||||
return;
|
||||
}
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
|
||||
// fetch the path parameter
|
||||
$this->section = $section;
|
||||
|
||||
$this->visiblepathtosection = array();
|
||||
|
||||
// this part is (potentially) processor-intensive... there's gotta be a better way
|
||||
// of handling this
|
||||
if ($this->pathtosection = $adminroot->path($this->section)) {
|
||||
foreach($this->pathtosection as $element) {
|
||||
if ($pointer = $adminroot->locate($element)) {
|
||||
array_push($this->visiblepathtosection, $pointer->visiblename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// all done
|
||||
$this->full_init_done = true;
|
||||
}
|
||||
|
||||
function blocks_get_default() {
|
||||
return 'admin_tree,admin_bookmarks';
|
||||
}
|
||||
|
||||
// seems reasonable that the only people that can edit blocks on the admin pages
|
||||
// are the admins... but maybe we want a role for this?
|
||||
function user_allowed_editing() {
|
||||
return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
}
|
||||
|
||||
// has to be fixed. i know there's a "proper" way to do this
|
||||
function user_is_editing() {
|
||||
global $USER;
|
||||
return $USER->adminediting;
|
||||
}
|
||||
|
||||
function url_get_path() {
|
||||
global $CFG;
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
|
||||
$root = $adminroot->locate($this->section);
|
||||
if (is_a($root, 'admin_externalpage')) {
|
||||
return $root->url;
|
||||
} else {
|
||||
return ($CFG->wwwroot . '/' . $CFG->admin . '/settings.php');
|
||||
}
|
||||
}
|
||||
|
||||
function url_get_parameters() { // only handles parameters relevant to the admin pagetype
|
||||
return array('section' => (isset($this->section) ? $this->section : ''));
|
||||
}
|
||||
|
||||
function blocks_get_positions() {
|
||||
return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
|
||||
}
|
||||
|
||||
function blocks_default_position() {
|
||||
return BLOCK_POS_LEFT;
|
||||
}
|
||||
|
||||
function blocks_move_position(&$instance, $move) {
|
||||
if($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
|
||||
return BLOCK_POS_RIGHT;
|
||||
} else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
|
||||
return BLOCK_POS_LEFT;
|
||||
}
|
||||
return $instance->position;
|
||||
}
|
||||
|
||||
// does anything need to be done here?
|
||||
function init_quick($data) {
|
||||
parent::init_quick($data);
|
||||
}
|
||||
|
||||
function print_header($section = '') {
|
||||
global $USER, $CFG, $SITE;
|
||||
|
||||
$this->init_full($section); // we're trusting that init_full() has already been called by now; it should have.
|
||||
// if not, print_header() has to be called with a $section parameter
|
||||
|
||||
if ($this->user_allowed_editing()) {
|
||||
$buttons = '<table><tr><td><form target="' . $CFG->framename . '" method="get" action="' . $this->url_get_path() . '">'.
|
||||
'<input type="hidden" name="adminedit" value="'.($this->user_is_editing()?'off':'on').'" />'.
|
||||
'<input type="hidden" name="section" value="'.$this->section.'" />'.
|
||||
'<input type="submit" value="'.get_string($this->user_is_editing()?'blockseditoff':'blocksediton').'" /></form></td>' .
|
||||
'</tr></table>';
|
||||
} else {
|
||||
$buttons = ' ';
|
||||
}
|
||||
|
||||
print_header("$SITE->shortname: " . implode(": ",$this->visiblepathtosection), $SITE->fullname,
|
||||
implode(" -> ",$this->visiblepathtosection),'', '', true, $buttons, '');
|
||||
}
|
||||
|
||||
function get_type() {
|
||||
return PAGE_ADMIN;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+23
-21
@@ -2,31 +2,33 @@
|
||||
// phpinfo.php - shows phpinfo for the current server
|
||||
|
||||
require_once("../config.php");
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('phpinfo', $adminroot);
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
if (!isadmin()) {
|
||||
error("Only the admin can use this page");
|
||||
}
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
if (isset($topframe)) {
|
||||
$stradministration = get_string("administration");
|
||||
$site = get_site();
|
||||
|
||||
print_header("$site->shortname: phpinfo", "$site->fullname",
|
||||
"<a target=\"$CFG->framename\" href=\"index.php\">$stradministration</a> -> PHP info");
|
||||
exit;
|
||||
}
|
||||
|
||||
echo '<div class="phpinfo">';
|
||||
|
||||
ob_start();
|
||||
phpinfo(INFO_GENERAL + INFO_CONFIGURATION + INFO_MODULES);
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$html = preg_replace('#(\n?<style[^>]*?>.*?</style[^>]*?>)|(\n?<style[^>]*?/>)#is', '', $html);
|
||||
$html = preg_replace('#(\n?<head[^>]*?>.*?</head[^>]*?>)|(\n?<head[^>]*?/>)#is', '', $html);
|
||||
|
||||
echo $html;
|
||||
|
||||
echo '</div>';
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
if (isset($bottomframe)) {
|
||||
phpinfo();
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
<head>
|
||||
<title>PHP info</title>
|
||||
</head>
|
||||
|
||||
<frameset rows="80,*">
|
||||
<frame src="phpinfo.php?topframe=true">
|
||||
<frame src="phpinfo.php?bottomframe=true">
|
||||
</frameset>
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
#!/usr/bin/php -f
|
||||
<?php // $Id$
|
||||
define('FULLME','cron'); // prevent warnings
|
||||
//error_reporting(0);
|
||||
//ini_set('display_errors',0);
|
||||
require_once(dirname(dirname(__FILE__)).'/config.php');
|
||||
$tmp = explode('@',$_ENV['RECIPIENT']);
|
||||
$address = $tmp[0];
|
||||
|
||||
// BOUNCE EMAILS TO NOREPLY
|
||||
if ($_ENV['RECIPIENT'] == $CFG->noreplyaddress) {
|
||||
$user->email = $_ENV['SENDER'];
|
||||
|
||||
if (!validate_email($user->email)) {
|
||||
die();
|
||||
}
|
||||
|
||||
$site = get_site();
|
||||
$subject = get_string('noreplybouncesubject','moodle',$site->fullname);
|
||||
$body = get_string('noreplybouncemessage','moodle',$site->fullname)."\n\n";
|
||||
|
||||
$fd = fopen('php://stdin','r');
|
||||
if ($fd) {
|
||||
while(!feof($fd)) {
|
||||
$body .= fgets($fd);
|
||||
}
|
||||
fclose($fd);
|
||||
}
|
||||
|
||||
$user->id = 0; // to prevent anything annoying happening
|
||||
|
||||
$from->firstname = null;
|
||||
$from->lastname = null;
|
||||
$from->email = '<>';
|
||||
$from->maildisplay = true;
|
||||
|
||||
email_to_user($user,$from,$subject,$body);
|
||||
die ();
|
||||
}
|
||||
/// ALL OTHER PROCESSING
|
||||
// we need to split up the address
|
||||
$prefix = substr($address,0,4);
|
||||
$mod = substr($address,4,2);
|
||||
$modargs = substr($address,6,-16);
|
||||
$hash = substr($address,-16);
|
||||
|
||||
if (substr(md5($prefix.$mod.$modargs.$CFG->siteidentifier),0,16) != $hash) {
|
||||
die("HASH DIDN'T MATCH!\n");
|
||||
}
|
||||
list(,$modid) = unpack('C',base64_decode($mod.'=='));
|
||||
|
||||
if ($modid == '0') { // special
|
||||
$modname = 'moodle';
|
||||
}
|
||||
else {
|
||||
$modname = get_field("modules","name","id",$modid);
|
||||
require_once('mod/'.$modname.'/lib.php');
|
||||
}
|
||||
$function = $modname.'_process_email';
|
||||
|
||||
if (!function_exists($function)) {
|
||||
die();
|
||||
}
|
||||
$fd = fopen('php://stdin','r');
|
||||
if (!$fd) {
|
||||
exit();
|
||||
}
|
||||
|
||||
while(!feof($fd)) {
|
||||
$body .= fgets($fd);
|
||||
}
|
||||
|
||||
$function($modargs,$body);
|
||||
|
||||
fclose($handle);
|
||||
|
||||
|
||||
|
||||
?>
|
||||
+46
-112
@@ -1,20 +1,18 @@
|
||||
<?php // $Id$
|
||||
<?PHP // $Id$
|
||||
// register.php - allows admin to register their site on moodle.org
|
||||
|
||||
require_once('../config.php');
|
||||
include("../config.php");
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
if (!isadmin()) {
|
||||
error("Only the admin can use this page");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
redirect("index.php");
|
||||
}
|
||||
|
||||
if (!confirm_sesskey()) {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
|
||||
if (!$admin = get_admin()) {
|
||||
error("No admins");
|
||||
}
|
||||
@@ -23,8 +21,12 @@
|
||||
$admin->country = $CFG->country;
|
||||
}
|
||||
|
||||
if (empty($CFG->siteidentifier)) { // Unique site identification code
|
||||
set_config('siteidentifier', random_string(32).$_SERVER['HTTP_HOST']);
|
||||
if (!$admin->secret) { // secret field hasn't been set yet
|
||||
$admin->secret = random_string(15);
|
||||
|
||||
if (!set_field("user", "secret", $admin->secret, "id", $admin->id)) {
|
||||
error("Could not set admin's secret string!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,10 +36,10 @@
|
||||
$strregistration = get_string("registration");
|
||||
$strregistrationinfo = get_string("registrationinfo");
|
||||
|
||||
print_header("$site->shortname: $strregistration", "$site->fullname",
|
||||
print_header("$site->shortname: $strregistration", "$site->fullname",
|
||||
"<a href=\"../$CFG->admin/index.php\">$stradministration</a> -> $strregistration");
|
||||
|
||||
print_heading($strregistration);
|
||||
print_heading($strmanagemodules);
|
||||
|
||||
print_simple_box($strregistrationinfo, "center", "70%");
|
||||
echo "<br />";
|
||||
@@ -45,49 +47,46 @@
|
||||
|
||||
/// Print the form
|
||||
|
||||
print_simple_box_start("center", "");
|
||||
print_simple_box_start("center", "", "$THEME->cellheading");
|
||||
|
||||
echo "<form name=\"form\" action=\"http://moodle.org/register/\" method=\"post\">\n";
|
||||
echo "<table cellpadding=\"9\" border=\"0\">\n";
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"center\" colspan=\"2\">".get_string("location")."</td>\n";
|
||||
echo "</tr>\n";
|
||||
echo "<form name=\"form\" action=\"http://moodle.org/register/\" method=post>\n";
|
||||
echo "<table cellpadding=9 border=0>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\">Moodle URL:</td>\n";
|
||||
echo "<td>$CFG->wwwroot</td>\n";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td align=right><p>Moodle URL:</td>\n";
|
||||
echo "<td><p>$CFG->wwwroot</td>\n";
|
||||
echo "<!-- The following hidden variables are to help prevent fake entries being sent. -->\n";
|
||||
echo "<!-- Together they form a key. If any of these change between updates then the entry -->\n";
|
||||
echo "<!-- is flagged as a new entry and will be manually checked by the list maintainer -->\n";
|
||||
|
||||
echo "<input type=\"hidden\" name=\"url\" value=\"$CFG->wwwroot\">\n";
|
||||
echo "<input type=\"hidden\" name=\"secret\" value=\"$CFG->siteidentifier\">\n";
|
||||
echo "<input type=\"hidden\" name=\"secret\" value=\"$admin->secret\">\n";
|
||||
echo "<input type=\"hidden\" name=\"host\" value=\"".$_SERVER["HTTP_HOST"]."\">\n";
|
||||
echo "<input type=\"hidden\" name=\"lang\" value=\"".current_language()."\">\n";
|
||||
echo "</td></tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\">".get_string("currentversion").":</td>\n";
|
||||
echo "<td>$CFG->release ($CFG->version)</td>\n";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td align=right><p>".get_string("currentversion").":</td>\n";
|
||||
echo "<td><p>$CFG->release ($CFG->version)</td>\n";
|
||||
echo "<input type=\"hidden\" name=\"version\" value=\"$CFG->version\">\n";
|
||||
echo "<input type=\"hidden\" name=\"release\" value=\"$CFG->release\">\n";
|
||||
echo "</td></tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\">".get_string("fullsitename").":</td>\n";
|
||||
echo "<td><input size=\"50\" type=\"text\" name=\"sitename\" value=\"$site->fullname\"></td>\n";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td align=right><p>".get_string("fullsitename").":</td>\n";
|
||||
echo "<td><p><input size=50 type=\"text\" name=\"sitename\" value=\"$site->fullname\"></td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\">".get_string("country").":</td>\n";
|
||||
echo "<td>";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td align=right><p>".get_string("country").":</td>\n";
|
||||
echo "<td><p>";
|
||||
choose_from_menu (get_list_of_countries(), "country", $admin->country, get_string("selectacountry")."...", "", "");
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\"><a href=\"http://moodle.org/sites/?country=$admin->country\" title=\"See the current list of sites\" target=_blank>".get_string("publicdirectory")."</a>:</td>\n";
|
||||
echo "<td>";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td align=right><p><a href=\"http://moodle.org/sites\" title=\"See the current list of sites\" target=_blank>".get_string("publicdirectory")."</a>:</td>\n";
|
||||
echo "<td><p>";
|
||||
$options[0] = get_string("publicdirectory0");
|
||||
$options[1] = get_string("publicdirectory1");
|
||||
$options[2] = get_string("publicdirectory2");
|
||||
@@ -96,88 +95,23 @@
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\">".get_string("registrationcontact")."</a>:</td>\n";
|
||||
echo "<td>\n";
|
||||
$options[0] = get_string("registrationcontactno");
|
||||
$options[1] = get_string("registrationcontactyes");
|
||||
choose_from_menu ($options, "contact", "1", "", "", "");
|
||||
unset($options);
|
||||
echo "</td>\n";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td colspan=2><hr size=1 noshade>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\">".get_string("statistics").":";
|
||||
echo "<br />(".get_string("notpublic").')';
|
||||
echo "</td>\n";
|
||||
echo "<td>";
|
||||
|
||||
$count = count_records('course')-1;
|
||||
echo get_string("courses").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"courses\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('user', 'deleted', 0);
|
||||
echo get_string("users").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"users\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
// total number of role assignments
|
||||
$count = count_records('role_assignments');
|
||||
echo get_string('roleassignments', 'role').": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"roleassignments\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
// first find all distinct roles with mod/course:update
|
||||
// please change the name and strings to something appropriate to reflect the new data collected
|
||||
$sql = "SELECT COUNT(DISTINCT u.id)
|
||||
FROM {$CFG->prefix}role_capabilities rc,
|
||||
{$CFG->prefix}role_assignments ra,
|
||||
{$CFG->prefix}user u
|
||||
WHERE (rc.capability = 'moodle/course:update' or rc.capability='moodle/site:doanything')
|
||||
AND rc.roleid = ra.roleid
|
||||
AND u.id = ra.userid";
|
||||
|
||||
$count = count_records_sql($sql);
|
||||
echo get_string("teachers").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"courseupdaters\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('forum_posts');
|
||||
echo get_string("posts", 'forum').": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"posts\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('question');
|
||||
echo get_string("questions", 'quiz').": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"questions\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
$count = count_records('resource');
|
||||
echo get_string("modulenameplural", "resource").": ".$count;
|
||||
echo "<input type=\"hidden\" name=\"resources\" value=\"$count\">\n";
|
||||
echo '<br />';
|
||||
|
||||
echo "</td>\n";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td align=right><p>".get_string("administrator").":</td>\n";
|
||||
echo "<td><p><input size=50 type=\"text\" name=\"adminname\" value=\"".fullname($admin, true)."\"></td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"center\" colspan=\"2\"><hr size=\"1\" noshade>".get_string("administrator")."</td>\n";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td align=right><p>".get_string("email").":</td>\n";
|
||||
echo "<td><p><input size=50 type=\"text\" name=\"adminemail\" value=\"$admin->email\"></td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\">".get_string("administrator").":</td>\n";
|
||||
echo "<td><input size=\"50\" type=\"text\" name=\"adminname\" value=\"".fullname($admin, true)."\"></td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\">".get_string("email").":</td>\n";
|
||||
echo "<td><input size=\"50\" type=\"text\" name=\"adminemail\" value=\"$admin->email\"></td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\">".get_string("registrationemail")."</a>:</td>\n";
|
||||
echo "<td>\n";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td align=right><p>".get_string("registrationemail")."</a>:</td>\n";
|
||||
echo "<td><p>\n";
|
||||
$options[0] = get_string("registrationno");
|
||||
$options[1] = get_string("registrationyes");
|
||||
choose_from_menu ($options, "mailme", "1", "", "", "");
|
||||
@@ -185,9 +119,9 @@
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
echo "<tr valign=\"top\">\n";
|
||||
echo "<td align=\"right\"> </td>\n";
|
||||
echo "<td><input type=\"submit\" value=\"".get_string("registrationsend")."\"></td>\n";
|
||||
echo "<tr valign=top>\n";
|
||||
echo "<td align=right> </td>\n";
|
||||
echo "<td><p><input type=\"submit\" value=\"".get_string("registrationsend")."\"></td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php /// $Id$
|
||||
/// Search and replace strings throughout all texts in the whole database
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('replace', $adminroot);
|
||||
|
||||
$search = optional_param('search', '', PARAM_RAW);
|
||||
$replace = optional_param('replace', '', PARAM_RAW);
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
|
||||
###################################################################
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
print_heading('Search and replace text throughout the whole database');
|
||||
|
||||
|
||||
if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Print a form
|
||||
|
||||
print_simple_box_start('center');
|
||||
echo '<div align="center">';
|
||||
echo '<form action="replace.php" method="post">';
|
||||
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'">';
|
||||
echo 'Search whole database for: <input type="text" name="search"><br />';
|
||||
echo 'Replace with this string: <input type="text" name="replace"><br /></br />';
|
||||
echo '<input type="submit" value="Yes, do it now"><br />';
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
print_simple_box_end();
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
if (!$tables = $db->Metatables() ) { // No tables yet at all.
|
||||
error("no tables");
|
||||
}
|
||||
|
||||
print_simple_box_start('center');
|
||||
|
||||
/// Turn off time limits, sometimes upgrades can be slow.
|
||||
|
||||
@set_time_limit(0);
|
||||
@ob_implicit_flush(true);
|
||||
while(@ob_end_flush());
|
||||
|
||||
foreach ($tables as $table) {
|
||||
if (in_array($table, array($CFG->prefix.'config'))) { // Don't process these
|
||||
continue;
|
||||
}
|
||||
if ($columns = $db->MetaColumns($table, false)) {
|
||||
foreach ($columns as $column => $data) {
|
||||
if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) { // Text stuff only
|
||||
$db->debug = true;
|
||||
execute_sql("UPDATE $table SET $column = REPLACE($column, '$search', '$replace');");
|
||||
$db->debug = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print_simple_box_end();
|
||||
|
||||
/// Rebuild course cache which might be incorrect now
|
||||
notify('Rebuilding course cache...');
|
||||
rebuild_course_cache();
|
||||
notify('...finished');
|
||||
|
||||
print_continue('index.php');
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
?>
|
||||
@@ -1,120 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once($CFG->dirroot.'/lib/statslib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
|
||||
admin_externalpage_setup('reportcourseoverview', $adminroot);
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
$report = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT);
|
||||
$time = optional_param('time', 0, PARAM_INT);
|
||||
$numcourses = optional_param('numcourses', 20, PARAM_INT);
|
||||
|
||||
require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID)); // needed?
|
||||
|
||||
if (empty($CFG->enablestats)) {
|
||||
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'));
|
||||
}
|
||||
|
||||
|
||||
$course = get_site();
|
||||
stats_check_uptodate($course->id);
|
||||
|
||||
$strreports = get_string('reports');
|
||||
$strcourseoverview = get_string('courseoverview');
|
||||
|
||||
$reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED);
|
||||
|
||||
$tableprefix = $CFG->prefix.'stats_';
|
||||
|
||||
$earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
|
||||
$earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
|
||||
$earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend');
|
||||
|
||||
if (empty($earliestday)) $earliestday = time();
|
||||
if (empty($earliestweek)) $earliestweek = time();
|
||||
if (empty($earliestmonth)) $earliestmonth = time();
|
||||
|
||||
$now = stats_get_base_daily();
|
||||
$lastweekend = stats_get_base_weekly();
|
||||
$lastmonthend = stats_get_base_monthly();
|
||||
|
||||
$timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
|
||||
|
||||
if (empty($timeoptions)) {
|
||||
error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/view.php?id='.$course->id);
|
||||
}
|
||||
|
||||
echo '<form action="index.php" method="post">'."\n";
|
||||
|
||||
$table->width = '*';
|
||||
|
||||
$table->align = array('left','left','left','left','left','left');
|
||||
$table->data[] = array(get_string('statsreporttype'),choose_from_menu($reportoptions,'report',$report,'','','',true),
|
||||
get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true),
|
||||
'<input type="text" name="numcourses" size="3" maxlength="2" value="'.$numcourses.'" />',
|
||||
'<input type="submit" value="'.get_string('view').'" />') ;
|
||||
|
||||
print_table($table);
|
||||
echo '</form>';
|
||||
|
||||
if (!empty($report) && !empty($time)) {
|
||||
$param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
|
||||
|
||||
if (!empty($param->sql)) {
|
||||
$sql = $param->sql;
|
||||
} else {
|
||||
$sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table
|
||||
." WHERE timeend >= ".$param->timeafter.' AND stattype = \'activity\''
|
||||
." GROUP BY courseid "
|
||||
.$param->extras
|
||||
." ORDER BY ".$param->orderby;
|
||||
}
|
||||
error_log($sql);
|
||||
|
||||
$courses = get_records_sql($sql, 0, $numcourses);
|
||||
|
||||
if (empty($courses)) {
|
||||
notify(get_string('statsnodata'));
|
||||
|
||||
} else {
|
||||
if (empty($CFG->gdversion)) {
|
||||
echo '<div align="center">(' . get_string("gdneed") .')</div>';
|
||||
} else {
|
||||
echo '<div align="center"><img src="'.$CFG->wwwroot.'/'.$CFG->admin.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
|
||||
}
|
||||
|
||||
$table = new StdClass;
|
||||
$table->align = array('left','center','center','center');
|
||||
$table->head = array(get_string('course'),$param->line1);
|
||||
if (!empty($param->line2)) {
|
||||
$table->head[] = $param->line2;
|
||||
}
|
||||
if (!empty($param->line3)) {
|
||||
$table->head[] = $param->line3;
|
||||
}
|
||||
|
||||
foreach ($courses as $c) {
|
||||
$a = array();
|
||||
$a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.get_field('course','shortname','id',$c->courseid).'</a>';
|
||||
|
||||
$a[] = $c->line1;
|
||||
if (isset($c->line2)) {
|
||||
$a[] = $c->line2;
|
||||
}
|
||||
if (isset($c->line3)) {
|
||||
$a[] = round($c->line3,2);
|
||||
}
|
||||
$table->data[] = $a;
|
||||
}
|
||||
print_table($table);
|
||||
}
|
||||
}
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
?>
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once($CFG->dirroot.'/lib/statslib.php');
|
||||
require_once($CFG->dirroot.'/lib/graphlib.php');
|
||||
|
||||
$report = required_param('report', PARAM_INT);
|
||||
$time = required_param('time', PARAM_INT);
|
||||
$numcourses = required_param('numcourses', PARAM_INT);
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
|
||||
stats_check_uptodate($course->id);
|
||||
|
||||
$param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
|
||||
|
||||
if (!empty($param->sql)) {
|
||||
$sql = $param->sql;
|
||||
} else {
|
||||
$sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table
|
||||
." WHERE timeend >= ".$param->timeafter.' AND stattype = \'activity\''
|
||||
." GROUP BY courseid "
|
||||
.$param->extras
|
||||
." ORDER BY ".$param->orderby;
|
||||
}
|
||||
|
||||
$courses = get_records_sql($sql, 0, $numcourses);
|
||||
|
||||
if (empty($courses)) {
|
||||
error(get_string('statsnodata'),$CFG->wwwroot.'/'.$CFG->admin.'/report/course/index.php');
|
||||
}
|
||||
|
||||
|
||||
$graph = new graph(750,400);
|
||||
|
||||
$graph->parameter['legend'] = 'outside-right';
|
||||
$graph->parameter['legend_size'] = 10;
|
||||
$graph->parameter['x_axis_angle'] = 90;
|
||||
$graph->parameter['title'] = false; // moodle will do a nicer job.
|
||||
$graph->y_tick_labels = null;
|
||||
$graph->offset_relation = null;
|
||||
if ($report != STATS_REPORT_ACTIVE_COURSES) {
|
||||
$graph->parameter['y_decimal_left'] = 2;
|
||||
}
|
||||
|
||||
foreach ($courses as $c) {
|
||||
$graph->x_data[] = get_field('course','shortname','id',$c->courseid);
|
||||
$graph->y_data['bar1'][] = $c->{$param->graphline};
|
||||
}
|
||||
$graph->y_order = array('bar1');
|
||||
$graph->y_format['bar1'] = array('colour' => 'blue','bar' => 'fill','legend' => $param->{$param->graphline});
|
||||
|
||||
$graph->draw_stack();
|
||||
|
||||
?>
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
require_once($CFG->dirroot.'/course/report/log/lib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
|
||||
admin_externalpage_setup('reportlog', $adminroot);
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
|
||||
$course = get_site();
|
||||
|
||||
print_heading(get_string('chooselogs') .':');
|
||||
|
||||
print_log_selector_form($course);
|
||||
|
||||
echo '<br />';
|
||||
print_heading(get_string('chooselivelogs') .':');
|
||||
|
||||
echo '<center><h3>';
|
||||
link_to_popup_window('/course/report/log/live.php?id='. $course->id,'livelog', get_string('livelogs'), 500, 800);
|
||||
echo '</h3></center>';
|
||||
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
?>
|
||||
@@ -1,195 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A SimpleTest report format for Moodle.
|
||||
*
|
||||
* @copyright © 2006 The Open University
|
||||
* @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @version $Id$
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
|
||||
/** */
|
||||
require_once(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/moodlelib.php');
|
||||
require_once($CFG->libdir . '/simpletestlib/reporter.php');
|
||||
|
||||
/**
|
||||
* Extended in-browser test displayer. HtmlReporter generates
|
||||
* only failure messages and a pass count. ExHtmlReporter also
|
||||
* generates pass messages and a time-stamp.
|
||||
*
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class ExHtmlReporter extends HtmlReporter {
|
||||
|
||||
// Options set when the class is created.
|
||||
var $showpasses;
|
||||
|
||||
// Lang strings. Set in the constructor.
|
||||
var $strrunonlyfolder;
|
||||
var $strrunonlyfile;
|
||||
|
||||
var $strseparator;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param bool $showpasses Whether this reporter should output anything for passes.
|
||||
*/
|
||||
function ExHtmlReporter($showpasses) {
|
||||
global $CFG;
|
||||
|
||||
$this->HtmlReporter();
|
||||
$this->showpasses = $showpasses;
|
||||
|
||||
$this->strrunonlyfolder = $this->get_string('runonlyfolder');
|
||||
$this->strrunonlyfile = $this->get_string('runonlyfile');
|
||||
$this->strseparator = ' <img src="' . $CFG->pixpath . '/a/r_breadcrumb.gif" class="resize" alt="" /> ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a pass needs to be output.
|
||||
*/
|
||||
function paintPass($message) {
|
||||
//(Implicitly call grandparent, as parent not implemented.)
|
||||
parent::paintPass($message);
|
||||
if ($this->showpasses) {
|
||||
$this->_paintPassFail('pass', $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a fail needs to be output.
|
||||
*/
|
||||
function paintFail($message) {
|
||||
// Explicitly call grandparent, not parent::paintFail.
|
||||
SimpleScorer::paintFail($message);
|
||||
$this->_paintPassFail('fail', $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an error (uncaught exception or PHP error) needs to be output.
|
||||
*/
|
||||
function paintError($message) {
|
||||
// Explicitly call grandparent, not parent::paintFail.
|
||||
SimpleScorer::paintError($message);
|
||||
$this->_paintPassFail('exception', $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private method. Used by printPass/Fail/Error.
|
||||
*/
|
||||
function _paintPassFail($passorfail, $message) {
|
||||
global $FULLME, $CFG;
|
||||
|
||||
print_simple_box_start('', '100%', '', 5, $passorfail . ' generalbox');
|
||||
$url = $this->_htmlEntities($this->_stripParameterFromUrl($FULLME, 'path'));
|
||||
echo '<b class="', $passorfail, '">', $this->get_string($passorfail), '</b>: ';
|
||||
$breadcrumb = $this->getTestList();
|
||||
array_shift($breadcrumb);
|
||||
$file = array_shift($breadcrumb);
|
||||
$pathbits = preg_split('/\/|\\\\/', substr($file, strlen($CFG->dirroot) + 1));
|
||||
$file = array_pop($pathbits);
|
||||
$folder = '';
|
||||
foreach ($pathbits as $pathbit) {
|
||||
$folder .= $pathbit . '/';
|
||||
echo "<a href=\"{$url}path=$folder\" title=\"$this->strrunonlyfolder\">$pathbit</a>/";
|
||||
}
|
||||
echo "<a href=\"{$url}path=$folder$file\" title=\"$this->strrunonlyfile\">$file</a>";
|
||||
echo $this->strseparator, implode($this->strseparator, $breadcrumb);
|
||||
echo $this->strseparator, '<br />', $this->_htmlEntities($message), "\n\n";
|
||||
print_simple_box_end();
|
||||
flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a notice needs to be output.
|
||||
*/
|
||||
function paintNotice($message) {
|
||||
$this->paintMessage($this->_htmlEntities($message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a simple supplementary message.
|
||||
* @param string $message Text to display.
|
||||
*/
|
||||
function paintMessage($message) {
|
||||
if ($this->showpasses) {
|
||||
print_simple_box_start('', '100%');
|
||||
echo '<span class="notice">', $this->get_string('notice'), '</span>: ';
|
||||
$breadcrumb = $this->getTestList();
|
||||
array_shift($breadcrumb);
|
||||
echo implode($this->strseparator, $breadcrumb);
|
||||
echo $this->strseparator, '<br />', $message, "\n";
|
||||
print_simple_box_end();
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output anything that should appear above all the test output.
|
||||
*/
|
||||
function paintHeader($test_name) {
|
||||
// We do this the moodle way instead.
|
||||
}
|
||||
|
||||
/**
|
||||
* Output anything that should appear below all the test output, e.g. summary information.
|
||||
*/
|
||||
function paintFooter($test_name) {
|
||||
$summarydata = new stdClass;
|
||||
$summarydata->run = $this->getTestCaseProgress();
|
||||
$summarydata->total = $this->getTestCaseCount();
|
||||
$summarydata->passes = $this->getPassCount();
|
||||
$summarydata->fails = $this->getFailCount();
|
||||
$summarydata->exceptions = $this->getExceptionCount();
|
||||
|
||||
if ($summarydata->fails == 0 && $summarydata->exceptions == 0) {
|
||||
$status = "pass";
|
||||
} else {
|
||||
$status = "fail";
|
||||
}
|
||||
echo '<div class="unittestsummary ', $status, '">';
|
||||
echo $this->get_string('summary', $summarydata);
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="performanceinfo">',
|
||||
$this->get_string('runat', date('<b>d-m-Y H:i T</b>')),
|
||||
$this->get_string('version', SimpleTestOptions::getVersion()),
|
||||
'</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip a specified parameter from the query string of a URL, if present.
|
||||
* Adds a separator to the end of the URL, so that a new parameter
|
||||
* can easily be appended. For example (assuming $param = 'frog'):
|
||||
*
|
||||
* http://example.com/index.php -> http://example.com/index.php?
|
||||
* http://example.com/index.php?frog=1 -> http://example.com/index.php?
|
||||
* http://example.com/index.php?toad=1 -> http://example.com/index.php?toad=1&
|
||||
* http://example.com/index.php?frog=1&toad=1 -> http://example.com/index.php?toad=1&
|
||||
*
|
||||
* @param string $url the URL to modify.
|
||||
* @param string $param the parameter to strip from the URL, if present.
|
||||
*
|
||||
* @return string The modified URL.
|
||||
*/
|
||||
function _stripParameterFromUrl($url, $param) {
|
||||
$url = preg_replace('/(\?|&)' . $param . '=[^&]*&?/', '$1', $url);
|
||||
if (strpos($url, '?') === false) {
|
||||
$url = $url . '?';
|
||||
} else {
|
||||
$url = $url . '&';
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a lang string in the appropriate file.
|
||||
*/
|
||||
function get_string($identifier, $a = NULL) {
|
||||
return get_string($identifier, 'simpletest', $a);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,208 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* A SimpleTest GroupTest that automatically finds all the
|
||||
* test files in a directory tree according to certain rules.
|
||||
*
|
||||
* @copyright © 2006 The Open University
|
||||
* @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @version $Id$
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
|
||||
/** */
|
||||
require_once(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/simpletestlib/test_case.php');
|
||||
|
||||
/**
|
||||
* This is a composite test class for finding test cases and
|
||||
* other RunnableTest classes in a directory tree and combining
|
||||
* them into a group test.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class AutoGroupTest extends GroupTest {
|
||||
|
||||
var $thorough;
|
||||
var $showsearch;
|
||||
|
||||
function AutoGroupTest($showsearch, $thorough, $test_name = null) {
|
||||
$this->GroupTest($test_name);
|
||||
$this->showsearch = $showsearch;
|
||||
$this->thorough = $thorough;
|
||||
}
|
||||
|
||||
function setLabel($test_name) {
|
||||
//:HACK: there is no GroupTest::setLabel, so access parent::_label.
|
||||
$this->_label = $test_name;
|
||||
}
|
||||
|
||||
function addIgnoreFolder($ignorefolder) {
|
||||
$this->ignorefolders[]=$ignorefolder;
|
||||
}
|
||||
|
||||
function _recurseFolders($path) {
|
||||
if ($this->showsearch) {
|
||||
echo '<li>' . basename(realpath($path)) . '<ul>';
|
||||
}
|
||||
|
||||
$files = scandir($path);
|
||||
static $s_count = 0;
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file == '.' || $file == '..') {
|
||||
continue;
|
||||
}
|
||||
$file_path = $path . '/' . $file;
|
||||
if (is_dir($file_path)) {
|
||||
if ($file != 'CVS' && !in_array($file_path, $this->ignorefolders)) {
|
||||
$this->_recurseFolders($file_path);
|
||||
}
|
||||
} elseif (preg_match('/simpletest(\/|\\\\)test.*\.php$/', $file_path) ||
|
||||
($this->thorough && preg_match('/simpletest(\/|\\\\)slowtest.*\.php$/', $file_path))) {
|
||||
|
||||
$s_count++;
|
||||
// OK, found: this shows as a 'Notice' for any 'simpletest/test*.php' file.
|
||||
$this->addTestCase(new FindFileNotice($file_path, 'Found unit test file, '. $s_count));
|
||||
|
||||
// addTestFile: Unfortunately this doesn't return fail/success (bool).
|
||||
$this->addTestFile($file_path, true);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->showsearch) {
|
||||
echo '</ul></li>';
|
||||
}
|
||||
return $s_count;
|
||||
}
|
||||
|
||||
function findTestFiles($dir) {
|
||||
if ($this->showsearch) {
|
||||
echo '<p>Searching folder: ' . realpath($dir) . '</p><ul>';
|
||||
}
|
||||
$path = $dir;
|
||||
$count = $this->_recurseFolders($path);
|
||||
if ($count <= 0) {
|
||||
$this->addTestCase(new BadAutoGroupTest($path, 'Search complete. No unit test files found'));
|
||||
} else {
|
||||
$this->addTestCase(new AutoGroupTestNotice($path, 'Search complete. Total unit test files found: '. $count));
|
||||
}
|
||||
if ($this->showsearch) {
|
||||
echo '</ul>';
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
function addTestFile($file, $internalcall = false) {
|
||||
if ($this->showsearch) {
|
||||
if ($internalcall) {
|
||||
echo '<li><b>' . basename($file) . '</b></li>';
|
||||
} else {
|
||||
echo '<p>Adding test file: ' . realpath($file) . '</p>';
|
||||
}
|
||||
// Make sure that syntax errors show up suring the search, otherwise you often
|
||||
// get blank screens because evil people turn down error_reporting elsewhere.
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
if(!is_file($file) ){
|
||||
parent::addTestCase(new BadTest($file, 'Not a file or does not exist'));
|
||||
}
|
||||
parent::addTestFile($file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ======================================================================= */
|
||||
// get_class_ex: Insert spaces to prettify the class-name.
|
||||
function get_class_ex($object) {
|
||||
return preg_replace('/(.?)([A-Z])/', '${1} ${2}', get_class($object));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A failing test base-class for when a test suite has NOT loaded properly.
|
||||
* See class, simple_test.php: BadGroupTest.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class BadTest {
|
||||
|
||||
var $label;
|
||||
var $error;
|
||||
|
||||
function BadTest($label, $error) {
|
||||
$this->label = $label;
|
||||
$this->error = $error;
|
||||
}
|
||||
|
||||
function getLabel() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
function run(&$reporter) {
|
||||
$reporter->paintGroupStart(basename(__FILE__), $this->getSize());
|
||||
$reporter->paintFail(get_class_ex($this) .' [' . $this->getLabel() .
|
||||
'] with error [' . $this->error . ']');
|
||||
$reporter->paintGroupEnd($this->getLabel());
|
||||
return $reporter->getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int the number of test cases starting.
|
||||
*/
|
||||
function getSize() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An informational notice base-class for when a test suite is being processed.
|
||||
* See class, simple_test.php: BadGroupTest.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class Notice {
|
||||
|
||||
var $label;
|
||||
var $status;
|
||||
|
||||
function Notice($label, $error) {
|
||||
$this->label = $label;
|
||||
$this->status = $error;
|
||||
}
|
||||
|
||||
function getLabel() {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
function run(&$reporter) {
|
||||
$reporter->paintGroupStart(basename(__FILE__), $this->getSize());
|
||||
$reporter->paintNotice(get_class_ex($this) .
|
||||
' ['. $this->getLabel() .'] with status [' . $this->status . ']');
|
||||
$reporter->paintGroupEnd($this->getLabel());
|
||||
return $reporter->getStatus();
|
||||
}
|
||||
|
||||
function getSize() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A failing folder test for when the test-user specifies an invalid directory
|
||||
* (run.php?folder=woops).
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class BadFolderTest extends BadTest { }
|
||||
|
||||
/**
|
||||
* A failing auto test for when no unit test files are found.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class BadAutoGroupTest extends BadTest { }
|
||||
|
||||
/**
|
||||
* Auto group test notices - 1. Search complete. 2. A test file has been found.
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
class AutoGroupTestNotice extends Notice { }
|
||||
|
||||
class FindFileNotice extends Notice { }
|
||||
?>
|
||||
@@ -1,109 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Run the unit tests.
|
||||
*
|
||||
* @copyright © 2006 The Open University
|
||||
* @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @version $Id$
|
||||
* @package SimpleTestEx
|
||||
*/
|
||||
|
||||
/** */
|
||||
require_once(dirname(__FILE__) . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/moodlelib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once('ex_simple_test.php');
|
||||
require_once('ex_reporter.php');
|
||||
|
||||
require_login();
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
|
||||
/* The UNITTEST constant can be checked elsewhere if you need to know
|
||||
* when your code is being run as part of a unit test. */
|
||||
define('UNITTEST', true);
|
||||
$langfile = 'simpletest';
|
||||
|
||||
// CGI arguments
|
||||
$path = optional_param('path', null, PARAM_PATH);
|
||||
$showpasses = optional_param('showpasses', false, PARAM_BOOL);
|
||||
$showsearch = optional_param('showsearch', false, PARAM_BOOL);
|
||||
$thorough = optional_param('thorough', false, PARAM_BOOL);
|
||||
|
||||
// Print the header.
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('reportsimpletest', $adminroot);
|
||||
$strtitle = get_string('unittests', $langfile);
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
if (!is_null($path)) {
|
||||
// Create the group of tests.
|
||||
$test =& new AutoGroupTest($showsearch, $thorough);
|
||||
|
||||
// OU specific. We use the _nonproject folder for stuff we want to
|
||||
// keep in CVS, but which is not really relevant. It does no harm
|
||||
// to leave this here.
|
||||
$test->addIgnoreFolder($CFG->dirroot . '/_nonproject');
|
||||
|
||||
// Make the reporter, which is what displays the results.
|
||||
$reporter = new ExHtmlReporter($showpasses);
|
||||
|
||||
if ($showsearch) {
|
||||
print_heading('Searching for test cases');
|
||||
}
|
||||
flush();
|
||||
|
||||
// Work out what to test.
|
||||
if (substr($path, 0, 1) == '/') {
|
||||
$path = substr($path, 1);
|
||||
}
|
||||
$path = $CFG->dirroot . '/' . $path;
|
||||
if (substr($path, -1) == '/') {
|
||||
$path = substr($path, 0, -1);
|
||||
}
|
||||
$displaypath = substr($path, strlen($CFG->dirroot) + 1);
|
||||
$ok = true;
|
||||
if (is_file($path)) {
|
||||
$test->addTestFile($path);
|
||||
} else if (is_dir($path)){
|
||||
$test->findTestFiles($path);
|
||||
} else {
|
||||
print_simple_box(get_string('pathdoesnotexist', $langfile, $path), '', '', '', '', 'errorbox');
|
||||
$ok = false;
|
||||
}
|
||||
|
||||
// If we have something to test, do it.
|
||||
if ($ok) {
|
||||
if ($path == $CFG->dirroot) {
|
||||
$title = get_string('moodleunittests', $langfile, get_string('all', $langfile));
|
||||
} else {
|
||||
$title = get_string('moodleunittests', $langfile, $displaypath);
|
||||
}
|
||||
print_heading($title);
|
||||
$test->run($reporter);
|
||||
}
|
||||
|
||||
$formheader = get_string('retest', $langfile);
|
||||
} else {
|
||||
$displaypath = '';
|
||||
$formheader = get_string('rununittests', $langfile);
|
||||
}
|
||||
// Print the form for adjusting options.
|
||||
print_simple_box_start('center', '70%');
|
||||
echo '<form method="GET" action="index.php">';
|
||||
print_heading($formheader);
|
||||
echo '<p>'; print_checkbox('showpasses', 1, $showpasses, get_string('showpasses', $langfile)); echo '</p>';
|
||||
echo '<p>'; print_checkbox('showsearch', 1, $showsearch, get_string('showsearch', $langfile)); echo '</p>';
|
||||
echo '<p>'; print_checkbox('thorough', 1, $thorough, get_string('thorough', $langfile)); echo '</p>';
|
||||
echo '<p>';
|
||||
echo '<label for="path">', get_string('onlytest', $langfile), '</label> ';
|
||||
echo '<input type="text" id="path" name="path" value="', $displaypath, '" size="60" />';
|
||||
echo '</p>';
|
||||
echo '<input type="submit" value="' . get_string('runtests', $langfile) . '" />';
|
||||
echo '</form>';
|
||||
print_simple_box_end();
|
||||
|
||||
// Footer.
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
?>
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once($CFG->dirroot.'/lib/statslib.php');
|
||||
require_once($CFG->dirroot.'/course/report/stats/lib.php');
|
||||
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
|
||||
admin_externalpage_setup('reportstats', $adminroot);
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
|
||||
$courseid = optional_param('course', SITEID, PARAM_INT);
|
||||
$report = optional_param('report', 0, PARAM_INT);
|
||||
$time = optional_param('time', 0, PARAM_INT);
|
||||
$mode = optional_param('mode', STATS_MODE_GENERAL, PARAM_INT);
|
||||
$userid = optional_param('userid', 0, PARAM_INT);
|
||||
$roleid = 0;
|
||||
|
||||
if ($report > 50) {
|
||||
$roleid = substr($report,1);
|
||||
$report = 5;
|
||||
}
|
||||
|
||||
if ($report == STATS_REPORT_USER_LOGINS) {
|
||||
$courseid = SITEID; //override
|
||||
}
|
||||
|
||||
if ($mode == STATS_MODE_RANKED) {
|
||||
redirect($CFG->wwwroot.'/'.$CFG->admin.'/report/stats/index.php?time='.$time);
|
||||
}
|
||||
|
||||
if (!$course = get_record("course","id",$courseid)) {
|
||||
error("That's an invalid course id");
|
||||
}
|
||||
|
||||
if (!empty($userid)) {
|
||||
if (!$user = get_record('user','id',$userid)) {
|
||||
error("That's an invalid user id");
|
||||
}
|
||||
}
|
||||
|
||||
require_login();
|
||||
|
||||
if (empty($CFG->enablestats)) {
|
||||
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'));
|
||||
}
|
||||
|
||||
require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $course->id));
|
||||
|
||||
add_to_log($course->id, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id);
|
||||
|
||||
stats_check_uptodate($course->id);
|
||||
|
||||
|
||||
// $strreports = get_string("reports");
|
||||
// $strstats = get_string('stats');
|
||||
//
|
||||
// $menu = report_stats_mode_menu($course, $mode, $time);
|
||||
//
|
||||
//
|
||||
// $crumb = "<a href=\"{$CFG->wwwroot}/admin\">".get_string('administration')."</a> ->
|
||||
// <a href=\"{$CFG->wwwroot}/admin/report.php\">$strreports</a> ->
|
||||
// $strstats";
|
||||
|
||||
// print_header("$course->shortname: $strstats", "$course->fullname",
|
||||
// $crumb, '', '', true, ' ', $menu);
|
||||
|
||||
|
||||
require_once($CFG->dirroot.'/course/report/stats/report.php');
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
?>
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* this page defines what roles can access (grant user that role and override that roles'
|
||||
* capabilities in different context. For example, we can say that Teachers can only grant
|
||||
* student role or modify student role's capabilities. Note that you need both the right
|
||||
* capability moodle/role:assign or moodle/role:manage and this database table roles_deny_grant
|
||||
* to be able to grant roles. If a user has moodle/role:manage at site level assignment
|
||||
* then he can modify the roles_allow_assign table via this interface.
|
||||
*/
|
||||
require_once('../../config.php');
|
||||
/// check capabilities here
|
||||
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('defineroles', $adminroot);
|
||||
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
require_capability('moodle/role:manage', $sitecontext);
|
||||
|
||||
/// form processiong here
|
||||
|
||||
/// get all roles
|
||||
|
||||
$roles = get_all_roles();
|
||||
|
||||
if ($grant = data_submitted()) {
|
||||
|
||||
foreach ($grant as $grole => $val) {
|
||||
if ($grole == 'dummy') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$string = explode('_', $grole);
|
||||
$temp[$string[1]][$string[2]] = 1; // if set, means can access
|
||||
}
|
||||
|
||||
// if current assignment is in data_submitted, ignore, else, write deny into db
|
||||
foreach ($roles as $srole) {
|
||||
foreach ($roles as $trole) {
|
||||
if (isset($temp[$srole->id][$trole->id])) { // if set, need to write to db
|
||||
if (!$record = get_record('role_allow_assign', 'roleid', $srole->id, 'allowassign', $trole->id)) {
|
||||
allow_assign($srole->id, $trole->id);
|
||||
}
|
||||
} else { //if set, means can access, attempt to remove it from db
|
||||
delete_records('role_allow_assign', 'roleid', $srole->id, 'allowassign', $trole->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// displaying form here
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
$currenttab='allowassign';
|
||||
require_once('managetabs.php');
|
||||
|
||||
$table->tablealign = 'center';
|
||||
$table->cellpadding = 5;
|
||||
$table->cellspacing = 0;
|
||||
$table->width = '90%';
|
||||
$table->align[] = 'right';
|
||||
|
||||
/// get all the roles identifier
|
||||
foreach ($roles as $role) {
|
||||
$rolesname[] = format_string($role->name);
|
||||
$roleids[] = $role->id;
|
||||
$table->align[] = 'center';
|
||||
$table->wrap[] = 'nowrap';
|
||||
}
|
||||
|
||||
$table->head = array_merge(array(''), $rolesname);
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$beta = get_box_list($role->id, $roleids);
|
||||
$table->data[] = array_merge(array(format_string($role->name)), $beta);
|
||||
}
|
||||
|
||||
print_simple_box(get_string('configallowassign', 'admin'), 'center');
|
||||
|
||||
echo '<form action="allowassign.php" method="post">';
|
||||
print_table($table);
|
||||
echo '<div class="singlebutton"><input type="submit" value="'.get_string('savechanges').'"/></div>';
|
||||
echo '<input type="hidden" name="dummy" value="1" />'; // this is needed otherwise we do not know a form has been submitted
|
||||
echo '</form>';
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
|
||||
|
||||
function get_box_list($roleid, $arraylist){
|
||||
|
||||
foreach ($arraylist as $targetid) {
|
||||
if (get_record('role_allow_assign', 'roleid', $roleid, 'allowassign', $targetid)) {
|
||||
$array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" checked="checked"/>';
|
||||
} else {
|
||||
$array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" />';
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
?>
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* this page defines what roles can override (override roles in different context. For example,
|
||||
* we can say that Admin can override teacher roles in a course
|
||||
* To be able to override roles. If a user has moodle/role:override at context level
|
||||
* and be in the roles_allow_override table.
|
||||
*/
|
||||
require_once('../../config.php');
|
||||
/// check capabilities here
|
||||
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('defineroles', $adminroot);
|
||||
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
require_capability('moodle/role:manage', $sitecontext);
|
||||
|
||||
/// form processiong here
|
||||
|
||||
/// get all roles
|
||||
|
||||
$roles = get_all_roles();
|
||||
|
||||
if ($grant = data_submitted()) {
|
||||
|
||||
foreach ($grant as $grole => $val) {
|
||||
if ($grole == 'dummy') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$string = explode('_', $grole);
|
||||
$temp[$string[1]][$string[2]] = 1; // if set, means can access
|
||||
}
|
||||
|
||||
// if current assignment is in data_submitted, ignore, else, write deny into db
|
||||
foreach ($roles as $srole) {
|
||||
foreach ($roles as $trole) {
|
||||
if (isset($temp[$srole->id][$trole->id])) { // if set, need to write to db
|
||||
if (!$record = get_record('role_allow_override', 'roleid', $srole->id, 'allowoverride', $trole->id)) {
|
||||
allow_override($srole->id, $trole->id);
|
||||
}
|
||||
} else { //if set, means can access, attempt to remove it from db
|
||||
delete_records('role_allow_override', 'roleid', $srole->id, 'allowoverride', $trole->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// displaying form here
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
$currenttab='allowoverride';
|
||||
require_once('managetabs.php');
|
||||
|
||||
$table->tablealign = 'center';
|
||||
$table->cellpadding = 5;
|
||||
$table->cellspacing = 0;
|
||||
$table->width = '90%';
|
||||
$table->align[] = 'right';
|
||||
|
||||
/// get all the roles identifier
|
||||
foreach ($roles as $role) {
|
||||
$rolesname[] = format_string($role->name);
|
||||
$roleids[] = $role->id;
|
||||
$table->align[] = 'center';
|
||||
$table->wrap[] = 'nowrap';
|
||||
}
|
||||
|
||||
$table->head = array_merge(array(''), $rolesname);
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$beta = get_box_list($role->id, $roleids);
|
||||
$table->data[] = array_merge(array(format_string($role->name)), $beta);
|
||||
}
|
||||
|
||||
print_simple_box(get_string('configallowoverride', 'admin'), 'center');
|
||||
|
||||
echo '<form action="allowoverride.php" method="post">';
|
||||
print_table($table);
|
||||
echo '<div class="singlebutton"><input type="submit" value="'.get_string('savechanges').'"/></div>';
|
||||
echo '<input type="hidden" name="dummy" value="1" />'; // this is needed otherwise we do not know a form has been submitted
|
||||
echo '</form>';
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
// returns array
|
||||
function get_box_list($roleid, $arraylist){
|
||||
|
||||
foreach ($arraylist as $targetid) {
|
||||
if (get_record('role_allow_override', 'roleid', $roleid, 'allowoverride', $targetid)) {
|
||||
$array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" checked="checked"/>';
|
||||
} else {
|
||||
$array[] = '<input type="checkbox" name="s_'.$roleid.'_'.$targetid.'" value="1" />';
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
?>
|
||||
@@ -1,98 +0,0 @@
|
||||
|
||||
<form name="assignform" id="assignform" method="post" action="">
|
||||
<input type="hidden" name="previoussearch" value="<?php p($previoussearch) ?>" />
|
||||
<input type="hidden" name="userid" value="<?php p($userid) ?>" />
|
||||
<input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
|
||||
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
|
||||
<input type="hidden" name="contextid" value="<?php p($contextid) ?>" />
|
||||
<input type="hidden" name="roleid" value="<?php p($roleid) ?>" />
|
||||
<table align="center" border="0" cellpadding="5" cellspacing="0">
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<?php print_string('existingusers', 'role', count($contextusers)); ?>
|
||||
</td>
|
||||
<td></td>
|
||||
<td valign="top">
|
||||
<?php print_string('potentialusers', 'role', $usercount); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<select name="removeselect[]" size="20" id="removeselect" multiple
|
||||
onFocus="document.assignform.add.disabled=true;
|
||||
document.assignform.remove.disabled=false;
|
||||
document.assignform.addselect.selectedIndex=-1;" />
|
||||
<?php
|
||||
foreach ($contextusers as $contextuser) {
|
||||
$fullname = fullname($contextuser, true);
|
||||
echo "<option value=\"$contextuser->id\">".$fullname.", ".$contextuser->email."</option>\n";
|
||||
}
|
||||
?>
|
||||
|
||||
</select></td>
|
||||
<td valign="top">
|
||||
<br />
|
||||
<input name="add" type="submit" id="add" value="←" />
|
||||
<br />
|
||||
<input name="remove" type="submit" id="remove" value="→" />
|
||||
<br />
|
||||
</td>
|
||||
<td valign="top">
|
||||
<select name="addselect[]" size="20" id="addselect" multiple
|
||||
onFocus="document.assignform.add.disabled=false;
|
||||
document.assignform.remove.disabled=true;
|
||||
document.assignform.removeselect.selectedIndex=-1;">
|
||||
<?php
|
||||
|
||||
if (!empty($searchtext)) {
|
||||
echo "<optgroup label=\"$strsearchresults (" . $availableusers->_numOfRows . ")\">\n";
|
||||
while (! $availableusers->EOF) {
|
||||
$user = $availableusers->FetchObj();
|
||||
if (!isset($contextusers[$user->id])) {
|
||||
$fullname = fullname($user, true);
|
||||
echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
|
||||
}
|
||||
$availableusers->MoveNext();
|
||||
}
|
||||
echo "</optgroup>\n";
|
||||
|
||||
} else {
|
||||
if ($usercount > MAX_USERS_PER_PAGE) {
|
||||
echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
|
||||
.'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
|
||||
} else {
|
||||
while (! $availableusers->EOF) {
|
||||
$user = $availableusers->FetchObj();
|
||||
if (!isset($contextusers[$user->id])) {
|
||||
$fullname = fullname($user, true);
|
||||
echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
|
||||
}
|
||||
$availableusers->MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br />
|
||||
<input type="text" name="searchtext" size="30" value="<?php p($searchtext, true) ?>"
|
||||
onFocus ="document.assignform.add.disabled=true;
|
||||
document.assignform.remove.disabled=true;
|
||||
document.assignform.removeselect.selectedIndex=-1;
|
||||
document.assignform.addselect.selectedIndex=-1;"
|
||||
onkeydown = "var keyCode = event.which ? event.which : event.keyCode;
|
||||
if (keyCode == 13) {
|
||||
document.assignform.previoussearch.value=1;
|
||||
document.assignform.submit();
|
||||
} " />
|
||||
<input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
|
||||
<?php
|
||||
if (!empty($searchusers)) {
|
||||
echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -1,285 +0,0 @@
|
||||
<?php // $Id$
|
||||
// Script to assign users to contexts
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->dirroot.'/mod/forum/lib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
define("MAX_USERS_PER_PAGE", 5000);
|
||||
|
||||
$contextid = required_param('contextid',PARAM_INT); // context id
|
||||
$roleid = optional_param('roleid', 0, PARAM_INT); // required role id
|
||||
$add = optional_param('add', 0, PARAM_BOOL);
|
||||
$remove = optional_param('remove', 0, PARAM_BOOL);
|
||||
$showall = optional_param('showall', 0, PARAM_BOOL);
|
||||
$searchtext = optional_param('searchtext', '', PARAM_RAW); // search string
|
||||
$previoussearch = optional_param('previoussearch', 0, PARAM_BOOL);
|
||||
$hidden = optional_param('hidden', 0, PARAM_BOOL); // whether this assignment is hidden
|
||||
$timestart = optional_param('timestart', 0, PARAM_INT);
|
||||
$timeend = optional_param('timened', 0, PARAM_INT);
|
||||
$userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs
|
||||
$courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
|
||||
|
||||
$errors = array();
|
||||
|
||||
$previoussearch = ($searchtext != '') or ($previoussearch) ? 1:0;
|
||||
|
||||
$baseurl = 'assign.php?contextid='.$contextid;
|
||||
if (!empty($userid)) {
|
||||
$baseurl .= '&userid='.$userid;
|
||||
}
|
||||
if (!empty($courseid)) {
|
||||
$baseurl .= '&courseid='.$courseid;
|
||||
}
|
||||
|
||||
if (! $context = get_context_instance_by_id($contextid)) {
|
||||
error("Context ID was incorrect (can't find it)");
|
||||
}
|
||||
|
||||
|
||||
$inmeta = 0;
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
$courseid = $context->instanceid;
|
||||
if ($course = get_record('course', 'id', $courseid)) {
|
||||
$inmeta = $course->metacourse;
|
||||
} else {
|
||||
error('Invalid course id');
|
||||
}
|
||||
} else if (!empty($courseid)){ // we need this for user tabs in user context
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
error('Invalid course id');
|
||||
}
|
||||
} else {
|
||||
$courseid = SITEID;
|
||||
$course = get_site();
|
||||
}
|
||||
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
require_login($context->instanceid);
|
||||
} else {
|
||||
require_login();
|
||||
}
|
||||
|
||||
require_capability('moodle/role:assign', $context);
|
||||
|
||||
$assignableroles = get_assignable_roles($context);
|
||||
|
||||
/// Get some language strings
|
||||
|
||||
$strassignusers = get_string('assignusers', 'role');
|
||||
$strpotentialusers = get_string('potentialusers', 'role');
|
||||
$strexistingusers = get_string('existingusers', 'role');
|
||||
$straction = get_string('assignroles', 'role');
|
||||
$strroletoassign = get_string('roletoassign', 'role');
|
||||
$strcurrentcontext = get_string('currentcontext', 'role');
|
||||
$strsearch = get_string('search');
|
||||
$strshowall = get_string('showall');
|
||||
$strparticipants = get_string('participants');
|
||||
$strsearchresults = get_string('searchresults');
|
||||
|
||||
|
||||
|
||||
/// Make sure this user can assign that role
|
||||
|
||||
if ($roleid) {
|
||||
if (!user_can_assign($context, $roleid)) {
|
||||
error ('you can not override this role in this context');
|
||||
}
|
||||
}
|
||||
|
||||
if ($userid) {
|
||||
$user = get_record('user', 'id', $userid);
|
||||
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
|
||||
}
|
||||
|
||||
|
||||
/// Print the header and tabs
|
||||
|
||||
if ($context->contextlevel == CONTEXT_USER) {
|
||||
/// course header
|
||||
if ($courseid != SITEID) {
|
||||
print_header("$fullname", "$fullname",
|
||||
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
|
||||
<a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"$CFG->wwwroot/user/view.php?id=$userid&course=$courseid\">$fullname</a> ->".$straction,
|
||||
"", "", true, " ", navmenu($course));
|
||||
|
||||
/// site header
|
||||
} else {
|
||||
print_header("$course->fullname: $fullname", "$course->fullname",
|
||||
"<a href=\"$CFG->wwwroot/user/view.php?id=$userid&course=$courseid\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
|
||||
}
|
||||
|
||||
$showroles = 1;
|
||||
$currenttab = 'assign';
|
||||
include_once($CFG->dirroot.'/user/tabs.php');
|
||||
} else if ($context->contextlevel == CONTEXT_SYSTEM) {
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('assignroles', $adminroot);
|
||||
admin_externalpage_print_header($adminroot);
|
||||
} else {
|
||||
$currenttab = '';
|
||||
$tabsmode = 'assign';
|
||||
include_once('tabs.php');
|
||||
}
|
||||
|
||||
|
||||
/// Process incoming role assignment
|
||||
|
||||
if ($frm = data_submitted()) {
|
||||
|
||||
if ($add and !empty($frm->addselect) and confirm_sesskey()) {
|
||||
|
||||
$timemodified = time();
|
||||
|
||||
foreach ($frm->addselect as $adduser) {
|
||||
if (!$adduser = clean_param($adduser, PARAM_INT)) {
|
||||
continue;
|
||||
}
|
||||
$allow = true;
|
||||
if ($inmeta) {
|
||||
if (has_capability('moodle/course:managemetacourse', $context, $adduser)) {
|
||||
//ok
|
||||
} else {
|
||||
$managerroles = get_roles_with_capability('moodle/course:managemetacourse', CAP_ALLOW, $context);
|
||||
if (!empty($managerroles) and !array_key_exists($roleid, $managerroles)) {
|
||||
$erruser = get_record('user', 'id', $adduser, '','','','', 'id, firstname, lastname');
|
||||
$errors[] = get_string('metaassignerror', 'role', fullname($erruser));
|
||||
$allow = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($allow) {
|
||||
if (! role_assign($roleid, $adduser, 0, $context->id, $timestart, $timeend, $hidden)) {
|
||||
$errors[] = "Could not add user with id $adduser to this role!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if ($remove and !empty($frm->removeselect) and confirm_sesskey()) {
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$topleveladmin = false;
|
||||
|
||||
// we only worry about this if the role has doanything capability at site level
|
||||
if ($adminroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $sitecontext)) {
|
||||
foreach ($adminroles as $adminrole) {
|
||||
if ($adminrole->id == $roleid) {
|
||||
$topleveladmin = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($frm->removeselect as $removeuser) {
|
||||
$removeuser = clean_param($removeuser, PARAM_INT);
|
||||
|
||||
if ($topleveladmin && ($removeuser == $USER->id)) { // Prevent unassigning oneself from being admin
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! role_unassign($roleid, $removeuser, 0, $context->id)) {
|
||||
$errors[] = "Could not remove user with id $removeuser from this role!";
|
||||
} else if ($inmeta) {
|
||||
sync_metacourse($courseid);
|
||||
$newroles = get_user_roles($context, $removeuser, false);
|
||||
if (!empty($newroles) and !array_key_exists($roleid, $newroles)) {
|
||||
$erruser = get_record('user', 'id', $removeuser, '','','','', 'id, firstname, lastname');
|
||||
$errors[] = get_string('metaunassignerror', 'role', fullname($erruser));
|
||||
$allow = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if ($showall) {
|
||||
$searchtext = '';
|
||||
$previoussearch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print_heading_with_help(get_string('assignroles', 'role'), 'assignroles');
|
||||
|
||||
if ($roleid) { /// prints a form to swap roles
|
||||
|
||||
/// Get all existing participants in this context.
|
||||
// Why is this not done with get_users???
|
||||
|
||||
if (!$contextusers = get_role_users($roleid, $context, false, 'u.id, u.firstname, u.lastname, u.email')) {
|
||||
$contextusers = array();
|
||||
}
|
||||
|
||||
$select = "username <> 'guest' AND username <> 'changeme' AND deleted = 0 AND confirmed = 1";
|
||||
|
||||
$usercount = count_records_select('user', $select) - count($contextusers);
|
||||
|
||||
$searchtext = trim($searchtext);
|
||||
|
||||
if ($searchtext !== '') { // Search for a subset of remaining users
|
||||
$LIKE = sql_ilike();
|
||||
$FULLNAME = sql_fullname();
|
||||
|
||||
$select .= " AND ($FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%') ";
|
||||
}
|
||||
|
||||
$availableusers = get_recordset_sql('SELECT id, firstname, lastname, email
|
||||
FROM '.$CFG->prefix.'user
|
||||
WHERE '.$select.'
|
||||
ORDER BY lastname ASC, firstname ASC');
|
||||
|
||||
/// In the .html file below we loop through these results and exclude any in $contextusers
|
||||
|
||||
echo '<form name="rolesform" action="assign.php" method="post">';
|
||||
echo '<div align="center">'.$strcurrentcontext.': '.print_context_name($context).'<br/>';
|
||||
if ($userid) {
|
||||
echo '<input type="hidden" name="userid" value="'.$userid.'" />';
|
||||
}
|
||||
echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
|
||||
echo '<input type="hidden" name="contextid" value="'.$context->id.'" />'.$strroletoassign.': ';
|
||||
choose_from_menu ($assignableroles, 'roleid', $roleid, get_string('listallroles', 'role').'...', $script='rolesform.submit()');
|
||||
echo '</div></form>';
|
||||
|
||||
print_simple_box_start('center');
|
||||
include('assign.html');
|
||||
print_simple_box_end();
|
||||
|
||||
if (!empty($errors)) {
|
||||
$msg = '<p>';
|
||||
foreach ($errors as $e) {
|
||||
$msg .= $e.'<br />';
|
||||
}
|
||||
$msg .= '</p>';
|
||||
print_simple_box_start('center');
|
||||
notify($msg);
|
||||
print_simple_box_end();
|
||||
}
|
||||
|
||||
} else { // Print overview table
|
||||
|
||||
// sync metacourse enrolments if needed
|
||||
if ($inmeta) {
|
||||
sync_metacourse($course);
|
||||
}
|
||||
|
||||
$table->tablealign = 'center';
|
||||
$table->cellpadding = 5;
|
||||
$table->cellspacing = 0;
|
||||
$table->width = '60%';
|
||||
$table->head = array(get_string('roles', 'role'), get_string('description'), get_string('users'));
|
||||
$table->wrap = array('nowrap', '', 'nowrap');
|
||||
$table->align = array('right', 'left', 'center');
|
||||
|
||||
foreach ($assignableroles as $roleid => $rolename) {
|
||||
$countusers = count_role_users($roleid, $context);
|
||||
$description = format_string(get_field('role', 'description', 'id', $roleid));
|
||||
$table->data[] = array('<a href="'.$baseurl.'&roleid='.$roleid.'">'.$rolename.'</a>',$description, $countusers);
|
||||
}
|
||||
|
||||
print_table($table);
|
||||
}
|
||||
|
||||
if ($context->contextlevel == CONTEXT_SYSTEM) {
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
} else {
|
||||
print_footer($course);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,157 +0,0 @@
|
||||
<?php //$Id$
|
||||
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
$submitlabel = get_string('addrole', 'role');
|
||||
break;
|
||||
case 'view':
|
||||
$submitlabel = get_string('listallroles', 'role');
|
||||
break;
|
||||
case 'edit':
|
||||
default:
|
||||
$submitlabel = get_string('savechanges');
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<form name="rolesform" action="manage.php" method="post">
|
||||
<input type="hidden" name="roleid" value="<?php p($roleid) ?>" />
|
||||
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
|
||||
<input type="hidden" name="action" value="<?php if ($action != 'view') { echo p($action); } ?>" />
|
||||
|
||||
<table cellpadding="9" cellspacing="0" align="center">
|
||||
<tr valign="top">
|
||||
<td align="right"><?php print_string('name') ?>:</td>
|
||||
<td><?php
|
||||
if ($action == 'view') {
|
||||
p($role->name);
|
||||
} else {
|
||||
echo '<input type="text" name="name" maxlength="254" size="50" value="'.s($role->name).'" />';
|
||||
if (isset($errors["name"])) formerr($errors["name"]);
|
||||
} ?></td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><?php print_string('shortname') ?>:</td>
|
||||
<td><?php
|
||||
if ($action == 'view') {
|
||||
p($role->shortname);
|
||||
} else {
|
||||
echo '<input type="text" name="shortname" maxlength="20" size="15" value="'.s($role->shortname).'" />';
|
||||
if (isset($errors["shortname"])) formerr($errors["shortname"]);
|
||||
} ?></td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><?php print_string('description') ?>:</td>
|
||||
<td><?php
|
||||
if ($action == 'view') {
|
||||
p($role->description);
|
||||
$usehtmleditor = false;
|
||||
} else {
|
||||
print_textarea($usehtmleditor, 10, 50, 50, 10, 'description', $role->description);
|
||||
} ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
print_heading_with_help(get_string('permissions','role'), 'permissions');
|
||||
|
||||
$strinherit = get_string('inherit','role');
|
||||
$strallow = get_string('allow','role');
|
||||
$strprevent = get_string('prevent','role');
|
||||
$strprohibit = get_string('prohibit','role');
|
||||
?>
|
||||
|
||||
<table class="rolecap" align="center">
|
||||
|
||||
<tr>
|
||||
<th class="name" align="left"><?php print_string('capability','role') ?></th>
|
||||
<th class="inherit"><?php p($strinherit); ?></th>
|
||||
<th class="allow"><?php p($strallow); ?></th>
|
||||
<th class="prevent"><?php p($strprevent); ?></th>
|
||||
<th class="prohibit"><?php p($strprohibit); ?></th>
|
||||
<th class="risk" colspan="5"><?php print_string('risks','role') ?></th>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
|
||||
// init these 2
|
||||
$contextlevel = 0;
|
||||
$component = '';
|
||||
|
||||
$strrisks = s(get_string('risks', 'role'));
|
||||
$strcapabilities = s(get_string('capabilities', 'role'));
|
||||
|
||||
foreach ($capabilities as $capability) {
|
||||
// prints a breaker if component or name or context level
|
||||
if ($capability->component != $component or $capability->contextlevel != $contextlevel) {
|
||||
echo ('<tr class="rolecapheading header"><td colspan="10" class="header"><strong>'.
|
||||
get_component_string($capability->component, $capability->contextlevel).'</strong></td></tr>');
|
||||
}
|
||||
|
||||
// these 2 are used to see to group same mod/core capabilities together
|
||||
$contextlevel = $capability->contextlevel;
|
||||
$component = $capability->component;
|
||||
|
||||
if (empty($errors)) {
|
||||
// check the capability override for this cap, this role in this context
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
$localoverride = get_local_override($roleid, $sitecontext->id, $capability->name);
|
||||
} else {
|
||||
$localoverride = new object();
|
||||
$localoverride->permission = $role->{$capability->name};
|
||||
}
|
||||
|
||||
$disabled = ($action != 'edit' and $action != 'add') ? ' disabled="disabled" ' : '';
|
||||
|
||||
$riskinfo = '<td class="risk managetrust">';
|
||||
$rowclasses = '';
|
||||
if (RISK_MANAGETRUST & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskmanagetrust', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">T</a>';
|
||||
$rowclasses .= ' riskmanagetrust';
|
||||
}
|
||||
$riskinfo .= '</td><td class="risk config">';
|
||||
if (RISK_CONFIG & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskconfig', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">C</a>';
|
||||
$rowclasses .= ' riskconfig';
|
||||
}
|
||||
$riskinfo .= '</td><td class="risk xss">';
|
||||
if (RISK_XSS & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskxss', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">X</a>';
|
||||
$rowclasses .= ' riskxss';
|
||||
}
|
||||
$riskinfo .= '</td><td class="risk personal">';
|
||||
if (RISK_PERSONAL & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskpersonal', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">P</a>';
|
||||
$rowclasses .= ' riskpersonal';
|
||||
}
|
||||
$riskinfo .= '</td><td class="risk spam">';
|
||||
if (RISK_SPAM & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskspam', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">S</a>';
|
||||
$rowclasses .= ' riskspam';
|
||||
}
|
||||
$riskinfo .= '</td>';
|
||||
|
||||
?>
|
||||
|
||||
<tr class="rolecap <?php echo $rowclasses; ?>">
|
||||
<td class="name"><span class="cap-desc"><a target="docspopup" href="<?php echo $CFG->docroot.'/'.$lang.'/'.$strcapabilities.'/'.$capability->name ?>"><?php echo get_capability_string($capability->name); ?></a><span class="cap-name"><?php echo $capability->name ?></span></label></td>
|
||||
<td class="inherit"><input type="radio" title="<?php p($strinherit); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_INHERIT ?>" <?php if (!isset($localoverride->permission) || $localoverride->permission==CAP_INHERIT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
|
||||
<td class="allow"><input type="radio" title="<?php p($strallow); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_ALLOW ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_ALLOW){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
|
||||
<td class="prevent" ><input type="radio" title="<?php p($strprevent); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_PREVENT ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_PREVENT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
|
||||
<td class="prohibit" ><input type="radio" title="<?php p($strprohibit); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_PROHIBIT ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_PROHIBIT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
|
||||
|
||||
<?php echo $riskinfo; ?>
|
||||
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
</table>
|
||||
|
||||
<div class="submit" align="center">
|
||||
<input type="submit" value="<?php p($submitlabel) ?>" />
|
||||
<?php if ($action != 'view') { ?>
|
||||
<input type="submit" name="cancel" value="<?php print_string('cancel') ?>" />
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
@@ -1,420 +0,0 @@
|
||||
<?php //$Id$
|
||||
|
||||
require_once('../../config.php');
|
||||
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
|
||||
admin_externalpage_setup('defineroles', $adminroot);
|
||||
|
||||
$roleid = optional_param('roleid', 0, PARAM_INT); // if set, we are editing a role
|
||||
$name = optional_param('name', '', PARAM_MULTILANG); // new role name
|
||||
$shortname = optional_param('shortname', '', PARAM_RAW); // new role shortname, special cleaning before storage
|
||||
$description = optional_param('description', '', PARAM_CLEAN); // new role desc
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
$cancel = optional_param('cancel', 0, PARAM_BOOL);
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
|
||||
if ($cancel) {
|
||||
redirect('manage.php');
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
$newrole = false;
|
||||
|
||||
$roles = get_all_roles();
|
||||
$rolescount = count($roles);
|
||||
|
||||
/// fix sort order if needed
|
||||
$rolesort = array();
|
||||
$i = 0;
|
||||
foreach ($roles as $rolex) {
|
||||
$rolesort[$i] = $rolex->id;
|
||||
if ($rolex->sortorder != $i) {
|
||||
$r = new object();
|
||||
$r->id = $rolex->id;
|
||||
$r->sortorder = $i;
|
||||
update_record('role', $r);
|
||||
$roles[$rolex->id]->sortorder = $i;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
/// form processing, editing a role, adding a role, deleting a role etc.
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
if ($data = data_submitted() and confirm_sesskey()) {
|
||||
|
||||
$shortname = moodle_strtolower(clean_param(clean_filename($shortname), PARAM_SAFEDIR)); // only lowercase safe ASCII characters
|
||||
|
||||
if (empty($name)) {
|
||||
$errors['name'] = get_string('errorbadrolename', 'role');
|
||||
} else if (count_records('role', 'name', $name)) {
|
||||
$errors['name'] = get_string('errorexistsrolename', 'role');
|
||||
}
|
||||
|
||||
if (empty($shortname)) {
|
||||
$errors['shortname'] = get_string('errorbadroleshortname', 'role');
|
||||
} else if (count_records('role', 'shortname', $shortname)) {
|
||||
$errors['shortname'] = get_string('errorexistsroleshortname', 'role');
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
$newrole = create_role($name, $shortname, $description);
|
||||
} else {
|
||||
$newrole = new object();
|
||||
$newrole->name = $name;
|
||||
$newrole->shortname = $shortname;
|
||||
$newrole->description = $description;
|
||||
}
|
||||
|
||||
$allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT);
|
||||
$capabilities = fetch_context_capabilities($sitecontext); // capabilities applicable in this context
|
||||
|
||||
foreach ($capabilities as $cap) {
|
||||
if (!isset($data->{$cap->name})) {
|
||||
continue;
|
||||
}
|
||||
$capname = $cap->name;
|
||||
$value = clean_param($data->{$cap->name}, PARAM_INT);
|
||||
if (!in_array($value, $allowed_values)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
assign_capability($capname, $value, $newrole, $sitecontext->id);
|
||||
} else {
|
||||
$newrole->$capname = $value;
|
||||
}
|
||||
}
|
||||
if (empty($errors)) {
|
||||
redirect('manage.php');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
if ($data = data_submitted() and confirm_sesskey()) {
|
||||
|
||||
$shortname = moodle_strtolower(clean_param(clean_filename($shortname), PARAM_SAFEDIR)); // only lowercase safe ASCII characters
|
||||
|
||||
if (empty($name)) {
|
||||
$errors['name'] = get_string('errorbadrolename', 'role');
|
||||
} else if ($rs = get_records('role', 'name', $name)) {
|
||||
unset($rs[$roleid]);
|
||||
if (!empty($rs)) {
|
||||
$errors['name'] = get_string('errorexistsrolename', 'role');
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($shortname)) {
|
||||
$errors['shortname'] = get_string('errorbadroleshortname', 'role');
|
||||
} else if ($rs = get_records('role', 'shortname', $shortname)) {
|
||||
unset($rs[$roleid]);
|
||||
if (!empty($rs)) {
|
||||
$errors['shortname'] = get_string('errorexistsroleshortname', 'role');
|
||||
}
|
||||
}
|
||||
if (!empty($errors)) {
|
||||
$newrole = new object();
|
||||
$newrole->name = $name;
|
||||
$newrole->shortname = $shortname;
|
||||
$newrole->description = $description;
|
||||
}
|
||||
|
||||
$allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT);
|
||||
$capabilities = fetch_context_capabilities($sitecontext); // capabilities applicable in this context
|
||||
|
||||
foreach ($capabilities as $cap) {
|
||||
if (!isset($data->{$cap->name})) {
|
||||
continue;
|
||||
}
|
||||
$capname = $cap->name;
|
||||
$value = clean_param($data->{$cap->name}, PARAM_INT);
|
||||
if (!in_array($value, $allowed_values)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$newrole->$capname = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
// edit default caps
|
||||
$SQL = "SELECT * FROM {$CFG->prefix}role_capabilities
|
||||
WHERE roleid = $roleid AND capability = '$capname'
|
||||
AND contextid = $sitecontext->id";
|
||||
|
||||
$localoverride = get_record_sql($SQL);
|
||||
|
||||
if ($localoverride) { // update current overrides
|
||||
if ($value == CAP_INHERIT) { // inherit = delete
|
||||
unassign_capability($capname, $roleid, $sitecontext->id);
|
||||
|
||||
} else {
|
||||
$localoverride->permission = $value;
|
||||
$localoverride->timemodified = time();
|
||||
$localoverride->modifierid = $USER->id;
|
||||
update_record('role_capabilities', $localoverride);
|
||||
}
|
||||
} else { // insert a record
|
||||
if ($value != CAP_INHERIT) {
|
||||
assign_capability($capname, $value, $roleid, $sitecontext->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
// update normal role settings
|
||||
$role->id = $roleid;
|
||||
$role->name = $name;
|
||||
$role->shortname = $shortname;
|
||||
$role->description = $description;
|
||||
|
||||
if (!update_record('role', $role)) {
|
||||
error('Could not update role!');
|
||||
}
|
||||
redirect('manage.php');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
if ($confirm and data_submitted() and confirm_sesskey()) {
|
||||
if (!delete_role($roleid)) {
|
||||
error('Could not delete role with ID '.$roleid);
|
||||
}
|
||||
|
||||
} else if (confirm_sesskey()){
|
||||
// show confirmation
|
||||
admin_externalpage_print_header($adminroot);
|
||||
$optionsyes = array('action'=>'delete', 'roleid'=>$roleid, 'sesskey'=>sesskey(), 'confirm'=>1);
|
||||
$a = new object();
|
||||
$a->id = $roleid;
|
||||
$a->name = $roles[$roleid]->name;
|
||||
$a->shortname = $roles[$roleid]->shortname;
|
||||
$a->count = (int)count_records('role_assignments', 'roleid', $roleid);
|
||||
notice_yesno(get_string('deleterolesure', 'role', $a), 'manage.php', 'manage.php', $optionsyes, NULL, 'post', 'get');
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
die;
|
||||
}
|
||||
|
||||
redirect('manage.php');
|
||||
break;
|
||||
|
||||
case 'moveup':
|
||||
if (array_key_exists($roleid, $roles) and confirm_sesskey()) {
|
||||
$role = $roles[$roleid];
|
||||
if ($role->sortorder > 0) {
|
||||
$above = $roles[$rolesort[$role->sortorder - 1]];
|
||||
|
||||
if (!switch_roles($role, $above)) {
|
||||
error("Cannot move role with ID $roleid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
redirect('manage.php');
|
||||
break;
|
||||
|
||||
case 'movedown':
|
||||
if (array_key_exists($roleid, $roles) and confirm_sesskey()) {
|
||||
$role = $roles[$roleid];
|
||||
if ($role->sortorder + 1 < $rolescount) {
|
||||
$below = $roles[$rolesort[$role->sortorder + 1]];
|
||||
|
||||
if (!switch_roles($role, $below)) {
|
||||
error("Cannot move role with ID $roleid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
redirect('manage.php');
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
/// print UI now
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
$currenttab = 'manage';
|
||||
include_once('managetabs.php');
|
||||
|
||||
if (($roleid and ($action == 'view' or $action == 'edit')) or $action == 'add') { // view or edit role details
|
||||
|
||||
if ($action == 'add') {
|
||||
$roleid = 0;
|
||||
if (empty($errors) or empty($newrole)) {
|
||||
$role = new object();
|
||||
$role->name='';
|
||||
$role->shortname='';
|
||||
$role->description='';
|
||||
} else {
|
||||
$role = stripslashes_safe($newrole);
|
||||
}
|
||||
} else if ($action == 'edit' and !empty($errors) and !empty($newrole)) {
|
||||
$role = stripslashes_safe($newrole);
|
||||
} else {
|
||||
if(!$role = get_record('role', 'id', $roleid)) {
|
||||
error('Incorrect role ID!');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($roles as $rolex) {
|
||||
$roleoptions[$rolex->id] = strip_tags(format_string($rolex->name));
|
||||
}
|
||||
|
||||
// this is the array holding capabilities of this role sorted till this context
|
||||
$r_caps = role_context_capabilities($roleid, $sitecontext);
|
||||
|
||||
// this is the available capabilities assignable in this context
|
||||
$capabilities = fetch_context_capabilities($sitecontext);
|
||||
|
||||
$usehtmleditor = can_use_html_editor();
|
||||
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
print_heading_with_help(get_string('addrole', 'role'), 'roles');
|
||||
break;
|
||||
case 'view':
|
||||
print_heading_with_help(get_string('viewrole', 'role'), 'roles');
|
||||
break;
|
||||
case 'edit':
|
||||
print_heading_with_help(get_string('editrole', 'role'), 'roles');
|
||||
break;
|
||||
}
|
||||
|
||||
echo '<div align="center" class="selector">';
|
||||
if ($action == 'view') {
|
||||
echo get_string('selectrole', 'role').': ';
|
||||
echo '<form style="display:inline;" name="switchrole" action="manage.php" method="get">';
|
||||
echo '<input type="hidden" name="action" value="view" />';
|
||||
choose_from_menu ($roleoptions, 'roleid', $roleid, get_string('listallroles', 'role').'...', $script='switchrole.submit()');
|
||||
echo '</form>';
|
||||
echo '<form style="display:inline;" name="editrole" action="manage.php" method="get">';
|
||||
echo '<input type="hidden" name="roleid" value="'.$roleid.'" />';
|
||||
echo '<input type="hidden" name="action" value="edit" />';
|
||||
echo '<input type="submit" value="'.get_string('edit').'" />';
|
||||
echo '</form>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
$lang = str_replace('_utf8', '', current_language());
|
||||
|
||||
print_simple_box_start('center');
|
||||
include_once('manage.html');
|
||||
print_simple_box_end();
|
||||
|
||||
if ($usehtmleditor) {
|
||||
use_html_editor('description');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
print_heading_with_help(get_string('roles', 'role'), 'roles');
|
||||
|
||||
$table = new object;
|
||||
|
||||
$table->tablealign = 'center';
|
||||
$table->align = array('right', 'left', 'left', 'left');
|
||||
$table->wrap = array('nowrap', '', 'nowrap','nowrap');
|
||||
$table->cellpadding = 5;
|
||||
$table->cellspacing = 0;
|
||||
$table->width = '90%';
|
||||
$table->data = array();
|
||||
|
||||
$table->head = array(get_string('name'),
|
||||
get_string('description'),
|
||||
get_string('shortname'),
|
||||
get_string('edit'));
|
||||
|
||||
/*************************
|
||||
* List all current roles *
|
||||
**************************/
|
||||
|
||||
foreach ($roles as $role) {
|
||||
|
||||
$stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
$strmoveup = get_string('moveup');
|
||||
$strmovedown = get_string('movedown');
|
||||
|
||||
$row = array();
|
||||
$row[0] = '<a href="manage.php?roleid='.$role->id.'&action=view">'.format_string($role->name).'</a>';
|
||||
$row[1] = format_text($role->description, FORMAT_HTML);
|
||||
$row[2] = s($role->shortname);
|
||||
$row[3] = '<a title="'.$stredit.'" href="manage.php?action=edit&roleid='.$role->id.'">'.
|
||||
'<img src="'.$CFG->pixpath.'/t/edit.gif" height="11" width="11" border="0" alt="'.$stredit.'" /></a> ';
|
||||
$row[3] .= '<a title="'.$strdelete.'" href="manage.php?action=delete&roleid='.$role->id.'&sesskey='.sesskey().'">'.
|
||||
'<img src="'.$CFG->pixpath.'/t/delete.gif" height="11" width="11" border="0" alt="'.$strdelete.'" /></a> ';
|
||||
if ($role->sortorder != 0) {
|
||||
$row[3] .= '<a title="'.$strmoveup.'" href="manage.php?action=moveup&roleid='.$role->id.'&sesskey='.sesskey().'">'.
|
||||
'<img src="'.$CFG->pixpath.'/t/up.gif" height="11" width="11" border="0" alt="'.$strmoveup.'" /></a> ';
|
||||
} else {
|
||||
$row[3] .= '<img src="'.$CFG->wwwroot.'/pix/spacer.gif" height="11" width="11" border="0" alt="" /> ';
|
||||
}
|
||||
if ($role->sortorder+1 < $rolescount) {
|
||||
$row[3] .= '<a title="'.$strmovedown.'" href="manage.php?action=movedown&roleid='.$role->id.'&sesskey='.sesskey().'">'.
|
||||
'<img src="'.$CFG->pixpath.'/t/down.gif" height="11" width="11" border="0" alt="'.$strmovedown.'" /></a> ';
|
||||
} else {
|
||||
$row[3] .= '<img src="'.$CFG->wwwroot.'/pix/spacer.gif" height="11" width="11" border="0" alt="" /> ';
|
||||
}
|
||||
|
||||
$table->data[] = $row;
|
||||
|
||||
}
|
||||
print_table($table);
|
||||
|
||||
$options = new object();
|
||||
$options->action = 'add';
|
||||
print_single_button('manage.php', $options, get_string('addrole', 'role'), 'get');
|
||||
}
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
die;
|
||||
|
||||
|
||||
/// ================ some internal functions ====================////
|
||||
|
||||
function switch_roles($first, $second) {
|
||||
$status = true;
|
||||
//first find temorary sortorder number
|
||||
$tempsort = count_records('role') + 3;
|
||||
while (get_record('role','sortorder', $tempsort)) {
|
||||
$tempsort += 3;
|
||||
}
|
||||
|
||||
$r1 = new object();
|
||||
$r1->id = $first->id;
|
||||
$r1->sortorder = $tempsort;
|
||||
$r2 = new object();
|
||||
$r2->id = $second->id;
|
||||
$r2->sortorder = $first->sortorder;
|
||||
|
||||
if (!update_record('role', $r1)) {
|
||||
debugging("Can not update role with ID $r1->id!");
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if (!update_record('role', $r2)) {
|
||||
debugging("Can not update role with ID $r2->id!");
|
||||
$status = false;
|
||||
}
|
||||
|
||||
$r1->sortorder = $second->sortorder;
|
||||
if (!update_record('role', $r1)) {
|
||||
debugging("Can not update role with ID $r1->id!");
|
||||
$status = false;
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
// this page deals with the 2 tabs for manage.php and grant.php
|
||||
|
||||
$toprow[] = new tabobject('manage', $CFG->wwwroot.'/'.$CFG->admin.'/roles/manage.php', get_string('manageroles', 'role'),'', true);
|
||||
|
||||
$toprow[] = new tabobject('allowassign', $CFG->wwwroot.'/'.$CFG->admin.'/roles/allowassign.php', get_string('allowassign', 'role'));
|
||||
|
||||
$toprow[] = new tabobject('allowoverride', $CFG->wwwroot.'/'.$CFG->admin.'/roles/allowoverride.php', get_string('allowoverride', 'role'));
|
||||
|
||||
$tabs = array($toprow);
|
||||
|
||||
print_tabs($tabs, $currenttab);
|
||||
|
||||
?>
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
$strinherit = get_string('inherit','role');
|
||||
$strallow = get_string('allow','role');
|
||||
$strprevent = get_string('prevent','role');
|
||||
$strprohibit = get_string('prohibit','role');
|
||||
?>
|
||||
|
||||
<form name="overrideform" action="override.php" method="post">
|
||||
<input type="hidden" name="contextid" value="<?php p($contextid) ?>">
|
||||
<input type="hidden" name="roleid" value="<?php p($roleid) ?>">
|
||||
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
|
||||
<input type="hidden" name="userid" value="<?php p($userid) ?>" />
|
||||
<input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
|
||||
|
||||
<table class="rolecap">
|
||||
<tr>
|
||||
<th class="name" align="left"><?php print_string('capability','role') ?></th>
|
||||
<th class="inherit"><?php p($strinherit); ?></th>
|
||||
<th class="allow"><?php p($strallow); ?></th>
|
||||
<th class="prevent"><?php p($strprevent); ?></th>
|
||||
<th class="prohibit"><?php p($strprohibit); ?></th>
|
||||
<th class="risk" colspan="5"><?php print_string('risks','role') ?></th>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
// init these 2
|
||||
$contextlevel = 0;
|
||||
$component = '';
|
||||
|
||||
$strrisks = s(get_string('risks', 'role'));
|
||||
$strcapabilities = s(get_string('capabilities', 'role'));
|
||||
|
||||
foreach ($capabilities as $capability) {
|
||||
// prints a breaker if component or name or context level
|
||||
if ($capability->component != $component or $capability->contextlevel != $contextlevel) {
|
||||
echo ('<tr class="rolecapheading header"><td colspan="10" class="header"><strong>'.get_component_string($capability->component, $capability->contextlevel).'</strong></td></tr>');
|
||||
}
|
||||
|
||||
// these 2 are used to see to group same mod/core capabilities together
|
||||
$contextlevel = $capability->contextlevel;
|
||||
$component = $capability->component;
|
||||
|
||||
// check the capability override for this cap, this role in this context
|
||||
if (isset($localoverrides[$capability->name])) {
|
||||
$localpermission = $localoverrides[$capability->name]->permission;
|
||||
} else {
|
||||
$localpermission = 0; // Just inherit
|
||||
}
|
||||
|
||||
if (isset($r_caps[$capability->name])) {
|
||||
$isallow = $r_caps[$capability->name] > 0;
|
||||
$isprevent = $r_caps[$capability->name] < 0 && $r_caps[$capability->name] > -500;
|
||||
$isprohibit = $r_caps[$capability->name] <= -500;
|
||||
} else {
|
||||
$isallow = 0;
|
||||
$isprevent = 0;
|
||||
$isprohibit = 0;
|
||||
}
|
||||
|
||||
$isdisabled = $isprohibit || islegacy($capability->name);
|
||||
|
||||
$riskinfo = '<td class="risk managetrust">';
|
||||
$rowclasses = '';
|
||||
if (RISK_MANAGETRUST & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskmanagetrust', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">T</a>';
|
||||
$rowclasses .= ' riskmanagetrust';
|
||||
}
|
||||
$riskinfo .= '</td><td class="risk config">';
|
||||
if (RISK_CONFIG & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskconfig', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">C</a>';
|
||||
$rowclasses .= ' riskconfig';
|
||||
}
|
||||
$riskinfo .= '</td><td class="risk xss">';
|
||||
if (RISK_XSS & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskxss', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">X</a>';
|
||||
$rowclasses .= ' riskxss';
|
||||
}
|
||||
$riskinfo .= '</td><td class="risk personal">';
|
||||
if (RISK_PERSONAL & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskpersonal', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">P</a>';
|
||||
$rowclasses .= ' riskpersonal';
|
||||
}
|
||||
$riskinfo .= '</td><td class="risk spam">';
|
||||
if (RISK_SPAM & (int)$capability->riskbitmask) {
|
||||
$riskinfo .= '<a target="docspopup" title="'.get_string('riskspam', 'admin').'" href="'.$CFG->docroot.'/'.$lang.'/'.$strrisks.'">S</a>';
|
||||
$rowclasses .= ' riskspam';
|
||||
}
|
||||
$riskinfo .= '</td>';
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<tr class="rolecap <?php echo $rowclasses; ?>">
|
||||
<td class="name"><span class="cap-desc"><a target="docspopup" href="<?php echo $CFG->docroot.'/'.$lang.'/'.$strcapabilities.'/'.$capability->name ?>"><?php echo get_capability_string($capability->name); ?></a><span class="cap-name"><?php echo $capability->name ?></span></label></td>
|
||||
|
||||
<td class="inherit">
|
||||
<input type="radio" title="<?php p($strinherit); ?>" name="<?php echo $capability->name; ?>" value="0"
|
||||
<?php
|
||||
if ($localpermission == CAP_INHERIT) {echo 'checked="checked"';}
|
||||
if ($isdisabled) {echo 'disabled="disabled"';}?> />
|
||||
</td>
|
||||
|
||||
<td class="allow <?php if ($isallow) {echo ' capcurrent';} ?>">
|
||||
<input type="radio" title="<?php p($strallow); ?>" name="<?php echo $capability->name; ?>"
|
||||
<?php echo ' value="'.CAP_ALLOW.'"';
|
||||
if ($localpermission == CAP_ALLOW) {echo ' checked="checked"';}
|
||||
if ($isdisabled) {echo ' disabled="disabled"';}?> />
|
||||
</td>
|
||||
|
||||
<td class="prevent <?php if ($isprevent) {echo ' capcurrent';} ?>">
|
||||
<input type="radio" title="<?php p($strprevent); ?>" name="<?php echo $capability->name; ?>"
|
||||
<?php echo ' value="'.CAP_PREVENT.'"';
|
||||
if ($localpermission == CAP_PREVENT) {echo ' checked="checked"';}
|
||||
if ($isdisabled) {echo ' disabled="disabled"';}?> />
|
||||
</td>
|
||||
|
||||
<td class="prohibit <?php if ($isprohibit) {echo ' capcurrent';} ?>">
|
||||
<input type="radio" title="<?php p($strprohibit); ?>" name="<?php echo $capability->name; ?>"
|
||||
<?php echo ' value="'.CAP_PROHIBIT.'"';
|
||||
if ($localpermission == CAP_PROHIBIT) {echo ' checked="checked"';}
|
||||
if ($isdisabled) {echo ' disabled="disabled"';}?> />
|
||||
</td>
|
||||
<?php echo $riskinfo; ?>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
</table>
|
||||
<br />
|
||||
<div align="center">
|
||||
<input type="submit" value="<?php print_string('savechanges') ?>" />
|
||||
<input type="submit" name="cancel" value="<?php print_string('cancel') ?>" />
|
||||
</div>
|
||||
</form>
|
||||
@@ -1,209 +0,0 @@
|
||||
<?php //$Id$
|
||||
|
||||
require_once('../../config.php');
|
||||
|
||||
$contextid = required_param('contextid',PARAM_INT); // context id
|
||||
$roleid = optional_param('roleid', 0, PARAM_INT); // requested role id
|
||||
$userid = optional_param('userid', 0, PARAM_INT); // needed for user tabs
|
||||
$courseid = optional_param('courseid', 0, PARAM_INT); // needed for user tabs
|
||||
$cancel = optional_param('cancel', 0, PARAM_BOOL);
|
||||
|
||||
if (!$context = get_record('context', 'id', $contextid)) {
|
||||
error('Bad context ID');
|
||||
}
|
||||
|
||||
if (!$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID)) {
|
||||
error('No site ID');
|
||||
}
|
||||
|
||||
if ($context->id == $sitecontext->id) {
|
||||
error ('Can not override base role capabilities');
|
||||
}
|
||||
|
||||
require_capability('moodle/role:override', $context); // Just to make sure
|
||||
|
||||
if ($courseid) {
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
error('Bad course ID');
|
||||
}
|
||||
} else {
|
||||
$course = $SITE;
|
||||
}
|
||||
|
||||
$baseurl = 'override.php?contextid='.$context->id;
|
||||
if (!empty($userid)) {
|
||||
$baseurl .= '&userid='.$userid;
|
||||
}
|
||||
if (!empty($courseid)) {
|
||||
$baseurl .= '&courseid='.$courseid;
|
||||
}
|
||||
|
||||
if ($cancel) {
|
||||
redirect($baseurl);
|
||||
}
|
||||
|
||||
|
||||
/// Get some language strings
|
||||
|
||||
$strroletooverride = get_string('roletooverride', 'role');
|
||||
$stroverrideusers = get_string('overrideusers', 'role');
|
||||
$straction = get_string('overrideroles', 'role');
|
||||
$strcurrentrole = get_string('currentrole', 'role');
|
||||
$strcurrentcontext = get_string('currentcontext', 'role');
|
||||
$strparticipants = get_string('participants');
|
||||
|
||||
/// Make sure this user can override that role
|
||||
if ($roleid) {
|
||||
if (!user_can_override($context, $roleid)) {
|
||||
error ('you can not override this role in this context');
|
||||
}
|
||||
}
|
||||
|
||||
if ($userid) {
|
||||
$user = get_record('user', 'id', $userid);
|
||||
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
|
||||
}
|
||||
|
||||
/// Process incoming role override
|
||||
if ($data = data_submitted() and $roleid and confirm_sesskey()) {
|
||||
$allowed_values = array(CAP_INHERIT, CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT);
|
||||
$capabilities = fetch_context_capabilities($context); // capabilities applicable in this context
|
||||
|
||||
$localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
|
||||
'', 'capability, permission, id');
|
||||
|
||||
foreach ($capabilities as $cap) {
|
||||
if (!isset($data->{$cap->name})) {
|
||||
continue;
|
||||
}
|
||||
$capname = $cap->name;
|
||||
$value = clean_param($data->{$cap->name}, PARAM_INT);
|
||||
if (!in_array($value, $allowed_values)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($localoverrides[$capname])) { // Something exists, so update it
|
||||
if ($value == CAP_INHERIT) { // inherit = delete
|
||||
delete_records('role_capabilities', 'roleid', $roleid, 'contextid', $context->id,
|
||||
'capability', $capname);
|
||||
} else {
|
||||
$localoverride = new object();
|
||||
$localoverride->id = $localoverrides[$capname]->id;
|
||||
$localoverride->permission = $value;
|
||||
$localoverride->timemodified = time();
|
||||
$localoverride->modifierid = $USER->id;
|
||||
if (!update_record('role_capabilities', $localoverride)) {
|
||||
error('Could not update a capability!');
|
||||
}
|
||||
}
|
||||
|
||||
} else { // insert a record
|
||||
if ($value != CAP_INHERIT) { // Ignore inherits
|
||||
$localoverride = new object();
|
||||
$localoverride->capability = $capname;
|
||||
$localoverride->contextid = $context->id;
|
||||
$localoverride->roleid = $roleid;
|
||||
$localoverride->permission = $value;
|
||||
$localoverride->timemodified = time();
|
||||
$localoverride->modifierid = $USER->id;
|
||||
if (!insert_record('role_capabilities', $localoverride)) {
|
||||
error('Could not insert a capability!');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
redirect($baseurl);
|
||||
}
|
||||
|
||||
|
||||
/// Print the header and tabs
|
||||
|
||||
if ($context->contextlevel == CONTEXT_USER) {
|
||||
|
||||
/// course header
|
||||
if ($course->id != SITEID) {
|
||||
print_header("$fullname", "$fullname",
|
||||
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
|
||||
<a href=\"$CFG->wwwroot/user/index.php?id=$course->id\">$strparticipants</a> -> <a href=\"$CFG->wwwroot/user/view.php?id=$userid&course=$course->id\">$fullname</a> -> $straction",
|
||||
"", "", true, " ", navmenu($course));
|
||||
|
||||
/// site header
|
||||
} else {
|
||||
print_header("$course->fullname: $fullname", "$course->fullname",
|
||||
"<a href=\"$CFG->wwwroot/user/view.php?id=$userid&course=$course->id\">$fullname</a> -> $straction", "", "", true, " ", navmenu($course));
|
||||
}
|
||||
$showroles = 1;
|
||||
$currenttab = 'override';
|
||||
include_once($CFG->dirroot.'/user/tabs.php');
|
||||
} else {
|
||||
$currenttab = '';
|
||||
$tabsmode = 'override';
|
||||
include_once('tabs.php');
|
||||
}
|
||||
|
||||
print_heading_with_help(get_string('overrides', 'role'), 'overrides');
|
||||
|
||||
$overridableroles = get_overridable_roles($context);
|
||||
|
||||
if ($roleid) {
|
||||
/// prints a form to swap roles
|
||||
echo '<form name="rolesform" action="override.php" method="get">';
|
||||
echo '<div align="center">'.$strcurrentcontext.': '.print_context_name($context).'<br/>';
|
||||
if ($userid) {
|
||||
echo '<input type="hidden" name="userid" value="'.$userid.'" />';
|
||||
}
|
||||
if ($courseid) {
|
||||
echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
|
||||
}
|
||||
echo '<input type="hidden" name="contextid" value="'.$context->id.'" />'.$strroletooverride.': ';
|
||||
choose_from_menu ($overridableroles, 'roleid', $roleid, get_string('listallroles', 'role').'...', $script='rolesform.submit()');
|
||||
echo '</div></form>';
|
||||
|
||||
$parentcontexts = get_parent_contexts($context);
|
||||
if (!empty($parentcontexts)) {
|
||||
$parentcontext = array_shift($parentcontexts);
|
||||
$parentcontext = get_context_instance_by_id($parentcontext);
|
||||
} else {
|
||||
$parentcontext = $context; // site level in override??
|
||||
}
|
||||
|
||||
$r_caps = role_context_capabilities($roleid, $parentcontext);
|
||||
|
||||
$localoverrides = get_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id",
|
||||
'', 'capability, permission, id');
|
||||
|
||||
$lang = str_replace('_utf8', '', current_language());
|
||||
|
||||
// Get the capabilities overrideable in this context
|
||||
if ($capabilities = fetch_context_capabilities($context)) {
|
||||
print_simple_box_start('center');
|
||||
include_once('override.html');
|
||||
print_simple_box_end();
|
||||
} else {
|
||||
notice(get_string('nocapabilitiesincontext', 'role'),
|
||||
$CFG->wwwroot.'/'.$CFG->admin.'/roles/'.$baseurl);
|
||||
}
|
||||
|
||||
} else { // Print overview table
|
||||
|
||||
$table->tablealign = 'center';
|
||||
$table->cellpadding = 5;
|
||||
$table->cellspacing = 0;
|
||||
$table->width = '60%';
|
||||
$table->head = array(get_string('roles', 'role'), get_string('description'), get_string('overrides', 'role'));
|
||||
$table->wrap = array('nowrap', '', 'nowrap');
|
||||
$table->align = array('right', 'left', 'center');
|
||||
|
||||
foreach ($overridableroles as $roleid => $rolename) {
|
||||
$countusers = 0;
|
||||
$overridecount = count_records_select('role_capabilities', "roleid = $roleid AND contextid = $context->id");
|
||||
$description = format_string(get_field('role', 'description', 'id', $roleid));
|
||||
$table->data[] = array('<a href="'.$baseurl.'&roleid='.$roleid.'">'.$rolename.'</a>', $description, $overridecount);
|
||||
}
|
||||
|
||||
print_table($table);
|
||||
}
|
||||
|
||||
print_footer($course);
|
||||
|
||||
?>
|
||||
@@ -1,169 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// Handles headers and tabs for the roles control at any level apart from SYSTEM level
|
||||
|
||||
if ($currenttab != 'update') {
|
||||
switch ($context->contextlevel) {
|
||||
|
||||
case CONTEXT_SYSTEM:
|
||||
$stradministration = get_string('administration');
|
||||
print_header($SITE->fullname, "$SITE->fullname","<a href=\"../index.php\">$stradministration</a> -> $straction");
|
||||
break;
|
||||
|
||||
case CONTEXT_PERSONAL:
|
||||
break;
|
||||
|
||||
case CONTEXT_USER:
|
||||
print_header();
|
||||
break;
|
||||
|
||||
case CONTEXT_COURSECAT:
|
||||
$category = get_record('course_categories', 'id', $context->instanceid);
|
||||
$strcategories = get_string("categories");
|
||||
$strcategory = get_string("category");
|
||||
$strcourses = get_string("courses");
|
||||
print_header("$SITE->shortname: $category->name", "$SITE->fullname: $strcourses",
|
||||
"<a href=\"$CFG->wwwroot/course/index.php\">$strcategories</a> -> <a href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a> -> $straction", "", "", true);
|
||||
break;
|
||||
|
||||
case CONTEXT_COURSE:
|
||||
$streditcoursesettings = get_string("editcoursesettings");
|
||||
|
||||
$course = get_record('course', 'id', $context->instanceid);
|
||||
print_header($streditcoursesettings, "$course->fullname",
|
||||
"<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> $straction");
|
||||
break;
|
||||
|
||||
case CONTEXT_GROUP:
|
||||
break;
|
||||
|
||||
case CONTEXT_MODULE:
|
||||
// get module type?
|
||||
if (!$cm = get_record('course_modules','id',$context->instanceid)) {
|
||||
error('Bad course module ID');
|
||||
}
|
||||
if (!$module = get_record('modules','id',$cm->module)) { //$module->name;
|
||||
error('Bad module ID');
|
||||
}
|
||||
if (!$course = get_record('course','id',$cm->course)) {
|
||||
error('Bad course ID');
|
||||
}
|
||||
if (!$instance = get_record($module->name, 'id', $cm->instance)) {
|
||||
error("The required instance of this module doesn't exist");
|
||||
}
|
||||
|
||||
$strnav = "<a href=\"$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id\">$instance->name</a> ->";
|
||||
$fullmodulename = get_string("modulename", $module->name);
|
||||
$streditinga = get_string("editinga", "moodle", $fullmodulename);
|
||||
$strmodulenameplural = get_string("modulenameplural", $module->name);
|
||||
|
||||
if ($module->name == "label") {
|
||||
$focuscursor = "";
|
||||
} else {
|
||||
$focuscursor = "form.name";
|
||||
}
|
||||
|
||||
$COURSE = $course;
|
||||
print_header_simple($streditinga, '',
|
||||
"<a href=\"$CFG->wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural</a> ->
|
||||
$strnav <a href=\"$CFG->wwwroot/course/mod.php?update=$cm->id&sesskey=".sesskey()."\">$streditinga</a> -> $straction", $focuscursor, "", false);
|
||||
|
||||
break;
|
||||
|
||||
case CONTEXT_BLOCK:
|
||||
if ($blockinstance = get_record('block_instance', 'id', $context->instanceid)) {
|
||||
if ($block = get_record('block', 'id', $blockinstance->blockid)) {
|
||||
$blockname = print_context_name($context);
|
||||
$navigation = $blockname. ' -> '.$straction;
|
||||
|
||||
switch ($blockinstance->pagetype) {
|
||||
case 'course-view':
|
||||
if ($course = get_record('course', 'id', $blockinstance->pageid)) {
|
||||
if ($course->id != SITEID) {
|
||||
$navigation = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> $navigation";
|
||||
}
|
||||
print_header("$straction: $blockname", $course->fullname, $navigation);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'blog-view':
|
||||
$strblogs = get_string('blogs','blog');
|
||||
$navigation = '<a href="'.$CFG->wwwroot.'/blog/index.php">'.
|
||||
$strblogs.'</a> -> '.$navigation;
|
||||
print_header("$straction: $strblogs", $SITE->fullname, $navigation);
|
||||
break;
|
||||
|
||||
default:
|
||||
print_header("$straction: $blockname", $SITE->fullname, $navigation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
error ('This is an unknown context!');
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($context->contextlevel != CONTEXT_SYSTEM) { // Print tabs for anything except SYSTEM context
|
||||
|
||||
if ($context->contextlevel == CONTEXT_MODULE) { // only show update button if module?
|
||||
|
||||
$toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='.
|
||||
$context->instanceid.'&return=true&sesskey='.sesskey(), get_string('update'));
|
||||
|
||||
}
|
||||
|
||||
$toprow[] = new tabobject('roles', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.
|
||||
$context->id, get_string('roles'));
|
||||
|
||||
if (isset($tabsmode)) {
|
||||
|
||||
if (!isset($assignableroles)) {
|
||||
$assignableroles = get_assignable_roles($context);
|
||||
}
|
||||
if (!isset($overridableroles)) {
|
||||
$overridableroles = get_overridable_roles($context);
|
||||
}
|
||||
|
||||
$inactive[] = 'roles';
|
||||
if (!empty($assignableroles)) {
|
||||
$secondrow[] = new tabobject('assign',
|
||||
$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id,
|
||||
get_string('assignroles', 'role'),
|
||||
get_string('showallroles', 'role'),
|
||||
true);
|
||||
}
|
||||
|
||||
if (!empty($overridableroles)) {
|
||||
$secondrow[] = new tabobject('override',
|
||||
$CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id,
|
||||
get_string('overrideroles', 'role'),
|
||||
get_string('showallroles', 'role'),
|
||||
true);
|
||||
}
|
||||
|
||||
if ($tabsmode == 'override') {
|
||||
$currenttab = 'override';
|
||||
} elseif ($tabsmode == 'assign') {
|
||||
$currenttab = 'assign';
|
||||
}
|
||||
|
||||
} else {
|
||||
$inactive[] = '';
|
||||
}
|
||||
|
||||
if (!empty($secondrow)) {
|
||||
$tabs = array($toprow, $secondrow);
|
||||
} else {
|
||||
$tabs = array($toprow);
|
||||
}
|
||||
|
||||
print_tabs($tabs, $currenttab, $inactive);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,150 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// searches for admin settings
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$query = trim(stripslashes_safe(required_param('query', PARAM_NOTAGS))); // Search string
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('search', $adminroot); // now hidden page
|
||||
|
||||
$CFG->adminsearchquery = $query; // So we can reference it in search boxes later in this invocation
|
||||
|
||||
|
||||
// now we'll deal with the case that the admin has submitted the form with changed settings
|
||||
|
||||
$statusmsg = '';
|
||||
|
||||
if ($data = data_submitted()) {
|
||||
$unslashed = (array)stripslashes_recursive($data);
|
||||
if (confirm_sesskey()) {
|
||||
$olddbsessions = !empty($CFG->dbsessions);
|
||||
$changedsettings = search_settings(admin_get_root(), $query);
|
||||
$errors = '';
|
||||
|
||||
foreach($changedsettings as $changedsetting) {
|
||||
if (!isset($unslashed['s_' . $changedsetting->name])) {
|
||||
$unslashed['s_' . $changedsetting->name] = ''; // needed for checkboxes
|
||||
}
|
||||
$errors .= $changedsetting->write_setting($unslashed['s_' . $changedsetting->name]);
|
||||
}
|
||||
|
||||
if ($olddbsessions != !empty($CFG->dbsessions)) {
|
||||
require_logout();
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
$statusmsg = get_string('changessaved');
|
||||
} else {
|
||||
$statusmsg = get_string('errorwithsettings', 'admin') . ' <br />' . $errors;
|
||||
}
|
||||
} else {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
// now update $SITE - it might have been changed
|
||||
$SITE = get_record('course', 'id', $SITE->id);
|
||||
$COURSE = clone($SITE);
|
||||
}
|
||||
|
||||
// and finally, if we get here, then there are matching settings and we have to print a form
|
||||
// to modify them
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
if ($statusmsg != '') {
|
||||
notify ($statusmsg);
|
||||
}
|
||||
|
||||
$resultshtml = search_settings_html(admin_get_root(), $query);
|
||||
|
||||
echo '<form action="search.php" method="post" name="adminsettings" id="adminsettings">';
|
||||
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
|
||||
echo '<input type="hidden" name="query" value="' . s($query) . '" />';
|
||||
echo '<fieldset>';
|
||||
echo '<div class="clearer"><!-- --></div>';
|
||||
if ($resultshtml != '') {
|
||||
echo $resultshtml;
|
||||
echo '<div class="form-buttons"><input class="form-submit" type="submit" value="' . get_string('savechanges','admin') . '" /></div>';
|
||||
} else {
|
||||
echo get_string('noresults','admin');
|
||||
}
|
||||
echo '</fieldset>';
|
||||
echo '</form>';
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
|
||||
/**
|
||||
* Find settings using a query.
|
||||
*
|
||||
* @param string &$node The node at which to start searching. Should be $ADMIN for all external calls to this function.
|
||||
* @param string $query The search string.
|
||||
* @return array An array containing admin_setting objects that match $query.
|
||||
*/
|
||||
function search_settings(&$node, $query) {
|
||||
|
||||
if (is_a($node, 'admin_category')) {
|
||||
$return = array();
|
||||
$entries = array_keys($node->children);
|
||||
foreach ($entries as $entry) {
|
||||
$return = array_merge($return, search_settings($node->children[$entry], $query));
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
if (is_a($node, 'admin_settingpage')) {
|
||||
$return = array();
|
||||
foreach ($node->settings as $setting) {
|
||||
if (stristr($setting->name,$query) || stristr($setting->visiblename,$query) || stristr($setting->description,$query)) {
|
||||
$return[] =& $setting;
|
||||
}
|
||||
unset($setting); // needed to prevent odd (imho) reference behaviour
|
||||
// see http://www.php.net/manual/en/language.references.whatdo.php#AEN6399
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
return array();
|
||||
|
||||
}
|
||||
|
||||
function search_settings_html(&$node, $query) {
|
||||
|
||||
global $CFG;
|
||||
if (is_a($node, 'admin_category')) {
|
||||
$entries = array_keys($node->children);
|
||||
$return = '';
|
||||
foreach ($entries as $entry) {
|
||||
$return .= search_settings_html($node->children[$entry], $query);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
if (is_a($node, 'admin_settingpage')) {
|
||||
$foundsettings = array();
|
||||
foreach ($node->settings as $setting) {
|
||||
if (stristr($setting->name,$query) || stristr($setting->visiblename,$query) || stristr($setting->description,$query)) {
|
||||
$foundsettings[] =& $setting;
|
||||
}
|
||||
unset($setting); // needed to prevent odd (imho) reference behaviour
|
||||
// see http://www.php.net/manual/en/language.references.whatdo.php#AEN6399
|
||||
}
|
||||
$return = '';
|
||||
if (count($foundsettings) > 0) {
|
||||
$return .= print_heading(get_string('searchresults','admin').' - '. '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=' . $node->name . '">' . $node->visiblename . '</a>', '', 2, 'main', true);
|
||||
$return .= '<fieldset class="adminsettings">' . "\n";
|
||||
foreach ($foundsettings as $foundsetting) {
|
||||
$return .= '<div class="clearer"><!-- --></div>' . "\n";
|
||||
$return .= highlight($query,$foundsetting->output_html());
|
||||
}
|
||||
$return .= '</fieldset>';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,143 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/blocklib.php');
|
||||
require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php');
|
||||
|
||||
if ($site = get_site()) {
|
||||
require_login();
|
||||
}
|
||||
|
||||
|
||||
page_map_class(PAGE_ADMIN, 'page_admin');
|
||||
|
||||
$PAGE = page_create_object(PAGE_ADMIN, 0); // there must be any constant id number
|
||||
|
||||
$section = optional_param('section', '', PARAM_ALPHAEXT);
|
||||
|
||||
$PAGE->init_extra($section); // hack alert!
|
||||
|
||||
$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
|
||||
$return = optional_param('return','', PARAM_ALPHA);
|
||||
|
||||
if (!isset($USER->adminediting)) {
|
||||
$USER->adminediting = false;
|
||||
}
|
||||
|
||||
if ($PAGE->user_allowed_editing()) {
|
||||
if ($adminediting == 1) {
|
||||
$USER->adminediting = true;
|
||||
} elseif ($adminediting == 0) {
|
||||
$USER->adminediting = false;
|
||||
}
|
||||
}
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
|
||||
$root = $adminroot->locate($PAGE->section);
|
||||
|
||||
if (!is_a($root, 'admin_settingpage')) {
|
||||
error(get_string('sectionerror', 'admin'));
|
||||
die;
|
||||
}
|
||||
|
||||
if (!($root->check_access())) {
|
||||
error(get_string('accessdenied', 'admin'));
|
||||
die;
|
||||
}
|
||||
|
||||
$CFG->pagepath = 'admin/setting/'.$section;
|
||||
|
||||
|
||||
|
||||
/// WRITING SUBMITTED DATA (IF ANY) -------------------------------------------------------------------------------
|
||||
|
||||
$statusmsg = '';
|
||||
|
||||
if ($data = data_submitted()) {
|
||||
if (confirm_sesskey()) {
|
||||
$olddbsessions = !empty($CFG->dbsessions);
|
||||
$unslashed = (array)stripslashes_recursive($data);
|
||||
$errors = $root->write_settings($unslashed);
|
||||
//force logout if dbsession setting changes
|
||||
if ($olddbsessions != !empty($CFG->dbsessions)) {
|
||||
require_logout();
|
||||
}
|
||||
if (empty($errors)) {
|
||||
switch ($return) {
|
||||
case 'site':
|
||||
redirect("$CFG->wwwroot/");
|
||||
case 'admin':
|
||||
redirect("$CFG->wwwroot/$CFG->admin/");
|
||||
default:
|
||||
$statusmsg = get_string('changessaved');
|
||||
}
|
||||
} else {
|
||||
$statusmsg = get_string('errorwithsettings', 'admin') . ' <br />' . $errors;
|
||||
}
|
||||
} else {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
}
|
||||
// now update $SITE - it might have been changed
|
||||
$SITE = get_record('course', 'id', $SITE->id);
|
||||
$COURSE = clone($SITE);
|
||||
}
|
||||
|
||||
|
||||
/// print header stuff ------------------------------------------------------------
|
||||
// header must be printed after the redirects and require_logout
|
||||
if (!empty($SITE->fullname)) {
|
||||
$pageblocks = blocks_setup($PAGE);
|
||||
|
||||
$preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
|
||||
BLOCK_L_MAX_WIDTH);
|
||||
$preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
|
||||
BLOCK_R_MAX_WIDTH);
|
||||
|
||||
$PAGE->print_header();
|
||||
|
||||
echo '<table id="layout-table"><tr>';
|
||||
echo '<td style="width: ' . $preferred_width_left . 'px;" id="left-column">';
|
||||
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
|
||||
echo '</td>';
|
||||
echo '<td id="middle-column">';
|
||||
} else {
|
||||
|
||||
print_header();
|
||||
print_simple_box(get_string('configintrosite', 'admin'), 'center', '50%');
|
||||
|
||||
}
|
||||
|
||||
if ($statusmsg != '') {
|
||||
notify ($statusmsg);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
echo '<form action="settings.php" method="post" name="adminsettings" id="adminsettings">';
|
||||
echo '<input type="hidden" name="section" value="' . $PAGE->section . '" />';
|
||||
echo '<input type="hidden" name="sesskey" value="' . $USER->sesskey . '" />';
|
||||
echo '<input type="hidden" name="return" value="' . $return . '" />';
|
||||
print_heading($root->visiblename);
|
||||
|
||||
echo $root->output_html();
|
||||
|
||||
echo '<div class="form-buttons"><input class="form-submit" type="submit" value="' . get_string('savechanges','admin') . '" /></div>';
|
||||
|
||||
echo '</form>';
|
||||
|
||||
if (!empty($SITE->fullname)) {
|
||||
echo '</td>';
|
||||
echo '<td style="width: ' . $preferred_width_right . 'px;" id="right-column">';
|
||||
blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
|
||||
echo '</td></tr></table>';
|
||||
}
|
||||
|
||||
if (!empty($CFG->adminusehtmleditor)) {
|
||||
use_html_editor();
|
||||
}
|
||||
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
@@ -1,129 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// This file defines settingpages and externalpages under the "appearance" category
|
||||
|
||||
$ADMIN->add('appearance', new admin_category('themes', get_string('themes')));
|
||||
// "themesettings" settingpage
|
||||
$temp = new admin_settingpage('themesettings', get_string('themesettings', 'admin'));
|
||||
$temp->add(new admin_setting_configtext('themelist', get_string('themelist', 'admin'), get_string('configthemelist','admin'), '', PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configcheckbox('allowuserthemes', get_string('allowuserthemes', 'admin'), get_string('configallowuserthemes', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('allowcoursethemes', get_string('allowcoursethemes', 'admin'), get_string('configallowcoursethemes', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('allowuserblockhiding', get_string('allowuserblockhiding', 'admin'), get_string('configallowuserblockhiding', 'admin'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('showblocksonmodpages', get_string('showblocksonmodpages', 'admin'), get_string('configshowblocksonmodpages', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('tabselectedtofront', get_string('tabselectedtofronttext', 'admin'), get_string('tabselectedtofront', 'admin'), 0));
|
||||
$ADMIN->add('themes', $temp);
|
||||
$ADMIN->add('themes', new admin_externalpage('themeselector', get_string('themeselector','admin'), $CFG->wwwroot . '/theme/index.php'));
|
||||
|
||||
|
||||
// "frontpage" settingpage
|
||||
$temp = new admin_settingpage('frontpage', get_string('frontpage','admin'));
|
||||
$temp->add(new admin_setting_sitesettext('fullname', get_string('fullsitename'), '', ''));
|
||||
$temp->add(new admin_setting_sitesettext('shortname', get_string('shortsitename'), '', ''));
|
||||
$temp->add(new admin_setting_special_frontpagedesc());
|
||||
$temp->add(new admin_setting_courselist_frontpage(false)); // non-loggedin version of the setting (that's what the parameter is for :) )
|
||||
$temp->add(new admin_setting_courselist_frontpage(true)); // loggedin version of the setting
|
||||
$temp->add(new admin_setting_sitesetcheckbox('numsections', get_string('sitesection'),
|
||||
get_string('sitesectionhelp','admin'), 1));
|
||||
$temp->add(new admin_setting_sitesetselect('newsitems', get_string('newsitemsnumber'),
|
||||
'', 3,
|
||||
array('0' => '0',
|
||||
'1' => '1',
|
||||
'2' => '2',
|
||||
'3' => '3',
|
||||
'4' => '4',
|
||||
'5' => '5',
|
||||
'6' => '6',
|
||||
'7' => '7',
|
||||
'8' => '8',
|
||||
'9' => '9',
|
||||
'10' => '10')));
|
||||
$temp->add(new admin_setting_configtext('coursesperpage', get_string('coursesperpage', 'admin'), get_string('configcoursesperpage', 'admin'), 20, PARAM_INT));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
// calendar
|
||||
$temp = new admin_settingpage('calendar', get_string('calendarsettings','admin'));
|
||||
$temp->add(new admin_setting_special_adminseesall());
|
||||
$temp->add(new admin_setting_configselect('calendar_startwday', get_string('configstartwday', 'admin'), get_string('helpstartofweek', 'admin'), 0,
|
||||
array(
|
||||
0 => get_string('sunday', 'calendar'),
|
||||
1 => get_string('monday', 'calendar'),
|
||||
2 => get_string('tuesday', 'calendar'),
|
||||
3 => get_string('wednesday', 'calendar'),
|
||||
4 => get_string('thursday', 'calendar'),
|
||||
5 => get_string('friday', 'calendar'),
|
||||
6 => get_string('saturday', 'calendar')
|
||||
)));
|
||||
$temp->add(new admin_setting_special_calendar_weekend());
|
||||
$temp->add(new admin_setting_configtext('calendar_lookahead',get_string('configlookahead','admin'),get_string('helpupcominglookahead', 'admin'),21,PARAM_INT));
|
||||
$temp->add(new admin_setting_configtext('calendar_maxevents',get_string('configmaxevents','admin'),get_string('helpupcomingmaxevents', 'admin'),10,PARAM_INT));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
// "filtersettings" settingpage
|
||||
$temp = new admin_settingpage('filtersettings', get_string('filtersettings', 'admin'));
|
||||
$temp->add(new admin_setting_configselect('cachetext', get_string('cachetext', 'admin'), get_string('configcachetext', 'admin'), 60, array(604800 => get_string('numdays','',7),
|
||||
86400 => get_string('numdays','',1),
|
||||
43200 => get_string('numhours','',12),
|
||||
10800 => get_string('numhours','',3),
|
||||
7200 => get_string('numhours','',2),
|
||||
3600 => get_string('numhours','',1),
|
||||
2700 => get_string('numminutes','',45),
|
||||
1800 => get_string('numminutes','',30),
|
||||
900 => get_string('numminutes','',15),
|
||||
600 => get_string('numminutes','',10),
|
||||
540 => get_string('numminutes','',9),
|
||||
480 => get_string('numminutes','',8),
|
||||
420 => get_string('numminutes','',7),
|
||||
360 => get_string('numminutes','',6),
|
||||
300 => get_string('numminutes','',5),
|
||||
240 => get_string('numminutes','',4),
|
||||
180 => get_string('numminutes','',3),
|
||||
120 => get_string('numminutes','',2),
|
||||
60 => get_string('numminutes','',1),
|
||||
30 => get_string('numseconds','',30),
|
||||
0 => get_string('no'))));
|
||||
$temp->add(new admin_setting_configselect('filteruploadedfiles', get_string('filteruploadedfiles', 'admin'), get_string('configfilteruploadedfiles', 'admin'), 0, array('0' => get_string('none'),
|
||||
'1' => get_string('allfiles'),
|
||||
'2' => get_string('htmlfilesonly'))));
|
||||
$temp->add(new admin_setting_configcheckbox('filtermatchoneperpage', get_string('filtermatchoneperpage', 'admin'), get_string('configfiltermatchoneperpage', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('filtermatchonepertext', get_string('filtermatchonepertext', 'admin'), get_string('configfiltermatchonepertext', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('filterall', get_string('filterall', 'admin'), get_string('configfilterall', 'admin'), 0));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// "htmleditor" settingpage
|
||||
$temp = new admin_settingpage('htmleditor', get_string('htmleditor', 'admin'));
|
||||
$temp->add(new admin_setting_configcheckbox('htmleditor', get_string('usehtmleditor', 'admin'), get_string('confightmleditor','admin'), 1));
|
||||
$temp->add(new admin_setting_configtext('editorbackgroundcolor', get_string('editorbackgroundcolor', 'admin'), get_string('edhelpbgcolor'), '#ffffff', PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configtext('editorfontfamily', get_string('editorfontfamily', 'admin'), get_string('edhelpfontfamily'), 'Trebuchet MS,Verdana,Arial,Helvetica,sans-serif', PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configtext('editorfontsize', get_string('editorfontsize', 'admin'), get_string('edhelpfontsize'), '', PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_special_editorfontlist());
|
||||
$temp->add(new admin_setting_configcheckbox('editorkillword', get_string('editorkillword', 'admin'), get_string('edhelpcleanword'), 1));
|
||||
if (!empty($CFG->aspellpath)) { // make aspell settings disappear if path isn't set
|
||||
$temp->add(new admin_setting_configcheckbox('editorspelling', get_string('editorspelling', 'admin'), get_string('editorspellinghelp', 'admin'), 0));
|
||||
$temp->add(new admin_setting_special_editordictionary());
|
||||
}
|
||||
$temp->add(new admin_setting_special_editorhidebuttons());
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
// "documentation" settingpage
|
||||
$temp = new admin_settingpage('documentation', get_string('moodledocs'));
|
||||
$temp->add(new admin_setting_configtext('docroot', get_string('docroot', 'admin'), get_string('configdocroot', 'admin'), 'http://docs.moodle.org', PARAM_URL));
|
||||
$temp->add(new admin_setting_configcheckbox('doctonewwindow', get_string('doctonewwindow', 'admin'), get_string('configdoctonewwindow', 'admin'), 0));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
$temp = new admin_settingpage('mymoodle', get_string('mymoodle', 'admin'));
|
||||
$temp->add(new admin_setting_configcheckbox('mymoodleredirect', get_string('mymoodleredirect', 'admin'), get_string('configmymoodleredirect', 'admin'), 0));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
// new CFG variable for gradebook (what roles to display)
|
||||
$temp = new admin_settingpage('gradebook', get_string('gradebook', 'admin'));
|
||||
$temp->add(new admin_setting_special_gradebookroles());
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
|
||||
$ADMIN->add('appearance', new admin_externalpage('stickyblocks', get_string('stickyblocks', 'admin'), "$CFG->wwwroot/$CFG->admin/stickyblocks.php"));
|
||||
|
||||
?>
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// This file defines settingpages and externalpages under the "courses" category
|
||||
|
||||
|
||||
$ADMIN->add('courses', new admin_externalpage('coursemgmt', get_string('coursemgmt', 'admin'), $CFG->wwwroot . '/course/index.php?categoryedit=on'));
|
||||
|
||||
$ADMIN->add('courses', new admin_externalpage('enrolment', get_string('enrolments'), $CFG->wwwroot . '/'.$CFG->admin.'/enrol.php'));
|
||||
|
||||
// "courserequests" settingpage
|
||||
$temp = new admin_settingpage('courserequest', get_string('courserequest'));
|
||||
$temp->add(new admin_setting_configcheckbox('enablecourserequests', get_string('enablecourserequests', 'admin'), get_string('configenablecourserequests', 'admin'), 0));
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
$temp->add(new admin_setting_configselect('defaultrequestcategory', get_string('defaultrequestcategory', 'admin'), get_string('configdefaultrequestcategory', 'admin'), 1, make_categories_options()));
|
||||
$ADMIN->add('courses', $temp);
|
||||
|
||||
|
||||
|
||||
// "backups" settingpage
|
||||
$temp = new admin_settingpage('backups', get_string('backups','admin'));
|
||||
$temp->add(new admin_setting_backupcheckbox('backup_sche_modules', get_string('includemodules'), get_string('backupincludemoduleshelp'), 0));
|
||||
$temp->add(new admin_setting_backupcheckbox('backup_sche_withuserdata', get_string('includemoduleuserdata'), get_string('backupincludemoduleuserdatahelp'), 0));
|
||||
$temp->add(new admin_setting_backupcheckbox('backup_sche_metacourse', get_string('metacourse'), get_string('backupmetacoursehelp'), 0));
|
||||
$temp->add(new admin_setting_backupselect('backup_sche_users', get_string('users'), get_string('backupusershelp'), 0, array(0 => get_string('all'),
|
||||
1 => get_string('course'))));
|
||||
$temp->add(new admin_setting_backupcheckbox('backup_sche_logs', get_string('logs'), get_string('backuplogshelp'), 0));
|
||||
$temp->add(new admin_setting_backupcheckbox('backup_sche_userfiles', get_string('userfiles'), get_string('backupuserfileshelp'), 0));
|
||||
$temp->add(new admin_setting_backupcheckbox('backup_sche_coursefiles', get_string('coursefiles'), get_string('backupcoursefileshelp'), 0));
|
||||
$temp->add(new admin_setting_backupcheckbox('backup_sche_messages', get_string('messages', 'message'), get_string('backupmessageshelp','message'), 0));
|
||||
$temp->add(new admin_setting_backupselect('backup_sche_keep', get_string('keep'), get_string('backupkeephelp'), 1, array(0 => get_string('all'),
|
||||
1 => '1',
|
||||
2 => '2',
|
||||
5 => '5',
|
||||
10 => '10',
|
||||
20 => '20',
|
||||
30 => '30',
|
||||
40 => '40',
|
||||
50 => '50',
|
||||
100 => '100',
|
||||
200 => '200',
|
||||
300 => '300',
|
||||
400 => '400',
|
||||
500 => '500')));
|
||||
$temp->add(new admin_setting_backupcheckbox('backup_sche_active', get_string('active'), get_string('backupactivehelp'), 0));
|
||||
$temp->add(new admin_setting_special_backupdays());
|
||||
$temp->add(new admin_setting_special_backuptime());
|
||||
$temp->add(new admin_setting_special_backupsaveto());
|
||||
$ADMIN->add('courses', $temp);
|
||||
|
||||
?>
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// This file defines settingpages and externalpages under the "appearance" category
|
||||
|
||||
// "languageandlocation" settingpage
|
||||
$temp = new admin_settingpage('langsettings', get_string('languagesettings', 'admin'));
|
||||
$temp->add(new admin_setting_configselect('lang', get_string('lang', 'admin'), get_string('configlang', 'admin'), current_language(), get_list_of_languages())); // $CFG->lang might be set in installer already, default en or en_utf8 is in setup.php
|
||||
$temp->add(new admin_setting_configcheckbox('langmenu', get_string('langmenu', 'admin'), get_string('configlangmenu', 'admin'), 1));
|
||||
$temp->add(new admin_setting_configtext('langlist', get_string('langlist', 'admin'), get_string('configlanglist', 'admin'), '', PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configcheckbox('langcache', get_string('langcache', 'admin'), get_string('configlangcache', 'admin'), 1));
|
||||
$temp->add(new admin_setting_configtext('locale', get_string('localetext', 'admin'), get_string('configlocale', 'admin'), '', PARAM_FILE));
|
||||
$ADMIN->add('language', $temp);
|
||||
|
||||
|
||||
|
||||
$ADMIN->add('language', new admin_externalpage('langedit', get_string('langedit', 'admin'), "$CFG->wwwroot/$CFG->admin/lang.php"));
|
||||
$ADMIN->add('language', new admin_externalpage('langimport', get_string('langpacks', 'admin'), "$CFG->wwwroot/$CFG->admin/langimport.php"));
|
||||
|
||||
?>
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// "locations" settingpage
|
||||
$temp = new admin_settingpage('locationsettings', get_string('locationsettings', 'admin'));
|
||||
$options = get_list_of_timezones();
|
||||
$options[99] = get_string('serverlocaltime');
|
||||
$temp->add(new admin_setting_configselect('timezone', get_string('timezone','admin'), get_string('configtimezone', 'admin'), 99, $options));
|
||||
$options = get_list_of_timezones();
|
||||
$options[99] = get_string('timezonenotforced', 'admin');
|
||||
$temp->add(new admin_setting_configselect('forcetimezone', get_string('forcetimezone', 'admin'), get_string('helpforcetimezone', 'admin'), 99, $options));
|
||||
$options = get_list_of_countries();
|
||||
$options[0] = get_string('choose') .'...';
|
||||
$temp->add(new admin_setting_configselect('country', get_string('country', 'admin'), get_string('configcountry', 'admin'), 0, $options));
|
||||
|
||||
$iplookups = array();
|
||||
if ($plugins = get_list_of_plugins('iplookup')) {
|
||||
foreach ($plugins as $plugin) {
|
||||
$iplookups[$plugin] = $plugin;
|
||||
}
|
||||
}
|
||||
$temp->add(new admin_setting_configselect('iplookup', get_string('iplookup', 'admin'), get_string('configiplookup', 'admin'), 'hostip', $iplookups));
|
||||
|
||||
$ADMIN->add('location', $temp);
|
||||
|
||||
|
||||
$ADMIN->add('location', new admin_externalpage('timezoneimport', get_string('updatetimezones', 'admin'), "$CFG->wwwroot/$CFG->admin/timezoneimport.php"));
|
||||
|
||||
?>
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// * Miscellaneous settings
|
||||
|
||||
// Experimental settings page
|
||||
$temp = new admin_settingpage('experimental', get_string('experimental', 'admin'));
|
||||
$temp->add(new admin_setting_configcheckbox('enableajax', get_string('enableajax', 'admin'), get_string('configenableajax', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('enableglobalsearch', get_string('enableglobalsearch', 'admin'), get_string('configenableglobalsearch', 'admin'), 0));
|
||||
$ADMIN->add('misc', $temp);
|
||||
|
||||
// XMLDB editor
|
||||
$ADMIN->add('misc', new admin_externalpage('xmldbeditor', get_string('xmldbeditor'), "$CFG->wwwroot/$CFG->admin/xmldb/"));
|
||||
|
||||
|
||||
// hidden scripts linked from elsewhere
|
||||
$ADMIN->add('misc', new admin_externalpage('oacleanup', 'Online Assignment Cleanup', $CFG->wwwroot.'/'.$CFG->admin.'/oacleanup.php', 'moodle/site:config', true));
|
||||
$ADMIN->add('misc', new admin_externalpage('upgradeforumread', 'Upgrade forum', $CFG->wwwroot.'/'.$CFG->admin.'/upgradeforumread.php', 'moodle/site:config', true));
|
||||
$ADMIN->add('misc', new admin_externalpage('upgradelogs', 'Upgrade logs', $CFG->wwwroot.'/'.$CFG->admin.'/upgradelogs.php', 'moodle/site:config', true));
|
||||
|
||||
?>
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
|
||||
|
||||
// "sitepolicies" settingpage
|
||||
$temp = new admin_settingpage('sitepolicies', get_string('sitepolicies', 'admin'));
|
||||
$temp->add(new admin_setting_configcheckbox('protectusernames', get_string('protectusernames', 'admin'), get_string('configprotectusernames', 'admin'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('forcelogin', get_string('forcelogin', 'admin'), get_string('configforcelogin', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('forceloginforprofiles', get_string('forceloginforprofiles', 'admin'), get_string('configforceloginforprofiles', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('opentogoogle', get_string('opentogoogle', 'admin'), get_string('configopentogoogle', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configtext('maxbytes', get_string('maxbytes', 'admin'), get_string('configmaxbytes', 'admin'), 0, PARAM_INT));
|
||||
$temp->add(new admin_setting_configcheckbox('messaging', get_string('messaging', 'admin'), get_string('configmessaging','admin'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('allowobjectembed', get_string('allowobjectembed', 'admin'), get_string('configallowobjectembed', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('enabletrusttext', get_string('enabletrusttext', 'admin'), get_string('configenabletrusttext', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configselect('maxeditingtime', get_string('maxeditingtime','admin'), get_string('configmaxeditingtime','admin'), 1800,
|
||||
array(60 => get_string('numminutes', '', 1),
|
||||
300 => get_string('numminutes', '', 5),
|
||||
900 => get_string('numminutes', '', 15),
|
||||
1800 => get_string('numminutes', '', 30),
|
||||
2700 => get_string('numminutes', '', 45),
|
||||
3600 => get_string('numminutes', '', 60))));
|
||||
$temp->add(new admin_setting_configselect('fullnamedisplay', get_string('fullnamedisplay', 'admin'), get_string('configfullnamedisplay', 'admin'),
|
||||
'firstname lastname', array('language' => get_string('language'),
|
||||
'firstname lastname' => get_string('firstname') . ' + ' . get_string('lastname'),
|
||||
'lastname firstname' => get_string('lastname') . ' + ' . get_string('firstname'),
|
||||
'firstname' => get_string('firstname'))));
|
||||
$temp->add(new admin_setting_configcheckbox('extendedusernamechars', get_string('extendedusernamechars', 'admin'), get_string('configextendedusernamechars', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configtext('sitepolicy', get_string('sitepolicy', 'admin'), get_string('configsitepolicy', 'admin'), '', PARAM_URL));
|
||||
$temp->add(new admin_setting_configselect('bloglevel', get_string('bloglevel', 'admin'), get_string('configbloglevel', 'admin'), 4, array(5 => get_string('worldblogs','blog'),
|
||||
4 => get_string('siteblogs','blog'),
|
||||
3 => get_string('courseblogs','blog'),
|
||||
2 => get_string('groupblogs','blog'),
|
||||
1 => get_string('personalblogs','blog'),
|
||||
0 => get_string('disableblogs','blog'))));
|
||||
|
||||
$ADMIN->add('security', $temp);
|
||||
|
||||
|
||||
|
||||
|
||||
// "httpsecurity" settingpage
|
||||
$temp = new admin_settingpage('httpsecurity', get_string('httpsecurity', 'admin'));
|
||||
$temp->add(new admin_setting_configcheckbox('loginhttps', get_string('loginhttps', 'admin'), get_string('configloginhttps', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('secureforms', get_string('secureforms', 'admin'), get_string('configsecureforms', 'admin'), 0));
|
||||
$ADMIN->add('security', $temp);
|
||||
|
||||
|
||||
// "modulesecurity" settingpage
|
||||
$temp = new admin_settingpage('modulesecurity', get_string('modulesecurity', 'admin'));
|
||||
$temp->add(new admin_setting_configselect('restrictmodulesfor', get_string('restrictmodulesfor', 'admin'), get_string('configrestrictmodulesfor', 'admin'), 'none', array('none' => 'No courses',
|
||||
'all' => 'All courses',
|
||||
'requested' => 'Requested courses')));
|
||||
$temp->add(new admin_setting_configcheckbox('restrictbydefault', get_string('restrictbydefault', 'admin'), get_string('configrestrictbydefault', 'admin'), 0));
|
||||
if (!$options = get_records("modules")) {
|
||||
$options = array();
|
||||
}
|
||||
$options2 = array();
|
||||
foreach ($options as $option) {
|
||||
$options2[$option->id] = $option->name;
|
||||
}
|
||||
$temp->add(new admin_setting_configmultiselect('defaultallowedmodules', get_string('defaultallowedmodules', 'admin'), get_string('configdefaultallowedmodules', 'admin'), array(), $options2));
|
||||
$ADMIN->add('security', $temp);
|
||||
|
||||
|
||||
|
||||
// "notifications" settingpage
|
||||
$temp = new admin_settingpage('notifications', get_string('notifications', 'admin'));
|
||||
$temp->add(new admin_setting_configselect('displayloginfailures', get_string('displayloginfailures', 'admin'), get_string('configdisplayloginfailures', 'admin'), '', array('' => get_string('nobody'),
|
||||
'admin' => get_string('administrators'),
|
||||
'teacher' => get_string('administratorsandteachers'),
|
||||
'everybody' => get_string('everybody'))));
|
||||
$temp->add(new admin_setting_configselect('notifyloginfailures', get_string('notifyloginfailures', 'admin'), get_string('confignotifyloginfailures', 'admin'), '', array('' => get_string('nobody'),
|
||||
'mainadmin' => get_string('administrator'),
|
||||
'alladmins' => get_string('administratorsall'))));
|
||||
$options = array();
|
||||
for ($i = 1; $i <= 100; $i++) {
|
||||
$options[$i] = $i;
|
||||
}
|
||||
$temp->add(new admin_setting_configselect('notifyloginthreshold', get_string('notifyloginthreshold', 'admin'), get_string('confignotifyloginthreshold', 'admin'), '10', $options));
|
||||
$ADMIN->add('security', $temp);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// "antivirus" settingpage
|
||||
$temp = new admin_settingpage('antivirus', get_string('antivirus', 'admin'));
|
||||
$temp->add(new admin_setting_configcheckbox('runclamonupload', get_string('runclamavonupload', 'admin'), get_string('configrunclamavonupload', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configtext('pathtoclam', get_string('pathtoclam', 'admin'), get_string('configpathtoclam', 'admin'), '', PARAM_RAW)); // TODO: add path validation
|
||||
$temp->add(new admin_setting_configtext('quarantinedir', get_string('quarantinedir', 'admin'), get_string('configquarantinedir', 'admin'), '', PARAM_RAW)); // TODO: add path validation
|
||||
$temp->add(new admin_setting_configselect('clamfailureonupload', get_string('clamfailureonupload', 'admin'), get_string('configclamfailureonupload', 'admin'), 'donothing', array('donothing' => get_string('configclamdonothing', 'admin'),
|
||||
'actlikevirus' => get_string('configclamactlikevirus', 'admin'))));
|
||||
$ADMIN->add('security', $temp);
|
||||
|
||||
?>
|
||||
@@ -1,187 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// This file defines settingpages and externalpages under the "server" category
|
||||
|
||||
// "systempaths" settingpage
|
||||
$temp = new admin_settingpage('systempaths', get_string('systempaths','admin'));
|
||||
$temp->add(new admin_setting_configselect('gdversion', get_string('gdversion','admin'), get_string('configgdversion', 'admin'), check_gd_version(), array('0' => get_string('gdnot'),
|
||||
'1' => get_string('gd1'),
|
||||
'2' => get_string('gd2'))));
|
||||
$temp->add(new admin_setting_configtext('zip', get_string('pathtozip','admin'), get_string('configzip', 'admin'), '', PARAM_RAW)); // TODO: add path validation
|
||||
$temp->add(new admin_setting_configtext('unzip', get_string('pathtounzip','admin'), get_string('configunzip', 'admin'), '', PARAM_RAW)); // TODO: add path validation
|
||||
$temp->add(new admin_setting_configtext('pathtodu', get_string('pathtodu', 'admin'), get_string('configpathtodu', 'admin'), '', PARAM_RAW)); // TODO: add path validation
|
||||
$temp->add(new admin_setting_configtext('aspellpath', get_string('aspellpath', 'admin'), get_string('edhelpaspellpath'), '', PARAM_RAW)); // TODO: add path validation
|
||||
$ADMIN->add('server', $temp, 0);
|
||||
|
||||
|
||||
|
||||
// "email" settingpage
|
||||
$temp = new admin_settingpage('mail', get_string('mail','admin'));
|
||||
$temp->add(new admin_setting_configtext('smtphosts', get_string('smtphosts', 'admin'), get_string('configsmtphosts', 'admin'), '', PARAM_HOST));
|
||||
$temp->add(new admin_setting_configtext('smtpuser', get_string('smtpuser', 'admin'), get_string('configsmtpuser', 'admin'), '', PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configtext('smtppass', get_string('smtppass', 'admin'), get_string('configsmtpuser', 'admin'), '', PARAM_RAW));
|
||||
$temp->add(new admin_setting_configtext('noreplyaddress', get_string('noreplyaddress', 'admin'), get_string('confignoreplyaddress', 'admin'), 'noreply@' . $_SERVER['HTTP_HOST'], PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configtext('allowemailaddresses', get_string('allowemailaddresses', 'admin'), get_string('configallowemailaddresses', 'admin'), '', PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configtext('denyemailaddresses', get_string('denyemailaddresses', 'admin'), get_string('configdenyemailaddresses', 'admin'), '', PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configselect('digestmailtime', get_string('digestmailtime', 'admin'), get_string('configdigestmailtime', 'admin'), 17, array('00' => '00',
|
||||
'01' => '01',
|
||||
'02' => '02',
|
||||
'03' => '03',
|
||||
'04' => '04',
|
||||
'05' => '05',
|
||||
'06' => '06',
|
||||
'07' => '07',
|
||||
'08' => '08',
|
||||
'09' => '09',
|
||||
'10' => '10',
|
||||
'11' => '11',
|
||||
'12' => '12',
|
||||
'13' => '13',
|
||||
'14' => '14',
|
||||
'15' => '15',
|
||||
'16' => '16',
|
||||
'17' => '17',
|
||||
'18' => '18',
|
||||
'19' => '19',
|
||||
'20' => '20',
|
||||
'21' => '21',
|
||||
'22' => '22',
|
||||
'23' => '23')));
|
||||
if (!empty($CFG->unicodedb)) { // These options are only available if running under unicodedb
|
||||
unset($options);
|
||||
unset($charsets);
|
||||
$charsets = get_list_of_charsets();
|
||||
$options['0'] = get_string('none');
|
||||
$options = array_merge($options, $charsets);
|
||||
$temp->add(new admin_setting_configselect('sitemailcharset', get_string('sitemailcharset', 'admin'), get_string('configsitemailcharset','admin'), '', $options));
|
||||
$temp->add(new admin_setting_configcheckbox('allowusermailcharset', get_string('allowusermailcharset', 'admin'), get_string('configallowusermailcharset', 'admin'), 0));
|
||||
}
|
||||
$ADMIN->add('server', $temp, 100);
|
||||
|
||||
|
||||
|
||||
// "sessionhandling" settingpage
|
||||
$temp = new admin_settingpage('sessionhandling', get_string('sessionhandling', 'admin'));
|
||||
$temp->add(new admin_setting_configcheckbox('dbsessions', get_string('dbsessions', 'admin'), get_string('configdbsessions', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configselect('sessiontimeout', get_string('sessiontimeout', 'admin'), get_string('configsessiontimeout', 'admin'), 7200, array(14400 => get_string('numhours', '', 4),
|
||||
10800 => get_string('numhours', '', 3),
|
||||
7200 => get_string('numhours', '', 2),
|
||||
5400 => get_string('numhours', '', '1.5'),
|
||||
3600 => get_string('numminutes', '', 60),
|
||||
2700 => get_string('numminutes', '', 45),
|
||||
1800 => get_string('numminutes', '', 30),
|
||||
900 => get_string('numminutes', '', 15),
|
||||
300 => get_string('numminutes', '', 5))));
|
||||
$temp->add(new admin_setting_configtext('sessioncookie', get_string('sessioncookie', 'admin'), get_string('configsessioncookie', 'admin'), '', PARAM_ALPHANUM));
|
||||
$temp->add(new admin_setting_configtext('sessioncookiepath', get_string('sessioncookiepath', 'admin'), get_string('configsessioncookiepath', 'admin'), '/', PARAM_LOCALURL));
|
||||
$ADMIN->add('server', $temp, 50);
|
||||
|
||||
|
||||
|
||||
// "rss" settingpage
|
||||
$temp = new admin_settingpage('rss', get_string('rss'));
|
||||
$temp->add(new admin_setting_configcheckbox('enablerssfeeds', get_string('enablerssfeeds', 'admin'), get_string('configenablerssfeeds', 'admin'), 0));
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
|
||||
// "debugging" settingpage
|
||||
$temp = new admin_settingpage('debugging', get_string('debugging', 'admin'));
|
||||
$temp->add(new admin_setting_special_debug());
|
||||
$temp->add(new admin_setting_special_perfdebug());
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
|
||||
// "stats" settingpage
|
||||
$temp = new admin_settingpage('stats', get_string('stats'));
|
||||
$temp->add(new admin_setting_configcheckbox('enablestats', get_string('enablestats', 'admin'), get_string('configenablestats', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configselect('statsfirstrun', get_string('statsfirstrun', 'admin'), get_string('configstatsfirstrun', 'admin'), 'none', array('none' => get_string('none'),
|
||||
60*60*24*7 => get_string('numweeks','moodle',1),
|
||||
60*60*24*14 => get_string('numweeks','moodle',2),
|
||||
60*60*24*21 => get_string('numweeks','moodle',3),
|
||||
60*60*24*28 => get_string('nummonths','moodle',1),
|
||||
60*60*24*56 => get_string('nummonths','moodle',2),
|
||||
60*60*24*84 => get_string('nummonths','moodle',3),
|
||||
60*60*24*112 => get_string('nummonths','moodle',4),
|
||||
60*60*24*140 => get_string('nummonths','moodle',5),
|
||||
60*60*24*168 => get_string('nummonths','moodle',6),
|
||||
'all' => get_string('all') )));
|
||||
$temp->add(new admin_setting_configselect('statsmaxruntime', get_string('statsmaxruntime', 'admin'), get_string('configstatsmaxruntime', 'admin'), 0, array(0 => get_string('untilcomplete'),
|
||||
60*60 => '1 '.get_string('hour'),
|
||||
60*60*2 => '2 '.get_string('hours'),
|
||||
60*60*3 => '3 '.get_string('hours'),
|
||||
60*60*4 => '4 '.get_string('hours'),
|
||||
60*60*5 => '5 '.get_string('hours'),
|
||||
60*60*6 => '6 '.get_string('hours'),
|
||||
60*60*7 => '7 '.get_string('hours'),
|
||||
60*60*8 => '8 '.get_string('hours') )));
|
||||
$temp->add(new admin_setting_configtime('statsruntimestarthour', 'statsruntimestartminute', get_string('statsruntimestart', 'admin'), get_string('configstatsruntimestart', 'admin'), array('h' => 0, 'm' => 0)));
|
||||
$temp->add(new admin_setting_configtext('statsuserthreshold', get_string('statsuserthreshold', 'admin'), get_string('configstatsuserthreshold', 'admin'), 0, PARAM_INT));
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
|
||||
// "http" settingpage
|
||||
$temp = new admin_settingpage('http', get_string('http', 'admin'));
|
||||
$temp->add(new admin_setting_configtext('framename', get_string('framename', 'admin'), get_string('configframename', 'admin'), '_top', PARAM_ALPHAEXT));
|
||||
$temp->add(new admin_Setting_configcheckbox('slasharguments', get_string('slasharguments', 'admin'), get_string('configslasharguments', 'admin'), 1));
|
||||
$temp->add(new admin_setting_configtext('proxyhost', get_string('proxyhost', 'admin'), get_string('configproxyhost', 'admin'), '', PARAM_HOST));
|
||||
$temp->add(new admin_setting_configtext('proxyport', get_string('proxyport', 'admin'), get_string('configproxyport', 'admin'), 0, PARAM_INT));
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
$ADMIN->add('server', new admin_externalpage('sitefiles', get_string('sitefiles'), $CFG->wwwroot . '/files/index.php?id=' . SITEID));
|
||||
|
||||
$ADMIN->add('server', new admin_externalpage('maintenancemode', get_string('sitemaintenancemode', 'admin'), "$CFG->wwwroot/$CFG->admin/maintenance.php"));
|
||||
|
||||
|
||||
$temp = new admin_settingpage('cleanup', get_string('cleanup', 'admin'));
|
||||
$temp->add(new admin_setting_configselect('longtimenosee', get_string('longtimenosee', 'admin'), get_string('configlongtimenosee', 'admin'), 120, array(0 => get_string('never'),
|
||||
1000 => get_string('numdays', '', 1000),
|
||||
365 => get_string('numdays', '', 365),
|
||||
180 => get_string('numdays', '', 180),
|
||||
150 => get_string('numdays', '', 150),
|
||||
120 => get_string('numdays', '', 120),
|
||||
90 => get_string('numdays', '', 90),
|
||||
60 => get_string('numdays', '', 60),
|
||||
30 => get_string('numdays', '', 30),
|
||||
21 => get_string('numdays', '', 21),
|
||||
14 => get_string('numdays', '', 14),
|
||||
7 => get_string('numdays', '', 7) )));
|
||||
$temp->add(new admin_setting_configselect('deleteunconfirmed', get_string('deleteunconfirmed', 'admin'), get_string('configdeleteunconfirmed', 'admin'), 168, array(0 => get_string('never'),
|
||||
168 => get_string('numdays', '', 7),
|
||||
144 => get_string('numdays', '', 6),
|
||||
120 => get_string('numdays', '', 5),
|
||||
96 => get_string('numdays', '', 4),
|
||||
72 => get_string('numdays', '', 3),
|
||||
48 => get_string('numdays', '', 2),
|
||||
24 => get_string('numdays', '', 1),
|
||||
12 => get_string('numhours', '', 12),
|
||||
6 => get_string('numhours', '', 6),
|
||||
1 => get_string('numhours', '', 1))));
|
||||
|
||||
$temp->add(new admin_setting_configselect('loglifetime', get_string('loglifetime', 'admin'), get_string('configloglifetime', 'admin'), 0, array(0 => get_string('neverdeletelogs'),
|
||||
1000 => get_string('numdays', '', 1000),
|
||||
365 => get_string('numdays', '', 365),
|
||||
180 => get_string('numdays', '', 180),
|
||||
150 => get_string('numdays', '', 150),
|
||||
120 => get_string('numdays', '', 120),
|
||||
90 => get_string('numdays', '', 90),
|
||||
60 => get_string('numdays', '', 60),
|
||||
30 => get_string('numdays', '', 30))));
|
||||
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
|
||||
|
||||
$ADMIN->add('server', new admin_externalpage('environment', get_string('environment','admin'), "$CFG->wwwroot/$CFG->admin/environment.php"));
|
||||
$ADMIN->add('server', new admin_externalpage('phpinfo', get_string('phpinfo'), "$CFG->wwwroot/$CFG->admin/phpinfo.php"));
|
||||
|
||||
|
||||
// "performance" settingpage
|
||||
$temp = new admin_settingpage('performance', get_string('performance', 'admin'));
|
||||
$temp->add(new admin_setting_configcheckbox('enablerecordcache', get_string('enablerecordcache', 'admin'), get_string('configenablerecordcache', 'admin'), 1));
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
if (file_exists("$CFG->dirroot/$CFG->admin/mysql/frame.php")) {
|
||||
$ADMIN->add('server', new admin_externalpage('database', get_string('managedatabase'), "$CFG->wwwroot/$CFG->admin/mysql/frame.php"));
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// This is the first file read by the lib/adminlib.php script
|
||||
// We use it to create the categories in correct order,
|
||||
// since they need to exist *before* settingpages and externalpages
|
||||
// are added to them.
|
||||
|
||||
$ADMIN->add('root', new admin_externalpage('adminnotifications', get_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
|
||||
|
||||
// hidden upgrade script
|
||||
$ADMIN->add('root', new admin_externalpage('upgradesettings', get_string('upgradesettings', 'admin'), "$CFG->wwwroot/$CFG->admin/upgradesettings.php", 'moodle/site:config', true));
|
||||
|
||||
// hidden search script
|
||||
$ADMIN->add('root', new admin_externalpage('search', get_string('search', 'admin'), "$CFG->wwwroot/$CFG->admin/search.php", 'moodle/site:config', true));
|
||||
|
||||
$ADMIN->add('root', new admin_category('users', get_string('users','admin')));
|
||||
$ADMIN->add('root', new admin_category('courses', get_string('courses','admin')));
|
||||
$ADMIN->add('root', new admin_category('location', get_string('location','admin')));
|
||||
$ADMIN->add('root', new admin_category('language', get_string('language')));
|
||||
|
||||
$ADMIN->add('root', new admin_category('modules', get_string('plugins', 'admin')));
|
||||
$ADMIN->add('modules', new admin_externalpage('managemodules', get_string('activities'), "$CFG->wwwroot/$CFG->admin/modules.php"));
|
||||
$ADMIN->add('modules', new admin_externalpage('manageblocks', get_string('blocks'), "$CFG->wwwroot/$CFG->admin/blocks.php"));
|
||||
$ADMIN->add('modules', new admin_externalpage('managefilters', get_string('managefilters'), "$CFG->wwwroot/$CFG->admin/filters.php"));
|
||||
|
||||
$ADMIN->add('root', new admin_category('security', get_string('security','admin')));
|
||||
$ADMIN->add('root', new admin_category('appearance', get_string('appearance','admin')));
|
||||
$ADMIN->add('root', new admin_category('server', get_string('server','admin')));
|
||||
|
||||
$ADMIN->add('root', new admin_category('reports', get_string('reports')));
|
||||
foreach (get_list_of_plugins('admin/report') as $plugin) {
|
||||
/// This snippet is temporary until simpletest can be fixed to use xmldb. See MDL-7377 XXX TODO
|
||||
if ($plugin == 'simpletest' && $CFG->dbtype != 'mysql' && $CFG->dbtype != 'postgres7') {
|
||||
continue;
|
||||
}
|
||||
/// End of removable snippet
|
||||
$ADMIN->add('reports', new admin_externalpage('report'.$plugin, get_string($plugin, 'admin'), "$CFG->wwwroot/$CFG->admin/report/$plugin/index.php"));
|
||||
}
|
||||
|
||||
$ADMIN->add('root', new admin_category('misc', get_string('miscellaneous')));
|
||||
|
||||
// hidden unsupported category
|
||||
$ADMIN->add('root', new admin_category('unsupported', get_string('unsupported', 'admin'), true));
|
||||
|
||||
?>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// This file defines settingpages and externalpages in the "unsupported" hidden category, use wisely!
|
||||
|
||||
$ADMIN->add('unsupported', new admin_externalpage('purgemoodledata', 'Purge moodledata', $CFG->wwwroot.'/'.$CFG->admin.'/delete.php'));
|
||||
$ADMIN->add('unsupported', new admin_externalpage('healthcenter', get_string('healthcenter'), $CFG->wwwroot.'/'.$CFG->admin.'/health.php'));
|
||||
$ADMIN->add('unsupported', new admin_externalpage('toinodb', 'Convert to InnoDB', $CFG->wwwroot.'/'.$CFG->admin.'/innodb.php'));
|
||||
$ADMIN->add('unsupported', new admin_externalpage('replace', 'Search and replace', $CFG->wwwroot.'/'.$CFG->admin.'/replace.php'));
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// This file defines settingpages and externalpages under the "users" category
|
||||
|
||||
|
||||
$ADMIN->add('users', new admin_externalpage('userauthentication', get_string('authentication','admin'), "$CFG->wwwroot/$CFG->admin/auth.php"));
|
||||
|
||||
|
||||
// stuff under the "accounts" subcategory
|
||||
$ADMIN->add('users', new admin_category('accounts', get_string('accounts', 'admin')));
|
||||
$ADMIN->add('accounts', new admin_externalpage('editusers', get_string('userlist','admin'), "$CFG->wwwroot/$CFG->admin/user.php", array('moodle/user:update', 'moodle/user:delete')));
|
||||
$ADMIN->add('accounts', new admin_externalpage('addnewuser', get_string('addnewuser'), "$CFG->wwwroot/$CFG->admin/user.php?newuser=true", 'moodle/user:create'));
|
||||
$ADMIN->add('accounts', new admin_externalpage('uploadusers', get_string('uploadusers'), "$CFG->wwwroot/$CFG->admin/uploaduser.php", 'moodle/site:uploadusers'));
|
||||
|
||||
|
||||
// stuff under the "roles" subcategory
|
||||
$ADMIN->add('users', new admin_category('roles', get_string('permissions', 'role')));
|
||||
$ADMIN->add('roles', new admin_externalpage('defineroles', get_string('defineroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/manage.php"));
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$ADMIN->add('roles', new admin_externalpage('assignroles', get_string('assignroles', 'role'), "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=" . $sitecontext->id));
|
||||
|
||||
|
||||
// "userpolicies" settingpage
|
||||
$temp = new admin_settingpage('userpolicies', get_string('userpolicies', 'admin'));
|
||||
|
||||
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
|
||||
if (!$guestrole = get_guest_role()) {
|
||||
$guestrole->id = 0;
|
||||
}
|
||||
if ($studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
|
||||
$studentrole = array_shift($studentroles); /// Take the first one
|
||||
} else {
|
||||
$studentrole->id = 0;
|
||||
}
|
||||
$assignableroles = get_assignable_roles($context);
|
||||
|
||||
$temp->add(new admin_setting_configselect('notloggedinroleid', get_string('notloggedinroleid', 'admin'),
|
||||
get_string('confignotloggedinroleid', 'admin'), $guestrole->id, $assignableroles ));
|
||||
$temp->add(new admin_setting_configselect('defaultuserroleid', get_string('defaultuserroleid', 'admin'),
|
||||
get_string('configdefaultuserroleid', 'admin'), $guestrole->id, $assignableroles));
|
||||
$temp->add(new admin_setting_configselect('defaultcourseroleid', get_string('defaultcourseroleid', 'admin'),
|
||||
get_string('configdefaultcourseroleid', 'admin'), $studentrole->id, $assignableroles));
|
||||
|
||||
$temp->add(new admin_setting_configcheckbox('autologinguests', get_string('autologinguests', 'admin'), get_string('configautologinguests', 'admin'), 0));
|
||||
//$temp->add(new admin_setting_configcheckbox('allusersaresitestudents', get_string('allusersaresitestudents', 'admin'), get_string('configallusersaresitestudents','admin'), 1));
|
||||
$temp->add(new admin_setting_configmultiselect('hiddenuserfields', get_string('hiddenuserfields', 'admin'),
|
||||
get_string('confighiddenuserfields', 'admin'), array(),
|
||||
array('none' => get_string('none'),
|
||||
'description' => get_string('description'),
|
||||
'city' => get_string('city'),
|
||||
'country' => get_string('country'),
|
||||
'webpage' => get_string('webpage'),
|
||||
'icqnumber' => get_string('icqnumber'),
|
||||
'skypeid' => get_string('skypeid'),
|
||||
'yahooid' => get_string('yahooid'),
|
||||
'aimid' => get_string('aimid'),
|
||||
'msnid' => get_string('msnid'),
|
||||
'lastaccess' => get_string('lastaccess'))));
|
||||
//$temp->add(new admin_setting_special_adminseesall());
|
||||
|
||||
|
||||
$ADMIN->add('roles', $temp);
|
||||
|
||||
|
||||
?>
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
<form method="post" action="site.php" name="form" <?php echo $onsubmit ?>>
|
||||
<table cellpadding=9 cellspacing=0 >
|
||||
<tr valign=top>
|
||||
<td align=right><P><?php print_string("fullsitename") ?>:</td>
|
||||
<td><input type="text" name="fullname" size=50 value="<?php p($form->fullname) ?>">
|
||||
<?php if (isset($err["fullname"])) formerr($err["fullname"]); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><P><?php print_string("shortsitename") ?>:</td>
|
||||
<td><input type="text" name="shortname" size=50 value="<?php p($form->shortname) ?>">
|
||||
<?php if (isset($err["shortname"])) formerr($err["shortname"]); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><P><?php print_string("frontpagedescription") ?>:</P><br />
|
||||
<font size=1>
|
||||
<?PHP
|
||||
helpbutton("writing", get_string("helpwriting"), "moodle", true, true);
|
||||
echo "<br />";
|
||||
if ($usehtmleditor) {
|
||||
helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
|
||||
} else {
|
||||
helpbutton("html", get_string("helphtml"), "moodle", true, true);
|
||||
}
|
||||
?>
|
||||
<br />
|
||||
</font>
|
||||
</td>
|
||||
<td><?php print_textarea($usehtmleditor, 20, 50, 600, 400, "summary", $form->summary); ?></td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><P><?php print_string("frontpageformat") ?>:</td>
|
||||
<td><?php
|
||||
$options = array("0" => get_string("frontpagenews"),
|
||||
"1" => get_string("frontpagecourselist"),
|
||||
"2" => get_string("frontpagecategorynames"));
|
||||
if (count_records("course") > 200) {
|
||||
unset($options[1]);
|
||||
if ($form->frontpage == 1) {
|
||||
$form->frontpage = 2;
|
||||
}
|
||||
}
|
||||
choose_from_menu ($options, "frontpage", "$form->frontpage", "");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p><?php print_string("newsitemsnumber") ?>:</td>
|
||||
<td><?php
|
||||
$newsitem = get_string("newsitem");
|
||||
$newsitems = get_string("newsitems");
|
||||
$options = array("0" => "0 $newsitems",
|
||||
"1" => "1 $newsitem",
|
||||
"2" => "2 $newsitems",
|
||||
"3" => "3 $newsitems",
|
||||
"4" => "4 $newsitems",
|
||||
"5" => "5 $newsitems",
|
||||
"6" => "6 $newsitems",
|
||||
"7" => "7 $newsitems",
|
||||
"8" => "8 $newsitems",
|
||||
"9" => "9 $newsitems",
|
||||
"10" => "10 $newsitems");
|
||||
choose_from_menu ($options, "newsitems", "$form->newsitems", "");
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p><?php print_string("wordforteacher") ?>:</td>
|
||||
<td><input type="text" name="teacher" maxlength="100" size=25 value="<?php p($form->teacher) ?>">
|
||||
(<?php print_string("wordforteachereg") ?>)
|
||||
<?php if (isset($err["teacher"])) formerr($err["teacher"]); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p><?php print_string("wordforteachers") ?>:</td>
|
||||
<td><input type="text" name="teachers" maxlength="100" size=25 value="<?php p($form->teachers) ?>">
|
||||
(<?php print_string("wordforteacherseg") ?>)
|
||||
<?php if (isset($err["teachers"])) formerr($err["teachers"]); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p><?php print_string("wordforstudent") ?>:</td>
|
||||
<td><input type="text" name="student" maxlength="100" size=25 value="<?php p($form->student) ?>">
|
||||
(<?php print_string("wordforstudenteg") ?>)
|
||||
<?php if (isset($err["student"])) formerr($err["student"]); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign=top>
|
||||
<td align=right><p><?php print_string("wordforstudents") ?>:</td>
|
||||
<td><input type="text" name="students" maxlength="100" size=25 value="<?php p($form->students) ?>">
|
||||
(<?php print_string("wordforstudentseg") ?>)
|
||||
<?php if (isset($err["students"])) formerr($err["students"]); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><input type="submit" value="<?php print_string("savechanges") ?>"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type="hidden" name="id" value="<?php p($form->id) ?>">
|
||||
<input type="hidden" name="category" value="<?php p($form->category) ?>">
|
||||
<input type="hidden" name="format" value="<?php p($form->format) ?>">
|
||||
</form>
|
||||
|
||||
<?php
|
||||
if ($usehtmleditor) {
|
||||
print_richedit_javascript("form", "summary", "no");
|
||||
}
|
||||
?>
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
require_once("../config.php");
|
||||
|
||||
if ($site = get_site()) {
|
||||
require_login();
|
||||
if (!isadmin()) {
|
||||
error("You need to be admin to edit this page");
|
||||
}
|
||||
$site->format = "social"; // override
|
||||
}
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($form = data_submitted()) {
|
||||
|
||||
validate_form($form, $err);
|
||||
|
||||
if (count($err) == 0) {
|
||||
|
||||
set_config("frontpage", $form->frontpage);
|
||||
|
||||
$form->timemodified = time();
|
||||
|
||||
if ($form->id) {
|
||||
if (update_record("course", $form)) {
|
||||
redirect("$CFG->wwwroot/", get_string("changessaved"));
|
||||
} else {
|
||||
error("Serious Error! Could not update the site record! (id = $form->id)");
|
||||
}
|
||||
} else {
|
||||
if ($newid = insert_record("course", $form)) {
|
||||
$cat->name = get_string("miscellaneous");
|
||||
if (insert_record("course_categories", $cat)) {
|
||||
redirect("$CFG->wwwroot/$CFG->admin/index.php", get_string("changessaved"), 1);
|
||||
} else {
|
||||
error("Serious Error! Could not set up a default course category!");
|
||||
}
|
||||
} else {
|
||||
error("Serious Error! Could not set up the site!");
|
||||
}
|
||||
}
|
||||
die;
|
||||
|
||||
} else {
|
||||
foreach ($err as $key => $value) {
|
||||
$focus = "form.$key";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Otherwise fill and print the form.
|
||||
|
||||
if ($site and empty($form)) {
|
||||
$form = $site;
|
||||
$course = $site;
|
||||
$firsttime = false;
|
||||
} else {
|
||||
$form->fullname = "";
|
||||
$form->shortname = "";
|
||||
$form->summary = "";
|
||||
$form->newsitems = 3;
|
||||
$form->id = "";
|
||||
$form->category = 0;
|
||||
$form->format = "social";
|
||||
$form->teacher = get_string("defaultcourseteacher");
|
||||
$form->teachers = get_string("defaultcourseteachers");
|
||||
$form->student = get_string("defaultcoursestudent");
|
||||
$form->students = get_string("defaultcoursestudents");
|
||||
$firsttime = true;
|
||||
}
|
||||
|
||||
if (isset($CFG->frontpage)) {
|
||||
$form->frontpage = $CFG->frontpage;
|
||||
|
||||
} else {
|
||||
if ($form->newsitems > 0) {
|
||||
$form->frontpage = 0;
|
||||
} else {
|
||||
$form->frontpage = 1;
|
||||
}
|
||||
set_config("frontpage", $form->frontpage);
|
||||
}
|
||||
|
||||
if (empty($focus)) {
|
||||
$focus = "form.fullname";
|
||||
}
|
||||
|
||||
$stradmin = get_string("administration");
|
||||
$strconfiguration = get_string("configuration");
|
||||
$strsitesettings = get_string("sitesettings");
|
||||
|
||||
if ($firsttime) {
|
||||
print_header();
|
||||
print_heading($strsitesettings);
|
||||
print_simple_box(get_string("configintrosite"), "center", "50%");
|
||||
echo "<br />";
|
||||
} else {
|
||||
print_header("$site->shortname: $strsitesettings", "$site->fullname",
|
||||
"<a href=\"index.php\">$stradmin</a> -> ".
|
||||
"<a href=\"configure.php\">$strconfiguration</a> -> $strsitesettings", "$focus");
|
||||
print_heading($strsitesettings);
|
||||
}
|
||||
|
||||
$defaultformat = FORMAT_HTML;
|
||||
if ($usehtmleditor = can_use_richtext_editor()) {
|
||||
$onsubmit = "onsubmit=\"copyrichtext(form.summary);\"";
|
||||
} else {
|
||||
$onsubmit = "";
|
||||
}
|
||||
|
||||
print_simple_box_start("center", "", "$THEME->cellheading");
|
||||
include("site.html");
|
||||
print_simple_box_end();
|
||||
|
||||
if (!$firsttime) {
|
||||
print_footer();
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
/// Functions /////////////////////////////////////////////////////////////////
|
||||
|
||||
function validate_form(&$form, &$err) {
|
||||
|
||||
if (empty($form->fullname))
|
||||
$err["fullname"] = get_string("missingsitename");
|
||||
|
||||
if (empty($form->shortname))
|
||||
$err["shortname"] = get_string("missingshortsitename");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,87 +0,0 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->dirroot.'/my/pagelib.php');
|
||||
require_once($CFG->dirroot.'/lib/pagelib.php');
|
||||
require_once($CFG->dirroot.'/lib/blocklib.php');
|
||||
|
||||
$pt = optional_param('pt', null, PARAM_SAFEDIR); //alhanumeric and -
|
||||
|
||||
$pagetypes = array(PAGE_MY_MOODLE => array('id' => PAGE_MY_MOODLE,
|
||||
'lib' => '/my/pagelib.php',
|
||||
'name' => get_string('mymoodle','admin')),
|
||||
PAGE_COURSE_VIEW => array('id' => PAGE_COURSE_VIEW,
|
||||
'lib' => '/lib/pagelib.php',
|
||||
'name' => get_string('stickyblockscourseview','admin'))
|
||||
// ... more?
|
||||
);
|
||||
|
||||
// for choose_from_menu
|
||||
$options = array();
|
||||
foreach ($pagetypes as $p) {
|
||||
$options[$p['id']] = $p['name'];
|
||||
}
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
|
||||
// first thing to do is print the dropdown menu
|
||||
|
||||
$strtitle = get_string('stickyblocks','admin');
|
||||
$strheading = get_string('adminhelpstickyblocks');
|
||||
|
||||
|
||||
|
||||
if (!empty($pt)) {
|
||||
|
||||
require_once($CFG->dirroot.$pagetypes[$pt]['lib']);
|
||||
|
||||
define('ADMIN_STICKYBLOCKS',$pt);
|
||||
|
||||
$PAGE = page_create_object($pt, SITEID);
|
||||
$blocks = blocks_setup($PAGE,BLOCKS_PINNED_TRUE);
|
||||
$blocks_preferred_width = bounded_number(180, blocks_preferred_width($blocks[BLOCK_POS_LEFT]), 210);
|
||||
|
||||
print_header($strtitle,$strtitle,'<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/index.php">'.
|
||||
get_string('administration').'</a> -> '.$strtitle);
|
||||
|
||||
echo '<table border="0" cellpadding="3" cellspacing="0" width="100%" id="layout-table">';
|
||||
echo '<tr valign="top">';
|
||||
|
||||
echo '<td valign="top" style="width: '.$blocks_preferred_width.'px;" id="left-column">';
|
||||
|
||||
blocks_print_group($PAGE, $blocks, BLOCK_POS_LEFT);
|
||||
echo '</td>';
|
||||
echo '<td valign="top" id="middle-column">';
|
||||
|
||||
} else {
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('stickyblocks', $adminroot);
|
||||
admin_externalpage_print_header($adminroot);
|
||||
}
|
||||
|
||||
|
||||
print_simple_box_start('center');
|
||||
print_heading($strheading);
|
||||
echo '<form method="post" action="'.$CFG->wwwroot.'/'.$CFG->admin.'/stickyblocks.php">'
|
||||
.'<p align="center">'.get_string('stickyblockspagetype','admin').': ';
|
||||
choose_from_menu($options,'pt',$pt,'choose','this.form.submit();');
|
||||
echo '</p></form>';
|
||||
echo get_string('stickyblocksduplicatenotice','admin');
|
||||
print_simple_box_end();
|
||||
|
||||
|
||||
if (!empty($pt)) {
|
||||
echo '</td>';
|
||||
echo '<td valign="top" style="width: '.$blocks_preferred_width.'px;" id="left-column">';
|
||||
blocks_print_group($PAGE, $blocks, BLOCK_POS_RIGHT);
|
||||
echo '</td>';
|
||||
echo '</tr></table>';
|
||||
print_footer();
|
||||
} else {
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
}
|
||||
|
||||
?>
|
||||
+27
-12
@@ -1,12 +1,12 @@
|
||||
<?php // $Id$
|
||||
|
||||
require_once('../config.php');
|
||||
|
||||
$zone = optional_param('zone', '', PARAM_PATH); //not a path, but it looks like it anyway
|
||||
include("../config.php");
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
if (!isadmin()) {
|
||||
error("You must be an admin");
|
||||
}
|
||||
|
||||
$strtimezone = get_string("timezone");
|
||||
$strsavechanges = get_string("savechanges");
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
print_heading("");
|
||||
|
||||
if (!empty($zone) and confirm_sesskey()) {
|
||||
if (isset($zone)) {
|
||||
$db->debug = true;
|
||||
echo "<center>";
|
||||
execute_sql("UPDATE {$CFG->prefix}user SET timezone = '$zone'");
|
||||
@@ -27,15 +27,30 @@
|
||||
$USER->timezone = $zone;
|
||||
}
|
||||
|
||||
require_once($CFG->dirroot.'/calendar/lib.php');
|
||||
$timezones = get_list_of_timezones();
|
||||
$user = $USER;
|
||||
|
||||
echo '<center><form action="timezone.php" method="get">';
|
||||
if (abs($user->timezone) > 13) {
|
||||
$user->timezone = 99;
|
||||
}
|
||||
$timenow = time();
|
||||
|
||||
for ($tz = -26; $tz <= 26; $tz++) {
|
||||
$zone = (float)$tz/2.0;
|
||||
$usertime = $timenow + ($tz * 1800);
|
||||
if ($tz == 0) {
|
||||
$timezones["$zone"] = gmstrftime("%a, %I:%M %p", $usertime)." (GMT)";
|
||||
} else if ($tz < 0) {
|
||||
$timezones["$zone"] = gmstrftime("%a, %I:%M %p", $usertime)." (GMT$zone)";
|
||||
} else {
|
||||
$timezones["$zone"] = gmstrftime("%a, %I:%M %p", $usertime)." (GMT+$zone)";
|
||||
}
|
||||
}
|
||||
|
||||
echo "<center><form action=timezone.php method=get>";
|
||||
echo "$strusers ($strall): ";
|
||||
choose_from_menu ($timezones, "zone", 99, get_string("serverlocaltime"), "", "99");
|
||||
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\">";
|
||||
echo "<input type=\"submit\" value=\"$strsavechanges\">";
|
||||
echo "</form></center>";
|
||||
choose_from_menu ($timezones, "zone", $user->timezone, get_string("serverlocaltime"), "", "99");
|
||||
echo "<input type=submit value=\"$strsavechanges\">";
|
||||
echo "</form>";
|
||||
|
||||
print_footer();
|
||||
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// Automatic update of Timezones from a new source
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->libdir.'/olson.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('timezoneimport', $adminroot);
|
||||
|
||||
$ok = optional_param('ok', 0, PARAM_BOOL);
|
||||
|
||||
|
||||
/// Print headings
|
||||
|
||||
$strcalendarsettings = get_string('calendarsettings', 'admin');
|
||||
$strimporttimezones = get_string('importtimezones', 'admin');
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
print_heading($strimporttimezones);
|
||||
|
||||
if (!$ok or !confirm_sesskey()) {
|
||||
$message = '<p>';
|
||||
$message .= $CFG->dataroot.'/temp/olson.txt<br />';
|
||||
$message .= $CFG->dataroot.'/temp/timezones.txt<br />';
|
||||
$message .= '<a href="http://download.moodle.org/timezones/">http://download.moodle.org/timezones/</a><br />';
|
||||
$message .= '<a href="'.$CFG->wwwroot.'/lib/timezones.txt">'.$CFG->dirroot.'/lib/timezones.txt</a><br />';
|
||||
$message .= '</p>';
|
||||
|
||||
$message = get_string("configintrotimezones", 'admin', $message);
|
||||
|
||||
notice_yesno($message, 'timezoneimport.php?ok=1&sesskey='.sesskey(), 'index.php');
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/// Try to find a source of timezones to import from
|
||||
|
||||
$importdone = false;
|
||||
|
||||
/// First, look for an Olson file locally
|
||||
|
||||
$source = $CFG->dataroot.'/temp/olson.txt';
|
||||
if (!$importdone and is_readable($source)) {
|
||||
if ($timezones = olson_to_timezones($source)) {
|
||||
update_timezone_records($timezones);
|
||||
$importdone = $source;
|
||||
}
|
||||
}
|
||||
|
||||
/// Next, look for a CSV file locally
|
||||
|
||||
$source = $CFG->dataroot.'/temp/timezones.txt';
|
||||
if (!$importdone and is_readable($source)) {
|
||||
if ($timezones = get_records_csv($source, 'timezone')) {
|
||||
update_timezone_records($timezones);
|
||||
$importdone = $source;
|
||||
}
|
||||
}
|
||||
|
||||
/// Otherwise, let's try moodle.org's copy
|
||||
|
||||
$source = 'http://download.moodle.org/timezones/';
|
||||
if (!$importdone and ini_get('allow_url_fopen')) {
|
||||
if (is_readable($source) && $contents = file_get_contents($source)) { // Grab whole page
|
||||
if ($file = fopen($CFG->dataroot.'/temp/timezones.txt', 'w')) { // Make local copy
|
||||
fwrite($file, $contents);
|
||||
fclose($file);
|
||||
if ($timezones = get_records_csv($CFG->dataroot.'/temp/timezones.txt', 'timezone')) { // Parse it
|
||||
update_timezone_records($timezones);
|
||||
$importdone = $source;
|
||||
}
|
||||
unlink($CFG->dataroot.'/temp/timezones.txt');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Final resort, use the copy included in Moodle
|
||||
|
||||
$source = $CFG->dirroot.'/lib/timezones.txt';
|
||||
if (!$importdone and is_readable($source)) { // Distribution file
|
||||
if ($timezones = get_records_csv($source, 'timezone')) {
|
||||
update_timezone_records($timezones);
|
||||
$importdone = $source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// That's it!
|
||||
|
||||
if ($importdone) {
|
||||
$a = null;
|
||||
$a->count = count($timezones);
|
||||
$a->source = $importdone;
|
||||
print_heading(get_string('importtimezonescount', 'admin', $a), '', 3);
|
||||
|
||||
print_continue('index.php');
|
||||
|
||||
$timezonelist = array();
|
||||
foreach ($timezones as $timezone) {
|
||||
if (isset($timezonelist[$timezone->name])) {
|
||||
$timezonelist[$timezone->name]++;
|
||||
} else {
|
||||
$timezonelist[$timezone->name] = 1;
|
||||
}
|
||||
}
|
||||
ksort($timezonelist);
|
||||
|
||||
echo "<br />";
|
||||
print_simple_box_start('center');
|
||||
foreach ($timezonelist as $name => $count) {
|
||||
echo "$name ($count)<br />";
|
||||
}
|
||||
print_simple_box_end();
|
||||
|
||||
} else {
|
||||
print_heading(get_string('importtimezonesfailed', 'admin'), '', 3);
|
||||
print_continue('index.php');
|
||||
}
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
?>
|
||||
@@ -1,113 +0,0 @@
|
||||
<?PHP //$Id$
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->dirroot.'/mod/forum/lib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('upgradeforumread', $adminroot);
|
||||
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
|
||||
if ($CFG->version < 2005042300) {
|
||||
error("This script does not work with this old version of Moodle");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
redirect('index.php');
|
||||
}
|
||||
|
||||
|
||||
/// Print header
|
||||
|
||||
$strupgradingdata = get_string('upgradingdata', 'admin');
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_heading($strupgradingdata);
|
||||
|
||||
if (!data_submitted() or empty($confirm) or !confirm_sesskey()) {
|
||||
$optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
|
||||
notice_yesno(get_string('upgradeforumreadinfo', 'admin'),
|
||||
'upgradeforumread.php', 'index.php', $optionsyes, NULL, 'post', 'get');
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/// Turn off time limits, sometimes upgrades can be slow.
|
||||
|
||||
@set_time_limit(0);
|
||||
@ob_implicit_flush(true);
|
||||
while(@ob_end_flush());
|
||||
|
||||
execute_sql('TRUNCATE TABLE '.$CFG->prefix.'forum_read;', false); // Trash all old entries
|
||||
|
||||
/// Enter initial read records for all posts older than 1 day.
|
||||
|
||||
/// Timestamp for old posts (and therefore considered read).
|
||||
$dateafter = time() - ($CFG->forum_oldpostdays*24*60*60);
|
||||
|
||||
/// Timestamp for one day ago.
|
||||
$onedayago = time() - (24*60*60);
|
||||
|
||||
|
||||
/// Get all discussions that have had posts since the old post date.
|
||||
if ($discussions = get_records_select('forum_discussions', 'timemodified > '.$dateafter,
|
||||
'course', 'id,course,forum,groupid,userid')) {
|
||||
$dtotal = count($discussions);
|
||||
print_heading('Updating forum post read/unread records for '.$dtotal.' discussions...'.
|
||||
'Please keep this window open until it completes', '', 3);
|
||||
|
||||
$groups = array();
|
||||
|
||||
$currcourse = 0;
|
||||
$users = 0;
|
||||
$count = 0;
|
||||
$dcount = 0;
|
||||
|
||||
foreach ($discussions as $discussion) {
|
||||
$dcount++;
|
||||
print_progress($dcount, $dtotal);
|
||||
|
||||
if ($discussion->course != $currcourse) {
|
||||
/// Discussions are ordered by course, so we only need to get any course's users once.
|
||||
$currcourse = $discussion->course;
|
||||
$users = get_course_users($currcourse, '', '', 'u.id,u.confirmed');
|
||||
}
|
||||
/// If this course has users, and posts more than a day old, mark them for each user.
|
||||
if ($users &&
|
||||
($posts = get_records_select('forum_posts', 'discussion = '.$discussion->id.
|
||||
' AND '.$dateafter.' < modified AND modified < '.$onedayago,
|
||||
'', 'id,discussion,modified'))) {
|
||||
foreach ($users as $user) {
|
||||
/// If its a group discussion, make sure the user is in the group.
|
||||
if ($discussion->groupid) {
|
||||
if (!isset($groups[$discussion->groupid][$user->id])) {
|
||||
$groups[$discussion->groupid][$user->id] = ismember($discussion->groupid, $user->id);
|
||||
}
|
||||
}
|
||||
if (!$discussion->groupid || !empty($groups[$discussion->groupid][$user->id])) {
|
||||
foreach ($posts as $post) {
|
||||
print_progress($dcount, $dtotal);
|
||||
forum_tp_mark_post_read($user->id, $post, $discussion->forum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print_progress($dcount, $dtotal, 0);
|
||||
}
|
||||
|
||||
|
||||
delete_records('config', 'name', 'upgrade', 'value', 'forumread');
|
||||
|
||||
notify('Log upgrading was successful!', 'notifysuccess');
|
||||
|
||||
print_continue('index.php');
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
?>
|
||||
+36
-38
@@ -1,15 +1,14 @@
|
||||
<?PHP //$Id$
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('upgradelogs', $adminroot);
|
||||
require("../config.php");
|
||||
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
optional_variable($confirm);
|
||||
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
if (!isadmin()) {
|
||||
error("You must be an admin to use this script");
|
||||
}
|
||||
|
||||
if ($CFG->version < 2004013101) {
|
||||
error("This script does not work with this old version of Moodle");
|
||||
@@ -22,29 +21,29 @@
|
||||
/// Turn off time limits, sometimes upgrades can be slow.
|
||||
|
||||
@set_time_limit(0);
|
||||
@ob_implicit_flush(true);
|
||||
while(@ob_end_flush());
|
||||
|
||||
|
||||
/// Print header
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strupgradinglogs = get_string("upgradinglogs", "admin");
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_heading($strupgradinglogs);
|
||||
|
||||
if (!data_submitted() or empty($confirm) or !confirm_sesskey()) {
|
||||
$optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
|
||||
notice_yesno(get_string('upgradeforumreadinfo', 'admin'),
|
||||
'upgradelogs.php', 'index.php', $optionsyes, NULL, 'post', 'get');
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_header("$site->shortname: $stradministration: $strupgradinglogs", "$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> $strupgradinglogs");
|
||||
|
||||
if (empty($_GET['confirm'])) {
|
||||
notice_yesno(get_string("upgradelogsinfo", "admin"),
|
||||
"upgradelogs.php?confirm=true",
|
||||
"index.php");
|
||||
print_footer();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/// Try and extract as many cmids as possible from the existing logs
|
||||
|
||||
if ($coursemodules = get_records_sql("SELECT cm.*, m.name
|
||||
FROM {$CFG->prefix}course_modules cm,
|
||||
if ($coursemodules = get_records_sql("SELECT cm.*, m.name
|
||||
FROM {$CFG->prefix}course_modules cm,
|
||||
{$CFG->prefix}modules m
|
||||
WHERE cm.module = m.id")) {
|
||||
$cmcount = count($coursemodules);
|
||||
@@ -59,52 +58,52 @@
|
||||
}
|
||||
|
||||
if ($cmcount > 10) {
|
||||
print_simple_box('This process may take a very long time ... please be patient and let it finish.',
|
||||
print_simple_box('This process may take a very long time ... please be patient and let it finish.',
|
||||
'center', '', '#ffcccc');
|
||||
$sleeptime = 1;
|
||||
}
|
||||
foreach ($coursemodules as $cm) {
|
||||
|
||||
switch ($cm->name) {
|
||||
switch ($cm->name) {
|
||||
case "forum":
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
|
||||
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url = 'view.php?f=$cm->instance'", false);
|
||||
|
||||
|
||||
if ($discussions = get_records("forum_discussions", "forum", $cm->instance)) {
|
||||
foreach ($discussions as $discussion) {
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url $LIKE 'discuss.php?d=$discussion->id%'", false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "glossary":
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
case "glossary":
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url $LIKE 'view.php?id=$cm->id%'", false);
|
||||
break;
|
||||
|
||||
case "quiz":
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
case "quiz":
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
|
||||
break;
|
||||
|
||||
case "assignment":
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
case "assignment":
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url = 'view.php?a=$cm->instance'", false);
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url = 'submissions.php?id=$cm->instance'", false);
|
||||
break;
|
||||
|
||||
case "journal":
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
|
||||
case "journal":
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url = 'report.php?id=$cm->id'", false);
|
||||
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
|
||||
WHERE module = '$cm->name' AND url = 'view.php?id=$cm->id'", false);
|
||||
break;
|
||||
|
||||
@@ -124,10 +123,9 @@
|
||||
|
||||
delete_records("config", "name", "upgrade", "value", "logs");
|
||||
|
||||
notify('Log upgrading was successful!', 'notifysuccess');
|
||||
notify("Log upgrading was successful!");
|
||||
|
||||
print_continue('index.php');
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_footer();
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
// detects settings that were added during an upgrade, displays a screen for the admin to
|
||||
// modify them, and then processes modifications
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('upgradesettings', $adminroot); // now hidden page
|
||||
|
||||
// a caveat: we're depending on only having one admin access this page at once. why? the following line
|
||||
// (the function call to find_new_settings) must have the EXACT SAME RETURN VALUE both times that this
|
||||
// page is loaded (i.e. both when we're displaying the form and then when we process the form's input).
|
||||
// if the return values don't match, we could potentially lose changes that the admin is making.
|
||||
|
||||
$newsettingshtml = output_new_settings_by_page(admin_get_root());
|
||||
|
||||
// first we deal with the case where there are no new settings to be set
|
||||
if ($newsettingshtml == '') {
|
||||
redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
|
||||
die;
|
||||
}
|
||||
|
||||
// now we'll deal with the case that the admin has submitted the form with new settings
|
||||
if ($data = data_submitted()) {
|
||||
$unslashed = (array)stripslashes_recursive($data);
|
||||
if (confirm_sesskey()) {
|
||||
$newsettings = find_new_settings(admin_get_root());
|
||||
$errors = '';
|
||||
|
||||
foreach($newsettings as $newsetting) {
|
||||
if (isset($unslashed['s_' . $newsetting->name])) {
|
||||
$errors .= $newsetting->write_setting($unslashed['s_' . $newsetting->name]);
|
||||
} else {
|
||||
$errors .= $newsetting->write_setting($newsetting->defaultsetting);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
// there must be either redirect without message or continue button or else upgrade would be sometimes broken
|
||||
redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
|
||||
die;
|
||||
} else {
|
||||
error(get_string('errorwithsettings', 'admin') . ' <br />' . $errors);
|
||||
die;
|
||||
}
|
||||
} else {
|
||||
error(get_string('confirmsesskeybad', 'error'));
|
||||
die;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// and finally, if we get here, then there are new settings and we have to print a form
|
||||
// to modify them
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
print_simple_box(get_string('upgradesettingsintro','admin'),'','100%','',5,'generalbox','');
|
||||
|
||||
echo '<form action="upgradesettings.php" method="post" name="adminsettings" id="adminsettings">';
|
||||
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
|
||||
echo '<fieldset>';
|
||||
echo '<div class="clearer"><!-- --></div>';
|
||||
echo $newsettingshtml;
|
||||
echo '<div class="form-buttons"><input class="form-submit" type="submit" value="' . get_string('savechanges','admin') . '" /></div>';
|
||||
echo '</form>';
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
|
||||
|
||||
/**
|
||||
* Find settings that have not been initialized (e.g. during initial install or an upgrade).
|
||||
*
|
||||
* Tests each setting's get_setting() method. If the result is NULL, we consider the setting
|
||||
* to be uninitialized.
|
||||
*
|
||||
* @param string &$node The node at which to start searching. Should be $ADMIN for all external calls to this function.
|
||||
* @return array An array containing admin_setting objects that haven't yet been initialized
|
||||
*/
|
||||
function find_new_settings(&$node) {
|
||||
|
||||
if (is_a($node, 'admin_category')) {
|
||||
$return = array();
|
||||
$entries = array_keys($node->children);
|
||||
foreach ($entries as $entry) {
|
||||
$return = array_merge($return, find_new_settings($node->children[$entry]));
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
if (is_a($node, 'admin_settingpage')) {
|
||||
$return = array();
|
||||
foreach ($node->settings as $setting) {
|
||||
if ($setting->get_setting() === NULL) {
|
||||
$return[] =& $setting;
|
||||
}
|
||||
unset($setting); // needed to prevent odd (imho) reference behaviour
|
||||
// see http://www.php.net/manual/en/language.references.whatdo.php#AEN6399
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
return array();
|
||||
|
||||
}
|
||||
|
||||
function output_new_settings_by_page(&$node) {
|
||||
|
||||
if (is_a($node, 'admin_category')) {
|
||||
$entries = array_keys($node->children);
|
||||
$return = '';
|
||||
foreach ($entries as $entry) {
|
||||
$return .= output_new_settings_by_page($node->children[$entry]);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
if (is_a($node, 'admin_settingpage')) {
|
||||
$newsettings = array();
|
||||
foreach ($node->settings as $setting) {
|
||||
if ($setting->get_setting() === NULL) {
|
||||
$newsettings[] =& $setting;
|
||||
}
|
||||
unset($setting); // needed to prevent odd (imho) reference behaviour
|
||||
// see http://www.php.net/manual/en/language.references.whatdo.php#AEN6399
|
||||
}
|
||||
$return = '';
|
||||
if (count($newsettings) > 0) {
|
||||
$return .= print_heading(get_string('upgradesettings','admin').' - '.$node->visiblename, '', 2, 'main', true);
|
||||
$return .= '<fieldset class="adminsettings">' . "\n";
|
||||
foreach ($newsettings as $newsetting) {
|
||||
$return .= '<div class="clearer"><!-- --></div>' . "\n";
|
||||
$return .= $newsetting->output_html();
|
||||
}
|
||||
$return .= '</fieldset>';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
+243
-386
@@ -1,416 +1,273 @@
|
||||
<?php // $Id$
|
||||
<?PHP // $Id$
|
||||
|
||||
/// Bulk user registration script from a comma separated file
|
||||
/// Returns list of users with their user ids
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/uploadlib.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
$adminroot = admin_get_root();
|
||||
admin_externalpage_setup('uploadusers', $adminroot);
|
||||
require_once("../config.php");
|
||||
|
||||
$createpassword = optional_param('createpassword', 0, PARAM_BOOL);
|
||||
$updateaccounts = optional_param('updateaccounts', 0, PARAM_BOOL);
|
||||
$allowrenames = optional_param('allowrenames', 0, PARAM_BOOL);
|
||||
optional_variable($numusers, 0);
|
||||
|
||||
require_login();
|
||||
require_login();
|
||||
|
||||
require_capability('moodle/site:uploadusers', get_context_instance(CONTEXT_SYSTEM, SITEID));
|
||||
|
||||
if (! $site = get_site()) {
|
||||
error("Could not find site-level course");
|
||||
}
|
||||
|
||||
if (!$adminuser = get_admin()) {
|
||||
error("Could not find site admin");
|
||||
}
|
||||
|
||||
$strfile = get_string('file');
|
||||
$struser = get_string('user');
|
||||
$strusersnew = get_string('usersnew');
|
||||
$strusersupdated = get_string('usersupdated');
|
||||
$struploadusers = get_string('uploadusers');
|
||||
$straddnewuser = get_string('importuser');
|
||||
|
||||
$csv_encode = '/\&\#44/';
|
||||
if (isset($CFG->CSV_DELIMITER)) {
|
||||
$csv_delimiter = '\\' . $CFG->CSV_DELIMITER;
|
||||
$csv_delimiter2 = $CFG->CSV_DELIMITER;
|
||||
|
||||
if (isset($CFG->CSV_ENCODE)) {
|
||||
$csv_encode = '/\&\#' . $CFG->CSV_ENCODE . '/';
|
||||
if (!isadmin()) {
|
||||
error("You must be an administrator to edit users this way.");
|
||||
}
|
||||
|
||||
if (! $site = get_site()) {
|
||||
error("Could not find site-level course");
|
||||
}
|
||||
|
||||
if (!$adminuser = get_admin()) {
|
||||
error("Could not find site admin");
|
||||
}
|
||||
|
||||
$streditmyprofile = get_string("editmyprofile");
|
||||
$stradministration = get_string("administration");
|
||||
$strchoose = get_string("choose");
|
||||
$struser = get_string("user");
|
||||
$strusers = get_string("users");
|
||||
$strusersnew = get_string("usersnew");
|
||||
$struploadusers = get_string("uploadusers");
|
||||
$straddnewuser = get_string("importuser");
|
||||
|
||||
$csv_encode = '/\&\#44/';
|
||||
if (isset($CFG->CSV_DELIMITER)) {
|
||||
$csv_delimiter = '\\' . $CFG->CSV_DELIMITER;
|
||||
$csv_delimiter2 = $CFG->CSV_DELIMITER;
|
||||
|
||||
if (isset($CFG->CSV_ENCODE)) {
|
||||
$csv_encode = '/\&\#' . $CFG->CSV_ENCODE . '/';
|
||||
}
|
||||
} else {
|
||||
$csv_delimiter = "\,";
|
||||
$csv_delimiter2 = ",";
|
||||
}
|
||||
} else {
|
||||
$csv_delimiter = "\,";
|
||||
$csv_delimiter2 = ",";
|
||||
}
|
||||
|
||||
/// Print the header
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
print_header("$site->shortname: $struploadusers", $site->fullname,
|
||||
"<a href=\"index.php\">$stradministration</a> ->
|
||||
<a href=\"users.php\">$strusers</a> -> $struploadusers");
|
||||
|
||||
|
||||
/// If a file has been uploaded, then process it
|
||||
|
||||
if ($filename = valid_uploaded_file($_FILES['userfile'])) {
|
||||
|
||||
$um = new upload_manager('userfile',false,false,null,false,0);
|
||||
//Fix mac/dos newlines
|
||||
$text = my_file_get_contents($filename);
|
||||
$text = preg_replace('!\r\n?!',"\n",$text);
|
||||
$fp = fopen($filename, "w");
|
||||
fwrite($fp,$text);
|
||||
fclose($fp);
|
||||
|
||||
if ($um->preprocess_files() && confirm_sesskey()) {
|
||||
$filename = $um->files['userfile']['tmp_name'];
|
||||
$fp = fopen($filename, "r");
|
||||
|
||||
// Large files are likely to take their time and memory. Let PHP know
|
||||
// that we'll take longer, and that the process should be recycled soon
|
||||
// to free up memory.
|
||||
@set_time_limit(0);
|
||||
@raise_memory_limit("128M");
|
||||
if (function_exists('apache_child_terminate')) {
|
||||
@apache_child_terminate();
|
||||
// make arrays of valid fields for error checking
|
||||
$required = array("username" => 1,
|
||||
"password" => 1,
|
||||
"firstname" => 1,
|
||||
"lastname" => 1,
|
||||
"email" => 1);
|
||||
$optionalDefaults = array("institution" => 1,
|
||||
"department" => 1,
|
||||
"city" => 1,
|
||||
"country" => 1,
|
||||
"lang" => 1,
|
||||
"timezone" => 1);
|
||||
$optional = array("idnumber" => 1,
|
||||
"icq" => 1,
|
||||
"phone1" => 1,
|
||||
"phone2" => 1,
|
||||
"address" => 1,
|
||||
"url" => 1,
|
||||
"description" => 1,
|
||||
"mailformat" => 1,
|
||||
"maildisplay" => 1,
|
||||
"htmleditor" => 1,
|
||||
"autosubscribe" => 1,
|
||||
"idnumber" => 1,
|
||||
"icq" => 1,
|
||||
"course1" => 1,
|
||||
"course2" => 1,
|
||||
"course3" => 1,
|
||||
"course4" => 1,
|
||||
"course5" => 1,
|
||||
"group1" => 1,
|
||||
"group2" => 1,
|
||||
"group3" => 1,
|
||||
"group4" => 1,
|
||||
"group5" =>1);
|
||||
|
||||
// --- get header (field names) ---
|
||||
$header = split($csv_delimiter, fgets($fp,1024));
|
||||
// check for valid field names
|
||||
foreach ($header as $i => $h) {
|
||||
$h = trim($h); $header[$i] = $h; // remove whitespace
|
||||
if (!($required[$h] or $optionalDefaults[$h] or $optional[$h])) {
|
||||
error(get_string('invalidfieldname', 'error', $h), 'uploaduser.php');
|
||||
}
|
||||
if ($required[$h]) {
|
||||
$required[$h] = 2;
|
||||
}
|
||||
}
|
||||
// check for required fields
|
||||
foreach ($required as $key => $value) {
|
||||
if ($value < 2) {
|
||||
error(get_string('fieldrequired', 'error', $key), 'uploaduser.php');
|
||||
}
|
||||
}
|
||||
$linenum = 2; // since header is line 1
|
||||
|
||||
while (!feof ($fp)) {
|
||||
foreach ($optionalDefaults as $key => $value) {
|
||||
$user->$key = addslashes($adminuser->$key);
|
||||
}
|
||||
//Note: commas within a field should be encoded as , (for comma separated csv files)
|
||||
//Note: semicolon within a field should be encoded as ; (for semicolon separated csv files)
|
||||
$line = split($csv_delimiter, fgets($fp,1024));
|
||||
foreach ($line as $key => $value) {
|
||||
//decode encoded commas
|
||||
$record[$header[$key]] = preg_replace($csv_encode,$csv_delimiter2,trim($value));
|
||||
}
|
||||
if ($record[$header[0]]) {
|
||||
// add a new user to the database
|
||||
optional_variable($newuser, "");
|
||||
|
||||
// add fields to object $user
|
||||
foreach ($record as $name => $value) {
|
||||
// check for required values
|
||||
if ($required[$name] and !$value) {
|
||||
error(get_string('missingfield', 'error', $name). " ".
|
||||
get_string('erroronline', 'error', $linenum),
|
||||
'uploaduser.php');
|
||||
}
|
||||
// password needs to be encrypted
|
||||
else if ($name == "password") {
|
||||
$user->password = md5($value);
|
||||
}
|
||||
// normal entry
|
||||
else {
|
||||
$user->{$name} = addslashes($value);
|
||||
}
|
||||
}
|
||||
$user->confirmed = 1;
|
||||
$user->timemodified = time();
|
||||
$linenum++;
|
||||
$username = $user->username;
|
||||
$addcourse[0] = $user->course1;
|
||||
$addcourse[1] = $user->course2;
|
||||
$addcourse[2] = $user->course3;
|
||||
$addcourse[3] = $user->course4;
|
||||
$addcourse[4] = $user->course5;
|
||||
$addgroup[0] = $user->group1;
|
||||
$addgroup[1] = $user->group2;
|
||||
$addgroup[2] = $user->group3;
|
||||
$addgroup[3] = $user->group4;
|
||||
$addgroup[4] = $user->group5;
|
||||
$courses = get_courses("all");
|
||||
for ($i=0; $i<5; $i++) {
|
||||
$courseid[$i]=0;
|
||||
}
|
||||
foreach ($courses as $course) {
|
||||
for ($i=0; $i<5; $i++) {
|
||||
if ($course->shortname == $addcourse[$i]) {
|
||||
$courseid[$i] = $course->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! $user->id = insert_record("user", $user)) {
|
||||
if (!$user = get_record("user", "username", "changeme")) { // half finished user from another time
|
||||
//Record not added - probably because user is already registered
|
||||
//In this case, output userid from previous registration
|
||||
//This can be used to obtain a list of userids for existing users
|
||||
if ($user = get_record("user","username",$username)) {
|
||||
notify("$user->id ".get_string('usernotaddedregistered', 'error', $username));
|
||||
} else {
|
||||
notify(get_string('usernotaddederror', 'error', $username));
|
||||
}
|
||||
}
|
||||
} else if ($user->username != "changeme") {
|
||||
notify("$struser: $user->id = $user->username");
|
||||
$numusers++;
|
||||
}
|
||||
for ($i=0; $i<5; $i++) {
|
||||
if ($addcourse[$i] && !$courseid[$i]) {
|
||||
notify(get_string('unknowncourse', 'error', $addcourse[$i]));
|
||||
}
|
||||
}
|
||||
for ($i=0; $i<5; $i++) {
|
||||
$groupid[$i] = 0;
|
||||
if ($addgroup[$i]) {
|
||||
if (!$courseid[$i]) {
|
||||
notify(get_string('coursegroupunknown','error',$addgroup[$i]));
|
||||
} else {
|
||||
if ($group = get_record("groups","courseid",$courseid[$i],"name",$addgroup[$i])) {
|
||||
$groupid[$i] = $group->id;
|
||||
} else {
|
||||
notify(get_string('groupunknown','error',$addgroup[$i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i=0; $i<5; $i++) {
|
||||
if ($courseid[$i]) {
|
||||
if (enrol_student($user->id, $courseid[$i])) {
|
||||
notify('-->'. get_string('enrolledincourse', '', $addcourse[$i]));
|
||||
} else {
|
||||
notify('-->'.get_string('enrolledincoursenot', '', $addcourse[$i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i=0; $i<5; $i++) {
|
||||
if ($courseid[$i] && $groupid[$i]) {
|
||||
if (record_exists("user_students","userid",$user->id,"course",$courseid[$i])) {
|
||||
$usergroup = user_group($courseid[$i],$user->id);
|
||||
if ($usergroup) {
|
||||
notify('-->' . get_string('groupalready','error',$usergroup->name));
|
||||
} else {
|
||||
$group_member->groupid = $groupid[$i];
|
||||
$group_member->userid = $user->id;
|
||||
$group_member->timeadded = time();
|
||||
if (insert_record("groups_members",$group_member)) {
|
||||
notify('-->' . get_string('addedtogroup','',$addgroup[$i]));
|
||||
} else {
|
||||
notify('-->' . get_string('addedtogroupnot','',$addgroup[$i]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
notify('-->' . get_string('addedtogroupnotenrolled','',$addgroup[$i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset ($user);
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
notify("$strusersnew: $numusers");
|
||||
|
||||
echo '<hr />';
|
||||
}
|
||||
|
||||
//Fix mac/dos newlines
|
||||
$text = my_file_get_contents($filename);
|
||||
$text = preg_replace('!\r\n?!',"\n",$text);
|
||||
$fp = fopen($filename, "w");
|
||||
fwrite($fp,$text);
|
||||
fclose($fp);
|
||||
|
||||
$fp = fopen($filename, "r");
|
||||
|
||||
// make arrays of valid fields for error checking
|
||||
$required = array("username" => 1,
|
||||
"password" => !$createpassword,
|
||||
"firstname" => 1,
|
||||
"lastname" => 1,
|
||||
"email" => 1);
|
||||
$optionalDefaults = array("institution" => 1,
|
||||
"department" => 1,
|
||||
"city" => 1,
|
||||
"country" => 1,
|
||||
"lang" => 1,
|
||||
"auth" => 1,
|
||||
"timezone" => 1);
|
||||
$optional = array("idnumber" => 1,
|
||||
"icq" => 1,
|
||||
"phone1" => 1,
|
||||
"phone2" => 1,
|
||||
"address" => 1,
|
||||
"url" => 1,
|
||||
"description" => 1,
|
||||
"mailformat" => 1,
|
||||
"maildisplay" => 1,
|
||||
"htmleditor" => 1,
|
||||
"autosubscribe" => 1,
|
||||
"idnumber" => 1,
|
||||
"icq" => 1,
|
||||
"course1" => 1,
|
||||
"course2" => 1,
|
||||
"course3" => 1,
|
||||
"course4" => 1,
|
||||
"course5" => 1,
|
||||
"group1" => 1,
|
||||
"group2" => 1,
|
||||
"group3" => 1,
|
||||
"group4" => 1,
|
||||
"group5" => 1,
|
||||
"type1" => 1,
|
||||
"type2" => 1,
|
||||
"type3" => 1,
|
||||
"type4" => 1,
|
||||
"type5" => 1,
|
||||
"role1" => 1,
|
||||
"role2" => 1,
|
||||
"role3" => 1,
|
||||
"role4" => 1,
|
||||
"role5" => 1,
|
||||
"password" => $createpassword,
|
||||
"oldusername" => $allowrenames);
|
||||
|
||||
// --- get header (field names) ---
|
||||
$header = split($csv_delimiter, fgets($fp,1024));
|
||||
// check for valid field names
|
||||
foreach ($header as $i => $h) {
|
||||
$h = trim($h); $header[$i] = $h; // remove whitespace
|
||||
if (!($required[$h] or $optionalDefaults[$h] or $optional[$h])) {
|
||||
error(get_string('invalidfieldname', 'error', $h), 'uploaduser.php?sesskey='.$USER->sesskey);
|
||||
}
|
||||
if ($required[$h]) {
|
||||
$required[$h] = 0;
|
||||
}
|
||||
}
|
||||
// check for required fields
|
||||
foreach ($required as $key => $value) {
|
||||
if ($value) { //required field missing
|
||||
error(get_string('fieldrequired', 'error', $key), 'uploaduser.php?sesskey='.$USER->sesskey);
|
||||
}
|
||||
}
|
||||
$linenum = 2; // since header is line 1
|
||||
|
||||
$usersnew = 0;
|
||||
$usersupdated = 0;
|
||||
$userserrors = 0;
|
||||
$renames = 0;
|
||||
$renameerrors = 0;
|
||||
|
||||
// Will use this course array a lot
|
||||
// so fetch it early and keep it in memory
|
||||
$courses = get_courses('all','c.sortorder','c.id,c.shortname,c.fullname,c.sortorder,c.teacher,c.visible');
|
||||
|
||||
while (!feof ($fp)) {
|
||||
foreach ($optionalDefaults as $key => $value) {
|
||||
$user->$key = addslashes($adminuser->$key);
|
||||
}
|
||||
//Note: commas within a field should be encoded as , (for comma separated csv files)
|
||||
//Note: semicolon within a field should be encoded as ; (for semicolon separated csv files)
|
||||
$line = split($csv_delimiter, fgets($fp,1024));
|
||||
foreach ($line as $key => $value) {
|
||||
//decode encoded commas
|
||||
$record[$header[$key]] = preg_replace($csv_encode,$csv_delimiter2,trim($value));
|
||||
}
|
||||
if ($record[$header[0]]) {
|
||||
// add a new user to the database
|
||||
|
||||
// add fields to object $user
|
||||
foreach ($record as $name => $value) {
|
||||
// check for required values
|
||||
if ($required[$name] and !$value) {
|
||||
error(get_string('missingfield', 'error', $name). " ".
|
||||
get_string('erroronline', 'error', $linenum) .". ".
|
||||
get_string('processingstops', 'error'),
|
||||
'uploaduser.php?sesskey='.$USER->sesskey);
|
||||
}
|
||||
// password needs to be encrypted
|
||||
else if ($name == "password" && !empty($value)) {
|
||||
$user->password = hash_internal_user_password($value);
|
||||
}
|
||||
else if ($name == "username") {
|
||||
$user->username = addslashes(moodle_strtolower($value));
|
||||
}
|
||||
// normal entry
|
||||
else {
|
||||
$user->{$name} = addslashes($value);
|
||||
}
|
||||
}
|
||||
$user->confirmed = 1;
|
||||
$user->timemodified = time();
|
||||
$linenum++;
|
||||
$username = $user->username;
|
||||
$addcourse[0] = isset($user->course1) ? $user->course1 : NULL;
|
||||
$addcourse[1] = isset($user->course2) ? $user->course2 : NULL;
|
||||
$addcourse[2] = isset($user->course3) ? $user->course3 : NULL;
|
||||
$addcourse[3] = isset($user->course4) ? $user->course4 : NULL;
|
||||
$addcourse[4] = isset($user->course5) ? $user->course5 : NULL;
|
||||
$addgroup[0] = isset($user->group1) ? $user->group1 : NULL;
|
||||
$addgroup[1] = isset($user->group2) ? $user->group2 : NULL;
|
||||
$addgroup[2] = isset($user->group3) ? $user->group3 : NULL;
|
||||
$addgroup[3] = isset($user->group4) ? $user->group4 : NULL;
|
||||
$addgroup[4] = isset($user->group5) ? $user->group5 : NULL;
|
||||
$addtype[0] = isset($user->type1) ? $user->type1 : NULL;
|
||||
$addtype[1] = isset($user->type2) ? $user->type2 : NULL;
|
||||
$addtype[2] = isset($user->type3) ? $user->type3 : NULL;
|
||||
$addtype[3] = isset($user->type4) ? $user->type4 : NULL;
|
||||
$addtype[4] = isset($user->type5) ? $user->type5 : NULL;
|
||||
$addrole[0] = isset($user->role1) ? $user->role1 : NULL;
|
||||
$addrole[1] = isset($user->role2) ? $user->role2 : NULL;
|
||||
$addrole[2] = isset($user->role3) ? $user->role3 : NULL;
|
||||
$addrole[3] = isset($user->role4) ? $user->role4 : NULL;
|
||||
$addrole[4] = isset($user->role5) ? $user->role5 : NULL;
|
||||
|
||||
for ($i=0; $i<5; $i++) {
|
||||
$course[$i]=NULL;
|
||||
}
|
||||
foreach ($courses as $eachcourse) {
|
||||
for ($i=0; $i<5; $i++) {
|
||||
if ($eachcourse->shortname == $addcourse[$i]) {
|
||||
$course[$i] = $eachcourse;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->username === 'changeme') {
|
||||
notify(get_string('invaliduserchangeme', 'admin'));
|
||||
$userserrors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// before insert/update, check whether we should be updating
|
||||
// an old record instead
|
||||
if ($allowrenames && !empty($user->oldusername) ) {
|
||||
$user->oldusername = moodle_strtolower($user->oldusername);
|
||||
if ($olduser = get_record('user','username',$user->oldusername)) {
|
||||
if (set_field('user', 'username', $user->username, 'username', $user->oldusername)) {
|
||||
notify(get_string('userrenamed', 'admin') . " : $user->oldusername $user->username");
|
||||
$renames++;
|
||||
} else {
|
||||
notify(get_string('usernotrenamedexists', 'error') . " : $user->oldusername $user->username");
|
||||
$renameerrors++;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
notify(get_string('usernotrenamedmissing', 'error') . " : $user->oldusername $user->username");
|
||||
$renameerrors++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($olduser = get_record("user","username",$username)) {
|
||||
if ($updateaccounts) {
|
||||
// Record is being updated
|
||||
$user->id = $olduser->id;
|
||||
if (update_record('user', $user)) {
|
||||
notify("$user->id , $user->username ".get_string('useraccountupdated', 'admin'));
|
||||
$usersupdated++;
|
||||
} else {
|
||||
notify(get_string('usernotupdatederror', 'error', $username));
|
||||
$userserrors++;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
//Record not added - user is already registered
|
||||
//In this case, output userid from previous registration
|
||||
//This can be used to obtain a list of userids for existing users
|
||||
notify("$olduser->id ".get_string('usernotaddedregistered', 'error', $username));
|
||||
$userserrors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
} else { // new user
|
||||
if ($user->id = insert_record("user", $user)) {
|
||||
notify("$struser: $user->id = $user->username");
|
||||
$usersnew++;
|
||||
if (empty($user->password) && $createpassword) {
|
||||
// passwords will be created and sent out on cron
|
||||
insert_record('user_preferences', array( userid => $user->id,
|
||||
name => 'create_password',
|
||||
value => 1));
|
||||
insert_record('user_preferences', array( userid => $user->id,
|
||||
name => 'auth_forcepasswordchange',
|
||||
value => 1));
|
||||
}
|
||||
} else {
|
||||
// Record not added -- possibly some other error
|
||||
notify(get_string('usernotaddederror', 'error', $username));
|
||||
$userserrors++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for ($i=0; $i<5; $i++) {
|
||||
if ($addcourse[$i] && !$course[$i]) {
|
||||
notify(get_string('unknowncourse', 'error', $addcourse[$i]));
|
||||
}
|
||||
}
|
||||
for ($i=0; $i<5; $i++) {
|
||||
$groupid[$i] = 0;
|
||||
if ($addgroup[$i]) {
|
||||
if (!$course[$i]) {
|
||||
notify(get_string('coursegroupunknown','error',$addgroup[$i]));
|
||||
} else {
|
||||
if ($group = get_record("groups","courseid",$course[$i]->id,"name",$addgroup[$i])) {
|
||||
$groupid[$i] = $group->id;
|
||||
} else {
|
||||
notify(get_string('groupunknown','error',$addgroup[$i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i=0; $i<5; $i++) { /// Enrol into courses if necessary
|
||||
if ($course[$i]) {
|
||||
if (isset($addrole[$i])) {
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course[$i]->id);
|
||||
if (!user_can_assign($coursecontext, $addrole[$i])) {
|
||||
notify('--> Can not assign role in course'); //TODO: localize
|
||||
}
|
||||
$ret = role_assign($addrole[$i], $user->id, 0, $coursecontext->id);
|
||||
} else if (isset($addtype[$i])) {
|
||||
switch ($addtype[$i]) {
|
||||
case 2: // teacher
|
||||
$ret = add_teacher($user->id, $course[$i]->id, 1);
|
||||
break;
|
||||
|
||||
case 3: // non-editing teacher
|
||||
$ret = add_teacher($user->id, $course[$i]->id, 0);
|
||||
break;
|
||||
|
||||
default: // student
|
||||
$ret = enrol_student($user->id, $course[$i]->id);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$ret = enrol_student($user->id, $course[$i]->id);
|
||||
}
|
||||
if ($ret) { // OK
|
||||
notify('-->'. get_string('enrolledincourse', '', $addcourse[$i]));
|
||||
} else {
|
||||
notify('-->'.get_string('enrolledincoursenot', '', $addcourse[$i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i=0; $i<5; $i++) { // Add user to groups if necessary
|
||||
if ($course[$i] && $groupid[$i]) {
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $course[$i]->id);
|
||||
if (count(get_user_roles($coursecontext, $user->id))) {
|
||||
if (add_user_to_group($groupid[$i], $user->id)) {
|
||||
notify('-->' . get_string('addedtogroup','',$addgroup[$i]));
|
||||
} else {
|
||||
notify('-->' . get_string('addedtogroupnot','',$addgroup[$i]));
|
||||
}
|
||||
} else {
|
||||
notify('-->' . get_string('addedtogroupnotenrolled','',$addgroup[$i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset ($user);
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
notify("$strusersnew: $usersnew");
|
||||
notify(get_string('usersupdated', 'admin') . ": $usersupdated");
|
||||
notify(get_string('errors', 'admin') . ": $userserrors");
|
||||
if ($allowrenames) {
|
||||
notify(get_string('usersrenamed', 'admin') . ": $renames");
|
||||
notify(get_string('renameerrors', 'admin') . ": $renameerrors");
|
||||
}
|
||||
echo '<hr />';
|
||||
}
|
||||
|
||||
/// Print the form
|
||||
print_heading_with_help($struploadusers, 'uploadusers');
|
||||
print_heading_with_help($struploadusers, 'uploadusers');
|
||||
|
||||
$noyesoptions = array( get_string('no'), get_string('yes') );
|
||||
$maxuploadsize = get_max_upload_file_size();
|
||||
echo '<center>';
|
||||
echo '<form method="post" enctype="multipart/form-data" action="uploaduser.php">'.
|
||||
$strchoose.':<input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'">'.
|
||||
'<input type="file" name="userfile" size=30>'.
|
||||
'<input type="submit" value="'.$struploadusers.'">'.
|
||||
'</form></br>';
|
||||
echo '</center>';
|
||||
|
||||
$maxuploadsize = get_max_upload_file_size();
|
||||
echo '<center>';
|
||||
echo '<form method="post" enctype="multipart/form-data" action="uploaduser.php">'.
|
||||
$strfile.' <input type="hidden" name="MAX_FILE_SIZE" value="'.$maxuploadsize.'">'.
|
||||
'<input type="hidden" name="sesskey" value="'.$USER->sesskey.'">'.
|
||||
'<input type="file" name="userfile" size="30">';
|
||||
print_heading(get_string('settings'));
|
||||
echo '<table>';
|
||||
echo '<tr><td>' . get_string('passwordhandling', 'auth') . '</td><td>';
|
||||
$passwordopts = array( 0 => get_string('infilefield', 'auth'),
|
||||
1 => get_string('createpasswordifneeded', 'auth'),
|
||||
);
|
||||
choose_from_menu($passwordopts, 'createpassword', $createpassword);
|
||||
echo '</td></tr>';
|
||||
|
||||
echo '<tr><td>' . get_string('updateaccounts', 'admin') . '</td><td>';
|
||||
choose_from_menu($noyesoptions, 'updateaccounts', $updateaccounts);
|
||||
echo '</td></tr>';
|
||||
|
||||
echo '<tr><td>' . get_string('allowrenames', 'admin') . '</td><td>';
|
||||
choose_from_menu($noyesoptions, 'allowrenames', $allowrenames);
|
||||
echo '</td></tr>';
|
||||
echo '</table><br />';
|
||||
echo '<input type="submit" value="'.$struploadusers.'">';
|
||||
echo '</form><br />';
|
||||
echo '</center>';
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_footer($course);
|
||||
|
||||
|
||||
|
||||
function my_file_get_contents($filename, $use_include_path = 0) {
|
||||
/// Returns the file as one big long string
|
||||
/// Returns the file as one big long string
|
||||
|
||||
$data = "";
|
||||
$file = @fopen($filename, "rb", $use_include_path);
|
||||
|
||||
+150
-193
@@ -1,73 +1,68 @@
|
||||
<?php // $Id$
|
||||
<?PHP // $Id$
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once("../config.php");
|
||||
|
||||
$newuser = optional_param('newuser', 0, PARAM_BOOL);
|
||||
$delete = optional_param('delete', 0, PARAM_INT);
|
||||
$confirm = optional_param('confirm', '', PARAM_ALPHANUM); //md5 confirmation hash
|
||||
$confirmuser = optional_param('confirmuser', 0, PARAM_INT);
|
||||
$sort = optional_param('sort', 'name', PARAM_ALPHA);
|
||||
$dir = optional_param('dir', 'ASC', PARAM_ALPHA);
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
$perpage = optional_param('perpage', 30, PARAM_INT); // how many per page
|
||||
$search = trim(optional_param('search', '', PARAM_RAW));
|
||||
$lastinitial = optional_param('lastinitial', '', PARAM_CLEAN); // only show students with this last initial
|
||||
$firstinitial = optional_param('firstinitial', '', PARAM_CLEAN); // only show students with this first initial
|
||||
optional_variable($newuser, "");
|
||||
optional_variable($delete, "");
|
||||
optional_variable($confirm, "");
|
||||
optional_variable($confirmuser, "");
|
||||
optional_variable($sort, "name");
|
||||
optional_variable($dir, "ASC");
|
||||
optional_variable($page, 0);
|
||||
optional_variable($search, "");
|
||||
optional_variable($lastinitial, ""); // only show students with this last initial
|
||||
optional_variable($firstinitial, ""); // only show students with this first initial
|
||||
optional_variable($perpage, "30"); // how many per page
|
||||
|
||||
if (!$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID)) { // Should never happen
|
||||
redirect('index.php');
|
||||
}
|
||||
unset($user);
|
||||
unset($admin);
|
||||
unset($teacher);
|
||||
|
||||
if (empty($CFG->rolesactive)) { // No admin user yet.
|
||||
if (! record_exists("user_admins")) { // No admin user yet
|
||||
|
||||
$user = new object();
|
||||
$user->firstname = get_string('admin');
|
||||
$user->lastname = get_string('user');
|
||||
$user->username = 'admin';
|
||||
$user->password = hash_internal_user_password('admin');
|
||||
$user->email = 'root@localhost';
|
||||
$user->confirmed = 1;
|
||||
$user->lang = $CFG->lang;
|
||||
$user->maildisplay = 1;
|
||||
$user->firstname = get_string("admin");
|
||||
$user->lastname = get_string("user");
|
||||
$user->username = "admin";
|
||||
$user->password = md5("admin");
|
||||
$user->email = "root@localhost";
|
||||
$user->confirmed = 1;
|
||||
$user->lang = $CFG->lang;
|
||||
$user->maildisplay = 1;
|
||||
$user->timemodified = time();
|
||||
|
||||
if (! $user->id = insert_record('user', $user)) {
|
||||
if (! $user->id = insert_record("user", $user)) {
|
||||
error("SERIOUS ERROR: Could not create admin user record !!!");
|
||||
}
|
||||
|
||||
if (! $user = get_record('user', 'id', $user->id)) { // Double check.
|
||||
$admin->userid = $user->id;
|
||||
|
||||
if (! insert_record("user_admins", $admin)) {
|
||||
error("Could not make user $user->id an admin !!!");
|
||||
}
|
||||
|
||||
if (! $user = get_record("user", "id", $user->id)) { // Double check
|
||||
error("User ID was incorrect (can't find it)");
|
||||
}
|
||||
|
||||
|
||||
// Assign the default admin role to the new user.
|
||||
if (!$adminroles = get_roles_with_capability('moodle/legacy:admin', CAP_ALLOW)) {
|
||||
error('No admin role could be found');
|
||||
}
|
||||
foreach ($adminroles as $adminrole) {
|
||||
role_assign($adminrole->id, $user->id, 0, $sitecontext->id);
|
||||
}
|
||||
set_config('rolesactive', 1);
|
||||
|
||||
|
||||
if (! $site = get_site()) {
|
||||
error("Could not find site-level course");
|
||||
}
|
||||
|
||||
// Log the user in.
|
||||
$teacher->userid = $user->id;
|
||||
$teacher->course = $site->id;
|
||||
$teacher->authority = 1;
|
||||
if (! insert_record("user_teachers", $teacher)) {
|
||||
error("Could not make user $id a teacher of site-level course !!!");
|
||||
}
|
||||
|
||||
$USER = $user;
|
||||
$USER->loggedin = true;
|
||||
$USER->sessionIP = md5(getremoteaddr()); // Store the current IP in the session
|
||||
$USER->site = $CFG->wwwroot;
|
||||
$USER->admin = true;
|
||||
$USER->teacher["$site->id"] = true;
|
||||
$USER->newadminuser = true;
|
||||
|
||||
sesskey(); // For added security, used to check script parameters
|
||||
|
||||
load_all_capabilities();
|
||||
|
||||
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id"); // Edit thyself
|
||||
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id");
|
||||
exit;
|
||||
|
||||
} else {
|
||||
@@ -78,78 +73,68 @@
|
||||
|
||||
require_login();
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
|
||||
if ($newuser) {
|
||||
admin_externalpage_setup('addnewuser', $adminroot);
|
||||
} else {
|
||||
admin_externalpage_setup('editusers', $adminroot);
|
||||
if (!isadmin()) {
|
||||
error("You must be an administrator to edit users this way.");
|
||||
}
|
||||
|
||||
|
||||
if ($newuser) { // Create a new user
|
||||
$user->firstname = "";
|
||||
$user->lastname = "";
|
||||
$user->username = "changeme";
|
||||
$user->password = "";
|
||||
$user->email = "";
|
||||
$user->lang = $CFG->lang;
|
||||
$user->confirmed = 1;
|
||||
$user->timemodified = time();
|
||||
|
||||
if (!has_capability('moodle/user:create', $sitecontext)) {
|
||||
error('You do not have the required permission to create new users.');
|
||||
}
|
||||
|
||||
if (!$user = get_record('user', 'username', 'changeme')) { // half finished user from another time
|
||||
|
||||
$user = new object();
|
||||
$user->auth = 'manual';
|
||||
$user->firstname = '';
|
||||
$user->lastname = '';
|
||||
$user->username = 'changeme';
|
||||
$user->password = '';
|
||||
$user->email = '';
|
||||
$user->lang = $CFG->lang;
|
||||
$user->confirmed = 1;
|
||||
$user->timemodified = time();
|
||||
|
||||
if (! $user->id = insert_record('user', $user)) {
|
||||
error('Could not start a new user!');
|
||||
if (! $user->id = insert_record("user", $user)) {
|
||||
if (!$user = get_record("user", "username", "changeme")) { // half finished user from another time
|
||||
error("Could not start a new user!");
|
||||
}
|
||||
}
|
||||
|
||||
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id");
|
||||
|
||||
redirect("$CFG->wwwroot/user/edit.php?id=$user->id&course=$site->id");
|
||||
|
||||
} else { // List all users for editing
|
||||
|
||||
if (!has_capability('moodle/user:update', $sitecontext) and !has_capability('moodle/user:delete', $sitecontext)) {
|
||||
error('You do not have the required permission to edit/delete users.');
|
||||
$stredituser = get_string("edituser");
|
||||
$stradministration = get_string("administration");
|
||||
$strusers = get_string("users");
|
||||
$stredit = get_string("edit");
|
||||
$strdelete = get_string("delete");
|
||||
$strdeletecheck = get_string("deletecheck");
|
||||
$strsearch = get_string("search");
|
||||
$strshowallusers = get_string("showallusers");
|
||||
|
||||
if ($firstinitial or $lastinitial or $search or $page) {
|
||||
print_header("$site->shortname: $stredituser", $site->fullname,
|
||||
"<a href=\"index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"users.php\">$strusers</a> -> ".
|
||||
"<a href=\"user.php\">$stredituser</a>");
|
||||
} else {
|
||||
print_header("$site->shortname: $stredituser", $site->fullname,
|
||||
"<a href=\"index.php\">$stradministration</a> -> ".
|
||||
"<a href=\"users.php\">$strusers</a> -> $stredituser");
|
||||
}
|
||||
|
||||
$stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
$strdeletecheck = get_string('deletecheck');
|
||||
$strsearch = get_string('search');
|
||||
$strshowallusers = get_string('showallusers');
|
||||
|
||||
admin_externalpage_print_header($adminroot);
|
||||
|
||||
if ($confirmuser and confirm_sesskey()) {
|
||||
if (!$user = get_record('user', 'id', $confirmuser)) {
|
||||
if ($confirmuser) {
|
||||
if (!$user = get_record("user", "id", "$confirmuser")) {
|
||||
error("No such user!");
|
||||
}
|
||||
|
||||
$confirmeduser = new object();
|
||||
unset($confirmeduser);
|
||||
$confirmeduser->id = $confirmuser;
|
||||
$confirmeduser->confirmed = 1;
|
||||
$confirmeduser->timemodified = time();
|
||||
|
||||
if (update_record('user', $confirmeduser)) {
|
||||
notify(get_string('userconfirmed', '', fullname($user, true)) );
|
||||
if (update_record("user", $confirmeduser)) {
|
||||
notify(get_string("userconfirmed", "", fullname($user, true)) );
|
||||
} else {
|
||||
notify(get_string('usernotconfirmed', '', fullname($user, true)));
|
||||
notify(get_string("usernotconfirmed", "", fullname($user, true)));
|
||||
}
|
||||
|
||||
} else if ($delete and confirm_sesskey()) { // Delete a selected user, after confirmation
|
||||
|
||||
if (!has_capability('moodle/user:delete', $sitecontext)) {
|
||||
error('You do not have the required permission to delete a user.');
|
||||
}
|
||||
|
||||
if (!$user = get_record('user', 'id', $delete)) {
|
||||
} else if ($delete) { // Delete a selected user, after confirmation
|
||||
if (!$user = get_record("user", "id", "$delete")) {
|
||||
error("No such user!");
|
||||
}
|
||||
|
||||
@@ -160,26 +145,24 @@
|
||||
|
||||
if ($confirm != md5($delete)) {
|
||||
$fullname = fullname($user, true);
|
||||
print_heading(get_string('deleteuser', 'admin'));
|
||||
$optionsyes = array('delete'=>$delete, 'confirm'=>md5($delete), 'sesskey'=>sesskey());
|
||||
notice_yesno(get_string('deletecheckfull', '', "'$fullname'"), 'user.php', 'user.php', $optionsyes, NULL, 'post', 'get');
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
die;
|
||||
} else if (data_submitted() and !$user->deleted) {
|
||||
$updateuser = new object();
|
||||
notice_yesno(get_string("deletecheckfull", "", "'$fullname'"),
|
||||
"user.php?delete=$delete&confirm=".md5($delete), "user.php");
|
||||
|
||||
exit;
|
||||
} else if (!$user->deleted) {
|
||||
unset($updateuser);
|
||||
$updateuser->id = $user->id;
|
||||
$updateuser->deleted = 1;
|
||||
$updateuser->username = addslashes("$user->email.".time()); // Remember it just in case
|
||||
$updateuser->email = ''; // Clear this field to free it up
|
||||
$updateuser->idnumber = ''; // Clear this field to free it up
|
||||
$updateuser->deleted = "1";
|
||||
$updateuser->username = "$user->email.".time(); // Remember it just in case
|
||||
$updateuser->email = ""; // Clear this field to free it up
|
||||
$updateuser->timemodified = time();
|
||||
if (update_record('user', $updateuser)) {
|
||||
// not sure if this is needed. unenrol_student($user->id); // From all courses
|
||||
delete_records('role_assignments', 'userid', $user->id); // unassign all roles
|
||||
// remove all context assigned on this user?
|
||||
notify(get_string('deletedactivity', '', fullname($user, true)) );
|
||||
if (update_record("user", $updateuser)) {
|
||||
unenrol_student($user->id); // From all courses
|
||||
remove_teacher($user->id); // From all courses
|
||||
remove_admin($user->id);
|
||||
notify(get_string("deletedactivity", "", fullname($user, true)) );
|
||||
} else {
|
||||
notify(get_string('deletednot', '', fullname($user, true)));
|
||||
notify(get_string("deletednot", "", fullname($user, true)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,10 +187,10 @@
|
||||
} else {
|
||||
$columnicon = $dir == "ASC" ? "down":"up";
|
||||
}
|
||||
$columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" alt=\"\" />";
|
||||
$columnicon = " <img src=\"$CFG->pixpath/t/$columnicon.gif\" />";
|
||||
|
||||
}
|
||||
$$column = "<a href=\"user.php?sort=$column&dir=$columndir&search=".urlencode(stripslashes($search))."&firstinitial=$firstinitial&lastinitial=$lastinitial\">".$string[$column]."</a>$columnicon";
|
||||
$$column = "<a href=\"user.php?sort=$column&dir=$columndir&search=$search&firstinitial=$firstinitial&lastinitial=$lastinitial\">".$string[$column]."</a>$columnicon";
|
||||
}
|
||||
|
||||
if ($sort == "name") {
|
||||
@@ -219,14 +202,14 @@
|
||||
$usersearchcount = get_users(false, $search, true, "", "", $firstinitial, $lastinitial);
|
||||
|
||||
if ($search or $firstinitial or $lastinitial) {
|
||||
print_heading("$usersearchcount / $usercount ".get_string('users'));
|
||||
print_heading("$usersearchcount / $usercount ".get_string("users"));
|
||||
$usercount = $usersearchcount;
|
||||
} else {
|
||||
print_heading("$usercount ".get_string('users'));
|
||||
print_heading("$usercount ".get_string("users"));
|
||||
}
|
||||
|
||||
$alphabet = explode(',', get_string('alphabet'));
|
||||
$strall = get_string('all');
|
||||
$strall = get_string("all");
|
||||
|
||||
|
||||
/// Bar of first initials
|
||||
@@ -234,8 +217,8 @@
|
||||
echo "<center><p align=\"center\">";
|
||||
echo get_string("firstname")." : ";
|
||||
if ($firstinitial) {
|
||||
echo " <a href=\"user.php?sort=firstname&dir=ASC&".
|
||||
"perpage=$perpage&lastinitial=$lastinitial\">$strall</a> ";
|
||||
echo " <a href=\"user.php?sort=firstname&dir=ASC&".
|
||||
"perpage=$perpage&lastinitial=$lastinitial\">$strall</a> ";
|
||||
} else {
|
||||
echo " <b>$strall</b> ";
|
||||
}
|
||||
@@ -243,8 +226,8 @@
|
||||
if ($letter == $firstinitial) {
|
||||
echo " <b>$letter</b> ";
|
||||
} else {
|
||||
echo " <a href=\"user.php?sort=firstname&dir=ASC&".
|
||||
"perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> ";
|
||||
echo " <a href=\"user.php?sort=firstname&dir=ASC&".
|
||||
"perpage=$perpage&lastinitial=$lastinitial&firstinitial=$letter\">$letter</a> ";
|
||||
}
|
||||
}
|
||||
echo "<br />";
|
||||
@@ -253,8 +236,8 @@
|
||||
|
||||
echo get_string("lastname")." : ";
|
||||
if ($lastinitial) {
|
||||
echo " <a href=\"user.php?sort=lastname&dir=ASC&".
|
||||
"perpage=$perpage&firstinitial=$firstinitial\">$strall</a> ";
|
||||
echo " <a href=\"user.php?sort=lastname&dir=ASC&".
|
||||
"perpage=$perpage&firstinitial=$firstinitial\">$strall</a> ";
|
||||
} else {
|
||||
echo " <b>$strall</b> ";
|
||||
}
|
||||
@@ -262,34 +245,32 @@
|
||||
if ($letter == $lastinitial) {
|
||||
echo " <b>$letter</b> ";
|
||||
} else {
|
||||
echo " <a href=\"user.php?sort=lastname&dir=ASC&".
|
||||
"perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> ";
|
||||
echo " <a href=\"user.php?sort=lastname&dir=ASC&".
|
||||
"perpage=$perpage&firstinitial=$firstinitial&lastinitial=$letter\">$letter</a> ";
|
||||
}
|
||||
}
|
||||
echo "</p>";
|
||||
echo "</center>";
|
||||
|
||||
print_paging_bar($usercount, $page, $perpage,
|
||||
"user.php?sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&search=".urlencode(stripslashes($search))."&");
|
||||
"user.php?sort=$sort&dir=$dir&perpage=$perpage&firstinitial=$firstinitial&lastinitial=$lastinitial&search=$search&");
|
||||
|
||||
flush();
|
||||
|
||||
|
||||
if (!$users) {
|
||||
$match = array();
|
||||
if ($search !== '') {
|
||||
$match[] = s($search);
|
||||
if ($search) {
|
||||
$match[] = $search;
|
||||
}
|
||||
if ($firstinitial) {
|
||||
$match[] = get_string('firstname').": $firstinitial"."___";
|
||||
$match[] = get_string("firstname").": $firstinitial"."___";
|
||||
}
|
||||
if ($lastinitial) {
|
||||
$match[] = get_string('lastname').": $lastinitial"."___";
|
||||
$match[] = get_string("lastname").": $lastinitial"."___";
|
||||
}
|
||||
$matchstring = implode(", ", $match);
|
||||
print_heading(get_string('nousersmatching', '', $matchstring));
|
||||
|
||||
$table = NULL;
|
||||
print_heading(get_string("nousersmatching", "", $matchstring));
|
||||
|
||||
} else {
|
||||
|
||||
@@ -315,79 +296,55 @@
|
||||
$table->align = array ("left", "left", "left", "left", "left", "center", "center", "center");
|
||||
$table->width = "95%";
|
||||
foreach ($users as $user) {
|
||||
if ($user->username == 'changeme' or $user->username == 'guest') {
|
||||
continue; // do not dispaly dummy new user and guest here
|
||||
}
|
||||
|
||||
if ($user->id == $USER->id) {
|
||||
if ($user->id == $USER->id or $user->username == "changeme") {
|
||||
$deletebutton = "";
|
||||
} else {
|
||||
if (has_capability('moodle/user:delete', $sitecontext)) {
|
||||
$deletebutton = "<a href=\"user.php?delete=$user->id&sesskey=$USER->sesskey\">$strdelete</a>";
|
||||
} else {
|
||||
$deletebutton ="";
|
||||
}
|
||||
$deletebutton = "<a href=\"user.php?delete=$user->id\">$strdelete</a>";
|
||||
}
|
||||
|
||||
if (has_capability('moodle/user:update', $sitecontext)) {
|
||||
$editbutton = "<a href=\"../user/edit.php?id=$user->id&course=$site->id\">$stredit</a>";
|
||||
if ($user->confirmed == 0) {
|
||||
$confirmbutton = "<a href=\"user.php?confirmuser=$user->id&sesskey=$USER->sesskey\">" . get_string('confirm') . "</a>";
|
||||
} else {
|
||||
$confirmbutton = "";
|
||||
}
|
||||
} else {
|
||||
$editbutton ="";
|
||||
if ($user->confirmed == 0) {
|
||||
$confirmbutton = "<span class=\"dimmed_text\">".get_string('confirm')."</span>";
|
||||
} else {
|
||||
$confirmbutton = "";
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->lastaccess) {
|
||||
$strlastaccess = format_time(time() - $user->lastaccess);
|
||||
} else {
|
||||
$strlastaccess = get_string('never');
|
||||
$strlastaccess = get_string("never");
|
||||
}
|
||||
if ($user->confirmed == 0) {
|
||||
$confirmbutton = "<a href=\"user.php?confirmuser=$user->id\">" . get_string("confirm") . "</a>";
|
||||
} else {
|
||||
$confirmbutton = "";
|
||||
}
|
||||
$fullname = fullname($user, true);
|
||||
|
||||
$table->data[] = array ("<a href=\"../user/view.php?id=$user->id&course=$site->id\">$fullname</a>",
|
||||
"$user->email",
|
||||
"$user->city",
|
||||
"$user->country",
|
||||
$strlastaccess,
|
||||
$editbutton,
|
||||
$deletebutton,
|
||||
$confirmbutton);
|
||||
$table->data[] = array ("<a href=\"../user/view.php?id=$user->id&course=$site->id\">$fullname</a>",
|
||||
"$user->email",
|
||||
"$user->city",
|
||||
"$user->country",
|
||||
$strlastaccess,
|
||||
"<a href=\"../user/edit.php?id=$user->id&course=$site->id\">$stredit</a>",
|
||||
$deletebutton,
|
||||
$confirmbutton);
|
||||
}
|
||||
}
|
||||
|
||||
echo "<table class=\"searchbox\" align=\"center\" cellpadding=\"10\"><tr><td>";
|
||||
echo "<form action=\"user.php\" method=\"get\">";
|
||||
echo "<input type=\"text\" name=\"search\" value=\"".s($search, true)."\" size=\"20\" />";
|
||||
echo "<input type=\"submit\" value=\"$strsearch\" />";
|
||||
if ($search) {
|
||||
echo "<input type=\"button\" onclick=\"document.location='user.php';\" value=\"$strshowallusers\" />";
|
||||
}
|
||||
echo "</form>";
|
||||
echo "</td></tr></table>";
|
||||
echo "<table align=center cellpadding=10><tr><td>";
|
||||
echo "<form action=user.php method=post>";
|
||||
echo "<input type=text name=search value=\"$search\" size=20>";
|
||||
echo "<input type=submit value=\"$strsearch\">";
|
||||
if ($search) {
|
||||
echo "<input type=\"button\" onclick=\"document.location='user.php';\" value=\"$strshowallusers\">";
|
||||
}
|
||||
echo "</form>";
|
||||
echo "</td></tr></table>";
|
||||
|
||||
if (has_capability('moodle/user:create', $sitecontext)) {
|
||||
print_heading("<a href=\"user.php?newuser=true&sesskey=$USER->sesskey\">".get_string('addnewuser')."</a>");
|
||||
}
|
||||
if (!empty($table)) {
|
||||
print_table($table);
|
||||
|
||||
print_paging_bar($usercount, $page, $perpage,
|
||||
"user.php?sort=$sort&dir=$dir&perpage=$perpage".
|
||||
"&firstinitial=$firstinitial&lastinitial=$lastinitial&search=".urlencode(stripslashes($search))."&");
|
||||
if (has_capability('moodle/user:create', $sitecontext)) {
|
||||
print_heading("<a href=\"user.php?newuser=true&sesskey=$USER->sesskey\">".get_string("addnewuser")."</a>");
|
||||
}
|
||||
"user.php?sort=$sort&dir=$dir&perpage=$perpage".
|
||||
"&firstinitial=$firstinitial&lastinitial=$lastinitial&search=$search&");
|
||||
|
||||
}
|
||||
|
||||
if ($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual"){
|
||||
print_heading("<a href=\"user.php?newuser=true\">".get_string("addnewuser")."</a>");
|
||||
}
|
||||
|
||||
admin_externalpage_print_footer($adminroot);
|
||||
print_footer();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?PHP // $Id$
|
||||
|
||||
require_once("../config.php");
|
||||
|
||||
require_login();
|
||||
|
||||
if (!isadmin()) {
|
||||
error("Only admins can access this page");
|
||||
}
|
||||
|
||||
if (!$site = get_site()) {
|
||||
redirect("index.php");
|
||||
}
|
||||
|
||||
$stradministration = get_string("administration");
|
||||
$strusers = get_string("users");
|
||||
|
||||
print_header("$site->shortname: $stradministration: $strusers", "$site->fullname",
|
||||
"<a href=\"index.php\">$stradministration</a> -> $strusers");
|
||||
|
||||
print_heading($strusers);
|
||||
|
||||
$table->align = array ("right", "left");
|
||||
|
||||
$table->data[] = array("<b><a href=\"auth.php\">".get_string("authentication")."</a></b>",
|
||||
get_string("adminhelpauthentication"));
|
||||
|
||||
if (is_internal_auth()) {
|
||||
$table->data[] = array("<b><a href=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true\">".get_string("addnewuser")."</a></b>",
|
||||
get_string("adminhelpaddnewuser"));
|
||||
$table->data[] = array("<b><a href=\"$CFG->wwwroot/$CFG->admin/uploaduser.php\">".get_string("uploadusers")."</a></b>",
|
||||
get_string("adminhelpuploadusers"));
|
||||
}
|
||||
$table->data[] = array("<b><a href=\"user.php\">".get_string("edituser")."</a></b>",
|
||||
get_string("adminhelpedituser"));
|
||||
$table->data[] = array("<b><a href=\"admin.php\">".get_string("assignadmins")."</a></b>",
|
||||
get_string("adminhelpassignadmins"));
|
||||
$table->data[] = array("<b><a href=\"creators.php\">".get_string("assigncreators")."</a></b>",
|
||||
get_string("adminhelpassigncreators"));
|
||||
$table->data[] = array("<b><a href=\"../course/index.php?edit=on\">".get_string("assignteachers")."</a></b>",
|
||||
get_string("adminhelpassignteachers")." <img src=\"../pix/t/user.gif\" height=11 width=11>");
|
||||
$table->data[] = array("<b><a href=\"../course/index.php?edit=off\">".get_string("assignstudents")."</a></b>",
|
||||
get_string("adminhelpassignstudents"));
|
||||
|
||||
print_table($table);
|
||||
|
||||
print_footer($site);
|
||||
|
||||
?>
|
||||
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
if (!isset($form->dbhost)) {
|
||||
$form->dbhost = '';
|
||||
}
|
||||
if (!isset($form->dbname)) {
|
||||
$form->dbname = '';
|
||||
}
|
||||
if (!isset($form->dbuser)) {
|
||||
$form->dbuser = '';
|
||||
}
|
||||
if (!isset($form->dbpass)) {
|
||||
$form->dbpass = '';
|
||||
}
|
||||
if (!isset($form->dbcluster)) {
|
||||
$form->dbcluster = '';
|
||||
}
|
||||
if (!isset($form->pathtopgdump)) {
|
||||
$form->pathtopgdump = '';
|
||||
}
|
||||
if (!isset($form->pathtopsql)) {
|
||||
$form->pathtopsql = '';
|
||||
}
|
||||
?>
|
||||
<form name="migratefrom" action="utfdbmigrate.php" method="POST">
|
||||
<input name="migrate" type="hidden" value="1" />
|
||||
<input name="sesskey" type="hidden" value="<?php echo sesskey() ?>" />
|
||||
<?php if (isset($err["dbconnect"])) formerr($err["dbconnect"]); ?>
|
||||
<?php if (isset($err["pathtopgdump"])) formerr($err["pathtopgdump"]); ?>
|
||||
<?php if (isset($err["pathtopsql"])) formerr($err["pathtopsql"]); ?>
|
||||
<table cellpadding="9" cellspacing="0" width="500">
|
||||
<tr valign="top">
|
||||
<td align="right"><?php print_string("dbhost", "install") ?>:</td>
|
||||
<td><input type="text" name="dbhost" value="<?php p($form->dbhost) ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><?php print_string("database", "install") ?>:</td>
|
||||
<td><input type="text" name="dbname" value="<?php p($form->dbname) ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><?php print_string("user") ?>:</td>
|
||||
<td><input type="text" name="dbuser" value="<?php p($form->dbuser) ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><?php print_string("password") ?>:</td>
|
||||
<td><input type="text" name="dbpass" value="<?php p($form->dbpass) ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right"><?php print_string("pgcluster", "admin") ?>:</td>
|
||||
<td><input type="text" name="dbcluster" value="<?php p($form->dbcluster) ?>" />
|
||||
<td><?php print_string("pgclusterdescription", "admin") ?></td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right" nowrap="nowrap"><?php print_string("pathtopgdump","admin") ?>:</td>
|
||||
<td><input type="text" name="pathtopgdump" value="<?php p($form->pathtopgdump) ?>" />
|
||||
<td><?php print_string("pathtopgdumpdesc","admin"); ?></td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right" nowrap="nowrap"><?php print_string("pathtopsql","admin") ?>:</td>
|
||||
<td><input type="text" name="pathtopsql" value="<?php p($form->pathtopsql) ?>" />
|
||||
<td><?php print_string("pathtopsqldesc","admin"); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
<center>
|
||||
<input type="submit" value="<?php print_string('continue') ?>"/>
|
||||
<input type="button" value="<?php print_string('cancel') ?>" onclick="javascript:history.go(-1)" />
|
||||
</center>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,78 +0,0 @@
|
||||
XMLDB - Base classes and edition interface.
|
||||
|
||||
Complete Documentation:
|
||||
|
||||
http://docs.moodle.org/en/XMLDB_Defining_one_XML_structure
|
||||
|
||||
Ciao, Eloy Lafuente (stronk7)
|
||||
|
||||
========== ========== ========== ========== ==========
|
||||
========== ========== HISTORY ========== ==========
|
||||
========== ========== ========== ========== ==========
|
||||
|
||||
2006-08-07 - Editor working on production
|
||||
|
||||
The editor has been used succesfully to build
|
||||
a bunch of install.xml files and everything
|
||||
seems to be working properly.
|
||||
|
||||
========== ========== ========== ========== ==========
|
||||
|
||||
2006-07-11 - PHP4 compatible release
|
||||
|
||||
Now everything seems to be working under PHP 4. What
|
||||
a horrible OOP implementation!
|
||||
|
||||
Note that write permissions to */db dirs are required.
|
||||
|
||||
Now working in the 3 missing forms, to manually edit
|
||||
fields, keys and indexes.
|
||||
|
||||
Ciao, Eloy Lafuente (stronk7)
|
||||
|
||||
========== ========== ========== ========== ==========
|
||||
|
||||
2006-07-11 - Important notes
|
||||
|
||||
I've just discovered this some seconds ago, in order
|
||||
to test properly the XMLDB classes and editor:
|
||||
|
||||
1.- PHP 5 required for now. Will change this soon.
|
||||
2.- Perms to "apache" user needed in */db
|
||||
dirs in order to allow the XMDBD interface
|
||||
to write files.
|
||||
|
||||
Ciao, Eloy Lafuente (stronk7)
|
||||
|
||||
========== ========== ========== ========== ==========
|
||||
|
||||
2006-07-11 - Initial commit
|
||||
|
||||
This directory contains the XMLDB classes to be used
|
||||
under Moodle > 1.7 to store all the DB info in a
|
||||
neutral form (classes dir). Also it contains one simple
|
||||
interface to edit all those structures.
|
||||
|
||||
To install and test it, simply copy the whole xmldb directory
|
||||
under your moodle/admin dir and point your browser (as admin)
|
||||
to http://your.server/moodle/admin/xmldb
|
||||
|
||||
The edition interface isn't completed yet (it laks 3 more forms
|
||||
to edit fields, keys and indexes) and there isn't any lang file
|
||||
(although I hope everything is really clear).
|
||||
|
||||
The edition interface includes one reverse-engineering tool that
|
||||
provides an easy way to retroffit and to generate any table from
|
||||
MySQL to the new XMLDB format.
|
||||
|
||||
Once the XMLDB format was approved, we'll be able to build all the
|
||||
"generators" needed in order to use it to create Moodle DB structures
|
||||
for each RDBMS flavour.
|
||||
|
||||
Once the interface was finished (2-3 days from now) related documentation
|
||||
will be sent to http://docs.moodle.org/en/XML_database_schema in order
|
||||
to comment/modify/approve the final XML format.
|
||||
|
||||
All the code is, obviously GPL, with its copyrights and so on...
|
||||
|
||||
Ciao, Eloy Lafuente (stronk7) :-)
|
||||
@@ -1,191 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This is the main action class. It implements all the basic
|
||||
/// functionalities to be shared by each action.
|
||||
|
||||
class XMLDBAction {
|
||||
|
||||
var $does_generate; //Type of value returned by the invoke method
|
||||
//ACTION_GENERATE_HTML have contents to show
|
||||
//set by each specialized invoke
|
||||
|
||||
var $title; //Title of the Action (class name, by default)
|
||||
//set by parent init automatically
|
||||
|
||||
var $str; //Strings used by the action
|
||||
//set by each specialized init, calling loadStrings
|
||||
|
||||
var $output; //Output of the action
|
||||
//set by each specialized invoke, get with getOutput
|
||||
|
||||
var $errormsg; //Last Error produced. Check when any invoke returns false
|
||||
//get with getError
|
||||
|
||||
var $postaction; //Action to execute at the end of the invoke script
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function XMLDBAction() {
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to keep PHP5 happy
|
||||
*/
|
||||
function __construct() {
|
||||
$this->XMLDBAction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own,
|
||||
* always calling the parent one
|
||||
*/
|
||||
function init() {
|
||||
$this->does_generate = ACTION_NONE;
|
||||
$this->title = strtolower(get_class($this));
|
||||
$this->str = array();
|
||||
$this->output = NULL;
|
||||
$this->errormsg = NULL;
|
||||
$this->subaction = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the type of output of the file
|
||||
*/
|
||||
function getDoesGenerate() {
|
||||
return $this->does_generate;
|
||||
}
|
||||
|
||||
/**
|
||||
* getError method, returns the last error string.
|
||||
* Used if the invoke() methods returns false
|
||||
*/
|
||||
function getError() {
|
||||
return $this->errormsg;
|
||||
}
|
||||
|
||||
/**
|
||||
* getOutput method, returns the output generated by the action.
|
||||
* Used after execution of the invoke() methods if they return true
|
||||
*/
|
||||
function getOutput() {
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPostAtion method, returns the action to launch after executing
|
||||
* another one
|
||||
*/
|
||||
function getPostAction() {
|
||||
return $this->postaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* getTitle method returns the title of the action (that is part
|
||||
* of the $str array attribute
|
||||
*/
|
||||
function getTitle() {
|
||||
return $this->str['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* loadStrings method, loads the required strings specified in the
|
||||
* array parameter
|
||||
*/
|
||||
function loadStrings($strings) {
|
||||
/// Load some commonly used strings
|
||||
$this->str['title'] = get_string($this->title, 'xmldb');
|
||||
|
||||
/// Now process the $strings array loading it in the $str atribute
|
||||
if ($strings) {
|
||||
foreach ($strings as $key => $module) {
|
||||
$this->str[$key] = get_string($key, $module);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* main invoke method, it simply sets the postaction attribute
|
||||
* if possible
|
||||
*/
|
||||
function invoke() {
|
||||
|
||||
global $SESSION;
|
||||
|
||||
/// If we are used any dir, save it in the lastused session object
|
||||
/// Some actions can use it to perform positioning
|
||||
if ($lastused = optional_param ('dir', NULL, PARAM_PATH)) {
|
||||
$SESSION->lastused = stripslashes_safe($lastused);
|
||||
}
|
||||
|
||||
$this->postaction = optional_param ('postaction', NULL, PARAM_ALPHAEXT);
|
||||
/// Avoid being recursive
|
||||
if ($this->title == $this->postaction) {
|
||||
$this->postaction = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* launch method, used to easily call invoke methods between actions
|
||||
*/
|
||||
function launch($action) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
/// Get the action path and invoke it
|
||||
$actionsroot = "$CFG->dirroot/$CFG->admin/xmldb/actions";
|
||||
$actionclass = $action . '.class.php';
|
||||
$actionpath = "$actionsroot/$action/$actionclass";
|
||||
|
||||
/// Load and invoke the proper action
|
||||
$result = false;
|
||||
if (file_exists($actionpath) && is_readable($actionpath)) {
|
||||
require_once($actionpath);
|
||||
if ($xmldb_action = new $action) {
|
||||
$result = $xmldb_action->invoke();
|
||||
if ($result) {
|
||||
if ($xmldb_action->does_generate != ACTION_NONE &&
|
||||
$xmldb_action->getOutput()) {
|
||||
$this->does_generate = $xmldb_action->does_generate;
|
||||
$this->title = $xmldb_action->title;
|
||||
$this->str = $xmldb_action->str;
|
||||
$this->output .= $xmldb_action->getOutput();
|
||||
}
|
||||
} else {
|
||||
$this->errormsg = $xmldb_action->getError();
|
||||
}
|
||||
} else {
|
||||
$this->errormsg = "Error: cannot instantiate class (actions/$action/$actionclass)";
|
||||
}
|
||||
} else {
|
||||
$this->errormsg = "Error: wrong action specified ($action)";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,108 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will
|
||||
|
||||
class create_xml_file extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
/// Set own core attributes
|
||||
$this->can_subaction = ACTION_NONE;
|
||||
//$this->can_subaction = ACTION_HAVE_SUBACTIONS;
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
/// 'key' => 'module',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
$file = $dirpath . '/install.xml';
|
||||
|
||||
/// Some variables
|
||||
$xmlpath = dirname(str_replace($CFG->dirroot . '/', '', $file));
|
||||
$xmlversion = userdate(time(), '%Y%m%d', 99, false);
|
||||
$xmlcomment = 'XMLDB file for Moodle ' . dirname($xmlpath);
|
||||
|
||||
$xmltable = strtolower(basename(dirname($xmlpath)));
|
||||
|
||||
/// Initial contents
|
||||
$c = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
|
||||
$c.= ' <XMLDB PATH="' . $xmlpath . '" VERSION="' . $xmlversion .'" COMMENT="' . $xmlcomment .'">' . "\n";
|
||||
$c.= ' <TABLES>' . "\n";
|
||||
$c.= ' <TABLE NAME="' . $xmltable . '" COMMENT="Default comment for ' . $xmltable .', please edit me">' . "\n";
|
||||
$c.= ' <FIELDS>' . "\n";
|
||||
$c.= ' <FIELD NAME="id" TYPE="int" LENGTH="10" UNSIGNED="true" NOTNULL="true" SEQUENCE="true" COMMENT="id of the table, please edit me" />' . "\n";
|
||||
$c.= ' </FIELDS>' . "\n";
|
||||
$c.= ' <KEYS>' . "\n";
|
||||
$c.= ' <KEY NAME="primary" COMMENT="Primary key for ' . $xmltable . '" TYPE="primary" FIELDS="id" />' . "\n";
|
||||
$c.= ' </KEYS>' . "\n";
|
||||
$c.= ' </TABLE>' . "\n";
|
||||
$c.= ' </TABLES>' . "\n";
|
||||
$c.= ' </XMLDB>';
|
||||
|
||||
if (!file_put_contents($file, $c)) {
|
||||
$errormsg = 'Error creando fichero ' . $file;
|
||||
$result = false;
|
||||
}
|
||||
|
||||
/// Launch postaction if exists
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,140 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will delete completely one field
|
||||
|
||||
class delete_field extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletefield' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
$fieldparam = required_param('field', PARAM_CLEAN);
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
$o.= ' <p align="center">' . $this->str['confirmdeletefield'] . '<br /><br />' . $fieldparam . '</p>';
|
||||
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=delete_field&confirmed=yes&postaction=edit_table&field=' . $fieldparam . '&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||
$o.= ' </td><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= '</table>';
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
/// Move adjacent fields prev and next attributes
|
||||
$tables =& $structure->getTables();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$fields =& $table->getFields();
|
||||
$field =& $table->getField($fieldparam);
|
||||
if ($field->getPrevious()) {
|
||||
$prev =& $table->getField($field->getPrevious());
|
||||
$prev->setNext($field->getNext());
|
||||
}
|
||||
if ($field->getNext()) {
|
||||
$next =& $table->getField($field->getNext());
|
||||
$next->setPrevious($field->getPrevious());
|
||||
}
|
||||
/// Remove the field
|
||||
$table->deleteField($fieldparam);
|
||||
|
||||
/// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,140 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will delete completely one index
|
||||
|
||||
class delete_index extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeleteindex' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
$tableparam = required_param('table', PARAM_PATH);
|
||||
$indexparam = required_param('index', PARAM_PATH);
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
$o.= ' <p align="center">' . $this->str['confirmdeleteindex'] . '<br /><br />' . $indexparam . '</p>';
|
||||
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=delete_index&confirmed=yes&postaction=edit_table&index=' . $indexparam . '&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||
$o.= ' </td><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= '</table>';
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
/// Move adjacent indexes prev and next attributes
|
||||
$tables =& $structure->getTables();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$indexes =& $table->getIndexes();
|
||||
$index =& $table->getIndex($indexparam);
|
||||
if ($index->getPrevious()) {
|
||||
$prev =& $table->getIndex($index->getPrevious());
|
||||
$prev->setNext($index->getNext());
|
||||
}
|
||||
if ($index->getNext()) {
|
||||
$next =& $table->getIndex($index->getNext());
|
||||
$next->setPrevious($index->getPrevious());
|
||||
}
|
||||
/// Remove the index
|
||||
$table->deleteIndex($indexparam);
|
||||
|
||||
/// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,140 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will delete completely one key
|
||||
|
||||
class delete_key extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletekey' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
$tableparam = required_param('table', PARAM_PATH);
|
||||
$keyparam = required_param('key', PARAM_PATH);
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
$o.= ' <p align="center">' . $this->str['confirmdeletekey'] . '<br /><br />' . $keyparam . '</p>';
|
||||
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=delete_key&confirmed=yes&postaction=edit_table&key=' . $keyparam . '&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||
$o.= ' </td><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= '</table>';
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
/// Move adjacent keys prev and next attributes
|
||||
$tables =& $structure->getTables();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$keys =& $table->getKeys();
|
||||
$key =& $table->getKey($keyparam);
|
||||
if ($key->getPrevious()) {
|
||||
$prev =& $table->getKey($key->getPrevious());
|
||||
$prev->setNext($key->getNext());
|
||||
}
|
||||
if ($key->getNext()) {
|
||||
$next =& $table->getKey($key->getNext());
|
||||
$next->setPrevious($key->getPrevious());
|
||||
}
|
||||
/// Remove the key
|
||||
$table->deleteKey($keyparam);
|
||||
|
||||
/// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will delete completely one sentence
|
||||
|
||||
class delete_sentence extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletesentence' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
$statementparam = required_param('statement', PARAM_CLEAN);
|
||||
$sentenceparam = required_param('sentence', PARAM_INT);
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
$o.= ' <p align="center">' . $this->str['confirmdeletesentence'] . '</p>';
|
||||
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=delete_sentence&confirmed=yes&postaction=edit_statement&sentence=' . $sentenceparam . '&statement=' . urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||
$o.= ' </td><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=edit_statement&statement=' . urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= '</table>';
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
$statements =& $structure->getStatements();
|
||||
$statement =& $structure->getStatement($statementparam);
|
||||
$sentences =& $statement->getSentences();
|
||||
/// Remove the sentence
|
||||
unset ($sentences[$sentenceparam]);
|
||||
|
||||
/// The statement has changed
|
||||
$statement->setChanged(true);
|
||||
|
||||
/// Recalculate the hash
|
||||
$structure->calculateHash(true);
|
||||
|
||||
/// If the hash has changed from the original one, change the version
|
||||
/// and mark the structure as changed
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
if ($structure->getHash() != $origstructure->getHash()) {
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,115 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will delete completely one statement
|
||||
|
||||
class delete_statement extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletestatement' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
$statementparam = required_param('statement', PARAM_CLEAN);
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
$o.= ' <p align="center">' . $this->str['confirmdeletestatement'] . '<br /><br />' . $statementparam . '</p>';
|
||||
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=delete_statement&confirmed=yes&postaction=edit_xml_file&statement=' . $statementparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||
$o.= ' </td><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= '</table>';
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
/// Remove the table
|
||||
$structure->deleteStatement($statementparam);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,115 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will delete completely one table
|
||||
|
||||
class delete_table extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletetable' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
$o.= ' <p align="center">' . $this->str['confirmdeletetable'] . '<br /><br />' . $tableparam . '</p>';
|
||||
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=delete_table&confirmed=yes&postaction=edit_xml_file&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||
$o.= ' </td><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= '</table>';
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the edited dir
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
if (isset($XMLDB->editeddirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
if ($editeddir) {
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
/// Remove the table
|
||||
$structure->deleteTable($tableparam);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,111 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will delete completely one XML file
|
||||
|
||||
class delete_xml_file extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'confirmdeletexmlfile' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_CLEAN);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
|
||||
|
||||
/// If not confirmed, show confirmation box
|
||||
if (!$confirmed) {
|
||||
$o = '<table align="center" width="60" class="generalbox" border="0" cellpadding="5" cellspacing="0" id="notice">';
|
||||
$o.= ' <tr><td class="generalboxcontent">';
|
||||
$o.= ' <p align="center">' . $this->str['confirmdeletexmlfile'] . '<br /><br />' . $dirpath . '/install.php</p>';
|
||||
$o.= ' <table align="center" cellpadding="20"><tr><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=delete_xml_file&confirmed=yes&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&postaction=main_view#lastused" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['yes'] .'" /></form></div>';
|
||||
$o.= ' </td><td>';
|
||||
$o.= ' <div class="singlebutton">';
|
||||
$o.= ' <form action="index.php?action=main_view#lastused" method="post">';
|
||||
$o.= ' <input type="submit" value="'. $this->str['no'] .'" /></form></div>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= ' </td></tr>';
|
||||
$o.= '</table>';
|
||||
|
||||
$this->output = $o;
|
||||
} else {
|
||||
/// Get the original dir and delete the xml file
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
if (isset($XMLDB->dbdirs[$dirpath])) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
if ($dbdir) {
|
||||
@unlink($dirpath . '/install.xml');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,204 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will provide the interface for all the edit field actions
|
||||
|
||||
class edit_field extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'xmldb',
|
||||
'vieworiginal' => 'xmldb',
|
||||
'viewedited' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => '',
|
||||
'back' => 'xmldb'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
/// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// Fetch request data
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
if (!$table =& $structure->getTable($tableparam)) {
|
||||
$this->errormsg = 'Wrong table specified: ' . $tableparm;
|
||||
return false;
|
||||
}
|
||||
$fieldparam = required_param('field', PARAM_CLEAN);
|
||||
if (!$field =& $table->getField($fieldparam)) {
|
||||
/// Arriving here from a name change, looking for the new field name
|
||||
$fieldparam = required_param('name', PARAM_CLEAN);
|
||||
$field =& $table->getField($fieldparam);
|
||||
}
|
||||
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
|
||||
/// Add the main form
|
||||
$o = '<form name="form" id="form" action="index.php" method="post">';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
$o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="field" value="' . $fieldparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_field_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||
$o.= ' <table id="formelements" align="center">';
|
||||
/// XMLDB field name
|
||||
/// If the field has dependencies, we cannot change its name
|
||||
$disabled = '';
|
||||
if ($structure->getFieldUses($table->getName(), $field->getName())) {
|
||||
$o.= ' <input type="hidden" name ="name" value="' . s($field->getName()) .'" />';
|
||||
$o.= ' <tr valign="top"><td>Name:</td><td colspan="2">' . s($field->getName()) . '</td></tr>';
|
||||
} else {
|
||||
$o.= ' <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="30" maxlength="30" id="name" value="' . s($field->getName()) . '" /></td></tr>';
|
||||
}
|
||||
/// XMLDB field comment
|
||||
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td colspan="2"><textarea name="comment" rows="3" cols="80" id="comment">' . s($field->getComment()) . '</textarea></td></tr>';
|
||||
/// XMLDBField Type
|
||||
$typeoptions = array (XMLDB_TYPE_INTEGER => $field->getXMLDBTypeName(XMLDB_TYPE_INTEGER),
|
||||
XMLDB_TYPE_NUMBER => $field->getXMLDBTypeName(XMLDB_TYPE_NUMBER),
|
||||
XMLDB_TYPE_FLOAT => $field->getXMLDBTypeName(XMLDB_TYPE_FLOAT),
|
||||
XMLDB_TYPE_DATETIME=> $field->getXMLDBTypeName(XMLDB_TYPE_DATETIME),
|
||||
XMLDB_TYPE_CHAR => $field->getXMLDBTypeName(XMLDB_TYPE_CHAR),
|
||||
XMLDB_TYPE_TEXT => $field->getXMLDBTypeName(XMLDB_TYPE_TEXT),
|
||||
XMLDB_TYPE_BINARY => $field->getXMLDBTypeName(XMLDB_TYPE_BINARY));
|
||||
/// If current field isnt float, delete such column type to avoid its creation from the interface
|
||||
/// Note that float fields are supported completely but it's possible than in a next future
|
||||
/// we delete them completely from Moodle DB, using, exlusively, number(x,y) types
|
||||
if ($field->getType() != XMLDB_TYPE_FLOAT) {
|
||||
unset ($typeoptions[XMLDB_TYPE_FLOAT]);
|
||||
}
|
||||
/// Also we hide datetimes. Only edition of them is allowed (and retrofit) but not new creation
|
||||
if ($field->getType() != XMLDB_TYPE_DATETIME) {
|
||||
unset ($typeoptions[XMLDB_TYPE_DATETIME]);
|
||||
}
|
||||
$o.= ' <tr valign="top"><td><label for="menutype" accesskey="t">Type:</label></td>';
|
||||
$o.= ' <td colspan="2">' . choose_from_menu($typeoptions, 'type', $field->getType(), '', '', '', true) . '</td></tr>';
|
||||
/// XMLDBField Length
|
||||
$o.= ' <tr valign="top"><td><label for="length" accesskey="l">Length:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="length" type="text" size="6" maxlength="6" id="length" value="' . s($field->getLength()) . '" /><span id="lengthtip"></span></td></tr>';
|
||||
/// XMLDBField Decimals
|
||||
$o.= ' <tr valign="top"><td><label for="decimals" accesskey="d">Decimals:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="decimals" type="text" size="6" maxlength="6" id="decimals" value="' . s($field->getDecimals()) . '" /><span id="decimalstip"></span></td></tr>';
|
||||
/// XMLDBField Unsigned
|
||||
$unsignedoptions = array (0 => 'signed', 1 => 'unsigned');
|
||||
$o.= ' <tr valign="top"><td><label for="menuunsigned" accesskey="u">Unsigned:</label></td>';
|
||||
$o.= ' <td colspan="2">' . choose_from_menu($unsignedoptions, 'unsigned', $field->getUnsigned(), '', '', '', true) . '</td></tr>';
|
||||
/// XMLDBField NotNull
|
||||
$notnulloptions = array (0 => 'null', 'not null');
|
||||
$o.= ' <tr valign="top"><td><label for="menunotnull" accesskey="n">Not Null:</label></td>';
|
||||
$o.= ' <td colspan="2">' . choose_from_menu($notnulloptions, 'notnull', $field->getNotNull(), '', '', '', true) . '</td></tr>';
|
||||
/// XMLDBField Sequence
|
||||
$sequenceoptions = array (0 => $this->str['no'], 1 => 'auto-numbered');
|
||||
$o.= ' <tr valign="top"><td><label for="menusequence" accesskey="s">Sequence:</label></td>';
|
||||
$o.= ' <td colspan="2">' . choose_from_menu($sequenceoptions, 'sequence', $field->getSequence(), '', '', '', true) . '</td></tr>';
|
||||
/// XMLDBField Enum and enumvalues
|
||||
$enumoptions = array (0 => $this->str['no'], 1 => $this->str['yes']);
|
||||
$o.= ' <tr valign="top"><td><label for="menuenum" accesskey="s">Enum:</label></td>';
|
||||
$o.= ' <td>' . choose_from_menu($enumoptions, 'enum', $field->getEnum(), '', '', '', true) . '</td>';
|
||||
if (is_array($field->getEnumValues())) {
|
||||
$enumvalues = implode(', ', $field->getEnumValues());
|
||||
} else {
|
||||
$enumvalues = '';
|
||||
}
|
||||
$o.= ' <td><textarea name="enumvalues" rows="3" cols="70" id="enumvalues">' . s($enumvalues) . '</textarea></td></tr>';
|
||||
/// XMLDBField Default
|
||||
$o.= ' <tr valign="top"><td><label for="default" accesskey="d">Default:</label></td>';
|
||||
$o.= ' <td colspan="2"><input type="text" name="default" size="30" maxlength="80" id="default" value="' . s($field->getDefault()) . '" /></td></tr>';
|
||||
/// Change button
|
||||
$o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</form>';
|
||||
/// Calculate the buttons
|
||||
$b = ' <p align="center" class="buttons">';
|
||||
/// The view original XML button
|
||||
if ($table->getField($fieldparam)) {
|
||||
$b .= ' <a href="index.php?action=view_field_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&table=' . $tableparam . '&field=' . $fieldparam . '" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||
}
|
||||
/// The view edited XML button
|
||||
if ($field->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_field_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&table=' . $tableparam . '&field=' . $fieldparam . '" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The back to edit table button
|
||||
$b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $b;
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,187 +0,0 @@
|
||||
/// $Id $
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/// Register the needed events
|
||||
|
||||
onload=function() {
|
||||
/// Adjust the form on load
|
||||
transformForm();
|
||||
|
||||
/// Get the required fields
|
||||
var typeField = document.getElementById('menutype');
|
||||
var sequenceField = document.getElementById('menusequence');
|
||||
var enumField = document.getElementById('menuenum');
|
||||
|
||||
/// Register the rest of events
|
||||
if (typeField.addEventListener) {
|
||||
/// Standard
|
||||
typeField.addEventListener('change', transformForm, false);
|
||||
sequenceField.addEventListener('change', transformForm, false);
|
||||
enumField.addEventListener('change', transformForm, false);
|
||||
} else {
|
||||
/// IE 5.5
|
||||
typeField.attachEvent('onchange', transformForm);
|
||||
sequenceField.attachEvent('onchange', transformForm);
|
||||
enumField.attachEvent('onchange', transformForm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function controls all modifications to perform when any field changes
|
||||
*/
|
||||
function transformForm(event) {
|
||||
|
||||
/// Initialize all the needed variables
|
||||
var typeField = document.getElementById('menutype');
|
||||
var lengthField = document.getElementById('length');
|
||||
var decimalsField = document.getElementById('decimals');
|
||||
var unsignedField = document.getElementById('menuunsigned');
|
||||
var notnullField = document.getElementById('menunotnull');
|
||||
var sequenceField = document.getElementById('menusequence');
|
||||
var enumField = document.getElementById('menuenum');
|
||||
var enumvaluesField = document.getElementById('enumvalues');
|
||||
var defaultField = document.getElementById('default');
|
||||
|
||||
var lengthTip = document.getElementById('lengthtip');
|
||||
var decimalsTip = document.getElementById('decimalstip');
|
||||
|
||||
/// Initially, enable everything
|
||||
decimalsField.disabled = false;
|
||||
unsignedField.disabled = false;
|
||||
notnullField.disabled = false;
|
||||
sequenceField.disabled = false;
|
||||
enumField.disabled = false;
|
||||
enumvaluesField.disabled = false;
|
||||
defaultField.disabled = false;
|
||||
|
||||
/// Based on enum, disable some items
|
||||
if (enumField.value == '0') {
|
||||
enumvaluesField.disabled = true;
|
||||
enumvaluesField.value = '';
|
||||
};
|
||||
|
||||
/// Based on sequence, disable some items
|
||||
if (sequenceField.value == '1') {
|
||||
unsignedField.disabled = true;
|
||||
unsignedField.value = '1';
|
||||
notnullField.disabled = true;
|
||||
notnullField.value = '1';
|
||||
defaultField.disabled = true;
|
||||
defaultField.value = '';
|
||||
enumField.disabled = true;
|
||||
enumField.value = '0';
|
||||
enumvaluesField.disabled = true;
|
||||
enumvaluesField.value = '';
|
||||
}
|
||||
|
||||
|
||||
/// Based on type, disable some items
|
||||
switch (typeField.value) {
|
||||
case '1': // XMLDB_TYPE_INTEGER
|
||||
lengthTip.innerHTML = ' 1...20';
|
||||
decimalsTip.innerHTML = '';
|
||||
decimalsField.disabled = true;
|
||||
decimalsField.value = '';
|
||||
enumField.disabled = true;
|
||||
enumField.value = '0';
|
||||
enumvaluesField.disabled = true;
|
||||
enumvaluesField.value = '';
|
||||
break;
|
||||
case '2': // XMLDB_TYPE_NUMBER
|
||||
lengthTip.innerHTML = ' 1...20';
|
||||
decimalsTip.innerHTML = ' 0...length or empty';
|
||||
enumField.disabled = true;
|
||||
enumField.value = '0';
|
||||
enumvaluesField.disabled = true;
|
||||
enumvaluesField.value = '';
|
||||
break;
|
||||
case '3': // XMLDB_TYPE_FLOAT
|
||||
lengthTip.innerHTML = ' 1...20 or empty';
|
||||
decimalsTip.innerHTML = ' 0...length or empty';
|
||||
enumField.disabled = true;
|
||||
enumField.value = '0';
|
||||
enumvaluesField.disabled = true;
|
||||
enumvaluesField.value = '';
|
||||
break;
|
||||
case '4': // XMLDB_TYPE_CHAR
|
||||
lengthTip.innerHTML = ' 1...255';
|
||||
decimalsTip.innerHTML = '';
|
||||
decimalsField.disabled = true;
|
||||
decimalsField.value = '';
|
||||
unsignedField.disabled = true;
|
||||
unsignedField.value = '0';
|
||||
sequenceField.disabled = true;
|
||||
sequenceField.value = '0';
|
||||
break;
|
||||
case '5': // XMLDB_TYPE_TEXT
|
||||
lengthTip.innerHTML = ' small, medium, big';
|
||||
decimalsTip.innerHTML = '';
|
||||
decimalsField.disabled = true;
|
||||
decimalsField.value = '';
|
||||
unsignedField.disabled = true;
|
||||
unsignedField.value = '0';
|
||||
sequenceField.disabled = true;
|
||||
sequenceField.value = '0';
|
||||
defaultField.disabled = true;
|
||||
defaultField.value = '';
|
||||
break;
|
||||
case '6': // XMLDB_TYPE_BINARY
|
||||
lengthTip.innerHTML = ' small, medium, big';
|
||||
decimalsTip.innerHTML = '';
|
||||
decimalsField.disabled = true;
|
||||
decimalsField.value = '';
|
||||
unsignedField.disabled = true;
|
||||
unsignedField.value = '0';
|
||||
sequenceField.disabled = true;
|
||||
sequenceField.value = '0';
|
||||
enumField.disabled = true;
|
||||
enumField.value = '0';
|
||||
enumvaluesField.disabled = true;
|
||||
enumvaluesField.value = '';
|
||||
defaultField.disabled = true;
|
||||
defaultField.value = '';
|
||||
break;
|
||||
case '7': // XMLDB_TYPE_DATETIME
|
||||
lengthTip.innerHTML = '';
|
||||
lengthField.disabled = true;
|
||||
lengthField.value = '';
|
||||
decimalsTip.innerHTML = '';
|
||||
decimalsField.disabled = true;
|
||||
decimalsField.value = '';
|
||||
unsignedField.disabled = true;
|
||||
unsignedField.value = '0';
|
||||
sequenceField.disabled = true;
|
||||
sequenceField.value = '0';
|
||||
enumField.disabled = true;
|
||||
enumField.value = '0';
|
||||
enumvaluesField.disabled = true;
|
||||
enumvaluesField.value = '';
|
||||
defaultField.disabled = true;
|
||||
defaultField.value = '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,350 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will save the changes performed to one field
|
||||
|
||||
class edit_field_save extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'fieldnameempty' => 'xmldb',
|
||||
'incorrectfieldname' => 'xmldb',
|
||||
'duplicatefieldname' => 'xmldb',
|
||||
'integerincorrectlength' => 'xmldb',
|
||||
'numberincorrectlength' => 'xmldb',
|
||||
'floatincorrectlength' => 'xmldb',
|
||||
'charincorrectlength' => 'xmldb',
|
||||
'textincorrectlength' => 'xmldb',
|
||||
'binaryincorrectlength' => 'xmldb',
|
||||
'numberincorrectdecimals' => 'xmldb',
|
||||
'floatincorrectdecimals' => 'xmldb',
|
||||
'enumvaluesincorrect' => 'xmldb',
|
||||
'wronglengthforenum' => 'xmldb',
|
||||
'defaultincorrect' => 'xmldb',
|
||||
'administration' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
if (!data_submitted('nomatch')) { ///Basic prevention
|
||||
error('Wrong action call');
|
||||
}
|
||||
|
||||
/// Get parameters
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
$tableparam = strtolower(required_param('table', PARAM_PATH));
|
||||
$fieldparam = strtolower(required_param('field', PARAM_PATH));
|
||||
$name = substr(trim(strtolower(optional_param('name', $fieldparam, PARAM_PATH))),0,30);
|
||||
|
||||
$comment = required_param('comment', PARAM_CLEAN);
|
||||
$comment = trim(stripslashes_safe($comment));
|
||||
|
||||
$type = required_param('type', PARAM_INT);
|
||||
$length = strtolower(optional_param('length', NULL, PARAM_ALPHANUM));
|
||||
$decimals = optional_param('decimals', NULL, PARAM_INT);
|
||||
$unsigned = optional_param('unsigned', false, PARAM_BOOL);
|
||||
$notnull = optional_param('notnull', false, PARAM_BOOL);
|
||||
$sequence = optional_param('sequence', false, PARAM_BOOL);
|
||||
$enum = optional_param('enum', false, PARAM_BOOL);
|
||||
$enumvalues = optional_param('enumvalues', 0, PARAM_CLEAN);
|
||||
$enumvalues = trim(stripslashes_safe($enumvalues));
|
||||
$default = optional_param('default', NULL, PARAM_PATH);
|
||||
$default = trim(stripslashes_safe($default));
|
||||
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$field =& $table->getField($fieldparam);
|
||||
$oldhash = $field->getHash();
|
||||
|
||||
$errors = array(); /// To store all the errors found
|
||||
|
||||
/// Perform some automatic asumptions
|
||||
if ($sequence) {
|
||||
$unsigned = true;
|
||||
$notnull = true;
|
||||
$enum = false;
|
||||
$default = NULL;
|
||||
}
|
||||
if ($type != XMLDB_TYPE_NUMBER && $type != XMLDB_TYPE_FLOAT) {
|
||||
$decimals = NULL;
|
||||
}
|
||||
if ($type != XMLDB_TYPE_CHAR && $type != XMLDB_TYPE_TEXT) {
|
||||
$enum = false;
|
||||
}
|
||||
if ($type == XMLDB_TYPE_BINARY) {
|
||||
$default = NULL;
|
||||
}
|
||||
if (!$enum) {
|
||||
$enumvalues = NULL;
|
||||
}
|
||||
if ($default === '') {
|
||||
$default = NULL;
|
||||
}
|
||||
|
||||
/// Perform some checks
|
||||
/// Check empty name
|
||||
if (empty($name)) {
|
||||
$errors[] = $this->str['fieldnameempty'];
|
||||
}
|
||||
/// Check incorrect name
|
||||
if ($name == 'changeme') {
|
||||
$errors[] = $this->str['incorrectfieldname'];
|
||||
}
|
||||
/// Check duplicate name
|
||||
if ($fieldparam != $name && $table->getField($name)) {
|
||||
$errors[] = $this->str['duplicatefieldname'];
|
||||
}
|
||||
/// Integer checks
|
||||
if ($type == XMLDB_TYPE_INTEGER) {
|
||||
if (!(is_numeric($length) && !empty($length) && intval($length)==floatval($length) &&
|
||||
$length > 0 && $length <= 20)) {
|
||||
$errors[] = $this->str['integerincorrectlength'];
|
||||
}
|
||||
if (!(empty($default) || (is_numeric($default) &&
|
||||
!empty($default) &&
|
||||
intval($default)==floatval($default)))) {
|
||||
$errors[] = $this->str['defaultincorrect'];
|
||||
}
|
||||
}
|
||||
/// Number checks
|
||||
if ($type == XMLDB_TYPE_NUMBER) {
|
||||
if (!(is_numeric($length) && !empty($length) && intval($length)==floatval($length) &&
|
||||
$length > 0 && $length <= 20)) {
|
||||
$errors[] = $this->str['numberincorrectlength'];
|
||||
}
|
||||
if (!(empty($decimals) || (is_numeric($decimals) &&
|
||||
!empty($decimals) &&
|
||||
intval($decimals)==floatval($decimals) &&
|
||||
$decimals >= 0 &&
|
||||
$decimals < $length))) {
|
||||
$errors[] = $this->str['numberincorrectdecimals'];
|
||||
}
|
||||
if (!(empty($default) || (is_numeric($default) &&
|
||||
!empty($default)))) {
|
||||
$errors[] = $this->str['defaultincorrect'];
|
||||
}
|
||||
}
|
||||
/// Float checks
|
||||
if ($type == XMLDB_TYPE_FLOAT) {
|
||||
if (!(empty($length) || (is_numeric($length) &&
|
||||
!empty($length) &&
|
||||
intval($length)==floatval($length) &&
|
||||
$length > 0 &&
|
||||
$length <= 20))) {
|
||||
$errors[] = $this->str['floatincorrectlength'];
|
||||
}
|
||||
if (!(empty($decimals) || (is_numeric($decimals) &&
|
||||
!empty($decimals) &&
|
||||
intval($decimals)==floatval($decimals) &&
|
||||
$decimals >= 0 &&
|
||||
$decimals < $length))) {
|
||||
$errors[] = $this->str['floatincorrectdecimals'];
|
||||
}
|
||||
if (!(empty($default) || (is_numeric($default) &&
|
||||
!empty($default)))) {
|
||||
$errors[] = $this->str['defaultincorrect'];
|
||||
}
|
||||
}
|
||||
/// Char checks
|
||||
if ($type == XMLDB_TYPE_CHAR) {
|
||||
if (!(is_numeric($length) && !empty($length) && intval($length)==floatval($length) &&
|
||||
$length > 0 && $length <= 255)) {
|
||||
$errors[] = $this->str['charincorrectlength'];
|
||||
}
|
||||
if ($default !== NULL && $default !== '') {
|
||||
if (substr($default, 0, 1) == "'" ||
|
||||
substr($default, -1, 1) == "'") {
|
||||
$errors[] = $this->str['defaultincorrect'];
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Text checks
|
||||
if ($type == XMLDB_TYPE_TEXT) {
|
||||
if ($length != 'small' &&
|
||||
$length != 'medium' &&
|
||||
$length != 'big') {
|
||||
$errors[] = $this->str['textincorrectlength'];
|
||||
}
|
||||
if ($default !== NULL && $default !== '') {
|
||||
if (substr($default, 0, 1) == "'" ||
|
||||
substr($default, -1, 1) == "'") {
|
||||
$errors[] = $this->str['defaultincorrect'];
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Binary checks
|
||||
if ($type == XMLDB_TYPE_BINARY) {
|
||||
if ($length != 'small' &&
|
||||
$length != 'medium' &&
|
||||
$length != 'big') {
|
||||
$errors[] = $this->str['binaryincorrectlength'];
|
||||
}
|
||||
}
|
||||
/// Enum checks
|
||||
if ($enum) {
|
||||
$enumerr = false;
|
||||
$enumarr = explode(',',$enumvalues);
|
||||
$maxlength = 0;
|
||||
if ($enumarr) {
|
||||
foreach ($enumarr as $key => $enumelement) {
|
||||
/// Clear some spaces
|
||||
$enumarr[$key] = trim($enumelement);
|
||||
$enumelement = trim($enumelement);
|
||||
/// Calculate needed length
|
||||
$le = strlen(str_replace("'", '', $enumelement));
|
||||
if ($le > $maxlength) {
|
||||
$maxlength = $le;
|
||||
}
|
||||
/// Skip if under error
|
||||
if ($enumerr) {
|
||||
continue;
|
||||
}
|
||||
/// Look for quoted strings
|
||||
if (substr($enumelement, 0, 1) != "'" ||
|
||||
substr($enumelement, -1, 1) != "'") {
|
||||
$enumerr = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$enumerr = true;
|
||||
}
|
||||
if ($enumerr) {
|
||||
$errors[] = $this->str['enumvaluesincorrect'];
|
||||
} else {
|
||||
$enumvalues = $enumarr;
|
||||
}
|
||||
if ($length < $maxlength) {
|
||||
$errors[] = $this->str['wronglengthforenum'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$tempfield = new XMLDBField($name);
|
||||
$tempfield->setType($type);
|
||||
$tempfield->setLength($length);
|
||||
$tempfield->setDecimals($decimals);
|
||||
$tempfield->setUnsigned($unsigned);
|
||||
$tempfield->setNotNull($notnull);
|
||||
$tempfield->setSequence($sequence);
|
||||
$tempfield->setEnum($enum);
|
||||
$tempfield->setEnumValues($enumvalues);
|
||||
$tempfield->setDefault($default);
|
||||
/// Prepare the output
|
||||
$site = get_site();
|
||||
print_header("$site->shortname: XMLDB",
|
||||
"$site->fullname",
|
||||
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||
notice ('<p>' .implode(', ', $errors) . '</p>
|
||||
<p>' . $tempfield->readableInfo(),
|
||||
'index.php?action=edit_field&field=' .$field->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
|
||||
die; /// re-die :-P
|
||||
}
|
||||
|
||||
/// Continue if we aren't under errors
|
||||
if (empty($errors)) {
|
||||
/// If there is one name change, do it, changing the prev and next
|
||||
/// atributes of the adjacent fields
|
||||
if ($fieldparam != $name) {
|
||||
$field->setName($name);
|
||||
if ($field->getPrevious()) {
|
||||
$prev =& $table->getField($field->getPrevious());
|
||||
$prev->setNext($name);
|
||||
$prev->setChanged(true);
|
||||
}
|
||||
if ($field->getNext()) {
|
||||
$next =& $table->getField($field->getNext());
|
||||
$next->setPrevious($name);
|
||||
$next->setChanged(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Set comment
|
||||
$field->setComment($comment);
|
||||
|
||||
/// Set the rest of fields
|
||||
$field->setType($type);
|
||||
$field->setLength($length);
|
||||
$field->setDecimals($decimals);
|
||||
$field->setUnsigned($unsigned);
|
||||
$field->setNotNull($notnull);
|
||||
$field->setSequence($sequence);
|
||||
$field->setEnum($enum);
|
||||
$field->setEnumValues($enumvalues);
|
||||
$field->setDefault($default);
|
||||
|
||||
/// If the hash has changed from the old one, change the version
|
||||
/// and mark the structure as changed
|
||||
$field->calculateHash(true);
|
||||
if ($oldhash != $field->getHash()) {
|
||||
$field->setChanged(true);
|
||||
$table->setChanged(true);
|
||||
/// Recalculate the structure hash
|
||||
$structure->calculateHash(true);
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
/// Mark as changed
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,159 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will provide the interface for all the edit index actions
|
||||
|
||||
class edit_index extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'xmldb',
|
||||
'vieworiginal' => 'xmldb',
|
||||
'viewedited' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => '',
|
||||
'back' => 'xmldb'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
/// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// Fetch request data
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
if (!$table =& $structure->getTable($tableparam)) {
|
||||
$this->errormsg = 'Wrong table specified: ' . $tableparm;
|
||||
return false;
|
||||
}
|
||||
$indexparam = required_param('index', PARAM_CLEAN);
|
||||
if (!$index =& $table->getIndex($indexparam)) {
|
||||
/// Arriving here from a name change, looking for the new key name
|
||||
$indexparam = required_param('name', PARAM_CLEAN);
|
||||
$index =& $table->getIndex($indexparam);
|
||||
}
|
||||
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
|
||||
/// Add the main form
|
||||
$o = '<form name="form" id="form" action="index.php" method="post">';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
$o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="index" value="' . $indexparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_index_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||
$o.= ' <table id="formelements" align="center">';
|
||||
/// XMLDB index name
|
||||
/// If the index has dependencies, we cannot change its name
|
||||
$disabled = '';
|
||||
if ($structure->getIndexUses($table->getName(), $index->getName())) {
|
||||
$disabled = ' disabled="disabled " ';
|
||||
}
|
||||
$o.= ' <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="30" id="name"' . $disabled . 'value="' . s($index->getName()) . '" /></td></tr>';
|
||||
/// XMLDB key comment
|
||||
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td colspan="2"><textarea name="comment" rows="3" cols="80" id="comment">' . s($index->getComment()) . '</textarea></td></tr>';
|
||||
/// XMLDBIndex Type
|
||||
$typeoptions = array (0 => 'not unique',
|
||||
1 => 'unique');
|
||||
$o.= ' <tr valign="top"><td><label for="menuunique" accesskey="t">Type:</label></td>';
|
||||
$o.= ' <td colspan="2">' . choose_from_menu($typeoptions, 'unique', $index->getUnique(), '', '', '', true) . '</td></tr>';
|
||||
/// XMLDBIndex Fields
|
||||
$o.= ' <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $index->getFields())) . '" /></td></tr>';
|
||||
/// Change button
|
||||
$o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</form>';
|
||||
/// Calculate the buttons
|
||||
$b = ' <p align="center" class="buttons">';
|
||||
/// The view original XML button
|
||||
if ($table->getIndex($indexparam)) {
|
||||
$b .= ' <a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&table=' . $tableparam . '&index=' . $indexparam . '" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||
}
|
||||
/// The view edited XML button
|
||||
if ($index->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_index_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&table=' . $tableparam . '&index=' . $indexparam . '" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The back to edit table button
|
||||
$b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $b;
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,224 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will save the changes performed to one index
|
||||
|
||||
class edit_index_save extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'indexnameempty' => 'xmldb',
|
||||
'incorrectindexname' => 'xmldb',
|
||||
'duplicateindexname' => 'xmldb',
|
||||
'nofieldsspecified' => 'xmldb',
|
||||
'duplicatefieldsused' => 'xmldb',
|
||||
'fieldsnotintable' => 'xmldb',
|
||||
'fieldsusedinkey' => 'xmldb',
|
||||
'fieldsusedinindex' => 'xmldb',
|
||||
'administration' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
if (!data_submitted('nomatch')) { ///Basic prevention
|
||||
error('Wrong action call');
|
||||
}
|
||||
|
||||
/// Get parameters
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
$tableparam = strtolower(required_param('table', PARAM_PATH));
|
||||
$indexparam = strtolower(required_param('index', PARAM_PATH));
|
||||
$name = trim(strtolower(optional_param('name', $indexparam, PARAM_PATH)));
|
||||
|
||||
$comment = required_param('comment', PARAM_CLEAN);
|
||||
$comment = trim(stripslashes_safe($comment));
|
||||
|
||||
$unique = required_param('unique', PARAM_INT);
|
||||
$fields = required_param('fields', PARAM_CLEAN);
|
||||
$fields = str_replace(' ', '', trim(strtolower(stripslashes_safe($fields))));
|
||||
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$index =& $table->getIndex($indexparam);
|
||||
$oldhash = $index->getHash();
|
||||
|
||||
$errors = array(); /// To store all the errors found
|
||||
|
||||
/// Perform some checks
|
||||
/// Check empty name
|
||||
if (empty($name)) {
|
||||
$errors[] = $this->str['indexnameempty'];
|
||||
}
|
||||
/// Check incorrect name
|
||||
if ($name == 'changeme') {
|
||||
$errors[] = $this->str['incorrectindexname'];
|
||||
}
|
||||
/// Check duplicate name
|
||||
if ($indexparam != $name && $table->getIndex($name)) {
|
||||
$errors[] = $this->str['duplicateindexname'];
|
||||
}
|
||||
$fieldsarr = explode(',', $fields);
|
||||
/// Check the fields isn't empty
|
||||
if (empty($fieldsarr[0])) {
|
||||
$errors[] = $this->str['nofieldsspecified'];
|
||||
} else {
|
||||
/// Check that there aren't duplicate column names
|
||||
$uniquearr = array_unique($fieldsarr);
|
||||
if (count($fieldsarr) != count($uniquearr)) {
|
||||
$errors[] = $this->str['duplicatefieldsused'];
|
||||
}
|
||||
/// Check that all the fields in belong to the table
|
||||
foreach ($fieldsarr as $field) {
|
||||
if (!$table->getField($field)) {
|
||||
$errors[] = $this->str['fieldsnotintable'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// Check that there isn't any key using exactly the same fields
|
||||
$tablekeys = $table->getKeys();
|
||||
if ($tablekeys) {
|
||||
foreach ($tablekeys as $tablekey) {
|
||||
$keyfieldsarr = $tablekey->getFields();
|
||||
/// Compare both arrays, looking for diferences
|
||||
$diferences = array_merge(array_diff($fieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $fieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$errors[] = $this->str['fieldsusedinkey'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Check that there isn't any index using exactlt the same fields
|
||||
$tableindexes = $table->getIndexes();
|
||||
if ($tableindexes) {
|
||||
foreach ($tableindexes as $tableindex) {
|
||||
/// Skip checking against itself
|
||||
if ($indexparam == $tableindex->getName()) {
|
||||
continue;
|
||||
}
|
||||
$indexfieldsarr = $tableindex->getFields();
|
||||
/// Compare both arrays, looking for diferences
|
||||
$diferences = array_merge(array_diff($fieldsarr, $indexfieldsarr), array_diff($indexfieldsarr, $fieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$errors[] = $this->str['fieldsusedinindex'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$tempindex = new XMLDBIndex($name);
|
||||
$tempindex->setUnique($unique);
|
||||
$tempindex->setFields($fieldsarr);
|
||||
/// Prepare the output
|
||||
$site = get_site();
|
||||
print_header("$site->shortname: XMLDB",
|
||||
"$site->fullname",
|
||||
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||
notice ('<p>' .implode(', ', $errors) . '</p>
|
||||
<p>' . $tempindex->readableInfo(),
|
||||
'index.php?action=edit_index&index=' .$index->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
|
||||
die; /// re-die :-P
|
||||
}
|
||||
|
||||
/// Continue if we aren't under errors
|
||||
if (empty($errors)) {
|
||||
/// If there is one name change, do it, changing the prev and next
|
||||
/// atributes of the adjacent fields
|
||||
if ($indexparam != $name) {
|
||||
$index->setName($name);
|
||||
if ($index->getPrevious()) {
|
||||
$prev =& $table->getIndex($index->getPrevious());
|
||||
$prev->setNext($name);
|
||||
$prev->setChanged(true);
|
||||
}
|
||||
if ($index->getNext()) {
|
||||
$next =& $table->getIndex($index->getNext());
|
||||
$next->setPrevious($name);
|
||||
$next->setChanged(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Set comment
|
||||
$index->setComment($comment);
|
||||
|
||||
/// Set the rest of fields
|
||||
$index->setUnique($unique);
|
||||
$index->setFields($fieldsarr);
|
||||
|
||||
/// If the hash has changed from the old one, change the version
|
||||
/// and mark the structure as changed
|
||||
$index->calculateHash(true);
|
||||
if ($oldhash != $index->getHash()) {
|
||||
$index->setChanged(true);
|
||||
$table->setChanged(true);
|
||||
/// Recalculate the structure hash
|
||||
$structure->calculateHash(true);
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
/// Mark as changed
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,171 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will provide the interface for all the edit key actions
|
||||
|
||||
class edit_key extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'xmldb',
|
||||
'vieworiginal' => 'xmldb',
|
||||
'viewedited' => 'xmldb',
|
||||
'yes' => '',
|
||||
'no' => '',
|
||||
'back' => 'xmldb'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
/// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// Fetch request data
|
||||
$tableparam = required_param('table', PARAM_CLEAN);
|
||||
if (!$table =& $structure->getTable($tableparam)) {
|
||||
$this->errormsg = 'Wrong table specified: ' . $tableparm;
|
||||
return false;
|
||||
}
|
||||
$keyparam = required_param('key', PARAM_CLEAN);
|
||||
if (!$key =& $table->getKey($keyparam)) {
|
||||
/// Arriving here from a name change, looking for the new key name
|
||||
$keyparam = required_param('name', PARAM_CLEAN);
|
||||
$key =& $table->getKey($keyparam);
|
||||
}
|
||||
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
|
||||
/// Add the main form
|
||||
$o = '<form name="form" id="form" action="index.php" method="post">';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
$o.= ' <input type="hidden" name ="table" value="' . $tableparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="key" value="' . $keyparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_key_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_table" />';
|
||||
$o.= ' <table id="formelements" align="center">';
|
||||
/// XMLDB key name
|
||||
/// If the key has dependencies, we cannot change its name
|
||||
$disabled = '';
|
||||
if ($structure->getKeyUses($table->getName(), $key->getName())) {
|
||||
$disabled = ' disabled="disabled " ';
|
||||
}
|
||||
$o.= ' <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="30" id="name"' . $disabled . 'value="' . s($key->getName()) . '" /></td></tr>';
|
||||
/// XMLDB key comment
|
||||
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td colspan="2"><textarea name="comment" rows="3" cols="80" id="comment">' . s($key->getComment()) . '</textarea></td></tr>';
|
||||
/// XMLDBKey Type
|
||||
$typeoptions = array (XMLDB_KEY_PRIMARY => $key->getXMLDBKeyName(XMLDB_KEY_PRIMARY),
|
||||
XMLDB_KEY_UNIQUE => $key->getXMLDBKeyName(XMLDB_KEY_UNIQUE),
|
||||
XMLDB_KEY_FOREIGN => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN),
|
||||
XMLDB_KEY_FOREIGN_UNIQUE => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN_UNIQUE));
|
||||
/// Only show the XMLDB_KEY_FOREIGN_UNIQUE if the Key has that type
|
||||
/// if ($key->getType() != XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||
/// unset ($typeoptions[XMLDB_KEY_FOREIGN_UNIQUE);
|
||||
/// }
|
||||
$o.= ' <tr valign="top"><td><label for="menutype" accesskey="t">Type:</label></td>';
|
||||
$o.= ' <td colspan="2">' . choose_from_menu($typeoptions, 'type', $key->getType(), '', '', '', true) . '</td></tr>';
|
||||
/// XMLDBKey Fields
|
||||
$o.= ' <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $key->getFields())) . '" /></td></tr>';
|
||||
/// XMLDBKey Reftable
|
||||
$o.= ' <tr valign="top"><td><label for="reftable" accesskey="t">Reftable:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="reftable" type="text" size="20" maxlength="40" id="reftable" value="' . s($key->getReftable()) . '" /></td></tr>';
|
||||
/// XMLDBKey Reffields
|
||||
$o.= ' <tr valign="top"><td><label for="reffields" accesskey="t">Reffields:</label></td>';
|
||||
$o.= ' <td colspan="2"><input name="reffields" type="text" size="40" maxlength="80" id="reffields" value="' . s(implode(', ', $key->getRefFields())) . '" /></td></tr>';
|
||||
/// Change button
|
||||
$o.= ' <tr valign="top"><td> </td><td colspan="2"><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</form>';
|
||||
/// Calculate the buttons
|
||||
$b = ' <p align="center" class="buttons">';
|
||||
/// The view original XML button
|
||||
if ($table->getKey($keyparam)) {
|
||||
$b .= ' <a href="index.php?action=view_key_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&table=' . $tableparam . '&key=' . $keyparam . '" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||
}
|
||||
/// The view edited XML button
|
||||
if ($key->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_key_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&table=' . $tableparam . '&key=' . $keyparam . '" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The back to edit table button
|
||||
$b .= ' <a href="index.php?action=edit_table&table=' . $tableparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $b;
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,77 +0,0 @@
|
||||
/// $Id $
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/// Register the needed events
|
||||
|
||||
onload=function() {
|
||||
/// Adjust the form on load
|
||||
transformForm();
|
||||
|
||||
/// Get the required fields
|
||||
var typeField = document.getElementById('menutype');
|
||||
|
||||
/// Register the rest of events
|
||||
if (typeField.addEventListener) {
|
||||
/// Standard
|
||||
typeField.addEventListener('change', transformForm, false);
|
||||
} else {
|
||||
/// IE 5.5
|
||||
typeField.attachEvent('onchange', transformForm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function controls all modifications to perform when any field changes
|
||||
*/
|
||||
function transformForm(event) {
|
||||
|
||||
/// Initialize all the needed variables
|
||||
var typeField = document.getElementById('menutype');
|
||||
var fieldsField = document.getElementById('fields');
|
||||
var reftableField = document.getElementById('reftable');
|
||||
var reffieldsField = document.getElementById('reffields');
|
||||
|
||||
/// Initially, enable everything
|
||||
typeField.disabled = false;
|
||||
fieldsField.disabled = false;
|
||||
reftableField.disabled = false;
|
||||
reffieldsField.disabled = false;
|
||||
|
||||
/// Based on type, disable some items
|
||||
switch (typeField.value) {
|
||||
case '1': // XMLDB_KEY_PRIMARY
|
||||
case '2': // XMLDB_KEY_UNIQUE
|
||||
reftableField.disabled = true;
|
||||
reftableField.value = '';
|
||||
reffieldsField.disabled = true;
|
||||
reffieldsField.value = '';
|
||||
break;
|
||||
case '3': // XMLDB_KEY_FOREIGN
|
||||
case '5': // XMLDB_KEY_FOREIGN_UNIQUE
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,305 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will save the changes performed to one key
|
||||
|
||||
class edit_key_save extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'keynameempty' => 'xmldb',
|
||||
'incorrectkeyname' => 'xmldb',
|
||||
'duplicatekeyname' => 'xmldb',
|
||||
'nofieldsspecified' => 'xmldb',
|
||||
'duplicatefieldsused' => 'xmldb',
|
||||
'fieldsnotintable' => 'xmldb',
|
||||
'fieldsusedinkey' => 'xmldb',
|
||||
'fieldsusedinindex' => 'xmldb',
|
||||
'noreftablespecified' => 'xmldb',
|
||||
'wrongnumberofreffields' => 'xmldb',
|
||||
'noreffieldsspecified' => 'xmldb',
|
||||
'nomasterprimaryuniquefound' => 'xmldb',
|
||||
'masterprimaryuniqueordernomatch' => 'xmldb',
|
||||
'primarykeyonlyallownotnullfields' => 'xmldb',
|
||||
'administration' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
if (!data_submitted('nomatch')) { ///Basic prevention
|
||||
error('Wrong action call');
|
||||
}
|
||||
|
||||
/// Get parameters
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
$tableparam = strtolower(required_param('table', PARAM_PATH));
|
||||
$keyparam = strtolower(required_param('key', PARAM_PATH));
|
||||
$name = trim(strtolower(optional_param('name', $keyparam, PARAM_PATH)));
|
||||
|
||||
$comment = required_param('comment', PARAM_CLEAN);
|
||||
$comment = trim(stripslashes_safe($comment));
|
||||
|
||||
$type = required_param('type', PARAM_INT);
|
||||
$fields = required_param('fields', PARAM_CLEAN);
|
||||
$fields = str_replace(' ', '', trim(strtolower(stripslashes_safe($fields))));
|
||||
|
||||
if ($type == XMLDB_KEY_FOREIGN ||
|
||||
$type == XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||
$reftable = trim(strtolower(required_param('reftable', PARAM_PATH)));
|
||||
$reffields= required_param('reffields', PARAM_CLEAN);
|
||||
$reffields = str_replace(' ', '', trim(strtolower(stripslashes_safe($reffields))));
|
||||
}
|
||||
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
$table =& $structure->getTable($tableparam);
|
||||
$key =& $table->getKey($keyparam);
|
||||
$oldhash = $key->getHash();
|
||||
|
||||
$errors = array(); /// To store all the errors found
|
||||
|
||||
/// Perform some checks
|
||||
/// Check empty name
|
||||
if (empty($name)) {
|
||||
$errors[] = $this->str['keynameempty'];
|
||||
}
|
||||
/// Check incorrect name
|
||||
if ($name == 'changeme') {
|
||||
$errors[] = $this->str['incorrectkeyname'];
|
||||
}
|
||||
/// Check duplicate name
|
||||
if ($keyparam != $name && $table->getKey($name)) {
|
||||
$errors[] = $this->str['duplicatekeyname'];
|
||||
}
|
||||
$fieldsarr = explode(',', $fields);
|
||||
/// Check the fields isn't empty
|
||||
if (empty($fieldsarr[0])) {
|
||||
$errors[] = $this->str['nofieldsspecified'];
|
||||
} else {
|
||||
/// Check that there aren't duplicate column names
|
||||
$uniquearr = array_unique($fieldsarr);
|
||||
if (count($fieldsarr) != count($uniquearr)) {
|
||||
$errors[] = $this->str['duplicatefieldsused'];
|
||||
}
|
||||
/// Check that all the fields in belong to the table
|
||||
foreach ($fieldsarr as $field) {
|
||||
if (!$table->getField($field)) {
|
||||
$errors[] = $this->str['fieldsnotintable'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// If primary, check that all the fields are not null
|
||||
if ($type == XMLDB_KEY_PRIMARY) {
|
||||
foreach ($fieldsarr as $field) {
|
||||
if ($fi = $table->getField($field)) {
|
||||
if (!$fi->getNotNull()) {
|
||||
$errors[] = $this->str['primarykeyonlyallownotnullfields'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Check that there isn't any key using exactly the same fields
|
||||
$tablekeys = $table->getKeys();
|
||||
if ($tablekeys) {
|
||||
foreach ($tablekeys as $tablekey) {
|
||||
/// Skip checking against itself
|
||||
if ($keyparam == $tablekey->getName()) {
|
||||
continue;
|
||||
}
|
||||
$keyfieldsarr = $tablekey->getFields();
|
||||
/// Compare both arrays, looking for diferences
|
||||
$diferences = array_merge(array_diff($fieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $fieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$errors[] = $this->str['fieldsusedinkey'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Check that there isn't any index using exactlt the same fields
|
||||
$tableindexes = $table->getIndexes();
|
||||
if ($tableindexes) {
|
||||
foreach ($tableindexes as $tableindex) {
|
||||
$indexfieldsarr = $tableindex->getFields();
|
||||
/// Compare both arrays, looking for diferences
|
||||
$diferences = array_merge(array_diff($fieldsarr, $indexfieldsarr), array_diff($indexfieldsarr, $fieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$errors[] = $this->str['fieldsusedinindex'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// If foreign key
|
||||
if ($type == XMLDB_KEY_FOREIGN ||
|
||||
$type == XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||
$reffieldsarr = explode(',', $reffields);
|
||||
/// Check reftable is not empty
|
||||
if (empty($reftable)) {
|
||||
$errors[] = $this->str['noreftablespecified'];
|
||||
} else
|
||||
/// Check reffields are not empty
|
||||
if (empty($reffieldsarr[0])) {
|
||||
$errors[] = $this->str['noreffieldsspecified'];
|
||||
} else
|
||||
/// Check the number of fields is correct
|
||||
if (count($fieldsarr) != count($reffieldsarr)) {
|
||||
$errors[] = $this->str['wrongnumberofreffields'];
|
||||
} else {
|
||||
/// Check, if pointing to one structure table, that there is one master key for this key
|
||||
if ($rt = $structure->getTable($reftable)) {
|
||||
$masterfound = false;
|
||||
$reftablekeys = $rt->getKeys();
|
||||
if ($reftablekeys) {
|
||||
foreach ($reftablekeys as $reftablekey) {
|
||||
/// Only compare with primary and unique keys
|
||||
if ($reftablekey->getType() != XMLDB_KEY_PRIMARY && $reftablekey->getType() != XMLDB_KEY_UNIQUE) {
|
||||
continue;
|
||||
}
|
||||
$keyfieldsarr = $reftablekey->getFields();
|
||||
/// Compare both arrays, looking for diferences
|
||||
$diferences = array_merge(array_diff($reffieldsarr, $keyfieldsarr), array_diff($keyfieldsarr, $reffieldsarr));
|
||||
if (empty($diferences)) {
|
||||
$masterfound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$masterfound) {
|
||||
$errors[] = $this->str['nomasterprimaryuniquefound'];
|
||||
} else {
|
||||
/// Quick test of the order
|
||||
if (implode(',', $reffieldsarr) != implode(',', $keyfieldsarr)) {
|
||||
$errors[] = $this->str['masterprimaryuniqueordernomatch'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($errors)) {
|
||||
$tempkey = new XMLDBKey($name);
|
||||
$tempkey->setType($type);
|
||||
$tempkey->setFields($fieldsarr);
|
||||
if ($type == XMLDB_KEY_FOREIGN ||
|
||||
$type == XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||
$tempkey->setRefTable($reftable);
|
||||
$tempkey->setRefFields($reffieldsarr);
|
||||
}
|
||||
/// Prepare the output
|
||||
$site = get_site();
|
||||
print_header("$site->shortname: XMLDB",
|
||||
"$site->fullname",
|
||||
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||
notice ('<p>' .implode(', ', $errors) . '</p>
|
||||
<p>' . $tempkey->readableInfo(),
|
||||
'index.php?action=edit_key&key=' .$key->getName() . '&table=' . $table->getName() . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
|
||||
die; /// re-die :-P
|
||||
}
|
||||
|
||||
/// Continue if we aren't under errors
|
||||
if (empty($errors)) {
|
||||
/// If there is one name change, do it, changing the prev and next
|
||||
/// atributes of the adjacent fields
|
||||
if ($keyparam != $name) {
|
||||
$key->setName($name);
|
||||
if ($key->getPrevious()) {
|
||||
$prev =& $table->getKey($key->getPrevious());
|
||||
$prev->setNext($name);
|
||||
$prev->setChanged(true);
|
||||
}
|
||||
if ($key->getNext()) {
|
||||
$next =& $table->getKey($key->getNext());
|
||||
$next->setPrevious($name);
|
||||
$next->setChanged(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// Set comment
|
||||
$key->setComment($comment);
|
||||
|
||||
/// Set the rest of fields
|
||||
$key->setType($type);
|
||||
$key->setFields($fieldsarr);
|
||||
if ($type == XMLDB_KEY_FOREIGN ||
|
||||
$type == XMLDB_KEY_FOREIGN_UNIQUE) {
|
||||
$key->setRefTable($reftable);
|
||||
$key->setRefFields($reffieldsarr);
|
||||
}
|
||||
|
||||
/// If the hash has changed from the old one, change the version
|
||||
/// and mark the structure as changed
|
||||
$key->calculateHash(true);
|
||||
if ($oldhash != $key->getHash()) {
|
||||
$key->setChanged(true);
|
||||
$table->setChanged(true);
|
||||
/// Recalculate the structure hash
|
||||
$structure->calculateHash(true);
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
/// Mark as changed
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,153 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will provide the interface for all the edit sentence actions
|
||||
|
||||
class edit_sentence extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'xmldb',
|
||||
'vieworiginal' => 'xmldb',
|
||||
'viewedited' => 'xmldb',
|
||||
'back' => 'xmldb'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
/// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
|
||||
/// ADD YOUR CODE HERE
|
||||
|
||||
/// Fetch request data
|
||||
$statementparam = required_param('statement', PARAM_CLEAN);
|
||||
$sentenceparam = optional_param('sentence', NULL, PARAM_CLEAN);
|
||||
|
||||
if (!$statement =& $structure->getStatement($statementparam)) {
|
||||
$this->errormsg = 'Wrong statement specified: ' . $statementparam;
|
||||
return false;
|
||||
}
|
||||
$sentences =& $statement->getSentences();
|
||||
|
||||
/// If no sentence has been specified, edit the last one
|
||||
if ($sentenceparam === NULL) {
|
||||
end($sentences);
|
||||
$sentenceparam = key($sentences);
|
||||
}
|
||||
|
||||
if (!$sentence =& $sentences[$sentenceparam]) {
|
||||
$this->errormsg = 'Wrong Sentence: ' . $sentenceparam;
|
||||
return false;
|
||||
}
|
||||
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
|
||||
/// Based in the type of statement, print different forms
|
||||
if ($statement->getType() != XMLDB_STATEMENT_INSERT) {
|
||||
/// Only INSERT is allowed!!
|
||||
$this->errormsg = 'Wrong Statement Type. Only INSERT allowed';
|
||||
return false;
|
||||
} else {
|
||||
/// Prepare INSERT sentence
|
||||
$fields = $statement->getFieldsFromInsertSentence($sentence);
|
||||
$values = $statement->getValuesFromInsertSentence($sentence);
|
||||
|
||||
/// Add the main form
|
||||
$o = '<form name="form" id="form" action="index.php" method="post">';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
$o.= ' <input type="hidden" name ="statement" value="' . $statementparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="sentence" value="' . $sentenceparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_sentence_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
|
||||
$o.= ' <table id="formelements" align="center">';
|
||||
/// The fields box
|
||||
$o.= ' <tr><td>INSERT INTO ' . s($statement->getTable()) . '</td></tr>';
|
||||
$o.= ' <tr><td><textarea name="fields" rows="2" cols="70" id="fields">' . s(implode(', ', $fields)) . '</textarea></td></tr>';
|
||||
/// The values box
|
||||
$o.= ' <tr><td>VALUES</td></tr>';
|
||||
$o.= ' <tr><td><textarea name="values" rows="2" cols="70" id="values">' . s(implode(', ', $values)) . '</textarea></td></tr>';
|
||||
/// The submit button
|
||||
$o.= ' <tr valign="top"><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</form>';
|
||||
/// Calculate the buttons
|
||||
$b = ' <p align="center" class="buttons">';
|
||||
/// The back to edit statement button
|
||||
$b .= ' <a href="index.php?action=edit_statement&statement=' . urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $b;
|
||||
|
||||
$this->output = $o;
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,155 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will save the changes performed to one sentence
|
||||
|
||||
class edit_sentence_save extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'cannotuseidfield' => 'xmldb',
|
||||
'missingfieldsinsentence' => 'xmldb',
|
||||
'missingvaluesinsentence' => 'xmldb',
|
||||
'wrongnumberoffieldsorvalues' => 'xmldb',
|
||||
'administration' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_NONE;
|
||||
//$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
|
||||
/// Get parameters
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
$statementparam = strtolower(required_param('statement', PARAM_CLEAN));
|
||||
$sentenceparam = strtolower(required_param('sentence', PARAM_ALPHANUM));
|
||||
|
||||
$fields = required_param('fields', PARAM_CLEAN);
|
||||
$fields = trim(stripslashes_safe($fields));
|
||||
$values = required_param('values', PARAM_CLEAN);
|
||||
$values = trim(stripslashes_safe($values));
|
||||
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
$statement =& $structure->getStatement($statementparam);
|
||||
$sentences =& $statement->getSentences();
|
||||
|
||||
$oldsentence = $sentences[$sentenceparam];
|
||||
|
||||
if (!$statement) {
|
||||
$this->errormsg = 'Wrong statement specified: ' . $statementparam;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// For now, only insert sentences are allowed
|
||||
if ($statement->getType() != XMLDB_STATEMENT_INSERT) {
|
||||
$this->errormsg = 'Wrong Statement Type. Only INSERT allowed';
|
||||
return false;
|
||||
}
|
||||
|
||||
$errors = array(); /// To store all the errors found
|
||||
|
||||
/// Build the whole sentence
|
||||
$sentence = '(' . $fields . ') VALUES (' . $values . ')';
|
||||
|
||||
/// Perform some checks
|
||||
$fields = $statement->getFieldsFromInsertSentence($sentence);
|
||||
$values = $statement->getValuesFromInsertSentence($sentence);
|
||||
|
||||
if (in_array('id', $fields)) {
|
||||
$errors[] = $this->str['cannotuseidfield'];
|
||||
}
|
||||
if ($result && count($fields) == 0) {
|
||||
$errors[] = $this->str['missingfieldsinsentence'];
|
||||
}
|
||||
if ($result && count($values) == 0) {
|
||||
$errors[] = $this->str['missingvaluesinsentence'];
|
||||
}
|
||||
if ($result && count($fields) != count($values)) {
|
||||
$errors[] = $this->str['wrongnumberoffieldsorvalues'];
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
/// Prepare the output
|
||||
$site = get_site();
|
||||
print_header("$site->shortname: XMLDB",
|
||||
"$site->fullname",
|
||||
"<a href=\"../index.php\">" . $this->str['administration'] . "</a> -> <a href=\"index.php\">XMLDB</a>");
|
||||
notice ('<p>' .implode(', ', $errors) . '</p>
|
||||
<p>' . s($sentence),
|
||||
'index.php?action=edit_sentence&sentence=' .$sentenceparam . '&statement=' . urlencode($statementparam) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)));
|
||||
die; /// re-die :-P
|
||||
}
|
||||
|
||||
/// Continue if we aren't under errors
|
||||
if (empty($errors)) {
|
||||
$sentences[$sentenceparam] = $sentence;
|
||||
|
||||
/// If the sentence has changed from the old one, change the version
|
||||
/// and mark the statement and structure as changed
|
||||
if ($oldsentence != $sentence) {
|
||||
$statement->setChanged(true);
|
||||
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
|
||||
/// Mark as changed
|
||||
$structure->setChanged(true);
|
||||
}
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,182 +0,0 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
|
||||
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// This class will provide the interface for all the edit statement actions
|
||||
|
||||
class edit_statement extends XMLDBAction {
|
||||
|
||||
/**
|
||||
* Init method, every subclass will have its own
|
||||
*/
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
/// Set own custom attributes
|
||||
|
||||
/// Get needed strings
|
||||
$this->loadStrings(array(
|
||||
'change' => 'xmldb',
|
||||
'vieworiginal' => 'xmldb',
|
||||
'viewedited' => 'xmldb',
|
||||
'newsentence' => 'xmldb',
|
||||
'sentences' => 'xmldb',
|
||||
'edit' => 'xmldb',
|
||||
'delete' => 'xmldb',
|
||||
'duplicate' => 'xmldb',
|
||||
'back' => 'xmldb'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke method, every class will have its own
|
||||
* returns true/false on completion, setting both
|
||||
* errormsg and output as necessary
|
||||
*/
|
||||
function invoke() {
|
||||
parent::invoke();
|
||||
|
||||
$result = true;
|
||||
|
||||
/// Set own core attributes
|
||||
$this->does_generate = ACTION_GENERATE_HTML;
|
||||
|
||||
/// These are always here
|
||||
global $CFG, $XMLDB;
|
||||
|
||||
/// Do the job, setting result as needed
|
||||
/// Get the dir containing the file
|
||||
$dirpath = required_param('dir', PARAM_PATH);
|
||||
$dirpath = $CFG->dirroot . stripslashes_safe($dirpath);
|
||||
|
||||
/// Get the correct dirs
|
||||
if (!empty($XMLDB->dbdirs)) {
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (!empty($XMLDB->editeddirs)) {
|
||||
$editeddir =& $XMLDB->editeddirs[$dirpath];
|
||||
$structure =& $editeddir->xml_file->getStructure();
|
||||
}
|
||||
|
||||
/// ADD YOUR CODE HERE
|
||||
$statementparam = optional_param('statement', NULL, PARAM_CLEAN);
|
||||
/// If no statement, then we are coming for a new one. Look for
|
||||
/// type and table and build the correct statementparam
|
||||
if (!$statementparam) {
|
||||
$typeparam = optional_param('type', NULL, PARAM_CLEAN);
|
||||
$tableparam = optional_param('table', NULL, PARAM_CLEAN);
|
||||
$typename = XMLDBStatement::getXMLDBStatementName($typeparam);
|
||||
$statementparam = trim(strtolower($typename . ' ' . $tableparam));
|
||||
}
|
||||
if (!$statement =& $structure->getStatement($statementparam)) {
|
||||
/// Arriving here from a name change, looking for the new statement name
|
||||
$statementname = required_param('name', PARAM_CLEAN);
|
||||
$statement =& $structure->getStatement($statementparam);
|
||||
}
|
||||
|
||||
$dbdir =& $XMLDB->dbdirs[$dirpath];
|
||||
$origstructure =& $dbdir->xml_file->getStructure();
|
||||
|
||||
/// Add the main form
|
||||
$o = '<form id="form" action="index.php" method="post">';
|
||||
$o.= ' <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
|
||||
$o.= ' <input type="hidden" name ="statement" value="' . $statementparam .'" />';
|
||||
$o.= ' <input type="hidden" name ="action" value="edit_statement_save" />';
|
||||
$o.= ' <input type="hidden" name ="postaction" value="edit_statement" />';
|
||||
$o.= ' <table id="formelements" align="center">';
|
||||
$o.= ' <tr valign="top"><td>Name:</td><td><input type="hidden" name ="name" value="' . s($statement->getName()) . '" />' . s($statement->getName()) .'</td></tr>';
|
||||
$o.= ' <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td><textarea name="comment" rows="3" cols="80" id="comment">' . s($statement->getComment()) . '</textarea></td></tr>';
|
||||
$o.= ' <tr valign="top"><td> </td><td><input type="submit" value="' .$this->str['change'] . '" /></td></tr>';
|
||||
$o.= ' </table>';
|
||||
$o.= '</form>';
|
||||
/// Calculate the buttons
|
||||
$b = ' <p align="center" class="buttons">';
|
||||
/// The view original XML button
|
||||
if ($origstructure->getStatement($statementparam)) {
|
||||
$b .= ' <a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=original&statement=' . $statementparam . '" target="_blank">[' . $this->str['vieworiginal'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['vieworiginal'] . ']';
|
||||
}
|
||||
/// The view edited XML button
|
||||
if ($statement->hasChanged()) {
|
||||
$b .= ' <a href="index.php?action=view_statement_xml&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&select=edited&statement=' . $statementparam . '" target="_blank">[' . $this->str['viewedited'] . ']</a>';
|
||||
} else {
|
||||
$b .= ' [' . $this->str['viewedited'] . ']';
|
||||
}
|
||||
/// The new sentence button
|
||||
$b .= ' <a href="index.php?action=new_sentence&postaction=edit_sentence&statement=' . $statementparam . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['newsentence'] . ']</a>';
|
||||
/// The back to edit xml file button
|
||||
$b .= ' <a href="index.php?action=edit_xml_file&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
|
||||
$b .= '</p>';
|
||||
$o .= $b;
|
||||
|
||||
/// Delete any 'changeme' sentence
|
||||
///$statement->deleteSentence('changeme');
|
||||
|
||||
/// Add the fields list
|
||||
$sentences =& $statement->getSentences();
|
||||
if (!empty($sentences)) {
|
||||
$o .= '<h3 class="main">' . $this->str['sentences'] . '</h3>';
|
||||
$o .= '<table id="listfields" border="0" align="center" cellpadding="5" cellspacing="1" class="flexible">';
|
||||
$row = 0;
|
||||
foreach ($sentences as $key => $sentence) {
|
||||
/// Prepend some SQL
|
||||
if ($statement->getType() == XMLDB_STATEMENT_INSERT) {
|
||||
$p = 'INSERT INTO ' . $statement->getTable() . ' ';
|
||||
} else {
|
||||
$p = 'UNSUPPORTED SENTENCE TYPE ';
|
||||
}
|
||||
/// Calculate buttons
|
||||
$b = '</td><td class="button cell">';
|
||||
/// The edit button
|
||||
$b .= '<a href="index.php?action=edit_sentence&sentence=' .$key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['edit'] . ']</a>';
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The duplicate button
|
||||
$b .= '<a href="index.php?action=new_sentence&postaction=edit_sentence&basesentence=' . $key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['duplicate'] . ']</a>';
|
||||
$b .= '</td><td class="button cell">';
|
||||
/// The delete button
|
||||
$b .= '<a href="index.php?action=delete_sentence&sentence=' . $key . '&statement=' . urlencode($statement->getName()) . '&dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['delete'] . ']</a>';
|
||||
$b .= '</td>';
|
||||
/// Print table row
|
||||
$o .= '<tr class="r' . $row . '"><td class="table cell">' . $p . $sentence . $b . '</tr>';
|
||||
$row = ($row + 1) % 2;
|
||||
}
|
||||
$o .= '</table>';
|
||||
}
|
||||
|
||||
$this->output = $o;
|
||||
|
||||
/// Launch postaction if exists (leave this here!)
|
||||
if ($this->getPostAction() && $result) {
|
||||
return $this->launch($this->getPostAction());
|
||||
}
|
||||
|
||||
/// Return ok if arrived here
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user