function eme_csv_booking_report($event_id) { global $eme_timezone; $event = eme_get_event($event_id); $is_multiprice = eme_is_multi($event['price']); $current_userid=get_current_user_id(); if (!(current_user_can( get_option('eme_cap_edit_events')) || current_user_can( get_option('eme_cap_list_events')) || (current_user_can( get_option('eme_cap_author_event')) && ($event['event_author']==$current_userid || $event['event_contactperson_id']==$current_userid)))) { echo "No access"; die; } header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"export.csv\""); $bookings = eme_get_bookings_for($event_id); $answer_columns = eme_get_answercolumns(eme_get_bookingids_for($event_id)); $out = fopen('php://output', 'w'); if (has_filter('eme_csv_header_filter')) { $line=apply_filters('eme_csv_header_filter',$event); fputcsv2($out,$line); } $line=array(); $line[]=__('ID', 'eme'); $line[]=__('Last Name', 'eme'); $line[]=__('First Name', 'eme'); $line[]=__('Address1', 'eme'); $line[]=__('Address2', 'eme'); $line[]=__('City', 'eme'); $line[]=__('State', 'eme'); $line[]=__('Zip', 'eme'); $line[]=__('Country', 'eme'); $line[]=__('E-mail', 'eme'); $line[]=__('Phone number', 'eme'); if ($is_multiprice) $line[]=__('Seats (Multiprice)', 'eme'); else $line[]=__('Seats', 'eme'); $line[]=__('Paid', 'eme'); $line[]=__('Booking date','eme'); $line[]=__('Total price','eme'); $line[]=__('Unique nbr','eme'); $line[]=__('Comment', 'eme'); foreach($answer_columns as $col) { $line[]=$col['field_name']; } fputcsv2($out,$line); foreach($bookings as $booking) { $localised_booking_date = eme_localised_date($booking['creation_date']." ".$eme_timezone); $localised_booking_time = eme_localised_time($booking['creation_date']." ".$eme_timezone); $person = eme_get_person ($booking['person_id']); $line=array(); $pending_string=""; if (eme_event_needs_approval($event_id) && !$booking['booking_approved']) { $pending_string=__('(pending)','eme'); } $line[]=$booking['booking_id']; $line[]=$person['lastname']; $line[]=$person['firstname']; $line[]=$person['address1']; $line[]=$person['address2']; $line[]=$person['city']; $line[]=$person['state']; $line[]=$person['zip']; $line[]=$person['country']; $line[]=$person['email']; $line[]=$person['phone']; if ($is_multiprice) { // in cases where the event switched to multiprice, but somebody already registered while it was still single price: booking_seats_mp is then empty if ($booking['booking_seats_mp'] == "") $booking['booking_seats_mp']=$booking['booking_seats']; $line[]=$booking['booking_seats']." (".$booking['booking_seats_mp'].") ".$pending_string; } else { $line[]=$booking['booking_seats']." ".$pending_string; } $line[]=$booking['booking_payed']? __('Yes'): __('No'); $line[]=$localised_booking_date." ".$localised_booking_time; $line[]=eme_get_total_booking_price($event,$booking); $line[]=$booking['transfer_nbr_be97']; $line[]=$booking['booking_comment']; $answers = eme_get_answers($booking['booking_id']); foreach($answer_columns as $col) { $found=0; foreach ($answers as $answer) { if ($answer['field_name'] == $col['field_name']) { $line[]=eme_convert_answer2tag($answer); $found=1; break; } } # to make sure the number of columns are correct, we add an empty answer if none was found if (!$found) $line[]=""; } fputcsv2($out,$line); } if (has_filter('eme_csv_footer_filter')) { $line=apply_filters('eme_csv_footer_filter',$event); fputcsv2($out,$line); } fclose($out); die(); }
function scip_input($year, $season, $dept, $sname) { /* error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); */ //so we have three csv files to make: ta, section, pref. $tacsv = array(); $prefcsv = array(); $sectioncsv = array(); //Each row gets its own array; let's start with headers. $header = array('Name', 'Ranking', 'Units', 'Status', 'Block', 'Sameday', 'Btb', 'Conflicts', 'NULL'); array_push($tacsv, $header); $header = array('Course', 'Section', 'Instructor', 'Day', 'Time', 'Units', 'TAs', 'NULL'); array_push($sectioncsv, $header); //given a TA, we already have a function to find all section prefs. So let the list of // section names be the pref header. $db = new PDO(DB_PATH, DB_LOGIN, DB_PW); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); try { //first we want to loop through all current sections of this dept. $sql = count_sections($dept, $year, $season); $result = $db->query($sql)->fetch(); if ($result[0] == 0) { return array("error-message", "Department {$dept} has no section data for {$sname} {$year}."); } $sql = sql_section($dept, $year, $season); //puts($sql); $result = $db->query($sql); $header = array(""); foreach ($result as $r) { $course = $r['course']; $row = array($course, $r['name'], ""); //Now to get the times. $sql2 = "SELECT *\n FROM event\n WHERE quarter_year = {$year} and quarter_season = {$season}\n AND department = '{$dept}' AND course = '" . $r['course'] . "' \n AND section = '" . $r['name'] . "' AND type = 'lecture'\n AND day != 'U' AND day != 'S'\n GROUP BY day;"; $result2 = $db->query($sql2); $days = ""; $start = ""; $end = ""; foreach ($result2 as $r2) { $days .= $r2['day']; $start = $r2['start']; $end = $r2['end']; } //Gather all the lecture days and get times. $time_full = $start . '-' . $end; array_push($row, $days); array_push($row, $time_full); array_push($row, $r['units']); array_push($row, $r['weight']); array_push($row, "0"); $row2 = array("", "", ""); $sql2 = "SELECT *\n FROM event\n WHERE quarter_year = {$year} and quarter_season = {$season}\n AND department = '{$dept}' AND course = '" . $r['course'] . "'\n AND day != 'U' AND day != 'S'\n AND section = '" . $r['name'] . "' AND type = 'discussion';"; //puts($sql2); $result2 = $db->query($sql2); $discussion = 0; $days = ""; $start = ""; $end = ""; foreach ($result2 as $r2) { $days = $r2['day']; $start = $r2['start']; $end = $r2['end']; $discussion = 1; array_push($row2, $days); $time_full = $start . '-' . $end; array_push($row2, $time_full); } //enter the discussion. array_push($row2, $r['units']); array_push($row2, $r['weight']); array_push($row2, "0"); //only put in sections with discussions array_push($header, $course . ' ' . $r['name']); array_push($sectioncsv, $row); array_push($sectioncsv, $row2); } //for all sections. array_push($prefcsv, $header); //Now we get all TAs. We can fill pref.csv as we go here. $sql = "SELECT t.name_first, t.name_last, t.rank, t.status, t.sid, u.value\n FROM ta t, units u\n WHERE u.sid = t.sid\n AND t.department = '{$dept}' AND u.year = {$year} AND u.season = {$season};"; //puts($sql); $result = $db->query($sql); foreach ($result as $r) { $fullname = scip_clean($r['name_first']) . ' ' . scip_clean($r['name_last']); $sid = $r['sid']; $row = array($fullname, $r['rank'], $r['value'], strtolower($r['status'])); $sql2 = "SELECT * FROM pref WHERE sid = " . $r['sid'] . ";"; $r2 = $db->query($sql2); $p = array(); $countr2 = 0; foreach ($r2 as $rr2) { $countr2++; $p = array($rr2['block'], $rr2['same_day'], $rr2['back_to_back']); } if ($countr2 == 0) { $p = array(0, 0, 0); } foreach ($p as $p2) { array_push($row, $p2); } //finally we need to get all time conflicts in form D|SSSS|EEEE D|SSSS|EEEE.... $sql2 = "SELECT day, start, end \n FROM calendar\n WHERE sid = {$sid} AND quarter_year = {$year} AND quarter_season = {$season};"; $result2 = $db->query($sql2); $conflicts = ""; foreach ($result2 as $r2) { $conflicts .= $r2['day'] . '|' . $r2['start'] . '|' . $r2['end'] . ' '; } //for each event of this TA array_push($row, $conflicts); array_push($row, "0"); array_push($tacsv, $row); $prefs = get_prefs($sid, $year, $season, $dept, "scip"); $prow = array($fullname); for ($i = 0; $i < count($prefs); $i++) { array_push($prow, $prefs[$i]->value); // array_push($prow, ($prefs[$i]->value." ".$prefs[$i]->section)); } array_push($prefcsv, $prow); } //foreach ta } catch (PDOException $e) { echo $e->getMessage(); } //Now we can save the csv files in the scip folder. $fp = fopen('scip/ta.csv', 'w'); foreach ($tacsv as $fields) { fputcsv2($fp, str_replace(array("(", ")"), "-", $fields)); } fclose($fp); $fp = fopen('scip/section.csv', 'w'); foreach ($sectioncsv as $fields) { fputcsv2($fp, $fields); } fclose($fp); $fp = fopen('scip/pref.csv', 'w'); foreach (transpose($prefcsv) as $fields) { fputcsv2($fp, str_replace(array("(", ")"), "-", $fields)); } $fp = fopen("csv/pref_{$dept}{$year}{$season}.csv", 'w'); foreach (transpose($prefcsv) as $fields) { fputcsv2($fp, str_replace(array("(", ")"), "-", $fields)); } fclose($fp); }