dolibarr 24.0.0-beta
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;
36$j = strlen($tmp2) - 1;
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}
68include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
69include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
70dol_include_once('/mymodule/class/myobject.class.php');
71dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
72
73// Load translation files required by the page
74$langs->loadLangs(array("mymodule@mymodule", "companies", "other", "mails"));
75
76$id = (GETPOST('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
77$ref = GETPOST('ref', 'alpha');
78$lineid = GETPOSTINT('lineid');
79$socid = GETPOSTINT('socid');
80$action = GETPOST('action', 'aZ09');
81
82// Initialize a technical objects
83$object = new MyObject($db);
84$extrafields = new ExtraFields($db);
85$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
86$hookmanager->initHooks(array($object->element.'contact', 'globalcard')); // Note that conf->hooks_modules contains array
87// Fetch optionals attributes and labels
88$extrafields->fetch_name_optionals_label($object->table_element);
89
90// Load object
91include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
92
93// There is several ways to check permission.
94// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
95$enablepermissioncheck = getDolGlobalInt('MYMODULE_ENABLE_PERMISSION_CHECK');
96if ($enablepermissioncheck) {
97 $permissiontoread = $user->hasRight('mymodule', 'myobject', 'read');
98 $permissiontoadd = $user->hasRight('mymodule', 'myobject', 'write');
99} else {
100 $permissiontoread = 1;
101 $permissiontoadd = 1;
102}
103
104// Security check (enable the most restrictive one)
105//if ($user->socid > 0) accessforbidden();
106//if ($user->socid > 0) $socid = $user->socid;
107//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
108//restrictedArea($user, $object->module, $object->id, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft);
109if (!isModEnabled("mymodule")) {
111}
112if (!$permissiontoread) {
114}
115
116
117/*
118 * Add a new contact
119 */
120
121if ($action == 'addcontact' && $permissiontoadd) {
122 $contactid = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
123 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
124 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
125
126 if ($result >= 0) {
127 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
128 exit;
129 } else {
130 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
131 $langs->load("errors");
132 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
133 } else {
134 setEventMessages($object->error, $object->errors, 'errors');
135 }
136 }
137} elseif ($action == 'swapstatut' && $permissiontoadd) {
138 // Toggle the status of a contact
139 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
140} elseif ($action == 'deletecontact' && $permissiontoadd) { // Permission to add on object because this is an update of a link of object, not a deletion of data
141 // Deletes a contact
142 $result = $object->delete_contact($lineid);
143
144 if ($result >= 0) {
145 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
146 exit;
147 } else {
149 }
150}
151
152
153/*
154 * View
155 */
156
157$title = $langs->trans("MyObject")." - ".$langs->trans('ContactsAddresses');
158//$title = $object->ref." - ".$langs->trans('ContactsAddresses');
159$help_url = '';
160//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
161llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-mymodule page-card_contact');
162
163$form = new Form($db);
164$formcompany = new FormCompany($db);
165$contactstatic = new Contact($db);
166$userstatic = new User($db);
167
168
169/* *************************************************************************** */
170/* */
171/* View and edit mode */
172/* */
173/* *************************************************************************** */
174
175if ($object->id) {
176 /*
177 * Show tabs
178 */
179 $head = myobjectPrepareHead($object);
180
181 print dol_get_fiche_head($head, 'contact', $langs->trans("MyObject"), -1, $object->picto);
182
183 $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
184
185 $morehtmlref = '<div class="refidno">';
186 /*
187 // Ref customer
188 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
189 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
190 // Thirdparty
191 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
192 // Project
193 if (isModEnabled('project')) {
194 $langs->load("projects");
195 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
196 if ($permissiontoadd)
197 {
198 if ($action != 'classify')
199 //$morehtmlref.='<a class="editfielda" href="' . dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true) . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
200 $morehtmlref.=' : ';
201 if ($action == 'classify') {
202 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
203 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
204 $morehtmlref.='<input type="hidden" name="action" value="classin">';
205 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
206 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
207 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
208 $morehtmlref.='</form>';
209 } else {
210 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
211 }
212 } else {
213 if (!empty($object->fk_project)) {
214 $proj = new Project($db);
215 $proj->fetch($object->fk_project);
216 $morehtmlref .= ': '.$proj->getNomUrl();
217 } else {
218 $morehtmlref .= '';
219 }
220 }
221 }*/
222 $morehtmlref .= '</div>';
223
224 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
225
226 print dol_get_fiche_end();
227
228 print '<br>';
229
230 // Contacts lines (modules that overwrite templates must declare this into descriptor)
231 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
232 foreach ($dirtpls as $reldir) {
233 $file = dol_buildpath($reldir.'/contacts.tpl.php');
234 if (file_exists($file)) {
235 $res = @include $file;
236 if ($res) {
237 break;
238 }
239 }
240 }
241}
242
243// End of page
244llxFooter();
245$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 MyObject.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
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)
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...
isModEnabled($module)
Is Dolibarr module enabled.
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.