'.mysql_error()); } mysql_select_db($mysql_database, $db) or die('Failed to select database
'.mysql_error()); if ($authorized) { $sql = "CREATE TABLE IF NOT EXISTS $mysql_table (id INT UNSIGNED NOT NULL AUTO_INCREMENT, wwb_index INT NOT NULL, wwb_title VARCHAR(255) NOT NULL, wwb_description VARCHAR(255), wwb_keywords VARCHAR(255), wwb_filename VARCHAR(50) NOT NULL, wwb_date TIMESTAMP NOT NULL, PRIMARY KEY(id));"; $result = mysql_query($sql, $db); if (!$result) { die('Invalid query: ' . mysql_error()); } if ($action == 'logout') { setcookie('OnlinePhotoGallery', ''); unset($_COOKIE['OnlinePhotoGallery'], $admin_password); header("Location: ".basename(__FILE__)); exit; } else if ($action == 'save') { $filename = ""; if (isset($_FILES['filename']) && $_FILES['filename']['name'] != "") { if (!file_exists($images_folder)) { if (!mkdir($images_folder, 0777)) { die("Failed to create images directory."); } } if (!file_exists($images_folder ."thumbnails/")) { if (!mkdir($images_folder ."thumbnails/", 0777)) { die("Failed to create thumbnail directory."); } } $error_msg = ""; $name = $_FILES['filename']['name']; $type = $_FILES['filename']['type']; $tmp_name = $_FILES['filename']['tmp_name']; $error = $_FILES['filename']['error']; $size = $_FILES['filename']['size']; switch ($error) { case 0: if ($type == 'image/gif' || $type == 'image/jpeg' || $type == 'image/pjpeg' || $type == 'image/png' || $type == 'image/x-png') { if ($size <= $max_photo_size) { if (!move_uploaded_file($tmp_name, $images_folder . $name)) { $error_msg = "Error: Upload failed, please verify the folder's permissions."; } else { $filename = $name; } } else { $error_msg = "Error: The image is too big."; } } else { $error_msg = "Error: Wrong file type, please only use jpg, gif or png images."; } break; case 1: $error_msg = "Error: The uploaded file exceeds the 'upload_max_filesize' directive."; break; case 2: $error_msg = "Error: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form."; break; case 3: $error_msg = "Error: The uploaded file was only partially uploaded."; break; case 4: $error_msg = "Error: No file was uploaded."; break; case 6: $error_msg = "Error: Missing a temporary folder."; break; case 7: $error_msg = "Error: Failed to write file to disk."; break; case 8: $error_msg = "Error: File upload stopped by extension."; break; } if ($error_msg != "") { die($error_msg); } list($width, $height, $image_type) = getimagesize($images_folder . $name); $image_ratio = $width/$height; if ($image_ratio > 1) { $thumbnail_width = $thumbnail_size; $thumbnail_height = $thumbnail_size / $image_ratio; } else { $thumbnail_width = $thumbnail_size * $image_ratio; $thumbnail_height = $thumbnail_size; } $thumbnail_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height); switch ($image_type) { case IMAGETYPE_JPEG: $source_image = imagecreatefromjpeg($images_folder . $name); break; case IMAGETYPE_PNG: $source_image = imagecreatefrompng($images_folder . $name); break; default: $source_image = imagecreatefromgif($images_folder . $name); break; } imagecopyresampled($thumbnail_image, $source_image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height); $thumbnail_name = $images_folder ."thumbnails/" . "tn_" . $name; switch ($image_type) { case IMAGETYPE_JPEG: imagejpeg($thumbnail_image, $thumbnail_name, 100); break; case IMAGETYPE_PNG: imagepng($thumbnail_image, $thumbnail_name); break; default: imagegif($thumbnail_image, $thumbnail_name); break; } } $title = get_magic_quotes_gpc() ? trim($_POST['title']) : addslashes(trim($_POST['title'])); $title = str_replace("\\'", "'", $title); $description = get_magic_quotes_gpc() ? trim($_POST['description']) : addslashes(trim($_POST['description'])); $description = str_replace("\\'", "'", $description); $keywords = get_magic_quotes_gpc() ? trim($_POST['keywords']) : addslashes(trim($_POST['keywords'])); $keywords = str_replace("\\'", "'", $keywords); if ($id >= 0) { $sql = "UPDATE $mysql_table SET `wwb_title` = '$title', `wwb_description` = '$description', `wwb_keywords` = '$keywords', `wwb_date` = '$timestamp'"; if ($filename != "") { $sql .= ", `wwb_filename` = '$filename'"; } $sql .= " WHERE `id` = '$id'"; mysql_query($sql, $db); } else { $sql = "SELECT * FROM $mysql_table"; $result = mysql_query($sql, $db); $wwb_index = mysql_num_rows($result); $wwb_index = $wwb_index + 1; $sql = "INSERT $mysql_table (`wwb_index`, `wwb_date`, `wwb_filename`, `wwb_title`, `wwb_description`, `wwb_keywords`) VALUES ($wwb_index, '$timestamp', '$filename', '$title', '$description', '$keywords')"; mysql_query($sql, $db); } $id = -1; } else if ($action == 'delete') { $sql = "SELECT * FROM $mysql_table WHERE `id` = '$id'"; $result = mysql_query($sql, $db); if ($data = mysql_fetch_array($result)) { $wwb_index = $data['wwb_index']; } $sql = "DELETE FROM $mysql_table WHERE `id` = '$id'"; mysql_query($sql, $db); $sql = "UPDATE $mysql_table SET wwb_index=wwb_index-1 WHERE wwb_index > '$wwb_index'"; mysql_query($sql, $db); $id = -1; } } ?> Gallery
View all Animals Landscapes Architecture
SRSK Group
Complete Textile and Handicraft Solution
\n"; echo "\n"; echo "\n"; echo "\n"; } else if ($action == 'edit' || $action == 'new') { if ($authorized) { $title = ''; $description = ''; $keywords = ''; if ($id >= 0) { $sql = "SELECT * FROM $mysql_table WHERE id = '".$id."'"; $result = mysql_query($sql, $db); if ($data = mysql_fetch_array($result)) { $title = $data['wwb_title']; $description = $data['wwb_description']; $keywords = $data['wwb_keywords']; } } echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Title:
Description:
Keywords:
Filename:
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; } } else if ($id >= 0) { $sql = "SELECT * FROM $mysql_table WHERE id='$id'"; $result = mysql_query($sql, $db); if ($data = mysql_fetch_array($result)) { $image_name = $images_folder . $data['wwb_filename']; echo "\"\"\r\n"; } } else { if ($authorized) { echo "Add new photo  "; echo "Logout

\n"; } $sql = "SELECT * FROM $mysql_table"; if (isset($_GET['q'])) { $terms = explode(" ", urldecode($_GET['q'])); $sql .= " WHERE `wwb_keywords` LIKE '%"; $sql .= $terms[0]; $sql .= "%'"; for ($i=1; $i\r\n"; echo "\r\n"; $counter = 1; while ($data = mysql_fetch_array($result)) { $thumbnail = $images_folder . "thumbnails/tn_" . $data['wwb_filename']; echo "\r\n"; echo " "; echo "\"\"
"; echo "" . $data['wwb_title'] . "
\r\n"; if ($authorized) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo " \n"; echo " \n"; echo "  \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo "

\r\n"; } echo "\r\n"; if ($counter != $columns) { $counter++; } else { echo "\r\n\n"; $counter = 1; } } if ($counter != 1) { while ($counter <= $columns) { echo " \r\n"; $counter++; } } echo "\r\n"; echo "\r\n"; } ?>