dolibarr  16.0.5
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)
28 if (!$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;
33 while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
34  $i--; $j--;
35 }
36 if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
37  $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
38 }
39 if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
40  $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
41 }
42 // Try main.inc.php using relative path
43 if (!$res && file_exists("../main.inc.php")) {
44  $res = @include "../main.inc.php";
45 }
46 if (!$res && file_exists("../../main.inc.php")) {
47  $res = @include "../../main.inc.php";
48 }
49 if (!$res && file_exists("../../../main.inc.php")) {
50  $res = @include "../../../main.inc.php";
51 }
52 if (!$res) {
53  die("Include of main fails");
54 }
55 
56 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
57 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
58 dol_include_once('/mymodule/class/myobject.class.php');
59 dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
60 
61 // Load translation files required by the page
62 $langs->loadLangs(array("mymodule@mymodule", "companies", "other", "mails"));
63 
64 $id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
65 $ref = GETPOST('ref', 'alpha');
66 $lineid = GETPOST('lineid', 'int');
67 $socid = GETPOST('socid', 'int');
68 $action = GETPOST('action', 'aZ09');
69 
70 // Initialize technical objects
71 $object = new MyObject($db);
72 $extrafields = new ExtraFields($db);
73 $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
74 $hookmanager->initHooks(array('myobjectcontact', 'globalcard')); // Note that conf->hooks_modules contains array
75 // Fetch optionals attributes and labels
76 $extrafields->fetch_name_optionals_label($object->table_element);
77 
78 // Load object
79 include 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
80 
81 // There is several ways to check permission.
82 // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
83 $enablepermissioncheck = 0;
84 if ($enablepermissioncheck) {
85  $permissiontoread = $user->rights->mymodule->myobject->read;
86  $permission = $user->rights->mymodule->myobject->write;
87 } else {
88  $permissiontoread = 1;
89  $permission = 1;
90 }
91 
92 // Security check (enable the most restrictive one)
93 //if ($user->socid > 0) accessforbidden();
94 //if ($user->socid > 0) $socid = $user->socid;
95 //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
96 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
97 if (empty($conf->mymodule->enabled)) accessforbidden();
98 if (!$permissiontoread) accessforbidden();
99 
100 
101 /*
102  * Add a new contact
103  */
104 
105 if ($action == 'addcontact' && $permission) {
106  $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
107  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
108  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
109 
110  if ($result >= 0) {
111  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
112  exit;
113  } else {
114  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
115  $langs->load("errors");
116  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
117  } else {
118  setEventMessages($object->error, $object->errors, 'errors');
119  }
120  }
121 } elseif ($action == 'swapstatut' && $permission) {
122  // Toggle the status of a contact
123  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
124 } elseif ($action == 'deletecontact' && $permission) {
125  // Deletes a contact
126  $result = $object->delete_contact($lineid);
127 
128  if ($result >= 0) {
129  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
130  exit;
131  } else {
132  dol_print_error($db);
133  }
134 }
135 
136 
137 /*
138  * View
139  */
140 
141 $title = $langs->trans('MyObject')." - ".$langs->trans('ContactsAddresses');
142 $help_url = '';
143 //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
144 llxHeader('', $title, $help_url);
145 
146 $form = new Form($db);
147 $formcompany = new FormCompany($db);
148 $contactstatic = new Contact($db);
149 $userstatic = new User($db);
150 
151 
152 /* *************************************************************************** */
153 /* */
154 /* View and edit mode */
155 /* */
156 /* *************************************************************************** */
157 
158 if ($object->id) {
159  /*
160  * Show tabs
161  */
162  $head = myobjectPrepareHead($object);
163 
164  print dol_get_fiche_head($head, 'contact', $langs->trans("MyObject"), -1, $object->picto);
165 
166  $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
167 
168  $morehtmlref = '<div class="refidno">';
169  /*
170  // Ref customer
171  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
172  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
173  // Thirdparty
174  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
175  // Project
176  if (! empty($conf->project->enabled))
177  {
178  $langs->load("projects");
179  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
180  if ($permissiontoadd)
181  {
182  if ($action != 'classify')
183  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
184  $morehtmlref.=' : ';
185  if ($action == 'classify') {
186  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
187  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
188  $morehtmlref.='<input type="hidden" name="action" value="classin">';
189  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
190  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
191  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
192  $morehtmlref.='</form>';
193  } else {
194  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
195  }
196  } else {
197  if (! empty($object->fk_project)) {
198  $proj = new Project($db);
199  $proj->fetch($object->fk_project);
200  $morehtmlref .= ': '.$proj->getNomUrl();
201  } else {
202  $morehtmlref .= '';
203  }
204  }
205  }*/
206  $morehtmlref .= '</div>';
207 
208  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
209 
210  print dol_get_fiche_end();
211 
212  print '<br>';
213 
214  // Contacts lines (modules that overwrite templates must declare this into descriptor)
215  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
216  foreach ($dirtpls as $reldir) {
217  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
218  if ($res) {
219  break;
220  }
221  }
222 }
223 
224 // End of page
225 llxFooter();
226 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
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.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
myobjectPrepareHead
myobjectPrepareHead($object)
Prepare array of tabs for MyObject.
Definition: mymodule_myobject.lib.php:30
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
MyObject
Class for MyObject.
Definition: myobject.class.php:33
User
Class to manage Dolibarr users.
Definition: user.class.php:44
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59