]> git.mjollnir.org Git - moodle.git/log
moodle.git
18 years agoAdded new function function fetch_context_independent_capabilities(). Modified fetch_...
vyshane [Wed, 20 Sep 2006 08:30:49 +0000 (08:30 +0000)]
Added new function function fetch_context_independent_capabilities(). Modified fetch_context_capabilities() to use the former.

Fixed get_roles_used_in_context() sql query. r.sortorder must be selected if it is to be used in an ORDER BY clause.

18 years agoMore capability name typos.
tjhunt [Wed, 20 Sep 2006 08:01:59 +0000 (08:01 +0000)]
More capability name typos.

18 years ago'updated CSS for the breadcrumb and calendar arrows'
urs_hunkler [Wed, 20 Sep 2006 07:40:55 +0000 (07:40 +0000)]
'updated CSS for the breadcrumb and calendar arrows'

18 years agomostly removed old isadmin() calls
skodak [Wed, 20 Sep 2006 06:59:32 +0000 (06:59 +0000)]
mostly removed old isadmin() calls

18 years agoRemoved some obsolete stuff
moodler [Wed, 20 Sep 2006 06:52:54 +0000 (06:52 +0000)]
Removed some obsolete stuff

18 years agorole_context_capabilities should handle current context too and role override simply...
skodak [Wed, 20 Sep 2006 06:24:55 +0000 (06:24 +0000)]
role_context_capabilities should handle current context too and role override simply use parent context

18 years agoadmin page cleanup -- added missing strings
vinkmar [Wed, 20 Sep 2006 04:48:39 +0000 (04:48 +0000)]
admin page cleanup -- added missing strings

18 years agoadmin page cleanup - added most missing strings
vinkmar [Wed, 20 Sep 2006 04:47:57 +0000 (04:47 +0000)]
admin page cleanup - added most missing strings

18 years agoAdded more overrides during restore process for forums from 1.6. Plus some bug fixes.
vyshane [Wed, 20 Sep 2006 02:59:43 +0000 (02:59 +0000)]
Added more overrides during restore process for forums from 1.6. Plus some bug fixes.

18 years agoAutomatic installer.php lang files by installer_builder (20060920)
moodler [Wed, 20 Sep 2006 02:59:20 +0000 (02:59 +0000)]
Automatic installer.php lang files by installer_builder (20060920)

18 years agoFixed notice
vyshane [Wed, 20 Sep 2006 02:47:57 +0000 (02:47 +0000)]
Fixed notice

18 years agoFIxed a bug where $context had not been defined in enrol_into_course
moodler [Wed, 20 Sep 2006 02:19:08 +0000 (02:19 +0000)]
FIxed a bug where $context had not been defined in enrol_into_course

18 years agoAdded unset_config as a companion to set_config
moodler [Wed, 20 Sep 2006 02:17:27 +0000 (02:17 +0000)]
Added unset_config as a companion to set_config

18 years agoMade the debugging message a bit less passive
moodler [Wed, 20 Sep 2006 01:52:49 +0000 (01:52 +0000)]
Made the debugging message a bit less passive

18 years agoAnd another typo in capability name.
tjhunt [Tue, 19 Sep 2006 22:58:12 +0000 (22:58 +0000)]
And another typo in capability name.

18 years agoAnother typo in capability name.
tjhunt [Tue, 19 Sep 2006 22:57:38 +0000 (22:57 +0000)]
Another typo in capability name.

18 years agoIn debug mode, warn people if they are asking for an unknown capability.
tjhunt [Tue, 19 Sep 2006 22:57:17 +0000 (22:57 +0000)]
In debug mode, warn people if they are asking for an unknown capability.

18 years agoTypo in capability name.
tjhunt [Tue, 19 Sep 2006 22:35:40 +0000 (22:35 +0000)]
Typo in capability name.

18 years agoAlways print the question list, so you can add questions to a quiz, even if you are...
tjhunt [Tue, 19 Sep 2006 22:35:02 +0000 (22:35 +0000)]
Always print the question list, so you can add questions to a quiz, even if you are not allowed to edit them.

18 years agoTypo in capability names.\r\rYou do not want to know how long I had to stare at the...
tjhunt [Tue, 19 Sep 2006 22:31:13 +0000 (22:31 +0000)]
Typo in capability names.\r\rYou do not want to know how long I had to stare at the code to spot that!

18 years agofixed MDL-6551
koenr [Tue, 19 Sep 2006 22:14:57 +0000 (22:14 +0000)]
fixed MDL-6551

18 years agoallowassign.php was submitting to allowoverride.php
tjhunt [Tue, 19 Sep 2006 21:53:37 +0000 (21:53 +0000)]
allowassign.php was submitting to allowoverride.php

18 years agoFix JavaScript problem reported in this thread: http://moodle.org/mod/forum/discuss...
tjhunt [Tue, 19 Sep 2006 21:48:16 +0000 (21:48 +0000)]
Fix JavaScript problem reported in this thread: http://moodle.org/mod/forum/discuss.php?d=54432. Merged from MOODLE_16_STABLE.

18 years agofix for mdl-3909
koenr [Tue, 19 Sep 2006 21:45:13 +0000 (21:45 +0000)]
fix for mdl-3909
cleaned up the file completely

18 years agometacourse role assignment fixes
skodak [Tue, 19 Sep 2006 20:39:55 +0000 (20:39 +0000)]
metacourse role assignment fixes

18 years agovarious minor Role UI fixes
skodak [Tue, 19 Sep 2006 17:34:29 +0000 (17:34 +0000)]
various minor Role UI fixes

18 years agoAdded some docs
moodler [Tue, 19 Sep 2006 16:38:53 +0000 (16:38 +0000)]
Added some docs

18 years agoDeleted the old students-based function and created the
moodler [Tue, 19 Sep 2006 16:29:43 +0000 (16:29 +0000)]
Deleted the old students-based function and created the
new-style setup_enrolments() function that uses roles
to do the tasks required when a user logs in.

Other enrolment plugins should use this as an example/guide

The sync parts of this plugin are not yet fixed.

18 years agoSlight extensions to get_my_courses() API to make it more useful in general
moodler [Tue, 19 Sep 2006 14:23:43 +0000 (14:23 +0000)]
Slight extensions to get_my_courses() API to make it more useful in general

18 years agorelacing deprecated functions with capability checks
toyomoyo [Tue, 19 Sep 2006 14:16:40 +0000 (14:16 +0000)]
relacing deprecated functions with capability checks

18 years agoMore efficient get_my_courses()
moodler [Tue, 19 Sep 2006 14:14:32 +0000 (14:14 +0000)]
More efficient get_my_courses()

18 years agoRenamed new commentary feature to 'general feedback'.
tjhunt [Tue, 19 Sep 2006 13:35:42 +0000 (13:35 +0000)]
Renamed new commentary feature to 'general feedback'.

18 years agoFixes bug MDL-6360 "Resizable image in breadcrumb trail..."
nfreear [Tue, 19 Sep 2006 11:36:21 +0000 (11:36 +0000)]
Fixes bug MDL-6360 "Resizable image in breadcrumb trail..."
  - files block_search_forums.php, calendar/lib.php, lang/en_utf8/access.php, weblib.php, theme/standard/config.php, styles_color.css

18 years agoRename column question_dataset_items->number to itemnumber, to avoid reserved word.
tjhunt [Tue, 19 Sep 2006 10:56:00 +0000 (10:56 +0000)]
Rename column question_dataset_items->number to itemnumber, to avoid reserved word.

18 years agoRISK_ADMIN replaced with RISK_CONFIG, part 2.
skodak [Tue, 19 Sep 2006 10:26:35 +0000 (10:26 +0000)]
RISK_ADMIN replaced with RISK_CONFIG, part 2.

18 years agoreplacing deprecated funciton calls with capability calls
toyomoyo [Tue, 19 Sep 2006 09:16:24 +0000 (09:16 +0000)]
replacing deprecated funciton calls with capability calls

18 years agoFew small fixes
vyshane [Tue, 19 Sep 2006 08:16:26 +0000 (08:16 +0000)]
Few small fixes

18 years agoTypos
vyshane [Tue, 19 Sep 2006 08:10:46 +0000 (08:10 +0000)]
Typos

18 years agofixed missing shortname pg upgrade code, sorry
skodak [Tue, 19 Sep 2006 07:35:48 +0000 (07:35 +0000)]
fixed missing shortname pg upgrade code, sorry

18 years agoRISK_ADMIN replaced with RISK_CONFIG
skodak [Tue, 19 Sep 2006 07:33:22 +0000 (07:33 +0000)]
RISK_ADMIN replaced with RISK_CONFIG

18 years agoMore typos...
vyshane [Tue, 19 Sep 2006 07:16:04 +0000 (07:16 +0000)]
More typos...

18 years agoFixed typo
vyshane [Tue, 19 Sep 2006 07:13:57 +0000 (07:13 +0000)]
Fixed typo

18 years agoIf the search and replace affected course->modinfo then courses may not work,
moodler [Tue, 19 Sep 2006 07:08:19 +0000 (07:08 +0000)]
If the search and replace affected course->modinfo then courses may not work,
so clear the cache

18 years agofixed missing dot
skodak [Tue, 19 Sep 2006 06:38:17 +0000 (06:38 +0000)]
fixed missing dot

18 years agofixed a bug where wrong parameters is passed
toyomoyo [Tue, 19 Sep 2006 06:36:54 +0000 (06:36 +0000)]
fixed a bug where wrong parameters is passed

18 years agomoodle/course:managemetacourse is now singular
skodak [Tue, 19 Sep 2006 06:35:52 +0000 (06:35 +0000)]
moodle/course:managemetacourse is now singular

18 years agoAttempted to improve the display of the table in collapsed view
mark-nielsen [Tue, 19 Sep 2006 05:57:57 +0000 (05:57 +0000)]
Attempted to improve the display of the table in collapsed view

18 years agoFix for the instance mentioned in MDL-3058
mark-nielsen [Tue, 19 Sep 2006 05:11:57 +0000 (05:11 +0000)]
Fix for the instance mentioned in MDL-3058

18 years agoCorrected a lang entry for better translation
mark-nielsen [Tue, 19 Sep 2006 05:10:24 +0000 (05:10 +0000)]
Corrected a lang entry for better translation

18 years agoMerged fix related to MDL-6020
moodler [Tue, 19 Sep 2006 04:53:56 +0000 (04:53 +0000)]
Merged fix related to MDL-6020

18 years agoGot ahead of myself, fixed by bug fix
mark-nielsen [Tue, 19 Sep 2006 04:49:45 +0000 (04:49 +0000)]
Got ahead of myself, fixed by bug fix

18 years agoNotice fix in report for numerical question types
mark-nielsen [Tue, 19 Sep 2006 04:48:13 +0000 (04:48 +0000)]
Notice fix in report for numerical question types

18 years agoFix in addpage.php when one deletes all pages in a lesson then adds a new one
mark-nielsen [Tue, 19 Sep 2006 04:45:18 +0000 (04:45 +0000)]
Fix in addpage.php when one deletes all pages in a lesson then adds a new one
Fix numerical questions were not displaying the student's answer in the feedback

18 years agotook out a comment, for proper debugging use the new debugging() function
toyomoyo [Tue, 19 Sep 2006 04:31:36 +0000 (04:31 +0000)]
took out a comment, for proper debugging use the new debugging() function

18 years agoSaw several problems with lesson_choose_from_menu, so finally replaced its use with...
mark-nielsen [Tue, 19 Sep 2006 04:06:32 +0000 (04:06 +0000)]
Saw several problems with lesson_choose_from_menu, so finally replaced its use with choose_from_menu in lib/weblib.php

18 years agoRemoved hard-coded strings and fixed labels
mark-nielsen [Tue, 19 Sep 2006 03:47:49 +0000 (03:47 +0000)]
Removed hard-coded strings and fixed labels

18 years agoRemoved a hard-coded string and added PHPdoc comments for the page
mark-nielsen [Tue, 19 Sep 2006 02:54:57 +0000 (02:54 +0000)]
Removed a hard-coded string and added PHPdoc comments for the page

18 years agoremoved some unecessary comments
mark-nielsen [Tue, 19 Sep 2006 02:48:29 +0000 (02:48 +0000)]
removed some unecessary comments

18 years agofunction should be looking up parent contexts too
toyomoyo [Tue, 19 Sep 2006 02:47:55 +0000 (02:47 +0000)]
function should be looking up parent contexts too

18 years agoFixed a bug when detecting a user as eligible for posting their name for high scores
mark-nielsen [Tue, 19 Sep 2006 02:41:10 +0000 (02:41 +0000)]
Fixed a bug when detecting a user as eligible for posting their name for high scores

18 years agoFixed alignment problem with the buttons for password protected lessons
mark-nielsen [Tue, 19 Sep 2006 02:29:42 +0000 (02:29 +0000)]
Fixed alignment problem with the buttons for password protected lessons

18 years agoreplacing references to user_* tables
toyomoyo [Tue, 19 Sep 2006 01:44:33 +0000 (01:44 +0000)]
replacing references to user_* tables

18 years agoPreset added. This is a basic javascript based preset.
tomflannaghan [Tue, 19 Sep 2006 01:21:13 +0000 (01:21 +0000)]
Preset added. This is a basic javascript based preset.

18 years agoadded capabilty risks into access.php and GUI for define role and override; minor...
skodak [Mon, 18 Sep 2006 21:32:49 +0000 (21:32 +0000)]
added capabilty risks into access.php and GUI for define role and override; minor fixes for capability types in forum

18 years agoMDL-6568 shortname added to roles
skodak [Mon, 18 Sep 2006 17:40:22 +0000 (17:40 +0000)]
MDL-6568 shortname added to roles

18 years agounenrol_student() -> role_unassign()
ethem [Mon, 18 Sep 2006 17:32:43 +0000 (17:32 +0000)]
unenrol_student() -> role_unassign()

18 years agoAdded new capabilities, renamed mod/data:readentry to mod/data:viewentry to make...
vyshane [Mon, 18 Sep 2006 13:46:09 +0000 (13:46 +0000)]
Added new capabilities, renamed mod/data:readentry to mod/data:viewentry to make capability name more consistent with the rest of moodle.

18 years agoFixing debugging
moodler [Mon, 18 Sep 2006 13:36:17 +0000 (13:36 +0000)]
Fixing debugging

18 years agoFixed up some more debug statements
moodler [Mon, 18 Sep 2006 13:26:58 +0000 (13:26 +0000)]
Fixed up some more debug statements

18 years agoFixed a some debugging statements
moodler [Mon, 18 Sep 2006 13:24:45 +0000 (13:24 +0000)]
Fixed a some debugging statements

18 years agoFixed notice
vyshane [Mon, 18 Sep 2006 12:48:00 +0000 (12:48 +0000)]
Fixed notice

18 years agoremoving get_creators(), no more reference to the function
toyomoyo [Mon, 18 Sep 2006 12:04:16 +0000 (12:04 +0000)]
removing get_creators(), no more reference to the function

18 years ago'merged from 1.6 - MDL-6020 - CSS changes to align text beside images'
urs_hunkler [Mon, 18 Sep 2006 12:01:16 +0000 (12:01 +0000)]
'merged from 1.6 - MDL-6020 - CSS changes to align text beside images'

18 years agono more refernece to remove_creator() function
toyomoyo [Mon, 18 Sep 2006 11:55:04 +0000 (11:55 +0000)]
no more refernece to remove_creator() function

18 years agoAdds Javascript Support for the presets.
tomflannaghan [Mon, 18 Sep 2006 11:45:12 +0000 (11:45 +0000)]
Adds Javascript Support for the presets.

18 years ago<?php // $Id: preset.php,v 1.5 2006/08/30 09:17:40 skodak Exp $
tomflannaghan [Mon, 18 Sep 2006 11:42:28 +0000 (11:42 +0000)]
<?php // $Id: preset.php,v 1.5 2006/08/30 09:17:40 skodak Exp $
/* Preset Menu
 *
 * This is the page that is the menu item in the config database
 * pages.
 */

require_once('../../config.php');
require_once('lib.php');
require_once($CFG->libdir.'/uploadlib.php');
require_once($CFG->libdir.'/xmlize.php');

$id      = optional_param('id', 0, PARAM_INT);    // course module id
$d       = optional_param('d', 0, PARAM_INT);     // database activity id
$action  = optional_param('action', 'base', PARAM_RAW); // current action
$file    = optional_param('file', false, PARAM_PATH); // path of file to upload

if ($id) {
    if (! $cm = get_record('course_modules', 'id', $id)) {
        error('Course Module ID Incorrect');
    }
    if (! $course = get_record('course', 'id', $cm->course)) {
        error('Course is misconfigured');
    }
    if (! $data = get_record('data', 'id', $cm->instance)) {
        error('Module Incorrect');
    }
} else if ($d) {
    if (! $data = get_record('data', 'id', $d)) {
        error('Database ID Incorrect');
    }
    if (! $course = get_record('course', 'id', $data->course)) {
        error('Course is misconfigured');
    }
    if (! $cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
        error('Course Module ID was incorrect');
    }
} else {
    error('Parameter missing');
}

require_login($course->id);

require_capability('mod/data:managetemplates', get_context_instance(CONTEXT_MODULE, $cm->id));

/* get the list of standard presets found in /mod/data/preset */
$presets = array();

if ($presetdir = opendir($CFG->dirroot.'/mod/data/preset')) {

    while ($userdir = readdir($presetdir)) {

        $fulluserdir = '/mod/data/preset/'.$userdir;

        if ($userdir == '.' || $userdir == '..') {
            continue;
        }

        /* Global Standard Presets */
        if (is_directory_a_preset($CFG->dirroot.$fulluserdir)) {
            $preset = new StdClass;
            $preset->path = $fulluserdir;
            $preset->name = $userdir;
            if (file_exists($fulluserdir.'/screenshot.jpg')) {
                $preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$userdir.'/screenshot.jpg';
            }
            $presets[] = $preset;
            unset($preset);
        }

        /* User made presets stored in user folders */
        else if (get_record('user', 'id', $userdir)) {
            $userdirh = opendir($CFG->dirroot.$fulluserdir);
            while ($userpresetdir = readdir($userdirh)) {
                $fulluserpresetdir = $fulluserdir.'/'.$userpresetdir;
                if ($userpresetdir != '.' && $userpresetdir != '..' && is_directory_a_preset($CFG->dirroot.$fulluserpresetdir)) {
                    $preset = new StdClass;
                    $preset->path = $fulluserpresetdir;
                    $preset->name = $userpresetdir;
                    $preset->user = $userdir;
                    if (file_exists($fulluserpresetdir.'/screenshot.jpg')) {
                        $preset->screenshot = $CFG->wwwroot.'/mod/data/preset/'.$userdir.'/'.$userpresetdir.'/screenshot.jpg';
                    }
                    $presets[] = $preset;
                    unset($preset);
                }
            }
        }
    }
    closedir($presetdir);
}

/* Need sesskey security check here for import instruction */
$sesskey = sesskey();

/********************************************************************/
/* Output */
data_presets_print_header($course, $cm, $data);

echo "<center>";
switch ($action) {
    /* Main selection menu - default mode also. */
 default:
 case 'base':
     $strimport = get_string('import');
     $strfromfile = get_string('fromfile', 'data');
     $strchooseorupload = get_string('chooseorupload', 'data');
     $strok = get_string('ok');
     $strusestandard = get_string('usestandard', 'data');
     $strchoose = get_string('choose');
     $strexport = get_string('export', 'data');
     $strexportaszip = get_string('exportaszip', 'data');
     $strsaveaspreset = get_string('saveaspreset', 'data');
     $strdelete = get_string('delete');

     echo "<table cellpadding=7>";
     echo "<tr><td><h3>$strimport</h3></td>";
     echo "<td><form name='form' method='POST' action='?d=$data->id&action=importzip&sesskey=$sesskey' enctype='multipart/form-data'>";
     helpbutton('importfromfile', '', 'data');
     echo " $strfromfile:</td><td><input name=\"file\" size=\"20\" value=\"\" alt=\"file\" type=\"text\"><input name=\"coursefiles\" title=\"Choose or upload a file\" value=\"$strchooseorupload\" onclick=\"return openpopup('/files/index.php?id=2&choose=form.file', 'coursefiles', 'menubar=0,location=0,scrollbars,resizable,width=750,height=500', 0);\" type=\"button\">";
     echo "<input type=\"submit\" value=\"$strok\"/>";
     echo "</form></td></tr>";

     echo "<tr valign=top><td></td><td>";
     helpbutton('usepreset', '', 'data');
     echo " $strusestandard: </td><td>";
     echo "<table width=100%>";
     foreach ($presets as $id => $preset) {
 echo "<tr><form action='' method='POST'>";
 echo "<input type='hidden' name='file' value=\"$preset->path\">";
 echo "<input type='hidden' name='action' value='importpreset'>";
 echo "<input type='hidden' name='d' value='$data->id'>";
 echo "<input type='hidden' name='sesskey' value='$sesskey'>";
 echo "<td>";
 if ($preset->screenshot) {
     echo "<img src='$preset->screenshot' alt='$preset->screenshot' />";
 }
 echo "</td><td>$preset->name";
 if ($preset->user) {
     $user = get_record('user', 'id', $preset->user);
     echo " by $user->firstname $user->lastname";
 }
 echo "</td><td><input type='submit' value='$strchoose'></td></form>";
 echo "<td>";
 if ($preset->user == $USER->id || isadmin()) {
     echo "<form action='' method='POST'>";
     echo "<input type='hidden' name='d' value='$data->id' />";
     echo "<input type='hidden' name='action' value='confirmdelete' />";
     echo "<input type='hidden' name='sesskey' value='$sesskey' />";
     echo "<input type='hidden' name='deleteid' value='$id' />";
     echo "<input type='hidden' name='deletename' value=\"$preset->name\" />";
     echo "<input type='submit' value='$strdelete' /></form>";
 }
 echo "</td></tr>";
     }
     echo "</table></td></tr>";

     echo "<tr><td valign=top><h3>$strexport</h3></td>";
     echo "<td><form action='' method='POST'>";
     helpbutton('exportzip', '', 'data');
     echo " <input type='hidden' name='action' value='export' />";
     echo "<input type='hidden' name='d' value='$data->id' />";
     echo "<input type='submit' value='$strexportaszip' />";
     echo "</form>";

     echo "<form action='' method='POST'>";
     helpbutton('savepreset', '', 'data');
     echo " <input type='hidden' name='action' value='save1' />";
     echo "<input type='hidden' name='d' value='$data->id' />";
     echo "<input type='hidden' name='sesskey' value='$sesskey' />";
     echo "<input type='submit' value='$strsaveaspreset' />";
     echo "</form>";

     echo "</table>";
     break;

     /***************** Deleting *****************/
 case 'confirmdelete' :
     if (!confirm_sesskey()) {
 error("Sesskey Invalid");
     }

     $deletename = required_param('deletename', PARAM_RAW);
     $deleteid = required_param('deleteid', PARAM_INT);

     $strwarning = get_string('deletewarning', 'data');
     $strdelete = get_string('delete');
     notify($strwarning);
     echo "<form action='' method='POST'>";
     echo "<input type='hidden' name='d' value='$data->id' />";
     echo "<input type='hidden' name='action' value='delete' />";
     echo "<input type='hidden' name='sesskey' value='$sesskey' />";
     echo "<input type='hidden' name='deleteid' value='$deleteid' />";
     echo "<input type='hidden' name='deletename' value=\"$deletename\" />";
     echo "<input type='submit' value='$strdelete' /></form>";
     break;

 case 'delete' :
     if (!confirm_sesskey()) {
 error('Sesskey Invalid');
     }

     $deletename = required_param('deletename', PARAM_RAW);
     $deleteid = required_param('deleteid', PARAM_INT);

     if (!empty($presets[$deleteid])) {
 if ($presets[$deleteid]->name == $deletename) {
     if (!clean_preset($CFG->dirroot.$presets[$deleteid]->path)) error("Error deleting");
 }
 rmdir($CFG->dirroot.$presets[$deleteid]->path);
     }
     else {
 error('Invalid delete');
     }

     $strdelete = get_string('deleted', 'data');
     notify("$deletename $strdeleted");

     break;

     /***************** Importing *****************/
 case 'importpreset' :
     if (!confirm_sesskey()) {
 error("Sesskey Invalid");
     }

     $pimporter = new PresetImporter($course, $cm, $data, $CFG->dirroot.$file);
     $pimporter->import_options();
     break;

     /* Imports a zip file. */
 case 'importzip' :
     if (!confirm_sesskey()) {
 error("Sesskey Invalid");
     }

     if (!make_upload_directory('temp/data/'.$USER->id)) {
 error("Can't Create Directory");
     }

     $presetfile = $CFG->dataroot."/temp/data/".$USER->id;
     clean_preset($presetfile);

     if (!unzip_file($CFG->dataroot."/$course->id/$file",
     $presetfile, false))
 error("Can't unzip file");

     $pimporter = new PresetImporter($course, $cm, $data, $presetfile);
     $pimporter->import_options();
     break;

 case 'finishimport':
     if (!confirm_sesskey()) {
 error('Sesskey Invalid');
     }

     $pimporter = new PresetImporter($course, $cm, $data, $file);
     $pimporter->import();

     $strimportsuccess = get_string('importsuccess', 'data');
     $straddentries = get_string('addentries', 'data');
     $strtodatabase = get_string('todatabase', 'data');
     if (!get_records('data_records', 'dataid', $data->id)) {
 notify("$strimportsuccess <a href='edit.php?d=$data->id'>$straddentries</a> $strtodatabase", 'notifysuccess');
     }
     else {
 notify("$strimportsuccess", 'notifysuccess');
     }
     break;

     /* Exports as a zip file ready for download. */
 case 'export':
     $file = data_presets_export($course, $cm, $data);
     echo get_string('exportedtozip', 'data')."<br>";
     $perminantfile = $CFG->dataroot."/$course->id/moddata/data/$data->id/preset.zip";
     @unlink($perminantfile);
     /* is this created elsewhere? sometimes its not present... */
     make_upload_directory("$course->id/moddata/data/$data->id");

     /* now just move the zip into this folder to allow a nice download */
     if (!rename($file, $perminantfile)) error("Can't move zip");
     echo "<a href='$CFG->wwwroot/file.php/$course->id/moddata/data/$data->id/preset.zip'>".get_string('download', 'data')."</a>";
     break;

     /***************** Exporting *****************/
 case 'save1':
     if (!confirm_sesskey()) {
 error("Sesskey Invalid");
     }

     $strcontinue = get_string('continue');
     $strwarning = get_string('presetwarning', 'data');

     echo "<div align=center>";
     echo "<p>$strwarning</p>";
     echo "<form action='' method='POST'>";
     echo "Name: <input type='textbox' name='name' value=\"$data->name\" />";
     echo "<input type='hidden' name='action' value='save2' />";
     echo "<input type='hidden' name='d' value='$data->id' />";
     echo "<input type='hidden' name='sesskey' value='$sesskey' />";
     echo "<input type='submit' value='$strcontinue' /></form></div>";
     break;

 case 'save2':
     if (!confirm_sesskey()) {
 error("Sesskey Invalid");
     }

     $strcontinue = get_string('continue');
     $stroverwrite = get_string('overwrite');

     $name = optional_param('name', $data->name, PARAM_FILE);

     if (is_directory_a_preset("$CFG->dirroot/mod/data/preset/$USER->id/$name")) {
 notify("Preset already exists: Pick another name or overwrite");

 echo "<div align=center>";
 echo "<form action='' method='POST'>";
 echo "New name: <input type='textbox' name='name' value=\"$name\" />";
 echo "<input type='hidden' name='action' value='save2' />";
 echo "<input type='hidden' name='d' value='$data->id' />";
 echo "<input type='hidden' name='sesskey' value='$sesskey' />";
 echo "<input type='submit' value='$strcontinue' /></form>";

 echo "<form action='' method='POST'>";
 echo "<input type='hidden' name='name' value=\"$name\" />";
 echo "<input type='hidden' name='action' value='save3' />";
 echo "<input type='hidden' name='d' value='$data->id' />";
 echo "<input type='hidden' name='sesskey' value='$sesskey' />";
 echo "<input type='submit' value='$stroverwrite' /></form>";
 echo "</div>";
 break;
     }

 case 'save3':
     if (!confirm_sesskey()) {
 error("Sesskey Invalid");
     }

     $name = optional_param('name', $data->name, PARAM_FILE);
     $presetdirectory = "$CFG->dirroot/mod/data/preset/$USER->id/$name";

     if (!is_dir($presetdirectory)) {
 @mkdir("$CFG->dirroot/mod/data/preset/$USER->id");
 mkdir($presetdirectory);
     }
     else {
 clean_preset($presetdirectory);
     }

     $file = data_presets_export($course, $cm, $data);
     if (!unzip_file($file, $presetdirectory, false)) error("Can't unzip to the preset directory");
     notify(get_string('savesuccess', 'data'), 'notifysuccess');
     break;

}
echo "</center>";
print_footer($course);

function is_directory_a_preset($directory) {
    $directory = rtrim($directory, '/\\') . '/';
    if (file_exists($directory.'singletemplate.html') &&
file_exists($directory.'listtemplate.html') &&
file_exists($directory.'listtemplateheader.html') &&
file_exists($directory.'listtemplatefooter.html') &&
file_exists($directory.'addtemplate.html') &&
file_exists($directory.'rsstemplate.html') &&
file_exists($directory.'rsstitletemplate.html') &&
file_exists($directory.'csstemplate.css') &&
file_exists($directory.'jstemplate.js') &&
file_exists($directory.'preset.xml')) return true;
    else return false;
}

function data_presets_print_header($course, $cm, $data, $showtabs=true) {

    global $CFG, $displaynoticegood, $displaynoticebad;

    $strdata = get_string('modulenameplural','data');

    print_header_simple($data->name, '', "<a href='index.php?id=$course->id'>$strdata</a> -> $data->name",
'', '', true, '', navmenu($course, $cm));

    print_heading(format_string($data->name));

    /// Print the tabs

    if ($showtabs) {
        $currenttab = 'presets';
        include_once('tabs.php');
    }

    /// Print any notices

    if (!empty($displaynoticegood)) {
        notify($displaynoticegood, 'notifysuccess');    // good (usually green)
    } else if (!empty($displaynoticebad)) {
        notify($displaynoticebad);                     // bad (usuually red)
    }
}

function clean_preset($folder) {
    if (unlink($folder.'/singletemplate.html') &&
unlink($folder.'/listtemplate.html') &&
unlink($folder.'/listtemplateheader.html') &&
unlink($folder.'/listtemplatefooter.html') &&
unlink($folder.'/addtemplate.html') &&
unlink($folder.'/rsstemplate.html') &&
unlink($folder.'/rsstitletemplate.html') &&
unlink($folder.'/csstemplate.css') &&
unlink($folder.'/jstemplate.js') &&
unlink($folder.'/preset.xml')) return true;
    else return false;
}

function data_presets_export($course, $cm, $data) {
    global $CFG;
    /* Info Collected. Now need to make files in moodledata/temp */
    $tempfolder = $CFG->dataroot.'/temp';
    $singletemplate     = fopen($tempfolder.'/singletemplate.html', 'w');
    $listtemplate       = fopen($tempfolder.'/listtemplate.html', 'w');
    $listtemplateheader = fopen($tempfolder.'/listtemplateheader.html', 'w');
    $listtemplatefooter = fopen($tempfolder.'/listtemplatefooter.html', 'w');
    $addtemplate        = fopen($tempfolder.'/addtemplate.html', 'w');
    $rsstemplate        = fopen($tempfolder.'/rsstemplate.html', 'w');
    $rsstitletemplate   = fopen($tempfolder.'/rsstitletemplate.html', 'w');
    $csstemplate        = fopen($tempfolder.'/csstemplate.css', 'w');
    $jstemplate         = fopen($tempfolder.'/jstemplate.js', 'w');

    fwrite($singletemplate, $data->singletemplate);
    fwrite($listtemplate, $data->listtemplate);
    fwrite($listtemplateheader, $data->listtemplateheader);
    fwrite($listtemplatefooter, $data->listtemplatefooter);
    fwrite($addtemplate, $data->addtemplate);
    fwrite($rsstemplate, $data->rsstemplate);
    fwrite($rsstitletemplate, $data->rsstitletemplate);
    fwrite($csstemplate, $data->csstemplate);
    fwrite($jstemplate, $data->jstemplate);

    fclose($singletemplate);
    fclose($listtemplate);
    fclose($listtemplateheader);
    fclose($listtemplatefooter);
    fclose($addtemplate);
    fclose($rsstemplate);
    fclose($rsstitletemplate);
    fclose($csstemplate);
    fclose($jstemplate);

    /* All the display data is now done. Now assemble preset.xml */
    $fields = get_records('data_fields', 'dataid', $data->id);
    $presetfile = fopen($tempfolder.'/preset.xml', 'w');
    $presetxml = "<preset>\n\n";

    /* Database settings first. Name not included? */
    $settingssaved = array('intro', 'comments', 'ratings', 'participants',
   'requiredentries', 'requiredentriestoview', 'maxentries',
   'rssarticles', 'approval', 'scale', 'assessed', 'assessedpublic',
   'defaultsort', 'defaultsortdir', 'editany');

    $presetxml .= "<settings>\n";
    foreach ($settingssaved as $setting) {
$presetxml .= "<$setting>{$data->$setting}</$setting>\n";
    }
    $presetxml .= "</settings>\n\n";

    /* Now for the fields. Grabs all settings that are non-empty */
    if (!empty($fields)) {
foreach ($fields as $field) {
    $presetxml .= "<field>\n";
    foreach ($field as $key => $value) {
if ($value != '' && $key != 'id' && $key != 'dataid') {
    $presetxml .= "<$key>$value</$key>\n";
}
    }
    $presetxml .= "</field>\n\n";
}
    }

    $presetxml .= "</preset>";
    fwrite($presetfile, $presetxml);
    fclose($presetfile);

    /* Check all is well */
    if (!is_directory_a_preset($tempfolder)) {
        error("Not all files generated!");
    }

    $filelist = array(
                      "singletemplate.html",
                      "listtemplate.html",
                      "listtemplateheader.html",
                      "listtemplatefooter.html",
                      "addtemplate.html",
                      "rsstemplate.html",
                      "rsstitletemplate.html",
                      "csstemplate.css",
      "jstemplate.js",
                      "preset.xml");

    foreach ($filelist as $key => $file) {
        $filelist[$key] = $tempfolder.'/'.$filelist[$key];
    }

    @unlink($tempfolder.'/export.zip');
    $status = zip_files($filelist, $tempfolder.'/export.zip');

    /* made the zip... now return the filename for storage.*/
    return $tempfolder.'/export.zip';
}

class PresetImporter {
    function PresetImporter($course, $cm, $data, $folder) {
        global $CFG;
        $this->course = $course;
        $this->cm = $cm;
        $this->data = $data;
        $this->folder = $folder;
        $this->postfolder = $folder;
    }

    function get_settings() {
        global $CFG;

        if (!is_directory_a_preset($this->folder)) {
            error("$this->folder Not a preset");
        }

        /* Grab XML */
        $presetxml = file_get_contents($this->folder.'/preset.xml');
        $parsedxml = xmlize($presetxml);

        /* First, do settings. Put in user friendly array. */
        $settingsarray = $parsedxml['preset']['#']['settings'][0]['#'];
        $settings = new StdClass();

        foreach ($settingsarray as $setting => $value) {
            $settings->$setting = $value[0]['#'];
        }

        /* Now work out fields to user friendly array */
        $fieldsarray = $parsedxml['preset']['#']['field'];
        $fields = array();
        foreach ($fieldsarray as $field) {
            $f = new StdClass();
            foreach ($field['#'] as $param => $value) {
                $f->$param = $value[0]['#'];
            }
            $f->dataid = $this->data->id;
            $fields[] = $f;
        }

        /* Now add the HTML templates to the settings array so we can update d */
        $settings->singletemplate     = file_get_contents($this->folder."/singletemplate.html");
        $settings->listtemplate       = file_get_contents($this->folder."/listtemplate.html");
        $settings->listtemplateheader = file_get_contents($this->folder."/listtemplateheader.html");
        $settings->listtemplatefooter = file_get_contents($this->folder."/listtemplatefooter.html");
        $settings->addtemplate        = file_get_contents($this->folder."/addtemplate.html");
        $settings->rsstemplate        = file_get_contents($this->folder."/rsstemplate.html");
        $settings->rsstitletemplate   = file_get_contents($this->folder."/rsstitletemplate.html");
        $settings->csstemplate        = file_get_contents($this->folder."/csstemplate.css");
        $settings->jstemplate         = file_get_contents($this->folder."/jstemplate.js");

        $settings->instance = $this->data->id;

        /* Now we look at the current structure (if any) to work out whether we need to clear db
           or save the data */
        $currentfields = array();
        $currentfields = get_records('data_fields', 'dataid', $this->data->id);

        return array($settings, $fields, $currentfields);
    }

    function import_options() {
        if (!confirm_sesskey()) {
            error("Sesskey Invalid");
        }

        $strblank = get_string('blank', 'data');
        $strnofields = get_string('nofields', 'data');
        $strcontinue = get_string("continue");
        $sesskey = sesskey();
        $strwarning = get_string('mappingwarning', 'data');
        $strfieldmappings = get_string('fieldmappings', 'data');
        $strnew = get_string("new");
        $strold = get_string("old");

        list($settings, $newfields,  $currentfields) = $this->get_settings();

        echo "<div align='center'><form action='' method='POST'>";
        echo "<input type='hidden' name='sesskey' value='$sesskey' />";
        echo "<input type='hidden' name='d' value='{$this->data->id}' />";
        echo "<input type='hidden' name='action' value='finishimport' />";
        echo "<input type='hidden' name='file' value=\"$this->postfolder\" />";

        if ($currentfields != array() && $newfields != array()) {
            echo "<h3>$strfieldmappings ";
            echo helpbutton('fieldmappings', '', 'data');
            echo "</h3><table>";

            foreach ($newfields as $nid => $newfield) {
                echo "<tr><td>$newfield->name </td>";
                echo "<td><select name='field_$nid'>";

                foreach ($currentfields as $cid => $currentfield) {
                    if ($currentfield->type == $newfield->type) {
                        if ($currentfield->name == $newfield->name) {
                            echo "<option value='$cid' selected='true'>$currentfield->name</option>";
                            $selected=true;
                        }
                        else {
    echo "<option value='$cid'>$currentfield->name</option>";
}
    }
                }

                if ($selected)
                    echo "<option value='-1'>-</option>";
                else
                    echo "<option value='-1' selected='true'>-</option>";
                echo "</select></td></tr>";
            }
            echo "</table>";
            echo "<p>$strwarning</p>";
        }
        else if ($newfields == array()) {
            error("New preset has no defined fields!");
        }
        echo "<input type='submit' value='$strcontinue' /></form></div>";

    }

    function import() {
        global $CFG;

        list($settings, $newfields, $currentfields) = $this->get_settings();
        $preservedfields = array();

        /* Maps fields and makes new ones */
        if ($newfields != array()) {
            /* We require an injective mapping, and need to know what to protect */
            foreach ($newfields as $nid => $newfield) {
                $cid = optional_param("field_$nid", -1, PARAM_INT);
                if ($cid == -1) continue;

                if (array_key_exists($cid, $preservedfields)) error("Not an injective map");
                else $preservedfields[$cid] = true;

            }

            foreach ($newfields as $nid => $newfield) {
                $cid = optional_param("field_$nid", -1, PARAM_INT);

                /* A mapping. Just need to change field params. Data kept. */
                if ($cid != -1) {
                    $fieldobject = data_get_field_from_id($currentfields[$cid]->id, $this->data);
                    foreach ($newfield as $param => $value) {
                        if ($param != "id") {
                            $fieldobject->field->$param = $value;
                        }
                    }
                    unset($fieldobject->field->similarfield);
                    $fieldobject->update_field();
                    unset($fieldobject);
                }
                /* Make a new field */
                else {
                    include_once("field/$newfield->type/field.class.php");

                    $classname = 'data_field_'.$newfield->type;
                    $fieldclass = new $classname($newfield, $this->data);
                    $fieldclass->insert_field();
                    unset($fieldclass);
                }
            }
        }

        /* Get rid of all old unused data */
        if ($preservedfields != array()) {
            foreach ($currentfields as $cid => $currentfield) {
                if (!array_key_exists($cid, $preservedfields)) {
                    /* Data not used anymore so wipe! */
                    print "Deleting field $currentfield->name<br>";
                    $id = $currentfield->id;

                    if ($content = get_records('data_content', 'fieldid', $id)) {
                        foreach ($content as $item) {
                            delete_records('data_ratings', 'recordid', $item->recordid);
                            delete_records('data_comments', 'recordid', $item->recordid);
                            delete_records('data_records', 'id', $item->recordid);
                        }
                    }
                    delete_records('data_content', 'fieldid', $id);
                    delete_records('data_fields', 'id', $id);

                }
            }
        }

        data_update_instance(addslashes_object($settings));

        if (strstr($this->folder, "/temp/")) clean_preset($this->folder); /* Removes the temporary files */
        return true;
    }
}

?>

18 years agoremoved references to /requested(teachers?|students?)name/ and 'showsiteparticipantsl...
skodak [Mon, 18 Sep 2006 11:21:24 +0000 (11:21 +0000)]
removed references to /requested(teachers?|students?)name/ and 'showsiteparticipantslist' - we are now using only default names stored in langpacks for backwards compatibility

18 years agoremove_admin() no longer referenced
toyomoyo [Mon, 18 Sep 2006 10:47:09 +0000 (10:47 +0000)]
remove_admin() no longer referenced

18 years agoRemoved configshowparticipantslist
vyshane [Mon, 18 Sep 2006 10:26:11 +0000 (10:26 +0000)]
Removed configshowparticipantslist

18 years agoadd_creator no longer in use
toyomoyo [Mon, 18 Sep 2006 10:18:26 +0000 (10:18 +0000)]
add_creator no longer in use

18 years agonew metacourse fixes for admin block
skodak [Mon, 18 Sep 2006 09:58:22 +0000 (09:58 +0000)]
new metacourse fixes for admin block

18 years agometacourse fixes for course editting
skodak [Mon, 18 Sep 2006 09:37:51 +0000 (09:37 +0000)]
metacourse fixes for course editting

18 years agovalidation should not watch out for teacher and students string anymore
toyomoyo [Mon, 18 Sep 2006 09:16:49 +0000 (09:16 +0000)]
validation should not watch out for teacher and students string anymore

18 years agoFIxed to use the new debugging function
moodler [Mon, 18 Sep 2006 09:13:04 +0000 (09:13 +0000)]
FIxed to use the new debugging function

18 years agoif the user has no capability, after creating a course we add him to the first role...
toyomoyo [Mon, 18 Sep 2006 09:10:03 +0000 (09:10 +0000)]
if the user has no capability, after creating a course we add him to the first role with legacy:edittingteacher, to make him a legacy editting teacher

18 years agoAdded moodle/site:viewparticipants
vyshane [Mon, 18 Sep 2006 09:09:25 +0000 (09:09 +0000)]
Added moodle/site:viewparticipants

18 years agoRemove duplicate call to print_header
tjhunt [Mon, 18 Sep 2006 09:02:30 +0000 (09:02 +0000)]
Remove duplicate call to print_header

18 years agoAdded moodle/site:viewparticipants
vyshane [Mon, 18 Sep 2006 09:02:12 +0000 (09:02 +0000)]
Added moodle/site:viewparticipants

18 years agoFixed some debugging statements
moodler [Mon, 18 Sep 2006 08:57:23 +0000 (08:57 +0000)]
Fixed some debugging statements

18 years agoReplaced managesharedfeeds by manageanyfeeds
vyshane [Mon, 18 Sep 2006 08:37:29 +0000 (08:37 +0000)]
Replaced managesharedfeeds by manageanyfeeds

18 years agometacourses gui fixes, part I.
skodak [Mon, 18 Sep 2006 08:20:01 +0000 (08:20 +0000)]
metacourses gui fixes, part I.

18 years agoRemoved isadmin()
vyshane [Mon, 18 Sep 2006 08:10:20 +0000 (08:10 +0000)]
Removed isadmin()

18 years agoGot rid of isadmin() calls, added capability checks.
vyshane [Mon, 18 Sep 2006 07:19:38 +0000 (07:19 +0000)]
Got rid of isadmin() calls, added capability checks.

18 years agoSome trivial tidying of source
moodler [Mon, 18 Sep 2006 05:50:02 +0000 (05:50 +0000)]
Some trivial  tidying of source

18 years agoRemoved isteacher()
vyshane [Mon, 18 Sep 2006 05:29:42 +0000 (05:29 +0000)]
Removed isteacher()

18 years agoRemoved references to showsiteparticipantslist. Replaced by capability.
vyshane [Mon, 18 Sep 2006 05:28:06 +0000 (05:28 +0000)]
Removed references to showsiteparticipantslist. Replaced by capability.

18 years agoRemoved showsiteparticipantslist strings.
vyshane [Mon, 18 Sep 2006 05:27:28 +0000 (05:27 +0000)]
Removed showsiteparticipantslist strings.

18 years agoRemoved showsiteparticipantslist, replaced with capability
vyshane [Mon, 18 Sep 2006 05:26:16 +0000 (05:26 +0000)]
Removed showsiteparticipantslist, replaced with capability

18 years agoRemoved showsiteparticipantslist. Replaced with capability.
vyshane [Mon, 18 Sep 2006 05:25:43 +0000 (05:25 +0000)]
Removed showsiteparticipantslist. Replaced with capability.

18 years agoremoving word for teachers and students, please use proper role names instead
toyomoyo [Mon, 18 Sep 2006 04:57:34 +0000 (04:57 +0000)]
removing word for teachers and students, please use proper role names instead