Authenticate:
$query"; SQLExec($query, "tables created"); } function updateCategories() { global $elections; global $schoolYear; $query = "begin;\n"; $reset_elections = (empty($election)) ? $elections : array($election); foreach($reset_elections as $votable) { $categories = file("schools/$schoolYear/$votable-categories.txt"); $categories = array_map('trim', $categories); $cats = sizeof($categories); for($i = 0; $i < $cats; $i++) { $query .= "INSERT INTO {$votable}_categories VALUES($i, '".escape($categories[$i])."');\n"; } } $query .= "end;"; echo "
$query
--
"; echo SQLExec($query, "categories added"); } function updateStudents() { global $schoolYear; $query = "begin;\n"; $students = file("schools/$schoolYear/students.txt"); // Maybe let the school redefine how the student file is parsed? $parseStudentFile = "schools/$schoolYear/parseStudent.php"; if(file_exists($parseStudentFile)) { echo "including parsetudentfile"; include($parseStudentFile); // not an error if it's not there. } else { // default (brandywine) parsing // students.txt should have lines of the format //Student Id "Last, First Middle" Gender Grade // gender == 'M' or 'F' // // Assumes that if a grade is not provided, you're importing only seniors. // To provide your own, simply put a named function in $schoolYear/parseStudent.php function parseStudent($line) { $studentinfo = explode("\t", $line); $studentinfo[0] = sprintf("%06s", $studentinfo[0]); $id = getHash($studentinfo[0]); preg_match('/\"(.*?)\, ([^ "]*)(?: ([^"]*))?\"/', $studentinfo[1], $nameinfo); // $nameinfo[3] is middle name, *usually* $lname = (($nameinfo[1])); // ucfirst(strtolower(? $fname = array( ($nameinfo[2]) ); if(sizeof($nameinfo) > 3) { if(strlen($fname[0]) == 1) // sometimes we'll get someone's initial mistakenly as the first name $fname[0] = $nameinfo[3]; if(strlen($nameinfo[3]) > 1) // or even nothing at all $fname[] = $nameinfo[3]; } $fname = implode($fname, ' '); $gender = trim($studentinfo[2]); if(sizeof($studentinfo) > 3) $grade = intval(trim($studentinfo[3])); else $grade = 12; return array("id" => $id, "lname" => $lname, "fname" => $fname , "gender" => $gender, "grade" => $grade); } } foreach($students as $line) { extract(parseStudent($line)); // extract() populates variables in local scope from associative array $query .= "INSERT INTO students VALUES($id, '$fname',\t'$lname',\t'$gender',\t$grade, '');\n"; } $query .= "end;"; echo "
$query
"; echo SQLExec($query, "students added"); } ?>