110 lines
3.1 KiB
PHP
110 lines
3.1 KiB
PHP
<?php
|
|
if (!defined('_ECRIRE_INC_VERSION')) return;
|
|
|
|
|
|
include_spip('inc/filtres');
|
|
|
|
/**
|
|
* formulaire générique pour envoyer des mails avec pieces attachés
|
|
*
|
|
* @param string $slug modele du mail a charger
|
|
* @param int|string $auteur id_auteur ou email du destinataire
|
|
* @param array $Tclient []['objet' => 'app_client', 'id_objet' => 3, 'champ' => 'email'] ou ['objet' => 'app_client', 'id_objet' => 3, 'champ' => 'email']
|
|
* @param array $Tpdf []['fichier' => 'pdf_facture', 'contexte' => ['id_app_facture' => 3]] ou ['fichier' => 'pdf_facture', 'contexte' => ['id_app_facture' => 3]]
|
|
* @param string $redirect
|
|
* @param array $options
|
|
* @return array $valeurs
|
|
*/
|
|
function formulaires_gamumail_charger_dist($slug, $auteur = 0, $Tclient = [], $Tpdf = [], $redirect = '', $options = []) :Array{
|
|
|
|
$Tmails = [];
|
|
if (intval($auteur)) {
|
|
$Tmails[] = sql_getfetsel('email', 'spip_auteurs', 'id_auteur='.intval($auteur));
|
|
} elseif (is_string($auteur)) {
|
|
if (email_valide($auteur)) {
|
|
$Tmails[] = $auteur;
|
|
}
|
|
}
|
|
|
|
if (is_array($Tclient) and count($Tclient)) {
|
|
if (array_key_exists('objet', $Tclient)) {
|
|
$Tclient = [$Tclient];
|
|
}
|
|
foreach ($Tclient as $o) {
|
|
$table = table_objet_sql($o['objet']);
|
|
$id = id_table_objet($o['objet']);
|
|
$mail = sql_getfetsel("{$o['champ']}", $table, "$id=".intval($o['id_objet']));
|
|
if (email_valide($mail)) {
|
|
$Tmails[] = $mail;
|
|
}
|
|
}
|
|
}
|
|
|
|
$TFichierPdf = [];
|
|
if (is_array($Tpdf) and count($Tpdf)) {
|
|
if (array_key_exists('fichier', $Tpdf)) {
|
|
$TFichierPdf = [$Tpdf];
|
|
}
|
|
foreach ($Tpdf as $pdf) {
|
|
$TFichierPdf[] = $pdf['fichier'];
|
|
}
|
|
}
|
|
|
|
$gamuMail = sql_fetsel('sujet, texte', 'spip_gamumails', 'slug='.sql_quote($slug));
|
|
$valeurs = array(
|
|
"slug" => $slug,
|
|
'sujet' => $gamuMail['sujet'],
|
|
'texte' => $gamuMail['texte'],
|
|
'pour' => implode(',', $Tmails),
|
|
'cc' => lire_config('gamumail/mail_cc'),
|
|
'cci' => lire_config('gamumail/mail_cci'),
|
|
'TFichierpdfs' => $TFichierPdf,
|
|
'Tpdfs_ok' => [],
|
|
'Tid_doc' => [],
|
|
'options' => $options
|
|
);
|
|
|
|
return $valeurs;
|
|
}
|
|
|
|
function formulaires_gamumail_verifier_dist($slug, $auteur = 0, $Tclient = [], $Tpdf = [], $redirect = '') :Array{
|
|
|
|
$erreurs = array();
|
|
//champs obligatoire
|
|
foreach (array ('pour', 'sujet', 'texte') as $obligatoire) {
|
|
if (!_request($obligatoire)) $erreurs[$obligatoire] = 'Ce champs est obligatoire';
|
|
}
|
|
|
|
////autres erreurs
|
|
//$erreurs[''] = "Ce champ ne convient pas.";
|
|
|
|
////Il y a des erreurs
|
|
//if (count($erreurs)) {
|
|
//$erreurs['message_erreur'] = 'Votre saisie contient des erreurs !';
|
|
//}
|
|
|
|
return $erreurs;
|
|
}
|
|
|
|
function formulaires_gamumail_traiter_dist($slug, $auteur = 0, $Tclient = [], $Tpdf = [], $redirect = '') :Array{
|
|
|
|
$retour = array();
|
|
|
|
$gamumail_traiter = charger_fonction('gamumail_traiter','inc');
|
|
$gamumail_traiter($slug, $objet = '', $id_objet = '', $Tid_auteur = [], $Temail = []);
|
|
|
|
|
|
$retour['message_ok'] = "bravo";
|
|
if ($redirect) {
|
|
$retour['redirect'] = $redirect;
|
|
}
|
|
$retour['editable'] = true;
|
|
|
|
return $retour;
|
|
}
|
|
|
|
function gamumail_supprimer_si_vide($v){
|
|
if (!empty($v)) {
|
|
return $v;
|
|
}
|
|
}
|