280 lines
8.9 KiB
PHP
280 lines
8.9 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Vue affichant les formulaires permettant de gérer les flux
|
||
|
* Saisie, affichage, mise à jour ou encore suppression.
|
||
|
* + scripts ajax testant la saisie
|
||
|
*
|
||
|
**/
|
||
|
$header_title="Les flux >> ".SITE_NOM;
|
||
|
$body_title="Gestion des flux.";
|
||
|
|
||
|
$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 flux proposés.</li>";
|
||
|
$ariane_items[1]["form"]=true;
|
||
|
$ariane_items[1]["actif"]=true;
|
||
|
|
||
|
$msg_infos[0]="Formulaire de gestion des <i>flux</i> importés dans les Bureaux de poste.";
|
||
|
|
||
|
$form[0]["nom"]="Rechercher un flux.";
|
||
|
$form[0]["champs"]="<form method='post' id='recherche_flux' name='recherche_flux' action='".PAGE_REPERTOIRE_ACCUEIL."' class='form-inline' role='form'>
|
||
|
<div class='form-group'>
|
||
|
<label class='sr-only' for='recherche'>Saisir l'expression à rechercher</label>
|
||
|
<input type='text' class='form-control' name='recherche' id='recherche' 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 flux.";
|
||
|
$form[1]["champs"]="<form method='post' id='maj_flux' name='maj_flux' action='".PAGE_MAJ_FLUX."' role='form'>";
|
||
|
// désignation de la source ?
|
||
|
if(!empty($source_select))
|
||
|
{
|
||
|
$form[1]["champs"].="
|
||
|
<div id='sup_sources'>
|
||
|
<div class='form-group'>
|
||
|
<label for='mere_id'>Sélectionner le site propriétaire du flux.</label>
|
||
|
<select name='source_id' autofocus class='form-control'>";
|
||
|
foreach ($source_select as $source_info)
|
||
|
$form[1]["champs"].="<option value='".$source_info["id_source"]."'>".htmlentities(affiche_utf8($source_info["nom"],UTF8_OK))."</option>";
|
||
|
$form[1]["champs"].="</select>
|
||
|
</div></div>
|
||
|
<div class='form-group'>
|
||
|
<label for='cherche_source'>Pas trouvé ? Lancez une nouvelle recherche.</label>
|
||
|
<input class='form-control' type='text' maxlength='20' name='cherche_source' id='cherche_source'>
|
||
|
</div>";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$form[1]["champs"].="
|
||
|
<div class='form-group'>
|
||
|
<label for='cherche_source'>Cherchez le site propriétaire du flux.</label>
|
||
|
<input class='form-control' type='text' maxlength='20' name='cherche_source' id='cherche_source'>
|
||
|
<p class='help-block'><b>Obligatoire</b>.</p>
|
||
|
</div>
|
||
|
<div id='sup_sources'></div>";
|
||
|
}
|
||
|
$form[1]["champs"].="
|
||
|
<div class='form-group'>
|
||
|
<label for='designation'>Titre.</label>
|
||
|
<input class='form-control' type='text' maxlength='".FLUX_MAX_NOM."' name='designation' id='nom' value=\"".htmlspecialchars($form["nom"])."\" required>
|
||
|
<p class='help-block'><b>Obligatoire</b>.</p>
|
||
|
</div>
|
||
|
<div class='form-group'>
|
||
|
<label for='url'>Adresse.</label>
|
||
|
<input class='form-control' type='url' maxlength='".FLUX_MAX_URL."' name='url' id='url' value=\"".$form["url"]."\" required>
|
||
|
<p class='help-block'><b>Obligatoire</b>. L'adresse complète du flux dont la lecture sera testée au moment de l'enregistrement.</p>
|
||
|
</div>
|
||
|
<div class='form-group'>
|
||
|
<label for='description'>Description.</label>
|
||
|
<input class='form-control' type='text' maxlength='".FLUX_MAX_DESCRIPTION."' name='description' id='description' value=\"".htmlspecialchars($form["description"])."\">
|
||
|
<p class='help-block'><b>Facultatif</b>.</p>
|
||
|
</div>";
|
||
|
$langues=explode("|",FLUX_LANGUES);
|
||
|
$form[1]["champs"].="<div class='form-group'><label for='langue'>Langue principale du flux :</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>";
|
||
|
$frequences=explode("|",FLUX_FREQUENCES);
|
||
|
$form[1]["champs"].="<div class='form-group'><label for='frequence_maj'>Fréquence d'actualisation du flux.</label>";
|
||
|
foreach ($frequences as $frequence)
|
||
|
{
|
||
|
if($frequence==$form["frequence_maj"])
|
||
|
$form[1]["champs"].="<label class='checkbox-inline'><input type='radio' name='frequence_maj' value='$frequence' checked='checked'> ".$frequence."</label>";
|
||
|
else
|
||
|
$form[1]["champs"].="<label class='checkbox-inline'><input type='radio' name='frequence_maj' value='$frequence'> ".$frequence."</label>";
|
||
|
}
|
||
|
$form[1]["champs"].="<p class='help-block'><b>Obligatoire</b>.</p></div>
|
||
|
<div class='form-group'>
|
||
|
<label for='memo'>Mémo.</label>
|
||
|
<input class='form-control' type='text' maxlength='".FLUX_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 flux_affiche(id_flux)
|
||
|
{
|
||
|
if(id_flux!==0)
|
||
|
{
|
||
|
$.ajax(
|
||
|
{
|
||
|
url:'<?=SITE_URL;?>/JS/admin_flux_affiche',
|
||
|
type:'GET',
|
||
|
data:'id_flux='+id_flux+'&ajax=1',
|
||
|
success:function(code)
|
||
|
{
|
||
|
if(code!=="")
|
||
|
{
|
||
|
$('#form1').html(code);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
$(document).ready(function()
|
||
|
{
|
||
|
$('#recherche_flux').on('submit', function(e)
|
||
|
{
|
||
|
e.preventDefault();
|
||
|
var $this=$(this);
|
||
|
var nom=$('#recherche').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_flux_recherche',
|
||
|
type:'POST',
|
||
|
data:$this.serialize()+'&ajax=1',
|
||
|
success:function(code)
|
||
|
{
|
||
|
if(code!=="")
|
||
|
{
|
||
|
$('#selection').html(code);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
$('#selection').on('change','#liste_flux', function()
|
||
|
{
|
||
|
var id_flux=$('#liste_flux').val();
|
||
|
flux_affiche(id_flux);
|
||
|
});
|
||
|
$('#form').on('blur','#cherche_source', function()
|
||
|
{
|
||
|
var recherche=$('#cherche_source').val();
|
||
|
if(recherche!=="")
|
||
|
{
|
||
|
$.ajax(
|
||
|
{
|
||
|
url:'<?=SITE_URL;?>/JS/admin_flux_select',
|
||
|
type:'POST',
|
||
|
data:'recherche='+recherche+'&ajax=1',
|
||
|
success:function(code)
|
||
|
{
|
||
|
$('#sup_sources').html(code);
|
||
|
}
|
||
|
});
|
||
|
$('#cherche_source').val("");
|
||
|
}
|
||
|
});
|
||
|
$('#form').on('submit','#maj_flux', function(e)
|
||
|
{
|
||
|
e.preventDefault();
|
||
|
var $this=$(this);
|
||
|
var nom=$('#designation').val();
|
||
|
var url=$('#url').val();
|
||
|
var langue=$('#langue').val();
|
||
|
var frequence_maj=$('#frequence_maj').val();
|
||
|
if((nom==='')||(url==='')||(langue==='')||(frequence_maj===''))
|
||
|
{
|
||
|
$('#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_flux_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_FLUX."\" title=\"Saisir un nouveau flux\" class=\"btn btn-info btn-sm\">+ Nouveau flux.</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_flux_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é
|
||
|
flux_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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
</script>
|
||
|
<?php
|
||
|
$footer_JS=ob_get_contents();
|
||
|
ob_end_clean();
|
||
|
require(TEMPLATE_REP."/page.php");
|