PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/mailing/liste.php

https://github.com/asterix14/dolibarr
PHP | 198 lines | 140 code | 27 blank | 31 comment | 29 complexity | b14d793053843b4c4a85f3f42f84f216 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/comm/mailing/liste.php
  20. * \ingroup mailing
  21. * \brief Liste des mailings
  22. */
  23. require("../../main.inc.php");
  24. require_once(DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php");
  25. $langs->load("mails");
  26. if (!$user->rights->mailing->lire) accessforbidden();
  27. // Securite acces client
  28. if ($user->societe_id > 0)
  29. {
  30. $action = '';
  31. $socid = $user->societe_id;
  32. }
  33. $sortfield = GETPOST("sortfield",'alpha');
  34. $sortorder = GETPOST("sortorder",'alpha');
  35. $page = GETPOST("page",'int');
  36. if ($page == -1) { $page = 0; }
  37. $offset = $conf->liste_limit * $page;
  38. $pageprev = $page - 1;
  39. $pagenext = $page + 1;
  40. if (! $sortorder) $sortorder="DESC";
  41. if (! $sortfield) $sortfield="m.date_creat";
  42. $sall=isset($_GET["sall"])?$_GET["sall"]:$_POST["sall"];
  43. $sref=isset($_GET["sref"])?$_GET["sref"]:$_POST["sref"];
  44. $filteremail=$_REQUEST["filteremail"]?$_REQUEST["filteremail"]:'';
  45. /*
  46. * View
  47. */
  48. llxHeader('',$langs->trans("Mailing"),'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
  49. $form = new Form($db);
  50. if ($filteremail)
  51. {
  52. $sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,";
  53. $sql.= " mc.statut as sendstatut";
  54. $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
  55. $sql.= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
  56. $sql.= " AND mc.email = '".$db->escape($filteremail)."'";
  57. if ($sref) $sql.= " AND m.rowid = '".$sref."'";
  58. if ($sall) $sql.= " AND (m.titre like '%".$sall."%' OR m.sujet like '%".$sall."%' OR m.body like '%".$sall."%')";
  59. if (! $sortorder) $sortorder="ASC";
  60. if (! $sortfield) $sortfield="m.rowid";
  61. $sql.= $db->order($sortfield,$sortorder);
  62. $sql.= $db->plimit($conf->liste_limit +1, $offset);
  63. }
  64. else
  65. {
  66. $sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
  67. $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
  68. $sql.= " WHERE m.entity = ".$conf->entity;
  69. if ($sref) $sql.= " AND m.rowid = '".$sref."'";
  70. if ($sall) $sql.= " AND (m.titre like '%".$sall."%' OR m.sujet like '%".$sall."%' OR m.body like '%".$sall."%')";
  71. if (! $sortorder) $sortorder="ASC";
  72. if (! $sortfield) $sortfield="m.rowid";
  73. $sql.= $db->order($sortfield,$sortorder);
  74. $sql.= $db->plimit($conf->liste_limit +1, $offset);
  75. }
  76. dol_syslog("sql=".$sql);
  77. //print $sql;
  78. $result = $db->query($sql);
  79. if ($result)
  80. {
  81. $num = $db->num_rows($result);
  82. $title=$langs->trans("ListOfEMailings");
  83. if ($filteremail) $title.=' ('.$langs->trans("SentTo",$filteremail).')';
  84. print_barre_liste($title, $page, "liste.php","",$sortfield,$sortorder,"",$num);
  85. $i = 0;
  86. $param = "&amp;sall=".$sall;
  87. if ($filteremail) $param.='&amp;filteremail='.urlencode($filteremail);
  88. print '<table class="liste">';
  89. print '<tr class="liste_titre">';
  90. print_liste_field_titre($langs->trans("Ref"),"liste.php","m.rowid",$param,"","",$sortfield,$sortorder);
  91. print_liste_field_titre($langs->trans("Title"),"liste.php","m.titre",$param,"","",$sortfield,$sortorder);
  92. print_liste_field_titre($langs->trans("DateCreation"),"liste.php","m.date_creat",$param,"",'align="center"',$sortfield,$sortorder);
  93. if (! $filteremail) print_liste_field_titre($langs->trans("NbOfEMails"),"liste.php","m.nbemail",$param,"",'align="center"',$sortfield,$sortorder);
  94. if (! $filteremail) print_liste_field_titre($langs->trans("DateLastSend"),"liste.php","m.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
  95. else print_liste_field_titre($langs->trans("DateSending"),"liste.php","mc.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
  96. print_liste_field_titre($langs->trans("Status"),"liste.php",($filteremail?"mc.statut":"m.statut"),$param,"",'align="right"',$sortfield,$sortorder);
  97. print "</tr>\n";
  98. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
  99. print '<tr class="liste_titre">';
  100. print '<td class="liste_titre">';
  101. print '<input type="text" class="flat" name="sref" value="'.$sref.'" size="6">';
  102. print '</td>';
  103. // Title
  104. print '<td class="liste_titre">';
  105. print '<input type="text" class="flat" name="sall" value="'.$sall.'" size="40">';
  106. print '</td>';
  107. print '<td class="liste_titre">&nbsp;</td>';
  108. if (! $filteremail) print '<td class="liste_titre">&nbsp;</td>';
  109. print '<td class="liste_titre">&nbsp;</td>';
  110. print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  111. print "</td>";
  112. print "</tr>\n";
  113. print '</form>';
  114. $var=True;
  115. $email=new Mailing($db);
  116. while ($i < min($num,$conf->liste_limit))
  117. {
  118. $obj = $db->fetch_object($result);
  119. $var=!$var;
  120. print "<tr $bc[$var]>";
  121. print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/fiche.php?id='.$obj->rowid.'">';
  122. print img_object($langs->trans("ShowEMail"),"email").' '.stripslashes($obj->rowid).'</a></td>';
  123. print '<td>'.$obj->titre.'</td>';
  124. // Date creation
  125. print '<td align="center">';
  126. print dol_print_date($db->jdate($obj->datec),'day');
  127. print '</td>';
  128. // Nb of email
  129. if (! $filteremail)
  130. {
  131. print '<td align="center">';
  132. $nbemail = $obj->nbemail;
  133. if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
  134. {
  135. $text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
  136. print $form->textwithpicto($nbemail,$text,1,'warning');
  137. }
  138. else
  139. {
  140. print $nbemail;
  141. }
  142. print '</td>';
  143. }
  144. // Last send
  145. print '<td align="center" nowrap="nowrap">'.dol_print_date($db->jdate($obj->date_envoi),'day').'</td>';
  146. print '</td>';
  147. // Status
  148. print '<td align="right" nowrap="nowrap">';
  149. if ($filteremail)
  150. {
  151. if ($obj->sendstatut==-1) print $langs->trans("MailingStatusError").' '.img_error();
  152. if ($obj->sendstatut==1) print $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
  153. }
  154. else
  155. {
  156. print $email->LibStatut($obj->statut,5);
  157. }
  158. print '</td>';
  159. print "</tr>\n";
  160. $i++;
  161. }
  162. print "</table>";
  163. $db->free($result);
  164. }
  165. else
  166. {
  167. dol_print_error($db);
  168. }
  169. $db->close();
  170. llxFooter();
  171. ?>