PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/manage/controllers/events/sessioncontroller.php

https://bitbucket.org/pooshonk/esw
PHP | 1370 lines | 1169 code | 155 blank | 46 comment | 168 complexity | 3fdc1061bd681561bdc149e7fa8bd5ac MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class Sessioncontroller {
  3. public function __construct( PeacockCarterFrameworkRegistry $registry, $directCall )
  4. {
  5. $this->registry = $registry;
  6. if( $this->registry->getObject('authenticate')->isAuthorised('events_sessions') == true )
  7. {
  8. $this->registry->getObject('adminmenubuilder')->buildMenu( 'events.sessions' );
  9. if( $this->registry->getURLBit(1) != '' )
  10. {
  11. switch( $this->registry->getURLBit(2) )
  12. {
  13. case'add':
  14. $this->addSession( intval( $this->registry->getURLBit(3) ) );
  15. break;
  16. case'create':
  17. $this->createSession( );
  18. break;
  19. case'edit':
  20. $this->editSessionByEvent( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ));
  21. break;
  22. case'edit-current':
  23. $this->editSession( intval( $this->registry->getURLBit(3) ), 'current' );
  24. break;
  25. case'edit-previous':
  26. $this->editSession( intval( $this->registry->getURLBit(3) ), 'previous' );
  27. break;
  28. case'delete':
  29. $this->delete( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ) );
  30. break;
  31. case'previous':
  32. $this->listPrevious( intval( $this->registry->getURLBit(4) ) );
  33. break;
  34. case'current':
  35. $this->listCurrent( intval( $this->registry->getURLBit(4) ) );
  36. break;
  37. case'attendees':
  38. $this->listAttendees( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(5) ) );
  39. break;
  40. case 'cancel-attendee':
  41. $this->cancelAttendee( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ));
  42. break;
  43. case 'toggle-active':
  44. $this->toggleActiveSession( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ));
  45. break;
  46. case 'toggle-pay-online':
  47. $this->togglePayOnline( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ));
  48. break;
  49. case 'toggle-bookable':
  50. $this->toggleBookable( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ));
  51. break;
  52. case 'toggle-non-members':
  53. $this->toggleNonMembers( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ));
  54. break;
  55. case 'toggle-featured':
  56. $this->toggleFeatured( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ));
  57. break;
  58. case 'toggle-active-session':
  59. $this->toggleActiveSessionFixture( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ));
  60. break;
  61. case 'list':
  62. $this->listSessions ( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(5) ) );
  63. break;
  64. case 'details-attendees':
  65. $this->detailsAttendees( intval( $this->registry->getURLBit(3) ) );
  66. break;
  67. default:
  68. $this->listCurrent( intval( $this->registry->getURLBit(4) ) );
  69. break;
  70. }
  71. }
  72. else
  73. {
  74. $this->listCurrent( intval( $this->registry->getURLBit(4) ) );
  75. }
  76. }
  77. else
  78. {
  79. $this->registry->getObject('authenticate')->redirectToAuthorised('primary');
  80. }
  81. }
  82. private function detailsAttendees( $sid )
  83. {
  84. $this->registry->getObject('template')->getPage()->removeTag( 'admin_menu_primary' );
  85. $this->registry->getObject('template')->getPage()->removeTag( 'admin_menu_sub' );
  86. /*
  87. $sql = "SELECT s.cost_structure, s.cost as standard_cost, s.comment as extra_information, s.ID as session_ID, vv.name as venue, ev.name as event, ev.content as event_content, DATE_FORMAT(s.date, '%b') as date_month, DATE_FORMAT(s.date, '%d') as date_day, s.ID as session_ID, DATE_FORMAT(s.date, '%D %M %Y') as date, " .
  88. "DATE_FORMAT(start_time, '%H:%i') as start_time, DATE_FORMAT(end_time, '%H:%i') as end_time, " .
  89. "((s.places)-((SELECT COUNT(*) FROM event_session_attendees WHERE session_ID=s.ID AND cancelled = 0) + (SELECT COUNT(*) FROM eventbasket_attendees a, eventbasket b WHERE b.ID = a.basket_id AND b.event_session = s.ID ))) as spaces, " .
  90. "IF( ((s.places)-((SELECT COUNT(*) FROM event_session_attendees WHERE session_ID=s.ID AND cancelled = 0) + (SELECT COUNT(*) FROM eventbasket_attendees a, eventbasket b WHERE b.ID = a.basket_id AND b.event_session = s.ID ))) > 0, '', '<!--' ) as fullleft, IF( ((s.places)-((SELECT COUNT(*) FROM event_session_attendees WHERE session_ID=s.ID AND cancelled = 0) + (SELECT COUNT(*) FROM eventbasket_attendees a, eventbasket b WHERE b.ID = a.basket_id AND b.event_session = s.ID ))) > 0, '', '-->' ) as fullright " .
  91. "FROM event_sessions s, content_versions ev, content ec, content_versions vv, content vc " .
  92. "WHERE s.venue_id = vc.ID AND vc.current_revision = vv.ID AND s.event_id = ec.ID AND ec.current_revision = ev.ID AND s.active = 1 AND s.deleted = 0 AND s.date >= CURDATE() AND s.ID = {$sid} LIMIT 1";
  93. */
  94. $sql = "SELECT vv.name as venue, ev.name as event, DATE_FORMAT(s.date, '%D %M %Y') as date, " .
  95. "DATE_FORMAT(start_time, '%H:%i') as start_time, DATE_FORMAT(end_time, '%H:%i') as end_time " .
  96. "FROM event_sessions s, content_versions ev, content ec, content_versions vv, content vc " .
  97. "WHERE s.venue_id = vc.ID AND vc.current_revision = vv.ID AND s.event_id = ec.ID AND ec.current_revision = ev.ID AND s.ID = {$sid} LIMIT 1";
  98. $this->registry->getObject('db')->executeQuery( $sql );
  99. $data = $this->registry->getObject('db')->getRows();
  100. $this->registry->getObject('template')->dataToTags( $data, '' );
  101. $sql = "SELECT *, ID as aid FROM event_session_attendees WHERE session_id = {$sid} AND cancelled = 0 ORDER BY name ASC";
  102. $this->registry->getObject('db')->executeQuery( $sql );
  103. if( $this->registry->getObject('db')->numRows() > 0 )
  104. {
  105. $attendees = array();
  106. $event_sessions = array();
  107. $session_ids = '';
  108. while( $row = $this->registry->getObject('db')->getRows() )
  109. {
  110. if( !in_array( $row['session_id'], ( $event_sessions ) ) )
  111. {
  112. $session_ids .= $row['session_id'] . ',';
  113. $event_sessions[] = $row['session_id'];
  114. }
  115. if( in_array( $row['aid'], array_keys( $attendees ) ) )
  116. {
  117. $attendees[ $row['aid'] ][] = $row;
  118. }
  119. else
  120. {
  121. $attendees[ $row['aid'] ] = array();
  122. $attendees[ $row['aid'] ][] = $row;
  123. }
  124. }
  125. $session_ids = substr( $session_ids, 0, -1 );
  126. $cache = $this->registry->getObject('db')->cacheQuery( $sql );
  127. $this->registry->getObject('template')->getPage()->addTag( 'attendees', array( 'SQL', $cache ) );
  128. //get the time slots and workshops for this session
  129. $sql = "SELECT s.ID as slot_id, DATE_FORMAT(s.time, '%H:%i') as time, s.heading, s.description, s.session_id FROM event_sessions_slots s WHERE ( SELECT COUNT(*) FROM event_sessions_slots_workshops w WHERE s.ID = w.slot_id ) > 0 AND s.session_id IN ( $session_ids ) ORDER BY s.ID ASC";
  130. $this->registry->getObject('db')->executeQuery( $sql );
  131. if( $this->registry->getObject('db')->numRows() > 0 )
  132. {
  133. $slots = array();
  134. while( $data = $this->registry->getObject('db')->getRows() )
  135. {
  136. if( in_array( $data['session_id'], array_keys( $slots ) ) )
  137. {
  138. $slots[ $data['session_id'] ][] = $data;
  139. }
  140. else
  141. {
  142. $slots[ $data['session_id'] ] = array();
  143. $slots[ $data['session_id'] ][] = $data;
  144. }
  145. }
  146. foreach( $attendees as $attendee => $details )
  147. {
  148. foreach( $details as $record )
  149. {
  150. if( in_array( $record ['session_id'], array_keys( $slots ) ) )
  151. {
  152. $this->registry->getObject('template')->addTemplateBit('workshops-' . $attendee, 'events/sessions/workshops.tpl.php', array('session_id' => $record['session_id'], 'aid' => $attendee ) );
  153. }
  154. else
  155. {
  156. $this->registry->getObject('template')->getPage()->addTag( 'workshops-' . $attendee, '' );
  157. }
  158. }
  159. }
  160. foreach( $attendees as $attendee => $details )
  161. {
  162. foreach( $slots as $session => $details )
  163. {
  164. $cache = $this->registry->getObject('db')->cacheData( $details );
  165. $this->registry->getObject('template')->getPage()->addPPTag( 'slots-' . $session . '-' . $attendee, array( 'DATA', $cache ) );
  166. }
  167. }
  168. //workshops
  169. $workshops = array();
  170. $sql = "SELECT ID as wid, slot_id, name as workshop FROM event_sessions_slots_workshops WHERE session_id IN ( $session_ids )";
  171. $this->registry->getObject('db')->executeQuery( $sql );
  172. while( $row = $this->registry->getObject('db')->getRows() )
  173. {
  174. if( in_array( $row['slot_id'], array_keys( $workshops ) ) )
  175. {
  176. $workshops[ $row['slot_id'] ][] = $row;
  177. }
  178. else
  179. {
  180. $workshops[ $row['slot_id'] ] = array();
  181. $workshops[ $row['slot_id'] ][] = $row;
  182. }
  183. }
  184. foreach( $attendees as $attendee => $data )
  185. {
  186. foreach( $workshops as $record => $details )
  187. {
  188. $cache = $this->registry->getObject('db')->cacheData( $details );
  189. $this->registry->getObject('template')->getPage()->addPPTag( 'workshops-' . $record . '-' . $attendee , array( 'DATA', $cache ) );
  190. }
  191. }
  192. //get attendee preferences
  193. $sql = "SELECT w.* FROM event_session_attendees_workshops w, event_session_attendees a WHERE w.attendee_id = a.ID AND a.session_id = {$sid}";
  194. $this->registry->getObject('db')->executeQuery( $sql );
  195. while( $row = $this->registry->getObject('db')->getRows() )
  196. {
  197. $this->registry->getObject('template')->getPage()->addPPTag( $row['attendee_id'] . $row['workshop_id'], $row['preference'] );
  198. }
  199. }
  200. else
  201. {
  202. foreach( $attendees as $attendee => $data )
  203. {
  204. $this->registry->getObject('template')->getPage()->addTag( 'workshops-' . $attendee, '' );
  205. }
  206. }
  207. }
  208. $this->registry->getObject('template')->buildFromTemplates( 'events/sessions/details-attendees.tpl.php' );
  209. }
  210. private function toggleFeatured( $id, $eid )
  211. {
  212. $sql = "UPDATE event_sessions SET featured=1-featured WHERE ID={$id}";
  213. $this->registry->getObject('db')->executeQuery( $sql );
  214. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
  215. exit();
  216. }
  217. private function listSessions( $eid, $offset=0 )
  218. {
  219. $sql = "SELECT ver.name as event FROM content_versions ver, content con WHERE con.current_revision = ver.ID AND con.ID = {$eid}";
  220. $this->registry->getObject('db')->executeQuery($sql);
  221. $data = $this->registry->getObject('db')->getRows();
  222. $this->registry->getObject('template')->getPage()->addTag( 'event', $data['event'] );
  223. $this->registry->getObject('template')->getPage()->addTag( 'eid', $eid );
  224. $sql = "SELECT v.name, s.featured, s.venue_ID, s.ID, DATE_FORMAT(s.date, '%D %b %Y') as date, s.cost, s.places, s.active, s.bookable, s.non_members, s.pay_online, (SELECT COUNT(*) FROM event_session_attendees a WHERE a.cancelled=0 AND a.session_ID=s.ID) as booked FROM event_sessions s, content_versions v, content c WHERE v.ID=c.current_revision AND s.deleted=0 AND s.event_ID={$eid} AND c.ID=s.venue_ID AND s.date >= CURDATE() ORDER BY s.date ASC";
  225. $pagination = $this->registry->pagination( $sql, 10, $offset, 'cache' );
  226. $this->registry->getObject('template')->getPage()->addTag('sessions', array( 'SQL', $pagination['cache'] ) );
  227. $this->registry->getObject('template')->getPage()->addTag('page_number', $pagination['cur_page'] );
  228. $this->registry->getObject('template')->getPage()->addTag('num_pages', $pagination['num_pages'] );
  229. // pagination links
  230. if( $pagination['is_first'] == true )
  231. {
  232. $this->registry->getObject('template')->getPage()->addTag('first', '');
  233. $this->registry->getObject('template')->getPage()->addTag('previous', '');
  234. }
  235. else
  236. {
  237. $this->registry->getObject('template')->getPage()->addTag('first', "<li><a href='events/sessions/list/$eid/page/'>First Page</a></li>");
  238. $this->registry->getObject('template')->getPage()->addTag('previous', "<li><a href='events/sessions/list/$eid/page/". ( $pagination['cur_page'] - 2 ) . "'>Previous Page</a></li>");
  239. }
  240. if( $pagination['is_last'] == true )
  241. {
  242. $this->registry->getObject('template')->getPage()->addTag('next', '');
  243. $this->registry->getObject('template')->getPage()->addTag('last', '');
  244. }
  245. else
  246. {
  247. $this->registry->getObject('template')->getPage()->addTag('last', "<li><a href='events/sessions/list/$eid/page/". ( $pagination['num_pages'] - 1 ) ."'>Last Page</a></li>");
  248. $this->registry->getObject('template')->getPage()->addTag('next', "<li><a href='events/sessions/list/$eid/page/". ( $pagination['cur_page'] ) . "'>Next Page</a></li>");
  249. }
  250. $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'events/sessions/list.tpl.php', 'footer.tpl.php');
  251. }
  252. private function listPrevious( $offset=0 )
  253. {
  254. $sql = "SELECT v.name, (SELECT ver.name FROM content_versions ver, content con WHERE s.event_ID = con.ID AND con.current_revision = ver.ID ) as event, s.venue_ID, s.event_ID, s.ID, DATE_FORMAT(s.date, '%D %b %Y') as date, s.cost, s.places, s.non_members, s.active, (SELECT COUNT(*) FROM event_session_attendees a WHERE a.cancelled=0 AND a.session_ID=s.ID) as booked FROM event_sessions s, content_versions v, content c WHERE v.ID=c.current_revision AND s.deleted=0 AND c.ID=s.venue_ID AND s.date < CURDATE() ORDER BY s.date ASC";
  255. $pagination = $this->registry->pagination( $sql, 10, $offset, 'cache' );
  256. $this->registry->getObject('template')->getPage()->addTag('sessions', array( 'SQL', $pagination['cache'] ) );
  257. $this->registry->getObject('template')->getPage()->addTag('page_number', $pagination['cur_page'] );
  258. $this->registry->getObject('template')->getPage()->addTag('num_pages', $pagination['num_pages'] );
  259. // pagination links
  260. if( $pagination['is_first'] == true )
  261. {
  262. $this->registry->getObject('template')->getPage()->addTag('first', '');
  263. $this->registry->getObject('template')->getPage()->addTag('previous', '');
  264. }
  265. else
  266. {
  267. $this->registry->getObject('template')->getPage()->addTag('first', "<li><a href='events/sessions/previous/page/'>First Page</a></li>");
  268. $this->registry->getObject('template')->getPage()->addTag('previous', "<li><a href='events/sessions/previous/page/". ( $pagination['cur_page'] - 2 ) . "'>Previous Page</a></li>");
  269. }
  270. if( $pagination['is_last'] == true )
  271. {
  272. $this->registry->getObject('template')->getPage()->addTag('next', '');
  273. $this->registry->getObject('template')->getPage()->addTag('last', '');
  274. }
  275. else
  276. {
  277. $this->registry->getObject('template')->getPage()->addTag('last', "<li><a href='events/sessions/previous/page/". ( $pagination['num_pages'] - 1 ) ."'>Last Page</a></li>");
  278. $this->registry->getObject('template')->getPage()->addTag('next', "<li><a href='events/sessions/previous/page/". ( $pagination['cur_page'] ) . "'>Next Page</a></li>");
  279. }
  280. $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'events/sessions/previous.tpl.php', 'footer.tpl.php');
  281. }
  282. private function listCurrent( $offset=0 )
  283. {
  284. $sql = "SELECT v.name, (SELECT ver.name FROM content_versions ver, content con WHERE s.event_ID = con.ID AND con.current_revision = ver.ID ) as event, s.venue_ID, s.event_ID, s.ID, DATE_FORMAT(s.date, '%D %b %Y') as date, s.cost, s.places, s.active, s.non_members, s.bookable, s.pay_online, (SELECT COUNT(*) FROM event_session_attendees a WHERE a.cancelled=0 AND a.session_ID=s.ID) as booked FROM event_sessions s, content_versions v, content c WHERE v.ID=c.current_revision AND s.deleted=0 AND c.ID=s.venue_ID AND s.date >= CURDATE() ORDER BY s.date ASC";
  285. $pagination = $this->registry->pagination( $sql, 10, $offset, 'cache' );
  286. $this->registry->getObject('template')->getPage()->addTag('sessions', array( 'SQL', $pagination['cache'] ) );
  287. $this->registry->getObject('template')->getPage()->addTag('page_number', $pagination['cur_page'] );
  288. $this->registry->getObject('template')->getPage()->addTag('num_pages', $pagination['num_pages'] );
  289. // pagination links
  290. if( $pagination['is_first'] == true )
  291. {
  292. $this->registry->getObject('template')->getPage()->addTag('first', '');
  293. $this->registry->getObject('template')->getPage()->addTag('previous', '');
  294. }
  295. else
  296. {
  297. $this->registry->getObject('template')->getPage()->addTag('first', "<li><a href='events/sessions/current/page/'>First Page</a></li>");
  298. $this->registry->getObject('template')->getPage()->addTag('previous', "<li><a href='events/sessions/current/page/". ( $pagination['cur_page'] - 2 ) . "'>Previous Page</a></li>");
  299. }
  300. if( $pagination['is_last'] == true )
  301. {
  302. $this->registry->getObject('template')->getPage()->addTag('next', '');
  303. $this->registry->getObject('template')->getPage()->addTag('last', '');
  304. }
  305. else
  306. {
  307. $this->registry->getObject('template')->getPage()->addTag('last', "<li><a href='events/sessions/current/page/". ( $pagination['num_pages'] - 1 ) ."'>Last Page</a></li>");
  308. $this->registry->getObject('template')->getPage()->addTag('next', "<li><a href='events/sessions/current/page/". ( $pagination['cur_page'] ) . "'>Next Page</a></li>");
  309. }
  310. $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'events/sessions/current.tpl.php', 'footer.tpl.php');
  311. }
  312. private function addSession( $eid )
  313. {
  314. if( isset( $_POST['createsession'] ) )
  315. {
  316. $insert = array();
  317. $insert['event_id'] = $this->registry->getObject('db')->sanitizeData( $eid );
  318. $insert['venue_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['venue']);
  319. if( isset( $_POST['date'] ) && $_POST['date'] > 0 )
  320. {
  321. $date = explode( '/', $_POST['date']);
  322. $dt = $date[2] . '-' . $date[1] .'-'. $date[0];
  323. $insert['date'] = $this->registry->getObject('db')->sanitizeData( $dt );
  324. }
  325. if( isset( $_POST['start_time'] ) && $_POST['start_time'] > 0 )
  326. {
  327. $time = explode( ':', $_POST['start_time'] );
  328. $t = $time[0].':'.$time[1];
  329. $insert['start_time'] = $this->registry->getObject('db')->sanitizeData( $t );
  330. }
  331. if( isset( $_POST['end_time'] ) && $_POST['end_time'] > 0 )
  332. {
  333. $time = explode( ':', $_POST['end_time'] );
  334. $t = $time[0].':'.$time[1];
  335. $insert['end_time'] = $this->registry->getObject('db')->sanitizeData( $t );
  336. }
  337. $insert['places'] = $this->registry->getObject('db')->sanitizeData( $_POST['places']);
  338. $insert['cost_structure'] = $this->registry->getObject('db')->sanitizeData( $_POST['cost_structure']);
  339. $insert['cost'] = $this->registry->getObject('db')->sanitizeData( $_POST['standard_cost']);
  340. $insert['discount'] = $this->registry->getObject('db')->sanitizeData( $_POST['discount']);
  341. $insert['comment'] = $this->registry->getObject('db')->sanitizeData( $_POST['comment']);
  342. $insert['active'] = 1;
  343. $insert['non_members'] = 1;
  344. $insert['pay_online'] = 1;
  345. $this->registry->getObject('db')->insertRecords( 'event_sessions', $insert);
  346. $session_id = $this->registry->getObject('db')->lastInsertID();
  347. //costs
  348. if( isset( $_POST['cost'] ) && is_array( $_POST['cost'] ) && count( $_POST['cost'] ) > 0 )
  349. {
  350. $sql = "INSERT INTO event_sessions_costs ( `session_ID`, `cost`, `type` ) VALUES ";
  351. foreach( $_POST['cost'] as $cost_type => $cost )
  352. {
  353. if( $cost == '' )
  354. {
  355. $cost = 0;
  356. }
  357. $cost = $this->registry->getObject('db')->sanitizeData( $cost );
  358. $cost_type = $this->registry->getObject('db')->sanitizeData( $cost_type );
  359. $sql .= " ( {$session_id}, {$cost}, '{$cost_type}' ),";
  360. }
  361. $sql = substr_replace($sql ,"",-1);
  362. $this->registry->getObject('db')->executeQuery( $sql );
  363. }
  364. //time slots and workshops
  365. if( isset( $_POST['times'] ) && is_array( $_POST['times'] ) && count( $_POST['times'] ) > 0 )
  366. {
  367. foreach( $_POST['times'] as $value )
  368. {
  369. $insert = array();
  370. $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $session_id );
  371. $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
  372. $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
  373. $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
  374. $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
  375. $slot_id = $this->registry->getObject('db')->lastInsertID();
  376. if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
  377. {
  378. $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
  379. foreach( $value['workshops'] as $data )
  380. {
  381. $slot_id = $this->registry->getObject('db')->sanitizeData( $slot_id );
  382. $name = $this->registry->getObject('db')->sanitizeData( $data );
  383. $sql .= " ( {$session_id}, {$slot_id}, '{$name}' ),";
  384. }
  385. $sql = substr_replace($sql ,"",-1);
  386. $this->registry->getObject('db')->executeQuery( $sql );
  387. }
  388. }
  389. }
  390. $this->registry->getObject('template')->getPage()->removeTag( 'venues' );
  391. $this->registry->redirectUser(array('events', 'sessions', 'list', $eid), 'Session created', 'The session has now been saved.',true);
  392. }
  393. else
  394. {
  395. $sql = "SELECT c.ID, v.name FROM content_versions v, content c, content_types ct WHERE v.ID=c.current_revision AND c.type=ct.ID AND ct.reference='venue' AND c.deleted=0 AND c.active=1";
  396. $cache = $this->registry->getObject('db')->cacheQuery( $sql );
  397. $this->registry->getObject('template')->getPage()->addTag( 'venues', array( 'SQL', $cache ) );
  398. $this->registry->getObject('template')->getPage()->addTag( 'eid', $eid );
  399. $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/add.tpl.php', 'footer.tpl.php');
  400. }
  401. }
  402. private function createSession ()
  403. {
  404. if( isset( $_POST['createsession'] ) )
  405. {
  406. $insert = array();
  407. $insert['event_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['event']);
  408. $insert['venue_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['venue']);
  409. if( isset( $_POST['date'] ) && $_POST['date'] > 0 )
  410. {
  411. $date = explode( '/', $_POST['date']);
  412. $dt = $date[2] . '-' . $date[1] .'-'. $date[0];
  413. $insert['date'] = $this->registry->getObject('db')->sanitizeData( $dt );
  414. }
  415. if( isset( $_POST['start_time'] ) && $_POST['start_time'] > 0 )
  416. {
  417. $time = explode( ':', $_POST['start_time'] );
  418. $t = $time[0].':'.$time[1];
  419. $insert['start_time'] = $this->registry->getObject('db')->sanitizeData( $t );
  420. }
  421. if( isset( $_POST['end_time'] ) && $_POST['end_time'] > 0 )
  422. {
  423. $time = explode( ':', $_POST['end_time'] );
  424. $t = $time[0].':'.$time[1];
  425. $insert['end_time'] = $this->registry->getObject('db')->sanitizeData( $t );
  426. }
  427. $insert['places'] = $this->registry->getObject('db')->sanitizeData( $_POST['places']);
  428. $insert['cost_structure'] = $this->registry->getObject('db')->sanitizeData( $_POST['cost_structure']);
  429. $insert['cost'] = $this->registry->getObject('db')->sanitizeData( $_POST['standard_cost']);
  430. $insert['discount'] = $this->registry->getObject('db')->sanitizeData( $_POST['discount']);
  431. $insert['comment'] = $this->registry->getObject('db')->sanitizeData( $_POST['comment']);
  432. $insert['active'] = 1;
  433. $insert['non_members'] = 1;
  434. $insert['pay_online'] = 1;
  435. $this->registry->getObject('db')->insertRecords( 'event_sessions', $insert);
  436. $session_id = $this->registry->getObject('db')->lastInsertID();
  437. //costs
  438. if( isset( $_POST['cost'] ) && is_array( $_POST['cost'] ) && count( $_POST['cost'] ) > 0 )
  439. {
  440. $sql = "INSERT INTO event_sessions_costs ( `session_ID`, `cost`, `type` ) VALUES ";
  441. foreach( $_POST['cost'] as $cost_type => $cost )
  442. {
  443. if( $cost == '' )
  444. {
  445. $cost = 0;
  446. }
  447. $cost = $this->registry->getObject('db')->sanitizeData( $cost );
  448. $cost_type = $this->registry->getObject('db')->sanitizeData( $cost_type );
  449. $sql .= " ( {$session_id}, {$cost}, '{$cost_type}' ),";
  450. }
  451. $sql = substr_replace($sql ,"",-1);
  452. $this->registry->getObject('db')->executeQuery( $sql );
  453. }
  454. //time slots and workshops
  455. if( isset( $_POST['times'] ) && is_array( $_POST['times'] ) && count( $_POST['times'] ) > 0 )
  456. {
  457. foreach( $_POST['times'] as $value )
  458. {
  459. $insert = array();
  460. $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $session_id );
  461. $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
  462. $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
  463. $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
  464. $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
  465. $slot_id = $this->registry->getObject('db')->lastInsertID();
  466. if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
  467. {
  468. $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
  469. foreach( $value['workshops'] as $data )
  470. {
  471. $slot_id = $this->registry->getObject('db')->sanitizeData( $slot_id );
  472. $name = $this->registry->getObject('db')->sanitizeData( $data );
  473. $sql .= " ( {$session_id}, {$slot_id}, '{$name}' ),";
  474. }
  475. $sql = substr_replace($sql ,"",-1);
  476. $this->registry->getObject('db')->executeQuery( $sql );
  477. }
  478. }
  479. }
  480. $this->registry->getObject('template')->getPage()->removeTag( 'venues' );
  481. $this->registry->getObject('template')->getPage()->removeTag( 'events' );
  482. $this->registry->redirectUser(array('events', 'sessions', '0', '0'), 'Session created', 'The session has now been saved.',true);
  483. }
  484. else
  485. {
  486. $sql = "SELECT c.ID, v.name FROM content_versions v, content c, content_types ct WHERE v.ID=c.current_revision AND c.type=ct.ID AND ct.reference='venue' AND c.deleted=0 AND c.active=1";
  487. $cache = $this->registry->getObject('db')->cacheQuery( $sql );
  488. $this->registry->getObject('template')->getPage()->addTag( 'venues', array( 'SQL', $cache ) );
  489. $sql = "SELECT c.ID, v.name FROM content_versions v, content c, content_types ct WHERE v.ID=c.current_revision AND c.type=ct.ID AND ct.reference='event' AND c.deleted=0 AND c.active=1";
  490. $cache = $this->registry->getObject('db')->cacheQuery( $sql );
  491. $this->registry->getObject('template')->getPage()->addTag( 'events', array( 'SQL', $cache ) );
  492. $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/create.tpl.php', 'footer.tpl.php');
  493. }
  494. }
  495. private function editSessionByEvent( $sid, $eid )
  496. {
  497. //session details
  498. $sql = "SELECT s.venue_id, s.discount, s.cost_structure, s.cost as standard_cost, s.event_id, DATE_FORMAT(s.date, '%m/%d/%Y') as date, DATE_FORMAT(s.start_time, '%H:%i:%s') as start_time, DATE_FORMAT(s.end_time, '%H:%i:%s') as end_time, s.places, s.comment " .
  499. "FROM event_sessions s " .
  500. "WHERE s.ID={$sid} LIMIT 1";
  501. $this->registry->getObject('db')->executeQuery($sql);
  502. $data = $this->registry->getObject('db')->getRows();
  503. $this->registry->getObject('template')->dataToTags($data, 'session_');
  504. //print_r($data);
  505. if( $data['cost_structure'] == 'standard' )
  506. {
  507. $this->registry->getObject('template')->getPage()->addTag( 'nbd_cost_structure_standard', 'checked="checked"' );
  508. }
  509. else
  510. {
  511. $this->registry->getObject('template')->getPage()->addTag( 'nbd_cost_structure_type', 'checked="checked"' );
  512. }
  513. //venues
  514. $sql = "SELECT c.ID, v.name FROM content_versions v, content c, content_types t WHERE v.ID=c.current_revision AND c.type=t.ID AND t.reference='venue' AND c.deleted=0 AND c.active=1";
  515. $cache = $this->registry->getObject('db')->cacheQuery( $sql );
  516. $this->registry->getObject('template')->getPage()->addTag( 'venues', array( 'SQL', $cache ) );
  517. //events
  518. $sql = "SELECT c.ID, v.name FROM content_versions v, content c, content_types t WHERE v.ID=c.current_revision AND c.type=t.ID AND t.reference='event' AND c.deleted=0 AND c.active=1";
  519. $cache = $this->registry->getObject('db')->cacheQuery( $sql );
  520. $this->registry->getObject('template')->getPage()->addTag( 'events', array( 'SQL', $cache ) );
  521. //costs
  522. $sql = "SELECT * FROM event_sessions_costs WHERE session_ID = {$sid}";
  523. $this->registry->getObject('db')->executeQuery($sql);
  524. $costs = array();
  525. while( $data = $this->registry->getObject('db')->getRows() )
  526. {
  527. $this->registry->getObject('template')->getPage()->addTag( 'nbd_costs_' . $data['type'], $data['cost'] );
  528. }
  529. //time slots
  530. $sql = "SELECT ID as slot_id, time, heading, description FROM event_sessions_slots WHERE session_id = {$sid} ORDER BY ID ASC";
  531. $this->registry->getObject('db')->executeQuery( $sql );
  532. $slots = array();
  533. $slot_id = '';
  534. while( $data = $this->registry->getObject('db')->getRows() )
  535. {
  536. $slots[] = $data;
  537. $slot_id = $data['slot_id'];
  538. }
  539. $next_slot_id = $slot_id + 1;
  540. $cache = $this->registry->getObject('db')->cacheData( $slots );
  541. $this->registry->getObject('template')->getPage()->addTag( 'slots', array( 'DATA', $cache ) );
  542. $this->registry->getObject('template')->getPage()->addTag( 'next_slot_id', $next_slot_id );
  543. //workshops
  544. $workshops = array();
  545. $workshop_id = '';
  546. $sql = "SELECT ID as wid, slot_id, name FROM event_sessions_slots_workshops WHERE session_id = {$sid} ORDER BY ID ASC";
  547. $this->registry->getObject('db')->executeQuery( $sql );
  548. while( $row = $this->registry->getObject('db')->getRows() )
  549. {
  550. if( in_array( $row['slot_id'], array_keys( $workshops ) ) )
  551. {
  552. $workshops[ $row['slot_id'] ][] = $row;
  553. }
  554. else
  555. {
  556. $workshops[ $row['slot_id'] ] = array();
  557. $workshops[ $row['slot_id'] ][] = $row;
  558. }
  559. $workshop_id = $row['wid'];
  560. }
  561. $next_workshop_id = $workshop_id + 1;
  562. $this->registry->getObject('template')->getPage()->addTag( 'next_workshop_id', $next_workshop_id );
  563. foreach( $workshops as $record => $details )
  564. {
  565. $cache = $this->registry->getObject('db')->cacheData( $details );
  566. $this->registry->getObject('template')->getPage()->addPPTag( 'workshops-' . $record, array( 'DATA', $cache ) );
  567. $this->registry->getObject('template')->addTemplateBit('nbd_workshop-' . $record, 'events/sessions/workshop.tpl.php' );
  568. }
  569. if( isset( $_POST['editsession'] ) )
  570. {
  571. $update = array();
  572. $update['venue_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['venue']);
  573. if( isset( $_POST['date'] ) && $_POST['date'] > 0 )
  574. {
  575. $date = explode( '/', $_POST['date']);
  576. $dt = $date[2] . '-' . $date[1] .'-'. $date[0];
  577. $update['date'] = $this->registry->getObject('db')->sanitizeData( $dt );
  578. }
  579. if( isset( $_POST['start_time'] ) && $_POST['start_time'] > 0 )
  580. {
  581. $time = explode( ':', $_POST['start_time'] );
  582. $t = $time[0].':'.$time[1];
  583. $update['start_time'] = $this->registry->getObject('db')->sanitizeData( $t );
  584. }
  585. if( isset( $_POST['end_time'] ) && $_POST['end_time'] > 0 )
  586. {
  587. $time = explode( ':', $_POST['end_time'] );
  588. $t = $time[0].':'.$time[1];
  589. $update['end_time'] = $this->registry->getObject('db')->sanitizeData( $t );
  590. }
  591. $update['places'] = $this->registry->getObject('db')->sanitizeData( $_POST['places']);
  592. $update['cost_structure'] = $this->registry->getObject('db')->sanitizeData( $_POST['cost_structure']);
  593. $update['discount'] = $this->registry->getObject('db')->sanitizeData( $_POST['discount']);
  594. $update['cost'] = $this->registry->getObject('db')->sanitizeData( $_POST['standard_cost']);
  595. $update['comment'] = $this->registry->getObject('db')->sanitizeData( $_POST['comment']);
  596. $this->registry->getObject('db')->updateRecords( 'event_sessions', $update, 'ID=' . $sid );
  597. //costs
  598. $sql = "DELETE FROM event_sessions_costs WHERE session_ID = {$sid}";
  599. $this->registry->getObject('db')->executeQuery( $sql );
  600. if( isset( $_POST['cost'] ) && is_array( $_POST['cost'] ) && count( $_POST['cost'] ) > 0 )
  601. {
  602. $sql = "INSERT INTO event_sessions_costs ( `session_ID`, `cost`, `type` ) VALUES ";
  603. foreach( $_POST['cost'] as $cost_type => $cost )
  604. {
  605. if( $cost == '' )
  606. {
  607. $cost = 0;
  608. }
  609. $cost = $this->registry->getObject('db')->sanitizeData( $cost );
  610. $cost_type = $this->registry->getObject('db')->sanitizeData( $cost_type );
  611. $sql .= " ( {$sid}, {$cost}, '{$cost_type}' ),";
  612. }
  613. $sql = substr_replace($sql ,"",-1);
  614. $this->registry->getObject('db')->executeQuery( $sql );
  615. }
  616. //time slots and workshops
  617. if( isset( $_POST['times'] ) && is_array( $_POST['times'] ) && count( $_POST['times'] ) > 0 )
  618. {
  619. //delete slots that have been removed
  620. foreach( $slots as $slot )
  621. {
  622. if( !in_array( $slot['slot_id'], array_keys( $_POST['times'] ) ) )
  623. {
  624. $sql = "DELETE FROM event_sessions_slots WHERE ID = " . $this->registry->getObject('db')->sanitizeData( $slot['slot_id'] );
  625. $this->registry->getObject('db')->executeQuery( $sql );
  626. $sql = "DELETE FROM event_sessions_slots_workshops WHERE slot_id = " . $this->registry->getObject('db')->sanitizeData( $slot['slot_id'] );
  627. $this->registry->getObject('db')->executeQuery( $sql );
  628. }
  629. }
  630. //update or insert
  631. foreach( $_POST['times'] as $value )
  632. {
  633. if( isset( $slots ) && is_array($slots) && count( $slots ) > 0 )
  634. {
  635. $action = '';
  636. foreach( $slots as $slot )
  637. {
  638. if( $value['ID'] == $slot['slot_id'] )
  639. {
  640. $action = 'update';
  641. }
  642. }
  643. if( $action == 'update' )
  644. {
  645. $update = array();
  646. $update['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
  647. $update['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
  648. $update['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
  649. $this->registry->getObject('db')->updateRecords( 'event_sessions_slots', $update, 'ID=' . $this->registry->getObject('db')->sanitizeData( $value['ID'] ) );
  650. if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
  651. {
  652. if( isset( $workshops ) && is_array($workshops) && count( $workshops ) > 0 )
  653. {
  654. //delete workshops that have been removed
  655. foreach( $workshops as $workshop => $details )
  656. {
  657. foreach( $details as $record )
  658. {
  659. if( !in_array( $record['wid'], array_keys( $value['workshops'] ) ) )
  660. {
  661. if( $value['ID'] == $record['slot_id'] )
  662. {
  663. $sql = "DELETE FROM event_sessions_slots_workshops WHERE ID = " . $this->registry->getObject('db')->sanitizeData( $record['wid'] );
  664. $this->registry->getObject('db')->executeQuery( $sql );
  665. }
  666. }
  667. }
  668. }
  669. //update or insert workshops
  670. foreach( $value['workshops'] as $workshop_values )
  671. {
  672. $workshop_action = '';
  673. foreach( $workshops as $workshop => $details )
  674. {
  675. foreach( $details as $record )
  676. {
  677. if( $record['wid'] == $workshop_values['wid'] )
  678. {
  679. $workshop_action = 'update';
  680. }
  681. }
  682. }
  683. if( $workshop_action == 'update' )
  684. {
  685. $update = array();
  686. $update['name'] = $this->registry->getObject('db')->sanitizeData( $workshop_values['name'] );
  687. $this->registry->getObject('db')->updateRecords( 'event_sessions_slots_workshops', $update, 'ID=' . $this->registry->getObject('db')->sanitizeData( $workshop_values['wid'] ) );
  688. }
  689. else
  690. {
  691. $insert = array();
  692. $insert['name'] = $this->registry->getObject('db')->sanitizeData( $workshop_values['name'] );
  693. $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
  694. $insert['slot_id'] = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  695. $this->registry->getObject('db')->insertRecords( 'event_sessions_slots_workshops', $insert );
  696. }
  697. }
  698. }
  699. else
  700. {
  701. $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
  702. foreach( $value['workshops'] as $data )
  703. {
  704. $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  705. $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
  706. $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
  707. }
  708. $sql = substr_replace($sql ,"",-1);
  709. $this->registry->getObject('db')->executeQuery( $sql );
  710. }
  711. }
  712. else
  713. {
  714. $sql = "DELETE FROM event_sessions_slots_workshops WHERE slot_id = " . $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  715. $this->registry->getObject('db')->executeQuery( $sql );
  716. }
  717. }
  718. else
  719. {
  720. $insert = array();
  721. $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
  722. $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
  723. $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
  724. $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
  725. $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
  726. $slot_id = $this->registry->getObject('db')->lastInsertID();
  727. if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
  728. {
  729. $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
  730. foreach( $value['workshops'] as $data )
  731. {
  732. $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  733. $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
  734. $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
  735. }
  736. $sql = substr_replace($sql ,"",-1);
  737. $this->registry->getObject('db')->executeQuery( $sql );
  738. }
  739. }
  740. }
  741. else
  742. {
  743. $insert = array();
  744. $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
  745. $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
  746. $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
  747. $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
  748. $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
  749. $slot_id = $this->registry->getObject('db')->lastInsertID();
  750. if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
  751. {
  752. $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
  753. foreach( $value['workshops'] as $data )
  754. {
  755. $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  756. $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
  757. $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
  758. }
  759. $sql = substr_replace($sql ,"",-1);
  760. $this->registry->getObject('db')->executeQuery( $sql );
  761. }
  762. }
  763. }
  764. }
  765. else
  766. {
  767. $sql = "DELETE FROM event_sessions_slots WHERE session_id = {$sid}";
  768. $this->registry->getObject('db')->executeQuery( $sql );
  769. }
  770. $this->registry->getObject('template')->getPage()->removeTag( 'venues' );
  771. $url = array( 'events', 'sessions', 'list', $eid );
  772. $this->registry->redirectUser( $url, 'Session updated', 'Taking you to the course sessions screen', true );
  773. }
  774. else
  775. {
  776. $this->registry->getObject('template')->getPage()->addAdditionalParsingData( 'venues', 'ID', $data['venue_id'], 'opt', "selected='selected'" );
  777. $this->registry->getObject('template')->getPage()->addTag( 'sid', $sid );
  778. $this->registry->getObject('template')->getPage()->addTag( 'eid', $eid );
  779. $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/editsessionbyevent.tpl.php', 'footer.tpl.php');
  780. }
  781. }
  782. private function editSession( $sid, $type )
  783. {
  784. //session details
  785. $sql = "SELECT s.venue_id, s.discount, s.cost_structure, s.cost as standard_cost, s.event_id, DATE_FORMAT(s.date, '%m/%d/%Y') as date, DATE_FORMAT(s.start_time, '%H:%i:%s') as start_time, DATE_FORMAT(s.end_time, '%H:%i:%s') as end_time, s.places, s.comment " .
  786. "FROM event_sessions s " .
  787. "WHERE s.ID={$sid} LIMIT 1";
  788. //print_r($sql);
  789. $this->registry->getObject('db')->executeQuery($sql);
  790. $data = $this->registry->getObject('db')->getRows();
  791. $this->registry->getObject('template')->dataToTags($data, 'session_');
  792. //print_r($data);
  793. if( $data['cost_structure'] == 'standard' )
  794. {
  795. $this->registry->getObject('template')->getPage()->addTag( 'nbd_cost_structure_standard', 'checked="checked"' );
  796. }
  797. else
  798. {
  799. $this->registry->getObject('template')->getPage()->addTag( 'nbd_cost_structure_type', 'checked="checked"' );
  800. }
  801. //venues
  802. $sql = "SELECT c.ID, v.name FROM content_versions v, content c, content_types t WHERE v.ID=c.current_revision AND c.type=t.ID AND t.reference='venue' AND c.deleted=0 AND c.active=1";
  803. $cache = $this->registry->getObject('db')->cacheQuery( $sql );
  804. $this->registry->getObject('template')->getPage()->addTag( 'venues', array( 'SQL', $cache ) );
  805. //events
  806. $sql = "SELECT c.ID, v.name FROM content_versions v, content c, content_types t WHERE v.ID=c.current_revision AND c.type=t.ID AND t.reference='event' AND c.deleted=0 AND c.active=1";
  807. $cache = $this->registry->getObject('db')->cacheQuery( $sql );
  808. $this->registry->getObject('template')->getPage()->addTag( 'events', array( 'SQL', $cache ) );
  809. //costs
  810. $sql = "SELECT * FROM event_sessions_costs WHERE session_ID = {$sid}";
  811. $this->registry->getObject('db')->executeQuery($sql);
  812. $costs = array();
  813. while( $data = $this->registry->getObject('db')->getRows() )
  814. {
  815. $this->registry->getObject('template')->getPage()->addTag( 'nbd_costs_' . $data['type'], $data['cost'] );
  816. }
  817. //time slots
  818. $sql = "SELECT ID as slot_id, time, heading, description FROM event_sessions_slots WHERE session_id = {$sid} ORDER BY ID ASC";
  819. $this->registry->getObject('db')->executeQuery( $sql );
  820. $slots = array();
  821. $slot_id = '';
  822. while( $data = $this->registry->getObject('db')->getRows() )
  823. {
  824. $slots[] = $data;
  825. $slot_id = $data['slot_id'];
  826. }
  827. $next_slot_id = $slot_id + 1;
  828. $cache = $this->registry->getObject('db')->cacheData( $slots );
  829. $this->registry->getObject('template')->getPage()->addTag( 'slots', array( 'DATA', $cache ) );
  830. $this->registry->getObject('template')->getPage()->addTag( 'next_slot_id', $next_slot_id );
  831. //workshops
  832. $workshops = array();
  833. $workshop_id = '';
  834. $sql = "SELECT ID as wid, slot_id, name FROM event_sessions_slots_workshops WHERE session_id = {$sid} ORDER BY ID ASC";
  835. $this->registry->getObject('db')->executeQuery( $sql );
  836. while( $row = $this->registry->getObject('db')->getRows() )
  837. {
  838. if( in_array( $row['slot_id'], array_keys( $workshops ) ) )
  839. {
  840. $workshops[ $row['slot_id'] ][] = $row;
  841. }
  842. else
  843. {
  844. $workshops[ $row['slot_id'] ] = array();
  845. $workshops[ $row['slot_id'] ][] = $row;
  846. }
  847. $workshop_id = $row['wid'];
  848. }
  849. $next_workshop_id = $workshop_id + 1;
  850. $this->registry->getObject('template')->getPage()->addTag( 'next_workshop_id', $next_workshop_id );
  851. foreach( $workshops as $record => $details )
  852. {
  853. $cache = $this->registry->getObject('db')->cacheData( $details );
  854. $this->registry->getObject('template')->getPage()->addPPTag( 'workshops-' . $record, array( 'DATA', $cache ) );
  855. $this->registry->getObject('template')->addTemplateBit('nbd_workshop-' . $record, 'events/sessions/workshop.tpl.php' );
  856. }
  857. if( isset( $_POST['editsession'] ) )
  858. {
  859. $update = array();
  860. $update['event_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['event']);
  861. $update['venue_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['venue']);
  862. if( isset( $_POST['date'] ) && $_POST['date'] > 0 )
  863. {
  864. $date = explode( '/', $_POST['date']);
  865. $dt = $date[2] . '-' . $date[1] .'-'. $date[0];
  866. $update['date'] = $this->registry->getObject('db')->sanitizeData( $dt );
  867. }
  868. if( isset( $_POST['start_time'] ) && $_POST['start_time'] > 0 )
  869. {
  870. $time = explode( ':', $_POST['start_time'] );
  871. $t = $time[0].':'.$time[1];
  872. $update['start_time'] = $this->registry->getObject('db')->sanitizeData( $t );
  873. }
  874. if( isset( $_POST['end_time'] ) && $_POST['end_time'] > 0 )
  875. {
  876. $time = explode( ':', $_POST['end_time'] );
  877. $t = $time[0].':'.$time[1];
  878. $update['end_time'] = $this->registry->getObject('db')->sanitizeData( $t );
  879. }
  880. $update['places'] = $this->registry->getObject('db')->sanitizeData( $_POST['places']);
  881. $update['cost_structure'] = $this->registry->getObject('db')->sanitizeData( $_POST['cost_structure']);
  882. $update['discount'] = $this->registry->getObject('db')->sanitizeData( $_POST['discount']);
  883. $update['cost'] = $this->registry->getObject('db')->sanitizeData( $_POST['standard_cost']);
  884. $update['comment'] = $this->registry->getObject('db')->sanitizeData( $_POST['comment']);
  885. $this->registry->getObject('db')->updateRecords( 'event_sessions', $update, 'ID=' . $sid );
  886. //costs
  887. $sql = "DELETE FROM event_sessions_costs WHERE session_ID = {$sid}";
  888. $this->registry->getObject('db')->executeQuery( $sql );
  889. if( isset( $_POST['cost'] ) && is_array( $_POST['cost'] ) && count( $_POST['cost'] ) > 0 )
  890. {
  891. $sql = "INSERT INTO event_sessions_costs ( `session_ID`, `cost`, `type` ) VALUES ";
  892. foreach( $_POST['cost'] as $cost_type => $cost )
  893. {
  894. if( $cost == '' )
  895. {
  896. $cost = 0;
  897. }
  898. $cost = $this->registry->getObject('db')->sanitizeData( $cost );
  899. $cost_type = $this->registry->getObject('db')->sanitizeData( $cost_type );
  900. $sql .= " ( {$sid}, {$cost}, '{$cost_type}' ),";
  901. }
  902. $sql = substr_replace($sql ,"",-1);
  903. $this->registry->getObject('db')->executeQuery( $sql );
  904. }
  905. //time slots and workshops
  906. if( isset( $_POST['times'] ) && is_array( $_POST['times'] ) && count( $_POST['times'] ) > 0 )
  907. {
  908. //delete slots that have been removed
  909. foreach( $slots as $slot )
  910. {
  911. if( !in_array( $slot['slot_id'], array_keys( $_POST['times'] ) ) )
  912. {
  913. $sql = "DELETE FROM event_sessions_slots WHERE ID = " . $this->registry->getObject('db')->sanitizeData( $slot['slot_id'] );
  914. $this->registry->getObject('db')->executeQuery( $sql );
  915. $sql = "DELETE FROM event_sessions_slots_workshops WHERE slot_id = " . $this->registry->getObject('db')->sanitizeData( $slot['slot_id'] );
  916. $this->registry->getObject('db')->executeQuery( $sql );
  917. }
  918. }
  919. //update or insert
  920. foreach( $_POST['times'] as $value )
  921. {
  922. if( isset( $slots ) && is_array($slots) && count( $slots ) > 0 )
  923. {
  924. $action = '';
  925. foreach( $slots as $slot )
  926. {
  927. if( $value['ID'] == $slot['slot_id'] )
  928. {
  929. $action = 'update';
  930. }
  931. }
  932. if( $action == 'update' )
  933. {
  934. $update = array();
  935. $update['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
  936. $update['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
  937. $update['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
  938. $this->registry->getObject('db')->updateRecords( 'event_sessions_slots', $update, 'ID=' . $this->registry->getObject('db')->sanitizeData( $value['ID'] ) );
  939. if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
  940. {
  941. if( isset( $workshops ) && is_array($workshops) && count( $workshops ) > 0 )
  942. {
  943. //delete workshops that have been removed
  944. foreach( $workshops as $workshop => $details )
  945. {
  946. foreach( $details as $record )
  947. {
  948. if( !in_array( $record['wid'], array_keys( $value['workshops'] ) ) )
  949. {
  950. if( $value['ID'] == $record['slot_id'] )
  951. {
  952. $sql = "DELETE FROM event_sessions_slots_workshops WHERE ID = " . $this->registry->getObject('db')->sanitizeData( $record['wid'] );
  953. $this->registry->getObject('db')->executeQuery( $sql );
  954. }
  955. }
  956. }
  957. }
  958. //update or insert workshops
  959. foreach( $value['workshops'] as $workshop_values )
  960. {
  961. $workshop_action = '';
  962. foreach( $workshops as $workshop => $details )
  963. {
  964. foreach( $details as $record )
  965. {
  966. if( $record['wid'] == $workshop_values['wid'] )
  967. {
  968. $workshop_action = 'update';
  969. }
  970. }
  971. }
  972. if( $workshop_action == 'update' )
  973. {
  974. $update = array();
  975. $update['name'] = $this->registry->getObject('db')->sanitizeData( $workshop_values['name'] );
  976. $this->registry->getObject('db')->updateRecords( 'event_sessions_slots_workshops', $update, 'ID=' . $this->registry->getObject('db')->sanitizeData( $workshop_values['wid'] ) );
  977. }
  978. else
  979. {
  980. $insert = array();
  981. $insert['name'] = $this->registry->getObject('db')->sanitizeData( $workshop_values['name'] );
  982. $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
  983. $insert['slot_id'] = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  984. $this->registry->getObject('db')->insertRecords( 'event_sessions_slots_workshops', $insert );
  985. }
  986. }
  987. }
  988. else
  989. {
  990. $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
  991. foreach( $value['workshops'] as $data )
  992. {
  993. $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  994. $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
  995. $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
  996. }
  997. $sql = substr_replace($sql ,"",-1);
  998. $this->registry->getObject('db')->executeQuery( $sql );
  999. }
  1000. }
  1001. else
  1002. {
  1003. $sql = "DELETE FROM event_sessions_slots_workshops WHERE slot_id = " . $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  1004. $this->registry->getObject('db')->executeQuery( $sql );
  1005. }
  1006. }
  1007. else
  1008. {
  1009. $insert = array();
  1010. $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
  1011. $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
  1012. $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
  1013. $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
  1014. $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
  1015. $slot_id = $this->registry->getObject('db')->lastInsertID();
  1016. if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
  1017. {
  1018. $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
  1019. foreach( $value['workshops'] as $data )
  1020. {
  1021. $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  1022. $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
  1023. $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
  1024. }
  1025. $sql = substr_replace($sql ,"",-1);
  1026. $this->registry->getObject('db')->executeQuery( $sql );
  1027. }
  1028. }
  1029. }
  1030. else
  1031. {
  1032. $insert = array();
  1033. $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
  1034. $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
  1035. $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
  1036. $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
  1037. $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
  1038. $slot_id = $this->registry->getObject('db')->lastInsertID();
  1039. if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
  1040. {
  1041. $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
  1042. foreach( $value['workshops'] as $data )
  1043. {
  1044. $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
  1045. $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
  1046. $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
  1047. }
  1048. $sql = substr_replace($sql ,"",-1);
  1049. $this->registry->getObject('db')->executeQuery( $sql );
  1050. }
  1051. }
  1052. }
  1053. }
  1054. else
  1055. {
  1056. $sql = "DELETE FROM event_sessions_slots WHERE session_id = {$sid}";
  1057. $this->registry->getObject('db')->executeQuery( $sql );
  1058. }
  1059. $this->registry->getObject('template')->getPage()->removeTag( 'venues' );
  1060. $this->registry->getObject('template')->getPage()->removeTag( 'events' );
  1061. if( $type == 'current' )
  1062. {
  1063. $url = array( 'events', 'sessions', 'current' );
  1064. }
  1065. else
  1066. {
  1067. $url = array( 'events', 'sessions', 'previous' );
  1068. }
  1069. $this->registry->redirectUser( $url, 'Session updated', 'Taking you to the sessions screen', true );
  1070. }
  1071. else
  1072. {
  1073. $this->registry->getObject('template')->getPage()->addTag( 'sid', $sid );
  1074. $this->registry->getObject('template')->getPage()->addTag( 'type', 'edit-'.$type );
  1075. $this->registry->getObject('template')->getPage()->addAdditionalParsingData( 'venues', 'ID', $data['venue_id'], 'opt', "selected='selected'" );
  1076. $this->registry->getObject('template')->getPage()->addAdditionalParsingData( 'events', 'ID', $data['event_id'], 'opt', "selected='selected'" );
  1077. $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/edit.tpl.php', 'footer.tpl.php');
  1078. }
  1079. }
  1080. private function delete( $type, $sid, $eid )
  1081. {
  1082. $sql = "UPDATE event_sessions SET deleted=1 WHERE ID={$sid}";
  1083. $this->registry->getObject('db')->executeQuery( $sql );
  1084. $sql = "DELETE FROM event_teeing_off_times WHERE session_id = {$sid}";
  1085. $this->registry->getObject('db')->executeQuery( $sql );
  1086. if( $type == 0 )
  1087. {
  1088. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
  1089. }
  1090. elseif( $type == 1 )
  1091. {
  1092. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'previous'), '', true ) );
  1093. }
  1094. else
  1095. {
  1096. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
  1097. }
  1098. exit();
  1099. }
  1100. private function toggleActiveSession( $type, $id, $eid )
  1101. {
  1102. $sql = "UPDATE event_sessions SET active=1-active WHERE ID={$id}";
  1103. $this->registry->getObject('db')->executeQuery( $sql );
  1104. if( $type == 0 )
  1105. {
  1106. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
  1107. }
  1108. else
  1109. {
  1110. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
  1111. }
  1112. exit();
  1113. }
  1114. private function toggleBookable( $type, $id, $eid )
  1115. {
  1116. $sql = "UPDATE event_sessions SET bookable=1-bookable WHERE ID={$id}";
  1117. $this->registry->getObject('db')->executeQuery( $sql );
  1118. if( $type == 0 )
  1119. {
  1120. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
  1121. }
  1122. else
  1123. {
  1124. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
  1125. }
  1126. exit();
  1127. }
  1128. private function toggleNonMembers( $type, $id, $eid )
  1129. {
  1130. $sql = "UPDATE event_sessions SET non_members=1-non_members WHERE ID={$id}";
  1131. $this->registry->getObject('db')->executeQuery( $sql );
  1132. if( $type == 0 )
  1133. {
  1134. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
  1135. }
  1136. else
  1137. {
  1138. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
  1139. }
  1140. exit();
  1141. }
  1142. private function togglePayOnline( $type, $id, $eid )
  1143. {
  1144. $sql = "UPDATE event_sessions SET pay_online=1-pay_online WHERE ID={$id}";
  1145. $this->registry->getObject('db')->executeQuery( $sql );
  1146. if( $type == 0 )
  1147. {
  1148. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
  1149. }
  1150. else
  1151. {
  1152. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
  1153. }
  1154. exit();
  1155. }
  1156. private function toggleOpen( $type, $id, $eid )
  1157. {
  1158. $sql = "UPDATE event_sessions SET open=1-open WHERE ID={$id}";
  1159. $this->registry->getObject('db')->executeQuery( $sql );
  1160. if( $type == 0 )
  1161. {
  1162. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
  1163. }
  1164. else
  1165. {
  1166. header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
  1167. }
  1168. exit();
  1169. }
  1170. private function toggleActiveSessionFixture( $id, $fid )
  1171. {
  1172. $sql = "UPDATE event_sessions SET active=1-active WHERE ID={$id}";
  1173. $this->registry->getObject('db')->executeQuery( $sql );
  1174. header('Location: ' . $this->registry->buildURL(array('events', 'fixtures', 'view', $fid), '', true ) );
  1175. exit();
  1176. }
  1177. private function listAttendees( $id, $offset=0 )
  1178. {
  1179. $this->registry->getObject('template')->getPage()->addTag( 'session_ID', $id );
  1180. $sql = "SELECT a.*, o.ID as order_id, IF( a.cancelled > 0, 'Cancelled', CONCAT( '<a href=\"events/sessions/cancel-attendee/', CONCAT( a.ID, '/', a.session_ID ), '\">Cancel</a>' ) ) as cancelled FROM event_session_attendees a, eventorders o WHERE o.ID = a.order AND a.session_ID = {$id} ORDER BY `order`, name ASC";
  1181. $pagination = $this->registry->pagination( $sql, 20, $offset, 'cache' );
  1182. $this->registry->getObject('template')->getPage()->addTag('attendees', array( 'SQL', $pagination['cache'] ) );
  1183. $this->registry->getObject('template')->getPage()->addTag('page_number', $pagination['cur_page'] );
  1184. $this->registry->getObject('template')->getPage()->addTag('num_pages', $pagination['num_pages'] );
  1185. // pagination links
  1186. if( $pagination['is_first'] == true )
  1187. {
  1188. $this->registry->getObject('template')->getPage()->addTag('first', '');
  1189. $this->registry->getObject('template')->getPage()->addTag('previous', '');
  1190. }
  1191. else
  1192. {
  1193. $this->registry->getObject('template')->getPage()->addTag('first', "<li><a href='events/sessions/attendees/$id/page/'>First Page</a></li>");
  1194. $this->registry->getObject('template')->getPage()->addTag('previous', "<li><a href='events/sessions/attendees/$id/page/". ( $pagination['cur_page'] - 2 ) . "'>Previous Page</a></li>");
  1195. }
  1196. if( $pagination['is_last'] == true )
  1197. {
  1198. $this->registry->getObject('template')->getPage()->addTag('next', '');
  1199. $this->registry->getObject('template')->getPage()->addTag('last', '');
  1200. }
  1201. else
  1202. {
  1203. $this->registry->getObject('template')->getPage()->addTag('last', "<li><a href='events/sessions/attendees/$id/page/". ( $pagination['num_pages'] - 1 ) ."'>Last Page</a></li>");
  1204. $this->registry->getObject('template')->getPage()->addTag('next', "<li><a href='events/sessions/attendees/$id/page/". ( $pagination['cur_page'] ) . "'>Next Page</a></li>");
  1205. }
  1206. $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/attendees.tpl.php', 'footer.tpl.php' );
  1207. }
  1208. private function cancelAttendee( $id, $sid )
  1209. {
  1210. $sql = "UPDATE event_session_attendees SET cancelled=1 WHERE ID={$id}";
  1211. $this->registry->getObject('db')->executeQuery( $sql );
  1212. $this->registry->redirectUser( array('events', 'sessions', 'attendees', $sid), 'Attendee cancelled', 'The attendee has been cancelled and the space released.', true );
  1213. }
  1214. }
  1215. ?>