|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @package API plugins |
| 4 | + * @copyright Copyright (C) 2009 2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved. |
| 5 | + * @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html> |
| 6 | + * @link http://www.techjoomla.com |
| 7 | +*/ |
| 8 | + |
| 9 | +defined('_JEXEC') or die; |
| 10 | + |
| 11 | +jimport('joomla.plugin.plugin'); |
| 12 | + |
| 13 | + |
| 14 | +class JticketApiResourceCheckin extends ApiResource |
| 15 | +{ |
| 16 | + public function get() |
| 17 | + { |
| 18 | + jimport( 'joomla.application.component.helper' ); |
| 19 | + $send_email_after_checkin=0; |
| 20 | + $com_params=JComponentHelper::getParams('com_jticketing'); |
| 21 | + $send_email_after_checkin = $com_params->get('send_email_after_checkin'); |
| 22 | + $jticketingmainhelper = new jticketingmainhelper(); |
| 23 | + $lang =JFactory::getLanguage(); |
| 24 | + $extension = 'com_jticketing'; |
| 25 | + $base_dir = JPATH_SITE; |
| 26 | + $lang->load($extension, $base_dir); |
| 27 | + $ticketidstr = JRequest::getVar('ticketid',0); |
| 28 | + $eventid = JRequest::getVar('eventid',0); |
| 29 | + $eventintegrationid=$jticketingmainhelper->getEventrefid($eventid); |
| 30 | + |
| 31 | + if(empty($ticketidstr)) |
| 32 | + { |
| 33 | + $obj->success = 0; |
| 34 | + $obj->message =JText::_("COM_JTICKETING_INVALID_TICKET"); |
| 35 | + $this->plugin->setResponse($obj); |
| 36 | + return; |
| 37 | + |
| 38 | + |
| 39 | + } |
| 40 | + |
| 41 | + $ticketidarr=explode('-',$ticketidstr); |
| 42 | + $oid=$ticketidarr[0]; |
| 43 | + $orderitemsid=$ticketidarr[1]; |
| 44 | + $obj = new stdClass(); |
| 45 | + |
| 46 | + $result=$jticketingmainhelper->GetActualTicketidAPI($oid,$orderitemsid,''); |
| 47 | + $originalticketid=JText::_("TICKET_PREFIX").$ticketidstr; |
| 48 | + |
| 49 | + if($result[0]->attendee_id) |
| 50 | + { |
| 51 | + $field_array=array('first_name','last_name'); |
| 52 | + //Get Attendee Details |
| 53 | + $attendee_details=$jticketingmainhelper->getAttendees_details($result[0]->attendee_id,$field_array); |
| 54 | + } |
| 55 | + |
| 56 | + if(!empty($attendee_details['first_name'])) |
| 57 | + { |
| 58 | + $attendernm=implode(" ",$attendee_details); |
| 59 | + } |
| 60 | + else |
| 61 | + { |
| 62 | + $attendernm=$result[0]->name; |
| 63 | + } |
| 64 | + |
| 65 | + if(empty($result)) |
| 66 | + { |
| 67 | + $obj->success = 0; |
| 68 | + $obj->message =JText::_("COM_JTICKETING_INVALID_TICKET"); |
| 69 | + |
| 70 | + } |
| 71 | + else if($result[0]->eventid!=$eventintegrationid) |
| 72 | + { |
| 73 | + $obj->success = 0; |
| 74 | + $obj->message =JText::_("COM_JTICKETING_INVALID_TICKET"); |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + $checkindone=$jticketingmainhelper->GetCheckinStatusAPI($orderitemsid); |
| 79 | + if($checkindone) |
| 80 | + { |
| 81 | + $obj->success = 0; |
| 82 | + if($attendernm) |
| 83 | + $obj->message =sprintf(JText::_('COM_JTICKETING_CHECKIN_FAIL_DUPLICATE'),$attendernm); |
| 84 | + else |
| 85 | + $obj->message =JText::_('COM_JTICKETING_CHECKIN_FAIL_DUPLICATE'); |
| 86 | + |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + |
| 91 | + |
| 92 | + $obj->success = $jticketingmainhelper->DoCheckinAPI($orderitemsid,$result); |
| 93 | + |
| 94 | + if($obj->success) |
| 95 | + { |
| 96 | + $obj->success = 1; |
| 97 | + $ticketTypeData=$jticketingmainhelper->GetTicketTypes('',$result[0]->type_id); |
| 98 | + $app =JFactory::getApplication(); |
| 99 | + $mailfrom = $app->getCfg('mailfrom'); |
| 100 | + $fromname = $app->getCfg('fromname'); |
| 101 | + $sitename = $app->getCfg('sitename'); |
| 102 | + $message=JText::_("CHECKIN_MESSAGE"); |
| 103 | + $message_subject=JText::_("CHECKIN_SUBJECT"); |
| 104 | + $eventnm=$jticketingmainhelper->getEventTitle($oid); |
| 105 | + $message_subject= stripslashes($message_subject); |
| 106 | + $message_subject = str_replace("[EVENTNAME]", $eventnm,$message_subject); |
| 107 | + |
| 108 | + $message_body = stripslashes($message); |
| 109 | + $message_body = str_replace("[EVENTNAME]", $eventnm,$message_body); |
| 110 | + $message_body = str_replace("[NAME]", $attendernm,$message_body); |
| 111 | + $message_body = str_replace("[TICKETID]", $originalticketid,$message_body); |
| 112 | + $message_body = str_replace("[TICKET_TYPE_TITLE]", $ticketTypeData[0]->title,$message_body); |
| 113 | + |
| 114 | + |
| 115 | + if($send_email_after_checkin) |
| 116 | + { |
| 117 | + $result=JFactory::getMailer()->sendMail($fromname,$mailfrom,$result[0]->email,$message_subject,$message_body,$html=1,null,null,''); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + if($attendernm and $ticketTypeData[0]->title and $originalticketid) |
| 122 | + { |
| 123 | + $obj->message =sprintf(JText::_('COM_JTICKETING_CHECKIN_SUCCESS'),$attendernm,$ticketTypeData[0]->title,$originalticketid); |
| 124 | + } |
| 125 | + else |
| 126 | + { |
| 127 | + $obj->message =JText::_('COM_JTICKETING_CHECKIN_SUCCESS'); |
| 128 | + |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + $this->plugin->setResponse($obj); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * This is not the best example to follow |
| 138 | + * Please see the category plugin for a better example |
| 139 | + */ |
| 140 | + public function post() |
| 141 | + { |
| 142 | + |
| 143 | + |
| 144 | + } |
| 145 | + |
| 146 | + public function put() |
| 147 | + { |
| 148 | + |
| 149 | + } |
| 150 | + |
| 151 | + |
| 152 | +} |
0 commit comments