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