예제 #1
0
 public static function sendNewBookingMail($booking, $userId)
 {
     $user = User::where('id', $userId)->first();
     $date = strftime('%A %e %B %Y, %H.%M (%Z)', $booking->startUts);
     $twig = UserFrosting::getInstance()->view()->getEnvironment();
     $template = $twig->loadTemplate("mail/sendNewBookingMail.twig");
     $subject = 'Ny taxibokning';
     if ($booking->originCity && $booking->destinationCity) {
         $subject = 'Ny taxibokning från ' . $booking->originCity . ' till ' . $booking->destinationCity;
         if ($booking->originCity == $booking->destinationCity) {
             $subject = 'Ny taxibokning inom ' . $booking->originCity;
         }
     }
     $notification = new Notification($template);
     $notification->from("*****@*****.**", $user->title, $user->email, $user->title);
     // future bookings
     $bookings = Booking::where('user_id', $userId)->where('id', '!=', $booking->id)->where('startUts', '>', time() - 21600)->get();
     $htmlRows = array();
     $statuses = array('new' => 'Ohanterat', 'accepted' => 'Accepterad', 'rejected' => 'Avvisad');
     foreach ($bookings as $key => $futureBooking) {
         $backgroundColor = $key % 2 == 0 ? '#e9e9e9' : '#ffffff';
         $style = "background-color: {$backgroundColor}; font-size: 12px; padding: 10px";
         $buttonHtml = '';
         if ($futureBooking->status == 'new') {
             $buttonHtml = '<a href="' . UserFrosting::getInstance()->site->uri['public'] . '/booking/' . $futureBooking->id . '/accept/' . $futureBooking->hash . '" style="background-color: #8ea604; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Acceptera</a><a href="' . UserFrosting::getInstance()->site->uri['public'] . '/booking/' . $futureBooking->id . '/reject/' . $futureBooking->hash . '" style="background-color: #c00000; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Avslå</a>';
             //$buttonHtml = '<a href="http://taxibooking.allanth.dk/?action=accept&amp;bookingId=' . $futureBooking->id . '&amp;hash=' . $futureBooking->hash . '&amp;c=' . $client->name . '" style="background-color: #8ea604; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Acceptera</a><a href="http://taxibooking.allanth.dk/?action=reject&amp;bookingId=' . $futureBooking->id . '&amp;hash=' . $futureBooking->hash . '&amp;c=' . $client->name . '" style="background-color: #C00000; color: white; padding: 10px; border-radius: 5px;text-decoration: none;margin-right: 20px;">Avslå</a>';
         }
         $htmlRows[] = "\n                <tr valign=\"top\">\n                    <td style=\"{$style}\" colspan=\"2\">Från <strong>" . htmlspecialchars($futureBooking->origin) . "</strong> till <strong>" . htmlspecialchars($futureBooking->destination) . "</strong></td>\n                </tr>\n                <tr valign=\"top\">\n                    <td style=\"{$style}\" width=\"60%\">\n                        Avresedatum: " . htmlspecialchars(strftime('%A %e %B %Y, %H.%M (%Z)', $futureBooking->startUts)) . "<br />\n                        Namn: " . htmlspecialchars($futureBooking->name) . "<br />\n                        Email: " . htmlspecialchars($futureBooking->email) . "<br />\n                        Telefon: " . htmlspecialchars($futureBooking->phone) . "<br /><br />\n                        Avstånd: " . htmlspecialchars($futureBooking->distance) . "<br />\n                        Körtid: " . htmlspecialchars($futureBooking->duration) . "<br />\n                        Pris: " . htmlspecialchars($futureBooking->price) . ":- kr.\n                    </td>\n                    <td style=\"{$style}\" width=\"40%\"><span style=\"font-size: 20px\">Tur: " . htmlspecialchars($futureBooking->alphaId) . "</span>\n                    <br />Status: " . htmlspecialchars($statuses[$futureBooking->status]) . "<br /><br />{$buttonHtml}</td> \n                </tr>";
     }
     $futureBookingsHtml = '';
     if (count($htmlRows)) {
         $futureBookingsHtml = "\n                <p><strong>Kommende bookings</strong></p>\n                <table cellspacing=\"0\">" . implode("", $htmlRows) . " \n                </table>\n            ";
     }
     $notification->addEmailRecipient($user->email, $user->title, ['date' => $date, 'booking' => $booking, 'client' => $user, 'headerLine1' => $user->title, 'headerLine2' => $subject, 'footerLine' => "Skickat " . strftime('%A %e %B %Y, %H.%M (%Z)'), 'subject' => $subject, 'futureBookingsHtml' => $futureBookingsHtml]);
     $success = NULL;
     try {
         $success = $notification->send();
     } catch (\phpmailerException $e) {
         print $e->errorMessage();
         $app->halt(500);
     }
     return $success;
 }
예제 #2
0
파일: Booking.php 프로젝트: allanth4/taxibo
 public static function alphaIdExists($alphaId, $userId)
 {
     $booking = Booking::where('alphaId', $alphaId)->where('user_id', $userId)->first();
     if ($booking) {
         return true;
     }
     return false;
 }
예제 #3
0
파일: index.php 프로젝트: allanth4/taxibo
                } else {
                    preg_match('/accepted-([0-9]+)/', $status, $matches);
                    if (!empty($matches[1])) {
                        $booking->status = 'accepted';
                        $booking->carId = $matches[1];
                    }
                }
            }
            $booking->save();
            $ms->addMessageTranslated("success", "Bokning uppdateras", $post);
        }
    }
});
// show booking
$app->get('/bookings/:booking_id/?', function ($bookingId) use($app) {
    $booking = UF\Booking::where('user_id', $app->user->id)->where('id', $bookingId)->first();
    if (empty($booking)) {
        exit("Show booking {$bookingId}: Booking not found");
    }
    // Get the validation rules for the form on this page
    $schema = new \Fortress\RequestSchema($app->config('schema.path') . "/forms/booking-update.json");
    $app->jsValidator->setSchema($schema);
    $cars = UF\Car::where('user_id', $app->user->id)->get();
    $statuses = array('new' => 'Ohanterat', 'accepted' => 'Accepterad');
    foreach ($cars as $car) {
        $statuses['accepted-' . $car->id] = 'Accepterad (' . $car->title . ')';
    }
    $statuses['rejected'] = 'Avvisad';
    $app->render('booking.twig', ['booking' => $booking, 'validators' => $app->jsValidator->rules(), 'statuses' => $statuses]);
});
$app->get('/bookings/?', function () use($app) {