PageRenderTime 28ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/event-espresso.3.1.23.P/includes/process-registration/attendee_edit_record.php

https://bitbucket.org/anneivycat/ebcookhouse
PHP | 342 lines | 233 code | 44 blank | 65 comment | 61 complexity | 1dcebddffe5e4448f5bc6f5858b9d2f1 MD5 | raw file
  1. <?php
  2. if (!defined('EVENT_ESPRESSO_VERSION'))
  3. exit('No direct script access allowed');
  4. function attendee_edit_record() {
  5. global $wpdb, $org_options;
  6. do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
  7. $id = $_REQUEST['id'];
  8. $registration_id = $_REQUEST['registration_id'];
  9. if (isset($_REQUEST['r_id']))
  10. $registration_id = $_REQUEST['r_id'];
  11. if (!empty($_REQUEST['delete_attendee']) && $_REQUEST['delete_attendee'] == 'true') {
  12. $sql = " DELETE FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id ='$id'";
  13. $wpdb->query($sql);
  14. $wpdb->query("SELECT id from " . EVENTS_ATTENDEE_TABLE . " WHERE registration_id ='$registration_id' ");
  15. if ($wpdb->num_rows == 0) {
  16. $sql = " UPDATE " . EVENTS_ATTENDEE_TABLE . " SET quantity = IF(quantity IS NULL ,NULL,IF(quantity > 0,IF(quantity-1>0,quantity-1,1),0)) WHERE registration_id ='$registration_id'";
  17. $wpdb->query($sql);
  18. $sql = " UPDATE " . EVENTS_ATTENDEE_COST_TABLE . " SET quantity = IF(quantity IS NULL ,NULL,IF(quantity > 0,IF(quantity-1>0,quantity-1,1),0)) WHERE attendee_id ='$id'";
  19. $wpdb->query($sql);
  20. event_espresso_cleanup_multi_event_registration_id_group_data();
  21. event_espresso_cleanup_attendee_cost_data();
  22. }
  23. return events_payment_page($_REQUEST['primary'], $_REQUEST['p_id']);
  24. }
  25. $counter = 0;
  26. $additional_attendees = NULL;
  27. $sql = "SELECT t1.*, t2.event_name, t2.question_groups, t2.event_meta FROM " . EVENTS_ATTENDEE_TABLE . " t1
  28. JOIN " . EVENTS_DETAIL_TABLE . " t2
  29. ON t1.event_id = t2.id
  30. WHERE t1.id = '" . $id . "' AND t1.registration_id = '" . $registration_id . "'
  31. ORDER BY t1.id";
  32. //Debug
  33. //echo '<p>$sql- '.$sql.'</p>';
  34. $results = $wpdb->get_results($sql);
  35. foreach ($results as $result) {
  36. if ($counter == 0) {
  37. $id = $result->id;
  38. $registration_id = $result->registration_id;
  39. $lname = $result->lname;
  40. $fname = $result->fname;
  41. $address = $result->address;
  42. $city = $result->city;
  43. $state = $result->state;
  44. $zip = $result->zip;
  45. $email = $result->email;
  46. $payment = $result->payment;
  47. $phone = $result->phone;
  48. $date = $result->date;
  49. $payment_status = $result->payment_status;
  50. $txn_type = $result->txn_type;
  51. $txn_id = $result->txn_id;
  52. $amount_pd = $result->amount_pd;
  53. $quantity = $result->quantity;
  54. $payment_date = $result->payment_date;
  55. $event_id = $result->event_id;
  56. $event_name = stripslashes_deep($result->event_name);
  57. $question_groups = unserialize($result->question_groups);
  58. $event_meta = unserialize($result->event_meta);
  59. $counter = 1;
  60. } else {
  61. $additional_attendees[$result->id] = array('full_name' => $result->fname . ' ' . $result->lname, 'email' => $result->email, 'phone' => $result->phone);
  62. }
  63. }
  64. $response_source = $_POST;
  65. $questions = $wpdb->get_row("SELECT question_groups, event_meta FROM " . EVENTS_DETAIL_TABLE . " WHERE id = " . $event_id . " ");
  66. $question_groups = unserialize($questions->question_groups);
  67. //Debug
  68. //echo "<pre>".print_r($question_groups,true)."</pre>";
  69. $event_meta = unserialize($questions->event_meta);
  70. if (isset($event_meta['add_attendee_question_groups']) && $event_meta['add_attendee_question_groups'] != NULL) {
  71. $question_groups = $event_meta['add_attendee_question_groups'];
  72. }
  73. $questions_in = '';
  74. if ( !is_array($question_groups) && !empty($question_groups)) {
  75. $question_groups = unserialize($question_groups);
  76. }
  77. foreach ($question_groups as $g_id)
  78. $questions_in .= $g_id . ',';
  79. $questions_in = substr($questions_in, 0, -1);
  80. $group_name = '';
  81. $counter = 0;
  82. //pull the list of questions that are relevant to this event
  83. $q_sql_1 = "SELECT q.*, q.id q_id, qg.group_name FROM " . EVENTS_QUESTION_TABLE . " q
  84. JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id
  85. JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id
  86. WHERE qgr.group_id in (" . $questions_in . ")
  87. AND q.admin_only = 'N'
  88. ORDER BY qg.id, q.sequence ASC";
  89. $questions = $wpdb->get_results($q_sql_1);
  90. /* DEBUG */
  91. // echo "<pre>";
  92. // echo '<p>'.print_r($questions).'</p>';
  93. // echo '<p>'.$q_sql_1.'</p>';
  94. /* END DEBUG */
  95. $a_sql = "SELECT question_id, answer FROM " . EVENTS_ANSWER_TABLE . " ans WHERE ans.attendee_id = '" . $id . "' ";
  96. /* DEBUG */
  97. // echo '<p>'.$a_sql.'</p>';
  98. /* END DEBUG */
  99. $answers = $wpdb->get_results($a_sql);
  100. /* DEBUG */
  101. // echo "<pre>";
  102. // echo 'print_r($answers) = <br/>';
  103. // print_r($answers);
  104. /* END DEBUG */
  105. $answer_a = array();
  106. foreach ($answers as $answer) {
  107. /* DEBUG */
  108. //echo '<p>$answers[question_id] = '.$answer->question_id.'</p>';
  109. array_push($answer_a, $answer->question_id);
  110. }
  111. /*
  112. * Update the attendee information
  113. */
  114. if (!empty($_REQUEST['attendee_action']) && $_REQUEST['attendee_action'] == 'update_attendee') {
  115. if (!empty($_POST['fname']))
  116. $fname = $_POST['fname'];
  117. if (!empty($_POST['lname']))
  118. $lname = $_POST['lname'];
  119. if (!empty($_POST['address']))
  120. $address = $_POST['address'];
  121. if (!empty($_POST['city']))
  122. $city = $_POST['city'];
  123. if (!empty($_POST['state']))
  124. $state = $_POST['state'];
  125. if (!empty($_POST['zip']))
  126. $zip = $_POST['zip'];
  127. if (!empty($_POST['phone']))
  128. $phone = $_POST['phone'];
  129. if (!empty($_POST['email']))
  130. $email = $_POST['email'];
  131. $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET fname='$fname', lname='$lname', address='$address', city='$city', state='$state', zip='$zip', phone='$phone', email='$email' WHERE id ='$id'";
  132. $wpdb->query($sql);
  133. //echo $sql;
  134. /* DEBUG */
  135. // echo "<pre>";
  136. // echo 'print_r($answers) = <br />';
  137. // print_r($answers);
  138. // echo 'print_r($questions) = <br />';
  139. // print_r($questions);
  140. // echo 'print_r($answer_a) = <br/>';
  141. // print_r($answer_a);
  142. // exit();
  143. /* END DEBUG */
  144. if ($questions) {
  145. foreach ($questions as $question) {
  146. switch ($question->question_type) {
  147. case "TEXT" :
  148. case "TEXTAREA" :
  149. case "DROPDOWN" :
  150. //$post_val = $_POST [ $question->question_type . '_' . $question->question_id ];
  151. $post_val = ($question->system_name != '') ? $response_source[$question->system_name] : $response_source[$question->question_type . '_' . $question->q_id];
  152. if (in_array($question->q_id, $answer_a)) {
  153. $sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='$post_val' WHERE attendee_id = '$id' AND question_id ='$question->q_id'";
  154. } else {
  155. $sql = "INSERT INTO " . EVENTS_ANSWER_TABLE . " (registration_id, answer,attendee_id,question_id) VALUES ('$registration_id','$post_val', $id,$question->q_id)";
  156. }
  157. $wpdb->query($sql);
  158. break;
  159. case "SINGLE" :
  160. //$post_val = $_POST [ $question->question_type . '_' . $question->question_id ];
  161. $post_val = ($question->system_name != '') ? $response_source[$question->system_name] : $response_source[$question->question_type . '_' . $question->q_id];
  162. if (in_array($question->q_id, $answer_a)) {
  163. $sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='$post_val' WHERE attendee_id = '$id' AND question_id ='$question->q_id'";
  164. } else {
  165. $sql = "INSERT INTO " . EVENTS_ANSWER_TABLE . " (registration_id, answer,attendee_id,question_id) VALUES ('$registration_id','$post_val', $id,$question->q_id)";
  166. }
  167. $wpdb->query($sql);
  168. break;
  169. case "MULTIPLE" :
  170. $value_string = '';
  171. for ($i = 0; $i < count($response_source[$question->question_type . '_' . $question->id]); $i++) {
  172. $value_string .= trim($response_source[$question->question_type . '_' . $question->id][$i]) . ",";
  173. }
  174. if (in_array($question->q_id, $answer_a)) {
  175. $sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='$value_string' WHERE attendee_id = '$id' AND question_id ='$question->q_id'";
  176. } else {
  177. $sql = "INSERT INTO " . EVENTS_ANSWER_TABLE . " (registration_id, answer,attendee_id,question_id) VALUES ('$registration_id','$value_string', $id, $question->q_id)";
  178. }
  179. $wpdb->query($sql);
  180. /* DEBUG */
  181. //echo '<p>'.$sql.'</p>';
  182. //$sql = "UPDATE " . EVENTS_ANSWER_TABLE . " SET answer='$value_string' WHERE attendee_id = '$id' AND question_id ='$question->question_id'";
  183. //echo '<p>$question->q_id = '.$question->q_id.'</p>';
  184. /* echo '<p> in_array($question->q_id, $answers) = ';
  185. echo in_array($question->q_id, $answers) ? 'true':'false';
  186. echo '</p>'; */
  187. //echo '<p>'.print_r($answers).'</p>';
  188. //echo '<p>$answers[question_id]'.$answers['question_id'].'</p>';
  189. //print_r($answer_a);
  190. //print_r($answers);
  191. /* if (!array_key_exists($question->id , $answers)) {
  192. echo 'test = '.$question->id.'<br />';
  193. } */
  194. /* END DEBUG */
  195. break;
  196. }
  197. }
  198. }
  199. //If this is not an attendee returing to edit thier details, then we need to return to the payment page
  200. if (!isset($_REQUEST['single']))
  201. return events_payment_page($_REQUEST['primary'], $_REQUEST['p_id']);
  202. }
  203. ?>
  204. <div id="event_espresso_registration_form" class="event-display-boxes">
  205. <div class="event_espresso_form_wrapper event-data-display">
  206. <h3 class="section-heading"><?php
  207. if ($_REQUEST['registration_id'] = 'true') {
  208. echo __('Edit Your', 'event_espresso') . ' ';
  209. }_e('Registration', 'event_espresso');
  210. ?></h3>
  211. <p><strong><?php _e('Event:', 'event_espresso'); ?> <?php echo $event_name; ?></strong></p>
  212. <form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>" class="espresso_form" id="registration_form">
  213. <?php
  214. if (count($question_groups) > 0) {
  215. $questions_in = '';
  216. foreach ($question_groups as $g_id)
  217. $questions_in .= $g_id . ',';
  218. $questions_in = substr($questions_in, 0, -1);
  219. $group_name = '';
  220. $counter = 0;
  221. $FILTER = '';
  222. if (isset($event_meta['additional_attendee_reg_info']) && $event_meta['additional_attendee_reg_info'] == '2' && isset($_REQUEST['attendee_num']) && $_REQUEST['attendee_num'] > 1) {
  223. $FILTER .= " AND qg.system_group = 1 ";
  224. }
  225. //pull the list of questions that are relevant to this event
  226. $q_sql_2 = "SELECT q.*, q.id q_id, at.*, qg.group_name, qg.show_group_description, qg.show_group_name FROM " . EVENTS_QUESTION_TABLE . " q
  227. LEFT JOIN " . EVENTS_ANSWER_TABLE . " at on q.id = at.question_id
  228. JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr on q.id = qgr.question_id
  229. JOIN " . EVENTS_QST_GROUP_TABLE . " qg on qg.id = qgr.group_id
  230. WHERE qgr.group_id in (" . $questions_in . ")
  231. AND (at.attendee_id IS NULL OR at.attendee_id = '" . $id . "')
  232. AND q.admin_only != 'Y'
  233. " . $FILTER . "
  234. ORDER BY qg.id, q.id ASC";
  235. /* DEBUG */
  236. //echo '<p>$q_sql_2 - '.$q_sql_2.'</p>';
  237. $questions = '';
  238. $questions = $wpdb->get_results($q_sql_2);
  239. $num_rows = $wpdb->num_rows;
  240. if ($num_rows > 0) {
  241. $q_ids = '';
  242. foreach ($questions as $question_ids) {
  243. $q_ids .= $question_ids->question_id . ',';
  244. }
  245. // DEBUG
  246. //echo '<p>$q_ids - '. rtrim($q_ids, ",").'</p>';
  247. $existing_questions = rtrim($q_ids, ",");
  248. $q_sql_3 = "SELECT q.* FROM " . EVENTS_QUESTION_TABLE . " q JOIN " . EVENTS_QST_GROUP_REL_TABLE . " qgr ON q.id = qgr.question_id JOIN " . EVENTS_QST_GROUP_TABLE . " qg ON qg.id = qgr.group_id WHERE qgr.group_id IN (" . $questions_in . ") AND q.id NOT IN (" . $existing_questions . ") GROUP BY q.question ORDER BY qg.id, q.id ASC";
  249. //DEBUG
  250. //echo '$q_sql_3 - <p>'.$q_sql_3.'</p>';
  251. $questions_2 = $wpdb->get_results($q_sql_3);
  252. $num_rows_2 = $wpdb->num_rows;
  253. //Merge the existing questions with any missing questions
  254. if ($num_rows_2 > 0) {
  255. $questions = array_merge($questions, $questions_2);
  256. }
  257. //Output the questions
  258. $question_displayed = array();
  259. foreach ($questions as $question) {
  260. if (!in_array($question->id, $question_displayed)) {
  261. $question_displayed[] = $question->id;
  262. //if new group, close fieldset
  263. echo ($group_name != '' && $group_name != $question->group_name) ? '</fieldset>' : '';
  264. // DEBUG
  265. //echo '<p>'.print_r($question).'</p>';
  266. //END DEBUG
  267. echo ($group_name != '' && $group_name != $question->group_name) ? '</div>' : '';
  268. if ($group_name != $question->group_name) {
  269. $group_id = (!empty($question->group_identifier)) ? 'id="' . $question->group_identifier . '"' : '';
  270. if (empty($question->group_description))
  271. $question->group_description = '';
  272. echo '<div class="event_questions" ' . $group_id . '>';
  273. echo $question->show_group_name != 0 ? '<h4 class="section-title">' . $question->group_name . '</h4>' : '';
  274. echo $question->show_group_description != 0 ? '<p>' . $question->group_description . '</p>' : '';
  275. $group_name = $question->group_name;
  276. }
  277. echo '<p>';
  278. echo event_form_build_edit($question, $question->answer, $show_admin_only = false);
  279. echo "</p>";
  280. $counter++;
  281. echo $counter == $num_rows ? '</div>' : '';
  282. }
  283. }
  284. }//end questions display
  285. }
  286. ?>
  287. <input type="hidden" name="id" value="<?php echo $id ?>" />
  288. <input type="hidden" name="event_id" value="<?php echo $event_id ?>" />
  289. <input type="hidden" name="form_action" value="edit_attendee" />
  290. <input type="hidden" name="attendee_action" value="update_attendee" />
  291. <input type="hidden" name="regevent_action" value="register" />
  292. <input type="hidden" name="primary" value="<?php echo $_REQUEST['primary'] ?>" />
  293. <p class="espresso_confirm_registration"><input class="btn_event_form_submit" type="submit" name="submit" value="<?php _e('Update Record', 'event_espresso'); ?>" /></p>
  294. </form>
  295. </div><!-- / .event-display-boxes -->
  296. </div><!-- / .event_espresso_form_wrapper .event-data-display -->
  297. <?php
  298. }