dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28
29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/class/knowledgerecord.class.php';
32require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/lib/knowledgemanagement_knowledgerecord.lib.php';
33
42// Load translation files required by the page
43$langs->loadLangs(array("knowledgemanagement", "companies", "other", "mails"));
44
45$id = (GETPOST('id') ? GETPOSTINT('id') : GETPOSTINT('facid')); // For backward compatibility
46$ref = GETPOST('ref', 'alpha');
47$lineid = GETPOSTINT('lineid');
48$socid = GETPOSTINT('socid');
49$action = GETPOST('action', 'aZ09');
50
51// Initialize a technical objects
52$object = new KnowledgeRecord($db);
53$extrafields = new ExtraFields($db);
54$diroutputmassaction = $conf->knowledgemanagement->dir_output.'/temp/massgeneration/'.$user->id;
55$hookmanager->initHooks(array('knowledgerecordcontact', 'globalcard')); // Note that conf->hooks_modules contains array
56// Fetch optionals attributes and labels
57$extrafields->fetch_name_optionals_label($object->table_element);
58
59// Load object
60include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'. Include fetch and fetch_thirdparty but not fetch_optionals
61
62// Security check - Protection if external user
63//if ($user->socid > 0) accessforbidden();
64//if ($user->socid > 0) $socid = $user->socid;
65$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
66restrictedArea($user, $object->module, $object->id, $object->table_element, $object->element, '', 'rowid', $isdraft);
67
68$permission = $user->hasRight('knowledgemanagement', 'knowledgerecord', 'write');
69
70
71/*
72 * Actions
73 */
74
75if ($action == 'addcontact' && $permission) {
76 $contactid = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
77 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
78 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
79
80 if ($result >= 0) {
81 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
82 exit;
83 } else {
84 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
85 $langs->load("errors");
86 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
87 } else {
88 setEventMessages($object->error, $object->errors, 'errors');
89 }
90 }
91} elseif ($action == 'swapstatut' && $permission) {
92 // Toggle the status of a contact
93 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
94} elseif ($action == 'deletecontact' && $permission) {
95 // Deletes a contact
96 $result = $object->delete_contact($lineid);
97
98 if ($result >= 0) {
99 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
100 exit;
101 } else {
102 dol_print_error($db);
103 }
104}
105
106
107/*
108 * View
109 */
110
111$title = $langs->trans('KnowledgeRecord')." - ".$langs->trans('ContactsAddresses');
112$help_url = '';
113//$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
114llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-knowledgemanagement page-contact');
115
116$form = new Form($db);
117$formcompany = new FormCompany($db);
118$contactstatic = new Contact($db);
119$userstatic = new User($db);
120
121
122// View and edit mode
123
124if ($object->id) {
125 // Show tabs
126 $head = knowledgerecordPrepareHead($object);
127
128 print dol_get_fiche_head($head, 'contact', $langs->trans("KnowledgeRecord"), -1, $object->picto);
129
130 $linkback = '<a href="'.dol_buildpath('/knowledgemanagement/knowledgerecord_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
131
132 $morehtmlref = '<div class="refidno">';
133 /*
134 // Ref customer
135 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
136 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
137 // Thirdparty
138 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
139 // Project
140 if (isModEnabled('project'))
141 {
142 $langs->load("projects");
143 $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
144 if ($permissiontoadd)
145 {
146 if ($action != 'classify')
147 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
148 $morehtmlref.=' : ';
149 if ($action == 'classify') {
150 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
151 $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
152 $morehtmlref.='<input type="hidden" name="action" value="classin">';
153 $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
154 $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
155 $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
156 $morehtmlref.='</form>';
157 } else {
158 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
159 }
160 } else {
161 if (!empty($object->fk_project)) {
162 $proj = new Project($db);
163 $proj->fetch($object->fk_project);
164 $morehtmlref .= ': '.$proj->getNomUrl();
165 } else {
166 $morehtmlref .= '';
167 }
168 }
169 }*/
170 $morehtmlref .= '</div>';
171
172 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
173
174 print dol_get_fiche_end();
175
176 print '<br>';
177
178 // Contacts lines (modules that overwrite templates must declare this into descriptor)
179 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
180 foreach ($dirtpls as $reldir) {
181 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
182 if ($res) {
183 break;
184 }
185 }
186}
187
188// End of page
189llxFooter();
190$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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 KnowledgeRecord.
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.
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...
knowledgerecordPrepareHead($object)
Prepare array of tabs for KnowledgeRecord.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.