dolibarr  17.0.4
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 
29 class Bookmark extends CommonObject
30 {
34  public $element = 'bookmark';
35 
39  public $table_element = 'bookmark';
40 
45  public $ismultientitymanaged = 1;
46 
50  public $picto = 'bookmark';
51 
55  public $db;
56 
60  public $id;
61 
65  public $fk_user;
66 
72  public $datec;
73 
77  public $url;
78 
79  public $target; // 0=replace, 1=new window
80 
84  public $title;
85 
89  public $position;
90 
94  public $favicon;
95 
96 
102  public function __construct($db)
103  {
104  $this->db = $db;
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 
128  $this->id = $obj->rowid;
129  $this->ref = $obj->rowid;
130 
131  $this->fk_user = $obj->fk_user;
132  $this->datec = $this->db->jdate($obj->datec);
133  $this->url = $obj->url;
134  $this->target = $obj->target;
135  $this->title = $obj->title;
136  $this->position = $obj->position;
137  $this->favicon = $obj->favicon;
138 
139  $this->db->free($resql);
140  return $this->id;
141  } else {
142  dol_print_error($this->db);
143  return -1;
144  }
145  }
146 
152  public function create()
153  {
154  global $conf;
155 
156  // Clean parameters
157  $this->url = trim($this->url);
158  $this->title = trim($this->title);
159  if (empty($this->position)) {
160  $this->position = 0;
161  }
162 
163  $now = dol_now();
164 
165  $this->db->begin();
166 
167  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target";
168  $sql .= ",title,favicon,position";
169  $sql .= ",entity";
170  $sql .= ") VALUES (";
171  $sql .= ($this->fk_user > 0 ? $this->fk_user : "0").",";
172  $sql .= " '".$this->db->idate($now)."',";
173  $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',";
174  $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', ".(int) $this->position;
175  $sql .= ", ".(int) $conf->entity;
176  $sql .= ")";
177 
178  dol_syslog("Bookmark::create", LOG_DEBUG);
179  $resql = $this->db->query($sql);
180  if ($resql) {
181  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark");
182  if ($id > 0) {
183  $this->id = $id;
184  $this->db->commit();
185  return $id;
186  } else {
187  $this->error = $this->db->lasterror();
188  $this->errno = $this->db->lasterrno();
189  $this->db->rollback();
190  return -2;
191  }
192  } else {
193  $this->error = $this->db->lasterror();
194  $this->errno = $this->db->lasterrno();
195  $this->db->rollback();
196  return -1;
197  }
198  }
199 
205  public function update()
206  {
207  // Clean parameters
208  $this->url = trim($this->url);
209  $this->title = trim($this->title);
210  if (empty($this->position)) {
211  $this->position = 0;
212  }
213 
214  $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark";
215  $sql .= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user : "0");
216  $sql .= " ,dateb = '".$this->db->idate($this->datec)."'";
217  $sql .= " ,url = '".$this->db->escape($this->url)."'";
218  $sql .= " ,target = '".$this->db->escape($this->target)."'";
219  $sql .= " ,title = '".$this->db->escape($this->title)."'";
220  $sql .= " ,favicon = '".$this->db->escape($this->favicon)."'";
221  $sql .= " ,position = ".(int) $this->position;
222  $sql .= " WHERE rowid = ".((int) $this->id);
223 
224  dol_syslog("Bookmark::update", LOG_DEBUG);
225  if ($this->db->query($sql)) {
226  return 1;
227  } else {
228  $this->error = $this->db->lasterror();
229  return -1;
230  }
231  }
232 
239  public function delete($user)
240  {
241  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark";
242  $sql .= " WHERE rowid = ".((int) $this->id);
243 
244  $resql = $this->db->query($sql);
245  if ($resql) {
246  return 1;
247  } else {
248  $this->error = $this->db->lasterror();
249  return -1;
250  }
251  }
252 
261  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
262  {
263  $tables = array(
264  'bookmark'
265  );
266 
267  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
268  }
269 
276  public function getLibStatut($mode)
277  {
278  return '';
279  }
280 
291  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
292  {
293  global $conf, $langs, $hookmanager;
294 
295  if (!empty($conf->dol_no_mouse_hover)) {
296  $notooltip = 1; // Force disable tooltips
297  }
298 
299  $result = '';
300 
301  $label = '<u>'.$langs->trans("Bookmark").'</u>';
302  $label .= '<br>';
303  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
304 
305  $url = DOL_URL_ROOT.'/bookmarks/card.php?id='.$this->id;
306 
307  if ($option != 'nolink') {
308  // Add param to save lastsearch_values or not
309  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
310  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
311  $add_save_lastsearch_values = 1;
312  }
313  if ($add_save_lastsearch_values) {
314  $url .= '&save_lastsearch_values=1';
315  }
316  }
317 
318  $linkclose = '';
319  if (empty($notooltip)) {
320  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
321  $label = $langs->trans("ShowBookmark");
322  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
323  }
324  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
325  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
326  } else {
327  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
328  }
329 
330  $linkstart = '<a href="'.$url.'"';
331  $linkstart .= $linkclose.'>';
332  $linkend = '</a>';
333 
334  $result .= $linkstart;
335  if ($withpicto) {
336  $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);
337  }
338  if ($withpicto != 2) {
339  $result .= $this->ref;
340  }
341  $result .= $linkend;
342  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
343 
344  global $action, $hookmanager;
345  $hookmanager->initHooks(array('mybookmarkdao'));
346  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
347  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
348  if ($reshook > 0) {
349  $result = $hookmanager->resPrint;
350  } else {
351  $result .= $hookmanager->resPrint;
352  }
353 
354  return $result;
355  }
356 }
$object ref
Definition: info.php:78
Class to manage bookmarks.
create()
Insert bookmark into database.
static replaceThirdparty(DoliDB $db, $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 label of contact status.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
static commonReplaceThirdparty(DoliDB $db, $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('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.
Definition: inc.php:41