/trunk/manage/controllers/events/sessioncontroller.php
PHP | 1370 lines | 1169 code | 155 blank | 46 comment | 168 complexity | 3fdc1061bd681561bdc149e7fa8bd5ac MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
-
- class Sessioncontroller {
-
- public function __construct( PeacockCarterFrameworkRegistry $registry, $directCall )
- {
- $this->registry = $registry;
- if( $this->registry->getObject('authenticate')->isAuthorised('events_sessions') == true )
- {
- $this->registry->getObject('adminmenubuilder')->buildMenu( 'events.sessions' );
- if( $this->registry->getURLBit(1) != '' )
- {
-
- switch( $this->registry->getURLBit(2) )
- {
- case'add':
- $this->addSession( intval( $this->registry->getURLBit(3) ) );
- break;
- case'create':
- $this->createSession( );
- break;
- case'edit':
- $this->editSessionByEvent( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ));
- break;
- case'edit-current':
- $this->editSession( intval( $this->registry->getURLBit(3) ), 'current' );
- break;
- case'edit-previous':
- $this->editSession( intval( $this->registry->getURLBit(3) ), 'previous' );
- break;
- case'delete':
- $this->delete( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ) );
- break;
- case'previous':
- $this->listPrevious( intval( $this->registry->getURLBit(4) ) );
- break;
- case'current':
- $this->listCurrent( intval( $this->registry->getURLBit(4) ) );
- break;
- case'attendees':
- $this->listAttendees( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(5) ) );
- break;
- case 'cancel-attendee':
- $this->cancelAttendee( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ));
- break;
- case 'toggle-active':
- $this->toggleActiveSession( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ));
- break;
- case 'toggle-pay-online':
- $this->togglePayOnline( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ));
- break;
- case 'toggle-bookable':
- $this->toggleBookable( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ));
- break;
- case 'toggle-non-members':
- $this->toggleNonMembers( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ), intval( $this->registry->getURLBit(5) ));
- break;
- case 'toggle-featured':
- $this->toggleFeatured( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ));
- break;
- case 'toggle-active-session':
- $this->toggleActiveSessionFixture( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(4) ));
- break;
- case 'list':
- $this->listSessions ( intval( $this->registry->getURLBit(3) ), intval( $this->registry->getURLBit(5) ) );
- break;
- case 'details-attendees':
- $this->detailsAttendees( intval( $this->registry->getURLBit(3) ) );
- break;
- default:
- $this->listCurrent( intval( $this->registry->getURLBit(4) ) );
- break;
- }
- }
- else
- {
- $this->listCurrent( intval( $this->registry->getURLBit(4) ) );
- }
-
- }
- else
- {
- $this->registry->getObject('authenticate')->redirectToAuthorised('primary');
- }
- }
-
- private function detailsAttendees( $sid )
- {
- $this->registry->getObject('template')->getPage()->removeTag( 'admin_menu_primary' );
- $this->registry->getObject('template')->getPage()->removeTag( 'admin_menu_sub' );
- /*
- $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, " .
- "DATE_FORMAT(start_time, '%H:%i') as start_time, DATE_FORMAT(end_time, '%H:%i') as end_time, " .
- "((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, " .
- "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 " .
- "FROM event_sessions s, content_versions ev, content ec, content_versions vv, content vc " .
- "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";
- */
-
-
- $sql = "SELECT vv.name as venue, ev.name as event, DATE_FORMAT(s.date, '%D %M %Y') as date, " .
- "DATE_FORMAT(start_time, '%H:%i') as start_time, DATE_FORMAT(end_time, '%H:%i') as end_time " .
- "FROM event_sessions s, content_versions ev, content ec, content_versions vv, content vc " .
- "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";
- $this->registry->getObject('db')->executeQuery( $sql );
- $data = $this->registry->getObject('db')->getRows();
- $this->registry->getObject('template')->dataToTags( $data, '' );
-
-
- $sql = "SELECT *, ID as aid FROM event_session_attendees WHERE session_id = {$sid} AND cancelled = 0 ORDER BY name ASC";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $this->registry->getObject('db')->numRows() > 0 )
- {
- $attendees = array();
- $event_sessions = array();
- $session_ids = '';
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- if( !in_array( $row['session_id'], ( $event_sessions ) ) )
- {
- $session_ids .= $row['session_id'] . ',';
- $event_sessions[] = $row['session_id'];
- }
-
- if( in_array( $row['aid'], array_keys( $attendees ) ) )
- {
- $attendees[ $row['aid'] ][] = $row;
- }
- else
- {
- $attendees[ $row['aid'] ] = array();
- $attendees[ $row['aid'] ][] = $row;
- }
- }
- $session_ids = substr( $session_ids, 0, -1 );
-
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'attendees', array( 'SQL', $cache ) );
-
- //get the time slots and workshops for this session
- $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";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $this->registry->getObject('db')->numRows() > 0 )
- {
- $slots = array();
- while( $data = $this->registry->getObject('db')->getRows() )
- {
- if( in_array( $data['session_id'], array_keys( $slots ) ) )
- {
- $slots[ $data['session_id'] ][] = $data;
- }
- else
- {
- $slots[ $data['session_id'] ] = array();
- $slots[ $data['session_id'] ][] = $data;
- }
- }
-
- foreach( $attendees as $attendee => $details )
- {
- foreach( $details as $record )
- {
- if( in_array( $record ['session_id'], array_keys( $slots ) ) )
- {
- $this->registry->getObject('template')->addTemplateBit('workshops-' . $attendee, 'events/sessions/workshops.tpl.php', array('session_id' => $record['session_id'], 'aid' => $attendee ) );
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag( 'workshops-' . $attendee, '' );
- }
- }
- }
-
- foreach( $attendees as $attendee => $details )
- {
- foreach( $slots as $session => $details )
- {
- $cache = $this->registry->getObject('db')->cacheData( $details );
- $this->registry->getObject('template')->getPage()->addPPTag( 'slots-' . $session . '-' . $attendee, array( 'DATA', $cache ) );
- }
- }
-
- //workshops
- $workshops = array();
- $sql = "SELECT ID as wid, slot_id, name as workshop FROM event_sessions_slots_workshops WHERE session_id IN ( $session_ids )";
- $this->registry->getObject('db')->executeQuery( $sql );
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- if( in_array( $row['slot_id'], array_keys( $workshops ) ) )
- {
- $workshops[ $row['slot_id'] ][] = $row;
- }
- else
- {
- $workshops[ $row['slot_id'] ] = array();
- $workshops[ $row['slot_id'] ][] = $row;
- }
- }
- foreach( $attendees as $attendee => $data )
- {
- foreach( $workshops as $record => $details )
- {
- $cache = $this->registry->getObject('db')->cacheData( $details );
- $this->registry->getObject('template')->getPage()->addPPTag( 'workshops-' . $record . '-' . $attendee , array( 'DATA', $cache ) );
- }
- }
-
- //get attendee preferences
- $sql = "SELECT w.* FROM event_session_attendees_workshops w, event_session_attendees a WHERE w.attendee_id = a.ID AND a.session_id = {$sid}";
- $this->registry->getObject('db')->executeQuery( $sql );
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- $this->registry->getObject('template')->getPage()->addPPTag( $row['attendee_id'] . $row['workshop_id'], $row['preference'] );
- }
-
- }
- else
- {
- foreach( $attendees as $attendee => $data )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'workshops-' . $attendee, '' );
- }
- }
- }
- $this->registry->getObject('template')->buildFromTemplates( 'events/sessions/details-attendees.tpl.php' );
- }
-
- private function toggleFeatured( $id, $eid )
- {
- $sql = "UPDATE event_sessions SET featured=1-featured WHERE ID={$id}";
- $this->registry->getObject('db')->executeQuery( $sql );
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
- exit();
- }
-
- private function listSessions( $eid, $offset=0 )
- {
- $sql = "SELECT ver.name as event FROM content_versions ver, content con WHERE con.current_revision = ver.ID AND con.ID = {$eid}";
- $this->registry->getObject('db')->executeQuery($sql);
- $data = $this->registry->getObject('db')->getRows();
- $this->registry->getObject('template')->getPage()->addTag( 'event', $data['event'] );
- $this->registry->getObject('template')->getPage()->addTag( 'eid', $eid );
-
- $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";
-
- $pagination = $this->registry->pagination( $sql, 10, $offset, 'cache' );
- $this->registry->getObject('template')->getPage()->addTag('sessions', array( 'SQL', $pagination['cache'] ) );
- $this->registry->getObject('template')->getPage()->addTag('page_number', $pagination['cur_page'] );
- $this->registry->getObject('template')->getPage()->addTag('num_pages', $pagination['num_pages'] );
-
- // pagination links
- if( $pagination['is_first'] == true )
- {
- $this->registry->getObject('template')->getPage()->addTag('first', '');
- $this->registry->getObject('template')->getPage()->addTag('previous', '');
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('first', "<li><a href='events/sessions/list/$eid/page/'>First Page</a></li>");
- $this->registry->getObject('template')->getPage()->addTag('previous', "<li><a href='events/sessions/list/$eid/page/". ( $pagination['cur_page'] - 2 ) . "'>Previous Page</a></li>");
- }
- if( $pagination['is_last'] == true )
- {
- $this->registry->getObject('template')->getPage()->addTag('next', '');
- $this->registry->getObject('template')->getPage()->addTag('last', '');
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('last', "<li><a href='events/sessions/list/$eid/page/". ( $pagination['num_pages'] - 1 ) ."'>Last Page</a></li>");
- $this->registry->getObject('template')->getPage()->addTag('next', "<li><a href='events/sessions/list/$eid/page/". ( $pagination['cur_page'] ) . "'>Next Page</a></li>");
-
- }
-
- $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'events/sessions/list.tpl.php', 'footer.tpl.php');
-
- }
-
- private function listPrevious( $offset=0 )
- {
- $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";
- $pagination = $this->registry->pagination( $sql, 10, $offset, 'cache' );
-
- $this->registry->getObject('template')->getPage()->addTag('sessions', array( 'SQL', $pagination['cache'] ) );
- $this->registry->getObject('template')->getPage()->addTag('page_number', $pagination['cur_page'] );
- $this->registry->getObject('template')->getPage()->addTag('num_pages', $pagination['num_pages'] );
-
- // pagination links
- if( $pagination['is_first'] == true )
- {
- $this->registry->getObject('template')->getPage()->addTag('first', '');
- $this->registry->getObject('template')->getPage()->addTag('previous', '');
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('first', "<li><a href='events/sessions/previous/page/'>First Page</a></li>");
- $this->registry->getObject('template')->getPage()->addTag('previous', "<li><a href='events/sessions/previous/page/". ( $pagination['cur_page'] - 2 ) . "'>Previous Page</a></li>");
- }
- if( $pagination['is_last'] == true )
- {
- $this->registry->getObject('template')->getPage()->addTag('next', '');
- $this->registry->getObject('template')->getPage()->addTag('last', '');
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('last', "<li><a href='events/sessions/previous/page/". ( $pagination['num_pages'] - 1 ) ."'>Last Page</a></li>");
- $this->registry->getObject('template')->getPage()->addTag('next', "<li><a href='events/sessions/previous/page/". ( $pagination['cur_page'] ) . "'>Next Page</a></li>");
-
- }
-
- $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'events/sessions/previous.tpl.php', 'footer.tpl.php');
-
- }
-
- private function listCurrent( $offset=0 )
- {
- $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";
-
- $pagination = $this->registry->pagination( $sql, 10, $offset, 'cache' );
-
- $this->registry->getObject('template')->getPage()->addTag('sessions', array( 'SQL', $pagination['cache'] ) );
- $this->registry->getObject('template')->getPage()->addTag('page_number', $pagination['cur_page'] );
- $this->registry->getObject('template')->getPage()->addTag('num_pages', $pagination['num_pages'] );
-
- // pagination links
- if( $pagination['is_first'] == true )
- {
- $this->registry->getObject('template')->getPage()->addTag('first', '');
- $this->registry->getObject('template')->getPage()->addTag('previous', '');
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('first', "<li><a href='events/sessions/current/page/'>First Page</a></li>");
- $this->registry->getObject('template')->getPage()->addTag('previous', "<li><a href='events/sessions/current/page/". ( $pagination['cur_page'] - 2 ) . "'>Previous Page</a></li>");
- }
- if( $pagination['is_last'] == true )
- {
- $this->registry->getObject('template')->getPage()->addTag('next', '');
- $this->registry->getObject('template')->getPage()->addTag('last', '');
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('last', "<li><a href='events/sessions/current/page/". ( $pagination['num_pages'] - 1 ) ."'>Last Page</a></li>");
- $this->registry->getObject('template')->getPage()->addTag('next', "<li><a href='events/sessions/current/page/". ( $pagination['cur_page'] ) . "'>Next Page</a></li>");
-
- }
-
- $this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'events/sessions/current.tpl.php', 'footer.tpl.php');
-
- }
-
- private function addSession( $eid )
- {
- if( isset( $_POST['createsession'] ) )
- {
- $insert = array();
- $insert['event_id'] = $this->registry->getObject('db')->sanitizeData( $eid );
- $insert['venue_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['venue']);
-
- if( isset( $_POST['date'] ) && $_POST['date'] > 0 )
- {
- $date = explode( '/', $_POST['date']);
- $dt = $date[2] . '-' . $date[1] .'-'. $date[0];
- $insert['date'] = $this->registry->getObject('db')->sanitizeData( $dt );
- }
-
- if( isset( $_POST['start_time'] ) && $_POST['start_time'] > 0 )
- {
-
- $time = explode( ':', $_POST['start_time'] );
- $t = $time[0].':'.$time[1];
- $insert['start_time'] = $this->registry->getObject('db')->sanitizeData( $t );
-
- }
-
- if( isset( $_POST['end_time'] ) && $_POST['end_time'] > 0 )
- {
- $time = explode( ':', $_POST['end_time'] );
- $t = $time[0].':'.$time[1];
- $insert['end_time'] = $this->registry->getObject('db')->sanitizeData( $t );
- }
-
- $insert['places'] = $this->registry->getObject('db')->sanitizeData( $_POST['places']);
- $insert['cost_structure'] = $this->registry->getObject('db')->sanitizeData( $_POST['cost_structure']);
- $insert['cost'] = $this->registry->getObject('db')->sanitizeData( $_POST['standard_cost']);
- $insert['discount'] = $this->registry->getObject('db')->sanitizeData( $_POST['discount']);
- $insert['comment'] = $this->registry->getObject('db')->sanitizeData( $_POST['comment']);
- $insert['active'] = 1;
- $insert['non_members'] = 1;
- $insert['pay_online'] = 1;
- $this->registry->getObject('db')->insertRecords( 'event_sessions', $insert);
- $session_id = $this->registry->getObject('db')->lastInsertID();
-
- //costs
- if( isset( $_POST['cost'] ) && is_array( $_POST['cost'] ) && count( $_POST['cost'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_costs ( `session_ID`, `cost`, `type` ) VALUES ";
- foreach( $_POST['cost'] as $cost_type => $cost )
- {
- if( $cost == '' )
- {
- $cost = 0;
- }
- $cost = $this->registry->getObject('db')->sanitizeData( $cost );
- $cost_type = $this->registry->getObject('db')->sanitizeData( $cost_type );
- $sql .= " ( {$session_id}, {$cost}, '{$cost_type}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- //time slots and workshops
- if( isset( $_POST['times'] ) && is_array( $_POST['times'] ) && count( $_POST['times'] ) > 0 )
- {
- foreach( $_POST['times'] as $value )
- {
- $insert = array();
- $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $session_id );
- $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
- $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
- $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
- $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
- $slot_id = $this->registry->getObject('db')->lastInsertID();
-
- if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
- foreach( $value['workshops'] as $data )
- {
- $slot_id = $this->registry->getObject('db')->sanitizeData( $slot_id );
- $name = $this->registry->getObject('db')->sanitizeData( $data );
- $sql .= " ( {$session_id}, {$slot_id}, '{$name}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- }
-
- }
-
- $this->registry->getObject('template')->getPage()->removeTag( 'venues' );
- $this->registry->redirectUser(array('events', 'sessions', 'list', $eid), 'Session created', 'The session has now been saved.',true);
- }
- else
- {
- $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";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'venues', array( 'SQL', $cache ) );
- $this->registry->getObject('template')->getPage()->addTag( 'eid', $eid );
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/add.tpl.php', 'footer.tpl.php');
- }
-
- }
-
- private function createSession ()
- {
- if( isset( $_POST['createsession'] ) )
- {
- $insert = array();
- $insert['event_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['event']);
- $insert['venue_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['venue']);
-
- if( isset( $_POST['date'] ) && $_POST['date'] > 0 )
- {
- $date = explode( '/', $_POST['date']);
- $dt = $date[2] . '-' . $date[1] .'-'. $date[0];
- $insert['date'] = $this->registry->getObject('db')->sanitizeData( $dt );
- }
-
- if( isset( $_POST['start_time'] ) && $_POST['start_time'] > 0 )
- {
-
- $time = explode( ':', $_POST['start_time'] );
- $t = $time[0].':'.$time[1];
- $insert['start_time'] = $this->registry->getObject('db')->sanitizeData( $t );
-
- }
-
- if( isset( $_POST['end_time'] ) && $_POST['end_time'] > 0 )
- {
- $time = explode( ':', $_POST['end_time'] );
- $t = $time[0].':'.$time[1];
- $insert['end_time'] = $this->registry->getObject('db')->sanitizeData( $t );
- }
-
- $insert['places'] = $this->registry->getObject('db')->sanitizeData( $_POST['places']);
- $insert['cost_structure'] = $this->registry->getObject('db')->sanitizeData( $_POST['cost_structure']);
- $insert['cost'] = $this->registry->getObject('db')->sanitizeData( $_POST['standard_cost']);
- $insert['discount'] = $this->registry->getObject('db')->sanitizeData( $_POST['discount']);
- $insert['comment'] = $this->registry->getObject('db')->sanitizeData( $_POST['comment']);
- $insert['active'] = 1;
- $insert['non_members'] = 1;
- $insert['pay_online'] = 1;
- $this->registry->getObject('db')->insertRecords( 'event_sessions', $insert);
- $session_id = $this->registry->getObject('db')->lastInsertID();
-
- //costs
- if( isset( $_POST['cost'] ) && is_array( $_POST['cost'] ) && count( $_POST['cost'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_costs ( `session_ID`, `cost`, `type` ) VALUES ";
- foreach( $_POST['cost'] as $cost_type => $cost )
- {
- if( $cost == '' )
- {
- $cost = 0;
- }
- $cost = $this->registry->getObject('db')->sanitizeData( $cost );
- $cost_type = $this->registry->getObject('db')->sanitizeData( $cost_type );
- $sql .= " ( {$session_id}, {$cost}, '{$cost_type}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- //time slots and workshops
- if( isset( $_POST['times'] ) && is_array( $_POST['times'] ) && count( $_POST['times'] ) > 0 )
- {
- foreach( $_POST['times'] as $value )
- {
- $insert = array();
- $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $session_id );
- $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
- $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
- $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
- $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
- $slot_id = $this->registry->getObject('db')->lastInsertID();
-
- if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
- foreach( $value['workshops'] as $data )
- {
- $slot_id = $this->registry->getObject('db')->sanitizeData( $slot_id );
- $name = $this->registry->getObject('db')->sanitizeData( $data );
- $sql .= " ( {$session_id}, {$slot_id}, '{$name}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- }
-
- }
-
- $this->registry->getObject('template')->getPage()->removeTag( 'venues' );
- $this->registry->getObject('template')->getPage()->removeTag( 'events' );
-
- $this->registry->redirectUser(array('events', 'sessions', '0', '0'), 'Session created', 'The session has now been saved.',true);
- }
- else
- {
- $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";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'venues', array( 'SQL', $cache ) );
-
- $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";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'events', array( 'SQL', $cache ) );
-
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/create.tpl.php', 'footer.tpl.php');
- }
-
- }
-
-
-
- private function editSessionByEvent( $sid, $eid )
- {
- //session details
- $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 " .
- "FROM event_sessions s " .
- "WHERE s.ID={$sid} LIMIT 1";
- $this->registry->getObject('db')->executeQuery($sql);
- $data = $this->registry->getObject('db')->getRows();
- $this->registry->getObject('template')->dataToTags($data, 'session_');
- //print_r($data);
- if( $data['cost_structure'] == 'standard' )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'nbd_cost_structure_standard', 'checked="checked"' );
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag( 'nbd_cost_structure_type', 'checked="checked"' );
- }
-
- //venues
- $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";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'venues', array( 'SQL', $cache ) );
-
- //events
- $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";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'events', array( 'SQL', $cache ) );
-
- //costs
- $sql = "SELECT * FROM event_sessions_costs WHERE session_ID = {$sid}";
- $this->registry->getObject('db')->executeQuery($sql);
- $costs = array();
- while( $data = $this->registry->getObject('db')->getRows() )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'nbd_costs_' . $data['type'], $data['cost'] );
- }
-
- //time slots
- $sql = "SELECT ID as slot_id, time, heading, description FROM event_sessions_slots WHERE session_id = {$sid} ORDER BY ID ASC";
- $this->registry->getObject('db')->executeQuery( $sql );
- $slots = array();
- $slot_id = '';
- while( $data = $this->registry->getObject('db')->getRows() )
- {
- $slots[] = $data;
- $slot_id = $data['slot_id'];
- }
-
- $next_slot_id = $slot_id + 1;
- $cache = $this->registry->getObject('db')->cacheData( $slots );
- $this->registry->getObject('template')->getPage()->addTag( 'slots', array( 'DATA', $cache ) );
- $this->registry->getObject('template')->getPage()->addTag( 'next_slot_id', $next_slot_id );
-
- //workshops
- $workshops = array();
- $workshop_id = '';
- $sql = "SELECT ID as wid, slot_id, name FROM event_sessions_slots_workshops WHERE session_id = {$sid} ORDER BY ID ASC";
- $this->registry->getObject('db')->executeQuery( $sql );
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- if( in_array( $row['slot_id'], array_keys( $workshops ) ) )
- {
- $workshops[ $row['slot_id'] ][] = $row;
- }
- else
- {
- $workshops[ $row['slot_id'] ] = array();
- $workshops[ $row['slot_id'] ][] = $row;
- }
-
- $workshop_id = $row['wid'];
- }
-
- $next_workshop_id = $workshop_id + 1;
- $this->registry->getObject('template')->getPage()->addTag( 'next_workshop_id', $next_workshop_id );
-
- foreach( $workshops as $record => $details )
- {
- $cache = $this->registry->getObject('db')->cacheData( $details );
- $this->registry->getObject('template')->getPage()->addPPTag( 'workshops-' . $record, array( 'DATA', $cache ) );
- $this->registry->getObject('template')->addTemplateBit('nbd_workshop-' . $record, 'events/sessions/workshop.tpl.php' );
- }
-
- if( isset( $_POST['editsession'] ) )
- {
- $update = array();
- $update['venue_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['venue']);
-
- if( isset( $_POST['date'] ) && $_POST['date'] > 0 )
- {
- $date = explode( '/', $_POST['date']);
- $dt = $date[2] . '-' . $date[1] .'-'. $date[0];
- $update['date'] = $this->registry->getObject('db')->sanitizeData( $dt );
- }
-
- if( isset( $_POST['start_time'] ) && $_POST['start_time'] > 0 )
- {
-
- $time = explode( ':', $_POST['start_time'] );
- $t = $time[0].':'.$time[1];
- $update['start_time'] = $this->registry->getObject('db')->sanitizeData( $t );
-
- }
-
- if( isset( $_POST['end_time'] ) && $_POST['end_time'] > 0 )
- {
- $time = explode( ':', $_POST['end_time'] );
- $t = $time[0].':'.$time[1];
- $update['end_time'] = $this->registry->getObject('db')->sanitizeData( $t );
- }
-
- $update['places'] = $this->registry->getObject('db')->sanitizeData( $_POST['places']);
- $update['cost_structure'] = $this->registry->getObject('db')->sanitizeData( $_POST['cost_structure']);
- $update['discount'] = $this->registry->getObject('db')->sanitizeData( $_POST['discount']);
- $update['cost'] = $this->registry->getObject('db')->sanitizeData( $_POST['standard_cost']);
- $update['comment'] = $this->registry->getObject('db')->sanitizeData( $_POST['comment']);
- $this->registry->getObject('db')->updateRecords( 'event_sessions', $update, 'ID=' . $sid );
-
- //costs
- $sql = "DELETE FROM event_sessions_costs WHERE session_ID = {$sid}";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( isset( $_POST['cost'] ) && is_array( $_POST['cost'] ) && count( $_POST['cost'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_costs ( `session_ID`, `cost`, `type` ) VALUES ";
- foreach( $_POST['cost'] as $cost_type => $cost )
- {
- if( $cost == '' )
- {
- $cost = 0;
- }
- $cost = $this->registry->getObject('db')->sanitizeData( $cost );
- $cost_type = $this->registry->getObject('db')->sanitizeData( $cost_type );
- $sql .= " ( {$sid}, {$cost}, '{$cost_type}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- //time slots and workshops
- if( isset( $_POST['times'] ) && is_array( $_POST['times'] ) && count( $_POST['times'] ) > 0 )
- {
- //delete slots that have been removed
- foreach( $slots as $slot )
- {
- if( !in_array( $slot['slot_id'], array_keys( $_POST['times'] ) ) )
- {
- $sql = "DELETE FROM event_sessions_slots WHERE ID = " . $this->registry->getObject('db')->sanitizeData( $slot['slot_id'] );
- $this->registry->getObject('db')->executeQuery( $sql );
- $sql = "DELETE FROM event_sessions_slots_workshops WHERE slot_id = " . $this->registry->getObject('db')->sanitizeData( $slot['slot_id'] );
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
-
- //update or insert
- foreach( $_POST['times'] as $value )
- {
- if( isset( $slots ) && is_array($slots) && count( $slots ) > 0 )
- {
- $action = '';
- foreach( $slots as $slot )
- {
- if( $value['ID'] == $slot['slot_id'] )
- {
- $action = 'update';
- }
- }
-
- if( $action == 'update' )
- {
- $update = array();
- $update['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
- $update['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
- $update['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
- $this->registry->getObject('db')->updateRecords( 'event_sessions_slots', $update, 'ID=' . $this->registry->getObject('db')->sanitizeData( $value['ID'] ) );
-
- if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
- {
- if( isset( $workshops ) && is_array($workshops) && count( $workshops ) > 0 )
- {
- //delete workshops that have been removed
- foreach( $workshops as $workshop => $details )
- {
- foreach( $details as $record )
- {
- if( !in_array( $record['wid'], array_keys( $value['workshops'] ) ) )
- {
- if( $value['ID'] == $record['slot_id'] )
- {
- $sql = "DELETE FROM event_sessions_slots_workshops WHERE ID = " . $this->registry->getObject('db')->sanitizeData( $record['wid'] );
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
- }
- }
-
- //update or insert workshops
- foreach( $value['workshops'] as $workshop_values )
- {
- $workshop_action = '';
- foreach( $workshops as $workshop => $details )
- {
- foreach( $details as $record )
- {
- if( $record['wid'] == $workshop_values['wid'] )
- {
- $workshop_action = 'update';
- }
- }
- }
-
- if( $workshop_action == 'update' )
- {
- $update = array();
- $update['name'] = $this->registry->getObject('db')->sanitizeData( $workshop_values['name'] );
- $this->registry->getObject('db')->updateRecords( 'event_sessions_slots_workshops', $update, 'ID=' . $this->registry->getObject('db')->sanitizeData( $workshop_values['wid'] ) );
-
- }
- else
- {
- $insert = array();
- $insert['name'] = $this->registry->getObject('db')->sanitizeData( $workshop_values['name'] );
- $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
- $insert['slot_id'] = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $this->registry->getObject('db')->insertRecords( 'event_sessions_slots_workshops', $insert );
- }
- }
-
- }
- else
- {
- $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
- foreach( $value['workshops'] as $data )
- {
- $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
- $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
- else
- {
- $sql = "DELETE FROM event_sessions_slots_workshops WHERE slot_id = " . $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- }
- else
- {
- $insert = array();
- $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
- $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
- $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
- $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
- $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
- $slot_id = $this->registry->getObject('db')->lastInsertID();
-
- if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
- foreach( $value['workshops'] as $data )
- {
- $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
- $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
-
- }
- else
- {
- $insert = array();
- $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
- $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
- $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
- $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
- $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
- $slot_id = $this->registry->getObject('db')->lastInsertID();
-
- if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
- foreach( $value['workshops'] as $data )
- {
- $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
- $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
- }
- }
- else
- {
- $sql = "DELETE FROM event_sessions_slots WHERE session_id = {$sid}";
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- $this->registry->getObject('template')->getPage()->removeTag( 'venues' );
-
- $url = array( 'events', 'sessions', 'list', $eid );
- $this->registry->redirectUser( $url, 'Session updated', 'Taking you to the course sessions screen', true );
-
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addAdditionalParsingData( 'venues', 'ID', $data['venue_id'], 'opt', "selected='selected'" );
- $this->registry->getObject('template')->getPage()->addTag( 'sid', $sid );
- $this->registry->getObject('template')->getPage()->addTag( 'eid', $eid );
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/editsessionbyevent.tpl.php', 'footer.tpl.php');
- }
-
- }
-
- private function editSession( $sid, $type )
- {
- //session details
- $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 " .
- "FROM event_sessions s " .
- "WHERE s.ID={$sid} LIMIT 1";
- //print_r($sql);
- $this->registry->getObject('db')->executeQuery($sql);
- $data = $this->registry->getObject('db')->getRows();
- $this->registry->getObject('template')->dataToTags($data, 'session_');
- //print_r($data);
- if( $data['cost_structure'] == 'standard' )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'nbd_cost_structure_standard', 'checked="checked"' );
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag( 'nbd_cost_structure_type', 'checked="checked"' );
- }
-
- //venues
- $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";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'venues', array( 'SQL', $cache ) );
-
- //events
- $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";
- $cache = $this->registry->getObject('db')->cacheQuery( $sql );
- $this->registry->getObject('template')->getPage()->addTag( 'events', array( 'SQL', $cache ) );
-
- //costs
- $sql = "SELECT * FROM event_sessions_costs WHERE session_ID = {$sid}";
- $this->registry->getObject('db')->executeQuery($sql);
- $costs = array();
- while( $data = $this->registry->getObject('db')->getRows() )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'nbd_costs_' . $data['type'], $data['cost'] );
- }
-
- //time slots
- $sql = "SELECT ID as slot_id, time, heading, description FROM event_sessions_slots WHERE session_id = {$sid} ORDER BY ID ASC";
- $this->registry->getObject('db')->executeQuery( $sql );
- $slots = array();
- $slot_id = '';
- while( $data = $this->registry->getObject('db')->getRows() )
- {
- $slots[] = $data;
- $slot_id = $data['slot_id'];
- }
-
- $next_slot_id = $slot_id + 1;
- $cache = $this->registry->getObject('db')->cacheData( $slots );
- $this->registry->getObject('template')->getPage()->addTag( 'slots', array( 'DATA', $cache ) );
- $this->registry->getObject('template')->getPage()->addTag( 'next_slot_id', $next_slot_id );
-
- //workshops
- $workshops = array();
- $workshop_id = '';
- $sql = "SELECT ID as wid, slot_id, name FROM event_sessions_slots_workshops WHERE session_id = {$sid} ORDER BY ID ASC";
- $this->registry->getObject('db')->executeQuery( $sql );
- while( $row = $this->registry->getObject('db')->getRows() )
- {
- if( in_array( $row['slot_id'], array_keys( $workshops ) ) )
- {
- $workshops[ $row['slot_id'] ][] = $row;
- }
- else
- {
- $workshops[ $row['slot_id'] ] = array();
- $workshops[ $row['slot_id'] ][] = $row;
- }
-
- $workshop_id = $row['wid'];
- }
-
- $next_workshop_id = $workshop_id + 1;
- $this->registry->getObject('template')->getPage()->addTag( 'next_workshop_id', $next_workshop_id );
-
- foreach( $workshops as $record => $details )
- {
- $cache = $this->registry->getObject('db')->cacheData( $details );
- $this->registry->getObject('template')->getPage()->addPPTag( 'workshops-' . $record, array( 'DATA', $cache ) );
- $this->registry->getObject('template')->addTemplateBit('nbd_workshop-' . $record, 'events/sessions/workshop.tpl.php' );
- }
-
- if( isset( $_POST['editsession'] ) )
- {
- $update = array();
- $update['event_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['event']);
- $update['venue_id'] = $this->registry->getObject('db')->sanitizeData( $_POST['venue']);
-
- if( isset( $_POST['date'] ) && $_POST['date'] > 0 )
- {
- $date = explode( '/', $_POST['date']);
- $dt = $date[2] . '-' . $date[1] .'-'. $date[0];
- $update['date'] = $this->registry->getObject('db')->sanitizeData( $dt );
- }
-
- if( isset( $_POST['start_time'] ) && $_POST['start_time'] > 0 )
- {
-
- $time = explode( ':', $_POST['start_time'] );
- $t = $time[0].':'.$time[1];
- $update['start_time'] = $this->registry->getObject('db')->sanitizeData( $t );
-
- }
-
- if( isset( $_POST['end_time'] ) && $_POST['end_time'] > 0 )
- {
- $time = explode( ':', $_POST['end_time'] );
- $t = $time[0].':'.$time[1];
- $update['end_time'] = $this->registry->getObject('db')->sanitizeData( $t );
- }
-
- $update['places'] = $this->registry->getObject('db')->sanitizeData( $_POST['places']);
- $update['cost_structure'] = $this->registry->getObject('db')->sanitizeData( $_POST['cost_structure']);
- $update['discount'] = $this->registry->getObject('db')->sanitizeData( $_POST['discount']);
- $update['cost'] = $this->registry->getObject('db')->sanitizeData( $_POST['standard_cost']);
- $update['comment'] = $this->registry->getObject('db')->sanitizeData( $_POST['comment']);
- $this->registry->getObject('db')->updateRecords( 'event_sessions', $update, 'ID=' . $sid );
-
- //costs
- $sql = "DELETE FROM event_sessions_costs WHERE session_ID = {$sid}";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( isset( $_POST['cost'] ) && is_array( $_POST['cost'] ) && count( $_POST['cost'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_costs ( `session_ID`, `cost`, `type` ) VALUES ";
- foreach( $_POST['cost'] as $cost_type => $cost )
- {
- if( $cost == '' )
- {
- $cost = 0;
- }
- $cost = $this->registry->getObject('db')->sanitizeData( $cost );
- $cost_type = $this->registry->getObject('db')->sanitizeData( $cost_type );
- $sql .= " ( {$sid}, {$cost}, '{$cost_type}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- //time slots and workshops
- if( isset( $_POST['times'] ) && is_array( $_POST['times'] ) && count( $_POST['times'] ) > 0 )
- {
- //delete slots that have been removed
- foreach( $slots as $slot )
- {
- if( !in_array( $slot['slot_id'], array_keys( $_POST['times'] ) ) )
- {
- $sql = "DELETE FROM event_sessions_slots WHERE ID = " . $this->registry->getObject('db')->sanitizeData( $slot['slot_id'] );
- $this->registry->getObject('db')->executeQuery( $sql );
- $sql = "DELETE FROM event_sessions_slots_workshops WHERE slot_id = " . $this->registry->getObject('db')->sanitizeData( $slot['slot_id'] );
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
-
- //update or insert
- foreach( $_POST['times'] as $value )
- {
- if( isset( $slots ) && is_array($slots) && count( $slots ) > 0 )
- {
- $action = '';
- foreach( $slots as $slot )
- {
- if( $value['ID'] == $slot['slot_id'] )
- {
- $action = 'update';
- }
- }
-
- if( $action == 'update' )
- {
- $update = array();
- $update['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
- $update['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
- $update['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
- $this->registry->getObject('db')->updateRecords( 'event_sessions_slots', $update, 'ID=' . $this->registry->getObject('db')->sanitizeData( $value['ID'] ) );
-
- if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
- {
- if( isset( $workshops ) && is_array($workshops) && count( $workshops ) > 0 )
- {
- //delete workshops that have been removed
- foreach( $workshops as $workshop => $details )
- {
- foreach( $details as $record )
- {
- if( !in_array( $record['wid'], array_keys( $value['workshops'] ) ) )
- {
- if( $value['ID'] == $record['slot_id'] )
- {
- $sql = "DELETE FROM event_sessions_slots_workshops WHERE ID = " . $this->registry->getObject('db')->sanitizeData( $record['wid'] );
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
- }
- }
-
- //update or insert workshops
- foreach( $value['workshops'] as $workshop_values )
- {
- $workshop_action = '';
- foreach( $workshops as $workshop => $details )
- {
- foreach( $details as $record )
- {
- if( $record['wid'] == $workshop_values['wid'] )
- {
- $workshop_action = 'update';
- }
- }
- }
-
- if( $workshop_action == 'update' )
- {
- $update = array();
- $update['name'] = $this->registry->getObject('db')->sanitizeData( $workshop_values['name'] );
- $this->registry->getObject('db')->updateRecords( 'event_sessions_slots_workshops', $update, 'ID=' . $this->registry->getObject('db')->sanitizeData( $workshop_values['wid'] ) );
-
- }
- else
- {
- $insert = array();
- $insert['name'] = $this->registry->getObject('db')->sanitizeData( $workshop_values['name'] );
- $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
- $insert['slot_id'] = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $this->registry->getObject('db')->insertRecords( 'event_sessions_slots_workshops', $insert );
- }
- }
-
- }
- else
- {
- $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
- foreach( $value['workshops'] as $data )
- {
- $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
- $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
- else
- {
- $sql = "DELETE FROM event_sessions_slots_workshops WHERE slot_id = " . $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- }
- else
- {
- $insert = array();
- $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
- $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
- $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
- $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
- $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
- $slot_id = $this->registry->getObject('db')->lastInsertID();
-
- if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
- foreach( $value['workshops'] as $data )
- {
- $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
- $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
-
- }
- else
- {
- $insert = array();
- $insert['session_id'] = $this->registry->getObject('db')->sanitizeData( $sid );
- $insert['time'] = $this->registry->getObject('db')->sanitizeData( $value['time'] );
- $insert['heading'] = $this->registry->getObject('db')->sanitizeData( $value['heading'] );
- $insert['description'] = $this->registry->getObject('db')->sanitizeData( $value['description'] );
- $this->registry->getObject('db')->insertRecords( 'event_sessions_slots', $insert );
- $slot_id = $this->registry->getObject('db')->lastInsertID();
-
- if( isset( $value['workshops'] ) && is_array( $value['workshops'] ) && count( $value['workshops'] ) > 0 )
- {
- $sql = "INSERT INTO event_sessions_slots_workshops ( `session_id`, `slot_id`, `name` ) VALUES ";
- foreach( $value['workshops'] as $data )
- {
- $slot_id = $this->registry->getObject('db')->sanitizeData( $value['ID'] );
- $name = $this->registry->getObject('db')->sanitizeData( $data['name'] );
- $sql .= " ( {$sid}, {$slot_id}, '{$name}' ),";
- }
- $sql = substr_replace($sql ,"",-1);
- $this->registry->getObject('db')->executeQuery( $sql );
- }
- }
- }
- }
- else
- {
- $sql = "DELETE FROM event_sessions_slots WHERE session_id = {$sid}";
- $this->registry->getObject('db')->executeQuery( $sql );
- }
-
- $this->registry->getObject('template')->getPage()->removeTag( 'venues' );
- $this->registry->getObject('template')->getPage()->removeTag( 'events' );
-
- if( $type == 'current' )
- {
- $url = array( 'events', 'sessions', 'current' );
- }
- else
- {
- $url = array( 'events', 'sessions', 'previous' );
- }
- $this->registry->redirectUser( $url, 'Session updated', 'Taking you to the sessions screen', true );
-
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag( 'sid', $sid );
- $this->registry->getObject('template')->getPage()->addTag( 'type', 'edit-'.$type );
- $this->registry->getObject('template')->getPage()->addAdditionalParsingData( 'venues', 'ID', $data['venue_id'], 'opt', "selected='selected'" );
- $this->registry->getObject('template')->getPage()->addAdditionalParsingData( 'events', 'ID', $data['event_id'], 'opt', "selected='selected'" );
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/edit.tpl.php', 'footer.tpl.php');
- }
-
- }
-
- private function delete( $type, $sid, $eid )
- {
- $sql = "UPDATE event_sessions SET deleted=1 WHERE ID={$sid}";
- $this->registry->getObject('db')->executeQuery( $sql );
-
- $sql = "DELETE FROM event_teeing_off_times WHERE session_id = {$sid}";
- $this->registry->getObject('db')->executeQuery( $sql );
-
- if( $type == 0 )
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
- }
- elseif( $type == 1 )
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'previous'), '', true ) );
- }
- else
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
- }
- exit();
- }
-
- private function toggleActiveSession( $type, $id, $eid )
- {
- $sql = "UPDATE event_sessions SET active=1-active WHERE ID={$id}";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $type == 0 )
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
- }
- else
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
- }
- exit();
- }
-
- private function toggleBookable( $type, $id, $eid )
- {
- $sql = "UPDATE event_sessions SET bookable=1-bookable WHERE ID={$id}";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $type == 0 )
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
- }
- else
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
- }
- exit();
- }
-
- private function toggleNonMembers( $type, $id, $eid )
- {
- $sql = "UPDATE event_sessions SET non_members=1-non_members WHERE ID={$id}";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $type == 0 )
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
- }
- else
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
- }
- exit();
- }
-
- private function togglePayOnline( $type, $id, $eid )
- {
- $sql = "UPDATE event_sessions SET pay_online=1-pay_online WHERE ID={$id}";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $type == 0 )
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
- }
- else
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
- }
- exit();
- }
-
- private function toggleOpen( $type, $id, $eid )
- {
- $sql = "UPDATE event_sessions SET open=1-open WHERE ID={$id}";
- $this->registry->getObject('db')->executeQuery( $sql );
- if( $type == 0 )
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'list', $eid), '', true ) );
- }
- else
- {
- header('Location: ' . $this->registry->buildURL(array('events', 'sessions', 'current'), '', true ) );
- }
- exit();
- }
-
- private function toggleActiveSessionFixture( $id, $fid )
- {
- $sql = "UPDATE event_sessions SET active=1-active WHERE ID={$id}";
- $this->registry->getObject('db')->executeQuery( $sql );
- header('Location: ' . $this->registry->buildURL(array('events', 'fixtures', 'view', $fid), '', true ) );
- exit();
- }
-
- private function listAttendees( $id, $offset=0 )
- {
- $this->registry->getObject('template')->getPage()->addTag( 'session_ID', $id );
- $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";
-
- $pagination = $this->registry->pagination( $sql, 20, $offset, 'cache' );
- $this->registry->getObject('template')->getPage()->addTag('attendees', array( 'SQL', $pagination['cache'] ) );
- $this->registry->getObject('template')->getPage()->addTag('page_number', $pagination['cur_page'] );
- $this->registry->getObject('template')->getPage()->addTag('num_pages', $pagination['num_pages'] );
-
- // pagination links
- if( $pagination['is_first'] == true )
- {
- $this->registry->getObject('template')->getPage()->addTag('first', '');
- $this->registry->getObject('template')->getPage()->addTag('previous', '');
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('first', "<li><a href='events/sessions/attendees/$id/page/'>First Page</a></li>");
- $this->registry->getObject('template')->getPage()->addTag('previous', "<li><a href='events/sessions/attendees/$id/page/". ( $pagination['cur_page'] - 2 ) . "'>Previous Page</a></li>");
- }
- if( $pagination['is_last'] == true )
- {
- $this->registry->getObject('template')->getPage()->addTag('next', '');
- $this->registry->getObject('template')->getPage()->addTag('last', '');
- }
- else
- {
- $this->registry->getObject('template')->getPage()->addTag('last', "<li><a href='events/sessions/attendees/$id/page/". ( $pagination['num_pages'] - 1 ) ."'>Last Page</a></li>");
- $this->registry->getObject('template')->getPage()->addTag('next', "<li><a href='events/sessions/attendees/$id/page/". ( $pagination['cur_page'] ) . "'>Next Page</a></li>");
- }
-
- $this->registry->getObject('template')->buildFromTemplates( 'header.tpl.php', 'events/sessions/attendees.tpl.php', 'footer.tpl.php' );
- }
-
- private function cancelAttendee( $id, $sid )
- {
- $sql = "UPDATE event_session_attendees SET cancelled=1 WHERE ID={$id}";
- $this->registry->getObject('db')->executeQuery( $sql );
- $this->registry->redirectUser( array('events', 'sessions', 'attendees', $sid), 'Attendee cancelled', 'The attendee has been cancelled and the space released.', true );
- }
-
- }
-
- ?>