<?

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

*************************************************
*			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:				artglobal@wp.pl			*
*************************************************

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

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

require_once('inc/config.inc.php');

require_once('class/object.class.php');



$object = new obj;

include('inc/seo.inc.php');

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

$sql = "SELECT a.*, b.*, c.*, d.*, e.*,  g.* 
FROM object AS a, type AS b, state AS c , region AS d, droga AS e, rodzaj AS g 
WHERE a.obTypeId = b.typeId AND a.obStateId = c.stateId AND a.obRegion = d.regionId AND a.obDroga = e.drogaId AND a.obRodzaj = g.rodzajId   AND a.obPromo = '1' AND a.obConfirm = '1' AND a.obDateEnd > NOW() ORDER by a.obId DESC LIMIT 5";
$q = $mysql -> q( $sql );
$smarty -> assign('nump', $mysql -> num( $sql ));
$promos = array();
$count = 0;
while ( $db = mysql_fetch_array( $q ) )
{
        $promos[$count] = $db;
        $sql2 = "SELECT photoUrl FROM photos WHERE photoObjectId = '".$db['obId']."' ORDER by photoId ASC LIMIT 1";
        $q2 = $mysql -> q( $sql2 );
        $db2 = mysql_fetch_array( $q2 );
        $promos[$count]['photo'] = $db2[0];
        $count++;
}
$smarty -> assign('promoA', $promos);
////////////////////

////////////////////

/*

if ( ! $session -> chesk_session () )

{

        header('Location: login.html');

        die();

}
*/
$id = html( $_GET['id'] );

$sql = "SELECT * FROM diler WHERE uzytkownik = '$id'  ";
$q = $mysql -> q( $sql );

$agent = array();
$count = 0;
while ( $db = mysql_fetch_array( $q ) )
{
        $agent[$count] = $db;
        $count++;
}


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


switch ( html( $_GET['mod'] ) )

{

        case 'oferta':

                        include('diler-podstrony.php');

                        $smarty -> assign('title', 'Oferta');

                        $smarty -> display('diler-podstrony.tpl');

        break;
        case 'firma':

                        include('diler-podstrony.php');
                        $smarty -> assign('title', 'Firma');

                        $smarty -> display('diler-podstrony.tpl');

        break;
        case 'kontakt':

                        include('diler-podstrony.php');

                        $smarty -> assign('title', 'Kontakt');

                        $smarty -> display('diler-podstrony.tpl');

        break;


        default:

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

                        

                        if ( $_GET['act'] == 'delete' && isset( $_GET['id'] ) )

                        {

                                if ( $object -> checkDelete ( $_GET['id'], $_SESSION['userId'], $mysql ) )

                                {

                                        $object -> delete ( $_GET['id'], $mysql );

                                        $smarty -> assign('success', 'Poprawnie usunięto obiekt!');

                                }

                                else

                                {

                                        $error = 'Wystąpił nieznany błąd';

                                }

                        }

                        
                       // $sql = "SELECT a.*, b.*  FROM object AS a, diler AS b WHERE a.obUserId = b.uzytkownik AND obUserId = '".$_SESSION['userId']."' ORDER by obId DESC";
												
                        $sql = "SELECT a.*, b.*  FROM object AS a, diler AS b WHERE a.obUserId = b.uzytkownik AND obUserId = '$id' ORDER by obId DESC";

                        $q = $mysql -> q( $sql );

                        $smarty -> assign('num', $mysql -> num( $sql ));

                        $ob = array();

                        $count = 0;

                        while ( $db = mysql_fetch_array( $q ) )

                        {

                                $ob[$count] = $db;

                                $ob[$count]['end'] = $object -> end( $db['obId'], $mysql );

                                $count++;

                        }

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

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

                        

                        $smarty -> assign('title', 'Stron Dilera');
$sql = "SELECT a.*, b.*, c.*, d.*, e.*,  g.*,  h.*,  i.*  
FROM object AS a, type AS b, state AS c , region AS d, droga AS e, rodzaj AS g, kategoria AS h, stan AS i
WHERE a.obTypeId = b.typeId AND a.obStateId = c.stateId AND a.obRegion = d.regionId AND a.obDroga = e.drogaId AND a.obRodzaj = g.rodzajId   AND a.obKat = h.katId AND a.obStan = i.stanId  AND a.obPromo = '1' AND a.obConfirm = '1'AND a.obDateEnd > NOW() AND obUserId = '$id' ORDER by a.obId DESC ";


$q = $mysql -> q( $sql );
$smarty -> assign('num', $mysql -> num( $sql ));
$index = array();
$count = 0;

while ( $db = mysql_fetch_array( $q ) )
{
        $index[$count] = $db;
        $sql2 = "SELECT photoUrl FROM photos WHERE photoObjectId = '".$db['obId']."' ORDER by photoId ASC LIMIT 1";
        $q2 = $mysql -> q( $sql2 );
        $db2 = mysql_fetch_array( $q2 );
        $index[$count]['photo'] = $db2[0];
        $count++;
}
$smarty -> assign('index', $index);


 $smarty -> assign('dilerid', $id);

$sql = "SELECT * FROM diler WHERE uzytkownik = '$id'  ";
$q = $mysql -> q( $sql );
$db = mysql_fetch_array( $q );

$smarty -> assign('dilerfoto', $db['dilerfoto']);


$sql = "SELECT userFrom  FROM users WHERE userId  = '$id'  ";
$q = $mysql -> q( $sql );
$db = mysql_fetch_array( $q );

$smarty -> assign('miastoDiler', $db['userFrom']);

  $smarty -> assign('title', 'Strona Agenta');
 $smarty -> display('diler2.tpl');

}



?>

