xinputuser.modules.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/modules/mailings/xinputuser.modules.php
  20. * \ingroup mailing
  21. * \brief File of class to offer a selector of emailing targets with Rule 'xinputuser'.
  22. */
  23. include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  25. /**
  26. * Class to offer a selector of emailing targets with Rule 'xinputuser'.
  27. */
  28. class mailing_xinputuser extends MailingTargets
  29. {
  30. public $name = 'EmailsFromUser'; // Identifiant du module mailing
  31. // This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
  32. public $desc = 'EMails input by user'; // Libelle utilise si aucune traduction pour MailingModuleDescXXX ou XXX=name trouv�e
  33. public $require_module = array(); // Module mailing actif si modules require_module actifs
  34. public $require_admin = 0; // Module mailing actif pour user admin ou non
  35. /**
  36. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  37. */
  38. public $picto = 'generic';
  39. public $tooltip = 'UseFormatInputEmailToTarget';
  40. /**
  41. * Constructor
  42. *
  43. * @param DoliDB $db Database handler
  44. */
  45. public function __construct($db)
  46. {
  47. $this->db = $db;
  48. }
  49. /**
  50. * On the main mailing area, there is a box with statistics.
  51. * If you want to add a line in this report you must provide an
  52. * array of SQL request that returns two field:
  53. * One called "label", One called "nb".
  54. *
  55. * @return array Array with SQL requests
  56. */
  57. public function getSqlArrayForStats()
  58. {
  59. global $langs;
  60. $langs->load("users");
  61. $statssql = array();
  62. return $statssql;
  63. }
  64. /**
  65. * Return here number of distinct emails returned by your selector.
  66. * For example if this selector is used to extract 500 different
  67. * emails from a text file, this function must return 500.
  68. *
  69. * @param string $sql Sql request to count
  70. * @return int|string Nb of recipient, or <0 if error, or '' if NA
  71. */
  72. public function getNbOfRecipients($sql = '')
  73. {
  74. return '';
  75. }
  76. /**
  77. * Renvoie url lien vers fiche de la source du destinataire du mailing
  78. *
  79. * @param int $id ID
  80. * @return string Url lien
  81. */
  82. public function url($id)
  83. {
  84. return '';
  85. }
  86. /**
  87. * Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings
  88. *
  89. * @return string Retourne zone select
  90. */
  91. public function formFilter()
  92. {
  93. global $langs;
  94. $s = '';
  95. $s .= '<input type="text" name="xinputuser" class="flat minwidth300" value="'.GETPOST("xinputuser").'">';
  96. return $s;
  97. }
  98. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  99. /**
  100. * Ajoute destinataires dans table des cibles
  101. *
  102. * @param int $mailing_id Id of emailing
  103. * @return int < 0 si erreur, nb ajout si ok
  104. */
  105. public function add_to_target($mailing_id)
  106. {
  107. // phpcs:enable
  108. global $conf, $langs, $_FILES;
  109. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  110. $tmparray = explode(';', GETPOST('xinputuser'));
  111. $email = $tmparray[0];
  112. $lastname = empty($tmparray[1]) ? '' : $tmparray[1];
  113. $firstname = empty($tmparray[2]) ? '' : $tmparray[2];
  114. $other = empty($tmparray[3]) ? '' : $tmparray[3];
  115. $cibles = array();
  116. if (!empty($email)) {
  117. if (isValidEMail($email)) {
  118. $cibles[] = array(
  119. 'email' => $email,
  120. 'lastname' => $lastname,
  121. 'firstname' => $firstname,
  122. 'other' => $other,
  123. 'source_url' => '',
  124. 'source_id' => '',
  125. 'source_type' => 'file'
  126. );
  127. return parent::addTargetsToDatabase($mailing_id, $cibles);
  128. } else {
  129. $langs->load("errors");
  130. $this->error = $langs->trans("ErrorBadEMail", $email);
  131. return -1;
  132. }
  133. } else {
  134. $langs->load("errors");
  135. $this->error = $langs->trans("ErrorBadEmail", $email);
  136. return -1;
  137. }
  138. }
  139. }