dolibarr 22.0.5
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
31{
35 public $element = 'bookmark';
36
40 public $table_element = 'bookmark';
41
45 public $picto = 'bookmark';
46
50 public $errno;
51
55 public $id;
56
60 public $fk_user;
61
67 public $datec;
68
72 public $url;
73
77 public $target;
78
82 public $title;
83
87 public $position;
88
92 public $favicon;
93
94
100 public function __construct($db)
101 {
102 $this->db = $db;
103
104 $this->ismultientitymanaged = 1;
105 }
106
113 public function fetch($id)
114 {
115 global $conf;
116
117 $sql = "SELECT rowid, fk_user, dateb as datec, url, target,";
118 $sql .= " title, position, favicon";
119 $sql .= " FROM ".MAIN_DB_PREFIX."bookmark";
120 $sql .= " WHERE rowid = ".((int) $id);
121 $sql .= " AND entity = ".$conf->entity;
122
123 dol_syslog("Bookmark::fetch", LOG_DEBUG);
124 $resql = $this->db->query($sql);
125 if ($resql) {
126 $obj = $this->db->fetch_object($resql);
127 if (!$obj) {
128 // Bookmark not found (unknown id, or bookmark of another entity)
129 $this->db->free($resql);
130 return 0;
131 }
132
133 $this->id = $obj->rowid;
134 $this->ref = $obj->rowid;
135
136 $this->fk_user = $obj->fk_user;
137 $this->datec = $this->db->jdate($obj->datec);
138 $this->url = $obj->url;
139 $this->target = $obj->target;
140 $this->title = $obj->title;
141 $this->position = $obj->position;
142 $this->favicon = $obj->favicon;
143
144 $this->db->free($resql);
145 return $this->id;
146 } else {
147 dol_print_error($this->db);
148 return -1;
149 }
150 }
151
157 public function create()
158 {
159 global $conf;
160
161 // Clean parameters
162 $this->url = trim($this->url);
163 $this->title = trim($this->title);
164 if (empty($this->position)) {
165 $this->position = 0;
166 }
167
168 $now = dol_now();
169
170 $this->db->begin();
171
172 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target";
173 $sql .= ",title,favicon,position";
174 $sql .= ",entity";
175 $sql .= ") VALUES (";
176 $sql .= ($this->fk_user > 0 ? $this->fk_user : "0").",";
177 $sql .= " '".$this->db->idate($now)."',";
178 $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',";
179 $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', ".(int) $this->position;
180 $sql .= ", ".(int) $conf->entity;
181 $sql .= ")";
182
183 dol_syslog("Bookmark::create", LOG_DEBUG);
184 $resql = $this->db->query($sql);
185 if ($resql) {
186 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark");
187 if ($id > 0) {
188 $this->id = $id;
189 $this->db->commit();
190 return $id;
191 } else {
192 $this->error = $this->db->lasterror();
193 $this->errno = $this->db->lasterrno();
194 $this->db->rollback();
195 return -2;
196 }
197 } else {
198 $this->error = $this->db->lasterror();
199 $this->errno = $this->db->lasterrno();
200 $this->db->rollback();
201 return -1;
202 }
203 }
204
210 public function update()
211 {
212 // Clean parameters
213 $this->url = trim($this->url);
214 $this->title = trim($this->title);
215 if (empty($this->position)) {
216 $this->position = 0;
217 }
218
219 $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark";
220 $sql .= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user : "0");
221 $sql .= " ,dateb = '".$this->db->idate($this->datec)."'";
222 $sql .= " ,url = '".$this->db->escape($this->url)."'";
223 $sql .= " ,target = '".$this->db->escape($this->target)."'";
224 $sql .= " ,title = '".$this->db->escape($this->title)."'";
225 $sql .= " ,favicon = '".$this->db->escape($this->favicon)."'";
226 $sql .= " ,position = ".(int) $this->position;
227 $sql .= " WHERE rowid = ".((int) $this->id);
228
229 dol_syslog("Bookmark::update", LOG_DEBUG);
230 if ($this->db->query($sql)) {
231 return 1;
232 } else {
233 $this->error = $this->db->lasterror();
234 return -1;
235 }
236 }
237
244 public function delete($user)
245 {
246 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark";
247 $sql .= " WHERE rowid = ".((int) $this->id);
248
249 $resql = $this->db->query($sql);
250 if ($resql) {
251 return 1;
252 } else {
253 $this->error = $this->db->lasterror();
254 return -1;
255 }
256 }
257
266 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
267 {
268 $tables = array(
269 'bookmark'
270 );
271
272 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
273 }
274
281 public function getLibStatut($mode)
282 {
283 return '';
284 }
285
296 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
297 {
298 global $conf, $langs, $hookmanager;
299
300 if (!empty($conf->dol_no_mouse_hover)) {
301 $notooltip = 1; // Force disable tooltips
302 }
303
304 $result = '';
305
306 $label = '<u>'.$langs->trans("Bookmark").'</u>';
307 $label .= '<br>';
308 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
309
310 $url = DOL_URL_ROOT.'/bookmarks/card.php?id='.$this->id;
311
312 if ($option != 'nolink') {
313 // Add param to save lastsearch_values or not
314 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
315 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
316 $add_save_lastsearch_values = 1;
317 }
318 if ($add_save_lastsearch_values) {
319 $url .= '&save_lastsearch_values=1';
320 }
321 }
322
323 $linkclose = '';
324 if (empty($notooltip)) {
325 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
326 $label = $langs->trans("ShowBookmark");
327 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
328 }
329 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
330 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
331 } else {
332 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
333 }
334
335 $linkstart = '<a href="'.$url.'"';
336 $linkstart .= $linkclose.'>';
337 $linkend = '</a>';
338
339 $result .= $linkstart;
340 if ($withpicto) {
341 $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);
342 }
343 if ($withpicto != 2) {
344 $result .= $this->ref;
345 }
346 $result .= $linkend;
347 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
348
349 global $action, $hookmanager;
350 $hookmanager->initHooks(array('mybookmarkdao'));
351 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
352 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
353 if ($reshook > 0) {
354 $result = $hookmanager->resPrint;
355 } else {
356 $result .= $hookmanager->resPrint;
357 }
358
359 return $result;
360 }
361}
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79