1<?php
2/* Copyright (C) 2012      Regis Houssin       <regis.houssin@inodbox.com>
3 * Copyright (C) 2013      Florian Henry	   <florian.henry@open-concept.pro>
4 * Copyright (C) 2014-2020 Laurent Destailleur <eldy@destailleur.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
20// Protection to avoid direct call of template
21if (empty($object) || !is_object($object)) {
22	print "Error, template page can't be called as URL";
23	exit;
24}
25
26// $permissionnote 	must be defined by caller. For example $permissionnote=$user->rights->module->create
27// $cssclass   		must be defined by caller. For example $cssclass='fieldtitle'
28$module       = $object->element;
29$note_public  = 'note_public';
30$note_private = 'note_private';
31
32$colwidth = (isset($colwidth) ? $colwidth : (empty($cssclass) ? '25' : ''));
33// Set $permission from the $permissionnote var defined on calling page
34$permission = (isset($permissionnote) ? $permissionnote : (isset($permission) ? $permission : (isset($user->rights->$module->create) ? $user->rights->$module->create : (isset($user->rights->$module->creer) ? $user->rights->$module->creer : 0))));
35$moreparam = (isset($moreparam) ? $moreparam : '');
36$value_public = $object->note_public;
37$value_private = $object->note_private;
38if (!empty($conf->global->MAIN_AUTO_TIMESTAMP_IN_PUBLIC_NOTES)) {
39	$stringtoadd = dol_print_date(dol_now(), 'dayhour').' '.$user->getFullName($langs).' --';
40	if (GETPOST('action', 'aZ09') == 'edit'.$note_public) {
41		$value_public = dol_concatdesc($value_public, ($value_public ? "\n" : "")."-- ".$stringtoadd);
42		if (dol_textishtml($value_public)) {
43			$value_public .= "<br>\n";
44		} else {
45			$value_public .= "\n";
46		}
47	}
48}
49if (!empty($conf->global->MAIN_AUTO_TIMESTAMP_IN_PRIVATE_NOTES)) {
50	$stringtoadd = dol_print_date(dol_now(), 'dayhour').' '.$user->getFullName($langs).' --';
51	if (GETPOST('action', 'aZ09') == 'edit'.$note_private) {
52		$value_private = dol_concatdesc($value_private, ($value_private ? "\n" : "")."-- ".$stringtoadd);
53		if (dol_textishtml($value_private)) {
54			$value_private .= "<br>\n";
55		} else {
56			$value_private .= "\n";
57		}
58	}
59}
60
61// Special cases
62if ($module == 'propal') {
63	$permission = $user->rights->propale->creer;
64} elseif ($module == 'supplier_proposal') {
65	$permission = $user->rights->supplier_proposal->creer;
66} elseif ($module == 'fichinter') {
67	$permission = $user->rights->ficheinter->creer;
68} elseif ($module == 'project') {
69	$permission = $user->rights->projet->creer;
70} elseif ($module == 'project_task') {
71	$permission = $user->rights->projet->creer;
72} elseif ($module == 'invoice_supplier') {
73	if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
74		$permission = $user->rights->fournisseur->facture->creer;
75	} else {
76		$permission = $user->rights->supplier_invoice->creer;
77	}
78} elseif ($module == 'order_supplier') {
79	if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
80		$permission = $user->rights->fournisseur->commande->creer;
81	} else {
82		$permission = $user->rights->supplier_order->creer;
83	}
84} elseif ($module == 'societe') {
85	$permission = $user->rights->societe->creer;
86} elseif ($module == 'contact') {
87	$permission = $user->rights->societe->creer;
88} elseif ($module == 'shipping') {
89	$permission = $user->rights->expedition->creer;
90} elseif ($module == 'product') {
91	$permission = $user->rights->produit->creer;
92} elseif ($module == 'ecmfiles') {
93	$permission = $user->rights->ecm->setup;
94}
95//else dol_print_error('','Bad value '.$module.' for param module');
96
97if (!empty($conf->fckeditor->enabled) && !empty($conf->global->FCKEDITOR_ENABLE_SOCIETE)) {
98	$typeofdata = 'ckeditor:dolibarr_notes:100%:200::1:12:95%:0'; // Rem: This var is for all notes, not only thirdparties note.
99} else {
100	$typeofdata = 'textarea:12:95%';
101}
102
103print '<!-- BEGIN PHP TEMPLATE NOTES -->'."\n";
104print '<div class="tagtable border table-border tableforfield centpercent">'."\n";
105print '<div class="tagtr table-border-row">'."\n";
106$editmode = (GETPOST('action', 'aZ09') == 'edit'.$note_public);
107print '<div class="tagtd tagtdnote tdtop'.($editmode ? '' : ' sensiblehtmlcontent').' table-key-border-col'.(empty($cssclass) ? '' : ' '.$cssclass).'"'.($colwidth ? ' style="width: '.$colwidth.'%"' : '').'>'."\n";
108print $form->editfieldkey("NotePublic", $note_public, $value_public, $object, $permission, $typeofdata, $moreparam, '', 0);
109print '</div>'."\n";
110print '<div class="tagtd wordbreak table-val-border-col'.($editmode ? '' : ' sensiblehtmlcontent').'">'."\n";
111print $form->editfieldval("NotePublic", $note_public, $value_public, $object, $permission, $typeofdata, '', null, null, $moreparam, 1)."\n";
112print '</div>'."\n";
113print '</div>'."\n";
114if (empty($user->socid)) {
115	// Private notes (always hidden to external users)
116	print '<div class="tagtr table-border-row">'."\n";
117	$editmode = (GETPOST('action', 'aZ09') == 'edit'.$note_private);
118	print '<div class="tagtd tagtdnote tdtop'.($editmode ? '' : ' sensiblehtmlcontent').' table-key-border-col'.(empty($cssclass) ? '' : ' '.$cssclass).'"'.($colwidth ? ' style="width: '.$colwidth.'%"' : '').'>'."\n";
119	print $form->editfieldkey("NotePrivate", $note_private, $value_private, $object, $permission, $typeofdata, $moreparam, '', 0);
120	print '</div>'."\n";
121	print '<div class="tagtd wordbreak table-val-border-col'.($editmode ? '' : ' sensiblehtmlcontent').'">'."\n";
122	print $form->editfieldval("NotePrivate", $note_private, $value_private, $object, $permission, $typeofdata, '', null, null, $moreparam, 1);
123	print '</div>'."\n";
124	print '</div>'."\n";
125}
126print '</div>'."\n";
127?>
128<!-- END PHP TEMPLATE NOTES-->
129