Guest User

Untitled

a guest
Apr 19th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. <?php if($this->session->userdata('user_id')): ?>
  2. <hr>
  3. <?php echo form_open('/attendees/add/'.$event['id']); ?>
  4. <input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id']; ?>">
  5. <input type="submit" value="I'm in!" class="btn btn-success">
  6. </form>
  7. <?php endif; ?>
  8.  
  9. <?php
  10. class Attendees extends CI_Controller {
  11. public function add($event_id) {
  12. // Check login
  13. if(!$this->session->userdata('logged_in')){
  14. redirect('users/login');
  15. }
  16. $this->form_validation->set_rules('user_id', 'required|callback_check_userid_eventid');
  17. if($this->form_validation->run() === FALSE){
  18. $this->session->set_flashdata('attendee_not_added', 'You are already on the list.');
  19. redirect('home');
  20. } else {
  21. $this->attendee_model->add_attendee($event_id);
  22. // Set message
  23. $this->session->set_flashdata('attendee_added', 'You have been added to this event.');
  24. redirect('events');
  25. }
  26. }
  27. }
  28.  
  29. <?php
  30. class Attendee_model extends CI_Model {
  31. public function __contruct() {
  32.  
  33. }
  34.  
  35. public function get_attendees($id = FALSE){
  36. if($id === FALSE) {
  37. $query = $this->db->get('attendees');
  38. return $query->result_array();
  39. }
  40. $this->db->select('attendees.id, attendees.team, attendees.is_goalie, event.id, user.first_name, user.last_name');
  41. $this->db->from('attendees');
  42. $this->db->join('event', 'attendees.event_id = event.id', 'inner');
  43. $this->db->join('user', 'attendees.user_id = user.id', 'inner');
  44. $this->db->where('event.id', $id);
  45. $query = $this->db->get();
  46. return $query->row_array();
  47. }
  48.  
  49. public function add_attendee($event_id){
  50. $data = array(
  51. 'event_id' => $event_id,
  52. 'user_id' => $this->session->userdata('user_id')
  53. );
  54. return $this->db->insert('attendees', $data);
  55. }
  56.  
  57. // Check attendee exists in event
  58. public function check_userid_eventid($event_id, $user_id){
  59. $query = $this->db->get_where('attendees', array('user_id' => $user_id, 'event_id' => $event_id));
  60. if(empty($query->row_array())){
  61. return true;
  62. } else {
  63. return false;
  64. }
  65. }
  66. }
Add Comment
Please, Sign In to add comment