예제 #1
0
 public function approveRegistration(Request $request, $id)
 {
     $employeeRepository = $this->getEmployeeRepository();
     if (is_null($employeeRepository->getEmployeeById($id))) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_EMPLOYEE_ID);
     }
     if ($employeeRepository->approveRegistration($id)) {
         return new JsonResponse(array('success' => true));
     } else {
         return JsonErrorResponse::fromKey(JsonErrorResponse::UNEXPECTED_ERROR);
     }
 }
예제 #2
0
 public function generateTanPdf(Customer $customer, $password)
 {
     $tanRepository = $this->getTanRepository();
     $tans = array();
     for ($i = 0; $i < self::NUMBER_OF_INIT_TANS; $i++) {
         $tan = Tan::generate($customer->id);
         if ($tanRepository->saveTan($tan)) {
             $tans[] = $tan;
         }
     }
     $tans = array_map(function ($tan) {
         return $tan->value;
     }, $tans);
     function wrapWithWhitespace($str, $length)
     {
         $neededPadding = $length - strlen($str);
         $front = floor($neededPadding / 2) > 0 ? floor($neededPadding / 2) : 0;
         $back = ceil($neededPadding / 2) > 0 ? ceil($neededPadding / 2) : 0;
         $str = str_repeat(" ", $front) . $str . str_repeat(" ", $back);
         return substr($str, 0, $length);
     }
     try {
         $p = new \PDFlib();
         if ($p->begin_document("", "") == 0) {
             die("Error: " . $p->get_errmsg());
         }
         $p->set_info("Creator", "SitzBank");
         $p->set_info("Author", "SitzBank App");
         $p->set_info("Title", "Tans for {$customer->firstname} {$customer->lastname}");
         $p->set_parameter("textformat", "utf8");
         $p->begin_page_ext(595, 842, "");
         $font = $p->load_font("Helvetica-Bold", "winansi", "");
         $p->setfont($font, 18.0);
         $p->set_text_pos(25, 780);
         $p->show("Tans for {$customer->firstname} {$customer->lastname}");
         $font = $p->load_font("Courier", "winansi", "");
         $p->setfont($font, 9.0);
         $p->set_text_pos(20, 750);
         $p->show(str_repeat("-", 100));
         $tansPerRow = 4;
         for ($i = 0; $i < count($tans); $i += $tansPerRow) {
             $limit = min($i + $tansPerRow, count($tans));
             $row = array_slice($tans, $i, $limit);
             $row = array_map(function ($str) {
                 return wrapWithWhitespace($str, 25);
             }, $row);
             $p->continue_text(implode('|', $row));
         }
         $p->continue_text(str_repeat("-", 100));
         $p->end_page_ext("");
         $p->end_document("");
         $buf = $p->get_buffer();
     } catch (\Exception $e) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::UNEXPECTED_ERROR);
     }
     $temp_file = tempnam(sys_get_temp_dir(), 'SBTanPdf');
     file_put_contents($temp_file, $buf);
     $temp_file_output = $temp_file . "-pw";
     if (in_array(strtoupper(substr(PHP_OS, 0, 3)), array('DAR', 'WIN'))) {
         shell_exec("cp {$temp_file} {$temp_file_output}");
     } else {
         shell_exec("/usr/bin/pdftk {$temp_file} output {$temp_file_output} user_pw {$password}");
     }
     return $temp_file_output;
 }
예제 #3
0
 public function customerTransactionsPdf(Request $request, $id)
 {
     $transactionRepository = $this->getTransactionRepository();
     $customerRepository = $this->getCustomerRepository();
     $transactions = $transactionRepository->getCustomerTransactions($id);
     $customer = $customerRepository->getCustomerById($id);
     if (is_null($customer)) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_CUSTOMER_ID);
     }
     //add customer data
     foreach ($transactions as $trans) {
         $trans->from_customer = $customerRepository->getCustomerById($trans->from_id);
         $trans->to_customer = $customerRepository->getCustomerById($trans->to_id);
     }
     function wrapWithWhitespace($str, $length)
     {
         $neededPadding = $length - strlen($str);
         $front = floor($neededPadding / 2) > 0 ? floor($neededPadding / 2) : 0;
         $back = ceil($neededPadding / 2) > 0 ? ceil($neededPadding / 2) : 0;
         $str = str_repeat(" ", $front) . $str . str_repeat(" ", $back);
         return substr($str, 0, $length);
     }
     try {
         $p = new \PDFlib();
         if ($p->begin_document("", "") == 0) {
             die("Error: " . $p->get_errmsg());
         }
         $p->set_info("Creator", "SitzBank");
         $p->set_info("Author", "SitzBank App");
         $p->set_info("Title", "Transactions for {$customer->firstname} {$customer->lastname}");
         $p->set_parameter("textformat", "utf8");
         $p->begin_page_ext(595, 842, "");
         $font = $p->load_font("Helvetica-Bold", "winansi", "");
         $p->setfont($font, 18.0);
         $p->set_text_pos(25, 780);
         $p->show("Transactions for {$customer->firstname} {$customer->lastname}");
         $font = $p->load_font("Courier", "winansi", "");
         $p->setfont($font, 9.0);
         $p->set_text_pos(20, 750);
         $p->show(str_repeat("-", 100));
         $header = array('Time', 'From', 'To', 'Amount', 'Status');
         $header = array_map(function ($str) {
             return wrapWithWhitespace($str, 19);
         }, $header);
         $p->continue_text(implode('|', $header));
         foreach ($transactions as $trans) {
             $p->continue_text(str_repeat("-", 100));
             $row = array($trans->timestamp, $trans->from_customer->firstname . ' ' . $trans->from_customer->lastname, $trans->to_customer->firstname . ' ' . $trans->to_customer->lastname, $trans->amount, $trans->status);
             $row = array_map(function ($str) {
                 return wrapWithWhitespace($str, 19);
             }, $row);
             $p->continue_text(implode('|', $row));
             $p->continue_text("Description: {$trans->description}");
         }
         $p->continue_text(str_repeat("=", 100));
         $p->continue_text(str_repeat(" ", 100));
         $p->setfont($font, 12.0);
         $p->continue_text("Balance: " . $customerRepository->getCustomerBalance($customer->id));
         $p->end_page_ext("");
         $p->end_document("");
         $buf = $p->get_buffer();
         $len = strlen($buf);
     } catch (\Exception $e) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::UNEXPECTED_ERROR);
     }
     header("Content-type: application/pdf");
     header("Content-Length: {$len}");
     header("Content-Disposition: inline; filename=transactions.pdf");
     return $buf;
 }
 public function isAuthorizedForRoute(Request $request, Route $route, $params)
 {
     if (is_null($route->tokenLevel) || count($route->tokenLevel) == 0) {
         return true;
     }
     $authorization = explode(' ', $request->headers['AUTHORIZATION']);
     if (count($authorization) != 2 || strlen($authorization[1]) != 32) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_TOKEN);
     }
     $value = $authorization[1];
     $token = $this->getTokenRepository()->getToken($value);
     if (is_null($token)) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_TOKEN);
     }
     if ($token->ip !== $request->getClientIp()) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::INVALID_TOKEN);
     }
     if ($token->scope === 'level1' && !is_null($token->customerId) && isset($params['id']) && $params['id'] != $token->customerId) {
         return JsonErrorResponse::fromKey(JsonErrorResponse::UNAUTHORIZED_REQUEST);
     }
     if (in_array($token->scope, $route->tokenLevel)) {
         return true;
     }
     return JsonErrorResponse::fromKey(JsonErrorResponse::UNAUTHORIZED_REQUEST);
 }