<?

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

*************************************************
*			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('news', '');

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['aktEd'] ) )
        {
                if ( !empty( $_POST['title'] ) && !empty( $_POST['txt'] ) )
                {
                        $sql = "UPDATE `aktualnosci` SET `aktTitle` = '".$_POST['title']."', `aktTxt` = '".$_POST['txt']."' WHERE aktId = '$id'";
                        mysql_query( $sql );
                        $smarty -> assign('success', 'Poprawnie zapisano zmiany!');
                
                }
                else
                {
                        $smarty -> assign('error', 'Wypełnij wszystkie pola!');
                }
        }
        
        $sql = "SELECT * FROM aktualnosci WHERE aktId = '$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'];
        
        
        $sql = "DELETE FROM `aktualnosci` WHERE aktId = '$id'";
        mysql_query( $sql );
        $smarty -> assign('success', 'Poprawnie usunięto newsa!');
}

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



$sql = "SELECT * FROM aktualnosci WHERE aktId BETWEEN 1 AND 1000";
$q = mysql_query( $sql );
$smarty -> assign('num', mysql_num_rows( $q ));
$akt = array();

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

$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 aktualnosci WHERE aktId BETWEEN 1 AND 4";
$q = mysql_query( $sql );

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