print_error('errorbaddirectorylocation', 'local_vmoodle');
     if ($automation) {
         return -1;
     }
 }
 if (!filesystem_is_dir('vmoodle', $CFG->dataroot)) {
     mkdir($CFG->dataroot . '/vmoodle');
 }
 if ($vmoodlestep == 0) {
     // Create directories, if necessary.
     if (!filesystem_is_dir($relative_datadir, $CFG->dataroot)) {
         mkdir($absolute_datadir, 0777, true);
     } else {
         filesystem_clear_dir($relative_datadir, false, $CFG->dataroot);
     }
     if (!filesystem_is_dir($relative_sqldir, $CFG->dataroot)) {
         mkdir($absolute_sqldir, 0777, true);
     }
     if (empty($automation)) {
         echo $OUTPUT->header();
         echo $OUTPUT->box(get_string('vmoodlesnapshot1', 'local_vmoodle'));
         echo $OUTPUT->continue_button(new moodle_url('/local/vmoodle/view.php', array('view' => 'management', 'what' => 'snapshot', 'step' => 1, 'wwwroot' => $wwwroot)));
         echo $OUTPUT->footer();
         die;
     } else {
         // Chain following steps
         $vmoodlestep++;
     }
 }
 if ($vmoodlestep > 0) {
     if ($wwwroot == $CFG->wwwroot) {
예제 #2
0
/**
 * Checks physical availability of the Vmoodle.
 * @param object $vmoodle The Vmoodle object.
 * @return boolean If true, the Vmoodle is physically available.
 */
function vmoodle_check_installed($vmoodle)
{
    return filesystem_is_dir($vmoodle->vdatapath, '');
}
예제 #3
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);
}
예제 #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);
 }
/**
* 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}");
            }
        }
    }
}