diff --git a/htdocs/categories/categorie.php b/htdocs/categories/categorie.php index 2d33607c092..7b88fa1bd6f 100644 --- a/htdocs/categories/categorie.php +++ b/htdocs/categories/categorie.php @@ -5,6 +5,7 @@ * Copyright (C) 2006-2011 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2010 Juanjo Menent + * Copyright (C) 2013 Florian Henry * * 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 ''; + + // Ref + print ''; + print ''; + + // Name + print ''; + print ''; + + // Company + if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) + { + print ''; + } + + // Civility + print ''; + + // Role + print ''; + + // Address + print ''; + + // Zip/Town + print ''; + + // Country + print ''; + + // State + if (empty($conf->global->SOCIETE_DISABLE_STATE)) + { + print ''; + } + + // Phone + print ''; + print ''; + + print ''; + print ''; + + // Email + print ''; + if (! empty($conf->mailing->enabled)) + { + $langs->load("mails"); + print ''; + print ''; + } + else + { + print ''; + } + print ''; + + // Instant message and no email + print ''; + if (!empty($conf->mailing->enabled)) + { + print ''; + } + else + { + print ''; + } + print ''; + + print ''; + + // Note Public + print ''; + + // Note Private + print ''; + + // 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 '
'.$langs->trans("Ref").''; + print $form->showrefnav($object,'rowid'); + print '
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$object->lastname.''.$langs->trans("Firstname").''.$object->firstname.'
'.$langs->trans("Company").''; + if (!empty($object->thirdparty->id)) + { + print $object->thirdparty->getNomUrl(1); + } + else + { + print $langs->trans("ContactNotLinkedToCompany"); + } + print '
'.$langs->trans("UserTitle").''; + print $object->getCivilityLabel(); + print '
'.$langs->trans("PostOrFunction").''.$object->poste.'
'.$langs->trans("Address").''; + dol_print_address($object->address,'gmap','contact',$object->id); + print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; + print $object->zip; + if ($object->zip) print ' '; + print $object->town.'
'.$langs->trans("Country").''; + $img=picto_from_langcode($object->country_code); + if ($img) print $img.' '; + print $object->country; + print '
'.$langs->trans('State').''.$object->state.'
'.$langs->trans("PhonePro").''.dol_print_phone($object->phone_pro,$object->country_code,$object->id,$object->socid,'AC_TEL').''.$langs->trans("PhonePerso").''.dol_print_phone($object->phone_perso,$object->country_code,$object->id,$object->socid,'AC_TEL').'
'.$langs->trans("PhoneMobile").''.dol_print_phone($object->phone_mobile,$object->country_code,$object->id,$object->socid,'AC_TEL').''.$langs->trans("Fax").''.dol_print_phone($object->fax,$object->country_code,$object->id,$object->socid,'AC_FAX').'
'.$langs->trans("EMail").''.dol_print_email($object->email,$object->id,$object->socid,'AC_EMAIL').''.$langs->trans("NbOfEMailingsReceived").''.$object->getNbOfEMailings().' 
'.$langs->trans("IM").''.$object->jabberid.''.$langs->trans("No_Email").''.yn($object->no_email).' 
'.$langs->trans("ContactVisibility").''; + print $object->LibPubPriv($object->priv); + print '
'.$langs->trans("NotePublic").''; + print nl2br($object->note_public); + print '
'.$langs->trans("NotePrivate").''; + print nl2br($object->note_private); + print '
'; + + 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 '
'; @@ -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 ''; print ''; @@ -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 ""; @@ -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 "
"; } diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 50950506778..ee4ff76a008 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -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"; diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index c97d023f5b8..b5d23ed8740 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -3,6 +3,7 @@ * Copyright (C) 2006-2011 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Patrick Raguin + * Copyright (C) 2013 Florian Henry * * 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; diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index eefbd4b73c6..d7ebb28034a 100755 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -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ó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 ''; print ''; + if (! empty($conf->categorie->enabled)) + { + $moreforfilter.=$langs->trans('Categories'). ': '; + $moreforfilter.=$formother->select_categories(4,$search_categ,'search_categ',1); + $moreforfilter.='       '; + } + if ($moreforfilter) + { + print '
'; + print $moreforfilter; + print '
'; + } + if ($sall) { print $langs->trans("Filter")." (".$langs->trans("Lastname").", ".$langs->trans("Firstname")." ".$langs->trans("or")." ".$langs->trans("EMail")."): ".$sall; diff --git a/htdocs/core/lib/contact.lib.php b/htdocs/core/lib/contact.lib.php index 96da640962d..f441229c1af 100644 --- a/htdocs/core/lib/contact.lib.php +++ b/htdocs/core/lib/contact.lib.php @@ -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"); diff --git a/htdocs/core/modules/mailings/contacts4.modules.php b/htdocs/core/modules/mailings/contacts4.modules.php new file mode 100644 index 00000000000..4138a605cae --- /dev/null +++ b/htdocs/core/modules/mailings/contacts4.modules.php @@ -0,0 +1,248 @@ + + * Copyright (C) 2013 florian HENRY + * + * 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 . + * 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 '
'.img_object('',"contact").''; + } + + /** + * 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.=''; + return $s; + } + else { + $this->error=$this->db->lasterrno(); + dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR); + return -1; + } + + } + +} + +?> diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php index 9d84058fa87..74d79547e2f 100644 --- a/htdocs/core/modules/mailings/modules_mailings.php +++ b/htdocs/core/modules/mailings/modules_mailings.php @@ -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))."',"; diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php index f4f4044a88b..d83d4fed1cc 100644 --- a/htdocs/core/modules/modCategorie.class.php +++ b/htdocs/core/modules/modCategorie.class.php @@ -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 //-------- diff --git a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql index 549397f99a0..e55f063ab15 100755 --- a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql +++ b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql @@ -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); + + diff --git a/htdocs/install/mysql/tables/llx_categorie_contact.key.sql b/htdocs/install/mysql/tables/llx_categorie_contact.key.sql new file mode 100644 index 00000000000..7720749afcc --- /dev/null +++ b/htdocs/install/mysql/tables/llx_categorie_contact.key.sql @@ -0,0 +1,24 @@ +-- ============================================================================ +-- Copyright (C) 2013 Florian HENRY +-- +-- 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 . +-- +-- ============================================================================ + +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); diff --git a/htdocs/install/mysql/tables/llx_categorie_contact.sql b/htdocs/install/mysql/tables/llx_categorie_contact.sql new file mode 100644 index 00000000000..d05cc195322 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_categorie_contact.sql @@ -0,0 +1,24 @@ +-- ============================================================================ +-- Copyright (C) 2013 Florian HENRY +-- +-- 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 . +-- +-- ============================================================================ + +create table llx_categorie_contact +( + fk_categorie integer NOT NULL, + fk_socpeople integer NOT NULL, + import_key varchar(14) +)ENGINE=innodb; diff --git a/htdocs/langs/en_US/categories.lang b/htdocs/langs/en_US/categories.lang index 3fce7f62d2a..bddaf125aec 100644 --- a/htdocs/langs/en_US/categories.lang +++ b/htdocs/langs/en_US/categories.lang @@ -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 diff --git a/htdocs/langs/en_US/mails.lang b/htdocs/langs/en_US/mails.lang index b7acdd63d86..f8262b44c95 100644 --- a/htdocs/langs/en_US/mails.lang +++ b/htdocs/langs/en_US/mails.lang @@ -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) diff --git a/htdocs/langs/fr_FR/categories.lang b/htdocs/langs/fr_FR/categories.lang index 6e3ad923600..c14906dd2fb 100644 --- a/htdocs/langs/fr_FR/categories.lang +++ b/htdocs/langs/fr_FR/categories.lang @@ -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 diff --git a/htdocs/langs/fr_FR/mails.lang b/htdocs/langs/fr_FR/mails.lang index 0c1d7c593fd..d6cc533d7c6 100644 --- a/htdocs/langs/fr_FR/mails.lang +++ b/htdocs/langs/fr_FR/mails.lang @@ -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)
'.$title.':