function process($parameters)
 {
     $registration = new Registration();
     if ($registration->checkLogin()) {
         $this->redirect('error');
     }
     //catch registration (button is pressed)
     if (isset($_POST['sent'])) {
         $data = $registration->sanitize(['email' => $_POST['email'], 'tariff' => $_POST['tariff'], 'firstname' => $_POST['firstname'], 'surname' => $_POST['surname'], 'telephone' => $_POST['telephone'], 'address' => $_POST['address'], 'startDate' => $_POST['startDate'], 'ic' => $_POST['ic'], 'p' => $_POST['p']]);
         $this->data = $data;
         //for autofilling from previous page
         $result = $registration->validateData($data);
         if ($result['s'] == 'success') {
             $fakturoid = new FakturoidWrapper();
             $newCustomer = $fakturoid->createCustomer($data);
             if ($newCustomer == false) {
                 $result = ['s' => 'error', 'cs' => 'Bohužel se nepovedlo uložit data do Faktuoidu; zkus to prosím za pár minut', 'en' => 'Sorry, we didn\'n safe your data into Fakturoid; try it again after a couple of minutes please'];
             } else {
                 //add fakturoid_id into data structure
                 $data['fakturoid_id'] = $newCustomer->id;
                 $result = $registration->registerUser($data, $this->language);
             }
         }
         $this->messages[] = $result;
         //if register success, show registration form no more
         if ($result['s'] == 'success') {
             $this->redirect('');
         }
     }
     $this->header['title'] = ['cs' => 'Registrace nového uživatele', 'en' => 'New user registration'];
     $this->data['tariffs'] = $registration->returnTariffsData($this->language);
     $this->view = 'registration';
 }
 function process($parameters)
 {
     $registration = new Registration();
     if (!$registration->checkIfAdmin($_SESSION['id_user'])) {
         $this->redirect('error');
     }
     //catch registration (button is pressed)
     if (isset($_POST['sent'])) {
         $data = $registration->sanitize(["email" => $_POST['email'], "tariff" => $_POST['tariff'], "firstname" => $_POST['firstname'], "surname" => $_POST['surname'], "telephone" => $_POST['telephone'], 'address' => $_POST['address'], "startDate" => $_POST['startDate'], "ic" => $_POST['ic'], "p" => $registration->getRandomHash()]);
         $this->data = $data;
         //for autofilling from previous page
         $result = $registration->validateData($data);
         if ($result['s'] == 'success') {
             $fakturoid = new FakturoidWrapper();
             $newCustomer = $fakturoid->createCustomer($data);
             if ($newCustomer == false) {
                 $result = ['s' => 'error', 'cs' => 'Bohužel se nepovedlo uložit data do Faktuoidu; zkus to prosím za pár minut', 'en' => 'Sorry, we didn\'n safe your data into Fakturoid; try it again after a couple of minutes please'];
             } else {
                 //add fakturoid_id into data structure
                 $data['fakturoid_id'] = $newCustomer->id;
                 $result = $registration->registerUser($data, $this->language);
             }
         }
         //change success message for admin
         if ($result['s'] == 'success') {
             $result = ['s' => 'success', 'cs' => 'Nový uživatel je úspěšně zaregistrován', 'en' => 'New member is successfully registred'];
         }
         $this->messages[] = $result;
     }
     $this->header['title'] = ['cs' => 'Registrace nového uživatele', 'en' => 'Registration of new user'];
     $this->data['tariffs'] = $registration->returnTariffsData($this->language);
     $this->view = 'forceRegistration';
 }
 function process($parameters)
 {
     $bitcoinPay = new Bitcoinpay();
     if (!$bitcoinPay->checkLogin()) {
         $this->redirect('error');
     }
     $paymentId = false;
     if (is_numeric($parameters[0])) {
         $paymentId = $parameters[0];
     } else {
         $this->redirect('error');
     }
     //allow delete only for admin
     $paymentUserId = $bitcoinPay->getPaymentUserId($paymentId);
     if (!$bitcoinPay->checkIfIsAdminOfUser($_SESSION['id_user'], $paymentUserId)) {
         $this->redirect('error');
     }
     //disable delete invoice, which is already payed
     $fakturoid = new FakturoidWrapper();
     $paymentFakturoidId = $fakturoid->getFakturoidInvoiceIdFromPaymentId($paymentId);
     $fakturoid->cancelInvoice($paymentFakturoidId);
     //TODO disable delete for already payed invoices
     $result = $bitcoinPay->deletePayment($paymentId);
     $this->messages[] = $result;
     //navigate to default view for this action
     $this->redirect('checkUsers');
 }
 function process($parameters)
 {
     $changePersonals = new ChangePersonals();
     if (!$changePersonals->checkLogin()) {
         $this->redirect('error');
     }
     //if empty parameter, add the current user
     if (isset($parameters[0])) {
         $userId = $parameters[0];
     } else {
         $userId = $_SESSION['id_user'];
     }
     //if not admin of the right place, throw error
     if ($userId != $_SESSION['id_user'] && !$changePersonals->checkIfIsAdminOfUser($_SESSION['id_user'], $userId)) {
         $this->redirect('error');
     }
     //if form is sent
     if (isset($_POST['sent'])) {
         $data = $changePersonals->sanitize(['firstname' => $_POST['firstname'], 'surname' => $_POST['surname'], 'telephone' => $_POST['telephone'], 'address' => $_POST['address'], 'ic' => $_POST['ic'], 'p' => $_POST['p'], 'csrf' => $_POST['csrf']]);
         if (!Csrf::validateCsrfRequest($data['csrf'])) {
             $this->messages[] = ['s' => 'error', 'cs' => 'Možný CSRF útok! Zkuste prosím změnit údaje znovu', 'en' => 'Possible CSRF attack! Please try to change your personals again'];
         } else {
             $result = $changePersonals->validateData($data);
             if ($result['s'] == 'success') {
                 $fakturoid = new FakturoidWrapper();
                 //add fakturoid_id into data
                 $data['fakturoid_id'] = $fakturoid->getFakturoidIdFromUserId($userId);
                 if ($fakturoid->updateCustomer($data) == false) {
                     $result = ['s' => 'error', 'cs' => 'Bohužel se nepovedlo uložit data do Faktuoidu; zkus to prosím za pár minut', 'en' => 'Sorry, we didn\'n safe your data into Fakturoid; try it again after a couple of minutes please'];
                 } else {
                     $result = $changePersonals->changePersonalData($data, $userId);
                 }
             }
             $this->messages[] = $result;
         }
     }
     //data for form
     $userData = $changePersonals->getUserData($userId);
     $this->data = $userData['user'];
     $this->data['csrf'] = Csrf::getCsrfToken();
     $this->header['title'] = ['cs' => 'Změna osobních údajů', 'en' => 'Change personal information'];
     $this->view = 'changePersonals';
 }
 function process($parameters)
 {
     $fakturoid = new FakturoidWrapper();
     if (!$fakturoid->checkLogin()) {
         $this->redirect('error');
     }
     $fakturoidInvoiceId = null;
     if (isset($parameters[0])) {
         $fakturoidInvoiceId = $parameters[0];
     } else {
         $this->redirect('error');
     }
     $userOfInvoice = $fakturoid->getUserIdFromInvoiceId($fakturoidInvoiceId);
     //if not admin of the right place then throw error
     if ($userOfInvoice != $_SESSION['id_user'] && !$fakturoid->checkIfIsAdminOfUser($_SESSION['id_user'], $userOfInvoice)) {
         $this->redirect('error');
     }
     $pdf = $fakturoid->getInvoiceAsPdf($fakturoidInvoiceId);
     $this->displayPdf($pdf);
 }
 function process($parameters)
 {
     $extras = new Extras();
     $fakturoid = new FakturoidWrapper();
     $action = $extras->sanitize($parameters[0]);
     switch ($action) {
         case 'add':
             $paymentId = $extras->sanitize($_POST['paymentId']);
             $price = $extras->sanitize($_POST['price']);
             $description = $extras->sanitize($_POST['description']);
             $result = $extras->checkAddValues($paymentId, $price, $description);
             if ($result['s'] == 'success') {
                 $status = $extras->getStatusOfPayment($paymentId);
                 //allow add extra only when new payment will be generated
                 if (!in_array($status, ['unpaid', 'refund', 'timeout'])) {
                     $this->messages[] = ['s' => 'error', 'cs' => 'Bohužel, položka nebyla přidána; platba se právě platí nebo je již zaplacená', 'en' => 'Sorry, we cannot add an extra; payment is processing'];
                 } else {
                     $invoiceFakturoidId = $fakturoid->getFakturoidInvoiceIdFromPaymentId($paymentId);
                     $extraFakturoidId = $fakturoid->addExtra($invoiceFakturoidId, $price, $description);
                     $result = $extras->addExtra($paymentId, $price, $description, $extraFakturoidId);
                     $this->messages[] = $result;
                 }
             }
             $this->redirect('checkUsers');
             break;
         case 'addBlank':
             $userId = $extras->sanitize($_POST['userId']);
             $price = $extras->sanitize($_POST['price']);
             $description = $extras->sanitize($_POST['description']);
             $result = $extras->checkAddBlankValues($userId, $price, $description);
             if ($result['s'] == 'success') {
                 $this->messages[] = $extras->addBlankExtra($userId, $price, $description);
             } else {
                 $this->messages[] = $result;
             }
             $this->redirect('checkUsers');
             break;
         case 'delete':
             $extraId = $parameters[1];
             $status = $extras->getStatusOfPaymentFromExtraId($extraId);
             //allow add extra only when new payment will be generated or is blank
             if (!in_array($status, ['unpaid', 'refund', 'timeout', null])) {
                 $this->messages[] = ['s' => 'error', 'cs' => 'Bohužel, položka nebyla zrušena; platba se právě platí nebo je již zaplacená', 'en' => 'Sorry, we cannot cancel an extra; payment is processing'];
             } else {
                 $extraFakturoidId = $fakturoid->getExtraFakturoidId($extraId);
                 $invoiceFakturoidId = $fakturoid->getInvoiceFakturoidIdFromExtraId($extraId);
                 $fakturoid->deleteExtra($invoiceFakturoidId, $extraFakturoidId);
                 $result = $extras->deleteExtra($extraId);
                 $this->messages[] = $result;
             }
             $this->redirect('checkUsers');
             break;
         default:
             $this->redirect('error');
     }
 }
Exemple #7
0
    private function createPayment($user, $tariff, $beginningDate, $lang)
    {
        $userId = $user['id_user'];
        $tariffId = $tariff['id_tariff'];
        $tariffName = $this->getTariffName($tariffId, 'cs');
        //invoice is in czech only
        $priceCZK = $tariff['priceCZK'];
        $fakturoid = new FakturoidWrapper();
        $fakturoidInvoice = $fakturoid->createInvoice($user, $tariff['priceCZK'], $tariffName, $beginningDate, $lang);
        if (!$fakturoidInvoice) {
            return ['s' => 'error', 'cs' => 'Nepovedlo se spojení s fakturoid.cz. Zkuste to prosím za pár minut', 'en' => 'We are unable to connect to fakturoid.cz. Try again in a few minutes'];
        }
        $fakturoidInvoiceId = $fakturoidInvoice->id;
        $fakturoidInvoiceNumber = $fakturoidInvoice->number;
        $now = date('Y-m-d H-i-s');
        Db::queryModify('
			INSERT INTO `payments` (
				`id_payer`, 
				`payment_first_date`, 
				`status`, 
				`time_generated`, 
				`tariff_id`,
				`price_CZK`, 
				`invoice_fakturoid_id`, 
				`invoice_fakturoid_number`
		  	) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [$userId, date('Y-m-d', $beginningDate), 'unpaid', $now, $tariffId, $priceCZK, $fakturoidInvoiceId, $fakturoidInvoiceNumber]);
        //add blank extras
        $extras = new Extras();
        $blankExtras = $extras->getBlankExtras($user['id_user']);
        if (!empty($blankExtras)) {
            foreach ($blankExtras as $extra) {
                $extraId = $extra['id_extra'];
                $price = $extra['priceCZK'];
                $description = $extra['description'];
                $fakturoidExtraId = $fakturoid->addExtra($fakturoidInvoiceId, $extra['priceCZK'], $extra['description']);
                $paymentId = $this->getPaymentIdFromFakturoidInvoiceId($fakturoidInvoiceId);
                $extras->assignBlankExtra($paymentId, $price, $description, $fakturoidExtraId, $extraId);
            }
        }
        //send email to user
        $subject = NAME . ' Paralelní Polis - nová faktura';
        $link = ROOT . '/cs/payments';
        $message = 'Ahoj,<br/>
<br/>
vystavili jsem ti fakturu za členství / pronájem v Paper Hub v Paralelní Polis.<br/>
<a href="' . $link . '">' . $link . '</a><br/>
Platbu uhradíš jednoduše na odkazu výše.<br/> 
<br/>
Díky za rychlou platbu!<br/>
Paper Hub';
        $this->sendEmail(EMAIL, $user['email'], $subject, $message);
        //and send copy of email to hub manager
        //TODO refractor
        $this->sendEmail(EMAIL, EMAIL_HUB_MANAGER, NAME . ' - Poslána výzva o nové faktuře na email ' . $user['email'], $message);
        return ['s' => 'success'];
    }
Exemple #8
0
    private function createPayment($user, $tariff, $beginningDate, $lang)
    {
        $userId = $user['id_user'];
        $tariffId = $tariff['id_tariff'];
        $tariffName = $this->getTariffName($tariffId, $lang);
        $priceCZK = $tariff['priceCZK'];
        $fakturoid = new FakturoidWrapper();
        $fakturoidInvoice = $fakturoid->createInvoice($user, $tariff['priceCZK'], $tariffName, $beginningDate);
        if (!$fakturoidInvoice) {
            return ['s' => 'error', 'cs' => 'Nepovedlo se spojení s fakturoid.cz. Zkuste to prosím za pár minut', 'en' => 'We cannot connect into fakturoid.cz. Try it again in a few minutes please'];
        }
        $fakturoidInvoiceId = $fakturoidInvoice->id;
        $fakturoidInvoiceNumber = $fakturoidInvoice->number;
        Db::queryModify('
			INSERT INTO `payments` (
				`id_payer`, 
				`payment_first_date`, 
				`status`, 
				`time_generated`, 
				`tariff_id`,
				`price_CZK`, 
				`invoice_fakturoid_id`, 
				`invoice_fakturoid_number`
		  	) VALUES (?, ?, ?, NOW(), ?, ?, ?, ?)', [$userId, $beginningDate, 'unpaid', $tariffId, $priceCZK, $fakturoidInvoiceId, $fakturoidInvoiceNumber]);
        return ['s' => 'success'];
    }