0byt3m1n1
Path:
/
var
/
www
/
listcrawler.app
/
public_html
/
admin
/
[
Home
]
File: add_list.php
<?php session_start(); require_once 'config/config.php'; require_once BASE_PATH.'/includes/auth_validate.php'; $db = getDbInstance(); // Serve POST method, After successful insert, redirect to lists.php page. if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Mass Insert Data. Keep "name" attribute in html form same as column name in mysql table. $data_to_db = array_filter($_POST); $listdata_to_db = array( 'list_title' => trim($data_to_db['list_title']), 'list_desc' => trim($data_to_db['list_desc']), 'age' => trim($data_to_db['age']) ); $last_id = $db->insert('lists', $listdata_to_db); if ($last_id) { // Add List Location $lists_locations_data = array( 'list_id' => $last_id, 'location_id' => trim($data_to_db['location_id']), 'subarea_id' => 0 ); $db->insert('lists_locations', $lists_locations_data); // Add pic 1 if(isset($_FILES['pic1']['name']) && $_FILES['pic1']['name']!='') { $pic=$_FILES['pic1']['name']; $path = pathinfo($pic); $filename = $path['filename']; $ext = $path['extension']; $final_pic = rand(10,100) . "" .time() . "." . $ext; $path = "../pics/" . $final_pic; $thumb = "../pics/" . $final_pic; move_uploaded_file($_FILES['pic1']['tmp_name'],$path); resizeImage($path, $thumb, 500, 650); $pic1_data = array( 'list_id' => $last_id, 'photo_name' => $final_pic ); $db->insert('photos', $pic1_data); } // Add pic 2 if(isset($_FILES['pic2']['name']) && $_FILES['pic2']['name']!='') { $pic=$_FILES['pic2']['name']; $path = pathinfo($pic); $filename = $path['filename']; $ext = $path['extension']; $final_pic = rand(10,100) . "" .time() . "." . $ext; $path = "../pics/" . $final_pic; $thumb = "../pics/" . $final_pic; move_uploaded_file($_FILES['pic2']['tmp_name'],$path); resizeImage($path, $thumb, 500, 650); $pic2_data = array( 'list_id' => $last_id, 'photo_name' => $final_pic ); $db->insert('photos', $pic2_data); } // Add pic 3 if(isset($_FILES['pic3']['name']) && $_FILES['pic3']['name']!='') { $pic=$_FILES['pic3']['name']; $path = pathinfo($pic); $filename = $path['filename']; $ext = $path['extension']; $final_pic = rand(10,100) . "" .time() . "." . $ext; $path = "../pics/" . $final_pic; $thumb = "../pics/" . $final_pic; move_uploaded_file($_FILES['pic3']['tmp_name'],$path); resizeImage($path, $thumb, 500, 650); $pic3_data = array( 'list_id' => $last_id, 'photo_name' => $final_pic ); $db->insert('photos', $pic3_data); } $_SESSION['success'] = 'Ad added successfully!'; // Redirect to the edit page header('Location: edit_list.php?list_id=' . $last_id . '&operation=edit'); // Important! Don't execute the rest put the exit/die. exit(); } else { echo 'Insert failed: ' . $db->getLastError(); exit(); } } // We are using same form for adding and editing. This is a create form so declare $edit = false. $getLocations = $db->rawQuery("SELECT `id`, `location_name` FROM `locations` ORDER BY `location_name` ASC "); $edit = false; ?> <?php include BASE_PATH.'/includes/header.php'; ?> <div id="page-wrapper"> <div class="row"> <div class="col-lg-6"> <h2 class="page-header">Add Ad</h2> </div> <div class="col-lg-6"> <div class="page-action-links text-right"> <a href="lists.php" class="btn btn-success"><i class="glyphicon glyphicon-chevron-left"></i> Free Ad Listing</a> </div> </div> </div> <!-- Flash messages --> <?php include BASE_PATH.'/includes/flash_messages.php'; ?> <form class="form" action="" method="post" id="list_form" enctype="multipart/form-data"> <?php include BASE_PATH.'/forms/list_form.php'; ?> </form> </div> <script type="text/javascript"> $(document).ready(function(){ $('#list_form').validate({ rules: { list_title: { required: true, minlength: 6 }, list_desc: { required: true, minlength: 6 }, age: { required: true, minlength: 2, number: true, min: 18, max: 99 }, location_id: { required: true } } }); }); </script> <?php include BASE_PATH.'/includes/footer.php'; ?>