Example #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;
 }
Example #2
0
 public static function alphaIdExists($alphaId, $userId)
 {
     $booking = Booking::where('alphaId', $alphaId)->where('user_id', $userId)->first();
     if ($booking) {
         return true;
     }
     return false;
 }
Example #3
0
        case 'week':
            $startUts = strtotime('this week');
            $endUts = strtotime('next week');
            break;
        case 'month':
            $d = new DateTime();
            $d->modify('first day of this month 00:00:00');
            $startUts = $d->format('U');
            $d->modify('first day of next month');
            $endUts = $d->format('U');
            break;
        default:
            exit("wrong period: {$period}");
            break;
    }
    $futureBookingsQuery = UF\Booking::QueryBuilder()->where('user_id', $app->user->id)->where('startUts', '>=', $startUts)->where('endUts', '<', $endUts)->orderBy('startUts');
    // important
    if ($period == 'plan') {
        $futureBookingsQuery = $futureBookingsQuery->take(25);
    }
    $futureBookings = $futureBookingsQuery->get();
    $app->render('bookings.twig', ["bookings" => $futureBookings, "period" => $period, "todayUts" => (new DateTime('today'))->getTimestamp(), "todaysDate" => strftime("%A %e %B %Y", $startUts)]);
})->name('bookings');
/********** ACCOUNT MANAGEMENT INTERFACE **********/
$app->get('/account/:action/?', function ($action) use($app) {
    // Forward to installation if not complete
    if (!isset($app->site->install_status) || $app->site->install_status == "pending") {
        $app->redirect($app->urlFor('uri_install'));
    }
    $get = $app->request->get();
    $controller = new UF\AccountController($app);