]> git.mjollnir.org Git - moodle.git/log
moodle.git
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

18 years agoNuked nuke.
moodler [Mon, 18 Sep 2006 03:28:02 +0000 (03:28 +0000)]
Nuked nuke.

18 years agoAutomatic installer.php lang files by installer_builder (20060918)
moodler [Mon, 18 Sep 2006 03:04:28 +0000 (03:04 +0000)]
Automatic installer.php lang files by installer_builder (20060918)

18 years agoFixes for MDL-6440 and MDL-6577
vinkmar [Mon, 18 Sep 2006 02:41:14 +0000 (02:41 +0000)]
Fixes for MDL-6440 and MDL-6577

18 years agoReplaced isteacher() in fullname() call.
vyshane [Mon, 18 Sep 2006 02:28:57 +0000 (02:28 +0000)]
Replaced isteacher() in fullname() call.

18 years agoAdded display default feedback in lesson settings
mark-nielsen [Mon, 18 Sep 2006 01:31:35 +0000 (01:31 +0000)]
Added display default feedback in lesson settings
Led to reducing some redundant code in action/continue.php
Also, a bug fix in locallib.php for function lesson_print_submit_link (needed to add slashes or else js would break)

18 years agoAdded lang entry for display default feedback
mark-nielsen [Mon, 18 Sep 2006 01:29:03 +0000 (01:29 +0000)]
Added lang entry for display default feedback

18 years agoHelp file for displaying default feedback
mark-nielsen [Mon, 18 Sep 2006 01:28:12 +0000 (01:28 +0000)]
Help file for displaying default feedback

18 years agometacourse sync now uses roles, I will continue with fixing of GUIs tomorrow
skodak [Sun, 17 Sep 2006 22:21:37 +0000 (22:21 +0000)]
metacourse sync now uses roles, I will continue with fixing of GUIs tomorrow

18 years agoadded new capability 'moodle/course:managemetacourses'
skodak [Sun, 17 Sep 2006 21:03:35 +0000 (21:03 +0000)]
added new capability 'moodle/course:managemetacourses'

18 years agofixed some more warnings in uploaduser.php script
skodak [Sun, 17 Sep 2006 21:02:31 +0000 (21:02 +0000)]
fixed some more warnings in uploaduser.php script

18 years agofixed warning
skodak [Sun, 17 Sep 2006 20:51:54 +0000 (20:51 +0000)]
fixed warning

18 years agoAdded dialog to confirm deletion of activity.
cap2501 [Sun, 17 Sep 2006 18:20:43 +0000 (18:20 +0000)]
Added dialog to confirm deletion of activity.

18 years agofixed several warnings in get_course()
skodak [Sun, 17 Sep 2006 18:07:35 +0000 (18:07 +0000)]
fixed several warnings in get_course()

18 years agoremoved foter login link during initial phase of installation
skodak [Sun, 17 Sep 2006 17:53:20 +0000 (17:53 +0000)]
removed foter login link during initial phase of installation

18 years agocleaned up some formatting
cap2501 [Sun, 17 Sep 2006 17:48:27 +0000 (17:48 +0000)]
cleaned up some formatting

18 years agoRemoved a PHP notice
gustav_delius [Sun, 17 Sep 2006 17:43:30 +0000 (17:43 +0000)]
Removed a PHP notice

18 years agofixed non-working edit button on course page for teachers, added explanation comments
skodak [Sun, 17 Sep 2006 17:32:45 +0000 (17:32 +0000)]
fixed non-working edit button on course page for teachers, added explanation comments

18 years agoNew string
moodler [Sun, 17 Sep 2006 16:39:12 +0000 (16:39 +0000)]
New string

18 years agoFixed a typo
moodler [Sun, 17 Sep 2006 16:10:00 +0000 (16:10 +0000)]
Fixed a typo

18 years agoRewritten manual enrolment module using new core functions.
moodler [Sun, 17 Sep 2006 16:08:34 +0000 (16:08 +0000)]
Rewritten manual enrolment module using new core functions.

(except for the last part of cron function, which is still ugly)

18 years agoAdded new convenience funtions:
moodler [Sun, 17 Sep 2006 16:06:25 +0000 (16:06 +0000)]
Added new convenience funtions:

   get_default_course_role()  - gets default role for enrolment

   enrol_into_course() - enrols a person using the default role

18 years agoAdded email_welcome_message_to_user() to send course welcome emails
moodler [Sun, 17 Sep 2006 16:04:15 +0000 (16:04 +0000)]
Added email_welcome_message_to_user() to send course welcome emails

18 years agoDon't rely on the legacy capabilities to identify admins, use doanything
moodler [Sun, 17 Sep 2006 16:00:16 +0000 (16:00 +0000)]
Don't rely on the legacy capabilities to identify admins, use doanything

18 years agoPartial fix for missing deafult values in upgradesettings.php script - MDL-6577
skodak [Sun, 17 Sep 2006 12:11:23 +0000 (12:11 +0000)]
Partial fix for missing deafult values in upgradesettings.php script -  MDL-6577

18 years ago$CFG->defaultcourseroleid defines a site default for the role given to
moodler [Sun, 17 Sep 2006 09:22:33 +0000 (09:22 +0000)]
$CFG->defaultcourseroleid defines a site default for the role given to
people who enrol in the course.

$course->defaultrole defines the value for each course for what role
should be used in the same case.   Naturally it defaults to the site config
(when it is zero).

This role is retained even when the person editing the course settings
doesn't actually have that role in their list of assignable rights (however
they are prevented from actually switching to any such role themselves).

Note that enrol plugins are free to ignore these values and use whatever
roles they like.  Generally, though, they should respect these settings.

18 years agoRemoved the setting of default values. The default is now just zero.
moodler [Sun, 17 Sep 2006 09:08:47 +0000 (09:08 +0000)]
Removed the setting of default values.  The default is now just zero.

18 years agoinfinite loop prevention when unassigning recursively
skodak [Sun, 17 Sep 2006 08:53:57 +0000 (08:53 +0000)]
infinite loop prevention when unassigning recursively

18 years agorole assignment and unassignment now propagates to metacourses
skodak [Sun, 17 Sep 2006 08:42:42 +0000 (08:42 +0000)]
role assignment and unassignment now propagates to metacourses

18 years agoJust tidying a couple of functions
moodler [Sun, 17 Sep 2006 07:00:47 +0000 (07:00 +0000)]
Just tidying a couple of functions

18 years agobackupdata folder is no longer displayed in list of directories when setting up Direc...
skodak [Sun, 17 Sep 2006 06:49:26 +0000 (06:49 +0000)]
backupdata folder is no longer displayed in list of directories when setting up Directory Resource - partially related to  MDL-6280 ; and some other typo fixes; get_directory_list() no accepts also array of exluded files

18 years agoAdding defaultrole to course table
moodler [Sun, 17 Sep 2006 06:37:59 +0000 (06:37 +0000)]
Adding defaultrole to course table

18 years agoChanges required for MDL-6439 made to admin_sitesettext object
vinkmar [Sun, 17 Sep 2006 06:08:10 +0000 (06:08 +0000)]
Changes required for MDL-6439 made to admin_sitesettext object

18 years agoFixing up script tag for compliance
moodler [Sun, 17 Sep 2006 03:40:22 +0000 (03:40 +0000)]
Fixing up script tag for compliance

18 years agoTidying up coursebox teacher listing (no bullets)
moodler [Sun, 17 Sep 2006 03:38:04 +0000 (03:38 +0000)]
Tidying up coursebox teacher listing (no bullets)

18 years agoSort get_user_roles from most local to most general
moodler [Sun, 17 Sep 2006 03:33:22 +0000 (03:33 +0000)]
Sort get_user_roles from most local to most general

18 years agoUpdated tags file
moodler [Sun, 17 Sep 2006 03:29:56 +0000 (03:29 +0000)]
Updated tags file

18 years agore-merge of "Merged fix from 1.6 for Bug #5131 - RSS Feeds and Moving Discussions."
martinlanghoff [Sun, 17 Sep 2006 02:27:13 +0000 (02:27 +0000)]
re-merge of "Merged fix from 1.6 for Bug #5131 - RSS Feeds and Moving Discussions."

Originally by vyshane - got dropped accidentally in one of the biiiiig roles
commits.

18 years agofixed recursive backing up of backup folder when resource diretory reference is cours...
skodak [Sat, 16 Sep 2006 18:15:40 +0000 (18:15 +0000)]
fixed recursive backing up of backup folder when resource diretory reference is course files root - MDL-6280 ; merged from MOODLE_16_STABLE

18 years agobackupdata folder is not visible in directory resource any more, the backup files...
skodak [Sat, 16 Sep 2006 17:15:18 +0000 (17:15 +0000)]
backupdata folder is not visible in directory resource any more, the backup files were not downloadable, but they might be stored in browser cache when teacher and student were logged from the same browser and computer account - MDL-6280 ; merged from MOODLE_16_STABLE

18 years agobackupdata folder is not visible in directory resource any more, the backup files...
skodak [Sat, 16 Sep 2006 17:15:18 +0000 (17:15 +0000)]
backupdata folder is not visible in directory resource any more, the backup files were not downloadable, but they might be stored in browser cache when teacher and student were logged from the same browser and computer account - MDL-6280 ; merged from MOODLE_16_STABLE

18 years agoUpgrading print_course to use roles properly
moodler [Sat, 16 Sep 2006 15:23:41 +0000 (15:23 +0000)]
Upgrading print_course to use roles properly

Added list for the teacher names for better XHTML

18 years agoextending get_user_roles with more options and more returned info
moodler [Sat, 16 Sep 2006 15:22:55 +0000 (15:22 +0000)]
extending get_user_roles with more options and more returned info

18 years agoFixed hard-codes string
moodler [Sat, 16 Sep 2006 14:26:13 +0000 (14:26 +0000)]
Fixed hard-codes string

18 years agoJust some cleanups and removed notices
moodler [Sat, 16 Sep 2006 14:22:59 +0000 (14:22 +0000)]
Just some cleanups and removed notices

18 years agoRemoving unneeded functions, still needs some modernising
moodler [Sat, 16 Sep 2006 14:02:51 +0000 (14:02 +0000)]
Removing unneeded functions, still needs some modernising

18 years agoEnrolments working better now. The core part is done, just the plugins to go.
moodler [Sat, 16 Sep 2006 13:59:38 +0000 (13:59 +0000)]
Enrolments working better now.  The core part is done, just the plugins to go.

The enrolment plugins are now checked from load_user_capability()

18 years agoAdded new capability
moodler [Sat, 16 Sep 2006 13:56:24 +0000 (13:56 +0000)]
Added new capability

   moodle/role:viewhiddenassigns  - for people to see hidden assignments

18 years agoConverted deprecated get_teacher() to use new tables
moodler [Sat, 16 Sep 2006 13:55:30 +0000 (13:55 +0000)]
Converted deprecated get_teacher() to use new tables

18 years agoTidy up get_users_with_capability
moodler [Sat, 16 Sep 2006 13:54:57 +0000 (13:54 +0000)]
Tidy up get_users_with_capability

18 years agoFixed a notice
moodler [Sat, 16 Sep 2006 12:58:50 +0000 (12:58 +0000)]
Fixed a notice

18 years agoFixed up some bugs and notices when assigning roles in a user context
moodler [Sat, 16 Sep 2006 12:41:47 +0000 (12:41 +0000)]
Fixed up some bugs and notices when assigning roles in a user context

18 years agofixed unenrol_student() - now uses roles instead of user_students table
skodak [Sat, 16 Sep 2006 12:05:31 +0000 (12:05 +0000)]
fixed unenrol_student() - now uses roles instead of user_students table

18 years agofixed error message
skodak [Sat, 16 Sep 2006 12:02:02 +0000 (12:02 +0000)]
fixed error message

18 years agofixed uploaduser.php to work with role assignments and groups, new csv columns role1...
skodak [Sat, 16 Sep 2006 12:01:08 +0000 (12:01 +0000)]
fixed uploaduser.php to work with role assignments and groups, new csv columns role1...role5 accepting role ids + updated help file

18 years agocoverted deprecated get_group_students() to use legacy capability instead of user_stu...
skodak [Sat, 16 Sep 2006 06:22:32 +0000 (06:22 +0000)]
coverted deprecated get_group_students() to use legacy capability instead of user_students table

18 years agofixed $groupidsql in get_users_by_capability()
skodak [Sat, 16 Sep 2006 05:56:51 +0000 (05:56 +0000)]
fixed $groupidsql in get_users_by_capability()

18 years agoAutomatic installer.php lang files by installer_builder (20060916)
moodler [Sat, 16 Sep 2006 02:50:27 +0000 (02:50 +0000)]
Automatic installer.php lang files by installer_builder (20060916)

18 years agoDeleting deprecated methods of assigning people to courses
moodler [Fri, 15 Sep 2006 16:03:49 +0000 (16:03 +0000)]
Deleting deprecated methods of assigning people to courses

18 years agoWe don't need these any more (obsolete because of role assignment)
moodler [Fri, 15 Sep 2006 15:56:05 +0000 (15:56 +0000)]
We don't need these any more (obsolete because of role assignment)

18 years agoFixed up a typo
moodler [Fri, 15 Sep 2006 15:07:43 +0000 (15:07 +0000)]
Fixed up a typo

18 years agoVarious logic and capability fixes
moodler [Fri, 15 Sep 2006 15:04:38 +0000 (15:04 +0000)]
Various logic and capability fixes

18 years agoFixed a bad bug in get_user_roles :-)
moodler [Fri, 15 Sep 2006 14:56:32 +0000 (14:56 +0000)]
Fixed a bad bug in get_user_roles  :-)

18 years agoNew capability: moodle/user:viewhiddendetails
moodler [Fri, 15 Sep 2006 14:39:16 +0000 (14:39 +0000)]
New capability:   moodle/user:viewhiddendetails

18 years agoMDL-6041 - Proper fix that eliminates the magic number 99999 when getting lists of...
tjhunt [Fri, 15 Sep 2006 14:32:35 +0000 (14:32 +0000)]
MDL-6041 - Proper fix that eliminates the magic number 99999 when getting lists of studnets. Now, there is no arbitrary upper limit in the datalib functions, and sensible upper limits on pages that display lists of users. However, if you try to get all the site students, then get_students prints a warning in debug mode, telling you that you need to rethink your code.

Also a few more ISNULL()s eliminated.

And a typo role_assignment -> role_assignments.

18 years agoRename CONTEXT_USERID --> CONTEXT_USER for consistency
moodler [Fri, 15 Sep 2006 14:09:16 +0000 (14:09 +0000)]
Rename CONTEXT_USERID  -->  CONTEXT_USER for consistency

18 years agoThe ISNULL() function is a nasty mysql-ism. The standard SQL syntax is "xxx IS NULL...
tjhunt [Fri, 15 Sep 2006 14:00:30 +0000 (14:00 +0000)]
The ISNULL() function is a nasty mysql-ism. The standard SQL syntax is "xxx IS NULL". Even mysql supports this, whereas noone else supports the mysql syntax.

18 years agoSome SQL fixes
moodler [Fri, 15 Sep 2006 13:51:42 +0000 (13:51 +0000)]
Some SQL fixes

18 years agoFixed some notices
moodler [Fri, 15 Sep 2006 13:46:11 +0000 (13:46 +0000)]
Fixed some notices

18 years agoFixed some SQL error
moodler [Fri, 15 Sep 2006 13:42:40 +0000 (13:42 +0000)]
Fixed some SQL error

18 years agoGuest account could be getting the default role
moodler [Fri, 15 Sep 2006 13:28:18 +0000 (13:28 +0000)]
Guest account could be getting the default role

18 years agoSome random quote fixing
moodler [Fri, 15 Sep 2006 13:26:39 +0000 (13:26 +0000)]
Some random quote fixing

18 years agoFix typo.
tjhunt [Fri, 15 Sep 2006 13:18:28 +0000 (13:18 +0000)]
Fix typo.

18 years agoJust tidying
moodler [Fri, 15 Sep 2006 12:53:23 +0000 (12:53 +0000)]
Just tidying

18 years agoTidy up
ethem [Fri, 15 Sep 2006 12:35:08 +0000 (12:35 +0000)]
Tidy up