67 lines
1.2 KiB
PHP
67 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Fonctions utiles au plugin GamuForm
|
|
*
|
|
* @plugin GamuForm
|
|
* @copyright 2020
|
|
* @author tofulm
|
|
* @licence GNU/GPL
|
|
* @package SPIP\Gamuform\Fonctions
|
|
*/
|
|
|
|
if (!defined('_ECRIRE_INC_VERSION')) {
|
|
return;
|
|
}
|
|
|
|
function gamuform_objet_autoriser(string $objet):bool {
|
|
if (
|
|
!empty($GLOBALS['gamuform_objets'])
|
|
and !empty($objet)
|
|
and in_array($objet, $GLOBALS['gamuform_objets'])
|
|
) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function gamuform_recup_champ($objet) {
|
|
$c = [];
|
|
|
|
if (gamuform_objet_autoriser($objet)) {
|
|
$T = $GLOBALS['gamuform_'.$objet];
|
|
if (!empty($T)) {
|
|
foreach ($T as $s) {
|
|
$c[] = $s['options']['nom'];
|
|
}
|
|
}
|
|
}
|
|
return $c;
|
|
}
|
|
|
|
function gamuform_recup_valeurs($objet, $id_objet = 0):array {
|
|
$r = [];
|
|
if (gamuform_objet_autoriser($objet)) {
|
|
$table = table_objet_sql($objet);
|
|
$id = id_table_objet($objet);
|
|
$s = gamuform_recup_champ($objet);
|
|
|
|
$s[] = $id;
|
|
if (intval($id_objet)) {
|
|
$valeurs = sql_fetsel($s, $table, "$id=".intval($id_objet));
|
|
$valeurs['id'] = $valeurs[$id];
|
|
if (!empty($valeurs)) {
|
|
$r[0] = $valeurs;
|
|
}
|
|
} else {
|
|
$T = sql_allfetsel($s, $table, 1);
|
|
if (!empty($T)) {
|
|
foreach ($T as $t) {
|
|
$t['id'] = $t[$id];
|
|
$r[] = $t;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $r;
|
|
}
|