dolibarr 25.0.0-alpha
knowledgerecord_card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017-2021 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
40require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/class/knowledgerecord.class.php';
41require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/lib/knowledgemanagement_knowledgerecord.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
43
44// Load translation files required by the page
45$langs->loadLangs(array("knowledgemanagement", "ticket", "other"));
46
47// Get parameters
48$id = GETPOSTINT('id');
49$ref = GETPOST('ref', 'alpha');
50$action = GETPOST('action', 'aZ09');
51$confirm = GETPOST('confirm', 'alpha');
52$cancel = GETPOST('cancel');
53$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'knowledgerecordcard'; // To manage different context of search
54$backtopage = GETPOST('backtopage', 'alpha');
55$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
56$lineid = GETPOSTINT('lineid');
57
58// Initialize a technical objects
59$object = new KnowledgeRecord($db);
60$extrafields = new ExtraFields($db);
61$diroutputmassaction = $conf->knowledgemanagement->dir_output.'/temp/massgeneration/'.$user->id;
62$hookmanager->initHooks(array('knowledgerecordcard', 'globalcard')); // Note that conf->hooks_modules contains array
63
64// Fetch optionals attributes and labels
65$extrafields->fetch_name_optionals_label($object->table_element);
66
67$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
68
69// Initialize array of search criteria
70$search_all = GETPOST("search_all", 'alpha');
71$search = array();
72foreach ($object->fields as $key => $val) {
73 if (GETPOST('search_'.$key, 'alpha')) {
74 $search[$key] = GETPOST('search_'.$key, 'alpha');
75 }
76}
77
78if (empty($action) && empty($id) && empty($ref)) {
79 $action = 'view';
80}
81
82// Load object
83include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
84
85
86$permissiontoread = $user->hasRight('knowledgemanagement', 'knowledgerecord', 'read');
87$permissiontoadd = $user->hasRight('knowledgemanagement', 'knowledgerecord', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
88$permissiontodelete = $user->hasRight('knowledgemanagement', 'knowledgerecord', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
89$permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $permissiontoadd) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('knowledgemanagement', 'knowledgerecord_advance', 'validate')));
90$permissionnote = $user->hasRight('knowledgemanagement', 'knowledgerecord', 'write'); // Used by the include of actions_setnotes.inc.php
91$permissiondellink = $user->hasRight('knowledgemanagement', 'knowledgerecord', 'write'); // Used by the include of actions_dellink.inc.php
92$upload_dir = $conf->knowledgemanagement->multidir_output[isset($object->entity) ? $object->entity : 1];
93
94// Security check - Protection if external user
95//if ($user->socid > 0) accessforbidden();
96//if ($user->socid > 0) $socid = $user->socid;
97$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
98restrictedArea($user, $object->module, $object->id, $object->table_element.'&'.$object->element, $object->element, '', 'rowid', $isdraft);
99//if (empty($conf->knowledgemanagement->enabled)) accessforbidden();
100//if (empty($permissiontoread)) accessforbidden();
101
102
103/*
104 * Actions
105 */
106
107$parameters = array();
108$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
109if ($reshook < 0) {
110 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
111}
112
113if (empty($reshook)) {
114 $error = 0;
115
116 $backurlforlist = DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_list.php';
117
118 if (empty($backtopage) || ($cancel && empty($id))) {
119 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
120 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
121 $backtopage = $backurlforlist;
122 } else {
123 $backtopage = DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_card.php?id='.($id > 0 ? $id : '__ID__');
124 }
125 }
126 }
127
128 $triggermodname = 'KNOWLEDGERECORD_MODIFY'; // Name of trigger action code to execute when we modify record
129
130 // Update / add for lang
131 if (($action == 'update' || $action == 'add') && !empty($permissiontoadd)) {
132 $object->lang = (GETPOSTISSET('langkm') ? GETPOST('langkm', 'aZ09') : $object->lang);
133 }
134
135 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
136 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
137
138 // Actions when linking object each other
139 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
140
141 // Actions when printing a doc from card
142 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
143
144 // Action to move up and down lines of object
145 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
146
147 // Action to build doc
148 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
149
150 if ($action == 'set_thirdparty' && $permissiontoadd) {
151 $object->setValueFrom('fk_soc', GETPOSTINT('fk_soc'), '', null, 'date', '', $user, $triggermodname);
152 }
153 if ($action == 'classin' && $permissiontoadd) {
154 $object->setProject(GETPOSTINT('projectid'));
155 }
156
157 // Actions to send emails
158 $triggersendname = 'KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_SENTBYMAIL';
159 $autocopy = 'MAIN_MAIL_AUTOCOPY_KNOWLEDGERECORD_TO';
160 $trackid = 'knowledgerecord'.$object->id;
161 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
162}
163if ($action == 'confirm_validate') { // Test on permission already done into actions_addupdatedelete.inc.php
164 $action = 'edit';
165}
166
167
168/*
169 * View
170 */
171
172$form = new Form($db);
173$formfile = new FormFile($db);
174$formproject = new FormProjets($db);
175$formadmin = new FormAdmin($db);
176
177$title = $langs->trans("KnowledgeRecord");
178$help_url = '';
179llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-knowledgemanagement page-card');
180
181// Part to create
182if ($action == 'create') {
183 print load_fiche_titre($langs->trans("NewKnowledgeRecord"), '', 'object_'.$object->picto);
184
185 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
186 print '<input type="hidden" name="token" value="'.newToken().'">';
187 print '<input type="hidden" name="action" value="add">';
188 if (!empty($backtopage)) {
189 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
190 }
191 if (!empty($backtopageforcancel)) {
192 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
193 }
194
195 print dol_get_fiche_head(array(), '', '', -3);
196
197 print '<table class="border centpercent tableforfieldcreate">'."\n";
198
199 // Common attributes
200 $object->fields['answer']['enabled'] = 0;
201 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
202 $object->fields['answer']['enabled'] = 1;
203
204 if (isModEnabled('category')) {
205 $cate_arbo = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', 'parent', 64, 0, 3);
206 // $output_mode is 3, so fix return type:
207 '@phan-var-force array<int,array{rowid:int,id:int,fk_parent:int,label:string,description:string,color:string,position:string,visible:int,ref_ext:string,picto:string,fullpath:string,fulllabel:string}> $cate_arbo';
208
209 if (count($cate_arbo)) {
210 // Categories
211 print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
212 print $form->selectCategories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, 'categories', $object);
213 print "</td></tr>";
214 }
215 }
216
217 // Other attributes
218 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
219
220
221 // Add field answer
222 print '<td>';
223 print $langs->trans($object->fields['answer']['label']);
224 print '</td><td>';
225
226 // Add layout and AI tools for answer
227 $out = '';
228 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
229 $formmail = new FormMail($db);
230 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formai.class.php';
231 $formai = new FormAI($db);
232
233 $formmail->withfckeditor = 1;
234 //$formmail->withlayout = 'email';
235 $formmail->withaiprompt = (isModEnabled('ai') ? 'html' : '');
236
237 $showlinktolayout = (getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT') ? $formmail->withlayout : '');
238 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
239 $showlinktoai = ($formmail->withaiprompt ? 'textgenerationemail' : '');
240 $showlinktoailabel = $langs->trans("FillMessageWithAIContent");
241 $htmlname = 'answer';
242
243 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
244 print $out;
245 print '</td>';
246
247 print '</table>'."\n";
248
249 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
250 $doleditor = new DolEditor('answer', $object->answer, '', 200, 'dolibarr_notes', 'In', true, true, true, ROWS_9, '100%');
251 $out = $doleditor->Create(1);
252 print $out;
253
254 // Prefill AI instructions with question text on create form
255 if (isModEnabled('ai')) {
256 $aipromptprefix = $langs->transnoentities('SuggestAnswerToQuestion');
257
258 print '<script nonce="'.getNonce().'" type="text/javascript">
259 $(document).ready(function() {
260 $("#linkforaiprompttextgenerationemail").on("click", function() {
261 setTimeout(function() {
262 var instructionField = $("#ai_instructionsanswer");
263 if (!instructionField.is(":visible")) {
264 return;
265 }
266 var prefix = \''.dol_escape_js($aipromptprefix).'\';
267 var currentVal = instructionField.val();
268 var question = "";
269 if (typeof CKEDITOR !== "undefined" && CKEDITOR.instances && CKEDITOR.instances["question"]) {
270 question = $("<div>").html(CKEDITOR.instances["question"].getData()).text().trim();
271 } else {
272 question = $("#question").val() ? $.trim($("#question").val()) : "";
273 }
274 if (currentVal === "" || currentVal === prefix || currentVal.indexOf(prefix) === 0) {
275 if (question) {
276 instructionField.val(prefix + " " + question);
277 } else {
278 instructionField.val(prefix);
279 }
280 $("#generate_buttonanswer").prop("disabled", (instructionField.val() === ""));
281 }
282 }, 50);
283 });
284 });
285 </script>';
286 }
287
288 print dol_get_fiche_end();
289
290 print $form->buttonsSaveCancel('Create');
291
292 print '</form>';
293
294 //dol_set_focus('input[name="ref"]');
295}
296
297// Part to edit record
298if (($id || $ref) && $action == 'edit') {
299 print load_fiche_titre($langs->trans("KnowledgeRecord"), '', 'object_'.$object->picto);
300
301 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
302 print '<input type="hidden" name="token" value="'.newToken().'">';
303 print '<input type="hidden" name="action" value="update">';
304 print '<input type="hidden" name="id" value="'.$object->id.'">';
305 if (!empty($backtopage)) {
306 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
307 }
308 if (!empty($backtopageforcancel)) {
309 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
310 }
311
312 print dol_get_fiche_head(array(), '', '', -3);
313
314 print '<table class="border centpercent tableforfieldedit">'."\n";
315
316 // Common attributes
317 $object->fields['answer']['enabled'] = 0;
318 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
319 $object->fields['answer']['enabled'] = 1;
320
321 if (isModEnabled('category')) {
322 $cate_arbo = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', 'parent', 64, 0, 3);
323 // $output_mode is 3, so fix return type:
324 '@phan-var-force array<int,array{rowid:int,id:int,fk_parent:int,label:string,description:string,color:string,position:string,visible:int,ref_ext:string,picto:string,fullpath:string,fulllabel:string}> $cate_arbo';
325
326 if (count($cate_arbo)) {
327 // Categories
328 print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
329 print $form->selectCategories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, 'categories', $object);
330 print "</td></tr>";
331 }
332 }
333
334 // Other attributes
335 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
336
337 print '</table>';
338
339 // Add field answer
340 print '<br>';
341 print $langs->trans($object->fields['answer']['label']).'<br>';
342
343 // Add layout and AI tools for answer
344 $out = '';
345 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
346 $formmail = new FormMail($db);
347 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formai.class.php';
348 $formai = new FormAI($db);
349
350 $formmail->withfckeditor = 1;
351 $formmail->withlayout = 'email';
352 $formmail->withaiprompt = (isModEnabled('ai') ? 'html' : '');
353
354 $showlinktolayout = (getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT') ? $formmail->withlayout : '');
355 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
356 $showlinktoai = ($formmail->withaiprompt ? 'textgenerationemail' : '');
357 $showlinktoailabel = $langs->trans("FillMessageWithAIContent");
358 $htmlname = 'answer';
359
360 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
361 print $out;
362 print '<br>';
363
364 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
365 $doleditor = new DolEditor('answer', $object->answer, '', 200, 'dolibarr_notes', 'In', true, true, true, ROWS_9, '100%');
366 $out = $doleditor->Create(1);
367 print $out;
368
369 print dol_get_fiche_end();
370
371 print $form->buttonsSaveCancel();
372
373 print '</form>';
374}
375
376// Part to show record
377if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
378 $res = $object->fetch_optionals();
379
380 $head = knowledgerecordPrepareHead($object);
381 print dol_get_fiche_head($head, 'card', $langs->trans("KnowledgeRecord"), -1, $object->picto, 0, '', '', 0, '', 1);
382
383 $formconfirm = '';
384
385 // Confirmation to delete
386 if ($action == 'delete') {
387 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteKnowledgeRecord'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
388 }
389 // Confirmation to delete line
390 if ($action == 'deleteline') {
391 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
392 }
393 // Clone confirmation
394 if ($action == 'clone') {
395 // Create an array for form
396 $formquestion = array();
397 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
398 }
399
400 // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
401 if ($action == 'close') {
402 $text = $langs->trans('ConfirmCloseKM', $object->ref);
403 /*if (isModEnabled('notification'))
404 {
405 require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
406 $notify = new Notify($db);
407 $text .= '<br>';
408 $text .= $notify->confirmMessage('MYOBJECT_CLOSE', $object->socid, $object);
409 }*/
410
411 $formquestion = array();
412 /*
413 $forcecombo=0;
414 if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
415 $formquestion = array(
416 // 'text' => $langs->trans("ConfirmClone"),
417 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
418 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
419 // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
420 );
421 */
422 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetObsolete'), $text, 'confirm_close', $formquestion, 0, 1, 220);
423 }
424
425 // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
426 if ($action == 'reopen') {
427 $text = $langs->trans('ConfirmReopenKM', $object->ref);
428 /*if (isModEnabled('notification'))
429 {
430 require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
431 $notify = new Notify($db);
432 $text .= '<br>';
433 $text .= $notify->confirmMessage('MYOBJECT_CLOSE', $object->socid, $object);
434 }*/
435
436 $formquestion = array();
437 /*
438 $forcecombo=0;
439 if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
440 $formquestion = array(
441 // 'text' => $langs->trans("ConfirmClone"),
442 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
443 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
444 // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
445 );
446 */
447 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Re-Open'), $text, 'confirm_reopen', $formquestion, 0, 1, 220);
448 }
449
450 // Call Hook formConfirm
451 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
452 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
453 if (empty($reshook)) {
454 $formconfirm .= $hookmanager->resPrint;
455 } elseif ($reshook > 0) {
456 $formconfirm = $hookmanager->resPrint;
457 }
458
459 // Print form confirm
460 print $formconfirm;
461
462
463 // Object card
464 // ------------------------------------------------------------
465 $linkback = '<a href="'.DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
466
467 $morehtmlref = '<div class="refidno">';
468 /*
469 // Ref customer
470 $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
471 $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
472 // Thirdparty
473 $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
474 // Project
475 if (isModEnabled('project')) {
476 $langs->load("projects");
477 $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
478 if ($permissiontoadd) {
479 //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true) . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
480 $morehtmlref .= ' : ';
481 if ($action == 'classify') {
482 //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 0, 1, '', 'maxwidth300');
483 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
484 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
485 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
486 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
487 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
488 $morehtmlref .= '</form>';
489 } else {
490 $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
491 }
492 } else {
493 if (!empty($object->fk_project)) {
494 $proj = new Project($db);
495 $proj->fetch($object->fk_project);
496 $morehtmlref .= ': '.$proj->getNomUrl();
497 } else {
498 $morehtmlref .= '';
499 }
500 }
501 }*/
502 $morehtmlref .= '</div>';
503
504
505 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
506
507
508 print '<div class="fichecenter">';
509 print '<div class="fichehalfleft">';
510 print '<div class="underbanner clearboth"></div>';
511 print '<table class="border centpercent tableforfield">'."\n";
512
513 // Common attributes
514 $keyforbreak = 'fk_c_ticket_category'; // We change column just before this field
515 //unset($object->fields['fk_project']); // Hide field already shown in banner
516 //unset($object->fields['fk_soc']); // Hide field already shown in banner
517 $object->fields['answer']['enabled'] = 0;
518 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
519 $object->fields['answer']['enabled'] = 1;
520
521 // Categories
522 if (isModEnabled('category')) {
523 print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
524 print $form->showCategories($object->id, Categorie::TYPE_KNOWLEDGEMANAGEMENT, 1);
525 print "</td></tr>";
526 }
527
528 // Other attributes. Fields from hook formObjectOptions and Extrafields.
529 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
530
531 print '</table>';
532
533 print '</div>';
534 print '</div>';
535
536 print '<div class="clearboth"></div>';
537
538 // Add field answer
539 print '<br>';
540 print load_fiche_titre($langs->trans($object->fields['answer']['label']), '', '');
541 if ($action == 'edit') {
542 // Add layout and AI tools for answer
543 $out = '';
544 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
545 $formmail = new FormMail($db);
546 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formai.class.php';
547 $formai = new FormAI($db);
548
549 $formmail->withfckeditor = 1;
550 $formmail->withlayout = 'email';
551 $formmail->withaiprompt = (isModEnabled('ai') ? 'html' : '');
552
553 $showlinktolayout = (getDolGlobalInt('MAIN_EMAIL_USE_LAYOUT') ? $formmail->withlayout : '');
554 $showlinktolayoutlabel = $langs->trans("FillMessageWithALayout");
555 $showlinktoai = ($formmail->withaiprompt ? 'textgenerationemail' : '');
556 $showlinktoailabel = $langs->trans("FillMessageWithAIContent");
557 $htmlname = 'answer';
558
559 include DOL_DOCUMENT_ROOT.'/core/tpl/formlayoutai.tpl.php';
560 print $out;
561 print '<br>';
562
563 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
564 $doleditor = new DolEditor('answer', $object->answer, '', 200, 'dolibarr_notes', 'In', true, true, true, ROWS_9, '100%', 1);
565 $out = $doleditor->Create(1);
566 } else {
567 $out = '<div class="content kmcontent">';
568 $out .= $object->answer;
569 $out .= '</div>';
570 }
571 print $out;
572 print dol_get_fiche_end();
573
574
575 // Buttons for actions
576
577 if ($action != 'presend' && $action != 'editline') {
578 print '<div class="tabsAction">'."\n";
579 $parameters = array();
580 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
581 if ($reshook < 0) {
582 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
583 }
584
585 if (empty($reshook)) {
586 // Send
587 //if (empty($user->socid)) {
588 //print dolGetButtonAction('', $langs->trans('SendMail'), 'email', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle');
589 //}
590
591 // Back to draft
592 if ($object->status == $object::STATUS_VALIDATED) {
593 print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken(), '', $permissiontoadd);
594 }
595 if (($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) && $permissiontovalidate) {
596 print dolGetButtonAction('', $langs->trans('Modify'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
597 }
598 // Validate
599 if ($object->status == $object::STATUS_DRAFT) {
600 if ((empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) && $permissiontovalidate) {
601 print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&token='.newToken().'&confirm=yes', '', $permissiontoadd);
602 } else {
603 $langs->load("errors");
604 //print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes', '', 0);
605 print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
606 }
607 }
608
609 // Clone
610 print dolGetButtonAction($langs->trans('ToClone'), $langs->trans('ToClone'), 'clone', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken().'&object=scrumsprint', '', $permissiontoadd, array('attr' => array('class' => 'reposition')));
611
612 /*
613 if ($permissiontoadd) {
614 if ($object->status == $object::STATUS_ENABLED) {
615 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a>'."\n";
616 } else {
617 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a>'."\n";
618 }
619 }
620 */
621 if ($permissiontoadd) {
622 if ($object->status == $object::STATUS_VALIDATED) {
623 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken().'">'.$langs->trans("SetObsolete").'</a>'."\n";
624 } elseif ($object->status == $object::STATUS_CANCELED) {
625 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'."\n";
626 }
627 }
628
629 // Delete (need delete permission, or if draft, just need create/modify permission)
630 print dolGetButtonAction($langs->trans('Delete'), $langs->trans('Delete'), 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd), array('attr' => array('class' => 'reposition')))."\n";
631 }
632 print '</div>'."\n";
633 }
634
635
636 // Select mail models is same action as presend
637 if (GETPOST('modelselected')) {
638 $action = 'presend';
639 }
640
641 if ($action != 'presend') {
642 print '<div class="fichecenter"><div class="fichehalfleft">';
643 print '<a name="builddoc"></a>'; // ancre
644
645 $includedocgeneration = 0;
646
647 // Documents
648 if ($includedocgeneration) {
649 $objref = dol_sanitizeFileName($object->ref);
650 $relativepath = $objref.'/'.$objref.'.pdf';
651 $filedir = $conf->knowledgemanagement->dir_output.'/'.$object->element.'/'.$objref;
652 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
653 $genallowed = $user->hasRight('knowledgemanagement', 'knowledgerecord', 'read'); // If you can read, you can build the PDF to read content
654 $delallowed = $user->hasRight('knowledgemanagement', 'knowledgerecord', 'write'); // If you can create/edit, you can remove a file on card
655 print $formfile->showdocuments('knowledgemanagement:KnowledgeRecord', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
656 }
657
658 // Show links to link elements
659 $tmparray = $form->showLinkToObjectBlock($object, array(), array('knowledgerecord'), 1);
660 $linktoelem = $tmparray['linktoelem'];
661 $htmltoenteralink = $tmparray['htmltoenteralink'];
662 print $htmltoenteralink;
663
664 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
665
666
667 print '</div><div class="fichehalfright">';
668
669 $MAXEVENT = 10;
670
671 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_agenda.php?id='.$object->id);
672
673 // List of actions on element
674 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
675 $formactions = new FormActions($db);
676 $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
677
678 print '</div></div>';
679 }
680
681 //Select mail models is same action as presend
682 if (GETPOST('modelselected')) {
683 $action = 'presend';
684 }
685
686 // Presend form
687 $modelmail = 'knowledgerecord';
688 $defaulttopic = 'InformationMessage';
689 $diroutput = $conf->knowledgemanagement->dir_output;
690 $trackid = 'knowledgerecord'.$object->id;
691
692 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
693}
694
695// End of page
696llxFooter();
697$db->close();
write(string $newInnerBlock)
Replace the whole permissions block, markers included, in a single write.
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:280
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:73
print $object position
Definition edit.php:206
$object ref
Definition info.php:90
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
Class to generate HTML forms for single email Usage: $formai = new FormAI($db) $formai->proprietes=1 ...
Class to generate html code for admin pages.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to manage building of HTML components.
Class for KnowledgeRecord.
Class to manage projects.
Class toolbox to validate values.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
treeview li table
No Email.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.