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';
47 public $enabled =
'isModEnabled("partnership")';
58 $langs->load(
'companies');
79 $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";
80 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"c_partnership_type as pt";
81 $sql .=
" WHERE s.email <> ''";
82 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
83 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
84 $sql .=
" AND p.fk_soc = s.rowid";
85 $sql .=
" AND pt.rowid = p.fk_type";
86 if (
GETPOST(
'filter',
'int') > 0) {
87 $sql .=
" AND pt.rowid=".((int)
GETPOST(
'filter',
'int'));
89 if (empty($this->evenunsubscribe)) {
90 $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).
")";
95 $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";
96 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as s, ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"c_partnership_type as pt";
97 $sql .=
" WHERE s.email <> ''";
98 $sql .=
" AND s.entity IN (".getEntity(
'member').
")";
99 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
100 $sql .=
" AND p.fk_member = s.rowid";
101 $sql .=
" AND pt.rowid = p.fk_type";
102 if (
GETPOST(
'filter',
'int') > 0) {
103 $sql .=
" AND pt.rowid=".((int)
GETPOST(
'filter',
'int'));
105 if (empty($this->evenunsubscribe)) {
106 $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).
")";
109 $sql .=
" ORDER BY email";
112 $result = $this->db->query($sql);
114 $num = $this->db->num_rows($result);
118 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
122 $obj = $this->db->fetch_object($result);
123 if ($old <> $obj->email) {
124 $otherTxt = ($obj->label ? $langs->transnoentities(
"PartnershipType").
'='.$obj->label :
'');
125 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
128 $otherTxt .= $addDescription;
130 'email' => $obj->email,
131 'fk_contact' => $obj->fk_contact,
132 'lastname' => $obj->name,
134 'other' => $otherTxt,
135 'source_url' => $this->url($obj->id, $obj->source),
136 'source_id' => $obj->id,
137 'source_type' => $obj->source
147 $this->error = $this->db->error();
151 return parent::addTargetsToDatabase($mailing_id, $cibles);
185 $sql =
"SELECT count(distinct(s.email)) as nb";
186 $sql .=
" FROM ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"societe as s";
187 $sql .=
" WHERE s.rowid = p.fk_soc AND s.email <> ''";
188 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
189 if (empty($this->evenunsubscribe)) {
190 $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).
")";
195 $sql .=
"SELECT count(distinct(s.email)) as nb";
196 $sql .=
" FROM ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"adherent as s";
197 $sql .=
" WHERE s.rowid = p.fk_member AND s.email <> ''";
198 $sql .=
" AND s.entity IN (".getEntity(
'member').
")";
199 if (empty($this->evenunsubscribe)) {
200 $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).
")";
206 return parent::getNbOfRecipients($sql);
217 global $conf, $langs;
219 $langs->load(
"companies");
221 $s =
'<select id="filter_partnership" name="filter" class="flat">';
224 $sql =
"SELECT rowid, label, code, active";
225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_partnership_type";
226 $sql .=
" WHERE active = 1";
227 $sql .=
" AND entity = ".$conf->entity;
228 $sql .=
" ORDER BY label";
231 $resql = $this->db->query($sql);
233 $num = $this->db->num_rows($resql);
235 if (empty($conf->partnership->enabled)) {
240 $s .=
'<option value="-1">'.$langs->trans(
"PartnershipType").
'</option>';
245 $obj = $this->db->fetch_object($resql);
269 public function url($id, $sourcetype =
'thirdparty')
271 if ($sourcetype ==
'thirdparty') {
272 return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.((int) $id).
'">'.
img_object(
'',
"societe").
'</a>';
274 if ($sourcetype ==
'member') {
275 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.
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...