dolibarr 21.0.0-alpha
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
74 public $target; // 0=replace, 1=new window
75
79 public $title;
80
84 public $position;
85
89 public $favicon;
90
91
97 public function __construct($db)
98 {
99 $this->db = $db;
100
101 $this->ismultientitymanaged = 1;
102 }
103
110 public function fetch($id)
111 {
112 global $conf;
113
114 $sql = "SELECT rowid, fk_user, dateb as datec, url, target,";
115 $sql .= " title, position, favicon";
116 $sql .= " FROM ".MAIN_DB_PREFIX."bookmark";
117 $sql .= " WHERE rowid = ".((int) $id);
118 $sql .= " AND entity = ".$conf->entity;
119
120 dol_syslog("Bookmark::fetch", LOG_DEBUG);
121 $resql = $this->db->query($sql);
122 if ($resql) {
123 $obj = $this->db->fetch_object($resql);
124
125 $this->id = $obj->rowid;
126 $this->ref = $obj->rowid;
127
128 $this->fk_user = $obj->fk_user;
129 $this->datec = $this->db->jdate($obj->datec);
130 $this->url = $obj->url;
131 $this->target = $obj->target;
132 $this->title = $obj->title;
133 $this->position = $obj->position;
134 $this->favicon = $obj->favicon;
135
136 $this->db->free($resql);
137 return $this->id;
138 } else {
139 dol_print_error($this->db);
140 return -1;
141 }
142 }
143
149 public function create()
150 {
151 global $conf;
152
153 // Clean parameters
154 $this->url = trim($this->url);
155 $this->title = trim($this->title);
156 if (empty($this->position)) {
157 $this->position = 0;
158 }
159
160 $now = dol_now();
161
162 $this->db->begin();
163
164 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target";
165 $sql .= ",title,favicon,position";
166 $sql .= ",entity";
167 $sql .= ") VALUES (";
168 $sql .= ($this->fk_user > 0 ? $this->fk_user : "0").",";
169 $sql .= " '".$this->db->idate($now)."',";
170 $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',";
171 $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', ".(int) $this->position;
172 $sql .= ", ".(int) $conf->entity;
173 $sql .= ")";
174
175 dol_syslog("Bookmark::create", LOG_DEBUG);
176 $resql = $this->db->query($sql);
177 if ($resql) {
178 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark");
179 if ($id > 0) {
180 $this->id = $id;
181 $this->db->commit();
182 return $id;
183 } else {
184 $this->error = $this->db->lasterror();
185 $this->errno = $this->db->lasterrno();
186 $this->db->rollback();
187 return -2;
188 }
189 } else {
190 $this->error = $this->db->lasterror();
191 $this->errno = $this->db->lasterrno();
192 $this->db->rollback();
193 return -1;
194 }
195 }
196
202 public function update()
203 {
204 // Clean parameters
205 $this->url = trim($this->url);
206 $this->title = trim($this->title);
207 if (empty($this->position)) {
208 $this->position = 0;
209 }
210
211 $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark";
212 $sql .= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user : "0");
213 $sql .= " ,dateb = '".$this->db->idate($this->datec)."'";
214 $sql .= " ,url = '".$this->db->escape($this->url)."'";
215 $sql .= " ,target = '".$this->db->escape($this->target)."'";
216 $sql .= " ,title = '".$this->db->escape($this->title)."'";
217 $sql .= " ,favicon = '".$this->db->escape($this->favicon)."'";
218 $sql .= " ,position = ".(int) $this->position;
219 $sql .= " WHERE rowid = ".((int) $this->id);
220
221 dol_syslog("Bookmark::update", LOG_DEBUG);
222 if ($this->db->query($sql)) {
223 return 1;
224 } else {
225 $this->error = $this->db->lasterror();
226 return -1;
227 }
228 }
229
236 public function delete($user)
237 {
238 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark";
239 $sql .= " WHERE rowid = ".((int) $this->id);
240
241 $resql = $this->db->query($sql);
242 if ($resql) {
243 return 1;
244 } else {
245 $this->error = $this->db->lasterror();
246 return -1;
247 }
248 }
249
258 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
259 {
260 $tables = array(
261 'bookmark'
262 );
263
264 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
265 }
266
273 public function getLibStatut($mode)
274 {
275 return '';
276 }
277
288 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
289 {
290 global $conf, $langs, $hookmanager;
291
292 if (!empty($conf->dol_no_mouse_hover)) {
293 $notooltip = 1; // Force disable tooltips
294 }
295
296 $result = '';
297
298 $label = '<u>'.$langs->trans("Bookmark").'</u>';
299 $label .= '<br>';
300 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
301
302 $url = DOL_URL_ROOT.'/bookmarks/card.php?id='.$this->id;
303
304 if ($option != 'nolink') {
305 // Add param to save lastsearch_values or not
306 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
307 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
308 $add_save_lastsearch_values = 1;
309 }
310 if ($add_save_lastsearch_values) {
311 $url .= '&save_lastsearch_values=1';
312 }
313 }
314
315 $linkclose = '';
316 if (empty($notooltip)) {
317 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
318 $label = $langs->trans("ShowBookmark");
319 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
320 }
321 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
322 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
323 } else {
324 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
325 }
326
327 $linkstart = '<a href="'.$url.'"';
328 $linkstart .= $linkclose.'>';
329 $linkend = '</a>';
330
331 $result .= $linkstart;
332 if ($withpicto) {
333 $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);
334 }
335 if ($withpicto != 2) {
336 $result .= $this->ref;
337 }
338 $result .= $linkend;
339 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
340
341 global $action, $hookmanager;
342 $hookmanager->initHooks(array('mybookmarkdao'));
343 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
344 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
345 if ($reshook > 0) {
346 $result = $hookmanager->resPrint;
347 } else {
348 $result .= $hookmanager->resPrint;
349 }
350
351 return $result;
352 }
353}
print $object position
Definition edit.php:195
$object ref
Definition info.php:79
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)
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.