<?

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

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

$id = $_GET['id'];
$smarty -> assign('id', $id);


if ( isset( $_POST['editagnet'] ) )
{
      
       
      
        
 if ( empty( $_POST['dilerNazwa'] ) || empty( $_POST['dilerMiasto'] ) || empty( $_POST['dilerTel'] ) || empty( $_POST['dilerEmail'] ) )
        {
                $smarty -> assign('error', 'Pola oznaczone \'*\' są obowiązkowe!');
        }
        else
        {
               $sql = "UPDATE `diler` SET `dilerNazwa` = '".$_POST['dilerNazwa']."', `dilerOfirmie` = '".$_POST['dilerOfirmie']."', `dilerUlica` = '".$_POST['dilerUlica']."', `dilerNrulicy` = '".$_POST['dilerNrulicy']."', `dilerPoczta` = '".$_POST['dilerPoczta']."', `dilerMiasto` = '".$_POST['dilerMiasto']."', `dilerWWW` = '".str_replace(array('http://', 'www.'), '', $_POST['dilerWWW'])."', `dilerTel` = '".$_POST['dilerTel']."', `dilerFax` = '".$_POST['dilerFax']."', `dilerEmail` = '".$_POST['dilerEmail']."', `dilerNr` = '".$_POST['dilerNr']."' WHERE id_diler = '".$_POST['id_diler']."' ";
								

						 

                mysql_query ( $sql );
				
				$smarty -> assign('success', 'Poprawnie zapisano zmiany!');

        }
}


if ( isset( $_POST['new_photo'] ) )
{
        function cropImage ( $nw, $nh, $source, $stype, $dest )
        {
                $size = getimagesize( $source );
                $w = $size[0];
                $h = $size[1];
                switch( $stype )
                {
                        case 'gif':
                                $simg = imagecreatefromgif( $source );
                        break;
                        case 'GIF':
                                $simg = imagecreatefromgif( $source );
                        break;
                        case 'jpg':
                                $simg = imagecreatefromjpeg( $source );
                        break;
                        case 'JPG':
                                $simg = imagecreatefromjpeg( $source );
                        break;
                        case 'png':
                                $simg = imagecreatefrompng( $source );
                        break;
                        case 'PNG':
                                $simg = imagecreatefrompng( $source );
                        break;
                }
                $dimg = imagecreatetruecolor( $nw, $nh );
                $wm = $w / $nw;
                $hm = $h / $nh;
                $h_height = $nh / 2;
                $w_height = $nw / 2;
                if( $w > $h )
                {
                        $adjusted_width = $w / $hm;
                        $half_width = $adjusted_width / 2;
                        $int_width = $half_width - $w_height;
                        imagecopyresampled( $dimg, $simg, -$int_width, 0, 0, 0, $adjusted_width, $nh, $w, $h);
                }
                elseif( ( $w < $h ) || ( $w == $h ) )
                {
                        $adjusted_height = $h / $wm;
                        $half_height = $adjusted_height / 2;
                        $int_height = $half_height - $h_height;
                        imagecopyresampled( $dimg, $simg, 0, -$int_height, 0, 0, $nw, $adjusted_height, $w, $h);
                }
                else
                {
                        imagecopyresampled( $dimg, $simg, 0, 0, 0, 0, $nw, $nh, $w, $h);
                }
                imagejpeg( $dimg, $dest, 100 );
        }
        if ( $_FILES['photo']['tmp_name'] !== '' )
        {
                $name = $_FILES['photo']['name'];
                $tempName = $_FILES['photo']['tmp_name'];


                $roz = array_pop( explode('.', $name) );
                $new_name =  md5( substr( str_shuffle('1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'), 0, 25) ) . '.' . $roz;
                move_uploaded_file( $tempName, '../diler/tmp/' . $new_name);
                cropImage( 200, 170, '../diler/tmp/' . $new_name, $roz, '../diler/duze/' . $new_name );
								cropImage( 100, 60, '../diler/tmp/' . $new_name, $roz, '../diler/male/' . $new_name );
				
                unlink('../diler/tmp/' . $new_name);
								$sql = "UPDATE `diler` SET  `dilerfoto`= '$new_name' WHERE  id_diler = '".$_POST['id_diler']."'  ";
               // $sql = "INSERT INTO `diler` (`uzytkownik`, `dilerfoto`) VALUES ('$id', '$new_name')";
                mysql_query( $sql );
                $smarty -> assign('success', 'Poprawnie dodano nowe zdjęcie!');
        }
        else
        {
                $error = 'Nie wybrano pliku zdjęcia!';
        }
}
				
				



$sql = "SELECT  * FROM `diler`  WHERE  id_diler  = '$id'";
$q = mysql_query( $sql );
$editagent= array();
while ( $db = mysql_fetch_array( $q ) )
{
        $editagent[] = $db;
}
$smarty -> assign('editagnet', $editagent);




?>
