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