200 lines
5.8 KiB
PHP
200 lines
5.8 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Vue affichant les formulaires permettant de gérer les sources de flux
|
||
|
* Saisie, affichage, mise à jour ou encore suppression.
|
||
|
* + scripts ajax testant la saisie
|
||
|
*
|
||
|
**/
|
||
|
$header_title="Les sources d'information >> ".SITE_NOM;
|
||
|
$body_title="Mise à jour des sources d'information.";
|
||
|
|
||
|
$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 sources de flux.</li>";
|
||
|
$ariane_items[1]["form"]=true;
|
||
|
$ariane_items[1]["actif"]=true;
|
||
|
|
||
|
$msg_infos[0]="Formulaire de gestion des <i>sources</i> d'information.";
|
||
|
|
||
|
$form[0]["nom"]="Rechercher une source.";
|
||
|
$form[0]["champs"]="<form method='post' id='recherche_source' name='recherche_source' action='".PAGE_MAJ_SOURCE."' 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))
|
||
|
$form[1]=$form_html;
|
||
|
else
|
||
|
{
|
||
|
$form[1]["nom"]="Saisie d'une nouvelle source.";
|
||
|
$form[1]["champs"]="<form method='post' id='maj_source' name='maj_source' action='".PAGE_MAJ_SOURCE." role='form'>
|
||
|
<div class='form-group'>
|
||
|
<label for='designation'>Nom du site.</label>
|
||
|
<input class='form-control' type='text' maxlength='".SOURCE_MAX_NOM."' name='designation' id='designation' value=\"".htmlspecialchars($form["designation"])."\" required>
|
||
|
<p class='help-block'><b>Obligatoire</b>.</p>
|
||
|
</div>
|
||
|
<div class='form-group'>
|
||
|
<label for='url'>Adresse du site.</label>
|
||
|
<input class='form-control' type='url' maxlength='".SOURCE_MAX_URL."' name='url' id='url' value=\"".$form["url"]."\" required>
|
||
|
<p class='help-block'><b>Obligatoire</b>.";
|
||
|
if((!empty($form["url"]))&&($form["url"]!="http://"))
|
||
|
{
|
||
|
$form[1]["champs"].=" <a href=\"".$form["url"]."\" title='Voir le site' class='btn btn-info btn-sm' target='_blank'>Voir le site.</a>";
|
||
|
}
|
||
|
$form[1]["champs"].="</p>
|
||
|
</div>
|
||
|
<div class='form-group'>
|
||
|
<label for='description'>Description.</label>
|
||
|
<input class='form-control' type='text' maxlength='".SOURCE_MAX_DESCRIPTION."' name='description' id='description' value=\"".htmlspecialchars($form["description"])."\">
|
||
|
<p class='help-block'><b>Facultatif</b>.</p>
|
||
|
</div>
|
||
|
<div id='msg_sources'></div>
|
||
|
<button type='submit' class='btn btn-success btn-lg'>Enregistrer.</button>
|
||
|
</fieldset></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 source_affiche(id_source)
|
||
|
{
|
||
|
if(id_source!==0)
|
||
|
{
|
||
|
$.ajax(
|
||
|
{
|
||
|
url:'<?=SITE_URL;?>/JS/admin_sources_affiche',
|
||
|
type:'GET',
|
||
|
data:'id_source='+id_source+'&ajax=1',
|
||
|
success:function(code)
|
||
|
{
|
||
|
if(code!=="")
|
||
|
{
|
||
|
$('#form1').html(code);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
$(document).ready(function()
|
||
|
{
|
||
|
$('#recherche_source').on('submit', function(e)
|
||
|
{
|
||
|
e.preventDefault();
|
||
|
var $this=$(this);
|
||
|
var nom=$('#recherche').val();
|
||
|
if(recherche==='')
|
||
|
{
|
||
|
$('#msg_sources').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) ERREUR_UTILISA_CHAMPS_ABSENTS));?>');
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$.ajax(
|
||
|
{
|
||
|
url:'<?=SITE_URL;?>/JS/admin_sources_recherche',
|
||
|
type:'POST',
|
||
|
data:$this.serialize()+'&ajax=1',
|
||
|
success:function(code)
|
||
|
{
|
||
|
if(code!=="")
|
||
|
{
|
||
|
$('#selection').html(code);
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
$('#selection').on('change','#liste_sources', function()
|
||
|
{
|
||
|
var id_source=$('#liste_sources').val();
|
||
|
source_affiche(id_source);
|
||
|
});
|
||
|
$('#form1').on('submit','#maj_source', function(e)
|
||
|
{
|
||
|
e.preventDefault();
|
||
|
var $this=$(this);
|
||
|
var nom=$('#designation').val();
|
||
|
var url=$('#url').val();
|
||
|
if(nom===''||url==='')
|
||
|
{
|
||
|
$('#msg_sources').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) 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_sources_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_SOURCE."\" title=\"Saisir une nouvelle source\" class=\"btn btn-info btn-sm\">+ Nouvelle source.</a></p>";?>');
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$('#msg_sources').html(code);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$.ajax(
|
||
|
{
|
||
|
url:'<?=SITE_URL;?>/JS/admin_sources_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é
|
||
|
source_affiche(code);
|
||
|
var x=setTimeout(function() { $('#msg_sources').html('<?php echo str_replace("'","\"",get_html_alerte_msg((array) MSG_ADMIN_VALID,"alert-success"));?>'); },500);//sinon ça va trop vite :-)
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$('#msg_sources').html(code);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
</script>
|
||
|
<?php
|
||
|
$footer_JS=ob_get_contents();
|
||
|
ob_end_clean();
|
||
|
require(TEMPLATE_REP."/page.php");
|