<?

/* ------------------------------------------------------------------- */
/*

*************************************************
*			UWAGA! SKRYPT NIE JEST DARMOWY.			*
*		DALSZE ROZPOWSZECHNIANIE BEZ ZGODY 			*
*			FIRMY ArtGlobal JEST ZABRONIONE.			*
*************************************************

*************************************************
*	WWW.ArtGlobal.PL		PRODUCENT OPROGRAMOWANIA	*
*	NAZWA SKRYPTU:		NIERUCHOMOSCI 6.0			*
*	WERSJA FINALNA:	04.10.2010						*
*	KONTAKT:				kontakt@artglobal.pl			*
*************************************************

Copyright (c) 2010 ArtGlobal. Wszelkie prawa zastrzeżone.

*/
/* ------------------------------------------------------------------- */

$smarty -> assign('pag', '');

function parse ( $str )
{
        if ( is_array( $str ) )
        {
                $str = htmlspecialchars( $str['str'] );
        }
        else
        {
                $str = htmlspecialchars( $str );
        }
        $str = strip_tags($str);
        $polish =   'ęó±¶łżĽćńĘÓˇ¦ŁŻ¬ĆŃ';
        $nopolish = 'eoaslzzcnEOASLZZCN';
        $str = strtr($str, $polish, $nopolish);
        $str = str_replace("`", "", $str);
        //$str = str_replace("-", "", $str);
        $str = str_replace("=", "_", $str);
        $str = str_replace("+", "_", $str);
        $str = str_replace(")", "_", $str);
        $str = str_replace("(", "_", $str);
        $str = str_replace("*", "_", $str);
        $str = str_replace("&", "_", $str);
        $str = str_replace("^", "_", $str);
        $str = str_replace("%", "_", $str);
        $str = str_replace("$", "_", $str);
        $str = str_replace("#", "_", $str);
        $str = str_replace("@", "_", $str);
        $str = str_replace("!", "_", $str);
        $str = str_replace("~", "_", $str);
        $str = str_replace("|", "_", $str);
        $str = str_replace(",", "", $str);
        $str = str_replace(".", "", $str);
        $str = str_replace("/", "_", $str);
        $str = str_replace(";", "", $str);
        $str = str_replace("'", "_", $str);
        $str = str_replace("]", "_", $str);
        $str = str_replace("[", "_", $str);
        $str = str_replace("<", "_", $str);
        $str = str_replace(">", "_", $str);
        $str = str_replace("?", "_", $str);
        $str = str_replace(":", "", $str);
        $str = str_replace("|", "_|", $str);
        $str = str_replace("}", "_", $str);
        $str = str_replace("{", "_", $str);
        $str = str_replace("\\", "_", $str);
        $str = str_replace(" ", "_", $str);
        $str = str_replace("  ", "_", $str);
        $str = str_replace("   ", "_", $str);

        return $str;
}

$smarty -> register_function('nopl', 'parse');

if ( $_GET['act'] == 'edit' )
{
        $smarty -> assign('edit', '');
        $id = $_GET['id'];
        $smarty -> assign('id', $id);
        
        if ( isset( $_POST['pagesEd'] ) )
        {
                if ( !empty( $_POST['title'] ) && !empty( $_POST['txt'] ) )
                {
                        $sql = "UPDATE `pages` SET `pagesTitle` = '".$_POST['title']."', `pagesTxt` = '".$_POST['txt']."' WHERE pagesId = '$id'";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
                
                }
                else
                {
                        $smarty -> assign('error', 'Wypełnij wszystkie pola!');
                }
        }
        
        $sql = "SELECT * FROM pages WHERE pagesId = '$id'";
        $q = mysql_query( $sql );
        $ed = array();
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $ed[] = $db;
        }
        $smarty -> assign('ed', $ed);
}

if ( $_GET['act'] == 'delete' )
{
        $id = $_GET['id'];
        
        if ( $id == 1 || $id == 2 || $id == 3 || $id == 4 )
        {
                $id = '';
        }
        
        $sql = "DELETE FROM `pages` WHERE pagesId = '$id'";
        mysql_query( $sql );
        $smarty -> assign('success', 'Poprawnie usunięto podstronę!');
}

if ( isset( $_POST['pagesAdd'] ) )
{
        $smarty -> assign('title', $_POST['title']);
        $smarty -> assign('txt', $_POST['txt']);
        
        if ( !empty( $_POST['title'] ) && !empty( $_POST['txt'] ) )
        {
                $sql = "INSERT INTO `pages` (`pagesTitle`, `pagesTxt`) VALUES ('".$_POST['title']."', '".$_POST['txt']."')";
                mysql_query( $sql );
                $smarty -> assign('success', 'Poprawnie dodano podstronę!');
                
                $smarty -> assign('title', '');
                $smarty -> assign('txt', '');
        }
        else
        {
                $smarty -> assign('error', 'Wypełnij wszystkie pola!');
        }
}

if ( isset( $_POST['pagesEdit'] ) )
{
        $glowna = $_POST['powitanie'];
        $regulamin = $_POST['regulamin'];
        $onas = $_POST['onas'];
				$oferta = $_POST['oferta'];
        $sql = "UPDATE `pages` SET `pagesTxt` = '$glowna' WHERE pagesId = '2'";
        mysql_query( $sql );
        $sql = "UPDATE `pages` SET `pagesTxt` = '$regulamin' WHERE pagesId = '1'";
        mysql_query( $sql );
        $sql = "UPDATE `pages` SET `pagesTxt` = '$onas' WHERE pagesId = '3'";
        mysql_query( $sql );
        $sql = "UPDATE `pages` SET `pagesTxt` = '$oferta' WHERE pagesId = '4'";
        mysql_query( $sql );
        $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
}

$sql = "SELECT * FROM pages WHERE pagesId BETWEEN 5 AND 1000";
$q = mysql_query( $sql );
$smarty -> assign('num', mysql_num_rows( $q ));
$pages = array();

while ( $db = mysql_fetch_array( $q ))
{
        $pages[] = $db;
}
$smarty -> assign('pages', $pages);

$sql = "SELECT cfgTxt FROM config WHERE cfgId = '1'";
$q = mysql_query( $sql );
$db = mysql_fetch_array ( $q );
$smarty -> assign('adress', $db[0]);

$sql = "SELECT * FROM pages WHERE pagesId BETWEEN 1 AND 4";
$q = mysql_query( $sql );

while ( $db = mysql_fetch_Array( $q ) )
{
        $smarty -> assign($db['pagesTitle'], $db['pagesTxt']);
}
?>
