mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-08 00:52:01 +01:00
code syntax fichinter directory
This commit is contained in:
@@ -204,8 +204,7 @@ class Fichinter extends CommonObject
|
||||
$sql = "SELECT count(fi.rowid) as nb";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."fichinter as fi";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON fi.fk_soc = s.rowid";
|
||||
if (!$user->rights->societe->client->voir && !$user->socid)
|
||||
{
|
||||
if (!$user->rights->societe->client->voir && !$user->socid) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
|
||||
$sql .= " WHERE sc.fk_user = ".$user->id;
|
||||
$clause = "AND";
|
||||
@@ -213,10 +212,8 @@ class Fichinter extends CommonObject
|
||||
$sql .= " ".$clause." fi.entity IN (".getEntity('intervention').")";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
while ($obj = $this->db->fetch_object($resql))
|
||||
{
|
||||
if ($resql) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$this->nb["interventions"] = $obj->nb;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
@@ -244,21 +241,20 @@ class Fichinter extends CommonObject
|
||||
dol_syslog(get_class($this)."::create ref=".$this->ref);
|
||||
|
||||
// Check parameters
|
||||
if (!empty($this->ref)) // We check that ref is not already used
|
||||
{
|
||||
if (!empty($this->ref)) { // We check that ref is not already used
|
||||
$result = self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$this->error = 'ErrorRefAlreadyExists';
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (!is_numeric($this->duration)) $this->duration = 0;
|
||||
if (!is_numeric($this->duration)) {
|
||||
$this->duration = 0;
|
||||
}
|
||||
|
||||
if ($this->socid <= 0)
|
||||
{
|
||||
if ($this->socid <= 0) {
|
||||
$this->error = 'ErrorBadParameterForFunc';
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
@@ -304,42 +300,42 @@ class Fichinter extends CommonObject
|
||||
|
||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
if ($result) {
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."fichinter");
|
||||
|
||||
if ($this->id)
|
||||
{
|
||||
if ($this->id) {
|
||||
$this->ref = '(PROV'.$this->id.')';
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX."fichinter SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) $error++;
|
||||
if (!$resql) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$result = $this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
// Add linked object
|
||||
if (!$error && $this->origin && $this->origin_id)
|
||||
{
|
||||
if (!$error && $this->origin && $this->origin_id) {
|
||||
$ret = $this->add_object_linked();
|
||||
if (!$ret) dol_print_error($this->db);
|
||||
if (!$ret) {
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$error && !$notrigger)
|
||||
{
|
||||
if (!$error && !$notrigger) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('FICHINTER_CREATE', $user);
|
||||
if ($result < 0) { $error++; }
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
@@ -370,14 +366,14 @@ class Fichinter extends CommonObject
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (!is_numeric($this->duration)) {
|
||||
$this->duration = 0;
|
||||
}
|
||||
if (!dol_strlen($this->fk_project)) {
|
||||
$this->fk_project = 0;
|
||||
}
|
||||
if (!is_numeric($this->duration)) {
|
||||
$this->duration = 0;
|
||||
}
|
||||
if (!dol_strlen($this->fk_project)) {
|
||||
$this->fk_project = 0;
|
||||
}
|
||||
|
||||
$error = 0;
|
||||
$error = 0;
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
@@ -391,22 +387,20 @@ class Fichinter extends CommonObject
|
||||
$sql .= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if (!$error)
|
||||
{
|
||||
if ($this->db->query($sql)) {
|
||||
if (!$error) {
|
||||
$result = $this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error && !$notrigger)
|
||||
{
|
||||
if (!$error && !$notrigger) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('FICHINTER_MODIFY', $user);
|
||||
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
|
||||
if ($result < 0) {
|
||||
$error++; $this->db->rollback(); return -1;
|
||||
}
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
@@ -437,14 +431,14 @@ class Fichinter extends CommonObject
|
||||
if ($ref) {
|
||||
$sql .= " WHERE f.entity IN (".getEntity('intervention').")";
|
||||
$sql .= " AND f.ref='".$this->db->escape($ref)."'";
|
||||
} else $sql .= " WHERE f.rowid=".$rowid;
|
||||
} else {
|
||||
$sql .= " WHERE f.rowid=".$rowid;
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
if ($resql) {
|
||||
if ($this->db->num_rows($resql)) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
@@ -470,7 +464,9 @@ class Fichinter extends CommonObject
|
||||
|
||||
$this->extraparams = (array) json_decode($obj->extraparams, true);
|
||||
|
||||
if ($this->statut == 0) $this->brouillon = 1;
|
||||
if ($this->statut == 0) {
|
||||
$this->brouillon = 1;
|
||||
}
|
||||
|
||||
// Retrieve extrafields
|
||||
$this->fetch_optionals();
|
||||
@@ -479,8 +475,7 @@ class Fichinter extends CommonObject
|
||||
* Lines
|
||||
*/
|
||||
$result = $this->fetch_lines();
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
return -3;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
@@ -505,8 +500,7 @@ class Fichinter extends CommonObject
|
||||
$error = 0;
|
||||
|
||||
// Protection
|
||||
if ($this->statut <= self::STATUS_DRAFT)
|
||||
{
|
||||
if ($this->statut <= self::STATUS_DRAFT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -519,8 +513,7 @@ class Fichinter extends CommonObject
|
||||
$sql .= " WHERE rowid = ".$this->id;
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
if (!$error) {
|
||||
$this->oldcopy = clone $this;
|
||||
}
|
||||
@@ -528,7 +521,9 @@ class Fichinter extends CommonObject
|
||||
if (!$error) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('FICHINTER_UNVALIDATE', $user);
|
||||
if ($result < 0) $error++;
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
@@ -560,15 +555,13 @@ class Fichinter extends CommonObject
|
||||
|
||||
$error = 0;
|
||||
|
||||
if ($this->statut != 1)
|
||||
{
|
||||
if ($this->statut != 1) {
|
||||
$this->db->begin();
|
||||
|
||||
$now = dol_now();
|
||||
|
||||
// Define new ref
|
||||
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
|
||||
{
|
||||
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
|
||||
$num = $this->getNextNumRef($this->thirdparty);
|
||||
} else {
|
||||
$num = $this->ref;
|
||||
@@ -586,51 +579,48 @@ class Fichinter extends CommonObject
|
||||
|
||||
dol_syslog(get_class($this)."::setValid", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql)
|
||||
{
|
||||
if (!$resql) {
|
||||
dol_print_error($this->db);
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error && !$notrigger)
|
||||
{
|
||||
if (!$error && !$notrigger) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('FICHINTER_VALIDATE', $user);
|
||||
if ($result < 0) { $error++; }
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$this->oldref = $this->ref;
|
||||
|
||||
// Rename directory if dir was a temporary ref
|
||||
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
||||
{
|
||||
if (preg_match('/^[\(]?PROV/i', $this->ref)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Now we rename also files into index
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'ficheinter/".$this->db->escape($this->newref)."'";
|
||||
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'ficheinter/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
|
||||
if (!$resql) {
|
||||
$error++; $this->error = $this->db->lasterror();
|
||||
}
|
||||
|
||||
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
|
||||
$oldref = dol_sanitizeFileName($this->ref);
|
||||
$newref = dol_sanitizeFileName($num);
|
||||
$dirsource = $conf->ficheinter->dir_output.'/'.$oldref;
|
||||
$dirdest = $conf->ficheinter->dir_output.'/'.$newref;
|
||||
if (!$error && file_exists($dirsource))
|
||||
{
|
||||
if (!$error && file_exists($dirsource)) {
|
||||
dol_syslog(get_class($this)."::setValid rename dir ".$dirsource." into ".$dirdest);
|
||||
|
||||
if (@rename($dirsource, $dirdest))
|
||||
{
|
||||
if (@rename($dirsource, $dirdest)) {
|
||||
dol_syslog("Rename ok");
|
||||
// Rename docs starting with $oldref with $newref
|
||||
$listoffiles = dol_dir_list($conf->ficheinter->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
|
||||
foreach ($listoffiles as $fileentry)
|
||||
{
|
||||
foreach ($listoffiles as $fileentry) {
|
||||
$dirsource = $fileentry['name'];
|
||||
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
|
||||
$dirsource = $fileentry['path'].'/'.$dirsource;
|
||||
@@ -643,8 +633,7 @@ class Fichinter extends CommonObject
|
||||
}
|
||||
|
||||
// Set new ref and define current statut
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$this->ref = $num;
|
||||
$this->statut = 1;
|
||||
$this->brouillon = 0;
|
||||
@@ -740,8 +729,7 @@ class Fichinter extends CommonObject
|
||||
{
|
||||
// phpcs:enable
|
||||
// Init/load array of translation of status
|
||||
if (empty($this->statuts) || empty($this->statuts_short) || empty($this->statuts_logo))
|
||||
{
|
||||
if (empty($this->statuts) || empty($this->statuts_short) || empty($this->statuts_logo)) {
|
||||
global $langs;
|
||||
$langs->load("fichinter");
|
||||
|
||||
@@ -785,19 +773,20 @@ class Fichinter extends CommonObject
|
||||
|
||||
$url = DOL_URL_ROOT.'/fichinter/card.php?id='.$this->id;
|
||||
|
||||
if ($option !== 'nolink')
|
||||
{
|
||||
if ($option !== 'nolink') {
|
||||
// Add param to save lastsearch_values or not
|
||||
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
|
||||
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';
|
||||
}
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
$linkclose = '';
|
||||
if (empty($notooltip))
|
||||
{
|
||||
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
|
||||
{
|
||||
if (empty($notooltip)) {
|
||||
if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
|
||||
$label = $langs->trans("ShowIntervention");
|
||||
$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
|
||||
}
|
||||
@@ -817,16 +806,23 @@ class Fichinter extends CommonObject
|
||||
$linkend = '</a>';
|
||||
|
||||
$result .= $linkstart;
|
||||
if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($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, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
|
||||
}
|
||||
if ($withpicto != 2) {
|
||||
$result .= $this->ref;
|
||||
}
|
||||
$result .= $linkend;
|
||||
|
||||
global $action;
|
||||
$hookmanager->initHooks(array('interventiondao'));
|
||||
$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
|
||||
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||
if ($reshook > 0) $result = $hookmanager->resPrint;
|
||||
else $result .= $hookmanager->resPrint;
|
||||
if ($reshook > 0) {
|
||||
$result = $hookmanager->resPrint;
|
||||
} else {
|
||||
$result .= $hookmanager->resPrint;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -844,8 +840,7 @@ class Fichinter extends CommonObject
|
||||
global $conf, $db, $langs;
|
||||
$langs->load("interventions");
|
||||
|
||||
if (!empty($conf->global->FICHEINTER_ADDON))
|
||||
{
|
||||
if (!empty($conf->global->FICHEINTER_ADDON)) {
|
||||
$mybool = false;
|
||||
|
||||
$file = "mod_".$conf->global->FICHEINTER_ADDON.".php";
|
||||
@@ -870,8 +865,7 @@ class Fichinter extends CommonObject
|
||||
$numref = "";
|
||||
$numref = $obj->getNextValue($soc, $this);
|
||||
|
||||
if ($numref != "")
|
||||
{
|
||||
if ($numref != "") {
|
||||
return $numref;
|
||||
} else {
|
||||
dol_print_error($db, "Fichinter::getNextNumRef ".$obj->error);
|
||||
@@ -905,10 +899,8 @@ class Fichinter extends CommonObject
|
||||
$sql .= " WHERE f.rowid = ".$id;
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
if ($resql) {
|
||||
if ($this->db->num_rows($resql)) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
@@ -921,14 +913,12 @@ class Fichinter extends CommonObject
|
||||
$cuser->fetch($obj->fk_user_author);
|
||||
$this->user_creation = $cuser;
|
||||
|
||||
if ($obj->fk_user_valid)
|
||||
{
|
||||
if ($obj->fk_user_valid) {
|
||||
$vuser = new User($this->db);
|
||||
$vuser->fetch($obj->fk_user_valid);
|
||||
$this->user_validation = $vuser;
|
||||
}
|
||||
if ($obj->fk_user_modification)
|
||||
{
|
||||
if ($obj->fk_user_modification) {
|
||||
$muser = new User($this->db);
|
||||
$muser->fetch($obj->fk_user_modification);
|
||||
$this->user_modification = $muser;
|
||||
@@ -956,27 +946,27 @@ class Fichinter extends CommonObject
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
if (!$error && !$notrigger)
|
||||
{
|
||||
if (!$error && !$notrigger) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('FICHINTER_DELETE', $user);
|
||||
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
|
||||
if ($result < 0) {
|
||||
$error++; $this->db->rollback(); return -1;
|
||||
}
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
// Delete linked object
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$res = $this->deleteObjectLinked();
|
||||
if ($res < 0) $error++;
|
||||
if ($res < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete linked contacts
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$res = $this->delete_linked_contact();
|
||||
if ($res < 0)
|
||||
{
|
||||
if ($res < 0) {
|
||||
$this->error = 'ErrorFailToDeleteLinkedContact';
|
||||
$error++;
|
||||
}
|
||||
@@ -988,62 +978,61 @@ class Fichinter extends CommonObject
|
||||
$sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".$this->id.")";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) $error++;
|
||||
if (!$resql) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
|
||||
$sql .= " WHERE fk_fichinter = ".$this->id;
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) $error++;
|
||||
if (!$resql) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
// Remove extrafields
|
||||
$res = $this->deleteExtraFields();
|
||||
if ($res < 0) $error++;
|
||||
if ($res < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
// Delete object
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
|
||||
$sql .= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog("Fichinter::delete", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) $error++;
|
||||
if (!$resql) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
// Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive
|
||||
$this->deleteEcmFiles();
|
||||
|
||||
// Remove directory with files
|
||||
$fichinterref = dol_sanitizeFileName($this->ref);
|
||||
if ($conf->ficheinter->dir_output)
|
||||
{
|
||||
if ($conf->ficheinter->dir_output) {
|
||||
$dir = $conf->ficheinter->dir_output."/".$fichinterref;
|
||||
$file = $conf->ficheinter->dir_output."/".$fichinterref."/".$fichinterref.".pdf";
|
||||
if (file_exists($file))
|
||||
{
|
||||
if (file_exists($file)) {
|
||||
dol_delete_preview($this);
|
||||
|
||||
if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers
|
||||
{
|
||||
if (!dol_delete_file($file, 0, 0, 0, $this)) { // For triggers
|
||||
$langs->load("errors");
|
||||
$this->error = $langs->trans("ErrorFailToDeleteFile", $file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (file_exists($dir))
|
||||
{
|
||||
if (!dol_delete_dir_recursive($dir))
|
||||
{
|
||||
if (file_exists($dir)) {
|
||||
if (!dol_delete_dir_recursive($dir)) {
|
||||
$langs->load("errors");
|
||||
$this->error = $langs->trans("ErrorFailToDeleteDir", $dir);
|
||||
return 0;
|
||||
@@ -1052,8 +1041,7 @@ class Fichinter extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
} else {
|
||||
@@ -1075,15 +1063,13 @@ class Fichinter extends CommonObject
|
||||
// phpcs:enable
|
||||
global $conf;
|
||||
|
||||
if ($user->rights->ficheinter->creer)
|
||||
{
|
||||
if ($user->rights->ficheinter->creer) {
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
|
||||
$sql .= " SET datei = '".$this->db->idate($date_delivery)."'";
|
||||
$sql .= " WHERE rowid = ".$this->id;
|
||||
$sql .= " AND fk_statut = 0";
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if ($this->db->query($sql)) {
|
||||
$this->date_delivery = $date_delivery;
|
||||
return 1;
|
||||
} else {
|
||||
@@ -1107,15 +1093,13 @@ class Fichinter extends CommonObject
|
||||
// phpcs:enable
|
||||
global $conf;
|
||||
|
||||
if ($user->rights->ficheinter->creer)
|
||||
{
|
||||
if ($user->rights->ficheinter->creer) {
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
|
||||
$sql .= " SET description = '".$this->db->escape($description)."',";
|
||||
$sql .= " fk_user_modif = ".$user->id;
|
||||
$sql .= " WHERE rowid = ".$this->id;
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if ($this->db->query($sql)) {
|
||||
$this->description = $description;
|
||||
return 1;
|
||||
} else {
|
||||
@@ -1140,14 +1124,12 @@ class Fichinter extends CommonObject
|
||||
// phpcs:enable
|
||||
global $conf;
|
||||
|
||||
if ($user->rights->ficheinter->creer)
|
||||
{
|
||||
if ($user->rights->ficheinter->creer) {
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
|
||||
$sql .= " SET fk_contrat = ".((int) $contractid);
|
||||
$sql .= " WHERE rowid = ".$this->id;
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if ($this->db->query($sql)) {
|
||||
$this->fk_contrat = $contractid;
|
||||
return 1;
|
||||
} else {
|
||||
@@ -1176,19 +1158,18 @@ class Fichinter extends CommonObject
|
||||
$this->db->begin();
|
||||
|
||||
// get extrafields so they will be clone
|
||||
foreach ($this->lines as $line)
|
||||
foreach ($this->lines as $line) {
|
||||
$line->fetch_optionals();
|
||||
}
|
||||
|
||||
// Load source object
|
||||
$objFrom = clone $this;
|
||||
|
||||
// Change socid if needed
|
||||
if (!empty($socid) && $socid != $this->socid)
|
||||
{
|
||||
if (!empty($socid) && $socid != $this->socid) {
|
||||
$objsoc = new Societe($this->db);
|
||||
|
||||
if ($objsoc->fetch($socid) > 0)
|
||||
{
|
||||
if ($objsoc->fetch($socid) > 0) {
|
||||
$this->socid = $objsoc->id;
|
||||
//$this->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
|
||||
//$this->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
|
||||
@@ -1213,31 +1194,31 @@ class Fichinter extends CommonObject
|
||||
// Create clone
|
||||
$this->context['createfromclone'] = 'createfromclone';
|
||||
$result = $this->create($user);
|
||||
if ($result < 0) $error++;
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
// Add lines because it is not included into create function
|
||||
foreach ($this->lines as $line)
|
||||
{
|
||||
foreach ($this->lines as $line) {
|
||||
$this->addline($user, $this->id, $line->desc, $line->datei, $line->duration);
|
||||
}
|
||||
|
||||
// Hook of thirdparty module
|
||||
if (is_object($hookmanager))
|
||||
{
|
||||
if (is_object($hookmanager)) {
|
||||
$parameters = array('objFrom'=>$objFrom);
|
||||
$action = '';
|
||||
$reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||
if ($reshook < 0) $error++;
|
||||
if ($reshook < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($this->context['createfromclone']);
|
||||
|
||||
// End
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$this->db->commit();
|
||||
return $this->id;
|
||||
} else {
|
||||
@@ -1262,8 +1243,7 @@ class Fichinter extends CommonObject
|
||||
{
|
||||
dol_syslog(get_class($this)."::addline $fichinterid, $desc, $date_intervention, $duration");
|
||||
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
if ($this->statut == 0) {
|
||||
$this->db->begin();
|
||||
|
||||
// Insertion ligne
|
||||
@@ -1280,8 +1260,7 @@ class Fichinter extends CommonObject
|
||||
|
||||
$result = $line->insert($user);
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
if ($result >= 0) {
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
} else {
|
||||
@@ -1317,8 +1296,7 @@ class Fichinter extends CommonObject
|
||||
$this->duration = 0;
|
||||
$nbp = 25;
|
||||
$xnbp = 0;
|
||||
while ($xnbp < $nbp)
|
||||
{
|
||||
while ($xnbp < $nbp) {
|
||||
$line = new FichinterLigne($this->db);
|
||||
$line->desc = $langs->trans("Description")." ".$xnbp;
|
||||
$line->datei = ($now - 3600 * (1 + $xnbp));
|
||||
@@ -1348,12 +1326,10 @@ class Fichinter extends CommonObject
|
||||
|
||||
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
$objp = $this->db->fetch_object($resql);
|
||||
|
||||
$line = new FichinterLigne($this->db);
|
||||
@@ -1466,8 +1442,7 @@ class FichinterLigne extends CommonObjectLine
|
||||
|
||||
dol_syslog("FichinterLigne::fetch", LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
if ($result) {
|
||||
$objp = $this->db->fetch_object($result);
|
||||
$this->rowid = $objp->rowid;
|
||||
$this->id = $objp->rowid;
|
||||
@@ -1503,14 +1478,12 @@ class FichinterLigne extends CommonObjectLine
|
||||
$this->db->begin();
|
||||
|
||||
$rangToUse = $this->rang;
|
||||
if ($rangToUse == -1)
|
||||
{
|
||||
if ($rangToUse == -1) {
|
||||
// Recupere rang max de la ligne d'intervention dans $rangmax
|
||||
$sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'fichinterdet';
|
||||
$sql .= ' WHERE fk_fichinter ='.$this->fk_fichinter;
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$rangToUse = $obj->max + 1;
|
||||
} else {
|
||||
@@ -1532,16 +1505,13 @@ class FichinterLigne extends CommonObjectLine
|
||||
|
||||
dol_syslog("FichinterLigne::insert", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'fichinterdet');
|
||||
$this->rowid = $this->id;
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$result = $this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
@@ -1549,15 +1519,15 @@ class FichinterLigne extends CommonObjectLine
|
||||
|
||||
$result = $this->update_total();
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
if ($result > 0) {
|
||||
$this->rang = $rangToUse;
|
||||
|
||||
if (!$notrigger)
|
||||
{
|
||||
if (!$notrigger) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('LINEFICHINTER_CREATE', $user);
|
||||
if ($result < 0) { $error++; }
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
// End call triggers
|
||||
}
|
||||
}
|
||||
@@ -1602,31 +1572,27 @@ class FichinterLigne extends CommonObjectLine
|
||||
|
||||
dol_syslog("FichinterLigne::update", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if (!$error)
|
||||
{
|
||||
if ($resql) {
|
||||
if (!$error) {
|
||||
$result = $this->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->update_total();
|
||||
if ($result > 0)
|
||||
{
|
||||
if (!$notrigger)
|
||||
{
|
||||
if ($result > 0) {
|
||||
if (!$notrigger) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('LINEFICHINTER_UPDATE', $user);
|
||||
if ($result < 0) { $error++; }
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
// End call triggers
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$this->db->commit();
|
||||
return $result;
|
||||
} else {
|
||||
@@ -1660,11 +1626,12 @@ class FichinterLigne extends CommonObjectLine
|
||||
|
||||
dol_syslog("FichinterLigne::update_total", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$total_duration = 0;
|
||||
if (!empty($obj->total_duration)) $total_duration = $obj->total_duration;
|
||||
if (!empty($obj->total_duration)) {
|
||||
$total_duration = $obj->total_duration;
|
||||
}
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
|
||||
$sql .= " SET duree = ".$total_duration;
|
||||
@@ -1674,8 +1641,7 @@ class FichinterLigne extends CommonObjectLine
|
||||
|
||||
dol_syslog("FichinterLigne::update_total", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
} else {
|
||||
@@ -1703,8 +1669,7 @@ class FichinterLigne extends CommonObjectLine
|
||||
|
||||
$error = 0;
|
||||
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
if ($this->statut == 0) {
|
||||
dol_syslog(get_class($this)."::deleteline lineid=".$this->id);
|
||||
$this->db->begin();
|
||||
|
||||
@@ -1718,16 +1683,15 @@ class FichinterLigne extends CommonObjectLine
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet WHERE rowid = ".$this->id;
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$result = $this->update_total();
|
||||
if ($result > 0)
|
||||
{
|
||||
if (!$notrigger)
|
||||
{
|
||||
if ($result > 0) {
|
||||
if (!$notrigger) {
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('LINEFICHINTER_DELETE', $user);
|
||||
if ($result < 0) { $error++; $this->db->rollback(); return -1; }
|
||||
if ($result < 0) {
|
||||
$error++; $this->db->rollback(); return -1;
|
||||
}
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user