dolibarr  16.0.5
contact.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2010-2017 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2015-2021 Frederic France <frederic.france@netlogic.fr>
5  * Copyright (C) 2015 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  * or see https://www.gnu.org/
20  */
21 
33 function contact_prepare_head(Contact $object)
34 {
35  global $db, $langs, $conf, $user;
36 
37  $tab = 0;
38  $head = array();
39 
40  $head[$tab][0] = DOL_URL_ROOT.'/contact/card.php?id='.$object->id;
41  $head[$tab][1] = $langs->trans("Contact");
42  $head[$tab][2] = 'card';
43  $tab++;
44 
45  if ((!empty($conf->ldap->enabled) && !empty($conf->global->LDAP_CONTACT_ACTIVE))
46  && (empty($conf->global->MAIN_DISABLE_LDAP_TAB) || !empty($user->admin))) {
47  $langs->load("ldap");
48 
49  $head[$tab][0] = DOL_URL_ROOT.'/contact/ldap.php?id='.$object->id;
50  $head[$tab][1] = $langs->trans("LDAPCard");
51  $head[$tab][2] = 'ldap';
52  $tab++;
53  }
54 
55  $head[$tab][0] = DOL_URL_ROOT.'/contact/perso.php?id='.$object->id;
56  $head[$tab][1] = $langs->trans("PersonalInformations");
57  $head[$tab][2] = 'perso';
58  $tab++;
59 
60  if (!empty($conf->project->enabled) && $user->hasRight('project', 'lire')) {
61  $nbProject = 0;
62  // Enable caching of thirdrparty count projects
63  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
64  $cachekey = 'count_projects_contact_'.$object->id;
65  $dataretrieved = dol_getcache($cachekey);
66 
67  if (!is_null($dataretrieved)) {
68  $nbProject = $dataretrieved;
69  } else {
70  $sql = 'SELECT COUNT(n.rowid) as nb';
71  $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as n';
72  $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact as cc ON (n.rowid = cc.element_id)';
73  $sql .= ' WHERE cc.fk_socpeople = '.((int) $object->id);
74  $sql .= ' AND cc.fk_c_type_contact IN (SELECT rowid FROM '.MAIN_DB_PREFIX."c_type_contact WHERE element='project' AND source='external')";
75  $sql .= ' AND n.entity IN ('.getEntity('project').')';
76  $resql = $db->query($sql);
77  if ($resql) {
78  $obj = $db->fetch_object($resql);
79  $nbProject = $obj->nb;
80  } else {
81  dol_print_error($db);
82  }
83  dol_setcache($cachekey, $nbProject, 120); // If setting cache fails, this is not a problem, so we do not test result.
84  }
85  $head[$tab][0] = DOL_URL_ROOT.'/contact/project.php?id='.$object->id;
86  $head[$tab][1] = $langs->trans("Projects");
87  if ($nbProject > 0) {
88  $head[$tab][1] .= '<span class="badge marginleftonlyshort">'.$nbProject.'</span>';
89  }
90  $head[$tab][2] = 'project';
91  $tab++;
92  }
93 
94  // Related items
95  if (!empty($conf->commande->enabled) || !empty($conf->propal->enabled) || isModEnabled('facture') || !empty($conf->ficheinter->enabled) || (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) {
96  $head[$tab][0] = DOL_URL_ROOT.'/contact/consumption.php?id='.$object->id;
97  $head[$tab][1] = $langs->trans("Referers");
98  $head[$tab][2] = 'consumption';
99  $tab++;
100  }
101 
102  // Show more tabs from modules
103  // Entries must be declared in modules descriptor with line
104  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
105  // $this->tabs = array('entity:-tabname); to remove a tab
106  complete_head_from_modules($conf, $langs, $object, $head, $tab, 'contact');
107 
108  // Notes
109  if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
110  $nbNote = (empty($object->note_private) ? 0 : 1) + (empty($object->note_public) ? 0 : 1);
111  $head[$tab][0] = DOL_URL_ROOT.'/contact/note.php?id='.$object->id;
112  $head[$tab][1] = $langs->trans("Note");
113  if ($nbNote > 0) {
114  $head[$tab][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
115  }
116  $head[$tab][2] = 'note';
117  $tab++;
118  }
119 
120  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
121  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
122  $upload_dir = $conf->societe->dir_output."/contact/".dol_sanitizeFileName($object->ref);
123  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
124  $nbLinks = Link::count($db, $object->element, $object->id);
125  $head[$tab][0] = DOL_URL_ROOT.'/contact/document.php?id='.$object->id;
126  $head[$tab][1] = $langs->trans("Documents");
127  if (($nbFiles + $nbLinks) > 0) {
128  $head[$tab][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
129  }
130  $head[$tab][2] = 'documents';
131  $tab++;
132 
133  // Agenda / Events
134  $head[$tab][0] = DOL_URL_ROOT.'/contact/agenda.php?id='.$object->id;
135  $head[$tab][1] = $langs->trans("Events");
136  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
137  $head[$tab][1] .= '/';
138  $head[$tab][1] .= $langs->trans("Agenda");
139  }
140  $head[$tab][2] = 'agenda';
141  $tab++;
142 
143  // Log
144  /*
145  $head[$tab][0] = DOL_URL_ROOT.'/contact/info.php?id='.$object->id;
146  $head[$tab][1] = $langs->trans("Info");
147  $head[$tab][2] = 'info';
148  $tab++;*/
149 
150  complete_head_from_modules($conf, $langs, $object, $head, $tab, 'contact', 'remove');
151 
152  return $head;
153 }
154 
167 function show_contacts_projects($conf, $langs, $db, $object, $backtopage = '', $nocreatelink = 0, $morehtmlright = '')
168 {
169  global $user;
170 
171  $i = -1;
172 
173  if (!empty($conf->project->enabled) && $user->rights->projet->lire) {
174  $langs->load("projects");
175 
176  $newcardbutton = '';
177  if (!empty($conf->project->enabled) && $user->rights->projet->creer && empty($nocreatelink)) {
178  $newcardbutton .= dolGetButtonTitle($langs->trans('AddProject'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/card.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage));
179  }
180 
181  print "\n";
182  print load_fiche_titre($langs->trans("ProjectsHavingThisContact"), $newcardbutton.$morehtmlright, '');
183  print '<div class="div-table-responsive">';
184  print "\n".'<table class="noborder" width=100%>';
185 
186  $sql = 'SELECT p.rowid as id, p.entity, p.title, p.ref, p.public, p.dateo as do, p.datee as de, p.fk_statut as status, p.fk_opp_status, p.opp_amount, p.opp_percent, p.tms as date_update, p.budget_amount';
187  $sql .= ', cls.code as opp_status_code, ctc.libelle';
188  $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p';
189  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_lead_status as cls on p.fk_opp_status = cls.rowid';
190  $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact as cc ON (p.rowid = cc.element_id)';
191  $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_contact as ctc ON (ctc.rowid = cc.fk_c_type_contact)';
192  $sql .= ' WHERE cc.fk_socpeople = '.((int) $object->id);
193  $sql .= " AND ctc.element='project' AND ctc.source='external'";
194  $sql .= ' AND p.entity IN ('.getEntity('project').')';
195  $sql .= ' ORDER BY p.dateo DESC';
196 
197  $result = $db->query($sql);
198  if ($result) {
199  $num = $db->num_rows($result);
200 
201  print '<tr class="liste_titre">';
202  print '<td>'.$langs->trans("Ref").'</td>';
203  print '<td>'.$langs->trans("Name").'</td>';
204  print '<td>'.$langs->trans("ContactType").'</td>';
205  print '<td class="center">'.$langs->trans("DateStart").'</td>';
206  print '<td class="center">'.$langs->trans("DateEnd").'</td>';
207  print '<td class="right">'.$langs->trans("OpportunityAmountShort").'</td>';
208  print '<td class="center">'.$langs->trans("OpportunityStatusShort").'</td>';
209  print '<td class="right">'.$langs->trans("OpportunityProbabilityShort").'</td>';
210  print '<td class="right">'.$langs->trans("Status").'</td>';
211  print '</tr>';
212 
213  if ($num > 0) {
214  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
215 
216  $projecttmp = new Project($db);
217 
218  $i = 0;
219 
220  while ($i < $num) {
221  $obj = $db->fetch_object($result);
222  $projecttmp->fetch($obj->id);
223 
224  // To verify role of users
225  $userAccess = $projecttmp->restrictedProjectArea($user);
226 
227  if ($user->rights->projet->lire && $userAccess > 0) {
228  print '<tr class="oddeven">';
229 
230  // Ref
231  print '<td>';
232  print $projecttmp->getNomUrl(1);
233  print '</td>';
234 
235  // Label
236  print '<td>'.$obj->title.'</td>';
237  print '<td>'.$obj->libelle.'</td>';
238  // Date start
239  print '<td class="center">'.dol_print_date($db->jdate($obj->do), "day").'</td>';
240  // Date end
241  print '<td class="center">'.dol_print_date($db->jdate($obj->de), "day").'</td>';
242  // Opp amount
243  print '<td class="right">';
244  if ($obj->opp_status_code) {
245  print price($obj->opp_amount, 1, '', 1, -1, -1, '');
246  }
247  print '</td>';
248  // Opp status
249  print '<td class="center">';
250  if ($obj->opp_status_code) {
251  print $langs->trans("OppStatus".$obj->opp_status_code);
252  }
253  print '</td>';
254  // Opp percent
255  print '<td class="right">';
256  if ($obj->opp_percent) {
257  print price($obj->opp_percent, 1, '', 1, 0).'%';
258  }
259  print '</td>';
260  // Status
261  print '<td class="right">'.$projecttmp->getLibStatut(5).'</td>';
262 
263  print '</tr>';
264  }
265  $i++;
266  }
267  } else {
268  print '<tr class="oddeven"><td colspan="8"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
269  }
270  $db->free($result);
271  } else {
272  dol_print_error($db);
273  }
274  print "</table>";
275  print '</div>';
276 
277  print "<br>\n";
278  }
279 
280  return $i;
281 }
dol_setcache
dol_setcache($memoryid, $data, $expire=0)
Save data into a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:68
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
Project
Class to manage projects.
Definition: project.class.php:35
dol_getcache
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:135
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10605
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
show_contacts_projects
show_contacts_projects($conf, $langs, $db, $object, $backtopage='', $nocreatelink=0, $morehtmlright='')
Show html area for list of projects.
Definition: contact.lib.php:167
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
contact_prepare_head
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541