dolibarr 23.0.3
partnership_contact.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 NextGestion <contact@nextgestion.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
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 */
20
28// Load Dolibarr environment
29require '../main.inc.php';
30
31require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
34require_once DOL_DOCUMENT_ROOT.'/partnership/lib/partnership.lib.php';
35
44// Load translation files required by the page
45$langs->loadLangs(array("partnership", "companies", "other", "mails"));
46
47$id = (GETPOST('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
48$ref = GETPOST('ref', 'alpha');
49$lineid = GETPOSTINT('lineid');
50$socid = GETPOSTINT('socid');
51$action = GETPOST('action', 'aZ09');
52
53// Initialize a technical objects
54$object = new Partnership($db);
55$extrafields = new ExtraFields($db);
56$diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id;
57$hookmanager->initHooks(array('partnershipcontact', 'globalcard')); // Note that conf->hooks_modules contains array
58// Fetch optionals attributes and labels
59$extrafields->fetch_name_optionals_label($object->table_element);
60
61// Load object
62include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
63
64$permissiontoread = $user->hasRight('partnership', 'read');
65$permission = $user->hasRight('partnership', 'write');
66$managedfor = getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty');
67
68// Security check - Protection if external user
69//if ($user->socid > 0) accessforbidden();
70//if ($user->socid > 0) $socid = $user->socid;
71//restrictedArea($user, 'partnership', $object->id);
72if (empty($conf->partnership->enabled)) {
74}
75if (empty($permissiontoread)) {
77}
78if ($object->id > 0 && !($object->fk_member > 0) && $managedfor == 'member') {
80}
81if ($object->id > 0 && !($object->fk_soc > 0) && $managedfor == 'thirdparty') {
83}
84
85
86
87/*
88 * Actions
89 */
90
91if ($action == 'addcontact' && $permission) {
92 $contactid = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
93 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
94 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
95
96 if ($result >= 0) {
97 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
98 exit;
99 } else {
100 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
101 $langs->load("errors");
102 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
103 } else {
104 setEventMessages($object->error, $object->errors, 'errors');
105 }
106 }
107} elseif ($action == 'swapstatut' && $permission) {
108 // Toggle the status of a contact
109 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
110} elseif ($action == 'deletecontact' && $permission) {
111 // Deletes a contact
112 $result = $object->delete_contact($lineid);
113
114 if ($result >= 0) {
115 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
116 exit;
117 } else {
118 dol_print_error($db);
119 }
120}
121
122
123/*
124 * View
125 */
126
127$title = $langs->trans('Partnership')." - ".$langs->trans('ContactsAddresses');
128$help_url = '';
129//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
130llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-partnership page-contact');
131
132$form = new Form($db);
133$formcompany = new FormCompany($db);
134$contactstatic = new Contact($db);
135$userstatic = new User($db);
136
137
138/* *************************************************************************** */
139/* */
140/* View and edit mode */
141/* */
142/* *************************************************************************** */
143
144if ($object->id) {
145 /*
146 * Show tabs
147 */
148 $head = partnershipPrepareHead($object);
149
150 print dol_get_fiche_head($head, 'contact', $langs->trans("Partnership"), -1, $object->picto);
151
152 $linkback = '<a href="'.dol_buildpath('/partnership/partnership_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
153
154 $morehtmlref = '<div class="refidno">';
155 /*
156 // Ref customer
157 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
158 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
159 // Thirdparty
160 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
161 // Project
162 if (isModEnabled('project'))
163 {
164 $langs->load("projects");
165 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
166 if ($permissiontoadd)
167 {
168 if ($action != 'classify')
169 //$morehtmlref.='<a class="editfielda" href="' . dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true) . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
170 $morehtmlref.=' : ';
171 if ($action == 'classify') {
172 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
173 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
174 $morehtmlref.='<input type="hidden" name="action" value="classin">';
175 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
176 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
177 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
178 $morehtmlref.='</form>';
179 } else {
180 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
181 }
182 } else {
183 if (!empty($object->fk_project)) {
184 $proj = new Project($db);
185 $proj->fetch($object->fk_project);
186 $morehtmlref .= ': '.$proj->getNomUrl();
187 } else {
188 $morehtmlref .= '';
189 }
190 }
191 }*/
192 $morehtmlref .= '</div>';
193
194 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
195
196 print dol_get_fiche_end();
197
198 print '<br>';
199
200 // Contacts lines (modules that overwrite templates must declare this into descriptor)
201 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
202 foreach ($dirtpls as $reldir) {
203 $file = dol_buildpath($reldir.'/contacts.tpl.php');
204 if (file_exists($file)) {
205 $res = @include $file;
206 if ($res) {
207 break;
208 }
209 }
210 }
211}
212
213// End of page
214llxFooter();
215$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class for Partnership.
Class to manage Dolibarr users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
partnershipPrepareHead($object)
Prepare array of tabs for Partnership.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.