Jump to content

Moorcam

Members
  • Posts

    254
  • Joined

  • Last visited

Everything posted by Moorcam

  1. Hi guys, Trying to implement an import function in Codeigniter 3 but not working. There are no errors, just get this screen: An Error Was Encountered The action you have requested is not allowed. Here is the Controller part: public function importdata() { $this->load->view('view_fleet'); if(isset($_POST["submit"])) { $file = $_FILES['file']['tmp_name']; $handle = fopen($file, "r"); $c = 0;// while(($filesop = fgetcsv($handle, 1000, ",")) !== false) { $v_number = $filesop[0]; $v_eng_number = $filesop[1]; $v_vin = $filesop[2]; $v_chassis = $filesop[3]; $v_make = $filesop[4]; $v_model = $filesop[5]; $v_height = $filesop[6]; $v_length = $filesop[7]; $v_width = $filesop[8]; $v_reg = $filesop[9]; $v_pax = $filesop[10]; $tacho_number = $$filesop[11]; $service_date = $filesop[12]; $v_notes = $filesop[13]; $status = $filesop[14]; if($c<>0){ /* SKIP THE FIRST ROW */ $this->Model_fleet->saverecords( $v_number, $v_eng_number, $v_vin, $$v_chassis, $v_make, $v_model, $v_height, $v_length, $v_width, $v_reg, $v_pax, $tacho_number, $service_date, $v_notes, $status ); } $c = $c + 1; } echo "sucessfully import data !"; } } Now the Model part: function saverecords($v_number,$v_reg) { $query="insert into tbl_fleet values('$v_number','$v_eng_number','$v_vin','$v_chassis','$v_make','$v_model','$v_height','$v_length','$v_width','$v_reg','$v_pax','$tacho_number','$service_date','$v_notes,$status')"; $this->db->query($query); } And finally the View part: <label for="exampleInputFile">Upload Excel or CSV</label> <form enctype="multipart/form-data" method="post" role="form"> <div class="form-group"> <input type="file" name="file" id="file" size="150"> <p class="help-block">Only Excel/CSV File Import.</p> </div> <button type="submit" class="btn btn-default" name="submit" value="submit">Upload</button> </form> </div> Please note that the View section is infact in a Modal. Not sure if that's the issue? If anyone can help with this I will send you some Guinness. Thanks.
  2. Yeah sorted mate. Sorry, meant to come back and update. But exactly as you said.
  3. Yeah I may need to look further into this. If more than one instance is created, for example, Tom buys tickets to two different events or whatever, the above JS will only work for printing the first instance. No idea why.
  4. If anyone else wants this, here's what solved it for me... document.getElementById("printButton1").addEventListener("click", function() { var printContents = document.getElementById('invoice').innerHTML; var originalContents = document.body.innerHTML; var printButton = document.getElementById("printButton1"); var closeButton = document.getElementById("closeButton1"); document.body.innerHTML = printContents; document.getElementById('printButton1').style.visibility = 'hidden'; window.print(); document.body.innerHTML = originalContents; window.location.reload(true); });
  5. You were correct. I was loading the URL wrong. Don't ask me now what I did because I can't remember lol but your advice led to the solution.
  6. I have changed the above code and tried this, adding a link to the CSS file of the website... function printDiv() { var divToPrint=document.getElementById('invoice'); var newWin=window.open('','Print-Window'); var cssURL='<?php echo base_url('public/css/style.css'); ?>'; var printButton = document.getElementById("printButton1"); var closeButton = document.getElementById("closeButton1"); newWin.document.open(); printButton.style.visibility = 'hidden'; closeButton.style.visibility = 'hidden'; newWin.document.write('<html><head><link href="'+cssURL+'" rel="stylesheet" type="text/css"></head><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>'); printButton.style.visibility = 'visible'; closeButton.style.visibility = 'visible'; newWin.document.close(); setTimeout(function(){newWin.close();},10); } Still not getting any styling in the print dialog.
  7. Hi folks, I am using the following JS to print the contents of a Div. However, when I click on Print, the print preview window opens but the document has no styling. function printDiv() { var divToPrint=document.getElementById('invoice'); var newWin=window.open('','Print-Window'); var printButton = document.getElementById("printButton1"); var closeButton = document.getElementById("closeButton1"); newWin.document.open(); printButton.style.visibility = 'hidden'; closeButton.style.visibility = 'hidden'; newWin.document.write('<html><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>'); printButton.style.visibility = 'visible'; closeButton.style.visibility = 'visible'; newWin.document.close(); setTimeout(function(){newWin.close();},10); } Button for printing: <input type="button" id="printButton1" class="btn btn-success" onclick="printDiv('invoice')" value="Print Invoice" /> Is there something wrong here or am I just missing something? Cheers, Dan
  8. Hey man, Yeah it's in the Controller: $this->load->view('traveller/view_testimonial_add',$data); Yeah I'm still learning it. Went for an older version because I was told it's easier. It is but this has me stumped.
  9. Hi all, Hope you are all well and Happy New Year. Now, I have pulled hair out with this since last night. When I click on Add Testimonial it should open traveller/testimonial/add, which has a file name of view_traveller_testimonial_add.php But, when I click on the button to add a new Testimonial, it doesn't work. Just refreshed the page. Any ideas? Here is this file: <section class="content-header"> <div class="content-header-left"> <h1>Add Testimonial</h1> </div> <div class="content-header-right"> <a href="<?php echo base_url(); ?>traveller/testimonial" class="btn btn-primary btn-sm">View All</a> </div> </section> <section class="content"> <div class="row"> <div class="col-md-12"> <?php if($this->session->flashdata('error')) { ?> <div class="callout callout-danger"> <p><?php echo $this->session->flashdata('error'); ?></p> </div> <?php } if($this->session->flashdata('success')) { ?> <div class="callout callout-success"> <p><?php echo $this->session->flashdata('success'); ?></p> </div> <?php } ?> <?php echo form_open_multipart(base_url().'traveller/testimonial/add',array('class' => 'form-horizontal')); ?> <div class="box box-info"> <div class="box-body"> <div class="form-group"> <label for="" class="col-sm-2 control-label">Name <span>*</span></label> <div class="col-sm-6"> <input type="text" class="form-control" name="name" value="<?php echo $d_arr['traveller_name']; ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Website</label> <div class="col-sm-6"> <input type="url" autocomplete="off" class="form-control" name="url" value=""> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Comment <span>*</span></label> <div class="col-sm-6"> <textarea class="form-control" name="comment" style="height:200px;"></textarea> </div> </div> <div class="col-sm-6" hidden> <label for="" class="col-sm-2 control-label">Status</label> <input type="text" autocomplete="off" class="form-control" name="status" value="Pending"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label"></label> <div class="col-sm-6"> <button type="submit" class="btn btn-success pull-left" name="form1">Submit</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> </div> </section> Here is the file that has the button to open the above page: <div class="dashboard-area bg-area pt_50 pb_80"> <div class="container wow fadeIn"> <div class="row"> <div class="col-md-3 col-sm-12 wow fadeIn" data-wow-delay="0.1s"> <div class="option-board mt_30"> <ul> <?php $this->view('view_traveller_sidebar'); ?> </ul> </div> </div> <div class="col-md-9 col-sm-12 wow fadeIn" data-wow-delay="0.2s"> <div class="box-body table-responsive"> <h1>My Testimonials</h1> <table id="example1" class="table table-bordered table-striped"> <thead> <tr> <th>Serial</th> <th>Name</th> <th>Comment</th> </tr> </thead> <tbody> <?php $i=0; foreach ($my_testimonial as $row) { $i++; $CI =& get_instance(); $CI->load->model('Model_testimonial'); $CI->load->model('Model_traveller'); $d_arr = $CI->Model_traveller->get_traveller_name_by_id($row['traveller_id']); ?> <tr> <td><?php echo $i; ?></td> <td><?php echo $d_arr['traveller_name']; ?></td> <td><?php echo $row['comment']; ?></td> </tr> <?php } ?> </tbody> </table> <div class="box-body"> <a href="<?php echo base_url(); ?>traveller/testimonial/add" class="btn btn-primary btn-sm">Add Testimonial</a> </div> </div> </div> </div> </div> </div> Here is my Controller: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Testimonial extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('traveller/Model_common'); $this->load->model('traveller/Model_testimonial'); } public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $data['testimonial'] = $this->Model_testimonial->show(); $this->load->view('traveller/view_header',$data); $this->load->view('traveller/view_testimonial',$data); $this->load->view('traveller/view_footer'); } public function add() { $data['setting'] = $this->Model_common->get_setting_data(); $error = ''; $success = ''; if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('name', 'Name', 'trim|required'); $this->form_validation->set_rules('comment', 'Comment', 'trim|required'); if($this->form_validation->run() == FALSE) { $valid = 0; $error .= validation_errors(); } if($valid == 1) { $next_id = $this->Model_testimonial->get_auto_increment_id(); foreach ($next_id as $row) { $ai_id = $row['Auto_increment']; } $form_data = array( 'name' => $_POST['name'], 'url' => $_POST['url'], 'status' => $_POST['status'], 'comment' => $_POST['comment'] ); $this->Model_testimonial->add($form_data); $success = 'Testimonial is added successfully!'; $this->session->set_flashdata('success',$success); redirect(base_url().'traveller/testimonial'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'traveller/testimonial/add'); } } else { $this->load->view('traveller/view_header',$data); $this->load->view('traveller/view_testimonial_add',$data); $this->load->view('traveller/view_footer'); } } public function edit($id) { // If there is no testimonial in this id, then redirect $tot = $this->Model_testimonial->testimonial_check($id); if(!$tot) { redirect(base_url().'traveller/testimonial'); exit; } $data['setting'] = $this->Model_common->get_setting_data(); $error = ''; $success = ''; if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('name', 'Name', 'trim|required'); $this->form_validation->set_rules('comment', 'Comment', 'trim|required'); if($this->form_validation->run() == FALSE) { $valid = 0; $error .= validation_errors(); } if($valid == 1) { $data['testimonial'] = $this->Model_testimonial->get_testimonial($id); $form_data = array( 'name' => $_POST['name'], 'url' => $_POST['url'], 'status' => $_POST['status'], 'comment' => $_POST['comment'] ); $this->Model_testimonial->update($id,$form_data); $success = 'Testimonial is updated successfully'; $this->session->set_flashdata('success',$success); redirect(base_url().'traveller/testimonial'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'traveller/testimonial/edit'.$id); } } else { $data['testimonial'] = $this->Model_testimonial->get_testimonial($id); $this->load->view('traveller/view_header',$data); $this->load->view('traveller/view_testimonial_edit',$data); $this->load->view('traveller/view_footer'); } } public function delete($id) { // If there is no testimonial in this id, then redirect $tot = $this->Model_testimonial->testimonial_check($id); if(!$tot) { redirect(base_url().'traveller/testimonial'); exit; } $data['testimonial'] = $this->Model_testimonial->get_testimonial($id); if($data['testimonial']) { unlink('./public/uploads/'.$data['testimonial']['photo']); } $this->Model_testimonial->delete($id); $success = 'Testimonial is deleted successfully'; $this->session->set_flashdata('success',$success); redirect(base_url().'traveller/testimonial'); } } And my Model: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Model_testimonial extends CI_Model { function get_auto_increment_id() { $sql = "SHOW TABLE STATUS LIKE 'tbl_testimonial'"; $query = $this->db->query($sql); return $query->result_array(); } function show() { $sql = "SELECT * FROM tbl_testimonial ORDER BY id ASC"; $query = $this->db->query($sql); return $query->result_array(); } function add($data) { $this->db->insert('tbl_testimonial',$data); return $this->db->insert_id(); } function update($id,$data) { $this->db->where('id',$id); $this->db->update('tbl_testimonial',$data); } function delete($id) { $this->db->where('id',$id); $this->db->delete('tbl_testimonial'); } function get_testimonial($id) { $sql = 'SELECT * FROM tbl_testimonial WHERE id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } function testimonial_check($id) { $sql = 'SELECT * FROM tbl_testimonial WHERE id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } } Really appreciate the help guys. Thanks in advance.
  10. Already asked for it here
  11. Hi mate, Sorry. Made a few changes but the above was the culprit really. Here is the full update. Controller: public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $data['tour'] = $this->Model_dashboard->all_tour('p_id'); $data['total_category'] = $this->Model_dashboard->show_total_category(); $data['total_news'] = $this->Model_dashboard->show_total_news(); $data['total_motel'] = $this->Model_dashboard->show_total_motel(); $data['total_tour'] = $this->Model_dashboard->show_total_tour(); $data['total_team_member'] = $this->Model_dashboard->show_total_team_member(); $data['total_agent'] = $this->Model_dashboard->show_total_agent(); $data['total_service'] = $this->Model_dashboard->show_total_service(); $data['total_testimonial'] = $this->Model_dashboard->show_total_testimonial(); $data['total_traveller'] = $this->Model_dashboard->show_total_traveller(); $data['amount_paid'] = $this->Model_dashboard->show_amount_paid(); $data['total_fleet'] = $this->Model_dashboard->show_total_fleet(); $data['total_driver'] = $this->Model_dashboard->show_total_driver(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_dashboard',$data); $this->load->view('admin/view_footer'); } Model: public function all_tour() { $e_id = $this->session->userdata('e_id'); $query = $this->db->query("SELECT * FROM tbl_tour WHERE e_id = $e_id ORDER BY p_id ASC"); return $query->result_array(); } View: <table class="table table-striped"> <tr> <th>Tour</th> <th>Departure Date</th> <th>Return Date</th> <th>Fleet Number</th> </tr> <?php foreach($tour as $row):?> <tr> <td><?php echo $row['p_name']; ?></td> <td><?php echo $row['p_start_date']; ?></td> <td><?php echo $row['p_end_date']; ?></td> <td><?php echo $row['v_number']; ?></td> </tr> <?php endforeach;?> </table>
  12. Fixed Change the following: <td><?php echo $job->start_date;?></td> <td><?php echo $job->name;?></td> To... <td><?php echo $row['p_start_date']; ?></td> <td><?php echo $row['p_name']; ?></td>
  13. Ok, I have added the following to the Controller index and now getting no error. But, not getting anything at all lol. $data['tour'] = $this->Model_dashboard->tour('p_id');
  14. So, when a user logs in, I would like to grab data from the db and display it based on their id, which is in a session. Here is my Controller: public function jobs() { if($this->session->userdata('e_id')){ $id = $this->session->userdata('e_id'); $data['tour'] = $this->usermodel->job($id); $this->load->view('tour',$data); }else{ echo "No results"; } } Here is my Model: public function job($id) { $this->db->select('*') ->from('tbl_tour') ->where('e_id', $id); return $this->db->get()->result(); } And finally, View: <table class="table table-striped"> <tr> <th>Date</th> <th>Tour</th> </tr> <?php foreach($tour as $job):?> <tr> <td><?php echo $job->start_date;?></td> <td><?php echo $job->name;?></td> </tr> <?php endforeach;?> </table> When executing I get Undefined variable: tour And also: Message: Invalid argument supplied for foreach() If anyone can help with this it would be appreciated.
  15. Fixed. Was not getting id from database. So, changed function update($id) { $this->db->where('id',$id); $this->db->update('tbl_team_member',$data); } to this function update($data) { $this->db->where('id',$this->session->userdata('id')); $this->db->update('tbl_team_member',$data); } Just in case anyone else runs into same issue.
  16. Hi guys, Been fighting with this and can't get it to work. Basically, on submit, session is being updated but data is not being sent to the database. Here is my view_profile.php <?php if(!$this->session->userdata('id')) { redirect(base_url().'admin'); } ?> <section class="content-header"> <div class="content-header-left"> <h1>Edit Profile</h1> </div> </section> <section class="content" style="min-height:auto;margin-bottom: -30px;"> <div class="row"> <div class="col-md-12"> <?php if($this->session->flashdata('error')) { ?> <div class="callout callout-danger"> <p><?php echo $this->session->flashdata('error'); ?></p> </div> <?php } if($this->session->flashdata('success')) { ?> <div class="callout callout-success"> <p><?php echo $this->session->flashdata('success'); ?></p> </div> <?php } ?> </div> </div> </section> <section class="content"> <div class="row"> <div class="col-md-12"> <div class="nav-tabs-custom"> <ul class="nav nav-tabs"> <li class="active"><a href="#tab_1" data-toggle="tab">Update Information</a></li> <li><a href="#tab_2" data-toggle="tab">Update Photo</a></li> <li><a href="#tab_3" data-toggle="tab">Update Password</a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="tab_1"> <?php echo form_open(base_url().'admin/profile/update',array('class' => 'form-horizontal')); ?> <div class="box box-info"> <div class="box-body"> <div class="form-group"> <label for="" class="col-sm-2 control-label">Display Name <span>*</span></label> <div class="col-sm-4"> <input type="text" class="form-control" name="name" value="<?php echo $this->session->userdata('name'); ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Email Address <span>*</span></label> <div class="col-sm-4"> <input type="text" class="form-control" name="email" value="<?php echo $this->session->userdata('email'); ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Phone <span>*</span></label> <div class="col-sm-4"> <input type="text" class="form-control" name="phone" value="<?php echo $this->session->userdata('phone'); ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label"></label> <div class="col-sm-6"> <button type="submit" class="btn btn-success pull-left" name="form1">Update Information</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> <div class="tab-pane" id="tab_2"> <?php echo form_open_multipart(base_url().'admin/profile/update',array('class' => 'form-horizontal')); ?> <div class="box box-info"> <div class="box-body"> <div class="form-group"> <label for="" class="col-sm-2 control-label">Existing Photo</label> <div class="col-sm-6" style="padding-top:6px;"> <?php if($this->session->userdata('photo') ==''): ?> <img src="<?php echo base_url(); ?>public/img/no-photo.jpg" class="existing-photo" alt="profile photo" width="140"> <?php else: ?> <img src="<?php echo base_url(); ?>public/uploads/<?php echo $this->session->userdata('photo'); ?>" class="existing-photo" width="140"> <?php endif; ?> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">New Photo</label> <div class="col-sm-6" style="padding-top:6px;"> <input type="file" name="photo"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label"></label> <div class="col-sm-6"> <button type="submit" class="btn btn-success pull-left" name="form2">Update Photo</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> <div class="tab-pane" id="tab_3"> <?php echo form_open(base_url().'admin/profile/update',array('class' => 'form-horizontal')); ?> <div class="box box-info"> <div class="box-body"> <div class="form-group"> <label for="" class="col-sm-2 control-label">Password </label> <div class="col-sm-4"> <input type="password" class="form-control" name="password"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Retype Password </label> <div class="col-sm-4"> <input type="password" class="form-control" name="re_password"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label"></label> <div class="col-sm-6"> <button type="submit" class="btn btn-success pull-left" name="form3">Update Password</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> </div> </div> </div> </div> </section> Here is my controller - Profile.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Profile extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('admin/Model_common'); $this->load->model('admin/Model_profile'); } public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_profile',$data); $this->load->view('admin/view_footer'); } public function update() { $error = ''; $success = ''; $data['setting'] = $this->Model_common->get_setting_data(); if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email'); if($this->form_validation->run() == FALSE) { $valid = 0; $error = validation_errors(); } if($valid == 1) { $form_data = array( 'email' => $_POST['email'], 'name' => $_POST['name'], 'phone' => $_POST['phone'] ); $this->Model_profile->update($form_data); $success = 'Profile Information is updated successfully!'; $this->session->set_userdata($form_data); $this->session->set_flashdata('success',$success); redirect(base_url().'admin/profile'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/profile'); } } if(isset($_POST['form2'])) { $valid = 1; $path = $_FILES['photo']['name']; $path_tmp = $_FILES['photo']['tmp_name']; if($path!='') { $ext = pathinfo( $path, PATHINFO_EXTENSION ); $file_name = basename( $path, '.' . $ext ); $ext_check = $this->Model_common->extension_check_photo($ext); if($ext_check == FALSE) { $valid = 0; $data['error'] = 'You must have to upload jpg, jpeg, gif or png file<br>'; } } else { $valid = 0; $data['error'] = 'You must have to select a photo<br>'; } if($valid == 1) { // removing the existing photo unlink('./public/uploads/'.$this->session->userdata('photo')); // updating the data $final_name = 'user-'.'.'.$ext; move_uploaded_file( $path_tmp, './public/uploads/'.$final_name ); $form_data = array( 'photo' => $final_name ); $this->Model_profile->update($id,$form_data); $success = 'Photo is updated successfully!'; $this->session->set_userdata($id,$form_data); $this->session->set_flashdata('success',$success); redirect(base_url().'admin/profile'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/profile'); } } if(isset($_POST['form3'])) { $valid = 1; $this->form_validation->set_rules('password', 'Password', 'trim|required'); $this->form_validation->set_rules('re_password', 'Retype Password', 'trim|required|matches[password]'); if($this->form_validation->run() == FALSE) { $valid = 0; $error = validation_errors(); } if($valid == 1) { $form_data = array( 'password' => md5($_POST['password']) ); $this->Model_profile->update($id,$form_data); $success = 'Password is updated successfully!'; $this->session->set_userdata($id,$form_data); $this->session->set_flashdata('success',$success); redirect(base_url().'admin/profile'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/profile'); } } $data['setting'] = $this->Model_common->get_setting_data(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_profile',$id,$data); $this->load->view('admin/view_footer'); } } And finally, my Model_profile.php (only need to update) No errors etc. Any help would be appreciated. Cheers, Dan <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Model_profile extends CI_Model { function update($id) { $this->db->where('id',$id); $this->db->update('tbl_team_member',$data); } }
  17. Just adding to this. I also wanted this to calculate tax and format with the correct locale, tax name (example: GST for Australia). So, after hours of clowning around, pulling hair out, Googling, and channelling the masters of Code who have long passed away, I finally have it doing what I want. For those of you in the same creek without a paddle, I will share my newfound expertise with you: <?php if($setting['site_currency'] == 'EUR') { $locale = 'en-IE'; } if($setting['site_currency'] == 'GBP') { $locale = 'en-GB'; } if($setting['site_currency'] == 'USD') { $locale = 'en-US'; } if($setting['site_currency'] == 'AUD') { $locale = 'en-AU'; } ?> <script> $(document).ready(function() { $('#numberPerson').on('change',function() { var format = (num) => new Intl.NumberFormat('<?php echo $locale; ?>', { style: 'currency', currency: '<?php echo $setting['site_currency']; ?>' }).format(num); var selectVal = $('#numberPerson').val(); var selectPrice = <?php echo $p_price['p_price_single']; ?>; var taxRate = <?php echo $setting['tax_amount']; ?>; var salesTax = selectPrice * taxRate / 100; var total = selectPrice + salesTax; var totalPrice = selectVal * total; $('#totalPrice').text(format(totalPrice)); }); }); </script> It's probably not what the true experts would do but it works and does what I want it to do and that's what matters. Love you Bye
  18. Scrap my last reply. I am tired and read it wrong. Been driving Interstate last few days. Did it again, looked at it, went, nope, then looked again, did it, and yep. You are a legend. Thank you.
  19. Tried that man. Still no change. Total stays the same.
  20. Hi there, Thanks for the reply. No, only the ID and quantity is being sent forward. I have tried a few different suggestions I have found on Google with this but nothing working. I guess it's not a major issue with "$3000" being displayed rather than "$3,000.00" but I am stubborn lol
  21. Hi guys, I feel this is a Javascript issue so here goes. I am trying to update the total cost of a ticket by selecting the number of passengers from a dropdown. It works. However, not when I format the output within the js by using a number_format() function. Here is the Form: <div class="row book-now"> <div class="col-md-12"> <?php echo form_open(base_url().'payment',array('class' => '')); ?> <input type="hidden" name="p_id" value="<?php echo $id; ?>"> <input type="hidden" name="p_price_single" value="<?php echo number_format($tour['p_price_single'],2); ?>"> <div class="row"> <div class="col-md-12 col-sm-12"> <div class="form-group"> <label>Total Price (per person)</label> <div class="mb_5" style="font-size:32px;"> <?php echo $symbol; ?><?php echo number_format($tour['p_price_single'],2); ?> </div> <div class="sep mb_10"></div> <label>Number of Persons</label> <select id="numberPerson" name="number_of_person" class="custom-select select2 mb_15" style="width: auto;"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> </select> <div class="sep mb_15"></div> <label>Total Price</label> <div class="mb_15" style="font-size:32px;"> <?php echo $symbol; ?><span id="totalPrice"><?php echo number_format($tour['p_price_single'], 2); ?></span> </div> </div> </div> </div> Here is the JS without the function: <script> $(document).ready(function() { $('#numberPerson').on('change',function() { var selectVal = $('#numberPerson').val(); var selectPrice = <?php echo $p_price['p_price_single']; ?>; var totalPrice = selectVal * selectPrice; $('#totalPrice').text(totalPrice); }); }); </script> The above works. However, when the total is calculated from the selection in the dropdown, the total amount loses format. So, for example, if 2 is selected it will show $3000 instead of $3,000.00 Here is the Javascript WITH the number_format function: <script> $(document).ready(function() { $('#numberPerson').on('change',function() { var selectVal = $('#numberPerson').val(); var selectPrice = <?php echo number_format($p_price['p_price_single'], 2); ?>; var totalPrice = selectVal * selectPrice; $('#totalPrice').text(totalPrice); }); }); </script> This just doesn't allow any calculation. The total will stay formatted but just not calculate. Any help would be greatly appreciated. Cheers, Dan
  22. Ignore my impatient and lazy outburst of the "Please rescue me!". I went and put my grown up pants on and figured it out. I was missing some of the Model_FFleet file. Jeesh!
  23. Hi guys, I am using this same code on other sections of the application with no issues but on this particular one I am getting "Undefined Method "Model_fleet::show()" Here is Fleet.php line 16 is the error: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Fleet extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('admin/Model_common'); $this->load->model('admin/Model_fleet'); } public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $data['fleet'] = $this->Model_fleet->show(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_fleet',$data); $this->load->view('admin/view_footer'); } public function add() { $data['setting'] = $this->Model_common->get_setting_data(); $error = ''; $success = ''; if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('v_number', 'Fleet Number', 'trim|required'); $this->form_validation->set_rules('designation', 'Designated Driver', 'trim|required'); if($this->form_validation->run() == FALSE) { $valid = 0; $error .= validation_errors(); } $path = $_FILES['photo']['name']; $path_tmp = $_FILES['photo']['tmp_name']; if($path!='') { $ext = pathinfo( $path, PATHINFO_EXTENSION ); $file_name = basename( $path, '.' . $ext ); $ext_check = $this->Model_common->extension_check_photo($ext); if($ext_check == FALSE) { $valid = 0; $error .= 'You must have to upload jpg, jpeg, gif or png file for featured photo<br>'; } } else { $valid = 0; $error .= 'You must have to select a photo for featured photo<br>'; } if($valid == 1) { $next_id = $this->Model_fleet->get_auto_increment_id(); foreach ($next_id as $row) { $ai_id = $row['Auto_increment']; } $final_name = 'fleet-'.$ai_id.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name; $new_width = 600; $new_height = 600; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $final_name_thumb = 'fleet-'.$ai_id.'-thumb'.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name_thumb; $new_width = 260; $new_height = 260; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $form_data = array( 'v_number' => $_POST['v_number'], 'designation' => $_POST['designation'], 'v_reg' => $_POST['v_reg'], 'v_pax' => $_POST['v_pax'], 'photo' => $final_name ); $this->Model_fleet->add($form_data); $success = 'Fleet is added successfully!'; $this->session->set_flashdata('success',$success); redirect(base_url().'admin/fleet'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/fleet/add'); } } else { $this->load->view('admin/view_header',$data); $this->load->view('admin/view_fleet_add',$data); $this->load->view('admin/view_footer'); } } public function edit($id) { $tot = $this->Model_fleet->fleet_check($id); if(!$tot) { redirect(base_url().'admin/fleet'); exit; } $data['setting'] = $this->Model_common->get_setting_data(); $error = ''; $success = ''; if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('v_number', 'Fleet Number', 'trim|required'); $this->form_validation->set_rules('designation', 'Designation', 'trim|required'); if($this->form_validation->run() == FALSE) { $valid = 0; $error .= validation_errors(); } $path = $_FILES['photo']['name']; $path_tmp = $_FILES['photo']['tmp_name']; if($path!='') { $ext = pathinfo( $path, PATHINFO_EXTENSION ); $file_name = basename( $path, '.' . $ext ); $ext_check = $this->Model_common->extension_check_photo($ext); if($ext_check == FALSE) { $valid = 0; $error .= 'You must have to upload jpg, jpeg, gif or png file for featured photo<br>'; } } if($valid == 1) { $data['fleet'] = $this->Model_fleet->get_fleet($id); if($path == '') { $form_data = array( 'v_number' => $_POST['v_number'], 'designation' => $_POST['designation'], 'v_reg' => $_POST['v_reg'], 'v_pax' => $_POST['v_pax'] ); $this->Model_fleet->update($id,$form_data); } if($path != '') { unlink('./public/uploads/'.$_POST['current_photo']); $final_name = 'fleet-'.$id.'.'.$ext; $temp_arr = explode('.',$_POST['current_photo']); $temp_final = $temp_arr[0].'-thumb'.'.'.$temp_arr[1]; unlink('./public/uploads/'.$temp_final); $final_name = 'fleet-'.$id.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name; $new_width = 600; $new_height = 600; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $final_name_thumb = 'fleet-'.$id.'-thumb'.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name_thumb; $new_width = 260; $new_height = 260; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $form_data = array( 'v_number' => $_POST['v_number'], 'designation' => $_POST['designation'], 'v_reg' => $_POST['v_reg'], 'v_pax' => $_POST['v_pax'], 'photo' => $final_name ); $this->Model_fleet->update($id,$form_data); } if($path != '') { unlink('./public/uploads/'.$_POST['current_photo']); $final_name = 'fleet-'.$id.'.'.$ext; $temp_arr = explode('.',$_POST['current_photo']); $temp_final = $temp_arr[0].'-thumb'.'.'.$temp_arr[1]; unlink('./public/uploads/'.$temp_final); $final_name = 'fleet-'.$id.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name; $new_width = 600; $new_height = 600; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $final_name_thumb = 'fleet-'.$id.'-thumb'.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name_thumb; $new_width = 260; $new_height = 260; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $form_data = array( 'v_number' => $_POST['v_number'], 'designation' => $_POST['designation'], 'v_reg' => $_POST['v_reg'], 'v_pax' => $_POST['v_pax'], 'photo' => $final_name ); $this->Model_fleet->update($id,$form_data); } $success = 'Fleet is updated successfully'; $this->session->set_flashdata('success',$success); redirect(base_url().'admin/fleet'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/fleet/edit/'.$id); } } else { $data['fleet'] = $this->Model_fleet->get_fleet($id); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_fleet_edit',$data); $this->load->view('admin/view_footer'); } } public function delete($id) { // If there is no Fleet in this id, then redirect $tot = $this->Model_fleet->fleet_check($id); if(!$tot) { redirect(base_url().'admin/fleet'); exit; } $data['fleet'] = $this->Model_fleet->get_fleet($id); if($data['fleet']) { unlink('./public/uploads/'.$data['fleet']['photo']); $temp_arr = explode('.',$data['fleet']['photo']); $temp_final = $temp_arr[0].'-thumb'.'.'.$temp_arr[1]; unlink('./public/uploads/'.$temp_final); } $this->Model_fleet->delete($id); $success = 'Fleet is deleted successfully'; $this->session->set_flashdata('success',$success); redirect(base_url().'admin/fleet'); } } Here is Model_fleet.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Model_fleet extends CI_Model { function get_auto_increment_id() { $sql = "SHOW TABLE STATUS LIKE 'tbl_fleet'"; $query = $this->db->query($sql); return $query->result_array(); } function get_fleet_number_by_id($id) { $sql = 'SELECT * FROM tbl_fleet WHERE v_id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } function show() { $sql = "SELECT * FROM tbl_fleet"; $query = $this->db->query($sql); return $query->result_array(); } function add($data) { $this->db->insert('tbl_fleet',$data); return $this->db->insert_id(); } function update($id,$data) { $this->db->where('v_id',$id); $this->db->update('tbl_fleet',$data); } function delete($id) { $this->db->where('v_id',$id); $this->db->delete('tbl_fleet'); } function getData($id) { $sql = 'SELECT * FROM tbl_fleet WHERE v_id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } function fleet_check($id) { $sql = 'SELECT * FROM tbl_fleet WHERE v_id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } function get_fleet($id) { $sql = 'SELECT * FROM tbl_fleet WHERE v_id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } } And finally view_fleet.php <?php if(!$this->session->userdata('id')) { redirect(base_url().'admin'); } ?> <section class="content-header"> <div class="content-header-left"> <h1>View Fleets</h1> </div> <div class="content-header-right"> <a href="<?php echo base_url(); ?>admin/fleet/add" class="btn btn-primary btn-sm">Add New Fleet</a> </div> </section> <section class="content"> <div class="row"> <div class="col-md-12"> <?php if($this->session->flashdata('error')) { ?> <div class="callout callout-danger"> <p><?php echo $this->session->flashdata('error'); ?></p> </div> <?php } if($this->session->flashdata('success')) { ?> <div class="callout callout-success"> <p><?php echo $this->session->flashdata('success'); ?></p> </div> <?php } ?> <div class="box box-info"> <div class="box-body table-responsive"> <table id="example1" class="table table-bordered table-striped"> <thead> <tr> <th>ID</th> <th>Photo</th> <th>Designation</th> <th>Fleet #</th> <th>Registration</th> <th>Max Pax <th width="140">Action</th> </tr> </thead> <tbody> <?php $i=0; foreach ($fleet as $row) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td style="width:130px;"><img src="<?php echo base_url(); ?>public/uploads/<?php echo $row['photo']; ?>" alt="<?php echo $row['v_number']; ?>" style="width:120px;"></td> <td><?php echo $row['designation']; ?></td> <td><?php echo $row['v_number']; ?></td> <td><?php echo $row['v_reg']; ?></td> <td><?php echo $row['v_pax']; ?></td> <td> <a href="<?php echo base_url(); ?>admin/fleet/edit/<?php echo $row['v_id']; ?>" class="btn btn-primary btn-xs">Edit</a> <a href="<?php echo base_url(); ?>admin/fleet/delete/<?php echo $row['v_id']; ?>" class="btn btn-danger btn-xs" onClick="return confirm('Are you sure?');">Delete</a> </td> </tr> <?php } ?> </tbody> </table> </div> </div> </div> </div> </section> I can't work out why this is happening as all other sections, use the same code concept and layout with no issue. Any guidance would be appreciated. Cheers Dan
  24. By using <button onclick="myFunction('<?php echo $target;?>')">go to url</button> And from looking at the code: $target="target"; You are asking the myfunction to look for 'target' That's all it will look for is 'target'. Change it to $target=$row['target']; I could be wrong though. But that's how I am seeing it.
  25. Thank you so much mate. That resolved it.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.