box_bookmarks.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/boxes/box_bookmarks.php
  20. * \ingroup bookmark
  21. * \brief Module to generate box of bookmarks list
  22. */
  23. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  24. /**
  25. * Class to manage the box to show bookmarks
  26. */
  27. class box_bookmarks extends ModeleBoxes
  28. {
  29. public $boxcode = "bookmarks";
  30. public $boximg = "bookmark";
  31. public $boxlabel = "BoxMyLastBookmarks";
  32. public $depends = array("bookmark");
  33. /**
  34. * @var DoliDB Database handler.
  35. */
  36. public $db;
  37. public $param;
  38. public $info_box_head = array();
  39. public $info_box_contents = array();
  40. /**
  41. * Constructor
  42. *
  43. * @param DoliDB $db Database handler
  44. * @param string $param More parameters
  45. */
  46. public function __construct($db, $param)
  47. {
  48. global $user;
  49. $this->db = $db;
  50. $this->hidden = !($user->rights->bookmark->lire);
  51. }
  52. /**
  53. * Load data for box to show them later
  54. *
  55. * @param int $max Maximum number of records to load
  56. * @return void
  57. */
  58. public function loadBox($max = 5)
  59. {
  60. global $user, $langs, $conf;
  61. $langs->load("boxes");
  62. $this->max = $max;
  63. $this->info_box_head = array(
  64. 'text' => $langs->trans("BoxMyLastBookmarks", $max),
  65. 'sublink' => DOL_URL_ROOT.'/bookmarks/list.php',
  66. );
  67. if ($user->rights->bookmark->creer) {
  68. $this->info_box_head['subpicto'] = 'bookmark';
  69. $this->info_box_head['subtext'] = $langs->trans("BookmarksManagement");
  70. } else {
  71. $this->info_box_head['subpicto'] = 'bookmark';
  72. $this->info_box_head['subtext'] = $langs->trans("ListOfBookmark");
  73. }
  74. if ($user->rights->bookmark->lire) {
  75. $sql = "SELECT b.title, b.url, b.target, b.favicon";
  76. $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b";
  77. $sql .= " WHERE fk_user = ".((int) $user->id);
  78. $sql .= " AND b.entity = ".$conf->entity;
  79. $sql .= $this->db->order("position", "ASC");
  80. $sql .= $this->db->plimit($max, 0);
  81. $result = $this->db->query($sql);
  82. if ($result) {
  83. $num = $this->db->num_rows($result);
  84. $line = 0;
  85. while ($line < $num) {
  86. $objp = $this->db->fetch_object($result);
  87. $this->info_box_contents[$line][0] = array(
  88. 'td' => 'class="left" width="16"',
  89. 'logo' => $this->boximg,
  90. 'url' => $objp->url,
  91. 'tooltip' => $objp->title,
  92. 'target' => $objp->target ? 'newtab' : '',
  93. );
  94. $this->info_box_contents[$line][1] = array(
  95. 'td' => '',
  96. 'text' => $objp->title,
  97. 'url' => $objp->url,
  98. 'tooltip' => $objp->title,
  99. 'target' => $objp->target ? 'newtab' : '',
  100. );
  101. $line++;
  102. }
  103. if ($num == 0) {
  104. $mytxt = $langs->trans("NoRecordedBookmarks");
  105. if ($user->rights->bookmark->creer) {
  106. $mytxt .= ' '.$langs->trans("ClickToAdd");
  107. }
  108. $this->info_box_contents[$line][0] = array(
  109. 'td' => 'class="center" colspan="2"',
  110. 'tooltip' => $mytxt,
  111. 'url'=> DOL_URL_ROOT.'/bookmarks/list.php', 'text'=>$mytxt,
  112. );
  113. }
  114. $this->db->free($result);
  115. } else {
  116. $this->info_box_contents[0][0] = array(
  117. 'td' => '',
  118. 'maxlength'=>500,
  119. 'text' => ($this->db->error().' sql='.$sql),
  120. );
  121. }
  122. } else {
  123. $this->info_box_contents[0][0] = array(
  124. 'td' => 'class="nohover opacitymedium left"',
  125. 'text' => $langs->trans("ReadPermissionNotAllowed")
  126. );
  127. }
  128. }
  129. /**
  130. * Method to show box
  131. *
  132. * @param array $head Array with properties of box title
  133. * @param array $contents Array with properties of box lines
  134. * @param int $nooutput No print, only return string
  135. * @return string
  136. */
  137. public function showBox($head = null, $contents = null, $nooutput = 0)
  138. {
  139. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  140. }
  141. }