how to upload file in codeigniter - mysql

hello I'm try to insert file in database but don't working
file which I'm upload gives the value 0 in my coloumn lampiran in database
and not file in folder to store my upload
database
id|npp|tgl_pengajuan|ket|status|lampiran|lama|tgl_mulai|tgl_selesai | id_jenis
controller
class Cutidiluar extends CI_Controller {
var $limit=10;
var $offset=10;
var $gallery_path;
var $gallery_path_url;
public function __construct(){
parent::__construct();
$this->gallery_path = realpath(APPPATH . '../asset');
$this->gallery_path_url = base_url().'asset/';
} public function add()
{ if($this->session->userdata('LOGIN')=='TRUE')
{
$this->load->library('form_validation');
$this->load->model('Diluartahunan_Model');
//load uploading file library
$config['upload_path'] = './asset/';
$config['allowed_types'] = 'jpg|png|pdf|jpeg|word';
$this->load->library('upload',$config);
$this->upload->do_upload();
$this->upload->data();
$this->form_validation->set_rules('ket', 'ket');
$this->form_validation->set_rules('lama', 'lama');
$this->form_validation->set_rules('lampiran', 'lampiran');
if ($this->form_validation->run() == false) {
$data['nama'] = $this->Diluartahunan_Model->nama();
$data['view'] = 'Cutidiluar/add';
$data['judul']='';
$this->load->view('index',$data);
}else {
$this->load->model('Cutidiluar_Model');
$this->Cutidiluar_Model->add();
redirect('Cutidiluar');
} }}
Model
public function add() {
$npp = $this->session->userdata('NPP');
$id_jenis = $this->input->post('id_jenis');
$ket = $this->input->post('ket');
$lama = $this->input->post('lama');
$tgl_selesai= date('Y-m-d',strtotime($this->input->post('tgl_selesai')));
$tgl_mulai= date('Y-m-d', strtotime($this->input->post('tgl_mulai')));
$lampiran = $this->input->post('lampiran');
$data = array(
'npp'=> $npp,
'id_jenis'=> $id_jenis,
'tgl_pengajuan' => date('y-m-d'),
'ket' => $ket,
'status' => 'P',
'lampiran'=> $lampiran,
'lama'=> $lama,
'tgl_mulai'=> $tgl_mulai,
'tgl_selesai'=> $tgl_selesai,);
$this->db->insert('Cuti_diluar', $data);}
view
<link rel="stylesheet" href="<?php echo base_url();?>css/themes/jquery.ui.all.css" type="text/css" />
<script>
$(document).ready(function() {
$( ".datepicker" ).datepicker();
});
function save(){
$.ajax({
url:'<?php echo base_url(); ?>Cutidiluar/add/',
type:'POST',
data:$('#frmsave').serialize(),
success:function(data){
if(data!=''){
$( "#infodlg" ).html(data);
$( "#infodlg" ).dialog({ title:"Info...", draggable: false});
} else {
window.location="<?php echo base_url() ?>Cutidiluar";
} } }); }
function confirmdlg(){
$("#confirm").dialog({
resizable: false,
modal: true,
title:"Info...",
draggable: false,
width: 'auto',
height: 'auto',
buttons: {
"Ya": function(){
save();
$(this).dialog("close");
window.location="<?php echo base_url() ?>Cutidiluar";
},
"Tutup": function(){
$(this).dialog("close");
}
}
});
}
</script>
<div class="span6">
<div class="well grey">
<div class="well-header">
<h5>Tambah Cuti </h5>
</div>
<div class="well-content no-search">
<form id="frmsave" name="frmsave" class="form-validate" >
<form id="frmsave" name="frmsave" class="form-validate">
<h3>Detail </h3>
<div class="form_row">
<label class="field_name">Pilih cuti</label>
<div class="field">
<?php foreach ($nama->result() as $valnama) { ?>
<input type="radio" name="id_jenis" value="<?php echo $valnama->id_jenis; ?>"> <?php echo $valnama->nama ?></br></br> <?php } ?>
</div>
</div>
<div class="form_row">
<label class="field_name">Tanggal Pengambilan Cuti</label>
<div class="field">
<input placeholder="TANGGAL MULAI CUTI" class="datepicker" size="16" type="text" name="tgl_mulai" id="tgl_mulai" value="<?php echo set_value('tgl_mulai'); ?>" >
<input placeholder="TANGGAL SELESAI CUTI" class="datepicker" size="16" type="text" name="tgl_selesai" id="tgl_selesai" value="<?php echo set_value('tgl_selesai'); ?>" >
</div>
</div>
<div class="form_row">
<label class="field_name">lama</label>
<div class="field">
<input type="text" name="lama" class="input-large" value="<?php echo set_value('lama'); ?>" placeholder="masukan lama cuti">
</div>
</div>
<div class="form_row">
<label class="field_name">Lampiran</label>
<div class="field">
<input type="file" name="userfile">
</div>
</div>
<div class="form_row">
<label class="field_name">Keterangan (MAKS 50 KARAKTER)</label>
<div class="field">
<textarea placeholder="KETERANGAN CUTI" id="ket" name="ket" class="span12" cols="40" rows="5" value="<?php echo set_value('ket'); ?>"></textarea>
</div>
</div>
<div class="form_row">
<div class="field">
<a onclick="return confirmdlg()" class="blue btn">Submit</a>
Cancel
</div>
</div>
</form>
I have change my view and model
in view
<form id="frmsave" name="frmsave" class="form-validate" enctype="multipart/form-data" >
and this my model
public function add() {
$npp = $this->session->userdata('NPP');
$id_jenis = $this->input->post('id_jenis');
$ket = $this->input->post('ket');
$lama = $this->input->post('lama');
$tgl_selesai= date('Y-m-d', strtotime($this->input->post('tgl_selesai')));
$tgl_mulai= date('Y-m-d', strtotime($this->input->post('tgl_mulai')));
$lampiran = $_FILES['userfile']['name'];
$data = array(
'npp'=> $npp,
'id_jenis'=> $id_jenis,
'tgl_pengajuan' => date('y-m-d'),
'ket' => $ket,
'status' => 'P',
'lampiran'=> $lampiran,
'lama'=> $lama,
'tgl_mulai'=> $tgl_mulai,
'tgl_selesai'=> $tgl_selesai);
and result can't insert to my database

The upload process must be done after the validation, and use $this->upload->display_errors() to see what's wrong :
$this->form_validation->run() === TRUE) {
$this->load->library('upload');
$this->upload->initialize($config);
if (!$this->upload->do_upload()){
$data['errors'] = $this->upload->display_errors(); // <-- HERE
$this->load->view('index', $data);
}
else{
$upload_data = $this->upload->data();
$this->load->model('Cutidiluar_Model');
$this->Cutidiluar_Model->add();
}

Related

Custom filter and export filtered data into excel sheet not working in codeigniter

I have data table with search filed. I am trying to filter table using data range and order status. I want to filter table also using range and status and also want to export into excel sheet. Code is working for only search and simple export (Not filtered data).
Thanks
This is my file (View, Controller and Model)
View:-
<a class="pull-right btn btn-primary btn-xs" href="<?php echo base_url()?>order/createXLS"><i class="fa fa-file-excel-o"></i> Export Data</a>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title" >Custom Filter : </h3>
</div>
<div class="panel-body">
<form id="form-filter" method="POST" action="order/ajax_list" class="form-horizontal">
<div class="form-group">
<label for="FirstName" class="col-sm-2 control-label">From</label>
<div class="col-sm-4">
<input type="date" class="form-control" id="from">
</div>
</div>
<div class="form-group">
<label for="LastName" class="col-sm-2 control-label">To</label>
<div class="col-sm-4">
<input type="date" class="form-control" id="to">
</div>
</div>
<div class="form-group">
<label for="LastName" class="col-sm-2 control-label">Status</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="status">
</div>
</div>
<div class="form-group">
<label for="LastName" class="col-sm-2 control-label"></label>
<div class="col-sm-4">
<button type="button" id="btn-filter" class="btn btn-primary">Filter</button>
<button type="button" id="btn-reset" class="btn btn-default">Reset</button>
</div>
</div>
</form>
</div>
</div>
<table class="table table-bordered table-striped" id="mytable">
<thead>
<tr>
<th width="80px">No</th>
<th>Order Number</th>
<th>Service Date</th>
<th>Service Location</th>
<th>Customer Name</th>
<th>Contact Number</th>
<th>Order Status</th>
<th>Payment Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$start = 0;
foreach ($job_positions_data as $job_positions)
{
?>
<tr>
<td>
<?php echo ++$start ?>
</td>
<td>
<?php echo $job_positions->order_number ?>
</td>
<td>
<?php echo $job_positions->service_date ?>
</td>
<td>
<?php if($job_positions->service_location == 1)
{
echo 'vkool_branch';
}
else
{
echo 'customer_location' ;
}
?>
</td>
<td>
<?php echo $job_positions->firstname ?>
</td>
<td>
<?php echo $job_positions->contact_number ?>
</td>
<td>
<?php if($job_positions->order_status == 0)
{
echo 'Action Pending';
}
elseif($job_positions->order_status == 1)
{
echo 'Under Process' ;
}
elseif($job_positions->order_status == 2)
{
echo 'Cancelled' ;
}
elseif($job_positions->order_status == 3)
{
echo 'Completed' ;
}
elseif($job_positions->order_status == 4)
{
echo 'Refund' ;
}
?>
</td>
<td>
<?php if( $job_positions->payment_status == 1)
{
echo 'Pending (Pay at Store)';
}
elseif($job_positions->payment_status == 0)
{
echo 'Pending (Pay Online)';
}
elseif($job_positions->payment_status == 14)
{
echo 'Paid';
}?>
</td>
<td style="text-align:center" width="200px">
<i class="fa fa-search-plus"></i>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$("#mytable").dataTable();
});
</script>
Controller : -
public function createXLS() {
$fileName = 'data-'.time().'.xlsx';
require_once APPPATH . "/third_party/PHPExcel/Classes/PHPExcel.php";
$orderInfo = $this->Order_model->get_For_Export();
$ordervalue = json_encode($orderInfo, true);
/*echo '<pre>';
print_r($orderInfo);
echo '</pre>';
exit;*/
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
// set Header
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'S.No');
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Order Number');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Service Location');
$objPHPExcel->getActiveSheet()->SetCellValue('D1', 'First Name');
$objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Last Name');
$objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Contact_No');
$objPHPExcel->getActiveSheet()->SetCellValue('G1', 'Order Status');
$objPHPExcel->getActiveSheet()->SetCellValue('H1', 'Payment Status');
// Style
$style = array(
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
),
'font' => array(
'bold' => true,
'color' => array('rgb' => '2F4F4F'),
'size' => 20,
),
);
$styleHeading = array(
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
),
'font' => array(
'bold' => true,
'size' => 15,
),
);
// set Row
$rowCount = 2;
foreach ($orderInfo as $element) {
$objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $element['id']);
$objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $element['order_number']);
$objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $element['service_location']);
$objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowCount, $element['firstname']);
$objPHPExcel->getActiveSheet()->SetCellValue('E' . $rowCount, $element['lastname']);
$objPHPExcel->getActiveSheet()->SetCellValue('F' . $rowCount, $element['contact_number']);
$objPHPExcel->getActiveSheet()->SetCellValue('G' . $rowCount, $element['order_status']);
$objPHPExcel->getActiveSheet()->SetCellValue('H' . $rowCount, $element['payment_status']);
$rowCount++;
}
// download file
$filename = "jobSummery". date("Y-m-d-H-i-s").".xls";
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
public function list_view()
{
$job_positions = $this->Order_model->get_all();
$data = array(
'job_positions_data' => $job_positions
);
$this->load->view('order/index', $data);
}
Model :-
public function get_all()
{
$this->db->order_by('id', 'DESC');
$this->db->from('tbl_order');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function get_For_Export()
{
$this->db->order_by('id', 'DESC');
$this->db->from('tbl_order');
$query = $this->db->get();
$result = $query->result_array();
return $result;
}

how to enter data according to the user who is currently logged in?

i make a table post and i have a field email_id to foreign key with user id and i make some Added posting, my question is how i can added automaticly the email_id from who the user session posting it.. i have tried 2 days and the post can be post but the email_id not automaticly get the data from who posting it..
<?php echo form_open_multipart('user/addpost'); ?>
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control" id="namaFes" name="namaFes" placeholder="Nama Festival">
</div>
<div class="form-group">
<select name="daerah_id" id="daerah_id" class="form-control">
<option value="">Pilih Daerah</option>
<?php foreach ($nm_daerah as $nm) : ?>
<option value="<?= $nm['id_daerah']; ?>"><?= $nm['nm_daerah']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<input type="date" class="form-control" id="tanggal" name="tanggal" placeholder="Tanggal Festival">
</div>
<div class="form-group">
<textarea style="height: 80px;" class="form-control" id="deskripsi" name="deskripsi" placeholder="Keterangan"></textarea>
</div>
<div class="form-group">
<input type="text" class="form-control" id="email_id" name="email_id" value="<?= $user['email']; ?>" readonly>
<!--<div class=" form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" name="isActive" id="isActive" checked>
<label class="form-check-label" for="isActive">
Is it active?
</label>
</div>
</div>-->
<div class="custom-file">
<input type="file" class="custom-file-input" id="image" name="image">
<label class="custom-file-label" for="image">Choose 1:1 image...</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add</button>
<? echo form_close(); ?>
this my addedpost.php
$data['title'] = 'Add Posting';
$data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();
$data['nm_daerah'] = $this->db->get('daerah')->result_array();
$data['postfes'] = $this->db->get('postfes')->row_array();
$this->load->model('PostModel', 'post');
$data['postFes'] = $this->post->getPostModel4();
$this->form_validation->set_rules('namaFes', 'Nama Festival', 'required|trim');
$this->form_validation->set_rules('daerah_id', 'Nama Daerah', 'required|trim');
$this->form_validation->set_rules('tanggal', 'Tanggal', 'required|trim');
$this->form_validation->set_rules('deskripsi', 'Deskripsi', 'required|trim');
if ($this->form_validation->run() == false) {
$this->load->view('templates/user-header', $data);
$this->load->view('templates/user-sidebar', $data);
$this->load->view('templates/user-topbar', $data);
$this->load->view('user/addpost', $data);
$this->load->view('templates/user-footer');
} else {
$namaFes = $this->input->post('namaFes');
$daerah = $this->input->post('daerah_id');
$tanggal = $this->input->post('tanggal');
$desk = $this->input->post('deskripsi');
$idpost = $this->input->post('email_id');
$image = $_FILES['image'];
if ($image = '') {
} else {
$config['upload_path'] = './assets/img/posting/';
$config['allowed_types'] = 'jpg|gif|png|jpeg';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('image')) {
echo 'failed upload image';
die();
} else {
$image = $this->upload->data('file_name');
}
}
$data = [
'namaFes' => $namaFes,
'daerah_id' => $daerah,
'tanggal' => $tanggal,
'deskripsi' => $desk,
'email_id' => $idpost,
'image' => $image
];
$this->db->insert('postfes', $data);
$this->session->set_flashdata('message', '<div class="alert alert-success" role="alert">Please wait admin approve your post</div>');
redirect('user/addpost');
}
}
and this my model and controller i join it
<input type="text" class="form-control" id="email_id" name="email_id" value="<?= $user['email']; ?>" readonly>
you email show and email against email_id post on controller page.
you can use on view page this:
<input type="text" class="form-control" id="email" name="email" value="<?= $user['email']; ?>" readonly>
<input type="hidden" class="form-control" id="email_id" name="email_id" value="<?= $user['email_id']; ?>">
and then on controller page:
$emailpost = $this->input->post('email');
$idpost = $this->input->post('email_id');
$data = [
'namaFes' => $namaFes,
'daerah_id' => $daerah,
'tanggal' => $tanggal,
'deskripsi' => $desk,
'email_id' => $idpost,
'email' => $emailpost,
'image' => $image
];
Please replace these code and your issue resolved.

MySQL Update Batch Process Remove Some Records

I have a program to store some financial values using batch process. Main tables are finance_budget & finance_budget_issue. finance_budget.budget_id = finance_budget_issue.budget_id (1 to many join)
I tried to edit some records using following code
Controller
public function editIssues($id)
{
$this->checkPermissions('edit', 'allocationIssues');
$bc = array(array('link' => 'budget/regIssues', 'page' => 'Allocation Issues'), array('link' => '#', 'page' => 'Edit'));
$meta = array('page_title' => 'Allocation Issues', 'bc' => $bc);
$this->form_validation->set_rules('vote_id', 'Vote', 'required');
$this->form_validation->set_rules('budget_date', 'Budget Date', 'required');
if ($this->form_validation->run() == true) {
$ustock = array(
'vote_id' => $this->input->post('vote_id'),
'budget_date' => $this->input->post('budget_date'),
'ref_no' => $this->input->post('ref_no'),
'usr' => $this->session->userdata('id_user'),
'added_time' => date('Y-m-d h:i:s'),
'budget_status' => 'issues',
'transfer_status' => 'Pending'
);
$count = count($this->input->post('office'));
$offices = $this->input->post('office');
$amount = $this->input->post('amount');
$notes = $this->input->post('notes');
for ($x = 0; $x < $count; $x++) {
$details[$x]['budget_id'] = $id;
$details[$x]['office'] = $offices[$x];
$details[$x]['amount'] = $amount[$x];
$details[$x]['notes'] = $notes[$x];
}
}
if ($this->form_validation->run() == true && $this->Budget_model->editIssuedAllocations($ustock, $details, $id)) {
$this->session->set_flashdata('message', 'Successfully Updated ..!!');
redirect('budget/regIssues');
} else {
$this->data['vote'] = $this->Budget_model->getVote(array('office_id'=>$this->session->userdata('office_id')));
$this->data['office'] = $this->Budget_model->getOffice();
$this->data['issues'] = $this->Budget_model->budgetById($id);
$this->render('budget/editIssues', $meta, $this->data);
}
}
Model
function editIssuedAllocations($ustock,$details,$id)
{
if(!empty($id)){
$this->db->trans_start();
$this->db->update('finance_budget',$ustock,array('budget_id'=>$id));
if($id!=1){
$this->db->where('budget_id', $id);
$this->db->delete('finance_budget_issue');
$this->db->insert_batch('finance_budget_issue', $details);
}
$this->db->trans_complete();
return $this->db->trans_status();
}
return false;
}
View
<?php
if (!empty($purchase)) {
$details = $purchase;
$purchase = $purchase[0];
}
?>
<script type="text/javascript">
$(document).ready(function () {
var i = $('#last').val();
$(".add-new").click(function () {
i++;
// $('.tab_logic').append();
$('#addr' + i).html("<td><a href='javascript:void(0);' id='add-post' class='external add-new'><i style='color: #00C853 !important;' class='fa fa-2x fa-plus-circle'></i></a></td>" +
"<td><select name='office[]' id='office" + i + "' class='select2 form-control' required>" +
"<option value=''></option>" +
<?php
if (!empty($office)) {
foreach ($office as $row) {
?>
"<option value='<?= $row->office_id ?>'><?= addslashes($row->office_name) ?></option>" +
<?php
}
}
?>
"</select></td>" +
"<td><input name='amount[]' type='number' step='any' placeholder='Amount' class='form-control input-md' required></td>" +
"<td><input name='notes[]' type='text' placeholder='Notes' class='form-control input-md'></td>" +
"<td><a href='javascript:void(0);' class='external remove'><i style='color: #dd4b39 !important;' class='fa fa-2x fa-minus-circle' id='addIcon'></i></a></td>");
$('#tab_logic').append('<tr id="addr' + (i + 1) + '"></tr>');
$('#i').val(i);
// alert($('#i').val());
$('#item' + i).select2();
});
$(document).on("click", ".remove", function () {
var count = $('#tab_logic>tbody').children().length;
if (count > 0) {
$(this).closest('tr').remove();
}
});
});
</script>
<div class="box box-info">
<div class="box box-info collapsed-box">
<div class="box-header with-border">
<h3 class="box-title">Edit Issued Allocations</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" style="font-size: 16px;" data-widget="collapse"><i
class="fa fa-plus"></i>
</button>
</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body" style="display: block">
<form action="<?= site_url('budget/editPurchase/' . $purchase->budget_id) ?>" method="post">
<div class="row">
<div class="col-md-2">
<div class="form-group"><label>Budget ID</label>
<input type="text" name="budget_id" id="budget_id" class="form-control" disabled
value="<?= $purchase->budget_id ?> ">
</div>
</div>
<div class="col-md-4">
<div class="form-group"><label>වැය ශීර්ෂය</label>
<select name="vote_id" id="vote_id" class="form-control select2" required>
<option value="<?= $purchase->vote_id ?>"><?= $purchase->vote ?></option>
<?php
if (!empty($vote)) {
foreach ($vote as $row) {
?>
<option value="<?= $row->vote_id ?>"><?= $row->vote ?></option>
<?php
}
}
?>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group"><label>යොමු / ගොණු අංකය</label>
<input type="text" name="ref_no" id="ref_no" class="form-control"
value="<?= $purchase->ref_no ?>">
</div>
</div>
<div class="col-md-2">
<div class="form-group"><label>දිනය</label>
<input type="date" name="budget_date" id="budget_date" class="form-control"
value="<?= $purchase->budget_date ?>">
</div>
</div>
</div>
<div class="col-md-12 column">
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr>
<th class="text-center">
</th>
<th class="text-center">
Office
</th>
<th class="text-center">
Amount
</th>
<th class="text-center">
Notes
</th>
<th class="text-center">
</th>
</tr>
</thead>
<tbody>
<?php
//dd($details);
$x = 0;
foreach ($details as $i => $values) {
// foreach ($values as $key => $value) {
$x = $i;
?>
<tr id='addr0'>
<td>
<a href="javascript:void(0);" id="add-post" class="external add-new"><i
style="color: #00C853 !important;"
class="fa fa-2x fa-plus-circle"></i></a>
</td>
<td style="width: 50%">
<input type="hidden" name="i" id="i" value="<?= $i ?>">
<select name="office[]" id="<?= "office" . $i ?>" class="form-control select2" required>
<option value="<?= $details[$i]->office_id ?>"><?= $details[$i]->office_name ?></option>
<?php
if (!empty($office)) {
foreach ($office as $row) {
?>
<option value="<?= $row->office_id ?>"><?= $row->office_name ?></option>
<?php
}
}
?>
</select>
</td>
<td>
<input type="number" name='amount[]' placeholder='Amount' class="form-control"
value="<?= (-1) * $details[$i]->amount ?>" required/>
</td>
<td>
<input type="text" name="notes[]" placeholder='Notes'
value="<?= $details[$i]->notes ?>" class="form-control"/>
<input type="hidden" name="table_id"
value="<?= $details[$i]->notes ?>">
</td>
<td><a href='javascript:void(0)' class='external remove'><i
style='color: #dd4b39 !important;'
class='fa fa-2x fa-minus-circle ' id='addIcon'></i></a>
</td>
</tr>
<tr id='addr1'></tr>
<?php
//print " $key => $value\n";
// }
//print "}\n";
}
?>
</tbody>
</table>
</div>
<!--table-->
<div class="row">
<div class="col-md-8"></div>
<div class="col-md-4">
<input type="hidden" value="<?= $x ?>" name="last" id="last">
<input type="submit" value="Update" class="btn btn-primary btn-block">
</div>
</div>
</form>
<!--end of table-->
</div>
</div>
</div>
Desired Output
Should be edit some values in the finance_budget & finance_budget_issue tables that related with same budget_id (Eg:- budget_id =2995)
Error
After editing some values in my view that is working & save properly. When I press the save button in my view without editing any value, the record in finance_budget_issue table that is related to finance_budget table by budget_id is deleted.
I can not understand what I am going wrong ? Can anyone help me ?
You could modify the model to check whether $details are empty or not to leave the finance_budget_issue table intact :
function editIssuedAllocations($ustock,$details,$id)
{
if(!empty($id)){
$this->db->trans_start();
$this->db->update('finance_budget',$ustock,array('budget_id'=>$id));
if($id!=1 && !empty($details[0])){
$this->db->where('budget_id', $id);
$this->db->delete('finance_budget_issue');
$this->db->insert_batch('finance_budget_issue', $details);
}
$this->db->trans_complete();
return $this->db->trans_status();
}
return false;
}
I have modified the for loop as follows in the controller.
$count = count($this->input->post('office'));
$offices = $this->input->post('office');
$votes = $this->input->post('vote_id');
$amount = $this->input->post('amount');
$notes = $this->input->post('notes');
$bdate = $this->input->post('budget_date');
for ($x = 0; $x < $count; $x++) {
$details[$x]['budget_id'] = $id;
$details[$x]['office'] = $offices[$x];
$details[$x]['vote_id'] = $votes[$x];
$details[$x]['amount'] = (-1)*$amount[$x];
$details[$x]['notes'] = $notes[$x];
$details[$x]['budget_date'] = $bdate[$x];
$details[$x]['status'] = 1;
}
Now the issue was fixed partially. But the saving vote_id of finance_budget_issue table is incorrect without editing.

WordPress Custom Repeater Controller For Customizer

I want to create custom repeater controller for theme, for this i tried but i am stuck with issue and i am unable to save any changes to my repeater section, any help is highly appreciated, here is link to my code
The code for customizer class is
if (class_exists('WP_Customize_Control')):
class Test_Testimonial_Control extends WP_Customize_Control {
public $type = 'textarea';
public function render_content() {
?>
<div class="test-rep-section-wrap">
<div class="test-rep-section">
<h3 class="test-title"><?php echo esc_html( $this->label ); ?></h3>
<div class="test-contents">
<input type="text" name="testimonial" placeholder="Image URL" id="img-link-testimonial">
Upload Image
<span><?php _e('Description Text','text-domain'); ?></span>
<textarea rows="2" style="width:100%;"><?php echo esc_textarea( $this->value() ); ?></textarea>
<input type="text" name="cl_name" placeholder="Name">
</div>
Add More
<input <?php $this->link(); ?> type="hidden" value="<?php echo esc_attr($this->value()); ?>"/>
</div>
</div>
<?php
}
}
endif;
jquery code is
$('.test-contents').hide();
$('body').on('click', '.test-title', function(){
$('.test-contents').slideToggle();
});
$('body').on('click', '.new_section', function(){
var tCount = 0;
$('.test-rep-section-wrap').append('<div class="test-rep-section"><h3 class="test-title">Testimonial Options</h3><div class="test-contents" style="display: block;"><input type="text" name="testimonial" placeholder="Image URL" id="img-link-testimonial">Upload Image<span>Description Text</span><textarea rows="5" style="width:100%;"></textarea><input type="text" name="cl_name" placeholder="Name"></div>Add More<input data-customize-setting-link="ripple_pro_testimonial_repeater" type="hidden" value=""><div class="delete-test-feature">Delete Feature</div></div>');
});
$(document).on('click', '.delete-test-feature > a', function(){
$(this).parents('.test-rep-section').remove();
});

Codeigniter Email Class is not working

I am trying Codeigniter Email Class but it is not working or May be, I am making mistakes with configuration or something else. please fix it and inform me someone what I should do. I am having a problem with the codeigniter email class.
This is the screenshot after sending the form data to the controller.
View:
<h4>Send Your Feedback</h4>
<form action="<?php echo base_url('front/feedBack') ?>" enctype="multipart/form-data" method="post" class="form-horizontal">
<div class="form-group">
<label for="Name" class="col-sm-3 control-label">Name<span>*</span></label>
<div class="col-sm-9">
<input type="text" name="senderName" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group">
<label for="Phone" class="col-sm-3 control-label">Phone no<span>*</span></label>
<div class="col-sm-9">
<input type="text" name="senderPhone" class="form-control" id="Phone" placeholder="Phone no">
</div>
</div>
<div class="form-group">
<label for="Email" class="col-sm-3 control-label">Email<span>*</span></label>
<div class="col-sm-9">
<input type="text" name="senderEmail" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="Subject" class="col-sm-3 control-label">Subject</label>
<div class="col-sm-9">
<input type="text" name="senderSubject" class="form-control" id="Subject" placeholder="Subject">
</div>
</div>
<div class="form-group">
<label for="Message" class="col-sm-3 control-label">Message<span>*</span></label>
<div class="col-sm-9">
<textarea name="senderMsg" class="form-control" id="Message" cols="30" rows="5" placeholder="Message"></textarea>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-3 control-label"></label>
<div class="col-sm-9">
<button type="submit" class="btn btn-default btn-lg btn-block">Send Message</button>
</div>
</div>
</form>
Controller:
public function feedBack()
{
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'host8.registrar-servers.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '30';
$config['smtp_user'] = 'info#dewbn.com';
$config['smtp_pass'] = 'myPass';
$config['charset'] = 'utf-8';
$config['crlf'] = '\r\n'; //should be "\r\n"
$config['newline'] = '\r\n'; //should be "\r\n"
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$senderName = $this->input->post('senderName');
$senderPhone = $this->input->post('senderPhone');
$senderEmail = $this->input->post('senderEmail');
$senderSubject = $this->input->post('senderSubject');
$senderMsg = $this->input->post('senderMsg');
$this->email->from($senderEmail, $senderName);
$this->email->to('bablukpik#gmail.com');
$this->email->subject($senderSubject);
$this->email->message($senderMsg);
if($this->email->send()) {
echo "Success!";
//return true;
} else {
echo "Failure!";
//return false;
}
}
Try this :
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'test1#gmail.com',
'smtp_port' => 2525,
'smtp_user' => 'gmailusername',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$THIS->email->initialize($config);
$THIS->email->set_newline("\r\n");
$body = str_replace(array('{LOGO_IMAGE}'),array($logo_image),$body);
$body.= email_footer();
$body = '<div style="width:700px;float:left;">'.$body.'</div>';
if (!empty($from))
{
$from_name = !empty($from_name) ? $from_name : SITE_NAME;
$from = !empty($from) ? $from : 'noreply#test.com';
$THIS->email->from($from, $from_name);
}
else
{
$THIS->email->from('noreply#test.com', $from_name);
}
if (!empty($to))
{
$THIS->email->to($to);
}
if (!empty($cc))
{
$THIS->email->cc($cc);
}
if (!empty($bcc))
{
$THIS->email->cc($bcc);
}
$THIS->email->subject($subject);
$THIS->email->message($body);
if (!empty($attachment))
{
if (is_array($attachment))
{
foreach ($attachment as $val)
{
$THIS->email->attach($val);
}
}
else
{
$THIS->email->attach($val);
}
}
if ($THIS->email->send())
{
return TRUE;
}
else{
echo $THIS->email->print_debugger();
exit;
}
Mark it accepted if it works.