* Copyright (C) 2005 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ * */ /** \file htdocs/comm/mailing/cibles.php \ingroup mailing \brief Page des cibles de mailing \version $Revision$ */ require("./pre.inc.php"); $langs->load("mails"); $user->getrights("mailing"); if (! $user->rights->mailing->lire || $user->societe_id > 0) accessforbidden(); $dir=DOL_DOCUMENT_ROOT."/includes/modules/mailings"; $mesg = ''; $page=$_GET["page"]; $sortorder=$_GET["sortorder"]; $sortfield=$_GET["sortfield"]; if ($page == -1) { $page = 0 ; } $offset = $conf->liste_limit * $_GET["page"] ; $pageprev = $_GET["page"] - 1; $pagenext = $_GET["page"] + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="nom"; /* * Actions */ if ($_GET["action"] == 'add') { $modulename=$_GET["module"]; // Chargement de la classe $file = $dir."/".$modulename.".modules.php"; $classname = "mailing_".$modulename; require_once($file); $obj = new $classname($db); $result=$obj->add_to_target($_GET["rowid"]); if ($result > 0) { Header("Location: cibles.php?id=".$_GET["rowid"]); } if ($result == 0) { $mesg='
'.$langs->trans("WarningNoEMailsAdded").'
'; } if ($result < 0) { $mesg='
'.$obj->error.'
'; } $_GET["id"]=$_GET["rowid"]; } if ($_GET["action"] == 'clear') { // Chargement de la classe $file = $dir."/modules_mailings.php"; $classname = "MailingTargets"; require_once($file); $obj = new $classname($db); $obj->clear_target($_GET["rowid"]); Header("Location: cibles.php?id=".$_GET["rowid"]); } if ($_GET["action"] == 'delete') { // Ici, rowid indique le destinataire et id le mailing $sql="DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles where rowid=".$_GET["rowid"]; $resql=$db->query($sql); if ($resql) { $file = $dir."/modules_mailings.php"; $classname = "MailingTargets"; require_once($file); $obj = new $classname($db); $obj->update_nb($_GET["id"]); } else { dolibarr_print_error($db); } } /* * Liste des destinataires */ llxHeader("","",$langs->trans("MailCard")); $mil = new Mailing($db); $html = new Form($db); if ($mil->fetch($_GET["id"]) == 0) { $h=0; $head[$h][0] = DOL_URL_ROOT."/comm/mailing/fiche.php?id=".$mil->id; $head[$h][1] = $langs->trans("MailCard"); $h++; $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$mil->id; $head[$h][1] = $langs->trans("MailRecipients"); $hselected = $h; $h++; /* $head[$h][0] = DOL_URL_ROOT."/comm/mailing/history.php?id=".$mil->id; $head[$h][1] = $langs->trans("MailHistory"); $h++; */ dolibarr_fiche_head($head, $hselected, $langs->trans("Mailing").": ".substr($mil->titre,0,20)); print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("MailTitle").''.$mil->titre.'
'.$langs->trans("MailFrom").''.htmlentities($mil->email_from).'
'.$langs->trans("TotalNbOfDistinctRecipients").''.($mil->nbemail?$mil->nbemail:''.$langs->trans("NoTargetYet").'').'
'.$langs->trans("Status").''.$mil->statuts[$mil->statut].'

'; print ""; if ($mesg) print "$mesg
\n"; // Affiche les listes de sélection if ($mil->statut == 0) { print ''; print ''; print ''; print ''; print ''; print "\n"; clearstatcache(); $handle=opendir($dir); $var=True; while (($file = readdir($handle))!==false) { if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') { if (eregi("(.*)\.(.*)\.(.*)",$file,$reg)) { $modulename=$reg[1]; // Chargement de la classe $file = $dir."/".$modulename.".modules.php"; $classname = "mailing_".$modulename; require_once($file); $obj = new $classname($db); $qualified=1; foreach ($obj->require_module as $key) { if (! $conf->$key->enabled || (! $user->admin && $obj->require_admin)) { $qualified=0; //print "Les prérequis d'activation du module mailing ne sont pas respectés. Il ne sera pas actif"; break; } } // Si le module mailing est qualifié if ($qualified) { $var = !$var; print ''; print ''; /* print '"; */ print ''; print ''; print "\n"; } } } } closedir($handle); $var=!$var; print ''; print ''; print ''; print '
'.$langs->trans("RecipientSelectionModules").''.$langs->trans("NbOfUniqueEMails").''; if ($mil->statut == 0) { print $langs->trans("Actions"); } print '
'; print img_object('',$obj->picto).' '.$obj->getDesc(); print ''; print $modulename; print "'.$obj->getNbOfRecipients().''; if ($mil->statut == 0) { print '
'; } else { //print $langs->trans("MailNoChangePossible"); print " "; } print '
  

'; } // Liste des destinataires sélectionnés $sql = "SELECT mc.rowid, mc.nom, mc.prenom, mc.email, mc.statut, mc.date_envoi"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; $sql .= " WHERE mc.fk_mailing=".$mil->id; if ($sortfield) { $sql .= " ORDER BY $sortfield $sortorder"; } $sql .= $db->plimit($conf->liste_limit+1, $offset); $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $addu = "&id=".$mil->id."&page=$page";; print_barre_liste($langs->trans("MailSelectedRecipients"), $page, "cibles.php","&id=".$mil->id,$sortfield,$sortorder,"",$num); print ''; print ''; print_liste_field_titre($langs->trans("Lastname"),"cibles.php","mc.nom",$addu,"","",$sortfield); print_liste_field_titre($langs->trans("Firstname"),"cibles.php","mc.prenom",$addu,"","",$sortfield); print_liste_field_titre($langs->trans("EMail"),"cibles.php","mc.email",$addu,"","",$sortfield); print ''; if ($mil->statut == 0) { print ''; } if ($mil->statut != 0) { print ''; } print ''; $var = true; $i = 0; while ($i < $num ) { $obj = $db->fetch_object($resql); $var=!$var; print ""; print ''; print ''; print ''; if ($mil->statut == 0) { print ''; print ''; } if ($mil->statut != 0) { print ''; print ''; } print ''; $i++; } print "
'.$langs->trans("Status").' '.$langs->trans("Date").'
'.stripslashes($obj->nom).''.stripslashes($obj->prenom).''.$obj->email.''.$langs->trans("MailingStatusNotSent").''.img_delete($langs->trans("RemoveRecipient")).''; if ($obj->statut==-1) print $langs->trans("MailingStatusError"); if ($obj->statut==1) print $langs->trans("MailingStatusSent"); print ''.$obj->date_envoi.'

"; $db->free($resql); } else { dolibarr_print_error($db); } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>