dolibarr  9.0.0
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 <http://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 
67  public $datec;
68 
69  public $url;
70 
71  public $target; // 0=replace, 1=new window
72 
73  public $title;
74 
75  public $position;
76 
77  public $favicon;
78 
79 
85  function __construct($db)
86  {
87  $this->db = $db;
88  }
89 
96  function fetch($id)
97  {
98  global $conf;
99 
100  $sql = "SELECT rowid, fk_user, dateb as datec, url, target,";
101  $sql.= " title, position, favicon";
102  $sql.= " FROM ".MAIN_DB_PREFIX."bookmark";
103  $sql.= " WHERE rowid = ".$id;
104  $sql.= " AND entity = ".$conf->entity;
105 
106  dol_syslog("Bookmark::fetch", LOG_DEBUG);
107  $resql = $this->db->query($sql);
108  if ($resql)
109  {
110  $obj = $this->db->fetch_object($resql);
111 
112  $this->id = $obj->rowid;
113  $this->ref = $obj->rowid;
114 
115  $this->fk_user = $obj->fk_user;
116  $this->datec = $this->db->jdate($obj->datec);
117  $this->url = $obj->url;
118  $this->target = $obj->target;
119  $this->title = $obj->title;
120  $this->position= $obj->position;
121  $this->favicon = $obj->favicon;
122 
123  $this->db->free($resql);
124  return $this->id;
125  }
126  else
127  {
128  dol_print_error($this->db);
129  return -1;
130  }
131  }
132 
138  function create()
139  {
140  global $conf;
141 
142  // Clean parameters
143  $this->url=trim($this->url);
144  $this->title=trim($this->title);
145  if (empty($this->position)) $this->position=0;
146 
147  $now=dol_now();
148 
149  $this->db->begin();
150 
151  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target";
152  $sql.= ",title,favicon,position";
153  $sql.= ",entity";
154  $sql.= ") VALUES (";
155  $sql.= ($this->fk_user > 0 ? $this->fk_user:"0").",";
156  $sql.= " '".$this->db->idate($now)."',";
157  $sql.= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',";
158  $sql.= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', '".$this->db->escape($this->position)."'";
159  $sql.= ", ".$this->db->escape($conf->entity);
160  $sql.= ")";
161 
162  dol_syslog("Bookmark::create", LOG_DEBUG);
163  $resql = $this->db->query($sql);
164  if ($resql)
165  {
166  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark");
167  if ($id > 0)
168  {
169  $this->id = $id;
170  $this->db->commit();
171  return $id;
172  }
173  else
174  {
175  $this->error=$this->db->lasterror();
176  $this->errno=$this->db->lasterrno();
177  $this->db->rollback();
178  return -2;
179  }
180  }
181  else
182  {
183  $this->error=$this->db->lasterror();
184  $this->errno=$this->db->lasterrno();
185  $this->db->rollback();
186  return -1;
187  }
188  }
189 
195  function update()
196  {
197  // Clean parameters
198  $this->url=trim($this->url);
199  $this->title=trim($this->title);
200  if (empty($this->position)) $this->position=0;
201 
202  $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark";
203  $sql.= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user :"0");
204  $sql.= " ,dateb = '".$this->db->idate($this->datec)."'";
205  $sql.= " ,url = '".$this->db->escape($this->url)."'";
206  $sql.= " ,target = '".$this->db->escape($this->target)."'";
207  $sql.= " ,title = '".$this->db->escape($this->title)."'";
208  $sql.= " ,favicon = '".$this->db->escape($this->favicon)."'";
209  $sql.= " ,position = '".$this->db->escape($this->position)."'";
210  $sql.= " WHERE rowid = ".$this->id;
211 
212  dol_syslog("Bookmark::update", LOG_DEBUG);
213  if ($this->db->query($sql))
214  {
215  return 1;
216  }
217  else
218  {
219  $this->error=$this->db->lasterror();
220  return -1;
221  }
222  }
223 
230  function remove($id)
231  {
232  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark";
233  $sql .= " WHERE rowid = ".$id;
234 
235  dol_syslog("Bookmark::remove", LOG_DEBUG);
236  $resql=$this->db->query($sql);
237  if ($resql)
238  {
239  return 1;
240  }
241  else
242  {
243  $this->error=$this->db->lasterror();
244  return -1;
245  }
246  }
247 
256  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
257  {
258  $tables = array(
259  'bookmark'
260  );
261 
262  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
263  }
264 
271  function getLibStatut($mode)
272  {
273  return '';
274  }
275 }
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
fetch($id)
Directs the bookmark.
Class to manage Dolibarr database access.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
create()
Insert bookmark into database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
dol_now($mode='gmt')
Return date for now.
__construct($db)
Constructor.
update()
Update bookmark record.
getLibStatut($mode)
Return label of contact status.
Class to manage bookmarks.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)