On crée une fonction "info_param($objet, $id_objet,$param)" permettant de créer un squelette générique toggle_param et une action de même nom qui active ou désactive en ajax n'importe quel champ booléen d'un objet

This commit is contained in:
Pierre 2020-03-14 02:38:07 +01:00
parent 4b988fc6a2
commit f52f327bac
4 changed files with 52 additions and 6 deletions

35
action/toggle_param.php Normal file
View file

@ -0,0 +1,35 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) return;
function action_toggle_param_dist(){
$securiser_action = charger_fonction('securiser_action', 'inc');
$arg = $securiser_action();
list($objet,$id_objet,$param)=explode('/',$arg);
$id_objet = intval($id_objet);
include_spip('inc/autoriser');
if (! autoriser("modifier",$objet, $id_objet)) {
return false;
}
if($id_objet){
$table = "spip_". $objet . "s";
$where= "id_$objet=$id_objet";
if (sql_getfetsel($param,$table,$where)=='on'){
$set = array($param => '');
}
else{
$set = array($param => 'on');
}
sql_updateq($table, $set, $where);
include_spip('inc/invalideur');
suivre_invalideur("id='$objet/$id_objet'");
}
// redirection sur la page courante
include_spip('inc/headers');
redirige_par_entete(_request('redirect'));
}

View file

@ -76,3 +76,8 @@ if (!function_exists('array_column')) {
return $result; return $result;
} }
} }
function info_param($arg){
list($objet,$id_objet,$param)=explode('/',$arg);
return sql_getfetsel($param,'spip_' .$objet. 's',"id_$objet=$id_objet");
}

View file

@ -11,10 +11,10 @@
<tr> <tr>
<th scope="col">Nom</th> <th scope="col">Nom</th>
<th scope="col">Statut</th> <th scope="col">Statut</th>
<th scope="col">Bureau</th>
<th scope="col">Animateur</th> <th scope="col">Animateur</th>
<th scope="col">Email</th> <th scope="col">Email</th>
<th scope="col">Téléphone</th> <th scope="col">Téléphone</th>
<th scope="col">Téléphone 2</th>
<th scope="col">Actions</th> <th scope="col">Actions</th>
</tr> </tr>
</thead> </thead>
@ -25,17 +25,19 @@
<td class="cellule-tableau">#NOM</td> <td class="cellule-tableau">#NOM</td>
<td class="cellule-tableau"> <td class="cellule-tableau">
[(#STATUT|=={0minirezo}|oui) Administrateur] [(#STATUT|=={0minirezo}|oui) Administrateur]
[(#STATUT|=={1comite}|oui) Rédacteur] [(#STATUT|=={1comite}|oui) Membre]
[(#STATUT|=={6forum}|oui) Inscrit] [(#STATUT|=={6forum}|oui) Inscrit]
</td> </td>
<td class="cellule-tableau"> <td class="cellule-tableau">
<BOUCLE_groupes(ARTICLES){id_secteur=#CONFIG{balint/id_rub_groupes}}{id_auteur=#ID_AUTEUR}> <INCLURE{fond=inclure/toggle_param,env,objet=auteur,id_objet=#ID_AUTEUR,param=bureau,ajax}>
[(#SURTITRE|unique)] </td>
<td class="cellule-tableau">
<BOUCLE_groupes(ARTICLES){id_secteur=#CONFIG{balint/id_rub_groupes}}{id_auteur=#ID_AUTEUR}{fusion surtitre}>
#SURTITRE
</BOUCLE_groupes> </BOUCLE_groupes>
</td> </td>
<td class="cellule-tableau">#EMAIL</td> <td class="cellule-tableau">#EMAIL</td>
<td class="cellule-tableau">#TELEPHONE</td> <td class="cellule-tableau">#TELEPHONE</br>#TELEPHONE2</td>
<td class="cellule-tableau">#TELEPHONE2</td>
<td class="row"> <td class="row">
<a class="btn mediabox" href="[(#URL_PAGE{editer_auteur}|parametre_url{id_auteur,#ID_AUTEUR})]"> <a class="btn mediabox" href="[(#URL_PAGE{editer_auteur}|parametre_url{id_auteur,#ID_AUTEUR})]">
<i class="fas fa-pencil"></i> <i class="fas fa-pencil"></i>

View file

@ -0,0 +1,4 @@
<a class="ajax nohistory nocache bouton-toggle [(#VAL{#ENV{objet}/#ENV{id_objet}/#ENV{param}}|info_param|=={on}|oui) vert]"
href="[(#URL_ACTION_AUTEUR{toggle_param,#ENV{objet}/#ENV{id_objet}/#ENV{param},#SELF})]">
<i class="fas fa-star"></i>
</a>