23include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
34 public $name =
'PartnershipThirdpartiesOrMembers';
39 public $desc =
"Thirdparties or members included into a partnership program";
44 public $require_admin = 0;
50 public $require_module = array(
'partnership');
55 public $picto =
'partnership';
60 public $enabled =
'isModEnabled("partnership")';
71 $langs->load(
'companies');
92 $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";
93 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"c_partnership_type as pt";
94 $sql .=
" WHERE s.email <> ''";
95 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
96 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
97 $sql .=
" AND p.fk_soc = s.rowid";
98 $sql .=
" AND pt.rowid = p.fk_type";
100 $sql .=
" AND pt.rowid=".(GETPOSTINT(
'filter'));
102 if (GETPOSTISSET(
'filter_status_partnership') &&
GETPOSTINT(
'filter_status_partnership') >= 0) {
103 $sql .=
" AND p.status = ".GETPOSTINT(
'filter_status_partnership');
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).
")";
111 $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";
112 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as s, ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"c_partnership_type as pt";
113 $sql .=
" WHERE s.email <> ''";
114 $sql .=
" AND s.entity IN (".getEntity(
'member').
")";
115 $sql .=
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
116 $sql .=
" AND p.fk_member = s.rowid";
117 $sql .=
" AND pt.rowid = p.fk_type";
119 $sql .=
" AND pt.rowid=".(GETPOSTINT(
'filter'));
121 if (GETPOSTISSET(
'filter_status_partnership') &&
GETPOSTINT(
'filter_status_partnership') >= 0) {
122 $sql .=
" AND p.status = ".GETPOSTINT(
'filter_status_partnership');
124 if (empty($this->evenunsubscribe)) {
125 $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).
")";
128 $sql .=
" ORDER BY email";
131 $result = $this->db->query($sql);
133 $num = $this->db->num_rows($result);
137 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
141 $obj = $this->db->fetch_object($result);
142 if ($old != $obj->email) {
143 $otherTxt = ($obj->label ? $langs->transnoentities(
"PartnershipType").
'='.$obj->label :
'');
144 if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
147 $otherTxt .= $addDescription;
149 'email' => $obj->email,
150 'fk_contact' => (
int) $obj->fk_contact,
151 'lastname' => $obj->name,
153 'other' => $otherTxt,
154 'source_url' => $this->url($obj->id, $obj->source),
155 'source_id' => (
int) $obj->id,
156 'source_type' => $obj->source
166 $this->error = $this->db->error();
170 return parent::addTargetsToDatabase($mailing_id, $cibles);
204 $sql =
"SELECT count(distinct(s.email)) as nb";
205 $sql .=
" FROM ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"societe as s";
206 $sql .=
" WHERE s.rowid = p.fk_soc AND s.email <> ''";
207 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
208 if (empty($this->evenunsubscribe)) {
209 $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).
")";
214 $sql .=
"SELECT count(distinct(s.email)) as nb";
215 $sql .=
" FROM ".MAIN_DB_PREFIX.
"partnership as p, ".MAIN_DB_PREFIX.
"adherent as s";
216 $sql .=
" WHERE s.rowid = p.fk_member AND s.email <> ''";
217 $sql .=
" AND s.entity IN (".getEntity(
'member').
")";
218 if (empty($this->evenunsubscribe)) {
219 $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).
")";
225 return parent::getNbOfRecipients($sql);
236 global
$conf, $langs, $form;
238 $langs->load(
"companies");
240 $s =
'<select id="filter_partnership" name="filter" class="flat">';
243 $sql =
"SELECT rowid, label, code, active";
244 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_partnership_type";
245 $sql .=
" WHERE active = 1";
246 $sql .=
" AND entity = ".$conf->entity;
247 $sql .=
" ORDER BY label";
250 $resql = $this->db->query($sql);
252 $num = $this->db->num_rows($resql);
254 if (empty(
$conf->partnership->enabled)) {
259 $s .=
'<option value="-1">'.$langs->trans(
"PartnershipType").
'</option>';
264 $obj = $this->db->fetch_object($resql);
278 include_once DOL_DOCUMENT_ROOT.
'/partnership/class/partnership.class.php';
280 $dummy = $tmppartnership->getLibStatut(0);
282 $s .= $form->selectarray(
'filter_status_partnership', $tmppartnership->labelStatus,
GETPOST(
'filter_status_partnership'), $langs->trans(
"Status"));
295 public function url(
$id, $sourcetype =
'thirdparty')
297 if ($sourcetype ==
'thirdparty') {
298 return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.((int)
$id).
'">'.
img_object(
'',
"societe").
'</a>';
300 if ($sourcetype ==
'member') {
301 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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...