backoffice/application/views/gestion_operateurs_admin.php

576 lines
21 KiB
PHP
Raw Normal View History

2020-10-27 10:50:41 +00:00
<link rel="stylesheet" href="<?php echo base_url('bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css') ?>">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/css/bootstrap-multiselect.css">
<link rel="stylesheet" href="<?php echo base_url('bower_components/toastr/toastr.css') ?>">
2020-10-27 10:50:41 +00:00
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
2020-11-06 17:47:42 +00:00
<?php echo $this->lang->line('management_operators'); ?>
2020-10-27 10:50:41 +00:00
<input type="button" class="btn btn-primary pull-right" id="Bactiver" value="Activer/Désactiver le(s) banque(s)" style="display: none;" />
</h1>
<?php
$site_url = base_url();
if($alert=="ok") {
if(!$success=="ok"){
?>
<div class='alert alert-danger alert-dismissible col-xs-6'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
<h4><i class='icon fa fa-ban'></i> Erreur!</h4>
<?php echo $message; ?>
</div>
<?php
} else {
?>
<div class="alert alert-success alert-dismissible col-xs-6">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<h4><i class="icon fa fa-check"></i> Success!</h4>
<?php echo $message; ?>
</div>
<?php
}
}
?>
</section>
<section class="content">
<div class="row">
<div class="col-lg-8">
<div class="box">
<div class="box-header">
2020-11-06 17:47:42 +00:00
<h3 class="box-title"><?php echo $this->lang->line('operators'); ?></h3>
2020-10-27 10:50:41 +00:00
</div>
<div class="box-body" style="overflow-x:auto;">
<?php
2020-11-06 17:47:42 +00:00
$sql2 = $operators;
2020-10-27 10:50:41 +00:00
if($sql2!=false){
$numrows=$sql2->num_rows();
$num = 0;
if ($numrows > 0) {
?>
<table id="validated" class="table table-bordered table-striped">
<thead>
<tr>
<th align='center'></th>
<th><?php echo $this->lang->line('Pays'); ?></th>
2020-11-06 17:47:42 +00:00
<th>Type</th>
2020-10-27 10:50:41 +00:00
<th><?php echo $this->lang->line('Nom'); ?></th>
2020-11-06 17:47:42 +00:00
<th>Code</th>
2020-10-27 10:50:41 +00:00
<th><?php echo $this->lang->line('Adresse'); ?></th>
<th align='center'><?php echo $this->lang->line('Statut'); ?></th>
<th align='center'><?php echo $this->lang->line('Activer/Désactiver'); ?></th>
2020-11-06 17:47:42 +00:00
<th align='center'>Action</th>
2020-10-27 10:50:41 +00:00
</tr>
</thead>
<tbody>
<?php
foreach($sql2->result() as $row) {
$num ++;
$libelle_status = $this->lang->line('Actif');
if($row->status==0){
$libelle_status = $this->lang->line('Inactif');
}
2020-11-06 17:47:42 +00:00
$type = $this->session->userdata('site_lang') === 'french' ? $row->type_fr : $row->type_en;
?>
<tr>
<td align='center'><?= $num?></td>
<td><?= $row->country?></td>
<td><?=$type ?></td>
<td ><?=$row->operator_name ?></td>
<td ><?=$row->operator_code?></td>
<td ><?=$row->operator_address?></td>
<td align='center'><?=$libelle_status?></td>
<?php
2020-10-27 10:50:41 +00:00
if($row->status==0){
echo "<td align='center'><label>
2020-11-06 17:47:42 +00:00
<input type='checkbox' name='activer' class='minimal' data-id-operator='".$row->id."' data-id-country='".$row->country_id."' >
2020-10-27 10:50:41 +00:00
</label>
<label>
2020-11-06 17:47:42 +00:00
<input type='checkbox' name='desactiver' class='minimal-red' disabled data-id-operator='".$row->id."' data-id-country='".$row->country_id."'>
2020-10-27 10:50:41 +00:00
</label></td>";
}else{
echo "<td align='center'><label>
2020-11-06 17:47:42 +00:00
<input type='checkbox' name='activer' class='minimal' disabled data-id-operator='".$row->id."' data-id-country='".$row->country_id."'>
2020-10-27 10:50:41 +00:00
</label>
<label>
2020-11-06 17:47:42 +00:00
<input type='checkbox' name='desactiver' class='minimal-red' data-id-operator='".$row->id."' data-id-country='".$row->country_id."'>
2020-10-27 10:50:41 +00:00
</label></td>";
}
2020-11-06 17:47:42 +00:00
?>
<td align='center'>
<button data-toggle='modal' data-id-operator='<?=$row->id?>' data-name-operator='<?=$row->operator_name?>' data-type-operator="<?=$type?>"
data-address-operator='<?=$row->operator_address?>' data-code-operator='<?=$row->operator_code?>' data-country='<?=$row->country?>' data-id-country='<?=$row->country_id?>' class='open-modal btn btn-success' data-target='#editModal'><i class='fa fa-edit'></i></button>
<button data-id-operator='<?=$row->id?>' data-id-country='<?=$row->country_id?>' class='delete-operator btn btn-danger' ><i class='fa fa-trash'></i></button>
2020-10-27 10:50:41 +00:00
</td>
2020-11-06 17:47:42 +00:00
</tr>
<?php } ?>
2020-10-27 10:50:41 +00:00
</tbody>
</table>
<?php
}
else {
2020-11-06 17:47:42 +00:00
echo $this->lang->line('no_operator');
2020-10-27 10:50:41 +00:00
}
}else {
2020-11-06 17:47:42 +00:00
echo $this->lang->line('no_operator');
2020-10-27 10:50:41 +00:00
}
?>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="box">
<div class="box-header">
2020-11-06 17:47:42 +00:00
<h3 class="box-title"><?php echo $this->lang->line('add_operator'); ?></h3>
2020-10-27 10:50:41 +00:00
</div>
<div class="box-body">
2020-11-06 17:47:42 +00:00
<form id="add-operator" method="post" class="bottom-75 center-block">
2020-10-27 10:50:41 +00:00
<div class="form-group">
<label for="name"><?php echo $this->lang->line('Nom'); ?></label>
<input type="text" class="form-control input-lg" name="name" required id="name">
</div>
2020-11-06 17:47:42 +00:00
<div class="form-group">
<label for="type"><?php echo $this->lang->line('operator_type'); ?></label>
<?php
$result=$operators_types;
$numrows=$result->num_rows();
if ($numrows > 0) { ?>
<select class="form-control input-lg" name="type" required id="type" >
<?php foreach($result->result() as $row) {
echo "<option value='".$row->code."' id='".$row->id."'>".($this->session->userdata('site_lang') === 'french' ? $row->description_fr : $row->description_en)."</option>";
} ?>
</select>
<?php }else{
echo $this->lang->line("no_type");
}
?>
</div>
2020-10-27 10:50:41 +00:00
<div class="form-group">
<button type="submit" class="btn btn-primary"><?php echo $this->lang->line('Ajouter'); ?></button>
<button type="button" class="btn btn-success" data-toggle='modal' data-target='#addOperatorType' > <?php echo $this->lang->line('add_operator_type'); ?></button>
2020-10-27 10:50:41 +00:00
</div>
</form>
</div>
</div>
<div class="box">
<div class="box-header">
2020-11-06 17:47:42 +00:00
<h3 class="box-title"><?php echo $this->lang->line('assign_operator_to_country'); ?></h3>
2020-10-27 10:50:41 +00:00
</div>
<div class="box-body">
<form id="assign-form" method="post" class="bottom-75 center-block">
<div class="form-group">
<label for="pays"><?php echo $this->lang->line('Pays'); ?></label>
<?php
$result=$pays;
$numrows=$result->num_rows();
if ($numrows > 0) { ?>
<select class="form-control input-lg" name="pays" required id="pays" multiple="multiple" >
<?php foreach($result->result() as $row) {
echo "<option value='".$row->id."' id='".$row->code_country."'>".$row->name."</option>";
} ?>
</select>
<?php }else{
echo $this->lang->line("Aucun pays");
}
?>
</div>
<div class="form-group">
2020-11-06 17:47:42 +00:00
<label for="ville"><?php echo $this->lang->line('operators'); ?></label>
2020-10-27 10:50:41 +00:00
<?php
2020-11-06 17:47:42 +00:00
$result=$distinct_operators;
2020-10-27 10:50:41 +00:00
if($result!=false) {
$numrows = $result->num_rows();
if ($numrows > 0) { ?>
2020-11-06 17:47:42 +00:00
<select class="form-control input-lg" name="operator" required id="operator">
2020-10-27 10:50:41 +00:00
<?php foreach ($result->result() as $row) {
2020-11-06 17:47:42 +00:00
echo "<option value='" . $row->id. "'>" . $row->nom." - ".($this->session->userdata('site_lang') === 'french' ? $row->description_fr : $row->description_en). "</option>";
2020-10-27 10:50:41 +00:00
} ?>
</select>
<?php } else {
2020-11-06 17:47:42 +00:00
echo $this->lang->line("no_operator");
2020-10-27 10:50:41 +00:00
}
}else{
2020-11-06 17:47:42 +00:00
echo $this->lang->line("no_operator");
2020-10-27 10:50:41 +00:00
}
?>
</div>
<div class="form-group">
<input type="submit" value="<?php echo $this->lang->line('Ajouter'); ?>" class="btn btn-primary">
2020-10-27 10:50:41 +00:00
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="editModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
2020-11-06 17:47:42 +00:00
<h4 class="modal-title"><?php echo $this->lang->line('modify_operator'); ?></h4>
2020-10-27 10:50:41 +00:00
</div>
<div class="modal-body">
<form id="update-form" method="post" class="bottom-75 center-block">
<div class="form-group">
<label for="modal-pays"><?php echo $this->lang->line('Pays'); ?></label>
<input type="text" class="form-control input-lg" name="pays" required id="modal-pays" readonly="readonly">
</div>
2020-11-06 17:47:42 +00:00
<div class="form-group">
<label for="type">Type</label>
<input type="text" class="form-control input-lg" name="pays" required id="type" readonly="readonly">
</div>
2020-10-27 10:50:41 +00:00
<div class="form-group">
<label for="name"><?php echo $this->lang->line('Nom'); ?></label>
<input type="text" class="form-control input-lg" name="name" required id="name">
</div>
<div class="form-group">
2020-11-06 17:47:42 +00:00
<label for=code">Code</label>
<input type="text" pattern=".{4,}" class="form-control input-lg" name="code" id="code">
</div>
2020-10-27 10:50:41 +00:00
<div class="form-group">
<label for="address"><?php echo $this->lang->line('Adresse'); ?></label>
<input type="text" class="form-control input-lg" name="address" id="address">
2020-10-27 10:50:41 +00:00
</div>
<div class="form-group">
<input type="submit" value="Confirmer" class="btn btn-primary">
<button type="button" class="btn btn-default pull-right" data-dismiss="modal"><?php echo $this->lang->line('Fermer'); ?></button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="addOperatorType">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title"><?php echo $this->lang->line('new_operator_type'); ?></h4>
</div>
<div class="modal-body">
<form id="add-operator-type-form" method="post" class="bottom-75 center-block">
<div class="form-group">
<label>Code</label>
<input type="text" class="form-control input-lg" name="code" required id="code">
</div>
<div class="form-group">
<label>Description</label>
<input type="text" class="form-control input-lg" name="description_fr" required id="description_fr">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary"><?php echo $this->lang->line('Confirmer'); ?></button>
2020-10-27 10:50:41 +00:00
<button type="button" class="btn btn-default pull-right" data-dismiss="modal"><?php echo $this->lang->line('Fermer'); ?></button>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
</div>
<!-- jQuery 3 -->
<script src="<?php echo base_url('bower_components/jquery/dist/jquery.min.js') ?>"></script>
<!-- Bootstrap 3.3.7 -->
<script src="<?php echo base_url('bower_components/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
<!-- DataTables -->
<script src="<?php echo base_url('bower_components/datatables.net/js/jquery.dataTables.min.js') ?>"></script>
<script src="<?php echo base_url('bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js') ?>"></script>
<!-- Slimscroll -->
<script src="<?php echo base_url('bower_components/jquery-slimscroll/jquery.slimscroll.min.js') ?>"></script>
<!-- FastClick -->
<script src="<?php echo base_url('bower_components/fastclick/lib/fastclick.js') ?>"></script>
<!-- AdminLTE App -->
<script src="<?php echo base_url('dist/js/adminlte.min.js') ?>"></script>
<!-- AdminLTE for demo purposes -->
<script src="<?php echo base_url('dist/js/demo.js') ?>"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.js"></script>
<script src="<?php echo base_url('bower_components/toastr/toastr.js') ?>"></script>
<script src="<?php echo base_url('dist/js/sweetalert2.js') ?>"></script>
2020-10-27 10:50:41 +00:00
<script>
toastr.options.closeButton = true;
toastr.options.closeMethod = 'fadeOut';
toastr.options.closeDuration = 5000;
toastr.options.closeEasing = 'swing';
2020-10-27 10:50:41 +00:00
$(document).ready(function() {
var checkboxes = $("td input[type='checkbox']");
checkboxes.click(function() {
if ($("td input:checkbox:checked").length > 0)
{
$("#Bactiver").css("display", "block");
}else{
$("#Bactiver").css("display", "none");
}
});
var Bactiver = $("#Bactiver");
Bactiver.click(function(){
var activation = [];
var desactivation = [];
$.each($("input[name='activer']:checked"), function(){
2020-11-06 17:47:42 +00:00
activation.push({"id_operator" : $(this).data('id-operator'),"id_country": $(this).data('id-country')});
2020-10-27 10:50:41 +00:00
});
$.each($("input[name='desactiver']:checked"), function(){
2020-11-06 17:47:42 +00:00
desactivation.push({"id_operator" : $(this).data('id-operator'),"id_country": $(this).data('id-country')});
2020-10-27 10:50:41 +00:00
});
// console.log('act' , activation)
// console.log('desact' , desactivation)
$.ajax({
url:'<?php echo base_url('Gestion/change_operator_status')?>',
2020-10-27 10:50:41 +00:00
type: 'post',
data: {activations: activation,desactivations:desactivation},
dataType: 'json',
success: function(data){
if(data==='completed'){
Swal.fire({
icon: 'success',
title: "<?php echo $this->lang->line('operators_enabled_disabled')?>",
text: "<?php echo $this->lang->line('informations_updated')?>",
timer: 3000
}).then(()=>{
location.reload();
});
2020-10-27 10:50:41 +00:00
}else{
console.log('Error' , data);
toastr.error("<?php echo $this->lang->line('error_message')?>" , "<?php echo $this->lang->line('request_error')?>");
2020-10-27 10:50:41 +00:00
}
}
});
});
});
</script>
<script>
$(function() {
$('#unvalidated').DataTable();
$('#validated').DataTable();
})
</script>
<script>
$(function() {
$('#pays').multiselect({
includeSelectAllOption: true
});
});
</script>
<script>
2020-11-06 17:47:42 +00:00
var id_operator = null;
2020-10-27 10:50:41 +00:00
var name_network = null;
var id_country = null;
var country = null;
$(document).on("click", ".open-modal", function () {
2020-11-06 17:47:42 +00:00
id_operator = $(this).data('id-operator');
const operator_name = $(this).data('name-operator');
const operator_type = $(this).data('type-operator');
console.log('type',operator_type)
const operator_address = $(this).data('address-operator');
const operator_code = $(this).data('code-operator');
2020-10-27 10:50:41 +00:00
id_country = $(this).data('id-country');
country = $(this).data('country');
$(".modal-body #modal-pays").val(country);
2020-11-06 17:47:42 +00:00
$(".modal-body #type").val(operator_type);
$(".modal-body #name").val( operator_name );
$(".modal-body #address").val( operator_address );
$(".modal-body #code").val( operator_code );
2020-10-27 10:50:41 +00:00
});
2020-11-06 17:47:42 +00:00
$(document).on("click", ".delete-operator", function (event) {
id_operator = $(this).data('id-operator');
2020-10-27 10:50:41 +00:00
id_country = $(this).data('id-country');
$.ajax({
url:'<?php echo base_url('Gestion/delete_operator')?>',
2020-10-27 10:50:41 +00:00
type: 'post',
2020-11-06 17:47:42 +00:00
data: {id_operator: id_operator , id_country : id_country},
2020-10-27 10:50:41 +00:00
dataType: 'json',
success: function(data){
if(data==='completed'){
Swal.fire({
icon: 'success',
title: "<?php echo $this->lang->line('operator_deleted')?>",
text: "<?php echo $this->lang->line('informations_updated')?>",
timer: 3000
}).then(()=>{
location.reload();
});
2020-10-27 10:50:41 +00:00
}else{
console.log("Error",data);
toastr.error("<?php echo $this->lang->line('unexpected_error')?>" , "<?php echo $this->lang->line('request_error')?>");
2020-10-27 10:50:41 +00:00
}
},
error: function (resultat, statut, error) {
console.log(resultat + " " + error);
toastr.error("<?php echo $this->lang->line('error_message')?>" , "<?php echo $this->lang->line('request_error')?>");
2020-10-27 10:50:41 +00:00
}
});
event.preventDefault();
});
$("#assign-form").submit(function(event){
2020-11-06 17:47:42 +00:00
var id_operator = $("#assign-form #operator").val();
2020-10-27 10:50:41 +00:00
var selectedValues = $('#assign-form #pays').val();
$.ajax({
url:'<?php echo base_url('Gestion/assign_operator')?>',
2020-10-27 10:50:41 +00:00
type: 'post',
2020-11-06 17:47:42 +00:00
data: {id_country: selectedValues,id_operator:id_operator},
2020-10-27 10:50:41 +00:00
dataType: 'json',
success: function(data){
if(data==='completed'){
Swal.fire({
icon: 'success',
title: "<?php echo $this->lang->line('operator_assigned')?>",
text: "<?php echo $this->lang->line('informations_updated')?>",
timer: 3000
}).then(()=>{
location.reload();
});
2020-10-27 10:50:41 +00:00
}else if(data==='existe'){
alert('Ce réseau a déjà été assigné à certains des pays sélectionnés');
location.reload();
2020-10-27 10:50:41 +00:00
}else{
console.log("Error",data);
toastr.error("<?php echo $this->lang->line('unexpected_error')?>" , "<?php echo $this->lang->line('request_error')?>");
2020-10-27 10:50:41 +00:00
}
},
error: function (resultat, statut, error) {
console.log(resultat + " " + error);
toastr.error("<?php echo $this->lang->line('error_message')?>" , "<?php echo $this->lang->line('request_error')?>");
2020-10-27 10:50:41 +00:00
}
});
event.preventDefault();
});
2020-11-06 17:47:42 +00:00
$("#add-operator").submit(function(event){
var name = $("#add-operator #name").val();
var type = $("#add-operator #type").val();
2020-10-27 10:50:41 +00:00
$.ajax({
url:'<?php echo base_url('Gestion/add_operator')?>',
2020-10-27 10:50:41 +00:00
type: 'post',
2020-11-06 17:47:42 +00:00
data: {name: name , type :type},
2020-10-27 10:50:41 +00:00
dataType: 'json',
success: function(data){
if(data==='completed'){
Swal.fire({
icon: 'success',
title: "<?php echo $this->lang->line('operator_added')?>",
text: "<?php echo $this->lang->line('informations_updated')?>",
timer: 3000
}).then(()=>{
location.reload();
});
2020-10-27 10:50:41 +00:00
}else{
console.log("Error",data);
toastr.error("<?php echo $this->lang->line('unexpected_error')?>" , "<?php echo $this->lang->line('request_error')?>");
2020-10-27 10:50:41 +00:00
}
},
error: function (resultat, statut, error) {
console.log(resultat + " " + error);
toastr.error("<?php echo $this->lang->line('error_message')?>" , "<?php echo $this->lang->line('request_error')?>");
2020-10-27 10:50:41 +00:00
}
});
event.preventDefault();
});
$("#update-form").submit(function(event){
const name = $("#update-form #name").val();
const address = $("#update-form #address").val();
const code = $("#update-form #code").val();
2020-10-27 10:50:41 +00:00
$.ajax({
url:'<?php echo base_url('Gestion/update_operator')?>',
2020-10-27 10:50:41 +00:00
type: 'post',
2020-11-06 17:47:42 +00:00
data: {id_operator: id_operator ,name:name , address :address , id_country : id_country , code : code},
2020-10-27 10:50:41 +00:00
dataType: 'json',
success: function(data){
if(data==='completed'){
Swal.fire({
icon: 'success',
title: "<?php echo $this->lang->line('operator_modified')?>",
text: "<?php echo $this->lang->line('informations_updated')?>",
timer: 3000
}).then(()=>{
location.reload();
});
2020-10-27 10:50:41 +00:00
}else{
console.log("Error",data);
toastr.error("<?php echo $this->lang->line('unexpected_error')?>" , "<?php echo $this->lang->line('request_error')?>");
2020-10-27 10:50:41 +00:00
}
},
error: function (resultat, statut, error) {
console.log(resultat + " " + error);
toastr.error("<?php echo $this->lang->line('error_message')?>" , "<?php echo $this->lang->line('request_error')?>");
2020-10-27 10:50:41 +00:00
}
});
event.preventDefault();
});
$("#add-operator-type-form").submit(function(event){
var code = $("#add-operator-type-form #code").val();
// var description_en = $("#add-operator-type-form #description_en").val();
var description_fr = $("#add-operator-type-form #description_fr").val();
$.ajax({
url:'<?php echo base_url('Gestion/add_operator_type')?>',
type: 'post',
data: {code: code , description_fr :description_fr},
dataType: 'json',
success: function(data){
if(data===200){
Swal.fire({
icon: 'success',
title: "<?php echo $this->lang->line('new_operator_added')?>",
text: "<?php echo $this->lang->line('informations_updated')?>",
timer: 3000
}).then(()=>{
location.reload();
});
}else if(data === 422){
toastr.error("<?php echo $this->lang->line('operator_type_code_exists')?>" , "<?php echo $this->lang->line('request_error')?>");
}else if(data === 500){
toastr.error("<?php echo $this->lang->line('unexpected_error')?>" , "<?php echo $this->lang->line('request_error')?>");
}
},
error: function (resultat, statut, error) {
console.log(resultat + " " + error);
toastr.error("<?php echo $this->lang->line('error_message')?>" , "<?php echo $this->lang->line('request_error')?>");
}
});
event.preventDefault();
});
2020-10-27 10:50:41 +00:00
</script>