Exemplo n.º 1
0
}
$object = new Account($db);
if ($id) {
    $object->fetch($id);
}
/*
 * Actions
 */
// Envoi fichier
if ($_POST["sendit"] && !empty($conf->global->MAIN_UPLOAD_DOC)) {
    if ($object->fetch($id)) {
        $upload_dir = $conf->bank->dir_output . "/" . $object->ref;
        if (dol_mkdir($upload_dir) >= 0) {
            $resupload = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']), 0, 0, $_FILES['userfile']['error']);
            if (is_numeric($resupload) && $resupload > 0) {
                if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1) {
                    // Create small thumbs for image (Ratio is near 16/9)
                    // Used on logon for example
                    $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
                    // Create mini thumbs for image (Ratio is near 16/9)
                    // Used on menu or for setup page for example
                    $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
                }
                $mesg = '<div class="ok">' . $langs->trans("FileTransferComplete") . '</div>';
            } else {
                $langs->load("errors");
                if ($resupload < 0) {
                    // Unknown error
                    $mesg = '<div class="error">' . $langs->trans("ErrorFileNotUploaded") . '</div>';
                } else {
                    if (preg_match('/ErrorFileIsInfectedWithAVirus/', $resupload)) {
Exemplo n.º 2
0
 /**
  *  Show list of documents in a directory
  *
  *  @param	 array	$filearray          Array of files loaded by dol_dir_list('files') function before calling this
  * 	@param	 Object	$object				Object on which document is linked to
  * 	@param	 string	$modulepart			Value for modulepart used by download or viewimage wrapper
  * 	@param	 string	$param				Parameters on sort links (param must start with &, example &aaa=bbb&ccc=ddd)
  * 	@param	 int	$forcedownload		Force to open dialog box "Save As" when clicking on file
  * 	@param	 string	$relativepath		Relative path of docs (autodefined if not provided)
  * 	@param	 int	$permtodelete		Permission to delete
  * 	@param	 int	$useinecm			Change output for use in ecm module
  * 	@param	 string	$textifempty		Text to show if filearray is empty ('NoFileFound' if not defined)
  *  @param   int	$maxlength          Maximum length of file name shown
  *  @param	 string	$title				Title before list
  *  @param	 string $url				Full url to use for click links ('' = autodetect)
  *  @param	 int	$showrelpart		0=Show only filename (default), 1=Show first level 1 dir
  * 	@return	 int						<0 if KO, nb of files shown if OK
  */
 function list_of_documents($filearray, $object, $modulepart, $param = '', $forcedownload = 0, $relativepath = '', $permtodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $title = '', $url = '', $showrelpart = 0)
 {
     global $user, $conf, $langs, $hookmanager;
     global $bc;
     global $sortfield, $sortorder, $maxheightmini;
     $hookmanager->initHooks(array('formfile'));
     $parameters = array('filearray' => $filearray, 'modulepart' => $modulepart, 'param' => $param, 'forcedownload' => $forcedownload, 'relativepath' => $relativepath, 'permtodelete' => $permtodelete, 'useinecm' => $useinecm, 'textifempty' => $textifempty, 'maxlength' => $maxlength, 'title' => $title, 'url' => $url);
     $reshook = $hookmanager->executeHooks('showFilesList', $parameters, $object);
     if (isset($reshook) && $reshook != '') {
         return $reshook;
     } else {
         $param = (isset($object->id) ? '&id=' . $object->id : '') . $param;
         // Show list of existing files
         if (empty($useinecm)) {
             print load_fiche_titre($title ? $title : $langs->trans("AttachedFiles"));
         }
         if (empty($url)) {
             $url = $_SERVER["PHP_SELF"];
         }
         print '<table width="100%" class="' . ($useinecm ? 'nobordernopadding' : 'liste') . '">';
         print '<tr class="liste_titre">';
         print_liste_field_titre($langs->trans("Documents2"), $url, "name", "", $param, 'align="left"', $sortfield, $sortorder);
         print_liste_field_titre($langs->trans("Size"), $url, "size", "", $param, 'align="right"', $sortfield, $sortorder);
         print_liste_field_titre($langs->trans("Date"), $url, "date", "", $param, 'align="center"', $sortfield, $sortorder);
         if (empty($useinecm)) {
             print_liste_field_titre('', $url, "", "", $param, 'align="center"');
         }
         print_liste_field_titre('');
         print "</tr>\n";
         $nboffiles = count($filearray);
         if ($nboffiles > 0) {
             include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';
         }
         $var = true;
         foreach ($filearray as $key => $file) {
             if ($file['name'] != '.' && $file['name'] != '..' && !preg_match('/\\.meta$/i', $file['name'])) {
                 // Define relative path used to store the file
                 if (empty($relativepath)) {
                     $relativepath = (!empty($object->ref) ? dol_sanitizeFileName($object->ref) : '') . '/';
                     if ($object->element == 'invoice_supplier') {
                         $relativepath = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier') . $relativepath;
                     }
                     // TODO Call using a defined value for $relativepath
                     if ($object->element == 'member') {
                         $relativepath = get_exdir($object->id, 2, 0, 0, $object, 'member') . $relativepath;
                     }
                     // TODO Call using a defined value for $relativepath
                     if ($object->element == 'project_task') {
                         $relativepath = 'Call_not_supported_._Call_function_using_a_defined_relative_path_.';
                     }
                 }
                 // For backward compatiblity, we detect file is stored into an old path
                 if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO) && $file['level1name'] == 'photos') {
                     $relativepath = preg_replace('/^.*\\/produit\\//', '', $file['path']) . '/';
                 }
                 $var = !$var;
                 print '<tr ' . $bc[$var] . '>';
                 print '<td>';
                 //print "XX".$file['name'];	//$file['name'] must be utf8
                 print '<a data-ajax="false" href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart;
                 if ($forcedownload) {
                     print '&attachment=1';
                 }
                 if (!empty($object->entity)) {
                     print '&entity=' . $object->entity;
                 }
                 $filepath = $relativepath . $file['name'];
                 /* Restore old code: When file is at level 2+, full relative path (and not only level1) must be into url
                 			if ($file['level1name'] <> $object->id)
                 				$filepath=$object->id.'/'.$file['level1name'].'/'.$file['name'];
                 			else
                 				$filepath=$object->id.'/'.$file['name'];
                 			*/
                 print '&file=' . urlencode($filepath);
                 print '">';
                 print img_mime($file['name'], $file['name'] . ' (' . dol_print_size($file['size'], 0, 0) . ')') . ' ';
                 if ($showrelpart == 1) {
                     print $relativepath;
                 }
                 print dol_trunc($file['name'], $maxlength, 'middle');
                 print '</a>';
                 print "</td>\n";
                 print '<td align="right">' . dol_print_size($file['size'], 1, 1) . '</td>';
                 print '<td align="center">' . dol_print_date($file['date'], "dayhour", "tzuser") . '</td>';
                 // Preview
                 if (empty($useinecm)) {
                     $fileinfo = pathinfo($file['name']);
                     print '<td align="center">';
                     $minifile = $fileinfo['filename'] . '_mini.' . strtolower($fileinfo['extension']);
                     // Thumbs are created with filename in lower case
                     if (image_format_supported($file['name']) > 0) {
                         print '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&file=' . urlencode($relativepath . $fileinfo['filename'] . '.' . strtolower($fileinfo['extension'])) . '" class="aphoto" target="_blank">';
                         print '<img border="0" height="' . $maxheightmini . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&file=' . urlencode($relativepath . 'thumbs/' . $minifile) . '" title="">';
                         print '</a>';
                     } else {
                         print '&nbsp;';
                     }
                     print '</td>';
                 }
                 // Delete or view link
                 // ($param must start with &)
                 print '<td align="right">';
                 if ($useinecm) {
                     print '<a href="' . DOL_URL_ROOT . '/ecm/docfile.php?urlfile=' . urlencode($file['name']) . $param . '" class="editfilelink" rel="' . urlencode($file['name']) . '">' . img_view() . '</a> &nbsp; ';
                 } else {
                     if (image_format_supported($file['name']) > 0) {
                         $permtoedit = 0;
                         $newmodulepart = $modulepart;
                         if ($modulepart == 'product' || $modulepart == 'produit' || $modulepart == 'service') {
                             if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) {
                                 $permtoedit = 1;
                             }
                             if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) {
                                 $permtoedit = 1;
                             }
                             $newmodulepart = 'produit|service';
                         }
                         /* TODO Not yet working
                         			if ($modulepart == 'holiday')
                         			{
                         				if ($user->rights->holiday->write_all) $permtoedit=1;
                         			}
                         			*/
                         if (empty($conf->global->MAIN_UPLOAD_DOC)) {
                             $permtoedit = 0;
                         }
                         if ($permtoedit) {
                             // Link to resize
                             print '<a href="' . DOL_URL_ROOT . '/core/photos_resize.php?modulepart=' . urlencode($newmodulepart) . '&id=' . $object->id . '&file=' . urlencode($relativepath . $fileinfo['filename'] . '.' . strtolower($fileinfo['extension'])) . '" title="' . dol_escape_htmltag($langs->trans("Resize")) . '">' . img_picto($langs->trans("Resize"), DOL_URL_ROOT . '/theme/common/transform-crop-and-resize', '', 1) . '</a> &nbsp; ';
                         }
                     }
                 }
                 if ($permtodelete) {
                     /*
                     if ($file['level1name'] <> $object->id)
                     	$filepath=$file['level1name'].'/'.$file['name'];
                     else
                     	$filepath=$file['name'];
                     */
                     $useajax = 1;
                     if (!empty($conf->dol_use_jmobile)) {
                         $useajax = 0;
                     }
                     if (empty($conf->use_javascript_ajax)) {
                         $useajax = 0;
                     }
                     if (!empty($conf->global->MAIN_ECM_DISABLE_JS)) {
                         $useajax = 0;
                     }
                     print '<a href="' . ($useinecm && $useajax ? '#' : $url . '?action=delete&urlfile=' . urlencode($filepath) . $param) . '" class="deletefilelink" rel="' . $filepath . '">' . img_delete() . '</a>';
                 } else {
                     print '&nbsp;';
                 }
                 print "</td>";
                 print "</tr>\n";
             }
         }
         if ($nboffiles == 0) {
             print '<tr ' . $bc[false] . '><td colspan="' . (empty($useinecm) ? '5' : '4') . '">';
             if (empty($textifempty)) {
                 print $langs->trans("NoFileFound");
             } else {
                 print $textifempty;
             }
             print '</td></tr>';
         }
         print "</table>";
         return $nboffiles;
     }
 }
Exemplo n.º 3
0
        $object->localtax1_assuj	= $_POST["localtax1assuj_value"];
        $object->localtax2_assuj	= $_POST["localtax2assuj_value"];

        $object->tva_intra			= $_POST["tva_intra"];

        $object->commercial_id		= $_POST["commercial_id"];
        $object->default_lang		= $_POST["default_lang"];

        $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);

        // Gestion du logo de la société
        $dir     = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos";
        $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
        if ($file_OK)
        {
            if (image_format_supported($_FILES['photo']['name']))
            {
                dol_mkdir($dir);

                if (@is_dir($dir))
                {
                    $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
                    $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);

                    if (! $result > 0)
                    {
                        $errors[] = "ErrorFailedToSaveFile";
                    }
                    else
                    {
                        // Create small thumbs for company (Ratio is near 16/9)
Exemplo n.º 4
0
/**
 *    	Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
 *      If file is myfile.jpg, new file may be myfile_small.jpg
 *
 *    	@param     string	$file           	Path of source file to resize
 *    	@param     int		$maxWidth       	Largeur maximum que dois faire la miniature (-1=unchanged, 160 by default)
 *    	@param     int		$maxHeight      	Hauteur maximum que dois faire l'image (-1=unchanged, 120 by default)
 *    	@param     string	$extName        	Extension to differenciate thumb file name ('_small', '_mini')
 *    	@param     int		$quality        	Quality of compression (0=worst, 100=best)
 *      @param     string	$outdir           	Directory where to store thumb
 *      @param     int		$targetformat     	New format of target (1,2,3,... or 0 to keep old format)
 *    	@return    string						Full path of thumb or '' if it fails
 */
function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName = '_small', $quality = 50, $outdir = 'thumbs', $targetformat = 0)
{
    require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
    global $conf, $langs;
    dol_syslog("vignette file=" . $file . " extName=" . $extName . " maxWidth=" . $maxWidth . " maxHeight=" . $maxHeight . " quality=" . $quality . " outdir=" . $outdir . " targetformat=" . $targetformat);
    // Clean parameters
    $file = trim($file);
    // Check parameters
    if (!$file) {
        // Si le fichier n'a pas ete indique
        return 'ErrorBadParameters';
    } elseif (!file_exists($file)) {
        // Si le fichier passe en parametre n'existe pas
        dol_syslog($langs->trans("ErrorFileNotFound", $file), LOG_ERR);
        return $langs->trans("ErrorFileNotFound", $file);
    } elseif (image_format_supported($file) < 0) {
        dol_syslog('This file ' . $file . ' does not seem to be an image format file name.', LOG_WARNING);
        return 'ErrorBadImageFormat';
    } elseif (!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1) {
        // Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
        dol_syslog('Wrong value for parameter maxWidth', LOG_ERR);
        return 'Error: Wrong value for parameter maxWidth';
    } elseif (!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1) {
        // Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0)
        dol_syslog('Wrong value for parameter maxHeight', LOG_ERR);
        return 'Error: Wrong value for parameter maxHeight';
    }
    $fichier = realpath($file);
    // Chemin canonique absolu de l'image
    $dir = dirname($file);
    // Chemin du dossier contenant l'image
    $infoImg = getimagesize($fichier);
    // Recuperation des infos de l'image
    $imgWidth = $infoImg[0];
    // Largeur de l'image
    $imgHeight = $infoImg[1];
    // Hauteur de l'image
    if ($maxWidth == -1) {
        $maxWidth = $infoImg[0];
    }
    // If size is -1, we keep unchanged
    if ($maxHeight == -1) {
        $maxHeight = $infoImg[1];
    }
    // If size is -1, we keep unchanged
    // Si l'image est plus petite que la largeur et la hauteur max, on ne cree pas de vignette
    if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight) {
        // On cree toujours les vignettes
        dol_syslog("File size is smaller than thumb size", LOG_DEBUG);
        //return 'Le fichier '.$file.' ne necessite pas de creation de vignette';
    }
    $imgfonction = '';
    switch ($infoImg[2]) {
        case IMAGETYPE_GIF:
            // 1
            $imgfonction = 'imagecreatefromgif';
            break;
        case IMAGETYPE_JPEG:
            // 2
            $imgfonction = 'imagecreatefromjpeg';
            break;
        case IMAGETYPE_PNG:
            // 3
            $imgfonction = 'imagecreatefrompng';
            break;
        case IMAGETYPE_BMP:
            // 6
            // Not supported by PHP GD
            break;
        case IMAGETYPE_WBMP:
            // 15
            $imgfonction = 'imagecreatefromwbmp';
            break;
    }
    if ($imgfonction) {
        if (!function_exists($imgfonction)) {
            // Fonctions de conversion non presente dans ce PHP
            return 'Error: Creation of thumbs not possible. This PHP does not support GD function ' . $imgfonction;
        }
    }
    // On cree le repertoire contenant les vignettes
    $dirthumb = $dir . ($outdir ? '/' . $outdir : '');
    // Chemin du dossier contenant les vignettes
    dol_mkdir($dirthumb);
    // Initialisation des variables selon l'extension de l'image
    switch ($infoImg[2]) {
        case IMAGETYPE_GIF:
            // 1
            $img = imagecreatefromgif($fichier);
            $extImg = '.gif';
            // Extension de l'image
            break;
        case IMAGETYPE_JPEG:
            // 2
            $img = imagecreatefromjpeg($fichier);
            $extImg = preg_match('/\\.jpeg$/', $file) ? '.jpeg' : '.jpg';
            // Extension de l'image
            break;
        case IMAGETYPE_PNG:
            // 3
            $img = imagecreatefrompng($fichier);
            $extImg = '.png';
            break;
        case IMAGETYPE_BMP:
            // 6
            // Not supported by PHP GD
            $extImg = '.bmp';
            break;
        case IMAGETYPE_WBMP:
            // 15
            $img = imagecreatefromwbmp($fichier);
            $extImg = '.bmp';
            break;
    }
    if (!is_resource($img)) {
        dol_syslog('Failed to detect type of image. We found infoImg[2]=' . $infoImg[2], LOG_WARNING);
        return 0;
    }
    // Initialisation des dimensions de la vignette si elles sont superieures a l'original
    if ($maxWidth > $imgWidth) {
        $maxWidth = $imgWidth;
    }
    if ($maxHeight > $imgHeight) {
        $maxHeight = $imgHeight;
    }
    $whFact = $maxWidth / $maxHeight;
    // Facteur largeur/hauteur des dimensions max de la vignette
    $imgWhFact = $imgWidth / $imgHeight;
    // Facteur largeur/hauteur de l'original
    // Fixe les dimensions de la vignette
    if ($whFact < $imgWhFact) {
        // Si largeur determinante
        $thumbWidth = $maxWidth;
        $thumbHeight = $thumbWidth / $imgWhFact;
    } else {
        // Si hauteur determinante
        $thumbHeight = $maxHeight;
        $thumbWidth = $thumbHeight * $imgWhFact;
    }
    $thumbHeight = round($thumbHeight);
    $thumbWidth = round($thumbWidth);
    // Define target format
    if (empty($targetformat)) {
        $targetformat = $infoImg[2];
    }
    // Create empty image
    if ($targetformat == IMAGETYPE_GIF) {
        // Compatibilite image GIF
        $imgThumb = imagecreate($thumbWidth, $thumbHeight);
    } else {
        $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
    }
    // Activate antialiasing for better quality
    if (function_exists('imageantialias')) {
        imageantialias($imgThumb, true);
    }
    // This is to keep transparent alpha channel if exists (PHP >= 4.2)
    if (function_exists('imagesavealpha')) {
        imagesavealpha($imgThumb, true);
    }
    // Initialisation des variables selon l'extension de l'image
    switch ($targetformat) {
        case IMAGETYPE_GIF:
            // 1
            $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255);
            // On procede autrement pour le format GIF
            imagecolortransparent($imgThumb, $trans_colour);
            $extImgTarget = '.gif';
            $newquality = 'NU';
            break;
        case IMAGETYPE_JPEG:
            // 2
            $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
            $extImgTarget = preg_match('/\\.jpeg$/', $file) ? '.jpeg' : '.jpg';
            $newquality = $quality;
            break;
        case IMAGETYPE_PNG:
            // 3
            imagealphablending($imgThumb, false);
            // Pour compatibilite sur certain systeme
            $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127);
            // Keep transparent channel
            $extImgTarget = '.png';
            $newquality = $quality - 100;
            $newquality = round(abs($quality - 100) * 9 / 100);
            break;
        case IMAGETYPE_BMP:
            // 6
            // Not supported by PHP GD
            $extImgTarget = '.bmp';
            $newquality = 'NU';
            break;
        case IMAGETYPE_WBMP:
            // 15
            $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0);
            $extImgTarget = '.bmp';
            $newquality = 'NU';
            break;
    }
    if (function_exists("imagefill")) {
        imagefill($imgThumb, 0, 0, $trans_colour);
    }
    dol_syslog("vignette: convert image from ({$imgWidth} x {$imgHeight}) to ({$thumbWidth} x {$thumbHeight}) as {$extImg}, newquality={$newquality}");
    //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee
    imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight);
    // Insere l'image de base redimensionnee
    $fileName = preg_replace('/(\\.gif|\\.jpeg|\\.jpg|\\.png|\\.bmp)$/i', '', $file);
    // On enleve extension quelquesoit la casse
    $fileName = basename($fileName);
    $imgThumbName = $dirthumb . '/' . $fileName . $extName . $extImgTarget;
    // Chemin complet du fichier de la vignette
    // Check if permission are ok
    //$fp = fopen($imgThumbName, "w");
    //fclose($fp);
    // Create image on disk
    switch ($targetformat) {
        case IMAGETYPE_GIF:
            // 1
            imagegif($imgThumb, $imgThumbName);
            break;
        case IMAGETYPE_JPEG:
            // 2
            imagejpeg($imgThumb, $imgThumbName, $newquality);
            break;
        case IMAGETYPE_PNG:
            // 3
            imagepng($imgThumb, $imgThumbName, $newquality);
            break;
        case IMAGETYPE_BMP:
            // 6
            // Not supported by PHP GD
            break;
        case IMAGETYPE_WBMP:
            // 15
            image2wbmp($imgThumb, $imgThumbName);
            break;
    }
    // Set permissions on file
    if (!empty($conf->global->MAIN_UMASK)) {
        @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK));
    }
    // Free memory. This does not delete image.
    imagedestroy($img);
    imagedestroy($imgThumb);
    return $imgThumbName;
}
Exemplo n.º 5
0
/**
 * Get and save an upload file (for example after submitting a new file a mail form).
 * All information used are in db, conf, langs, user and _FILES.
 * Note: This function can be used only into a HTML page context.
 *
 * @param	string	$upload_dir				Directory where to store uploaded file (note: also find in first part of dest_file)
 * @param	int		$allowoverwrite			1=Allow overwrite existing file
 * @param	int		$donotupdatesession		1=Do no edit _SESSION variable
 * @param	string	$varfiles				_FILES var name
 * @param	string	$savingdocmask			Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__'
 * @param	string	$link					Link to add
 * @return	void
 */
function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles = 'addedfile', $savingdocmask = '', $link = null)
{
    global $db, $user, $conf, $langs;
    if (!empty($_FILES[$varfiles])) {
        dol_syslog('dol_add_file_process upload_dir=' . $upload_dir . ' allowoverwrite=' . $allowoverwrite . ' donotupdatesession=' . $donotupdatesession . ' savingdocmask=' . $savingdocmask, LOG_DEBUG);
        if (dol_mkdir($upload_dir) >= 0) {
            $TFile = $_FILES[$varfiles];
            if (!is_array($TFile['name'])) {
                foreach ($TFile as $key => &$val) {
                    $val = array($val);
                }
            }
            $nbfile = count($TFile['name']);
            for ($i = 0; $i < $nbfile; $i++) {
                // Define $destpath (path to file including filename) and $destfile (only filename)
                $destpath = $upload_dir . "/" . $TFile['name'][$i];
                $destfile = $TFile['name'][$i];
                $savingdocmask = dol_sanitizeFileName($savingdocmask);
                if ($savingdocmask) {
                    $destpath = $upload_dir . "/" . preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask);
                    $destfile = preg_replace('/__file__/', $TFile['name'][$i], $savingdocmask);
                }
                $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destpath, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles);
                if (is_numeric($resupload) && $resupload > 0) {
                    global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
                    include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';
                    if (empty($donotupdatesession)) {
                        include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php';
                        $formmail = new FormMail($db);
                        $formmail->add_attached_files($destpath, $destfile, $TFile['type'][$i]);
                    }
                    if (image_format_supported($destpath) == 1) {
                        // Create small thumbs for image (Ratio is near 16/9)
                        // Used on logon for example
                        $imgThumbSmall = vignette($destpath, $maxwidthsmall, $maxheigthsmall, '_small', 50, "thumbs");
                        // Create mini thumbs for image (Ratio is near 16/9)
                        // Used on menu or for setup page for example
                        $imgThumbMini = vignette($destpath, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
                    }
                    setEventMessages($langs->trans("FileTransferComplete"), null, 'mesgs');
                } else {
                    $langs->load("errors");
                    if ($resupload < 0) {
                        setEventMessages($langs->trans("ErrorFileNotUploaded"), null, 'errors');
                    } else {
                        if (preg_match('/ErrorFileIsInfectedWithAVirus/', $resupload)) {
                            setEventMessages($langs->trans("ErrorFileIsInfectedWithAVirus"), null, 'errors');
                        } else {
                            setEventMessages($langs->trans($resupload), null, 'errors');
                        }
                    }
                }
            }
        }
    } elseif ($link) {
        if (dol_mkdir($upload_dir) >= 0) {
            require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
            $linkObject = new Link($db);
            $linkObject->entity = $conf->entity;
            $linkObject->url = $link;
            $linkObject->objecttype = GETPOST('objecttype', 'alpha');
            $linkObject->objectid = GETPOST('objectid', 'int');
            $linkObject->label = GETPOST('label', 'alpha');
            $res = $linkObject->create($user);
            $langs->load('link');
            if ($res > 0) {
                setEventMessages($langs->trans("LinkComplete"), null, 'mesgs');
            } else {
                setEventMessages($langs->trans("ErrorFileNotLinked"), null, 'errors');
            }
        }
    } else {
        $langs->load("errors");
        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("File")), null, 'errors');
    }
}
Exemplo n.º 6
0
if ($user->societe_id) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
$mesg = '';
$object = new Product($db);
if ($id > 0 || !empty($ref)) {
    $result = $object->fetch($id, $ref);
    $dir = !empty($conf->product->multidir_output[$object->entity]) ? $conf->product->multidir_output[$object->entity] : $conf->service->multidir_output[$object->entity];
}
/*
 * Actions
 */
if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && GETPOST('sendit') && !empty($conf->global->MAIN_UPLOAD_DOC)) {
    if ($object->id) {
        if (image_format_supported($_FILES['userfile']['name']) >= 1) {
            $result = $object->add_photo($dir, $_FILES['userfile']);
            if ($result > 0) {
                setEventMessage($langs->trans("FileUploaded"));
            } else {
                setEventMessage($langs->trans("FileNotUploaded"), 'errors');
            }
        } else {
            $langs->load("errors");
            setEventMessage($langs->trans("ErrorBadImageFormat"), 'errors');
        }
    }
}
if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer)) {
    $object->delete_photo($dir . "/" . $_GET["file"]);
}
Exemplo n.º 7
0
     $isimage = image_format_supported($_GET["file"]);
     // Create thumbs of logo
     if ($isimage > 0) {
         // Create small thumbs for company (Ratio is near 16/9)
         // Used on logon for example
         $imgThumbSmall = vignette($conf->mycompany->dir_output . '/logos/' . $_GET["file"], $maxwidthsmall, $maxheightsmall, '_small', $quality);
         if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbSmall, $reg)) {
             $imgThumbSmall = $reg[1];
             dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL", $imgThumbSmall, 'chaine', 0, '', $conf->entity);
         } else {
             dol_syslog($imgThumbSmall);
         }
         // Create mini thumbs for company (Ratio is near 16/9)
         // Used on menu or for setup page for example
         $imgThumbMini = vignette($conf->mycompany->dir_output . '/logos/' . $_GET["file"], $maxwidthmini, $maxheightmini, '_mini', $quality);
         if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i', $imgThumbMini, $reg)) {
             $imgThumbMini = $reg[1];
             dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI", $imgThumbMini, 'chaine', 0, '', $conf->entity);
         } else {
             dol_syslog($imgThumbMini);
         }
         Header("Location: " . $_SERVER["PHP_SELF"]);
         exit;
     } else {
         $message .= '<div class="error">' . $langs->trans("ErrorImageFormatNotSupported") . '</div>';
         dol_syslog($langs->transnoentities("ErrorImageFormatNotSupported"), LOG_WARNING);
     }
 } else {
     $message .= '<div class="error">' . $langs->trans("ErrorFileDoesNotExists", $_GET["file"]) . '</div>';
     dol_syslog($langs->transnoentities("ErrorFileDoesNotExists", $_GET["file"]), LOG_WARNING);
 }
Exemplo n.º 8
0
 /**
  *  Show list of documents in a directory
  *
  *  @param	 array	$filearray          Array of files loaded by dol_dir_list('files') function before calling this
  * 	@param	 Object	$object				Object on which document is linked to
  * 	@param	 string	$modulepart			Value for modulepart used by download or viewimage wrapper
  * 	@param	 string	$param				Parameters on sort links
  * 	@param	 int	$forcedownload		Force to open dialog box "Save As" when clicking on file
  * 	@param	 string	$relativepath		Relative path of docs (autodefined if not provided)
  * 	@param	 int	$permtodelete		Permission to delete
  * 	@param	 int	$useinecm			Change output for use in ecm module
  * 	@param	 string	$textifempty		Text to show if filearray is empty ('NoFileFound' if not defined)
  *  @param  int		$maxlength          Maximum length of file name shown
  *  @param	 string	$title				Title before list
  *  @param	 string $url				Full url to use for click links ('' = autodetect)
  * 	@return	 int						<0 if KO, nb of files shown if OK
  */
 function list_of_documents($filearray, $object, $modulepart, $param, $forcedownload = 0, $relativepath = '', $permtodelete = 1, $useinecm = 0, $textifempty = '', $maxlength = 0, $title = '', $url = '')
 {
     global $user, $conf, $langs;
     global $bc;
     global $sortfield, $sortorder, $maxheightmini;
     // Show list of existing files
     if (empty($useinecm)) {
         print_titre($title ? $title : $langs->trans("AttachedFiles"));
     }
     if (empty($url)) {
         $url = $_SERVER["PHP_SELF"];
     }
     print '<table width="100%" class="' . ($useinecm ? 'nobordernopadding' : 'liste') . '">';
     print '<tr class="liste_titre">';
     print_liste_field_titre($langs->trans("Documents2"), $url, "name", "", $param, 'align="left"', $sortfield, $sortorder);
     print_liste_field_titre($langs->trans("Size"), $url, "size", "", $param, 'align="right"', $sortfield, $sortorder);
     print_liste_field_titre($langs->trans("Date"), $url, "date", "", $param, 'align="center"', $sortfield, $sortorder);
     if (empty($useinecm)) {
         print_liste_field_titre('', $url, "", "", $param, 'align="center"');
     }
     print_liste_field_titre('', '', '');
     print '</tr>';
     $nboffiles = count($filearray);
     if ($nboffiles > 0) {
         include_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';
     }
     $var = true;
     foreach ($filearray as $key => $file) {
         if ($file['name'] != '.' && $file['name'] != '..' && $file['name'] != 'CVS' && !preg_match('/\\.meta$/i', $file['name'])) {
             // Define relative path used to store the file
             if (!$relativepath) {
                 $relativepath = dol_sanitizeFileName($object->ref) . '/';
             }
             $var = !$var;
             print '<tr ' . $bc[$var] . '>';
             print '<td>';
             //print "XX".$file['name'];	//$file['name'] must be utf8
             print '<a href="' . DOL_URL_ROOT . '/document.php?modulepart=' . $modulepart;
             if ($forcedownload) {
                 print '&attachment=1';
             }
             if (!empty($object->entity)) {
                 print '&entity=' . $object->entity;
             }
             print '&file=' . urlencode($relativepath . $file['name']) . '">';
             print img_mime($file['name'], $file['name'] . ' (' . dol_print_size($file['size'], 0, 0) . ')') . ' ';
             print dol_trunc($file['name'], $maxlength, 'middle');
             print '</a>';
             print "</td>\n";
             print '<td align="right">' . dol_print_size($file['size'], 1, 1) . '</td>';
             print '<td align="center">' . dol_print_date($file['date'], "dayhour") . '</td>';
             // Preview
             if (empty($useinecm)) {
                 print '<td align="center">';
                 $tmp = explode('.', $file['name']);
                 $minifile = $tmp[0] . '_mini.' . $tmp[1];
                 if (image_format_supported($file['name']) > 0) {
                     print '<img border="0" height="' . $maxheightmini . '" src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&file=' . urlencode($relativepath . 'thumbs/' . $minifile) . '" title="">';
                 } else {
                     print '&nbsp;';
                 }
                 print '</td>';
             }
             // Delete or view link
             print '<td align="right">';
             if ($useinecm) {
                 print '<a href="' . DOL_URL_ROOT . '/ecm/docfile.php?urlfile=' . urlencode($file['name']) . $param . '" class="editfilelink" rel="' . urlencode($file['name']) . '">' . img_view() . '</a> &nbsp; ';
             }
             if ($permtodelete) {
                 print '<a href="' . ($useinecm && !empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE_JS) ? '#' : $url . '?id=' . $object->id . '&action=delete&urlfile=' . urlencode($file['name']) . $param) . '" class="deletefilelink" rel="' . urlencode($file['name']) . '">' . img_delete() . '</a>';
             } else {
                 print '&nbsp;';
             }
             print "</td>";
             print "</tr>\n";
         }
     }
     if ($nboffiles == 0) {
         print '<tr ' . $bc[$var] . '><td colspan="' . (empty($useinecm) ? '5' : '4') . '">';
         if (empty($textifempty)) {
             print $langs->trans("NoFileFound");
         } else {
             print $textifempty;
         }
         print '</td></tr>';
     }
     print "</table>";
     return $nboffiles;
 }