<?php
include './header.php';
include("../class/resize-class.php");
$db = new DB();
if (isset($_POST['save-data'])) {
if (!$_POST['name'] || !$_POST['date'] || !$_POST['description']) {
?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Error!</strong> Please enter the all data.
</div>
<?php
} else {
$emsg = "";
$folderName = "../images/photo-albums/";
$valid_image_check = array("image/gif", "image/jpeg", "image/jpg", "image/png", "image/bmp");
for ($i = 0; $i < count($_FILES["image"]["name"]); $i++) {
if ($_FILES["image"]["name"][$i] <> "") {
$image_mime = strtolower(image_type_to_mime_type(exif_imagetype($_FILES["image"]["tmp_name"][$i])));
// if valid image type then upload
if (in_array($image_mime, $valid_image_check)) {
$ext = explode("/", strtolower($image_mime));
$ext = strtolower(end($ext));
$filename = $_POST['olbumImage'];
$filepath = $folderName . $filename;
if (!move_uploaded_file($_FILES["image"]["tmp_name"][$i], $filepath)) {
$emsg .= "Failed to upload <strong>" . $_FILES["image"]["name"][$i] . "</strong>. <br>";
$counter++;
} else {
$resizeObj = new resize($filepath);
$resizeObj->resizeImage(500, 300, 'crop');
$resizeObj->saveImage($filepath, 80);
}
} else {
$emsg .= "<strong>" . $_FILES["user_files"]["name"][$i] . "</strong> not a valid image. <br>";
}
}
}
$sql = "UPDATE `photo-albums` SET "
. "`name` = '" . mysql_real_escape_string($_POST['name']) . "',"
. "`date` = '" . mysql_real_escape_string($_POST['date']) . "',"
. " `description` = '" . mysql_real_escape_string($_POST['description']) . "' "
. "WHERE `id` = '" . $_POST['id'] . "'";
$db->readQuery($sql);
echo '<input type="hidden" id="reload" value="1">';
?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong>Success!</strong> Album "<?php echo $_POST['name']; ?>" was updated successfully.
</div>
<?php
}
}
$id = $_GET['id'];
$album = getAlbumById($id);
?>
<script src="tinymce/js/tinymce/tinymce.min.js"></script>
<script>
tinymce.init({
selector: "textarea",
// ===========================================
// INCLUDE THE PLUGIN
// ===========================================
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
// ===========================================
// PUT PLUGIN'S BUTTON on the toolbar
// ===========================================
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages",
// ===========================================
// SET RELATIVE_URLS to FALSE (This is required for images to display properly)
// ===========================================
relative_urls: false
});
</script>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Edit Album ( <?php echo $album['name']; ?> )</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-9">
<form action="" method="POST" enctype="multipart/form-data" class="form-horizontal" id="main-form">
<div class="form-group">
<label for="name" class="col-sm-3 control-label">Album Name:</label>
<div class="col-sm-9">
<input type="text" value="<?php echo $album['name']; ?>" name="name" id="name" class="form-control" required="TRUE">
<input type="hidden" value="<?php echo $album['id']; ?>" name="id" id="id" >
<input type="hidden" value="<?php echo $album['photo']; ?>" name="olbumImage" id="olbumImage" >
</div>
</div>
<div class="form-group">
<label for="date" class="col-sm-3 control-label">Date:</label>
<div class="col-sm-9">
<input type="date" name="date" id="date" value="<?php echo $album['date']; ?>" class="form-control" required="TRUE">
</div>
</div>
<div class="form-group">
<label for="image" class="col-sm-3 control-label">Main Album Photo:</label>
<div class="col-sm-9">
<input type="file" name="image[]" id="image" class="form-control"/>
</div>
</div>
<div class="form-group">
<label for="description" class="col-sm-3 control-label">Description</label>
<div class="col-sm-9">
<textarea id="description" name="description" rows="15" ><?php echo $album['description']; ?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<input type="submit" class="btn btn-default" id="btn-submit" value="Save" name="save-data">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function () {
if ($('#reload').val() == 1) {
var mess = "Album <?php echo $_POST['title']; ?> was updated successfully."
alert(mess);
window.location.replace("view-albums.php");
}
});
</script>
<?php
include './footer.php';
?> |