* Copyright (C) 2005-2015 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2014 Florian Henry * * 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 3 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, see . */ /** * \file htdocs/comm/mailing/cibles.php * \ingroup mailing * \brief Page to define emailing targets */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php'; require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmailing.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $langs->load("mails"); // Security check if (! $user->rights->mailing->lire || $user->societe_id > 0) accessforbidden(); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="email"; $id=GETPOST('id','int'); $rowid=GETPOST('rowid','int'); $action=GETPOST("action"); $search_lastname=GETPOST("search_lastname"); $search_firstname=GETPOST("search_firstname"); $search_email=GETPOST("search_email"); $search_dest_status=GETPOST('search_dest_status'); // Search modules dirs $modulesdir = dolGetModulesDirs('/mailings'); $object = new Mailing($db); /* * Actions */ if ($action == 'add') { $module=GETPOST("module"); $result=-1; $var=true; foreach ($modulesdir as $dir) { // Load modules attributes in arrays (name, numero, orders) from dir directory //print $dir."\n
"; dol_syslog("Scan directory ".$dir." for modules"); // Chargement de la classe $file = $dir."/".$module.".modules.php"; $classname = "mailing_".$module; if (file_exists($file)) { require_once $file; // We fill $filtersarray. Using this variable is now deprecated. // Kept for backward compatibility. $filtersarray=array(); if (isset($_POST["filter"])) $filtersarray[0]=$_POST["filter"]; // Add targets into database $obj = new $classname($db); $result=$obj->add_to_target($id,$filtersarray); } } if ($result > 0) { setEventMessage($langs->trans("XTargetsAdded",$result),'mesgs'); header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } if ($result == 0) { setEventMessage($langs->trans("WarningNoEMailsAdded"),'warnings'); } if ($result < 0) { setEventMessage($langs->trans("Error").($obj->error?' '.$obj->error:''),'errors'); } } if (GETPOST('clearlist')) { // Chargement de la classe $obj = new MailingTargets($db); $obj->clear_target($id); header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } if ($action == 'delete') { // Ici, rowid indique le destinataire et id le mailing $sql="DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$rowid; $resql=$db->query($sql); if ($resql) { if (!empty($id)) { $obj = new MailingTargets($db); $obj->update_nb($id); header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } else { header("Location: list.php"); exit; } } else { dol_print_error($db); } } if ($_POST["button_removefilter"]) { $search_lastname=''; $search_firstname=''; $search_email=''; } /* * View */ llxHeader('',$langs->trans("Mailing"),'EN:Module_EMailing|FR:Module_Mailing|ES:Módulo_Mailing'); $form = new Form($db); $formmailing = new FormMailing($db); if ($object->fetch($id) >= 0) { $head = emailing_prepare_head($object); dol_fiche_head($head, 'targets', $langs->trans("Mailing"), 0, 'email'); print ''; $linkback = ''.$langs->trans("BackToList").''; print ''; print ''; print ''; print ''; // Errors to print ''; // Status print ''; // Nb of distinct emails print ''; print '
'.$langs->trans("Ref").''; print $form->showrefnav($object,'id', $linkback); print '
'.$langs->trans("MailTitle").''.$object->titre.'
'.$langs->trans("MailFrom").''.dol_print_email($object->email_from,0,0,0,0,1).'
'.$langs->trans("MailErrorsTo").''.dol_print_email($object->email_errorsto,0,0,0,0,1); print '
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'; print $langs->trans("TotalNbOfDistinctRecipients"); print ''; $nbemail = ($object->nbemail?$object->nbemail:'0'); if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) { $text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB); print $form->textwithpicto($nbemail,$text,1,'warning'); } else { print $nbemail; } print '
'; print ""; $var=!$var; $allowaddtarget=($object->statut == 0); // Show email selectors if ($allowaddtarget && $user->rights->mailing->creer) { print_fiche_titre($langs->trans("ToAddRecipientsChooseHere"),($user->admin?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"),1):''),''); print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; clearstatcache(); $var=true; foreach ($modulesdir as $dir) { $modulenames=array(); // Load modules attributes in arrays (name, numero, orders) from dir directory //print $dir."\n
"; dol_syslog("Scan directory ".$dir." for modules"); $handle=@opendir($dir); if (is_resource($handle)) { while (($file = readdir($handle))!==false) { if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS') { if (preg_match("/(.*)\.modules\.php$/i",$file,$reg)) { if ($reg[1] == 'example') continue; $modulenames[]=$reg[1]; } } } closedir($handle); } // Sort $modulenames sort($modulenames); // Loop on each submodule foreach($modulenames as $modulename) { // Chargement de la classe $file = $dir.$modulename.".modules.php"; $classname = "mailing_".$modulename; require_once $file; $obj = new $classname($db); // Check dependencies $qualified=(isset($obj->enabled)?$obj->enabled:1); foreach ($obj->require_module as $key) { if (! $conf->$key->enabled || (! $user->admin && $obj->require_admin)) { $qualified=0; //print "Les prerequis d'activation du module mailing ne sont pas respectes. Il ne sera pas actif"; break; } } // Si le module mailing est qualifie if ($qualified) { $var = !$var; print ''; if ($allowaddtarget) { print ''; print ''; } print ''; try { $nbofrecipient=$obj->getNbOfRecipients(''); } catch(Exception $e) { dol_syslog($e->getMessage(), LOG_ERR); } print ''; print ''; print ''; if ($allowaddtarget) print ''; print "\n"; } } } // End foreach dir print '
'.$langs->trans("RecipientSelectionModules").''.$langs->trans("NbOfUniqueEMails").''.$langs->trans("Filter").' 
'; if (empty($obj->picto)) $obj->picto='generic'; print img_object($langs->trans("Module").': '.get_class($obj),$obj->picto).' '.$obj->getDesc(); print ''; if ($nbofrecipient >= 0) { print $nbofrecipient; } else { print $langs->trans("Error").' '.img_error($obj->error); } print ''; try { $filter=$obj->formFilter(); } catch(Exception $e) { dol_syslog($e->getMessage(), LOG_ERR); } if ($filter) print $filter; else print $langs->trans("None"); print ''; if ($allowaddtarget) { print ''; } else { //print $langs->trans("MailNoChangePossible"); print " "; } print '
'; print '
'; } // List of selected targets $sql = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.source_url, mc.source_id, mc.source_type"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; $sql .= " WHERE mc.fk_mailing=".$object->id; if ($search_lastname) $sql.= " AND mc.lastname LIKE '%".$db->escape($search_lastname)."%'"; if ($search_firstname) $sql.= " AND mc.firstname LIKE '%".$db->escape($search_firstname)."%'"; if ($search_email) $sql.= " AND mc.email LIKE '%".$db->escape($search_email)."%'"; if (!empty($search_dest_status)) $sql.= " AND mc.statut=".$db->escape($search_dest_status)." "; $sql .= $db->order($sortfield,$sortorder); $sql .= $db->plimit($conf->liste_limit+1, $offset); $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $param = "&id=".$object->id; if ($search_lastname) $param.= "&search_lastname=".urlencode($search_lastname); if ($search_firstname) $param.= "&search_firstname=".urlencode($search_firstname); if ($search_email) $param.= "&search_email=".urlencode($search_email); print '
'; print ''; print ''; print ''; print ''; if ($allowaddtarget) { $cleartext='
'.$langs->trans("ToClearAllRecipientsClickHere").': '.''; } print_barre_liste($langs->trans("MailSelectedRecipients").$cleartext,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,"",$num,$object->nbemail,''); print ''; print "\n\n"; print '
'; print ''; print ''; print ''; print ''; if ($page) $param.= "&page=".$page; print ''; print ''; print_liste_field_titre($langs->trans("EMail"),$_SERVER["PHP_SELF"],"mc.email",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Lastname"),$_SERVER["PHP_SELF"],"mc.lastname",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Firstname"),$_SERVER["PHP_SELF"],"mc.firstname",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("OtherInformations"),$_SERVER["PHP_SELF"],"",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Source"),$_SERVER["PHP_SELF"],"",$param,"",'align="center"',$sortfield,$sortorder); // Date sending if ($object->statut < 2) { print_liste_field_titre(''); } else { print_liste_field_titre($langs->trans("DateSending"),$_SERVER["PHP_SELF"],"mc.date_envoi",$param,'','align="center"',$sortfield,$sortorder); } print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"mc.statut",$param,'','align="right"',$sortfield,$sortorder); print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); print ''; // Ligne des champs de filtres print ''; // EMail print ''; // Name print ''; // Firstname print ''; // Other print ''; // Source print ''; // Date sending print ''; //Statut print ''; //Search Icon print ''; print ''; $var = true; $i = 0; if ($num) { while ($i < min($num,$conf->liste_limit)) { $obj = $db->fetch_object($resql); $var=!$var; print ""; print ''; print ''; print ''; print ''; print ''; // Statut pour l'email destinataire (Attentioon != statut du mailing) if ($obj->statut == 0) { print ''; print ''; } else { print ''; print ''; } //Sreach Icon print ''; print ''; $i++; } } else { print ''; } print "
'; print ''; print ''; print ''; print ''; print ''; print ''; print ' '; print ''; print ' '; print ''; print ' '; print ''; print $formmailing->selectDestinariesStatus($search_dest_status,'search_dest_status',1); print ''; print ''; print ''; print '
'.$obj->email.''.$obj->lastname.''.$obj->firstname.''.$obj->other.''; if (empty($obj->source_id) || empty($obj->source_type)) { print $obj->source_url; // For backward compatibility } else { if ($obj->source_type == 'member') { include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $m=new Adherent($db); $m->id=$obj->source_id; print $m->getNomUrl(2); } else if ($obj->source_type == 'user') { include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; $m=new User($db); $m->id=$obj->source_id; print $m->getNomUrl(2); } else if ($obj->source_type == 'thirdparty') { include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $m=new Societe($db); $m->id=$obj->source_id; print $m->getNomUrl(2); } else { print $obj->source_url; } } print ' '.$langs->trans("MailingStatusNotSent"); print ''.$obj->date_envoi.''; print $object::libStatutDest($obj->statut,2); print ''; if ($obj->statut == 0) { if ($user->rights->mailing->creer && $allowaddtarget) { print ''.img_delete($langs->trans("RemoveRecipient")); } } print '
'.$langs->trans("NoTargetYet").'

"; print '
'; $db->free($resql); } else { dol_print_error($db); } print "\n\n"; } llxFooter(); $db->close();