--- /tmp/dsg/dolibarr/htdocs/bookmarks/class/github_19.0.3_bookmark.class.php +++ /tmp/dsg/dolibarr/htdocs/bookmarks/class/client_bookmark.class.php @@ -31 +31 @@ - /** + /** @@ -36,6 +36,6 @@ - /** - * @var string Name of table without prefix where object is stored - */ - public $table_element = 'bookmark'; - - /** + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'bookmark'; + + /** @@ -45,3 +45,3 @@ - public $ismultientitymanaged = 1; - - /** + public $ismultientitymanaged = 1; + + /** @@ -52,13 +52,12 @@ - /** - * Last error code on a local method - * @var int Error number - */ - public $errno; - - /** - * @var int ID - */ - public $id; - - /** - * @var int User ID. If > 0, bookmark of one user. If == 0, bookmark public (for everybody) + /** + * @var DoliDB Database handler. + */ + public $db; + + /** + * @var int ID + */ + public $id; + + /** + * @var int User ID @@ -68,31 +67,19 @@ - /** - * Date creation record (datec) - * - * @var integer - */ - public $datec; - - /** - * @var string url - */ - public $url; - - public $target; // 0=replace, 1=new window - - /** - * @var string title - */ - public $title; - - /** - * @var int position of bookmark - */ - public $position; - - /** - * @var string favicon - */ - public $favicon; - - - /** + /** + * Date creation record (datec) + * + * @var integer + */ + public $datec; + + public $url; + + public $target; // 0=replace, 1=new window + + public $title; + + public $position; + + public $favicon; + + + /** @@ -102,21 +89,21 @@ - */ - public function __construct($db) - { - $this->db = $db; - } - - /** - * Directs the bookmark - * - * @param int $id Bookmark Id Loader - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetch($id) - { - global $conf; - - $sql = "SELECT rowid, fk_user, dateb as datec, url, target,"; - $sql .= " title, position, favicon"; - $sql .= " FROM ".MAIN_DB_PREFIX."bookmark"; - $sql .= " WHERE rowid = ".((int) $id); - $sql .= " AND entity = ".$conf->entity; + */ + public function __construct($db) + { + $this->db = $db; + } + + /** + * Directs the bookmark + * + * @param int $id Bookmark Id Loader + * @return int <0 if KO, >0 if OK + */ + public function fetch($id) + { + global $conf; + + $sql = "SELECT rowid, fk_user, dateb as datec, url, target,"; + $sql .= " title, position, favicon"; + $sql .= " FROM ".MAIN_DB_PREFIX."bookmark"; + $sql .= " WHERE rowid = ".$id; + $sql .= " AND entity = ".$conf->entity; @@ -125,38 +112,39 @@ - $resql = $this->db->query($sql); - if ($resql) { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - - $this->fk_user = $obj->fk_user; - $this->datec = $this->db->jdate($obj->datec); - $this->url = $obj->url; - $this->target = $obj->target; - $this->title = $obj->title; - $this->position = $obj->position; - $this->favicon = $obj->favicon; - - $this->db->free($resql); - return $this->id; - } else { - dol_print_error($this->db); - return -1; - } - } - - /** - * Insert bookmark into database - * - * @return int Return integer <0 si ko, rowid du bookmark cree si ok - */ - public function create() - { - global $conf; - - // Clean parameters - $this->url = trim($this->url); - $this->title = trim($this->title); - if (empty($this->position)) { - $this->position = 0; - } + $resql = $this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + + $this->fk_user = $obj->fk_user; + $this->datec = $this->db->jdate($obj->datec); + $this->url = $obj->url; + $this->target = $obj->target; + $this->title = $obj->title; + $this->position = $obj->position; + $this->favicon = $obj->favicon; + + $this->db->free($resql); + return $this->id; + } + else + { + dol_print_error($this->db); + return -1; + } + } + + /** + * Insert bookmark into database + * + * @return int <0 si ko, rowid du bookmark cree si ok + */ + public function create() + { + global $conf; + + // Clean parameters + $this->url = trim($this->url); + $this->title = trim($this->title); + if (empty($this->position)) $this->position = 0; @@ -166,87 +154,98 @@ - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target"; - $sql .= ",title,favicon,position"; - $sql .= ",entity"; - $sql .= ") VALUES ("; - $sql .= ($this->fk_user > 0 ? $this->fk_user : "0").","; - $sql .= " '".$this->db->idate($now)."',"; - $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',"; - $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', ".(int) $this->position; - $sql .= ", ".(int) $conf->entity; - $sql .= ")"; - - dol_syslog("Bookmark::create", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark"); - if ($id > 0) { - $this->id = $id; - $this->db->commit(); - return $id; - } else { - $this->error = $this->db->lasterror(); - $this->errno = $this->db->lasterrno(); - $this->db->rollback(); - return -2; - } - } else { - $this->error = $this->db->lasterror(); - $this->errno = $this->db->lasterrno(); - $this->db->rollback(); - return -1; - } - } - - /** - * Update bookmark record - * - * @return int Return integer <0 if KO, > if OK - */ - public function update() - { - // Clean parameters - $this->url = trim($this->url); - $this->title = trim($this->title); - if (empty($this->position)) { - $this->position = 0; - } - - $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark"; - $sql .= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user : "0"); - $sql .= " ,dateb = '".$this->db->idate($this->datec)."'"; - $sql .= " ,url = '".$this->db->escape($this->url)."'"; - $sql .= " ,target = '".$this->db->escape($this->target)."'"; - $sql .= " ,title = '".$this->db->escape($this->title)."'"; - $sql .= " ,favicon = '".$this->db->escape($this->favicon)."'"; - $sql .= " ,position = ".(int) $this->position; - $sql .= " WHERE rowid = ".((int) $this->id); - - dol_syslog("Bookmark::update", LOG_DEBUG); - if ($this->db->query($sql)) { - return 1; - } else { - $this->error = $this->db->lasterror(); - return -1; - } - } - - /** - * Removes the bookmark - * - * @param User $user User deleting - * @return int Return integer <0 if KO, >0 if OK - */ - public function delete($user) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark"; - $sql .= " WHERE rowid = ".((int) $this->id); - - $resql = $this->db->query($sql); - if ($resql) { - return 1; - } else { - $this->error = $this->db->lasterror(); - return -1; - } - } + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_user,dateb,url,target"; + $sql .= ",title,favicon,position"; + $sql .= ",entity"; + $sql .= ") VALUES ("; + $sql .= ($this->fk_user > 0 ? $this->fk_user : "0").","; + $sql .= " '".$this->db->idate($now)."',"; + $sql .= " '".$this->db->escape($this->url)."', '".$this->db->escape($this->target)."',"; + $sql .= " '".$this->db->escape($this->title)."', '".$this->db->escape($this->favicon)."', '".$this->db->escape($this->position)."'"; + $sql .= ", ".$this->db->escape($conf->entity); + $sql .= ")"; + + dol_syslog("Bookmark::create", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."bookmark"); + if ($id > 0) + { + $this->id = $id; + $this->db->commit(); + return $id; + } + else + { + $this->error = $this->db->lasterror(); + $this->errno = $this->db->lasterrno(); + $this->db->rollback(); + return -2; + } + } + else + { + $this->error = $this->db->lasterror(); + $this->errno = $this->db->lasterrno(); + $this->db->rollback(); + return -1; + } + } + + /** + * Update bookmark record + * + * @return int <0 if KO, > if OK + */ + public function update() + { + // Clean parameters + $this->url = trim($this->url); + $this->title = trim($this->title); + if (empty($this->position)) $this->position = 0; + + $sql = "UPDATE ".MAIN_DB_PREFIX."bookmark"; + $sql .= " SET fk_user = ".($this->fk_user > 0 ? $this->fk_user : "0"); + $sql .= " ,dateb = '".$this->db->idate($this->datec)."'"; + $sql .= " ,url = '".$this->db->escape($this->url)."'"; + $sql .= " ,target = '".$this->db->escape($this->target)."'"; + $sql .= " ,title = '".$this->db->escape($this->title)."'"; + $sql .= " ,favicon = '".$this->db->escape($this->favicon)."'"; + $sql .= " ,position = '".$this->db->escape($this->position)."'"; + $sql .= " WHERE rowid = ".$this->id; + + dol_syslog("Bookmark::update", LOG_DEBUG); + if ($this->db->query($sql)) + { + return 1; + } + else + { + $this->error = $this->db->lasterror(); + return -1; + } + } + + /** + * Removes the bookmark + * + * @param int $id Id removed bookmark + * @return int <0 si ko, >0 si ok + */ + public function remove($id) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark"; + $sql .= " WHERE rowid = ".$id; + + dol_syslog("Bookmark::remove", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + return 1; + } + else + { + $this->error = $this->db->lasterror(); + return -1; + } + } @@ -257,6 +256,6 @@ - * @param DoliDB $dbs Database handler, because function is static we name it $dbs not $db to avoid breaking coding test - * @param int $origin_id Old thirdparty id - * @param int $dest_id New thirdparty id - * @return bool - */ - public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id) + * @param DoliDB $db Database handler + * @param int $origin_id Old thirdparty id + * @param int $dest_id New thirdparty id + * @return bool + */ + public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) @@ -268 +267 @@ - return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables); + return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); @@ -272 +271 @@ - * Return the label of the status + * Return label of contact status @@ -274,2 +273,2 @@ - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of contact status @@ -279 +278 @@ - return ''; + return ''; @@ -296,3 +295 @@ - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips @@ -308 +305,2 @@ - if ($option != 'nolink') { + if ($option != 'nolink') + { @@ -311,6 +309,2 @@ - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; @@ -320,2 +314,4 @@ - if (empty($notooltip)) { - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { @@ -327,2 +322,0 @@ - } else { - $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); @@ -329,0 +324 @@ + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); @@ -336,6 +331,2 @@ - if ($withpicto) { - $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); - } - if ($withpicto != 2) { - $result .= $this->ref; - } + if ($withpicto) $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); + if ($withpicto != 2) $result .= $this->ref; @@ -347 +338 @@ - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); + $parameters = array('id'=>$this->id, 'getnomurl'=>$result); @@ -349,5 +340,2 @@ - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + if ($reshook > 0) $result = $hookmanager->resPrint; + else $result .= $hookmanager->resPrint;