27include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
28include_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
36 public $name =
'FundationMembers';
38 public $desc =
'Foundation members with emails';
40 public $require_admin = 0;
42 public $require_module = array(
'adherent');
44 public $enabled =
'isModEnabled("adherent")';
49 public $picto =
'user';
75 $langs->load(
"members");
80 $statssql[0] =
"SELECT '".$this->db->escape($langs->trans(
"FundationMembers")).
"' as label, count(*) as nb";
81 $statssql[0] .=
" FROM ".MAIN_DB_PREFIX.
"adherent where statut = 1 and entity IN (".
getEntity(
'member').
")";
98 $sql =
"SELECT count(distinct(a.email)) as nb";
99 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as a";
100 $sql .=
" WHERE (a.email IS NOT NULL AND a.email != '') AND a.entity IN (".getEntity(
'member').
")";
101 if (empty($this->evenunsubscribe)) {
102 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = a.email and mu.entity = ".((int) $conf->entity).
")";
106 return parent::getNbOfRecipients($sql);
117 global $conf, $langs;
120 $langs->loadLangs(array(
"members",
"companies",
"categories"));
122 $form =
new Form($this->db);
127 $s .=
'<select id="filter_fraise" name="filter" class="flat">';
128 $s .=
'<option value="-1">'.$langs->trans(
"Status").
'</option>';
129 $s .=
'<option value="draft">'.$langs->trans(
"MemberStatusDraft").
'</option>';
130 $s .=
'<option value="1a">'.$langs->trans(
"MemberStatusActiveShort").
' ('.$langs->trans(
"MemberStatusPaidShort").
')</option>';
131 $s .=
'<option value="1b">'.$langs->trans(
"MemberStatusActiveShort").
' ('.$langs->trans(
"MemberStatusActiveLateShort").
')</option>';
132 $s .=
'<option value="0">'.$langs->trans(
"MemberStatusResiliatedShort").
'</option>';
136 $s .=
'<select id="filter_type_fraise" name="filter_type" class="flat">';
137 $sql =
"SELECT rowid, libelle as label, statut";
138 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type";
139 $sql .=
" WHERE entity IN (".getEntity(
'member_type').
")";
140 $sql .=
" ORDER BY rowid";
141 $resql = $this->db->query($sql);
143 $num = $this->db->num_rows($resql);
145 $s .=
'<option value="-1">'.$langs->trans(
"Type").
'</option>';
147 $s .=
'<option value="0" disabled="disabled">'.$langs->trans(
"NoCategoriesDefined").
'</option>';
152 $obj = $this->db->fetch_object($resql);
154 $s .=
'<option value="'.$obj->rowid.
'">'.
dol_trunc($obj->label, 38,
'middle');
168 $s .=
'<select id="filter_category_fraise" name="filter_category" class="flat">';
171 $sql =
"SELECT rowid, label, type, visible";
172 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
173 $sql .=
" WHERE type = 3";
175 $sql .=
" AND entity = ".$conf->entity;
176 $sql .=
" ORDER BY label";
179 $resql = $this->db->query($sql);
181 $num = $this->db->num_rows($resql);
183 $s .=
'<option value="-1">'.$langs->trans(
"Category").
'</option>';
185 $s .=
'<option value="0" disabled>'.$langs->trans(
"NoCategoriesDefined").
'</option>';
190 $obj = $this->db->fetch_object($resql);
192 $s .=
'<option value="'.$obj->rowid.
'">'.
dol_trunc($obj->label, 38,
'middle');
204 $s .=
'<br><span class="opacitymedium">';
205 $s .= $langs->trans(
"DateEndSubscription").
': ';
206 $s .= $langs->trans(
"After").
' > </span>'.$form->selectDate(-1,
'subscriptionafter', 0, 0, 1,
'fraise', 1, 0, 0);
208 $s .=
'<span class="opacitymedium">'.$langs->trans(
"Before").
' < </span>'.$form->selectDate(-1,
'subscriptionbefore', 0, 0, 1,
'fraise', 1, 0, 0);
222 return '<a href="'.DOL_URL_ROOT.
'/adherents/card.php?rowid='.$id.
'">'.
img_object(
'',
"user").
'</a>';
236 global $conf, $langs, $_POST;
239 $langs->loadLangs(array(
"members",
"companies"));
244 $dateendsubscriptionafter =
dol_mktime(
GETPOST(
'subscriptionafterhour',
'int'),
GETPOST(
'subscriptionaftermin',
'int'),
GETPOST(
'subscriptionaftersec',
'int'),
GETPOST(
'subscriptionaftermonth',
'int'),
GETPOST(
'subscriptionafterday',
'int'),
GETPOST(
'subscriptionafteryear',
'int'));
245 $dateendsubscriptionbefore =
dol_mktime(
GETPOST(
'subscriptionbeforehour',
'int'),
GETPOST(
'subscriptionbeforemin',
'int'),
GETPOST(
'subscriptionbeforesec',
'int'),
GETPOST(
'subscriptionbeforemonth',
'int'),
GETPOST(
'subscriptionbeforeday',
'int'),
GETPOST(
'subscriptionbeforeyear',
'int'));
248 $sql =
"SELECT a.rowid as id, a.email as email, null as fk_contact, ";
249 $sql .=
" a.lastname, a.firstname,";
250 $sql .=
" a.datefin, a.civility as civility_id, a.login, a.societe";
251 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as a";
252 if (
GETPOST(
'filter_category',
'int') > 0) {
253 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"categorie_member as cm ON cm.fk_member = a.rowid";
254 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"categorie as c ON c.rowid = cm.fk_categorie AND c.rowid = ".((int)
GETPOST(
'filter_category',
'int'));
256 $sql .=
" , ".MAIN_DB_PREFIX.
"adherent_type as ta";
257 $sql .=
" WHERE a.entity IN (".getEntity(
'member').
") AND a.email <> ''";
258 $sql .=
" AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
260 if (
GETPOST(
"filter",
'aZ09') ==
'draft') {
261 $sql .=
" AND a.statut = -1";
262 } elseif (
GETPOST(
"filter",
'aZ09') ==
'1a') {
263 $sql .=
" AND a.statut=1 AND (a.datefin >= '".$this->db->idate($now).
"' OR ta.subscription = 0)";
264 } elseif (
GETPOST(
"filter",
'aZ09') ==
'1b') {
265 $sql .=
" AND a.statut=1 AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now).
"') AND ta.subscription = 1)";
266 } elseif (
GETPOST(
"filter",
'aZ09') ===
'0') {
267 $sql .=
" AND a.statut=0";
270 if ($dateendsubscriptionafter > 0) {
271 $sql .=
" AND datefin > '".$this->db->idate($dateendsubscriptionafter).
"'";
273 if ($dateendsubscriptionbefore > 0) {
274 $sql .=
" AND datefin < '".$this->db->idate($dateendsubscriptionbefore).
"'";
276 $sql .=
" AND a.fk_adherent_type = ta.rowid";
278 if (
GETPOST(
'filter_type',
'int') > 0) {
279 $sql .=
" AND ta.rowid = ".((int)
GETPOST(
'filter_type',
'int'));
281 if (empty($this->evenunsubscribe)) {
282 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe as mu WHERE mu.email = a.email and mu.entity = ".((int) $conf->entity).
")";
284 $sql .=
" ORDER BY a.email";
288 dol_syslog(get_class($this).
"::add_to_target", LOG_DEBUG);
289 $result = $this->db->query($sql);
291 $num = $this->db->num_rows($result);
295 dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
299 $obj = $this->db->fetch_object($result);
300 if ($old != $obj->email) {
302 'email' => $obj->email,
303 'fk_contact' => $obj->fk_contact,
304 'lastname' => $obj->lastname,
305 'firstname' => $obj->firstname,
307 ($langs->transnoentities(
"Login").
'='.$obj->login).
';'.
308 ($langs->transnoentities(
"UserTitle").
'='.($obj->civility_id ? $langs->transnoentities(
"Civility".$obj->civility_id) :
'')).
';'.
309 ($langs->transnoentities(
"DateEnd").
'='.
dol_print_date($this->db->jdate($obj->datefin),
'day')).
';'.
310 ($langs->transnoentities(
"Company").
'='.$obj->societe),
311 'source_url' => $this->
url($obj->id),
312 'source_id' => $obj->id,
313 'source_type' =>
'member'
323 $this->error = $this->db->error();
327 return parent::addTargetsToDatabase($mailing_id, $cibles);
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 generate target according to rule Fraise.
url($id)
Renvoie url lien vers fiche de la source du destinataire du mailing.
add_to_target($mailing_id)
Ajoute destinataires dans table des cibles.
getSqlArrayForStats()
On the main mailing area, there is a box with statistics.
formFilter()
Affiche formulaire de filtre qui apparait dans page de selection des destinataires de mailings.
__construct($db)
Constructor.
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
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)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.