dolibarr 19.0.3
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 *
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
30{
34 public $element = 'bookmark';
35
39 public $table_element = 'bookmark';
40
45 public $ismultientitymanaged = 1;
46
50 public $picto = 'bookmark';
51
56 public $errno;
57
61 public $id;
62
66 public $fk_user;
67
73 public $datec;
74
78 public $url;
79
80 public $target; // 0=replace, 1=new window
81
85 public $title;
86
90 public $position;
91
95 public $favicon;
96
97
103 public function __construct($db)
104 {
105 $this->db = $db;
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 = ".$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
129 $this->id = $obj->rowid;
130 $this->ref = $obj->rowid;
131
132 $this->fk_user = $obj->fk_user;
133 $this->datec = $this->db->jdate($obj->datec);
134 $this->url = $obj->url;
135 $this->target = $obj->target;
136 $this->title = $obj->title;
137 $this->position = $obj->position;
138 $this->favicon = $obj->favicon;
139
140 $this->db->free($resql);
141 return $this->id;
142 } else {
143 dol_print_error($this->db);
144 return -1;
145 }
146 }
147
153 public function create()
154 {
155 global $conf;
156
157 // Clean parameters
158 $this->url = trim($this->url);
159 $this->title = trim($this->title);
160 if (empty($this->position)) {
161 $this->position = 0;
162 }
163
164 $now = dol_now();
165
166 $this->db->begin();
167
168 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target";
169 $sql .= ",title,favicon,position";
170 $sql .= ",entity";
171 $sql .= ") VALUES (";
172 $sql .= ($this->fk_user > 0 ? $this->fk_user : "0").",";
173 $sql .= " '".$this->db->idate($now)."',";
174 $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',";
175 $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', ".(int) $this->position;
176 $sql .= ", ".(int) $conf->entity;
177 $sql .= ")";
178
179 dol_syslog("Bookmark::create", LOG_DEBUG);
180 $resql = $this->db->query($sql);
181 if ($resql) {
182 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark");
183 if ($id > 0) {
184 $this->id = $id;
185 $this->db->commit();
186 return $id;
187 } else {
188 $this->error = $this->db->lasterror();
189 $this->errno = $this->db->lasterrno();
190 $this->db->rollback();
191 return -2;
192 }
193 } else {
194 $this->error = $this->db->lasterror();
195 $this->errno = $this->db->lasterrno();
196 $this->db->rollback();
197 return -1;
198 }
199 }
200
206 public function update()
207 {
208 // Clean parameters
209 $this->url = trim($this->url);
210 $this->title = trim($this->title);
211 if (empty($this->position)) {
212 $this->position = 0;
213 }
214
215 $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark";
216 $sql .= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user : "0");
217 $sql .= " ,dateb = '".$this->db->idate($this->datec)."'";
218 $sql .= " ,url = '".$this->db->escape($this->url)."'";
219 $sql .= " ,target = '".$this->db->escape($this->target)."'";
220 $sql .= " ,title = '".$this->db->escape($this->title)."'";
221 $sql .= " ,favicon = '".$this->db->escape($this->favicon)."'";
222 $sql .= " ,position = ".(int) $this->position;
223 $sql .= " WHERE rowid = ".((int) $this->id);
224
225 dol_syslog("Bookmark::update", LOG_DEBUG);
226 if ($this->db->query($sql)) {
227 return 1;
228 } else {
229 $this->error = $this->db->lasterror();
230 return -1;
231 }
232 }
233
240 public function delete($user)
241 {
242 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark";
243 $sql .= " WHERE rowid = ".((int) $this->id);
244
245 $resql = $this->db->query($sql);
246 if ($resql) {
247 return 1;
248 } else {
249 $this->error = $this->db->lasterror();
250 return -1;
251 }
252 }
253
262 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
263 {
264 $tables = array(
265 'bookmark'
266 );
267
268 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
269 }
270
277 public function getLibStatut($mode)
278 {
279 return '';
280 }
281
292 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
293 {
294 global $conf, $langs, $hookmanager;
295
296 if (!empty($conf->dol_no_mouse_hover)) {
297 $notooltip = 1; // Force disable tooltips
298 }
299
300 $result = '';
301
302 $label = '<u>'.$langs->trans("Bookmark").'</u>';
303 $label .= '<br>';
304 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
305
306 $url = DOL_URL_ROOT.'/bookmarks/card.php?id='.$this->id;
307
308 if ($option != 'nolink') {
309 // Add param to save lastsearch_values or not
310 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
311 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
312 $add_save_lastsearch_values = 1;
313 }
314 if ($add_save_lastsearch_values) {
315 $url .= '&save_lastsearch_values=1';
316 }
317 }
318
319 $linkclose = '';
320 if (empty($notooltip)) {
321 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
322 $label = $langs->trans("ShowBookmark");
323 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
324 }
325 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
326 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
327 } else {
328 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
329 }
330
331 $linkstart = '<a href="'.$url.'"';
332 $linkstart .= $linkclose.'>';
333 $linkend = '</a>';
334
335 $result .= $linkstart;
336 if ($withpicto) {
337 $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);
338 }
339 if ($withpicto != 2) {
340 $result .= $this->ref;
341 }
342 $result .= $linkend;
343 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
344
345 global $action, $hookmanager;
346 $hookmanager->initHooks(array('mybookmarkdao'));
347 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
348 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
349 if ($reshook > 0) {
350 $result = $hookmanager->resPrint;
351 } else {
352 $result .= $hookmanager->resPrint;
353 }
354
355 return $result;
356 }
357}
$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 optionaly 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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
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.
rtl background position