public static function post()
 {
     //If required data is not in session go to search page
     if (!isset($_SESSION['Stippers']['ManageUserSearch']['inputData']['values'])) {
         header('Location: manageuser', TRUE, 303);
     } else {
         $page = new Page();
         $page->data['title'] = 'E-mail versturen naar gebruikers';
         $errMsgs = SendEmailToUsersViewValidator::validate($_POST);
         if (empty($errMsgs)) {
             try {
                 //Get search users
                 $select = ['email' => true, 'firstName' => true, 'lastName' => true];
                 $users = array_column(UserDB::getSearchUsers($select, $_SESSION['Stippers']['ManageUserSearch']['inputData']['values'], null), 'user');
                 //Send email
                 $failedAddresses = Email::sendEmails($_POST['email_file'], $_POST['subject'], EmailConfig::FROM_ADDRESS, $users, null);
                 //Check if some emails failed
                 if (empty($failedAddresses)) {
                     $page->date['SuccessMessageNoDescriptionWithLinkView']['successTitle'] = 'E-mails succesvol verzonden';
                     $page->date['SuccessMessageNoDescriptionWithLinkView']['redirectUrl'] = 'manageuser';
                     $page->addView('success/SuccessMessageNoDescriptionWithLinkView');
                 } else {
                     $page->data['ErrorMessageWithDescriptionNoLinkView']['errorTitle'] = 'Kan niet alle e-mails verzenden';
                     $page->data['ErrorMessageWithDescriptionNoLinkView']['errorDescription'] = 'Het verzenden van de e-mail naar onderstaande addressen is mislukt.';
                     $page->addView('error/ErrorMessageWithDescriptionNoLinkView');
                     $page->data['FailedEmailListView']['addresses'] = $failedAddresses;
                     $page->data['FailedEmailListView']['redirectUrl'] = 'manageuser';
                     $page->addView('sendEmailToUsers/FailedEmailListView');
                 }
             } catch (UserDBException $ex) {
                 $page->data['ErrorMessageNoDescriptionWithLinkView']['errorTitle'] = 'Kan gebruikers niet ophalen';
                 $page->data['ErrorMessageNoDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
                 $page->addView('error/ErrorMessageNoDescriptionWithLinkView');
             } catch (EmailException $ex) {
                 if ($ex->getCode() == EmailException::CANNOTREADEMAILFILE) {
                     $page->data['ErrorMessageNoDescriptionWithLinkView']['errorTitle'] = 'Kan e-mailbestand niet lezen';
                 } else {
                     $page->data['ErrorMessageNoDescriptionWithLinkView']['errorTitle'] = 'Kan e-mails niet verzenden';
                 }
                 $page->data['ErrorMessageNoDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
                 $page->addView('error/ErrorMessageNoDescriptionWithLinkView');
             } catch (Exception $ex) {
                 $page->data['ErrorMessageNoDescriptionWithLinkView']['errorTitle'] = 'Kan e-mails niet verzenden';
                 $page->data['ErrorMessageNoDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
                 $page->addView('error/ErrorMessageNoDescriptionWithLinkView');
             }
         } else {
             $page->addView('sendEmailToUsers/SendEmailToUsersTitleView');
             SendEmailToUsersController::buildSendEmailToUsersFormView($page, true);
             $page->data['SendEmailToUsersFormView']['errMsgs'] = array_merge($page->data['SendEmailToUsersFormView']['errMsgs'], $errMsgs);
         }
         $page->showWithMenu();
     }
 }
Пример #2
0
 public static function post()
 {
     $page = new Page();
     $page->data['title'] = 'Wachtwoord resetten';
     $errMsgs = ResetPasswordViewValidator::validate($_POST);
     if (empty($errMsgs)) {
         try {
             //Get the user's password salt and calculate password hash
             $passwordSalt = UserDB::getPasswordSaltByEmail($_POST['email']);
             $newPassword = Random::getPassword();
             $newPasswordHash = hash_pbkdf2('sha256', $newPassword, $passwordSalt, SecurityConfig::N_PASSWORD_HASH_ITERATIONS);
             //Get user from database and reset password.
             $user = UserDB::getBasicUserByEmail($_POST['email']);
             UserDB::resetPassword($_POST['email'], $newPasswordHash);
             //Show success message
             $page->data['ResetSuccessfulView']['redirectUrl'] = 'login';
             $page->addView('resetPassword/ResetSuccessfulView');
             //Send email with password
             $failedEmails = Email::sendEmails('ResetPassword.html', 'JH De Stip - Wachtwoord reset', EmailConfig::FROM_ADDRESS, [$user], array($user->userId => array('newPassword' => $newPassword)));
             //If failedEmails is not empty the mail was not sent
             if (!empty($failedEmails)) {
                 $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan e-mail met nieuwe wachtwoord niet verzenden.';
                 $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
             }
         } catch (UserDBException $ex) {
             $page->data['ResetPasswordView']['reset_password_formAction'] = $_SERVER['REQUEST_URI'];
             $page->data['ResetPasswordView']['email'] = $_POST['email'];
             $page->data['ResetPasswordView']['errMsgs'] = ResetPasswordViewValidator::initErrMsgs();
             if ($ex->getCode() == UserDBException::NOUSERFOREMAIL) {
                 $page->data['ResetPasswordView']['errMsgs']['global'] = '<h2 class="error_message" id="reset_password_form_error_message">Er is geen gebruiker met dit e-mailadres.</h2>';
             } else {
                 $page->data['ResetPasswordView']['errMsgs']['global'] = '<h2 class="error_message" id="reset_password_form_error_message">Kan wachtwoord niet resetten, probeer het opnieuw.</h2>';
             }
             $page->addView('resetPassword/ResetPasswordView');
         } catch (EmailException $ex) {
             $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan e-mail met nieuwe wachtwoord niet verzenden.';
             $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
         } catch (Exception $ex) {
             $page->data['ResetPasswordView']['reset_password_formAction'] = $_SERVER['REQUEST_URI'];
             $page->data['ResetPasswordView']['email'] = $_POST['email'];
             $page->data['ResetPasswordView']['errMsgs']['global'] = '<h2 class="error_message" id="reset_password_form_error_message">Kan wachtwoord niet resetten, probeer het opnieuw.</h2>';
             $page->addView('resetPassword/ResetPasswordView');
         }
     } else {
         $page->data['ResetPasswordView']['reset_password_formAction'] = $_SERVER['REQUEST_URI'];
         $page->data['ResetPasswordView']['email'] = $_POST['email'];
         $page->data['ResetPasswordView']['errMsgs'] = ResetPasswordViewValidator::initErrMsgs();
         $page->data['ResetPasswordView']['errMsgs'] = array_merge($page->data['ResetPasswordView']['errMsgs'], $errMsgs);
         $page->addView('resetPassword/ResetPasswordView');
     }
     $page->showWithMenu();
 }
Пример #3
0
 public static function post()
 {
     $page = new Page();
     $page->data['title'] = 'Gebruiker toevoegen';
     //Validate input
     $formTopViewErrMsgs = UserDataFormTopViewValidator::validate($_POST);
     $formPasswordViewErrMsgs = UserDataFormPasswordViewValidator::validate($_POST);
     $formMiddleViewErrMsgs = UserDataFormMiddleViewValidator::validate($_POST);
     //No error means we create a user and password salt
     if (empty($formTopViewErrMsgs) && empty($formPasswordViewErrMsgs) && empty($formMiddleViewErrMsgs)) {
         $passwordSalt = Random::getGuid();
         $user = new User();
         $user->email = $_POST['email'];
         $user->firstName = ucwords($_POST['first_name']);
         $user->lastName = ucwords($_POST['last_name']);
         $user->passwordHash = hash_pbkdf2("sha256", $_POST['password'], $passwordSalt, SecurityConfig::N_PASSWORD_HASH_ITERATIONS);
         $user->street = ucwords($_POST['street']);
         $user->houseNumber = $_POST['house_number'];
         $user->city = ucwords($_POST['city']);
         $user->postalCode = $_POST['postal_code'];
         $user->country = ucwords($_POST['country']);
         $user->phone = $_POST['phone'];
         $user->dateOfBirth = $_POST['date_of_birth'];
         //Add the user
         try {
             $userId = UserDB::addUser($user, $passwordSalt, $_POST['card_number']);
             $page->addView('addRenewUser/addUser/SuccessfullyAddedView');
             //Send welcome mail
             try {
                 $failedEmails = Email::sendEmails('WelcomeNewMember.html', 'JH DE Stip - Welkom', EmailConfig::FROM_ADDRESS, [$user], null);
                 //If failedEmails is not empty the mail was not sent
                 if (!empty($failedEmails)) {
                     $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan welkomstmail niet verzenden.';
                     $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
                 }
             } catch (Exception $ex) {
                 $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan welkomstmail niet verzenden.';
                 $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
             }
             //Add money to user's card
             try {
                 $addedUser = UserDB::getFullUserById($userId);
                 $executingBrowserName = BrowserDB::getBrowserById($_SESSION['Stippers']['browser']->browserId)->name;
                 $trans = new MoneyTransaction(null, $addedUser->userId, 0, AddOrRenewUserConfig::NEW_OR_RENEWED_USER_BONUS, 0, 0, true, null, $executingBrowserName, null);
                 MoneyTransactionDB::addTransaction($addedUser, $trans);
             } catch (Exception $ex) {
                 if (isset($page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'])) {
                     $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] .= ' Kan het saldo van het account niet verhogen, probeer dit handmatig te doen.';
                 } else {
                     $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan het saldo van het account niet verhogen, probeer dit handmatig te doen.';
                 }
                 $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
             }
         } catch (UserDBException $ex) {
             AddUserController::buildAddUserPage($page, true);
             if ($ex->getCode() == UserDBException::EMAILALREADYEXISTS) {
                 $page->data['UserDataFormTopView']['errMsgs']['global'] = '<h2 class="error_message" id="user_data_form_error_message">Dit e-mailadres is al in gebruik.</h2>';
             } elseif ($ex->getCode() == UserDBException::CARDALREADYUSED) {
                 $page->data['UserDataFormTopView']['errMsgs']['global'] = '<h2 class="error_message" id="user_data_form_error_message">Dit kaartnummer is al in gebruik.</h2>';
             } else {
                 $page->data['UserDataFormTopView']['errMsgs']['global'] = '<h2 class="error_message" id="user_data_form_error_message">Kan gebruiker niet toevoegen, probeer het opnieuw.</h2>';
             }
         } catch (Exception $ex) {
             AddUserController::buildAddUserPage($page, true);
             $page->data['UserDataFormTopView']['errMsgs']['global'] = '<h2 class="error_message" id="user_data_form_error_message">Kan gebruiker niet toevoegen, probeer het opnieuw.</h2>';
         }
     } else {
         AddUserController::buildAddUserPage($page, true);
         $page->data['UserDataFormTopView']['errMsgs'] = array_merge($page->data['UserDataFormTopView']['errMsgs'], $formTopViewErrMsgs);
         $page->data['UserDataFormPasswordView']['errMsgs'] = array_merge($page->data['UserDataFormPasswordView']['errMsgs'], $formPasswordViewErrMsgs);
         $page->data['UserDataFormMiddleView']['errMsgs'] = array_merge($page->data['UserDataFormMiddleView']['errMsgs'], $formMiddleViewErrMsgs);
     }
     $page->showWithMenu();
 }
Пример #4
0
 public static function post()
 {
     if (isset($_POST['save'])) {
         $page = new Page();
         $page->data['title'] = 'Gebruiker hernieuwen';
         //Validate input
         $formTopViewErrMsgs = UserDataFormTopViewValidator::validate($_POST);
         $formMiddleViewErrMsgs = UserDataFormMiddleViewValidator::validate($_POST);
         //No error means we create a user and password salt
         if (empty($formTopViewErrMsgs) && empty($formMiddleViewErrMsgs)) {
             $newUser = new User();
             $newUser->userId = $_SESSION['Stippers']['RenewUser']['user']->userId;
             $newUser->email = $_POST['email'];
             $newUser->passwordHash = $_SESSION['Stippers']['RenewUser']['user']->passwordHash;
             $newUser->firstName = ucwords($_POST['first_name']);
             $newUser->lastName = ucwords($_POST['last_name']);
             $newUser->street = ucwords($_POST['street']);
             $newUser->houseNumber = $_POST['house_number'];
             $newUser->city = ucwords($_POST['city']);
             $newUser->postalCode = $_POST['postal_code'];
             $newUser->country = ucwords($_POST['country']);
             $newUser->phone = $_POST['phone'];
             $newUser->dateOfBirth = $_POST['date_of_birth'];
             $newUser->balance = $_SESSION['Stippers']['RenewUser']['user']->balance;
             $newUser->isAdmin = $_SESSION['Stippers']['RenewUser']['user']->isAdmin;
             $newUser->isHintManager = $_SESSION['Stippers']['RenewUser']['user']->isHintManager;
             $newUser->isUserManager = $_SESSION['Stippers']['RenewUser']['user']->isUserManager;
             $newUser->isBrowserManager = $_SESSION['Stippers']['RenewUser']['user']->isBrowserManager;
             $newUser->isMoneyManager = $_SESSION['Stippers']['RenewUser']['user']->isMoneyManager;
             $newUser->creationTime = $_SESSION['Stippers']['RenewUser']['user']->creationTime;
             //Renew the user
             try {
                 UserDB::renewMembership($_SESSION['Stippers']['RenewUser']['user'], $newUser, $_POST['card_number']);
                 $page->addView('addRenewUser/renewUser/SuccessfullyRenewedView');
                 //Send welcome mail
                 try {
                     $failedEmails = Email::sendEmails('WelcomeOldMember.html', 'JH DE Stip - Welkom', EmailConfig::FROM_ADDRESS, [$newUser], null);
                     //If failedEmails is not empty the mail was not sent
                     if (!empty($failedEmails)) {
                         $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan welkomstmail niet verzenden.';
                         $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
                     }
                 } catch (Exception $ex) {
                     $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan welkomstmail niet verzenden.';
                     $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
                 }
                 //Add money to user's card
                 try {
                     $executingBrowserName = BrowserDB::getBrowserById($_SESSION['Stippers']['browser']->browserId)->name;
                     $trans = new MoneyTransaction(null, $newUser->userId, $newUser->balance, AddOrRenewUserConfig::NEW_OR_RENEWED_USER_BONUS, 0, 0, true, null, $executingBrowserName, null);
                     MoneyTransactionDB::addTransaction($newUser, $trans);
                 } catch (Exception $ex) {
                     if (isset($page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'])) {
                         $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] .= ' Kan het saldo van het account niet verhogen, probeer dit handmatig te doen.';
                     } else {
                         $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan het saldo van het account niet verhogen, probeer dit handmatig te doen.';
                     }
                     $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
                 }
             } catch (UserDBException $ex) {
                 if ($ex->getCode() == UserDBException::USERALREADYMEMBER) {
                     $page->addView('addRenewUser/renewUser/UserAlreadyMemberView');
                 } elseif ($ex->getCode() == UserDBException::USEROUTOFDATE) {
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorTitle'] = 'Gebruiker niet hernieuwd';
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['errorDescription'] = 'Iemand anders heeft de gebruiker in tussentijd al gewijzigd.';
                     $page->data['ErrorMessageWithDescriptionWithLinkView']['tryAgainUrl'] = $_SERVER['REQUEST_URI'];
                     $page->addView('error/ErrorMessageWithDescriptionWithLinkView');
                 } else {
                     RenewUserController::buildRenewUserPage($page, true);
                     if ($ex->getCode() == UserDBException::EMAILALREADYEXISTS) {
                         $page->data['UserDataFormTopView']['errMsgs']['global'] = '<h2 class="error_message" id="user_data_form_error_message">Dit e-mailadres is al in gebruik.</h2>';
                     } elseif ($ex->getCode() == UserDBException::CARDALREADYUSED) {
                         $page->data['UserDataFormTopView']['errMsgs']['global'] = '<h2 class="error_message" id="user_data_form_error_message">Dit kaartnummer is al in gebruik.</h2>';
                     } else {
                         $page->data['UserDataFormTopView']['errMsgs']['global'] = '<h2 class="error_message" id="user_data_form_error_message">Kan gebruiker niet hernieuwen, probeer het opnieuw.</h2>';
                     }
                 }
             } catch (Exception $ex) {
                 RenewUserController::buildRenewUserPage($page, true);
                 $page->data['UserDataFormTopView']['errMsgs']['global'] = '<h2 class="error_message" id="user_data_form_error_message">Kan gebruiker niet hernieuwen, probeer het opnieuw.</h2>';
             }
         } else {
             RenewUserController::buildRenewUserPage($page, true);
             $page->data['UserDataFormTopView']['errMsgs'] = array_merge($page->data['UserDataFormTopView']['errMsgs'], $formTopViewErrMsgs);
             $page->data['UserDataFormMiddleView']['errMsgs'] = array_merge($page->data['UserDataFormMiddleView']['errMsgs'], $formMiddleViewErrMsgs);
         }
         $page->showWithMenu();
     } else {
         header('Location: renewusersearch', true, 303);
     }
 }
Пример #5
0
 public static function post()
 {
     $page = new Page();
     $page->data['title'] = 'Inchecken';
     $errMsgs = CheckInFormViewValidator::validate($_POST);
     $user = null;
     if (empty($errMsgs)) {
         $checkInOk = false;
         $weeklyWinnerOk = true;
         //Get user to check in
         try {
             //Get the user who's card number for this year was entered
             $user = UserDB::getBasicUserByCardNumber($_POST['card_number']);
         } catch (Exception $ex) {
             //Check-in failed (can't get user)
             CheckInController::buildCheckInFormView($page, true);
             $page->data['CheckInFormView']['errMsgs']['global'] = '<h2 class="error_message" id="check_in_form_error_message">Kan gebruiker niet inchecken, probeer het opnieuw.</h2>';
             $page->showWithMenu();
             exit;
         }
         if (!$user) {
             //There's no user for this card
             CheckInController::buildCheckInFormView($page, true);
             $page->data['CheckInFormView']['errMsgs']['global'] = '<h2 class="error_message" id="check_in_form_error_message">Dit kaartnummer is niet gekoppeld aan een gebruiker.</h2>';
             $page->showWithMenu();
             exit;
         } else {
             //Check user in
             try {
                 $checkInOk = CheckInDB::checkIn($user->userId);
             } catch (Exception $ex) {
                 //Check-in failed (something went wrong or check-in isn't valid)
                 CheckInController::buildCheckInFormView($page, true);
                 $page->data['CheckInFormView']['errMsgs']['global'] = '<h2 class="error_message" id="check_in_form_error_message">Kan gebruiker niet inchecken, probeer het opnieuw.</h2>';
                 $page->showWithMenu();
                 exit;
             }
         }
         if (!$checkInOk) {
             //The user has already checked in
             CheckInController::buildCheckInFormView($page, true);
             $page->data['CheckInFormView']['errMsgs']['global'] = '<h2 class="error_message" id="check_in_form_error_message">Deze gebruiker is de voorbije 12 uur al ingechecked.</h2>';
             $page->showWithMenu();
             exit;
         } else {
             //Check in successful, check whether he is the winner of the week
             $isWinner = false;
             try {
                 //Check if this user is the winner of the week
                 $weeklyWinnerData = WeeklyWinnerDB::getThisWeeksWinnerData();
                 $isWinner = $weeklyWinnerData && $weeklyWinnerData->userId == $user->userId && !$weeklyWinnerData->hasCollectedPrize;
                 //If he is the winner we set in the database that the user collected his prize
                 if ($isWinner) {
                     $newWeeklyWinnerData = new WeeklyWinnerData($weeklyWinnerData->startOfWeek, $weeklyWinnerData->userId, true);
                     WeeklyWinnerDB::updateWeeklyWinnerData($weeklyWinnerData, $newWeeklyWinnerData);
                 }
             } catch (Exception $ex) {
                 $weeklyWinnerOk = false;
             }
             //If he is the winner, add the winner views and try to send an email to all usermanagers
             if ($isWinner) {
                 $page->addView('checkIn/CheckInWeeklyWinnerTitleView');
                 CheckInController::buildCheckInSuccessfulView($page, $user);
                 try {
                     $select = array('email' => true);
                     $searchFilter = array('isUserManager' => true);
                     $searchUsers = UserDB::getSearchUsers($select, $searchFilter, null);
                     $extras['common']['winnerFirstName'] = $user->firstName;
                     $extras['common']['winnerLastName'] = $user->lastName;
                     $failedAddresses = Email::sendEmails('WeeklyWinnerNotification.html', 'Winnaar van de week', EmailConfig::FROM_ADDRESS, array_column($searchUsers, 'user'), $extras);
                     if (!empty($failedAddresses)) {
                         $page->data['ErrorMessageWithDescriptionNoLinkView']['errorTitle'] = 'Kan e-mail niet versturen.';
                         $page->data['ErrorMessageWithDescriptionNoLinkView']['description'] = 'Kan geen e-mail versturen naar het bestuur om te laten weten dat je gewonnen hebt. Meld dit even aan een tapper of bestuurslid.';
                         $page->addView('error/ErrorMessageWithDescriptionNoLinkView');
                     }
                 } catch (Exception $ex) {
                     $page->data['ErrorMessageWithDescriptionNoLinkView']['errorTitle'] = 'Kan e-mail niet versturen.';
                     $page->data['ErrorMessageWithDescriptionNoLinkView']['errorDescription'] = 'Kan geen e-mail versturen naar het bestuur om te laten weten dat je gewonnen hebt. Meld dit even aan een tapper of bestuurslid.';
                     $page->addView('error/ErrorMessageWithDescriptionNoLinkView');
                 }
                 $page->addView('checkIn/CheckInWeeklyWinnerImageView');
                 $page->showWithMenu();
             } else {
                 $page->addView('checkIn/CheckInSuccessfulTitleView');
                 CheckInController::buildCheckInSuccessfulView($page, $user);
                 if (!$weeklyWinnerOk) {
                     $page->data['ErrorMessageNoDescriptionNoLinkView']['errorTitle'] = 'Kan niet controleren of je de winnaar van de week bent.';
                     $page->addView('error/ErrorMessageNoDescriptionNoLinkView');
                 } else {
                     $page->addExtraJsFile('views/checkIn/CheckInRedirector.js');
                     $page->addExtraJsFile('views/checkIn/checkInSuccessfulOnLoadHandler.js');
                 }
                 $page->showWithMenu();
             }
         }
     } else {
         //Errors in the form, retry
         CheckInController::buildCheckInFormView($page, true);
         $page->data['CheckInFormView']['errMsgs'] = array_merge($page->data['CheckInFormView']['errMsgs'], $errMsgs);
         $page->showWithMenu();
     }
 }
 public static function run()
 {
     try {
         //Create timestamps of start and end of week
         $fromTimeStamp = strtotime('monday last week ' . GlobalConfig::PHP_TIME_ZONE);
         $toTimeStamp = strtotime('monday this week ' . GlobalConfig::PHP_TIME_ZONE);
         //Get all gransactions for this week
         $transactions = MoneyTransactionDB::getTransactionsBetween($fromTimeStamp, $toTimeStamp);
         //Get total amount of money in the system right now
         $totalBalanceAfter = MoneyTransactionDB::getTotalBalance();
         //Get total amount of money added and removed during this week.
         $incrMoneyFromRealMoney = 0;
         $incrMoneyFromPrize = 0;
         $decrMoneyWithoutDiscount = 0;
         $decrMoneyWithDiscount = 0;
         foreach ($transactions as $transaction) {
             if ($transaction->isFromPrize()) {
                 $incrMoneyFromPrize += $transaction->getIncrMoney();
             } else {
                 $incrMoneyFromRealMoney += $transaction->getIncrMoney();
             }
             $decrMoneyWithoutDiscount += $transaction->getDecrMoney();
             $decrMoneyWithDiscount += $transaction->getDecrMoneyWithDiscount();
         }
         //Get total amount of money in the system before this week
         $totalBalanceBefore = $totalBalanceAfter - $incrMoneyFromRealMoney - $incrMoneyFromPrize + $decrMoneyWithDiscount;
         //Create from and to time strings
         $fromTime = new DateTime();
         $fromTime->setTimeZone(new DateTimeZone(GlobalConfig::PHP_TIME_ZONE));
         $fromTime->setTimeStamp($fromTimeStamp);
         $fromTime->setTimeZone(new DateTimeZone(GlobalConfig::PHP_TIME_ZONE));
         $fromDateString = $fromTime->format('d/m/y');
         $fromTimeString = $fromTime->format('d/m/y H:i:s');
         $toTime = new DateTime();
         $toTime->setTimeZone(new DateTimeZone(GlobalConfig::PHP_TIME_ZONE));
         $toTime->setTimeStamp($toTimeStamp);
         //Subtract 1 second to display the correct date.
         $toTime = date_sub($toTime, new DateInterval('PT1S'));
         $toDateString = $toTime->format('d/m/y');
         $toTimeString = $toTime->format('d/m/y H:i:s');
         //Create array with date to show in the email
         $emailExtras['common']['fromDate'] = $fromDateString;
         $emailExtras['common']['toDate'] = $toDateString;
         $emailExtras['common']['fromTime'] = $fromTimeString;
         $emailExtras['common']['toTime'] = $toTimeString;
         $emailExtras['common']['totalBalanceBefore'] = $totalBalanceBefore / 100;
         $emailExtras['common']['incrMoneyFromRealMoney'] = $incrMoneyFromRealMoney / 100;
         $emailExtras['common']['incrMoneyFromPrize'] = $incrMoneyFromPrize / 100;
         $emailExtras['common']['decrMoneyWithoutDiscount'] = $decrMoneyWithoutDiscount / 100;
         $emailExtras['common']['decrMoneyWithDiscount'] = $decrMoneyWithDiscount / 100;
         $emailExtras['common']['totalBalanceAfter'] = $totalBalanceAfter / 100;
         //Create fake users to send email to addresses
         $users = array();
         foreach (BalandeSummaryEmailSenderConfig::EMAIL_ADDRESSES as $emailAddress) {
             $user = new User();
             $user->email = $emailAddress;
             array_push($users, $user);
         }
         //Send email
         Email::sendEmails('MoneyOverview.html', 'Saldo lidkaarten ' . $fromDateString . ' - ' . $toDateString, '*****@*****.**', $users, $emailExtras);
     } catch (Exception $ex) {
         var_dump($ex);
     }
 }
Пример #7
0
 public static function post()
 {
     //Get the request body as json
     $checkInRequest = json_decode(file_get_contents('php://input'));
     //Check if the json was valid and a card number is given
     if (!$checkInRequest || !isset($checkInRequest->cardNumber)) {
         header('HTTP/1.1 400 Bad Request');
     } else {
         //Create response object
         $response = new APICheckInResponse();
         //Check if the card number is valid
         if (!CheckInController::validateCardNumber($checkInRequest->cardNumber)) {
             $response->errorCode = APICheckInResponse::MALFORMED_CARDNUMBER;
             echo json_encode($response);
             exit;
         } else {
             $user = null;
             $checkInOk = false;
             $weeklyWinnerOk = true;
             //Get user to check in
             try {
                 //Get the user who's card number for this year was entered
                 $user = UserDB::getBasicUserByCardNumber($checkInRequest->cardNumber);
             } catch (Exception $ex) {
                 $response->errorCode = APICheckInResponse::CANNOT_GET_USER_DATA;
                 echo json_encode($response);
                 exit;
             }
             if (!$user) {
                 //There's no user for this card
                 $response->errorCode = APICheckInResponse::NO_USER_FOR_CARD_NUMBER;
                 echo json_encode($response);
                 exit;
             } else {
                 //We have a user so get the names in the response
                 $response->userFirstName = $user->firstName;
                 $response->userLastName = $user->lastName;
                 //Check user in
                 try {
                     $checkInOk = CheckInDB::checkIn($user->userId);
                 } catch (Exception $ex) {
                     //Check-in failed (something went wrong or check-in isn't valid)
                     $response->errorCode = APICheckInResponse::CANNOT_CHECK_IN;
                     echo json_encode($response);
                     exit;
                 }
             }
             if (!$checkInOk) {
                 //The user has already checked in
                 $response->errorCode = APICheckInResponse::ALREADY_CHECKED_IN;
                 echo json_encode($response);
                 exit;
             } else {
                 $response->checkInSuccessful = true;
                 //Check in successful, check whether he is the winner of the week
                 $isWinner = false;
                 try {
                     //Check if this user is the winner of the week
                     $weeklyWinnerData = WeeklyWinnerDB::getThisWeeksWinnerData();
                     $isWinner = $weeklyWinnerData && $weeklyWinnerData->userId == $user->userId && !$weeklyWinnerData->hasCollectedPrize;
                     //If he is the winner we set in the database that the user collected his prize
                     if ($isWinner) {
                         $newWeeklyWinnerData = new WeeklyWinnerData($weeklyWinnerData->startOfWeek, $weeklyWinnerData->userId, true);
                         WeeklyWinnerDB::updateWeeklyWinnerData($weeklyWinnerData, $newWeeklyWinnerData);
                     }
                 } catch (Exception $ex) {
                     $response->errorCode = APICheckInResponse::CANNOT_CHECK_WEEKLY_WINNER;
                     echo json_encode($response);
                     exit;
                 }
                 $response->isWeeklyWinner = $isWinner;
                 //If he is the winner, add the winner views and try to send an email to all usermanagers
                 if ($isWinner) {
                     try {
                         $select = array('email' => true);
                         $searchFilter = array('isUserManager' => true);
                         $searchUsers = UserDB::getSearchUsers($select, $searchFilter, null);
                         $extras['common']['winnerFirstName'] = $user->firstName;
                         $extras['common']['winnerLastName'] = $user->lastName;
                         $failedAddresses = Email::sendEmails('WeeklyWinnerNotification.html', 'Winnaar van de week', EmailConfig::FROM_ADDRESS, array_column($searchUsers, 'user'), $extras);
                         if (!empty($failedAddresses)) {
                             $response->errorCode = APICheckInResponse::CANNOT_SEND_WINNER_NOTIFICATIONS;
                         }
                         echo json_encode($response);
                         exit;
                     } catch (Exception $ex) {
                         $response->errorCode = APICheckInResponse::CANNOT_SEND_WINNER_NOTIFICATIONS;
                         echo json_encode($response);
                         exit;
                     }
                 } else {
                     echo json_encode($response);
                     exit;
                 }
             }
         }
     }
 }