/**
  * Hydrate a taoresource_entry object reading by identifier
  * 
  * @param identifier   hash, sha1 hash identifier
  * @return taoresource_entry object
  */
 static function get_by_identifier($identifier)
 {
     return $taoresource_entry = taoresource_entry::read($identifier);
 }
Example #2
0
/**
 * This constructs the course module information the gets used
 * in the course module list.
 */
function taoresource_get_coursemodule_info($coursemodule)
{
    /// Given a course_module object, this function returns any
    /// "extra" information that may be needed when printing
    /// this activity in a course listing.
    ///
    /// See get_array_of_activities() in course/lib.php
    ///
    global $CFG;
    $info = NULL;
    if ($taoresource = get_record("taoresource", "id", $coursemodule->instance, '', '', '', '', 'id, popup, identifier, type, name')) {
        $taoresource_entry = taoresource_entry::read($taoresource->identifier);
        $info = new object();
        $info->name = $taoresource->name;
        if (!empty($taoresource->popup)) {
            $info->extra = urlencode("onclick=\"this.target='taoresource{$taoresource->id}'; return " . "openpopup('/mod/taoresource/view.php?inpopup=true&id=" . $coursemodule->id . "','taoresource{$taoresource->id}','{$taoresource->popup}');\"");
        }
        require_once $CFG->libdir . '/filelib.php';
        if ($taoresource->type == 'file') {
            if (!$taoresource_entry) {
                $icon = 'unknown.gif';
            } else {
                $icon = mimeinfo("icon", $taoresource_entry->url);
            }
            if ($icon != 'unknown.gif') {
                $info->icon = "f/{$icon}";
            } else {
                $info->icon = "f/web.gif";
            }
        } else {
            if ($taoresource->type == 'directory') {
                $info->icon = "f/folder.gif";
            }
        }
    }
    return $info;
}
Example #3
0
function taoresource_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //Now, start building the TAORESOURCE record structure
        $taoresource = new object();
        $taoresource->course = $restore->course_id;
        $taoresource->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $taoresource->type = $info['MOD']['#']['TYPE']['0']['#'];
        $taoresource->identifier = backup_todb($info['MOD']['#']['IDENTIFIER']['0']['#']);
        $taoresource->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']);
        $taoresource->alltext = backup_todb($info['MOD']['#']['ALLTEXT']['0']['#']);
        $taoresource->popup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
        $taoresource->options = backup_todb($info['MOD']['#']['OPTIONS']['0']['#']);
        $taoresource->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
        //The structure is equal to the db, so insert the taoresource
        $newid = insert_record("taoresource", $taoresource);
        // restore any associated files and the taoresource_entry ...
        if ($taoresource->type == 'file') {
            // if the user wants to, then lets try restoring index entries anyway, and even then we dont overwrite them
            if ($CFG->taoresource_restore_index && !empty($info['MOD']['#']['ENTRIES']['0']['#'])) {
                $trentries_data = $info['MOD']['#']['ENTRIES']['0']['#']['ENTRY'];
                foreach ($trentries_data as $tre_data) {
                    // Only grab this particular one - we don't know if this was a complete backup or not
                    $taoresource_entry = taoresource_entry::read($tre_data['#']['IDENTIFIER']['0']['#']);
                    if ($taoresource_entry) {
                        continue;
                    }
                    if (!empty($tre_data['#']['FILE']['0']['#'])) {
                        $tre_data['#']['URL']['0']['#'] = preg_replace('/\\$\\@TAORESOURCEINDEX\\@\\$/', $CFG->wwwroot, $tre_data['#']['URL']['0']['#']);
                    }
                    // restore the entry
                    taoresource_restore_mods_one_index($tre_data);
                    // restore files if necessary
                    taoresource_restore_files($mod->id, $newid, $taoresource_entry, $restore);
                }
            } else {
                // does the physical resource entry exist?  We only resotre if it doesn't exist - we dont overwrite
                $taoresource_entry = taoresource_entry::read($taoresource->identifier);
                if (!$taoresource_entry && !empty($info['MOD']['#']['ENTRIES']['0']['#'])) {
                    $trentries_data = $info['MOD']['#']['ENTRIES']['0']['#']['ENTRY'];
                    foreach ($trentries_data as $tre_data) {
                        // Only grab this particular one - we don't know if this was a complete backup or not
                        if ($tre_data['#']['IDENTIFIER']['0']['#'] != $taoresource->identifier) {
                            continue;
                        }
                        // we are not restoring the index locally so we must reove the file reference
                        // this will force the resource to look to the original source
                        $tre_data['#']['FILE']['0']['#'] = '';
                        // restore the entry
                        taoresource_restore_mods_one_index($tre_data);
                        // restore files if necessary
                        taoresource_restore_files($mod->id, $newid, $taoresource_entry, $restore);
                    }
                }
            }
        }
        // does the physical resource entry exist?
        $taoresource_entry = taoresource_entry::read($taoresource->identifier);
        if (!$taoresource_entry) {
            print_error('cannotrestore', 'taoresource', '', $taoresource->identifier);
        }
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "taoresource") . " \"" . format_string(stripslashes($taoresource->name), true) . "\"</li>";
        }
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Example #4
0
 /**
  * TODO document
  */
 function setup_elements(&$mform)
 {
     global $CFG, $USER, $TAORESOURCE_WINDOW_OPTIONS;
     $taoresource_entry;
     $add = optional_param('add', 0, PARAM_ALPHA);
     $update = optional_param('update', 0, PARAM_INT);
     $return = optional_param('return', 0, PARAM_BOOL);
     //return to course/view.php if false or mod/modname/view.php if true
     $type = optional_param('type', '', PARAM_ALPHANUM);
     $section = optional_param('section', PARAM_INT);
     $course = optional_param('course', PARAM_INT);
     if (!empty($add)) {
         $entry_id = optional_param('entry_id', false, PARAM_INT);
         // Have we selected a resource yet ?
         if (empty($entry_id)) {
             redirect($CFG->wwwroot . "/mod/taoresource/search.php?course={$course}&section={$section}&type={$type}&add={$add}&return={$return}");
         } else {
             if (!($taoresource_entry = taoresource_entry::read_by_id($entry_id))) {
                 error('Invalid taoresource_entry::id supplied: ' . $entry_id);
             }
         }
     } else {
         if (!empty($update)) {
             if (!($cm = get_coursemodule_from_id('taoresource', $update))) {
                 error('Course Module ID was incorrect');
             }
             if (!($resource = get_record('taoresource', 'id', $cm->instance))) {
                 error('Resource ID was incorrect');
             }
             if (!($taoresource_entry = taoresource_entry::read($resource->identifier))) {
                 error('Invalid taoresource_entry::identifier supplied: ' . $resource->identifier);
             }
         }
     }
     $this->set_parameters();
     // set the parameter array for the form
     $mform->addElement('hidden', 'entry_id', $taoresource_entry->id);
     $mform->addElement('hidden', 'identifier', $taoresource_entry->identifier);
     $mform->setDefault('name', stripslashes_safe($taoresource_entry->title));
     $mform->setDefault('description', stripslashes_safe($taoresource_entry->description));
     $location = $mform->addElement('static', 'origtitle', get_string('title', 'taoresource') . ': ', stripslashes_safe($taoresource_entry->title));
     $strpreview = get_string('preview', 'taoresource');
     $link = "<a href=\"{$CFG->wwwroot}/mod/taoresource/view.php?identifier={$taoresource_entry->identifier}&amp;inpopup=true\" " . "onclick=\"this.target='resource{$taoresource_entry->id}'; return openpopup('/mod/taoresource/view.php?inpopup=true&amp;identifier={$taoresource_entry->identifier}', " . "'resource{$taoresource_entry->id}','resizable=1,scrollbars=1,directories=1,location=0,menubar=0,toolbar=0,status=1,width=800,height=600');\">(" . $strpreview . ")</a>";
     $location = $mform->addElement('static', 'url', get_string('location', 'taoresource') . ': ', $link);
     $searchbutton = $mform->addElement('submit', 'searchtaoresource', get_string('searchtaoresource', 'taoresource'));
     $buttonattributes = array('title' => get_string('searchtaoresource', 'taoresource'), 'onclick' => " window.location.href ='" . $CFG->wwwroot . "/mod/taoresource/search.php?course={$this->course->id}&section={$section}&type={$type}&add={$add}&return={$return}" . "'; return false;");
     $searchbutton->updateAttributes($buttonattributes);
     $mform->addElement('header', 'displaysettings', get_string('display', 'resource'));
     $mform->addElement('checkbox', 'forcedownload', get_string('forcedownload', 'resource'));
     $mform->setHelpButton('forcedownload', array('forcedownload', get_string('forcedownload', 'resource'), 'resource'));
     $mform->disabledIf('forcedownload', 'windowpopup', 'eq', 1);
     $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource'));
     $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions);
     $mform->setDefault('windowpopup', empty($CFG->taoresource_popup) ? 1 : 0);
     $mform->disabledIf('windowpopup', 'forcedownload', 'checked');
     $mform->addElement('checkbox', 'framepage', get_string('keepnavigationvisible', 'resource'));
     $mform->setHelpButton('framepage', array('frameifpossible', get_string('keepnavigationvisible', 'resource'), 'resource'));
     $mform->setDefault('framepage', 0);
     $mform->disabledIf('framepage', 'windowpopup', 'eq', 1);
     $mform->disabledIf('framepage', 'forcedownload', 'checked');
     $mform->setAdvanced('framepage');
     foreach ($TAORESOURCE_WINDOW_OPTIONS as $option) {
         if ($option == 'height' or $option == 'width') {
             $mform->addElement('text', $option, get_string('new' . $option, 'resource'), array('size' => '4'));
             $mform->setDefault($option, $CFG->{'taoresource_popup' . $option});
             $mform->disabledIf($option, 'windowpopup', 'eq', 0);
         } else {
             $mform->addElement('checkbox', $option, get_string('new' . $option, 'resource'));
             $mform->setDefault($option, $CFG->{'taoresource_popup' . $option});
             $mform->disabledIf($option, 'windowpopup', 'eq', 0);
         }
         $mform->setAdvanced($option);
     }
     $mform->addElement('header', 'parameters', get_string('parameters', 'resource'));
     $options = array();
     $options['-'] = get_string('chooseparameter', 'resource') . '...';
     $optgroup = '';
     foreach ($this->parameters as $pname => $param) {
         if ($param['value'] == '/optgroup') {
             $optgroup = '';
             continue;
         }
         if ($param['value'] == 'optgroup') {
             $optgroup = $param['langstr'];
             continue;
         }
         $options[$pname] = $optgroup . ' - ' . $param['langstr'];
     }
     for ($i = 0; $i < $this->maxparameters; $i++) {
         $parametername = "parameter{$i}";
         $parsename = "parse{$i}";
         $group = array();
         $group[] =& $mform->createElement('text', $parsename, '', array('size' => '12'));
         //TODO: accessiblity
         $group[] =& $mform->createElement('select', $parametername, '', $options);
         //TODO: accessiblity
         $mform->addGroup($group, 'pargroup' . $i, get_string('variablename', 'resource') . '=' . get_string('parameter', 'resource'), ' ', false);
         $mform->setAdvanced('pargroup' . $i);
         $mform->setDefault($parametername, '-');
     }
 }