Location: PHPKode > projects > EZphotopress > ezphotopress-1.0.0/admin/projects/modifyProject.php
<h3><?=MODIFYPROJECT_TITLE?></h3>
<br>
<?php
if (isset($pid) && $pid != '' && is_numeric($pid) && $pid > 0) {
	if (isset($_POST['action']) && $_POST['action'] == MODIFYPROJECT_FORM_SUBMIT) {
		$category = $_POST['category'];
		$name = $_POST['name'];
		$description = $_POST['description'];
		
		//if thummb is uploaded, get the path and move it
		$thumbUpload = 0;
		$imageUpload = 0;
		
		$filename = time();
		$fullPathThumb = "";
		$fullPathGallery = "";
		if (@is_uploaded_file($_FILES['thumb']['tmp_name'])) {
			$ext = pathinfo($_FILES['thumb']['name'], PATHINFO_EXTENSION);
			$fullPathThumb = $_CONFIG['thumbnail_path'].$filename."_thumb".".".$ext;
			if (@move_uploaded_file($_FILES['thumb']['tmp_name'], "../".$fullPathThumb)) {
				$thumbUpload = 1;
			}
		}
		
		if (@is_uploaded_file($_FILES['image']['tmp_name'])) {
			$ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
			$fullPathGallery = $_CONFIG['gallery_path'].$filename.".".$ext;
			if (@move_uploaded_file($_FILES['image']['tmp_name'], "../".$fullPathGallery)) {
				$imageUpload = 1;
			}
		}
		
		//before try to update, get the path of the saved images
		$queryImage = $db->query("select path_thumb,path_img from ".TABPREFIX."projects where id=".$pid);
		$rowImage = $queryImage->fetch();
		
		$query = "update ".TABPREFIX."projects set id_category=".$category.",";
		$query .= "title='".addslashes($name)."',";
		$query .= "body='".addslashes($description)."',";
		
		if ($thumbUpload == 1) {
			$query .= "path_thumb='".$fullPathThumb."',";	
		}
		
		if ($imageUpload == 1) {
			$query .= "path_img='".$fullPathGallery."',";	
		}
		
		$query .= "last_modify=NOW()";
		$query .= " where id=".$pid;
		
		$result = $db->query($query);
		
		$msg = "";
		if ($result->sizeIDU() != -1) {
			$msg .= MODIFYPROJECT_MESSAGE_SUCCESS_1;
			if ($thumbUpload == 1) {
				$msg .= MODIFYPROJECT_MESSAGE_THUMB_SUCCESS_1;
				//try to detele the thumbnail
				if (isset($rowImage['path_thumb']) && $rowImage['path_thumb'] != "") {
					try {
						unlink("../".$rowImage['path_thumb']);
						$msg .= MODIFYPROJECT_MESSAGE_THUMB_SUCCESS_2.$rowImage['path_thumb'].MODIFYPROJECT_MESSAGE_THUMB_SUCCESS_3;
					} catch (Exception $e) {
						$msg .= MODIFYPROJECT_MESSAGE_THUMB_ERROR_1.$rowImage['path_thumb'].MODIFYPROJECT_MESSAGE_THUMB_ERROR_2;
					}
				}
			} else {
				$msg .= MODIFYPROJECT_MESSAGE_THUMB_ERROR_3;
			}
			
			if ($imageUpload == 1) {
				$msg .= MODIFYPROJECT_MESSAGE_IMAGE_SUCCESS_1;
				//try to detele the image
				if (isset($rowImage['path_img']) && $rowImage['path_img'] != "") {
					try {
						unlink("../".$rowImage['path_img']);
						$msg .= MODIFYPROJECT_MESSAGE_IMAGE_SUCCESS_2.$rowImage['path_img'].MODIFYPROJECT_MESSAGE_IMAGE_SUCCESS_3;
					} catch (Exception $e) {
						$msg .= MODIFYPROJECT_MESSAGE_IMAGE_ERROR_1.$rowImage['path_img'].MODIFYPROJECT_MESSAGE_IMAGE_ERROR_2;
					}
				}
			} else {
				$msg .= MODIFYPROJECT_MESSAGE_IMAGE_ERROR_3;
			}
		} else {
			$msg .= MODIFYPROJECT_MESSAGE_ERROR_1;
			//try to remove the uplodaed files
			try {
				if ($fullPathThumb != "") {
					unlink("../".$fullPathThumb);
				}
				
				if ($fullPathGallery != "") {
					unlink("../".$fullPathGallery);
				}
			} catch (Exception $e) {
				$msg .= MODIFYPROJECT_MESSAGE_EXCEPTION_1;
				$msg .= MODIFYPROJECT_MESSAGE_EXCEPTION_2;
				$msg .= MODIFYPROJECT_MESSAGE_EXCEPTION_3.$e->getMessage();
	        	$msg .= MODIFYPROJECT_MESSAGE_EXCEPTION_4.$e->getFile();
	        	$msg .= MODIFYPROJECT_MESSAGE_EXCEPTION_5.$e->getLine();
	        	$msg .= MODIFYPROJECT_MESSAGE_EXCEPTION_6;
			}
		}
		?>	
		<center>
			<?=$msg?>
			<a href="home.php?id=projects&action=manage&type=e" class="back"><?=MODIFYPROJECT_LINK_CONTINUE?></a>
		</center>
		<?php
	} else {
		$query = $db->query("select * from ".TABPREFIX."projects where id=".$pid);
		$row = $query->fetch();
		?>
		<form action="home.php?id=projects&action=modify&pid=<?=$pid?>" method="post" name="form_project" id="form_project" enctype="multipart/form-data">
			<input type="hidden" id="idproject" name="idproject" value="-1">
			<fieldset>
				<div>
					<label><?=MODIFYPROJECT_FORM_CATEGORY?></label>
					<select name="category">
						<?php 
						$resultCategory = $db->query("select * from ".TABPREFIX."categories where deleted = 0 order by name");
						while ($rowCategory = $resultCategory->fetch()) {
							if ($rowCategory['id'] == $row['id_category']) {
								?>
								<option value="<?=$rowCategory['id']?>" selected="selected"><?=$rowCategory['name']?></option>
								<?php
							} else {
								?>
								<option value="<?=$rowCategory['id']?>"><?=$rowCategory['name']?></option>
								<?php 	
							}
						}
						?>
					</select>
				</div>
				<div>
					<label><?=MODIFYPROJECT_FORM_NAME?></label>
					<input type="text" id="idname" name="name" size="30" value="<?=$row['title']?>">
				</div>
				<div>
					<label><?=MODIFYPROJECT_FORM_DESCRIPTION?></label>
					<textarea rows="15" class="tinymce" name="description"><?=$row['body']?></textarea>
				</div>
				<div>
					<label><?=MODIFYPROJECT_FORM_THUMBNAIL?></label>
					<input type="file" name="thumb">
					<?php 
					if (isset($row['path_thumb']) && $row['path_thumb'] != "") {
						?>
						<a href="../<?=$row['path_thumb']?>" class="lightbox"><?=MODIFYPROJECT_LINK_VIEW_THUMBNAIL?></a>
						<?php 	
					}
					?>
				</div>
				<div>
					<label><?=MODIFYPROJECT_FORM_IMAGE?></label>
					<input type="file" name="image">
					<?php 
					if (isset($row['path_img']) && $row['path_img'] != "") {
						?>
						<a href="../<?=$row['path_img']?>" class="lightbox"><?=MODIFYPROJECT_LINK_VIEW_IMAGE?></a>
						<?php 	
					}
					?>
				</div>
				<div style="text-align: center;">
					<input type="submit" name="action" value="<?=MODIFYPROJECT_FORM_SUBMIT?>">
				</div>
			</fieldset>
		</form>
		<br>
		<center>
			<a href="javascript:history.back()" class="back"><?=MODIFYPROJECT_LINK_BACK?></a>
		</center>
		<?php 
	}
}
?>
Return current item: EZphotopress