function write_excel1($quarter, $dept) { $xls = new Excel('TAData'); $xls->home(); $xls->top(); $xls->label("Name"); $xls->right(); $xls->label("Likes"); $xls->right(); $xls->label("Hates"); $xls->right(); $xls->label("Conflicts"); $xls->right(); $xls->label("# Classes Taught"); $xls->right(); $xls->label("Ranking"); $xls->right(); $xls->label("Units"); $xls->right(); $xls->label("%"); $xls->home(); $xls->down(); $db = new PDO(DB_PATH, DB_LOGIN, DB_PW); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); try { //for each TA we need to gather the prefs and blacklist not given in the input file. $sql = "SELECT * from ta WHERE department = \"{$dept}\";"; $results = $db->query($sql); foreach ($results as $re) { //The headers are as seen above. We tackle each in turn. $xls->label($re['name_full']); $xls->right(); $prefs = get_prefs($re['sid'], $quarter); $likes = array(); $dislikes = array(); for ($i = 0; $i < count($prefs); $i++) { if ($prefs[$i]->value > 50) { array_push($likes, $prefs[$i]); } else { if ($prefs[$i]->value < 50) { array_push($dislikes, $prefs[$i]); } } usort($likes, prefcmp); usort($dislikes, prefcmpr); } $likes_full = ""; for ($i = 0; $i < count($likes) - 1; $i++) { $likes_full .= $likes[$i]->section; $likes_full .= ", "; } $likes_full .= $likes[count($likes) - 1]->section; // if($re['sid'] == 6260) puts($likes_full); $dislikes_full = ""; for ($i = 0; $i < count($dislikes) - 1; $i++) { $dislikes_full .= $dislikes[$i]->section; $dislikes_full .= ", "; } $dislikes_full .= $dislikes[count($dislikes) - 1]->section; // if($re['sid'] == 6260) puts($dislikes_full); $xls->label($likes_full); $xls->right(); $xls->label($dislikes_full); $xls->right(); //Now conflicts. This should be as simple as adding together all the events of TA. $sql2 = 'SELECT e.start, e.end, e.day FROM event e, calendar c WHERE c.id_event=e.id AND c.id_ta = ' . $re['sid'] . ' AND e.id_quarter = ' . $quarter . ';'; $result2 = $db->query($sql2); $conflict_full = ""; foreach ($result2 as $r2) { $conflict_full .= $r2['day'] . ' ' . round($r2['start'] / 100) . '-' . round($r2['end'] / 100) . ', '; } $conflict_full = substr($conflict_full, 0, -2); // if($re['sid'] == 6260) puts($conflict_full); $xls->label($conflict_full); $xls->right(); $u = $re['units']; $xls->label((int) ($u / 2)); $xls->right(); $xls->label($re['rank']); $xls->right(); $xls->label((int) $u); $xls->right(); $xls->label((int) ($u * 12.5)); $xls->down(); $xls->home(); // puts($re['name_full']."|".$likes_full); // print_r($likes); // print_r($dislikes); } $xls->send(); } catch (PDOException $e) { echo $e->getMessage(); } }