EVOLUTION-NINJA
Edit File: lead_account.php
<?php $this->load->view('includes/admin_header');?> <!-- Modal --> <div class="main-container " id="main-container"> <div class="main-content"> <div class="main-content-inner"> <div class=" page-content" style="background-color:#f0f0f0;"> <div class="row"> <div class="col-sm-10 " style="margin-top:5px;"> <!-- <select name="" id="" class="breadcrumb"> <option value="">All Accounts</option> <option value="">My Accounts</option> <option value="">New Last Week</option> <option value="">New This Week</option> <option value="">Recently Created Accounts</option> <option value="">Recently Modified Accounts</option> <option>Unread Accounts</option> </select> --> </div> <div class="col-sm-2 sort-by"> <ul class="breadcrumb"> <li> <div class="col-sm-1 pd-7"> <div style="float:right;"> <div class="" style="padding-top:10px;"><a href="<?php echo base_url('add-account');?>"><i class=" fa fa-plus fa-2x"></i></a></div> </div> </div> </li> <li> <button type="button" id="account_lists" class="btn btn-sm">Export</button> </li> </ul> </div> </div> <div class="row" style="background-color:white;margin-top:10px;"> <div class="col-xs-12"> <!-- PAGE CONTENT BEGINS --> <div class="hr dotted"></div> <div> <div class="row search-page" id="search-page-1"> <div class="col-xs-12"> <div class="row"> <div class="col-xs-12 col-sm-12"> <div class="row"> <div id="addele_more"> <div class="col-sm-12 table-responsive"> <table class="table" id="maintable"> <thead> <tr id="column_id"> <th>Sl No.</th> <th>Account Name</th> <!--<th>Company Name</th>--> <th style="width: 100px;!important;">Contact Person</th> <th>Account Opened On</th> <th>Phone</th> <th>Website</th> <th>Account Owner</th> <th>Action</th> </tr> </thead> <tbody> <?php $ct = 1; foreach ($accounts_data as $value) { ?> <tr class="hoverr click-on"> <td><?php echo $ct; ?></td> <td><a href="<?php echo site_url("account-info/$value->account_id"); ?>"><?php echo $value->account_name; ?></a></td> <td><?php echo $value->lead_contact_person; ?></td> <td><?php if($value->opened_on != '0000-00-00'){ $date = new DateTime($value->opened_on); echo $date->format('d-m-Y'); } ?></td> <td><?php echo $value->phone; ?></td> <td><?php echo $value->website; ?></td> <td><?php echo $value->user_name; ?></td> <td> <div class=" btnwarning" data-toggle="modal" data-target="#editModal" data-id="<?php echo $value->account_id; ?>" data-name="<?php echo $value->account_name; ?>" data-contact="<?php echo $value->lead_contact_person; ?>" data-phone="<?php echo $value->phone; ?>" data-website="<?php echo $value->website; ?>" data-owner="<?php echo $value->user_name; ?>"> <span class="glyphicon glyphicon-pencil "></span> <span class="glyphicon glyphicon-trash" onclick='delete_account("<?php echo $value->account_id; ?>");' ></span> </div> </td> </tr> <?php $ct++; } ?> </tbody> </table> </div> </div> </div> </div> </div> </div> </div> </div> </div><!-- /.col --> </div><!-- /.row --> </div><!-- /.page-content --> </div> </div><!-- /.main-content --> <!-- script edit by dileep ****************************************************** --> <!-- Modal --> <!-- Edit Modal --> <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="editModalLabel">Edit Account</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <form id="editForm"> <input type="hidden" name="account_id" id="account_id"> <div class="form-group"> <label for="account_name">Account Name</label> <input type="text" class="form-control" name="account_name" id="account_name"> </div> <div class="form-group"> <label for="contact_person">Contact Person</label> <input type="text" class="form-control" name="contact_person" id="contact_person"> </div> <div class="form-group"> <label for="phone">Phone</label> <input type="text" class="form-control" name="phone" id="phone"> </div> <div class="form-group"> <label for="website">Website</label> <input type="text" class="form-control" name="website" id="website"> </div> <div class="form-group"> <label for="owner">Account Owner</label> <input type="text" class="form-control" name="owner" id="owner"> </div> <button type="submit" class="btn btn-primary">Save changes</button> </form> </div> </div> </div> </div> <script> $(document).ready(function() { // When the Edit button is clicked, fetch the account details $(document).on('click', '.btnwarning', function() { var accountId = $(this).data('id'); // Send an AJAX request to fetch account details $.ajax({ url: "<?php echo site_url('yaskawa/fetch_account_details'); ?>", method: "POST", data: { account_id: accountId }, dataType: "json", success: function(response) { if (response.status == 'success') { // Populate the modal fields with the data $('#account_id').val(response.data.account_id); $('#account_name').val(response.data.account_name); $('#contact_person').val(response.data.contact_person); $('#phone').val(response.data.phone); $('#website').val(response.data.website); $('#owner').val(response.data.owner); // Show the modal $('#editModal').modal('show'); } else { alert('Unable to fetch account details.'); } } }); }); // When the form is submitted, send the updated data via AJAX $('#editForm').on('submit', function(e) { e.preventDefault(); // Prevent normal form submission var formData = $(this).serialize(); // Serialize the form data // Send the data via AJAX $.ajax({ url: "<?php echo site_url('Yaskawa/update_account'); ?>", method: "POST", data: formData, dataType: "json", success: function(response) { if (response.status == 'success') { // Show SweetAlert success notification Swal.fire({ title: 'Success!', text: 'Account updated successfully!', icon: 'success', timer:3000, confirmButtonText: 'OK' }).then((result) => { if (result.isConfirmed) { $('#editModal').modal('hide'); // Hide the modal location.reload(); // Reload the page to reflect the changes } }); } else { // Show SweetAlert error notification Swal.fire({ title: 'Error!', text: 'Failed to update the account.', icon: 'error', confirmButtonText: 'OK' }); } } }); }); }); </script> <!-- delete --> </script> <!-- ****************************************************************************** --> <script src="<?php echo base_url('admin_assets/assets/js/jquery-2.1.4.min.js'); ?>"></script> <!-- <script src="<?php echo base_url('admin_assets/assets/js/bootstrap.min.js'); ?>"></script> --> <!-- page specific plugin scripts --> <script src="<?php echo base_url('admin_assets/assets/js/tree.min.js'); ?>"></script> <script src="<?php echo base_url('admin_assets/assets/js/select2.min.js'); ?>"></script> <script src="<?php echo base_url('admin_assets/assets/js/jquery-ui.custom.min.js'); ?>"></script> <script src="<?php echo base_url('admin_assets/assets/js/jquery.ui.touch-punch.min.js'); ?>"></script> <script src="<?php echo base_url('admin_assets/assets/js/holder.min.js'); ?>"></script> <!-- ace scripts --> <script src="<?php echo base_url('admin_assets/assets/js/ace-elements.min.js'); ?>"></script> <script src="<?php echo base_url('admin_assets/assets/js/ace.min.js'); ?>"></script> <!-- inline scripts related to this page --> <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet"> <script src="<?php echo base_url('admin_assets/assets/js/jquery-ui.js');?>"></script> <script src="<?php echo base_url('admin_assets/assets/js/jquery.table2excel.js');?>"></script> <script src="<?php echo base_url('admin_assets/assets/datatables/jquery.dataTables.min.js');?>"></script> <script src="<?php echo base_url('admin_assets/assets/datatables/dataTables.bootstrap.min.js');?>"></script> <link rel="stylesheet" href="<?php echo base_url('admin_assets/assets/datatables/dataTables.bootstrap.css');?>"> <script src="<?php echo base_url('admin_assets/assets/js/jquery.table2excel.js');?>"></script> <!-- jQuery (required for Bootstrap's JavaScript plugins) --> <!-- jQuery (required for DataTables and Bootstrap) --> <!-- DataTables JS (should be loaded after jQuery) --> <script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css"> <!-- Include Bootstrap JS (make sure it's after jQuery) --> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> <!-- Include SweetAlert2 CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11.7.0/dist/sweetalert2.min.css"> <!-- Include SweetAlert2 JS --> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.7.0/dist/sweetalert2.all.min.js"></script> <script> function delete_account(account_id) { event.stopPropagation(); // Prevents any further event handlers from being triggered (like opening the edit modal) // Show SweetAlert confirmation prompt Swal.fire({ title: 'Are you sure?', text: "You won't Delete ", icon: 'warning', showCancelButton: true, confirmButtonColor: '#d33', cancelButtonColor: '#3085d6', confirmButtonText: 'Yes, delete it!' }).then((result) => { if (result.isConfirmed) { // Proceed with the deletion using AJAX $.ajax({ url: "<?php echo site_url('Yaskawa/delete_account'); ?>", // The controller and method for deletion method: "POST", data: { account_id: account_id }, // Sending account_id for deletion dataType: "json", success: function(response) { if (response.status === 'success') { // SweetAlert for success Swal.fire({ title: 'Deleted!', text: 'Account has been deleted.', icon: 'success', confirmButtonText: 'OK' }).then(() => { // Optionally, remove the row from the table $('tr').find(`td:contains(${account_id})`).closest('tr').remove(); location.reload(); // Reload the page to reflect the changes }); } else { // SweetAlert for failure Swal.fire({ title: 'Error!', text: 'Failed to delete the account.', icon: 'error', confirmButtonText: 'OK' }); } }, error: function(xhr, status, error) { // SweetAlert for AJAX error Swal.fire({ title: 'Error!', text: 'An error occurred while deleting the account.', icon: 'error', confirmButtonText: 'OK' }); console.error('AJAX Error:', error); } }); } }); } </script> </body> </html> <script type="text/javascript"> $(".table td").hover(function() { //$(this).prop('title', $.trim($(this).text())); addclass(); }); function addclass(){ $('.table td').addClass("edit1"); } var datatable; var tbody = $('#table_body'); datatable = $('.table').DataTable({ }); </script> <style type="text/css"> #treeview-searchable .node-disabled { display: none; } .hoverr:hover .addd { display:block; } .addd{ display:none; } .add_more { padding: 0px 7px !important; font-size: 12px !important; } #block{display:none;padding-left:10px;} .pd-7{ padding-right:7px !important; padding-left:7px !important; } .pd-9{ padding:2px 9px !important; } </style> <script type="text/javascript"> $("#account_lists").click(function(){ //alert(); $("#maintable").table2excel({ exclude: ".noExl", name: "Excel Document Name", filename: "Account list", fileext: ".xls", exclude_img: true, exclude_links: true, exclude_inputs: true }); }); </script> <script> $(".col1").click(function(){ var text = $(this).val(); var test = $(this); if($(this).is(':checked')) { $("#column_id").append('<th>'+text+'</th>'); } else { $(".column_id").empty(); $('input[name="columns[]"]:checked').each(function() { console.log(this.value); $(".column_id").append('<th>'+this.value+'</th>'); }); } }); $('#cbxShowHide').click(function(){ this.checked?$('#block').show():$('#block').hide(); }); </script> <!-- Later in the body --> <?php $this->load->view('includes/admin_footer');?>