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 {
/*echo "Jméno: ". $row[ 3 ]. " ". $row[ 5 ]. "<br />";
echo "Adresa: ". $row[ 5 ]. ", ". $row[ 6 ]. "<br />";
echo "Email: ". $row[ 7 ]. "<br />";
echo "Telefon: ". $row[ 8 ]. "<br />";
echo "GSM: ". $row[ 9 ]. "<br />";
echo "Fax: ". $row[ 10 ]. "<br />";
echo '<a href="?action=hotel&make=edit" title="Upravit profil">Upravit profil</a>';*/
$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 = "-";
}
$smarty->assign( 'email', $email );
if ( !empty( $row[ 8 ] ) ) {
$phone = $row[ 8 ];
} else {
$phone = "-";
}
$smarty->assign( 'phone', $phone );
if ( !empty( $row[ 9 ] ) ) {
$gsm = $row[ 9 ];
} else {
$gsm = "-";
}
$smarty->assign( 'gsm', $gsm );
if ( !empty( $row[ 10 ] ) ) {
$fax = $row[ 10 ];
} else {
$fax = "-";
}
$smarty->assign( 'fax', $fax );
$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 == "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 );
$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( '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}/' );
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" ];
$query = "UPDATE `hotels` SET `name` = '$name', `address_street` = '$address_street', `address_city` = '$address_city', `email` = '$email', `phone` = '$phone', `gsm` = '$gsm', `fax` = '$fax' 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