/Users/johnr/Desktop/IA pdf Downloads/_New Projects Downloads May 7th/CS_IA_Mattew/thankyou.html
  1 <?php
  2 require 'vendor/autoload.php';
  3 use PHPMailer\PHPMailer\PHPMailer;
  4 spl_autoload_register(function ($class_name) { // https://www.php.net/manual/en/language.oop5.autoload.php
  5     include $class_name . '.class.php';
  6 });
  7 
  8 $inquiry = apcu_fetch('inquiry');
  9 $destination = apcu_fetch('destination');
 10 $customer = apcu_fetch('customer');
 11 $dayPlans = apcu_fetch('dayplans');
 12 $insertData = new InsertData();
 13 $lastInquiryID = $insertData->insertInquiryData($inquiry, $destination);
 14 $customerInsert = $insertData->insertCustomerData($lastInquiryID, $customer);
 15 
 16 if($lastInquiryID == false || $customerInsert == false){
 17     promptError();
 18 }
 19 
 20 for($i = 0; $i < count($dayPlans); $i++){
 21     $dayPlanInsert = $insertData->insertDailyPlanData($lastInquiryID, $dayPlans[$i], $i+1);
 22     if(!$dayPlanInsert){
 23         promptError();
 24     }
 25 }
 26 function promptError(){
 27     echo '<script>alert("An error occured, please try again")</script>';
 28     ?><script>history.back()</script><?php
 29 }
 30 
 31 //first object/iteration is sending mail to the customer, second object/iteration is sending to the golfasian employee email
 32 for($j = 0; $j < 2; $j++){
 33 //php mailer: https://github.com/PHPMailer/PHPMailer
 34     //Mailing host info
 35     //Change info below to golfasian host email
 36     $phpmailer = new PHPMailer();
 37     $phpmailer->isSMTP();
 38     $phpmailer->Mailer = "smtp";
 39     $phpmailer->SMTPAuth = true;
 40 
 41     //from https://netcorecloud.com/tutorials/send-an-email-via-gmail-smtp-server-using-php/
 42     $phpmailer->SMTPSecure = "tls";
 43     $phpmailer->Port = 587;
 44     $phpmailer->Host = "smtp.gmail.com";
 45     $phpmailer->Username = "ibcomputerscienceia14@gmail.com";
 46     $phpmailer->Password = "Computersciencepass1";
 47 
 48     $phpmailer->setFrom('ibcomputerscienceia14@gmail.com', 'Golfasian');
 49     $phpmailer->addReplyTo('info@golfasian.com', 'Golfasian');
 50     if($j == 0){
 51         $phpmailer->addAddress($customer->getEmail(), $customer->getFullName()); //customer email
 52     }else{
 53         $phpmailer->addAddress('ibcomputerscienceia14@gmail.com'); //golfasian employee email
 54     }
 55     
 56     $phpmailer->isHTML(true);
 57     $phpmailer->Subject = 'Golfasian Inquiry for '.$customer->getFullName(). ' ID: '.$lastInquiryID;
 58 
 59     //storing the HTML as an object to be sent as the email body
 60     ob_start(); ?>
 61     <!DOCTYPE html>
 62     <div class="container">
 63         <?php
 64         if($j == 1){ ?>
 65         <p>
 66             <a href="localhost/CS_IA/inquiryExcelDownload.html?inquiryid=<?php echo $lastInquiryID; ?>" target="_blank" style="font-size: 22px">Download inquiry to excel file</a> <br>
 67             <a href="localhost/CS_IA/entireExcelDownload.html" target="_blank" style="font-size: 22px">Download entire database to excel file</a>
 68         </p>
 69             
 70         <?php } ?>
 71             <p>
 72             <h4>Customer and Contact Information:</h4>
 73             <hr>
 74             <table style="border-spacing: auto; width: 100%; text-align: center;">
 75             <tr>
 76                 <th>InquiryID</th>
 77                 <th>Name</th>
 78                 <th>Email</th>
 79                 <th>Phone Number</th>
 80                 <th>Nationality</th>
 81             </tr>
 82             <tr>
 83                 <td> <?php echo $lastInquiryID; ?> </td>
 84                 <td> <?php echo $customer->getFirstName()." ".$customer->getMiddlename()." ".$customer->getLastName(); ?> </td>
 85                 <td> <?php echo $customer->getEmail(); ?> </td>
 86                 <td> <?php echo $customer->getPhoneNumber(); ?> </td>
 87                 <td> <?php echo $customer->getNationality(); ?> </td>
 88             </tr>
 89             </table>
 90             <hr>
 91             </p><p>
 92             <h4>Trip Details:</h4>
 93             <hr>
 94             <table style="border-spacing: auto; width: 100%; text-align: center;">
 95             <tr>
 96                 <th>Destination(s)</th>
 97                 <th>Arrival</th>
 98                 <th>Departure</th>
 99                 <th>Period</th>
100                 <th>Hotel Standard</th>
101             </tr>
102             <tr>
103                 <td> <?php echo $destination->getChosenDestination(); ?> </td>
104                 <td> <?php echo $inquiry->getArrivalDate(); ?> </td>
105                 <td> <?php echo $inquiry->getDepartureDate(); ?> </td>
106                 <td> <?php echo $inquiry->getNumberOfDays(); ?> days, <?php echo $inquiry->getNumberOfNights() ?> nights</td>
107                 <td> <?php echo $inquiry->getHotelRating()." stars"; ?> </td>
108             </tr>
109             </table>
110             <hr>
111             </p><p>
112             <h4>Day by Day Details:</h4>
113             <table style="border-spacing: auto; width: 100%; text-align: center;">
114             <hr>
115             <tr>
116                 <th>Day Number</th>
117                 <th>Hotel</th>
118                 <th>Hotel Breakfast</th>
119                 <th>Golf</th>
120                 <th>Requested Tee Time</th>
121                 <th>Cart</th>
122                 <th>Caddie</th>
123                 <th>Transportation Required</th>
124             </tr>
125             <?php for($i = 0; $i < $inquiry->getNumberOfDays(); $i++){            
126                 if($dayPlans[$i]->getHotelBreakfast()){
127                     $hotelBreakfast = "Yes";
128                 }else{
129                     $hotelBreakfast = "None";
130                 }
131                 if($dayPlans[$i]->getGolfCourse() != "No golf day"){
132                     if($dayPlans[$i]->getCart()){
133                         $cart = "Yes";
134                     }else{
135                         $cart = "None";
136                     }
137                     if($dayPlans[$i]->getCaddie()){
138                         $caddie = "Yes";
139                     }else{
140                         $caddie = "None";
141                     }
142                 }else{
143                     $cart = NULL;
144                     $caddie = NULL;
145                 }
146                 if($dayPlans[$i]->getTransportation()){
147                     $transportation = "Yes";
148                 }else{
149                     $transportation = "No";
150                 }
151                 ?>
152                 <tr>
153                 <td> <?php echo $i+1; ?> </td>
154                 <td> <?php echo $dayPlans[$i]->getHotel(); ?> </td>
155                 <td> <?php echo $hotelBreakfast; ?> </td>
156                 <td> <?php echo $dayPlans[$i]->getGolfCourse(); ?> </td>
157                 <td> <?php echo $dayPlans[$i]->getTeeTime(); ?> </td>
158                 <td> <?php echo $cart; ?> </td>
159                 <td> <?php echo $caddie; ?> </td>
160                 <td> <?php echo $transportation; ?> </td>
161             </tr>
162             <?php } ?>
163             </table>
164             </p>
165             <hr>
166     </html>
167     <?php $customerMailContent = ob_get_clean();
168 
169     $phpmailer->Body = $customerMailContent;
170 
171     if(!$phpmailer->send()){
172         exit('<script>alert("Invalid Email, please try again. \r\n Mailer Error: ' . $phpmailer->ErrorInfo.'"); history.back()</script>');
173 
174     }
175     
176 }
177 
178 ?>
179 <!DOCTYPE html>
180 <head>
181     <link href="style.css" rel="stylesheet">
182 </head>
183 
184 <h1>Golfasian Inquiry Form</h1>
185 
186 <body>
187 <div class="container">
188     <h2>Thank you for your submission</h2>
189     You will recieve an email shortly with your inquiry details
190 </div>
191 </body>
192 </html>
193 <?php
194 apcu_delete('inquiry');
195 apcu_delete('customer');
196 apcu_delete('destination');
197 apcu_delete('dayplans');
198 ?>
199 
200