449 lines
17 KiB
PHP
449 lines
17 KiB
PHP
<?php
|
|
|
|
use Glpi\Event;
|
|
|
|
include ('../inc/includes.php');
|
|
include ('../front/publications_fonctions.php');
|
|
|
|
Session::checkLoginUser();
|
|
|
|
//Display All PHP Errors false
|
|
ini_set('display_errors', 0);
|
|
|
|
if (Session::getCurrentInterface() == "helpdesk") {
|
|
Html::helpHeader("Publication", '', $_SESSION["glpiname"]);
|
|
} else {
|
|
Html::header("Publication", '', "", "");
|
|
}
|
|
|
|
echo'<link rel="stylesheet" href="'.$CFG_GLPI["root_doc"].'/css/swiper-bundle.min.css">
|
|
<link rel="stylesheet" href="'.$CFG_GLPI["root_doc"].'/css/publication.css">
|
|
<script src="'.$CFG_GLPI["root_doc"].'/js/facebook-reactions.js"></script>';
|
|
|
|
|
|
$TotalPublications = getTotalPublications();
|
|
|
|
//Security - Get Variables
|
|
if(isset($_GET['next']) ){
|
|
if($_GET['next'] == -0) $_GET['next'] = 0;
|
|
if( filter_var($_GET['next'], FILTER_VALIDATE_INT)=== 0 || !filter_var($_GET['next'], FILTER_VALIDATE_INT)=== FALSE){
|
|
if( $_GET['next'] < 0) $_GET['next'] = 0;
|
|
if( $_GET['next'] >= $TotalPublications ) $_GET['next'] = 0;
|
|
}else{
|
|
$_GET['next'] = 0;
|
|
}
|
|
}else{
|
|
$_GET['next'] = 0;
|
|
}
|
|
|
|
$Publication = getAllPublications();
|
|
|
|
|
|
|
|
if( CanAddPublication() == true){
|
|
echo'<div class="grid-container" id="creepublication">
|
|
<span style=" font-size: 1rem; color: #606770;font-weight: 600;display: block;text-align: center;">Créer une publication</span>
|
|
</div>
|
|
<form class="form" method="post" action="'.$CFG_GLPI["root_doc"].'/ajax/publication.php" enctype="multipart/form-data">
|
|
<div class="grid-container" id="publicationAdd" style="display:none;">
|
|
<div class="flex-container">
|
|
<input type="hidden" name="function" value="publication">
|
|
<input type="hidden" name="action" value="add">
|
|
<textarea id="titre" name="titre" style="background-color: #ffffff; " placeholder="Que voulez-vous dire"></textarea>
|
|
</div>
|
|
<div>
|
|
<div class="fileupload draghoverable">
|
|
<div id="fileupload_info_ticket" class="fileupload_info"></div>
|
|
<div id="dropdoc">
|
|
<span class="b">déposez votre fichier ici, ou</span><br>
|
|
<input id="fileToUpload" type="file" name="files[]" multiple="multiple" accept=".jpg, .jpeg, .png">
|
|
</div>
|
|
<button name="submit" onclick="submitForm()" class="BUTTON_BDX" style="width: 200px;">Publier</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
';
|
|
}
|
|
|
|
|
|
|
|
for($i=0 ; $i < count($Publication) ;$i++){
|
|
$User = getUser($Publication[$i]['id_user']);
|
|
$isJaime = isJaime($Publication[$i]['id_publication'] ,$_SESSION["glpiID"]);
|
|
$class = $isJaime == false ? '' : $isJaime;
|
|
|
|
echo'
|
|
<div class="grid-container">
|
|
|
|
<div class="header">
|
|
<div class="flex-container">
|
|
<div style="width: 40px"><img src="'.$CFG_GLPI["root_doc"].'/file_upload/paris.png" style="border-radius: 50%;" width="40" height="40"></div>
|
|
<div style="width: 100%;"><div style ="text-align: left;"><a class="link" href="">Communication INTERNE</a> <br> <span style="color: #616770;font-size: 11px;">'.$Publication[$i]['date'].'</span></div></div>';
|
|
if($Publication[$i]['id_user'] == $_SESSION["glpiID"])
|
|
echo'<div style="width: 20px"><a href="'.$CFG_GLPI["root_doc"].'/front/publications.edit.php?id='.$Publication[$i]['id_publication'].'"><i class="fa fa-edit" style="cursor: pointer; text-decoration: none; color:#999;" title="Edit"></i></a></div>';
|
|
|
|
echo'
|
|
</div>
|
|
</div>';
|
|
|
|
$is_arabic = preg_match('/\p{Arabic}/u', nl2br($Publication[$i]['titre']));
|
|
if($is_arabic == true ){
|
|
echo'<div class="Stitre" style="direction: rtl;">'.nl2br($Publication[$i]['titre']).'</div>';
|
|
}else{
|
|
echo'<div class="Stitre">'.nl2br($Publication[$i]['titre']).'</div>';
|
|
}
|
|
|
|
|
|
|
|
|
|
//files
|
|
$file = getPublicationsFiles($Publication[$i]['id_publication']);
|
|
if(count($file) == 1){
|
|
if($file[0]['type'] == "image"){
|
|
echo'
|
|
<div class="picteurs"><img src="'.$CFG_GLPI["root_doc"]."/file_upload/".$file[0]['lien'].'" style="width:100%; height: auto;"></div>';
|
|
}elseif($file[0]['type'] == "video"){
|
|
}
|
|
}elseif(count($file) > 1){
|
|
echo'
|
|
<div class="picteurs">
|
|
|
|
<div class="swiper-container mySwiper">
|
|
<div class="swiper-wrapper">';
|
|
for($y=0 ; $y < count($file) ;$y++){
|
|
echo'<div class="swiper-slide"><img src="'.$CFG_GLPI["root_doc"]."/file_upload/".$file[$y]['lien'].'" style="width:100%; height: auto;"></div>';
|
|
}
|
|
echo'
|
|
</div>
|
|
<!-- Add Arrows -->
|
|
<div class="swiper-button-next"></div>
|
|
<div class="swiper-button-prev"></div>
|
|
</div></div>';
|
|
}
|
|
|
|
|
|
echo'
|
|
<div>
|
|
<div class="flex-container">
|
|
<div style="display: inline-flex;">';
|
|
$totalEmoj =getTopEmoj($Publication[$i]['id_publication']);
|
|
$emojs = count($totalEmoj);
|
|
if($emojs != 0){
|
|
for($pp=0;$pp < $emojs ; $pp++){
|
|
echo'<img src="../file_upload/emojis/'.$totalEmoj[$pp]['reaction'].'.svg" style="" width="18" />';
|
|
}
|
|
}else{
|
|
echo'<img src="../file_upload/emojis/jaime.svg" style="" width="18" />';
|
|
}
|
|
echo '</div>
|
|
<div style="color: inherit; color: #606770; line-height: 20px;" id="jaimeTotal'.$Publication[$i]['id_publication'].'"><a href="'.$CFG_GLPI["root_doc"].'/front/publications.reactions.php?id='.$Publication[$i]['id_publication'].'">'.getTotal($Publication[$i]['id_publication'],"jaime").'</a></div>
|
|
<div style="width: 100%;text-align: right;"><span style="color: inherit; color: #606770; line-height: 20px;">'.getTotal($Publication[$i]['id_publication'],"comment").' commentaires</span></div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<hr class="ligneA">
|
|
<div class="item5">
|
|
<div class="flex-container">
|
|
<div class="button "style="width:50%;text-align: center; position:relative;" >
|
|
<a class="FB_reactions" data-reactions-type="horizontal" data-unique-id="'.$Publication[$i]['id_publication'].'" data-emoji-class="'.$class.'">';
|
|
if($class == ""){
|
|
echo'<span>J'aime</span>';
|
|
}else{
|
|
if($class == "Jadore") $class="J'adore";
|
|
if($class == "jaime") $class="J'aime";
|
|
echo'<span>'.$class.'</span>';
|
|
}
|
|
echo' </a>
|
|
</div>
|
|
<div class="button" style="width:50%;text-align: center;">
|
|
<div class="Buttoncomment">
|
|
<i class="far fa-comment fa-3" style="margin-right:7px;"></i>
|
|
<span>Commenter</span></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<hr class="ligneA">';
|
|
|
|
//all Commentaires
|
|
$Commentaires = getCommentaires($Publication[$i]['id_publication']);
|
|
echo'<div class="SallCommentaires" id="allCommentaires'.$Publication[$i]['id_publication'].'" style="padding:10px 15px 0px 15px;">';
|
|
//if(count($Commentaires) != 0)
|
|
//echo'<span class="text" style="margin: 8px 0px 8px 5px; display: block; cursor: pointer;">Afficher autres commentaires</span>';
|
|
for($x=0 ; $x < count($Commentaires) ;$x++){
|
|
$User = getUser($Commentaires[$x]['id_user']);
|
|
echo'
|
|
<div id="deleteCommentaire'.$Commentaires[$x]['id'].'">
|
|
<div class="flex-container">
|
|
<div class="picteurComment" id="aa">
|
|
<img src="'.$CFG_GLPI["root_doc"].'/file_upload/avatar.png" style="border-radius: 50%;" width="40" height="40">
|
|
</div>
|
|
<div class="comment" style="max-width: calc(100% - 65px);">
|
|
<div class="textarea-replace1">
|
|
<span style="color:#3A5693;font-weight: 600;">'.$User['nom']." ".$User['prenom'].'</span>
|
|
<div id="idCommentaire'.$Commentaires[$x]['id'].'" class="textarea-replace">'.$Commentaires[$x]['commentaire'].'</div>
|
|
</div>
|
|
</div>
|
|
<div style="width:25px;">
|
|
<div id="buttonSend'.$Commentaires[$x]['id'].'" style="visibility: hidden ;">
|
|
<img src="'.$CFG_GLPI["root_doc"].'/file_upload/send.png" onclick="commentaireUpdate('.$Commentaires[$x]['id'].')" width="20" height="20">
|
|
</div>
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
if($Commentaires[$x]['id_user'] == $_SESSION["glpiID"]){
|
|
echo'<div style="padding-left: 50px;">
|
|
<span onclick="modifier('.$Commentaires[$x]['id'].')" style="margin-left: 10px;font-weight: bold;color:#65676b;cursor: pointer;display: none;">Modifier .</span>
|
|
<span onclick="commentaireDelete('.$Commentaires[$x]['id'].')" style="font-weight: bold;color:#65676b;cursor: pointer;display: none;">Supprimer</span>
|
|
</div>';
|
|
}
|
|
echo'</div>' ;
|
|
}
|
|
echo'</div>';
|
|
|
|
echo'
|
|
<div class="nouveauCommentaire"style="padding:10px 15px 0px 15px;">
|
|
<div>
|
|
<div class="flex-container">
|
|
<div id="aa"><img src="'.$CFG_GLPI["root_doc"].'/file_upload/avatar.png" style="border-radius: 50%;" width="40" height="40"></div>
|
|
<div style="width:100%;max-width: calc(100% - 65px);">
|
|
<div class="textarea-replace1">
|
|
<div class="textarea-replace" id="commentaire'.$Publication[$i]['id_publication'].'" contenteditable="" placeholder="Ecrivez un commentaire..."></div>
|
|
</div>
|
|
</div>
|
|
<div style="width:25px;"><img src="'.$CFG_GLPI["root_doc"].'/file_upload/send.png" onclick="commentaireAdd('.$Publication[$i]['id_publication'].')" width="20" height="20"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>';
|
|
}
|
|
|
|
//pagination
|
|
echo"<div class='center'>
|
|
<div class='pagination'>";
|
|
if( $_GET["next"] == 0){
|
|
echo"<a href='".$CFG_GLPI["root_doc"]."/front/publications.php?next=6' class='active'>»</a>";
|
|
}else{
|
|
|
|
if( ($_GET["next"]+6) < $TotalPublications){
|
|
echo"<a href='".$CFG_GLPI["root_doc"]."/front/publications.php?next=".($_GET["next"]-6)."'>«</a>";
|
|
echo"<a href='".$CFG_GLPI["root_doc"]."/front/publications.php?next=".($_GET["next"]+6)."' class='active'>»</a>";
|
|
}else{
|
|
echo"<a href='".$CFG_GLPI["root_doc"]."/front/publications.php?next=".($_GET["next"]-6)."' class='active'>«</a>";
|
|
}
|
|
}
|
|
echo"</div>
|
|
</div>";
|
|
|
|
|
|
echo"<script src='".$CFG_GLPI["root_doc"]."/js/swiper-bundle.min.js'></script>";
|
|
$root = $CFG_GLPI["root_doc"];
|
|
$fullname = $_SESSION["glpifriendlyname"];
|
|
|
|
if (Session::getCurrentInterface() == "helpdesk") {
|
|
Html::helpFooter();
|
|
} else {
|
|
Html::footer();
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
<!-- Initialize Swiper -->
|
|
<script>
|
|
|
|
var root = <?php echo json_encode($root); ?>;
|
|
var fullname =<?php echo json_encode($fullname); ?>;
|
|
|
|
//silder
|
|
var swiper = new Swiper('.swiper-container', {
|
|
autoHeight: true, //enable auto height
|
|
spaceBetween: 20,
|
|
pagination: {
|
|
el: '.swiper-pagination',
|
|
clickable: true,
|
|
},
|
|
navigation: {
|
|
nextEl: '.swiper-button-next',
|
|
prevEl: '.swiper-button-prev',
|
|
},
|
|
});
|
|
|
|
|
|
|
|
function commentaireAdd(idPublication) {
|
|
|
|
var commentaire = $('#commentaire'+idPublication).text();
|
|
//commentaire = commentaire.replace(/\r?\n/g, '<br />');
|
|
|
|
if( commentaire != ''){
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: root+"/ajax/publication.php",
|
|
data: {"id_publication":idPublication,"commentaire" : commentaire,"function" : 'commentaire' , "action" : 'add'},
|
|
success: function (data) {
|
|
data = JSON.parse(data);
|
|
$("#allCommentaires"+idPublication).append(
|
|
'<div id="deleteCommentaire'+data.id+'">'+
|
|
'<div class="flex-container">'+
|
|
'<div class="picteurComment" id="aa"><img src="'+root+'/file_upload/avatar.png" style="border-radius: 50%;" width="40" height="40"></div>'+
|
|
' <div class="comment" style="width: 100%;max-width: calc(100% - 65px);">'+
|
|
'<div class="textarea-replace1"><span style="color:#3A5693;font-weight: 600;">'+fullname+'</span><div id="idCommentaire'+data.id+'" class="textarea-replace">'+data.commentaire+'</div></div>'+
|
|
'</div>'+
|
|
'<div style="width:25px;">'+
|
|
'<div id="buttonSend'+data.id+'" style="visibility: hidden ;">'+
|
|
'<img src="'+root+'/file_upload/send.png" onclick="commentaireUpdate('+data.id+')" width="20" height="20">'+
|
|
' </div>'+
|
|
'</div>'+
|
|
'</div>'+
|
|
|
|
|
|
|
|
'<div style="padding-left: 50px;">'+
|
|
'<span onclick="modifier('+data.id+')" style="margin-left: 10px;font-weight: bold;color:#65676b;cursor: pointer;">Modifier .</span>'+
|
|
'<span onclick="commentaireDelete('+data.id+');" style="font-weight: bold;color:#65676b;cursor: pointer;" > Supprimer</span>' +
|
|
'</div>'+
|
|
'</div>'+
|
|
|
|
'</div>').hide().show('slow');
|
|
$('#commentaire'+idPublication).text("");
|
|
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
function commentaireUpdate(idCommentaire) {
|
|
|
|
var commentaire = $('#idCommentaire'+idCommentaire).text();
|
|
if( commentaire != ''){
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
url: root+"/ajax/publication.php",
|
|
data: {"idCommentaire":idCommentaire,"commentaire" : commentaire,"function" : 'commentaire' , "action" : 'update'},
|
|
success: function (data) {
|
|
$('#idCommentaire'+idCommentaire).hide().show('slow');
|
|
$('#idCommentaire'+idCommentaire).text(commentaire);
|
|
$('#buttonSend'+idCommentaire).css("visibility" , "hidden");
|
|
$('#idCommentaire'+idCommentaire).attr("contenteditable",false);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
function commentaireDelete(idCommentaire) {
|
|
|
|
var t = confirm("Etes-vous sûr de vouloir supprimer cette Commentaire ?");
|
|
if (t == true) {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: root+"/ajax/publication.php",
|
|
data: {"idCommentaire":idCommentaire,"function" : 'commentaire' , "action" : 'delete'},
|
|
success: function (data) {
|
|
$('#deleteCommentaire'+idCommentaire).remove().hide().show('slow');
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function modifier(idCommentaire) {
|
|
|
|
$('#buttonSend'+idCommentaire).css("visibility","visible");
|
|
$('#idCommentaire'+idCommentaire).attr("contenteditable",true);
|
|
$('#idCommentaire'+idCommentaire).focus();
|
|
};
|
|
|
|
|
|
|
|
//contenteditable
|
|
$(document).ready(function() {
|
|
var t = $('.textarea-replace'), // register placeholder
|
|
p = t.attr('placeholder'); // get placeholder value
|
|
|
|
/* when focus is set to the element - placeholder disappears */
|
|
t.on('focus', function() {
|
|
$(this).attr('placeholder', '')
|
|
}),
|
|
/* when element loses focus if there is no text - set placeholder again */
|
|
t.on('focusout', function() {
|
|
$(this).text().trim().length || $(this).attr('placeholder', p)
|
|
})
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$( "#creepublication" ).click(function() {
|
|
$("#publicationAdd").slideToggle( "slow" );
|
|
$("#titre").focus();
|
|
});
|
|
|
|
|
|
|
|
//textarea detect language
|
|
function checkRTL(s){
|
|
var ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF'+'\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF',
|
|
rtlChars = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC',
|
|
rtlDirCheck = new RegExp('^[^'+ltrChars+']*['+rtlChars+']');
|
|
|
|
return rtlDirCheck.test(s);
|
|
};
|
|
|
|
var input = $('#titre').on('keypress', keypress)[0];
|
|
|
|
function keypress(e){
|
|
|
|
setTimeout(function(){
|
|
var text = $('#titre').val().split(/\s/).join('');
|
|
if( text.length == 1 ){
|
|
var isRTL = checkRTL( String.fromCharCode(e.charCode) );
|
|
var dir = isRTL ? 'RTL' : 'LTR';
|
|
$('#titre').css('direction', dir);
|
|
}
|
|
},100);
|
|
}
|
|
//textarea detect language
|
|
|
|
|
|
function submitForm() {
|
|
$('.form').on('submit', function(e){
|
|
jQuery("button[name='submit']").attr("disabled","disabled");
|
|
$( ".form" ).submit()
|
|
});
|
|
};
|
|
|
|
$("#fileToUpload").on("change", function(e) {
|
|
var files = e.target.files,
|
|
filesLength = files.length;
|
|
$('#fileupload_info_ticket').empty();
|
|
|
|
for(var up=0 ; up < filesLength ; up++){
|
|
if(files[up].type == "image/jpeg" || files[up].type == "image/jpg" || files[up].type == "image/png" )
|
|
$('#fileupload_info_ticket').append('<p id=""><img src="'+root+'/pics/icones/jpg-dist.png" title="jpg"> <b>'+files[up].name+'</b> </p>');
|
|
}
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
$('.FB_reactions').facebookReactions({
|
|
postUrl: root+"/ajax/publication.php",
|
|
});
|
|
});
|
|
|
|
</script>
|