Ejemplo n.º 1
0
/**
 * Add url instance.
 * @param object $data
 * @param object $mform
 * @return int new url instance id
 */
function morsle_add_instance($data, $mform)
{
    global $CFG, $DB, $COURSE, $USER;
    require_once $CFG->dirroot . '/mod/morsle/locallib.php';
    require_once $CFG->dirroot . '/google/lib.php';
    require_once $CFG->dirroot . '/blocks/morsle/morsle.php';
    require_once $CFG->dirroot . '/repository/morsle/lib.php';
    require_once $CFG->dirroot . '/repository/morsle/morsle_class.php';
    $username = '******';
    $morsle = new morsle_google_auth($username, 'drive');
    $morsle->domain = '@luther.edu';
    $morsle->useremail = strtolower($COURSE->shortname) . $morsle->domain;
    $parameters = array();
    for ($i = 0; $i < 100; $i++) {
        $parameter = "parameter_{$i}";
        $variable = "variable_{$i}";
        if (empty($data->{$parameter}) or empty($data->{$variable})) {
            continue;
        }
        $parameters[$data->{$parameter}] = $data->{$variable};
    }
    $data->parameters = serialize($parameters);
    $displayoptions = array();
    if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
        $displayoptions['popupwidth'] = $data->popupwidth;
        $displayoptions['popupheight'] = $data->popupheight;
    }
    if (in_array($data->display, array(RESOURCELIB_DISPLAY_AUTO, RESOURCELIB_DISPLAY_EMBED, RESOURCELIB_DISPLAY_FRAME))) {
        $displayoptions['printheading'] = (int) (!empty($data->printheading));
        $displayoptions['printintro'] = (int) (!empty($data->printintro));
    }
    $data->displayoptions = serialize($displayoptions);
    $data->externalurl = morsle_fix_submitted_url($data->externalurl);
    // get the docid
    $docid = get_doc_id($data->externalurl);
    // get the read-only folder id
    //    $morsle = new repository_morsle();
    $title = strtolower($COURSE->shortname) . '-read';
    $owner = strtolower($COURSE->shortname) . '@' . $morsle->domain;
    $collectionid = get_collection($morsle, $title);
    // share resource with course user
    //	$base_feed = $morsle->docs_feed . $docid . '/acl';
    assign_permissions($morsle, $docid, 'writer', $USER->email, $base_feed);
    // link resource to the read-only folder
    add_file_tocollection($morsle, $docid, $collectionid);
    $data->timemodified = time();
    $data->id = $DB->insert_record('morsle', $data);
    return $data->id;
}
Ejemplo n.º 2
0
         }
         if (empty($_POST)) {
             $_POST['file1'] = $file;
         }
         $files = morsle_get_files($morsle, $wdir, $collectionid);
         setfilelist($_POST, $wdir, $owner, $files, $type);
         if (!empty($USER->filelist)) {
             foreach ($USER->filelist as $name => $value) {
                 if (!link_to_gdoc($name, $value->link, $value->type)) {
                     print_error("gdocslinkerror", "error");
                 } elseif (strpos($wdir, $deptstr) !== false || strpos($wdir, $userstr) !== false) {
                     // need to share resource with course user account
                     $acl_base_feed = 'https://docs.google.com/feeds/default/private/full/' . $value->id . '/acl';
                     assign_file_permissions($courseowner, 'writer', $owner, $acl_base_feed);
                     // need to place anything from departmental or instructors resources into the read-only collection so students can see them
                     add_file_tocollection($morsle, $readfolderid, $value->id);
                 }
             }
         }
     }
     notify(get_string('linkedfile', 'block_morsle'));
     // get ready to display the list of resources again
     clearfilelist();
     $files = morsle_get_files($morsle, $wdir, $collectionid);
     displaydir($wdir, $files);
     break;
 case "makedir":
     if ($name != '' && confirm_sesskey()) {
         $collections = explode("\r\n", $_POST['name']);
         foreach ($collections as $name) {
             if ($name !== '') {