dolibarr 21.0.0-beta
bloc_comment.tpl.php
1<?php
2/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
3 */
4
16// Protection to avoid direct call of template
17if (empty($conf) || !is_object($conf)) {
18 print "Error, template page can't be called as URL";
19 exit(1);
20}
21
22// Require
23require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
24require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
25
26
27// Vars
28$userstatic = new User($db);
29$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
30
31
32// Add comment
33print '<br>';
34print '<div id="comment">';
35print '<form method="POST" action="'.$varpage.'?id='.$object->id.'">';
36print '<input type="hidden" name="token" value="'.newToken().'">';
37print '<input type="hidden" name="action" value="addcomment">';
38print '<input type="hidden" name="id" value="'.$object->id.'">';
39print '<input type="hidden" name="comment_element_type" value="'.$object->element.'">';
40print '<input type="hidden" name="withproject" value="'.$withproject.'">';
41
42print '<table class="noborder nohover centpercent">';
43
44print '<tr class="liste_titre">';
45print '<td width="25%">'.$langs->trans("Comments").'</td>';
46print '<td width="25%"></td>';
47print '<td width="25%"></td>';
48print '<td width="25%"></td>';
49print "</tr>\n";
50
51if ($action !== 'editcomment') {
52 print '<tr class="oddeven">';
53
54 // Description
55 print '<td colspan="3">';
56
57 $desc = GETPOST('comment_description');
58
59 $doleditor = new DolEditor('comment_description', $desc, '', 80, 'dolibarr_notes', 'In', false, true, true, ROWS_3, '100%');
60 print $doleditor->Create(1);
61
62 print '</td>';
63
64 print '<td class="center">';
65 print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
66 print '</td></tr>';
67}
68
69print '</table></form>';
70
71// List of comments
72if (!empty($object->comments)) {
73 // Default color for current user
74 $TColors = array($user->id => array('bgcolor'=>'efefef', 'color'=>'555'));
75 $first = true;
76 foreach ($object->comments as $comment) {
77 $fk_user = $comment->fk_user_author;
78 $userstatic->fetch($fk_user);
79
80 if (empty($TColors[$fk_user])) {
81 $bgcolor = randomColor(180, 240);
82 if (!empty($userstatic->color)) {
83 $bgcolor = $userstatic->color;
84 }
85 $color = (colorIsLight($bgcolor)) ? '555' : 'fff';
86 $TColors[$fk_user] = array('bgcolor'=>$bgcolor, 'color'=>$color);
87 }
88 print '<div class="width100p" style="color:#'.$TColors[$fk_user]['color'].'">';
89 if ($fk_user != $user->id) {
90 print '<div class="width25p float">&nbsp;</div>';
91 }
92
93 print '<div class="width75p float comment comment-table" style="background-color:#'.$TColors[$fk_user]['bgcolor'].'">';
94 print '<div class="comment-info comment-cell">';
95 if (!empty($user->photo)) {
96 print Form::showphoto('userphoto', $userstatic, 80, 0, 0, '', 'small', 0, 1).'<br>';
97 }
98 print $langs->trans('User').' : '.$userstatic->getNomUrl().'<br>';
99 print $langs->trans('Date').' : '.dol_print_date($comment->datec, 'dayhoursec');
100 print '</div>'; // End comment-info
101
102 print '<div class="comment-cell comment-right">';
103 print '<div class="comment-table width100p">';
104
105 if ($action === 'editcomment' && $comment->id == $idcomment) {
106 print '<form method="POST" action="'.$varpage.'?id='.$object->id.'">';
107 print '<input type="hidden" name="token" value="'.newToken().'">';
108 print '<input type="hidden" name="action" value="updatecomment">';
109 print '<input type="hidden" name="id" value="'.$object->id.'">';
110 print '<input type="hidden" name="idcomment" value="'.$idcomment.'">';
111 print '<input type="hidden" name="withproject" value="'.$withproject.'">';
112 }
113
114 print '<div class="comment-description comment-cell">';
115 if ($action === 'editcomment' && $comment->id == $idcomment) {
116 $doleditor = new DolEditor('comment_description', $comment->description, '', 80, 'dolibarr_notes', 'In', false, true, true, ROWS_3, '100%');
117 print $doleditor->Create(1);
118 } else {
119 print $comment->description;
120 }
121 print '</div>'; // End comment-description
122
123 if ($action === 'editcomment' && $comment->id == $idcomment) {
124 print '<input name="update" type="submit" class="button" value="'.$langs->trans("Update").'">';
125 print '<input name="cancel" type="submit" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
126
127 print '</form>';
128 } else {
129 if ($fk_user == $user->id || $user->admin == 1) {
130 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').'">';
131 print img_picto('', 'edit.png');
132 print '</a>';
133 }
134 if (($first && $fk_user == $user->id) || $user->admin == 1) {
135 print '<a class="comment-delete comment-cell" href="'.$varpage.'?action=deletecomment&token='.newToken().'&id='.$id.'&withproject=1&idcomment='.$comment->id.'" title="'.$langs->trans('Delete').'">';
136 print img_picto('', 'delete.png');
137 print '</a>';
138 }
139 }
140
141 print '</div>'; // End comment-table
142 print '</div>'; // End comment-right
143 print '</div>'; // End comment
144
145 if ($fk_user == $user->id) {
146 print '<div class="width25p float">&nbsp;</div>';
147 }
148 print '<div class="clearboth"></div>';
149 print '</div>'; // end 100p
150
151 $first = false;
152 }
153}
154
155print '<br>';
156print '</div>';
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79