public function validate() { $return = true; if ($this->user_id == "") { $this->errors[] = "You must enter a user ID"; $return = false; } if ($this->survey_id == "") { $this->errors[] = "You must enter a survey ID"; $return = false; } $user_id = mysql_real_escape_string($this->user_id); $survey_id = mysql_real_escape_string($this->survey_id); $and_not_self = ""; if ($this->id) { $id = mysql_real_escape_string($this->id); $and_not_self = " AND `id` != '{$id}'"; } $result = mysql_query("SELECT `id` FROM `survey_responses` WHERE `user_id` = '{$user_id}' AND `survey_id` = '{$survey_id}'{$and_not_self} AND `deleted` = false"); if (mysql_num_rows($result) > 0) { $this->errors[] = "This user has already responded to this survey."; $return = false; } if (!$this->survey) { if ($this->survey_id) { $this->survey = Survey::find_by_id($this->survey_id); } } if (!$this->survey) { $this->errors[] = "You must enter a survey ID"; $return = false; } else { if ($this->survey->event_id) { // Survey user must have been to the event $event_id = mysql_real_escape_string($this->survey->event_id); $result = EventSignup::find("events.id = '{$event_id}' AND users.id = '{$user_id}' AND event_signups.paid"); if (!$result) { $this->errors[] = "You must have attended {$event->name} to complete this survey"; $return = false; } } } if (count($this->errors) > 0) { $return = false; } return $return; }
public function move($permalink = null) { $event = self::load_event($permalink); $event_id = mysql_real_escape_string($event->id); $signup_id = mysql_real_escape_string($_GET['seat']); $signup = EventSignup::find("event_signups.event_id = '{$event_id}' AND event_tickets.participant = true AND event_signups.paid = true AND event_signups.id = '{$signup_id}'"); if (!$signup) { Error404(); } if (isset($_GET['destination'])) { $anchor = ''; if ($_GET['destination'] == "unseat") { $signup->event_seat_id = null; if ($signup->save()) { Site::Flash("notice", "{$signup->user->nickname} has been unseated"); } else { Site::Flash("error", "Unable to unseat {$signup->user->nickname}"); } } else { $destination = self::load_seat($_GET['destination'], $event); if ($destination) { $anchor = "#{$destination->seating_plan->permalink}-"; if ($destination->event_signup->id) { $destination->event_signup->event_seat_id = null; $destination->event_signup->save(); } $signup->event_seat_id = $destination->id; if ($signup->save()) { //Email::send_event_checkin($signup); Site::Flash("notice", "{$signup->user->nickname} has been moved to {$destination->label}"); } else { Site::Flash("error", "Unable to move {$signup->user->nickname}"); } } } Redirect("admin/events/{$event->permalink}/seating{$anchor}"); } $this->assign("event", $event); $this->assign("signup", $signup); $this->title = "{$event->name} Seating"; $this->render("event_seat/move.tpl"); }
public function signup($nickname = null) { $user = $this->load_user($nickname); $signup = new EventSignup(); if ($this->post) { $event_id = mysql_real_escape_string($_POST['event']); $event = Event::find_by_id($event_id); if (!$event) { Error404(); } $signup->event_id = $event->id; $signup->user_id = $user->id; if (!isset($_POST['stage'])) { $signup->paid = $this->PostData('paid'); $signup->lift_required = $this->PostData('lift_required'); $signup->voucher = $this->PostData('voucher'); $signup->voucher_code = $this->PostData('voucher_code'); $ticket_id = mysql_real_escape_string($this->PostData('ticket')); $ticket = EventTicket::find("event_tickets.event_id = '{$event_id}' AND event_tickets.id = '{$ticket_id}'"); if ($ticket) { $signup->event_ticket_id = $ticket->id; } if ($signup->save()) { Site::Flash('notice', "{$user->nickname} has been signed up to {$event->name}"); Redirect("admin/signups/{$signup->id}"); } } } $tickets = array(); foreach ($event->tickets() as $ticket) { $tickets[$ticket->id] = $ticket->name; } $this->assign("signup", $signup); $this->assign("user", $user); $this->assign("event", $event); $this->assign("tickets", $tickets); $this->title = "Event Signup"; $this->render("user/signup.tpl"); }
public function edit() { $event = self::load_event(); if ($event->enddate <= time()) { Site::Flash("error", "It is not possible to change your seat"); Redirect("{$event->permalink}/seating"); } $seat = self::load_seat($event); if ($seat->event_signup->id) { Site::Flash("error", "The seat has already been chosen"); Redirect("{$seat->event->permalink}/seating/{$seat->seating_plan->permalink}"); } // Fetch signups $event_id = mysql_real_escape_string($event->id); $user_id = mysql_real_escape_string(Site::CurrentUser()->id); $signups = EventSignup::find_all("event_signups.event_id = '{$event_id}' AND (event_signups.user_id = '{$user_id}' OR event_signups.manager_id = '{$user_id}') AND event_signups.paid = true AND event_tickets.participant = true"); $total = count($signups); if ($total == 0) { Site::Flash("error", "You need to be a paid participant to choose your seat"); Redirect("{$seat->event->permalink}/seating/{$seat->seating_plan->permalink}"); } $eligible = array(); foreach ($signups as $signup) { if ($signup->event_seat_id && $event->lock_seating) { // A seat is assigned, and seating is locked - No continue; } if (!$signup->event_ticket->seating_group_id && !$seat->seating_group_id && !$seat->disabled) { // Seat is not disabled, there's no group on the ticket or the seat, so we're good $eligible[$signup->id] = $signup; continue; } if ($signup->event_ticket->seating_group_id && $seat->seating_group_id && $signup->event_ticket->seating_group_id == $seat->seating_group_id) { // Seat has a group, and it's the same as the ticket, this is good $eligible[$signup->id] = $signup; } } if (count($eligible) == 0) { if (count($signups) == 0) { Site::Flash("error", "You need to be a paid participant to choose your seat"); } else { Site::Flash('error', 'You have no bookings that can choose this seat'); } Redirect("{$seat->event->permalink}/seating/{$seat->seating_plan->permalink}"); } if (count($eligible) == 1) { $signup = current($eligible); $signup->event_seat_id = $seat->id; if ($signup->save()) { Site::Flash("notice", "You have chosen seat {$seat->label}"); //Email::send_event_checkin($signup); } else { Site::Flash('error', 'Unable to choose seat, please try again'); } Redirect("{$seat->event->permalink}/seating/{$seat->seating_plan->permalink}"); } // We have more than one eligible booking, we need the user to select which one if ($this->post) { $id = $this->postData('signup'); if (!$this->csrf) { Site::InstantFlash('error', 'Invalid form submission'); } elseif (!$id || !array_key_exists($id, $eligible)) { Site::InstantFlash('error', 'Please select a valid event booking'); } else { $eligible[$id]->event_seat_id = $seat->id; if ($eligible[$id]->save()) { Site::Flash('notice', "You have chosen seat {$seat->label}"); //Email::send_event_checkin($signup); Redirect("{$seat->event->permalink}/seating/{$seat->seating_plan->permalink}"); } else { Site::InstantFlash('error', 'Unable to choose seat, please try again'); } } } $this->assign("event", $event); $this->assign("seat", $seat); $this->assign("signups", $eligible); $this->title = "{$event->name} :: Seating Plan"; $this->render("event_seat/edit.tpl"); }
<?php require "init.php"; $script = Script::find_by_code("unpaid_emails"); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Forums\r\n\r\n"; $offset = 31; $lower = strtotime("-{$offset} days midnight"); $offset--; $upper = strtotime("-{$offset} days midnight"); $signups = EventSignup::find_all("\n\t\tevent_signups.paid = false\n\t\tAND event_signups.voucher = false\n\t\tAND event_signups.created_at BETWEEN FROM_UNIXTIME({$lower}) AND FROM_UNIXTIME({$upper})\n\t\tAND events.startdate > NOW()\n\t\tAND users.allow_emails = true\n\t\tAND users.suspended = false\n\t\tAND users.activated = true\n\t"); $users = array(); foreach ($signups as $signup) { if (!in_array($signup->user->id, $users)) { if ($signup->event_ticket->participant && $signup->event->count_participants("paid") < $signup->event->capacity) { $users[] = $signup->user->id; $script->addlog("Reminder sent to {$signup->user->email} ({$signup->user->nickname}) for [{$signup->id}]"); echo "Sending reminder to {$signup->user->email} ({$signup->user->nickname}) for signup {$signup->id}\n"; Email::send_signup_reminder($signup); } } } $script = Script::find_by_code("unpaid_emails"); $output = ob_get_contents(); $script->finish($output);
protected static function get_fields() { return implode(', ', array(self::select_fields(), Event::select_fields(), EventSignup::select_fields(), SeatingPlan::select_fields(), User::select_fields(), SeatingGroup::select_fields())); }
protected static function get_fields() { return self::select_fields() . ", " . EventSignup::select_fields() . ", " . Service::select_fields() . ", " . User::select_fields(); }
public function show($permalink = null, $id = null) { $event = self::load_event(); $ticket = self::load_ticket($event); $sort = ""; if (isset($_GET['sort'])) { $sort = $_GET['sort']; } if ($sort == "nickname") { $order = "users.nickname ASC"; } elseif ($sort == "date") { $order = "event_signups.created_at DESC"; } elseif ($sort == "id") { $order = "event_signups.id ASC"; } else { $order = "event_signups.paid DESC, users.nickname ASC"; } $page = 1; if (isset($_GET['page'])) { $page = $_GET['page']; } $id = mysql_real_escape_string($ticket->id); $signups = EventSignup::paginate("event_signups.event_ticket_id = '{$id}'", $order, $page, 20); $this->assign("event", $event); $this->assign("ticket", $ticket); $this->assign("signups", $signups); $this->assign("sort", $sort); $this->title = "View Ticket"; $this->render("event_ticket/show.tpl"); }
protected static function load_signup($id = null) { if (!$id) { $id = $_GET['signup_id']; } $id = mysql_real_escape_string($id); $signup = EventSignup::find_by_id($id); if ($signup and $signup->user_id == Site::CurrentUser()->id) { return $signup; } else { Error404(); } }
<?php require "init.php"; $script = Script::find_by_code('loyalty_attendance'); $script->start(); ob_start(); $time = date("H:i:s"); echo "[{$time}] Attendance Loyalty Points\r\n\r\n"; $page = EventSignup::paginate("event_signups.paid = 1 AND event_signups.processed = 0 AND events.startdate <= NOW()", "event_signups.created_at ASC", 1, 50); $count = count($page->collection); echo " Processing {$count} / {$page->total} signups\r\n"; foreach ($page->collection as $obj) { mysql_query('BEGIN'); $loyalty = true; if ($obj->event_ticket->points_value > 0 && !$obj->event_ticket->staff) { $loyalty = $obj->user->award_loyalty($obj->event_ticket->points_value, "Attendance: {$obj->event->shortname} {$obj->event_ticket->name}"); $script->addlog("Awarded {$obj->event_ticket->points_value}pts to [{$obj->user}] {$obj->user->nickname} for [{$obj->event_ticket}] {$obj->event->shortname} {$obj->event_ticket->name}"); } $obj->processed = true; $ua = $obj->save(); if ($loyalty && $ua) { mysql_query('COMMIT'); } else { echo "Error processing [{$obj}]\r\n"; print_r($obj); mysql_query('ROLLBACK'); $script->addlog("Error processing [{$obj}]", 'Critical'); } } $script = Script::find_by_code('loyalty_attendance'); $output = ob_get_clean();
public function signups($reload = false) { if ($reload or !$this->signups_cache) { $id = mysql_real_escape_string($this->id); $this->signups_cache = EventSignup::find_all("event_signups.event_id = '{$id}'"); } return $this->signups_cache; }
protected static function load_signup($signup_id = null) { if (!$signup_id) { $signup_id = $_GET['signup_id']; } $signup_id = mysql_real_escape_string($signup_id); $signup = EventSignup::find_by_id($signup_id); if ($signup) { return $signup; } else { Error404(); } }
if (count($achievements) == 0) { $achievement = new UserAchievement(); $achievement->user_id = $user->id; $achievement->achievement_id = 79; $achievement->category_id = 14; $achievement->save(); echo "-> Awarding"; } else { echo " -> Already awarded"; } echo "\r\n<br />"; } } */ $user = User::find_by_id(4791); $event = Event::find_by_id(33); $ticket = EventTicket::find_by_id(179); for ($i = 0; $i < 40; $i++) { $event_signup = new EventSignup(); $event_signup->event_id = $event->id; $event_signup->user_id = $user->id; $event_signup->event_ticket_id = $ticket->id; $event_signup->event_ticket = $ticket; if ($i != 0) { $event_signup->voucher = true; $event_signup->voucher_code = md5(time() . $event->id . mt_rand(0, 99999999999)); $event_signup->manager_id = $user->id; } $event_signup->paid = true; $event_signup->save(); }
protected static function load_signup($id = null) { if (!$id) { $id = $_GET['id']; } $id = mysql_real_escape_string($id); $signup = EventSignup::find("event_signups.id = '{$id}'"); if ($signup) { return $signup; } else { Error404(); } }
public function get_signups($reload = false) { if (!$this->signup_cache or $reload) { $this->signup_cache = array(); foreach ($this->items() as $item) { if (is_a($item->object, "EventSignup")) { $this->signup_cache[$item->object_id] = EventSignup::find_by_id($item->object_id); break; } } } return $this->signup_cache; }
protected static function get_fields() { return implode(', ', array(self::select_fields(), DiscountCode::select_fields(), Cart::select_fields(), CartItem::select_fields(), EventSignup::select_fields(), EventService::select_fields(), User::select_fields())); }
public function limitForUser($user, $reload = false) { if ($this->limit == -1) { return -1; } // Count the number of signups this user has $user_id = mysql_real_escape_string($user->id); $ticket_id = mysql_real_escape_string($this->id); $signups = EventSignup::count("users.id = '{$user_id}' AND event_tickets.id = '{$ticket_id}'"); $remaining = $this->limit - $signups; if ($remaining < 0) { $remaining = 0; } return $remaining; }
protected static function get_fields() { return implode(', ', array(self::select_fields(), User::select_fields(), User::select_fields('referer'), EventSignup::select_fields(), EventTicket::select_fields(), Event::select_fields())); }
public function __get($name) { switch ($name) { case 'requiresContactData': if (!$this->id) { $this->requiresContactData = false; return false; } $id = mysql_real_escape_string($this->id); $count = EventSignup::find("users.id = '{$id}'"); $this->requiresContactData = false; if ($count) { $this->requiresContactData = true; } return $this->requiresContactData; break; case 'hasContactData': $fields = array('address1', 'towncity', 'county', 'postcode', 'phone'); $this->hasContactData = true; foreach ($fields as $field) { if (!$this->{$field}) { $this->hasContactData = false; break; } } return $this->hasContactData; case 'forumPmLink': global $config; return $config['forums']['url'] . 'index.php?app=core&module=epic§ion=profile&feature=pm&id=' . $this->id; case 'forumProfileLink': global $config; return $config['forums']['url'] . 'index.php?app=core&module=epic§ion=profile&feature=profile&id=' . $this->id; case 'steam_id': // Calculate traditional Steam ID if (!$this->steamid64bit) { return ''; } $offset = bcsub($this->steamid64bit, '76561197960265728'); $id = bcdiv($offset, '2'); $idParts = explode('.', $id); $id = array_shift($idParts); if (bcmod($offset, '2')) { $steamid = 'STEAM_0:1:' . $id; } else { $steamid = "STEAM_0:0:" . $id; } return $steamid; default: return $this->{$name}; } }
public function show($permalink = null) { if (isset($_GET['permalink'])) { $permalink = $_GET['permalink']; } $survey = Survey::find_by_permalink($permalink); if (!$survey or !$survey->active && Site::CurrentUser()->isAdmin() == 0) { Error404(); } if ($survey->event->id) { $event_id = mysql_real_escape_string($survey->event_id); $user_id = mysql_real_escape_string(Site::CurrentUser()->id); $result = EventSignup::find("events.id = '{$event_id}' AND users.id = '{$user_id}' AND event_signups.paid"); if (!$result) { Site::Flash("error", "You must have attended {$survey->event->name} to take this survey"); RedirectBack(); } } $user_id = mysql_real_escape_string(Site::CurrentUser()->id); $survey_id = mysql_real_escape_string($survey->id); $response = SurveyResponse::find("surveys.id = '{$survey_id}' AND users.id = '{$user_id}'"); if ($response) { Site::Flash("error", "You have already completed this survey"); Redirect("surveys"); } $response = new SurveyResponse(); $response->survey = $survey; $response->survey_id = $survey->id; $response->user = Site::CurrentUser(); $response->user_id = Site::CurrentUser()->id; $answers = array(); $choices = array(); $valid = true; $errors = array(); if ($this->post) { foreach ($survey->questions() as $question) { $answer = new SurveyAnswer(); $answer->survey_question_id = $question->id; if (in_array($question->type, array("sqtTextbox", "sqtTextArea"))) { // Free-text input if (isset($_POST['question'][$question->id])) { $answer->value = $_POST['question'][$question->id]; } elseif (!$question->required) { continue; } } else { if (isset($_POST['question'][$question->id])) { $chosen = array(); if ($question->type == "sqtCheckbox") { // Checkboxes $chosen = $_POST['question'][$question->id]; } else { // Radio/Select $chosen = array($_POST['question'][$question->id]); } foreach ($chosen as $id) { $option = SurveyQuestionOption::find_by_id($id); if (!$option or $option->question->id != $question->id) { if (!$question->required) { continue; } $valid = false; $answer->add_error("Answer for question {$question->position} is invalid"); $errors[] = $question->id; break; } $choice = new SurveyAnswerChoice(); $choice->survey_question_option_id = $option->id; $choices[$question->id][$option->id] = $choice; } } elseif ($question->required) { $valid = false; $answer->add_error("You must enter an answer for question {$question->position}"); $errors[] = $question->id; } else { continue; } } $result = $answer->validate(); if (!$result) { $valid = false; } $answers[$question->id] = $answer; } if ($valid) { // This is valid, let's save everything! if ($response->save()) { foreach ($answers as $answer) { $answer->survey_response_id = $response->id; $answer->save(); $answers[$answer->survey_question_id] = $answer; } foreach ($choices as $question_id => $answer_choices) { foreach ($answer_choices as $choice) { $choice->survey_answer_id = $answers[$question_id]->id; $choice->save(); } } $account = TwitterAccount::find_by_code('site'); if ($account) { $message = "{$response->user->nickname} has completed the {$survey->name} Survey"; $account->add_tweet($message); } Redirect("surveys/{$survey->permalink}/complete"); } $valid = false; } } $this->assign("answers", $answers); $this->assign("choices", $choices); $this->assign("valid", $valid); $this->assign("survey", $survey); $this->assign("response", $response); $this->assign("errors", $errors); $this->title = $survey->name; $this->render("survey/show.tpl"); }