dolibarr 24.0.2
bookmark.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
32{
36 public $element = 'bookmark';
37
41 public $table_element = 'bookmark';
42
46 public $picto = 'bookmark';
47
51 public $errno;
52
56 public $id;
57
61 public $fk_user;
62
68 public $datec;
69
73 public $url;
74
78 public $target;
79
83 public $title;
84
88 public $position;
89
93 public $favicon;
94
95
101 public function __construct($db)
102 {
103 $this->db = $db;
104
105 $this->ismultientitymanaged = 1;
106 }
107
114 public function fetch($id)
115 {
116 global $conf;
117
118 $sql = "SELECT rowid, fk_user, dateb as datec, url, target,";
119 $sql .= " title, position, favicon";
120 $sql .= " FROM ".MAIN_DB_PREFIX."bookmark";
121 $sql .= " WHERE rowid = ".((int) $id);
122 $sql .= " AND entity = ".((int) $conf->entity);
123
124 dol_syslog("Bookmark::fetch", LOG_DEBUG);
125 $resql = $this->db->query($sql);
126 if ($resql) {
127 $obj = $this->db->fetch_object($resql);
128 if (!$obj) {
129 // Bookmark not found (unknown id, or bookmark of another entity)
130 $this->db->free($resql);
131 return 0;
132 }
133
134 $this->id = $obj->rowid;
135 $this->ref = $obj->rowid;
136
137 $this->fk_user = $obj->fk_user;
138 $this->datec = $this->db->jdate($obj->datec);
139 $this->url = $obj->url;
140 $this->target = $obj->target;
141 $this->title = $obj->title;
142 $this->position = $obj->position;
143 $this->favicon = $obj->favicon;
144
145 $this->db->free($resql);
146 return $this->id;
147 } else {
148 dol_print_error($this->db);
149 return -1;
150 }
151 }
152
158 public function create()
159 {
160 global $conf;
161
162 // Clean parameters
163 $this->url = trim($this->url);
164 $this->title = trim($this->title);
165 if (empty($this->position)) {
166 $this->position = 0;
167 }
168
169 $now = dol_now();
170
171 $this->db->begin();
172
173 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target";
174 $sql .= ",title,favicon,position";
175 $sql .= ",entity";
176 $sql .= ") VALUES (";
177 $sql .= ($this->fk_user > 0 ? ((int) $this->fk_user) : "0").",";
178 $sql .= " '".$this->db->idate($now)."',";
179 $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',";
180 $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', ".(int) $this->position;
181 $sql .= ", ".(int) $conf->entity;
182 $sql .= ")";
183
184 dol_syslog("Bookmark::create", LOG_DEBUG);
185 $resql = $this->db->query($sql);
186 if ($resql) {
187 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark");
188 if ($id > 0) {
189 $this->id = $id;
190 $this->db->commit();
191 return $id;
192 } else {
193 $this->error = $this->db->lasterror();
194 $this->errno = $this->db->lasterrno();
195 $this->db->rollback();
196 return -2;
197 }
198 } else {
199 $this->error = $this->db->lasterror();
200 $this->errno = $this->db->lasterrno();
201 $this->db->rollback();
202 return -1;
203 }
204 }
205
211 public function update()
212 {
213 // Clean parameters
214 $this->url = trim($this->url);
215 $this->title = trim($this->title);
216 if (empty($this->position)) {
217 $this->position = 0;
218 }
219
220 $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark";
221 $sql .= " SET fk_user = ".($this->fk_user > 0 ? ((int) $this->fk_user) : "0");
222 $sql .= " ,dateb = '".$this->db->idate($this->datec)."'";
223 $sql .= " ,url = '".$this->db->escape($this->url)."'";
224 $sql .= " ,target = '".$this->db->escape($this->target)."'";
225 $sql .= " ,title = '".$this->db->escape($this->title)."'";
226 $sql .= " ,favicon = '".$this->db->escape($this->favicon)."'";
227 $sql .= " ,position = ".(int) $this->position;
228 $sql .= " WHERE rowid = ".((int) $this->id);
229
230 dol_syslog("Bookmark::update", LOG_DEBUG);
231 if ($this->db->query($sql)) {
232 return 1;
233 } else {
234 $this->error = $this->db->lasterror();
235 return -1;
236 }
237 }
238
245 public function delete($user)
246 {
247 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark";
248 $sql .= " WHERE rowid = ".((int) $this->id);
249
250 $resql = $this->db->query($sql);
251 if ($resql) {
252 return 1;
253 } else {
254 $this->error = $this->db->lasterror();
255 return -1;
256 }
257 }
258
267 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
268 {
269 $tables = array(
270 'bookmark'
271 );
272
273 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
274 }
275
282 public function getLibStatut($mode)
283 {
284 return '';
285 }
286
297 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
298 {
299 global $conf, $langs, $hookmanager;
300
301 if (!empty($conf->dol_no_mouse_hover)) {
302 $notooltip = 1; // Force disable tooltips
303 }
304
305 $result = '';
306
307 $label = '<u>'.$langs->trans("Bookmark").'</u>';
308 $label .= '<br>';
309 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
310
311 $url = DOL_URL_ROOT.'/bookmarks/card.php?id='.$this->id;
312
313 if ($option != 'nolink') {
314 // Add param to save lastsearch_values or not
315 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
316 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
317 $add_save_lastsearch_values = 1;
318 }
319 if ($add_save_lastsearch_values) {
320 $url .= '&save_lastsearch_values=1';
321 }
322 }
323
324 $linkclose = '';
325 if (empty($notooltip)) {
326 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
327 $label = $langs->trans("ShowBookmark");
328 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
329 }
330 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
331 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
332 } else {
333 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
334 }
335
336 $linkstart = '<a href="'.$url.'"';
337 $linkstart .= $linkclose.'>';
338 $linkend = '</a>';
339
340 $result .= $linkstart;
341 if ($withpicto) {
342 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
343 }
344 if ($withpicto != 2) {
345 $result .= $this->ref;
346 }
347 $result .= $linkend;
348 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
349
350 global $action, $hookmanager;
351 $hookmanager->initHooks(array('mybookmarkdao'));
352 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
353 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
354 if ($reshook > 0) {
355 $result = $hookmanager->resPrint;
356 } else {
357 $result .= $hookmanager->resPrint;
358 }
359
360 return $result;
361 }
362}
print $object position
Definition edit.php:206
$object ref
Definition info.php:90
Class to manage bookmarks.
create()
Insert bookmark into database.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
update()
Update bookmark record.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
fetch($id)
Directs the bookmark.
__construct($db)
Constructor.
getLibStatut($mode)
Return the label of the status.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Class to manage Dolibarr database access.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.