dolibarr 24.0.0-beta
bloc_comment.tpl.php
1<?php
2/* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
3 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
4 */
5
19'
20@phan-var-force string $action
21@phan-var-force string $withproject
22@phan-var-force int $withproject
23@phan-var-force int $id
24@phan-var-force string $idcomment
25';
26
27// Protection to avoid direct call of template
28if (empty($conf) || !is_object($conf)) {
29 print "Error, template page can't be called as URL";
30 exit(1);
31}
32
33// Require
34require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
36
37
38// Vars
39$userstatic = new User($db);
40$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
41
42
43// Add comment
44print '<br>';
45print '<div id="comment">';
46print '<form method="POST" action="'.$varpage.'?id='.$object->id.'">';
47print '<input type="hidden" name="token" value="'.newToken().'">';
48print '<input type="hidden" name="action" value="addcomment">';
49print '<input type="hidden" name="id" value="'.$object->id.'">';
50print '<input type="hidden" name="comment_element_type" value="'.$object->element.'">';
51print '<input type="hidden" name="withproject" value="'.$withproject.'">';
52
53print '<table class="noborder nohover centpercent">';
54
55print '<tr class="liste_titre">';
56print '<td width="25%">'.$langs->trans("Comments").'</td>';
57print '<td width="25%"></td>';
58print '<td width="25%"></td>';
59print '<td width="25%"></td>';
60print "</tr>\n";
61
62if ($action !== 'editcomment') {
63 print '<tr class="oddeven">';
64
65 // Description
66 print '<td colspan="3">';
67
68 $desc = GETPOST('comment_description');
69
70 $doleditor = new DolEditor('comment_description', $desc, '', 80, 'dolibarr_notes', 'In', false, true, true, ROWS_3, '100%');
71 print $doleditor->Create(1);
72
73 print '</td>';
74
75 print '<td class="center">';
76 print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
77 print '</td></tr>';
78}
79
80print '</table></form>';
81
82// List of comments
83if (!empty($object->comments)) {
84 // Default color for current user
85 $TColors = array($user->id => array('bgcolor' => 'efefef', 'color' => '555'));
86 $first = true;
87 foreach ($object->comments as $comment) {
88 $fk_user = $comment->fk_user_author;
89 $userstatic->fetch($fk_user);
90
91 if (empty($TColors[$fk_user])) {
92 $bgcolor = randomColor(180, 240);
93 if (!empty($userstatic->color)) {
94 $bgcolor = $userstatic->color;
95 }
96 $color = (colorIsLight($bgcolor)) ? '555' : 'fff';
97 $TColors[$fk_user] = array('bgcolor' => $bgcolor, 'color' => $color);
98 }
99 print '<div class="width100p" style="color:#'.$TColors[$fk_user]['color'].'">';
100 if ($fk_user != $user->id) {
101 print '<div class="width25p float">&nbsp;</div>';
102 }
103
104 print '<div class="width75p float comment comment-table" style="background-color:#'.$TColors[$fk_user]['bgcolor'].'">';
105 print '<div class="comment-info comment-cell">';
106 if (!empty($user->photo)) {
107 print Form::showphoto('userphoto', $userstatic, 80, 0, 0, '', 'small', 0, 1).'<br>';
108 }
109 print $langs->trans('User').' : '.$userstatic->getNomUrl().'<br>';
110 print $langs->trans('Date').' : '.dol_print_date($comment->datec, 'dayhoursec');
111 print '</div>'; // End comment-info
112
113 print '<div class="comment-cell comment-right">';
114 print '<div class="comment-table width100p">';
115
116 if ($action === 'editcomment' && $comment->id == $idcomment) {
117 print '<form method="POST" action="'.$varpage.'?id='.$object->id.'">';
118 print '<input type="hidden" name="token" value="'.newToken().'">';
119 print '<input type="hidden" name="action" value="updatecomment">';
120 print '<input type="hidden" name="id" value="'.$object->id.'">';
121 print '<input type="hidden" name="idcomment" value="'.$idcomment.'">';
122 print '<input type="hidden" name="withproject" value="'.$withproject.'">';
123 }
124
125 print '<div class="comment-description comment-cell">';
126 if ($action === 'editcomment' && $comment->id == $idcomment) {
127 $doleditor = new DolEditor('comment_description', $comment->description, '', 80, 'dolibarr_notes', 'In', false, true, true, ROWS_3, '100%');
128 print $doleditor->Create(1);
129 } else {
130 print $comment->description;
131 }
132 print '</div>'; // End comment-description
133
134 if ($action === 'editcomment' && $comment->id == $idcomment) {
135 print '<input name="update" type="submit" class="button" value="'.$langs->trans("Update").'">';
136 print '<input name="cancel" type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
137
138 print '</form>';
139 } else {
140 if ($fk_user == $user->id || $user->admin == 1) {
141 print '<a class="comment-edit comment-cell" href="'.$varpage.'?action=editcomment&token='.newToken().'&id='.$id.'&withproject=1&idcomment='.$comment->id.'#comment" title="'.$langs->trans('Edit').'">';
142 print img_picto('', 'edit');
143 print '</a>';
144 }
145 if (($first && $fk_user == $user->id) || $user->admin == 1) {
146 print '<a class="comment-delete comment-cell" href="'.$varpage.'?action=deletecomment&token='.newToken().'&id='.$id.'&withproject=1&idcomment='.$comment->id.'" title="'.$langs->trans('Delete').'">';
147 print img_picto('', 'delete');
148 print '</a>';
149 }
150 }
151
152 print '</div>'; // End comment-table
153 print '</div>'; // End comment-right
154 print '</div>'; // End comment
155
156 if ($fk_user == $user->id) {
157 print '<div class="width25p float">&nbsp;</div>';
158 }
159 print '<div class="clearboth"></div>';
160 print '</div>'; // end 100p
161
162 $first = false;
163 }
164}
165
166print '<br>';
167print '</div>';
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage a WYSIWYG editor.
static showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='', $addlinktofullsize=1, $cache=0, $forcecapture='', $noexternsourceoverwrite=0, $usesharelinkifavailable=0)
Return HTML code to output a photo.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
randomColor($min=0, $max=255)
Return hexadecimal color randomly.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).