ACC SHELL
<?php
$make = select( "make", "view" );
/*
* Vypsání seznamu položek s možností jejich zobrazení, editace či smazání. Také je zde možnost
* přidání nové položky.
*/
if ( $make == "view" ) {
/*
* Vypsání zprávy o úspěčně dokončené akci - přidání, smazání či editování položky.
* Probíhá zde také akce mazání položky (kůli výpisu názvu položky).
*/
$do = select( "do", "empty" );
if ( $do != "empty" )
{
$title = "";
$id = select( "id", -1 );
$find = FALSE;
/*
* Získání názvu položky - pokud není v databázi nalezen, nepřiřadí se do proměné $title nic,
* a název položky se v tom případě nevypíše.
*/
if ( $id != -1 )
{
$query = "SELECT title FROM `content` WHERE ID = $id";
$result = @mysql_query( $query, $dbc );
if ( @mysql_num_rows( $result ) > 0 )
{
$row = mysql_fetch_row( $result );
$title = " <strong>\"". $row[0]. "\"</strong>";
$find = TRUE;
}
}
if ( $do == "saved" )
{
message( "Položka$title byla úspěčně uložena" );
}
elseif ( $do == "updated" )
{
message( "Položka$title byla úpěšně editována" );
}
elseif ( $do == "deleted" )
{
/*
* Pokud byla položka nalezena, je smazána, pokud nebyla, není provedeno nic.
*/
if ( $find ) {
$query = "DELETE FROM `content` WHERE ID = $id";
$result = mysql_query( $query, $dbc );
if ( $result )
{
message( "Položka$title byla úpěšně smazána" );
}
else
{
message( "system_error", TRUE );
write_log( "\nSoubor: ". __FILE__. "\nŘádek : ". __LINE__. "\nChyba : ". mysql_error() );
}
}
}
}
$query = "SELECT * FROM `content` ORDER BY `order` ASC";
$result = mysql_query( $query, $dbc );
$table = array();
$i = -1;
if ( mysql_num_rows( $result ) > 0 )
{
while ( $row = mysql_fetch_row( $result ) )
{
$i++;
$table[ $i ][ 'id' ] = $row[ 0 ];
$table[ $i ][ 'title' ] = $row[ 1 ];
$table[ $i ][ 'display' ] = $row[ 3 ];
}
$smarty->assign( 'table', $table );
}
$smarty->display( 'admin/content_view.tpl' );
}
/*
* Vypsání obsahu položky bez možnosti přímé editace, ale s možností jejího smazání. Zde je
* položka "read-only".
*/
elseif ( $make == "viewcnt" )
{
$id = select( "id", -1 );
if ( $id != -1 ) {
$query = "SELECT * FROM `content` WHERE ID = $id";
$result = @mysql_query( $query, $dbc );
if ( @mysql_num_rows( $result ) > 0 ) {
$row = mysql_fetch_row( $result );
$smarty->assign( "ID", $row[ 0 ] );
$smarty->assign( "title", $row[ 1 ] );
$smarty->assign( "content", $row[ 2 ] );
$smarty->display( "admin/content_qview.tpl" );
} else {
message( "id_not_exist", TRUE );
}
} else {
message( "Nebylo zadáno ID položky kterou chcete zobrazit" );
}
}
/*
* Přidání nové položky.
*/
elseif ( $make == "add" )
{
/*
* Zpracování odeslaného formuláře.
*/
if ( isset( $_POST[ "submit" ] ) )
{
$correct = TRUE;
$message = "";
if ( empty( $_POST[ "title" ] ) ) {
$correct = FALSE;
$message .= "<p>Nebyl zadán název položky!</p>\n";
}
if ( empty( $_POST[ "content" ] ) ) {
$correct = FALSE;
$message .= "<p>Nebyl zadán obsah položky!</p>\n";
}
if ( $correct ) {
$title = htmlspecialchars( $_POST[ "title" ] );
$content = $_POST[ "content" ];
$show = ( $_POST[ "show"] == "on" )?1:0;
$query = "SELECT MAX(`order`) FROM `content`";
$result = mysql_query( $query, $dbc );
/*
* Určení pozice položky jako nejposlednější.
*/
if ( mysql_num_rows( $result ) > 0 )
{
$row = @mysql_fetch_array( $result );
$order = $row[ 0 ] + 1;
$query = "INSERT INTO `content` (`ID`,`title`,`content`,`display`,`order`) VALUES ('0','$title','$content','$show','". $order. "')";
}
else
{
$query = "INSERT INTO `content` (`ID`,`title`,`content`,`display`,`order`) VALUES ('0','$title','$content','$show','1')";
}
$result = @mysql_query( $query, $dbc );
if ( $result) {
$res = mysql_query( "SELECT ID FROM `content` ORDER BY ID DESC LIMIT 0,1", $dbc );
$row = mysql_fetch_array( $res );
header ( "Location: index.php?action=content&make=view&do=saved&id=$row[0]" );
} else {
echo "chyba:". mysql_error();
}
} else {
echo "\n". $message. "<p>Zkuste to znovu..</p>\n";
}
}
$smarty->assign( "title", $title );
$smarty->assign( "content", $_POST[ "content" ] );
/*
* Pokud byl přepínač už zapnut, a nebo pokud je stránka načtená poprvé tak přepínač
* zapnout.
*/
if ( $_POST[ "show"] == "on" || !isset( $_POST[ "submit" ] ) )
{
$smarty->assign( 'show', 'on' );
}
$smarty->display( "admin/content_add.tpl" );
}
elseif ( $make == "edit" )
{
$id = select( "id", -1 );
if ( isset( $_POST[ "submit" ] ) )
{
$correct = TRUE;
$message = "";
if ( empty( $_POST[ "title" ] ) )
{
$correct = FALSE;
$message .= "<p>Nebyl zadán nadpis položky!</p>\n";
}
if ( empty( $_POST[ "content" ] ) )
{
$correct = FALSE;
$message .= "<p>Nebyl zadán obsah položky!</p>\n";
}
if ( $correct )
{
$title = htmlspecialchars( $_POST[ "title" ] );
$content = $_POST[ "content" ];
$show = ( $_POST[ "show"] == "on" )?1:0;
$query = "UPDATE `content` SET `title` = '$title', `content` = '$content', `display` = $show WHERE ID = $id";
$result = @mysql_query( $query, $dbc );
if ( $result)
{
header ( "Location: index.php?action=content&make=view&do=updated&id=$id" );
}
else
{
message( "system_error", TRUE );
write_log( "\nSoubor: ". __FILE__. "\nŘádek : ". __LINE__. "\nChyba : ". mysql_error() );
}
}
else
{
echo "\n". $message. "<p>Zkuste to znovu..</p>\n";
}
}
if ( $id != -1 )
{
$query = "SELECT * FROM `content` WHERE ID = $id";
$result = mysql_query( $query, $dbc );
if ( mysql_num_rows( $result ) > 0 ) {
$row = mysql_fetch_row( $result );
if ( !isset( $_POST[ "submit" ] ) )
{
$title = $row[ 1 ];
$content = $row[ 2 ];
}
else
{
$title = $_POST[ "title" ];
$content = $_POST[ "content" ];
}
$smarty->assign( 'title', $title );
$smarty->assign( 'content', $content );
if ( $_POST[ "show"] == "on" || ( !isset( $_POST[ "submit" ] ) && $row[ 3 ] == 1 ) ) {
$smarty->assign( 'show', 'on' );
}
$smarty->display( "admin/content_add.tpl" );
}
else
{
message( "id_not_exist", TRUE );
}
}
else
{
message( "Nebylo zadáno ID položky kterou chcete editovat." );
}
}
elseif ( $make == "del" )
{
$id = select( "id", -1 );
if ( $id != -1 )
{
$query = "SELECT * FROM `content` WHERE ID = $id";
$result = mysql_query( $query, $dbc );
if ( mysql_num_rows( $result ) > 0 )
{
$row = mysql_fetch_array( $result, $dbc );
$smarty->assign( 'ID', $row[ 0 ] );
$smarty->assign( 'title', $row[ 1 ] );
$smarty->display( 'admin/content_del.tpl' );
}
else
{
message( "id_not_exist", TRUE );
}
}
else
{
message( "Nebylo zadáno ID položky kterou chcete smazat." );
}
}
elseif ( $make == "visible" )
{
$id = select( "id", -1 );
$do = select( "do", "show" );
if ( $id != -1 )
{
$query = "SELECT ID FROM `content` WHERE ID = $id";
$result = @mysql_query( $query, $dbc );
if ( @mysql_num_rows( $result ) > 0 )
{
if ( $do == "hide" )
{
$show = 0;
}
else
{
$show = 1;
}
$query = "UPDATE `content` SET `display` = $show WHERE ID = $id";
$result = @mysql_query( $query, $dbc );
if ( $result )
{
header ( "Location: index.php?action=content&make=view&do=updated&id=$id" );
}
else
{
message( "system_error", TRUE );
write_log( "\nSoubor: ". __FILE__. "\nŘádek : ". __LINE__. "\nChyba : ". mysql_error() );
}
}
else
{
message( "id_not_exist", TRUE );
}
}
else
{
if ( $do == "hide" )
{
$act = "zneviditelnit";
}
else
{
$act = "zviditelnit";
}
message( "Nebylo zadáno ID položky kterou chcete $act." );
}
}
elseif ( $make == "move" )
{
$id = select( "id", -1 );
$do = select( "do", "" );
if ( $id != -1 )
{
$query = "SELECT ID, `order` FROM `content` WHERE ID = $id";
$result = @mysql_query( $query, $dbc );
if ( @mysql_num_rows( $result ) > 0 )
{
if ( $do != "up" && $do != "down" )
{
message( "action_not_exist", TRUE );
}
else
{
if ( $do == "up" )
{
$row = mysql_fetch_array( $result );
$order = $row[ 1 ];
$query = "SELECT ID, `order` FROM `content` WHERE `order` < ". $order. " ORDER BY `order` DESC LIMIT 0,1";
$result = mysql_query( $query, $dbc );
if ( mysql_num_rows( $result ) > 0 ) {
$row = mysql_fetch_array( $result );
$old_id = $row[ 0 ];
$query = "UPDATE `content` SET `order` = ".$row[ 1 ]." WHERE ID = $id";
$result = mysql_query( $query, $dbc );
if ( $result )
{
$first = TRUE;
}
else
{
$first = FALSE;
}
$query = "UPDATE `content` SET `order` = ".$order." WHERE ID = ".$old_id;
$result = mysql_query( $query, $dbc );
if ( $result )
{
$second = TRUE;
}
else
{
$second = FALSE;
}
if ( $first && $second )
{
header ( "Location: index.php?action=content&make=view&do=updated&id=$id" );
}
else
{
message( "system_error", TRUE );
write_log( "\nSoubor: ". __FILE__. "\nŘádek : ". __LINE__. "\nChyba : ". mysql_error() );
}
}
else
{
message( "Položka již nemůže být posunuta výše." );
}
}
elseif ( $do == "down" )
{
$row = mysql_fetch_array( $result );
$order = $row[ 1 ];
$query = "SELECT ID, `order` FROM `content` WHERE `order` > ". $order. " ORDER BY `order` ASC LIMIT 0,1";
$result = mysql_query( $query, $dbc );
if ( mysql_num_rows( $result ) > 0 ) {
$row = mysql_fetch_array( $result );
$old_id = $row[ 0 ];
$query = "UPDATE `content` SET `order` = ".$row[ 1 ]." WHERE ID = $id";
$result = mysql_query( $query, $dbc );
if ( $result )
{
$first = TRUE;
}
else
{
$first = FALSE;
}
$query = "UPDATE `content` SET `order` = ".$order." WHERE ID = ".$old_id;
$result = mysql_query( $query, $dbc );
if ( $result )
{
$second = TRUE;
}
else
{
$second = FALSE;
}
if ( $first && $second )
{
header ( "Location: index.php?action=content&make=view&do=updated&id=$id" );
}
else
{
message( "system_error", TRUE );
write_log( "\nSoubor: ". __FILE__. "\nŘádek : ". __LINE__. "\nChyba : ". mysql_error() );
}
}
else
{
message( "Položka již nemůže být posunuta níže." );
}
}
}
}
else
{
message( "id_not_exist", TRUE );
}
}
else
{
$act = "";
if ( $do == "up" )
{
$act = "nahoru";
}
elseif ( $do == "down" )
{
$act = "dolů";
}
message( "Nebylo zadáno ID položky kterou chcete přesunout $act." );
}
}
else
{
message( "action_not_exist", TRUE );
}
?>
ACC SHELL 2018