Merge pull request #1096 from FHenry/develop_categorycontact

Develop categorycontact
This commit is contained in:
Laurent Destailleur 2013-07-17 08:41:02 -07:00
commit 7b97214df5
15 changed files with 634 additions and 5 deletions

View File

@ -5,6 +5,7 @@
* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -79,6 +80,13 @@ if ($id || $ref)
$dbtablename = 'adherent';
$fieldid = ! empty($ref)?'ref':'rowid';
}
elseif ($type == 4) {
$elementtype = 'societe';
$objecttype = 'contact';
$objectid = isset($id)?$id:(isset($ref)?$ref:'');
$dbtablename = 'socpeople&societe';
$fieldid = ! empty($ref)?'ref':'rowid';
}
}
// Security check
@ -128,6 +136,13 @@ if (empty($reshook))
$result = $object->fetch($objectid);
$elementtype = 'member';
}
if ($type == 4 && $user->rights->societe->creer)
{
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$object = new Contact($db);
$result = $object->fetch($objectid);
$elementtype = 'contact';
}
$cat = new Categorie($db);
$result=$cat->fetch($removecat);
@ -163,6 +178,13 @@ if (empty($reshook))
$result = $object->fetch($objectid);
$elementtype = 'member';
}
if ($type == 4 && $user->rights->societe->creer)
{
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$object = new Contact($db);
$result = $object->fetch($objectid);
$elementtype = 'contact';
}
$cat = new Categorie($db);
$result=$cat->fetch($parent);
@ -431,6 +453,154 @@ else if ($id || $ref)
formCategory($db,$member,3);
}
if ($type == 4)
{
$langs->load("contact");
/*
* Fiche categorie d'contact
*/
require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
// Produit
$object = new Contact($db);
$result = $object->fetch($id, $ref);
$object->fetch_thirdparty();
llxHeader("","",$langs->trans("Contact"));
$head=contact_prepare_head($object, $user);
$titre=$langs->trans("Contact");
$picto='user';
dol_fiche_head($head, 'tabCategorie', $titre,0,$picto);
$rowspan=5;
if (! empty($conf->societe->enabled)) $rowspan++;
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
print '<td class="valeur">';
print $form->showrefnav($object,'rowid');
print '</td></tr>';
// Name
print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';
// Company
if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
{
print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
if (!empty($object->thirdparty->id))
{
print $object->thirdparty->getNomUrl(1);
}
else
{
print $langs->trans("ContactNotLinkedToCompany");
}
print '</td></tr>';
}
// Civility
print '<tr><td width="15%">'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $object->getCivilityLabel();
print '</td></tr>';
// Role
print '<tr><td>'.$langs->trans("PostOrFunction").'</td><td colspan="3">'.$object->poste.'</td>';
// Address
print '<tr><td>'.$langs->trans("Address").'</td><td colspan="3">';
dol_print_address($object->address,'gmap','contact',$object->id);
print '</td></tr>';
// Zip/Town
print '<tr><td>'.$langs->trans("Zip").' / '.$langs->trans("Town").'</td><td colspan="3">';
print $object->zip;
if ($object->zip) print '&nbsp;';
print $object->town.'</td></tr>';
// Country
print '<tr><td>'.$langs->trans("Country").'</td><td colspan="3">';
$img=picto_from_langcode($object->country_code);
if ($img) print $img.' ';
print $object->country;
print '</td></tr>';
// State
if (empty($conf->global->SOCIETE_DISABLE_STATE))
{
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">'.$object->state.'</td>';
}
// Phone
print '<tr><td>'.$langs->trans("PhonePro").'</td><td>'.dol_print_phone($object->phone_pro,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td>';
print '<td>'.$langs->trans("PhonePerso").'</td><td>'.dol_print_phone($object->phone_perso,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td></tr>';
print '<tr><td>'.$langs->trans("PhoneMobile").'</td><td>'.dol_print_phone($object->phone_mobile,$object->country_code,$object->id,$object->socid,'AC_TEL').'</td>';
print '<td>'.$langs->trans("Fax").'</td><td>'.dol_print_phone($object->fax,$object->country_code,$object->id,$object->socid,'AC_FAX').'</td></tr>';
// Email
print '<tr><td>'.$langs->trans("EMail").'</td><td>'.dol_print_email($object->email,$object->id,$object->socid,'AC_EMAIL').'</td>';
if (! empty($conf->mailing->enabled))
{
$langs->load("mails");
print '<td nowrap>'.$langs->trans("NbOfEMailingsReceived").'</td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/mailing/liste.php?filteremail='.urlencode($object->email).'">'.$object->getNbOfEMailings().'</a></td>';
}
else
{
print '<td colspan="2">&nbsp;</td>';
}
print '</tr>';
// Instant message and no email
print '<tr><td>'.$langs->trans("IM").'</td><td>'.$object->jabberid.'</td>';
if (!empty($conf->mailing->enabled))
{
print '<td>'.$langs->trans("No_Email").'</td><td>'.yn($object->no_email).'</td>';
}
else
{
print '<td colspan="2">&nbsp;</td>';
}
print '</tr>';
print '<tr><td>'.$langs->trans("ContactVisibility").'</td><td colspan="3">';
print $object->LibPubPriv($object->priv);
print '</td></tr>';
// Note Public
print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td><td colspan="3">';
print nl2br($object->note_public);
print '</td></tr>';
// Note Private
print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td><td colspan="3">';
print nl2br($object->note_private);
print '</td></tr>';
// Other attributes
$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
print $object->showOptionals($extrafields);
}
print '</table>';
dol_fiche_end();
dol_htmloutput_mesg($mesg);
formCategory($db,$object,4);
}
}
@ -451,6 +621,7 @@ function formCategory($db,$object,$typeid,$socid=0)
if ($typeid == 1) $title = $langs->trans("SuppliersCategoriesShort");
if ($typeid == 2) $title = $langs->trans("CustomersProspectsCategoriesShort");
if ($typeid == 3) $title = $langs->trans("MembersCategoriesShort");
if ($typeid == 4) $title = $langs->trans("ContactCategoriesShort");
// Formulaire ajout dans une categorie
print '<br>';
@ -490,6 +661,7 @@ function formCategory($db,$object,$typeid,$socid=0)
if ($typeid == 1) $title=$langs->trans("CompanyIsInSuppliersCategories");
if ($typeid == 2) $title=$langs->trans("CompanyIsInCustomersCategories");
if ($typeid == 3) $title=$langs->trans("MemberIsInCategories");
if ($typeid == 4) $title=$langs->trans("ContactIsInCategories");
print "\n";
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$title.':</td></tr>';
@ -517,6 +689,7 @@ function formCategory($db,$object,$typeid,$socid=0)
if ($typeid == 1) $permission=$user->rights->societe->creer;
if ($typeid == 2) $permission=$user->rights->societe->creer;
if ($typeid == 3) $permission=$user->rights->adherent->creer;
if ($typeid == 4) $permission=$user->rights->societe->creer;
if ($permission)
{
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid)?'id':'socid')."=".$object->id."&amp;type=".$typeid."&amp;removecat=".$cat->id."'>";
@ -544,6 +717,7 @@ function formCategory($db,$object,$typeid,$socid=0)
if ($typeid == 1) $title=$langs->trans("CompanyHasNoCategory");
if ($typeid == 2) $title=$langs->trans("CompanyHasNoCategory");
if ($typeid == 3) $title=$langs->trans("MemberHasNoCategory");
if ($typeid == 4) $title=$langs->trans("ContactHasNoCategory");
print $title;
print "<br/>";
}

View File

@ -378,10 +378,16 @@ class Categorie
function add_type($obj,$type)
{
if ($this->id == -1) return -2;
if ($type == 'company') $type='societe';
if ($type == 'fournisseur') $type='societe';
$column_name=$type;
if ($type=='contact') {
$column_name='socpeople';
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".$type." (fk_categorie, fk_".$type.")";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".$type." (fk_categorie, fk_".$column_name.")";
$sql .= " VALUES (".$this->id.", ".$obj->id.")";
dol_syslog(get_class($this).'::add_type sql='.$sql);
@ -413,9 +419,16 @@ class Categorie
*/
function del_type($obj,$type)
{
if ($type == 'company') $type='societe';
if ($type == 'fournisseur') $type='societe';
$column_name=$type;
if ($type=='contact') $column_name='socpeople';
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_".$type;
$sql .= " WHERE fk_categorie = ".$this->id;
$sql .= " AND fk_".($type=='fournisseur'?'societe':$type)." = ".$obj->id;
$sql .= " AND fk_".$column_name." = ".$obj->id;
dol_syslog(get_class($this).'::del_type sql='.$sql);
if ($this->db->query($sql))
@ -972,6 +985,7 @@ class Categorie
else if ($typeid == 1 || $typeid == 'supplier') { $typeid=1; $table='societe'; $type='fournisseur'; }
else if ($typeid == 2 || $typeid == 'customer') { $typeid=2; $table='societe'; $type='societe'; }
else if ($typeid == 3 || $typeid == 'member') { $typeid=3; $table='member'; $type='member'; }
else if ($typeid == 4 || $typeid == 'contact') { $typeid=4; $table='socpeople'; $type='contact'; }
$sql = "SELECT ct.fk_categorie, c.label";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie_".$type." as ct, ".MAIN_DB_PREFIX."categorie as c";

View File

@ -3,6 +3,7 @@
* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -53,6 +54,7 @@ if ($origin)
if ($type == 1) $idSupplierOrigin = $origin;
if ($type == 2) $idCompanyOrigin = $origin;
if ($type == 3) $idMemberOrigin = $origin;
if ($type == 4) $idContactOrigin = $origin;
}
if ($catorigin && $type == 0) $idCatOrigin = $catorigin;
@ -98,6 +100,11 @@ if ($action == 'add' && $user->rights->categorie->creer)
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCatOrigin.'&type='.$type);
exit;
}
else if ($idContactOrigin)
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&type='.$type);
exit;
}
else
{
header("Location: ".DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type);
@ -170,6 +177,11 @@ if (($action == 'add' || $action == 'confirmed') && $user->rights->categorie->cr
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idCatOrigin.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}
else if ($idContactOrigin)
{
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$idContactOrigin.'&mesg='.urlencode($langs->trans("CatCreated")));
exit;
}
header("Location: ".DOL_URL_ROOT.'/categories/viewcat.php?id='.$result.'&type='.$type);
exit;

View File

@ -27,6 +27,7 @@
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
$langs->load("companies");
$langs->load("suppliers");
@ -47,6 +48,7 @@ $search_phonemob=GETPOST("search_phonemob");
$search_fax=GETPOST("search_fax");
$search_email=GETPOST("search_email");
$search_priv=GETPOST("search_priv");
$search_categ = GETPOST("search_categ",'int');
$type=GETPOST("type");
$view=GETPOST("view");
@ -109,6 +111,7 @@ $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("
llxHeader('',$title,'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas');
$form=new Form($db);
$formother=new FormOther($db);
$sql = "SELECT s.rowid as socid, s.nom as name,";
$sql.= " p.rowid as cidp, p.lastname as lastname, p.firstname, p.poste, p.email,";
@ -117,6 +120,7 @@ $sql.= " cp.code as country_code";
$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as cp ON cp.rowid = p.fk_pays";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_contact as cs ON s.rowid = cs.fk_socpeople"; // We need this table joined to the select in order to filter by categ
if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
$sql.= ' WHERE p.entity IN ('.getEntity('societe', 1).')';
if (!$user->rights->societe->client->voir && !$socid) //restriction
@ -139,6 +143,9 @@ else
if ($search_priv == '1') $sql .= " AND (p.priv='1' AND p.fk_user_creat=".$user->id.")";
}
if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$search_categ;
if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL";
if ($search_lastname) // filter on lastname
{
$sql .= " AND p.lastname LIKE '%".$db->escape($search_lastname)."%'";
@ -235,7 +242,8 @@ if ($result)
$param ='&begin='.urlencode($begin).'&view='.urlencode($view).'&userid='.urlencode($userid).'&contactname='.urlencode($sall);
$param.='&type='.urlencode($type).'&view='.urlencode($view).'&search_lastname='.urlencode($search_lastname).'&search_firstname='.urlencode($search_firstname).'&search_societe='.urlencode($search_societe).'&search_email='.urlencode($search_email);
if ($search_priv == '0' || $search_priv == '1') $param.="&search_priv=".urlencode($search_priv);
if (!empty($search_categ)) $param.='&search_categ='.$search_categ;
if ($search_priv == '0' || $search_priv == '1') $param.="&search_priv=".urlencode($search_priv);
$num = $db->num_rows($result);
$i = 0;
@ -248,6 +256,19 @@ if ($result)
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
if (! empty($conf->categorie->enabled))
{
$moreforfilter.=$langs->trans('Categories'). ': ';
$moreforfilter.=$formother->select_categories(4,$search_categ,'search_categ',1);
$moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
}
if ($moreforfilter)
{
print '<div class="liste_titre">';
print $moreforfilter;
print '</div>';
}
if ($sall)
{
print $langs->trans("Filter")." (".$langs->trans("Lastname").", ".$langs->trans("Firstname")." ".$langs->trans("or")." ".$langs->trans("EMail")."): ".$sall;

View File

@ -30,7 +30,7 @@
*/
function contact_prepare_head($object)
{
global $langs, $conf;
global $langs, $conf, $user;
$h = 0;
$head = array();
@ -72,6 +72,15 @@ function contact_prepare_head($object)
$head[$h][2] = 'note';
$h++;
if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire))
{
$type = 4;
$head[$h][0] = DOL_URL_ROOT.'/categories/categorie.php?id='.$object->id."&type=".$type;
$head[$h][1] = $langs->trans('Categories');
$head[$h][2] = 'category';
$h++;
}
// Info
$head[$h][0] = DOL_URL_ROOT.'/contact/info.php?id='.$object->id;
$head[$h][1] = $langs->trans("Info");

View File

@ -0,0 +1,248 @@
<?php
/* Copyright (C) 2011 François Cerbelle <francois@cerbelle.net>
* Copyright (C) 2013 florian HENRY <florian.henry@open-concept.pro>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/modules/mailings/contacts4.modules.php
* \ingroup mailing
* \brief Provides a list of recipients for mailing module
*/
include_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
/**
* \class mailing_contacts4
* \brief Class to manage a list of personalised recipients for mailing feature
*/
class mailing_contacts4 extends MailingTargets
{
var $name='ContactsByCategory';
// This label is used if no translation is found for key MailingModuleDescXXX where XXX=name is found
var $desc='Add contacts by category';
var $require_admin=0;
var $require_module=array();
var $picto='contact';
var $db;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db=$db;
}
/**
* Renvoie url lien vers fiche de la source du destinataire du mailing
*
* @param int $id ID
* @return string Url lien
*/
function url($id)
{
return '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$id.'">'.img_object('',"contact").'</a>';
}
/**
* This is the main function that returns the array of emails
*
* @param int $mailing_id Id of mailing. No need to use it.
* @param array $filtersarray Category
* @return int <0 if error, number of emails added if ok
*/
function add_to_target($mailing_id,$filtersarray=array())
{
global $conf,$langs;
$target = array();
// La requete doit retourner: id, email, fk_contact, name, firstname, other
$sql = "SELECT sp.rowid as id, sp.email as email, sp.rowid as fk_contact,";
$sql.= " sp.lastname, sp.firstname, sp.civilite,";
$sql.= " s.nom as companyname";
$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
if ($filtersarray[0] <> 'all')$sql.= " INNER JOIN ".MAIN_DB_PREFIX."categorie_contact as cs ON cs.fk_socpeople=sp.rowid";
if ($filtersarray[0] <> 'all') $sql.= " INNER JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = sp.fk_soc";
$sql.= " WHERE sp.email != ''"; // Note that null != '' is false
$sql.= " AND sp.no_email = 0";
$sql.= " AND sp.entity IN (".getEntity('societe', 1).")";
if ($filtersarray[0] <> 'all') $sql.= " AND c.label = '".$this->db->escape($filtersarray[0])."'";
$sql.= " ORDER BY sp.lastname, sp.firstname";
dol_syslog(get_class($this).':: add_to_target sql='.$sql,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj= $this->db->fetch_object($resql);
$target[] = array(
'email' => $obj->email,
'fk_contact' => $obj->fk_contact,
'lastname' => $obj->lastname,
'firstname' => $obj->firstname,
'other' =>
($langs->transnoentities("ThirdParty").'='.$obj->companyname).';'.
($langs->transnoentities("UserTitle").'='.($obj->civilite?$langs->transnoentities("Civility".$obj->civilite):'')),
'source_url' => $this->url($obj->id),
'source_id' => $obj->id,
'source_type' => 'contact'
);
$i++;
}
}else {
$this->error=$this->db->lasterrno();
dol_syslog(get_class($this)."Error sql=".$sql." ".$this->error, LOG_ERR);
return -1;
}
return parent::add_to_target($mailing_id, $target);
}
/**
* 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
*/
function getSqlArrayForStats()
{
global $conf, $langs;
$statssql=array();
/*for ($i=0; $i<5; $i++) {
$statssql[$i] = "SELECT c.label, count(sp.rowid) AS nb";
$statssql[$i].= " FROM ".MAIN_DB_PREFIX."socpeople as sp,";
$statssql[$i].= " ".MAIN_DB_PREFIX."societe as s,";
$statssql[$i].= " ".MAIN_DB_PREFIX."categorie as c,";
$statssql[$i].= " ".MAIN_DB_PREFIX."categorie_societe as cs";
$statssql[$i].= " WHERE s.rowid = sp.fk_soc";
$statssql[$i].= " AND sp.email != ''"; // Note that null != '' is false
$statssql[$i].= " AND sp.entity IN (".getEntity('societe', 1).")";
$statssql[$i].= " AND cs.fk_categorie = c.rowid";
$statssql[$i].= " AND cs.fk_societe = sp.fk_soc";
$statssql[$i].= " GROUP BY c.label";
$statssql[$i].= " ORDER BY nb DESC";
$statssql[$i].= " LIMIT $i,1";
}*/
return $statssql;
}
/**
* Return here number of distinct emails returned by your selector.
*
* @param string $sql Requete sql de comptage
* @return int Number of recipients
*/
function getNbOfRecipients($sql='')
{
global $conf;
// We must report here number of contacts when absolutely no filter selected (so all contacts).
// Number with a filter are show in the combo list for each filter.
// If we want a filter "is inside at least one category", we must add it into formFilter
$sql = "SELECT count(distinct(c.email)) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
$sql.= " WHERE c.entity IN (".getEntity('societe', 1).")";
$sql.= " AND c.email != ''"; // Note that null != '' is false
$sql.= " AND c.no_email = 0";
/*
$sql = "SELECT count(distinct(sp.email)) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp,";
$sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX."categorie as c,";
$sql.= " ".MAIN_DB_PREFIX."categorie_societe as cs";
$sql.= " WHERE s.rowid = sp.fk_soc";
$sql.= " AND sp.entity IN (".getEntity('societe', 1).")";
$sql.= " AND sp.email != ''"; // Note that null != '' is false
$sql.= " AND cs.fk_categorie = c.rowid";
$sql.= " AND cs.fk_societe = sp.fk_soc";
*/
// 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
*/
function formFilter()
{
global $conf, $langs;
$langs->load("companies");
$sql = "SELECT c.label, count(distinct(sp.email)) AS nb";
$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."categorie_contact as cs ON cs.fk_socpeople=sp.rowid";
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
$sql.= " WHERE sp.email != ''"; // Note that null != '' is false
$sql.= " AND sp.no_email = 0";
$sql.= " AND sp.entity IN (".getEntity('societe', 1).")";
$sql.= " GROUP BY c.label";
$sql.= " ORDER BY c.label";
$resql = $this->db->query($sql);
dol_syslog(get_class($this).':: formFilter sql='.$sql,LOG_DEBUG);
if ($resql) {
$s='';
$s.='<select name="filter" class="flat">';
$s.='<option value="all"></option>';
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$s.='<option value="'.$obj->label.'">'.$obj->label.' ('.$obj->nb.')</option>';
$i++;
}
}
$s.='</select>';
return $s;
}
else {
$this->error=$this->db->lasterrno();
dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
return -1;
}
}
}
?>

View File

@ -169,7 +169,6 @@ class MailingTargets // This can't be abstract as it is used for some method
$sql .= "'".$this->db->escape($targetarray['email'])."',";
$sql .= "'".$this->db->escape($targetarray['other'])."',";
$sql .= "'".$this->db->escape($targetarray['source_url'])."',";
$sql .= "'".$this->db->escape($targetarray['source_id'])."',";
$sql .= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").",";
if (! empty($conf->global->MAILING_EMAIL_UNSUBSCRIBE)) {
$sql .= "'".$this->db->escape(md5($targetarray['email'].';'.$targetarray['name'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY))."',";

View File

@ -163,6 +163,84 @@ class modCategorie extends DolibarrModules
$this->export_sql_end[$r] .=' WHERE u.rowid = cp.fk_categorie AND cp.fk_member = p.rowid';
$this->export_sql_end[$r] .=' AND u.entity = '.$conf->entity;
$this->export_sql_end[$r] .=' AND u.type = 3'; // Supplier categories
$r = 0;
$r ++;
$this->export_code [$r] = 'category_'.$r;
$this->export_label [$r] = 'CatContactList';
$this->export_icon [$r] = 'category';
$this->export_enabled [$r] = '$conf->societe->enabled';
$this->export_permission [$r] = array (
array (
"categorie",
"lire"
),
array (
"societe",
"lire"
)
);
$this->export_fields_array [$r] = array (
'u.rowid' => "CategId",
'u.label' => "Label",
'u.description' => "Description",
'p.rowid' => 'ContactId',
'p.civilite' => 'Civitity',
'p.lastname' => 'LastName',
'p.firstname' => 'Firstname',
'p.address' => 'Address',
'p.zip' => 'Zip',
'p.town' => 'Town',
'country.code' => 'CountryCode',
'country.libelle' => 'Country',
'p.birthday' => 'DateToBirth',
'p.poste' => 'PostOrFunction',
'p.phone' => 'Phone',
'p.phone_perso' => 'PhonePerso',
'p.phone_mobile' => 'PhoneMobile',
'p.fax' => 'Fax',
'p.email' => 'Email',
'p.note_private' => 'NotePrivate',
'p.note_public' => 'NotePublic'
);
$this->export_TypeFields_array [$r] = array (
'u.label' => "Text",
'u.description' => "Text",
'p.rowid' => 'List:contact:lastname',
'p.lastname' => 'Text',
'p.firstname' => 'Text'
);
$this->export_entities_array [$r] = array (
'u.rowid' => "category",
'u.label' => "category",
'u.description' => "category",
'p.rowid' => 'contact',
'p.rowid' => 'contact',
'p.civilite' => 'contact',
'p.lastname' => 'contact',
'p.firstname' => 'contact',
'p.address' => 'contact',
'p.zip' => 'contact',
'p.town' => 'contact',
'country.code' => 'contact',
'country.libelle' => 'contact',
'p.birthday' => 'contact',
'p.poste' => 'contact',
'p.phone' => 'contact',
'p.phone_perso' => 'contact',
'p.phone_mobile' => 'contact',
'p.fax' => 'contact',
'p.email' => 'contact',
'p.note_private' => 'contact',
'p.note_public' => 'contact'
); // We define here only fields that use another picto
$this->export_sql_start [$r] = 'SELECT DISTINCT ';
$this->export_sql_end [$r] .= ' FROM ' . MAIN_DB_PREFIX . 'categorie as u ';
$this->export_sql_end [$r] .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'categorie_contact as cp ON u.rowid = cp.fk_categorie ';
$this->export_sql_end [$r] .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'socpeople as p ON cp.fk_socpeople = p.rowid ';
$this->export_sql_end [$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_pays as country ON p.fk_pays = country.rowid';
$this->export_sql_end [$r] .= ' WHERE u.entity = ' . $conf->entity;
$this->export_sql_end [$r] .= ' AND u.type = 4'; // contact categories
// Imports
//--------

View File

@ -75,3 +75,19 @@ ALTER TABLE llx_cronjob ADD libname VARCHAR(255);
INSERT INTO llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values (30,'PROJECT_CREATE','Project creation','Executed when a project is created','project',30);
create table llx_categorie_contact
(
fk_categorie integer NOT NULL,
fk_socpeople integer NOT NULL,
import_key varchar(14)
)ENGINE=innodb;
ALTER TABLE llx_categorie_contact ADD PRIMARY KEY pk_categorie_contact (fk_categorie, fk_socpeople);
ALTER TABLE llx_categorie_contact ADD INDEX idx_categorie_contact_fk_categorie (fk_categorie);
ALTER TABLE llx_categorie_contact ADD INDEX idx_categorie_contact_fk_socpeople (fk_socpeople);
ALTER TABLE llx_categorie_contact ADD CONSTRAINT fk_categorie_contact_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid);
ALTER TABLE llx_categorie_contact ADD CONSTRAINT fk_categorie_contact_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople (rowid);

View File

@ -0,0 +1,24 @@
-- ============================================================================
-- Copyright (C) 2013 Florian HENRY <florian.henry@open-concept.pro>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ============================================================================
ALTER TABLE llx_categorie_contact ADD PRIMARY KEY pk_categorie_contact (fk_categorie, fk_socpeople);
ALTER TABLE llx_categorie_contact ADD INDEX idx_categorie_contact_fk_categorie (fk_categorie);
ALTER TABLE llx_categorie_contact ADD INDEX idx_categorie_contact_fk_socpeople (fk_socpeople);
ALTER TABLE llx_categorie_contact ADD CONSTRAINT fk_categorie_contact_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid);
ALTER TABLE llx_categorie_contact ADD CONSTRAINT fk_categorie_contact_fk_socpeople FOREIGN KEY (fk_socpeople) REFERENCES llx_socpeople (rowid);

View File

@ -0,0 +1,24 @@
-- ============================================================================
-- Copyright (C) 2013 Florian HENRY <florian.henry@open-concept.pro>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ============================================================================
create table llx_categorie_contact
(
fk_categorie integer NOT NULL,
fk_socpeople integer NOT NULL,
import_key varchar(14)
)ENGINE=innodb;

View File

@ -50,10 +50,12 @@ SupplierIsInCategories=Third party owns to following suppliers categories
CompanyIsInCustomersCategories=This third party owns to following customers/prospects categories
CompanyIsInSuppliersCategories=This third party owns to following suppliers categories
MemberIsInCategories=This member owns to following members categories
ContactIsInCategories=This contact owns to following contacts categories
ProductHasNoCategory=This product/service is not in any categories
SupplierHasNoCategory=This supplier is not in any categories
CompanyHasNoCategory=This company is not in any categories
MemberHasNoCategory=This member is not in any categories
ContactHasNoCategory=This contact is not in any categories
ClassifyInCategory=Classify in category
NoneCategory=None
NotCategorized=Without category
@ -79,6 +81,7 @@ CustomersCategoriesShort=Customers categories
CustomersProspectsCategoriesShort=Custo./Prosp. categories
ProductsCategoriesShort=Products categories
MembersCategoriesShort=Members categories
ContactCategoriesShort=Contacts categories
ThisCategoryHasNoProduct=This category does not contain any product.
ThisCategoryHasNoSupplier=This category does not contain any supplier.
ThisCategoryHasNoCustomer=This category does not contain any customer.
@ -92,6 +95,7 @@ CatSupList=List of supplier categories
CatCusList=List of customer/prospect categories
CatProdList=List of products categories
CatMemberList=List of members categories
CatContactList=List of contact categories and contact
CatSupLinks=Links between suppliers and categories
CatCusLinks=Links between customers/prospects and categories
CatProdLinks=Links between products/services and categories

View File

@ -90,6 +90,7 @@ MailingModuleDescEmailsFromUser=EMails from user input (email;lastname;firstname
MailingModuleDescContactsCategories=Third parties (by category)
MailingModuleDescDolibarrContractsLinesExpired=Third parties with expired contract's lines
MailingModuleDescContactsByCompanyCategory=Contacts/addresses of third parties (by third parties category)
MailingModuleDescContactsByCategory=Contacts/addresses of third parties by category
MailingModuleDescMembersCategories=Foundation members (by categories)
MailingModuleDescContactsByFunction=Contacts/addresses of third parties (by position/function)

View File

@ -50,10 +50,12 @@ SupplierIsInCategories=Ce fournisseur est dans les catégories suivantes
CompanyIsInCustomersCategories=Cette société est dans les catégories clients/prospects suivantes
CompanyIsInSuppliersCategories=Cette société est dans les catégories fournisseurs suivantes
MemberIsInCategories=Cet adhérent est dans les catégories adhérent suivantes
ContactIsInCategories=Ce contact est dans les catégories contact suivantes
ProductHasNoCategory=Ce produit/service n'est dans aucune catégorie en particulier
SupplierHasNoCategory=Ce fournisseur n'est dans aucune catégorie en particulier
CompanyHasNoCategory=Cette société n'est dans aucune catégorie en particulier
MemberHasNoCategory=Cet adhérent n'est dans aucune catégorie en particulier
ContactHasNoCategory=Ce contact n'est dans aucune catégorie en particulier
ClassifyInCategory=Classer dans la catégorie
NoneCategory=Aucune
NotCategorized=Sans catégorie
@ -74,6 +76,7 @@ SuppliersCategoryShort=Catégorie fournisseurs
CustomersCategoryShort=Catégorie clients
ProductsCategoryShort=Catégorie produits
MembersCategoryShort=Catégorie adhérent
ContactCategoriesShort=Catégorie Contacts
SuppliersCategoriesShort=Catégories fournisseurs
CustomersCategoriesShort=Catégories clients
CustomersProspectsCategoriesShort=Catégories clients/prospects
@ -92,6 +95,7 @@ CatSupList=Liste des catégories fournisseurs
CatCusList=Liste des catégories clients/prospects
CatProdList=Liste des catégories produits
CatMemberList=Liste des catégories adhérents
CatContactList=Liste des catégories contacts et contacts
CatSupLinks=Liens entre les fournisseurs et les catégories
CatCusLinks=Liens entre les clients/prospects et les catégories
CatProdLinks=Liens entre les produits/services et les catégories

View File

@ -90,6 +90,7 @@ MailingModuleDescEmailsFromUser=Emails saisis manuellement (email;nom;prenom;aut
MailingModuleDescContactsCategories=Tiers (par catégorie)
MailingModuleDescDolibarrContractsLinesExpired=Tiers avec lignes de contrats de services expirées
MailingModuleDescContactsByCompanyCategory=Contacts de tiers (par catégorie de tiers)
MailingModuleDescContactsByCategory=Contacts de tiers par catégorie de contact
MailingModuleDescMembersCategories=Adhérents (par catégorie)
MailingModuleDescContactsByFunction=Contacts de tiers (par poste/fonction)