$xajax = new xajax(); $xajax -> register( XAJAX_FUNCTION, 'sendContactForm' ); $xajax -> register( XAJAX_FUNCTION, 'sendGuestBookEntry' ); $xajax -> register( XAJAX_FUNCTION, 'changeLang'); $xajax -> register( XAJAX_FUNCTION, 'checkRegisterForm' ); $xajax -> register( XAJAX_FUNCTION, 'registerUser' ); $xajax -> register( XAJAX_FUNCTION, 'recoverPassword' ); $xajax -> register( XAJAX_FUNCTION, 'loginUser' ); $xajax -> register( XAJAX_FUNCTION, 'logout' ); $xajax -> register( XAJAX_FUNCTION, 'closeAdvert' ); $xajax -> register( XAJAX_FUNCTION, 'setCookieInf' ); if ( $user && $user -> _values['admin'] ) { $xajax -> register( XAJAX_FUNCTION, 'saveArticleTranslation' ); $xajax -> register( XAJAX_FUNCTION, 'saveLayout' ); $xajax -> register( XAJAX_FUNCTION, 'saveArticle' ); $xajax -> register( XAJAX_FUNCTION, 'deleteArticleImg' ); $xajax -> register( XAJAX_FUNCTION, 'moveArticlesToArchive' ); $xajax -> register( XAJAX_FUNCTION, 'deleteArticles' ); $xajax -> register( XAJAX_FUNCTION, 'articleFileInfo' ); $xajax -> register( XAJAX_FUNCTION, 'saveArticleFileInfo' ); $xajax -> register( XAJAX_FUNCTION, 'deleteArticleFile' ); $xajax -> register( XAJAX_FUNCTION, 'savePageOrder' ); $xajax -> register( XAJAX_FUNCTION, 'deleteTranslations' ); $xajax -> register( XAJAX_FUNCTION, 'generateSeoLink' ); $xajax -> register( XAJAX_FUNCTION, 'savePagesCookie' ); $xajax -> register( XAJAX_FUNCTION, 'saveMenuCookie' ); } if ( file_exists( '../functions/xajax-articles.php' ) ) include '../functions/xajax-articles.php'; include 'xajax-newsletter.php'; include 'xajax-site.php'; include 'xajax-contact.php'; $xajax -> processRequest(); $xajax -> configure( 'javascript URI', '../resources/xajax/' ); function saveMenuCookie( $id ) { $array = unserialize( $_COOKIE[ 'menu_definition' ] ); if ( $array[ $id ] == 0 ) $array[ $id ] = 1; else $array[ $id ] = 0; $array = serialize( $array ); setcookie( 'menu_definition', $array, time() + 3600 * 24 * 365 ); } function savePagesCookie( $id ) { $array = unserialize( $_COOKIE[ 'pages_definition' ] ); if ( $array[ $id ] == 0 ) $array[ $id ] = 1; else $array[ $id ] = 0; $array = serialize( $array ); setcookie( 'pages_definition', $array, time() + 3600 * 24 * 365 ); } function generateSeoLink( $lang, $title ) { global $db; $seo_link = \System::seo( $title ); while ( !$seo_link_check ) { $query = $db -> prepare( 'SELECT id FROM pp_pages_langs WHERE seo_link = :seo_link' ); $query -> bindValue( ':seo_link', $seo_link, \PDO::PARAM_STR ); $query -> execute(); if ( $query -> rowCount() ) $seo_link = \System::seo( $title ) . '-' . ( ++$i ); else $seo_link_check = true; } $seo_link_check = false; while ( !$seo_link_check ) { $query = $db -> prepare( 'SELECT id FROM pp_articles_langs WHERE seo_link = :seo_link' ); $query -> bindValue( ':seo_link', $seo_link, \PDO::PARAM_STR ); $query -> execute(); if ( $query -> rowCount() ) $seo_link = \System::seo( $title ) . '-' . ( ++$i ); else $seo_link_check = true; } $objResponse = new xajaxResponse(); $objResponse -> script( '$( "#seo_link_' . $lang . '" ).val( "' . $seo_link . '" );' ); return $objResponse; } function setCookieInf() { setcookie( "cookie_information", "true", mktime( 0, 0, 0, 12, 31, 2115 ) ); } function savePageOrder( $pages, $id_menu ) { global $db; if ( is_array( $pages ) ) { $query = $db -> prepare( 'UPDATE pp_pages SET o = 0 WHERE id_menu = :id_menu' ); $query -> bindValue( ':id_menu', $id_menu, \PDO::PARAM_INT ); $query -> execute(); $query -> closeCursor(); for ( $i = 0; $i < count( $pages ); $i++ ) { if ( $pages[$i]['item_id'] ) { $pages[$i]['parent_id'] ? $parent_id = $pages[$i]['parent_id'] : $parent_id = 0; if ( $pages[$i]['item_id'] && $pages[$i]['depth'] > 1 ) { if ( $pages[$i]['depth'] == 2 ) $parent_id = 0; $x++; $query = $db -> prepare( 'UPDATE pp_pages SET o = :o, parent_id = :parent_id WHERE id = :id' ); $query -> bindValue( ':id', $pages[$i]['item_id'], \PDO::PARAM_INT ); $query -> bindValue( ':parent_id', $parent_id, \PDO::PARAM_INT ); $query -> bindValue( ':o', $x, \PDO::PARAM_INT ); $query -> execute(); $query -> closeCursor(); } } } } $objResponse = new xajaxResponse(); $objResponse -> script( '$( ".jqibox" ).remove();;' ); return $objResponse; } function deleteArticleFile( $id ) { global $db; $query = $db -> prepare( 'SELECT * FROM pp_articles_file WHERE id = :id' ); $query -> bindValue( ':id' , $id , \PDO::PARAM_INT ); $query -> execute(); if ( $query -> rowCount() ) while ( $row = $query -> fetch() ) { if ( file_exists( "../" . $row['file'] ) ) unlink( "../" . $row['file'] ); } $query -> closeCursor(); $query = $db -> prepare( 'DELETE FROM pp_articles_file WHERE id = :id' ); $query -> bindValue( ':id' , $id , \PDO::PARAM_INT ); $query -> execute(); $query -> closeCursor(); \System::deleteCacheAdmin(); \System::deleteCache(); $objResponse = new xajaxResponse(); $objResponse -> script( '$( "#file_li_' . $id . '").remove(); jQuery( "#file_edit_id").val( "" ); jQuery( "#name" ).val( "" ); jQuery( ".plik_bg, .plik_edycja" ).hide();' ); return $objResponse; } function saveArticleFileInfo( $id, $name ) { global $db; $query = $db -> prepare( 'UPDATE pp_articles_file SET name = :name WHERE id = :id' ); $query -> bindValue( ':id', $id, \PDO::PARAM_INT ); $query -> bindValue( ':name', $name, \PDO::PARAM_STR ); $query -> execute(); $query -> closeCursor(); $objResponse = new xajaxResponse(); $objResponse -> script( 'jQuery( "#file_edit_id").val( "" ); jQuery( "#name" ).val( "" ); jQuery( ".plik_bg, .plik_edycja" ).hide();' ); return $objResponse; } function articleFileInfo( $id ) { global $db; $query = $db -> prepare( 'SELECT * FROM pp_articles_file WHERE id = :id' ); $query -> bindValue( ':id', $id, \PDO::PARAM_INT ); $query -> execute(); if ( $query -> rowCount() ) while ( $row = $query -> fetch() ) $file = $row; $query -> closeCursor(); $objResponse = new xajaxResponse(); $objResponse -> script( 'jQuery( "#name" ).val( "' . $file['name'] . '" );' ); return $objResponse; } function deleteArticles( $articles ) { $articles = explode( ':', $articles ); if ( is_array( $articles ) ) foreach ( $articles as $art ) \admin\factory\Articles::deleteArticle( $art ); $objResponse = new xajaxResponse(); $objResponse -> script( 'document.location.href="./";' ); return $objResponse; } function deleteTranslations( $translations ) { $translations = explode( ':', $translations ); if ( is_array( $translations ) ) foreach ( $translations as $translation ) \admin\factory\Languages::deleteTranslation( $translation ); $objResponse = new xajaxResponse(); $objResponse -> script( 'document.location.href="./";' ); return $objResponse; } function moveArticlesToArchive( $articles ) { $articles = explode( ':', $articles ); if ( is_array( $articles ) ) foreach ( $articles as $art ) \admin\factory\Articles::setAsArchive( $art ); $objResponse = new xajaxResponse(); $objResponse -> script( 'document.location.href="./";' ); return $objResponse; } function closeAdvert() { \System::setSessionVar( 'advert_close' , true ); } function deleteArticleImg( $id ) { global $db; $query = $db -> prepare( 'SELECT * FROM pp_articles_img WHERE id = :id' ); $query -> bindValue( ':id' , $id , \PDO::PARAM_INT ); $query -> execute(); if ( $query -> rowCount() ) while ( $row = $query -> fetch() ) { if ( file_exists( "../" . $row['src'] ) ) unlink( "../" . $row['src'] ); } $query -> closeCursor(); $query = $db -> prepare( 'DELETE FROM pp_articles_img WHERE id = :id' ); $query -> bindValue( ':id' , $id , \PDO::PARAM_INT ); $query -> execute(); $query -> closeCursor(); $objResponse = new xajaxResponse(); $objResponse -> script( '$( "#li_' . $id . '").remove();' ); return $objResponse; } function logout() { \System::deleteSessionVar( 'user' ); $objResponse = new xajaxResponse(); $message = 'document.location.href="' . \System::getMainPage() . '";'; $objResponse -> script( $message ); return $objResponse; } function loginUser( $login, $password ) { global $db, $lang; $objResponse = new xajaxResponse(); $login = \System::saveString( $login, true ); $password = \System::saveString( $password, true ); $query = $db -> prepare( 'SELECT * FROM pp_users WHERE login = :login AND password = :password AND enabled = "1"' ); $query -> bindValue( ':login', $login, \PDO::PARAM_STR ); $query -> bindValue( ':password', md5( $password ), \PDO::PARAM_STR ); $query -> execute(); if ( $query -> rowCount() ) { $user = \user\FUser::login( $login, $password ); \System::setSessionVar( 'user' , $user ); $message = 'location.reload();'; } else { $message = '$( ".jqibox" ).remove();;'; $message .= "$.prompt('" . $lang -> getTrans( 'T_BRAK_UZYTKOWNIKA_KONTO_NIEAKTYWNE' ) . "',{ buttons: { " . $lang -> getTrans( 'T_ZAMKNIJ' ) . ": true }, focus: 1 });"; $message .= 'setTimeout(function(){$( ".jqibox" ).remove();;},3000);'; } $query -> closeCursor(); $objResponse -> script( $message ); return $objResponse; } function recoverPassword( $email ) { global $db , $lang; $objResponse = new xajaxResponse(); $message = ''; $hash = \System::gen_hash( 16 ); $email = \System::saveString( $email , true ); if ( !\System::checkEmail( $email ) ) { $message = '$( ".jqibox" ).remove();;'; $message .= "$.prompt('" . $lang -> getTrans( 'T_NIEPRAWIDLOWY_EMAIL_REJESTRACJA' ) . "',{ buttons: { " . $lang -> getTrans( 'T_ZAMKNIJ' ) . ": true }, focus: 1 });"; $message .= 'setTimeout(function(){$( ".jqibox" ).remove();;},3000);'; } else { if ( !System::isEmailFree( $email ) ) { $query = $db -> prepare( 'UPDATE pp_users SET recover = :recover WHERE email = :email' ); $query -> bindValue( ':recover' , $hash , \PDO::PARAM_STR ); $query -> bindValue( ':email' , $email , \PDO::PARAM_STR ); $query -> execute(); $query -> closeCursor(); $query = $db -> prepare( 'SELECT id FROM pp_users WHERE email = :email' ); $query -> bindValue( ':email' , $email , \PDO::PARAM_STR ); $query -> execute(); if ( $query -> rowCount() ) while ( $row = $query -> fetch() ) $user_id = $row['id']; $query -> closeCursor(); $link = "" . $lang -> getTrans( 'T_RESETUJ' ) . ""; $tresc = str_replace( '{LINK}' , $link , $lang -> getTrans( 'T_ODZYSKIWANIE_TRESC_UZYTKOWNIK' ) ); $tresc = str_replace( '{SERWER}' , \System::getSystemSettings( 'firm_name' ) , $tresc ); \System::sendEmail( $email , str_replace( '{SERWER}' , \System::getSystemSettings( 'firm_name' ) , $lang -> getTrans( 'T_ODZYSKIWANIE_HASLA' ) ), $tresc ); $message = '$( ".jqibox" ).remove();;'; $message .= "$.prompt('" . $lang -> getTrans( 'T_ODZYSKIWANIE_HASLA_ALERT' ) . "',{ buttons: { " . $lang -> getTrans( 'T_ZAMKNIJ' ) . ": true }, focus: 1 });"; $message .= 'setTimeout(function(){$( ".jqibox" ).remove();;},3000);'; } else { $message = '$( ".jqibox" ).remove();;'; $message .= "$.prompt('" . $lang -> getTrans( 'T_BRAK_EMAILA_W_BAZIE' ) . "',{ buttons: { " . $lang -> getTrans( 'T_ZAMKNIJ' ) . ": true }, focus: 1 });"; $message .= 'setTimeout(function(){$( ".jqibox" ).remove();;},3000);'; } } $objResponse -> script( $message ); return $objResponse; } function registerUser( $login , $password , $email ) { global $db , $lang; $login = \System::saveString( $login , true ); $password = \System::saveString( $password , true ); $email = \System::saveString( $email , true ); $hash = \System::gen_hash( 16 ); $c_login = \System::checkLoginRegister( $login ); $c_password = \System::checkPasswordRegister( $password , $password ); $c_email = \System::checkEmailRegister( $email ); $objResponse = new xajaxResponse(); if ( $c_login == 0 && $c_password == 0 && $c_email == 0 && \System::getSystemSettings( 'register' ) != 0 ) { $query = $db -> prepare( 'INSERT INTO pp_users ( login , password , email , registered , hash ) VALUES ( :login , :password , :email , :registered , :hash )' ); $query -> bindValue( ':login' , $login , \PDO::PARAM_STR ); $query -> bindValue( ':password' , md5( $password ) , \PDO::PARAM_STR ); $query -> bindValue( ':email' , $email , \PDO::PARAM_STR ); $query -> bindValue( ':registered' , \System::getDate() , \PDO::PARAM_STR ); $query -> bindValue( ':hash' , $hash , \PDO::PARAM_STR ); $query -> execute(); $query -> closeCursor(); $user_id = $db -> lastInsertId(); if ( \System::getSystemSettings( 'register' ) == 1 ) { \System::sendEmail( \System::getSystemSettings( 'admin_email' ) , str_replace( '{SERWER}' , \System::getSystemSettings( 'firm_name' ) , $lang -> getTrans( 'T_REJESTRACJA_UZYTKOWNIKA' ) ), str_replace( '{LOGIN}' , $login , $lang -> getTrans( 'T_REJESTRACJA_TRESC_ADMIN' ) ) ); $tresc = str_replace( '{LOGIN}' , $login , $lang -> getTrans( 'T_REJESTRACJA_TRESC_UZYTKOWNIK' ) ); $tresc = str_replace( '{SERWER}' , \System::getSystemSettings( 'firm_name' ) , $tresc ); $tresc = str_replace( '{HASLO}' , $password , $tresc ); \System::sendEmail( $email , str_replace( '{SERWER}' , \System::getSystemSettings( 'firm_name' ) , $lang -> getTrans( 'T_REJESTRACJA_UZYTKOWNIKA' ) ), $tresc ); } else if ( \System::getSystemSettings( 'register' ) == 2 ) { $link = "" . $lang -> getTrans( 'T_AKTYWUJ' ) . ""; $tresc = str_replace( '{LOGIN}' , $login , $lang -> getTrans( 'T_REJESTRACJA_TRESC_UZYTKOWNIK_AKTYWACJA' ) ); $tresc = str_replace( '{SERWER}' , \System::getSystemSettings( 'firm_name' ) , $tresc ); $tresc = str_replace( '{HASLO}' , $password , $tresc ); $tresc = str_replace( '{LINK}' , $link , $tresc ); \System::sendEmail( $email , str_replace( '{SERWER}' , \System::getSystemSettings( 'firm_name' ) , $lang -> getTrans( 'T_REJESTRACJA_UZYTKOWNIKA' ) ), $tresc ); } $message = '$( ".jqibox" ).remove();;'; $message .= "$.prompt('" . $lang -> getTrans( 'T_REJESTRACJA_SUKCES' ) . "',{ buttons: { " . $lang -> getTrans( 'T_ZAMKNIJ' ) . ": true }, focus: 1 });"; $message .= 'setTimeout(function(){$( ".jqibox" ).remove();;},3000);'; } else { $message = '$( ".jqibox" ).remove();;'; $message .= "$.prompt('" . $lang -> getTrans( 'T_BLEDY_REJESTRACJA_FORMULARZ' ) . "',{ buttons: { " . $lang -> getTrans( 'T_ZAMKNIJ' ) . ": true }, focus: 1 });"; $message .= 'setTimeout(function(){$( ".jqibox" ).remove();;},3000);'; } $objResponse -> script( $message ); return $objResponse; } function checkRegisterForm( $param , $value , $value2 = '' ) { global $lang; $value = \System::saveString( $value , true ); $value2 = \System::saveString( $value2 , true ); if ( $param == 'login' ) { $r_login = false; $c_login = \System::checkLoginRegister( $value ); if ( $c_login == 1 ) $out = '