dolibarr  7.0.0-beta
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 {
31  public $element='bookmark';
32  public $table_element='bookmark';
33  public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
34  public $picto = 'bookmark';
35 
36  var $db;
37 
38  var $id;
39  var $fk_user;
40  var $datec;
41  var $url;
42  var $target; // 0=replace, 1=new window
43  var $title;
44  var $position;
45  var $favicon;
46 
47 
53  function __construct($db)
54  {
55  $this->db = $db;
56  }
57 
64  function fetch($id)
65  {
66  global $conf;
67 
68  $sql = "SELECT rowid, fk_user, dateb as datec, url, target,";
69  $sql.= " title, position, favicon";
70  $sql.= " FROM ".MAIN_DB_PREFIX."bookmark";
71  $sql.= " WHERE rowid = ".$id;
72  $sql.= " AND entity = ".$conf->entity;
73 
74  dol_syslog("Bookmark::fetch", LOG_DEBUG);
75  $resql = $this->db->query($sql);
76  if ($resql)
77  {
78  $obj = $this->db->fetch_object($resql);
79 
80  $this->id = $obj->rowid;
81  $this->ref = $obj->rowid;
82 
83  $this->fk_user = $obj->fk_user;
84  $this->datec = $this->db->jdate($obj->datec);
85  $this->url = $obj->url;
86  $this->target = $obj->target;
87  $this->title = $obj->title;
88  $this->position= $obj->position;
89  $this->favicon = $obj->favicon;
90 
91  $this->db->free($resql);
92  return $this->id;
93  }
94  else
95  {
96  dol_print_error($this->db);
97  return -1;
98  }
99  }
100 
106  function create()
107  {
108  global $conf;
109 
110  // Clean parameters
111  $this->url=trim($this->url);
112  $this->title=trim($this->title);
113  if (empty($this->position)) $this->position=0;
114 
115  $now=dol_now();
116 
117  $this->db->begin();
118 
119  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target";
120  $sql.= ",title,favicon,position";
121  $sql.= ",entity";
122  $sql.= ") VALUES (";
123  $sql.= ($this->fk_user > 0 ? $this->fk_user:"0").",";
124  $sql.= " '".$this->db->idate($now)."',";
125  $sql.= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',";
126  $sql.= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', '".$this->db->escape($this->position)."'";
127  $sql.= ", ".$this->db->escape($conf->entity);
128  $sql.= ")";
129 
130  dol_syslog("Bookmark::update", LOG_DEBUG);
131  $resql = $this->db->query($sql);
132  if ($resql)
133  {
134  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark");
135  if ($id > 0)
136  {
137  $this->id = $id;
138  $this->db->commit();
139  return $id;
140  }
141  else
142  {
143  $this->error=$this->db->lasterror();
144  $this->errno=$this->db->lasterrno();
145  $this->db->rollback();
146  return -2;
147  }
148  }
149  else
150  {
151  $this->error=$this->db->lasterror();
152  $this->errno=$this->db->lasterrno();
153  $this->db->rollback();
154  return -1;
155  }
156  }
157 
163  function update()
164  {
165  // Clean parameters
166  $this->url=trim($this->url);
167  $this->title=trim($this->title);
168  if (empty($this->position)) $this->position=0;
169 
170  $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark";
171  $sql.= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user :"0");
172  $sql.= " ,dateb = '".$this->db->idate($this->datec)."'";
173  $sql.= " ,url = '".$this->db->escape($this->url)."'";
174  $sql.= " ,target = '".$this->db->escape($this->target)."'";
175  $sql.= " ,title = '".$this->db->escape($this->title)."'";
176  $sql.= " ,favicon = '".$this->db->escape($this->favicon)."'";
177  $sql.= " ,position = '".$this->db->escape($this->position)."'";
178  $sql.= " WHERE rowid = ".$this->id;
179 
180  dol_syslog("Bookmark::update", LOG_DEBUG);
181  if ($this->db->query($sql))
182  {
183  return 1;
184  }
185  else
186  {
187  $this->error=$this->db->lasterror();
188  return -1;
189  }
190  }
191 
198  function remove($id)
199  {
200  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark";
201  $sql .= " WHERE rowid = ".$id;
202 
203  dol_syslog("Bookmark::remove", LOG_DEBUG);
204  $resql=$this->db->query($sql);
205  if ($resql)
206  {
207  return 1;
208  }
209  else
210  {
211  $this->error=$this->db->lasterror();
212  return -1;
213  }
214 
215  }
216 
225  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
226  {
227  $tables = array(
228  'bookmark'
229  );
230 
231  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
232  }
233 
240  function getLibStatut($mode)
241  {
242  return '';
243  }
244 
245 }
fetch($id)
Directs the bookmark.
Class to manage Dolibarr database access.
background position
Definition: style.css.php:368
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.
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:1013
getLibStatut($mode)
Return label of contact status.
Class to manage bookmarks.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)