I am trying to get confirmation message before deleting the data, and also I would like to maintain my data in database while deleting them in frontend .
here is my (project) index.php view
<div class="main-sec-contant">
<div class="ProjectsDetails">
<h2 class="heading">Projects Details</h2>
<div class="row">
<div class="col-md-12">
<table id="table_id" class="display">
<thead>
<tr>
<th>Project Name</th>
<th>Client Name</th>
<th>Company</th>
<th>Project Manager</th>
<th>Support Staff</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
foreach($project as $n)
{
?>
<tr>
<td><?php echo $n->project_name;?></td>
<td><?php echo $n->client_name;?></td>
<td><?php echo $n->company;?></td>
<td><a class="pro-circle"><img class="img-sm" src="<?php echo site_url('assets/image/man.png');?>" data-toggle="tooltip" data-placement="bottom" title="<?php echo $n-> project_manager;?>" data-original-title="Click to deactivate the user"></a>   </td>
<td><a class="pro-circle"><img class="img-sm" src="<?php echo site_url('assets/image/man.png');?>" data-toggle="tooltip" data-placement="bottom" title="<?php echo $n-> support_staff;?>" data-original-title="Click to deactivate the user"></a>  
<a class="pro-circle"><img class="img-sm" src="<?php echo site_url('assets/image/man.png');?>"></a>  
<a class="pro-circle"><img class="img-sm" src="<?php echo site_url('assets/image/man.png');?>"></a></td>
<td><span class="icoact"></span> Active</td>
<td><a class="edit" href="<?php echo site_url('admin/project/edit/'.$n->id);?>"><i class="fa fa-pencil-square-o" ></i></a>  <a class="delete" href="<?php echo site_url('admin/project/delete/'.$n->id);?>"><i class="fa fa-trash-o"></i></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
Here is my Project.php controller
public function index ()
{
$data['company_name'] = $this->project_model->getAllCompanyName();
$data['project'] = $this->project_model->getProjectDetails();
$this->load->view('admin/project/index',$data);
}
function delete($id)
{
$this->project_model->delete($id);
$this->session->set_flashdata ('success','Project Deleted Sucessfully');
redirect('admin/project/index');
}
And here is my Project_model.php , delete function
function getProjectDetails()
{
//table (projects)
$delete_flag=0;
$data['project'] = $this->db->get_where('projects',array('delete_flag!='=>$delete_flag))->result_array();
}
function getById($id)
{
return $this->db->get_where('projects',array('id'=>$id))->row();
}
function delete($id)
{
$delete_flag=0;
$this->db->where('id',$id)->update('projects',array('delete_flag'=>$delete_flag));
}
Right now I am able to delete the data successfully from both frontend and database, I would appreciate if you can help me how I can get the confirmation message, and also maintain my data in database while deleting them from frontend ?
Here is the database table
Delete in Frontend only:
Add a boolean Column "delete_flag" to your project database table and update it to TRUE when delete is clicked in frontend.
Then change your load Method in Project model to only get Projects where delete_flag = 0
Delete Confirmation:
Search for Modal Dialog. You can easily set up a message and confirm button link with a modal Dialog. Maybe you are even using a Template which already provides it.
See an example here: https://www.w3schools.com/howto/howto_css_modals.asp
For Data Delete from Frontend only but not from database:-
You should add a Column name delete_flag int datatype to your project database table and update it to 0, while deleting the record.
Data Delete Confirmation Alert Message:-
<td><a class="delete" href="<?php echo site_url('admin/project/delete/'.$n->id);?>" onclick="return confirm('Are you sure want to Delete this Record?')"><i class="fa fa-trash-o"></i></a></td>
controller Code Project.php :-
function delete($id)
{
$this->project_model->delete($id);
$this->session->set_flashdata ('success','Project Deleted Sucessfully');
redirect('admin/project/index');
}
Model Code Project_model.php :-
function getProjectDetails()
{
$delete_flag=0;
$data['project'] = $this->db->get_where('projects',array('delete_flag!='=>$delete_flag))->result_array();
}
function delete($id)
{
$delete_flag=0;
$this->db->where('id',$id)->update('projects',array('delete_flag'=>$delete_flag));
}
In Your View:-
Show Only records which have delete_flag!=0 by this query in your getProjectDetails()
Related
My team and I are making a project wherein we need to pass on variables to a modal. How do I pass the data to the modal using loan id as parameter from the table row that I selected?
example:
loan id
name
view
0964
charles
button
0562
ultor
button
when you press the button of that particular row, a modal will show up wherein the details of that row will be loaded.
In addition, the modal will also have information that would be needed, but is from a different database table, but the parameter is name instead of loan id
Is there a way to do that? I don't have a lot of experience in jquery and ajax, but i read that it might be a solution to my problem.
here is my table view that shows the button and the row information.
<?php foreach($open_applications as $row): ?>
<tr>
<td><?php echo $row->col_full_name; ?></strong><td>
<td><?php echo $row->col_loan_assignid; ?></td>
<td>
<button class="btn btn-secondary btn-xs" data-bs-toggle="modal" data-bs-target="#loanDecision">Pending</button>
<a href="<?php echo site_url('Users/borrowerdetails')?>" role="button" class="btn btn-link btn-xs">View</button>
</td>
</tr>
Here is my modal where it would need to show information that are in the row and information from a different table
<div class="modal fade" id="loanDecision" tabindex="-1" aria-labelledby="loanDecisionLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header border-0">
<h5 class="modal-title" id="loanDecisionLabel">This would be where the name is from the row</h5><br>
</div>
<div class="modal-header">
<h5 class="modal-title" id="loanDecisionSubtitle">this would be where the person's job is from the row</h5>
</div>
<div class="modal-body">
<div class="table-responsive">
<table class="table table-hover table-bordered">
<thead class="thead">
<tr>
<th scope="col">title of the column from a different table</th>
<th scope="col">title of the column from a different table</th>
<th scope="col">title of the column from a different table</th>
</tr>
</thead>
<tbody>
<tr>
<td>data from the column from the different table</td>
<td>data from the column from the different table</td>
<td>data from the column from the different table</td>
<td>data from the column from the different table</td>
<td>data from the column from the different table</td>
<td>data from the column from the different table</td>
<td>data from the column from the different table</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
I have created a controller and a model, but I don't know how to connect them to the modal, but here is my controller and model:
public function fetchDetails($col_loan_assignid, $col_borrower_id)
{
$data['getloandetails'] = $this->Users_model->getingloandetails($col_loan_assignid);
$data['getactiondetails'] = $this->Users_model->getingactiondetails($col_borrower_id);
}
public function getingloandetails($col_loan_assignid){
$sql = "select * from $this->tbl_loan_application where col_loan_assignid like '%$col_loan_assignid%'";
$query = $this->db->query($sql);
return $query->result();
}
public function getactiondetails($col_borrower_id){
$sql = "select * from $this->tbl_action where col_loan_assignid like '%$col_borrower_id%'";
$query = $this->db->query($sql);
return $query->result();
}
Step 1 : set unique id to data attributes in view button.
Example data-loanid='".$row->loanid."'
Step 2 : add a common class to view button and add event-listner to it.
Example view-btn
Step 3 : after adding event listener get data attributes from its. So you can able to access unique.
$(".view-btn").click(function(){
let loan_id=$(this).data('loanid');
console.log(loan_id);
});
Step 4 : after getting unique id so can able send a request via ajax or fetch api.
Step 5: on ci3 create a route and validate data in controller and pass data to model and fetch data from database and return response.
Fetch api Example
let ApiRequest = async function(Url,param) {
try {
const url = Url;
const options = {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: param,
//body:field1=Value1&field2=value2
}
const response = await fetch(url, options);
// response as json
return await response.json();
} catch (error) {
console.error('Error:', error);
return false;
}
}
let url="http://www.example.com/api/getdata";
let parameter=field1=Value1&field2=value2;
let Result=ApiRequest(url,parameter);
console.log(Result);
So I have a table on blade view file, I have successfully exported it into the excel file. Now I want to export without exporting the 'Actions" column. How can I do that?
I have attached my code and blade file below, it works perfectly. I just want to export everything except the Actions Column as it contains Buttons for Database Operations
THIS IS MY EXPORT CLASS CODE:
public function view(): View
{
return view ('ims.view_inventory_history_table', [
'data' => inbound_history::all()
]);
}
public function headings(): array
{
return [
'ID',
'Warehouse',
'SKU',
'Child SKU',
'Units',
'Invoice No.',
'Container No.',
'Entry Date'
];}
/**
* #return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$cellRange = 'A1:W1'; // All headers
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);
},
];
}}
THIS IS MY CONTROLLER FUNCTION:
public function export_view()
{
return Excel::download(new inboundHistory(), 'inboundHistory.xlsx');
}
THIS IS MY ROUTE:
Route::Get('inbound_history/export_view' ,'imsController#export_view')->name('inbound_history.export_view');
THIS IS MY BLADE TABLE VIEW:
<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th style="width:5%">ID</th>
<th>Warehouse</th>
<th>SKU</th>
<th>Child SKU</th>
<th>Cases</th>
<th>Units</th>
<th>Invoice No.</th>
<th>Container No.</th>
<th>Entry Date</th>
<th class="disabled-sorting text-right" style="width:12%">Actions</th>
</tr>
</thead>
<tbody>
#foreach ($data as $row)
<tr>
<td>{{$row['id']}}</td>
<td>{{$row['warehouse']}}</td>
<td>{{$row['sku_parent']}}</td>
<td>{{$row['sku_child']}}</td>
<td>{{$row['total_cases']}}</td>
<td>{{$row['total_units']}}</td>
<td>{{$row['invoice_no']}}</td>
<td>{{$row['container_no']}}</td>
<td>{{$row['date_rec']}}</td>
<td class="td-actions text-right">
{{-- <a rel="tooltip" class="btn btn-success btn-link" href="{{action('imsController#edit',$row['id'])}}">
<i class="material-icons">edit</i></a> --}}
<a rel="tooltip" class="btn btn-danger btn-link" href="{{action('imsController#destroy',$row['id'])}}" onclick = "if (! confirm('Confirm: Press OK to delete the Entry.')) { return false; }"style="color: red;">
<i class="material-icons">close</i></a>
</td>
</tr>
#endforeach
</tbody>
I don't know if I got everything correctly, but why don't you do something like this:
Pass an additional variable to your blade template like $isView, when you want to create a view for the user.
And in your blade.php template you do something like this:
#isset($isView)
<th class="disabled-sorting text-right" style="width:12%">Actions</th>
#endisset
// do the same #isset test for the corresponding <td> element
When you want to render it to excel you just don't pass this variable and the column is not rendered.
I'm trying to add products items into the shopping cart when I click to add to cart button but facing some error how to fix it error
please see this error
Non-static method Gloudemans\Shoppingcart\Cart::add() should not be called statically
http://localhost/Projects/E-commerce/cart/action
Controller
namespace App\ Http\ Controllers;
use Illuminate\ Http\ Request;
use Gloudemans\ Shoppingcart\ Cart;
class CartController extends Controller {
public
function cart() {
$cartcontent = Cart::Content();
return view('front_end/cart', ['cartcontent' => $cartcontent]);
}
public
function addcart(Request $request) {
$image = [$request - > product_image];
$add = Cart::add(
$request - > productid,
$request - > product_name,
$request - > qty,
$request - > product_price,
$image
);
if ($add) {
redirect('/cart');
}
}
html view
<tbody class="cart-table__body">
#foreach($cartcontent as $cartcontents)
<tr class="cart-table__row">
<td class="cart-table__column cart-table__column--image">
<a href="{{$cartcontents->product_image}}">
<img src="{{$cartcontents->product_image}}" alt="">
</a>
</td>
<td class="cart-table__column cart-table__column--product">
{{$cartcontents->product_name}}
</td>
<td class="cart-table__column cart-table__column--price" data-title="Price">
{{$cartcontents->product_price}}</td>
<td class="cart-table__column cart-table__column--quantity" data-title="Quantity">
<div class="input-number">
<input class="form-control input-number__input" type="number" min="1" value="
{{$cartcontents->qty}}">
<div class="input-number__add"></div>
<div class="input-number__sub"></div>
</div>
</td>
<td class="cart-table__column cart-table__column--total" data-title="Total"></td>
<td class="cart-table__column cart-table__column--remove">
<a href="" class="btn btn-light btn-sm btn-svg-icon">
<svg width="12px" height="12px">
<use xlink:href="{{url('public/assets/images/sprite.svg#cross-12')}}"></use>
</svg>
</a>
</td>
</tr>
#endforeach
</tbody>
Use this method to pass cart data to your view
public function cart()
{
$cartcontent = Cart::Content();
$cart_data = [];
foreach($cart_list as $cart){
$cart_data [] = [
//define keys as per your cart's content and pass $cart_data in your view
//like this:
// 'product' => $cart->product
];
}
return view('front_end/cart')->with(compact(['cart_data']));
}
After that loop through cart_data in your view just like you did.
I created a management system in codeigniter that loads data from the database in datatables for specific suppliers. When the user clicks at any of these data rows he is navigating to each supplier's company products. My problem is that I want to find a session or something else that will keep the data of the previous selected rows when the page reloads. At the moment I am using flashdata but when I go back a step or return to the previous page all the data from the database disappear. What I want is something that will keep my data even if I am reloading the page or if I go back a step.
That's my controller:
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
$this->load->model('dash_match_model');
$this->session->keep_flashdata('supplier_id');
$this->session->keep_flashdata('segment');
$this->session->keep_flashdata('class');
$this->session->keep_flashdata('commodity');
$this->load->library('session');
$this->load->helper('url');
}
public function index() {
$arr['page']='dash1';
$user_id = $this->session->userdata('id');
$supplier = $this->dash_match_model->dash_present_all_suppliers($user_id);
$arr['dash_present_all_suppliers'] = $supplier;
$this->load->view('clients/clDashboard',$arr);
}
public function select_supplier()
{
$supplier_name = $this->input->get('name', TRUE);
$supplier_sel = $this->dash_match_model->selected_supplier_id($supplier_name);
foreach ($supplier_sel->result() as $row){
$this->session->set_flashdata('supplier_id', $row->supplier_id);
}
$selected_supplier = $this->dash_match_model->unspsc_matched_skus($this->session->flashdata('supplier_id'));
$arr['dash_present_all_selected_suppliers'] = $selected_supplier;
$this->load->view('clients/unspscSegment', $arr);
}
public function select_segment(){
$segment = $this->input->get('segment', TRUE);
$supplier_id = $this->session->flashdata('supplier_id');
$this->session->set_flashdata('segment', $segment);
$segment_sel =$this->session->flashdata('segment');
$selected_segment = $this->dash_match_model->unspsc_class($supplier_id, $segment_sel);
$arr['dash_present_all_selected_segments'] = $selected_segment;
$this->load->view('clients/unspscClass', $arr);
}
public function select_class(){
$class = $this->input->get('class', TRUE);
$supplier_id = $this->session->flashdata('supplier_id');
$segment_sel =$this->session->flashdata('segment');
$this->session->set_flashdata('class', $class);
$class_sel = $this->session->flashdata('class');
$selected_class =$this->dash_match_model->unspsc_commodity($supplier_id, $segment_sel, $class_sel);
$arr['dash_present_all_selected_class'] = $selected_class;
$this->load->view('clients/unsspscCommodity', $arr);
That's one of my first table view file with suppliers:
<div class="row-fluid sortable">
<div class="box span12">
<div class="box-header" data-original-title>
<div class="box-icon">
<i class="halflings-icon wrench"></i>
<i class="halflings-icon chevron-up"></i>
<i class="halflings-icon remove"></i>
</div>
</div>
<div class="box-content">
<table id="suppliertable" class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Supplier</th>
<th>Open Range</th>
<th>Fill Content</th>
<th>Total Match</th>
</tr>
</thead>
<tbody>
<?php foreach($dash_present_all_suppliers as $v): ?>
<tr>
<td class="center" style="color:#0c595b;"><?php echo $v['supplierCompany']?> </td>
<td class="center">70%</td>
<td class="center">12%</td>
<td class="center">82%</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div><!--/span-->
</div>
Instead of using $this->session->flashdata() user the normal session i.e. $this->session->userdata() to store the temp browse data and write a cron which will delete this session in a regular interval or at the time of logout or any desired specific action.
Hope this will give better approach n help you in solving your problem
I have table in which data comes from the database.and I have the form on the same page which insert the data in the table.but when I insert data using $.ajax , it inserts record in database , but after reloading table in same function is not working, means it doesn't reload the table.
below is my code.
HTML
<div class="col-lg-8" id="value_table">
<div class="panel-body">
<div class="table-responsive">
<?php
$q=$db->query('select attr_val_id,attr_val,sortorder,status from db_attribute_value where attr_id="'.$attr_id.'"' );
?>
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php $c=1; while($r=$q->fetch_assoc()){?>
<tr class=" gradeX">
<td><?php echo $c; ?></td>
<td><?php echo $r['attr_val']; ?></td>
<td><a href="add_attribute_val.php?id=<?php echo $r['attr_val_id']; ?>&attr_id=<?php echo #$r['attr_id']; ?>">
<button type="button" class="btn btn-default btn-circle"><i class="fa fa-pencil-square-o"></i></button>
</a>
<button type="button" class="btn btn-danger btn-default btn-circle" id="<?php echo $r['attr_val_id']; ?>" name="deleteRecord"><i class="fa fa-times"></i></button></td>
</tr>
<?php $c++;}?>
</tbody>
</table>
</div>
<!-- /.table-responsive -->
</div>
</div>
JQuery
$('#attr_val_form').submit(function(event) {
//$('.form-group').removeClass('has-error'); // remove the error class
//$('.help-block').remove(); // remove the error text
// get the form data
// there are many ways to get this data using jQuery (you can use the class or id also)
var formData = {
'attr_val' : $('input[name=attr_val]').val(),
'attr_id' : $('input[name=attr_id]').val(),
'sortorder' : $('input[name=sortorder]').val(),
};
// process the form
$.ajax({
type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
url : 'admin_operation.php?mode=add_attr_value', // the url where we want to POST
data : formData, // our data object
cache: false,
success: function(data)
{
if($.trim(data)== 'yes')
{
$("#value_table").html($("#value_table").html());
$("#notice")
.show()
.html('<div class="alert alert-success"<strong>Successfully !</strong> record added.</div>')
.fadeOut(3000);
}
else
{
$("#notice")
.show()
.html('<div class="alert alert-danger"<strong>Error !</strong>Record already exist.</div>')
.fadeOut(10000);
}
}
})
// using the done promise callback
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
});
});
I guess what you think this line should do is get the data from the response and substitute the same tag in your DOM:
$("#value_table").html($("#value_table").html());
You should use something like that instead:
$("#value_table").html($.parseHTML(data).find("#value_table").html());
This code has not been tested, but the main idea is to parse the data parameter and the find the #value_table element.
More info here: http://api.jquery.com/jquery.parsehtml/
As you say it seems like 'admin_operation.php?mode=add_attr_value' not success, try to call to always function instead success (for debugging it).
if the always function called successfully you have to return true from admin_operation.php
if not you have a problem on admin_operation.php after the insertion.