<?

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

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

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

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

if ( isset( $_POST['edit'] ) )
{
        $sql = "UPDATE `users` SET `userName` = '".$_POST['login']."', `userEmail` = '".$_POST['email']."', `userFrom` = '".$_POST['from']."', `UserConfirm` = '".$_POST['confirm']."' WHERE userId = '".$_GET['id']."'";
        mysql_query( $sql );
        $success = "Poprawnie zapisano zmiany!";
}

if ( $_GET['act'] == 'delete' && isset( $_GET['id'] ) )
{
        $id = $_GET['id'];
        
        $sql = "SELECT obId FROM object WHERE obUserId = '$id'";
        $q = mysql_query( $sql );
        
        while ( $db = mysql_fetch_array( $q ) )
        {
                $sql2 = "SELECT photoUrl FROM photos WHERE photoObjectId = ".$db[0]."";
                $q2 = mysql_query( $sql2 );
                
                while ( $db2 = mysql_fetch_array( $q2 ) )
                {
                        @unlink('../files/photo/mini/' . $db2[0]);
                        @unlink('../files/photo/big/' . $db2[0]);
                }
                
                $sql3 = "DELETE FROM photos WHERE photoObjectId = ".$db[0]."";
                mysql_query( $sql3 );
        }
        
        $sql = "DELETE FROM object WHERE obUserId = '$id'";
        mysql_query( $sql );
        
        $sql = "DELETE FROM users WHERE userId = '$id'";
        mysql_query( $sql );

        $success = "Poprawnie usunięto użytkownika oraz obiekty dodane przez niego!";
}
if ( $_GET['act'] == 'edit' && isset( $_GET['id'] ) )
{
        $smarty -> assign('edit', '');
        $id = $_GET['id'];
        $smarty -> assign('id', $id);
}

$n = '30';
$sql = "SELECT * FROM users";
$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=users&site={^link}\">{^name}</a>\n");
$p -> Render();
$start = $p -> startRecord();

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

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

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