knowledgerecord_card.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <?php
  2. /* Copyright (C) 2017-2021 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file knowledgerecord_card.php
  19. * \ingroup knowledgemanagement
  20. * \brief Page to create/edit/view knowledgerecord
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/class/knowledgerecord.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/lib/knowledgemanagement_knowledgerecord.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("knowledgemanagement", "ticket", "other"));
  33. // Get parameters
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $action = GETPOST('action', 'aZ09');
  37. $confirm = GETPOST('confirm', 'alpha');
  38. $cancel = GETPOST('cancel', 'aZ09');
  39. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'knowledgerecordcard'; // To manage different context of search
  40. $backtopage = GETPOST('backtopage', 'alpha');
  41. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  42. $lineid = GETPOST('lineid', 'int');
  43. // Initialize technical objects
  44. $object = new KnowledgeRecord($db);
  45. $extrafields = new ExtraFields($db);
  46. $diroutputmassaction = $conf->knowledgemanagement->dir_output.'/temp/massgeneration/'.$user->id;
  47. $hookmanager->initHooks(array('knowledgerecordcard', 'globalcard')); // Note that conf->hooks_modules contains array
  48. // Fetch optionals attributes and labels
  49. $extrafields->fetch_name_optionals_label($object->table_element);
  50. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  51. // Initialize array of search criterias
  52. $search_all = GETPOST("search_all", 'alpha');
  53. $search = array();
  54. foreach ($object->fields as $key => $val) {
  55. if (GETPOST('search_'.$key, 'alpha')) {
  56. $search[$key] = GETPOST('search_'.$key, 'alpha');
  57. }
  58. }
  59. if (empty($action) && empty($id) && empty($ref)) {
  60. $action = 'view';
  61. }
  62. // Load object
  63. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  64. $permissiontoread = $user->rights->knowledgemanagement->knowledgerecord->read;
  65. $permissiontovalidate = $user->rights->knowledgemanagement->knowledgerecord->write;
  66. $permissiontoadd = $user->rights->knowledgemanagement->knowledgerecord->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  67. $permissiontodelete = $user->rights->knowledgemanagement->knowledgerecord->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  68. $permissionnote = $user->rights->knowledgemanagement->knowledgerecord->write; // Used by the include of actions_setnotes.inc.php
  69. $permissiondellink = $user->rights->knowledgemanagement->knowledgerecord->write; // Used by the include of actions_dellink.inc.php
  70. $upload_dir = $conf->knowledgemanagement->multidir_output[isset($object->entity) ? $object->entity : 1];
  71. // Security check - Protection if external user
  72. //if ($user->socid > 0) accessforbidden();
  73. //if ($user->socid > 0) $socid = $user->socid;
  74. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  75. //restrictedArea($user, $object->element, $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
  76. //if (empty($conf->knowledgemanagement->enabled)) accessforbidden();
  77. //if (empty($permissiontoread)) accessforbidden();
  78. /*
  79. * Actions
  80. */
  81. $parameters = array();
  82. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  83. if ($reshook < 0) {
  84. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  85. }
  86. if (empty($reshook)) {
  87. $error = 0;
  88. $backurlforlist = DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_list.php';
  89. if (empty($backtopage) || ($cancel && empty($id))) {
  90. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  91. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  92. $backtopage = $backurlforlist;
  93. } else {
  94. $backtopage = DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_card.php?id='.($id > 0 ? $id : '__ID__');
  95. }
  96. }
  97. }
  98. $triggermodname = 'KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_MODIFY'; // Name of trigger action code to execute when we modify record
  99. // Upadate / add for lang
  100. if (($action == 'update' || $action == 'add') && !empty($permissiontoadd)) {
  101. $object->lang = (GETPOSTISSET('langkm') ? GETPOST('langkm', 'aZ09') : $object->lang);
  102. }
  103. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  104. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  105. // Actions when linking object each other
  106. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  107. // Actions when printing a doc from card
  108. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  109. // Action to move up and down lines of object
  110. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  111. // Action to build doc
  112. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  113. if ($action == 'set_thirdparty' && $permissiontoadd) {
  114. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  115. }
  116. if ($action == 'classin' && $permissiontoadd) {
  117. $object->setProject(GETPOST('projectid', 'int'));
  118. }
  119. // Actions to send emails
  120. $triggersendname = 'KNOWLEDGEMANAGEMENT_KNOWLEDGERECORD_SENTBYMAIL';
  121. $autocopy = 'MAIN_MAIL_AUTOCOPY_KNOWLEDGERECORD_TO';
  122. $trackid = 'knowledgerecord'.$object->id;
  123. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  124. }
  125. if ($action == 'confirm_validate') {
  126. $action = 'edit';
  127. }
  128. /*
  129. * View
  130. */
  131. $form = new Form($db);
  132. $formfile = new FormFile($db);
  133. $formproject = new FormProjets($db);
  134. $formadmin = new FormAdmin($db);
  135. $title = $langs->trans("KnowledgeRecord");
  136. $help_url = '';
  137. llxHeader('', $title, $help_url);
  138. // Part to create
  139. if ($action == 'create') {
  140. print load_fiche_titre($langs->trans("NewKnowledgeRecord"), '', 'object_'.$object->picto);
  141. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  142. print '<input type="hidden" name="token" value="'.newToken().'">';
  143. print '<input type="hidden" name="action" value="add">';
  144. if (!empty($backtopage)) {
  145. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  146. }
  147. if (!empty($backtopageforcancel)) {
  148. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  149. }
  150. print dol_get_fiche_head(array(), '');
  151. print '<table class="border centpercent tableforfieldcreate">'."\n";
  152. // Common attributes
  153. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  154. if (!empty($conf->categorie->enabled)) {
  155. $cate_arbo = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', 'parent', 64, 0, 1);
  156. if (count($cate_arbo)) {
  157. // Categories
  158. print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
  159. print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, GETPOST('categories', 'array'), '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  160. print "</td></tr>";
  161. }
  162. }
  163. // Other attributes
  164. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  165. print '</table>'."\n";
  166. print dol_get_fiche_end();
  167. print $form->buttonsSaveCancel('Create');
  168. print '</form>';
  169. //dol_set_focus('input[name="ref"]');
  170. }
  171. // Part to edit record
  172. if (($id || $ref) && $action == 'edit') {
  173. print load_fiche_titre($langs->trans("KnowledgeRecord"), '', 'object_'.$object->picto);
  174. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  175. print '<input type="hidden" name="token" value="'.newToken().'">';
  176. print '<input type="hidden" name="action" value="update">';
  177. print '<input type="hidden" name="id" value="'.$object->id.'">';
  178. if (!empty($backtopage)) {
  179. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  180. }
  181. if (!empty($backtopageforcancel)) {
  182. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  183. }
  184. print dol_get_fiche_head();
  185. print '<table class="border centpercent tableforfieldedit">'."\n";
  186. // Common attributes
  187. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  188. if (!empty($conf->categorie->enabled)) {
  189. $cate_arbo = $form->select_all_categories(Categorie::TYPE_KNOWLEDGEMANAGEMENT, '', 'parent', 64, 0, 1);
  190. if (count($cate_arbo)) {
  191. // Categories
  192. print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
  193. $c = new Categorie($db);
  194. $cats = $c->containing($object->id, Categorie::TYPE_KNOWLEDGEMANAGEMENT);
  195. $arrayselected = array();
  196. if (is_array($cats)) {
  197. foreach ($cats as $cat) {
  198. $arrayselected[] = $cat->id;
  199. }
  200. }
  201. print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  202. print "</td></tr>";
  203. }
  204. }
  205. // Other attributes
  206. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  207. print '</table>';
  208. print dol_get_fiche_end();
  209. print $form->buttonsSaveCancel();
  210. print '</form>';
  211. }
  212. // Part to show record
  213. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  214. $res = $object->fetch_optionals();
  215. $head = knowledgerecordPrepareHead($object);
  216. print dol_get_fiche_head($head, 'card', $langs->trans("KnowledgeRecord"), -1, $object->picto);
  217. $formconfirm = '';
  218. // Confirmation to delete
  219. if ($action == 'delete') {
  220. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteKnowledgeRecord'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  221. }
  222. // Confirmation to delete line
  223. if ($action == 'deleteline') {
  224. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  225. }
  226. // Clone confirmation
  227. if ($action == 'clone') {
  228. // Create an array for form
  229. $formquestion = array();
  230. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  231. }
  232. // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
  233. if ($action == 'close') {
  234. $text = $langs->trans('ConfirmCloseKM', $object->ref);
  235. /*if (! empty($conf->notification->enabled))
  236. {
  237. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  238. $notify = new Notify($db);
  239. $text .= '<br>';
  240. $text .= $notify->confirmMessage('MYOBJECT_CLOSE', $object->socid, $object);
  241. }*/
  242. $formquestion = array();
  243. /*
  244. $forcecombo=0;
  245. if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  246. $formquestion = array(
  247. // 'text' => $langs->trans("ConfirmClone"),
  248. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  249. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  250. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
  251. );
  252. */
  253. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetObsolete'), $text, 'confirm_close', $formquestion, 0, 1, 220);
  254. }
  255. // Confirmation of action xxxx (You can use it for xxx = 'close', xxx = 'reopen', ...)
  256. if ($action == 'reopen') {
  257. $text = $langs->trans('ConfirmReopenKM', $object->ref);
  258. /*if (! empty($conf->notification->enabled))
  259. {
  260. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  261. $notify = new Notify($db);
  262. $text .= '<br>';
  263. $text .= $notify->confirmMessage('MYOBJECT_CLOSE', $object->socid, $object);
  264. }*/
  265. $formquestion = array();
  266. /*
  267. $forcecombo=0;
  268. if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  269. $formquestion = array(
  270. // 'text' => $langs->trans("ConfirmClone"),
  271. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  272. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  273. // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo))
  274. );
  275. */
  276. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Re-Open'), $text, 'confirm_reopen', $formquestion, 0, 1, 220);
  277. }
  278. // Call Hook formConfirm
  279. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  280. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  281. if (empty($reshook)) {
  282. $formconfirm .= $hookmanager->resPrint;
  283. } elseif ($reshook > 0) {
  284. $formconfirm = $hookmanager->resPrint;
  285. }
  286. // Print form confirm
  287. print $formconfirm;
  288. // Object card
  289. // ------------------------------------------------------------
  290. $linkback = '<a href="'.DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  291. $morehtmlref = '<div class="refidno">';
  292. /*
  293. // Ref customer
  294. $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
  295. $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
  296. // Thirdparty
  297. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . (is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
  298. // Project
  299. if (! empty($conf->project->enabled)) {
  300. $langs->load("projects");
  301. $morehtmlref .= '<br>'.$langs->trans('Project') . ' ';
  302. if ($permissiontoadd) {
  303. //if ($action != 'classify') $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
  304. $morehtmlref .= ' : ';
  305. if ($action == 'classify') {
  306. //$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  307. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  308. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  309. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  310. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  311. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  312. $morehtmlref .= '</form>';
  313. } else {
  314. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  315. }
  316. } else {
  317. if (! empty($object->fk_project)) {
  318. $proj = new Project($db);
  319. $proj->fetch($object->fk_project);
  320. $morehtmlref .= ': '.$proj->getNomUrl();
  321. } else {
  322. $morehtmlref .= '';
  323. }
  324. }
  325. }*/
  326. $morehtmlref .= '</div>';
  327. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  328. print '<div class="fichecenter">';
  329. print '<div class="fichehalfleft">';
  330. print '<div class="underbanner clearboth"></div>';
  331. print '<table class="border centpercent tableforfield">'."\n";
  332. // Common attributes
  333. $keyforbreak='fk_c_ticket_category'; // We change column just before this field
  334. //unset($object->fields['fk_project']); // Hide field already shown in banner
  335. //unset($object->fields['fk_soc']); // Hide field already shown in banner
  336. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  337. // Categories
  338. if (isModEnabled('categorie')) {
  339. print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td colspan="3">';
  340. print $form->showCategories($object->id, Categorie::TYPE_KNOWLEDGEMANAGEMENT, 1);
  341. print "</td></tr>";
  342. }
  343. // Other attributes. Fields from hook formObjectOptions and Extrafields.
  344. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  345. print '</table>';
  346. print '</div>';
  347. print '</div>';
  348. print '<div class="clearboth"></div>';
  349. print dol_get_fiche_end();
  350. // Buttons for actions
  351. if ($action != 'presend' && $action != 'editline') {
  352. print '<div class="tabsAction">'."\n";
  353. $parameters = array();
  354. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  355. if ($reshook < 0) {
  356. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  357. }
  358. if (empty($reshook)) {
  359. // Send
  360. if (empty($user->socid)) {
  361. //print dolGetButtonAction($langs->trans('SendMail'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle');
  362. }
  363. // Back to draft
  364. if ($object->status == $object::STATUS_VALIDATED) {
  365. print dolGetButtonAction($langs->trans('SetToDraft'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes', '', $permissiontoadd);
  366. }
  367. if (($object->status == $object::STATUS_DRAFT || $object->status == $object::STATUS_VALIDATED) && $permissiontovalidate) {
  368. print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken(), '', $permissiontoadd);
  369. }
  370. // Validate
  371. if ($object->status == $object::STATUS_DRAFT) {
  372. if ((empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) && $permissiontovalidate) {
  373. print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&token='.newToken().'&confirm=yes', '', $permissiontoadd);
  374. } else {
  375. $langs->load("errors");
  376. //print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes', '', 0);
  377. print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Reply").'</a>';
  378. }
  379. }
  380. // Clone
  381. print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken().'&object=scrumsprint', '', $permissiontoadd);
  382. /*
  383. if ($permissiontoadd) {
  384. if ($object->status == $object::STATUS_ENABLED) {
  385. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a>'."\n";
  386. } else {
  387. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a>'."\n";
  388. }
  389. }
  390. */
  391. if ($permissiontoadd) {
  392. if ($object->status == $object::STATUS_VALIDATED) {
  393. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken().'">'.$langs->trans("SetObsolete").'</a>'."\n";
  394. } else {
  395. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("Re-Open").'</a>'."\n";
  396. }
  397. }
  398. // Delete (need delete permission, or if draft, just need create/modify permission)
  399. print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd));
  400. }
  401. print '</div>'."\n";
  402. }
  403. // Select mail models is same action as presend
  404. if (GETPOST('modelselected')) {
  405. $action = 'presend';
  406. }
  407. if ($action != 'presend') {
  408. print '<div class="fichecenter"><div class="fichehalfleft">';
  409. print '<a name="builddoc"></a>'; // ancre
  410. $includedocgeneration = 0;
  411. // Documents
  412. if ($includedocgeneration) {
  413. $objref = dol_sanitizeFileName($object->ref);
  414. $relativepath = $objref.'/'.$objref.'.pdf';
  415. $filedir = $conf->knowledgemanagement->dir_output.'/'.$object->element.'/'.$objref;
  416. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  417. $genallowed = $user->rights->knowledgemanagement->knowledgerecord->read; // If you can read, you can build the PDF to read content
  418. $delallowed = $user->rights->knowledgemanagement->knowledgerecord->write; // If you can create/edit, you can remove a file on card
  419. print $formfile->showdocuments('knowledgemanagement:KnowledgeRecord', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  420. }
  421. // Show links to link elements
  422. $linktoelem = $form->showLinkToObjectBlock($object, null, array('knowledgerecord'));
  423. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  424. print '</div><div class="fichehalfright">';
  425. $MAXEVENT = 10;
  426. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/knowledgemanagement/knowledgerecord_agenda.php?id='.$object->id);
  427. // List of actions on element
  428. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  429. $formactions = new FormActions($db);
  430. $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  431. print '</div></div>';
  432. }
  433. //Select mail models is same action as presend
  434. if (GETPOST('modelselected')) {
  435. $action = 'presend';
  436. }
  437. // Presend form
  438. $modelmail = 'knowledgerecord';
  439. $defaulttopic = 'InformationMessage';
  440. $diroutput = $conf->knowledgemanagement->dir_output;
  441. $trackid = 'knowledgerecord'.$object->id;
  442. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  443. }
  444. // End of page
  445. llxFooter();
  446. $db->close();