/** * Migrate file from old path to new one for product $product * * @param Product $product Object product * @return void */ function migrate_product_photospath($product) { global $conf; $dir = $conf->product->multidir_output[$product->entity]; $origin = $dir . '/' . get_exdir($product->id, 2) . $product->id . "/photos"; $destin = $dir . '/' . dol_sanitizeFileName($product->ref); $error = 0; $origin_osencoded = dol_osencode($origin); $destin_osencoded = dol_osencode($destin); dol_mkdir($destin); if (dol_is_dir($origin)) { $handle = opendir($origin_osencoded); if (is_resource($handle)) { while (($file = readdir($handle)) != false) { if ($file != '.' && $file != '..' && is_dir($origin_osencoded . '/' . $file)) { $thumbs = opendir($origin_osencoded . '/' . $file); if (is_resource($thumbs)) { dol_mkdir($destin . '/' . $file); while (($thumb = readdir($thumbs)) != false) { dol_move($origin . '/' . $file . '/' . $thumb, $destin . '/' . $file . '/' . $thumb); } // dol_delete_dir($origin.'/'.$file); } } else { if (dol_is_file($origin . '/' . $file)) { dol_move($origin . '/' . $file, $destin . '/' . $file); } } } } } }
/** * Update a record into database * * @param int $id Id of product * @param User $user Object user making update * @param int $notrigger Disable triggers * @return int 1 if OK, -1 if ref already exists, -2 if other error */ function update($id, $user, $notrigger=false) { global $langs, $conf; $error=0; $this->db->begin(); // Verification parametres if (! $this->libelle) $this->libelle = 'MISSING LABEL'; // Clean parameters $this->ref = dol_string_nospecial(trim($this->ref)); $this->libelle = trim($this->libelle); $this->description = trim($this->description); $this->note = trim($this->note); $this->weight = price2num($this->weight); $this->weight_units = trim($this->weight_units); $this->length = price2num($this->length); $this->length_units = trim($this->length_units); $this->surface = price2num($this->surface); $this->surface_units = trim($this->surface_units); $this->volume = price2num($this->volume); $this->volume_units = trim($this->volume_units); if (empty($this->tva_tx)) $this->tva_tx = 0; if (empty($this->tva_npr)) $this->tva_npr = 0; //Local taxes if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; if (empty($this->finished)) $this->finished = 0; if (empty($this->country_id)) $this->country_id = 0; $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell= trim($this->accountancy_code_sell); $sql = "UPDATE ".MAIN_DB_PREFIX."product"; $sql.= " SET label = '" . $this->db->escape($this->libelle) ."'"; $sql.= ",ref = '" . $this->ref ."'"; $sql.= ",tva_tx = " . $this->tva_tx; $sql.= ",recuperableonly = " . $this->tva_npr; //Local taxes $sql.= ",localtax1_tx = " . $this->localtax1_tx; $sql.= ",localtax2_tx = " . $this->localtax2_tx; $sql.= ",tosell = " . $this->status; $sql.= ",tobuy = " . $this->status_buy; $sql.= ",finished = " . ($this->finished<0 ? "null" : $this->finished); $sql.= ",weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null'); $sql.= ",weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null'); $sql.= ",length = " . ($this->length!='' ? "'".$this->length."'" : 'null'); $sql.= ",length_units = " . ($this->length_units!='' ? "'".$this->length_units."'" : 'null'); $sql.= ",surface = " . ($this->surface!='' ? "'".$this->surface."'" : 'null'); $sql.= ",surface_units = " . ($this->surface_units!='' ? "'".$this->surface_units."'" : 'null'); $sql.= ",volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null'); $sql.= ",volume_units = " . ($this->volume_units!='' ? "'".$this->volume_units."'" : 'null'); $sql.= ",seuil_stock_alerte = " . ((isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '') ? "'".$this->seuil_stock_alerte."'" : "null"); $sql.= ",description = '" . $this->db->escape($this->description) ."'"; $sql.= ",customcode = '" . $this->db->escape($this->customcode) ."'"; $sql.= ",fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null'); $sql.= ",note = '" . $this->db->escape($this->note) ."'"; $sql.= ",duration = '" . $this->duration_value . $this->duration_unit ."'"; $sql.= ",accountancy_code_buy = '" . $this->accountancy_code_buy."'"; $sql.= ",accountancy_code_sell= '" . $this->accountancy_code_sell."'"; $sql.= " WHERE rowid = " . $id; dol_syslog(get_class($this)."update sql=".$sql); $resql=$this->db->query($sql); if ($resql) { $this->id = $id; // Multilangs if($conf->global->MAIN_MULTILANGS) { if ( $this->setMultiLangs() < 0) { $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; return -2; } } // Actions on extra fields (by external module or standard code) include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); $hookmanager=new HookManager($this->db); $hookmanager->initHooks(array('productdao')); $parameters=array('id'=>$this->id); $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { $result=$this->insertExtraFields(); if ($result < 0) { $error++; } } else if ($reshook < 0) $error++; if (! $error && ! $notrigger) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); $result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) { // We remove directory if ($conf->product->dir_output) { $olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); $newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref); if (file_exists($olddir)) { $res=@dol_move($olddir, $newdir); if (! $res) { $this->error='ErrorFailToMoveDir'; $error++; } } } } if (! $error) { $this->db->commit(); return 1; } else { $this->db->rollback(); return -$error; } } else { if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref); return -1; } else { $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; return -2; } } }
/** * Update a record into database * * @param int $id Id of product * @param User $user Object user making update * @param int $notrigger Disable triggers * @param string $action Current action for hookmanager ('add' or 'update') * @return int 1 if OK, -1 if ref already exists, -2 if other error */ function update($id, $user, $notrigger = false, $action = 'update') { global $langs, $conf, $hookmanager; $error = 0; // Check parameters if (!$this->label) { $this->label = 'MISSING LABEL'; } // Clean parameters $this->ref = dol_string_nospecial(trim($this->ref)); $this->label = trim($this->label); $this->description = trim($this->description); $this->note = isset($this->note) ? trim($this->note) : null; $this->weight = price2num($this->weight); $this->weight_units = trim($this->weight_units); $this->length = price2num($this->length); $this->length_units = trim($this->length_units); $this->surface = price2num($this->surface); $this->surface_units = trim($this->surface_units); $this->volume = price2num($this->volume); $this->volume_units = trim($this->volume_units); if (empty($this->tva_tx)) { $this->tva_tx = 0; } if (empty($this->tva_npr)) { $this->tva_npr = 0; } if (empty($this->localtax1_tx)) { $this->localtax1_tx = 0; } if (empty($this->localtax2_tx)) { $this->localtax2_tx = 0; } if (empty($this->status)) { $this->status = 0; } if (empty($this->status_buy)) { $this->status_buy = 0; } if (empty($this->country_id)) { $this->country_id = 0; } // Barcode value $this->barcode = trim($this->barcode); $this->accountancy_code_buy = trim($this->accountancy_code_buy); $this->accountancy_code_sell = trim($this->accountancy_code_sell); $this->db->begin(); // Check name is required and codes are ok or unique. // If error, this->errors[] is filled if ($action != 'add') { $result = $this->verify(); // We don't check when update called during a create because verify was already done } if ($result >= 0) { if (empty($this->oldcopy)) { $org = new self($this->db); $org->fetch($this->id); $this->oldcopy = $org; } // test if batch management is activated on existing product if ($this->hasbatch() && !$this->oldcopy->hasbatch()) { $this->load_stock(); foreach ($this->stock_warehouse as $idW => $ObjW) { $qty_batch = 0; foreach ($ObjW->detail_batch as $detail) { $qty_batch += $detail->qty; } // Quantities in batch details are not same same as stock quantity // So we add a default batch record if ($ObjW->real != $qty_batch) { $ObjBatch = new Productbatch($this->db); $ObjBatch->batch = $langs->trans('BatchDefaultNumber'); $ObjBatch->qty = $ObjW->real - $qty_batch; $ObjBatch->fk_product_stock = $ObjW->id; if ($ObjBatch->create($user, 1) < 0) { $error++; $this->errors = $ObjBatch->errors; } } } } // For automatic creation if ($this->barcode == -1) { $this->barcode = $this->get_barcode($this, $this->barcode_type_code); } $sql = "UPDATE " . MAIN_DB_PREFIX . "product"; $sql .= " SET label = '" . $this->db->escape($this->label) . "'"; $sql .= ", ref = '" . $this->db->escape($this->ref) . "'"; $sql .= ", ref_ext = " . (!empty($this->ref_ext) ? "'" . $this->db->escape($this->ref_ext) . "'" : "null"); $sql .= ", tva_tx = " . $this->tva_tx; $sql .= ", recuperableonly = " . $this->tva_npr; $sql .= ", localtax1_tx = " . $this->localtax1_tx; $sql .= ", localtax2_tx = " . $this->localtax2_tx; $sql .= ", barcode = " . (empty($this->barcode) ? "null" : "'" . $this->db->escape($this->barcode) . "'"); $sql .= ", fk_barcode_type = " . (empty($this->barcode_type) ? "null" : $this->db->escape($this->barcode_type)); $sql .= ", tosell = " . $this->status; $sql .= ", tobuy = " . $this->status_buy; $sql .= ", tobatch = " . (empty($this->status_batch) || $this->status_batch < 0 ? '0' : $this->status_batch); $sql .= ", finished = " . (!isset($this->finished) || $this->finished < 0 ? "null" : (int) $this->finished); $sql .= ", weight = " . ($this->weight != '' ? "'" . $this->weight . "'" : 'null'); $sql .= ", weight_units = " . ($this->weight_units != '' ? "'" . $this->weight_units . "'" : 'null'); $sql .= ", length = " . ($this->length != '' ? "'" . $this->length . "'" : 'null'); $sql .= ", length_units = " . ($this->length_units != '' ? "'" . $this->length_units . "'" : 'null'); $sql .= ", surface = " . ($this->surface != '' ? "'" . $this->surface . "'" : 'null'); $sql .= ", surface_units = " . ($this->surface_units != '' ? "'" . $this->surface_units . "'" : 'null'); $sql .= ", volume = " . ($this->volume != '' ? "'" . $this->volume . "'" : 'null'); $sql .= ", volume_units = " . ($this->volume_units != '' ? "'" . $this->volume_units . "'" : 'null'); $sql .= ", seuil_stock_alerte = " . (isset($this->seuil_stock_alerte) && $this->seuil_stock_alerte != '' ? "'" . $this->seuil_stock_alerte . "'" : "null"); $sql .= ", description = '" . $this->db->escape($this->description) . "'"; $sql .= ", url = " . ($this->url ? "'" . $this->db->escape($this->url) . "'" : 'null'); $sql .= ", customcode = '" . $this->db->escape($this->customcode) . "'"; $sql .= ", fk_country = " . ($this->country_id > 0 ? $this->country_id : 'null'); $sql .= ", note = " . (isset($this->note) ? "'" . $this->db->escape($this->note) . "'" : 'null'); $sql .= ", duration = '" . $this->db->escape($this->duration_value . $this->duration_unit) . "'"; $sql .= ", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) . "'"; $sql .= ", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) . "'"; $sql .= ", desiredstock = " . (isset($this->desiredstock) && $this->desiredstock != '' ? $this->desiredstock : "null"); $sql .= ", fk_unit= " . (!$this->fk_unit ? 'NULL' : $this->fk_unit); $sql .= " WHERE rowid = " . $id; dol_syslog(get_class($this) . "::update", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $this->id = $id; // Multilangs if (!empty($conf->global->MAIN_MULTILANGS)) { if ($this->setMultiLangs() < 0) { $this->error = $langs->trans("Error") . " : " . $this->db->error() . " - " . $sql; return -2; } } $action = 'update'; // Actions on extra fields (by external module or standard code) $hookmanager->initHooks(array('productdao')); $parameters = array('id' => $this->id); $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } } else { if ($reshook < 0) { $error++; } } if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('PRODUCT_MODIFY', $user); if ($result < 0) { $error++; } // End call triggers } if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) { // We remove directory if ($conf->product->dir_output) { $olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); $newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref); if (file_exists($olddir)) { include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $res = dol_move($olddir, $newdir); if (!$res) { $this->error = 'ErrorFailToMoveDir'; $error++; } } } } if (!$error) { $this->db->commit(); return 1; } else { $this->db->rollback(); return -$error; } } else { if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { if (empty($conf->barcode->enabled)) { $this->error = $langs->trans("Error") . " : " . $langs->trans("ErrorProductAlreadyExists", $this->ref); } else { $this->error = $langs->trans("Error") . " : " . $langs->trans("ErrorProductBarCodeAlreadyExists", $this->barcode); } $this->db->rollback(); return -1; } else { $this->error = $langs->trans("Error") . " : " . $this->db->error() . " - " . $sql; $this->db->rollback(); return -2; } } } else { $this->db->rollback(); dol_syslog(get_class($this) . "::Update fails verify " . join(',', $this->errors), LOG_WARNING); return -3; } }
/** * Update a project * * @param User $user User object of making update * @param int $notrigger 1=Disable all triggers * @return int */ function update($user, $notrigger = 0) { global $langs, $conf; $error = 0; // Clean parameters $this->title = trim($this->title); $this->description = trim($this->description); if (dol_strlen(trim($this->ref)) > 0) { $this->db->begin(); $sql = "UPDATE " . MAIN_DB_PREFIX . "projet SET"; $sql .= " ref='" . $this->db->escape($this->ref) . "'"; $sql .= ", title = '" . $this->db->escape($this->title) . "'"; $sql .= ", description = '" . $this->db->escape($this->description) . "'"; $sql .= ", fk_soc = " . ($this->socid > 0 ? $this->socid : "null"); $sql .= ", fk_statut = " . $this->statut; $sql .= ", public = " . ($this->public ? 1 : 0); $sql .= ", datec=" . ($this->date_c != '' ? "'" . $this->db->idate($this->date_c) . "'" : 'null'); $sql .= ", dateo=" . ($this->date_start != '' ? "'" . $this->db->idate($this->date_start) . "'" : 'null'); $sql .= ", datee=" . ($this->date_end != '' ? "'" . $this->db->idate($this->date_end) . "'" : 'null'); $sql .= " WHERE rowid = " . $this->id; dol_syslog(get_class($this) . "::Update", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { if (!$notrigger) { // Call trigger $result = $this->call_trigger('PROJECT_MODIFY', $user); if ($result < 0) { $error++; } // End call triggers } //Update extrafield if (!$error) { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { $result = $this->insertExtraFields(); if ($result < 0) { $error++; } } } if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) { // We remove directory if ($conf->projet->dir_output) { $olddir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); $newdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($this->ref); if (file_exists($olddir)) { include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; $res = dol_move($olddir, $newdir); if (!$res) { $this->error = 'ErrorFailToMoveDir'; $error++; } } } } if (!$error) { $this->db->commit(); $result = 1; } else { $this->db->rollback(); $result = -1; } } else { $this->error = $this->db->lasterror(); $this->errors[] = $this->error; $this->db->rollback(); dol_syslog(get_class($this) . "::Update error -2 " . $this->error, LOG_ERR); $result = -2; } } else { dol_syslog(get_class($this) . "::Update ref null"); $result = -1; } return $result; }
/** * Export events from database into a cal file. * * @param string $format 'vcal', 'ical/ics', 'rss' * @param string $type 'event' or 'journal' * @param int $cachedelay Do not rebuild file if date older than cachedelay seconds * @param string $filename Force filename * @param array $filters Array of filters * @return int <0 if error, nb of events in new file if ok */ function build_exportfile($format, $type, $cachedelay, $filename, $filters) { global $conf, $langs, $dolibarr_main_url_root, $mysoc; require_once DOL_DOCUMENT_ROOT . "/core/lib/xcal.lib.php"; require_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php"; require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php"; dol_syslog(get_class($this) . "::build_exportfile Build export file format=" . $format . ", type=" . $type . ", cachedelay=" . $cachedelay . ", filename=" . $filename . ", filters size=" . count($filters), LOG_DEBUG); // Check parameters if (empty($format)) { return -1; } // Clean parameters if (!$filename) { $extension = 'vcs'; if ($format == 'ical') { $extension = 'ics'; } $filename = $format . '.' . $extension; } // Create dir and define output file (definitive and temporary) $result = dol_mkdir($conf->agenda->dir_temp); $outputfile = $conf->agenda->dir_temp . '/' . $filename; $result = 0; $buildfile = true; $login = ''; $logina = ''; $logind = ''; $logint = ''; $now = dol_now(); if ($cachedelay) { $nowgmt = dol_now(); include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; if (dol_filemtime($outputfile) > $nowgmt - $cachedelay) { dol_syslog(get_class($this) . "::build_exportfile file " . $outputfile . " is not older than now - cachedelay (" . $nowgmt . " - " . $cachedelay . "). Build is canceled"); $buildfile = false; } } if ($buildfile) { // Build event array $eventarray = array(); $sql = "SELECT a.id,"; $sql .= " a.datep,"; // Start $sql .= " a.datep2,"; // End $sql .= " a.durationp,"; // deprecated $sql .= " a.datec, a.tms as datem,"; $sql .= " a.label, a.code, a.note, a.fk_action as type_id,"; $sql .= " a.fk_soc,"; $sql .= " a.fk_user_author, a.fk_user_mod,"; $sql .= " a.fk_user_action,"; $sql .= " a.fk_contact, a.percent as percentage,"; $sql .= " a.fk_element, a.elementtype,"; $sql .= " a.priority, a.fulldayevent, a.location, a.punctual, a.transparency,"; $sql .= " u.firstname, u.lastname,"; $sql .= " s.nom as socname,"; $sql .= " c.id as type_id, c.code as type_code, c.libelle"; $sql .= " FROM (" . MAIN_DB_PREFIX . "c_actioncomm as c, " . MAIN_DB_PREFIX . "actioncomm as a)"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on u.rowid = a.fk_user_author"; // Link to get author of event for export $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s on s.rowid = a.fk_soc"; // We must filter on assignement table if ($filters['logint'] || $filters['login']) { $sql .= ", " . MAIN_DB_PREFIX . "actioncomm_resources as ar"; } $sql .= " WHERE a.fk_action=c.id"; $sql .= " AND a.entity IN (" . getEntity('actioncomm', 1) . ")"; foreach ($filters as $key => $value) { if ($key == 'notolderthan' && $value != '') { $sql .= " AND a.datep >= '" . $this->db->idate($now - $value * 24 * 60 * 60) . "'"; } if ($key == 'year') { $sql .= " AND a.datep BETWEEN '" . $this->db->idate(dol_get_first_day($value, 1)) . "' AND '" . $this->db->idate(dol_get_last_day($value, 12)) . "'"; } if ($key == 'id') { $sql .= " AND a.id=" . (is_numeric($value) ? $value : 0); } if ($key == 'idfrom') { $sql .= " AND a.id >= " . (is_numeric($value) ? $value : 0); } if ($key == 'idto') { $sql .= " AND a.id <= " . (is_numeric($value) ? $value : 0); } if ($key == 'project') { $sql .= " AND a.fk_project=" . (is_numeric($value) ? $value : 0); } // We must filter on assignement table if ($key == 'logint' || $key == 'login') { $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'"; } if ($key == 'logina') { $logina = $value; $userforfilter = new User($this->db); $result = $userforfilter->fetch('', $value); $sql .= " AND a.fk_user_author = " . $userforfilter->id; } if ($key == 'logint' || $key == 'login') { $logint = $value; $userforfilter = new User($this->db); $result = $userforfilter->fetch('', $value); $sql .= " AND ar.fk_element = " . $userforfilter->id; } } $sql .= " AND a.datep IS NOT NULL"; // To exclude corrupted events and avoid errors in lightning/sunbird import $sql .= " ORDER by datep"; //print $sql;exit; dol_syslog(get_class($this) . "::build_exportfile select events", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { // Note: Output of sql request is encoded in $conf->file->character_set_client // This assignment in condition is not a bug. It allows walking the results. while ($obj = $this->db->fetch_object($resql)) { $qualified = true; // 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author' $event = array(); $event['uid'] = 'dolibarragenda-' . $this->db->database_name . '-' . $obj->id . "@" . $_SERVER["SERVER_NAME"]; $event['type'] = $type; $datestart = $this->db->jdate($obj->datep) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : $conf->global->AGENDA_EXPORT_FIX_TZ * 3600); $dateend = $this->db->jdate($obj->datep2) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : $conf->global->AGENDA_EXPORT_FIX_TZ * 3600); $duration = $datestart && $dateend ? $dateend - $datestart : 0; $event['summary'] = $obj->label . ($obj->socname ? " (" . $obj->socname . ")" : ""); $event['desc'] = $obj->note; $event['startdate'] = $datestart; $event['enddate'] = $dateend; // Not required with type 'journal' $event['duration'] = $duration; // Not required with type 'journal' $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname); $event['priority'] = $obj->priority; $event['fulldayevent'] = $obj->fulldayevent; $event['location'] = $obj->location; $event['transparency'] = $obj->transparency > 0 ? 'OPAQUE' : 'TRANSPARENT'; // OPAQUE (busy) or TRANSPARENT (not busy) $event['punctual'] = $obj->punctual; $event['category'] = $obj->libelle; // libelle type action // Define $urlwithroot $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root)); $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current $url = $urlwithroot . '/comm/action/card.php?id=' . $obj->id; $event['url'] = $url; $event['created'] = $this->db->jdate($obj->datec) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : $conf->global->AGENDA_EXPORT_FIX_TZ * 3600); $event['modified'] = $this->db->jdate($obj->datem) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : $conf->global->AGENDA_EXPORT_FIX_TZ * 3600); if ($qualified && $datestart) { $eventarray[$datestart] = $event; } } } else { $this->error = $this->db->lasterror(); return -1; } $langs->load("agenda"); // Define title and desc $more = ''; if ($login) { $more = $langs->transnoentities("User") . ' ' . $login; } if ($logina) { $more = $langs->transnoentities("ActionsAskedBy") . ' ' . $logina; } if ($logint) { $more = $langs->transnoentities("ActionsToDoBy") . ' ' . $logint; } if ($logind) { $more = $langs->transnoentities("ActionsDoneBy") . ' ' . $logind; } if ($more) { $title = 'Dolibarr actions ' . $mysoc->name . ' - ' . $more; $desc = $more; $desc .= ' (' . $mysoc->name . ' - built by Dolibarr)'; } else { $title = 'Dolibarr actions ' . $mysoc->name; $desc = $langs->transnoentities('ListOfActions'); $desc .= ' (' . $mysoc->name . ' - built by Dolibarr)'; } // Create temp file $outputfiletmp = tempnam($conf->agenda->dir_temp, 'tmp'); // Temporary file (allow call of function by different threads @chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK)); // Write file if ($format == 'vcal') { $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp); } if ($format == 'ical') { $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp); } if ($format == 'rss') { $result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp); } if ($result >= 0) { if (dol_move($outputfiletmp, $outputfile, 0, 1)) { $result = 1; } else { $this->error = 'Failed to rename ' . $outputfiletmp . ' into ' . $outputfile; dol_syslog(get_class($this) . "::build_exportfile " . $this->error, LOG_ERR); dol_delete_file($outputfiletmp, 0, 1); $result = -1; } } else { dol_syslog(get_class($this) . "::build_exportfile build_xxxfile function fails to for format=" . $format . " outputfiletmp=" . $outputfile, LOG_ERR); dol_delete_file($outputfiletmp, 0, 1); $langs->load("errors"); $this->error = $langs->trans("ErrorFailToCreateFile", $outputfile); } } return $result; }
$oldlabel=GETPOST('urlfile'); $newlabel=GETPOST('label'); //$db->begin(); $olddir=$ecmdir->getRelativePath(0); $olddir=$conf->ecm->dir_output.'/'.$olddir; $newdir=$olddir; $oldfile=$olddir.$oldlabel; $newfile=$newdir.$newlabel; //print $oldfile.' - '.$newfile; if ($newlabel != $oldlabel) { $result=dol_move($oldfile,$newfile); if (! $result) { $langs->load('errors'); $mesg='<div class="error">'.$langs->trans('ErrorFailToRenameFile',$oldfile,$newfile).'</div>'; $error++; } } if (! $error) { //$db->commit(); $urlfile=$newlabel; } else {
/** * testDolCopyMove * * @return int */ public function testDolCopyMove() { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $file=dirname(__FILE__).'/Example_import_company_1.csv'; $result=dol_copy($file, '/adir/that/does/not/exists/file.csv'); print __METHOD__." result=".$result."\n"; $this->assertLessThan(0,$result); // We should have error $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,1); print __METHOD__." result=".$result."\n"; $this->assertGreaterThanOrEqual(1,$result); // Should be 1 // Again to test with overwriting=0 $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,0); print __METHOD__." result=".$result."\n"; $this->assertEquals(0,$result); // Should be 0 // Again to test with overwriting=1 $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv',0,1); print __METHOD__." result=".$result."\n"; $this->assertGreaterThanOrEqual(1,$result); // Should be 1 // Again to test with overwriting=1 $result=dol_move($conf->admin->dir_temp.'/file.csv',$conf->admin->dir_temp.'/file2.csv',0,1); print __METHOD__." result=".$result."\n"; $this->assertTrue($result); $result=dol_delete_file($conf->admin->dir_temp.'/file2.csv'); print __METHOD__." result=".$result."\n"; $this->assertTrue($result); // Again to test no erreor when deleteing a non existing file $result=dol_delete_file($conf->admin->dir_temp.'/file2.csv'); print __METHOD__." result=".$result."\n"; $this->assertTrue($result); }
/** * Update a project * * @param User $user User object of making update * @param int $notrigger 1=Disable all triggers * @return int */ function update($user, $notrigger=0) { global $langs, $conf; $error=0; // Clean parameters $this->title = trim($this->title); $this->description = trim($this->description); if (dol_strlen(trim($this->ref)) > 0) { $sql = "UPDATE " . MAIN_DB_PREFIX . "projet SET"; $sql.= " ref='" . $this->ref . "'"; $sql.= ", title = '" . $this->db->escape($this->title) . "'"; $sql.= ", description = '" . $this->db->escape($this->description) . "'"; $sql.= ", fk_soc = " . ($this->socid > 0 ? $this->socid : "null"); $sql.= ", fk_statut = " . $this->statut; $sql.= ", public = " . ($this->public ? 1 : 0); $sql.= ", datec=" . ($this->date_c != '' ? $this->db->idate($this->date_c) : 'null'); $sql.= ", dateo=" . ($this->date_start != '' ? $this->db->idate($this->date_start) : 'null'); $sql.= ", datee=" . ($this->date_end != '' ? $this->db->idate($this->date_end) : 'null'); $sql.= " WHERE rowid = " . $this->id; dol_syslog(get_class($this)."::Update sql=" . $sql, LOG_DEBUG); if ($this->db->query($sql)) { if (!$notrigger) { // Call triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface = new Interfaces($this->db); $result = $interface->run_triggers('PROJECT_MODIFY', $this, $user, $langs, $conf); if ($result < 0) { $error++; $this->errors = $interface->errors; } // End call triggers } if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) { // We remove directory if ($conf->projet->dir_output) { $olddir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); $newdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($this->ref); if (file_exists($olddir)) { $res=@dol_move($olddir, $newdir); if (! $res) { $this->error='ErrorFailToMoveDir'; $error++; } } } } $result = 1; } else { $this->error = $this->db->lasterror(); dol_syslog(get_class($this)."::Update error -2 " . $this->error, LOG_ERR); $result = -2; } } else { dol_syslog(get_class($this)."::Update ref null"); $result = -1; } return $result; }