dolibarr 21.0.0-alpha
bloc_comment.tpl.php
1<?php
2/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
3 */
4
5// Protection to avoid direct call of template
6if (empty($conf) || !is_object($conf)) {
7 print "Error, template page can't be called as URL";
8 exit(1);
9}
10
11// Require
12require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
13require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
14
15
16// Vars
17$userstatic = new User($db);
18$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
19
20
21// Add comment
22print '<br>';
23print '<div id="comment">';
24print '<form method="POST" action="'.$varpage.'?id='.$object->id.'">';
25print '<input type="hidden" name="token" value="'.newToken().'">';
26print '<input type="hidden" name="action" value="addcomment">';
27print '<input type="hidden" name="id" value="'.$object->id.'">';
28print '<input type="hidden" name="comment_element_type" value="'.$object->element.'">';
29print '<input type="hidden" name="withproject" value="'.$withproject.'">';
30
31print '<table class="noborder nohover centpercent">';
32
33print '<tr class="liste_titre">';
34print '<td width="25%">'.$langs->trans("Comments").'</td>';
35print '<td width="25%"></td>';
36print '<td width="25%"></td>';
37print '<td width="25%"></td>';
38print "</tr>\n";
39
40if ($action !== 'editcomment') {
41 print '<tr class="oddeven">';
42
43 // Description
44 print '<td colspan="3">';
45
46 $desc = GETPOST('comment_description');
47
48 $doleditor = new DolEditor('comment_description', $desc, '', 80, 'dolibarr_notes', 'In', false, true, true, ROWS_3, '100%');
49 print $doleditor->Create(1);
50
51 print '</td>';
52
53 print '<td class="center">';
54 print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
55 print '</td></tr>';
56}
57
58print '</table></form>';
59
60// List of comments
61if (!empty($object->comments)) {
62 // Default color for current user
63 $TColors = array($user->id => array('bgcolor'=>'efefef', 'color'=>'555'));
64 $first = true;
65 foreach ($object->comments as $comment) {
66 $fk_user = $comment->fk_user_author;
67 $userstatic->fetch($fk_user);
68
69 if (empty($TColors[$fk_user])) {
70 $bgcolor = randomColor(180, 240);
71 if (!empty($userstatic->color)) {
72 $bgcolor = $userstatic->color;
73 }
74 $color = (colorIsLight($bgcolor)) ? '555' : 'fff';
75 $TColors[$fk_user] = array('bgcolor'=>$bgcolor, 'color'=>$color);
76 }
77 print '<div class="width100p" style="color:#'.$TColors[$fk_user]['color'].'">';
78 if ($fk_user != $user->id) {
79 print '<div class="width25p float">&nbsp;</div>';
80 }
81
82 print '<div class="width75p float comment comment-table" style="background-color:#'.$TColors[$fk_user]['bgcolor'].'">';
83 print '<div class="comment-info comment-cell">';
84 if (!empty($user->photo)) {
85 print Form::showphoto('userphoto', $userstatic, 80, 0, 0, '', 'small', 0, 1).'<br>';
86 }
87 print $langs->trans('User').' : '.$userstatic->getNomUrl().'<br>';
88 print $langs->trans('Date').' : '.dol_print_date($comment->datec, 'dayhoursec');
89 print '</div>'; // End comment-info
90
91 print '<div class="comment-cell comment-right">';
92 print '<div class="comment-table width100p">';
93
94 if ($action === 'editcomment' && $comment->id == $idcomment) {
95 print '<form method="POST" action="'.$varpage.'?id='.$object->id.'">';
96 print '<input type="hidden" name="token" value="'.newToken().'">';
97 print '<input type="hidden" name="action" value="updatecomment">';
98 print '<input type="hidden" name="id" value="'.$object->id.'">';
99 print '<input type="hidden" name="idcomment" value="'.$idcomment.'">';
100 print '<input type="hidden" name="withproject" value="'.$withproject.'">';
101 }
102
103 print '<div class="comment-description comment-cell">';
104 if ($action === 'editcomment' && $comment->id == $idcomment) {
105 $doleditor = new DolEditor('comment_description', $comment->description, '', 80, 'dolibarr_notes', 'In', false, true, true, ROWS_3, '100%');
106 print $doleditor->Create(1);
107 } else {
108 print $comment->description;
109 }
110 print '</div>'; // End comment-description
111
112 if ($action === 'editcomment' && $comment->id == $idcomment) {
113 print '<input name="update" type="submit" class="button" value="'.$langs->trans("Update").'">';
114 print '<input name="cancel" type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
115
116 print '</form>';
117 } else {
118 if ($fk_user == $user->id || $user->admin == 1) {
119 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').'">';
120 print img_picto('', 'edit.png');
121 print '</a>';
122 }
123 if (($first && $fk_user == $user->id) || $user->admin == 1) {
124 print '<a class="comment-delete comment-cell" href="'.$varpage.'?action=deletecomment&token='.newToken().'&id='.$id.'&withproject=1&idcomment='.$comment->id.'" title="'.$langs->trans('Delete').'">';
125 print img_picto('', 'delete.png');
126 print '</a>';
127 }
128 }
129
130 print '</div>'; // End comment-table
131 print '</div>'; // End comment-right
132 print '</div>'; // End comment
133
134 if ($fk_user == $user->id) {
135 print '<div class="width25p float">&nbsp;</div>';
136 }
137 print '<div class="clearboth"></div>';
138 print '</div>'; // end 100p
139
140 $first = false;
141 }
142}
143
144print '<br>';
145print '</div>';
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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)
Return HTML code to output a photo.
Class to manage Dolibarr users.
randomColor($min=0, $max=255)
Return hexadecimal color randomly.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
colorIsLight($stringcolor)
Return true if the color is light.