/**
 * Given an object containing all the necessary data, 
 * (defined by the form in mod.html) this function 
 * will update an existing instance with new data.
 * @uses $COURSE, $DB
 *
 */
function flashcard_update_instance($flashcard)
{
    global $COURSE, $DB;
    $flashcard->timemodified = time();
    $flashcard->id = $flashcard->instance;
    // Make physical repository for customisation
    if (!file_exists($COURSE->id . '/moddata/flashcard/' . $flashcard->id)) {
        filesystem_create_dir($COURSE->id . '/moddata/flashcard/' . $flashcard->id, FS_RECURSIVE);
    }
    if (!isset($flashcard->starttimeenable)) {
        $flashcard->starttime = 0;
    }
    if (!isset($flashcard->endtimeenable)) {
        $flashcard->endtime = 0;
    }
    return $DB->update_record('flashcard', $flashcard);
}
Exemplo n.º 2
0
/**
* Given an object containing all the necessary data, 
*(defined by the form in mod.html) this function 
* will update an existing instance with new data.
*
*/
function poodllflashcard_update_instance($flashcard)
{
    global $COURSE;
    $flashcard->timemodified = time();
    $flashcard->id = $flashcard->instance;
    // Make physical repository for customisation
    if (!file_exists($COURSE->id . '/moddata/poodllflashcard/' . $flashcard->id)) {
        filesystem_create_dir($COURSE->id . '/moddata/poodllflashcard/' . $flashcard->id, FS_RECURSIVE);
    }
    // update first deck with questions that might be added
    if (isset($flashcard->forcereload) && $flashcard->forcereload) {
        poodllflashcard_import($flashcard);
    }
    if (!isset($flashcard->starttimeenable)) {
        $flashcard->starttime = 0;
    }
    if (!isset($flashcard->endtimeenable)) {
        $flashcard->endtime = 0;
    }
    return update_record('poodllflashcard', $flashcard);
}
Exemplo n.º 3
0
     $erroritem->message = get_string('shortnameexists', 'local_vmoodle');
     $erroritem->on = 'shortname';
     $errors[] = $erroritem;
 } elseif ($DB->get_record('local_vmoodle', array('vhostname' => $form->vhostname))) {
     $erroritem->message = get_string('hostnameexists', 'local_vmoodle');
     $erroritem->on = 'shortname';
     $errors[] = $erroritem;
 } else {
     // cannot install anything when editing data.
     // installing a vmoodle needs delete/add procedure
     // the update function is only provided for fixing
     // wring parameter values that have not influence upon
     // physical bindings.
     if ($form->id == '') {
         if (!file_exists($form->vdatapath)) {
             if (!filesystem_create_dir($form->vdatapath, FS_RECURSIVE, $CFG->local_vmoodle_vdatapathbase)) {
                 $erroritem->message = get_string('couldnotcreatedataroot', 'local_vmoodle') . " " . $form->vdatapath;
                 $erroritem->on = 'vdatapath';
                 $errors[] = $erroritem;
             } else {
                 filesystem_copy_tree($CFG->dirroot . '/local/vmoodle/' . $v . '_vmoodledata', $vmoodle->vdatapath, '');
             }
         } else {
             $done[] = 'datapath';
             print_string('datapathcreated', 'local_vmoodle');
             echo '<br/>';
         }
         /// drop any previous database that could be on the way
         $erroritem = vmoodle_drop_database($form);
         if (!$erroritem) {
             $errors[] = $erroritem;
Exemplo n.º 4
0
 /**
 * copy a file creating all path on the way if needed
 * @param string $source the source path from dataroot
 * @param string $dest the dest path from dataroot
 * @param string $pathbase the base path
 */
 function filesystem_copy_file($source, $dest, $pathbase = null)
 {
     global $CFG;
     if (is_null($pathbase)) {
         $pathbase = $CFG->dataroot . '/';
     } elseif ($pathbase === '') {
         $pathbase = '';
     } else {
         $pathbase = $pathbase . '/';
     }
     if (@$CFG->filedebug) {
         mtrace("copying file <i>{$pathbase}{$source}</i> to <i>{$pathbase}{$dest}</i><br/>");
     }
     if (!filesystem_file_exists($source, $pathbase)) {
         return -1;
     }
     $parts = pathinfo($dest);
     if (!filesystem_is_dir($parts['dirname'], $pathbase)) {
         filesystem_create_dir($parts['dirname'], $pathbase);
     }
     return copy($pathbase . $source, $pathbase . $dest);
 }
// Retrieve parameters for database connection test.
$dataroot = required_param('dataroot', PARAM_TEXT);
if (is_dir($dataroot)) {
    $DIR = opendir($dataroot);
    $cpt = 0;
    $hasfiles = false;
    while (($file = readdir($DIR)) && !$hasfiles) {
        if (!preg_match("/^\\./", $file)) {
            $hasfiles = true;
        }
    }
    closedir($DIR);
    if ($hasfiles) {
        echo $OUTPUT->box(get_string('datapathnotavailable', 'local_vmoodle'), 'error');
    } else {
        echo get_string('datapathavailable', 'local_vmoodle');
    }
} else {
    if (filesystem_create_dir('', true, $dataroot)) {
        echo get_string('datapathcreated', 'local_vmoodle');
    } else {
        echo $OUTPUT->box(get_string('couldnotcreatedataroot', 'local_vmoodle', $dataroot), 'error');
    }
    echo stripslashes($dataroot);
}
echo "</p>";
$closestr = get_string('closewindow', 'local_vmoodle');
echo '<center>';
echo '<input type="button" name="close" value="' . $closestr . '" onclick="self.close();" />';
echo '</center>';
echo $OUTPUT->footer();
Exemplo n.º 6
0
/**
* copy a file creating all path on the way if needed
* @param source the source path from dataroot
* @param dest the dest path from dataroot
*/
function filesystem_copy_file($source, $dest)
{
    global $CFG;
    if ($CFG->debug > 8) {
        mtrace("copying file <i>{$source}</i> to <i>{$dest}</i><br/>");
    }
    if (!filesystem_file_exists($source)) {
        return -1;
    }
    $parts = pathinfo($dest);
    if (!filesystem_is_dir($parts['dirname'])) {
        filesystem_create_dir($parts['dirname']);
    }
    return copy($CFG->dataroot . '/' . $source, $CFG->dataroot . '/' . $dest);
}
/**
* stores in database the element values
* @uses $CFG
* @param object $issue
*/
function tracker_recordelements(&$issue)
{
    global $CFG, $COURSE;
    $keys = array_keys($_POST);
    // get the key value of all the fields submitted
    $keys = preg_grep('/element./', $keys);
    // filter out only the element keys
    $filekeys = array_keys($_FILES);
    // get the key value of all the fields submitted
    $filekeys = preg_grep('/element./', $filekeys);
    // filter out only the element keys
    $keys = array_merge($keys, $filekeys);
    foreach ($keys as $key) {
        preg_match('/element(.*)$/', $key, $elementid);
        $elementname = $elementid[1];
        $sql = "\n            SELECT \n              e.id as elementid,\n              e.type as type\n            FROM\n                {$CFG->prefix}tracker_elementused eu,\n                {$CFG->prefix}tracker_element e\n            WHERE\n                eu.elementid = e.id AND\n                e.name = '{$elementname}' AND\n                eu.trackerid = {$issue->trackerid} \n        ";
        $attribute = get_record_sql($sql);
        $attribute->timemodified = $issue->datereported;
        $values = optional_param($key, '', PARAM_CLEANHTML);
        $attribute->issueid = $issue->id;
        $attribute->trackerid = $issue->trackerid;
        /// For those elements where more than one option can be selected
        if (is_array($values)) {
            foreach ($values as $value) {
                $attribute->elementitemid = $value;
                $attributeid = insert_record('tracker_issueattribute', $attribute);
                if (!$attributeid) {
                    error("Could not submit issue(s) attribute(s): issue:{$issue->id} issueid:{$elementid['1']} elementitemid:{$attribute->elementitemid}");
                }
            }
        } else {
            //For the rest of the elements that can only support one answer
            if ($attribute->type != 'file') {
                require_once $CFG->libdir . '/uploadlib.php';
                $attribute->elementitemid = $values;
                $attributeid = insert_record('tracker_issueattribute', $attribute);
            } else {
                $uploader = new upload_manager($key, false, false, $COURSE->id, true, 0, true);
                $uploader->preprocess_files();
                $newfilename = $uploader->get_new_filename();
                $encodedfilename = '';
                if (!empty($newfilename)) {
                    $encodedfilename = md5(time()) . '_' . $newfilename;
                    $storebase = "{$COURSE->id}/moddata/tracker/{$issue->trackerid}/{$issue->id}";
                    if (!filesystem_is_dir($storebase)) {
                        filesystem_create_dir($storebase, FS_RECURSIVE);
                    }
                    $uploader->save_files($storebase);
                    filesystem_move_file($storebase . '/' . $newfilename, $storebase . '/' . $encodedfilename);
                    $attribute->elementitemid = $encodedfilename;
                    $attributeid = insert_record('tracker_issueattribute', $attribute);
                }
            }
            if (empty($attributeid)) {
                error("Could not submit issue attribute: issue:{$issue->id} elementid:{$elementid['1']} elementitemid:{$attribute->elementitemid}");
            }
        }
    }
}