<?

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

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

$url = $_SERVER['REQUEST_URI'];
$smarty -> assign('url', $url);

if ( isset( $_GET['site'] ) )
{
        $form_url = 'administrator.php?mod=diler&site=' . $_GET['site'];
}
else
{
        $form_url = 'administrator.php?mod=diler';
}
$smarty ->assign('formUrl', $form_url);



if ( $_GET['act'] == 'delete' && isset( $_GET['id'] ) )
{
        $id = $_GET['id'];
        
        $sql = "SELECT * FROM diler WHERE uzytkownik = '$id'";
        $q = mysql_query( $sql );
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $sql2 = "SELECT dilerfoto FROM diler WHERE uzytkownik = ".$db[0]."";
                $q2 = mysql_query( $sql2 );
                
                while ( $db2 = mysql_fetch_array( $q2 ) )
                {
                        @unlink('../diler/' . $db2[0]);
                }
                
                $sql3 = "DELETE FROM diler WHERE uzytkownik = ".$db[0]."";
                mysql_query( $sql3 );
        }
        
        $sql = "DELETE FROM diler WHERE uzytkownik = '$id'";
        mysql_query( $sql );
        

        $success = "Poprawnie usunięto dilera";
}
if ( $_GET['act'] == 'edit' && isset( $_GET['id'] ) )
{
        $smarty -> assign('edit', '');
        $id = $_GET['id'];
        $smarty -> assign('id', $id);
}

$n = '30';
$sql = "SELECT * FROM diler";
$q = mysql_query( $sql );
$num = mysql_num_rows( $q );
$smarty -> assign('num', $num);

$p = new Pager('kat', $num, $n, '100');

$p -> setVar("html_link", "<a href=\"administrator.php?mod=diler&site={^link}\">{^name}</a>\n");
$p -> Render();
$start = $p -> startRecord();

$sql = "SELECT * FROM diler ORDER by uzytkownik DESC LIMIT $start, $n";
$q = mysql_query( $sql );
$diler = array();
while ( $db = mysql_fetch_array( $q ) )
{
        $diler[] = $db;
}
$smarty -> assign('diler', $diler);

$str = $p -> getVar("html_out");
$smarty->assign('str', $str);

$smarty -> assign('success', $success);
$smarty -> assign('error', $error);
?>
