21include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
30 public $name =
'PartnershipThirdpartiesOrMembers';
31 public $desc =
"Thirdparties or members included into a partnership program";
33 public $require_admin = 0;
35 public $require_module = array(
'partnership');
40 public $picto =
'partnership';
42 public $enabled =
'isModEnabled("partnership")';
53 $langs->load(
'companies');
74 $sql =
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, pt.label as label, 'thirdparty' as source";
75 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"c_partnership_type as pt";
76 $sql .=
" WHERE s.email <> ''";
77 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
78 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
79 $sql .=
" AND p.fk_soc = s.rowid";
80 $sql .=
" AND pt.rowid = p.fk_type";
81 if (
GETPOST(
'filter',
'int') > 0) {
82 $sql .=
" AND pt.rowid=".((int)
GETPOST(
'filter',
'int'));
84 if (GETPOSTISSET(
'filter_status_partnership') &&
GETPOSTINT(
'filter_status_partnership') >= 0) {
85 $sql .=
" AND p.status = ".GETPOSTINT(
'filter_status_partnership');
87 if (empty($this->evenunsubscribe)) {
88 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).
")";
93 $sql .=
"SELECT s.rowid as id, s.email as email, s.lastname as name, null as fk_contact, s.firstname as firstname, pt.label as label, 'member' as source";
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as s, ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"c_partnership_type as pt";
95 $sql .=
" WHERE s.email <> ''";
96 $sql .=
" AND s.entity IN (".getEntity(
'member').
")";
97 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
98 $sql .=
" AND p.fk_member = s.rowid";
99 $sql .=
" AND pt.rowid = p.fk_type";
100 if (
GETPOST(
'filter',
'int') > 0) {
101 $sql .=
" AND pt.rowid=".((int)
GETPOST(
'filter',
'int'));
103 if (GETPOSTISSET(
'filter_status_partnership') &&
GETPOSTINT(
'filter_status_partnership') >= 0) {
104 $sql .=
" AND p.status = ".GETPOSTINT(
'filter_status_partnership');
106 if (empty($this->evenunsubscribe)) {
107 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).
")";
110 $sql .=
" ORDER BY email";
113 $result = $this->db->query($sql);
115 $num = $this->db->num_rows($result);
119 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
123 $obj = $this->db->fetch_object($result);
124 if ($old != $obj->email) {
125 $otherTxt = ($obj->label ? $langs->transnoentities(
"PartnershipType").
'='.$obj->label :
'');
126 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
129 $otherTxt .= $addDescription;
131 'email' => $obj->email,
132 'fk_contact' => $obj->fk_contact,
133 'lastname' => $obj->name,
135 'other' => $otherTxt,
136 'source_url' => $this->url($obj->id, $obj->source),
137 'source_id' => $obj->id,
138 'source_type' => $obj->source
148 $this->error = $this->db->error();
152 return parent::addTargetsToDatabase($mailing_id, $cibles);
186 $sql =
"SELECT count(distinct(s.email)) as nb";
187 $sql .=
" FROM ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"societe as s";
188 $sql .=
" WHERE s.rowid = p.fk_soc AND s.email <> ''";
189 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
190 if (empty($this->evenunsubscribe)) {
191 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).
")";
196 $sql .=
"SELECT count(distinct(s.email)) as nb";
197 $sql .=
" FROM ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"adherent as s";
198 $sql .=
" WHERE s.rowid = p.fk_member AND s.email <> ''";
199 $sql .=
" AND s.entity IN (".getEntity(
'member').
")";
200 if (empty($this->evenunsubscribe)) {
201 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = s.email and mu.entity = ".((int) $conf->entity).
")";
207 return parent::getNbOfRecipients($sql);
218 global $conf, $langs, $form;
220 $langs->load(
"companies");
222 $s =
'<select id="filter_partnership" name="filter" class="flat">';
225 $sql =
"SELECT rowid, label, code, active";
226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_partnership_type";
227 $sql .=
" WHERE active = 1";
228 $sql .=
" AND entity = ".$conf->entity;
229 $sql .=
" ORDER BY label";
232 $resql = $this->db->query($sql);
234 $num = $this->db->num_rows($resql);
236 if (empty($conf->partnership->enabled)) {
241 $s .=
'<option value="-1">'.$langs->trans(
"PartnershipType").
'</option>';
246 $obj = $this->db->fetch_object($resql);
260 include_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
262 $dummy = $tmppartnership->getLibStatut(0);
264 $s .= $form->selectarray(
'filter_status_partnership', $tmppartnership->labelStatus,
GETPOST(
'filter_status_partnership'), $langs->trans(
"Status"));
277 public function url($id, $sourcetype =
'thirdparty')
279 if ($sourcetype ==
'thirdparty') {
280 return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.((int) $id).
'">'.
img_object(
'',
"societe").
'</a>';
282 if ($sourcetype ==
'member') {
283 return '<a href="'.DOL_URL_ROOT.
'/adherent/card.php?id='.((int) $id).
'">'.
img_object(
'',
"member").
'</a>';
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Parent class of emailing target selectors modules.
Class to manage a list of personalised recipients for mailing feature.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
add_to_target($mailing_id)
This is the main function that returns the array of emails.
__construct($db)
Constructor.
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...
url($id, $sourcetype='thirdparty')
Can include an URL link on each record provided by selector shown on target page.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...