ACC SHELL
<?php
$make = ( isset( $_GET[ "make" ] ) )?$_GET[ "make" ]:"view";
if ( $make == "view" ) {
if ( isset( $_GET[ "do" ] ) ) {
$do = $_GET[ "do" ];
if ( $do == "updated" ) {
message( "Profil hotelu byl úspěšně editován." );
}
}
$query = "SELECT * FROM `hotels` WHERE `ID_user` = '". $_SESSION[ "ID" ]. "'";
$result = mysql_query( $query, $dbc );
if ( mysql_num_rows( $result ) > 0 )
{
$row = mysql_fetch_row( $result );
if ( $row[ 3 ] == '' ) {
message( 'Profil hotelu je prázdný.<br />'
.'<a href="?action=hotel&make=edit" title="Upravit profil">Upravit profil</a>' );
} else {
$smarty->assign( 'name', $row[ 3 ] );
$smarty->assign( 'address_street', $row[ 5 ] );
$smarty->assign( 'address_city', $row[ 6 ] );
if ( !empty( $row[ 7 ] ) ) {
$email = $row[ 7 ];
} else {
$email = "<em>není</em>";
}
$smarty->assign( 'email', $email );
if ( !empty( $row[ 8 ] ) ) {
$phone = $row[ 8 ];
} else {
$phone = "<em>není</em>";
}
$smarty->assign( 'phone', $phone );
if ( !empty( $row[ 9 ] ) ) {
$gsm = $row[ 9 ];
} else {
$gsm = "<em>není</em>";
}
$smarty->assign( 'gsm', $gsm );
if ( !empty( $row[ 10 ] ) ) {
$fax = $row[ 10 ];
} else {
$fax = "<em>není</em>";
}
$smarty->assign( 'fax', $fax );
if ( !empty( $row[ 12 ] ) ) {
$smallinfo = $row[ 12 ];
} else {
$smallinfo = "<em>není</em>";
}
$smarty->assign( 'smallinfo', $smallinfo );
$smarty->display( 'user/hotel.tpl' );
}
} else {
message( "Hotel není regitrovaný v databázi.<br />Informujte o tom prosím systémového administrátora." );
}
} elseif ( $make == "editimg" ) {
if ( isset( $_POST[ "submit" ] ) )
{
$correct = TRUE;
$message = "";
if ( empty( $_FILES[ 'file' ][ 'name' ] ) ) {
$correct = FALSE;
$message .= "<p>Nebyl zadán soubor!</p>\n";
}
if ( !preg_match( '/.*\.(GIF|JPG|JPEG|PNG)/', strtoupper( $_FILES[ 'file' ][ 'name' ] ), $finded ) && $correct == TRUE) {
$correct = FALSE;
$message .= "<p>Zadaný soubor (".$_FILES[ 'file' ][ 'name' ].") není obrázek!</p>\n";
}
/*if ( file_exists( "../images/content/". $_FILES[ 'file' ][ 'name' ] ) ) {
$correct = FALSE;
$message .= "<p>Zadaný soubor (".$_FILES[ 'file' ][ 'name' ].") již existuje!</p>\n";
}*/
if ( $correct ) {
$info = getimagesize( $_FILES[ 'file' ][ 'tmp_name' ] );
$width = $width_old = $info[ 0 ];
$height = $height_old = $info[ 1 ];
if ( $width > 640 || $height > 480 ) {
if ( $width_old > 640 ) {
$height = $height - (($width_old-640)/($width_old/100))*($height_old/100);
$width = 640;
}
if ( $height > 480 ) {
$width = $width - (($height-640)/($height/100))*($width/100);
$height = 480;
}
switch ($info[ 2 ]) {
case 1: $img = @imagecreatefromgif($_FILES[ 'file' ][ 'tmp_name' ]); break;
case 2: $img = @imagecreatefromjpeg($_FILES[ 'file' ][ 'tmp_name' ]); break;
case 3: $img = @imagecreatefrompng($_FILES[ 'file' ][ 'tmp_name' ]); break;
default: return false;
}
$img2 = imagecreatetruecolor($width, $height);
imagecopyresampled($img2, $img, 0, 0, 0, 0, $width, $height, $width_old, $height_old);
switch ($info[ 2 ]) {
case 1: $img = @imagegif($img2); break;
case 2: $img = @imagejpeg($img2); break;
case 3: $img = @imagepng($img2); break;
default: return false;
}
$query = "DELETE FROM `photos` WHERE `ID_user` = '". $_SESSION[ "ID" ]. " && is_title = 1'";
$result = @mysql_query( $query, $dbc );
if ( $result ) {
echo "smazano";
}
header ( "Location: index.php?action=images&make=view&do=saved&file=". $_FILES[ 'file' ][ 'name' ] );
}
} else {
echo "\n". $message. "<p>Zkuste to znovu...</p>\n";
}
}
$smarty->display( 'user/hotel_photo_add.tpl' );
} elseif ( $make == "edit" ) {
$query = "SELECT * FROM `hotels` WHERE `ID_user` = '". $_SESSION[ "ID" ]. "'";
$result = @mysql_query( $query, $dbc );
if ( mysql_num_rows( $result ) > 0 ) {
$row = mysql_fetch_row( $result );
$include_path = ':./scripts/:';
ini_set ('include_path',ini_get('include_path'). $include_path);
require_once './scripts/HTML/QuickForm.php';
$form = new HTML_QuickForm( 'user', 'POST', 'index.php?action=hotel&make=edit' );
if ( !isset( $_POST[ "save" ] ) ) {
$form->addElement( 'header', 'info', 'Obecné informace' );
$element =& HTML_QuickForm::createElement( 'text', 'name', 'Název hotelu:' );
$element->setValue( $row[ 3 ] );
$form->addElement( $element );
$element =& HTML_QuickForm::createElement( 'text', 'smallinfo', 'Krátký popisek:', 'maxlength="15"' );
$element->setValue( $row[ 12 ] );
$form->addElement( $element );
$form->addElement( 'header', 'address', 'Adresa:' );
$element =& HTML_QuickForm::createElement( 'text', 'address_street', 'Ulice a č.p.:' );
$element->setValue( $row[ 5 ] );
$form->addElement( $element );
$element =& HTML_QuickForm::createElement( 'text', 'address_city', 'PSČ a město:' );
$element->setValue( $row[ 6 ] );
$form->addElement( $element );
$form->addElement( 'header', 'contacts', 'Kontakty:' );
$element =& HTML_QuickForm::createElement( 'text', 'email', 'Email:' );
$element->setValue( $row[ 7 ] );
$form->addElement( $element );
$element =& HTML_QuickForm::createElement( 'text', 'phone', 'Telefon:' );
$element->setValue( $row[ 8 ] );
$form->addElement( $element );
$element =& HTML_QuickForm::createElement( 'text', 'gsm', 'GSM:' );
$element->setValue( $row[ 9 ] );
$form->addElement( $element );
$element =& HTML_QuickForm::createElement( 'text', 'fax', 'Fax:' );
$element->setValue( $row[ 10 ] );
$form->addElement( $element );
} else {
$form->addElement( 'header', 'info', 'Obecné informace' );
$form->addElement( 'text', 'name', 'Název hotelu:' );
$form->addElement( 'text', 'smallinfo', 'Krátký popisek:', 'maxlength="15"' );
$form->addElement( 'header', 'address', 'Adresa:' );
$form->addElement( 'text', 'address_street', 'Ulice a č.p.:' );
$form->addElement( 'text', 'address_city', 'PSČ a město:' );
$form->addElement( 'header', 'contacts', 'Kontakty:' );
$form->addElement( 'text', 'email', 'Email:' );
$form->addElement( 'text', 'phone', 'Telefon:' );
$form->addElement( 'text', 'gsm', 'GSM:' );
$form->addElement( 'text', 'fax', 'Fax:' );
}
$form->addElement( 'submit', 'save', 'Uložit' );
$form->addRule( 'name', 'Zadejte název hotelu', 'required' );
$form->addRule( 'address_street', 'Zadejte ulici a č.p. hotelu', 'required' );
$form->addRule( 'address_city', 'Zadejte PSČ a město', 'required' );
$form->addRule( 'email', 'Zadejte email ve správném tvaru', 'email' );
$form->addRule( 'phone', 'Zadejte platné telefoní číslo', 'regex', '/(\+[0-9]{1,3})?[ ]?[0-9]{3}[ ]?[0-9]{3}[ ]?[0-9]{3}/' );
$form->addRule( 'gsm', 'Zadejte platné GSM číslo', 'regex', '/(\+[0-9]{1,3})?[ ]?[0-9]{3}[ ]?[0-9]{3}[ ]?[0-9]{3}/' );
$form->addRule( 'fax', 'Zadejte platné číslo faxu', 'regex', '/(\+[0-9]{1,3})?[ ]?[0-9]{3}[ ]?[0-9]{3}[ ]?[0-9]{3}/' );
$form->addRule( 'smallinfo', 'Krátký popisek může mít max. 15 znaků', 'maxlength', 15 );
if ( $form->validate() ) {
$form->process( 'saveToDB' );
} else {
$form->display();
}
} else {
message( "Nepovedlo se připojit k databázi." );
}
} else {
message( "Požadovaná akce neexistuje." );
}
function saveToDB( $v ) {
global $dbc;
$name = $v[ "name" ];
$address_street = $v[ "address_street" ];
$address_city = $v[ "address_city" ];
$email = $v[ "email" ];
$phone = $v[ "phone" ];
$gsm = $v[ "gsm" ];
$fax = $v[ "fax" ];
$smallinfo = $v[ "smallinfo" ];
$query = "UPDATE `hotels` SET `name` = '$name', `address_street` = '$address_street', `address_city` = '$address_city', `email` = '$email', `phone` = '$phone', `gsm` = '$gsm', `fax` = '$fax', `smallinfo` = '$smallinfo' WHERE ID_user = ". $_SESSION[ "ID" ];
$result = @mysql_query( $query, $dbc );
if ( $result ) {
header ( "Location: index.php?action=hotel&make=view&do=updated" );
} else {
message( "Omlouváme se, ale nastala systémová chyba." );
}
}
?>
ACC SHELL 2018