hellofacteurV1/vues/admin_hub_maj.php

440 lines
13 KiB
PHP
Executable File

<?php
/**
* Vue affichant les formulaires permettant de gérer les hubs
* Saisie, affichage, mise à jour ou encore suppression.
* + scripts ajax testant la saisie
*
**/
$header_title="Les hubs >> ".SITE_NOM;
$body_title="Gestion des hubs.";
$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 hubs.</li>";
$ariane_items[1]["form"]=true;
$ariane_items[1]["actif"]=true;
$msg_infos[0]="Formulaire de gestion des <i>hubs</i> auxquels les utilisateurs peuvent s'abonner.";
$form[0]["nom"]="Rechercher un hub.";
$form[0]["champs"]="<form method='post' id='form_recherche_hub' name='form_recherche_hub' action='".PAGE_MAJ_HUB."' class='form-inline' role='form'>
<div class='form-group'>
<label class='sr-only' for='recherche_hub'>Saisir l'expression à rechercher</label>
<input type='text' class='form-control' name='recherche_hub' id='recherche_hub' placeholder=\"Saisir votre recherche\" required>
</div>
<button type='submit' class='btn btn-default'>Rechercher</button><br><br>
<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"]="Saisie d'un nouveau hub.";
$form[1]["champs"]="<form method='post' id='maj_hub' name='maj_hub' action='".PAGE_MAJ_HUB."' role='form'>
<div class='form-group'>
<label for='nom'>Désignation.</label>
<input class='form-control' type='text' maxlength='".HUB_MAX_NOM."' name='nom' id='nom' value=\"".htmlspecialchars($form["nom"])."\" required>
<p class='help-block'><b>Obligatoire</b>.</p>
</div>
<div class='form-group'>
<label for='description'>Description.</label>
<input class='form-control' type='text' maxlength='".HUB_MAX_DESCRIPTION."' name='description' id='description' value=\"".htmlspecialchars($form["description"])."\">
<p class='help-block'><b>Facultatif</b>.</p>
</div>
<div class='form-group'>
<label for='mots_cles'>Mots-clés.</label>
<textarea class='form-control' rows='4' name='mots_cles' id='mots_cles'>".htmlspecialchars($form["mots_cles"])."</textarea>
<p class='help-block'><b>Facultatif</b>. Utile pour les recherches des utilisateurs. À séparer par des virgules.</p>
</div>";
$langues=explode("|",HUB_LANGUES);
$form[1]["champs"].="<div class='form-group'><label for='langue'>Langue principale :</label>";
foreach ($langues as $langue)
{
if($langue==$form["langue"])
$form[1]["champs"].="<label class='checkbox-inline'><input type='radio' name='langue' value='$langue' checked='checked'> ".$langue."</label>";
else
$form[1]["champs"].="<label class='checkbox-inline'><input type='radio' name='langue' value='$langue'> ".$langue."</label>";
}
$form[1]["champs"].="<p class='help-block'><b>Obligatoire</b>.</p></div>";
if($form["publication_ok"]==1)
$form[1]["champs"].="<div class='form-group'><label class='checkbox-inline'><input type='checkbox' id='publication_ok' name='publication_ok' value='1' checked='checked'> Publication autorisée.</label></div>";
else
$form[1]["champs"].="<div class='form-group'><label class='checkbox-inline'><input type='checkbox' id='publication_ok' name='publication_ok' value='1'> Publication autorisée.</label></div>";
if($form["index_ok"]==1)
$form[1]["champs"].="<div class='form-group'><label class='checkbox-inline'><input type='checkbox' id='index_ok' name='index_ok' value='1' checked='checked'> Indexation autorisée.</label></div>";
else
$form[1]["champs"].="<div class='form-group'><label class='checkbox-inline'><input type='checkbox' id='index_ok' name='index_ok' value='1'> Indexation autorisée.</label></div>";
$form[1]["champs"].="<div class='form-group'>
<label for='memo'>Mémo.</label>
<input class='form-control' type='text' maxlength='".HUB_MAX_MEMO."' name='memo' id='memo' value=\"".htmlspecialchars($form["memo"])."\">
<p class='help-block'><b>Facultatif</b>. Mémo interne non publié.</p>
</div>
<button type='submit' class='btn btn-success btn-lg'>Enregistrer.</button>
</form>";
}
//le code pour ajax
ob_start();
?>
<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 hub_affiche(id_hub)
{
if(id_hub!==0)
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_hub_affiche',
type:'GET',
data:'id_hub='+id_hub+'&ajax=1',
success:function(code)
{
if(code!=="")
{
$('#form1').html(code);
$("#uploadFrame").hide();
}
}
});
}
}
$(document).ready(function()
{
$('#form_recherche_hub').on('submit', function(e)
{
e.preventDefault();
var $this=$(this);
var recherche=$('#recherche_hub').val();
if(recherche==='')
{
$('#msg_form').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').html(code);
}
}
});
}
});
$('#selection').on('change','#liste_hubs', function()
{
var id_hub=$('#liste_hubs').val();
hub_affiche(id_hub);
});
$('#form').on('submit','#maj_hub', function(e)
{
e.preventDefault();
var $this=$(this);
var nom=$('#nom').val();
var langue=$('#langue').val();
if((nom==='')||(langue===''))
{
$('#msg_form').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
alert('<?=ERREUR_UTILISA_CHAMPS_ABSENTS;?>');
}
else
{
var suppr_ok=$("input[name=suppr_ok]:checked").val();
var suppr_ok_tot=$("input[name=suppr_ok_tot]:checked").val();
if((suppr_ok!=undefined)||(suppr_ok_tot!=undefined))
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_hub_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"))."<p><br><br><a href=\"".PAGE_MAJ_HUB."\" title=\"Saisir un nouveau hub\" class=\"btn btn-info btn-sm\">+ Nouveau hub.</a></p>";?>');
}
else
{
$('#msg_form').html(code);
decode=code.replace(/(<([^>]+)>)/ig,"");//trouvé : http://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/
alert(decode);
}
}
}
});
}
else
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_hub_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 est retourné pour être affiché
hub_affiche(code);
$('#msg_form').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>');
alert('<?=MSG_ADMIN_VALID;?>');
}
else
{
$('#msg_form').html(code);
decode=code.replace(/(<([^>]+)>)/ig,"");//trouvé : http://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/
alert(decode);
}
}
}
});
}
}
});
$('#form').on('submit','#post_hub', function(e)
{
e.preventDefault();
var $this=$(this);
var ancre=$('#ancre').val();
var url=$('#url').val();
var annonce=$('#annonce').val();
if((ancre==='')||((url==='')&&(annonce==='')))
{
$('#msg_form_post').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
}
else
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_hub_post_ajout_tests',
type:'POST',
data:$this.serialize()+'&ajax=1',
success:function(code)
{
if(code!=="")
{
if(is_int(code))
{//tout s'est bien passé, l'id est retourné pour être affiché
hub_affiche(code);
var x=setTimeout(function() { $('#msg_form_post').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>'); },500);//sinon ça va trop vite :-)
$('html,body').animate({scrollTop:$("#msg_form_post").offset().top},'slow');
}
else
{
$('#msg_form_post').html(code);
}
}
}
});
}
});
$('#form').on('blur','#recherche_rubrique',function(e)
{
e.preventDefault();
var $this=$(this);
var recherche=$('#recherche_rubrique').val();
if(recherche==='')
{
$('#msg_form_classement').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
}
else
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_rubriques_recherche',
type:'POST',
data:'recherche='+recherche+'&ajax=1',
success:function(code)
{
if(code!=="")
{
$('#select_rubriques').html(code);
}
}
});
}
});
$('#form').on('submit','#rubriques_hub', function(e)
{
e.preventDefault();
var $this=$(this);
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_hub_classement_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 hub est retourné pour être affiché
hub_affiche(code);
$('#msg_form_classement').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>');
}
else
{//des erreurs ont été rencontrées
$('#msg_form_classement').html(code);
}
}
}
});
});
$('#form').on('blur','#recherche_flux',function(e)
{
e.preventDefault();
var $this=$(this);
var recherche=$('#recherche_flux').val();
if(recherche==='')
{
$('#msg_form_flux').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
}
else
{
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_flux_recherche',
type:'POST',
data:'recherche='+recherche+'&ajax=1',
success:function(code)
{
if(code!=="")
{
$('#select_flux').html(code);
}
}
});
}
});
$('#form').on('submit','#flux_hub', function(e)
{
e.preventDefault();
var $this=$(this);
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_hub_flux_import_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 hub est retourné pour être affiché
hub_affiche(code);
$('#msg_form_flux').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>');
}
else
{//des erreurs ont été rencontrées
$('#msg_form_flux').html(code);
}
}
}
});
});
$('#form').on('blur','#recherche_admin',function(e)
{
e.preventDefault();
var $this=$(this);
var recherche=$('#recherche_admin').val();
if(recherche==='')
{
$('#msg_form_admin').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:'recherche='+recherche+'&ajax=1',
success:function(code)
{
if(code!=="")
{
$('#select_admins').html(code);
}
}
});
}
});
$('#form').on('submit','#admin_hub', function(e)
{
e.preventDefault();
var $this=$(this);
$.ajax(
{
url:'<?=SITE_URL;?>/JS/admin_hub_admins_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 hub est retourné pour être affiché
hub_affiche(code);
$('#msg_form_admin').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>');
}
else
{//des erreurs ont été rencontrées
$('#msg_form_admin').html(code);
}
}
}
});
});
});
function msg_telechargement(code)
{
if(code!=="")
{
if(code=="<?php echo str_replace("\"","'",MSG_ADMIN_VALID);?>")
{
var id_hub=$('#id_hub').val();
hub_affiche(id_hub);
$('html,body').animate({scrollTop:$("#maj_hub_illustration").offset().top},'slow');
var x=setTimeout(function() { $('#msg_illustration').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>'); },500);
}
else
{
$('#msg_illustration').html(code);
}
}
}
</script>
<?php
$footer_JS=ob_get_contents();
ob_end_clean();
require(TEMPLATE_REP."/page.php");