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