352 lines
11 KiB
PHP
352 lines
11 KiB
PHP
<?php
|
|
|
|
use Glpi\Event;
|
|
include ('../model_controller/fiche.config.evaluation.php');
|
|
|
|
Session::checkLoginUser();
|
|
if (Session::getCurrentInterface() == "helpdesk") {
|
|
Html::helpHeader("DRH", '', $_SESSION["glpiname"]);
|
|
} else {
|
|
Html::header("DRH", '', "", "");
|
|
}
|
|
|
|
if(isset($_GET['fiche'])) {
|
|
$ficheEvaluation = getFicheEvaluation($_GET['fiche']);
|
|
$lignesFicheEvaluation = getLignesFicheEvaluation($_GET['fiche']);
|
|
}
|
|
|
|
if(isset($_POST['save'])) {
|
|
|
|
$delayedlignesFicheEvaluation = [];
|
|
|
|
if(isset($_GET['fiche'])) {
|
|
$last_id = $_GET['fiche'];
|
|
updateFicheEvaluation($last_id, $_POST['NomFormulaire'], $_POST['active']);
|
|
if(sizeof($lignesFicheEvaluation) > 0){
|
|
$inc=1;
|
|
foreach ($lignesFicheEvaluation as $row) {
|
|
$question = $_POST["question".$inc];
|
|
$reponse = $_POST["reponse".$inc];
|
|
$block = $_POST["block".$inc];
|
|
$order = $_POST["ordre".$inc];
|
|
$comment = $_POST["comment".$inc];
|
|
$imgurl = $row['img_url'];
|
|
if($_FILES["inputimg".$inc]['name'] != '')
|
|
$imgurl = "../fiche_eval_upload/".$_FILES["inputimg".$inc]['name'];
|
|
|
|
if (strpos($block, 'temp') !== false) {
|
|
$delayedlignesFicheEvaluation[] = ['update', $row['id_ligne_fiche_evaluation'], $question, $reponse, $block, $order, $comment, $imgurl];
|
|
} else
|
|
updateLigneFicheEvaluation($row['id_ligne_fiche_evaluation'], $question, $reponse, $block, $order, $comment, $imgurl);
|
|
|
|
$inc=$inc+1;
|
|
}
|
|
}
|
|
|
|
} else {
|
|
$last_id = insertFicheEvaluation($_POST['NomFormulaire'], $_POST['active']);
|
|
}
|
|
|
|
$incligneid = [];
|
|
for ($y = 0; $y < sizeof($_POST['InsertFormulaire']); $y++) {
|
|
|
|
$inc = $_POST['InsertFormulaire'][$y];
|
|
|
|
$question = $_POST["question".$inc];
|
|
$reponse = $_POST["reponse".$inc];
|
|
$block = $_POST["block".$inc];
|
|
$order = $_POST["ordre".$inc];
|
|
$comment = $_POST["comment".$inc];
|
|
$imgurl = "";
|
|
if($_FILES["inputimg".$inc]['name'] != '')
|
|
$imgurl = "../fiche_eval_upload/".$_FILES["inputimg".$inc]['name'];
|
|
|
|
if (strpos($block, 'temp') !== false) {
|
|
$ligneidinc = -1;
|
|
$astring = explode('temp', $block)[1];
|
|
foreach ($incligneid as $row) {
|
|
if($row[0] == $astring)
|
|
$ligneidinc = $row[1];
|
|
}
|
|
if($ligneidinc == -1)
|
|
$delayedlignesFicheEvaluation[] = ['insert', $last_id, $question, $reponse, $block, $order, $comment, $imgurl];
|
|
else {
|
|
$block = $ligneidinc;
|
|
$last_ligne_id = insertLigneFicheEvaluation($last_id, $question, $reponse, $block, $order, $comment, $imgurl);
|
|
$incligneid[] = [$inc, $last_ligne_id];
|
|
}
|
|
} else {
|
|
$last_ligne_id = insertLigneFicheEvaluation($last_id, $question, $reponse, $block, $order, $comment, $imgurl);
|
|
$incligneid[] = [$inc, $last_ligne_id];
|
|
$newdelayedarray = [];
|
|
foreach ($delayedlignesFicheEvaluation as $row) {
|
|
|
|
if($row[4] == 'temp'.$inc) {
|
|
$newrow = [$row[0], $row[1], $row[2], $row[3], $last_ligne_id, $row[5], $row[6], $row[7]];
|
|
$newdelayedarray[] = $newrow;
|
|
}else
|
|
$newdelayedarray[] = $row;
|
|
}
|
|
$delayedlignesFicheEvaluation = $newdelayedarray;
|
|
}
|
|
}
|
|
|
|
foreach ($delayedlignesFicheEvaluation as $row) {
|
|
if($row[0] == 'update')
|
|
updateLigneFicheEvaluation($row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7]);
|
|
else
|
|
insertLigneFicheEvaluation($row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7]);
|
|
}
|
|
|
|
|
|
Html::redirect("fiche.config.evaluation.list.php");
|
|
}
|
|
|
|
|
|
$blocks = [];
|
|
foreach ($lignesFicheEvaluation as $row) {
|
|
if($row['id_parent'] == 0)
|
|
$blocks[] = [$row['id_ligne_fiche_evaluation'], $row['question']];
|
|
}
|
|
|
|
function getBlock($blockid) {
|
|
global $lignesFicheEvaluation;
|
|
foreach ($lignesFicheEvaluation as $row) {
|
|
if($row['id_ligne_fiche_evaluation'] == $blockid)
|
|
return $row['question'];
|
|
}
|
|
}
|
|
|
|
|
|
echo '<div>
|
|
<form method="post" enctype="multipart/form-data" accept-charset = "character_set">
|
|
<input type="hidden" id="_glpi_csrf_token" name="_glpi_csrf_token" value="'.Session::getNewCSRFToken().'">';
|
|
|
|
|
|
$NomFormulaire = "";
|
|
$active = "checked";
|
|
if(isset($ficheEvaluation)) {
|
|
$NomFormulaire = str_replace('\'','"',$ficheEvaluation["nom_fiche_evaluation"]);
|
|
if($ficheEvaluation["actif"] != 1)
|
|
$active = "";
|
|
}
|
|
|
|
echo "<div class='center'>
|
|
<h4 class='fieldBlockHeader'>Details Questionnaire</h4>
|
|
<table border='0' class='tab_cadrehov js-dynamitable'>
|
|
<thead>
|
|
<tr class='tab_bg_2'>
|
|
<td class='fieldLabel alignMiddle'>Nom Fiche d'Evaluation</td>
|
|
<td class='fieldValue'><input type='text' style='width:250px;' class='inputElement' name='NomFormulaire' value='".$NomFormulaire."' autocomplete='off' required=''></td>
|
|
</tr>
|
|
<tr class='tab_bg_2'>
|
|
<td class='fieldValue'><label for='active'>Active </label><input type='checkbox' id='active' name='active' ".$active."></td>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class='center'>
|
|
<h4 class='fieldBlockHeader'>Lignes Questionnaire</h4>
|
|
<button name='add' type='button' class='vsubmit add-row'><i class='fas fa-plus'></i> Ajouter</button>
|
|
|
|
<table border='0' class='tab_cadrehov js-dynamitable' id='dynamique'>
|
|
<thead>
|
|
<tr class='tab_bg_2'>
|
|
<th >Question</th>
|
|
<th >Reponses</th>
|
|
<th >Block</th>
|
|
<th >Ordre</th>
|
|
<th >Commentaire</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>";
|
|
$inc=1;
|
|
if(isset($lignesFicheEvaluation)){
|
|
if(sizeof($lignesFicheEvaluation) > 0){
|
|
foreach ($lignesFicheEvaluation as $row) {
|
|
result($row, $inc);
|
|
$inc=$inc+1;
|
|
}
|
|
}
|
|
}
|
|
echo' </tbody>
|
|
</table>
|
|
</div>';
|
|
|
|
|
|
echo'<div class="center"><br><br>
|
|
<button class="vsubmit" type="submit" name="save" value="save">Save</button>
|
|
<a class="cancelLink" href="javascript:history.back()" type="reset">Annuler</a>
|
|
</div>';
|
|
|
|
echo'</form></div>';
|
|
Html::footer();
|
|
|
|
|
|
|
|
|
|
function result($row_data, $inc){
|
|
|
|
global $blocks;
|
|
$block = $row_data['id_parent'];
|
|
$blockdata = getBlock($block);
|
|
|
|
$mycomment="";
|
|
if($row_data['comment'] == 1)
|
|
$mycomment="checked";
|
|
|
|
echo " <tr style='height:70px;'>
|
|
<td><textarea style='height:50px;' id='".$row_data['id_ligne_fiche_evaluation']."' name='question".$inc."' class='qty smallInputBox inputElement'>".$row_data['question']."</textarea>
|
|
<label for='inputimg".$inc."'><i class='fa fa-upload' aria-hidden='true'></i></label><input type='file' id='inputimg".$inc."' name='inputimg".$inc."' hidden onchange='upload_image(this);' accept='image/png, image/gif, image/jpeg, image/jpg'>
|
|
</td>
|
|
<td><textarea style='height:50px;' name='reponse".$inc."' class='qty smallInputBox inputElement'>".$row_data['reponses']."</textarea></td>
|
|
<td>
|
|
<select class='js-example-basic-single form-control' style='width:160px;height:25px;' onChange='changeselect(this);' onclick='selectpopulate(this);' name='block".$inc."'>
|
|
<option value='0'"; if($block == 0) echo "selected"; echo "></option>";
|
|
foreach ($blocks as $row) {
|
|
if($blockdata == $row[1])
|
|
echo "<option value='".$row[0]."' selected>".$row[1]."</option>";
|
|
else {
|
|
if($row[1] != $row_data['question'])
|
|
echo "<option value='".$row[0]."'>".$row[1]."</option>";
|
|
}
|
|
}
|
|
echo "</select></td>
|
|
<td><input type='number' value='".$row_data['ordre']."' name='ordre".$inc."' ";
|
|
if($block != 0) echo "hidden";
|
|
echo "></td>
|
|
<td><input type='checkbox' ".$mycomment." name='comment".$inc."'></td>
|
|
</tr>";
|
|
}
|
|
|
|
?>
|
|
|
|
<script>
|
|
$(document).ready(function(){
|
|
|
|
$("#c_ssmenu2").html('<ul>'+
|
|
'<li class="breadcrumb_item"><a href="central.php" title="Accueil">Accueil</a></li>'+
|
|
'<li class="breadcrumb_item"><a href="" title="">Ressources Humaines</a></li>'+
|
|
'<li class="breadcrumb_item"><a href="fiche.config.evaluation.list.php" class="here" title="Configuration des evaluations"><i class="far fa-sticky-note"></i> Configuration des evaluations</a></li>'+
|
|
'</ul>');
|
|
});
|
|
|
|
|
|
function changeselect(selectobject) {
|
|
|
|
var tr = selectobject.closest('td').closest('tr');
|
|
var order;
|
|
$(tr).find('td').each(function(cellIndex, td) {
|
|
if($(td).find('input[type="number"]').length)
|
|
order = $(td).find('input[type="number"]');
|
|
});
|
|
if(selectobject.value != '0') {
|
|
|
|
order.css("display", "none");
|
|
} else {
|
|
order.css("display", "");
|
|
}
|
|
}
|
|
|
|
function selectpopulate(selectobject) {
|
|
|
|
$('#dynamique tr').each(function(){
|
|
var firsttd = $(this).find("td:first");
|
|
var txtarea = firsttd.find("textarea");
|
|
var question = txtarea.val();
|
|
var select;
|
|
$(this).find('td').each(function(cellIndex, td) {
|
|
if($(td).find('select').length)
|
|
select = $(td).find('select');
|
|
});
|
|
|
|
var tempid;
|
|
$(firsttd).find('input').each(function() {
|
|
if($(this).val() != '') {
|
|
tempid = $(this).val();
|
|
}
|
|
});
|
|
//var tempid = firsttd.find("input").val();
|
|
if(typeof(select) !== 'undefined' && select.val() == '0') {
|
|
|
|
var isexiste = 0;
|
|
for (var i=0; i<selectobject.length; i++) {
|
|
if (selectobject.options[i].text.trim() == question.trim())
|
|
isexiste = 1;
|
|
}
|
|
|
|
var tr = selectobject.closest('td').closest('tr');
|
|
if(tr.firstElementChild.firstElementChild.value == question)
|
|
isexiste = 1;
|
|
|
|
if(isexiste == 0) {
|
|
|
|
var opt = document.createElement('option');
|
|
if(typeof(tempid) !== 'undefined') {
|
|
opt.value = 'temp'+tempid;
|
|
} else {
|
|
opt.value = txtarea.attr('id');
|
|
}
|
|
opt.innerHTML = question;
|
|
selectobject.appendChild(opt);
|
|
}
|
|
} else {
|
|
for (var i=0; i<selectobject.length; i++) {
|
|
if (selectobject.options[i].text == question)
|
|
selectobject.remove(i);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function upload_image(input) {
|
|
|
|
if (input.files && input.files[0]) {
|
|
|
|
var fd = new FormData();
|
|
fd.append('file',input.files[0]);
|
|
|
|
$.ajax({
|
|
url: 'fiche.config.evaluation.upload.php',
|
|
type: 'post',
|
|
data: fd,
|
|
async: true,
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
timeout: 60000,
|
|
success: function(response){
|
|
if(response != 0){
|
|
// $("#img").attr("src",response);
|
|
//$(".preview img").show(); // Display image element
|
|
}else{
|
|
alert('file not uploaded');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
var inc = <?php echo $inc; ?>;
|
|
$(".add-row").click(function(){
|
|
|
|
var markup = "<tr style='height:50px;'>"
|
|
+"<td> <input type='hidden' id='InsertFormulaire' name='InsertFormulaire[]' value='"+inc+"'><textarea style='height:50px;' name='question"+inc+"' class='qty smallInputBox inputElement'></textarea>"
|
|
+"<label for='inputimg"+inc+"'><i class='fa fa-upload' aria-hidden='true'></i></label><input type='file' id='inputimg"+inc+"' name='inputimg"+inc+"' hidden onchange='upload_image(this);' accept='image/png, image/gif, image/jpeg, image/jpg'>"
|
|
+"</td>"
|
|
+"<td><textarea style='height:50px;' name='reponse"+inc+"' class='qty smallInputBox inputElement'></textarea></td>"
|
|
+"<td><select class='js-example-basic-single form-control' style='width:160px;height:25px;' onChange='changeselect(this);' onclick='selectpopulate(this);' name='block"+inc+"'><option value='0' selected></option></select></td>"
|
|
+"<td><input type='number' name='ordre"+inc+"'></td>"
|
|
+"<td><input type='checkbox' name='comment"+inc+"'></td>"
|
|
+"</tr>";
|
|
|
|
inc=inc+1;
|
|
$("#dynamique").append(markup);
|
|
});
|
|
|
|
</script>
|