Skip to content

Instantly share code, notes, and snippets.

@devnullone
Created July 27, 2022 22:58
Show Gist options
  • Save devnullone/bee0e9d2525e3fdec2cc219df8cb9424 to your computer and use it in GitHub Desktop.
Save devnullone/bee0e9d2525e3fdec2cc219df8cb9424 to your computer and use it in GitHub Desktop.
Example CI4 MVC
<!-- Header Start-->
<?php include('includes/header.php');?>
<!-- Header End-->
<!--begin::Content-->
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
<!--begin::Container-->
<!-- breadcrumb start -->
<?php include('includes/breadcrumb.php');?>
<!-- breadcrumb end -->
<!-- begin:Entry -->
<div class="d-flex flex-column-fluid">
<!--begin::Container-->
<div class="container">
<div class="d-lg-flex flex-row-fluid">
<!-- Navbar Start-->
<?php include('includes/navbar.php');?>
<!-- Navbar End-->
<div class="content-wrapper flex-row-fluid">
<div class="card card-custom">
<div class="card-header flex-wrap border-0 pt-6 pb-0">
<h2>Clients</h2>
<div class="card-toolbar">
<!--begin::Button-->
<a href="#" class="btn btn-primary font-weight-bolder" data-toggle="modal" data-target="#addModal">
<span class="svg-icon svg-icon-md">
<!--begin::Svg Icon | path:assets/media/svg/icons/Design/Flatten.svg-->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect x="0" y="0" width="24" height="24"></rect>
<circle fill="#000000" cx="9" cy="15" r="6"></circle>
<path d="M8.8012943,7.00241953 C9.83837775,5.20768121 11.7781543,4 14,4 C17.3137085,4 20,6.6862915 20,10 C20,12.2218457 18.7923188,14.1616223 16.9975805,15.1987057 C16.9991904,15.1326658 17,15.0664274 17,15 C17,10.581722 13.418278,7 9,7 C8.93357256,7 8.86733422,7.00080962 8.8012943,7.00241953 Z" fill="#000000" opacity="0.3"></path>
</g>
</svg>
<!--end::Svg Icon-->
</span>Ajouter</a>
<!--end::Button-->
</div>
</div>
<div class="card-body">
<!--begin: Search Form-->
<!--begin::Search Form-->
<div class="mb-7">
<div class="row align-items-center">
<div class="col-lg-9 col-xl-8">
<div class="row align-items-center">
<div class="col-md-8 my-2 my-md-0">
<div class="input-icon">
<input type="text" class="form-control" placeholder="" id="kt_datatable_search_query">
<span>
<i class="flaticon2-search-1 text-muted"></i>
</span>
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-xl-4 mt-5 mt-lg-0">
<a href="#" class="btn btn-light-primary px-6 font-weight-bold">Search</a>
</div>
</div>
</div>
<!--end::Search Form-->
<!--end: Search Form-->
<!--begin: Datatable-->
<div class="datatable datatable-bordered datatable-head-custom datatable-default datatable-primary datatable-loaded" id="kt_datatable" style="">
<table class="datatable-table" style="display: block;" id="clientTable"> <!--clientTable-->
<thead class="datatable-head">
<tr class="datatable-row" style="left: 0px;">
<th data-field="RecordID" class="datatable-cell-center datatable-cell datatable-cell-check">
<span style="width: 20px;">
<label class="checkbox checkbox-single checkbox-all">
<input type="checkbox">&nbsp;
<span></span>
</label>
</span>
</th>
<th data-field="OrderID" class="datatable-cell datatable-cell-sort">
<span style="width: 100px;">Nom Prenom</span>
</th>
<th data-field="Status" class="datatable-cell datatable-cell-sort">
<span style="width: 70;">Telephone</span>
</th>
<th data-field="Type" data-autohide-disabled="false" class="datatable-cell datatable-cell-sort">
<span style="width: 150px;">Adresse</span>
</th>
<th data-field="Type" data-autohide-disabled="false" class="datatable-cell datatable-cell-sort">
<span style="width: 80px;">montant</span>
</th>
<th data-field="Actions" data-autohide-disabled="false" class="datatable-cell datatable-cell-sort">
<span style="width: 120px;">Actions</span>
</th>
</tr>
</thead>
<tbody class="datatable-body" style="">
<?php foreach($client_detail as $row){
?>
<tr id="<?php echo $row['id']; ?>" data-row="0" class="datatable-row" style="left: 0px;">
<td class="datatable-cell-center datatable-cell datatable-cell-check" data-field="RecordID" aria-label="1">
<span style="width: 20px;">
<label class="checkbox checkbox-single">
<input type="checkbox" value="<?php echo $row['id']; ?>">&nbsp;<span></span>
</label>
</span>
</td>
<td data-field="nomprenom" aria-label="<?php echo $row['nom']; ?> <?php echo $row['prenom']; ?>" class="datatable-cell">
<span style="width: 100px;">
<?php echo $row['nom']; ?> <?php echo $row['prenom']; ?>
</span>
</td>
<td data-field="telephone" aria-label="6" class="datatable-cell">
<span class="" style="width: 70px;">
<?php echo $row['telephone']; ?>
</span>
</td>
<td data-field="adresse" data-autohide-disabled="false" aria-label="2" class="datatable-cell">
<span class="" style="width: 150px;">
<?php echo $row['adresse']; ?>
</span>
</td>
<td data-field="montant" aria-label="6" class="datatable-cell">
<span class="" style="width: 70px;">
<?php echo $row['montant']; ?>
</span>
</td>
<td data-field="Actions" data-autohide-disabled="false" aria-label="null" class="datatable-cell">
<span style="overflow: visible; position: relative; width: 120px;">
<a data-id="<?php echo $row['id']; ?>" class="btn btn-sm btn-clean btn-icon mr-2 btnVoir" title="Voir">
<span class="svg-icon svg-icon-md"><!--begin::Svg Icon | path:C:\wamp64\www\keenthemes\legacy\metronic\theme\html\demo9\dist/../src/media/svg/icons\General\Visible.svg--><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><rect x="0" y="0" width="24" height="24"/><path d="M3,12 C3,12 5.45454545,6 12,6 C16.9090909,6 21,12 21,12 C21,12 16.9090909,18 12,18 C5.45454545,18 3,12 3,12 Z" fill="#000000" fill-rule="nonzero" opacity="0.3"/><path d="M12,15 C10.3431458,15 9,13.6568542 9,12 C9,10.3431458 10.3431458,9 12,9 C13.6568542,9 15,10.3431458 15,12 C15,13.6568542 13.6568542,15 12,15 Z" fill="#000000" opacity="0.3"/></g></svg><!--end::Svg Icon--></span>
</a>
<a id="btnEdit" data-id="<?php echo $row['id']; ?>" class="btn btn-sm btn-clean btn-icon mr-2 btnEdit" title="Modifier">
<span class="svg-icon svg-icon-md"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect x="0" y="0" width="24" height="24"></rect>
<path d="M8,17.9148182 L8,5.96685884 C8,5.56391781 8.16211443,5.17792052 8.44982609,4.89581508 L10.965708,2.42895648 C11.5426798,1.86322723 12.4640974,1.85620921 13.0496196,2.41308426 L15.5337377,4.77566479 C15.8314604,5.0588212 16,5.45170806 16,5.86258077 L16,17.9148182 C16,18.7432453 15.3284271,19.4148182 14.5,19.4148182 L9.5,19.4148182 C8.67157288,19.4148182 8,18.7432453 8,17.9148182 Z" fill="#000000" fill-rule="nonzero" transform="translate(12.000000, 10.707409) rotate(-135.000000) translate(-12.000000, -10.707409) "></path>
<rect fill="#000000" opacity="0.3" x="5" y="20" width="15" height="2" rx="1"></rect>
</g></svg>
</span>
</a>
<a href="#" id="btn_delete" data-id="<?php echo $row['id']; ?>" class="btn btn-sm btn-clean btn-icon btn_delete" title="Supprimer">
<span class="svg-icon svg-icon-md">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect x="0" y="0" width="24" height="24"></rect>
<path d="M6,8 L6,20.5 C6,21.3284271 6.67157288,22 7.5,22 L16.5,22 C17.3284271,22 18,21.3284271 18,20.5 L18,8 L6,8 Z" fill="#000000" fill-rule="nonzero"></path>
<path d="M14,4.5 L14,4 C14,3.44771525 13.5522847,3 13,3 L11,3 C10.4477153,3 10,3.44771525 10,4 L10,4.5 L5.5,4.5 C5.22385763,4.5 5,4.72385763 5,5 L5,5.5 C5,5.77614237 5.22385763,6 5.5,6 L18.5,6 C18.7761424,6 19,5.77614237 19,5.5 L19,5 C19,4.72385763 18.7761424,4.5 18.5,4.5 L14,4.5 Z" fill="#000000" opacity="0.3"></path>
</g>
</svg>
</span>
</a>
</span>
</td>
</tr>
<?php }
?>
</tbody>
</table>
<div class="datatable-pager datatable-paging-loaded">
<ul class="datatable-pager-nav my-2 mb-sm-0">
<li>
<a title="First" class="datatable-pager-link datatable-pager-link-first datatable-pager-link-disabled" data-page="1" disabled="disabled">
<i class="flaticon2-fast-back"></i>
</a>
</li>
<li>
<a title="Previous" class="datatable-pager-link datatable-pager-link-prev datatable-pager-link-disabled" data-page="1" disabled="disabled">
<i class="flaticon2-back"></i></a>
</li>
<li style="display: none;">
<input type="text" class="datatable-pager-input form-control" title="Page number">
</li>
<li>
<a class="datatable-pager-link datatable-pager-link-number datatable-pager-link-active" data-page="1" title="1">1</a>
</li>
<li>
<a class="datatable-pager-link datatable-pager-link-number" data-page="2" title="2">2</a>
</li>
<li>
<a class="datatable-pager-link datatable-pager-link-number" data-page="3" title="3">3</a>
</li>
<li>
<a class="datatable-pager-link datatable-pager-link-number" data-page="4" title="4">4</a>
</li>
<li>
<a class="datatable-pager-link datatable-pager-link-number" data-page="5" title="5">5</a>
</li>
<li>
<a title="Next" class="datatable-pager-link datatable-pager-link-next" data-page="2">
<i class="flaticon2-next"></i>
</a>
</li>
<li>
<a title="Last" class="datatable-pager-link datatable-pager-link-last" data-page="10"><i class="flaticon2-fast-next"></i></a>
</li>
</ul>
<div class="datatable-pager-info my-2 mb-sm-0">
<span class="datatable-pager-detail">Showing 1 - 10 of 100</span>
</div>
</div>
</div>
<!--end: Datatable-->
<!--Ajouter Modal-->
<div class="modal fade" id="addModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdrop" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addModal">Ajouter Client</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i aria-hidden="true" class="ki ki-close"></i>
</button>
</div>
<div class="modal-body">
<form id="addClient" name="addClient" action="<?php echo site_url('client/store');?>" method="post">
<div class="form-group row">
<div class="col-sm-6">
<label>Nom:</label>
<input type="text" id="nom" class="form-control" placeholder="ALI" name="nom">
</div>
<div class="col-sm-6">
<label>Prenom:</label>
<input type="text" id="prenom" class="form-control" placeholder="Grace" name="prenom" >
</div>
</div>
<div class="form-group row">
<div class="col-sm-6">
<label>Téléphone:</label>
<div class="input-group">
<input type="tel" id="telephone" class="form-control" placeholder="+228 90 85 53 01" name="telephone">
<div class="input-group-append">
<span class="input-group-text">
<i class="la la-phone"></i>
</span>
</div>
</div>
</div>
<div class="col-sm-6">
<label>Adresse:</label>
<div class="input-group">
<input type="text" id="adresse" class="form-control" placeholder="53 Rue de la Liberation" name="adresse">
<div class="input-group-append">
<span class="input-group-text">
<i class="la la-map-marker"></i>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-light-primary font-weight-bold" data-dismiss="modal">Annuler</button>
<button type="submit" name="submitButton" class=" btn btn-primary font-weight-bold">Enregistrer</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!--Voir Modal-->
<div class="modal fade" id="viewModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdrop" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="viewModal">Aperçu Client</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i aria-hidden="true" class="ki ki-close"></i>
</button>
</div>
<div class="modal-body">
<div class="card card-custom gutter-b">
<!--begin::Body-->
<div class="card-body pt-4">
<!--begin::Separator-->
<div class="d-flex justify-content-end mb-5">
</div>
<!--end::Separator-->
<!--begin::User-->
<div class="d-flex align-items-center">
<div class="symbol symbol-60 symbol-xxl-100 mr-5 align-self-start align-self-xxl-center">
<span class="symbol symbol-35">
<span class="symbol-label font-size-h5 font-weight-bold text-black bg-green-o-30"><i class="fa fa-user"></i></span>
</span>
<!-- <i class="symbol-badge bg-success"></i> -->
</div>
<div>
<a class="font-weight-bold font-size-h5 text-dark-75 text-hover-primary"><span class="nom_view"></span>&nbsp;&nbsp;<span class="prenom_view"></span></a>
<div class="text-muted">Client</div>
</div>
</div>
<!--end::User-->
<!--begin::View-->
<div class="pt-8 pb-6">
<div class="d-flex align-items-center justify-content-between mb-2">
<span class="font-weight-bold mr-2">IDENTIFIANT:</span>
<span class="text-muted"><span class="id_view"></span></span>
</div>
<div class="d-flex align-items-center justify-content-between mb-2">
<span class="font-weight-bold mr-2">TELEPHONE:</span>
<span class="text-muted"><span class="telephone_view"></span></span>
</div>
<div class="d-flex align-items-center justify-content-between mb-2">
<span class="font-weight-bold mr-2">ADRESSE:</span>
<span class="text-muted"><span class="adresse_view"></span></span>
</div>
<div class="d-flex align-items-center justify-content-between mb-2">
<span class="font-weight-bold mr-2">MONTANT:</span>
<a class="text-muted text-hover-primary"><span class="montant_view"></span>&nbsp;&nbsp;<span>CFA</span></a>
</div>
</div>
<!--end::View-->
</div>
<!--end::Body-->
</div>
</div>
</div>
</div>
</div>
<!--Modifier Modal-->
<div class="modal fade" id="updateModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdrop" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="updateModal">Modification</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i aria-hidden="true" class="ki ki-close"></i>
</button>
</div>
<div class="modal-body">
<form id="updateClient" name="updateClient" action="<?php echo site_url('client/update');?>" method="post">
<input type="hidden" name="hdnClientId" id="hdnClientId"/>
<div class="form-group row">
<div class="col-sm-6">
<label>Nom:</label>
<input type="text" id="txtNom" class="form-control" placeholder="" name="txtNom">
</div>
<div class="col-sm-6">
<label>Prénom:</label>
<input type="text" id="txtPrenom" class="form-control" placeholder="" name="txtPrenom" >
</div>
</div>
<div class="form-group row">
<div class="col-sm-6">
<label>Telphone:</label>
<div class="input-group">
<input type="tel" id="txtTelephone" class="form-control" placeholder="" name="txtTelephone">
<div class="input-group-append">
<span class="input-group-text">
<i class="la la-phone"></i>
</span>
</div>
</div>
</div>
<div class="col-sm-6">
<label>Adresse:</label>
<div class="input-group">
<input type="text" id="txtAdresse" class="form-control" placeholder="" name="txtAdresse">
<div class="input-group-append">
<span class="input-group-text">
<i class="la la-map-marker"></i>
</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12">
<label>Montant:</label>
<div class="input-group">
<input type="tel" id="txtMontant" class="form-control" placeholder="" name="txtMontant">
<div class="input-group-append">
<span class="input-group-text">
<i class="la la-dollar-sign"></i>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-light-primary font-weight-bold" data-dismiss="modal">Annuler</button>
<button type="submit" name="submitButton" class=" btn btn-primary font-weight-bold">Modifier</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!--Suprimer Modal-->
<div class="modal fade" id="deleteModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdrop" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModal">Supprimer Client</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i aria-hidden="true" class="ki ki-close"></i>
</button>
</div>
<div class="modal-body">
<form id="addClient" name="addClient" action="<?php echo site_url('client/store');?>" method="post">
<div class="form-group row">
<div class="col-sm-12">
<input type="hidden" id="client_del_id" class="form-control">
</div>
</div>
</form>
<h5>Veuillez confirmer la suppression</h5>
</div>
<div class="modal-footer">
<button type="reset" class="btn btn-light-primary font-weight-bold" data-dismiss="modal">Annuler</button>
<button type="submit" id ="deleteconfirmed" name="submitButton" class=" btn btn-primary font-weight-bold deleteconfirmed">Supprimer</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--end::Container-->
</div>
<!-- End:Entry -->
<!--end::Container-->
</div>
<!--end::Content-->
<script>
$(document).ready(function () {
//Ajouter Client
$("#addClient").validate({
rules: {
nom: "required",
prenom: "required",
telephone: "required",
adresse: "required",
},
messages: {
},
submitHandler: function(form) {
var form_action = $("#addClient").attr("action");
$.ajax({
data: $('#addClient').serialize(),
url: form_action,
type: "POST",
dataType: 'json',
success: function (res) {
var client = '<tr id="'+res.data.id+'" data-row="0" class="datatable-row" style="left: 0px;">';
client += '<td class="datatable-cell-center datatable-cell datatable-cell-check" data-field="RecordID" aria-label="1"><span style="width: 20px;"><label class="checkbox checkbox-single"><input type="checkbox" value="' + res.data.id + '">&nbsp;<span></span></label></span></td>';
client += '<td data-field="nomprenom" aria-label="" class="datatable-cell"><span style="width: 122px;">' + res.data.nom + + res.data.prenom + '</span></td>';
client += '<td data-field="telephone" aria-label="" class="datatable-cell"><span class="" style="width: 150px;">' + res.data.telephone + '</span></td>';
client += '<td data-field="adresse" data-autohide-disabled="false" aria-label="2" class="datatable-cell"> <span class="" style="width: 180px;">' + res.data.address + '</span></td>';
client += '<td data-field="montant" data-autohide-disabled="false" aria-label="2" class="datatable-cell"> <span class="" style="width: 180px;">' + res.data.montant + '</span></td>';
client += '<td data-field="Actions" data-autohide-disabled="false" aria-label="2" class="datatable-cell> <span style="overflow: visible; position: relative; width: 120px;"><a data-id="' + res.data.id + ' class="btn btn-sm btn-clean btn-icon mr-2" title="Modifier" ><i class="fa fa-home"></i></a>&nbsp;&nbsp;<a data-id="' + res.data.id + '" class="btn btn-sm btn-clean btn-icon" title="Supprimer"><i class="fa fa-home"></i></a></td>';
client += '<td><a data-id="' + res.data.id + '" class="btn btn-primary btnVoir">Voir</a>&nbsp;&nbsp;<a href="#" data-id="' + res.data.id + '" class="btn btn-danger btn_delete">Modifier</a><a data-id="' + res.data.id + '" class="btn btn-danger btnDelete">Supprimer</a></td>';
client += '</tr>';
$('#clientTable tbody').prepend(client);
$('#addClient')[0].reset();
$('#addModal').modal('hide');
},
error: function (data) {
}
});
}
});
});
</script>
<script>
// Modifier Client
$('body').on('click', '#btnEdit', function () {
var client_id = $(this).attr('data-id');
//alert(client_id);
$.ajax({
url: 'client/edit/'+client_id,
type: "GET",
dataType: 'json',
success: function (res) {
$('#updateModal').modal('show');
$('#updateClient #hdnClientId').val(res.data.id);
$('#updateClient #txtNom').val(res.data.nom);
$('#updateClient #txtPrenom').val(res.data.prenom);
$('#updateClient #txtTelephone').val(res.data.telephone);
$('#updateClient #txtAdresse').val(res.data.adresse);
$('#updateClient #txtMontant').val(res.data.montant);
},
error: function (data) {
}
});
});
// Maj Client
$("#updateClient").validate({
rules: {
txtNom: "required",
txtPrenom: "required",
txtTelephone: "required"
},
messages: {
},
submitHandler: function(form) {
var form_action = $("#updateClient").attr("action");
$.ajax({
data: $('#updateClient').serialize(),
url: form_action,
type: "POST",
dataType: 'json',
success: function (res) {
var client = '<tr id="'+res.data.id+'" data-row="0" class="datatable-row" style="left: 0px;">';
client += '<td class="datatable-cell-center datatable-cell datatable-cell-check" data-field="" aria-label="1"><span style="width: 20px;"><label class="checkbox checkbox-single"><input type="checkbox" value="' + res.data.id + '">&nbsp;<span></span></label></span></td>';
client += '<td data-field="nomprenom" aria-label="" class="datatable-cell"><span style="width: 100px;">' + res.data.nom + ' ' + res.data.prenom + '</span></td>';
client += '<td data-field="telephone" aria-label="" class="datatable-cell"><span class="" style="width: 70px;">' + res.data.telephone + '</span></td>';
client += '<td data-field="adresse" data-autohide-disabled="false" aria-label="2" class="datatable-cell"> <span class="" style="width: 150px;">' + res.data.adresse + '</span></td>';
client += '<td data-field="montant" data-autohide-disabled="false" aria-label="2" class="datatable-cell"> <span class="" style="width: 70px;">' + res.data.montant + '</span></td>';
client += '<td data-field="Actions" data-autohide-disabled="false" aria-label="null" class="datatable-cell"><span style="overflow: visible; position: relative; width: 120px;"><a data-id="' + res.data.id + '" class="btn btn-sm btn-clean btn-icon mr-2 btnVoir" title="Voir" ><span class="svg-icon svg-icon-md"><!--begin::Svg Icon | path:C:\wamp64\www\keenthemes\legacy\metronic\theme\html\demo9\dist/../src/media/svg/icons\General\Visible.svg--><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><rect x="0" y="0" width="24" height="24"/><path d="M3,12 C3,12 5.45454545,6 12,6 C16.9090909,6 21,12 21,12 C21,12 16.9090909,18 12,18 C5.45454545,18 3,12 3,12 Z" fill="#000000" fill-rule="nonzero" opacity="0.3"/><path d="M12,15 C10.3431458,15 9,13.6568542 9,12 C9,10.3431458 10.3431458,9 12,9 C13.6568542,9 15,10.3431458 15,12 C15,13.6568542 13.6568542,15 12,15 Z" fill="#000000" opacity="0.3"/></g></svg><!--end::Svg Icon--></span></a> <a id="btnEdit" data-id="' + res.data.id + '" class="btn btn-sm btn-clean btn-icon mr-2 btnEdit" title="Modifier"><span class="svg-icon svg-icon-md"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><rect x="0" y="0" width="24" height="24"></rect><path d="M8,17.9148182 L8,5.96685884 C8,5.56391781 8.16211443,5.17792052 8.44982609,4.89581508 L10.965708,2.42895648 C11.5426798,1.86322723 12.4640974,1.85620921 13.0496196,2.41308426 L15.5337377,4.77566479 C15.8314604,5.0588212 16,5.45170806 16,5.86258077 L16,17.9148182 C16,18.7432453 15.3284271,19.4148182 14.5,19.4148182 L9.5,19.4148182 C8.67157288,19.4148182 8,18.7432453 8,17.9148182 Z" fill="#000000" fill-rule="nonzero" transform="translate(12.000000, 10.707409) rotate(-135.000000) translate(-12.000000, -10.707409) "></path><rect fill="#000000" opacity="0.3" x="5" y="20" width="15" height="2" rx="1"></rect></g></svg> </span></a><a id="btn_delete" data-id="' + res.data.id + '" class="btn btn-sm btn-clean btn-icon btn_delete" title="Supprimer" ><span class="svg-icon svg-icon-md"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1"> <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><rect x="0" y="0" width="24" height="24"></rect><path d="M6,8 L6,20.5 C6,21.3284271 6.67157288,22 7.5,22 L16.5,22 C17.3284271,22 18,21.3284271 18,20.5 L18,8 L6,8 Z" fill="#000000" fill-rule="nonzero"></path><path d="M14,4.5 L14,4 C14,3.44771525 13.5522847,3 13,3 L11,3 C10.4477153,3 10,3.44771525 10,4 L10,4.5 L5.5,4.5 C5.22385763,4.5 5,4.72385763 5,5 L5,5.5 C5,5.77614237 5.22385763,6 5.5,6 L18.5,6 C18.7761424,6 19,5.77614237 19,5.5 L19,5 C19,4.72385763 18.7761424,4.5 18.5,4.5 L14,4.5 Z" fill="#000000" opacity="0.3"></path></g></svg></span></a></span></td>';
client += '</tr>';
$('#clientTable tbody #'+ res.data.id).html(client);
$('#updateClient')[0].reset();
$('#updateModal').modal('hide');
},
error: function (data) {
}
});
}
});
// Voir Client
$('body').on('click', '.btnVoir', function () {
var client_id = $(this).attr('data-id');
//alert(client_id);
$.ajax({
method: "POST",
url: "client/view",
dataType: 'json',
data: {
'client_id':client_id,
},
success: function(response){
//console.log(response);
$.each(response, function(key, clientview){
//console.log(clientview['nom']);
$('.id_view').text(clientview['id']);
$('.nom_view').text(clientview['nom']);
$('.prenom_view').text(clientview['prenom']);
$('.telephone_view').text(clientview['telephone']);
$('.adresse_view').text(clientview['adresse']);
$('.montant_view').text(clientview['montant']);
$('#viewModal').modal('show');
});
}
});
});
</script>
<script>
// Suppresion
$('body').on('click', '.btn_delete', function () {
var client_id = $(this).attr('data-id');
//alert(client_id);
$('#client_del_id').val(client_id);
$('#deleteModal').modal('show');
});
$('body').on('click', '#deleteconfirmed', function () {
var client_id = $('#client_del_id').val();
//alert(client_id);
$.get('client/delete/'+client_id, function (data) {
$('#clientTable tbody #'+ client_id).remove();
})
$('#deleteModal').modal('hide');
});
</script>
<!-- Footer Start-->
<?php include('includes/footer.php');?>
<!-- Footer End-->
<?php
namespace App\Controllers;
use App\Models\ClientModel;
class Client extends BaseController
{
public $appname = 'Systeme de Collecte Automatiser des Déchets';
public $appnameshort = 'SYCAD';
public function index()
{
$session = session();
$data['titre'] = "Profil";
$data['nom'] = $session->get('nom');
$data['admin_id'] = $session->get('id');
$data['prenom'] = $session->get('prenom');
$data['telephone'] = $session->get('telephone');
$data['adresse'] = $session->get('adresse');
$data['email'] = $session->get('email');
$model = new ClientModel();
$data['client_detail'] = $model->orderBy('id', 'DESC')->findAll();
$data['appname'] = $this->appname;
$data['appnameshort'] = $this->appnameshort;
$data['titre'] = "Client";
return view('client', $data);
}
public function store()
{
helper(['form', 'url']);
$model = new ClientModel();
$data = [
'nom' => $this->request->getVar('nom'),
'prenom' => $this->request->getVar('prenom'),
'telephone' => $this->request->getVar('telephone'),
'adresse' => $this->request->getVar('adresse'),
//'montant' => $this->request->getVar('montant'),
//'admin_id' => $this->request->getVar('admin_id'),
];
$save = $model->insert_data($data);
if($save != false){
$data = $model->where('id', $save)->first();
//echo json_encode(array("status" => true , 'data' => $data));
return redirect()->to('/client');
}else{
//echo json_encode(array("status" => false , 'data' => $data));
//return redirect()->to('/signin');
}
}
public function edit($id = null)
{
$model = new ClientModel();
$data = $model->where('id', $id)->first();
if($data){
echo json_encode(array("status" => true , 'data' => $data));
}else{
echo json_encode(array("status" => false));
}
}
public function update(){
helper(['form', 'url']);
$model = new ClientModel();
$id = $this->request->getVar('hdnClientId'); //id
$data = [
'nom' => $this->request->getVar('txtNom'), //nom
'prenom' => $this->request->getVar('txtPrenom'),
'telephone' => $this->request->getVar('txtTelephone'),
'adresse' => $this->request->getVar('txtAdresse'),
'montant' => $this->request->getVar('txtMontant'),
];
$update = $model->update($id,$data);
if($update != false)
{
$data = $model->where('id', $id)->first();
echo json_encode(array("status" => true , 'data' => $data));
}else{
echo json_encode(array("status" => false , 'data' => $data));
}
}
public function view()
{
$model = new ClientModel();
$client_id = $this->request->getPost('client_id');
$data['uClient'] = $model->find($client_id);
return $this->response->setJSON($data);
}
public function delete($id = null){
$model = new ClientModel();
$delete = $model->where('id', $id)->delete();
if($delete)
{
echo json_encode(array("status" => true));
}else{
echo json_encode(array("status" => false));
}
}
}
<?php
namespace App\Models;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;
Class ClientModel extends Model{
protected $table = 'clients';
protected $allowedFields = [
'nom',
'prenom',
'telephone',
'adresse',
'montant',
'creer_le',
'modifier_le',
'admin_id',
];
public function __construct() {
parent::__construct();
//$this->load->database();
$db = \Config\Database::connect();
$builder = $db->table('clients');
}
public function insert_data($data) {
if($this->db->table($this->table)->insert($data))
{
return $this->db->insertID();
}
else
{
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment