// all the database retrieval functions
/*
* $docRoot = "";
* $phpRoot = "/afs/andrew.cmu.edu/usr16/justinbr/naclo/www";
* $secBase = "secret";
*/
include_once '/afs/cs/project/naclo/www/includes.php';
include_once $SCRIPTS.'classes.php';
function suspend_registration() {
echo "
Official registration is over. Only walk-in registrations are now being accepted, pending approval from the local site coordinator. No new sites may be opened.
";
//die("Registration is closed. It will be up again Feb. 5 at 8 a.m. EST for walk-in registrations. Walk-in registrations may only participate at a site that is already established (i.e. no new sites may be created) and must have the permission of the site facilitator. They must register through this site before the end of the contest.");
}
$link = mysql_connect('localhost', 'naclo', 'MalEMEWi')
or die('Could not connect: ' . mysql_error());
mysql_select_db('NACLO') or die('Could not select database');
$leavethis = "variable as it is";
if (!function_exists("htmlspecialchars_decode")) {
function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) {
return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
}
}
// =========================
// = Convenience functions =
// =========================
function getName($info, $cutoff=-1) {
$title = $info['title'];
$first = $info['first'];
$last = $info['last'];
$name = "$first $last";
if($title)
$name = "$title $name";
if($cutoff > 0 && strlen($name) > $cutoff) $name = substr($name, 0, $cutoff) . "...";
return $name;
}
function getTeacherEmail($teacher_id, $pretty=FALSE) {
$query = mysql_query("SELECT first, last, email FROM teacher WHERE teacher_id = '$teacher_id'");
$row = mysql_fetch_row($query);
$name = $row[0] . " " . $row[1];
$email = $row[2];
$ret = $pretty? premail($name, $email) : $email;
return $ret;
}
//returns MySQL result string. orderby is optional, as is second/sval.
function query($table, $field, $value, $orderby="", $second="", $sval="") {
$query = "";
if($second && $sval){
$query = sprintf("SELECT * FROM %s WHERE %s='%s' AND %s='%s' %s",
mysql_real_escape_string($table),
mysql_real_escape_string($field),
mysql_real_escape_string($value),
mysql_real_escape_string($second),
mysql_real_escape_string($sval),
mysql_real_escape_string($orderby));
}else{
$query = sprintf("SELECT * FROM %s WHERE %s='%s'%s",
mysql_real_escape_string($table),
mysql_real_escape_string($field),
mysql_real_escape_string($value),
mysql_real_escape_string($orderby));
}
$result = mysql_query($query);
return $result;
}
// =====================
// = DB Read functions =
// =====================
//returns an array of Key => Value :: school_id => "School Name [Zip]"
function getSchool($state) {
$school = array("NOSCHOOL" => "Select a School...");
$query = sprintf("SELECT * FROM %s WHERE %s='%s' ORDER BY name",
mysql_real_escape_string("school"),
mysql_real_escape_string("state"),
mysql_real_escape_string($state));
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$school[$row['school_id']] = $row['name'] . " [" . $row['zip'] . "]";
}
return $school;
}
//returns an array of Key => Value :: teacher_id => Title First Last
function getTeacher($school) {
$school_id = strtolower($school);
if($school_id == "homeschool" || $school_id == "newschool"){
return "";
}
$teacher = array("NOSCHOOL" => "Select a Teacher...");
$query = sprintf("SELECT * FROM %s WHERE %s='%s' AND is_second='0' ORDER BY last",
mysql_real_escape_string("teacher"),
mysql_real_escape_string("school_id"),
mysql_real_escape_string($school));
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$teacher[$row['teacher_id']] = getName($row);
}
return $teacher;
}
function getSchoolInfo($school) {
$result = query("school","school_id",$school);
$row = mysql_fetch_assoc($result);
// $schoolInfo['name'] = $row['name'];
// $schoolInfo['street'] = $row['street'];
// $schoolInfo['city'] = $row['city'];
// $schoolInfo['zip'] = $row['zip'];
return $row;
}
function getTeacherInfo($teacher) {
$result = query("teacher","teacher_id",$teacher);
$row = mysql_fetch_assoc($result);
// $teacherInfo['title'] = $row['title'];
// $teacherInfo['first'] = $row['first'];
// $teacherInfo['last'] = $row['last'];
// $teacherInfo['email'] = $row['email'];
// $teacherInfo['phone_num'] = $row['phone_num'];
// $teacherInfo['phone_ext'] = $row['phone_ext'];
// $teacherInfo['site_id'] = $row['site_id'];
return $row;
}
function getSiteInfo($site_id) {
if($site_id==6){
$row = Array();
$row['name'] = 'High School Site';
$row['site_id'] = 6;
return $row;
}
if($site_id==0){
$row = Array();
$row['name'] = "No Site Selected";
$row['site_id'] = 0;
return $row;
}
$result = query("site","site_id",$site_id);
$row = mysql_fetch_assoc($result);
return $row;
}
//returns an array site_id => sitename for all the sites (sorted alphabetically)
function getSites() {
$siteList = array();
$result = mysql_query("SELECT * FROM site ORDER BY name");
//so it puts this at the front of the list
$siteList["6"] = "Select Site (Leave this field alone if you are registered at a high school).";
while($row = mysql_fetch_assoc($result)){
if(!$row['full'])
$siteList[$row['site_id']] = $row['name'] . " (" . $row['city'] . ", " . $row['state'] . ")";
else
$siteList[$row['site_id']] = $row['name'] . " (" . $row['city'] . ", " . $row['state'] . ")     [full]";
}
//There is no city or state
//$siteList["6"] = "High School Site";
return $siteList;
}
//returns an array site_id => sitename for all the sites (sorted alphabetically)
// Does not alter name if full
function getSites_stable() {
$siteList = array();
$result = mysql_query("SELECT * FROM site ORDER BY name");
//so it puts this at the front of the list
$siteList["6"] = "High School Site";
while($row = mysql_fetch_assoc($result)){
$siteList[$row['site_id']] = $row['name'] . " (" . $row['city'] . ", " . $row['state'] . ")";
}
return $siteList;
}
function getFullSites() {
$result = mysql_query("SELECT * from site where full = '1'");
while($row = mysql_fetch_assoc($result)) {
$sites[] = $row['name'];
}
return $sites;
}
function getSiteName($site_id, $where=TRUE, $cutoff=-1) {
//if it's at a high school
if($site_id == "6")
return "High School Site";
if(!$site_id)
return "No site selected";
$result = mysql_query("SELECT * FROM site WHERE site_id = '$site_id'");
$row = mysql_fetch_assoc($result);
$name = ($cutoff >= 0 && strlen($row['name']) > $cutoff) ? substr($row['name'], 0, $cutoff) . "..." : $row['name'];
if($where)
$name = $name . " (" . $row['city'] . ", " . $row['state'] . ")";
return $name;
}
function getSitePlace($site_id, $cutoff=-1) {
if(!$site_id)
return "No site selected";
//if it's online
if($site_id == "6")
return "High School Site";
$result = mysql_query("SELECT city, state FROM site WHERE site_id = '$site_id'");
$row = mysql_fetch_assoc($result);
$name = $row['city'] . ", " . $row['state'];
$name = ($cutoff >= 0 && strlen($name) > $cutoff) ? substr($name, 0, $cutoff) . "..." : $name;
return $name;
}
function getSchoolName($school_id, $where=TRUE, $cutoff=-1) {
$result = mysql_query("SELECT name, city, state FROM school WHERE school_id = '" . $school_id . "'");
$school = mysql_fetch_assoc($result);
$name = ($cutoff >= 0 && strlen($school['name']) > $cutoff) ? substr($school['name'], 0, $cutoff) . "..." : $school['name'];
if($where)
$name = $name . " (" . $school['city'] . ", " . $school['state'] . ")";
return $name;
}
//returns an array of contactInfo arrays... able to handle multiple contacts per site
function getContactInfo($site_id) {
$result = mysql_query("SELECT * FROM contact WHERE site_id = '".$site_id."'");
$contacts = array();
$info = array();
while($row = mysql_fetch_assoc($result)) {
$info['title'] = $row['title'];
$info['first'] = $row['first'];
$info['last'] = $row['last'];
$info['email'] = $row['email'];
$contacts[] = $info;
}
return $contacts;
}
function showHS(){
$schools = mysql_query("SELECT * FROM school");
echo "
Welcome, {$teacherInfo['name']}, what would you like to do?
";
}
// THIS LINE WAS IN THE ABOVE SECTION
//
student(s)
// print link to return to cpanel
function printRetLink($teacher_id, $pass, $message = "Click here to return to main menu") {
echo "$message";
}
function printRetDiv($teacher_id, $pass, $message="Click here to return to main menu") {
echo "