hellofacteurV1/vues/admin_posts_maj.php

402 lines
11 KiB
PHP
Executable File

<?php
/**
* Vue affichant les formulaires permettant de gérer les posts
* Affichage pour mise à jour / validation ou encore suppression.
* + scripts ajax testant la saisie
*
**/
$header_title="Les posts >> ".SITE_NOM;
$body_title="Gestion des posts.";
$ariane_items[0]["txt"]="<li><a href='".PAGE_ACCUEIL."'>Tableau de bord.</a></li>";
$ariane_items[0]["form"]=false;
$ariane_items[0]["actif"]=false;
$ariane_items[1]["txt"]="<li>Gestion des posts proposés.</li>";
$ariane_items[1]["form"]=true;
$ariane_items[1]["actif"]=true;
$msg_infos[0]="Formulaire de gestion des <i>posts</i> publiés dans les hubs.";
$form[0]["nom"]="Rechercher un post.";
$form[0]["champs"]="<form method='post' id='recherche_posts' name='recherche_posts' action='".PAGE_MAJ_POSTS."' role='form' class='form-horizontal'><fieldset>
<div class='form-group'>
<label class='sr-only' for='recherche' class='col-sm-3 control-label'>Saisir l'expression à rechercher</label>
<div class='col-sm-7'><input type='text' class='form-control' name='recherche' id='recherche' placeholder=\"Saisir votre recherche\" required></div>
<div class='col-sm-2'><button type='submit' class='btn btn-default'>Rechercher.</button></div>
</div>
<div id='selection'>";
if(!empty($select))
$form[0]["champs"].=$select;
$form[0]["champs"].="</div>
</fieldset></form>";
if(!empty($form_html))
{
$i=0;
while(isset($form_html[$i]))
{
$form[$i+1]=$form_html[$i];
$i++;
}
}
else
{
$form[1]["nom"]="Affichage du post.";
$form[1]["champs"]="<form method='post' id='maj_post' name='maj_post' action='".PAGE_MAJ_POSTS."' role='form'><div id='msg_posts'></div></form>";
}
//le code pour ajax
ob_start();
$header_css[]["url"]=SITE_URL."/js/cleditor/jquery.cleditor.css";
?>
<script src="<?=SITE_URL;?>/js/cleditor/jquery.cleditor.min.js"></script>
<script src="<?=SITE_URL;?>/themes/seb/assets/js/pickadate/picker.js"></script>
<script src="<?=SITE_URL;?>/themes/seb/assets/js/pickadate/picker.date.js"></script>
<script src="<?=SITE_URL;?>/themes/seb/assets/js/pickadate/picker.time.js"></script>
<script src="<?=SITE_URL;?>/themes/seb/assets/js/pickadate/legacy.js"></script>
<script src="<?=SITE_URL;?>/themes/seb/assets/js/pickadate/fr_FR.js"></script>
<script>
function is_int(value)
{//source : http://www.inventpartners.com/javascript_is_int
if((parseFloat(value)==parseInt(value))&&!isNaN(value))
{
return true;
}
else
{
return false;
}
return true;
}
function affiche_cleditor()
{
var x=setTimeout(
function()
{
$("#annonce").cleditor(
{
controls: // controls to add to the toolbar
"style | bold italic underline strikethrough | link unlink | bullets numbering " +
" highlight subscript superscript | removeformat | pastetext | outdent " +
"indent | alignleft center alignright justify | undo redo | " +
"rule image print source",
colors: // colors in the color popup
"FFF FCC FC9 FF9 FFC 9F9 9FF CFF CCF FCF " +
"CCC F66 F96 FF6 FF3 6F9 3FF 6FF 99F F9F " +
"BBB F00 F90 FC6 FF0 3F3 6CC 3CF 66C C6C " +
"999 C00 F60 FC3 FC0 3C0 0CC 36F 63F C3C " +
"666 900 C60 C93 990 090 399 33F 60C 939 " +
"333 600 930 963 660 060 366 009 339 636 " +
"000 300 630 633 330 030 033 006 309 303",
styles: // styles in the style popup
[["Paragraph", "<p>"], ["Header 3", "<h3>"], ["Header 4","<h4>"], ["Header 5","<h5>"],
["Header 6","<h6>"]],
useCSS:
true, // use CSS to style HTML when possible (not supported in ie)
docType: // Document type contained within the editor
"<!DOCTYPE html>",
bodyStyle: // style to assign to document body contained within the editor
"margin:4px; font:10pt Arial,Verdana; cursor:text",
})
},500);//sinon ça va trop vite :-)
}
function post_affiche(id_post)
{
if(id_post!==0)
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_posts_affiche',
type:'GET',
data:'id_post='+id_post+'&ajax=1',
success:function(code)
{
if(code!=="")
{
$('#form1').html(code);
$("#uploadFrame").hide();
$("input[name=time_diffusion][type=text]").pickadate();
$("input[name=time_expiration][type=text]").pickadate();
}
}
});
affiche_cleditor();
}
}
$(document).ready(function()
{
$("#uploadFrame").hide();
$("#time_diffusion").pickadate();
$("#time_expiration").pickadate();
$('#recherche_posts').on('submit', function(e)
{
e.preventDefault();
var $this=$(this);
var recherche=$('#recherche').val();
if(recherche==='')
{
$('#msg_posts').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
}
else
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_posts_recherche',
type:'POST',
data:$this.serialize()+'&ajax=1',
success:function(code)
{
if(code!=="")
{
$('#selection').html(code);
}
}
});
}
});
$('#form').on('blur','#time_diffusion', function()
{
var date_diffusion=$('#time_diffusion').val();
var date_expiration=$('#time_expiration').val();
if((date_diffusion!='')&&(date_expiration===''))
{
var date_expiration_auto=new Date(date_diffusion.split('/')[2],date_diffusion.split('/')[1] - 1,date_diffusion.split('/')[0]);
date_expiration_auto.setDate(date_expiration_auto.getDate()+8);
date_expiration=date_expiration_auto.toLocaleDateString();
$('#time_expiration').val(date_expiration);
}
});
$('#selection').on('change','#liste_posts', function()
{
var id_post=$('#liste_posts').val();
post_affiche(id_post);
});
$('#form').on('blur','#recherche_hub', function()
{
var $this=$(this);
var recherche=$('#recherche_hub').val();
if(recherche==='')
{
$('#msg_posts').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
}
else
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_hub_recherche',
type:'POST',
data:$this.serialize()+'&ajax=1',
success:function(code)
{
if(code!=="")
{
$('#selection_hubs').html(code);
}
}
});
}
});
$('#form').on('submit','#maj_post', function(e)
{
e.preventDefault();
var $this=$(this);
var ancre=$('#ancre').val();
var url=$('#url').val();
var annonce=$('#annonce').val();
if((ancre==='')||((url==='')&&(annonce==='')))
{
$('#msg_posts').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
}
else
{
var suppr_ok=$("input[name=suppr_ok]:checked").val();
if(suppr_ok!=undefined)
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_posts_suppr_tests',
type:'POST',
data:$this.serialize()+'&ajax=1',
success:function(code)
{
if(code!=="")
{
if(code==='<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>')
{
$('#form1').html("");
$('#msg_form').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>');
}
else
{
$('#msg_posts').html(code);
}
}
}
});
}
else
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_posts_infos_tests',
type:'POST',
data:$this.serialize()+'&ajax=1',
success:function(code)
{
if(code!=="")
{
if(is_int(code))
{//tout s'est bien passé : l'id du post est retourné pour être réaffiché.
post_affiche(code);
var x=setTimeout(function() { $('#msg_posts').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>'); },500);//sinon ça va trop vite :-)
}
else
{
$('#msg_posts').html(code);
}
}
}
});
}
}
});
});
$('#contenu').on('submit','#change_hub_post',function(e)
{
e.preventDefault();
var $this=$(this);
var recherche=$('#recherche_hub').val();
if(recherche==='')
{
$('#msg_posts').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
}
else
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_hub_recherche',
type:'POST',
data:$this.serialize()+'&ajax=1',
success:function(code)
{
if(code!=="")
{
$('#selection_hubs').html(code);
}
}
});
}
});
$('#contenu').on('change','#liste_hubs', function()
{
var id_post=$('#id_post').val();//ne doit être appelé que quand je modifie le hub d'un post et non en création.
var id_hub=$('#liste_hubs').val();
if((id_hub!=="")&&(id_post!=undefined))
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_posts_chg_hub_tests',
type:'POST',
data:$('#change_hub_post').serialize()+'&ajax=1',
success:function(code)
{
if(code!=="")
{
if(is_int(code))
{//tout s'est bien passé, l'id est retourné pour être affiché
post_affiche(code);
var x=setTimeout(function() { $('#msg_posts').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>'); },500);//sinon ça va trop vite :-)
}
else
{
$('#msg_posts').html(code);
}
}
}
});
}
});
$('#contenu').on('submit','#change_auteur_post',function(e)
{
e.preventDefault();
var $this=$(this);
var recherche=$('#recherche_auteur').val();
if(recherche==='')
{
$('#msg_posts').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
}
else
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_comptes_recherche',
type:'POST',
data:$this.serialize()+'&ajax=1',
success:function(code)
{
if(code!=="")
{
$('#selection_auteurs').html(code);
}
}
});
}
});
$('#contenu').on('change','#liste_utilisateurs', function()
{
var id_hub=$('#liste_utilisateurs').val();
if(id_hub!=="")
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_posts_chg_auteur_tests',
type:'POST',
data:$('#change_auteur_post').serialize()+'&ajax=1',
success:function(code)
{
if(code!=="")
{
if(is_int(code))
{//tout s'est bien passé, l'id est retourné pour être affiché
post_affiche(code);
var x=setTimeout(function() { $('#msg_posts').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>'); },500);//sinon ça va trop vite :-)
}
else
{
$('#msg_posts').html(code);
}
}
}
});
}
});
$('#contenu').on('focus','#annonce', function()
{
affiche_cleditor();
});
function msg_telechargement(code)
{
if(code!=="")
{
if(code=="<?php echo str_replace("\"","'",MSG_UTILISA_TELECHARGE_VALID);?>")
{
var id_post=$('#id_post').val();
post_affiche(id_post);
var x=setTimeout(function() { $('#msg_illustration').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_UTILISA_TELECHARGE_VALID,"alert-success"));?>'); },500);
}
else if(code=="<?php echo str_replace("\"","'",MSG_UTILISA_MAJ_SUPPR_VALID);?>")
{
var id_post=$('#id_post').val();
post_affiche(id_post);
var x=setTimeout(function() { $('#msg_illustration').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_UTILISA_MAJ_SUPPR_VALID,"alert-success"));?>'); },500);
}
else
{
$('#msg_illustration').html(code);
}
}
}
</script>
<?php
$footer_JS=ob_get_contents();
ob_end_clean();
require(TEMPLATE_REP."/page.php");