25require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'link';
41 public $table_element =
'links';
102 global $langs,
$conf;
105 $langs->load(
"errors");
107 if (empty($this->label)) {
108 $this->label = trim(basename($this->url));
110 if (empty($this->datea)) {
113 $this->url = trim($this->url);
115 dol_syslog(get_class($this).
"::create ".$this->url);
118 if (empty($this->url)) {
119 $this->error = $langs->trans(
"NoURL");
125 $sql =
"INSERT INTO ".$this->db->prefix().
"links (entity, datea, url, label, objecttype, objectid, share,share_pass)";
126 $sql .=
" VALUES (".$conf->entity.
", '".$this->db->idate($this->datea).
"'";
127 $sql .=
", '".$this->db->escape($this->url).
"'";
128 $sql .=
", '".$this->db->escape($this->label).
"'";
129 $sql .=
", '".$this->db->escape($this->objecttype).
"'";
130 $sql .=
", ".((int) $this->objectid);
131 $sql .=
', '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null");
132 $sql .=
', '.(!empty($this->share_pass) ?
"'".$this->db->escape($this->share_pass).
"'" :
"null").
")";
134 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
135 $result = $this->db->query($sql);
137 $this->
id = $this->db->last_insert_id($this->db->prefix().
"links");
151 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
155 dol_syslog(get_class($this).
"::Create echec update ".$this->error, LOG_ERR);
156 $this->db->rollback();
160 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
161 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", (
string) $this->
name);
164 $this->error = $this->db->lasterror();
167 $this->db->rollback();
181 global $langs,
$conf;
182 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
184 $langs->load(
"errors");
187 dol_syslog(get_class($this).
"::Update id = ".$this->
id.
" call_trigger = ".$call_trigger);
190 if (empty($this->url)) {
191 $this->error = $langs->trans(
"NoURL");
197 if (empty($this->label)) {
198 $this->label = basename($this->url);
200 $this->label = trim($this->label);
205 $sql =
"UPDATE ".$this->db->prefix().
"links SET ";
206 $sql .=
"entity = ".((int)
$conf->entity);
207 $sql .=
", datea = '".$this->db->idate(
dol_now()).
"'";
208 $sql .=
", url = '".$this->db->escape($this->url).
"'";
209 $sql .=
", label = '".$this->db->escape($this->label).
"'";
210 $sql .=
", objecttype = '".$this->db->escape($this->objecttype).
"'";
211 $sql .=
", objectid = ".((int) $this->objectid);
212 $sql .=
', share = '.(!empty($this->share) ?
"'".$this->db->escape($this->share).
"'" :
"null");
213 $sql .=
', share_pass = '.(!empty($this->share_pass) ?
"'".$this->db->escape($this->share_pass).
"'" :
"null");
214 $sql .=
" WHERE rowid = ".((int) $this->
id);
216 dol_syslog(get_class($this).
"::update sql = ".$sql);
217 $resql = $this->db->query($sql);
229 dol_syslog(get_class($this).
"::Update success");
234 $this->db->rollback();
238 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
240 $this->error = $langs->trans(
"ErrorDuplicateField");
243 $this->error = $langs->trans(
"Error sql").
"= $sql";
246 $this->db->rollback();
261 public function fetchAll(&$links, $objecttype, $objectid, $sortfield =
null, $sortorder =
null)
265 $sql =
"SELECT rowid, entity, datea, url, label, objecttype, objectid, share,share_pass FROM ".$this->db->prefix().
"links";
266 $sql .=
" WHERE objecttype = '".$this->db->escape($objecttype).
"' AND objectid = ".((int) $objectid);
267 if (
$conf->entity != 0) {
268 $sql .=
" AND entity = ".((int)
$conf->entity);
271 if (empty($sortorder)) {
274 $sql .=
" ORDER BY ".$sortfield.
" ".$sortorder;
277 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
278 $resql = $this->db->query($sql);
280 $num = $this->db->num_rows($resql);
281 dol_syslog(get_class($this).
"::fetchAll num=".((
int) $num), LOG_DEBUG);
283 while ($obj = $this->db->fetch_object($resql)) {
284 $link =
new Link($this->db);
285 $link->id = (int) $obj->rowid;
286 $link->entity = $obj->entity;
287 $link->datea = $this->db->jdate($obj->datea);
288 $link->url = $obj->url;
289 $link->label = $obj->label;
290 $link->objecttype = $obj->objecttype;
291 $link->objectid = $obj->objectid;
292 $link->share = $obj->share;
293 $link->share_pass = $obj->share_pass;
313 public static function count($dbs, $objecttype, $objectid)
317 $sql =
"SELECT COUNT(rowid) as nb FROM ".$dbs->prefix().
"links";
318 $sql .=
" WHERE objecttype = '".$dbs->escape($objecttype).
"' AND objectid = ".((int) $objectid);
319 if (
$conf->entity != 0) {
320 $sql .=
" AND entity = ".$conf->entity;
323 $resql = $dbs->query($sql);
325 $obj = $dbs->fetch_object($resql);
340 public function fetch($rowid =
null, $hashforshare =
'')
350 $sql =
"SELECT rowid, entity, datea, url, label, objecttype, objectid, share, share_pass FROM ".$this->db->prefix().
"links";
351 if (!empty((
int) $rowid)) {
352 $sqlwhere[] =
" rowid = ".((int) $rowid);
354 if (!empty($hashforshare)) {
355 $sqlwhere[] =
" share = '".$this->db->escape($hashforshare).
"'";
358 if (
$conf->entity != 0) {
359 $sqlwhere[] =
" entity = ".$conf->entity;
361 if (
count($sqlwhere)>0) {
362 $sql .=
' WHERE '.implode(
' AND ', $sqlwhere);
365 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
366 $resql = $this->db->query($sql);
368 if ($this->db->num_rows($resql) > 0) {
369 $obj = $this->db->fetch_object($resql);
371 $this->
id = $obj->rowid;
372 $this->entity = $obj->entity;
373 $this->datea = $this->db->jdate($obj->datea);
374 $this->url = $obj->url;
375 $this->label = $obj->label;
376 $this->objecttype = $obj->objecttype;
377 $this->objectid = $obj->objectid;
378 $this->share = $obj->share;
379 $this->share_pass = $obj->share_pass;
385 $this->error = $this->db->lasterror();
396 public function delete($user)
398 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
406 $this->db->rollback();
412 $sql =
"DELETE FROM ".$this->db->prefix().
"links";
413 $sql .=
" WHERE rowid = ".((int) $this->
id);
415 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
416 if (!$this->db->query($sql)) {
418 $this->error = $this->db->lasterror();
426 $this->db->rollback();
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
static count($dbs, $objecttype, $objectid)
Return nb of links.
update(User $user, $call_trigger=1)
Update parameters of third party.
__construct($db)
Constructor.
fetchAll(&$links, $objecttype, $objectid, $sortfield=null, $sortorder=null)
Loads all links from database.
create(User $user)
Create link in database.
fetch($rowid=null, $hashforshare='')
Loads a link from database.
Class to manage Dolibarr users.
clean_url($url, $http=1)
Clean an url string.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$conf db name
Only used if Module[ID]Name translation string is not found.