dolibarr  16.0.5
knowledgerecord_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 require '../main.inc.php';
27 
28 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/class/knowledgerecord.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/lib/knowledgemanagement_knowledgerecord.lib.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("knowledgemanagement", "companies", "other", "mails"));
35 
36 $id = (GETPOST('id') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
37 $ref = GETPOST('ref', 'alpha');
38 $lineid = GETPOST('lineid', 'int');
39 $socid = GETPOST('socid', 'int');
40 $action = GETPOST('action', 'aZ09');
41 
42 // Initialize technical objects
43 $object = new KnowledgeRecord($db);
44 $extrafields = new ExtraFields($db);
45 $diroutputmassaction = $conf->knowledgemanagement->dir_output.'/temp/massgeneration/'.$user->id;
46 $hookmanager->initHooks(array('knowledgerecordcontact', 'globalcard')); // Note that conf->hooks_modules contains array
47 // Fetch optionals attributes and labels
48 $extrafields->fetch_name_optionals_label($object->table_element);
49 
50 // Load object
51 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
52 
53 // Security check - Protection if external user
54 //if ($user->socid > 0) accessforbidden();
55 //if ($user->socid > 0) $socid = $user->socid;
56 //$result = restrictedArea($user, 'knowledgemanagement', $object->id);
57 
58 $permission = $user->rights->knowledgemanagement->knowledgerecord->write;
59 
60 /*
61  * Add a new contact
62  */
63 
64 if ($action == 'addcontact' && $permission) {
65  $contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
66  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
67  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
68 
69  if ($result >= 0) {
70  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
71  exit;
72  } else {
73  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
74  $langs->load("errors");
75  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
76  } else {
77  setEventMessages($object->error, $object->errors, 'errors');
78  }
79  }
80 } elseif ($action == 'swapstatut' && $permission) {
81  // Toggle the status of a contact
82  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
83 } elseif ($action == 'deletecontact' && $permission) {
84  // Deletes a contact
85  $result = $object->delete_contact($lineid);
86 
87  if ($result >= 0) {
88  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
89  exit;
90  } else {
91  dol_print_error($db);
92  }
93 }
94 
95 
96 /*
97  * View
98  */
99 
100 $title = $langs->trans('KnowledgeRecord')." - ".$langs->trans('ContactsAddresses');
101 $help_url = '';
102 //$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
103 llxHeader('', $title, $help_url);
104 
105 $form = new Form($db);
106 $formcompany = new FormCompany($db);
107 $contactstatic = new Contact($db);
108 $userstatic = new User($db);
109 
110 
111 /* *************************************************************************** */
112 /* */
113 /* View and edit mode */
114 /* */
115 /* *************************************************************************** */
116 
117 if ($object->id) {
118  /*
119  * Show tabs
120  */
121  $head = knowledgerecordPrepareHead($object);
122 
123  print dol_get_fiche_head($head, 'contact', $langs->trans("KnowledgeRecord"), -1, $object->picto);
124 
125  $linkback = '<a href="'.dol_buildpath('/knowledgemanagement/knowledgerecord_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
126 
127  $morehtmlref = '<div class="refidno">';
128  /*
129  // Ref customer
130  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
131  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
132  // Thirdparty
133  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
134  // Project
135  if (! empty($conf->project->enabled))
136  {
137  $langs->load("projects");
138  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
139  if ($permissiontoadd)
140  {
141  if ($action != 'classify')
142  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
143  $morehtmlref.=' : ';
144  if ($action == 'classify') {
145  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
146  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
147  $morehtmlref.='<input type="hidden" name="action" value="classin">';
148  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
149  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
150  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
151  $morehtmlref.='</form>';
152  } else {
153  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
154  }
155  } else {
156  if (! empty($object->fk_project)) {
157  $proj = new Project($db);
158  $proj->fetch($object->fk_project);
159  $morehtmlref .= ': '.$proj->getNomUrl();
160  } else {
161  $morehtmlref .= '';
162  }
163  }
164  }*/
165  $morehtmlref .= '</div>';
166 
167  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
168 
169  print dol_get_fiche_end();
170 
171  print '<br>';
172 
173  // Contacts lines (modules that overwrite templates must declare this into descriptor)
174  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
175  foreach ($dirtpls as $reldir) {
176  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
177  if ($res) {
178  break;
179  }
180  }
181 }
182 
183 // End of page
184 llxFooter();
185 $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
KnowledgeRecord
Class for KnowledgeRecord.
Definition: knowledgerecord.class.php:32
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
knowledgerecordPrepareHead
knowledgerecordPrepareHead($object)
Prepare array of tabs for KnowledgeRecord.
Definition: knowledgemanagement_knowledgerecord.lib.php:30
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
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
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
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