PSR et indentations

pull/15/head
Cerdic 1 year ago
parent 6babffdb2e
commit c55a10dfd5

@ -5,66 +5,68 @@
* (c) 2012 Les Développements Durables
* Licence GNU/GPL v3
*/
if (!defined('_ECRIRE_INC_VERSION'))
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Fonction d'installation du plugin et de mise à jour.
* */
function abonnements_upgrade($nom_meta_base_version, $version_cible) {
$maj = array();
$maj = [];
$maj['create'] = array(array('maj_tables', array('spip_abonnements_offres', 'spip_abonnements_offres_liens', 'spip_abonnements', 'spip_abonnements_offres_notifications')));
$maj['create'] = [['maj_tables', ['spip_abonnements_offres', 'spip_abonnements_offres_liens', 'spip_abonnements', 'spip_abonnements_offres_notifications']]];
// Ajout de la config des notifications
$maj['2.1.0'] = array(
array('maj_tables', array('spip_abonnements_offres_notifications'))
);
$maj['2.1.0'] = [
['maj_tables', ['spip_abonnements_offres_notifications']]
];
// Ajout de la date d'échéance possiblement différente avec la date de fin
$maj['2.2.0'] = array(
array('maj_tables', array('spip_abonnements')),
array('sql_update', 'spip_abonnements', array('date_echeance' => 'date_fin'))
);
$maj['2.2.0'] = [
['maj_tables', ['spip_abonnements']],
['sql_update', 'spip_abonnements', ['date_echeance' => 'date_fin']]
];
// Ajout des champs taxe et prix_ht, on copie la valeur de prix dans prix_ht
$maj['2.2.2'] = array(
array('maj_tables', array('spip_abonnements_offres')),
array('sql_alter', 'TABLE spip_abonnements_offres ADD prix_ht float(10,2) not null default 0 AFTER periode'),
array('sql_alter', 'TABLE spip_abonnements_offres ADD taxe decimal(4,4) null default 0 AFTER prix_ht'),
array('sql_update', 'spip_abonnements_offres', array('prix_ht' => 'prix')),
array('sql_update', 'spip_abonnements_offres', array('prix' => '0'))
);
$maj['2.2.2'] = [
['maj_tables', ['spip_abonnements_offres']],
['sql_alter', 'TABLE spip_abonnements_offres ADD prix_ht float(10,2) not null default 0 AFTER periode'],
['sql_alter', 'TABLE spip_abonnements_offres ADD taxe decimal(4,4) null default 0 AFTER prix_ht'],
['sql_update', 'spip_abonnements_offres', ['prix_ht' => 'prix']],
['sql_update', 'spip_abonnements_offres', ['prix' => '0']]
];
// Nettoyage (d'une table inexistante...)
$maj['2.2.3'] = array(
array('sql_alter',"TABLE spip_contacts_abonnements DROP prix"),
);
$maj['2.2.3'] = [
['sql_alter','TABLE spip_contacts_abonnements DROP prix'],
];
// relancer des abonnements après échéance
$maj['2.2.4'] = array(
array('sql_alter',"TABLE spip_abonnements_offres_notifications ADD `quand` ENUM('avant','apres') DEFAULT 'avant' NOT NULL AFTER `periode`"),
);
$maj['2.2.4'] = [
['sql_alter',"TABLE spip_abonnements_offres_notifications ADD `quand` ENUM('avant','apres') DEFAULT 'avant' NOT NULL AFTER `periode`"],
];
// Nettoyage : le champ `prix` est inutile, il suffit de `prix_ht` et `taxe`
$maj['2.2.5'] = array(
array('sql_alter',"TABLE spip_abonnements_offres DROP prix"),
);
// Ajout d'une valeur possible au champ `quand`
$maj['2.2.6'] = array(
array('sql_alter',"TABLE spip_abonnements_offres_notifications CHANGE `quand` `quand` ENUM('avant','apres','pendant') DEFAULT 'avant' NOT NULL")
);
$maj['2.2.5'] = [
['sql_alter','TABLE spip_abonnements_offres DROP prix'],
];
// Ajout d'une valeur possible au champ `quand`
$maj['2.2.6'] = [
['sql_alter',"TABLE spip_abonnements_offres_notifications CHANGE `quand` `quand` ENUM('avant','apres','pendant') DEFAULT 'avant' NOT NULL"]
];
// Ajout d'un champ immatériel pour savoir si c'est un service virtuel ou matériel
$maj['2.3.0'] = array(
array('maj_tables', array('spip_abonnements_offres')),
);
$maj['2.3.0'] = [
['maj_tables', ['spip_abonnements_offres']],
];
// Passage en décimal
$maj['2.3.1'] = array(
array('sql_alter', 'TABLE spip_abonnements_offres CHANGE prix_ht prix_ht DECIMAL(20,6) NOT NULL DEFAULT 0'),
);
$maj['2.3.1'] = [
['sql_alter', 'TABLE spip_abonnements_offres CHANGE prix_ht prix_ht DECIMAL(20,6) NOT NULL DEFAULT 0'],
];
include_spip('base/upgrade');
maj_plugin($nom_meta_base_version, $version_cible, $maj);
@ -74,15 +76,15 @@ function abonnements_upgrade($nom_meta_base_version, $version_cible) {
* Fonction de désinstallation du plugin.
* */
function abonnements_vider_tables($nom_meta_base_version) {
sql_drop_table("spip_abonnements_offres");
sql_drop_table("spip_abonnements_offres_liens");
sql_drop_table("spip_abonnements");
sql_drop_table("spip_abonnements_offres_notifications");
sql_drop_table('spip_abonnements_offres');
sql_drop_table('spip_abonnements_offres_liens');
sql_drop_table('spip_abonnements');
sql_drop_table('spip_abonnements_offres_notifications');
# Nettoyer les versionnages et forums
sql_delete("spip_versions", sql_in("objet", array('abonnements_offre', 'abonnement')));
sql_delete("spip_versions_fragments", sql_in("objet", array('abonnements_offre', 'abonnement')));
sql_delete("spip_forum", sql_in("objet", array('abonnements_offre', 'abonnement')));
sql_delete('spip_versions', sql_in('objet', ['abonnements_offre', 'abonnement']));
sql_delete('spip_versions_fragments', sql_in('objet', ['abonnements_offre', 'abonnement']));
sql_delete('spip_forum', sql_in('objet', ['abonnements_offre', 'abonnement']));
effacer_meta($nom_meta_base_version);
}

@ -1,14 +1,17 @@
<?php
/**
* Plugin Abonnements
* (c) 2012 Les Développements Durables
* Licence GNU/GPL v3
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) { return;
}
// declaration vide pour ce pipeline.
function abonnements_autoriser(){}
function abonnements_autoriser() {
}
// -----------------
@ -16,14 +19,14 @@ function abonnements_autoriser(){}
// bouton de menu
function autoriser_abonnementsoffres_menu_dist($faire, $type, $id, $qui, $opts){
function autoriser_abonnementsoffres_menu_dist($faire, $type, $id, $qui, $opts) {
return true;
}
}
// creer
function autoriser_abonnementsoffre_creer_dist($faire, $type, $id, $qui, $opt) {
return $qui['statut'] == '0minirezo' AND !$qui['restreint'];
return $qui['statut'] == '0minirezo' and !$qui['restreint'];
}
// voir les fiches completes
@ -33,18 +36,18 @@ function autoriser_abonnementsoffre_voir_dist($faire, $type, $id, $qui, $opt) {
// modifier
function autoriser_abonnementsoffre_modifier_dist($faire, $type, $id, $qui, $opt) {
return $qui['statut'] == '0minirezo' AND !$qui['restreint'];
return $qui['statut'] == '0minirezo' and !$qui['restreint'];
}
// supprimer
function autoriser_abonnementsoffre_supprimer_dist($faire, $type, $id, $qui, $opt) {
return $qui['statut'] == '0minirezo' AND !$qui['restreint'];
return $qui['statut'] == '0minirezo' and !$qui['restreint'];
}
// associer (lier / delier)
function autoriser_associerabonnementsoffres_dist($faire, $type, $id, $qui, $opt) {
return $qui['statut'] == '0minirezo' AND !$qui['restreint'];
return $qui['statut'] == '0minirezo' and !$qui['restreint'];
}
@ -54,7 +57,7 @@ function autoriser_associerabonnementsoffres_dist($faire, $type, $id, $qui, $opt
// creer
function autoriser_abonnement_creer_dist($faire, $type, $id, $qui, $opt) {
return $qui['statut'] == '0minirezo' AND !$qui['restreint'];
return $qui['statut'] == '0minirezo' and !$qui['restreint'];
}
// voir les fiches completes
@ -64,10 +67,10 @@ function autoriser_abonnement_voir_dist($faire, $type, $id, $qui, $opt) {
// modifier
function autoriser_abonnement_modifier_dist($faire, $type, $id, $qui, $opt) {
return $qui['statut'] == '0minirezo' AND !$qui['restreint'];
return $qui['statut'] == '0minirezo' and !$qui['restreint'];
}
// supprimer
function autoriser_abonnement_supprimer_dist($faire, $type, $id, $qui, $opt) {
return $qui['statut'] == '0minirezo' AND !$qui['restreint'];
return $qui['statut'] == '0minirezo' and !$qui['restreint'];
}

@ -1,4 +1,5 @@
<?php
/**
* Fonctions utiles au plugin Abonnements
*
@ -31,10 +32,10 @@ function filtre_abonnements_afficher_duree_dist($duree, $periode) {
$texte = '';
// Simplifions certaines durées
$simplifier = array(
'heure' => array('modulo' => 24, 'periode' => 'jour'),
'mois' => array('modulo' => 12, 'periode' => 'an'),
);
$simplifier = [
'heure' => ['modulo' => 24, 'periode' => 'jour'],
'mois' => ['modulo' => 12, 'periode' => 'an'],
];
if (
isset($simplifier[$periode])
and (($duree % $simplifier[$periode]['modulo']) === 0)
@ -50,8 +51,8 @@ function filtre_abonnements_afficher_duree_dist($duree, $periode) {
if (substr($periode, -1, 1) !== 's') {
$periode .= 's';
}
$texte = _T("abonnementsoffre:info_nb_$periode", array('nb' => $duree));
$texte = _T("abonnementsoffre:info_nb_$periode", ['nb' => $duree]);
}
return $texte;
}
}

@ -5,8 +5,10 @@
* (c) 2012 Les Développements Durables
* Licence GNU/GPL v3
*/
if (!defined('_ECRIRE_INC_VERSION'))
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Optimiser la base de donnees des abonnements
@ -18,20 +20,21 @@ function abonnements_optimiser_base_disparus($flux) {
//Offres d'abonnement à la poubelle
$mydate = sql_quote(trim($flux['args']['date'], "'"));
sql_delete("spip_abonnements_offres", "statut='poubelle' AND maj < $mydate");
sql_delete('spip_abonnements_offres', "statut='poubelle' AND maj < $mydate");
//Supprimer les abonnements lies à une offre d'abonnement inexistante
$res = sql_select("DISTINCT abonnements.id_abonnements_offre", "spip_abonnements AS abonnements
$res = sql_select('DISTINCT abonnements.id_abonnements_offre', 'spip_abonnements AS abonnements
LEFT JOIN spip_abonnements_offres AS offres
ON abonnements.id_abonnements_offre=offres.id_abonnements_offre", "offres.id_abonnements_offre IS NULL");
while ($row = sql_fetch($res))
sql_delete("spip_abonnements", "id_abonnements_offre=" . $row['id_abonnements_offre']);
ON abonnements.id_abonnements_offre=offres.id_abonnements_offre', 'offres.id_abonnements_offre IS NULL');
while ($row = sql_fetch($res)) {
sql_delete('spip_abonnements', 'id_abonnements_offre=' . $row['id_abonnements_offre']);
}
//Abonnements à la poubelle
sql_delete("spip_abonnements", "statut='poubelle' AND maj < $mydate");
sql_delete('spip_abonnements', "statut='poubelle' AND maj < $mydate");
include_spip('action/editer_liens');
$flux['data'] += objet_optimiser_liens(array('abonnement' => '*'), '*');
$flux['data'] += objet_optimiser_liens(['abonnement' => '*'], '*');
return $flux;
}
@ -60,10 +63,10 @@ function abonnements_post_edition($flux) {
// Si on a mis l'abonnement inactif ou à la poubelle, on doit enlever les tâches liées
if (
isset($flux['data']['statut'])
and in_array($flux['data']['statut'], array('inactif', 'poubelle'))
and in_array($flux['data']['statut'], ['inactif', 'poubelle'])
) {
include_spip('action/editer_liens');
$liens = objet_trouver_liens(array('job' => '*'), array('abonnement' => $abonnement['id_abonnement']));
$liens = objet_trouver_liens(['job' => '*'], ['abonnement' => $abonnement['id_abonnement']]);
if ($liens and is_array($liens)) {
// Et on les supprime toutes !
foreach ($liens as $lien) {
@ -80,12 +83,13 @@ function abonnements_post_edition($flux) {
// On lie cet abonnement avec la commande qui l'a généré
include_spip('action/editer_liens');
objet_associer(
array('commande' => $id_commande), array('abonnement' => $id_abonnement)
['commande' => $id_commande],
['abonnement' => $id_abonnement]
);
}
$modifs = array();
$modifs_instituer = array();
$modifs = [];
$modifs_instituer = [];
// Si l'échéance est VIDE, et que pourtant l'offre parente A BIEN une durée
// alors c'est qu'il faut initialiser les dates !
@ -110,8 +114,8 @@ function abonnements_post_edition($flux) {
and $jourdhui <= $abonnement['date_echeance']
) {
$modifs_instituer['statut'] = 'actif';
spip_log("Post-édition : passage de labonnement $id_abonnement en actif", 'abonnements.'._LOG_INFO);
spip_log($abonnement, 'abonnements.'._LOG_INFO);
spip_log("Post-édition : passage de labonnement $id_abonnement en actif", 'abonnements.' . _LOG_INFO);
spip_log($abonnement, 'abonnements.' . _LOG_INFO);
}
// Si aujourd'hui est en dehors des dates début et FIN, on désactive
// on ne teste pas date_echeance car ce sera à un génie de désactiver si trop dépassée
@ -128,8 +132,8 @@ function abonnements_post_edition($flux) {
)
) {
$modifs_instituer['statut'] = 'inactif';
spip_log("Post-édition : passage de labonnement $id_abonnement en inactif", 'abonnements.'._LOG_INFO);
spip_log($abonnement, 'abonnements.'._LOG_INFO);
spip_log("Post-édition : passage de labonnement $id_abonnement en inactif", 'abonnements.' . _LOG_INFO);
spip_log($abonnement, 'abonnements.' . _LOG_INFO);
}
}
@ -146,7 +150,7 @@ function abonnements_post_edition($flux) {
}
// Détection magique du plugin Commandes et d'une commande d'offre d'abonnement
elseif (
// Si on institue une commande
// Si on institue une commande
$flux['args']['table'] == 'spip_commandes'
and $id_commande = intval($flux['args']['id_objet'])
and $flux['args']['action'] == 'instituer'
@ -169,7 +173,7 @@ function abonnements_post_edition($flux) {
// on force toujours la création d'un nouvel abonnement
$forcer_creation = false;
if (
in_array($commande['echeances_type'], array('mois', 'annee'))
in_array($commande['echeances_type'], ['mois', 'annee'])
and include_spip('inc/commandes_echeances')
and commandes_nb_echeances_payees($id_commande) <= 1
) {
@ -215,14 +219,16 @@ function abonnements_taches_generales_cron($taches) {
* @return array
*/
function abonnements_affiche_gauche($flux) {
if (isset($flux['args']['exec'])
if (
isset($flux['args']['exec'])
and $flux['args']['exec'] == 'abonnements_offre'
and isset($flux['args']['id_abonnements_offre'])
) {
$flux['data'] .= recuperer_fond(
'prive/squelettes/navigation/inc-abonnements_notifications', array(
'prive/squelettes/navigation/inc-abonnements_notifications',
[
'id_abonnements_offre' => $flux['args']['id_abonnements_offre']
)
]
);
}
@ -234,7 +240,7 @@ function abonnements_affiche_gauche($flux) {
*/
function abonnements_affiche_milieu($flux) {
$e = trouver_objet_exec($flux['args']['exec']);
// Sur la page des auteurs
if (
is_array($e)
@ -243,11 +249,11 @@ function abonnements_affiche_milieu($flux) {
) {
$id_auteur = $flux['args']['id_auteur'];
$ins = recuperer_fond('prive/squelettes/inclure/abonnements_auteur', array('id_auteur' => $id_auteur));
if (($p = strpos($flux['data'], "<!--affiche_milieu-->")) !== false)
$ins = recuperer_fond('prive/squelettes/inclure/abonnements_auteur', ['id_auteur' => $id_auteur]);
if (($p = strpos($flux['data'], '<!--affiche_milieu-->')) !== false) {
$flux['data'] = substr_replace($flux['data'], $ins, $p, 0);
else
$flux['data'] .= $ins;
} else { $flux['data'] .= $ins;
}
}
return $flux;
@ -258,22 +264,22 @@ function abonnements_affiche_milieu($flux) {
*/
function abonnements_affiche_enfants($flux) {
$e = trouver_objet_exec($flux['args']['exec']);
// Sur la page d'un objet s'il fait partie de la config
if (
is_array($e)
and !$e['edition']
and in_array($e['table_objet_sql'], lire_config('abonnements/objets', array()))
and in_array($e['table_objet_sql'], lire_config('abonnements/objets', []))
and $texte = recuperer_fond(
'prive/objets/editer/liens',
array(
[
'table_source' => 'abonnements_offres',
'objet' => $e['type'],
'id_objet' => $flux['args']['id_objet']
)
]
)
) {
if ($p=strpos($flux['data'], '<!--affiche_milieu-->')) {
if ($p = strpos($flux['data'], '<!--affiche_milieu-->')) {
$flux['data'] = substr_replace($flux['data'], $texte, $p, 0);
} else {
$flux['data'] .= $texte;
@ -291,7 +297,7 @@ function abonnements_affiche_enfants($flux) {
*/
function abonnements_affiche_hierarchie($flux) {
include_spip('inc/config');
// Sur la page d'une offre
if (
$flux['args']['objet'] == 'abonnements_offre'
@ -299,14 +305,16 @@ function abonnements_affiche_hierarchie($flux) {
) {
include_spip('action/editer_liens');
$objets = array_map('objet_type', $objets);
// On cherche si cette offre à des liens
if ($liens = objet_trouver_liens(
array('abonnements_offre' => $flux['args']['id_objet']),
array('*' => '*')
)) {
$liens_parents = array();
$liens_offres = array();
if (
$liens = objet_trouver_liens(
['abonnements_offre' => $flux['args']['id_objet']],
['*' => '*']
)
) {
$liens_parents = [];
$liens_offres = [];
foreach ($liens as $lien) {
// Seulement si ce lien est actuellement prévu dans la config
if (in_array($lien['objet'], $objets)) {
@ -319,18 +327,18 @@ function abonnements_affiche_hierarchie($flux) {
}
}
}
if ($liens_parents) {
$liens_parents = PtoBR(propre(_T('abonnementsoffre:liens_parents_label') . join(', ', $liens_parents)));
$flux['data'] .= '<div class="parents_offres">'.$liens_parents.'</div>';
$flux['data'] .= '<div class="parents_offres">' . $liens_parents . '</div>';
}
if ($liens_offres) {
$liens_offres = PtoBR(propre(_T('abonnementsoffre:liens_offres_label') . join(', ', $liens_offres)));
$flux['data'] .= '<div class="liens_offres">'.$liens_offres.'</div>';
$flux['data'] .= '<div class="liens_offres">' . $liens_offres . '</div>';
}
}
}
return $flux;
}

@ -1,45 +1,46 @@
<?php
// Sécurité
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) { return;
}
/**
* Action de modif de l'échéance d'un abonnement
* @param unknown_type $arg
* @return unknown_type
*/
function action_modifier_echeance_abonnement_dist($arg=null) {
if (is_null($arg)){
function action_modifier_echeance_abonnement_dist($arg = null) {
if (is_null($arg)) {
$securiser_action = charger_fonction('securiser_action', 'inc');
$arg = $securiser_action();
}
list($id_abonnement, $duree, $periode) = explode('/', $arg);
// Si on a bien un abonnement et qu'on a le droit de le modifier et qu'on a une durée != 0
if (
$duree = intval($duree)
and $id_abonnement = intval($id_abonnement)
and autoriser('modifier', 'abonnement', $id_abonnement)
and $abonnement = sql_fetsel('date_debut, date_echeance, date_fin', 'spip_abonnements', 'id_abonnement = '.$id_abonnement)
and $abonnement = sql_fetsel('date_debut, date_echeance, date_fin', 'spip_abonnements', 'id_abonnement = ' . $id_abonnement)
) {
$jourdhui = date('Y-m-d H:i:s');
// Calculons la date de départ du renouvellement
// Par défaut on part de la dernière échéance
$date_depart = $abonnement['date_echeance'];
// Si la date d'échéance n'était pas encore définie, on reprend depuis le début
if ($date_depart == '0000-00-00 00:00:00'){
if ($date_depart == '0000-00-00 00:00:00') {
$date_depart = $abonnement['date_debut'];
}
// Et si la date d'échéance était *déjà passée*, alors on renouvelle *à partir d'aujourd'hui* !
elseif ($date_depart < $jourdhui) {
$date_depart = $jourdhui;
}
// De combien doit-on modifier la date
switch ($periode){
switch ($periode) {
case 'heures':
$ajout = " ${duree} hours";
break;
@ -50,21 +51,21 @@ function action_modifier_echeance_abonnement_dist($arg=null) {
$ajout = " ${duree} months";
break;
default:
$ajout ='';
$ajout = '';
break;
}
// Si la période existe
if ($ajout){
$modifications = array();
if ($ajout) {
$modifications = [];
// Si la durée est positive, on ajoute un + devant (le - est déjà là pour les négatives)
if ($duree > 0){
$ajout = ' +'.$ajout;
if ($duree > 0) {
$ajout = ' +' . $ajout;
}
// Calcul de la date de fin
$modifications['date_echeance'] = date('Y-m-d H:i:s', strtotime($date_depart.$ajout));
$modifications['date_echeance'] = date('Y-m-d H:i:s', strtotime($date_depart . $ajout));
// Si la date de fin n'est PAS infinie ET qu'elle se retrouve plus petite que l'échéance
// On la remet au moins au même endroit que la nouvelle échéance
if (
@ -73,14 +74,14 @@ function action_modifier_echeance_abonnement_dist($arg=null) {
) {
$modifications['date_fin'] = $modifications['date_echeance'];
}
// On lance la modification
include_spip('action/editer_objet');
$erreur = objet_modifier('abonnement', $id_abonnement, $modifications);
return array($id_abonnement, $erreur);
return [$id_abonnement, $erreur];
}
}
return false;
}

@ -1,32 +1,32 @@
<?php
// Sécurité
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) { return;
}
/**
* Action de renouveler un abonnement
* @param int $arg
* @return unknown_type
*/
function action_renouveler_abonnement_dist($arg=null) {
if (is_null($arg)){
function action_renouveler_abonnement_dist($arg = null) {
if (is_null($arg)) {
$securiser_action = charger_fonction('securiser_action', 'inc');
$arg = $securiser_action();
}
// Si on a bien un abonnement et qu'on a le droit de le modifier
if (
$id_abonnement = intval($arg)
and autoriser('modifier', 'abonnement', $id_abonnement)
and $abonnement = sql_fetsel('id_abonnements_offre, date_debut, date_fin', 'spip_abonnements', 'id_abonnement = '.$id_abonnement)
and $offre = sql_fetsel('duree, periode', 'spip_abonnements_offres', 'id_abonnements_offre = '.$abonnement['id_abonnements_offre'])
and $abonnement = sql_fetsel('id_abonnements_offre, date_debut, date_fin', 'spip_abonnements', 'id_abonnement = ' . $id_abonnement)
and $offre = sql_fetsel('duree, periode', 'spip_abonnements_offres', 'id_abonnements_offre = ' . $abonnement['id_abonnements_offre'])
and $offre['duree'] > 0
and $offre['periode']
) {
$action = charger_fonction('modifier_echeance_abonnement', 'action/');
return $action($id_abonnement.'/'.$offre['duree'].'/'.$offre['periode']);
return $action($id_abonnement . '/' . $offre['duree'] . '/' . $offre['periode']);
}
return false;
}

@ -4,12 +4,12 @@ if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function action_resilier_abonnement($id_abonnement=null) {
function action_resilier_abonnement($id_abonnement = null) {
if (is_null($id_abonnement)) {
$securiser_action = charger_fonction('securiser_action', 'inc');
$id_abonnement = $securiser_action();
}
if (
$id_abonnement = intval($id_abonnement)
and $id_abonnement > 0
@ -18,24 +18,24 @@ function action_resilier_abonnement($id_abonnement=null) {
) {
include_spip('action/editer_objet');
include_spip('inc/abonnements');
// L'abonnement SPIP sera désactivé à la fin de l'échéance, on force donc cette date de fin, et on reprogramme dès maintenant la désactivation
$date_echeance = sql_getfetsel('date_echeance', 'spip_abonnements', 'id_abonnement = '.$id_abonnement);
objet_modifier('abonnement', $id_abonnement, array(
$date_echeance = sql_getfetsel('date_echeance', 'spip_abonnements', 'id_abonnement = ' . $id_abonnement);
objet_modifier('abonnement', $id_abonnement, [
'date_fin' => $date_echeance,
));
]);
abonnements_programmer_desactivation($id_abonnement, $date_echeance);
// Si on détecte qu'il est lié à un prélèvement bancaire, on lance une résiliation par l'API
if (
defined('_DIR_PLUGIN_COMMANDES')
and defined('_DIR_PLUGIN_BANK')
and include_spip('action/editer_liens')
and $liens = objet_trouver_liens(array('commande' => '*'), array('abonnement' => $id_abonnement))
and $liens = objet_trouver_liens(['commande' => '*'], ['abonnement' => $id_abonnement])
and is_array($liens)
// On prend juste la première commande qu'on trouve
and $id_commande = intval($liens[0]['id_commande'])
and $bank_uid = sql_getfetsel('bank_uid', 'spip_commandes', 'id_commande = '.$id_commande)
and $bank_uid = sql_getfetsel('bank_uid', 'spip_commandes', 'id_commande = ' . $id_commande)
) {
include_spip('abos/resilier');
abos_resilier_notify_bank($bank_uid);

@ -5,8 +5,10 @@
* (c) 2012 Les Développements Durables
* Licence GNU/GPL v3
*/
if (!defined('_ECRIRE_INC_VERSION'))
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Déclaration des alias de tables et filtres automatiques de champs
@ -23,52 +25,52 @@ function abonnements_declarer_tables_interfaces($interfaces) {
* Déclaration des objets éditoriaux
*/
function abonnements_declarer_tables_objets_sql($tables) {
$tables['spip_abonnements_offres'] = array(
$tables['spip_abonnements_offres'] = [
'type' => 'abonnements_offre',
'principale' => "oui",
'table_objet_surnoms' => array('abonnementsoffre'), // table_objet('abonnement') => 'abonnements_offres'
'field' => array(
"id_abonnements_offre" => "bigint(21) NOT NULL",
"titre" => "text NOT NULL DEFAULT ''",
"descriptif" => "text NOT NULL DEFAULT ''",
"duree" => "int(11) NOT NULL DEFAULT 0",
"periode" => "varchar(25) NOT NULL DEFAULT ''",
'principale' => 'oui',
'table_objet_surnoms' => ['abonnementsoffre'], // table_objet('abonnement') => 'abonnements_offres'
'field' => [
'id_abonnements_offre' => 'bigint(21) NOT NULL',
'titre' => "text NOT NULL DEFAULT ''",
'descriptif' => "text NOT NULL DEFAULT ''",
'duree' => 'int(11) NOT NULL DEFAULT 0',
'periode' => "varchar(25) NOT NULL DEFAULT ''",
'prix_ht' => 'decimal(20,6) not null default 0',
"taxe" => "decimal(4,4) default 0",
'taxe' => 'decimal(4,4) default 0',
'immateriel' => 'varchar(3) default "on"',
"statut" => "varchar(20) DEFAULT '0' NOT NULL",
"maj" => "TIMESTAMP"
),
'key' => array(
"PRIMARY KEY" => "id_abonnements_offre",
"KEY statut" => "statut",
),
'statut' => "varchar(20) DEFAULT '0' NOT NULL",
'maj' => 'TIMESTAMP'
],
'key' => [
'PRIMARY KEY' => 'id_abonnements_offre',
'KEY statut' => 'statut',
],
'titre' => "titre AS titre, '' AS lang",
#'date' => "",
'champs_editables' => array('titre', 'descriptif', 'duree', 'periode', 'prix_ht', 'taxe', 'immateriel'),
'champs_versionnes' => array('titre', 'descriptif', 'duree', 'periode', 'prix_ht', 'taxe', 'immateriel'),
'rechercher_champs' => array("titre" => 10, "descriptif" => 5),
'tables_jointures' => array('spip_abonnements_offres_liens'),
'statut_textes_instituer' => array(
'champs_editables' => ['titre', 'descriptif', 'duree', 'periode', 'prix_ht', 'taxe', 'immateriel'],
'champs_versionnes' => ['titre', 'descriptif', 'duree', 'periode', 'prix_ht', 'taxe', 'immateriel'],
'rechercher_champs' => ['titre' => 10, 'descriptif' => 5],
'tables_jointures' => ['spip_abonnements_offres_liens'],
'statut_textes_instituer' => [
'prepa' => 'texte_statut_en_cours_redaction',
'prive' => 'abonnementsoffre:statut_prive',
'publie' => 'abonnementsoffre:statut_publie',
'poubelle' => 'texte_statut_poubelle',
),
'statut_images' => array(
],
'statut_images' => [
'prepa' => 'puce-preparer-8.png',
'prive' => 'puce-refuser-8.png',
'publie' => 'puce-publier-8.png',
'poubelle' => 'puce-supprimer-8.png',
),
'statut' => array(
array(
],
'statut' => [
[
'champ' => 'statut',
'publie' => 'publie',
'previsu' => 'publie,prepa',
'exception' => array('statut', 'tout')
)
),
'exception' => ['statut', 'tout']
]
],
'texte_modifier' => 'abonnementsoffre:icone_modifier_abonnementsoffre',
'texte_creer' => 'abonnementsoffre:icone_creer_abonnementsoffre',
'texte_creer_associer' => 'abonnementsoffre:texte_creer_associer_abonnementsoffre',
@ -81,59 +83,59 @@ function abonnements_declarer_tables_objets_sql($tables) {
'info_1_objet' => 'abonnementsoffre:info_1_abonnementsoffre',
'info_nb_objets' => 'abonnementsoffre:info_nb_abonnementsoffres',
'texte_changer_statut' => 'abonnementsoffre:texte_changer_statut_abonnementsoffre',
);
];
$tables['spip_abonnements'] = array(
$tables['spip_abonnements'] = [
'type' => 'abonnement',
'principale' => "oui",
'principale' => 'oui',
# 'url_voir' => false,
# 'url_edit' => false,
'field' => array(
"id_abonnement" => "bigint(21) NOT NULL",
"id_abonnements_offre" => "bigint(21) NOT NULL DEFAULT 0",
"id_auteur" => "bigint(21) NOT NULL DEFAULT 0",
"date_debut" => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'",
"date_echeance" => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'",
"date_fin" => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'",
"statut" => "varchar(20) DEFAULT '0' NOT NULL",
"maj" => "TIMESTAMP"
),
'key' => array(
"PRIMARY KEY" => "id_abonnement",
"KEY statut" => "statut",
"KEY id_abonnements_offre" => "id_abonnements_offre",
"KEY id_auteur" => "id_auteur",
),
'field' => [
'id_abonnement' => 'bigint(21) NOT NULL',
'id_abonnements_offre' => 'bigint(21) NOT NULL DEFAULT 0',
'id_auteur' => 'bigint(21) NOT NULL DEFAULT 0',
'date_debut' => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'",
'date_echeance' => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'",
'date_fin' => "datetime NOT NULL DEFAULT '0000-00-00 00:00:00'",
'statut' => "varchar(20) DEFAULT '0' NOT NULL",
'maj' => 'TIMESTAMP'
],
'key' => [
'PRIMARY KEY' => 'id_abonnement',
'KEY statut' => 'statut',
'KEY id_abonnements_offre' => 'id_abonnements_offre',
'KEY id_auteur' => 'id_auteur',
],
'titre' => "'' AS titre, '' AS lang",
'date' => "maj",
'champs_editables' => array('id_abonnements_offre', 'id_auteur', 'date_debut', 'date_echeance', 'date_fin'),
'champs_versionnes' => array('id_abonnements_offre', 'id_auteur', 'date_debut', 'date_echeance', 'date_fin'),
'rechercher_champs' => array('date_echeance ' => 1),
'rechercher_jointures' => array(
'auteur' => array('nom' => 10, 'email' => 10),
),
'tables_jointures' => array(),
'join' => array('id_auteur' => 'id_auteur'),
'statut_textes_instituer' => array(
'date' => 'maj',
'champs_editables' => ['id_abonnements_offre', 'id_auteur', 'date_debut', 'date_echeance', 'date_fin'],
'champs_versionnes' => ['id_abonnements_offre', 'id_auteur', 'date_debut', 'date_echeance', 'date_fin'],
'rechercher_champs' => ['date_echeance ' => 1],
'rechercher_jointures' => [
'auteur' => ['nom' => 10, 'email' => 10],
],
'tables_jointures' => [],
'join' => ['id_auteur' => 'id_auteur'],
'statut_textes_instituer' => [
'inactif' => 'abonnement:statut_inactif',
'actif' => 'abonnement:statut_actif',
'poubelle' => 'texte_statut_poubelle',
),
'statut_images' => array(
],
'statut_images' => [
'inactif' => 'puce-refuser-8.png',
'actif' => 'puce-publier-8.png',
'poubelle' => 'puce-supprimer-8.png',
),
'statut' => array(
array(
],
'statut' => [
[
'champ' => 'statut',
'publie' => 'actif',
'previsu' => 'actif,inactif',
'exception' => array('statut', 'tout')
)
),
'exception' => ['statut', 'tout']
]
],
'texte_changer_statut' => 'abonnement:texte_changer_statut_abonnement',
);
];
return $tables;
}
@ -143,19 +145,19 @@ function abonnements_declarer_tables_objets_sql($tables) {
*/
function abonnements_declarer_tables_principales($tables) {
$tables['spip_abonnements_offres_notifications'] = array(
'field' => array(
$tables['spip_abonnements_offres_notifications'] = [
'field' => [
'id_abonnements_offres_notification' => 'bigint(21) not null',
'id_abonnements_offre' => 'bigint(21) DEFAULT 0 NOT NULL',
'duree' => 'int(11) NOT NULL DEFAULT 0',
'periode' => 'varchar(25) NOT NULL DEFAULT ""',
'quand' => 'ENUM("avant","apres","pendant") DEFAULT "avant" NOT NULL',
),
'key' => array(
],
'key' => [
'PRIMARY KEY' => 'id_abonnements_offres_notification',
'KEY id_abonnements_offre' => 'id_abonnements_offre',
),
);
],
];
return $tables;
}
@ -164,18 +166,18 @@ function abonnements_declarer_tables_principales($tables) {
* Déclaration des tables secondaires (liaisons)
*/
function abonnements_declarer_tables_auxiliaires($tables) {
$tables['spip_abonnements_offres_liens'] = array(
'field' => array(
"id_abonnements_offre" => "bigint(21) DEFAULT '0' NOT NULL",
"id_objet" => "bigint(21) DEFAULT '0' NOT NULL",
"objet" => "VARCHAR(25) DEFAULT '' NOT NULL",
"vu" => "VARCHAR(6) DEFAULT 'non' NOT NULL"
),
'key' => array(
"PRIMARY KEY" => "id_abonnements_offre,id_objet,objet",
"KEY id_abonnements_offre" => "id_abonnements_offre"
)
);
$tables['spip_abonnements_offres_liens'] = [
'field' => [
'id_abonnements_offre' => "bigint(21) DEFAULT '0' NOT NULL",
'id_objet' => "bigint(21) DEFAULT '0' NOT NULL",
'objet' => "VARCHAR(25) DEFAULT '' NOT NULL",
'vu' => "VARCHAR(6) DEFAULT 'non' NOT NULL"
],
'key' => [
'PRIMARY KEY' => 'id_abonnements_offre,id_objet,objet',
'KEY id_abonnements_offre' => 'id_abonnements_offre'
]
];
return $tables;
}

@ -5,16 +5,16 @@ if (!defined('_ECRIRE_INC_VERSION')) {
}
function formulaires_configurer_abonnements_saisies_dist() {
$saisies = array(
array(
$saisies = [
[
'saisie' => 'choisir_objets',
'options' => array(
'options' => [
'nom' => 'objets',
'label' => _T('abonnementsoffre:configurer_objets_label'),
'explication' => _T('abonnementsoffre:configurer_objets_explication'),
),
),
);
],
],
];
return $saisies;
}

@ -1,11 +1,13 @@
<?php
/**
* Plugin Abonnements
* (c) 2012 Les Développements Durables
* Licence GNU/GPL v3
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) { return;
}
include_spip('inc/actions');
include_spip('inc/editer');
@ -13,117 +15,117 @@ include_spip('inc/editer');
/*
* Déclaration des champs du formulaire
*/
function formulaires_editer_abonnement_saisies_dist($id_abonnement='new', $retour='', $lier_trad=0, $config_fonc='', $row=array(), $hidden=''){
function formulaires_editer_abonnement_saisies_dist($id_abonnement = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
$id_abonnement = intval($id_abonnement);
// Si c'est une demande de création et qu'on trouve une offre, on ne doit donner que l'utilisateur et l'abonnement est défini caché
if ($id_abonnement == 0 and $id_abonnements_offre = _request('id_abonnements_offre')) {
$saisies = array(
array(
$saisies = [
[
'saisie' => 'hidden',
'options' => array(
'options' => [
'nom' => 'id_abonnements_offre',
'defaut' => $id_abonnements_offre,
),
),
array(
],
],
[
'saisie' => 'auteurs',
'options' => array(
'options' => [
'nom' => 'id_auteur',
'label' => _T('abonnement:champ_id_auteur_label'),
'obligatoire' => 'oui',
'cacher_option_intro' => 'oui',
),
),
);
],
],
];
}
// Sinon si c'est une demande de création et qu'on trouve un auteur, on ne doit donner que les offres et l'utilisateur est défini caché
elseif ($id_abonnement == 0 and $id_auteur = _request('id_auteur')) {
$saisies = array(
array(
$saisies = [
[
'saisie' => 'hidden',
'options' => array(
'options' => [
'nom' => 'id_auteur',
'defaut' => $id_auteur,
),
),
array(
],
],
[
'saisie' => 'abonnements_offres',
'options' => array(
'options' => [
'nom' => 'id_abonnements_offre',
'label' => _T('abonnement:champ_id_abonnements_offre_label'),
'obligatoire' => 'oui',
'cacher_option_intro' => 'oui',
),
),
);
],
],
];
}
// Sinon si c'est une demande de modification, on ne peut modifier que les dates
elseif ($id_abonnement > 0) {
$saisies = array(
array(
$saisies = [
[
'saisie' => 'date',
'options' => array(
'options' => [
'nom' => 'date_debut',
'label' => _T('abonnement:champ_date_debut_label'),
'horaire' => 'on',
'heure_pas' => 5,
),
'verifier' => array(
],
'verifier' => [
'type' => 'date',
'options' => array(
'options' => [
'normaliser' => 'datetime',
),
),
),
array(
],
],
],
[
'saisie' => 'date',
'options' => array(
'options' => [
'nom' => 'date_echeance',
'label' => _T('abonnement:champ_date_echeance_label'),
'horaire' => 'on',
'heure_pas' => 5,
),
'verifier' => array(
],
'verifier' => [
'type' => 'date',
'options' => array(
'options' => [
'normaliser' => 'datetime',
),
),
),
array(
],
],
],
[
'saisie' => 'date',
'options' => array(
'options' => [
'nom' => 'date_fin',
'label' => _T('abonnement:champ_date_fin_label'),
'horaire' => 'on',
'heure_pas' => 5,
),
'verifier' => array(
],
'verifier' => [
'type' => 'date',
'options' => array(
'options' => [
'normaliser' => 'datetime',
),
),
),
);
],
],
],
];
}
return $saisies;
}
/**
* Identifier le formulaire en faisant abstraction des parametres qui ne representent pas l'objet edite
*/
function formulaires_editer_abonnement_identifier_dist($id_abonnement='new', $retour='', $lier_trad=0, $config_fonc='', $row=array(), $hidden=''){
return serialize(array(intval($id_abonnement)));
function formulaires_editer_abonnement_identifier_dist($id_abonnement = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
return serialize([intval($id_abonnement)]);
}
/**
* Declarer les champs postes et y integrer les valeurs par defaut
*/
function formulaires_editer_abonnement_charger_dist($id_abonnement='new', $retour='', $lier_trad=0, $config_fonc='', $row=array(), $hidden=''){
$valeurs = formulaires_editer_objet_charger('abonnement',$id_abonnement,'',$lier_trad,$retour,$config_fonc,$row,$hidden);
function formulaires_editer_abonnement_charger_dist($id_abonnement = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
$valeurs = formulaires_editer_objet_charger('abonnement', $id_abonnement, '', $lier_trad, $retour, $config_fonc, $row, $hidden);
unset($valeurs['id_abonnement']);
return $valeurs;
}
@ -131,27 +133,27 @@ function formulaires_editer_abonnement_charger_dist($id_abonnement='new', $retou
/**
* Verifier les champs postes et signaler d'eventuelles erreurs
*/
function formulaires_editer_abonnement_verifier_dist($id_abonnement='new', $retour='', $lier_trad=0, $config_fonc='', $row=array(), $hidden=''){
$erreurs = array();//formulaires_editer_objet_verifier('abonnement',$id_abonnement);
function formulaires_editer_abonnement_verifier_dist($id_abonnement = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
$erreurs = [];//formulaires_editer_objet_verifier('abonnement',$id_abonnement);
// Pour une création on vérifie l'offre
if (
!intval($id_abonnement)
and (
!$id_abonnements_offre = _request('id_abonnements_offre')
or !sql_getfetsel('id_abonnements_offre', 'spip_abonnements_offres', 'id_abonnements_offre = '.intval($id_abonnements_offre))
or !sql_getfetsel('id_abonnements_offre', 'spip_abonnements_offres', 'id_abonnements_offre = ' . intval($id_abonnements_offre))
)
) {
$erreurs['message_erreur'] = _T('abonnement:erreur_id_abonnements_offre');
}
return $erreurs;
}
/**
* Traiter les champs postes
*/
function formulaires_editer_abonnement_traiter_dist($id_abonnement='new', $retour='', $lier_trad=0, $config_fonc='', $row=array(), $hidden=''){
function formulaires_editer_abonnement_traiter_dist($id_abonnement = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
# // Si c'est pour une modif on appelle l'allongement
# if (intval($id_abonnement) > 0) {
# // On récupère les champs qui ne font pas partie de la table
@ -162,16 +164,17 @@ function formulaires_editer_abonnement_traiter_dist($id_abonnement='new', $retou
# $modifier_echeance("$id_abonnement/$duree/$periode");
# }
// Normaliser les dates vides pour éviter une erreur SQL
foreach(array('date_debut', 'date_echeance', 'date_fin') as $champ_date){
if ($date = _request($champ_date)
foreach (['date_debut', 'date_echeance', 'date_fin'] as $champ_date) {
if (
$date = _request($champ_date)
and is_array($date)
and !count(array_filter(array_values($date)))
){
) {
set_request($champ_date, '0000-00-00 00:00:00');
}
}
$retours = formulaires_editer_objet_traiter('abonnement',$id_abonnement,'',$lier_trad,$retour,$config_fonc,$row,$hidden);
$retours = formulaires_editer_objet_traiter('abonnement', $id_abonnement, '', $lier_trad, $retour, $config_fonc, $row, $hidden);
return $retours;
}

@ -5,8 +5,10 @@
* (c) 2012 Les Développements Durables
* Licence GNU/GPL v3
*/
if (!defined('_ECRIRE_INC_VERSION'))
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
include_spip('inc/actions');
include_spip('inc/editer');
@ -15,114 +17,114 @@ include_spip('inc/editer');
* Déclaration des champs du formulaire
*/
function formulaires_editer_abonnements_offre_saisies_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') {
function formulaires_editer_abonnements_offre_saisies_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
$taxe_default = lire_config('produits/taxe', 0);
return array(
array(
return [
[
'saisie' => 'input',
'options' => array(
'options' => [
'nom' => 'titre',
'label' => _T('abonnementsoffre:champ_titre_label'),
'obligatoire' => 'oui',
),
),
array(
],
],
[
'saisie' => 'textarea',
'options' => array(
'options' => [
'nom' => 'descriptif',
'label' => _T('abonnementsoffre:champ_descriptif_label'),
'rows' => 10,
'inserer_barre' => 'edition',
),
),
array(
],
],
[
'saisie' => 'input',
'options' => array(
'options' => [
'nom' => 'duree',
'label' => _T('abonnementsoffre:champ_duree_label'),
'obligatoire' => 'oui',
'defaut' => 0,
),
'verifier' => array(
],
'verifier' => [
'type' => 'entier',
'options' => array(
'options' => [
'min' => 0,
),
),
),
array(
],
],
],
[
'saisie' => 'selection',
'options' => array(
'options' => [
'nom' => 'periode',
'label' => _T('abonnementsoffre:champ_periode_label'),
'obligatoire' => 'oui',
'cacher_option_intro' => 'oui',
'data' => array(
'data' => [
'mois' => _T('abonnementsoffre:champ_periode_choix_mois'),
'jours' => _T('abonnementsoffre:champ_periode_choix_jours'),
'heures' => _T('abonnementsoffre:champ_periode_choix_heures'),
),
],
'defaut' => 'mois',
),
),
array(
],
],
[
'saisie' => 'input',
'options' => array(
'options' => [
'nom' => 'prix_ht',
'label' => _T('abonnementsoffre:champ_prix_ht_label'),
'obligatoire' => 'oui',
'defaut' => 0,
),
'verifier' => array(
],
'verifier' => [
'type' => 'decimal',
'options' => array(
'options' => [
'min' => 0,
),
),
),
array(
],
],
],
[
'saisie' => 'input',
'options' => array(
'options' => [
'nom' => 'taxe',
'label' => _T('abonnementsoffre:champ_taxe_label'),
'obligatoire' => 'oui',
'defaut' => $taxe_default,
),
'verifier' => array(
],
'verifier' => [
'type' => 'decimal',
'options' => array(
'options' => [
'min' => 0,
'max' => 100
),
),
),
array(
],
],
],
[
'saisie' => 'case',
'options' => array(
'options' => [
'nom' => 'immateriel',
'label' => _T('abonnementsoffre:champ_immateriel_label'),
'label_case' => _T('abonnementsoffre:champ_immateriel_label_case'),
),
),
);
],
],
];
}
/**
* Identifier le formulaire en faisant abstraction des parametres qui ne representent pas l'objet edite
*/
function formulaires_editer_abonnements_offre_identifier_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') {
return serialize(array(intval($id_abonnements_offre)));
function formulaires_editer_abonnements_offre_identifier_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
return serialize([intval($id_abonnements_offre)]);
}
/**
* Declarer les champs postes et y integrer les valeurs par defaut
*/
function formulaires_editer_abonnements_offre_charger_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') {
function formulaires_editer_abonnements_offre_charger_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
$valeurs = formulaires_editer_objet_charger('abonnements_offre', $id_abonnements_offre, '', $lier_trad, $retour, $config_fonc, $row, $hidden);
unset($valeurs['id_abonnements_offre']);
if ($valeurs['taxe'] == 0)
if ($valeurs['taxe'] == 0) {
$valeurs['taxe'] = '0';
else {
} else {
$valeurs['taxe'] = $valeurs['taxe'] * 100;
}
return $valeurs;
@ -131,17 +133,15 @@ function formulaires_editer_abonnements_offre_charger_dist($id_abonnements_offre
/**
* Verifier les champs postes et signaler d'eventuelles erreurs
*/
function formulaires_editer_abonnements_offre_verifier_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') {
return formulaires_editer_objet_verifier('abonnements_offre', $id_abonnements_offre, array('titre'));
function formulaires_editer_abonnements_offre_verifier_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
return formulaires_editer_objet_verifier('abonnements_offre', $id_abonnements_offre, ['titre']);
}
/**
* Traiter les champs postes
*/
function formulaires_editer_abonnements_offre_traiter_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = array(), $hidden = '') {
function formulaires_editer_abonnements_offre_traiter_dist($id_abonnements_offre = 'new', $retour = '', $lier_trad = 0, $config_fonc = '', $row = [], $hidden = '') {
$taxe = _request('taxe') / 100;
set_request('taxe', $taxe);
return formulaires_editer_objet_traiter('abonnements_offre', $id_abonnements_offre, '', $lier_trad, $retour, $config_fonc, $row, $hidden);
}
?>

@ -1,94 +1,96 @@
<?php
// Sécurité
if (!defined('_ECRIRE_INC_VERSION')) return;
if (!defined('_ECRIRE_INC_VERSION')) { return;
}
function formulaires_editer_abonnements_offre_notifications_saisies_dist($id_abonnements_offre, $retour=''){
return array(
array(
function formulaires_editer_abonnements_offre_notifications_saisies_dist($id_abonnements_offre, $retour = '') {
return [
[
'saisie' => 'fieldset',
'options' => array(
'options' => [
'nom' => 'fieldset_ajouter',
'label' => _T('abonnementsoffre:champ_ajouter_notification_label'),
'pliable' => 'oui',
'plie' => 'oui',
),
'saisies' => array(
array(
],
'saisies' => [
[
'saisie' => 'selection',
'options' => array(
'options' => [
'nom' => 'quand',
'label' => _T('abonnementsoffre:champ_quand_label'),
'cacher_option_intro' => 'oui',
'data' => array(
'data' => [
'apres' => _T('abonnementsoffre:champ_quand_choix_apres'),
'avant' => _T('abonnementsoffre:champ_quand_choix_avant'),
'pendant' => _T('abonnementsoffre:champ_quand_choix_pendant'),
),
],
'defaut' => 'avant',
),
),
array(
],
],
[
'saisie' => 'input',
'options' => array(
'options' => [
'nom' => 'duree',
'label' => _T('abonnementsoffre:champ_duree_label'),
'defaut' => '',
'afficher_si_remplissage' => '@quand@ !== "pendant"',
),
'verifier' => array(
],
'verifier' => [
'type' => 'entier',
'options' => array(
'options' => [
'min' => 0,
),
),
),
array(
],
],
],
[
'saisie' => 'selection',
'options' => array(
'options' => [
'nom' => 'periode',
'label' => _T('abonnementsoffre:champ_periode_label'),
'cacher_option_intro' => 'oui',
'data' => array(
'data' => [
'mois' => _T('abonnementsoffre:champ_periode_choix_mois'),
'jours' => _T('abonnementsoffre:champ_periode_choix_jours'),
),
],
'defaut' => 'mois',
'afficher_si_remplissage' => '@quand@ !== "pendant"',
),
),
),
),
);
],
],
],
],
];
}
function formulaires_editer_abonnements_offre_notifications_charger_dist($id_abonnements_offre, $retour=''){
if (!$id_abonnements_offre or !autoriser('configurer')){
function formulaires_editer_abonnements_offre_notifications_charger_dist($id_abonnements_offre, $retour = '') {
if (!$id_abonnements_offre or !autoriser('configurer')) {
return false;
}
$contexte = array(
'supprimer' => array(),
$contexte = [
'supprimer' => [],
'id_abonnements_offre' => $id_abonnements_offre,
'_hidden' => '<input type="hidden" name="id_abonnements_offre" value="'.$id_abonnements_offre.'" />',
);
'_hidden' => '<input type="hidden" name="id_abonnements_offre" value="' . $id_abonnements_offre . '" />',
];
return $contexte;
}
function formulaires_editer_abonnements_offre_notifications_verifier_dist($id_abonnements_offre, $retour=''){
$erreurs = array();
if (!$supprimer = _request('supprimer')){
function formulaires_editer_abonnements_offre_notifications_verifier_dist($id_abonnements_offre, $retour = '') {
$erreurs = [];
if (!$supprimer = _request('supprimer')) {
$duree = _request('duree');
$periode = _request('periode');
$quand = _request('quand');
// Normalisons les valeurs pour les notifs le jour même
if ($quand == 'pendant'
if (
$quand == 'pendant'
or (
$quand != 'pendant'
and $duree == 0
)
){
) {
$duree = 0;
$periode = 'jours';
$quand = 'pendant';
@ -98,38 +100,40 @@ function formulaires_editer_abonnements_offre_notifications_verifier_dist($id_ab
}
// Durée obligatoire
// (ne pas utiliser l'option "obligatoire" des saisies car on ne pourrait pas supprimer)
if (!strlen($duree)){
if (!strlen($duree)) {
$erreurs['duree'] = _T('info_obligatoire');
}
// Vérifier les doublons
if (sql_countsel('spip_abonnements_offres_notifications', array(
if (
sql_countsel('spip_abonnements_offres_notifications', [
'id_abonnements_offre = ' . intval($id_abonnements_offre),
'duree = ' . intval($duree),
'periode = ' . sql_quote($periode),
'quand = ' . sql_quote($quand),
))){
])
) {
$erreurs['message_erreur'] = _T('abonnementsoffre:erreur_notification_doublon');
}
}
return $erreurs;
}
function formulaires_editer_abonnements_offre_notifications_traiter_dist($id_abonnements_offre, $retour=''){
function formulaires_editer_abonnements_offre_notifications_traiter_dist($id_abonnements_offre, $retour = '') {
// Si on demande à enregistrer une nouvelle notif
if (!$supprimer = _request('supprimer')){
if (!$supprimer = _request('supprimer')) {
include_spip('inc/editer');
$retours = formulaires_editer_objet_traiter('abonnements_offres_notification','new','','',$retour,'','','');
$retours = formulaires_editer_objet_traiter('abonnements_offres_notification', 'new', '', '', $retour, '', '', '');
}
// Sinon c'est pour en supprimer
elseif (is_array($supprimer)){
foreach ($supprimer as $id_notification=>$valeur){
if ($id_notification = intval($id_notification)){
sql_delete('spip_abonnements_offres_notifications', 'id_abonnements_offres_notification = '.$id_notification);
$retours = array('redirect' => $retour);
elseif (is_array($supprimer)) {
foreach ($supprimer as $id_notification => $valeur) {
if ($id_notification = intval($id_notification)) {
sql_delete('spip_abonnements_offres_notifications', 'id_abonnements_offres_notification = ' . $id_notification);
$retours = ['redirect' => $retour];
}
}
}
return $retours;
}

@ -1,7 +1,8 @@
<?php
/**
* Envoyer ponctuellement les notifications aux abonnés d'une offre
*
*
* On restreindre la liste des gens à notifier selon certains critères : statut, dates, ...
*/
@ -19,77 +20,77 @@ if (!defined('_ECRIRE_INC_VERSION')) {
* URL de redirection
* @return array
*/
function formulaires_notifier_echeances_abonnementsoffre_saisies_dist($id_abonnements_offre, $retour = ''){
$saisies = array(
array(