.., * where can be any arbitrary designation, but is currently used for the interviewer name, * is the name of the entire project, and is a more specific project * designation for a group of participants, or a particular facility. This utility will search for the * first calendar it finds ending with ., therefore assuming that this * user only has one calendar with this name pattern. * * * Generally, when using the scheduler, a project supervisor will: * 1) Upload all the subject records to the Ensemble database using the Subject Record Importer. * 2) Create a calendar for each interviewer named ... * Each event in the calendars will be a single string that specifies the subject ID for that time. * 3) Share each calendar with the google accounts for the interviewer(s). * 4) Email the interviewers links to the scheduler with the appropriate $_GET variables * (ticket code, project name, subproject name). * * Each interviewer will then: * 1) Open the scheduler utility link with the associated $_GET variables. * 2) Authenticate with the Ensemble database and Google API if necessary * 3) Click on the subject name for the appointed time. This will initiate an Ensemble session and * automatically assign the subject ID to that session * * Author(s): * June 21, 2010 - Stefan Tomic, original version */ $session_timeout = 3600 * 4; //four hours include_once('../../include/variables.php'); //spoof QPI_SESSION_NAME to another session name, so that SESSION info isn't wiped out when starting QPI sessions. $QPI_SESSION_NAME = "ENSEMBLE_SCHEDULER"; $googleCalFuncsLoc = sprintf('%s/thirdparty/include/google_calendar_functions.php',$ENSEMBLE_QEI_QPI_DIR); if(!is_file($googleCalFuncsLoc)) { die(sprintf('ERROR: Missing file %s. Make sure to download this from the thirdparty repository. ' . 'See the Ensemble Wiki for details.',$googleCalFuncsLoc)); } session_set_cookie_params($session_timeout); //include variables for subject. This also runs session_start and sets the cookie. include_once('../../include/subject_includes.php'); //handle logout button if(isset($_POST) && isset($_POST['logout'])) { //unset all of the session variables. $_SESSION = array(); //delete the session cookie if it is set if(isset($_COOKIE[$QPI_SESSION_NAME])) setcookie($QPI_SESSION_NAME,'',time()-3600,'/',"",0); //destroy the session session_destroy(); } ?> Google Scheduler for Ensemble Google Calendar Scheduling"; $printUsage = FALSE; //at initial entry, make sure that required $_GET variables are assigned if(!isset($_GET['tc'])) { print('
ERROR: Missing ticket code (tc) GET variable
'); $printUsage = TRUE; } if(!isset($_GET['projName'])) { print('
ERROR: Missing project name (projName) GET variable
'); $printUsage = TRUE; } if(!isset($_GET['subProjName'])) { print('
ERROR: Missing sub-project name (subProjName) GET variable
'); $printUsage = TRUE; } if($printUsage) { print "

USAGE:
"; print (empty($_SERVER['HTTPS']))? "http://" : "https://"; printf("%s%s?tc=512fb1b3f336&projName=myProject&subProjName=pilot

",$_SERVER['HTTP_HOST'],$_SERVER['PHP_SELF']); print '

where "myProject" is the name of the project and "pilot" is the name of the sub-project.

'; die(); } include_once($googleCalFuncsLoc); $enc_key = subinfo_encryption_key(); $tc = $_GET['tc']; $projName = $_GET['projName']; $subProjName = $_GET['subProjName']; $secsPerDay = 24*60*60; $todayDateStr = date('Y-m-d'); $tomorrowDateStr = date('Y-m-d',time()+$secsPerDay); $todayNiceFmt = date('F j, Y'); $linkExpiryBufferSecs = 3600 * 2; //two hour buffer for exiration of links (to handle early appointments) //authenticate Google API if (!isset($_SESSION['googleSessionToken']) && !isset($_GET['token'])) { requestUserLogin('Please login to your Google Account.'); die(); } $client = getAuthSubHttpClient(); $gdataCal = new Zend_Gdata_Calendar($client); $calFeed = $gdataCal->getCalendarListFeed(); $calID = NULL; //Find calendar name with appropriate tags and set to current calendar $calendarPattern = sprintf('/^.+\.%s\.%s$/',$subProjName,$projName); foreach ($calFeed as $key=>$calendar) { if($key == 0) { //the first key corresponds to default calendar $defURL = $calendar->getID(); $defURLParts = explode('/',$defURL); $defURLEnd = $defURLParts[sizeof($defURLParts)-1]; preg_match('/^(.+)\%40.*/',$defURLEnd,$matches); $userID = $matches[1]; } $calTitle = $calendar->title->text; if(preg_match($calendarPattern,$calTitle)) $calID = $calendar->getId(); } print "

Logged in as " . $userID . "
"; print "

Schedule for " . $todayNiceFmt . "

"; if(is_null($calID)) { printf("
ERROR: Could not find calendar title ending with .%s.%s
",$subProjName,$projName); } else { $clientConfig = array('timeout'=> 60); $client->setConfig($clientConfig); //obtain the group user ID from the calendar title $groupPathArray = explode('/',$calID); $groupUID = urldecode($groupPathArray[sizeof($groupPathArray) - 1]); //Get calendar events for today. Translate subject IDs to subject names and provide links to start an survey for each one $eventsToday = returnEventsByDateTimeRange($client,$groupUID,$todayDateStr,'00:00',$tomorrowDateStr,'00:00'); $eventIdx = 0; foreach($eventsToday as $event) { foreach($event->when as $when) { $startDateTime = $when->getStartTime(); $startTimestamp = strtotime($startDateTime); $subjectID = $event->title->text; $expiry_datetime = $startTimestamp - $linkExpiryBufferSecs; //subtract expiry buffer to handle early appointments //only add this subject to $eventArray if a session was not completed yet. //eliminating completions only after the appointment time to deal with possible //duplicate scheduling of a single subject on a single day $sql_check_completion = sprintf("select subject_id,session.session_id from session left join ticket using (ticket_id) " . "where unix_timestamp(`end_datetime`) >= %d and " . "ticket_code = '%s' and subject_id = '%s'", $expiry_datetime, $tc,$subjectID); $completed_session = mysql_query($sql_check_completion) or report_error_form(mysql_error()); if(mysql_num_rows($completed_session) == 0) { $eventArray[$eventIdx]['subject_id'] = $subjectID; $eventArray[$eventIdx]['timestamp'] = $startTimestamp; //get subject name $sql_get_subInfo = sprintf("select aes_decrypt(`name_last`,'%s') as name_last, ". "aes_decrypt(`name_first`,'%s') as name_first, ". "subject_x_attribute.attribute_value_text as `wing` " . "from subject " . "left join subject_x_attribute using (subject_id) " . "left join attribute using (attribute_id) " . "where subject.subject_id = '%s' ". "and attribute.name = 'wing'", $enc_key,$enc_key,$subjectID); //echo $sql_get_subInfo."
"; //die(); $get_subInfo = mysql_query($sql_get_subInfo) or report_error_form(mysql_error()); $subInfo = mysql_fetch_assoc($get_subInfo); $eventArray[$eventIdx]['subject_exists'] = (mysql_num_rows($get_subInfo) > 0)? TRUE : FALSE; $eventArray[$eventIdx]['name_last'] = $subInfo['name_last']; $eventArray[$eventIdx]['name_first'] = $subInfo['name_first']; $eventArray[$eventIdx]['wing'] = $subInfo['wing']; $eventIdx++; } } } $nEvents = sizeof($eventArray); print "\n"; if($nEvents == 0) { print "
No participants remaining in the schedule today.
"; } else { print ""; } for ($iEvent = 0; $iEvent < $nEvents; $iEvent++) { $subFullName = sprintf("%s %s",$eventArray[$iEvent]['name_first'],$eventArray[$iEvent]['name_last']); $timeStr = date('g:i a',$eventArray[$iEvent]['timestamp']); $thisSubsWing = $eventArray[$iEvent]['wing']; $thisSubID = $eventArray[$iEvent]['subject_id']; $encSubID = mysql_aes_encrypt($thisSubID,$enc_key); if($eventArray[$iEvent]['subject_exists']) { $subLink = sprintf('%s',$questionnaire_location,$tc,$encSubID,$subFullName); printf("". "\n",$timeStr,$subLink,$thisSubsWing); } else { printf("\n",$timeStr,$thisSubID); } } print "
TimeNameWing
%s%s%s
%s
subject ID %s not found in database.
\n"; print "

 

"; } //parse the current URL and remove the token $_GET variable //this will be the target for the logout button (which should include all $_GET variables except token) $URLParts = parse_url(getCurrentURL()); $URLParts['query'] = preg_replace('/\&token=[^&]*/','',$URLParts['query']); $logoutTarget = $URLParts['scheme'] . "://" . $URLParts['host'] . $URLParts['path'] . "?" . $URLParts['query']; printf("
",$logoutTarget); print ""; print ""; print "
"; ?>