@@ -30,13 +30,13 @@ function icalFormatTime($time) {
3030
3131function generateIcal ($ schedule ) {
3232 // Globals
33- global $ HTTPROOTADDRESS ;
33+ global $ HTTPROOTADDRESS , $ dbConn ;
3434
3535 // We need to lookup the information about the quarter
36- $ term = mysql_real_escape_string ($ schedule ['term ' ]);
36+ $ term = $ dbConn -> real_escape_string ($ schedule ['term ' ]);
3737 $ query = "SELECT start, end, breakstart, breakend FROM quarters WHERE quarter=' {$ term }' " ;
38- $ result = mysql_query ($ query );
39- $ term = mysql_fetch_assoc ( $ result );
38+ $ result = $ dbConn -> query ($ query );
39+ $ term = $ result-> fetch_assoc ( );
4040 $ termStart = strtotime ($ term ['start ' ]);
4141 $ termEnd = date ("Ymd " , strtotime ($ term ['end ' ]));
4242
@@ -103,18 +103,20 @@ function generateIcal($schedule) {
103103}
104104
105105function getScheduleFromId ($ id ) {
106+ global $ dbConn ;
107+
106108 // Query to see if the id exists, if we can update the last accessed time,
107109 // then the id most definitely exists.
108110 $ query = "UPDATE schedules SET datelastaccessed = NOW() WHERE id= {$ id }" ;
109- $ result = mysql_query ($ query );
111+ $ result = $ dbConn -> query ($ query );
110112
111113 $ query = "SELECT startday, endday, starttime, endtime, building, `quarter`, CAST(`image` AS unsigned int) AS `image` FROM schedules WHERE id= {$ id }" ;
112114
113- $ result = mysql_query ($ query );
115+ $ result = $ dbConn -> query ($ query );
114116 if (!$ result ) {
115117 return NULL ;
116118 }
117- $ scheduleInfo = mysql_fetch_assoc ( $ result );
119+ $ scheduleInfo = $ result-> fetch_assoc ( );
118120 if (!$ scheduleInfo ) {
119121 return NULL ;
120122 }
@@ -133,18 +135,18 @@ function getScheduleFromId($id) {
133135
134136 // It exists, so grab all the courses that exist for this schedule
135137 $ query = "SELECT section FROM schedulecourses WHERE schedule = {$ id }" ;
136- $ result = mysql_query ($ query );
137- while ($ course = mysql_fetch_assoc ( $ result )) {
138+ $ result = $ dbConn -> query ($ query );
139+ while ($ course = $ result-> fetch_assoc ( )) {
138140 $ schedule [] = getCourseBySectionId ($ course ['section ' ]);
139141 }
140142
141143 // Grab all the non courses that exist for this schedule
142144 $ query = "SELECT * FROM schedulenoncourses WHERE schedule = $ id " ;
143- $ result = mysql_query ($ query );
145+ $ result = $ dbConn -> query ($ query );
144146 if (!$ result ) {
145- echo mysql_error ();
147+ echo $ dbConn -> error ();
146148 }
147- while ($ nonCourseInfo = mysql_fetch_assoc ( $ result )) {
149+ while ($ nonCourseInfo = $ result-> fetch_assoc ( )) {
148150 $ schedule [] = array (
149151 "title " => $ nonCourseInfo ['title ' ],
150152 "courseNum " => "non " ,
@@ -170,12 +172,14 @@ function getScheduleFromId($id) {
170172}
171173
172174function getScheduleFromOldId ($ id ) {
175+ global $ dbConn ;
176+
173177 $ query = "SELECT id FROM schedules WHERE oldid = ' {$ id }' " ;
174- $ result = mysql_query ($ query );
175- if (!$ result || mysql_num_rows ( $ result) != 1 ) {
178+ $ result = $ dbConn -> query ($ query );
179+ if (!$ result || $ result-> num_rows != 1 ) {
176180 return NULL ;
177181 } else {
178- $ newId = mysql_fetch_assoc ( $ result );
182+ $ newId = $ result-> fetch_assoc ( );
179183 $ newId = $ newId ['id ' ];
180184 $ schedule = getScheduleFromId ($ newId );
181185 $ schedule ['id ' ] = $ newId ;
@@ -337,19 +341,19 @@ function renderSvg($svg, $id) {
337341 $ query = "INSERT INTO schedules (oldid, startday, endday, starttime, endtime, building, quarter) " .
338342 " VALUES('', ' {$ json ['startday ' ]}', ' {$ json ['endday ' ]}', ' {$ json ['starttime ' ]}', ' {$ json ['endtime ' ]}', ' {$ json ['building ' ]}', " .
339343 " ' {$ json ['term ' ]}') " ;
340- $ result = mysql_query ($ query );
344+ $ result = $ dbConn -> query ($ query );
341345 if (!$ result ) {
342- die (json_encode (array ("error " => "mysql " , "msg " => "Failed to store the schedule: " . mysql_error ( $ dbConn) )));
346+ die (json_encode (array ("error " => "mysql " , "msg " => "Failed to store the schedule: " . $ dbConn-> error )));
343347 }
344348
345349 // Grab the latest id for the schedule
346- $ schedId = mysql_insert_id () ;
350+ $ schedId = $ dbConn -> insert_id ;
347351
348352 // Optionally process the svg for the schedule
349353 $ image = false ;
350354 if (!empty ($ _POST ['svg ' ]) && renderSvg ($ _POST ['svg ' ], $ schedId )) {
351355 $ query = "UPDATE schedules SET image = ((1)) WHERE id = ' {$ schedId }' " ;
352- mysql_query ($ query ); // We don't particularly care if this fails
356+ $ dbConn -> query ($ query ); // We don't particularly care if this fails
353357 }
354358
355359 // Now iterate through the schedule
@@ -360,18 +364,18 @@ function renderSvg($svg, $id) {
360364 foreach ($ item ['times ' ] as $ time ) {
361365 $ query = "INSERT INTO schedulenoncourses (title, day, start, end, schedule) " .
362366 " VALUES(' {$ item ['title ' ]}', ' {$ time ['day ' ]}', ' {$ time ['start ' ]}', ' {$ time ['end ' ]}', ' {$ schedId }') " ;
363- $ result = mysql_query ($ query );
367+ $ result = $ dbConn -> query ($ query );
364368 if (!$ result ) {
365- die (json_encode (array ("error " => "mysql " , "msg " => "Storing non-course item ' {$ item ['title ' ]}' failed: " . mysql_error ( $ dbConn) )));
369+ die (json_encode (array ("error " => "mysql " , "msg " => "Storing non-course item ' {$ item ['title ' ]}' failed: " . $ dbConn-> error )));
366370 }
367371 }
368372 } else {
369373 // Process each course. It's crazy simple now.
370374 $ query = "INSERT INTO schedulecourses (schedule, section) " .
371375 " VALUES(' {$ schedId }', ' {$ item ['id ' ]}') " ;
372- $ result = mysql_query ($ query );
376+ $ result = $ dbConn -> query ($ query );
373377 if (!$ result ) {
374- die (json_encode (array ("error " => "mysql " , "msg " => "Storing a course ' {$ item ['courseNum ' ]}' failed: " . mysql_error ( $ dbConn) )));
378+ die (json_encode (array ("error " => "mysql " , "msg " => "Storing a course ' {$ item ['courseNum ' ]}' failed: " . $ dbConn-> erorr )));
375379 }
376380 }
377381 }
0 commit comments