diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 45221876e91..189cec49f80 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1051,7 +1051,7 @@ class FormFile global $bc; global $sortfield, $sortorder; - require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; $link = new Link($this->db); $links = array(); if ($sortfield == "name") { @@ -1066,9 +1066,9 @@ class FormFile // Show list of associated links print_titre($langs->trans("LinkedFiles")); - + print '
'; - + print ''; print ''; print_liste_field_titre( @@ -1113,12 +1113,12 @@ class FormFile if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; $var = true; - foreach ($links as $link) + foreach ($links as $link) { $var =! $var; print ''; //edit mode - if ($action == 'update' && $selected === $link->id) + if ($action == 'update' && $selected === $link->id) { print '\n"; } - if ($nboflinks == 0) + if ($nboflinks == 0) { print '
'; print ''; @@ -1157,7 +1157,7 @@ class FormFile } print "
'; print $langs->trans("NoLinkFound"); @@ -1166,7 +1166,7 @@ class FormFile print "
"; print '
'; - + return $nboflinks; } diff --git a/htdocs/link/class/link.class.php b/htdocs/core/class/link.class.php similarity index 88% rename from htdocs/link/class/link.class.php rename to htdocs/core/class/link.class.php index 0bb57c52cf6..8100d526718 100644 --- a/htdocs/link/class/link.class.php +++ b/htdocs/core/class/link.class.php @@ -16,7 +16,7 @@ */ /** - * \file htdocs/link/class/link.class.php + * \file htdocs/core/class/link.class.php * \ingroup link * \brief File for link class */ @@ -39,6 +39,7 @@ class Link extends CommonObject public $objecttype; public $objectid; + /** * Constructor * @@ -102,9 +103,9 @@ class Link extends CommonObject include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); $result=$interface->run_triggers('LINK_CREATE', $this, $user, $langs, $conf); - if ($result < 0) { - $error++; - $this->errors = $interface->errors; + if ($result < 0) { + $error++; + $this->errors = $interface->errors; } // Fin appel triggers } else { @@ -161,12 +162,12 @@ class Link extends CommonObject dol_syslog(get_class($this)."::Update id = " . $this->id . " call_trigger = " . $call_trigger); // Check parameters - if (empty($this->url)) + if (empty($this->url)) { $this->error = $langs->trans("NoURL"); return -1; } - + // Clean parameters $this->url = clean_url($this->url,1); if (empty($this->label)) $this->label = basename($this->url); @@ -176,7 +177,7 @@ class Link extends CommonObject $this->db->begin(); $sql = "UPDATE " . MAIN_DB_PREFIX . "links SET "; - $sql .= "entity = '" . $conf->entity ."'"; + $sql .= "entity = '" . $conf->entity ."'"; $sql .= ", datea = '" . $this->db->idate(dol_now()) . "'"; $sql .= ", url = '" . $this->db->escape($this->url) . "'"; $sql .= ", label = '" . $this->db->escape($this->label) . "'"; @@ -184,25 +185,24 @@ class Link extends CommonObject $sql .= ", objectid = " . $this->objectid; $sql .= " WHERE rowid = '" . $this->id ."'"; - - dol_syslog(get_class($this)."::Update sql = " .$sql); + dol_syslog(get_class($this)."::update sql = " .$sql); $resql = $this->db->query($sql); if ($resql) { - if ($call_trigger) + if ($call_trigger) { // Appel des triggers include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface = new Interfaces($this->db); $result = $interface->run_triggers('LINK_MODIFY', $this, $user, $langs, $conf); - if ($result < 0) { + if ($result < 0) { $error++; $this->errors = $interface->errors; } // Fin appel triggers } - if (! $error) + if (! $error) { dol_syslog(get_class($this) . "::Update success"); $this->db->commit(); @@ -211,16 +211,16 @@ class Link extends CommonObject $this->db->rollback(); return -1; } - } - else + } + else { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { // Doublon $this->error = $langs->trans("ErrorDuplicateField"); $result = -1; } - else + else { $this->error = $langs->trans("Error sql = " . $sql); dol_syslog(get_class($this) . "::Update fails update = " . $this->error, LOG_ERR); @@ -233,34 +233,39 @@ class Link extends CommonObject /** * Loads all links from database - * + * * @param array &$links array of Link objects to fill * @param string $objecttype type of the associated object in dolibarr * @param int $objectid id of the associated object in dolibarr * @param string $sortfield field used to sort * @param string $sortorder sort order * @return 1 if ok, 0 if no records, -1 if error - * + * * */ public function fetchAll(&$links, $objecttype, $objectid, $sortfield=null, $sortorder=null) { global $conf; + $sql = "SELECT rowid, entity, datea, url, label , objecttype, objectid FROM " . MAIN_DB_PREFIX . "links"; $sql .= " WHERE objecttype = '" . $objecttype . "' AND objectid = " . $objectid; - if($conf->entity != 0) $sql .= " AND entity = " . $conf->entity; + if ($conf->entity != 0) $sql .= " AND entity = " . $conf->entity; if ($sortfield) { if (empty($sortorder)) { $sortorder = "ASC"; } $sql .= " ORDER BY " . $sortfield . " " . $sortorder; } + + dol_syslog(get_class($this)."::fetchAll sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); - dol_syslog(get_class($this)."::fetchAll " . $sql, LOG_DEBUG); - if ($resql) { + if ($resql) + { $num = $this->db->num_rows($resql); dol_syslog(get_class($this)."::fetchAll " . $num . "records", LOG_DEBUG); - if ($num > 0) { - while ($obj = $this->db->fetch_object($resql)) { + if ($num > 0) + { + while ($obj = $this->db->fetch_object($resql)) + { $link = new Link($db); $link->id = $obj->rowid; $link->entity = $obj->entity; @@ -281,25 +286,31 @@ class Link extends CommonObject } } - /* + /** * Loads a link from database - * @param rowid id of link to load - * @return int 1 if ok, 0 if no record found, -1 if error - * - * */ + * + * @param int $rowid Id of link to load + * @return int 1 if ok, 0 if no record found, -1 if error + * + **/ public function fetch($rowid=null) { global $conf; + if (empty($rowid)) { $rowid = $this->id; } + $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM " . MAIN_DB_PREFIX . "links"; $sql .= " WHERE rowid = " . $rowid; if($conf->entity != 0) $sql .= " AND entity = " . $conf->entity; + + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); - dol_syslog(get_class($this)."::fetch " . $sql, LOG_DEBUG); - if ($resql) { - if($this->db->num_rows($resql) > 0) { + if ($resql) + { + if($this->db->num_rows($resql) > 0) + { $obj = $this->db->fetch_object($resql); $this->entity = $obj->entity; $this->datea = $this->db->jdate($obj->datea); @@ -308,14 +319,14 @@ class Link extends CommonObject $this->objecttype = $obj->objecttype; $this->objectid = $obj->objectid; return 1; - } else { - $this->error = 'Fetch no link found for id = ' . $rowid; - dol_syslog($this->error, LOG_ERR); + } + else + { return 0; } } else { - dol_syslog($this->db->error(), LOG_ERR); - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); + dol_syslog($this->error, LOG_ERR); return -1; } } @@ -335,11 +346,12 @@ class Link extends CommonObject $this->db->begin(); // Remove link - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "links"; $sql.= " WHERE rowid = " . $this->id; + dol_syslog(get_class($this)."::delete sql=" . $sql, LOG_DEBUG); - if (! $this->db->query($sql)) { + if (! $this->db->query($sql)) + { $error++; $this->error = $this->db->lasterror(); dol_syslog(get_class($this)."::delete error -4 " . $this->error, LOG_ERR); @@ -351,9 +363,9 @@ class Link extends CommonObject include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); $result = $interface->run_triggers('LINK_DELETE', $this, $user, $langs, $conf); - if ($result < 0) { - $error++; - $this->errors = $interface->errors; + if ($result < 0) { + $error++; + $this->errors = $interface->errors; } // Fin appel triggers } diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 17d96bd3356..ae1cf90a393 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1011,12 +1011,12 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio // Define $destpath (path to file including filename) and $destfile (only filename) $destpath=$upload_dir . "/" . $_FILES[$varfiles]['name']; $destfile=$_FILES[$varfiles]['name']; - if ($savingdocmask) + if ($savingdocmask) { $destpath=$upload_dir . "/" . preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask); $destfile=preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask); - } - + } + $resupload = dol_move_uploaded_file($_FILES[$varfiles]['tmp_name'], $destpath, $allowoverwrite, 0, $_FILES[$varfiles]['error'], 0, $varfiles); if (is_numeric($resupload) && $resupload > 0) { @@ -1058,7 +1058,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio } } elseif ($link) { if (dol_mkdir($upload_dir) >= 0) { - require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; $linkObject = new Link($db); $linkObject->entity = $conf->entity; $linkObject->url = $link; diff --git a/htdocs/core/tpl/document_actions_pre_headers.tpl.php b/htdocs/core/tpl/document_actions_pre_headers.tpl.php index 96344944666..06edca3c7c7 100644 --- a/htdocs/core/tpl/document_actions_pre_headers.tpl.php +++ b/htdocs/core/tpl/document_actions_pre_headers.tpl.php @@ -25,7 +25,7 @@ if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { } elseif (GETPOST('linkit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { if ($object->id) { $link = GETPOST('link', 'alpha'); - if ($link) + if ($link) { if (substr($link, 0, 7) != 'http://' && substr($link, 0, 8) != 'https://') { $link = 'http://' . $link; @@ -37,13 +37,13 @@ if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { // Delete file/link -if ($action == 'confirm_deletefile' && $confirm == 'yes') +if ($action == 'confirm_deletefile' && $confirm == 'yes') { - if ($object->id) + if ($object->id) { $urlfile = GETPOST('urlfile', 'alpha'); $linkid = GETPOST('linkid', 'int'); - if ($urlfile) + if ($urlfile) { $file = $upload_dir . "/" . $urlfile; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). @@ -53,10 +53,10 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') } else { setEventMessage($langs->trans("ErrorFailToDeleteFile", $urlfile), 'errors'); } - } - elseif ($linkid) + } + elseif ($linkid) { - require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; $link = new Link($db); $link->id = $linkid; $link->fetch(); @@ -71,29 +71,29 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id); exit; } -} -elseif ($action == 'confirm_updateline' && GETPOST('save') && GETPOST('link', 'alpha')) +} +elseif ($action == 'confirm_updateline' && GETPOST('save') && GETPOST('link', 'alpha')) { - require_once DOL_DOCUMENT_ROOT . '/link/class/link.class.php'; + require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; $langs->load('link'); $link = new Link($db); $link->id = GETPOST('linkid', 'int'); $f = $link->fetch(); - if ($f) + if ($f) { $link->url = GETPOST('link', 'alpha'); - if (substr($link->url, 0, 7) != 'http://' && substr($link->url, 0, 8) != 'https://') + if (substr($link->url, 0, 7) != 'http://' && substr($link->url, 0, 8) != 'https://') { $link->url = 'http://' . $link->url; } $link->label = GETPOST('label', 'alpha'); $res = $link->update($user); - if (!$res) + if (!$res) { setEventMessage($langs->trans("ErrorFailedToUpdateLink", $link->label)); } - } - else + } + else { //error fetching }