コード例 #1
0
ファイル: project.class.php プロジェクト: remyyounes/dolibarr
	/**
	 *    Delete a project from database
	 *    @param       user            User
	 *    @param       notrigger       Disable triggers
     *    @return      int             <0 if KO, 0 if not possible, >0 if OK
	 */
	function delete($user, $notrigger=0)
	{
		global $langs,$conf;
        require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");

		$error=0;

		$this->db->begin();

		if (! $error)
		{
			// Delete linked contacts
			$res = $this->delete_linked_contact();
			if ($res < 0)
			{
				$this->error='ErrorFailToDeleteLinkedContact';
				//$error++;
				$this->db->rollback();
				return 0;
			}
		}

        $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task";
        $sql.= " WHERE fk_projet=".$this->id;

        dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
        $resql = $this->db->query($sql);

        $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet";
		$sql.= " WHERE rowid=".$this->id;

		dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG);
		$resql = $this->db->query($sql);
		if ($resql)
		{
			// We remove directory
			$projectref = dol_sanitizeFileName($this->ref);
			if ($conf->projet->dir_output)
			{
				$dir = $conf->projet->dir_output . "/" . $projectref ;
				$file = $conf->projet->dir_output . "/" . $projectref . "/" . $projectref . ".pdf";
				if (file_exists($file))
				{
					//project_delete_preview($this->db, $this->id, $this->ref);

					if (!dol_delete_file($file))
					{
						$this->error='ErrorFailToDeleteFile';
						$this->db->rollback();
						return 0;
					}
				}
				if (file_exists($dir))
				{
					$res=@dol_delete_dir($dir);
					if (! $res)
					{
						$this->error='ErrorFailToDeleteDir';
						$this->db->rollback();
						return 0;
					}
				}
			}

			if (! $notrigger)
			{
	            // Call triggers
	            include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
	            $interface=new Interfaces($this->db);
	            $result=$interface->run_triggers('PROJECT_DELETE',$this,$user,$langs,$conf);
	            if ($result < 0) { $error++; $this->errors=$interface->errors; }
	            // End call triggers
			}

			dol_syslog("Project::delete sql=".$sql, LOG_DEBUG);
			$this->db->commit();
			return 1;
		}
		else
		{
			$this->error=$this->db->lasterror();
			dol_syslog("Project::delete ".$this->error, LOG_ERR);
			$this->db->rollback();
			return -1;
		}
	}
コード例 #2
0
ファイル: repair.php プロジェクト: NoisyBoy86/Dolibarr_test
                    preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1];
                }

                if ($id || $ref)
                {
                    //print 'Fetch '.$id.' or '.$ref.'<br>';
                    $result=$object_instance->fetch($id,$ref);
                    //print $result.'<br>';
                    if ($result == 0)    // Not found but no error
                    {
                        // Clean of orphelins directories are done into repair.php
                        print '<tr><td colspan="2">';
                        print 'Delete orphelins file '.$file['fullname'].'<br>';
                        if (GETPOST('purge') == 2)
                        {
                            dol_delete_file($file['fullname'],1,1,1);
                            dol_delete_dir(dirname($file['fullname']),1);
                        }
                        print "</td></tr>";
                    }
                    else if ($result < 0) print 'Error in '.get_class($object_instance).'.fetch of id'.$id.' ref='.$ref.', result='.$result.'<br>';
                }
            }
        }
    }
}

print '</table>';


コード例 #3
0
    if (GETPOST('confirm') == 'yes') {
        $langs->load("other");
        if ($section) {
            $result = $ecmdir->fetch($section);
            if (!($result > 0)) {
                dol_print_error($db, $ecmdir->error);
                exit;
            }
            $relativepath = $ecmdir->getRelativePath();
        } else {
            $relativepath = '';
        }
        $upload_dir = $conf->ecm->dir_output . ($relativepath ? '/' . $relativepath : '');
        $file = $upload_dir . "/" . GETPOST('urlfile');
        // Do not use urldecode here ($_GET and $_POST are already decoded by PHP).
        $ret = dol_delete_file($file);
        if ($ret) {
            setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
        } else {
            setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
        }
        $result = $ecmdir->changeNbOfFiles('-');
        clearstatcache();
    }
    $action = 'file_manager';
}
// Remove directory
if ($action == 'confirm_deletesection' && GETPOST('confirm') == 'yes') {
    $result = $ecmdir->delete($user);
    setEventMessage($langs->trans("ECMSectionWasRemoved", $ecmdir->label));
    clearstatcache();
コード例 #4
0
ファイル: facture.class.php プロジェクト: nrjacker4/crm-php
 /**
  * Tag invoice as validated + call trigger BILL_VALIDATE
  * Object must have lines loaded with fetch_lines
  *
  * @param	User	$user           Object user that validate
  * @param   string	$force_number	Reference to force on invoice
  * @param	int		$idwarehouse	Id of warehouse to use for stock decrease
  * @return	int						<0 if KO, >0 if OK
  */
 function validate($user, $force_number = '', $idwarehouse = 0)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php";
     $now = dol_now();
     $error = 0;
     dol_syslog(get_class($this) . '::validate user='******', force_number=' . $force_number . ', idwarehouse=' . $idwarehouse, LOG_WARNING);
     // Check parameters
     if (!$this->brouillon) {
         dol_syslog(get_class($this) . "::validate no draft status", LOG_WARNING);
         return 0;
     }
     if (!$user->rights->facture->valider) {
         $this->error = 'Permission denied';
         dol_syslog(get_class($this) . "::validate " . $this->error, LOG_ERR);
         return -1;
     }
     $this->db->begin();
     $this->fetch_thirdparty();
     $this->fetch_lines();
     // Check parameters
     if ($this->type == 1) {
         // Controle que facture source connue
         if ($this->fk_facture_source <= 0) {
             $this->error = $langs->trans("ErrorFieldRequired", $langs->trans("InvoiceReplacement"));
             $this->db->rollback();
             return -10;
         }
         // Charge la facture source a remplacer
         $facreplaced = new Facture($this->db);
         $result = $facreplaced->fetch($this->fk_facture_source);
         if ($result <= 0) {
             $this->error = $langs->trans("ErrorBadInvoice");
             $this->db->rollback();
             return -11;
         }
         // Controle que facture source non deja remplacee par une autre
         $idreplacement = $facreplaced->getIdReplacingInvoice('validated');
         if ($idreplacement && $idreplacement != $this->id) {
             $facreplacement = new Facture($this->db);
             $facreplacement->fetch($idreplacement);
             $this->error = $langs->trans("ErrorInvoiceAlreadyReplaced", $facreplaced->ref, $facreplacement->ref);
             $this->db->rollback();
             return -12;
         }
         $result = $facreplaced->set_canceled($user, 'replaced', '');
         if ($result < 0) {
             $this->error = $facreplaced->error;
             $this->db->rollback();
             return -13;
         }
     }
     // Define new ref
     if ($force_number) {
         $num = $force_number;
     } else {
         if (preg_match('/^[\\(]?PROV/i', $this->ref)) {
             if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
                 $this->date = dol_now();
                 $this->date_lim_reglement = $this->calculate_date_lim_reglement();
             }
             $num = $this->getNextNumRef($this->client);
         } else {
             $num = $this->ref;
         }
     }
     if ($num) {
         $this->update_price(1);
         // Validate
         $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture';
         $sql .= " SET facnumber='" . $num . "', fk_statut = 1, fk_user_valid = " . $user->id . ", date_valid = '" . $this->db->idate($now) . "'";
         if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
             $sql .= ', datef=' . $this->db->idate($this->date);
             $sql .= ', date_lim_reglement=' . $this->db->idate($this->date_lim_reglement);
         }
         $sql .= ' WHERE rowid = ' . $this->id;
         dol_syslog(get_class($this) . "::validate sql=" . $sql);
         $resql = $this->db->query($sql);
         if (!$resql) {
             dol_syslog(get_class($this) . "::validate Echec update - 10 - sql=" . $sql, LOG_ERR);
             dol_print_error($this->db);
             $error++;
         }
         // On verifie si la facture etait une provisoire
         if (!$error && preg_match('/^[\\(]?PROV/i', $this->ref)) {
             // La verif qu'une remise n'est pas utilisee 2 fois est faite au moment de l'insertion de ligne
         }
         if (!$error) {
             // Define third party as a customer
             $result = $this->client->set_as_client();
             // Si active on decremente le produit principal et ses composants a la validation de facture
             if ($this->type != 3 && $result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL) {
                 require_once DOL_DOCUMENT_ROOT . "/product/stock/class/mouvementstock.class.php";
                 $langs->load("agenda");
                 // Loop on each line
                 $cpt = count($this->lines);
                 for ($i = 0; $i < $cpt; $i++) {
                     if ($this->lines[$i]->fk_product > 0) {
                         $mouvP = new MouvementStock($this->db);
                         // We decrease stock for product
                         if ($this->type == 2) {
                             $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr", $num));
                         } else {
                             $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr", $num));
                         }
                         if ($result < 0) {
                             $error++;
                         }
                     }
                 }
             }
         }
         if (!$error) {
             $this->oldref = '';
             // Rename directory if dir was a temporary ref
             if (preg_match('/^[\\(]?PROV/i', $this->ref)) {
                 // On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref)
                 // afin de ne pas perdre les fichiers attaches
                 $facref = dol_sanitizeFileName($this->ref);
                 $snumfa = dol_sanitizeFileName($num);
                 $dirsource = $conf->facture->dir_output . '/' . $facref;
                 $dirdest = $conf->facture->dir_output . '/' . $snumfa;
                 if (file_exists($dirsource)) {
                     dol_syslog(get_class($this) . "::validate rename dir " . $dirsource . " into " . $dirdest);
                     if (@rename($dirsource, $dirdest)) {
                         $this->oldref = $facref;
                         dol_syslog("Rename ok");
                         // Suppression ancien fichier PDF dans nouveau rep
                         dol_delete_file($conf->facture->dir_output . '/' . $snumfa . '/' . $facref . '.*');
                     }
                 }
             }
         }
         // Set new ref and define current statut
         if (!$error) {
             $this->ref = $num;
             $this->facnumber = $num;
             $this->statut = 1;
             $this->date_validation = $now;
         }
         // Trigger calls
         if (!$error) {
             // Appel des triggers
             include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
             $interface = new Interfaces($this->db);
             $result = $interface->run_triggers('BILL_VALIDATE', $this, $user, $langs, $conf);
             if ($result < 0) {
                 $error++;
                 $this->errors = $interface->errors;
             }
             // Fin appel triggers
         }
     } else {
         $error++;
     }
     if (!$error) {
         $this->db->commit();
         return 1;
     } else {
         $this->db->rollback();
         $this->error = $this->db->lasterror();
         return -1;
     }
 }
コード例 #5
0
ファイル: facture.class.php プロジェクト: Samara94/dolibarr
 /**
  *	Delete invoice
  *
  *	@param     	int		$rowid      	Id of invoice to delete. If empty, we delete current instance of invoice
  *	@param		int		$notrigger		1=Does not execute triggers, 0= execute triggers
  *	@param		int		$idwarehouse	Id warehouse to use for stock change.
  *	@return		int						<0 if KO, >0 if OK
  */
 function delete($rowid = 0, $notrigger = 0, $idwarehouse = -1)
 {
     global $user, $langs, $conf;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     if (empty($rowid)) {
         $rowid = $this->id;
     }
     dol_syslog(get_class($this) . "::delete rowid=" . $rowid, LOG_DEBUG);
     // TODO Test if there is at least one payment. If yes, refuse to delete.
     $error = 0;
     $this->db->begin();
     if (!$error && !$notrigger) {
         // Call trigger
         $result = $this->call_trigger('BILL_DELETE', $user);
         if ($result < 0) {
             $error++;
         }
         // End call triggers
     }
     // Removed extrafields
     if (!$error) {
         $result = $this->deleteExtraFields();
         if ($result < 0) {
             $error++;
             dol_syslog(get_class($this) . "::delete error deleteExtraFields " . $this->error, LOG_ERR);
         }
     }
     if (!$error) {
         // Delete linked object
         $res = $this->deleteObjectLinked();
         if ($res < 0) {
             $error++;
         }
     }
     if (!$error) {
         // If invoice was converted into a discount not yet consumed, we remove discount
         $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'societe_remise_except';
         $sql .= ' WHERE fk_facture_source = ' . $rowid;
         $sql .= ' AND fk_facture_line IS NULL';
         $resql = $this->db->query($sql);
         // If invoice has consumned discounts
         $this->fetch_lines();
         $list_rowid_det = array();
         foreach ($this->lines as $key => $invoiceline) {
             $list_rowid_det[] = $invoiceline->rowid;
         }
         // Consumned discounts are freed
         if (count($list_rowid_det)) {
             $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'societe_remise_except';
             $sql .= ' SET fk_facture = NULL, fk_facture_line = NULL';
             $sql .= ' WHERE fk_facture_line IN (' . join(',', $list_rowid_det) . ')';
             dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
             if (!$this->db->query($sql)) {
                 $this->error = $this->db->error() . " sql=" . $sql;
                 $this->db->rollback();
                 return -5;
             }
         }
         // If we decrement stock on invoice validation, we increment
         if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse != -1) {
             require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
             $langs->load("agenda");
             $num = count($this->lines);
             for ($i = 0; $i < $num; $i++) {
                 if ($this->lines[$i]->fk_product > 0) {
                     $mouvP = new MouvementStock($this->db);
                     $mouvP->origin =& $this;
                     // We decrease stock for product
                     if ($this->type == self::TYPE_CREDIT_NOTE) {
                         $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceDeleteDolibarr", $this->ref));
                     } else {
                         $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceDeleteDolibarr", $this->ref));
                     }
                     // we use 0 for price, to not change the weighted average value
                 }
             }
         }
         // Delete invoice line
         $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'facturedet WHERE fk_facture = ' . $rowid;
         dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
         if ($this->db->query($sql) && $this->delete_linked_contact()) {
             $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'facture WHERE rowid = ' . $rowid;
             dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
             $resql = $this->db->query($sql);
             if ($resql) {
                 // On efface le repertoire de pdf provisoire
                 $ref = dol_sanitizeFileName($this->ref);
                 if ($conf->facture->dir_output && !empty($this->ref)) {
                     $dir = $conf->facture->dir_output . "/" . $ref;
                     $file = $conf->facture->dir_output . "/" . $ref . "/" . $ref . ".pdf";
                     if (file_exists($file)) {
                         $ret = dol_delete_preview($this);
                         if (!dol_delete_file($file, 0, 0, 0, $this)) {
                             $this->error = $langs->trans("ErrorCanNotDeleteFile", $file);
                             $this->db->rollback();
                             return 0;
                         }
                     }
                     if (file_exists($dir)) {
                         if (!dol_delete_dir_recursive($dir)) {
                             $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
                             $this->db->rollback();
                             return 0;
                         }
                     }
                 }
                 $this->db->commit();
                 return 1;
             } else {
                 $this->error = $this->db->lasterror() . " sql=" . $sql;
                 $this->db->rollback();
                 return -6;
             }
         } else {
             $this->error = $this->db->lasterror() . " sql=" . $sql;
             $this->db->rollback();
             return -4;
         }
     } else {
         $this->db->rollback();
         return -2;
     }
 }
コード例 #6
0
 /**
  *  Delete an order
  *
  *	@param	User	$user		Object user
  *	@return	int					<0 if KO, >0 if OK
  */
 function delete($user = '')
 {
     global $langs, $conf;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $error = 0;
     // Call trigger
     $result = $this->call_trigger('ORDER_SUPPLIER_DELETE', $user);
     if ($result < 0) {
         $this->errors[] = 'ErrorWhenRunningTrigger';
         dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
         return -1;
     }
     // End call triggers
     $this->db->begin();
     $sql = "DELETE FROM " . MAIN_DB_PREFIX . "commande_fournisseurdet WHERE fk_commande =" . $this->id;
     dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
     if (!$this->db->query($sql)) {
         $this->error = $this->db->lasterror();
         $this->errors[] = $this->db->lasterror();
         $error++;
     }
     $sql = "DELETE FROM " . MAIN_DB_PREFIX . "commande_fournisseur WHERE rowid =" . $this->id;
     dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
     if ($resql = $this->db->query($sql)) {
         if ($this->db->affected_rows($resql) < 1) {
             $this->error = $this->db->lasterror();
             $this->errors[] = $this->db->lasterror();
             $error++;
         }
     } else {
         $this->error = $this->db->lasterror();
         $this->errors[] = $this->db->lasterror();
         $error++;
     }
     // Remove extrafields
     if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
         $result = $this->deleteExtraFields();
         if ($result < 0) {
             $this->error = 'FailToDeleteExtraFields';
             $this->errors[] = 'FailToDeleteExtraFields';
             $error++;
             dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
         }
     }
     // Delete linked object
     $res = $this->deleteObjectLinked();
     if ($res < 0) {
         $this->error = 'FailToDeleteObjectLinked';
         $this->errors[] = 'FailToDeleteObjectLinked';
         $error++;
     }
     if (!$error) {
         // We remove directory
         $ref = dol_sanitizeFileName($this->ref);
         if ($conf->fournisseur->commande->dir_output) {
             $dir = $conf->fournisseur->commande->dir_output . "/" . $ref;
             $file = $dir . "/" . $ref . ".pdf";
             if (file_exists($file)) {
                 if (!dol_delete_file($file, 0, 0, 0, $this)) {
                     $this->error = 'ErrorFailToDeleteFile';
                     $this->errors[] = 'ErrorFailToDeleteFile';
                     $error++;
                 }
             }
             if (file_exists($dir)) {
                 $res = @dol_delete_dir_recursive($dir);
                 if (!$res) {
                     $this->error = 'ErrorFailToDeleteDir';
                     $this->errors[] = 'ErrorFailToDeleteDir';
                     $error++;
                 }
             }
         }
     }
     if (!$error) {
         dol_syslog(get_class($this) . "::delete {$this->id} by {$user->id}", LOG_DEBUG);
         $this->db->commit();
         return 1;
     } else {
         dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
         $this->db->rollback();
         return -$error;
     }
 }
コード例 #7
0
ファイル: fiche.php プロジェクト: ripasch/dolibarr
    $result = commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
    if ($result <= 0) {
        dol_print_error($db, $result);
        exit;
    } else {
        Header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (empty($conf->global->MAIN_JUMP_TAG) ? '' : '#builddoc'));
        exit;
    }
}
// Remove file in doc form
if ($action == 'remove_file') {
    if ($object->fetch($id)) {
        require_once DOL_DOCUMENT_ROOT . "/lib/files.lib.php";
        $upload_dir = $conf->commande->dir_output;
        $file = $upload_dir . '/' . $_GET['file'];
        dol_delete_file($file);
        $mesg = '<div class="ok">' . $langs->trans("FileWasRemoved") . '</div>';
    }
}
/*
 * Add file in email form
 */
if ($_POST['addfile']) {
    require_once DOL_DOCUMENT_ROOT . "/lib/files.lib.php";
    // Set tmp user directory TODO Use a dedicated directory for temp mails files
    $vardir = $conf->user->dir_output . "/" . $user->id;
    $upload_dir_tmp = $vardir . '/temp';
    $mesg = dol_add_file_process($upload_dir_tmp, 0, 0);
    $action = 'presend';
}
/*
コード例 #8
0
/**
 * Delete preview files, pour le cas de regeneration de commande
 * @param   $db		   data base object
 * @param   $comfournid  id de la commande a effacer
 * @param   $comfournref reference de la commande si besoin
 * @return  int
 */
function supplier_order_delete_preview($db, $comfournid, $comfournref='')
{
	global $langs,$conf;
    require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");

	if (!$comfournref)
	{
		$comfourn = new CommandeFournisseur($db,"",$comfournid);
		$comfourn->fetch($comfournid);
		$comfournref = $comfourn->ref;
		$soc = new Societe($db);
		$soc->fetch($comfourn->socid);
	}
	
	

	if ($conf->fournisseur->dir_output.'/commande')
	{
		$suppordref = dol_sanitizeFileName($comfournref);
		$dir = $conf->fournisseur->dir_output . "/" . $suppordref ;
		$file = $dir . "/" . $suppordref . ".pdf.png";
		$multiple = $file . ".";

		if ( file_exists( $file ) && is_writable( $file ) )
		{
			if ( ! dol_delete_file($file,1) )
			{
				$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
				return 0;
			}
		}
		else
		{
			for ($i = 0; $i < 20; $i++)
			{
				$preview = $multiple.$i;

				if ( file_exists( $preview ) && is_writable( $preview ) )
				{
					if ( ! dol_delete_file($preview,1) )
					{
						$this->error=$langs->trans("ErrorFailedToOpenFile",$preview);
						return 0;
					}
				}
			}
		}
	}

	return 1;
}
コード例 #9
0
	/**
	 *	Validate an order
	 *	@param		user		Utilisateur qui valide
	 */
	function valid($user)
	{
		global $langs,$conf;
		require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");

		$error=0;

		dol_syslog("CommandeFournisseur::Valid");
		$result = 0;
		if ($user->rights->fournisseur->commande->valider)
		{
			$this->db->begin();

			// Definition du nom de modele de numerotation de commande
			$soc = new Societe($this->db);
			$soc->fetch($this->fourn_id);

			// Check if object has a temporary ref
			if (preg_match('/^[\(]?PROV/i', $this->ref))
			{
				$num = $this->getNextNumRef($soc);
			}
			else
			{
				$num = $this->ref;
			}

			$sql = 'UPDATE '.MAIN_DB_PREFIX."commande_fournisseur";
			$sql.= " SET ref='".$num."'";
			$sql.= ", fk_statut = 1";
			$sql.= ", date_valid=".$this->db->idate(mktime());
			$sql.= ", fk_user_valid = ".$user->id;
			$sql.= " WHERE rowid = ".$this->id;
			$sql.= " AND fk_statut = 0";

			$resql=$this->db->query($sql);
			if (! $resql)
			{
				dol_syslog("CommandeFournisseur::valid() Echec update - 10 - sql=".$sql, LOG_ERR);
				dol_print_error($this->db);
				$error++;
			}

			if (! $error)
			{
				// Rename directory if dir was a temporary ref
				if (preg_match('/^[\(]?PROV/i', $this->ref))
				{
					// On renomme repertoire ($this->ref = ancienne ref, $num = nouvelle ref)
					// afin de ne pas perdre les fichiers attaches
					$oldref = dol_sanitizeFileName($this->ref);
					$newref = dol_sanitizeFileName($num);
					$dirsource = $conf->fournisseur->dir_output.'/commande/'.$oldref;
					$dirdest = $conf->fournisseur->dir_output.'/commande/'.$newref;
					if (file_exists($dirsource))
					{
						dol_syslog("CommandeFournisseur::valid() rename dir ".$dirsource." into ".$dirdest);

						if (@rename($dirsource, $dirdest))
						{
							dol_syslog("Rename ok");
							// Suppression ancien fichier PDF dans nouveau rep
							dol_delete_file($dirdest.'/'.$oldref.'.*');
						}
					}
				}
			}

			if (! $error)
			{
				$result = 1;
				$this->log($user, 1, time());	// Statut 1
				$this->ref = $num;
			}

			if (! $error)
			{
				// Appel des triggers
				include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
				$interface=new Interfaces($this->db);
				$result=$interface->run_triggers('ORDER_SUPPLIER_VALIDATE',$this,$user,$langs,$conf);
				if ($result < 0) { $error++; $this->errors=$interface->errors; }
				// Fin appel triggers
			}

			if (! $error)
			{
				$this->db->commit();
				return 1;
			}
			else
			{
				dol_syslog("CommandeFournisseur::valid ".$this->error, LOG_ERR);
				$this->db->rollback();
				$this->error=$this->db->lasterror();
				return -1;
			}
		}
		else
		{
			$this->error='Not Authorized';
			dol_syslog("CommandeFournisseur::valid ".$this->error, LOG_ERR);
			return -1;
		}
	}
コード例 #10
0
ファイル: document.php プロジェクト: remyyounes/dolibarr
				}
			}
		}
    }
}

// Delete
if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
	if ($object->fetch($id))
    {
    	$object->fetch_thirdparty();

    	$upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref);
    	$file = $upload_dir . '/' . $_GET['urlfile'];	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
    	dol_delete_file($file,0,0,0,'FILE_DELETE',$object);
    	$mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
    }
}


/*
 * View
 */

llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');

$html = new Form($db);

if ($id > 0 || ! empty($ref))
{
コード例 #11
0
ファイル: purge.php プロジェクト: ADDAdev/Dolibarr
         $filesarray = dol_dir_list($dolibarr_main_data_root, "all", 0, '', 'install\\.lock$');
     }
 }
 if ($choice == 'logfile') {
     $filesarray[] = array('fullname' => $filelog, 'type' => 'file');
 }
 $count = 0;
 if (count($filesarray)) {
     foreach ($filesarray as $key => $value) {
         //print "x ".$filesarray[$key]['fullname']."<br>\n";
         if ($filesarray[$key]['type'] == 'dir') {
             $count += dol_delete_dir_recursive($filesarray[$key]['fullname']);
         } elseif ($filesarray[$key]['type'] == 'file') {
             // If (file that is not logfile) or (if logfile with option logfile)
             if ($filesarray[$key]['fullname'] != $filelog || $choice == 'logfile') {
                 $count += dol_delete_file($filesarray[$key]['fullname']);
             }
         }
     }
     // Update cachenbofdoc
     if (!empty($conf->ecm->enabled) && $choice == 'allfiles') {
         require_once DOL_DOCUMENT_ROOT . '/ecm/class/ecmdirectory.class.php';
         $ecmdirstatic = new EcmDirectory($db);
         $result = $ecmdirstatic->refreshcachenboffile(1);
     }
 }
 if ($count) {
     $mesg = $langs->trans("PurgeNDirectoriesDeleted", $count);
 } else {
     $mesg = $langs->trans("PurgeNothingToDelete");
 }
コード例 #12
0
                @chmod($file, octdec($conf->global->MAIN_UMASK));
            }
        } else {
            $mesg = '<div class="error">' . $langs->trans('NoPDFAvailableForChecked') . '</div>';
        }
    } else {
        $mesg = '<div class="error">' . $langs->trans('InvoiceNotChecked') . '</div>';
    }
}
// Remove file
if ($action == 'remove_file') {
    require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
    $langs->load("other");
    $upload_dir = $diroutputpdf;
    $file = $upload_dir . '/' . GETPOST('file');
    $ret = dol_delete_file($file, 0, 0, 0, '');
    if ($ret) {
        setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
    } else {
        setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
    }
    $action = '';
}
/*
 * View
 */
$form = new Form($db);
$formfile = new FormFile($db);
if (GETPOST('courrier') == 1) {
    $title = $langs->trans("BillsByPrintOK");
} else {
コード例 #13
0
ファイル: modules_propale.php プロジェクト: netors/dolibarr
/**
 *  Delete preview files
 * 	@param	    db  		objet base de donnee
 * 	@param	    propalid	id de la propal a effacer
 * 	@param      propalref   reference de la propal si besoin
 */
function propale_delete_preview($db, $propalid, $propalref = '')
{
    global $langs, $conf;
    require_once DOL_DOCUMENT_ROOT . "/lib/files.lib.php";
    if (!$propalref) {
        $propal = new Propal($db, "", $propalid);
        $propal->fetch($propalid);
        $propalref = $propal->ref;
    }
    if ($conf->propale->dir_output) {
        $propalref = dol_sanitizeFileName($propalref);
        $dir = $conf->propale->dir_output . "/" . $propalref;
        $file = $dir . "/" . $propalref . ".pdf.png";
        $multiple = $file . ".";
        if (file_exists($file) && is_writable($file)) {
            if (!dol_delete_file($file, 1)) {
                $this->error = $langs->trans("ErrorFailedToOpenFile", $file);
                return 0;
            }
        } else {
            for ($i = 0; $i < 20; $i++) {
                $preview = $multiple . $i;
                if (file_exists($preview) && is_writable($preview)) {
                    if (!unlink($preview)) {
                        $this->error = $langs->trans("ErrorFailedToOpenFile", $preview);
                        return 0;
                    }
                }
            }
        }
    }
    return 1;
}
コード例 #14
0
ファイル: actioncomm.class.php プロジェクト: netors/dolibarr
 /**
  *		Export events from database into a cal file.
  *		@param		format			'vcal', 'ical/ics', 'rss'
  *		@param		type			'event' or 'journal'
  *		@param		cachedelay		Do not rebuild file if date older than cachedelay seconds
  *		@param		filename		Force filename
  *		@param		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 . "/lib/xcal.lib.php";
     require_once DOL_DOCUMENT_ROOT . "/lib/date.lib.php";
     dol_syslog("ActionComm::build_exportfile Build export file format=" . $format . ", type=" . $type . ", cachedelay=" . $cachedelay . ", filename=" . $filename . ", filters size=" . sizeof($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 = create_exdir($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 . '/lib/files.lib.php';
         if (dol_filemtime($outputfile) > $nowgmt - $cachedelay) {
             dol_syslog("ActionComm::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,";
         $sql .= " a.datec, a.tms as datem,";
         $sql .= " a.note, a.label, a.fk_action as type_id,";
         $sql .= " a.fk_soc,";
         $sql .= " a.fk_user_author, a.fk_user_mod,";
         $sql .= " a.fk_user_action, a.fk_user_done,";
         $sql .= " a.fk_contact, a.percent as percentage,";
         $sql .= " a.fk_element, a.elementtype,";
         $sql .= " a.priority, a.fulldayevent, a.location,";
         $sql .= " u.firstname, u.name,";
         $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";
         $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s on s.rowid = a.fk_soc AND s.entity IN (0, " . $conf->entity . ")";
         $sql .= " WHERE a.fk_action=c.id";
         $sql .= " AND a.entity = " . $conf->entity;
         foreach ($filters as $key => $value) {
             if ($key == 'notolderthan') {
                 $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 == 'login') {
                 $login = $value;
                 $userforfilter = new User($this->db);
                 $result = $userforfilter->fetch('', $value);
                 $sql .= " AND (";
                 $sql .= " a.fk_user_author = " . $userforfilter->id;
                 $sql .= " OR a.fk_user_action = " . $userforfilter->id;
                 $sql .= " OR a.fk_user_done = " . $userforfilter->id;
                 $sql .= ")";
             }
             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') {
                 $logint = $value;
                 $userforfilter = new User($this->db);
                 $result = $userforfilter->fetch('', $value);
                 $sql .= " AND a.fk_user_action = " . $userforfilter->id;
             }
             if ($key == 'logind') {
                 $logind = $value;
                 $userforfilter = new User($this->db);
                 $result = $userforfilter->fetch('', $value);
                 $sql .= " AND a.fk_user_done = " . $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("ActionComm::build_exportfile select events sql=" . $sql);
         $resql = $this->db->query($sql);
         if ($resql) {
             // Note: Output of sql request is encoded in $conf->file->character_set_client
             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=$obj->datea?$obj->datea:$obj->datep;
                 //$dateend=$obj->datea2?$obj->datea2:$obj->datep2;
                 //$duration=$obj->durationa?$obj->durationa:$obj->durationp;
                 $datestart = $this->db->jdate($obj->datep);
                 //print $datestart.'x'; exit;
                 $dateend = $this->db->jdate($obj->datep2);
                 $duration = $obj->durationp;
                 $event['summary'] = $langs->convToOutputCharset($obj->label . ($obj->socname ? " (" . $obj->socname . ")" : ""));
                 $event['desc'] = $langs->convToOutputCharset($obj->note);
                 $event['startdate'] = $datestart;
                 $event['duration'] = $duration;
                 // Not required with type 'journal'
                 $event['enddate'] = $dateend;
                 // Not required with type 'journal'
                 $event['author'] = $obj->firstname . ($obj->name ? " " . $obj->name : "");
                 $event['priority'] = $obj->priority;
                 $event['fulldayevent'] = $obj->fulldayevent;
                 $event['location'] = $langs->convToOutputCharset($obj->location);
                 $event['transparency'] = 'TRANSPARENT';
                 // OPAQUE (busy) or TRANSPARENT (not busy)
                 $event['category'] = $langs->convToOutputCharset($obj->libelle);
                 // libelle type action
                 $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', $dolibarr_main_url_root);
                 $url = $urlwithouturlroot . DOL_URL_ROOT . '/comm/action/fiche.php?id=' . $obj->id;
                 $event['url'] = $url;
                 $event['created'] = $this->db->jdate($obj->datec);
                 $event['modified'] = $this->db->jdate($obj->datem);
                 if ($qualified && $datestart) {
                     $eventarray[$datestart] = $event;
                 }
             }
         } else {
             $this->error = $this->db->lasterror();
             dol_syslog("ActionComm::build_exportfile " . $this->db->lasterror(), LOG_ERR);
             return -1;
         }
         $langs->load("agenda");
         // Define title and desc
         $more = '';
         if ($login) {
             $more = $langs->transnoentities("User") . ' ' . $langs->convToOutputCharset($login);
         }
         if ($logina) {
             $more = $langs->transnoentities("ActionsAskedBy") . ' ' . $langs->convToOutputCharset($logina);
         }
         if ($logint) {
             $more = $langs->transnoentities("ActionsToDoBy") . ' ' . $langs->convToOutputCharset($logint);
         }
         if ($logind) {
             $more = $langs->transnoentities("ActionsDoneBy") . ' ' . $langs->convToOutputCharset($logind);
         }
         if ($more) {
             $title = $langs->convToOutputCharset('Dolibarr actions ' . $mysoc->name) . ' - ' . $more;
             $desc = $more;
             $desc .= $langs->convToOutputCharset(' (' . $mysoc->name . ' - built by Dolibarr)');
         } else {
             $title = $langs->convToOutputCharset('Dolibarr actions ' . $mysoc->name);
             $desc = $langs->transnoentities('ListOfActions');
             $desc .= $langs->convToOutputCharset(' (' . $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 (rename($outputfiletmp, $outputfile)) {
                 $result = 1;
             } else {
                 dol_syslog("ActionComm::build_exportfile failed to rename " . $outputfiletmp . " to " . $outputfile, LOG_ERR);
                 dol_delete_file($outputfiletmp, 0, 1);
                 $result = -1;
             }
         } else {
             dol_syslog("ActionComm::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;
 }
コード例 #15
0
ファイル: export.php プロジェクト: TAASA/Dolibarr-ERP-3.8.1
        // Close file
        if ($compression == 'none') {
            fclose($handle);
        }
        if ($compression == 'gz') {
            gzclose($handle);
        }
        if ($compression == 'bz') {
            bzclose($handle);
        }
        if ($ok && preg_match('/^-- MySql/i', $errormsg)) {
            $errormsg = '';
        } else {
            // Renommer fichier sortie en fichier erreur
            //print "$outputfile -> $outputerror";
            @dol_delete_file($outputerror, 1);
            @rename($outputfile, $outputerror);
            // Si safe_mode on et command hors du parametre exec, on a un fichier out vide donc errormsg vide
            if (!$errormsg) {
                $langs->load("errors");
                $errormsg = $langs->trans("ErrorFailedToRunExternalCommand");
            }
        }
    }
    // Fin execution commande
}
if ($what == 'mysqlnobin') {
    $outputdir = $conf->admin->dir_output . '/backup';
    $outputfile = $outputdir . '/' . $file;
    $outputfiletemp = $outputfile . '-TMP.sql';
    // for compression format, we add extension
コード例 #16
0
ファイル: document.php プロジェクト: remyyounes/dolibarr
if ($action == 'remove_file')	// Remove a file
{
	clearstatcache();

	dol_syslog("document.php remove $original_file $urlsource", LOG_DEBUG);

	// This test should be useless. We keep it to find bug more easily
	$original_file_osencoded=dol_osencode($original_file);	// New file name encoded in OS encoding charset
	if (! file_exists($original_file_osencoded))
	{
		$file=basename($original_file);		// Do no show plain path of original_file in shown error message
		dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$file));
		exit;
	}

	dol_delete_file($original_file);

	dol_syslog("document.php back to ".urldecode($urlsource), LOG_DEBUG);

	header("Location: ".urldecode($urlsource));

	return;
}
else						// Open and return file
{
	clearstatcache();

	$filename = basename($original_file);

	// Output file on browser
	dol_syslog("document.php download $original_file $filename content-type=$type");
コード例 #17
0
ファイル: expedition.class.php プロジェクト: Albertopf/prueba
 /**
  * 	Delete shipment.
  *  Warning, do not delete a shipment if a delivery is linked to (with table llx_element_element)
  *
  * 	@return	int		>0 if OK, 0 if deletion done but failed to delete files, <0 if KO
  */
 function delete()
 {
     global $conf, $langs, $user;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     if ($conf->productbatch->enabled) {
         require_once DOL_DOCUMENT_ROOT . '/expedition/class/expeditionbatch.class.php';
     }
     $error = 0;
     $this->error = '';
     // Add a protection to refuse deleting if shipment has at least one delivery
     $this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery');
     // Get deliveries linked to this shipment
     if (count($this->linkedObjectsIds) > 0) {
         $this->error = 'ErrorThereIsSomeDeliveries';
         return -1;
     }
     $this->db->begin();
     // Stock control
     if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0) {
         require_once DOL_DOCUMENT_ROOT . "/product/stock/class/mouvementstock.class.php";
         $langs->load("agenda");
         // Loop on each product line to add a stock movement
         $sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as expeditiondet_id";
         $sql .= " FROM " . MAIN_DB_PREFIX . "commandedet as cd,";
         $sql .= " " . MAIN_DB_PREFIX . "expeditiondet as ed";
         $sql .= " WHERE ed.fk_expedition = " . $this->id;
         $sql .= " AND cd.rowid = ed.fk_origin_line";
         dol_syslog(get_class($this) . "::delete select details", LOG_DEBUG);
         $resql = $this->db->query($sql);
         if ($resql) {
             $cpt = $this->db->num_rows($resql);
             for ($i = 0; $i < $cpt; $i++) {
                 dol_syslog(get_class($this) . "::delete movement index " . $i);
                 $obj = $this->db->fetch_object($resql);
                 $mouvS = new MouvementStock($this->db);
                 // we do not log origin because it will be deleted
                 $mouvS->origin = null;
                 // get lot/serial
                 $lotArray = null;
                 if ($conf->productbatch->enabled) {
                     $lotArray = ExpeditionLineBatch::fetchAll($this->db, $obj->expeditiondet_id);
                     if (!is_array($lotArray)) {
                         $error++;
                         $this->errors[] = "Error " . $this->db->lasterror();
                     }
                 }
                 if (empty($lotArray)) {
                     // no lot/serial
                     // We increment stock of product (and sub-products)
                     // We use warehouse selected for each line
                     $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref));
                     // Price is set to 0, because we don't want to see WAP changed
                     if ($result < 0) {
                         $error++;
                         $this->errors = $this->errors + $mouvS->errors;
                         break;
                     }
                 } else {
                     // We increment stock of batches
                     // We use warehouse selected for each line
                     foreach ($lotArray as $lot) {
                         $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->dluo_qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch);
                         // Price is set to 0, because we don't want to see WAP changed
                         if ($result < 0) {
                             $error++;
                             $this->errors = $this->errors + $mouvS->errors;
                             break;
                         }
                     }
                     if ($error) {
                         break;
                     }
                     // break for loop incase of error
                 }
             }
         } else {
             $error++;
             $this->errors[] = "Error " . $this->db->lasterror();
         }
     }
     // delete batch expedition line
     if (!$error && $conf->productbatch->enabled) {
         if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0) {
             $error++;
             $this->errors[] = "Error " . $this->db->lasterror();
         }
     }
     if (!$error) {
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "expeditiondet";
         $sql .= " WHERE fk_expedition = " . $this->id;
         if ($this->db->query($sql)) {
             // Delete linked object
             $res = $this->deleteObjectLinked();
             if ($res < 0) {
                 $error++;
             }
             if (!$error) {
                 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "expedition";
                 $sql .= " WHERE rowid = " . $this->id;
                 if ($this->db->query($sql)) {
                     // Call trigger
                     $result = $this->call_trigger('SHIPPING_DELETE', $user);
                     if ($result < 0) {
                         $error++;
                     }
                     // End call triggers
                     if (!$error) {
                         $this->db->commit();
                         // We delete PDFs
                         $ref = dol_sanitizeFileName($this->ref);
                         if (!empty($conf->expedition->dir_output)) {
                             $dir = $conf->expedition->dir_output . '/sending/' . $ref;
                             $file = $dir . '/' . $ref . '.pdf';
                             if (file_exists($file)) {
                                 if (!dol_delete_file($file)) {
                                     return 0;
                                 }
                             }
                             if (file_exists($dir)) {
                                 if (!dol_delete_dir_recursive($dir)) {
                                     $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
                                     return 0;
                                 }
                             }
                         }
                         return 1;
                     } else {
                         $this->db->rollback();
                         return -1;
                     }
                 } else {
                     $this->error = $this->db->lasterror() . " - sql={$sql}";
                     $this->db->rollback();
                     return -3;
                 }
             } else {
                 $this->error = $this->db->lasterror() . " - sql={$sql}";
                 $this->db->rollback();
                 return -2;
             }
         } else {
             $this->error = $this->db->lasterror() . " - sql={$sql}";
             $this->db->rollback();
             return -1;
         }
     } else {
         $this->db->rollback();
         return -1;
     }
 }
コード例 #18
0
ファイル: commande.class.php プロジェクト: Albertopf/prueba
 /**
  *	Delete the customer order
  *
  *	@param	User	$user		User object
  *	@param	int		$notrigger	1=Does not execute triggers, 0= execuete triggers
  * 	@return	int					<=0 if KO, >0 if OK
  */
 function delete($user, $notrigger = 0)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $error = 0;
     $this->db->begin();
     if (!$error && !$notrigger) {
         // Call trigger
         $result = $this->call_trigger('ORDER_DELETE', $user);
         if ($result < 0) {
             $error++;
         }
         // End call triggers
     }
     //TODO: Check for error after each action. If one failed we rollback, don't waste time to do action if previous fail
     if (!$error) {
         // Delete order details
         $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commandedet WHERE fk_commande = " . $this->id;
         dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
         if (!$this->db->query($sql)) {
             $error++;
             $this->errors[] = $this->db->lasterror();
         }
         // Delete order
         $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commande WHERE rowid = " . $this->id;
         dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
         if (!$this->db->query($sql)) {
             $error++;
             $this->errors[] = $this->db->lasterror();
         }
         // Delete linked object
         $res = $this->deleteObjectLinked();
         if ($res < 0) {
             $error++;
         }
         // Delete linked contacts
         $res = $this->delete_linked_contact();
         if ($res < 0) {
             $error++;
         }
         // Remove extrafields
         if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
             $result = $this->deleteExtraFields();
             if ($result < 0) {
                 $error++;
                 dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR);
             }
         }
         // On efface le repertoire de pdf provisoire
         $comref = dol_sanitizeFileName($this->ref);
         if ($conf->commande->dir_output && !empty($this->ref)) {
             $dir = $conf->commande->dir_output . "/" . $comref;
             $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
             if (file_exists($file)) {
                 dol_delete_preview($this);
                 if (!dol_delete_file($file, 0, 0, 0, $this)) {
                     $this->db->rollback();
                     return 0;
                 }
             }
             if (file_exists($dir)) {
                 if (!dol_delete_dir_recursive($dir)) {
                     $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
                     $this->db->rollback();
                     return 0;
                 }
             }
         }
     }
     if (!$error) {
         dol_syslog(get_class($this) . "::delete {$this->id} by {$user->id}", LOG_DEBUG);
         $this->db->commit();
         return 1;
     } else {
         foreach ($this->errors as $errmsg) {
             dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR);
             $this->error .= $this->error ? ', ' . $errmsg : $errmsg;
         }
         $this->db->rollback();
         return -1 * $error;
     }
 }
コード例 #19
0
ファイル: fiche.php プロジェクト: netors/dolibarr
     $edituser->photo = dol_sanitizeFileName($_FILES['photo']['name']);
 }
 $ret = $edituser->update($user);
 if ($ret < 0) {
     if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
         $langs->load("errors");
         $message .= '<div class="error">' . $langs->trans("ErrorLoginAlreadyExists", $edituser->login) . '</div>';
     } else {
         $message .= '<div class="error">' . $edituser->error . '</div>';
     }
 }
 if ($ret >= 0 && !count($edituser->errors)) {
     if (GETPOST('deletephoto') && $edituser->photo) {
         $fileimg = $conf->user->dir_output . '/' . get_exdir($edituser->id, 2, 0, 1) . '/logos/' . $edituser->photo;
         $dirthumbs = $conf->user->dir_output . '/' . get_exdir($edituser->id, 2, 0, 1) . '/logos/thumbs';
         dol_delete_file($fileimg);
         dol_delete_dir_recursive($dirthumbs);
     }
     if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) {
         $dir = $conf->user->dir_output . '/' . get_exdir($edituser->id, 2, 0, 1);
         create_exdir($dir);
         if (@is_dir($dir)) {
             $newfile = $dir . '/' . dol_sanitizeFileName($_FILES['photo']['name']);
             $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']);
             if (!$result > 0) {
                 $message .= '<div class="error">' . $langs->trans("ErrorFailedToSaveFile") . '</div>';
             } else {
                 // Create small thumbs for company (Ratio is near 16/9)
                 // Used on logon for example
                 $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
                 // Create mini thumbs for company (Ratio is near 16/9)
コード例 #20
0
ファイル: docmine.php プロジェクト: remyyounes/dolibarr
			}
	    }
	}
	else
	{
	    // Echec transfert (fichier depassant la limite ?)
		$langs->load("errors");
		$mesg = '<div class="error">'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'</div>';
	}
}

// Remove file
if (GETPOST('action') == 'confirm_deletefile' && GETPOST('confirm') == 'yes')
{
  $file = $upload_dir . "/" . GETPOST('urlfile');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
  $result=dol_delete_file($file);

  $mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';

  $result=$ecmdir->changeNbOfFiles('-');
}

// Remove dir
if (GETPOST('action') == 'confirm_deletedir' && GETPOST('confirm') == 'yes')
{
	// Fetch was already done
	$result=$ecmdir->delete($user);
	if ($result > 0)
	{
		header("Location: ".DOL_URL_ROOT."/ecm/index.php");
		exit;
コード例 #21
0
ファイル: propal.class.php プロジェクト: ADDAdev/Dolibarr
 /**
  *	Delete proposal
  *
  *	@param	User	$user        	Object user that delete
  *	@param	int		$notrigger		1=Does not execute triggers, 0= execuete triggers
  *	@return	int						1 if ok, otherwise if error
  */
 function delete($user, $notrigger = 0)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $error = 0;
     $this->db->begin();
     if (!$notrigger) {
         // Call trigger
         $result = $this->call_trigger('PROPAL_DELETE', $user);
         if ($result < 0) {
             $error++;
         }
         // End call triggers
     }
     if (!$error) {
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE fk_propal = " . $this->id;
         if ($this->db->query($sql)) {
             $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propal WHERE rowid = " . $this->id;
             if ($this->db->query($sql)) {
                 // Delete linked object
                 $res = $this->deleteObjectLinked();
                 if ($res < 0) {
                     $error++;
                 }
                 // Delete linked contacts
                 $res = $this->delete_linked_contact();
                 if ($res < 0) {
                     $error++;
                 }
                 if (!$error) {
                     // We remove directory
                     $ref = dol_sanitizeFileName($this->ref);
                     if ($conf->propal->dir_output && !empty($this->ref)) {
                         $dir = $conf->propal->dir_output . "/" . $ref;
                         $file = $dir . "/" . $ref . ".pdf";
                         if (file_exists($file)) {
                             dol_delete_preview($this);
                             if (!dol_delete_file($file, 0, 0, 0, $this)) {
                                 $this->error = 'ErrorFailToDeleteFile';
                                 $this->errors = array('ErrorFailToDeleteFile');
                                 $this->db->rollback();
                                 return 0;
                             }
                         }
                         if (file_exists($dir)) {
                             $res = @dol_delete_dir_recursive($dir);
                             if (!$res) {
                                 $this->error = 'ErrorFailToDeleteDir';
                                 $this->errors = array('ErrorFailToDeleteDir');
                                 $this->db->rollback();
                                 return 0;
                             }
                         }
                     }
                 }
                 // Removed extrafields
                 if (!$error) {
                     if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
                         $result = $this->deleteExtraFields();
                         if ($result < 0) {
                             $error++;
                             $errorflag = -4;
                             dol_syslog(get_class($this) . "::delete erreur " . $errorflag . " " . $this->error, LOG_ERR);
                         }
                     }
                 }
                 if (!$error) {
                     dol_syslog(get_class($this) . "::delete " . $this->id . " by " . $user->id, LOG_DEBUG);
                     $this->db->commit();
                     return 1;
                 } else {
                     $this->error = $this->db->lasterror();
                     $this->db->rollback();
                     return 0;
                 }
             } else {
                 $this->error = $this->db->lasterror();
                 $this->db->rollback();
                 return -3;
             }
         } else {
             $this->error = $this->db->lasterror();
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->db->rollback();
         return -1;
     }
 }
コード例 #22
0
ファイル: product.class.php プロジェクト: nrjacker4/crm-php
	/**
	 *  Efface la photo du produit et sa vignette
	 *
	 *  @param  string		$file        Chemin de l'image
	 *  @return	void
	 */
	function delete_photo($file)
	{
        require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");

        $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
		$dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
		$filename = preg_replace('/'.preg_quote($dir,'/').'/i','',$file); // Nom du fichier

		// On efface l'image d'origine
		dol_delete_file($file);

		// Si elle existe, on efface la vignette
		if (preg_match('/(\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i',$filename,$regs))
		{
			$photo_vignette=preg_replace('/'.$regs[0].'/i','',$filename).'_small'.$regs[0];
			if (file_exists(dol_osencode($dirthumb.$photo_vignette)))
			{
				dol_delete_file($dirthumb.$photo_vignette);
			}
		}
	}
コード例 #23
0
ファイル: commande.class.php プロジェクト: ripasch/dolibarr
 /**
  *	Delete the customer order
  *	@param		user		User object
  * 	@return		int		<=0 if KO, >0 if OK
  */
 function delete($user)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . "/lib/files.lib.php";
     $err = 0;
     $this->db->begin();
     // Delete order details
     $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commandedet WHERE fk_commande = " . $this->id;
     dol_syslog("Commande::delete sql=" . $sql);
     if (!$this->db->query($sql)) {
         dol_syslog("CustomerOrder::delete error", LOG_ERR);
         $err++;
     }
     // Delete order
     $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . "commande WHERE rowid = " . $this->id;
     dol_syslog("Commande::delete sql=" . $sql);
     if (!$this->db->query($sql)) {
         dol_syslog("CustomerOrder::delete error", LOG_ERR);
         $err++;
     }
     // Delete linked object
     // TODO deplacer dans le common
     $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_element";
     $sql .= " WHERE fk_target = " . $this->id;
     $sql .= " AND targettype = '" . $this->element . "'";
     dol_syslog("Commande::delete sql=" . $sql);
     if (!$this->db->query($sql)) {
         dol_syslog("CustomerOrder::delete error", LOG_ERR);
         $err++;
     }
     // Delete linked contacts
     $res = $this->delete_linked_contact();
     if ($res < 0) {
         dol_syslog("CustomerOrder::delete error", LOG_ERR);
         $err++;
     }
     // On efface le repertoire de pdf provisoire
     $comref = dol_sanitizeFileName($this->ref);
     if ($conf->commande->dir_output) {
         $dir = $conf->commande->dir_output . "/" . $comref;
         $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf";
         if (file_exists($file)) {
             commande_delete_preview($this->db, $this->id, $this->ref);
             if (!dol_delete_file($file)) {
                 $this->error = $langs->trans("ErrorCanNotDeleteFile", $file);
                 $this->db->rollback();
                 return 0;
             }
         }
         if (file_exists($dir)) {
             if (!dol_delete_dir($dir)) {
                 $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
                 $this->db->rollback();
                 return 0;
             }
         }
     }
     if ($err == 0) {
         // Appel des triggers
         include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
         $interface = new Interfaces($this->db);
         $result = $interface->run_triggers('ORDER_DELETE', $this, $user, $langs, $conf);
         if ($result < 0) {
             $error++;
             $this->errors = $interface->errors;
         }
         // Fin appel triggers
         $this->db->commit();
         return 1;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
コード例 #24
0
ファイル: propal.class.php プロジェクト: nrjacker4/crm-php
 /**
  *	Delete proposal
  *
  *	@param	User	$user        	Object user that delete
  *	@param	int		$notrigger		1=Does not execute triggers, 0= execuete triggers
  *	@return	int						1 if ok, otherwise if error
  */
 function delete($user, $notrigger = 0)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php";
     $error = 0;
     $this->db->begin();
     if (!$error && !$notrigger) {
         // Call triggers
         include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
         $interface = new Interfaces($this->db);
         $result = $interface->run_triggers('PROPAL_DELETE', $this, $user, $langs, $conf);
         if ($result < 0) {
             $error++;
             $this->errors = $interface->errors;
         }
         // End call triggers
     }
     if (!$error) {
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE fk_propal = " . $this->id;
         if ($this->db->query($sql)) {
             $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propal WHERE rowid = " . $this->id;
             if ($this->db->query($sql)) {
                 // Delete linked object
                 $res = $this->deleteObjectLinked();
                 if ($res < 0) {
                     $error++;
                 }
                 // Delete linked contacts
                 $res = $this->delete_linked_contact();
                 if ($res < 0) {
                     $error++;
                 }
                 if (!$error) {
                     // We remove directory
                     $ref = dol_sanitizeFileName($this->ref);
                     if ($conf->propal->dir_output) {
                         $dir = $conf->propal->dir_output . "/" . $ref;
                         $file = $dir . "/" . $ref . ".pdf";
                         if (file_exists($file)) {
                             dol_delete_preview($this);
                             if (!dol_delete_file($file, 0, 0, 0, $this)) {
                                 $this->error = 'ErrorFailToDeleteFile';
                                 $this->db->rollback();
                                 return 0;
                             }
                         }
                         if (file_exists($dir)) {
                             $res = @dol_delete_dir_recursive($dir);
                             if (!$res) {
                                 $this->error = 'ErrorFailToDeleteDir';
                                 $this->db->rollback();
                                 return 0;
                             }
                         }
                     }
                 }
                 if (!$error) {
                     dol_syslog(get_class($this) . "::delete {$this->id} by {$user->id}", LOG_DEBUG);
                     $this->db->commit();
                     return 1;
                 } else {
                     $this->error = $this->db->lasterror();
                     dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
                     $this->db->rollback();
                     return 0;
                 }
             } else {
                 $this->error = $this->db->lasterror();
                 dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
                 $this->db->rollback();
                 return -3;
             }
         } else {
             $this->error = $this->db->lasterror();
             dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->error = $this->db->lasterror();
         dol_syslog(get_class($this) . "::delete " . $this->error, LOG_ERR);
         $this->db->rollback();
         return -1;
     }
 }
コード例 #25
0
     }
     $result = @(include_once $newdir . $generator . '.modules.php');
     if ($result) {
         break;
     }
 }
 // Load barcode class for generating barcode image
 $classname = "mod" . ucfirst($generator);
 $module = new $classname($db);
 if ($generator != 'tcpdfbarcode') {
     // May be phpbarcode
     $template = 'standardlabel';
     $is2d = false;
     if ($module->encodingIsSupported($encoding)) {
         $barcodeimage = $conf->barcode->dir_temp . '/barcode_' . $code . '_' . $encoding . '.png';
         dol_delete_file($barcodeimage);
         // File is created with full name $barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
         $result = $module->writeBarCode($code, $encoding, 'Y', 4, 1);
         if ($result <= 0 || !dol_is_file($barcodeimage)) {
             $error++;
             setEventMessages('Failed to generate image file of barcode for code=' . $code . ' encoding=' . $encoding . ' file=' . basename($barcodeimage), null, 'errors');
             setEventMessages($module->error, null, 'errors');
         }
     } else {
         $error++;
         setEventMessages("Error, encoding " . $encoding . " is not supported by encoder " . $generator . '. You must choose another barcode type or install a barcode generation engine that support ' . $encoding, null, 'errors');
     }
 } else {
     $template = 'tcpdflabel';
     $encoding = $module->getTcpdfEncodingType($encoding);
     //convert to TCPDF compatible encoding types
コード例 #26
0
    $listofmimes = array();
    if (!empty($_SESSION["listofpaths"])) {
        $listofpaths = explode(';', $_SESSION["listofpaths"]);
    }
    if (!empty($_SESSION["listofnames"])) {
        $listofnames = explode(';', $_SESSION["listofnames"]);
    }
    if (!empty($_SESSION["listofmimes"])) {
        $listofmimes = explode(';', $_SESSION["listofmimes"]);
    }
    include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
    $formmail = new FormMail($db);
    foreach ($listofpaths as $key => $value) {
        $pathtodelete = $value;
        $filetodelete = $listofnames[$key];
        $result = dol_delete_file($pathtodelete, 1);
        // Delete uploded Files
        $langs->load("other");
        setEventMessages($langs->trans("FileWasRemoved", $filetodelete), null, 'mesgs');
        $formmail->remove_attached_files($key);
        // Update Session
    }
}
/*
 * Send mail
 */
if (($action == 'send' || $action == 'relance') && !$_POST['addfile'] && !$_POST['removAll'] && !$_POST['removedfile'] && !$_POST['cancel'] && !$_POST['modelselected']) {
    if ($conf->dolimail->enabled) {
        $langs->load("dolimail@dolimail");
    }
    $langs->load('mails');
コード例 #27
0
    $sortfield = "date";
}
if ($page < 0) {
    $page = 0;
}
$limit = $conf->liste_limit;
$offset = $limit * $page;
if (!$user->admin) {
    accessforbidden();
}
/*
 * Actions
 */
if ($action == 'delete') {
    $file = $conf->admin->dir_output . '/' . GETPOST('urlfile');
    $ret = dol_delete_file($file, 1);
    if ($ret) {
        setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
    } else {
        setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
    }
    $action = '';
}
/*
 * View
 */
$form = new Form($db);
$formfile = new FormFile($db);
$label = getStaticMember($db, 'label');
$help_url = 'EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad';
llxHeader('', '', $help_url);
コード例 #28
0
 /**
  *  Efface la photo du produit et sa vignette
  *
  *  @param  string		$file        Chemin de l'image
  *  @return	void
  */
 function delete_photo($file)
 {
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $dir = dirname($file) . '/';
     // Chemin du dossier contenant l'image d'origine
     $dirthumb = $dir . '/thumbs/';
     // Chemin du dossier contenant la vignette
     $filename = preg_replace('/' . preg_quote($dir, '/') . '/i', '', $file);
     // Nom du fichier
     // On efface l'image d'origine
     dol_delete_file($file, 0, 0, 0, $this);
     // For triggers
     // Si elle existe, on efface la vignette
     if (preg_match('/(' . $this->regeximgext . ')$/i', $filename, $regs)) {
         $photo_vignette = preg_replace('/' . $regs[0] . '/i', '', $filename) . '_small' . $regs[0];
         if (file_exists(dol_osencode($dirthumb . $photo_vignette))) {
             dol_delete_file($dirthumb . $photo_vignette);
         }
         $photo_vignette = preg_replace('/' . $regs[0] . '/i', '', $filename) . '_mini' . $regs[0];
         if (file_exists(dol_osencode($dirthumb . $photo_vignette))) {
             dol_delete_file($dirthumb . $photo_vignette);
         }
     }
 }
コード例 #29
0
ファイル: document.php プロジェクト: Samara94/dolibarr
                        $mesg = '<div class="error">' . $langs->trans("ErrorFileIsInfectedWithAVirus") . '</div>';
                    } else {
                        // Known error
                        $mesg = '<div class="error">' . $langs->trans($resupload) . '</div>';
                    }
                }
            }
        }
    }
} else {
    if ($action == 'confirm_deletefile' && $confirm == 'yes') {
        if ($object->fetch($id)) {
            $upload_dir = $conf->bank->dir_output;
            $file = $upload_dir . '/' . GETPOST('urlfile');
            // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
            $ret = dol_delete_file($file, 0, 0, 0, $object);
            if ($ret) {
                setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
            } else {
                setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
            }
            Header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id);
            exit;
        }
    }
}
/*
 * View
 */
llxHeader();
$form = new Form($db);
コード例 #30
0
ファイル: fichinter.class.php プロジェクト: ADDAdev/Dolibarr
 /**
  *	Delete intervetnion
  *
  *	@param      User	$user			Object user who delete
  *	@param		int		$notrigger		Disable trigger
  *	@return		int						<0 if KO, >0 if OK
  */
 function delete($user, $notrigger = 0)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $error = 0;
     $this->db->begin();
     // Delete linked object
     $res = $this->deleteObjectLinked();
     if ($res < 0) {
         $error++;
     }
     // Delete linked contacts
     $res = $this->delete_linked_contact();
     if ($res < 0) {
         $this->error = 'ErrorFailToDeleteLinkedContact';
         $error++;
     }
     if ($error) {
         $this->db->rollback();
         return -1;
     }
     $sql = "DELETE FROM " . MAIN_DB_PREFIX . "fichinterdet";
     $sql .= " WHERE fk_fichinter = " . $this->id;
     dol_syslog("Fichinter::delete", LOG_DEBUG);
     if ($this->db->query($sql)) {
         $sql = "DELETE FROM " . MAIN_DB_PREFIX . "fichinter";
         $sql .= " WHERE rowid = " . $this->id;
         $sql .= " AND entity = " . $conf->entity;
         dol_syslog("Fichinter::delete", LOG_DEBUG);
         if ($this->db->query($sql)) {
             // Remove directory with files
             $fichinterref = dol_sanitizeFileName($this->ref);
             if ($conf->ficheinter->dir_output) {
                 $dir = $conf->ficheinter->dir_output . "/" . $fichinterref;
                 $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
                 if (file_exists($file)) {
                     dol_delete_preview($this);
                     if (!dol_delete_file($file, 0, 0, 0, $this)) {
                         $this->error = $langs->trans("ErrorCanNotDeleteFile", $file);
                         return 0;
                     }
                 }
                 if (file_exists($dir)) {
                     if (!dol_delete_dir_recursive($dir)) {
                         $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
                         return 0;
                     }
                 }
             }
             if (!$notrigger) {
                 // Call trigger
                 $result = $this->call_trigger('FICHINTER_DELETE', $user);
                 if ($result < 0) {
                     $error++;
                     $this->db->rollback();
                     return -1;
                 }
                 // End call triggers
             }
             $this->db->commit();
             return 1;
         } else {
             $this->error = $this->db->lasterror();
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->error = $this->db->lasterror();
         $this->db->rollback();
         return -1;
     }
 }