<?php
class Insert_products extends CI_Model{
function __construct()
{
parent::__construct();
}
function getleads($id)
{
$this->db->select('l_id');
$this->db->from('leads');
$query = $this->db->get();
return $query->result();
}
function insertproduct($data)
{
$query= $this->db->insert('product_master', $data);
return $query;
}
function productslist()
{
$query = $this->db
->select('*')
->from('product_master')
->get();
return $query->result();
}
function getproductsid($id)
{
$this->db->select('*');
$this->db->from('product_master');
$this->db->where('p_id', $id); // Also mention table name here
$query = $this->db->get();
return $query->result();
}}
?>
View:
<?php include_once "vwHeader.php" ?>
<html>
<body>
<div class="content-wrapper">
<section class="content-header">
<ol class="breadcrumb">
<li><a href="#">Unassign <i class="fa fa-times"></i></a></li>
</ol>
</section>
<br>
<?php include_once "vwLeadshead.php" ; ?>
<section class="content">
<div class="row">
<?php include_once "vwMenu.php" ; ?>
<div class="col-lg-9 col-xs-9">
<div class="box box-primary">
<div class="box-header">
Products
</div>
</div>
</div>
<div class="col-xs-9 col-xs-9">
<div class="input-group">
<input type="text" name="q" id="field1" onchange="duplicate()" class="form-control" placeholder="Product Name">
<span class="input-group-btn">
<p class="text-center">
<button class="btn btn-primary" data-toggle="modal" data-target="#productModal"><i class="fa fa-plus"></i>Add Product</button>
</p>
<div class="modal fade" id="productModal" tabindex="-1" role="dialog" aria-labelledby="Login" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h3 class="modal-title" id="myModalLabel">Add Product</h3>
</div>
<div class="modal-body">
<!-- The form is placed inside the body of modal -->
<?php echo form_open('admin/products/addproduct',['class'=>'form-horizontal panel' , 'method'=> 'POST', 'enctype'=>'multipart/form-data']); ?>
<div class="form-group">
<label class="col-xs-3 control-label"><h4>Product Name</h4></label>
<div class="col-xs-8">
<input type="text" id="field2" class="form-control" placeholder="Products Name" name="p_name" />
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label"><h4>Short Description</h4></label>
<div class="col-xs-8">
<input type="text" id="field2" class="form-control" placeholder="Short Description" name="p_short_name" />
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label"><h4>Long Description</h4></label>
<div class="col-xs-8">
<TEXTAREA Name="p_long_description" placeholder="Long Description" class="form-control" rows="4" cols="40"></TEXTAREA>
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label"><h4>image upload</h4></label>
<div class="col-xs-8">
<input name="attachment" class="form-control" type="file">
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label"><h4>Cost Price</h4></label>
<div class="col-xs-8">
<input type="text" class="form-control" placeholder="Cost Price" name="p_costprice" />
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label"><h4>Selling Price</h4></label>
<div class="col-xs-8">
<input type="text" class="form-control" placeholder="SellingPrice" name="p_sellingprice" />
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label"><h4>Supplier</h4></label>
<div class="col-xs-8">
<input type="text" class="form-control" placeholder="Supplier" name="p_supplier" />
</div>
</div>
<div class="form-group">
<label class="col-xs-3 control-label"><h4>Inventory</h4></label>
<div class="col-xs-8">
<input type="text" placeholder="Inventory" class="form-control" name="p_inventory" />
</div>
</div>
<div class="form-group">
<div class="col-xs-8 col-xs-offset-5">
<?php
echo form_reset(['name'=>'cancel', 'data-dismiss'=>'modal' , 'value'=>'Reset' , 'class'=>'btn btn-default']);
?>
<?php
echo form_submit(['name'=>'submit' , 'value'=>'Submit' , 'class'=>'btn btn-primary']);
?>
</div>
</div>
</form>
</div>
<div class="row">
<div class="col-xs-4 col-xs-4">
<br>
<table class="table_responsive">
<thead>
<tr>
<th>Name</th>
<th>Short Name</th>
<th>Long Description</th>
<th>Cost Price</th>
<th>Selling Price</th>
<th>Supplier</th>
<th>Inventory</th>
<th colspan="2">Action</th>
</tr>
</thead>
<?php
foreach ($record as $row)
{
?>
<tbody>
<tr>
<td><?php echo $row->p_name;?></td>
<td><?php echo $row->p_short_name;?></td>
<td><?php echo $row->p_long_description;?></td>
<td><?php echo $row->p_costprice;?></td>
<td><?php echo $row->p_sellingprice;?></td>
<td><?php echo $row->p_supplier;?></td>
<td><?php echo $row->p_inventory;?></td>
<td><a href="#">Edit</a></td>
<td><a href="#">Delete</a></td>
</tr>
</tbody>
<?php
}
?>
</table>
</div>
</div>
</div>
</section>
</body>
</html>
<?php include_once "vwFooter.php" ?>
Controller:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Products extends CI_Controller {
/**
* ark Admin Panel for Codeigniter
* Author: Abhishek R. Kaushik
* downloaded from http://devzone.co.in
*
*/
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
if (!$this->session->userdata('is_admin_login')) {
redirect('admin/home');
}
}
public function index() {
$query = $this->db->get("product_master");
$data['records'] = $query->result();
$data['page']='products';
$this->load->view("admin/vwProducts" , $data);
}
public function addproduct() {
$this->load->model('admin/insert_products');
$this->load->library('form_validation');
$this->form_validation->set_rules('p_name', 'productname');
$this->form_validation->set_rules('p_short_name', 'shortdesc', 'required');
$this->form_validation->set_rules('p_long_description', 'longdesc', 'required');
$this->form_validation->set_rules('p_costprice', 'cprice');
$this->form_validation->set_rules('p_sellingprice', 'sprice');
$this->form_validation->set_rules('p_supplier', 'supplier');
$this->form_validation->set_rules('p_inventory', 'inventory');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/vwProducts');
redirect('admin/products?ids='.$this->input->get('ids'));
}
else {
//Setting values for tabel columns
$data = array(
'p_name' => $this->input->post('p_name'),
'p_short_name' => $this->input->post('p_short_name'),
'p_long_description' => $this->input->post('p_long_description'),
'p_costprice' => $this->input->post('p_costprice'),
'p_sellingprice' => $this->input->post('p_sellingprice'),
'p_supplier' => $this->input->post('supplier'),
'p_inventory' => $this->input->post('p_inventory'),
);
unset($_POST);
$this->insert_products->insertproduct($data);
$this->load->view("admin/vwProducts",$data);
redirect('admin/products?ids='.$this->input->get('ids'));
}
}
public function productlist()
{
$this->load->library('table');
$id=$this->input->get('id');
$this->load->model('admin/insert_products');
$data['records']=$this->insert_products->getproductsid($id);
//return the data in view
$this->load->view('admin/vwProductlist', $data);
}
public function edit_user() {
$arr['page'] = 'products';
$this->load->view('admin/vwEditUser',$arr);
}
public function block_user() {
// Code goes here
}
public function delete_user() {
// Code goes here
}
}
?>