Advertisement
Guest User

Event Espresso Code

a guest
Mar 17th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.72 KB | None | 0 0
  1. <?php
  2.  
  3. //Added by Imon
  4. if (isset($_SESSION['espresso_session']['id'])) {
  5. unset($_SESSION['espresso_session']['id']);
  6. }
  7.  
  8. define('FPDF_FONTPATH', EVENT_ESPRESSO_PLUGINFULLPATH . 'class/fpdf/font/');
  9. require_once EVENT_ESPRESSO_PLUGINFULLPATH . 'class/fpdf/fpdf.php';
  10.  
  11. require_once(dirname(__FILE__) . '/function.pdf.php'); //Added by Imon
  12.  
  13. global $espresso_premium;
  14. if ($espresso_premium != true)
  15. return;
  16. global $wpdb, $org_options;
  17.  
  18. $invoice_payment_settings = get_option('event_espresso_invoice_payment_settings');
  19.  
  20. //Added by Imon
  21. $multi_reg = false;
  22. $registration_id = espresso_return_reg_id();
  23. $admin = isset($_REQUEST['admin']) ? $_REQUEST['admin'] : false;
  24. $registration_ids = array();
  25. $c_sql = "select * from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where registration_id = '$registration_id' ";
  26. //echo $c_sql;
  27. $check = $wpdb->get_row($c_sql);
  28. if ($check !== NULL) {
  29. $registration_id = $check->primary_registration_id;
  30. $registration_ids = $wpdb->get_results("select registration_id from " . EVENTS_MULTI_EVENT_REGISTRATION_ID_GROUP_TABLE . " where primary_registration_id = '$registration_id' ", ARRAY_A);
  31. $multi_reg = true;
  32. } else {
  33. $registration_ids[] = array("registration_id" => $registration_id);
  34. }
  35. $attendees = $wpdb->get_results("SELECT a.*, e.event_name FROM " . EVENTS_ATTENDEE_TABLE . " a JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id=a.event_id WHERE a.registration_id ='" . $registration_id . "' order by a.id LIMIT 0,1 ");
  36.  
  37. foreach ($attendees as $attendee) {
  38. $attendee_id = $attendee->id;
  39. $attendee_last = html_entity_decode(stripslashes($attendee->lname), ENT_QUOTES, "UTF-8");
  40. $attendee_first = html_entity_decode(stripslashes($attendee->fname), ENT_QUOTES, "UTF-8");
  41. $attendee_address = html_entity_decode(stripslashes($attendee->address), ENT_QUOTES, "UTF-8");
  42. $attendee_address .= isset($attendee->address2) ? "\n" . html_entity_decode(stripslashes($attendee->address2), ENT_QUOTES, "UTF-8") : '';
  43. $attendee_city = html_entity_decode(stripslashes($attendee->city), ENT_QUOTES, "UTF-8");
  44. $attendee_state = html_entity_decode(stripslashes($attendee->state), ENT_QUOTES, "UTF-8");
  45. $attendee_zip = $attendee->zip;
  46. $attendee_email = $attendee->email;
  47. $attendee_organization_name = $attendee->organization_name;
  48. //$attendee_country = $attendee->country_id;
  49. $phone = $attendee->phone;
  50. $date = $attendee->date;
  51. $num_people = $attendee->quantity;
  52. $payment_status = $attendee->payment_status;
  53. $txn_type = $attendee->txn_type;
  54. $amount_pd = $attendee->amount_pd;
  55. $payment_date = $attendee->payment_date;
  56. $event_id = $attendee->event_id;
  57. $event_name = html_entity_decode(stripslashes($attendee->event_name), ENT_QUOTES, "UTF-8");
  58. //$attendee_session = $attendee->attendee_session;
  59. //$registration_id=$attendee->registration_id;
  60. }
  61.  
  62. #$num_people = isset($num_people) && $num_people > 0 ? $num_people : espresso_count_attendees_for_registration($attendee_id);
  63. #$event_meta = event_espresso_get_event_meta($event_id);
  64. // $event_data['additional_attendee_reg_info']
  65. //if ($payment_status != 'Completed') {
  66. // $payment_status = 'Pending';
  67. // $txn_type = 'INV';
  68. // $payment_date = date('Y-m-d-H:i:s');
  69.  
  70. //Added by Imon
  71. // if (count($registration_ids) > 0 && $admin == false) {
  72. // foreach ($registration_ids as $reg_id) {
  73. // $sql = "UPDATE " . EVENTS_ATTENDEE_TABLE . " SET payment_status = '" . $payment_status . "', txn_type = '" . $txn_type . "', payment_date ='" . $payment_date . "' WHERE registration_id ='" . $reg_id['registration_id'] . "' AND txn_type ='' ";
  74. // $wpdb->query($sql);
  75. // }
  76. // }
  77. //}
  78. //Query Database for event and get variable
  79. /* $events = $wpdb->get_results("SELECT * FROM " . EVENTS_DETAIL_TABLE . " WHERE id='" . $event_id . "'");
  80. foreach ($events as $event){
  81. //$event_id = $event->id;
  82. $event_name = html_entity_decode(stripslashes($event->event_name),ENT_QUOTES,"UTF-8");
  83. $event_desc = $event->event_desc;
  84. $event_description = $event->event_desc;
  85. $event_identifier = $event->event_identifier;
  86. $start_date = $event->start_date;
  87. } */
  88. //This is an example of how to get custom questions for an attendee
  89. //Get the questions for the attendee
  90. /* $q_sql = "SELECT ea.answer, eq.question
  91. FROM " . EVENTS_ANSWER_TABLE . " ea
  92. LEFT JOIN " . EVENTS_QUESTION_TABLE . " eq ON eq.id = ea.question_id
  93. WHERE ea.registration_id = '".$registration_id."'";
  94. $q_sql .= " AND ea.question_id = '9' ";
  95. $q_sql .= " ORDER BY eq.sequence asc ";
  96. $wpdb->get_results($q_sql);*/
  97.  
  98. $organization_name = $wpdb->last_result[0]->answer;//question_id = '9'
  99.  
  100. $organization_name = do_shortcode('[EE_ANSWER q="9" a="'.$attendee_id.'"]');
  101.  
  102. //Instanciation of inherited class
  103. $pdf = new Espresso_PDF();
  104. $pdf->AliasNbPages();
  105. $pdf->SetAuthor(pdftext($org_options['organization']));
  106. if (isset($invoice_payment_settings['pdf_title'])) {
  107. $pdf->SetTitle(pdftext($event_name . ' - ' . $invoice_payment_settings['pdf_title']));
  108. } else {
  109. $pdf->SetTitle(pdftext($event_name));
  110. }
  111.  
  112. //$pdf->SetAutoPageBreak('auto');
  113. $pdf->AddPage();
  114. //Create the top right of invoice below header
  115. $pdf->SetFont('Times', '', 12);
  116. $pdf->Cell(180, 0, __('Date: ', 'event_espresso') . date(get_option('date_format')), 0, 1, 'R'); //Set invoice date
  117. $pdf->Cell(180, 10, __('Primary Attendee ID: ', 'event_espresso') . $attendee_id, 0, 0, 'R'); //Set Invoice number
  118. $pdf->Ln(0);
  119.  
  120. //Set the top left of invoice below header
  121. $pdf->SetFont('Times', 'BI', 14);
  122. if (isset($invoice_payment_settings['payable_to'])) {
  123. $pdf->MultiCell(0, 10, pdftext($invoice_payment_settings['payable_to']), 0, 'L'); //Set payable to
  124. } else {
  125. $pdf->MultiCell(0, 10, pdftext(''), 0, 'L'); //Set payable to
  126. }
  127. $pdf->SetFont('Times', '', 12);
  128. if (isset($invoice_payment_settings['payment_address'])) {
  129. $pdf->MultiCell(50, 5, pdftext($invoice_payment_settings['payment_address']), 0, 'L'); //Set address
  130. } else {
  131. $pdf->MultiCell(50, 5, pdftext(''), 0, 'L'); //Set address
  132. }
  133. $pdf->Ln(5);
  134.  
  135. //Set the biiling information
  136. $pdf->SetFont('Times', 'B', 12);
  137. $pdf->Cell(50, 5, __('Bill To: ', 'event_espresso'), 0, 1, 'L'); //Set biil to
  138. $pdf->SetFont('Times', '', 12);
  139. $pdf->Cell(50, 5, pdftext($attendee_first . ' ' . $attendee_last), 0, 1, 'L'); //Set attendee name
  140. $pdf->Cell(50, 5, $attendee_email, 0, 1, 'L'); //Set attendee email
  141. $pdf->Cell(50, 5, $organization_name, 0, 1, 'L'); //Set attendee email
  142. //Set attendee address
  143. $attendee_address != '' ? $pdf->Cell(100, 5, $attendee_address, 0, 1, 'L') : '';
  144. $pdf->Cell(100, 5, (pdftext($attendee_city != '' ? $attendee_city : '') . ($attendee_state != '' ? ' ' . $attendee_state : '')), 0, 1, 'L');
  145. $attendee_zip != '' ? $pdf->Cell(50, 5, $attendee_zip, 0, 1, 'L') : '';
  146.  
  147. $pdf->Ln(10);
  148.  
  149. //Added by Imon
  150. $attendees = array();
  151. $total_cost = 0.00;
  152. $total_orig_cost = 0.00;
  153. $total_amount_pd = 0.00;
  154. foreach ($registration_ids as $reg_id) {
  155. $sql = "select ea.registration_id, ed.event_name, ed.start_date, ed.event_identifier, ea.fname, ea.lname, ea.quantity, ea.orig_price, ea.final_price, ea.amount_pd from " . EVENTS_ATTENDEE_TABLE . " ea ";
  156. //$sql .= " inner join " . EVENTS_ATTENDEE_COST_TABLE . " eac on ea.id = eac.attendee_id ";
  157. $sql .= " inner join " . EVENTS_DETAIL_TABLE . " ed on ea.event_id = ed.id ";
  158. $sql .= " where ea.registration_id = '" . $reg_id['registration_id'] . "' order by ed.event_name ";
  159.  
  160. $tmp_attendees = $wpdb->get_results($sql, ARRAY_A);
  161.  
  162. foreach ($tmp_attendees as $tmp_attendee) {
  163. $sub_total = $tmp_attendee["final_price"] * $tmp_attendee["quantity"];
  164. $orig_total = $tmp_attendee["orig_price"] * $tmp_attendee["quantity"];
  165. $attendees[] = $pdf->LoadData(array(
  166. pdftext($tmp_attendee["event_name"] . "[" . date('m-d-Y', strtotime($tmp_attendee['start_date'])) . "]") . ' >> '
  167. . pdftext(html_entity_decode($tmp_attendee["fname"], ENT_QUOTES, "UTF-8") . " " . html_entity_decode($tmp_attendee["lname"], ENT_QUOTES, "UTF-8")) . ';'
  168. . pdftext($tmp_attendee["quantity"]) . ';'
  169. . doubleval($tmp_attendee["final_price"]) . ';'
  170. . doubleval($sub_total)
  171. )
  172. );
  173. $total_cost += $sub_total;
  174. $total_orig_cost += $orig_total;
  175. $total_amount_pd += $tmp_attendee["amount_pd"];
  176. $event_identifier = $tmp_attendee["event_identifier"];
  177. }
  178. }
  179. $header = array(__('Event & Attendee', 'event_espresso'), __('Quantity', 'event_espresso'), __('Per Unit', 'event_espresso'), __('Sub total', 'event_espresso'));
  180. $w = array(100, 25, 30, 30);
  181. $alling = array('L', 'L', 'C', 'C', 'C');
  182. $left = 100 + 25 + 30;
  183. $right = 30;
  184.  
  185. $pdf->ImprovedTable($header, $attendees, $w, $alling);
  186.  
  187. $pdf->Ln();
  188. //if ( $total_amount_pd != $total_cost ) {
  189. $pdf->InvoiceTotals(__('Total:', 'event_espresso'), $total_cost, $left, $right);
  190. $text = __('Amount Paid:', 'event_espresso');
  191. $pdf->InvoiceTotals($text, $total_amount_pd, $left, $right);
  192. // $discount = $total_orig_cost - $total_cost;
  193. // if ($discount > 0) {
  194. // $text = __('Discount:', 'event_espresso');
  195. // } else {
  196. // $text = __('Discount:', 'event_espresso');
  197. // $pdf->InvoiceTotals($text, $discount, $left, $right);
  198. // }
  199. //}
  200. $total_owing = $total_cost - $total_amount_pd;
  201. $text = __("Total due:", 'event_espresso');
  202. $pdf->InvoiceTotals($text, $total_owing, $left, $right);
  203. $pdf->Ln(10);
  204.  
  205. //Build the payment link and instructions
  206. if (isset($invoice_payment_settings['pdf_instructions'])) {
  207. $pdf->MultiCell(100, 5, pdftext($invoice_payment_settings['pdf_instructions']), 0, 'L'); //Set instructions
  208. } else {
  209. $pdf->MultiCell(100, 5, pdftext(''), 0, 'L'); //Set instructions
  210. }
  211.  
  212. //Create a payment link
  213. $payment_link = home_url() . "/?page_id=" . $org_options['return_url'] . "&r_id=" . $registration_id;
  214.  
  215. $pdf->SetFont('Arial', 'BU', 20);
  216. $pdf->Cell(200, 20, 'Pay Online', 0, 1, 'C', 0, $payment_link); //Set payment link
  217.  
  218. $pdf->Output('Invoice_' . $attendee_id . '_' . $event_identifier . '.pdf', 'D');
  219. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement