dolibarr 21.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 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 $_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}
60
61require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
62require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
63dol_include_once('/mymodule/class/myobject.class.php');
64dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
65
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//if ($user->socid > 0) accessforbidden();
107//if ($user->socid > 0) $socid = $user->socid;
108//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
109//restrictedArea($user, $object->module, $object->id, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft);
110if (!isModEnabled("mymodule")) {
112}
113if (!$permissiontoread) {
115}
116
117
118/*
119 * Add a new contact
120 */
121
122if ($action == 'addcontact' && $permissiontoadd) {
123 $contactid = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
124 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
125 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
126
127 if ($result >= 0) {
128 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
129 exit;
130 } else {
131 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
132 $langs->load("errors");
133 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
134 } else {
135 setEventMessages($object->error, $object->errors, 'errors');
136 }
137 }
138} elseif ($action == 'swapstatut' && $permissiontoadd) {
139 // Toggle the status of a contact
140 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
141} elseif ($action == 'deletecontact' && $permissiontoadd) { // Permission to add on object because this is an update of a link of object, not a deletion of data
142 // Deletes a contact
143 $result = $object->delete_contact($lineid);
144
145 if ($result >= 0) {
146 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
147 exit;
148 } else {
149 dol_print_error($db);
150 }
151}
152
153
154/*
155 * View
156 */
157
158$title = $langs->trans("MyObject")." - ".$langs->trans('ContactsAddresses');
159//$title = $object->ref." - ".$langs->trans('ContactsAddresses');
160$help_url = '';
161//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
162llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-mymodule page-card_contact');
163
164$form = new Form($db);
165$formcompany = new FormCompany($db);
166$contactstatic = new Contact($db);
167$userstatic = new User($db);
168
169
170/* *************************************************************************** */
171/* */
172/* View and edit mode */
173/* */
174/* *************************************************************************** */
175
176if ($object->id) {
177 /*
178 * Show tabs
179 */
180 $head = myobjectPrepareHead($object);
181
182 print dol_get_fiche_head($head, 'contact', $langs->trans("MyObject"), -1, $object->picto);
183
184 $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
185
186 $morehtmlref = '<div class="refidno">';
187 /*
188 // Ref customer
189 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
190 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
191 // Thirdparty
192 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
193 // Project
194 if (isModEnabled('project')) {
195 $langs->load("projects");
196 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
197 if ($permissiontoadd)
198 {
199 if ($action != 'classify')
200 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
201 $morehtmlref.=' : ';
202 if ($action == 'classify') {
203 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
204 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
205 $morehtmlref.='<input type="hidden" name="action" value="classin">';
206 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
207 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
208 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
209 $morehtmlref.='</form>';
210 } else {
211 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
212 }
213 } else {
214 if (!empty($object->fk_project)) {
215 $proj = new Project($db);
216 $proj->fetch($object->fk_project);
217 $morehtmlref .= ': '.$proj->getNomUrl();
218 } else {
219 $morehtmlref .= '';
220 }
221 }
222 }*/
223 $morehtmlref .= '</div>';
224
225 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
226
227 print dol_get_fiche_end();
228
229 print '<br>';
230
231 // Contacts lines (modules that overwrite templates must declare this into descriptor)
232 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
233 foreach ($dirtpls as $reldir) {
234 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
235 if ($res) {
236 break;
237 }
238 }
239}
240
241// End of page
242llxFooter();
243$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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.
llxFooter()
Footer empty.
Definition document.php:107
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)
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.