dolibarr  13.0.2
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"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
29 // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
30 $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
31 while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
32 if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
33 if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
34 // Try main.inc.php using relative path
35 if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
36 if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
37 if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
38 if (!$res) die("Include of main fails");
39 
40 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
42 dol_include_once('/mymodule/class/myobject.class.php');
43 dol_include_once('/mymodule/lib/mymodule_myobject.lib.php');
44 
45 // Load translation files required by the page
46 $langs->loadLangs(array("mymodule@mymodule", "companies", "other", "mails"));
47 
48 $id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
49 $ref = GETPOST('ref', 'alpha');
50 $lineid = GETPOST('lineid', 'int');
51 $socid = GETPOST('socid', 'int');
52 $action = GETPOST('action', 'aZ09');
53 
54 // Initialize technical objects
55 $object = new MyObject($db);
56 $extrafields = new ExtraFields($db);
57 $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
58 $hookmanager->initHooks(array('myobjectcontact', 'globalcard')); // Note that conf->hooks_modules contains array
59 // Fetch optionals attributes and labels
60 $extrafields->fetch_name_optionals_label($object->table_element);
61 
62 // Load object
63 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
64 
65 // Security check - Protection if external user
66 //if ($user->socid > 0) accessforbidden();
67 //if ($user->socid > 0) $socid = $user->socid;
68 //$result = restrictedArea($user, 'mymodule', $object->id);
69 
70 $permission = $user->rights->mymodule->myobject->write;
71 
72 /*
73  * Add a new contact
74  */
75 
76 if ($action == 'addcontact' && $permission)
77 {
78  $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
79  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
80  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
81 
82  if ($result >= 0)
83  {
84  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
85  exit;
86  } else {
87  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
88  {
89  $langs->load("errors");
90  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
91  } else {
92  setEventMessages($object->error, $object->errors, 'errors');
93  }
94  }
95 } // Toggle the status of a contact
96 elseif ($action == 'swapstatut' && $permission)
97 {
98  $result = $object->swapContactStatus(GETPOST('ligne'));
99 } // Deletes a contact
100 elseif ($action == 'deletecontact' && $permission)
101 {
102  $result = $object->delete_contact($lineid);
103 
104  if ($result >= 0)
105  {
106  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
107  exit;
108  } else {
109  dol_print_error($db);
110  }
111 }
112 
113 
114 /*
115  * View
116  */
117 
118 $title = $langs->trans('MyObject')." - ".$langs->trans('ContactsAddresses');
119 $help_url = '';
120 //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
121 llxHeader('', $title, $help_url);
122 
123 $form = new Form($db);
124 $formcompany = new FormCompany($db);
125 $contactstatic = new Contact($db);
126 $userstatic = new User($db);
127 
128 
129 /* *************************************************************************** */
130 /* */
131 /* View and edit mode */
132 /* */
133 /* *************************************************************************** */
134 
135 if ($object->id)
136 {
137  /*
138  * Show tabs
139  */
140  $head = myobjectPrepareHead($object);
141 
142  print dol_get_fiche_head($head, 'contact', $langs->trans("MyObject"), -1, $object->picto);
143 
144  $linkback = '<a href="'.dol_buildpath('/mymodule/myobject_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
145 
146  $morehtmlref = '<div class="refidno">';
147  /*
148  // Ref customer
149  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
150  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
151  // Thirdparty
152  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
153  // Project
154  if (! empty($conf->projet->enabled))
155  {
156  $langs->load("projects");
157  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
158  if ($permissiontoadd)
159  {
160  if ($action != 'classify')
161  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
162  $morehtmlref.=' : ';
163  if ($action == 'classify') {
164  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
165  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
166  $morehtmlref.='<input type="hidden" name="action" value="classin">';
167  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
168  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
169  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
170  $morehtmlref.='</form>';
171  } else {
172  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
173  }
174  } else {
175  if (! empty($object->fk_project)) {
176  $proj = new Project($db);
177  $proj->fetch($object->fk_project);
178  $morehtmlref .= ': '.$proj->getNomUrl();
179  } else {
180  $morehtmlref .= '';
181  }
182  }
183  }*/
184  $morehtmlref .= '</div>';
185 
186  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
187 
189 
190  print '<br>';
191 
192  // Contacts lines (modules that overwrite templates must declare this into descriptor)
193  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
194  foreach ($dirtpls as $reldir)
195  {
196  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
197  if ($res) break;
198  }
199 }
200 
201 // End of page
202 llxFooter();
203 $db->close();
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.
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class for MyObject.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
myobjectPrepareHead($object)
Prepare array of tabs for MyObject.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
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.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59