dolibarr 19.0.3
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) ---Put here your own copyright and developer email---
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26$res = 0;
27// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
28if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
29 $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
30}
31// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
32$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
33while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
34 $i--;
35 $j--;
36}
37if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
38 $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
39}
40if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
41 $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
42}
43// Try main.inc.php using relative path
44if (!$res && file_exists("../main.inc.php")) {
45 $res = @include "../main.inc.php";
46}
47if (!$res && file_exists("../../main.inc.php")) {
48 $res = @include "../../main.inc.php";
49}
50if (!$res && file_exists("../../../main.inc.php")) {
51 $res = @include "../../../main.inc.php";
52}
53if (!$res) {
54 die("Include of main fails");
55}
56
57require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
58require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
59dol_include_once('/mymodule/class/myobject.class.php');
60dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
61
62// Load translation files required by the page
63$langs->loadLangs(array("mymodule@mymodule", "companies", "other", "mails"));
64
65$id = (GETPOST('id') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
66$ref = GETPOST('ref', 'alpha');
67$lineid = GETPOST('lineid', 'int');
68$socid = GETPOST('socid', 'int');
69$action = GETPOST('action', 'aZ09');
70
71// Initialize technical objects
72$object = new MyObject($db);
73$extrafields = new ExtraFields($db);
74$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
75$hookmanager->initHooks(array($object->element.'contact', 'globalcard')); // Note that conf->hooks_modules contains array
76// Fetch optionals attributes and labels
77$extrafields->fetch_name_optionals_label($object->table_element);
78
79// Load object
80include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
81
82// There is several ways to check permission.
83// Set $enablepermissioncheck to 1 to enable a minimum low level of checks
84$enablepermissioncheck = 0;
85if ($enablepermissioncheck) {
86 $permissiontoread = $user->hasRight('mymodule', 'myobject', 'read');
87 $permissiontoadd = $user->hasRight('mymodule', 'myobject', 'write');
88} else {
89 $permissiontoread = 1;
90 $permissiontoadd = 1;
91}
92
93// Security check (enable the most restrictive one)
94//if ($user->socid > 0) accessforbidden();
95//if ($user->socid > 0) $socid = $user->socid;
96//$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
97//restrictedArea($user, $object->module, $object->id, $object->table_element, $object->element, 'fk_soc', 'rowid', $isdraft);
98if (!isModEnabled("mymodule")) {
100}
101if (!$permissiontoread) {
103}
104
105
106/*
107 * Add a new contact
108 */
109
110if ($action == 'addcontact' && $permissiontoadd) {
111 $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
112 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
113 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
114
115 if ($result >= 0) {
116 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
117 exit;
118 } else {
119 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
120 $langs->load("errors");
121 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
122 } else {
123 setEventMessages($object->error, $object->errors, 'errors');
124 }
125 }
126} elseif ($action == 'swapstatut' && $permissiontoadd) {
127 // Toggle the status of a contact
128 $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
129} elseif ($action == 'deletecontact' && $permissiontoadd) { // Permission to add on object because this is an update of a link of object, not a deletion of data
130 // Deletes a contact
131 $result = $object->delete_contact($lineid);
132
133 if ($result >= 0) {
134 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
135 exit;
136 } else {
137 dol_print_error($db);
138 }
139}
140
141
142/*
143 * View
144 */
145
146$title = $langs->trans("MyObject")." - ".$langs->trans('ContactsAddresses');
147//$title = $object->ref." - ".$langs->trans('ContactsAddresses');
148$help_url = '';
149//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
150llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-mymodule page-card_contact');
151
152$form = new Form($db);
153$formcompany = new FormCompany($db);
154$contactstatic = new Contact($db);
155$userstatic = new User($db);
156
157
158/* *************************************************************************** */
159/* */
160/* View and edit mode */
161/* */
162/* *************************************************************************** */
163
164if ($object->id) {
165 /*
166 * Show tabs
167 */
168 $head = myobjectPrepareHead($object);
169
170 print dol_get_fiche_head($head, 'contact', $langs->trans("MyObject"), -1, $object->picto);
171
172 $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
173
174 $morehtmlref = '<div class="refidno">';
175 /*
176 // Ref customer
177 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
178 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
179 // Thirdparty
180 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
181 // Project
182 if (isModEnabled('project')) {
183 $langs->load("projects");
184 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
185 if ($permissiontoadd)
186 {
187 if ($action != 'classify')
188 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
189 $morehtmlref.=' : ';
190 if ($action == 'classify') {
191 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
192 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
193 $morehtmlref.='<input type="hidden" name="action" value="classin">';
194 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
195 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
196 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
197 $morehtmlref.='</form>';
198 } else {
199 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
200 }
201 } else {
202 if (!empty($object->fk_project)) {
203 $proj = new Project($db);
204 $proj->fetch($object->fk_project);
205 $morehtmlref .= ': '.$proj->getNomUrl();
206 } else {
207 $morehtmlref .= '';
208 }
209 }
210 }*/
211 $morehtmlref .= '</div>';
212
213 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
214
215 print dol_get_fiche_end();
216
217 print '<br>';
218
219 // Contacts lines (modules that overwrite templates must declare this into descriptor)
220 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
221 foreach ($dirtpls as $reldir) {
222 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
223 if ($res) {
224 break;
225 }
226 }
227}
228
229// End of page
230llxFooter();
231$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
Contact()
Old copy.
Definition index.php:572