/htdocs/core/modules/mailings/example.modules.php

https://github.com/asterix14/dolibarr · PHP · 144 lines · 38 code · 28 blank · 78 comment · 0 complexity · bc9413f26b4cbabf05d5aa6abd403e54 MD5 · raw file

  1. <?php
  2. /* Copyright (C) 2005-2006 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This file is an example to follow to add your own email selector inside
  5. * the Dolibarr email tool.
  6. * Follow instructions given in README file to know what to change to build
  7. * your own emailing list selector.
  8. * Code that need to be changed in this file are marked by "CHANGE THIS" tag.
  9. */
  10. /**
  11. * \file htdocs/core/modules/mailings/example.modules.php
  12. * \ingroup mailing
  13. * \brief Example file to provide a list of recipients for mailing module
  14. */
  15. include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
  16. // CHANGE THIS: Class name must be called mailing_xxx with xxx=name of your selector
  17. /**
  18. \class mailing_example
  19. \brief Class to manage a list of personalised recipients for mailing feature
  20. */
  21. class mailing_example extends MailingTargets
  22. {
  23. // CHANGE THIS: Put here a name not already used
  24. var $name='example';
  25. // CHANGE THIS: Put here a description of your selector module.
  26. // This label is used if no translation is found for key MailingModuleDescXXX where XXX=name is found
  27. var $desc='Put here a description';
  28. // CHANGE THIS: Set to 1 if selector is available for admin users only
  29. var $require_admin=0;
  30. var $require_module=array();
  31. var $picto='';
  32. var $db;
  33. // CHANGE THIS: Constructor name must be called mailing_xxx with xxx=name of your selector
  34. /**
  35. * Constructor
  36. *
  37. * @param DoliDB $DB Database handler
  38. */
  39. function mailing_example($DB)
  40. {
  41. $this->db=$DB;
  42. }
  43. /**
  44. * This is the main function that returns the array of emails
  45. *
  46. * @param mailing_id Id of mailing. No need to use it.
  47. * @param filterarray If you used the formFilter function. Empty otherwise.
  48. * @return int <0 if error, number of emails added if ok
  49. */
  50. function add_to_target($mailing_id,$filtersarray=array())
  51. {
  52. $target = array();
  53. // CHANGE THIS
  54. // ----- Your code start here -----
  55. // You must fill the $target array with record like this
  56. // $target[0]=array('email'=>'email_0','name'=>'name_0','firstname'=>'firstname_0', 'other'=>'other_0');
  57. // ...
  58. // $target[n]=array('email'=>'email_n','name'=>'name_n','firstname'=>'firstname_n', 'other'=>'other_n');
  59. // Example: $target[0]=array('email'=>'myemail@mydomain.com', 'name'=>'Doe', 'firstname'=>'John', 'other'=>'Other information');
  60. // ----- Your code end here -----
  61. return parent::add_to_target($mailing_id, $target);
  62. }
  63. /**
  64. * On the main mailing area, there is a box with statistics.
  65. * If you want to add a line in this report you must provide an
  66. * array of SQL request that returns two field:
  67. * One called "label", One called "nb".
  68. *
  69. * @return array Array with SQL requests
  70. */
  71. function getSqlArrayForStats()
  72. {
  73. // CHANGE THIS: Optionnal
  74. //var $statssql=array();
  75. //$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL";
  76. return array();
  77. }
  78. /**
  79. * Return here number of distinct emails returned by your selector.
  80. * For example if this selector is used to extract 500 different
  81. * emails from a text file, this function must return 500.
  82. *
  83. * @return int
  84. */
  85. function getNbOfRecipients()
  86. {
  87. // CHANGE THIS: Optionnal
  88. // Example: return parent::getNbOfRecipients("SELECT count(*) as nb from dolibarr_table");
  89. // Example: return 500;
  90. return '?';
  91. }
  92. /**
  93. * This is to add a form filter to provide variant of selector
  94. * If used, the HTML select must be called "filter"
  95. *
  96. * @return string A html select zone
  97. */
  98. function formFilter()
  99. {
  100. // CHANGE THIS: Optionnal
  101. $s='';
  102. return $s;
  103. }
  104. /**
  105. * Can include an URL link on each record provided by selector
  106. * shown on target page.
  107. *
  108. * @return string Url link
  109. */
  110. function url($id)
  111. {
  112. // CHANGE THIS: Optionnal
  113. return '';
  114. }
  115. }
  116. ?>