ACC SHELL
<?php
$make = ( isset( $_GET[ "make" ] ) )?$_GET[ "make" ]:"view";
if ( $make == "view" ) {
if ( isset( $_GET[ "do" ] ) ) {
$do = $_GET[ "do" ];
if ( $do == "updated" ) {
message( "Váš profil byl úspěšně editován." );
}
}
$query = "SELECT * FROM `users` WHERE `ID` = '". $_SESSION[ "ID" ]. "'";
$result = mysql_query( $query, $dbc );
if ( mysql_num_rows( $result ) > 0 )
{
$row = mysql_fetch_row( $result );
if ( $row[ 4 ] == '' && $row[ 5 ] == '' && $row[ 6 ] == '' && $row[ 7 ] == '' ) {
message( 'Váš profil je prázdný.<br />'
.'<a href="?action=user&make=edit" title="Upravit profil">Upravit profil</a>' );
} else {
/*echo "Jméno: ". $row[ 4 ]. " ". $row[ 5 ]. "<br />";
echo "Email: ". $row[ 6 ]. "<br />";
echo "Telefon: ". $row[ 7 ]. "<br />";
echo '<a href="?action=user&make=edit" title="Upravit profil">Upravit profil</a>';*/
$smarty->assign( 'user_name', $row[ 4 ] );
$smarty->assign( 'user_surname', $row[ 5 ] );
$smarty->assign( 'user_email', $row[ 6 ] );
if ( !empty( $row[ 7 ] ) ) {
$phone = $row[ 7 ];
} else {
$phone = "-";
}
$smarty->assign( 'user_phone', $phone );
$smarty->display( 'user/user.tpl' );
}
} else {
message( "Váš profil nebyl nalezen.<br />Informujte o tom prosím systémového administrátora." );
}
} elseif ( $make == "edit" ) {
$query = "SELECT * FROM `users` WHERE `ID` = '". $_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=user&make=edit' );
if ( !isset( $_POST[ "save" ] ) ) {
$element =& HTML_QuickForm::createElement( 'text', 'name', 'Jméno:' );
$element->setValue( $row[ 4 ] );
$form->addElement( $element );
$element =& HTML_QuickForm::createElement( 'text', 'surname', 'Příjmení:' );
$element->setValue( $row[ 5 ] );
$form->addElement( $element );
$element =& HTML_QuickForm::createElement( 'text', 'email', 'Email:' );
$element->setValue( $row[ 6 ] );
$form->addElement( $element );
$element =& HTML_QuickForm::createElement( 'text', 'phone', 'Telefon:' );
$element->setValue( $row[ 7 ] );
$form->addElement( $element );
} else {
$form->addElement( 'text', 'name', 'Jméno:' );
$form->addElement( 'text', 'surname', 'Příjmení:' );
$form->addElement( 'text', 'email', 'Email:' );
$form->addElement( 'text', 'phone', 'Telefon:' );
}
$form->addElement( 'submit', 'save', 'Uložit' );
$form->addRule( 'name', 'Zadejte své jméno', 'required' );
$form->addRule( 'surname', 'Zadejte své příjmení', 'required' );
$form->addRule( 'email', 'Zadejte svůj email', 'required' );
$form->addRule( 'email', 'Zadejte email ve sprvné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( 'phone', 'Zadejte platné telefoní číslo', 'maxlenght', 16 );
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" ];
$surname = $v[ "surname" ];
$email = $v[ "email" ];
$phone = $v[ "phone" ];
$qr = "";
if ( !empty( $email ) ) {
$qr .= ", `email` = '$email'";
}
if ( !empty( $phone ) ) {
$qr .= ", `phone` = '$phone'";
}
$query = "UPDATE `users` SET `name` = '$name', `surname` = '$surname', `email` = '$email', `phone` = '$phone' WHERE ID = ". $_SESSION[ "ID" ];
$result = @mysql_query( $query, $dbc );
if ( $result ) {
header ( "Location: index.php?action=user&make=view&do=updated" );
} else {
message( "Omlouváme se, ale nastala systémová chyba." );
}
}
?>
ACC SHELL 2018