<?

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

*************************************************
*			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.

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

require_once('inc/config.inc.php');
require_once('class/object.class.php');
require_once('class/user.class.php');

$object = new obj;
include('inc/seo.inc.php');
$smarty -> register_function('nopl', 'parse');

$smarty -> assign('showPages', $object -> showPages( $mysql ));
$smarty -> assign('promoA', $object -> showPromoA( $mysql ));
$smarty -> assign('reklama', $object -> showReklamaA( $mysql ));
$smarty -> assign('showTypeLicz', $object -> showTypeLicz( $mysql ));
$smarty -> assign('showStateLicz', $object -> showStateLicz( $mysql ));
$smarty -> assign('showKategriaLicz', $object -> showKategriaLicz( $mysql ));

///////////////////
$login = new user;

if ( isset( $_POST['getLogin'] ) )
{
        ( $login -> isEmpty ( $_POST['login'] ) ? $smarty -> assign('login', $_POST['login']) : $error[] = 'Nie podano loginu!' );
        ( $login -> isEmpty ( $_POST['pass'] ) ? $smarty -> assign('pass', $_POST['pass']) : $error[] = 'Nie podano hasła!' );
        ( $login -> check_login ( $_POST['login'], $_POST['pass'], $mysql ) ? '' : $error[] = 'Dane są niepoprawne!' );
        
        if ( $error == null )
        {
                $session -> session_register ( $_POST['login'], $mysql );
                header('Location: panel.html');
        }
}
$smarty -> assign('error', $error);
///////////////////

/////////////////////
					$sql = "SELECT a.*, b.*, c.*, d.*, e.*,  g.*, h.* FROM object AS a, type AS b, state AS c , region AS d, kategoria AS e,  rodzaj AS g, stan AS h WHERE a.obTypeId = b.typeId AND a.obStateId = c.stateId AND a.obRegion = d.regionId AND a.obKat = e.katId  AND a.obRodzaj = g.rodzajId AND a.obStan = h.stanId AND a.obPromo = '1' AND a.obConfirm = '1' AND a.obDateEnd > NOW() ORDER by  RAND() LIMIT 5";
								$q = $mysql -> q( $sql );
$smarty -> assign('nump', $mysql -> num( $sql ));

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



if ( ! $session -> chesk_session () )
{
        header('Location: login.html');
        die();
}
switch ( html( $_GET['mod'] ) )
{
        case 'dodaj':
                        include('inc/panel-dodaj.inc.php');
                        $smarty -> assign('title', 'Dodaj obiekt');
                        $smarty -> display('panel-dodaj.tpl');
        break;
				case 'logout':

                        include('inc/logout.inc.php');
                        $smarty -> assign('title', 'Wylogowany');

                        $smarty -> display('kontakt.tpl');

        break;
				case 'agent':

                        include('diler-ustawienia.php');

                        $smarty -> assign('title', 'Ustawienia Agent/Developer ');

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

        break;
        case 'edit':
                        include('inc/panel-edit.inc.php');
                        $smarty -> assign('title', 'Edytuj obiekt');
                        $smarty -> display('panel-edit.tpl');
        break;
        case 'ustawienia':
                        include('inc/panel-ustawienia.inc.php');
                        $smarty -> assign('title', 'Ustawienia konta');
                        $smarty -> display('panel-ustawienia.tpl');
        break;
        case 'platnosci':
                        $smarty -> assign('title', 'Płatności');
                        include('inc/panel-platnosci.inc.php');
        break;
        default:
                        $smarty -> assign('panel', '');
                        
                        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 obId, obName,  obDate, obConfirm, obDateEnd, clicked, wizyt FROM object WHERE obUserId = '".$_SESSION['userId']."' 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++;
                        }
												
$dilerid = $_SESSION['userId'];
 $smarty -> assign('dilerid', $dilerid);
 
 
$sql = "SELECT * FROM users WHERE userId = $dilerid  ";
$q = $mysql -> q( $sql );
$db = mysql_fetch_array( $q );

$smarty -> assign('userFunkcja', $db['userFunkcja']);
 
                        $smarty -> assign('ob', $ob);
                        $smarty -> assign('error', $error);
                        
                        $smarty -> assign('title', 'Panel użytkownika');
                        
                        $smarty -> display('panel.tpl');
}
?>
