rendered paste body<?php
/**
* Open-Realty
*
* Open-Realty is free software; you can redistribute it and/or modify
* it under the terms of the Open-Realty License as published by
* Transparent Technologies; either version 1 of the License, or
* (at your option) any later version.
*
* Open-Realty is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Open-Realty License for more details.
* http://www.open-realty.org/license_info.html
*
* You should have received a copy of the Open-Realty License
* along with Open-Realty; if not, write to Transparent Technologies
* RR1 Box 162C, Kingsley, PA 18826 USA
*
* @author Ryan C. Bonham <ryan@transparent-tech.com>
* @copyright Transparent Technologies 2004
* @link http://www.open-realty.org Open-Realty Project
* @link http://www.transparent-tech.com Transparent Technologies
* @link http://www.open-realty.org/license_info.html Open-Realty License
*/
// Set Error Handling to E_ALL
class image_handler {
var $debug = false;
function exec_curl($array)
{
$array = @explode("?", $array);
$link = curl_init();
curl_setopt($link, CURLOPT_URL, $array[0]);
curl_setopt($link, CURLOPT_VERBOSE, 0);
curl_setopt($link, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($link, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($link, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($link, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($link, CURLOPT_MAXREDIRS, 6);
curl_setopt($link, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($link, CURLOPT_TIMEOUT, 60);
$results = curl_exec($link);
if (curl_errno($link) > 0) {
curl_close($link);
return false;
}
curl_close($link);
return $results;
}
function save_remote_file($url, $id, $type = 'listings', $owner, $replace_image = false, $append_file_name = false, $caption='', $description='')
{
error_reporting(E_ALL ^ E_WARNING);
// deals with incoming uploads
global $config, $conn;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
// Get file name from URL and remove any bad filename chars.
$url_parts = explode('/', $url);
$num = count($url_parts)-1;
$file_name = $url_parts[$num];
$badchararray = array(" ", "'", "\"", "$", "&", "%", "-", "#", "^", "*", "(", ")", "~", "@", "/", "?", "=");
$file_name = str_replace($badchararray, "", $file_name);
$file_name = stripslashes(strtolower($file_name));
if ($append_file_name == true) {
$save_name = $id . '_' . $file_name;
}else {
$save_name = $file_name;
}
// Now that we know the filename check if the file exist. If it does do not redownload the image.
if (file_exists($config["listings_upload_path"] . '/' . $save_name) && $replace_image == false) {
$thumb_name = 'thumb_' . $save_name;
// Get Max Image Rank
$sql = "SELECT MAX(listingsimages_rank) AS max_rank FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsdb_id = '$id')";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$rank = $recordSet->fields['max_rank'];
$rank++;
$caption = $misc->make_db_safe($caption);
$description = $misc->make_db_safe($description);
$sql = "INSERT INTO " . $config['table_prefix'] . "listingsimages (listingsdb_id, userdb_id, listingsimages_file_name, listingsimages_thumb_file_name,listingsimages_rank,listingsimages_caption,listingsimages_description) VALUES ('$id', '$owner', '$save_name', '$thumb_name',$rank,$caption,$description)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
return true;
}
// Image doesn't exist locally yet, so get it.
if (!ini_get('allow_url_fopen')) {
$imagecontent = $this->exec_curl($url);
}else {
$imagecontent = file_get_contents($url);
}
// Check to see if image existed on the remote server, if not skip it.
if ($imagecontent === false) {
return false;
}
// Ok we have a good file, so now lets save it.
$handle = fopen($config["listings_upload_path"] . '/' . $save_name, "wb");
fwrite($handle, $imagecontent);
fclose($handle);
// Verify File type
$extension = substr(strrchr($save_name, "."), 1);
if (!in_array($extension, explode(',', $config['allowed_upload_extensions']))) {
unlink($config["listings_upload_path"] . '/' . $save_name);
return false;
}
if (exif_imagetype($config["listings_upload_path"] . '/' . $save_name) === false) {
unlink($config["listings_upload_path"] . '/' . $save_name);
return false;
}
// Image is saved, check file widht/height.
// $imagedata = GetImageSize($config["listings_upload_path"].'/'.$save_name);
// $imagewidth = $imagedata[0];
// $imageheight = $imagedata[1];
$thumb_name = $save_name; // by default -- no difference... unless...
// Make the thumbnial image.
if ($config['make_thumbnail'] == '1') {
// if the option to make a thumbnail is activated...
$make_thumb = 'make_thumb_' . $config['thumbnail_prog'];
$thumb_name = $this->$make_thumb ($save_name, $config['listings_upload_path']);
} // end if $config[make_thumbnail] === "1"
// Get highest image rank from current db.
$sql = "SELECT MAX(listingsimages_rank) AS max_rank FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsdb_id = '$id')";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$rank = $recordSet->fields['max_rank'];
$rank++;
// Insert image with next highest rank.
$sql = "INSERT INTO " . $config['table_prefix'] . "listingsimages (listingsdb_id, userdb_id, listingsimages_file_name, listingsimages_thumb_file_name,listingsimages_rank) VALUES ('$id', '$owner', '$save_name', '$thumb_name',$rank)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
return true;
}
function renderUserImages($user)
{
// grabs the listings for a given user
global $conn, $config, $lang;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$display = '';
$user = $misc->make_db_safe($user);
// grab the images
$sql = "SELECT userimages_id, userimages_caption, userimages_thumb_file_name FROM " . $config['table_prefix'] . "userimages WHERE userdb_id = $user ORDER BY userimages_rank";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$num_images = $recordSet->RecordCount();
if ($num_images > 0) {
while (!$recordSet->EOF) {
$caption = $misc->make_db_unsafe ($recordSet->fields['userimages_caption']);
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['userimages_thumb_file_name']);
// $file_name = $misc->make_db_unsafe ($recordSet->fields['userimages_file_name']);
$imageID = $misc->make_db_unsafe ($recordSet->fields['userimages_id']);
// gotta grab the image size
$imagedata = GetImageSize("$config[user_upload_path]/$thumb_file_name");
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$shrinkage = $config['thumbnail_width'] / $imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
$display .= "<a href=\"index.php?action=view_user_image&image_id=$imageID\"> ";
$display .= "<img src=\"$config[user_view_images_path]/$thumb_file_name\" height=\"$displayheight\" width=\"$displaywidth\"></a><br /> ";
$display .= "<b>$caption</b><br /><br />";
$recordSet->MoveNext();
}
}else {
$display .= "<img src=\"images/nophoto.gif\" alt=\"\" /><br />";
} // end ($num_images > 0)
return $display;
} // end function renderUserImages
function get_image_caption()
{
global $conn, $config, $lang;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$sql_imageID = $misc->make_db_safe($_GET['image_id']);
$sql = "SELECT listingsimages_caption FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsimages_id = $sql_imageID)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$caption = $misc->make_db_unsafe ($recordSet->fields['listingsimages_caption']);
return $caption;
}
function view_image($type)
{
global $conn, $config, $lang;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$display = '';
if (!isset($_GET['image_id'])) {
return $lang['image_not_found'];
}
$sql_imageID = $misc->make_db_safe($_GET['image_id']);
if ($type == "listing") {
// get the image data
$sql = "SELECT listingsimages_caption, listingsimages_file_name, listingsimages_description, listingsdb_id FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsimages_id = $sql_imageID)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
} while (!$recordSet->EOF) {
$caption = $misc->make_db_unsafe ($recordSet->fields['listingsimages_caption']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_file_name']);
$description = $misc->make_db_unsafe ($recordSet->fields['listingsimages_description']);
$listing_id = $misc->make_db_unsafe ($recordSet->fields['listingsdb_id']);
$recordSet->MoveNext();
}
$display .= '<div class="view_image">';
$display .= '<span class="image_caption">';
if ($caption != "") {
$display .= "$caption - ";
}
$display .= '<a href="index.php?action=listingview&listingID=' . $listing_id . '">' . $lang['return_to_listing'] . '</a></span><br />';
$display .= '<img src="' . $config['listings_view_images_path'] . '/' . $file_name . '" alt="' . $caption . '" />';
$display .= '<br />';
$display .= $description ;
$display .= '</div>';
} // end if ($type == "listing")
elseif ($type == "userimage") {
// get the image data
$sql = "SELECT userimages_caption, userimages_file_name, userimages_description, userdb_id FROM " . $config['table_prefix'] . "userimages WHERE (userimages_id = $sql_imageID)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
} while (!$recordSet->EOF) {
$caption = $misc->make_db_unsafe ($recordSet->fields['userimages_caption']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['userimages_file_name']);
$description = $misc->make_db_unsafe ($recordSet->fields['userimages_description']);
$user_id = $recordSet->fields['userdb_id'];
$recordSet->MoveNext();
}
$display .= '<table class="form_" align="center">';
$display .= '<tr>';
$display .= ' <td class="row_main">';
$display .= ' <h3>';
if ($caption != "") {
$display .= "$caption - ";
}
$display .= '<a href="index.php?action=view_user&user=' . $user_id . '">' . $lang['return_to_user'] . '</a></h3>';
$display .= ' <center>';
$display .= ' <img src="' . $config['user_view_images_path'] . '/' . $file_name . '" alt="' . $caption . '" border="1">';
$display .= ' </center>';
$display .= ' <br />';
$display .= $description;
$display .= ' </td>';
$display .= '</tr>';
$display .= '</table>';
} // end if ($type == "listing")
return $display;
}
function edit_listing_images()
{
global $lang, $conn, $config;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$display = '';
$edit = $_POST['edit'];
$sql_edit = $misc->make_db_safe($_POST['edit']);
if (!isset($_POST['action'])) {
$_POST['action'] = '';
}
// does this person have access to these listings?
if (($_SESSION['edit_all_listings'] != "yes") && ($_SESSION['admin_privs'] != "yes")) {
$sql = "SELECT userdb_id FROM " . $config['table_prefix'] . "listingsdb WHERE (listingsdb_id = $sql_edit)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
} while (!$recordSet->EOF) {
$owner = $recordSet->fields['userdb_id'];
$recordSet->MoveNext();
}
if ($_SESSION['userID'] != $owner) {
die ($_SESSION['edit_all_listings']);
}
} // end priv check
if ($_POST['action'] == "update_pic") {
$sql_edit = $misc->make_db_safe($_POST['edit']);
$sql_caption = $misc->make_db_safe($_POST['caption']);
$sql_description = $misc->make_db_safe($_POST['description']);
$sql_rank = $misc->make_db_safe($_POST['rank']);
$sql_pic = $misc->make_db_safe($_POST['pic']);
if ($_SESSION['edit_all_listings'] == "yes") {
$sql = "UPDATE " . $config['table_prefix'] . "listingsimages SET listingsimages_caption = $sql_caption, listingsimages_description = $sql_description, listingsimages_rank = $sql_rank WHERE ((listingsdb_id = $sql_edit) AND (listingsimages_file_name = $sql_pic))";
}else {
$sql = "UPDATE " . $config['table_prefix'] . "listingsimages SET listingsimages_caption = $sql_caption, listingsimages_description = $sql_description, listingsimages_rank = $sql_rank WHERE ((listingsdb_id = $sql_edit) AND (listingsimages_file_name = $sql_pic) AND (userdb_id = $_SESSION[userID]))";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$display .= "<p>$lang[image] '$_POST[pic]' $lang[has_been_updated]</p>";
$misc->log_action ($lang['log_updated_listing_image'] . $_POST['pic']);
}
if ($_POST['action'] == "delete_pic") {
// get the data for the pic being deleted
$sql_pic_id = $misc->make_db_safe($_POST['pic_id']);
if ($_SESSION['edit_all_listings'] == "yes") {
$sql = "SELECT listingsimages_file_name, listingsimages_thumb_file_name FROM " . $config['table_prefix'] . "listingsimages WHERE ((listingsdb_id = $sql_edit) AND (listingsimages_id = $sql_pic_id))";
}else {
$sql = "SELECT listingsimages_file_name, listingsimages_thumb_file_name FROM " . $config['table_prefix'] . "listingsimages WHERE ((listingsdb_id = $sql_edit) AND (listingsimages_id = $sql_pic_id) AND (userdb_id = $_SESSION[userID]))";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
} while (!$recordSet->EOF) {
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_thumb_file_name']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_file_name']);
$recordSet->MoveNext();
} // end while
// delete from the db
if ($_SESSION['edit_all_listings'] == "yes") {
$sql = "DELETE FROM " . $config['table_prefix'] . "listingsimages WHERE ((listingsdb_id = $sql_edit) AND (listingsimages_file_name = '$file_name'))";
}else {
$sql = "DELETE FROM " . $config['table_prefix'] . "listingsimages WHERE ((listingsdb_id = $sql_edit) AND (listingsimages_file_name = '$file_name') AND (userdb_id = '$_SESSION[userID]'))";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
// delete the files themselves
// on widows, required php 4.11 or better (I think)
if (!unlink("$config[listings_upload_path]/$file_name")) die("$lang[alert_site_admin]");
if ($file_name != $thumb_file_name) {
if (!unlink("$config[listings_upload_path]/$thumb_file_name")) die("$lang[alert_site_admin]");
}
$misc->log_action ("$lang[log_deleted_listing_image] $file_name");
$display .= "<p>$lang[image] '$file_name' $lang[has_been_deleted]</p>";
}
if ($_POST['action'] == "upload") {
if ($_SESSION['edit_all_listings'] == "yes") {
// get the owner of the listing
$sql = "SELECT userdb_id FROM " . $config['table_prefix'] . "listingsdb WHERE (listingsdb_id = $sql_edit)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
} while (!$recordSet->EOF) {
$owner = $recordSet->fields['userdb_id'];
$recordSet->MoveNext();
}
$display .= $this->handleUpload("listings", $edit, $owner);
}else {
$display .= $this->handleUpload("listings", $edit, $_SESSION['userID']);
}
} // end if $action == "upload"
if ($_SESSION['edit_all_listings'] == "yes") {
$sql = "SELECT listingsimages_id, listingsimages_caption, listingsimages_file_name, listingsimages_thumb_file_name, listingsimages_description, listingsimages_rank FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsdb_id = $sql_edit) ORDER BY listingsimages_rank";
}else {
$sql = "SELECT listingsimages_id, listingsimages_caption, listingsimages_file_name, listingsimages_thumb_file_name, listingsimages_description, listingsimages_rank FROM " . $config['table_prefix'] . "listingsimages WHERE ((listingsdb_id = $sql_edit) AND (userdb_id = '$_SESSION[userID]')) ORDER BY listingsimages_rank";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$num_images = $recordSet->RecordCount();
$avaliable_iamges = $config["max_listings_uploads"] - $num_images;
$x = 0;
if ($num_images < $config['max_listings_uploads']) {
$display .= '<table border=0 cellspacing=0 cellpadding=0>';
$display .= '<tr>';
$display .= '<td colspan="2">';
$display .= '<h3>' . $lang['upload_a_picture'] . '</h3>';
$display .= '</td>';
$display .= '</tr>';
$display .= '<tr>';
$display .= '<td width="150"> </td>';
$display .= '<td>';
$display .= '<form enctype="multipart/form-data" action="index.php?action=edit_listing_images" method="post">';
$display .= '<input type="hidden" name="action" value="upload">';
$display .= '<input type="hidden" name="edit" value="' . $edit . '">';
$display .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . $config['max_listings_upload_size'] . '">';
while ($x < $avaliable_iamges) {
$display .= '<b>' . $lang['upload_send_this_file'] . ': </b><input name="userfile[]" type="file" /><br />';
$x++;
}
$display .= '<input type="submit" value="' . $lang['upload_send_file'] . '">';
$display .= '</form>';
$display .= '</td>';
$display .= '</tr>';
$display .= '</table>';
} // end if $num_images <= $config[max_user_uploads]
$display .= '<table class="image_upload">';
$display .= '<tr>';
$display .= '<td colspan="2">';
$display .= '<h3>' . $lang['edit_images'] . ' -- ';
if ($_SESSION['edit_all_listings'] == "yes") {
$display .= "<a href=\"index.php?action=edit_listings&edit=$edit\">";
}else {
$display .= "<a href=\"index.php?action=edit_my_listings&edit=$edit\">";
}
$display .= $lang['return_to_editing_listing'];
$display .= '</a></h3></td></tr>';
$count = 0;
while (!$recordSet->EOF) {
// $edit = $misc->make_db_safe($_POST['edit']);
$pic_id = $recordSet->fields['listingsimages_id'];
$rank = $recordSet->fields['listingsimages_rank'];
$caption = $misc->make_db_unsafe ($recordSet->fields['listingsimages_caption']);
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_thumb_file_name']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_file_name']);
$description = $misc->make_db_unsafe ($recordSet->fields['listingsimages_description']);
// gotta grab the image size
$imagedata = GetImageSize("$config[listings_upload_path]/$file_name");
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$shrinkage = $config['thumbnail_width'] / $imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
$filesize = filesize("$config[listings_upload_path]/$file_name");
$filesize = $filesize / 1000; // to get k
// now grab the thumbnail data
$thumb_imagedata = GetImageSize("$config[listings_upload_path]/$thumb_file_name");
$thumb_imagewidth = $thumb_imagedata[0];
$thumb_imageheight = $thumb_imagedata[1];
$thumb_filesize = filesize("$config[listings_upload_path]/$thumb_file_name");
$thumb_filesize = $thumb_filesize / 1000;
// alternate the colors
if ($count == 0) {
$count = 1;
}else {
$count = 0;
}
$display .= "<tr class=\"image_row_$count\"><td valign=\"top\" class=\"image_row_$count\" width=\"150\"><b>$file_name</b><br />$lang[width]=$imagewidth<br />$lang[height]=$imageheight<br />$lang[size]=$filesize" . "k<br />";
$display .= "<br />$lang[thumbnail]:<br />";
$display .= "<img src=\"$config[listings_view_images_path]/$thumb_file_name\" height=\"$displayheight\" width=\"$displaywidth\" border=\"1\"> ";
$display .= "<br />$lang[width]=$thumb_imagewidth<br />$lang[height]=$thumb_imageheight<br />$lang[size]=$thumb_filesize" . "k<br />";
$display .= "<p align=\"center\"><form action=\"$config[baseurl]/admin/index.php?action=edit_listing_images\" method=\"post\" name=\"delForm$pic_id\"><input type=\"hidden\" name=\"action\" value=\"delete_pic\" /><input type=\"hidden\" name=\"pic_id\" value=\"$pic_id\" /><input type=\"hidden\" name=\"edit\" value=\"$_POST[edit]\" /><a href=\"javascript:document.delForm$pic_id.submit()\">$lang[delete]</a></form>";
$display .= "</td><td align=\"center\" class=\"image_row_$count\"><img src=\"$config[listings_view_images_path]/$file_name\" border=\"1\">";
$display .= "</tr><tr><td align=\"center\" class=\"image_row_$count\" colspan=\"2\"><form action=\"index.php?action=edit_listing_images\" method=\"post\">";
$display .= "<input type=\"hidden\" name=\"edit\" value=\"$edit\">";
$display .= "<input type=\"hidden\" name=\"action\" value=\"update_pic\">";
$display .= "<input type=\"hidden\" name=\"pic\" value=\"$file_name\">";
$display .= "<table border=\"0\">";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><b>$lang[admin_template_editor_field_rank]:</b></td><td align=\"left\"><input type=\"text\" name=\"rank\" value=\"$rank\"><div class=\"small\">$lang[upload_rank_explanation]</div></td></tr>";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><b>$lang[upload_caption]:</b></td><td align=\"left\"><input type=\"text\" name=\"caption\" value=\"$caption\"></td></tr>";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><b>$lang[upload_description]:</b><td align=\"left\"><textarea name=\"description\" rows=\"6\" cols=\"40\">$description</textarea></td></tr>";
$display .= "<tr><td align=\"center\" class=\"image_row_$count\" colspan=\"2\"><input type=\"submit\" value=\"$lang[update]\">";
$display .= "</form></td></tr>";
$display .= "</table>";
$display .= "</td></tr><tr><td colspan=\"2\"><hr></td></tr>";
$recordSet->MoveNext();
} // end while
$display .= "</table>";
return $display;
}
function edit_user_images()
{
global $config, $lang, $conn;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$display = '';
if (!isset($_POST['action'])) {
$_POST['action'] = '';
}
if ($_POST['action'] == "update_pic") {
if ($_SESSION['edit_all_users'] == "yes") {
$sql = "UPDATE " . $config['table_prefix'] . "userimages SET userimages_caption = '$_POST[caption]', userimages_description = '$_POST[description]', userimages_rank = '$_POST[rank]' WHERE ((userdb_id = '$_POST[edit]') AND (userimages_file_name = '$_POST[pic]'))";
}else {
$sql = "UPDATE " . $config['table_prefix'] . "userimages SET userimages_caption = '$_POST[caption]', userimages_description = '$_POST[description]', userimages_rank = '$_POST[rank]' WHERE ((userimages_file_name = '$_POST[pic]') AND (userdb_id = '$_SESSION[userID] '))";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$misc->log_action ("$lang[log_updated_user_image] $_POST[pic]");
$display .= "<p>$lang[image] '$_POST[pic]' $lang[has_been_updated]</p>";
}
if ($_POST['action'] == "delete_pic") {
// get the data for the pic being deleted
$sql_pic_id = $misc->make_db_safe($_POST['pic_id']);
if ($_SESSION['edit_all_users'] == "yes") {
$sql = "SELECT userimages_file_name, userimages_thumb_file_name FROM " . $config['table_prefix'] . "userimages WHERE ((userdb_id = '$_POST[edit]') AND (userimages_id = $sql_pic_id))";
}else {
$sql = "SELECT userimages_file_name, userimages_thumb_file_name FROM " . $config['table_prefix'] . "userimages WHERE ((userimages_id = $sql_pic_id) AND (userdb_id = '$_SESSION[userID]'))";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
} while (!$recordSet->EOF) {
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['userimages_thumb_file_name']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['userimages_file_name']);
if ($this->debug) {
$display .= 'File Name: ' . $file_name . '<br />';
$display .= 'Thumbnail Name: ' . $thumb_file_name . '<br />';
}
$recordSet->MoveNext();
} // end while
// delete from the db
if ($_SESSION['edit_all_users'] == "yes") {
$sql = "DELETE FROM " . $config['table_prefix'] . "userimages WHERE ((userdb_id = '$_POST[edit]') AND (userimages_file_name = '$file_name'))";
}else {
$sql = "DELETE FROM " . $config['table_prefix'] . "userimages WHERE ((userimages_file_name = '$file_name') AND (userdb_id = '$_SESSION[userID]'))";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
// delete the files themselves
// on widows, required php 4.11 or better (I think)
if (!unlink("$config[user_upload_path]/$file_name")) {
die("$lang[alert_site_admin]");
}
if ($thumb_file_name != $file_name) {
// if (substr("$thumb_file_name", -3) == "jpg" || substr("$thumb_file_name", -3) == "png")
// {
if (!unlink("$config[user_upload_path]/$thumb_file_name")) {
die("$lang[alert_site_admin]");
}else {
$display .= "<p>$lang[image] '$thumb_file_name' $lang[has_been_deleted]</p>";
}
// }
}
$misc->log_action ("$lang[log_deleted_user_image] $file_name");
$display .= "<p>$lang[image] '$file_name' $lang[has_been_deleted]</p>";
}
if ($_POST['action'] == "upload") {
if ($_SESSION['edit_all_users'] == "yes") {
$display .= $this->handleUpload("user", '', $_POST['edit']);
}else {
$display .= $this->handleUpload("user", '', $_SESSION['userID']);
}
} // end if $action == "upload"
if ($_SESSION['edit_all_users'] == "yes") {
if (!isset($_POST['edit'])) {
if (isset($_POST['edit'])) {
$_POST['edit'] = $_POST['edit'];
}else {
$display .= 'Error in calling function. You forgot to pass the ID to edit';
}
}
$sql = "SELECT userimages_id, userimages_caption, userimages_file_name, userimages_thumb_file_name, userimages_description, userimages_rank FROM " . $config['table_prefix'] . "userimages WHERE (userdb_id = '$_POST[edit]') ORDER BY userimages_rank";
}else {
$sql = "SELECT userimages_id, userimages_caption, userimages_file_name, userimages_thumb_file_name, userimages_description, userimages_rank FROM " . $config['table_prefix'] . "userimages WHERE ((userdb_id = '$_SESSION[userID]')) ORDER BY userimages_rank";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$num_images = $recordSet->RecordCount();
$avaliable_iamges = $config["max_user_uploads"] - $num_images;
$x = 0;
if ($num_images < $config['max_user_uploads']) {
$display .= '<table border=0 cellspacing=0 cellpadding=0>';
$display .= '<tr>';
$display .= '<td colspan="2">';
$display .= '<h3>' . $lang['upload_a_picture'] . '</h3>';
$display .= '</td>';
$display .= '</tr>';
$display .= '<tr>';
$display .= '<td width="150"> </td>';
$display .= '<td>';
$display .= '<form enctype="multipart/form-data" action="index.php?action=edit_user_images" method="post">';
$display .= '<input type="hidden" name="action" value="upload" />';
$display .= '<input type="hidden" name="edit" value="' . $_POST['edit'] . '" />';
$display .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . $config['max_user_upload_size'] . '" />';
$display .= '<input type="hidden" name="caption" value=" " />';
while ($x < $avaliable_iamges) {
$display .= '<strong>' . $lang['upload_send_this_file'] . ': </strong><input name="userfile[]" type="file"><br />';
$x++;
}
$display .= '<input type="submit" name="upload_image" value="' . $lang['upload_send_file'] . '" />';
$display .= '</form>';
$display .= '</td>';
$display .= '</tr>';
$display .= '</table>';
} // end if $num_images <= $config[max_user_uploads]
$display .= ' <table class="admin_main">';
$display .= '<tr><td colspan="2" class="row_main"><form action="' . $config['baseurl'] . '/admin/index.php?action=user_manager&edit=' . $_POST['edit'] . '" method="post" name="editMyUser"><h3>' . $lang['edit_images'] . ' --';
$display .= '<a href="javascript:document.editMyUser.submit()">';
$display .= $lang['return_to_editing_account'];
$display .= '</a></h3></form></td></tr>';
$count = 0;
while (!$recordSet->EOF) {
$pic_id = $recordSet->fields['userimages_id'];
$rank = $recordSet->fields['userimages_rank'];
$caption = $misc->make_db_unsafe ($recordSet->fields['userimages_caption']);
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['userimages_thumb_file_name']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['userimages_file_name']);
$description = $misc->make_db_unsafe ($recordSet->fields['userimages_description']);
// gotta grab the image size
$imagedata = GetImageSize("$config[user_upload_path]/$file_name");
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$shrinkage = $config['thumbnail_width'] / $imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
$filesize = filesize("$config[user_upload_path]/$file_name");
$filesize = $filesize / 1000; // to get k
// now grab the thumbnail data
$thumb_imagedata = GetImageSize("$config[user_upload_path]/$thumb_file_name");
$thumb_imagewidth = $thumb_imagedata[0];
$thumb_imageheight = $thumb_imagedata[1];
$thumb_filesize = filesize("$config[user_upload_path]/$thumb_file_name");
$thumb_filesize = $thumb_filesize / 1000;
// alternate the colors
if ($count == 0) {
$count = $count + 1;
}else {
$count = 0;
}
$display .= "<tr class=\"image_row_$count\"><td valign=\"top\" class=\"image_row_$count\" width=\"150\"><strong>$file_name</strong><br />$lang[width]=$imagewidth<br />$lang[height]=$imageheight<br />$lang[size]=$filesize" . "k<br />";
$display .= "<br />$lang[thumbnail]:<br />";
$display .= "<img src=\"$config[user_view_images_path]/$thumb_file_name\" height=\"$displayheight\" width=\"$displaywidth\" border=\"1\" /> ";
$display .= "<br />$lang[width]=$thumb_imagewidth<br />$lang[height]=$thumb_imageheight<br />$lang[size]=$thumb_filesize" . "k<br />";
// $display .= "<p align=\"center\"><form action=\"$config[baseurl]/admin/index.php?action=edit_user_images\" method=\"post\" name=\"delForm\"><input type=\"hidden\" name=\"action\" value=\"delete_pic\" /><input type=\"hidden\" name=\"edit\" value=\"$_POST[edit]\" /><a href=\"javascript:document.delForm.submit()\">Delete</a></form>";
$display .= "<p align=\"center\"><form action=\"$config[baseurl]/admin/index.php?action=edit_user_images\" method=\"post\" name=\"delForm$pic_id\"><input type=\"hidden\" name=\"action\" value=\"delete_pic\" /><input type=\"hidden\" name=\"pic_id\" value=\"$pic_id\" /><input type=\"hidden\" name=\"edit\" value=\"$_POST[edit]\" /><a href=\"javascript:document.delForm$pic_id.submit()\">$lang[delete]</a></form>";
$display .= "</td><td align=\"center\" class=\"image_row_$count\"><img src=\"$config[user_view_images_path]/$file_name\" border=\"1\" />";
$display .= "</tr><tr><td align=\"center\" class=\"image_row_$count\" colspan=\"2\"><form action=\"index.php?action=edit_user_images&edit=$_POST[edit]&pic_id=$pic_id\" method=\"post\">";
$display .= "<input type=\"hidden\" name=\"edit\" value=\"$_POST[edit]\" />";
$display .= "<input type=\"hidden\" name=\"action\" value=\"update_pic\" />";
$display .= "<input type=\"hidden\" name=\"pic\" value=\"$file_name\" />";
$display .= "<table border=\"0\">";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><strong>$lang[admin_template_editor_field_rank]:</strong></td><td align=\"left\"><input type=\"text\" name=\"rank\" value=\"$rank\" /><div class=\"small\">$lang[upload_rank_explanation]</div></td></tr>";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><strong>$lang[upload_caption]:</strong></td><td align=\"left\"><input type=\"text\" name=\"caption\" value=\"$caption\" /></td></tr>";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><strong>$lang[upload_description]:</strong><td align=\"left\"><textarea name=\"description\" rows=\"6\" cols=\"40\">$description</textarea></td></tr>";
$display .= "<tr><td align=\"center\" class=\"image_row_$count\" colspan=\"2\"><input type=\"submit\" name=\"update_image\" value=\"$lang[update]\" />";
$display .= "</form></td></tr>";
$display .= "</table>";
$display .= "</td></tr><tr><td colspan=\"2\"><hr></td></tr>";
$recordSet->MoveNext();
} // end while
$display .= "</table>";
return $display;
}
function renderListingsMainImageSlideShow($listingID)
{
// shows the images connected to a given image
global $conn, $lang, $config;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
// grab the images
$listingID = $misc->make_db_extra_safe($listingID);
$sql = "SELECT listingsimages_id,listingsimages_file_name FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsdb_id = $listingID) ORDER BY listingsimages_rank";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$width = "500";
if ($config["max_listings_upload_width"] < 500 && $config['resize_img'] == '1') {
}
$num_images = $recordSet->RecordCount();
$output = '';
if ($num_images > 0) {
$output .= '<script type="text/javascript" src="'
. $config['baseurl'] . '/slideshow.js"></script>
<script type="text/javascript"><!--
SLIDES = new slideshow("SLIDES");
';
while (!$recordSet->EOF) {
// $caption = $misc->make_db_unsafe ($recordSet->fields['listingsimages_caption']);
// $thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_thumb_file_name']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_file_name']);
$imageID = $misc->make_db_unsafe ($recordSet->fields['listingsimages_id']);
$imagedata = GetImageSize("$config[listings_upload_path]/$file_name");
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$shrinkage = $width / $imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
if ($config['url_style'] == '1') {
$url = 'index.php?action=view_listing_image&image_id=' . $imageID;
}else {
$url = 'listing_image_' . $imageID . '.html';
}
$output .= 's = new slide();
s.src = "' . $config['listings_view_images_path'] . '/' . $file_name . '";
s.width = "' . $displaywidth . '";
s.height = "' . $displayheight . '";
s.alt = "' . $file_name . '";
s.text = unescape("");
s.link = "' . $url . '";
s.target = "";
s.attr = "";
s.filter = "";
SLIDES.add_slide(s);
';
$recordSet->MoveNext();
} // end while
$output .= '--></script>';
$output .= '<div class="slideshow_img"><a href="javascript:SLIDES.hotlink()"><img id="SLIDESIMG" src="image.jpg" width="'.$width.'" style="border:none;filter:progid:DXImageTransform.Microsoft.Fade()" alt="Slideshow image" /></a></div>
<div class="slideshow_links"><a href="javascript:;" onclick="SLIDES.previous()">Previous</a>
<a href="javascript:;" onclick="SLIDES.play()">Play</a>
<a href="javascript:;" onclick="SLIDES.pause()">Pause</a>
<a href="javascript:;" onclick="SLIDES.next()">Next</a></div>';
$output .= '<script type="text/javascript">
<!--
if (document.images) {
SLIDES.image = document.images.SLIDESIMG;
//SLIDES.textid = "SLIDESTEXT";
SLIDES.update();
}
//-->
</script>';
} // end if ($num_images > 0)
else {
if ($config['show_no_photo'] == 1) {
$output .= '<div class="slideshow_img"><img src="images/nophotobig.gif"></div>';
}
}
return $output;
} // end function renderListingsMainImageSlideShow
function renderListingsImages($listingID, $showcap)
{
// shows the images connected to a given image
global $conn, $lang, $config;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
// grab the images
$listingID = $misc->make_db_extra_safe($listingID);
$sql = "SELECT listingsimages_id, listingsimages_caption, listingsimages_thumb_file_name FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsdb_id = $listingID) ORDER BY listingsimages_rank";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
log_error($sql);
}
$display = '';
$num_images = $recordSet->RecordCount();
if ($num_images > 0) {
// $display .= "<td width=\"$style[image_column_width]\" valign=\"top\" class=\"row_main\" align=\"center\">";
$display .= "<strong>$lang[images]</strong><br /><hr style=\"width:75%;\" />";
while (!$recordSet->EOF) {
$caption = $misc->make_db_unsafe ($recordSet->fields['listingsimages_caption']);
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_thumb_file_name']);
// $file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_file_name']);
$imageID = $misc->make_db_unsafe ($recordSet->fields['listingsimages_id']);
if ($thumb_file_name != "" && file_exists("$config[listings_upload_path]/$thumb_file_name")) {
$imagedata = GetImageSize("$config[listings_upload_path]/$thumb_file_name");
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$shrinkage = $config['thumbnail_width'] / $imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
if ($config['url_style'] == '1') {
$display .= '<a href="index.php?action=view_listing_image&image_id=' . $imageID . '">';
}else {
$display .= '<a href="listing_image_' . $imageID . '.html">';
}
$display .= "<img src=\"$config[listings_view_images_path]/$thumb_file_name\" height=\"$displayheight\" width=\"$displaywidth\" alt=\"$thumb_file_name\" /></a><br /> ";
if ($showcap == 'yes') {
$display .= "<b>".urldecode($caption)."</b><br /><br />";
} else {
$display .= "<br />";
}
} // end if ($thumb_file_name != "")
$recordSet->MoveNext();
} // end while
// $display .= "</td>";
} // end if ($num_images > 0)
else {
if ($config['show_no_photo'] == 1) {
$display .= "<img src=\"$config[baseurl]/images/nophoto.gif\" width=\"$config[thumbnail_width]\" alt=\"$lang[no_photo]\" /><br /> ";
}
}
return $display;
} // end function renderListingsImages
function make_thumb_gd ($input_file_name, $input_file_path, $output_path = "")
{
// makes a thumbnail using the GD library
global $config;
$quality = $config['jpeg_quality']; // jpeg quality -- set in common.php
if($output_path == ""){
$output_path=$input_file_path;
}
// first, grab the dimensions of the pic
$imagedata = GetImageSize($input_file_path . '/' . $input_file_name);
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$imagetype = $imagedata[2];
// type definitions
// 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP
// 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order)
// 9 = JPC, 10 = JP2, 11 = JPX
$thumb_name = $input_file_name; //by default
// the GD library, which this uses, can only resize GIF, JPG and PNG
if ($imagetype == 1) {
// it's a GIF
// figure out the ratio to which it should be shrunk, if at all
// see if GIF support is enabled
if (imagetypes() &IMG_GIF) {
$shrinkage = 1;
if ($imagewidth > $config['thumbnail_width']) {
$shrinkage = $config['thumbnail_width'] / $imagewidth;
}
$dest_height = $shrinkage * $imageheight;
$dest_width = $config['thumbnail_width'];
$src_img = imagecreatefromgif("$input_file_path/$input_file_name");
$dst_img = imageCreate($dest_width, $dest_height);
// copy the original image info into the new image with new dimensions
// checking to see which function is available
ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
$thumb_name = "thumb_" . "$input_file_name";
imagegif($dst_img, "$output_path/$thumb_name");
@chmod("$output_path/$thumb_name", 0777);
imagedestroy($src_img);
imagedestroy($dst_img);
} // end if GIF support is enabled
} // end if $imagetype == 1
elseif ($imagetype == 2) {
// it's a JPG
// figure out the ratio to which it should be shrunk, if at all
$shrinkage = 1;
if ($imagewidth > $config['thumbnail_width']) {
$shrinkage = $config['thumbnail_width'] / $imagewidth;
}
$dest_height = $shrinkage * $imageheight;
$dest_width = $config['thumbnail_width'];
$src_img = @imagecreatefromjpeg("$input_file_path/$input_file_name");
if (!$src_img) { /* See if it failed */
$im = imagecreatetruecolor(150, 30); /* Create a black image */
$bgc = imagecolorallocate($src_img, 255, 255, 255);
$tc = imagecolorallocate($src_img, 0, 0, 0);
imagefilledrectangle($src_img, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($src_img, 1, 5, 5, "Error loading $input_file_name", $tc);
}
if ($config['gdversion2'] == false) {
$dst_img = imageCreate($dest_width, $dest_height);
}else {
$dst_img = imageCreateTrueColor($dest_width, $dest_height);
}
// copy the original image info into the new image with new dimensions
// checking to see which function is available
if ($config['gdversion2'] == false) {
ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
}else {
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
}
$thumb_name = "thumb_" . "$input_file_name";
imagejpeg($dst_img, "$output_path/$thumb_name", $quality);
@chmod("$output_path/$thumb_name", 0777);
imagedestroy($src_img);
imagedestroy($dst_img);
} // end if $imagetype == 2
elseif ($imagetype == 3) {
// it's a PNG
// figure out the ratio to which it should be shrunk, if at all
$shrinkage = 1;
if ($imagewidth > $config['thumbnail_width']) {
$shrinkage = $config['thumbnail_width'] / $imagewidth;
}
$dest_height = $shrinkage * $imageheight;
$dest_width = $config['thumbnail_width'];
$src_img = imagecreatefrompng("$input_file_path/$input_file_name");
$dst_img = imagecreate($dest_width, $dest_height);
imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
$thumb_name = "thumb_" . "$input_file_name";
imagepng($dst_img, "$output_path/$thumb_name");
@chmod("$output_path/$thumb_name", 0777);
imagedestroy($src_img);
imagedestroy($dst_img);
} // end if $imagetype == 3
return $thumb_name;
} // end function make_thumb_gd
function resize_img_gd ($input_file_name, $input_file_path, $type)
{
// resizes image using the GD library
global $config;
$quality = $config['jpeg_quality']; // jpeg quality -- set in common.php
$max_width = $config['max_' . $type . '_upload_width'];
// first, grab the dimensions of the pic
$imagedata = getimagesize($input_file_path . '/' . $input_file_name);
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$imagetype = $imagedata[2];
// type definitions
// 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP
// 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order)
// 9 = JPC, 10 = JP2, 11 = JPX
$img_name = $input_file_name; //by default
// the GD library, which this uses, can only resize GIF, JPG and PNG
if ($imagetype == 1) {
// it's a GIF
// see if GIF support is enabled
if (imagetypes() &IMG_GIF) {
// figure out the ratio to which it should be shrunk, if at all
$shrinkage = 1;
$shrinkage = $max_width / $imagewidth;
$dest_height = $shrinkage * $imageheight;
$dest_width = $max_width;
$src_img = imagecreatefromgif("$input_file_path/$input_file_name");
$dst_img = imageCreate($dest_width, $dest_height);
// copy the original image info into the new image with new dimensions
// checking to see which function is available
ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
$thumb_name = "thumb_" . "$input_file_name";
imagegif($dst_img, "$input_file_path/$img_name");
imagedestroy($src_img);
imagedestroy($dst_img);
} //end if GIF support is enabled
} // end if $imagetype == 1
elseif ($imagetype == 2) {
// it's a JPG
// figure out the ratio to which it should be shrunk, if at all
$shrinkage = 1;
$shrinkage = $max_width / $imagewidth;
$dest_height = $shrinkage * $imageheight;
$dest_width = $max_width;
$src_img = imagecreatefromjpeg("$input_file_path/$input_file_name");
if ($config['gdversion2'] == false) {
$dst_img = imageCreate($dest_width, $dest_height);
}else {
$dst_img = imageCreateTrueColor($dest_width, $dest_height);
}
// copy the original image info into the new image with new dimensions
// checking to see which function is available
if ($config['gdversion2'] == false) {
ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
}else {
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
}
$img_name = "$input_file_name";
imagejpeg($dst_img, "$input_file_path/$img_name", $quality);
imagedestroy($src_img);
imagedestroy($dst_img);
} // end if $imagetype == 2
elseif ($imagetype == 3) {
// it's a PNG
// figure out the ratio to which it should be shrunk, if at all
$shrinkage = 1;
$shrinkage = $max_width / $imagewidth;
$dest_height = $shrinkage * $imageheight;
$dest_width = $max_width;
$src_img = imagecreatefrompng("$input_file_path/$input_file_name");
$dst_img = imagecreate($dest_width, $dest_height);
imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $imagewidth, $imageheight);
$img_name = "$input_file_name";
imagepng($dst_img, "$input_file_path/$img_name");
imagedestroy($src_img);
imagedestroy($dst_img);
} // end if $imagetype == 3
} // end function resize_img_gd
function resize_img_imagemagick ($input_file_name, $input_file_path, $type)
{
// resizes image using ImageMagick
global $config;
// Specify your file details
$current_file = $input_file_path . '/' . $input_file_name;
$max_width = $config['max_' . $type . '_upload_width'];
// Get the current info on the file
$current_size = getimagesize($current_file);
$current_img_width = $current_size[0];
$current_img_height = $current_size[1];
// $image_base = explode('.', $current_file);
// This part gets the new thumbnail name
// $image_basename = $image_base[0];
// $image_ext = $image_base[1];
$too_big_diff_ratio = $current_img_width / $max_width;
$new_img_width = $max_width;
$new_img_height = round($current_img_height / $too_big_diff_ratio);
$path = $config['path_to_imagemagick'];
$debug_path = '"' . $path . '" -geometry ' . $new_img_width . 'x' . $new_img_height . ' "' . $current_file . '" current_file';
// Convert the file
$debug = exec($debug_path);
} // end function resize_img_imagemagick
function make_thumb_imagemagick ($input_file_name, $input_file_path)
{
// makes a thumbnail using ImageMagick
global $config;
// Specify your file details
$current_file = "$input_file_path/$input_file_name";
$max_width = $config['thumbnail_width'];
// Get the current info on the file
$current_size = getimagesize($current_file);
$current_img_width = $current_size[0];
$current_img_height = $current_size[1];
// $image_base = explode('.', $current_file);
// This part gets the new thumbnail name
// $image_basename = $image_base[0];
// $image_ext = $image_base[1];
$thumb_name = $input_file_path . "/thumb_" . $input_file_name;
$thumb_name2 = "thumb_" . $input_file_name;
$too_big_diff_ratio = $current_img_width / $max_width;
$new_img_width = $max_width;
$new_img_height = round($current_img_height / $too_big_diff_ratio);
$path = $config['path_to_imagemagick'];
// Convert the file
$debug_path = '"' . $path . '" -geometry ' . $new_img_width . 'x' . $new_img_height . ' "' . $current_file . '" "' . $thumb_name . '"';
$debug = exec($debug_path);
@chmod("$input_file_path/$thumb_name", 0777);
return $thumb_name2;
} // end function make_thumb
function handleUpload($type, $edit, $owner)
{
// deals with incoming uploads
global $config, $conn, $lang;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$display = '';
global $config, $conn, $lang;
$file_x = 0;
if ($type == 'user') {
$sql = "SELECT count(" . $type . "images_id) as num_images FROM " . $config['table_prefix'] . "" . $type . "images WHERE (userdb_id = $owner)";
}else {
$sql = "SELECT count(" . $type . "images_id) as num_images FROM " . $config['table_prefix'] . "" . $type . "images WHERE (listingsdb_id = $edit)";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$num_images = $recordSet->fields['num_images'];
$avaliable_iamges = $config['max_' . $type . '_uploads'] - $num_images;
while ($file_x < $avaliable_iamges) {
if (is_uploaded_file($_FILES['userfile']['tmp_name'][$file_x])) {
$badchararray = array(" ", "'", "\"", "$", "&", "%", "-");
$realname = str_replace($badchararray, "", $_FILES['userfile']['name'][$file_x]);
$realname = stripslashes(strtolower($realname));
$filename = $_FILES['userfile']['tmp_name'][$file_x];
$extension = substr(strrchr($realname, "."), 1);
print "<!-- $filename was uploaded successfully -->";
$filetype = $_FILES['userfile']['type'][$file_x];
print "<!-- type is $filetype -->";
// checking the filetype to make sure it's what we had in mind
$pass_the_upload = "true";
if (!in_array($_FILES['userfile']['type'][$file_x], explode(',', $config['allowed_upload_types']))) {
$pass_the_upload = "$realname $lang[upload_is_an_invalid_file_type]: $filetype";
}
// check size
$filesize = $_FILES['userfile']['size'][$file_x];
if ($config['max_' . $type . '_upload_size'] != 0 && $filesize > $config['max_' . $type . '_upload_size']) {
$pass_the_upload = "$lang[upload_too_large]: " . $_FILES['userfile']['name'][$file_x];
}
// check width
$imagedata = GetImageSize("$filename");
$imagewidth = $imagedata[0];
if ($imagedata != false) {
if ($imagewidth == '' || $imagewidth < 2 || $imagewidth > $config['max_' . $type . '_upload_width']) {
if (($config['resize_img'] == '1' && $type == 'vtour') || $config['resize_img'] != '1') {
$pass_the_upload = $lang['upload_too_wide'];
}
}
}
// check file extensions
// invalid extension
if (!in_array($extension, explode(',', $config['allowed_upload_extensions']))) {
$pass_the_upload = "$lang[upload_invalid_extension] ($extension).";
}
// security error
if (strstr($_FILES['userfile']['name'][$file_x], "..") != "") {
$pass_the_upload = "$lang[upload_security_violation]!";
}
// make sure the file hasn't already been uploaded...
if ($type == "listings") {
$save_name = "$_POST[edit]" . "_" . "$realname";
$sql = "SELECT listingsimages_file_name FROM " . $config['table_prefix'] . "listingsimages WHERE listingsimages_file_name = '$save_name'";
}elseif ($type == "vtour") {
$save_name = "$_POST[edit]" . "_" . "$realname";
$sql = "SELECT vtourimages_file_name FROM " . $config['table_prefix'] . "vtourimages WHERE vtourimages_file_name = '$save_name'";
}elseif ($type == "user") {
$save_name = "$owner" . "_" . "$realname";
$sql = "SELECT userimages_file_name FROM " . $config['table_prefix'] . "userimages WHERE userimages_file_name = '$save_name'";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$num = $recordSet->RecordCount();
if ($num > 0) {
$pass_the_upload = "$lang[file_exists]!";
}
if ($pass_the_upload == "true") {
// the upload has passed the tests!
if ($type == "listings") {
move_uploaded_file($_FILES['userfile']['tmp_name'][$file_x], "$config[listings_upload_path]/$save_name");
$thumb_name = $save_name; // by default -- no difference... unless...
if ($config['make_thumbnail'] == '1') {
// if the option to make a thumbnail is activated...
$make_thumb = 'make_thumb_' . $config['thumbnail_prog'];
$thumb_name = image_handler::$make_thumb ($save_name, $config['listings_upload_path']);
} // end if $config[make_thumbnail] === "1"
if ($config['resize_img'] == '1' && $imagewidth > $config['max_' . $type . '_upload_width']) {
// if the option to resize the images on upload is activated...
$resize_img = 'resize_img_' . $config['thumbnail_prog'];
$img_name = image_handler::$resize_img ($save_name, $config['listings_upload_path'], $type);
} // end if $config[resize_img] === "1"
// Get Max Image Rank
$sql = "SELECT MAX(listingsimages_rank) AS max_rank FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsdb_id = '$edit')";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$rank = $recordSet->fields['max_rank'];
$rank++;
$sql = "INSERT INTO " . $config['table_prefix'] . "listingsimages (listingsdb_id, userdb_id, listingsimages_file_name, listingsimages_thumb_file_name,listingsimages_rank,listingsimages_caption,listingsimages_description,listingsimages_active) VALUES ('$edit', '$owner', '$save_name', '$thumb_name',$rank,'','','yes')";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$misc->log_action ("$lang[log_uploaded_listing_image] $save_name");
@chmod("$config[listings_upload_path]/$save_name", 0777);
} // end if $type == "listings"
if ($type == "vtour") {
move_uploaded_file($_FILES['userfile']['tmp_name'][$file_x], "$config[vtour_upload_path]/$save_name");
$thumb_name = $save_name; // by default -- no difference... unless...
if ($config['make_thumbnail'] == '1' && $imagedata != false) {
// if the option to make a thumbnail is activated...
$make_thumb = 'make_thumb_' . $config['thumbnail_prog'];
$thumb_name = image_handler::$make_thumb ($save_name, $config['vtour_upload_path']);
} // end if $config[make_thumbnail] === "1"
// Get Max Image Rank
$sql = "SELECT MAX(vtourimages_rank) AS max_rank FROM " . $config['table_prefix'] . "vtourimages WHERE (listingsdb_id = '$edit')";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$rank = $recordSet->fields['max_rank'];
$rank++;
$sql = "INSERT INTO " . $config['table_prefix'] . "vtourimages (listingsdb_id, userdb_id, vtourimages_file_name, vtourimages_thumb_file_name, vtourimages_rank,vtourimages_caption,vtourimages_description,vtourimages_active) VALUES ('$edit', '$owner', '$save_name', '$thumb_name',$rank,'','','yes')";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$misc->log_action ("$lang[log_uploaded_listing_image] $save_name");
@chmod("$config[vtour_upload_path]/$save_name", 0777);
} // end if $type == "vtour"
if ($type == "user") {
if ($this->debug) {
$display .= 'Try to make Thumbnail? ' . $config['make_thumbnail'] . '<br />';
}
move_uploaded_file($_FILES['userfile']['tmp_name'][$file_x], "$config[user_upload_path]/$save_name");
$thumb_name = $save_name; // by default -- no difference... unless...
if ($config['make_thumbnail'] == 1) {
// if the option to make a thumbnail is activated...
// include ("$config[path_to_thumbnailer]");
$thumb_name = 'make_thumb_' . $config['thumbnail_prog'];
$thumb_name = image_handler::$thumb_name($save_name, $config['user_upload_path']);
} // end if $config[make_thumbnail] === "1"
if ($config['resize_img'] == '1' && $imagewidth > $config['max_' . $type . '_upload_width']) {
// if the option to make a thumbnail is activated...
// include ("$config[path_to_thumbnailer]");
$resize_img = 'resize_img_' . $config['thumbnail_prog'];
image_handler::$resize_img ($save_name, $config['user_upload_path'], $type);
} // end if $config[resize_img] === "1"
// Get Max Image Rank
$sql = "SELECT MAX(userimages_rank) AS max_rank FROM " . $config['table_prefix'] . "userimages WHERE (userdb_id = '$owner')";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$rank = $recordSet->fields['max_rank'];
$rank++;
$sql = "INSERT INTO " . $config['table_prefix'] . "userimages (userdb_id, userimages_file_name, userimages_thumb_file_name,userimages_rank,userimages_caption,userimages_description,userimages_active) VALUES ('$owner', '$save_name', '$thumb_name',$rank,'','','yes')";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$misc->log_action ("$lang[log_uploaded_user_image] $save_name");
@chmod("$config[user_upload_path]/$save_name", 0777);
} // end if $type == "user"
$display .= "<p>$realname $lang[upload_success].</p>";
} // end if $pass_the_upload == "true"
else {
// the upload has failed... here's why...
$display .= "<p><strong>$lang[upload_failed]</strong> $pass_the_upload</p>";
}
} // end if
else {
// print_r($_FILES);
if ($_FILES['userfile']['error'][$file_x] != 4) {
$display .= "$lang[upload_too_large]: " . $_FILES['userfile']['name'][$file_x] . ".<br />";
}
}
$file_x++;
}
return $display;
} // end function handleUpload
function renderListingsMainImage($listingID, $showdesc, $java)
{
// shows the main image
global $config, $lang, $conn;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
// grab the images
$listingID = $misc->make_db_extra_safe($listingID);
$width = "500";
if ($config["max_listings_upload_width"] < 500 && $config['resize_img'] == '1') {
}
$sql = "SELECT listingsimages_id, listingsimages_caption, listingsimages_file_name, listingsimages_description FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsdb_id = $listingID) ORDER BY listingsimages_rank";
$recordSet = $conn->SelectLimit($sql, 1, 0);
if ($recordSet === false) {
$misc->log_error($sql);
}
if ($java == 'yes') {
$display = "<script type=\"text/javascript\"> function imgchange(id,caption,description){if(document.images){document.getElementById('main').src = \"$config[listings_view_images_path]/\" + id; document.getElementById('main').alt = caption; document.getElementById('main_image_description').innerHTML = description; } else { document.getElementById('main').src = \"images/nophoto.gif\";document.getElementById('main_image_description').innerHTML = ''; }}</script>";
}
$num_images = $recordSet->RecordCount();
if ($num_images > 0) {
while (!$recordSet->EOF) {
$file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_file_name']);
$caption = $misc->make_db_unsafe ($recordSet->fields['listingsimages_caption']);
$description = $misc->make_db_unsafe ($recordSet->fields['listingsimages_description']);
if ($java == 'yes') {
if ($showdesc == 'yes') {
$display .= "<img src=\"$config[listings_view_images_path]/$file_name\" width=\"$width\" id=\"main\" alt=\"$caption\" /><br /><table width=\"$width\"><tr><td id=\"main_image_description\">$description</td></tr></table>";
} else {
$display .= "<img src=\"$config[listings_view_images_path]/$file_name\" width=\"$width\" id=\"main\" alt=\"$caption\" /><br />";
}
} else {
if ($showdesc == 'yes') {
$display .= "<img src=\"$config[listings_view_images_path]/$file_name\" width=\"$width\" alt=\"$caption\" /><br /><table width=\"$width\"><tr><td>$description</td></tr></table>";
} else {
$display .= "<img src=\"$config[listings_view_images_path]/$file_name\" width=\"$width\" alt=\"$caption\" /><br />";
}
}
$recordSet->MoveNext();
} // end while
} // end if ($num_images > 0)
else {
if ($config['show_no_photo'] == 1) {
$display .= "<img src=\"images/nophotobig.gif\" width=\"$width\" id=\"main\" alt=\"$lang[no_photo]\" /><br />";
}
}
return $display;
} // end function renderListingsMainImage
function renderListingsImagesJava($listingID, $showcap)
{
// shows the images connected to a given image
global $config, $lang, $conn, $style;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
// grab the images
$listingID = $misc->make_db_extra_safe($listingID);
$sql = "SELECT listingsimages_caption, listingsimages_file_name, listingsimages_thumb_file_name, listingsimages_description FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsdb_id = $listingID) ORDER BY listingsimages_rank";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$display = '';
$num_images = $recordSet->RecordCount();
if ($num_images > 0) {
// $display .= "<td width=\"$style[image_column_width]\" valign=\"top\" class=\"row_main\" align=\"center\">";
while (!$recordSet->EOF) {
$caption = $misc->make_db_unsafe ($recordSet->fields['listingsimages_caption']);
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_thumb_file_name']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_file_name']);
// $imageID = $misc->make_db_unsafe ($recordSet->fields['listingsimages_id']);
$description = $misc->make_db_unsafe ($recordSet->fields['listingsimages_description']);
$description = str_replace('"','"',$description);
$caption = str_replace('"','"',$caption);
$description = str_replace(' ','%20',$description);
$caption = str_replace(' ','%20',$caption);
// gotta grab the image size
$imagedata = GetImageSize("$config[listings_upload_path]/$thumb_file_name");
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$shrinkage = $config['thumbnail_width'] / $imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
$display .= "<a href=\"javascript:imgchange('$file_name','" . addslashes($caption) . "','" . addslashes($description) . "')\"> ";
$display .= "<img src=\"$config[listings_view_images_path]/$thumb_file_name\" height=\"$displayheight\" width=\"$displaywidth\" alt=\"$caption\" /></a><br />";
if ($showcap == 'yes') {
$display .= "<b>".urldecode($caption)."</b><br /><br />";
} else {
$display .= "<br />";
}
$recordSet->MoveNext();
} // end while
// $display .= "</td>";
} // end if ($num_images > 0)
else {
if ($config['show_no_photo'] == 1) {
$display .= "<img src=\"$config[baseurl]/images/nophoto.gif\" width=\"$config[thumbnail_width]\" alt=\"$lang[no_photo]\" /><br /> ";
}
}
return $display;
} // end function renderListingsImagesJava
function renderListingsImagesJavaRows($listingID)
{
// shows the images connected to a given image
global $config, $lang, $conn, $style;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
// grab the images
$var_reset = 1; // Reset the var (counter) (DO NOT CHANGE)
$user_col_max = 4; // How Many To show Per Row
$listingID = $misc->make_db_extra_safe($listingID);
$sql = "SELECT listingsimages_caption, listingsimages_file_name, listingsimages_thumb_file_name, listingsimages_description FROM " . $config['table_prefix'] . "listingsimages WHERE (listingsdb_id = $listingID) ORDER BY listingsimages_rank";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$display = '';
$num_images = $recordSet->RecordCount();
if ($num_images > 0) {
$display .= "<table width=\"440\" cellspacing=\"1\" cellpadding=\"2\" border=\"2\">";
while (!$recordSet->EOF) {
$caption = $misc->make_db_unsafe ($recordSet->fields['listingsimages_caption']);
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_thumb_file_name']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['listingsimages_file_name']);
$description = $misc->make_db_unsafe ($recordSet->fields['listingsimages_description']);
$description = str_replace('"','"',$description);
$caption = str_replace('"','"',$caption);
$description = str_replace(' ','%20',$description);
$caption = str_replace(' ','%20',$caption);
// gotta grab the image size
$imagedata = GetImageSize("$config[listings_upload_path]/$thumb_file_name");
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$shrinkage = $config['thumbnail_width'] / $imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
if ($var_reset == 1) {
$display .= "<tr>";
}
if ($caption=='')
{
$caption=$thumb_file_name;
}
$display .= "<td><a href=\"javascript:imgchange('$file_name','" . addslashes($caption) . "','" . addslashes($description) . "')\"> ";
$display .= "<img src=\"$config[listings_view_images_path]/$thumb_file_name\" height=\"$displayheight\" width=\"$displaywidth\" alt=\"$caption\" /></a>";
$display .= "</td>";
if ($var_reset == $user_col_max) {
$display .= "</tr>";
$var_reset = 1;
}else {
$var_reset++;
}
$recordSet->MoveNext();
} // end while
if ($var_reset != 1) {
$display .= "</tr>";
}
$display .= "</table>";
} // end if ($num_images > 0)
else {
if ($config['show_no_photo'] == 1) {
$display .= "<table width=\"440\" cellspacing=\"1\" cellpadding=\"2\" border=\"2\">";
$display .= "<tr><td><img src=\"$config[baseurl]/images/nophoto.gif\" width=\"$config[thumbnail_width]\" alt=\"$lang[no_photo]\" /></td></tr></table>";
}
}
return $display;
} // end function renderListingsImagesJavaRows
function edit_vtour_images()
{
global $lang, $conn, $config;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$display = '';
$edit = $_POST['edit'];
$sql_edit = $misc->make_db_safe($_POST['edit']);
if (!isset($_POST['action'])) {
$_POST['action'] = '';
}
// does this person have access to these listings?
if (($_SESSION['edit_all_listings'] != "yes") && ($_SESSION['admin_privs'] != "yes")) {
$sql = "SELECT userdb_id FROM " . $config['table_prefix'] . "listingsdb WHERE (listingsdb_id = $sql_edit)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
} while (!$recordSet->EOF) {
$owner = $recordSet->fields['userdb_id'];
$recordSet->MoveNext();
}
if ($_SESSION['userID'] != $owner) {
die ($lang['priv_failure']);
}
} // end priv check
if ($_POST['action'] == "update_pic") {
$sql_edit = $misc->make_db_safe($_POST['edit']);
$sql_caption = $misc->make_db_safe($_POST['caption']);
$sql_description = $misc->make_db_safe($_POST['description']);
$sql_rank = $misc->make_db_safe($_POST['rank']);
$sql_pic = $misc->make_db_safe($_POST['pic']);
if ($_SESSION['edit_all_listings'] == "yes") {
$sql = "UPDATE " . $config['table_prefix'] . "vtourimages SET vtourimages_caption = $sql_caption, vtourimages_description = $sql_description, vtourimages_rank = $sql_rank WHERE ((listingsdb_id = $sql_edit) AND (vtourimages_file_name = $sql_pic))";
}else {
$sql = "UPDATE " . $config['table_prefix'] . "vtourimages SET vtourimages_caption = $sql_caption, vtourimages_description = $sql_description, vtourimages_rank = $sql_rank WHERE ((listingsdb_id = $sql_edit) AND (vtourimages_file_name = $sql_pic) AND (userdb_id = $_SESSION[userID]))";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$display .= "<p>$lang[image] '$_POST[pic]' $lang[has_been_updated]</p>";
$misc->log_action ($lang['log_updated_listing_image'] . $_POST['pic']);
}
if ($_POST['action'] == "delete_pic") {
// get the data for the pic being deleted
$sql_pic_id = $misc->make_db_safe($_POST['pic_id']);
if ($_SESSION['edit_all_listings'] == "yes") {
$sql = "SELECT vtourimages_file_name, vtourimages_thumb_file_name FROM " . $config['table_prefix'] . "vtourimages WHERE ((listingsdb_id = $sql_edit) AND (vtourimages_id = $sql_pic_id))";
}else {
$sql = "SELECT vtourimages_file_name, vtourimages_thumb_file_name FROM " . $config['table_prefix'] . "vtourimages WHERE ((listingsdb_id = $sql_edit) AND (vtourimages_id = $sql_pic_id) AND (userdb_id = $_SESSION[userID]))";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
} while (!$recordSet->EOF) {
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['vtourimages_thumb_file_name']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['vtourimages_file_name']);
$recordSet->MoveNext();
} // end while
// delete from the db
if ($_SESSION['edit_all_listings'] == "yes") {
$sql = "DELETE FROM " . $config['table_prefix'] . "vtourimages WHERE ((listingsdb_id = $sql_edit) AND (vtourimages_file_name = '$file_name'))";
}else {
$sql = "DELETE FROM " . $config['table_prefix'] . "vtourimages WHERE ((listingsdb_id = $sql_edit) AND (vtourimages_file_name = '$file_name') AND (userdb_id = '$_SESSION[userID]'))";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
// delete the files themselves
// on widows, required php 4.11 or better (I think)
if (!unlink("$config[vtour_upload_path]/$file_name")) die("$lang[alert_site_admin]");
if ($file_name != $thumb_file_name) {
if (!unlink("$config[vtour_upload_path]/$thumb_file_name")) die("$lang[alert_site_admin]");
}
$misc->log_action ("$lang[log_deleted_listing_image] $file_name");
$display .= "<p>$lang[image] '$file_name' $lang[has_been_deleted]</p>";
}
if ($_POST['action'] == "upload") {
if ($_SESSION['admin_privs'] == "yes") {
// get the owner of the listing
$sql = "SELECT userdb_id FROM " . $config['table_prefix'] . "listingsdb WHERE (listingsdb_id = $sql_edit)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
} while (!$recordSet->EOF) {
$owner = $recordSet->fields['userdb_id'];
$recordSet->MoveNext();
}
$display .= $this->handleUpload("vtour", $edit, $owner);
}else {
$display .= $this->handleUpload("vtour", $edit, $_SESSION['userID']);
}
} // end if $action == "upload"
if ($_SESSION['edit_all_listings'] == "yes") {
$sql = "SELECT vtourimages_id, vtourimages_caption, vtourimages_file_name, vtourimages_thumb_file_name, vtourimages_description, vtourimages_rank FROM " . $config['table_prefix'] . "vtourimages WHERE (listingsdb_id = $sql_edit) ORDER BY vtourimages_rank";
}else {
$sql = "SELECT vtourimages_id, vtourimages_caption, vtourimages_file_name, vtourimages_thumb_file_name, vtourimages_description, vtourimages_rank FROM " . $config['table_prefix'] . "vtourimages WHERE ((listingsdb_id = $sql_edit) AND (userdb_id = '$_SESSION[userID]')) ORDER BY vtourimages_rank";
}
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
$display .= '<table class="image_upload">';
$display .= '<tr>';
$display .= '<td colspan="2">';
$display .= '<h3>' . $lang['edit_images'] . ' -- ';
if ($_SESSION['edit_all_listings'] == "yes") {
$display .= "<a href=\"index.php?action=edit_listings&edit=$edit\">";
}else {
$display .= "<a href=\"index.php?action=edit_my_listings&edit=$edit\">";
}
$display .= $lang['return_to_editing_listing'];
$display .= '</a></h3></td></tr>';
$count = 0;
$ext = '';
while (!$recordSet->EOF) {
// $edit = $misc->make_db_safe($_POST['edit']);
$pic_id = $recordSet->fields['vtourimages_id'];
$rank = $recordSet->fields['vtourimages_rank'];
$caption = $misc->make_db_unsafe ($recordSet->fields['vtourimages_caption']);
$thumb_file_name = $misc->make_db_unsafe ($recordSet->fields['vtourimages_thumb_file_name']);
$file_name = $misc->make_db_unsafe ($recordSet->fields['vtourimages_file_name']);
$description = $misc->make_db_unsafe ($recordSet->fields['vtourimages_description']);
$ext = substr(strrchr($file_name, '.'), 1);
if ($ext == 'jpg') {
// gotta grab the image size
$imagedata = GetImageSize("$config[vtour_upload_path]/$file_name");
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$shrinkage = $config['thumbnail_width'] / $imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
$filesize = filesize("$config[vtour_upload_path]/$file_name");
$filesize = $filesize / 1000; // to get k
// now grab the thumbnail data
$thumb_imagedata = GetImageSize("$config[vtour_upload_path]/$thumb_file_name");
$thumb_imagewidth = $thumb_imagedata[0];
$thumb_imageheight = $thumb_imagedata[1];
$thumb_filesize = filesize("$config[vtour_upload_path]/$thumb_file_name");
$thumb_filesize = $thumb_filesize / 1000;
// alternate the colors
if ($count == 0) {
$count = 1;
}else {
$count = 0;
}
$display .= "<tr class=\"image_row_$count\"><td valign=\"top\" class=\"image_row_$count\" width=\"150\"><b>$file_name</b><br />$lang[width]=$imagewidth<br />$lang[height]=$imageheight<br />$lang[size]=$filesize" . "k<br />";
$display .= "<br />$lang[thumbnail]:<br />";
$display .= "<img src=\"$config[vtour_view_images_path]/$thumb_file_name\" height=\"$displayheight\" width=\"$displaywidth\" border=\"1\"> ";
$display .= "<br />$lang[width]=$thumb_imagewidth<br />$lang[height]=$thumb_imageheight<br />$lang[size]=$thumb_filesize" . "k<br />";
$display .= "<p align=\"center\"><form action=\"$config[baseurl]/admin/index.php?action=edit_vtour_images\" method=\"post\" name=\"delForm$pic_id\"><input type=\"hidden\" name=\"action\" value=\"delete_pic\" /><input type=\"hidden\" name=\"pic_id\" value=\"$pic_id\" /><input type=\"hidden\" name=\"edit\" value=\"$_POST[edit]\" /><a href=\"javascript:document.delForm$pic_id.submit()\">$lang[delete]</a></form>";
$display .= "</td><td align=\"center\" class=\"image_row_$count\"><img src=\"$config[vtour_view_images_path]/$file_name\" width=\"600\" border=\"1\">";
$display .= "</tr><tr><td align=\"center\" class=\"image_row_$count\" colspan=\"2\"><form action=\"index.php?action=edit_vtour_images\" method=\"post\">";
$display .= "<input type=\"hidden\" name=\"edit\" value=\"$edit\">";
$display .= "<input type=\"hidden\" name=\"action\" value=\"update_pic\">";
$display .= "<input type=\"hidden\" name=\"pic\" value=\"$file_name\">";
$display .= "<table border=\"0\">";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><b>$lang[admin_template_editor_field_rank]:</b></td><td align=\"left\"><input type=\"text\" name=\"rank\" value=\"$rank\"><div class=\"small\">$lang[upload_rank_explanation]</div></td></tr>";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><b>$lang[upload_caption]:</b></td><td align=\"left\"><input type=\"text\" name=\"caption\" value=\"$caption\"></td></tr>";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><b>$lang[upload_description]:</b><td align=\"left\"><textarea name=\"description\" rows=\"6\" cols=\"40\">$description</textarea></td></tr>";
$display .= "<tr><td align=\"center\" class=\"image_row_$count\" colspan=\"2\"><input type=\"submit\" value=\"Update\">";
$display .= "</form></td></tr>";
$display .= "</table>";
$display .= "</td></tr><tr><td colspan=\"2\"><hr></td></tr>";
$recordSet->MoveNext();
} // end if ext = jpg
elseif ($ext == 'egg') {
// alternate the colors
if ($count == 0) {
$count = 1;
}else {
$count = 0;
}
$display .= "<tr class=\"image_row_$count\"><td valign=\"top\" align=\"center\" class=\"image_row_$count\"><b>$file_name</b><br />";
$display .= "<img src=\"$config[baseurl]/images/eggimage.gif\" border=\"1\"> ";
$display .= "<br /><p align=\"center\"><form action=\"$config[baseurl]/admin/index.php?action=edit_vtour_images\" method=\"post\" name=\"delForm$pic_id\"><input type=\"hidden\" name=\"action\" value=\"delete_pic\" /><input type=\"hidden\" name=\"pic_id\" value=\"$pic_id\" /><input type=\"hidden\" name=\"edit\" value=\"$_POST[edit]\" /><a href=\"javascript:document.delForm$pic_id.submit()\">$lang[delete]</a></form>";
$display .= "</tr>";
$recordSet->MoveNext();
} // end elseif ext = egg
// Unsupported VTour: Display that it's uploaded but let the user know Open-Realty doesn't support it
else {
// alternate the colors
if ($count == 0) {
$count = 1;
}else {
$count = 0;
}
$display .= "<tr class=\"image_row_$count\"><td valign=\"top\" class=\"image_row_$count\" width=\"150\"><b>$lang[unsupported_vtour]<br />$file_name</b><br />$lang[size]=$filesize" . "k<br />";
$display .= "<p align=\"center\"><form action=\"$config[baseurl]/admin/index.php?action=edit_vtour_images\" method=\"post\" name=\"delForm$pic_id\"><input type=\"hidden\" name=\"action\" value=\"delete_pic\" /><input type=\"hidden\" name=\"pic_id\" value=\"$pic_id\" /><input type=\"hidden\" name=\"edit\" value=\"$_POST[edit]\" /><a href=\"javascript:document.delForm$pic_id.submit()\">$lang[delete]</a></form>";
$display .= "</td>";
$display .= "</tr><tr><td align=\"center\" class=\"image_row_$count\" colspan=\"2\"><form action=\"index.php?action=edit_vtour_images\" method=\"post\">";
$display .= "<input type=\"hidden\" name=\"edit\" value=\"$edit\">";
$display .= "<input type=\"hidden\" name=\"action\" value=\"update_pic\">";
$display .= "<input type=\"hidden\" name=\"pic\" value=\"$file_name\">";
$display .= "<table border=\"0\">";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><b>$lang[admin_template_editor_field_rank]:</b></td><td align=\"left\"><input type=\"text\" name=\"rank\" value=\"$rank\"><div class=\"small\">$lang[upload_rank_explanation]</div></td></tr>";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><b>$lang[upload_caption]:</b></td><td align=\"left\"><input type=\"text\" name=\"caption\" value=\"$caption\"></td></tr>";
$display .= "<tr><td align=\"right\" class=\"image_row_$count\"><b>$lang[upload_description]:</b><td align=\"left\"><textarea name=\"description\" rows=\"6\" cols=\"40\">$description</textarea></td></tr>";
$display .= "<tr><td align=\"center\" class=\"image_row_$count\" colspan=\"2\"><input type=\"submit\" value=\"Update\">";
$display .= "</form></td></tr>";
$display .= "</table>";
$display .= "</tr>";
$recordSet->MoveNext();
} // end else it's not a supported vtour
} // end while
$num_images = $recordSet->RecordCount();
$avaliable_iamges = $config["max_vtour_uploads"] - $num_images;
$x = 0;
if ($num_images < $config['max_vtour_uploads'] && $ext != 'egg') {
$display .= '<table border=0 cellspacing=0 cellpadding=0>';
$display .= '<tr>';
$display .= '<td colspan="2">';
$display .= '<h3>' . $lang['upload_a_picture'] . '</h3>';
$display .= '</td>';
$display .= '</tr>';
$display .= '<tr>';
$display .= '<td width="150"> </td>';
$display .= '<td>';
$display .= '<form enctype="multipart/form-data" action="index.php?action=edit_vtour_images" method="post">';
$display .= '<input type="hidden" name="action" value="upload">';
$display .= '<input type="hidden" name="edit" value="' . $edit . '">';
$display .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . $config['max_vtour_upload_size'] . '">';
while ($x < $avaliable_iamges) {
$display .= '<b>' . $lang['upload_send_this_file'] . ': </b><input name="userfile[]" type="file"><br />';
$x++;
}
$display .= '<input type="submit" value="' . $lang['upload_send_file'] . '">';
$display .= '</form>';
$display .= '</td>';
$display .= '</tr>';
$display .= '</table>';
} // end if $num_images <= $config[max_user_uploads]
$display .= "</table>";
return $display;
}
} // End ImageHandler Class
?>