bloc_comment.tpl.php 5.0 KB

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