Location: PHPKode > projects > EZphotopress > ezphotopress-1.0.0/admin/projects/addProject.php
<h3>Create new project</h3>
<br>
<?php
if (isset($_POST['action']) && $_POST['action'] == ADDPROJECT_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;
		}
	}
	
	$query = "insert into ".TABPREFIX."projects(id_category,title,body,path_thumb,path_img,create_date,last_modify,deleted) values(";
	$query .= $category.",";
	$query .= "'".addslashes($name)."',";
	$query .= "'".addslashes($description)."',";
	
	if ($thumbUpload == 1) {
		$query .= "'".$fullPathThumb."',";
	} else {
		$query .= "'',";
	}
	
	if ($imageUpload == 1) {
		$query .= "'".$fullPathGallery."',";
	} else {
		$query .= "'',";
	}
	
	$query .= "NOW(),";
	$query .= "NOW(),";
	$query .= "0";
	$query .= ")";
	
	$result = $db->query($query);
	if ($result->sizeIDU() != -1) {
		$msg = '';
		if ($thumbUpload == 0) {
			$msg .= ADDPROJECT_ERROR_UPLOAD_THUMBNAIL;
		}
		
		if ($imageUpload == 0) {
			$msg .= ADDPROJECT_ERROR_UPLOAD_IMAGE;
		}
		?>
		<p class="ok">
			<?=$msg?>
			<?=ADDPROJECT_MESSAGE_SUCCESS?>
		</p>
		<br>
		<center>
			<a href="home.php?id=projects&action=new" class="back"><?=ADDPROJECT_LINK_CREATE?></a>
		</center>
		<?php
	} else {
		?>				
		<p class="ok">
			<?=ADDPROJECT_MESSAGE_ERROR?>
		</p>
		<br>
		<center>
			<a href="home.php?id=projects&action=new" class="back"><?=ADDPROJECT_LINK_CREATE?></a>
		</center>
		<?php
		//try to remove the uplodaed files
		try {
			if ($fullPathThumb != "") {
				unlink("../".$fullPathThumb);
			}
			
			if ($fullPathGallery != "") {
				unlink("../".$fullPathGallery);
			}
		} catch (Exception $e) {
			echo ADDPROJECT_MESSAGE_EXCEPTION_1;
			echo ADDPROJECT_MESSAGE_EXCEPTION_2;
			echo ADDPROJECT_MESSAGE_EXCEPTION_3.$e->getMessage();
        	echo ADDPROJECT_MESSAGE_EXCEPTION_4.$e->getFile();
        	echo ADDPROJECT_MESSAGE_EXCEPTION_5.$e->getLine();
        	echo ADDPROJECT_MESSAGE_EXCEPTION_6;
		}
	}
} else {
	?>
	<form action="home.php?id=projects&action=new" method="post" name="form_project" id="form_project" enctype="multipart/form-data">
		<input type="hidden" id="idproject" name="idproject" value="-1">
		<fieldset>
			<div>
				<label><?=ADDPROJECT_FORM_CATEGORY?></label>
				<select name="category">
					<?php 
					$result = $db->query("select * from ".TABPREFIX."categories where deleted = 0 order by name");
					while ($row = $result->fetch()) {
						?>
						<option value="<?=$row['id']?>"><?=$row['name']?></option>
						<?php 	
					}
					?>
				</select>
			</div>
			<div>
				<label><?=ADDPROJECT_FORM_NAME?></label>
				<input type="text" id="idname" name="name"  size="30">
			</div>
			<div>
				<label><?=ADDPROJECT_FORM_DESCRIPTION?></label>
				<textarea rows="15" class="tinymce" name="description"></textarea>
			</div>
			<div>
				<label><?=ADDPROJECT_FORM_THUMBNAIL?></label>
				<input type="file" name="thumb">
			</div>
			<div>
				<label><?=ADDPROJECT_FORM_IMAGE?></label>
				<input type="file" name="image">
			</div>
			<div style="text-align: center;">
				<input type="submit" name="action" value="<?=ADDPROJECT_FORM_SUBMIT?>">
			</div>
		</fieldset>
	</form>
	<?php 
}
?>
Return current item: EZphotopress