PageRenderTime 110ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/projekty/oberza/libs/model/indexModel.php

https://bitbucket.org/adamnow/adamnow.bitbucket.io
PHP | 214 lines | 164 code | 37 blank | 13 comment | 35 complexity | 44c5c7e099e0229e95ef2abbfbde688c MD5 | raw file
  1. <?php
  2. class indexModel extends Model {
  3. function index() {
  4. // var_dump( "Model" );
  5. }
  6. function widok() {
  7. $this->data['Title'] = ' - Home';
  8. $this->data['ogTitle'] = 'Aparthotel Oberża. Poczuj się jak w domu.';
  9. $this->data['Description'] = 'Aparthotel w centrum Krakowa o charakterze butikowym, polecany przez Michelin. Profesjonalna obsługa, doskonała restauracja.';
  10. $this->data['ogDescription'] = 'Aparthotel w centrum Krakowa o charakterze butikowym, polecany przez Michelin. Profesjonalna obsługa, doskonała restauracja.';
  11. $this->data['Keywords'] = 'hotel Kraków aparthotel Kraków, nocleg w Krakowie, pokoje , hotel butikowy, apartamenty kraków, pokoje, nocleg, noclegi, Kazimierz, boutique, pobyty, wczasy, urlop, weekend break Kraków, city break Kraków';
  12. $this->data['ogImage'] = '';
  13. if( Routing::$routing['param'] == 'pl' || Routing::$routing['param'] == 'en' ) {
  14. setcookie( COOKIE_LANG_NAME, Routing::$routing['param'], time()+157680000, '/' );
  15. header( "Location: " . BASE . Routing::$routing['controller'] . '/' . Routing::$routing['action'] );
  16. exit();
  17. }
  18. if( $_POST['send_secret'] == 1 ) {
  19. $email = $this->data['email'] = strip_tags( trim( $_POST['email'] ) );
  20. $start = $this->data['start'] = strip_tags( trim( $_POST['data-start'] ) );
  21. $stop = $this->data['stop'] = strip_tags( trim( $_POST['data-stop'] ) );
  22. if( !preg_match( "/@/" , $email ) ) {
  23. $this->data['error'] = $this->data['dictionary_page'][88][LANG];
  24. }
  25. if( !$this->data['error'] ) {
  26. $body = @file_get_contents( 'public/mail/mail.html' );
  27. $body = preg_replace( "/{{__CONTENT__}}/", $this->data['dictionary_page'][86][LANG], $body );
  28. $body = preg_replace( "/{{__BASE__}}/" , BASE, $body );
  29. $body = preg_replace( "/{{__FB__}}/", $this->data['dictionary_page'][91][LANG], $body );
  30. $body = preg_replace( "/{{__INSTA__}}/", $this->data['dictionary_page'][92][LANG], $body );
  31. $body = preg_replace( "/{{CTA}}/", '', $body );
  32. $mail = new PHPMailer();
  33. $mail->IsSMTP();
  34. // $mail->SMTPDebug = 2;
  35. $mail->SMTPAuth = true;
  36. $mail->Subject = $this->data['dictionary_page'][87][LANG];
  37. $mail->MsgHTML( $body );
  38. $mail->AddAddress( $email );
  39. if( !$mail->Send() ) {
  40. $this->data['error'] = $this->data['dictionary_page'][89][LANG];
  41. } else {
  42. $_SESSION[I_SUCCESS] = "Poprawnie wysłano wiadomosc";
  43. $nMail = new PHPMailer();
  44. $nMail->IsSMTP();
  45. $nMail->SMTPAuth = true;
  46. $nMail->Subject = "Nowe zgłoszenie Secret Deal";
  47. $nBody = @file_get_contents( 'public/mail/mail.html' );
  48. $txt = "Wpłynęło nowe zgłoszenie Secret Deal od:<br><br>";
  49. $txt .= "email: <strong>{$this->data['email']}</strong><br>";
  50. $txt .= "Data startu: <strong>{$this->data['start']}</strong><br>";
  51. $txt .= "Data zakończenia: <strong>{$this->data['stop']}</strong>";
  52. $nBody = preg_replace( "/{{__CONTENT__}}/", $txt, $nBody );
  53. $nBody = preg_replace( "/{{__BASE__}}/" , BASE, $nBody );
  54. $nBody = preg_replace( "/{{__FB__}}/", $this->data['dictionary_page'][91][LANG], $nBody );
  55. $nBody = preg_replace( "/{{__INSTA__}}/", $this->data['dictionary_page'][92][LANG], $nBody );
  56. $nBody = preg_replace( "/{{CTA}}/", '', $nBody );
  57. $nMail->MsgHTML( $nBody );
  58. $nMail->AddAddress( MAIL_FROM );
  59. $nMail->Send();
  60. header( "Location: " . BASE );
  61. exit();
  62. }
  63. }
  64. }
  65. }
  66. function admin() {
  67. $this->data['admin'] = true;
  68. if( Auth::ifAuth() ) {
  69. header( "Location: " . BASE . "admin" );
  70. exit();
  71. }
  72. if( Routing::$routing['param'] == 'pl' || Routing::$routing['param'] == 'en' ) {
  73. setcookie( COOKIE_LANG_NAME, Routing::$routing['param'], time()+157680000, '/' );
  74. header( "Location: " . BASE );
  75. exit();
  76. }
  77. if( $_POST['remind'] == 1 ) {
  78. $email = $_POST['email'];
  79. $sth = $this->pdo->prepare( "SELECT * FROM " . ADMIN_TABLE . " WHERE email = :email LIMIT 1" );
  80. $sth->execute( array( ':email' => $email ) );
  81. if( $sth->rowCount() > 0 ) {
  82. $this->data['u'] = $sth->fetch( PDO::FETCH_ASSOC );
  83. $token = $this->data['u']['token'];
  84. // $hashpass = substr( hash('sha512', rand()),0, 10 );
  85. // $newpass = sha1( $hashpass );
  86. // $token = sha1( $newpass . time() . $this->data['u']['id'] );
  87. // $sth = $this->pdo->prepare( "UPDATE uzytkownicy SET haslo = '{$newpass}', token = '{$token}' WHERE id = {$this->data['u']['id']}" );
  88. // $sth->execute();
  89. $l = $this->data['u']['lang'];
  90. $_SESSION[I_SUCCESS] = $this->data['dictionary'][136][$l];
  91. $mail = new PHPMailer();
  92. $body = file_get_contents( 'public/mailing/mailing.html' );
  93. $cta = BASE . "profil/haslo/" . $this->data['u']['id'] . "/" . $token;
  94. $body = preg_replace( "/{{CONTENT}}/" , $this->data['dictionary'][134][$l], $body );
  95. $body = preg_replace( "/{{LANG}}/" , $l, $body );
  96. $body = preg_replace( "/{{BASE}}/" , BASE, $body );
  97. $body = preg_replace( "/{{CTA}}/" , $cta, $body );
  98. $body = preg_replace( "/{{PREFIX}}/" , 'remind', $body );
  99. $body = preg_replace( "/{{ALT}}/" , $this->data['dictionary'][57][LANG], $body );
  100. $mail->IsSMTP();
  101. $mail->SMTPDebug = 0;
  102. $mail->SMTPAuth = true;
  103. $mail->Subject = $this->data['dictionary'][135][$l];
  104. $mail->MsgHTML($body);
  105. $mail->AddAddress( $this->data['u']['email'] );
  106. if( !$mail->Send() ) {
  107. echo "Mailer Error: " . $mail->ErrorInfo;
  108. }
  109. } else {
  110. $_SESSION[I_ERROR] = $this->data['dictionary'][6][LANG];
  111. }
  112. header("Location: " . BASE . Routing::$routing['controller']);
  113. exit();
  114. }
  115. if( $_POST['login-send'] == 1 ) {
  116. $login = ( $_POST['login'] ) ? trim( strip_tags( $_POST['login'] ) ) : null;
  117. $haslo = ( $_POST['haslo'] ) ? sha1( trim( strip_tags( $_POST['haslo'] ) ) ) : null;
  118. if( !$login )
  119. throw new modelException( $this->data['dictionary'][7][LANG], 4007 );
  120. if( !$haslo )
  121. throw new modelException( $this->data['dictionary'][8][LANG], 4008 );
  122. // $sth = $this->pdo->prepare( "SELECT *, DATE_FORMAT( ostatnie_logowanie, '%d-%m-%Y %H:%i') as ostatnie_logowanie_format FROM users WHERE email = :login AND haslo='{$haslo}' AND stat = '1' LIMIT 1" );
  123. $sth = $this->pdo->prepare( "SELECT *, DATE_FORMAT( ostatnie_logowanie, '%d-%m-%Y %H:%i') as ostatnie_logowanie_format FROM " . ADMIN_TABLE . " WHERE email = :login AND haslo='{$haslo}' AND stat = '1' LIMIT 1" );
  124. $sth->bindParam( ':login', $login, PDO::PARAM_STR );
  125. $sth->execute();
  126. $row = $sth->fetch();
  127. if( !$row )
  128. throw new modelException( $this->data['dictionary'][9][LANG], 4009 );
  129. if( $row['newsroom_klient_id'] != NULL ) {
  130. $sth = $this->pdo->prepare( "SELECT * FROM firmy WHERE stat = '1' AND id = {$row['newsroom_klient_id']} LIMIT 1" );
  131. $sth->execute();
  132. if( $sth->rowCount() < 1 )
  133. throw new modelException( $this->data['dictionary'][45][LANG], 4009 );
  134. }
  135. Auth::register( $row );
  136. $_SESSION[I_SUCCESS] = "Poprawnie zalogowano do panelu";
  137. // $sth = $this->pdo->prepare( "UPDATE " . ADMIN_TABLE . " SET ostatnie_logowanie = NOW(), pierwsze_logowanie = '1' WHERE id = {$row['id']}" );
  138. $sth = $this->pdo->prepare( "UPDATE " . ADMIN_TABLE . " SET ostatnie_logowanie = NOW() WHERE id = {$row['id']}" );
  139. $sth->execute();
  140. if( $row['pierwsze_logowanie'] == '0' ) {
  141. header( "Location: " . BASE . "profil/haslo/" . $row['id'] );
  142. exit();
  143. }
  144. if( $_SESSION['redirect'] && $_SESSION['redirect'] != BASE . 'konto/login' ) {
  145. header( "Location: " . $_SESSION['redirect'] );
  146. } else {
  147. header( "Location: " . BASE . "admin" );
  148. }
  149. $_SESSION['redirect'] = null;
  150. exit();
  151. }
  152. }
  153. function szukaj() {
  154. if( !$_GET['szukaj'] ) {
  155. $this->data['results'] = [];
  156. return;
  157. }
  158. $this->data['search'] = $search = strip_tags( trim( $_GET['szukaj'] ) );
  159. // szukam artykułów
  160. $sth = $this->pdo->prepare( "SELECT *, 'artykul' as _TYPE_LINK_ FROM artykuly WHERE stat = '1' AND (tytul_" . LANG . " REGEXP '{$search}' OR tresc_" . LANG . " REGEXP '{$search}')" );
  161. $sth->execute();
  162. $this->data['aktualnosci'] = $sth->fetchAll( PDO::FETCH_ASSOC );
  163. // szukam newsroom
  164. $sth = $this->pdo->prepare( "SELECT *, 'newsroom' as _TYPE_LINK_ FROM newsroom WHERE stat = '1' AND (tytul_" . LANG . " REGEXP '{$search}' OR tresc_" . LANG . " REGEXP '{$search}')" );
  165. $sth->execute();
  166. $this->data['newsroom'] = $sth->fetchAll( PDO::FETCH_ASSOC );
  167. // szukam wydarzeń
  168. $sth = $this->pdo->prepare( "SELECT *, 'wydarzenia' as _TYPE_LINK_ FROM wydarzenia WHERE stat = '1' AND (tytul_" . LANG . " REGEXP '{$search}' OR tresc_" . LANG . " REGEXP '{$search}')" );
  169. $sth->execute();
  170. $this->data['wydarzenia'] = $sth->fetchAll( PDO::FETCH_ASSOC );
  171. // szukam stron
  172. $sth = $this->pdo->prepare( "SELECT *, 'strona' as _TYPE_LINK_ FROM strony WHERE stat = '1' AND (tytul_" . LANG . " REGEXP '{$search}' OR tresc_" . LANG . " REGEXP '{$search}')" );
  173. $sth->execute();
  174. $this->data['strony'] = $sth->fetchAll( PDO::FETCH_ASSOC );
  175. $this->data['results'] = array_merge( $this->data['aktualnosci'], $this->data['newsroom'], $this->data['wydarzenia'], $this->data['strony'] );
  176. }
  177. }