dolibarr 25.0.0-alpha
myobject_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) 2024-2025 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) ---Replace with your own copyright and developer email---
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27$res = 0;
28// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
29if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
30 $res = @include str_replace("..", "", $_SERVER["CONTEXT_DOCUMENT_ROOT"])."/main.inc.php";
31}
32// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
33$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
34$tmp2 = realpath(__FILE__);
35$i = strlen($tmp) - 1; // @phan-suppress-current-line DolibarrForbiddenFunctionPlugin
36$j = strlen($tmp2) - 1; // @phan-suppress-current-line DolibarrForbiddenFunctionPlugin
37while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
38 $i--;
39 $j--;
40}
41if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
42 $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
43}
44if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
45 $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
46}
47// Try main.inc.php using relative path
48if (!$res && file_exists("../main.inc.php")) {
49 $res = @include "../main.inc.php";
50}
51if (!$res && file_exists("../../main.inc.php")) {
52 $res = @include "../../main.inc.php";
53}
54if (!$res && file_exists("../../../main.inc.php")) {
55 $res = @include "../../../main.inc.php";
56}
57if (!$res) {
58 die("Include of main fails");
59}
68require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
69include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
70include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
71dol_include_once('/mymodule/class/myobject.class.php');
72dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
73
74// Load translation files required by the page
75$langs->loadLangs(array("mymodule@mymodule", "companies", "other", "mails"));
76
77$id = (GETPOST('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
78$ref = GETPOST('ref', 'alpha');
79$lineid = GETPOSTINT('lineid');
80$socid = GETPOSTINT('socid');
81$action = GETPOST('action', 'aZ09');
82
83// Initialize a technical objects
84$object = new MyObject($db);
85$extrafields = new ExtraFields($db);
86$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
87$hookmanager->initHooks(array($object->element.'contact', 'globalcard')); // Note that conf->hooks_modules contains array
88// Fetch optionals attributes and labels
89$extrafields->fetch_name_optionals_label($object->table_element);
90
91// Load object
92include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
93
94// There is several ways to check permission.
95// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
96$enablepermissioncheck = getDolGlobalInt('MYMODULE_ENABLE_PERMISSION_CHECK');
97if ($enablepermissioncheck) {
98 $permissiontoread = $user->hasRight('mymodule', 'myobject', 'read');
99 $permissiontoadd = $user->hasRight('mymodule', 'myobject', 'write');
100} else {
101 $permissiontoread = 1;
102 $permissiontoadd = 1;
103}
104
105// Security check (enable the most restrictive one)
106// BEGIN MODULEBUILDER ACCESSPOLICY
107//if ($user->socid > 0) accessforbidden();
108//if ($user->socid > 0) $socid = $user->socid;
109//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
110//restrictedArea($user, $object->module, $object->id, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft);
111// END MODULEBUILDER ACCESSPOLICY
112if (!isModEnabled("mymodule")) {
114}
115if (!$permissiontoread) {
117}
118
119
120/*
121 * Add a new contact
122 */
123
124if ($action == 'addcontact' && $permissiontoadd) {
125 $contactid = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
126 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
127 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
128
129 if ($result >= 0) {
130 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
131 exit;
132 } else {
133 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
134 $langs->load("errors");
135 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
136 } else {
137 setEventMessages($object->error, $object->errors, 'errors');
138 }
139 }
140} elseif ($action == 'swapstatut' && $permissiontoadd) {
141 // Toggle the status of a contact
142 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
143} elseif ($action == 'deletecontact' && $permissiontoadd) { // Permission to add on object because this is an update of a link of object, not a deletion of data
144 // Deletes a contact
145 $result = $object->delete_contact($lineid);
146
147 if ($result >= 0) {
148 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
149 exit;
150 } else {
151 dol_print_error($db);
152 }
153}
154
155
156/*
157 * View
158 */
159
160$title = $langs->trans("MyObject")." - ".$langs->trans('ContactsAddresses');
161//$title = $object->ref." - ".$langs->trans('ContactsAddresses');
162$help_url = '';
163//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
164llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-mymodule page-card_contact');
165
166$form = new Form($db);
167$formcompany = new FormCompany($db);
168$contactstatic = new Contact($db);
169$userstatic = new User($db);
170
171
172/* *************************************************************************** */
173/* */
174/* View and edit mode */
175/* */
176/* *************************************************************************** */
177
178if ($object->id) {
179 /*
180 * Show tabs
181 */
182 $head = myobjectPrepareHead($object);
183
184 print dol_get_fiche_head($head, 'contact', $langs->trans("MyObject"), -1, $object->picto);
185
186 $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
187
188 $morehtmlref = '<div class="refidno">';
189 /*
190 // Ref customer
191 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
192 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
193 // Thirdparty
194 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
195 // Project
196 if (isModEnabled('project')) {
197 $langs->load("projects");
198 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
199 if ($permissiontoadd)
200 {
201 if ($action != 'classify')
202 //$morehtmlref.='<a class="editfielda" href="' . dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true) . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
203 $morehtmlref.=' : ';
204 if ($action == 'classify') {
205 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
206 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
207 $morehtmlref.='<input type="hidden" name="action" value="classin">';
208 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
209 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
210 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
211 $morehtmlref.='</form>';
212 } else {
213 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
214 }
215 } else {
216 if (!empty($object->fk_project)) {
217 $proj = new Project($db);
218 $proj->fetch($object->fk_project);
219 $morehtmlref .= ': '.$proj->getNomUrl();
220 } else {
221 $morehtmlref .= '';
222 }
223 }
224 }*/
225 $morehtmlref .= '</div>';
226
227 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
228
229 print dol_get_fiche_end();
230
231 print '<br>';
232
233 // Contacts lines (modules that overwrite templates must declare this into descriptor)
234 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
235 foreach ($dirtpls as $reldir) {
236 $file = dol_buildpath($reldir.'/contacts.tpl.php');
237 if (file_exists($file)) {
238 $res = @include $file;
239 if ($res) {
240 break;
241 }
242 }
243 }
244}
245
246// End of page
247llxFooter();
248$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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 MyObject.
Class to manage Dolibarr users.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
isModEnabled($module)
Is Dolibarr module enabled.
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.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
myobjectPrepareHead($object)
Prepare array of tabs for MyObject.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.