*/ //TODO: convert to objective php require_once '../../config.php'; require_once $CFG->dirroot . '/google/lib.php'; require_once $CFG->dirroot . '/google/gauth.php'; require_once $CFG->dirroot . '/blocks/morsle/morslelib.php'; global $DB; if (!($CONSUMER_KEY = get_config('blocks/morsle', 'consumer_key'))) { exit; } define("COURSEID", 1196); // define("SHORTNAME",'NEW-HPE-PORTFOLIO'); // define("OWNER",'*****@*****.**'); // define("OWNER",'*****@*****.**'); // establish authorization for gapps data $auth = clientauth(); $morsle = new morsle(); $morsle->get_aliases(); // setup other variables used by libraries $morsle->shortname = 'HPE-PORTFOLIO'; $morsle->courseid = COURSEID; $morsle->portfoliobase = 'HPE Portfolio Site for '; $morsle->user = '******'; $morsle->params = array('xoauth_requestor_id' => $morsle->user, 'max-results' => 500); $morsle->groupname = $morsle->shortname . '-group'; $morsle->groupfullname = $morsle->groupname . '@' . $morsle->domain; $morsle->visible = 1; $record = $DB->get_record('morsle_active', array('courseid' => COURSEID)); $morsle->sitename = substr($record->siteid, strpos($record->siteid, $morsle->domain), 100); // get all information for all members of the course $rosters = $morsle->get_full_roster($morsle->courseid, 1);
$service = 'wise'; } elseif (strpos($exportlink, 'download/spreadsheets') > 0) { $exformat = 'xls'; $exportlink .= '&exportFormat=' . $exformat . '&format=' . $exformat; $service = 'wise'; } elseif (strpos($exportlink, 'download/presentations') > 0) { $exformat = 'ppt'; $exportlink .= '&exportFormat=' . $exformat . '&format=' . $exformat; $service = 'wise'; } else { if (isset($e) && isset($gd)) { $service = 'writely'; $exportlink .= '&e=' . $e . '&gd=' . $gd; } else { echo "Unable to export file at this time"; exit; } } $title .= strpos($title, '.') ? '' : '.' . $exformat; $morslerec = get_record('morsle_active', 'shortname', $shortname); $userpassword = rc4decrypt($morslerec->password); if (!($CONSUMER_KEY = get_config('blocks/morsle', 'consumer_key'))) { exit; } $username = $shortname . '@' . $CONSUMER_KEY; // get client authorization $auth = clientauth($username, $userpassword, $service); $headers = "Authorization: GoogleLogin auth=" . $auth; $base_feed = $exportlink; $response = send_request('GET', $base_feed, $headers, null, null, '3.0'); send_file($response->response, $title, 'default', 1, true, false, $response->info['content_type']);
function calmassdelete() { global $CFG, $DB, $success; // require_once('../../../config.php'); require_once $CFG->dirroot . '/google/lib.php'; require_once $CFG->dirroot . '/google/gauth.php'; //$chewon = $DB->get_records('morsle_active'); // get course record from which events are to be deleted $coursesql = 'SELECT ma.* FROM mdl_morsle_active ma JOIN mdl_course c on c.id = ma.courseid WHERE c.id = 692'; $courseid = $DB->get_record_sql($coursesql); // authenticate $service = 'cl'; $owner = $courseid->shortname . '@' . $this->domain; $calowner = str_replace('@', '%40', $owner); $password = morsle_decode($courseid->password); $this->authstring = "Authorization: GoogleLogin auth=" . clientauth($owner, $password, $service); // $password = rc4decrypt($courseid->password); // set up get of feed $base_feed = $this->cal_feed; $counter = 0; while ($counter < 100) { $response = send_request('GET', $base_feed, $this->authstring, null, null, '2.0'); if ($success) { $feed = simplexml_load_string($response->response); if (!isset($feed->entry)) { $counter = 101; } else { $counter++; foreach ($feed->entry as $entry) { $event->googleid = substr($entry->id, strpos($entry->id, 'events/') + 7, 50); $delete_feed = "https://www.google.com/calendar/feeds/default/private/full/{$event->googleid}"; $response = send_request('DELETE', $delete_feed, $this->authstring, null, null, '2.0'); if ($success) { echo $entry->title . ' DELETED <br />'; } } } } } }
if (!($CONSUMER_KEY = get_config('blocks/morsle', 'consumer_key'))) { exit; } $curtime = time(); // at this point you need to query to get all the events that have been deleted from Reason and need to be deleted from Google // your record in Reason must store the Google calendar event id (noted below as $event->googleid) $eventsql = '<SQL STATEMEMT>'; $deleted = get_records_sql($eventsql); // probably don't have this function but something similar // ACTUALLY BECAUSE OF THE WAY THIS IS HANDLED YOU DON'T NEED AN ADMIN ACCOUNT, JUST THE CREDENTIALS FOR THE USER WHOSE ACCOUNT THE CALENDAR IS TIED TO // THIS ALL ASSUMES THE CALENDAR IS THE PRIMARY CALENDAR FOR THE USER SPECICIFIED $owner = '<AN ADMINISTRATIVE ACCOUNT EMAIL ADDRESS>'; $calowner = str_replace('@', '%40', $owner); // url encoded $password = '******'; $auth = clientauth($owner, $password, $service); $authstring = "Authorization: GoogleLogin auth=" . $auth; $headers = array($authstring, "GData-Version: 2.0"); foreach ($deleted as $event) { if ($event->courseid == $coursekey) { // TODO: this needs to be the edit link for the event $base_feed = "https://www.google.com/calendar/feeds/{$calowner}/private/full/{$event->googleid}"; $response = send_request('DELETE', $base_feed, $authstring, null, null, '2.0'); // only deleted from morsle_event if successfully deleted from google if ($response->info['http_code'] == 200) { $feed = simplexml_load_string($response->response); // delete your records from REASON $success = delete_records('morsle_event', 'eventid', $event->eventid); // log the action add_to_log($coursekey, 'Morsle', "Added", null, "{$event->name} added to calendar eventtime = {$eventtime}"); }