21include_once DOL_DOCUMENT_ROOT.
'/core/modules/mailings/modules_mailings.php';
 
   32  public $name = 
'ThirdPartiesByCategories';
 
   37  public $desc = 
"Third parties (by categories)";
 
   42  public $require_admin = 0;
 
   47  public $require_module = array(
"societe");
 
   52  public $enabled = 
'isModEnabled("societe")';
 
   57  public $picto = 
'company';
 
   68    $langs->load(
"companies");
 
 
   90    if (GETPOSTISSET(
"filter_client_thirdparties") && 
GETPOST(
"filter_client_thirdparties") != 
'-1') {
 
   91      $addFilter .= 
" AND s.client=".(GETPOSTINT(
"filter_client_thirdparties"));
 
   92      $addDescription = $langs->trans(
'ProspectCustomer').
"=";
 
   93      if (
GETPOST(
"filter_client_thirdparties") == 0) {
 
   94        $addDescription .= $langs->trans(
'NorProspectNorCustomer');
 
   95      } elseif (
GETPOST(
"filter_client_thirdparties") == 1) {
 
   96        $addDescription .= $langs->trans(
'Customer');
 
   97      } elseif (
GETPOST(
"filter_client_thirdparties") == 2) {
 
   98        $addDescription .= $langs->trans(
'Prospect');
 
   99      } elseif (
GETPOST(
"filter_client_thirdparties") == 3) {
 
  100        $addDescription .= $langs->trans(
'ProspectCustomer');
 
  102        $addDescription .= 
"Unknown status ".GETPOST(
"filter_client_thirdparties");
 
  105    if (GETPOSTISSET(
"filter_supplier_thirdparties") && 
GETPOST(
"filter_supplier_thirdparties") != 
'-1') {
 
  106      $addFilter .= 
" AND s.fournisseur = ".(GETPOSTINT(
"filter_supplier_thirdparties"));
 
  107      $addDescription = $langs->trans(
'Supplier').
"=";
 
  108      if (
GETPOST(
"filter_supplier_thirdparties") == 0) {
 
  109        $addDescription .= $langs->trans(
'No');
 
  110      } elseif (
GETPOST(
"filter_supplier_thirdparties") == 1) {
 
  111        $addDescription .= $langs->trans(
'Yes');
 
  113        $addDescription .= 
"Unknown status ".GETPOST(
"filter_supplier_thirdparties");
 
  116    if (GETPOSTISSET(
"filter_status")) {
 
  117      if (strlen($addDescription) > 0) {
 
  118        $addDescription .= 
";";
 
  120      $addDescription .= $langs->trans(
"Status").
"=";
 
  121      if (
GETPOST(
"filter_status") == 
'1') {
 
  122        $addFilter .= 
" AND s.status=1";
 
  123        $addDescription .= $langs->trans(
"Enabled");
 
  124      } elseif (
GETPOST(
"filter_status") == 
'0') {
 
  125        $addFilter .= 
" AND s.status=0";
 
  126        $addDescription .= $langs->trans(
"Disabled");
 
  129    if (GETPOSTISSET(
"filter_status")) {
 
  130      if (strlen($addDescription) > 0) {
 
  131        $addDescription .= 
";";
 
  133      $addDescription .= $langs->trans(
"Status").
"=";
 
  134      if (
GETPOST(
"filter_status") == 
'1') {
 
  135        $addFilter .= 
" AND s.status=1";
 
  136        $addDescription .= $langs->trans(
"Enabled");
 
  137      } elseif (
GETPOST(
"filter_status") == 
'0') {
 
  138        $addFilter .= 
" AND s.status=0";
 
  139        $addDescription .= $langs->trans(
"Disabled");
 
  142    if (
GETPOST(
'default_lang', 
'alpha') && 
GETPOST(
'default_lang', 
'alpha') != 
'-1') {
 
  143      $addFilter .= 
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'default_lang', 
'alpha')).
"%'";
 
  144      $addDescription = $langs->trans(
'DefaultLang').
"=";
 
  146    if (
GETPOST(
'filter_lang_thirdparties', 
'alpha') && 
GETPOST(
'filter_lang_thirdparties', 
'alpha') != 
'-1') {
 
  147      $addFilter .= 
" AND s.default_lang LIKE '".$this->db->escape(
GETPOST(
'filter_lang_thirdparties', 
'alpha')).
"%'";
 
  148      $addDescription = $langs->trans(
'DefaultLang').
"=";
 
  152    if (!
GETPOST(
'filter_thirdparties') || 
GETPOST(
'filter_thirdparties') == 
'-1') {
 
  153      $sql = 
"SELECT s.rowid as id, s.email as email, s.nom as name, null as fk_contact, null as firstname, null as label";
 
  154      $sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe as s";
 
  155      $sql .= 
" WHERE s.email <> ''";
 
  156      $sql .= 
" AND s.entity IN (".getEntity(
'societe').
")";
 
  157      $sql .= 
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
 
  158      if (empty($this->evenunsubscribe)) {
 
  159        $sql .= 
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
 
  163      $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";
 
  164      $sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_societe as cs, ".MAIN_DB_PREFIX.
"categorie as c";
 
  165      $sql .= 
" WHERE s.email <> ''";
 
  166      $sql .= 
" AND s.entity IN (".getEntity(
'societe').
")";
 
  167      $sql .= 
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
 
  168      $sql .= 
" AND cs.fk_soc = s.rowid";
 
  169      $sql .= 
" AND c.rowid = cs.fk_categorie";
 
  171        $sql .= 
" AND c.rowid=".(GETPOSTINT(
'filter_thirdparties'));
 
  173      if (empty($this->evenunsubscribe)) {
 
  174        $sql .= 
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
 
  178      $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";
 
  179      $sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"categorie_fournisseur as cs, ".MAIN_DB_PREFIX.
"categorie as c";
 
  180      $sql .= 
" WHERE s.email <> ''";
 
  181      $sql .= 
" AND s.entity IN (".getEntity(
'societe').
")";
 
  182      $sql .= 
" AND s.email NOT IN (SELECT email FROM ".MAIN_DB_PREFIX.
"mailing_cibles WHERE fk_mailing=".((int) $mailing_id).
")";
 
  183      $sql .= 
" AND cs.fk_soc = s.rowid";
 
  184      $sql .= 
" AND c.rowid = cs.fk_categorie";
 
  186        $sql .= 
" AND c.rowid=".(GETPOSTINT(
'filter_thirdparties'));
 
  188      if (empty($this->evenunsubscribe)) {
 
  189        $sql .= 
" AND (SELECT count(*) FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = s.email) = 0";
 
  193    $sql .= 
" ORDER BY email";
 
  198    $result = $this->db->query($sql);
 
  200      $num = $this->db->num_rows($result);
 
  204      dol_syslog(get_class($this).
"::add_to_target mailing ".$num.
" targets found");
 
  208        $obj = $this->db->fetch_object($result);
 
  209        if ($old != $obj->email) {
 
  210          $otherTxt = ($obj->label ? $langs->transnoentities(
"Category").
'='.$obj->label : 
'');
 
  211          if (strlen($addDescription) > 0 && strlen($otherTxt) > 0) {
 
  214          $otherTxt .= $addDescription;
 
  216                'email' => $obj->email,
 
  217                'fk_contact' => (
int) $obj->fk_contact,
 
  218                'lastname' => $obj->name, 
 
  220                'other' => $otherTxt,
 
  221                'source_url' => $this->url($obj->id),
 
  222                'source_id' => (
int) $obj->id,
 
  223                'source_type' => 
'thirdparty' 
  233      $this->error = $this->db->error();
 
  237    return parent::addTargetsToDatabase($mailing_id, $cibles);
 
 
  271    $sql = 
"SELECT count(distinct(s.email)) as nb";
 
  272    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe as s";
 
  273    $sql .= 
" WHERE s.email <> ''";
 
  274    $sql .= 
" AND s.entity IN (".getEntity(
'societe').
")";
 
  275    if (empty($this->evenunsubscribe)) {
 
  276      $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).
")";
 
  280    return parent::getNbOfRecipients($sql);
 
 
  291    global 
$conf, $langs;
 
  293    $langs->load(
"companies");
 
  296    $s = 
'<select id="filter_thirdparties" name="filter_thirdparties" class="flat maxwidth200">';
 
  299    $sql = 
"SELECT rowid, label, type, visible";
 
  300    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"categorie";
 
  301    $sql .= 
" WHERE type in (1,2)"; 
 
  303    $sql .= 
" AND entity = ".$conf->entity;
 
  304    $sql .= 
" ORDER BY label";
 
  307    $resql = $this->db->query($sql);
 
  309      $num = $this->db->num_rows($resql);
 
  311      if (!isModEnabled(
"category")) {
 
  316        $s .= 
'<option value="-1">'.$langs->trans(
"Categories").
'</option>';
 
  318        $s .= 
'<option value="0">'.$langs->trans(
"ContactsAllShort").
'</option>';
 
  323        $obj = $this->db->fetch_object($resql);
 
  326        if ($obj->type == 1) {
 
  327          $type = $langs->trans(
"Supplier");
 
  329        if ($obj->type == 2) {
 
  330          $type = $langs->trans(
"Customer");
 
  332        $labeltoshow = $obj->label;
 
  334          $labeltoshow .= 
' <span class="opacitymedium">('.$type.
')</span>';
 
  336        $s .= 
'<option value="'.$obj->rowid.
'" data-html="'.
dol_escape_htmltag($labeltoshow).
'">';
 
  349    $s .= 
'<select id="filter_client_thirdparties" name="filter_client_thirdparties" class="flat minwidth100">';
 
  350    $s .= 
'<option value="-1">'.$langs->trans(
'ProspectCustomer').
'</option>';
 
  352      $s .= 
'<option value="2">'.$langs->trans(
'Prospect').
'</option>';
 
  355      $s .= 
'<option value="3">'.$langs->trans(
'ProspectCustomer').
'</option>';
 
  358      $s .= 
'<option value="1">'.$langs->trans(
'Customer').
'</option>';
 
  360    $s .= 
'<option value="0">'.$langs->trans(
'NorProspectNorCustomer').
'</option>';
 
  366    $s .= 
' <select id="filter_supplier_thirdparties" name="filter_supplier_thirdparties" class="flat minwidth100">';
 
  367    $s .= 
'<option value="-1">'.$langs->trans(
"Supplier").
'</option>';
 
  368    $s .= 
'<option value="1">'.$langs->trans(
"Yes").
'</option>';
 
  369    $s .= 
'<option value="0">'.$langs->trans(
"No").
'</option>';
 
  374    $s .= 
' <select id="filter_status_thirdparties" name="filter_status" class="flat">';
 
  375    $s .= 
'<option value="-1">'.$langs->trans(
"Status").
'</option>';
 
  376    $s .= 
'<option value="1">'.$langs->trans(
"Enabled").
'</option>';
 
  377    $s .= 
'<option value="0">'.$langs->trans(
"Disabled").
'</option>';
 
  384      require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
 
  386      $s .= 
img_picto($langs->trans(
"DefaultLang"), 
'language', 
'class="pictofixedwidth"');
 
  388      $s .= $formadmin->select_language(
GETPOST(
'filter_lang_thirdparties', 
'aZ09'), 
'filter_lang_thirdparties', 0, 
null, $langs->trans(
"DefaultLang"), 0, 0, 
'', 0, 0, 0, 
null, 1);
 
 
  403    return '<a href="'.DOL_URL_ROOT.
'/societe/card.php?socid='.
$id.
'">'.
img_object(
'', 
"company").
'</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.
 
url($id)
Can include an URL link on each record provided by selector shown on target page.
 
__construct($db)
Constructor.
 
add_to_target($mailing_id)
This is the main function that returns the array of emails.
 
formFilter()
This is to add a form filter to provide variant of selector If used, the HTML select must be called "...
 
getNbOfRecipients($sql='')
Return here number of distinct emails returned by your selector.
 
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
 
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
 
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
 
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
 
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...
 
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
 
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...