Location: PHPKode > projects > EZphotopress > ezphotopress-1.0.0/admin/categories/modifyCategory.php
<h3><?=MODIFYCATEGORY_TITLE?></h3>
<br>
<?php
if (isset($catid) && $catid != '' && is_numeric($catid) && $catid > 0) {
	if (isset($_POST['action']) && $_POST['action'] == MODIFYCATEGORY_SUBMIT_FORM) {
		$name = $_POST['name'];
		
		//if thummb is uploaded, get the path and move it
		$imageUpload = 0;
		$filename = time();
		$fullPathCategory = "";
		
		if (@is_uploaded_file($_FILES['image']['tmp_name'])) {
			$ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
			$fullPathCategory = $_CONFIG['category_path'].$filename.".".$ext;
			if (@move_uploaded_file($_FILES['image']['tmp_name'], "../".$fullPathCategory)) {
				$imageUpload = 1;
			}
		}
		
		$query = "update ".TABPREFIX."categories set name='".addslashes($name)."',";
		if ($imageUpload == 1) {
			$query .= "path_img='".$fullPathCategory."',";	
		}
		$query .= "last_modify=NOW() where id=".$catid;
		$result = $db->query($query) or die("update categories - ");
		
		$msg = '';
		if ($result->sizeIDU() != -1) {
			$msg .= MODIFYCATEGORY_MESSAGE_SUCCESS;
			
			if ($imageUpload == 1) {
				$msg .= MODIFYCATEGORY_MESSAGE_SUCCESS_2;
				//try to detele the image
				if (isset($rowImage['path_img']) && $rowImage['path_img'] != "") {
					try {
						@unlink("../".$rowImage['path_img']);
						$msg .= MODIFYCATEGORY_MESSAGE_SUCCESS_3_1.$rowImage['path_img'].MODIFYCATEGORY_MESSAGE_SUCCESS_3_2;
					} catch (Exception $e) {
						$msg .= MODIFYCATEGORY_MESSAGE_ERROR_1_1.$rowImage['path_img'].MODIFYCATEGORY_MESSAGE_ERROR_1_2;
					}
				}
			} else {
				$msg .= MODIFYCATEGORY_MESSAGE_ERROR_2;
			}
		} else {
			$msg .= MODIFYCATEGORY_MESSAGE_ERROR_3;
			//try to remove the uplodaed files
			try {
				if ($fullPathCategory != "") {
					@unlink("../".$fullPathCategory);
				}
			} catch (Exception $e) {
				$msg .= MODIFYCATEGORY_MESSAGE_EXCEPTION_1;
				$msg .= MODIFYCATEGORY_MESSAGE_EXCEPTION_2;
				$msg .= MODIFYCATEGORY_MESSAGE_EXCEPTION_3.$e->getMessage();
	        	$msg .= MODIFYCATEGORY_MESSAGE_EXCEPTION_4.$e->getFile();
	        	$msg .= MODIFYCATEGORY_MESSAGE_EXCEPTION_5.$e->getLine();
	        	$msg .= MODIFYCATEGORY_MESSAGE_EXCEPTIOO_6;
			}
		}
		?>	
		<center>
			<?=$msg?>
			<a href="home.php?id=cate&action=manage&type=e" class="back"><?=MODIFYCATEGORY_CONTINUE?></a>
		</center>
		<?php
	} else {
		$result = $db->query("select * from ".TABPREFIX."categories where id = ".$catid);
		$row = $result->fetch();
		?>
		<form action="home.php?id=cate&action=modify&catid=<?=$catid?>" method="post" name="form_category" id="form_category" enctype="multipart/form-data">
			<input type="hidden" id="idcate" name="idcate" value="<?=$catid?>">
			<fieldset>
				<div>
					<label><?=MODIFYCATEGORY_FORM_NAME?></label>
					<input type="text" id="idname" name="name"  size="30" value="<?=$row['name']?>">
				</div>
				<div>
					<label><?=MODIFYCATEGORY_FORM_IMAGE?></label>
					<input type="file" name="image">
					<?php 
					if (isset($row['path_img']) && $row['path_img'] != "") {
						?>
						<a href="../<?=$row['path_img']?>" class="lightbox"><?=MODIFYCATEGORY_LINK_VIEW_IMAGE?></a>
						<?php 	
					}
					?>
				</div>
				<div style="text-align: center;">
					<input type="submit" name="action" value="<?=MODIFYCATEGORY_SUBMIT_FORM?>">
				</div>
			</fieldset>
		</form>
		<br>
		<center>
			<a href="javascript:history.back()" class="back"><?=MODIFYCATEGORY_LINK_BACK?></a>
		</center>
	<?php
	}
}
?>
Return current item: EZphotopress