Ensemble Participant Manager"; $tc = isset($_GET['tc'])? $_GET['tc'] : $_POST['tc'] ; //obtain current get string to pass back to this script if desired. $getStr = sprintf("?tc=%s",$tc); if(isset($_GET['id'])) { $getStr = $getStr . sprintf("&id=%s",$_GET['id']); } $printUsage = FALSE; //at initial entry, make sure that required $_GET variables are assigned if(empty($tc)) { print('
ERROR: Missing ticket code (tc) GET variable
'); $printUsage = TRUE; } if($printUsage) { print "

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

",$_SERVER['HTTP_HOST'],$_SERVER['PHP_SELF']); die(); } $enc_key = subinfo_encryption_key(); //authenticate the participant if username and password entered or if it is stored in $_SESSION if($login_posted || $login_saved) { $username = ($login_posted)? $_POST['username'] : $_SESSION['pman_username']; $passcode = ($login_posted)? $_POST['passcode'] : mysql_aes_decrypt($_SESSION['pman_passcode'],$enc_key); $sql_check_passcode = sprintf("select aes_decrypt(`passphrase`,'%s') as passphrase from subject " . "left join subject_x_attribute using (subject_id) left join attribute using (attribute_id) ". "where subject_id = '%s' and attribute.name = 'person_type' and ". "attribute_value_text = 'caregiver'",$enc_key,$username); $row_passcode = mysql_select($sql_check_passcode); if(strcmp($row_passcode['passphrase'],$passcode) != 0) { print "
Incorrect Username/Passcode Entered.
"; unset($_SESSION['pman_username']); unset($_SESSION['pman_passcode']); unset($_SESSION['wing_assignment']); } elseif($login_posted) { $_SESSION['pman_username'] = $_POST['username']; $_SESSION['pman_passcode'] = mysql_aes_encrypt($_POST['passcode'],$enc_key); } } //if username and password are not stored in $_SESSION, display the login form if(!isset($_SESSION['pman_username']) || !isset($_SESSION['pman_passcode'])) { //display username and password fields printf("
",$_SERVER['PHP_SELF'].$getStr); printf(""); print "\n"; if(isset($_GET['id'])) { //see if this ID is associated with a caregiver. If not, enter the standard username entry box. $sql_check_caregiver = sprintf("select attribute_value_text from subject_x_attribute left join ". "attribute using (attribute_id) where subject_id = '%s' ". " and attribute.name = 'person_type' and ". " attribute_value_text = 'caregiver'",$_GET['id']); $check_caregiver = mysql_query($sql_check_caregiver) or die(mysql_error()); if(mysql_num_rows($check_caregiver) > 0) $useGETID = TRUE; else $useGETID = FALSE; } //if we have determined that the ID belongs to a caregiver, use this if($useGETID) { printf("",$_GET['id']); $sub_name = get_subject_name($_GET['id']); printf("",$sub_name['name_first']); } else { print ""; printf(""); } print ""; print ""; print ""; print ""; die(); } $current_user_name = get_subject_name($_SESSION['pman_username']); printf("

Logged in as %s

",$current_user_name['name_first']); if(isset($_POST['wing_assignment'])) { $_SESSION['wing_assignment'] = $_POST['wing_assignment']; } if(!isset($_SESSION['wing_assignment'])) { //obtain the current user's "wing" $sql_get_wing = sprintf("select attribute_value_text from subject_x_attribute left join attribute using (attribute_id)". " where subject_id = '%s' and attribute.name = 'wing'",$_SESSION['pman_username']); $get_wing = mysql_query($sql_get_wing) or die(mysql_error()); //if this caregiver doesn't have a wing associated with it, then provide a list of wings to choose from if(mysql_num_rows($get_wing) == 0) { $wing_list = file('wing_list.txt',FILE_IGNORE_NEW_LINES) or die('ERROR: wing_list.txt does not exist. Please contact the system administrator.'); print "Please select your wing
"; printf("",$_SERVER['PHP_SELF'].$getStr); printf("\n"; print ""; print "\n"; die(); } else { $row_get_wing = mysql_fetch_assoc($get_wing); $_SESSION['wing_assignment'] = $row_get_wing['attribute_value_text']; } } //find all subjects that match the current user's wing, person_type=resident, and enrolled=1 $sql_get_subject_wing = sprintf("select subject_id, name_last, name_first from subject_x_attribute left join " . " attribute using (attribute_id) left join subject using (subject_id) where ". " attribute.name = 'wing' and attribute_value_text = '%s'",$_SESSION['wing_assignment']); $get_subject_wing = mysql_query($sql_get_subject_wing) or die(mysql_error()); while($subject_wing = mysql_fetch_assoc($get_subject_wing)) { $sub_wing_list[] = $subject_wing['subject_id']; } $sql_get_subject_resident = sprintf("select subject_id, name_last, name_first from subject_x_attribute left join " . " attribute using (attribute_id) left join subject using (subject_id) where ". " attribute.name = 'person_type' and attribute_value_text = 'resident'"); $get_subject_resident = mysql_query($sql_get_subject_resident) or die(mysql_error()); while($subject_resident = mysql_fetch_assoc($get_subject_resident)) { $sub_wing_resident[] = $subject_resident['subject_id']; } $sql_get_subject_enrolled = sprintf("select subject_id, name_last, name_first from subject_x_attribute left join " . " attribute using (attribute_id) left join subject using (subject_id) where ". " attribute.name = 'enrolled' and attribute_value_double = 1"); $get_subject_enrolled = mysql_query($sql_get_subject_enrolled) or die(mysql_error()); while($subject_enrolled = mysql_fetch_assoc($get_subject_enrolled)) { $sub_wing_enrolled[] = $subject_enrolled['subject_id']; } $sublist = array_intersect($sub_wing_list,$sub_wing_resident,$sub_wing_enrolled); //remove subjects from sublist that have completed a survey today $today = date('Y-m-d'); $sql_completed_session = sprintf("select subject_id,session.session_id from session left join ticket using (ticket_id) " . "where date(`date_time`) = '%s' and " . "end_datetime is not null and ticket_code = '%s'", $today, $tc); $completed_session = mysql_query($sql_completed_session) or die(mysql_error()); $completed_sublist = array(); while($row_completed_session = mysql_fetch_assoc($completed_session)) { $completed_sublist[] = $row_completed_session['subject_id']; } $sublist = array_diff($sublist,$completed_sublist); //obtain first and last names for $sublist foreach($sublist as $thisSubID) { $sql_get_sub_name = sprintf("select aes_decrypt(`name_last`,'%s') as name_last , " . "aes_decrypt(`name_first`,'%s') as name_first from subject ". "where subject_id = '%s'",$enc_key,$enc_key,$thisSubID); $sub_name = mysql_select($sql_get_sub_name); $sublist_name_last[] = $sub_name['name_last']; $sublist_name_first[] = $sub_name['name_first']; } //order subjects by last name, first name array_multisort($sublist_name_last,$sublist_name_first,$sublist); printf("

Participant List for wing \"%s\"

",$_SESSION['wing_assignment']); print "
Welcome %s, please enter your passcode" . LANGUAGE_TEXT_QUOTE_USERNAME . "
" . LANGUAGE_TEXT_QUOTE_PASSCODE . "
\n"; //list links for each subject foreach($sublist as $key=>$thisSubID) { $subFullName = $sublist_name_last[$key] . ", " . $sublist_name_first[$key]; $encSubID = mysql_aes_encrypt($thisSubID,$enc_key); $subLink = sprintf('%s',$questionnaire_location,$tc,$encSubID,$subFullName); printf("\n",$subLink); } if(sizeof($sublist) == 0) { print "
No remaining participants today.
"; } print "
%s
\n"; print "

 

"; printf("
",$_SERVER['PHP_SELF'].$getStr); print ""; print ""; print "
"; ?>