/** * gets affiliations from NRA list * @param $uni * @param $NRA_LIST_LOCATION * @return array of Affiliation objects */ function get_nra_affiliations($uni, $nra_list_location) { $cmd = "grep {$uni} {$nra_list_location}"; // put each line into an array $output = explode("\n", shell_exec($cmd)); $affiliations_array = array(); foreach ($output as $line) { $tmpArray = parseCsvLine($line); //check that there's a course listed - this ensures a full line if (isset($tmpArray[2])) { //create a new Affiliation object and add to array // function Affiliation($courseNumber, $uni, $affilType, $orig_type = "UNKNOWN") $affiliations_array[] = new Affiliation($tmpArray[2], $tmpArray[0], find_role($tmpArray[1]), "NRA"); } } return $affiliations_array; }
function getNRACoursesByUni() { global $NRA_FILE; $uni = $_SERVER['REMOTE_USER']; $cmd = "grep '{$uni},' {$NRA_FILE}"; //print $cmd; // put each line into an array $output = explode("\n", shell_exec($cmd)); $nra_array = array(); foreach ($output as $line) { if (!$line) { continue; } $nra_array[] = parseCsvLine($line); } $nra_classes = array(); // rows in nra-unified look like this: // jb2410,TA,ENGLG8401_001_2009_3 foreach ($nra_array as $nra_row) { $nra_classes[] = $nra_row[2]; } return $nra_classes; }
<?php $NRA_FILE = "/wwws/cgi/ccnmtl/draft/wikispaces-admin/sample.txt"; $uni = $_SERVER['REMOTE_USER']; $cmd = "grep {$uni} {$NRA_FILE}"; // put each line into an array $output = explode("\n", shell_exec($cmd)); //$output = shell_exec("ls -l"); $nra_array = array(); foreach ($output as $line) { if (!$line) { continue; } $nra_array[] = parseCsvLine($line); //$nra_array[] = $line; } //print_r($nra_array); $nra_classes = array(); foreach ($nra_array as $nra_row) { $nra_classes[] = $nra_row[3]; } print "NRA classes for {$uni}:<br>"; print_r($nra_classes); function parseCsvLine($str) { $delimier = ','; $qualifier = "'"; $qualifierEscape = '\\'; $fields = array(); while (strlen($str) > 0) { if ($str[0] == $delimier) {