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