Debug v15
This commit is contained in:
parent
648f1b7d1f
commit
d167e022eb
@ -310,6 +310,8 @@ if ($object->fetch($id) >= 0) {
|
||||
print load_fiche_titre($langs->trans("ToAddRecipientsChooseHere"), ($user->admin ?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"), 1) : ''), 'generic');
|
||||
|
||||
//print '<table class="noborder centpercent">';
|
||||
|
||||
print '<div class="div-table-responsive">';
|
||||
print '<div class="tagtable centpercent liste_titre_bydiv borderbottom" id="tablelines">';
|
||||
|
||||
//print '<tr class="liste_titre">';
|
||||
@ -323,7 +325,7 @@ if ($object->fetch($id) >= 0) {
|
||||
//print '<td class="liste_titre" align="center"> </td>';
|
||||
print '<div class="tagtd"> </div>';
|
||||
//print "</tr>\n";
|
||||
print '</div>';
|
||||
print '</div>'; // End tr
|
||||
|
||||
clearstatcache();
|
||||
|
||||
@ -424,9 +426,9 @@ if ($object->fetch($id) >= 0) {
|
||||
|
||||
print '<div class="tagtd right">';
|
||||
if ($allowaddtarget) {
|
||||
print '<input type="submit" class="button button-add" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
|
||||
print '<input type="submit" class="button button-add small" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
|
||||
} else {
|
||||
print '<input type="submit" class="button disabled" disabled="disabled" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
|
||||
print '<input type="submit" class="button small disabled" disabled="disabled" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
|
||||
//print $langs->trans("MailNoChangePossible");
|
||||
print " ";
|
||||
}
|
||||
@ -445,6 +447,7 @@ if ($object->fetch($id) >= 0) {
|
||||
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
||||
print $hookmanager->resPrint;
|
||||
|
||||
print '</div>'; // End table
|
||||
print '</div>';
|
||||
|
||||
print '<br><br>';
|
||||
@ -535,7 +538,7 @@ if ($object->fetch($id) >= 0) {
|
||||
|
||||
$morehtmlcenter = '';
|
||||
if ($allowaddtarget) {
|
||||
$morehtmlcenter = '<span class="opacitymedium">'.$langs->trans("ToClearAllRecipientsClickHere").'</span> <a href="'.$_SERVER["PHP_SELF"].'?clearlist=1&id='.$object->id.'" class="button reposition smallpaddingimp">'.$langs->trans("TargetsReset").'</a>';
|
||||
$morehtmlcenter = '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ToClearAllRecipientsClickHere").'</span> <a href="'.$_SERVER["PHP_SELF"].'?clearlist=1&id='.$object->id.'" class="button reposition smallpaddingimp">'.$langs->trans("TargetsReset").'</a>';
|
||||
}
|
||||
$morehtmlcenter .= ' <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?exportcsv=1&id='.$object->id.'">'.$langs->trans("Download").'</a>';
|
||||
|
||||
|
||||
@ -138,9 +138,8 @@ class mailing_contacts1 extends MailingTargets
|
||||
$sql .= " ORDER BY sp.poste";
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
$s .= $langs->trans("PostOrFunction").' ';
|
||||
$s .= '<select name="filter_jobposition" class="flat marginrightonly" placeholder="'.dol_escape_htmltag($langs->trans("PostOrFunction")).'">';
|
||||
$s .= '<option value="all"> </option>';
|
||||
$s .= '<select id="filter_jobposition_contact" name="filter_jobposition" class="flat" placeholder="'.dol_escape_htmltag($langs->trans("PostOrFunction")).'">';
|
||||
$s .= '<option value="-1">'.$langs->trans("PostOrFunction").'</option>';
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
@ -157,11 +156,10 @@ class mailing_contacts1 extends MailingTargets
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
$s .= '</select>';
|
||||
|
||||
$s .= ajax_combobox("filter_jobposition_contact");
|
||||
$s .= ' ';
|
||||
|
||||
// Filter on contact category
|
||||
$s .= $langs->trans("ContactCategoriesShort").' ';
|
||||
$sql = "SELECT c.label, count(distinct(sp.email)) AS nb";
|
||||
$sql .= " FROM ";
|
||||
$sql .= " ".MAIN_DB_PREFIX."socpeople as sp,";
|
||||
@ -176,8 +174,8 @@ class mailing_contacts1 extends MailingTargets
|
||||
$sql .= " ORDER BY c.label";
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
$s .= '<select name="filter_category" class="flat marginrightonly">';
|
||||
$s .= '<option value="all"> </option>';
|
||||
$s .= '<select id="filter_category_contact" name="filter_category" class="flat">';
|
||||
$s .= '<option value="-1">'.$langs->trans("ContactCategoriesShort").'</option>';
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num) {
|
||||
@ -194,12 +192,11 @@ class mailing_contacts1 extends MailingTargets
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
$s .= '</select>';
|
||||
|
||||
$s .= ajax_combobox("filter_category_contact");
|
||||
$s .= '<br>';
|
||||
|
||||
// Add prospect of a particular level
|
||||
$s .= $langs->trans("NatureOfThirdParty").' ';
|
||||
$s .= '<select name="filter" class="flat marginrightonly">';
|
||||
$s .= '<select id="filter_contact" name="filter" class="flat">';
|
||||
$sql = "SELECT code, label";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
|
||||
$sql .= " WHERE active > 0";
|
||||
@ -208,9 +205,9 @@ class mailing_contacts1 extends MailingTargets
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num) {
|
||||
$s .= '<option value="all"> </option>';
|
||||
$s .= '<option value="-1">'.$langs->trans("NatureOfThirdParty").'</option>';
|
||||
} else {
|
||||
$s .= '<option value="all">'.$langs->trans("ContactsAllShort").'</option>';
|
||||
$s .= '<option value="-1">'.$langs->trans("ContactsAllShort").'</option>';
|
||||
}
|
||||
$s .= '<option value="prospects">'.$langs->trans("ThirdPartyProspects").'</option>';
|
||||
|
||||
@ -231,11 +228,11 @@ class mailing_contacts1 extends MailingTargets
|
||||
//$s.='<option value="customersidprof">'.$langs->trans("ThirdPartyCustomersWithIdProf12",$langs->trans("ProfId1"),$langs->trans("ProfId2")).'</option>';
|
||||
$s .= '<option value="suppliers">'.$langs->trans("ThirdPartySuppliers").'</option>';
|
||||
$s .= '</select>';
|
||||
$s .= ajax_combobox("filter_contact");
|
||||
|
||||
$s .= ' ';
|
||||
|
||||
// Filter on thirdparty category
|
||||
$s .= $langs->trans("CustomersProspectsCategoriesShort").' ';
|
||||
$sql = "SELECT c.label, count(distinct(sp.email)) AS nb";
|
||||
$sql .= " FROM ";
|
||||
$sql .= " ".MAIN_DB_PREFIX."socpeople as sp,";
|
||||
@ -250,8 +247,8 @@ class mailing_contacts1 extends MailingTargets
|
||||
$sql .= " ORDER BY c.label";
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
$s .= '<select name="filter_category_customer" class="flat marginrightonly maxwidth200">';
|
||||
$s .= '<option value="all"> </option>';
|
||||
$s .= '<select id="filter_category_customer_contact" name="filter_category_customer" class="flat maxwidth200">';
|
||||
$s .= '<option value="-1">'.$langs->trans("CustomersProspectsCategoriesShort").'</option>';
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num) {
|
||||
@ -268,11 +265,11 @@ class mailing_contacts1 extends MailingTargets
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
$s .= '</select>';
|
||||
$s .= ajax_combobox("filter_category_customer_contact");
|
||||
|
||||
$s .= ' ';
|
||||
|
||||
// Filter on thirdparty category
|
||||
$s .= $langs->trans("SuppliersCategoriesShort").' ';
|
||||
$sql = "SELECT c.label, count(distinct(sp.email)) AS nb";
|
||||
$sql .= " FROM ";
|
||||
$sql .= " ".MAIN_DB_PREFIX."socpeople as sp,";
|
||||
@ -287,8 +284,8 @@ class mailing_contacts1 extends MailingTargets
|
||||
$sql .= " ORDER BY c.label";
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
$s .= '<select name="filter_category_supplier" class="flat marginrightonly maxwidth200">';
|
||||
$s .= '<option value="all"> </option>';
|
||||
$s .= '<select id="filter_category_supplier_contact" name="filter_category_supplier" class="flat maxwidth200">';
|
||||
$s .= '<option value="-1">'.$langs->trans("SuppliersCategoriesShort").'</option>';
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
if ($num) {
|
||||
@ -305,7 +302,7 @@ class mailing_contacts1 extends MailingTargets
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
$s .= '</select>';
|
||||
|
||||
$s .= ajax_combobox("filter_category_supplier_contact");
|
||||
return $s;
|
||||
}
|
||||
|
||||
@ -366,22 +363,16 @@ class mailing_contacts1 extends MailingTargets
|
||||
$sql .= " s.nom as companyname";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc";
|
||||
if ($filter_category <> 'all') {
|
||||
if ($filter_category != 'all' && $filter_category != '-1') {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."categorie as c";
|
||||
}
|
||||
if ($filter_category <> 'all') {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."categorie_contact as cs";
|
||||
}
|
||||
if ($filter_category_customer <> 'all') {
|
||||
if ($filter_category_customer != 'all' && $filter_category_customer != '-1') {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."categorie as c2";
|
||||
}
|
||||
if ($filter_category_customer <> 'all') {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c2s";
|
||||
}
|
||||
if ($filter_category_supplier <> 'all') {
|
||||
if ($filter_category_supplier != 'all' && $filter_category_supplier != '-1') {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."categorie as c3";
|
||||
}
|
||||
if ($filter_category_supplier <> 'all') {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."categorie_fournisseur as c3s";
|
||||
}
|
||||
$sql .= " WHERE sp.entity IN (".getEntity('socpeople').")";
|
||||
@ -391,34 +382,28 @@ class mailing_contacts1 extends MailingTargets
|
||||
$sql .= " AND sp.statut = 1";
|
||||
$sql .= " AND sp.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
|
||||
// Filter on category
|
||||
if ($filter_category <> 'all') {
|
||||
if ($filter_category != 'all' && $filter_category != '-1') {
|
||||
$sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_socpeople = sp.rowid";
|
||||
}
|
||||
if ($filter_category <> 'all') {
|
||||
$sql .= " AND c.label = '".$this->db->escape($filter_category)."'";
|
||||
}
|
||||
if ($filter_category_customer <> 'all') {
|
||||
if ($filter_category_customer != 'all' && $filter_category_customer != '-1') {
|
||||
$sql .= " AND c2s.fk_categorie = c2.rowid AND c2s.fk_soc = sp.fk_soc";
|
||||
}
|
||||
if ($filter_category_customer <> 'all') {
|
||||
$sql .= " AND c2.label = '".$this->db->escape($filter_category_customer)."'";
|
||||
}
|
||||
if ($filter_category_supplier <> 'all') {
|
||||
if ($filter_category_supplier != 'all' && $filter_category_supplier != '-1') {
|
||||
$sql .= " AND c3s.fk_categorie = c3.rowid AND c3s.fk_soc = sp.fk_soc";
|
||||
}
|
||||
if ($filter_category_supplier <> 'all') {
|
||||
$sql .= " AND c3.label = '".$this->db->escape($filter_category_supplier)."'";
|
||||
}
|
||||
// Filter on nature
|
||||
$key = $filter;
|
||||
{
|
||||
//print "xx".$key;
|
||||
|
||||
//print "xx".$key;
|
||||
if ($key == 'prospects') {
|
||||
$sql .= " AND s.client=2";
|
||||
}
|
||||
foreach ($prospectlevel as $codelevel => $valuelevel) {
|
||||
if ($key == 'prospectslevel'.$codelevel) {
|
||||
$sql .= " AND s.fk_prospectlevel='".$this->db->escape($codelevel)."'";
|
||||
$sql .= " AND s.fk_prospectlevel = '".$this->db->escape($codelevel)."'";
|
||||
}
|
||||
}
|
||||
if ($key == 'customers') {
|
||||
@ -427,17 +412,18 @@ class mailing_contacts1 extends MailingTargets
|
||||
if ($key == 'suppliers') {
|
||||
$sql .= " AND s.fournisseur=1";
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on job position
|
||||
$key = $filter_jobposition;
|
||||
if (!empty($key) && $key != 'all') {
|
||||
$sql .= " AND sp.poste ='".$this->db->escape($key)."'";
|
||||
$key = $filter_jobposition;
|
||||
if (!empty($key) && $key != 'all' && $key != '-1') {
|
||||
$sql .= " AND sp.poste = '".$this->db->escape($key)."'";
|
||||
}
|
||||
$sql .= " ORDER BY sp.email";
|
||||
|
||||
$sql .= " ORDER BY sp.email";
|
||||
//print "wwwwwwx".$sql;
|
||||
|
||||
// Stocke destinataires dans cibles
|
||||
$result = $this->db->query($sql);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
|
||||
@ -123,16 +123,16 @@ class mailing_fraise extends MailingTargets
|
||||
$s = '';
|
||||
|
||||
// Status
|
||||
$s .= $langs->trans("Status").': ';
|
||||
$s .= '<select name="filter" class="flat">';
|
||||
$s .= '<option value="none"> </option>';
|
||||
$s .= '<option value="-1">'.$langs->trans("MemberStatusDraft").'</option>';
|
||||
$s .= '<select id="filter_fraise" name="filter" class="flat">';
|
||||
$s .= '<option value="-1">'.$langs->trans("Status").'</option>';
|
||||
$s .= '<option value="draft">'.$langs->trans("MemberStatusDraft").'</option>';
|
||||
$s .= '<option value="1a">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusPaidShort").')</option>';
|
||||
$s .= '<option value="1b">'.$langs->trans("MemberStatusActiveShort").' ('.$langs->trans("MemberStatusActiveLateShort").')</option>';
|
||||
$s .= '<option value="0">'.$langs->trans("MemberStatusResiliatedShort").'</option>';
|
||||
$s .= '</select> ';
|
||||
$s .= $langs->trans("Type").': ';
|
||||
$s .= '<select name="filter_type" class="flat">';
|
||||
$s .= ajax_combobox("filter_fraise");
|
||||
|
||||
$s .= '<select id="filter_type_fraise" name="filter_type" class="flat">';
|
||||
$sql = "SELECT rowid, libelle as label, statut";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."adherent_type";
|
||||
$sql .= " WHERE entity IN (".getEntity('member_type').")";
|
||||
@ -141,7 +141,7 @@ class mailing_fraise extends MailingTargets
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
|
||||
$s .= '<option value="0"> </option>';
|
||||
$s .= '<option value="-1">'.$langs->trans("Type").'</option>';
|
||||
if (!$num) {
|
||||
$s .= '<option value="0" disabled="disabled">'.$langs->trans("NoCategoriesDefined").'</option>';
|
||||
}
|
||||
@ -154,16 +154,17 @@ class mailing_fraise extends MailingTargets
|
||||
$s .= '</option>';
|
||||
$i++;
|
||||
}
|
||||
$s .= ajax_combobox("filter_type");
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
$s .= '</select>';
|
||||
$s .= ajax_combobox("filter_type_fraise");
|
||||
|
||||
$s .= ' ';
|
||||
|
||||
$s .= $langs->trans("Category").': ';
|
||||
$s .= '<select name="filter_category" class="flat">';
|
||||
$s .= '<select id="filter_category_fraise" name="filter_category" class="flat">';
|
||||
|
||||
// Show categories
|
||||
$sql = "SELECT rowid, label, type, visible";
|
||||
@ -178,7 +179,7 @@ class mailing_fraise extends MailingTargets
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
|
||||
$s .= '<option value="0"> </option>';
|
||||
$s .= '<option value="-1">'.$langs->trans("Category").'</option>';
|
||||
if (!$num) {
|
||||
$s .= '<option value="0" disabled>'.$langs->trans("NoCategoriesDefined").'</option>';
|
||||
}
|
||||
@ -191,6 +192,7 @@ class mailing_fraise extends MailingTargets
|
||||
$s .= '</option>';
|
||||
$i++;
|
||||
}
|
||||
$s .= ajax_combobox("filter_category_fraise");
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
@ -246,7 +248,7 @@ class mailing_fraise extends MailingTargets
|
||||
$sql .= " a.lastname, a.firstname,";
|
||||
$sql .= " a.datefin, a.civility as civility_id, a.login, a.societe"; // Other fields
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
|
||||
if (GETPOST('filter_category')) {
|
||||
if (GETPOST('filter_category', 'int') > 0) {
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."categorie_member as cm ON cm.fk_member = a.rowid";
|
||||
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."categorie as c ON c.rowid = cm.fk_categorie AND c.rowid = ".((int) GETPOST('filter_category', 'int'));
|
||||
}
|
||||
@ -254,16 +256,13 @@ class mailing_fraise extends MailingTargets
|
||||
$sql .= " WHERE a.entity IN (".getEntity('member').") AND a.email <> ''"; // Note that null != '' is false
|
||||
$sql .= " AND a.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
|
||||
// Filter on status
|
||||
if (GETPOST("filter") == '-1') {
|
||||
$sql .= " AND a.statut=-1";
|
||||
}
|
||||
if (GETPOST("filter", 'aZ09') == '1a') {
|
||||
if (GETPOST("filter", 'aZ09') == 'draft') {
|
||||
$sql .= " AND a.statut = -1";
|
||||
} elseif (GETPOST("filter", 'aZ09') == '1a') {
|
||||
$sql .= " AND a.statut=1 AND (a.datefin >= '".$this->db->idate($now)."' OR ta.subscription = 0)";
|
||||
}
|
||||
if (GETPOST("filter", 'aZ09') == '1b') {
|
||||
} elseif (GETPOST("filter", 'aZ09') == '1b') {
|
||||
$sql .= " AND a.statut=1 AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND ta.subscription = 1)";
|
||||
}
|
||||
if (GETPOST("filter", 'aZ09') === '0') {
|
||||
} elseif (GETPOST("filter", 'aZ09') === '0') {
|
||||
$sql .= " AND a.statut=0";
|
||||
}
|
||||
// Filter on date
|
||||
@ -276,7 +275,7 @@ class mailing_fraise extends MailingTargets
|
||||
$sql .= " AND a.fk_adherent_type = ta.rowid";
|
||||
// Filter on type
|
||||
if (GETPOST('filter_type', 'int') > 0) {
|
||||
$sql .= " AND ta.rowid='".$this->db->escape(GETPOST('filter_type', 'int'))."'";
|
||||
$sql .= " AND ta.rowid = ".((int) GETPOST('filter_type', 'int'));
|
||||
}
|
||||
$sql .= " ORDER BY a.email";
|
||||
//print $sql;
|
||||
|
||||
264
htdocs/core/modules/mailings/partnership.modules.php
Normal file
264
htdocs/core/modules/mailings/partnership.modules.php
Normal file
@ -0,0 +1,264 @@
|
||||
<?php
|
||||
/* Copyright (C) 2018-2018 Andre Schild <a.schild@aarboard.ch>
|
||||
* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
|
||||
*
|
||||
* This file is an example to follow to add your own email selector inside
|
||||
* the Dolibarr email tool.
|
||||
* Follow instructions given in README file to know what to change to build
|
||||
* your own emailing list selector.
|
||||
* Code that need to be changed in this file are marked by "CHANGE THIS" tag.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/modules/mailings/partnership.modules.php
|
||||
* \ingroup mailing
|
||||
* \brief Example file to provide a list of recipients for mailing module
|
||||
*/
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
|
||||
|
||||
|
||||
/**
|
||||
* Class to manage a list of personalised recipients for mailing feature
|
||||
*/
|
||||
class mailing_partnership extends MailingTargets
|
||||
{
|
||||
public $name = 'PartnershipThirdartiesOrMembers';
|
||||
// This label is used if no translation is found for key XXX neither MailingModuleDescXXX where XXX=name is found
|
||||
public $desc = "Thirdparties or members included into a partnership program";
|
||||
public $require_admin = 0;
|
||||
|
||||
public $require_module = array(); // This module allows to select by categories must be also enabled if category module is not activated
|
||||
|
||||
/**
|
||||
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
|
||||
*/
|
||||
public $picto = 'partnership';
|
||||
|
||||
/**
|
||||
* @var DoliDB Database handler.
|
||||
*/
|
||||
public $db;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDB $db Database handler
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
global $conf, $langs;
|
||||
$langs->load("companies");
|
||||
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* This is the main function that returns the array of emails
|
||||
*
|
||||
* @param int $mailing_id Id of mailing. No need to use it.
|
||||
* @return int <0 if error, number of emails added if ok
|
||||
*/
|
||||
public function add_to_target($mailing_id)
|
||||
{
|
||||
// phpcs:enable
|
||||
global $conf, $langs;
|
||||
|
||||
$cibles = array();
|
||||
$addDescription = '';
|
||||
|
||||
$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";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."partnership as p, ".MAIN_DB_PREFIX."c_partnership_type as pt";
|
||||
$sql .= " WHERE s.email <> ''";
|
||||
$sql .= " AND s.entity IN (".getEntity('societe').")";
|
||||
$sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
|
||||
$sql .= " AND p.fk_soc = s.rowid";
|
||||
$sql .= " AND pt.rowid = p.fk_type";
|
||||
if (GETPOST('filter', 'int') > 0) {
|
||||
$sql .= " AND pt.rowid=".((int) GETPOST('filter', 'int'));
|
||||
}
|
||||
|
||||
$sql .= " UNION ";
|
||||
|
||||
$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";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."adherent as s, ".MAIN_DB_PREFIX."partnership as p, ".MAIN_DB_PREFIX."c_partnership_type as pt";
|
||||
$sql .= " WHERE s.email <> ''";
|
||||
$sql .= " AND s.entity IN (".getEntity('member').")";
|
||||
$sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
|
||||
$sql .= " AND p.fk_member = s.rowid";
|
||||
$sql .= " AND pt.rowid = p.fk_type";
|
||||
if (GETPOST('filter', 'int') > 0) {
|
||||
$sql .= " AND pt.rowid=".((int) GETPOST('filter', 'int'));
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY email";
|
||||
|
||||
// Stock recipients emails into targets table
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$num = $this->db->num_rows($result);
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
|
||||
dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
|
||||
|
||||
$old = '';
|
||||
while ($i < $num) {
|
||||
$obj = $this->db->fetch_object($result);
|
||||
if ($old <> $obj->email) {
|
||||
$otherTxt = ($obj->label ? $langs->transnoentities("PartnershipType").'='.$obj->label : '');
|
||||
if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
|
||||
$otherTxt .= ";";
|
||||
}
|
||||
$otherTxt .= $addDescription;
|
||||
$cibles[$j] = array(
|
||||
'email' => $obj->email,
|
||||
'fk_contact' => $obj->fk_contact,
|
||||
'lastname' => $obj->name, // For a thirdparty, we must use name
|
||||
'firstname' => '', // For a thirdparty, lastname is ''
|
||||
'other' => $otherTxt,
|
||||
'source_url' => $this->url($obj->id, $obj->source),
|
||||
'source_id' => $obj->id,
|
||||
'source_type' => $obj->source
|
||||
);
|
||||
$old = $obj->email;
|
||||
$j++;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
dol_syslog($this->db->error());
|
||||
$this->error = $this->db->error();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return parent::addTargetsToDatabase($mailing_id, $cibles);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On the main mailing area, there is a box with statistics.
|
||||
* If you want to add a line in this report you must provide an
|
||||
* array of SQL request that returns two field:
|
||||
* One called "label", One called "nb".
|
||||
*
|
||||
* @return array Array with SQL requests
|
||||
*/
|
||||
public function getSqlArrayForStats()
|
||||
{
|
||||
// CHANGE THIS: Optionnal
|
||||
|
||||
//var $statssql=array();
|
||||
//$this->statssql[0]="SELECT field1 as label, count(distinct(email)) as nb FROM mytable WHERE email IS NOT NULL";
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return here number of distinct emails returned by your selector.
|
||||
* For example if this selector is used to extract 500 different
|
||||
* emails from a text file, this function must return 500.
|
||||
*
|
||||
* @param string $sql Requete sql de comptage
|
||||
* @return int Nb of recipients
|
||||
*/
|
||||
public function getNbOfRecipients($sql = '')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT count(distinct(s.email)) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."partnership as p, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= " WHERE s.rowid = p.fk_soc AND s.email <> ''";
|
||||
$sql .= " AND s.entity IN (".getEntity('societe').")";
|
||||
|
||||
$sql .= " UNION ";
|
||||
|
||||
$sql .= "SELECT count(distinct(s.email)) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."partnership as p, ".MAIN_DB_PREFIX."adherent as s";
|
||||
$sql .= " WHERE s.rowid = p.fk_member AND s.email <> ''";
|
||||
$sql .= " AND s.entity IN (".getEntity('member').")";
|
||||
|
||||
//print $sql;
|
||||
|
||||
// La requete doit retourner un champ "nb" pour etre comprise
|
||||
// par parent::getNbOfRecipients
|
||||
return parent::getNbOfRecipients($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is to add a form filter to provide variant of selector
|
||||
* If used, the HTML select must be called "filter"
|
||||
*
|
||||
* @return string A html select zone
|
||||
*/
|
||||
public function formFilter()
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$langs->load("companies");
|
||||
|
||||
$s = '<select id="filter_partnership" name="filter" class="flat">';
|
||||
|
||||
// Show categories
|
||||
$sql = "SELECT rowid, label, code, active";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_partnership_type";
|
||||
$sql .= " WHERE active = 1";
|
||||
$sql .= " AND entity = ".$conf->entity;
|
||||
$sql .= " ORDER BY label";
|
||||
|
||||
//print $sql;
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
|
||||
if (empty($conf->partnership->enabled)) {
|
||||
$num = 0; // Force empty list if category module is not enabled
|
||||
}
|
||||
|
||||
if ($num) {
|
||||
$s .= '<option value="-1">'.$langs->trans("PartnershipType").'</option>';
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
while ($i < $num) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$s .= '<option value="'.$obj->rowid.'">'.dol_escape_htmltag($obj->label);
|
||||
$s .= '</option>';
|
||||
$i++;
|
||||
}
|
||||
$s .= ajax_combobox("filter_partnership");
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
$s .= '</select> ';
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Can include an URL link on each record provided by selector shown on target page.
|
||||
*
|
||||
* @param int $id ID
|
||||
* @param string $sourcetype Source type
|
||||
* @return string Url link
|
||||
*/
|
||||
public function url($id, $sourcetype = 'thirdparty')
|
||||
{
|
||||
if ($sourcetype == 'thirparty') {
|
||||
return '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.((int) $id).'">'.img_object('', "societe").'</a>';
|
||||
}
|
||||
if ($sourcetype == 'member') {
|
||||
return '<a href="'.DOL_URL_ROOT.'/adherent/card.php?id='.((int) $id).'">'.img_object('', "member").'</a>';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@ -119,20 +119,20 @@ class mailing_pomme extends MailingTargets
|
||||
$langs->load("users");
|
||||
|
||||
$s = '';
|
||||
$s .= $langs->trans("Status").' ';
|
||||
$s .= '<select name="filter" class="flat marginrightonly">';
|
||||
$s .= '<option value="-1"> </option>';
|
||||
$s .= '<select id="filter_pomme"" name="filter" class="flat">';
|
||||
$s .= '<option value="-1">'.$langs->trans("Status").'</option>';
|
||||
$s .= '<option value="1">'.$langs->trans("Enabled").'</option>';
|
||||
$s .= '<option value="0">'.$langs->trans("Disabled").'</option>';
|
||||
$s .= '</select>';
|
||||
$s .= ajax_combobox("filter_pomme");
|
||||
|
||||
$s .= ' ';
|
||||
$s .= $langs->trans("Employee").' ';
|
||||
$s .= '<select name="filteremployee" class="flat marginrightonly">';
|
||||
$s .= '<option value="-1"> </option>';
|
||||
$s .= '<select id="filteremployee_pomme" name="filteremployee" class="flat">';
|
||||
$s .= '<option value="-1">'.$langs->trans("Employee").'</option>';
|
||||
$s .= '<option value="1">'.$langs->trans("Yes").'</option>';
|
||||
$s .= '<option value="0">'.$langs->trans("No").'</option>';
|
||||
$s .= '</select>';
|
||||
$s .= ajax_combobox("filteremployee_pomme");
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
@ -115,7 +115,9 @@ class mailing_thirdparties extends MailingTargets
|
||||
$sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
|
||||
$sql .= " AND cs.fk_soc = s.rowid";
|
||||
$sql .= " AND c.rowid = cs.fk_categorie";
|
||||
$sql .= " AND c.rowid=".((int) GETPOST('filter', 'int'));
|
||||
if (GETPOST('filter', 'int') > 0) {
|
||||
$sql .= " AND c.rowid=".((int) GETPOST('filter', 'int'));
|
||||
}
|
||||
$sql .= $addFilter;
|
||||
$sql .= " UNION ";
|
||||
$sql .= "SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, c.label as label";
|
||||
@ -125,7 +127,9 @@ class mailing_thirdparties extends MailingTargets
|
||||
$sql .= " AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE fk_mailing=".((int) $mailing_id).")";
|
||||
$sql .= " AND cs.fk_soc = s.rowid";
|
||||
$sql .= " AND c.rowid = cs.fk_categorie";
|
||||
$sql .= " AND c.rowid=".((int) GETPOST('filter', 'int'));
|
||||
if (GETPOST('filter', 'int') > 0) {
|
||||
$sql .= " AND c.rowid=".((int) GETPOST('filter', 'int'));
|
||||
}
|
||||
$sql .= $addFilter;
|
||||
}
|
||||
$sql .= " ORDER BY email";
|
||||
@ -206,7 +210,7 @@ class mailing_thirdparties extends MailingTargets
|
||||
|
||||
$sql = "SELECT count(distinct(s.email)) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= " WHERE s.email != ''";
|
||||
$sql .= " WHERE s.email <> ''";
|
||||
$sql .= " AND s.entity IN (".getEntity('societe').")";
|
||||
|
||||
// La requete doit retourner un champ "nb" pour etre comprise
|
||||
@ -226,8 +230,7 @@ class mailing_thirdparties extends MailingTargets
|
||||
|
||||
$langs->load("companies");
|
||||
|
||||
$s = $langs->trans("Categories").' ';
|
||||
$s .= '<select name="filter" class="flat marginrightonly">';
|
||||
$s = '<select id="filter_thirdparties" name="filter" class="flat">';
|
||||
|
||||
// Show categories
|
||||
$sql = "SELECT rowid, label, type, visible";
|
||||
@ -247,7 +250,7 @@ class mailing_thirdparties extends MailingTargets
|
||||
}
|
||||
|
||||
if ($num) {
|
||||
$s .= '<option value="0"> </option>';
|
||||
$s .= '<option value="-1">'.$langs->trans("Categories").'</option>';
|
||||
} else {
|
||||
$s .= '<option value="0">'.$langs->trans("ContactsAllShort").'</option>';
|
||||
}
|
||||
@ -270,14 +273,15 @@ class mailing_thirdparties extends MailingTargets
|
||||
$s .= '</option>';
|
||||
$i++;
|
||||
}
|
||||
$s .= ajax_combobox("filter_thirdparties");
|
||||
} else {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
$s .= '</select> ';
|
||||
$s .= $langs->trans('ProspectCustomer');
|
||||
$s .= ' <select name="filter_client" class="flat marginrightonly">';
|
||||
$s .= '<option value="-1"> </option>';
|
||||
|
||||
$s .= '<select id="filter_client_thirdparties" name="filter_client_thirdparties" class="flat">';
|
||||
$s .= '<option value="-1">'.$langs->trans('ProspectCustomer').'</option>';
|
||||
if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
|
||||
$s .= '<option value="2">'.$langs->trans('Prospect').'</option>';
|
||||
}
|
||||
@ -290,13 +294,14 @@ class mailing_thirdparties extends MailingTargets
|
||||
$s .= '<option value="0">'.$langs->trans('NorProspectNorCustomer').'</option>';
|
||||
|
||||
$s .= '</select> ';
|
||||
$s .= ajax_combobox("filter_client_thirdparties");
|
||||
|
||||
$s .= $langs->trans("Status");
|
||||
$s .= ' <select name="filter_status" class="flat marginrightonly">';
|
||||
$s .= '<option value="-1"> </option>';
|
||||
$s .= '<option value="1" selected>'.$langs->trans("Enabled").'</option>';
|
||||
$s .= ' <select id="filter_status_thirdparties" name="filter_status" class="flat">';
|
||||
$s .= '<option value="-1">'.$langs->trans("Status").'</option>';
|
||||
$s .= '<option value="1">'.$langs->trans("Enabled").'</option>';
|
||||
$s .= '<option value="0">'.$langs->trans("Disabled").'</option>';
|
||||
$s .= '</select>';
|
||||
$s .= ajax_combobox("filter_status_thirdparties");
|
||||
return $s;
|
||||
}
|
||||
|
||||
|
||||
@ -215,10 +215,9 @@ class mailing_thirdparties_services_expired extends MailingTargets
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$s = $langs->trans("ProductOrService");
|
||||
$s .= '<select name="filter" class="flat">';
|
||||
$s .= '<select id="filter_services_expired" name="filter" class="flat">';
|
||||
if (count($this->arrayofproducts)) {
|
||||
$s .= '<option value="0"> </option>';
|
||||
$s .= '<option value="-1">'.$langs->trans("ProductOrService").'</option>';
|
||||
} else {
|
||||
$s .= '<option value="0">'.$langs->trans("ContactsAllShort").'</option>';
|
||||
}
|
||||
@ -226,6 +225,7 @@ class mailing_thirdparties_services_expired extends MailingTargets
|
||||
$s .= '<option value="'.$key.'">'.$val.'</option>';
|
||||
}
|
||||
$s .= '</select>';
|
||||
$s .= ajax_combobox("filter_services_expired");
|
||||
return $s;
|
||||
}
|
||||
|
||||
|
||||
@ -106,7 +106,7 @@ class Partnership extends CommonObject
|
||||
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
|
||||
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>4, 'noteditable'=>'1', 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"),
|
||||
'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => 1, 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1),
|
||||
'fk_type' => array('type' => 'integer:PartnershipType:partnership/class/partnership_type.class.php', 'label' => 'Type', 'enabled' => 1, 'visible' => 1, 'position' => 20),
|
||||
'fk_type' => array('type' => 'integer:PartnershipType:partnership/class/partnership_type.class.php', 'label' => 'Type', 'notnull'=>1, 'enabled' => 1, 'visible' => 1, 'position' => 20),
|
||||
'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
|
||||
'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
|
||||
'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
|
||||
@ -245,6 +245,11 @@ class Partnership extends CommonObject
|
||||
*/
|
||||
public function create(User $user, $notrigger = false)
|
||||
{
|
||||
if ($this->fk_soc <= 0 && $this->fk_member <= 0) {
|
||||
$this->error[] = "ErrorThirpdartyOrMemberidIsManadatory";
|
||||
return -1;
|
||||
}
|
||||
|
||||
$this->status = 0;
|
||||
return $this->createCommon($user, $notrigger);
|
||||
}
|
||||
@ -547,6 +552,11 @@ class Partnership extends CommonObject
|
||||
*/
|
||||
public function update(User $user, $notrigger = false)
|
||||
{
|
||||
if ($this->fk_soc <= 0 && $this->fk_member <= 0) {
|
||||
$this->error[] = "ErrorThirpdartyOrMemberidIsManadatory";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $this->updateCommon($user, $notrigger);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user