//
// 23-Feb-09 JRG Added edit and delete support to the page.
//
include "main_header.php";
include ( 'globals.php' );
include ( 'includes/utils.php' );
function nl2br2($string) {
$string = str_replace(array("\r\n", "\r", "\n"), "
", $string);
return $string;
}
function nl2br_skip_html($string)
{
// remove any carriage returns (mysql)
$string = str_replace("\r", '', $string);
// replace any newlines that aren't preceded by a > with a
$string = preg_replace('/(?)\n/', "
\n", $string);
return $string;
}
$l_connection = new mysqli($c_db_hostname, $c_db_username, $c_db_password, $c_db_database) or
die ( "Unable to connect to database." );
$p_image_id = $_GET["p_image_id"];
$submit = $_POST["submit"];
$p_comment = $_POST["p_comment"];
$p_image_comment_id = $_GET["p_image_comment_id"];
$p_edit_mode = $_GET["p_edit_mode"];
$p_delete_mode = $_GET["p_delete_mode"];
$offset = 0;
if ( isset ( $_GET["offset"] ) )
{
$offset = $_GET["offset"];
}
if ( ! isset ( $submit ) )
{
$submit = "";
}
if ( $submit == 'Update' )
{
$l_sql = "update user_aircraft_images set image_category_id = $p_image_category_id where id = $p_image_id";
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unable to update image category information." );
}
elseif ( $submit == 'Delete' )
{
$l_sql = "select i.id " .
"from user_aircraft_images i, user_aircraft ua " .
"where i.id=$p_image_id " .
"and ua.id = i.user_aircraft_id " .
"and ua.user_id = " . $_SESSION [ 'g_user_id' ];
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unable to delete(1) image." );
if ( $l_row = $l_result -> fetch_array(MYSQLI_ASSOC) )
{
$l_image_id = $l_row [ 'id' ];
$l_sql = "update user_aircraft_images set status = 0 where id = $l_image_id";
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unable to delete(2) image." );
}
}
elseif ( $submit == 'Make Default Image' )
{
$l_sql = "select ua.id " .
"from user_aircraft_images i, user_aircraft ua " .
"where i.id=$p_image_id " .
"and ua.id = i.user_aircraft_id " .
"and ua.user_id = " . $_SESSION [ 'g_user_id' ];
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unable to default(1) image." );
if ( $l_row = $l_result -> fetch_array(MYSQLI_ASSOC) )
{
$l_user_aircraft_id = $l_row [ 'id' ];
$l_sql = "update user_aircraft set image_id=$p_image_id where id = $l_user_aircraft_id";
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unable to delete(2) image." );
}
}
elseif ( $submit == 'Comment' )
{
$p_comment = mysqli_real_escape_string ( $l_connection, $p_comment );
$l_sql = "insert into image_comment " .
"(user_id, user_aircraft_image_id, comment, date_added, status) " .
"values (" . $_SESSION [ 'g_user_id' ] .
", $p_image_id, '$p_comment', sysdate(), 1)";
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unble to insert new image comment." );
}
elseif ( $submit == 'Save Changes')
{
$p_comment = mysqli_real_escape_string ( $l_connection, $p_comment );
$l_sql = "update image_comment set comment='$p_comment' where id=$p_image_comment_id and user_id=" . $_SESSION [ 'g_user_id' ];
$l_result = $l_connection -> query ( $l_sql ) or die ( "Unable to update your comment." );;
}
elseif ( $p_delete_mode == 1 )
{
$l_sql = "update image_comment " .
"set status = 0 " .
"where id = $p_image_comment_id " .
"and user_id = " . $_SESSION [ 'g_user_id' ];
$l_result = $l_connection -> query ( $l_sql ) or die ( "Unable to remove your comment." );
}
elseif ( isset ( $p_image_id ) )
{
//
// Update the image view counter for this image.
//
$l_sql = "update user_aircraft_images set view_count=view_count+1 where id = $p_image_id";
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unble to update image information." );
}
//
// Now get the details for the user who owns this image.
//
$l_sql = "select ua.aircraft_id, ua.id user_aircraft_id, u.id main_user_id, u.username main_username, " .
" i.view_count, i.comment, DATE_FORMAT(i.date_added, '$c_app_format_datetime' ) formatted_date_added, " .
" i.image_date, i.image_category_id, a.name aircraft_name, m.name manufacturer_name " .
"from user u, user_aircraft ua, user_aircraft_images i, aircraft a, manufacturer m " .
"where i.id = $p_image_id " .
"and ua.id = i.user_aircraft_id " .
"and u.id = ua.user_id " .
"and a.id = ua.aircraft_id " .
"and m.id = a.manufacturer_id";
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unable to read image information." );
$l_row = $l_result -> fetch_array(MYSQLI_ASSOC);
$l_user_id = $l_row [ 'main_user_id' ];
$l_username = $l_row [ 'main_username' ];
$l_view_count = $l_row [ 'view_count' ];
$l_comment = $l_row [ 'comment' ];
$l_date_added = $l_row [ 'formatted_date_added' ];
$l_image_date = $l_row [ 'image_date' ];
$l_image_category_id = $l_row [ 'image_category_id' ];
$l_aircraft_id = $l_row [ 'aircraft_id' ];
$l_user_aircraft_id = $l_row [ 'user_aircraft_id' ];
$l_manu_name = $l_row [ 'manufacturer_name' ];
$l_aircraft_name = $l_row [ 'aircraft_name' ];
$l_comment = clickable_link ( $l_comment );
//
// Find the next image for this aircraft.
//
$l_sql = "select * " .
"from user_aircraft_images i " .
"where i.id > $p_image_id " .
"and i.user_aircraft_id = $l_user_aircraft_id " .
"and i.status = 1 " .
"order by i.date_added ASC LIMIT 1";
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unble to read next image number." );
$l_row = $l_result -> fetch_array(MYSQLI_ASSOC);
$l_next_image = $l_row [ 'id' ];
//
// Find the prev image for this aircraft.
//
$l_sql = "select * " .
"from user_aircraft_images i " .
"where i.id < $p_image_id " .
"and i.user_aircraft_id = $l_user_aircraft_id " .
"and i.status = 1 " .
"order by i.date_added DESC LIMIT 1";
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unble to read prev image number." );
$l_row = $l_result -> fetch_array(MYSQLI_ASSOC);
$l_prev_image = $l_row [ 'id' ];
?>
| =$l_manu_name?> =$l_aircraft_name?> by =$l_username?>. Viewed =$l_view_count?> times. ">Build Thread |
|
![]() /* ![]() */ ?> |
|
//
// Now check to see if any comments have been made about this image.
//
$l_sql = "select c.id, c.user_id, c.comment, u.username, " .
" DATE_FORMAT(c.date_added, '$c_app_format_datetime' ) as date_added " .
"from image_comment c, user u " .
"where c.user_aircraft_image_id = $p_image_id " .
"and u.id = c.user_id " .
"and c.status = 1 ";
$l_result = $l_connection -> query ( $l_sql ) or
die ( "Unble to read image comment information." );
?>
|
//
// If we are logged in, let the user comment on the image.
//
if ( $p_edit_mode != 1 )
{
if ( $_SESSION [ 'g_logged_in' ] == 1 )
{
?>
}
else
{
?>
|
||||||||||||
include "main_footer.php"; ?>