From 94788e2ccb40dc8e3a0947f0d54ecb02ea54b4ae Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 6 Apr 2012 22:39:40 +0200 Subject: [PATCH] Fix: compatibility with multicompany sharings use new $conf->product->dir_output[$object->entity] instead $conf->product->dir_output --- htdocs/core/class/commonobject.class.php | 6 +- htdocs/core/class/conf.class.php | 32 ++- htdocs/core/class/html.formfile.class.php | 1 + htdocs/core/photos_resize.php | 78 +++--- htdocs/document.php | 4 +- htdocs/fourn/product/photos.php | 59 +++-- .../product/actions_card_product.class.php | 4 +- .../canvas/product/tpl/card_view.tpl.php | 2 +- htdocs/product/class/product.class.php | 101 ++++---- htdocs/product/document.php | 51 ++-- htdocs/product/fiche.php | 226 ++++++++--------- htdocs/product/photos.php | 239 +++++++++--------- htdocs/product/price.php | 4 +- htdocs/product/stats/fiche.php | 4 +- htdocs/viewimage.php | 12 +- 15 files changed, 397 insertions(+), 426 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index cfae5385e30..ac01cfd5bba 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1873,9 +1873,9 @@ abstract class CommonObject $sql = "SELECT rowid, canvas"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " WHERE entity = ".$conf->entity; - if (!empty($id)) $sql.= " AND rowid = ".$id; - if (!empty($ref)) $sql.= " AND ref = '".$ref."'"; + $sql.= " WHERE entity IN (".getEntity($this->element, 1).")"; + if (! empty($id)) $sql.= " AND rowid = ".$id; + if (! empty($ref)) $sql.= " AND ref = '".$ref."'"; $resql = $this->db->query($sql); if ($resql) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 3f1e3bf94a6..ac0d2ed72e1 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -213,6 +213,14 @@ class Conf //var_dump($this->modules); //var_dump($this->modules_parts); + // Object $mc + if (! defined('NOREQUIREMC') && ! empty($this->multicompany->enabled)) + { + global $mc; + $ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php'); + if ($ret) $mc = new ActionsMulticompany($db); + } + // Second or others levels object $this->propal->cloture = (object) array(); $this->propal->facturation = (object) array(); @@ -252,12 +260,9 @@ class Conf $rootfordata = DOL_DATA_ROOT; $rootforuser = DOL_DATA_ROOT; // If multicompany module is enabled, we redefine the root of data - if (! empty($this->global->MAIN_MODULE_MULTICOMPANY) && ! empty($this->entity) && $this->entity > 1) + if (! empty($this->multicompany->enabled) && ! empty($this->entity) && $this->entity > 1) { $rootfordata.='/'.$this->entity; - //var_dump($mc->sharings); - //var_dump($mc->referent); - //var_dump($mc->entities); } // For backward compatibility @@ -301,10 +306,10 @@ class Conf $this->fournisseur->facture->dir_output =$rootfordata."/fournisseur/facture"; $this->fournisseur->facture->dir_temp =$rootfordata."/fournisseur/facture/temp"; // Module product/service - $this->product->dir_output=$rootfordata."/produit"; - $this->product->dir_temp =$rootfordata."/produit/temp"; - $this->service->dir_output=$rootfordata."/produit"; - $this->service->dir_temp =$rootfordata."/produit/temp"; + $this->product->dir_output=array($this->entity => $rootfordata."/produit"); + $this->product->dir_temp =array($this->entity => $rootfordata."/produit/temp"); + $this->service->dir_output=array($this->entity => $rootfordata."/produit"); + $this->service->dir_temp =array($this->entity => $rootfordata."/produit/temp"); // Module contrat $this->contrat->dir_output=$rootfordata."/contracts"; $this->contrat->dir_temp =$rootfordata."/contracts/temp"; @@ -423,15 +428,8 @@ class Conf // Object $mc if (! defined('NOREQUIREMC') && ! empty($this->multicompany->enabled)) - { - global $mc; - - $ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php'); - if ($ret) - { - $mc = new ActionsMulticompany($db); - $mc->setValues($this); - } + { + if (is_object($mc)) $mc->setValues($this); } } } diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 1eee2e85b70..34ecea9488b 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -587,6 +587,7 @@ class FormFile //print "XX".$file['name']; //$file['name'] must be utf8 print ''; print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')').' '; print dol_trunc($file['name'],$maxlength,'middle'); diff --git a/htdocs/core/photos_resize.php b/htdocs/core/photos_resize.php index 02aee4ca100..46cd33e57a9 100644 --- a/htdocs/core/photos_resize.php +++ b/htdocs/core/photos_resize.php @@ -1,6 +1,7 @@ - * Copyright (C) 2009 Meos +/* Copyright (C) 2010-2011 Laurent Destailleur + * Copyright (C) 2009 Meos + * Copyright (C) 2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,25 +42,19 @@ require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); $langs->load("products"); $langs->load("other"); -$modulepart=$_REQUEST['modulepart']?$_REQUEST['modulepart']:'produit|service'; -if (isset($_GET["id"])) -{ - $id = isset($_GET["id"])?$_GET["id"]:''; -} +$id=GETPOST('id','int'); +$action=GETPOST('action','alpha'); +$modulepart=GETPOST('modulepart','alpha')?GETPOST('modulepart','alpha'):'produit|service'; $original_file = isset($_REQUEST["file"])?urldecode($_REQUEST["file"]):''; - // Security check if (empty($modulepart)) accessforbidden('Bad value for modulepart'); $accessallowed=0; -if ($modulepart) +if ($modulepart=='produit|service') { - if ($modulepart=='produit|service') - { - $result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid); - if ($modulepart=='produit|service' && (! $user->rights->produit->lire && ! $user->rights->service->lire)) accessforbidden(); - $accessallowed=1; - } + $result=restrictedArea($user,'produit|service',$id,'product&product'); + if ($modulepart=='produit|service' && (! $user->rights->produit->lire && ! $user->rights->service->lire)) accessforbidden(); + $accessallowed=1; } // Security: @@ -69,60 +64,52 @@ if (! $accessallowed) accessforbidden(); } - +$object = new Product($db); +if ($id > 0) +{ + $result = $object->fetch($id); + if ($result <= 0) dol_print_error($db,'Failed to load object'); + $dir=$conf->product->dir_output[$object->entity]; // By default + if ($object->type == 0) $dir=$conf->product->dir_output[$object->entity]; + if ($object->type == 1) $dir=$conf->service->dir_output[$object->entity]; +} /* * Actions */ -if ($_POST["action"] == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POST["sizex"]) != "") && (isset($_POST["sizey"]) != "")) +if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POST["sizex"]) != "") && (isset($_POST["sizey"]) != "")) { - $product=new Product($db); - $result=$product->fetch($_POST["id"]); - if ($result <= 0) dol_print_error($db,'Failed to load object'); - $dir=$conf->product->dir_output; // By default - if ($product->type == 0) $dir=$conf->product->dir_output; - if ($product->type == 1) $dir=$conf->service->dir_output; - $fullpath=$dir."/".$original_file; $result=dol_imageResizeOrCrop($fullpath,0,$_POST['sizex'],$_POST['sizey']); if ($result == $fullpath) { - header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$_POST["id"].'&action=addthumb&file='.urldecode($_POST["file"])); + header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$id.'&action=addthumb&file='.urldecode($_POST["file"])); exit; } else { $mesg=$result; $_GET['file']=$_POST["file"]; - $_GET['id']=$_POST["id"]; } } // Crop d'une image -if ($_POST["action"] == 'confirm_crop') +if ($action == 'confirm_crop') { - $product=new Product($db); - $result=$product->fetch($_POST["id"]); - if ($result <= 0) dol_print_error($db,'Failed to load object'); - $dir=$conf->product->dir_output; // By default - if ($product->type == 0) $dir=$conf->product->dir_output; - if ($product->type == 1) $dir=$conf->service->dir_output; - $fullpath=$dir."/".$original_file; $result=dol_imageResizeOrCrop($fullpath,1,$_POST['w'],$_POST['h'],$_POST['x'],$_POST['y']); if ($result == $fullpath) { - header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$_POST["id"].'&action=addthumb&file='.urldecode($_POST["file"])); + header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$id.'&action=addthumb&file='.urldecode($_POST["file"])); exit; } else { $mesg=$result; $_GET['file']=$_POST["file"]; - $_GET['id']=$_POST["id"]; } } @@ -138,7 +125,7 @@ print_fiche_titre($langs->trans("ImageEditor")); if ($mesg) print '
'.$mesg.'
'; -$infoarray=dol_getImageSize($conf->product->dir_output."/".urldecode($_GET["file"])); +$infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"])); $height=$infoarray['height']; $width=$infoarray['width']; print $langs->trans("CurrentInformationOnImage").':'; @@ -150,7 +137,7 @@ print '
    print '
    '."\n"; print ''."\n"; -print '
    '; +print ''; print '
    '; print ''.$langs->trans("Resize").''; @@ -159,8 +146,8 @@ print $langs->trans("NewLength").': trans("NewHeight").': px  
    '; print ''; print ''; -print ''; -print ''; +print ''; +print ''; print '
    '; print '
    '; print '
    '; @@ -174,7 +161,7 @@ print '
    '."\n"; if (! empty($conf->use_javascript_ajax)) { -$infoarray=dol_getImageSize($conf->product->dir_output."/".urldecode($_GET["file"])); +$infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"])); $height=$infoarray['height']; $width=$infoarray['width']; @@ -183,9 +170,9 @@ print '
    '; print ''.$langs->trans("Recenter").''; print $langs->trans("DefineNewAreaToPick").'...
    '; print '
    '; -print '
    '; +print '
    '; print '

    '; -print '
    +print '
    '.$langs->trans("NewSizeAfterCropping").': @@ -198,8 +185,8 @@ print ' - - + +
    '; print '
    '; @@ -208,4 +195,5 @@ print ''; llxFooter(); +$db->close(); ?> diff --git a/htdocs/document.php b/htdocs/document.php index 5fb795dcb70..b62bd0f9c8a 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -310,8 +310,8 @@ if ($modulepart) { $accessallowed=1; } - if ($conf->product->enabled) $original_file=$conf->product->dir_output.'/'.$original_file; - elseif ($conf->service->enabled) $original_file=$conf->service->dir_output.'/'.$original_file; + if ($conf->product->enabled) $original_file=$conf->product->dir_output[GETPOST('entity','int')].'/'.$original_file; + elseif ($conf->service->enabled) $original_file=$conf->service->dir_output[GETPOST('entity','int')].'/'.$original_file; } // Wrapping pour les contrats diff --git a/htdocs/fourn/product/photos.php b/htdocs/fourn/product/photos.php index 5e617a2c001..140f608a54f 100644 --- a/htdocs/fourn/product/photos.php +++ b/htdocs/fourn/product/photos.php @@ -25,9 +25,12 @@ require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); +$id = GETPOST('id', 'int'); if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbidden(); +$object = new Product($db); + /* * View @@ -35,12 +38,11 @@ if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbid if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) { - if ($_GET["id"]) + if ($id) { - $product = new Product($db); - $result = $product->fetch($_GET["id"]); + $result = $object->fetch($id); - $product->add_photo($conf->product->dir_output, $_FILES['photofile']); + $object->add_photo($conf->product->dir_output[$object->entity], $_FILES['photofile']); } } /* @@ -51,10 +53,9 @@ llxHeader("","",$langs->trans("CardProduct0")); /* * Fiche produit */ -if ($_GET["id"]) +if ($id) { - $product = new Product($db); - $result = $product->fetch($_GET["id"]); + $result = $object->fetch($id); if ( $result ) { @@ -64,56 +65,56 @@ if ($_GET["id"]) $h=0; - $head[$h][0] = DOL_URL_ROOT."/fourn/product/fiche.php?id=".$product->id; + $head[$h][0] = DOL_URL_ROOT."/fourn/product/fiche.php?id=".$object->id; $head[$h][1] = $langs->trans("Card"); $h++; if ($conf->stock->enabled) { - $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id; + $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$object->id; $head[$h][1] = $langs->trans("Stock"); $h++; } - $head[$h][0] = DOL_URL_ROOT."/fourn/product/photos.php?id=".$product->id; + $head[$h][0] = DOL_URL_ROOT."/fourn/product/photos.php?id=".$object->id; $head[$h][1] = $langs->trans("Photos"); $hselected = $h; $h++; - //Affichage onglet Cat�gories + //Affichage onglet Categories if ($conf->categorie->enabled){ - $head[$h][0] = DOL_URL_ROOT."/fourn/product/categorie.php?id=".$product->id; + $head[$h][0] = DOL_URL_ROOT."/fourn/product/categorie.php?id=".$object->id; $head[$h][1] = $langs->trans('Categories'); $h++; } - $head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$product->id; + $head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$object->id; $head[$h][1] = $langs->trans("CommercialCard"); $h++; - dol_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); + dol_fiche_head($head, $hselected, $langs->trans("CardProduct".$object->type).' : '.$object->ref); print($mesg); print ''; print ""; - print ''; + print ''; print ''; - print ''; - print ''; + print ''; + print ''; print "
    '.$langs->trans("Ref").''.$product->ref.''.$langs->trans("Ref").''.$object->ref.''; - print $product->getLibStatut(2); + print $object->getLibStatut(2); print '
    '.$langs->trans("Label").''.$product->libelle.''.$langs->trans("SellingPrice").''.price($product->price).'
    '.$langs->trans("Label").''.$object->libelle.''.$langs->trans("SellingPrice").''.price($object->price).'

    \n"; /* * Ajouter une photo * */ - if ($_GET["action"] == 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC)) + if ($action == 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC)) { print_titre($langs->trans("AddPhoto")); - print '
    '; + print ''; print ''; print ''; @@ -132,17 +133,17 @@ if ($_GET["id"]) // Affiche photos - if ($_GET["action"] != 'ajout_photo') + if ($action != 'ajout_photo') { $nbphoto=0; $nbbyrow=5; - $pdir = get_exdir($product->id,2) . $product->id ."/photos/"; - $dir = $conf->product->dir_output . '/'. $pdir; + $pdir = get_exdir($object->id,2) . $object->id ."/photos/"; + $dir = $conf->product->dir_output[$object->entity] . '/'. $pdir; print '
    '; - foreach ($product->liste_photos($dir) as $obj) + foreach ($object->liste_photos($dir) as $obj) { $nbphoto++; @@ -162,7 +163,7 @@ if ($_GET["id"]) print '
    '.$langs->trans("File").': '.dol_trunc($filename,16); if ($user->rights->produit->creer || $user->rights->service->creer) { - print '
    '.img_delete().''; + print '
    '.img_delete().''; } if ($nbbyrow) print ''; if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print ''; @@ -192,11 +193,11 @@ if ($_GET["id"]) print "\n
    \n"; - if ($_GET["action"] == '') + if ($action == '') { if (($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC)) { - print ''; + print 'id.'">'; print $langs->trans("AddPhoto").''; } } @@ -210,8 +211,6 @@ else } - -$db->close(); - llxFooter(); +$db->close(); ?> diff --git a/htdocs/product/canvas/product/actions_card_product.class.php b/htdocs/product/canvas/product/actions_card_product.class.php index 8b63af356b6..209782a1fd2 100755 --- a/htdocs/product/canvas/product/actions_card_product.class.php +++ b/htdocs/product/canvas/product/actions_card_product.class.php @@ -213,9 +213,9 @@ class ActionsCardProduct extends Product // Photo $this->tpl['nblignes'] = 4; - if ($this->object->is_photo_available($conf->product->dir_output)) + if ($this->object->is_photo_available($conf->product->dir_output[$this->object->entity])) { - $this->tpl['photos'] = $this->object->show_photos($conf->product->dir_output,1,1,0,0,0,80); + $this->tpl['photos'] = $this->object->show_photos($conf->product->dir_output[$this->object->entity],1,1,0,0,0,80); } // Nature diff --git a/htdocs/product/canvas/product/tpl/card_view.tpl.php b/htdocs/product/canvas/product/tpl/card_view.tpl.php index f6cb1470bf4..d8b02863ee1 100755 --- a/htdocs/product/canvas/product/tpl/card_view.tpl.php +++ b/htdocs/product/canvas/product/tpl/card_view.tpl.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index fe16b356b00..8380d390a96 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1015,7 +1015,7 @@ class Product extends CommonObject $sql.= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas,"; $sql.= " weight, weight_units, length, length_units, surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,"; $sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,"; - $sql.= " datec, tms, import_key"; + $sql.= " datec, tms, import_key, entity"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; if ($id) $sql.= " WHERE rowid = '".$id."'"; else @@ -1031,60 +1031,61 @@ class Product extends CommonObject { if ($this->db->num_rows($resql) > 0) { - $object = $this->db->fetch_object($resql); + $obj = $this->db->fetch_object($resql); - $this->id = $object->rowid; - $this->ref = $object->ref; - $this->libelle = $object->label; // TODO deprecated - $this->label = $object->label; - $this->description = $object->description; - $this->note = $object->note; + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->libelle = $obj->label; // TODO deprecated + $this->label = $obj->label; + $this->description = $obj->description; + $this->note = $obj->note; - $this->type = $object->fk_product_type; - $this->status = $object->tosell; - $this->status_buy = $object->tobuy; + $this->type = $obj->fk_product_type; + $this->status = $obj->tosell; + $this->status_buy = $obj->tobuy; - $this->customcode = $object->customcode; - $this->country_id = $object->fk_country; - $this->country_code = getCountry($this->country_id,2,$this->db); - $this->price = $object->price; - $this->price_ttc = $object->price_ttc; - $this->price_min = $object->price_min; - $this->price_min_ttc = $object->price_min_ttc; - $this->price_base_type = $object->price_base_type; - $this->tva_tx = $object->tva_tx; + $this->customcode = $obj->customcode; + $this->country_id = $obj->fk_country; + $this->country_code = getCountry($this->country_id,2,$this->db); + $this->price = $obj->price; + $this->price_ttc = $obj->price_ttc; + $this->price_min = $obj->price_min; + $this->price_min_ttc = $obj->price_min_ttc; + $this->price_base_type = $obj->price_base_type; + $this->tva_tx = $obj->tva_tx; //! French VAT NPR - $this->tva_npr = $object->tva_npr; + $this->tva_npr = $obj->tva_npr; //! Spanish local taxes - $this->localtax1_tx = $object->localtax1_tx; - $this->localtax2_tx = $object->localtax2_tx; + $this->localtax1_tx = $obj->localtax1_tx; + $this->localtax2_tx = $obj->localtax2_tx; - $this->finished = $object->finished; - $this->duration = $object->duration; - $this->duration_value = substr($object->duration,0,dol_strlen($object->duration)-1); - $this->duration_unit = substr($object->duration,-1); - $this->canvas = $object->canvas; - $this->weight = $object->weight; - $this->weight_units = $object->weight_units; - $this->length = $object->length; - $this->length_units = $object->length_units; - $this->surface = $object->surface; - $this->surface_units = $object->surface_units; - $this->volume = $object->volume; - $this->volume_units = $object->volume_units; - $this->barcode = $object->barcode; - $this->barcode_type = $object->fk_barcode_type; + $this->finished = $obj->finished; + $this->duration = $obj->duration; + $this->duration_value = substr($obj->duration,0,dol_strlen($obj->duration)-1); + $this->duration_unit = substr($obj->duration,-1); + $this->canvas = $obj->canvas; + $this->weight = $obj->weight; + $this->weight_units = $obj->weight_units; + $this->length = $obj->length; + $this->length_units = $obj->length_units; + $this->surface = $obj->surface; + $this->surface_units = $obj->surface_units; + $this->volume = $obj->volume; + $this->volume_units = $obj->volume_units; + $this->barcode = $obj->barcode; + $this->barcode_type = $obj->fk_barcode_type; - $this->accountancy_code_buy = $object->accountancy_code_buy; - $this->accountancy_code_sell= $object->accountancy_code_sell; + $this->accountancy_code_buy = $obj->accountancy_code_buy; + $this->accountancy_code_sell = $obj->accountancy_code_sell; - $this->seuil_stock_alerte = $object->seuil_stock_alerte; - $this->stock_reel = $object->stock; - $this->pmp = $object->pmp; + $this->seuil_stock_alerte = $obj->seuil_stock_alerte; + $this->stock_reel = $obj->stock; + $this->pmp = $obj->pmp; - $this->date_creation = $object->datec; - $this->date_modification = $object->tms; - $this->import_key = $object->import_key; + $this->date_creation = $obj->datec; + $this->date_modification = $obj->tms; + $this->import_key = $obj->import_key; + $this->entity = $obj->entity; $this->db->free($resql); @@ -2596,7 +2597,7 @@ class Product extends CommonObject if ($nbbyrow) $return.= '
    '; print ''; print ''; // Label - print ''; + print ''; // Status (to sell) print ''; // Status (to buy) print ''; print ''; @@ -172,12 +171,12 @@ if ($product->id) // Affiche formulaire upload $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/product/document.php?id='.$product->id,'',0,0,($user->rights->produit->creer||$user->rights->service->creer)); + $formfile->form_attach_new_file(DOL_URL_ROOT.'/product/document.php?id='.$object->id,'',0,0,($user->rights->produit->creer||$user->rights->service->creer)); // List of document - $param='&id='.$product->id; - $formfile->list_of_documents($filearray,$product,'produit',$param); + $param='&id='.$object->id; + $formfile->list_of_documents($filearray,$object,'produit',$param); } else @@ -185,7 +184,7 @@ else print $langs->trans("UnkownError"); } -$db->close(); llxFooter(); +$db->close(); ?> diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index f6ce3c148b4..87fac5ff693 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2007 Rodolphe Quiedeville * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005 Eric Seigne - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2006 Auguria SARL * Copyright (C) 2010-2011 Juanjo Menent @@ -47,8 +47,8 @@ $mesg=''; $error=0; $errors=array(); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$action=(GETPOST('action') ? GETPOST('action') : 'view'); -$confirm=GETPOST('confirm'); +$action=(GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view'); +$confirm=GETPOST('confirm','alpha'); $socid=GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; @@ -121,7 +121,7 @@ if (empty($reshook)) $result = $object->setValueFrom('accountancy_code_buy', $_POST['accountancy_code_buy']); if ($result < 0) { - $mesg=join(',',$product->errors); + $mesg=join(',',$object->errors); } $action=""; } @@ -132,7 +132,7 @@ if (empty($reshook)) $result = $object->setValueFrom('accountancy_code_sell', $_POST['accountancy_code_sell']); if ($result < 0) { - $mesg=join(',',$product->errors); + $mesg=join(',',$object->errors); } $action=""; } @@ -159,45 +159,43 @@ if (empty($reshook)) $error++; } - $product=new Product($db); - if (! $error) { - $product->ref = $ref; - $product->libelle = $_POST["libelle"]; - $product->price_base_type = $_POST["price_base_type"]; - if ($product->price_base_type == 'TTC') $product->price_ttc = $_POST["price"]; - else $product->price = $_POST["price"]; - if ($product->price_base_type == 'TTC') $product->price_min_ttc = $_POST["price_min"]; - else $product->price_min = $_POST["price_min"]; - $product->tva_tx = str_replace('*','',$_POST['tva_tx']); - $product->tva_npr = preg_match('/\*/',$_POST['tva_tx'])?1:0; + $object->ref = $ref; + $object->libelle = $_POST["libelle"]; + $object->price_base_type = $_POST["price_base_type"]; + if ($object->price_base_type == 'TTC') $object->price_ttc = $_POST["price"]; + else $object->price = $_POST["price"]; + if ($object->price_base_type == 'TTC') $object->price_min_ttc = $_POST["price_min"]; + else $object->price_min = $_POST["price_min"]; + $object->tva_tx = str_replace('*','',$_POST['tva_tx']); + $object->tva_npr = preg_match('/\*/',$_POST['tva_tx'])?1:0; // local taxes. - $product->localtax1_tx = get_localtax($product->tva_tx,1); - $product->localtax2_tx = get_localtax($product->tva_tx,2); + $object->localtax1_tx = get_localtax($object->tva_tx,1); + $object->localtax2_tx = get_localtax($object->tva_tx,2); - $product->type = $_POST["type"]; - $product->status = $_POST["statut"]; - $product->status_buy = $_POST["statut_buy"]; - $product->description = dol_htmlcleanlastbr($_POST["desc"]); - $product->note = dol_htmlcleanlastbr($_POST["note"]); - $product->customcode = $_POST["customcode"]; - $product->country_id = $_POST["country_id"]; - $product->duration_value = $_POST["duration_value"]; - $product->duration_unit = $_POST["duration_unit"]; - $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]?$_POST["seuil_stock_alerte"]:0; - $product->canvas = $_POST["canvas"]; - $product->weight = $_POST["weight"]; - $product->weight_units = $_POST["weight_units"]; - $product->length = $_POST["size"]; - $product->length_units = $_POST["size_units"]; - $product->surface = $_POST["surface"]; - $product->surface_units = $_POST["surface_units"]; - $product->volume = $_POST["volume"]; - $product->volume_units = $_POST["volume_units"]; - $product->finished = $_POST["finished"]; - $product->hidden = $_POST["hidden"]=='yes'?1:0; + $object->type = $_POST["type"]; + $object->status = $_POST["statut"]; + $object->status_buy = $_POST["statut_buy"]; + $object->description = dol_htmlcleanlastbr($_POST["desc"]); + $object->note = dol_htmlcleanlastbr($_POST["note"]); + $object->customcode = $_POST["customcode"]; + $object->country_id = $_POST["country_id"]; + $object->duration_value = $_POST["duration_value"]; + $object->duration_unit = $_POST["duration_unit"]; + $object->seuil_stock_alerte = $_POST["seuil_stock_alerte"]?$_POST["seuil_stock_alerte"]:0; + $object->canvas = $_POST["canvas"]; + $object->weight = $_POST["weight"]; + $object->weight_units = $_POST["weight_units"]; + $object->length = $_POST["size"]; + $object->length_units = $_POST["size_units"]; + $object->surface = $_POST["surface"]; + $object->surface_units = $_POST["surface_units"]; + $object->volume = $_POST["volume"]; + $object->volume_units = $_POST["volume_units"]; + $object->finished = $_POST["finished"]; + $object->hidden = $_POST["hidden"]=='yes'?1:0; // MultiPrix if($conf->global->PRODUIT_MULTIPRICES) @@ -206,12 +204,12 @@ if (empty($reshook)) { if($_POST["price_".$i]) { - $product->multiprices["$i"] = price2num($_POST["price_".$i],'MU'); - $product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i]; + $object->multiprices["$i"] = price2num($_POST["price_".$i],'MU'); + $object->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i]; } else { - $product->multiprices["$i"] = ""; + $object->multiprices["$i"] = ""; } } } @@ -221,11 +219,11 @@ if (empty($reshook)) { if (preg_match("/^options_/",$key)) { - $product->array_options[$key]=$_POST[$key]; + $object->array_options[$key]=$_POST[$key]; } } - $id = $product->create($user); + $id = $object->create($user); if ($id > 0) { @@ -234,7 +232,7 @@ if (empty($reshook)) } else { - $mesg='
    '.$langs->trans($product->error).'
    '; + $mesg='
    '.$langs->trans($object->error).'
    '; $action = "create"; $_GET["type"] = $_POST["type"]; } @@ -250,51 +248,50 @@ if (empty($reshook)) } else { - $product=new Product($db); - if ($product->fetch($id,$ref)) + if ($object->fetch($id,$ref)) { - $product->ref = $ref; - $product->libelle = $_POST["libelle"]; - $product->description = dol_htmlcleanlastbr($_POST["desc"]); - $product->note = dol_htmlcleanlastbr($_POST["note"]); - $product->customcode = $_POST["customcode"]; - $product->country_id = $_POST["country_id"]; - $product->status = $_POST["statut"]; - $product->status_buy = $_POST["statut_buy"]; - $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; - $product->duration_value = $_POST["duration_value"]; - $product->duration_unit = $_POST["duration_unit"]; - $product->canvas = $_POST["canvas"]; - $product->weight = $_POST["weight"]; - $product->weight_units = $_POST["weight_units"]; - $product->length = $_POST["size"]; - $product->length_units = $_POST["size_units"]; - $product->surface = $_POST["surface"]; - $product->surface_units = $_POST["surface_units"]; - $product->volume = $_POST["volume"]; - $product->volume_units = $_POST["volume_units"]; - $product->finished = $_POST["finished"]; - $product->hidden = $_POST["hidden"]=='yes'?1:0; + $object->ref = $ref; + $object->libelle = $_POST["libelle"]; + $object->description = dol_htmlcleanlastbr($_POST["desc"]); + $object->note = dol_htmlcleanlastbr($_POST["note"]); + $object->customcode = $_POST["customcode"]; + $object->country_id = $_POST["country_id"]; + $object->status = $_POST["statut"]; + $object->status_buy = $_POST["statut_buy"]; + $object->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; + $object->duration_value = $_POST["duration_value"]; + $object->duration_unit = $_POST["duration_unit"]; + $object->canvas = $_POST["canvas"]; + $object->weight = $_POST["weight"]; + $object->weight_units = $_POST["weight_units"]; + $object->length = $_POST["size"]; + $object->length_units = $_POST["size_units"]; + $object->surface = $_POST["surface"]; + $object->surface_units = $_POST["surface_units"]; + $object->volume = $_POST["volume"]; + $object->volume_units = $_POST["volume_units"]; + $object->finished = $_POST["finished"]; + $object->hidden = $_POST["hidden"]=='yes'?1:0; // Get extra fields foreach($_POST as $key => $value) { if (preg_match("/^options_/",$key)) { - $product->array_options[$key]=$_POST[$key]; + $object->array_options[$key]=$_POST[$key]; } } - if ($product->check()) + if ($object->check()) { - if ($product->update($product->id, $user) > 0) + if ($object->update($object->id, $user) > 0) { $action = ''; } else { $action = 'edit'; - $mesg = $product->error; + $mesg = $object->error; } } else @@ -317,47 +314,46 @@ if (empty($reshook)) { $db->begin(); - $product = new Product($db); $originalId = $id; - if ($product->fetch($id,$ref) > 0) + if ($object->fetch($id,$ref) > 0) { - $product->ref = GETPOST('clone_ref'); - $product->status = 0; - $product->status_buy = 0; - $product->finished = 1; - $product->id = null; + $object->ref = GETPOST('clone_ref'); + $object->status = 0; + $object->status_buy = 0; + $object->finished = 1; + $object->id = null; - if ($product->check()) + if ($object->check()) { - $id = $product->create($user); + $id = $object->create($user); if ($id > 0) { - // $product->clone_fournisseurs($originalId, $id); + // $object->clone_fournisseurs($originalId, $id); $db->commit(); $db->close(); - Header("Location: fiche.php?id=$id"); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else { - if ($product->error == 'ErrorProductAlreadyExists') + if ($object->error == 'ErrorProductAlreadyExists') { $db->rollback(); $_error = 1; $action = ""; - $mesg='
    '.$langs->trans("ErrorProductAlreadyExists",$product->ref); - $mesg.=' '.$langs->trans("ShowCardHere").'.'; + $mesg='
    '.$langs->trans("ErrorProductAlreadyExists",$object->ref); + $mesg.=' '.$langs->trans("ShowCardHere").'.'; $mesg.='
    '; - //dol_print_error($product->db); + //dol_print_error($object->db); } else { $db->rollback(); - dol_print_error($product->db); + dol_print_error($object->db); } } } @@ -365,7 +361,7 @@ if (empty($reshook)) else { $db->rollback(); - dol_print_error($product->db); + dol_print_error($object->db); } } } @@ -759,7 +755,7 @@ else // Duration if ($_GET["type"] == 1) { - print '
    '; - print ''; // MIN PRICE print ''; - print ''; // VAT @@ -861,7 +857,7 @@ else print ''; } - /** + /* * Product card */ @@ -881,12 +877,12 @@ else dol_htmloutput_errors($mesg); // Main official, simple, and not duplicated code - print ''."\n"; + print ''."\n"; print ''; print ''; print ''; print ''; - print '
    '; $return.= "\n"; - $return.= ''; + $return.= ''; // Show image (width height=$maxHeight) // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine @@ -2604,11 +2605,11 @@ class Product extends CommonObject $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; if ($photo_vignette && $imgarray['height'] > $maxHeight) { $return.= ''; - $return.= ''; + $return.= ''; } else { $return.= ''; - $return.= ''; + $return.= ''; } $return.= ''."\n"; @@ -2640,7 +2641,7 @@ class Product extends CommonObject } if ($size == 0) { // Format origine - $return.= ''; + $return.= ''; if ($showfilename) $return.= '
    '.$viewfilename; if ($showaction) diff --git a/htdocs/product/document.php b/htdocs/product/document.php index 768c2508f0c..68d9dd40132 100755 --- a/htdocs/product/document.php +++ b/htdocs/product/document.php @@ -34,16 +34,16 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); $langs->load("other"); $langs->load("products"); -$action=GETPOST('action', 'alpha'); +$id = GETPOST('id', 'int'); +$ref = GETPOST('ref', 'alpha'); +$action=GETPOST('action','alpha'); +$confirm=GETPOST('confirm','alpha'); // Security check -if (isset($_GET["id"]) || isset($_GET["ref"])) -{ - $id = isset($_GET["id"])?$_GET["id"]:(isset($_GET["ref"])?$_GET["ref"]:''); -} -$fieldid = isset($_GET["ref"])?'ref':'rowid'; +$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); +$fieldtype = (! empty($ref) ? 'ref' : 'rowid'); if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'produit|service',$id,'product&product','','',$fieldid); +$result=restrictedArea($user,'produit|service',$fielvalue,'product&product','','',$fieldtype); // Get parameters $sortfield = GETPOST("sortfield",'alpha'); @@ -57,14 +57,13 @@ if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="name"; -$product = new Product($db); -if ($_GET['id'] || $_GET["ref"]) +$object = new Product($db); +if ($id > 0 || ! empty($ref)) { - if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); - if ($_GET["id"]) $result = $product->fetch($_GET["id"]); + $result = $object->fetch($id, $ref); - if ($conf->product->enabled) $upload_dir = $conf->product->dir_output.'/'.dol_sanitizeFileName($product->ref); - elseif ($conf->service->enabled) $upload_dir = $conf->service->dir_output.'/'.dol_sanitizeFileName($product->ref); + if ($conf->product->enabled) $upload_dir = $conf->product->dir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); + elseif ($conf->service->enabled) $upload_dir = $conf->service->dir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); } $modulepart='produit'; @@ -109,10 +108,10 @@ if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) $form = new Form($db); -llxHeader("","",$langs->trans("CardProduct".$product->type)); +llxHeader("","",$langs->trans("CardProduct".$object->type)); -if ($product->id) +if ($object->id) { if ( $error_msg ) { @@ -126,9 +125,9 @@ if ($product->id) //if ($result >= 0) $mesg=$langs->trans("FileWasRemoced"); } - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - $picto=($product->type==1?'service':'product'); + $head=product_prepare_head($object, $user); + $titre=$langs->trans("CardProduct".$object->type); + $picto=($object->type==1?'service':'product'); dol_fiche_head($head, 'documents', $titre, 0, $picto); @@ -146,21 +145,21 @@ if ($product->id) // Ref print '
    '.$langs->trans("Ref").''; - print $form->showrefnav($product,'ref','',1,'ref'); + print $form->showrefnav($object,'ref','',1,'ref'); print '
    '.$langs->trans("Label").''.$product->libelle.'
    '.$langs->trans("Label").''.$object->libelle.'
    '.$langs->trans("Status").' ('.$langs->trans("Sell").')'; - print $product->getLibStatut(2,0); + print $object->getLibStatut(2,0); print '
    '.$langs->trans("Status").' ('.$langs->trans("Buy").')'; - print $product->getLibStatut(2,1); + print $object->getLibStatut(2,1); print '
    '.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
    '.$langs->trans("Duration").'  '; + print '
    '.$langs->trans("Duration").'  '; print ''.$langs->trans("Hour").' '; print ''.$langs->trans("Day").' '; print ''.$langs->trans("Week").' '; @@ -837,13 +833,13 @@ else // PRIX print '
    '.$langs->trans("SellingPrice").''; - print $form->select_PriceBaseType($product->price_base_type, "price_base_type"); + print ''; + print $form->select_PriceBaseType($object->price_base_type, "price_base_type"); print '
    '.$langs->trans("MinPrice").''; + print ''; print '
    '; + print '
    '; // Ref print ''; @@ -1048,7 +1044,7 @@ else if ($ret == 'html') print '
    '; } - $showphoto=$object->is_photo_available($conf->product->dir_output); + $showphoto=$object->is_photo_available($conf->product->dir_output[$object->entity]); $showbarcode=$conf->barcode->enabled && $user->rights->barcode->lire; // En mode visu @@ -1074,7 +1070,7 @@ else if ($showphoto || $showbarcode) { print ''; @@ -1099,10 +1095,10 @@ else print '
    '.$langs->trans("Ref").'
    '; - if ($showphoto) print $object->show_photos($conf->product->dir_output,1,1,0,0,0,80); + if ($showphoto) print $object->show_photos($conf->product->dir_output[$object->entity],1,1,0,0,0,80); if ($showphoto && $showbarcode) print '

    '; if ($showbarcode) print $form->showbarcode($object); print '
    '; + if (($action != 'editbarcodetype') && $user->rights->barcode->creer) print ''; print '
    '; print $langs->trans("BarcodeType"); print ''; - if (($_GET['action'] != 'editbarcodetype') && $user->rights->barcode->creer) print 'id.'">'.img_edit($langs->trans('Edit'),1).'id.'">'.img_edit($langs->trans('Edit'),1).'
    '; print ''; - if ($_GET['action'] == 'editbarcodetype') + if ($action == 'editbarcodetype') { require_once(DOL_DOCUMENT_ROOT."/core/class/html.formbarcode.class.php"); $formbarcode = new FormBarCode($db); @@ -1120,10 +1116,10 @@ else print ''; + if (($action != 'editbarcode') && $user->rights->barcode->creer) print ''; print '
    '; print $langs->trans("BarcodeValue"); print ''; - if (($_GET['action'] != 'editbarcode') && $user->rights->barcode->creer) print 'id.'">'.img_edit($langs->trans('Edit'),1).'id.'">'.img_edit($langs->trans('Edit'),1).'
    '; print ''; - if ($_GET['action'] == 'editbarcode') + if ($action == 'editbarcode') { print ''; print ''; @@ -1281,7 +1277,7 @@ if ($action == 'clone' || $conf->use_javascript_ajax) array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("FeatureNotYetAvailable").')', 'value' => 0, 'disabled' => true) ); // Paiement incomplet. On demande si motif = escompte ou autre - $form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneProduct'),$langs->trans('ConfirmCloneProduct',$object->ref),'confirm_clone',$formquestion,'yes','action-clone',230,600); + $form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id,$langs->trans('CloneProduct'),$langs->trans('ConfirmCloneProduct',$object->ref),'confirm_clone',$formquestion,'yes','action-clone',230,600); } @@ -1297,7 +1293,7 @@ if ($action == '' || $action == 'view') { if ($user->rights->produit->creer || $user->rights->service->creer) { - if ($object->no_button_edit <> 1) print 'id.'">'.$langs->trans("Modify").''; + if ($object->no_button_edit <> 1) print ''.$langs->trans("Modify").''; if ($object->no_button_copy <> 1) { @@ -1307,12 +1303,12 @@ if ($action == '' || $action == 'view') } else { - print 'id.'">'.$langs->trans("ToClone").''; + print ''.$langs->trans("ToClone").''; } } } - $object_is_used = $object->isObjectUsed($object->id); + $object_is_used = $object->isObjectUsed($id); if (($object->type == 0 && $user->rights->produit->supprimer) || ($object->type == 1 && $user->rights->service->supprimer)) { @@ -1324,7 +1320,7 @@ if ($action == '' || $action == 'view') } else { - print 'id.'">'.$langs->trans("Delete").''; + print ''.$langs->trans("Delete").''; } } else @@ -1345,7 +1341,7 @@ print "\n
    \n"; * All the "Add to" areas */ -if ($object->id && ($action == '' || $action == 'view') && $object->status) +if ($id && ($action == '' || $action == 'view') && $object->status) { print ''; @@ -1395,7 +1391,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) { $objp = $db->fetch_object($result); $var=!$var; - print ''; + print ''; print ''; print ''; print ""; @@ -1433,7 +1429,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) $var=true; $otherprop = $propal->liste_array(1,1,1); - print ''; + print ''; print ''; print '
    '; if (is_array($otherprop) && count($otherprop)) @@ -1512,7 +1508,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) { $objc = $db->fetch_object($result); $var=!$var; - print ''; + print ''; print ''; print ''; print ""; @@ -1551,7 +1547,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) $var=true; $othercom = $commande->liste_array(1, $user); - print ''; + print ''; print ''; print '
    '; if (is_array($othercom) && count($othercom)) @@ -1626,7 +1622,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) { $objp = $db->fetch_object($result); $var=!$var; - print ''; + print ''; print ''; print ''; print ""; @@ -1691,7 +1687,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) $objp = $db->fetch_object($result); $var=!$var; - print ''; + print ''; print ''; print ''; print ""; diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php index 45533e043cb..8e0c34b6792 100644 --- a/htdocs/product/photos.php +++ b/htdocs/product/photos.php @@ -43,9 +43,14 @@ $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); - $mesg = ''; -$dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output); + +$object = new Product($db); +if ($id > 0 || ! empty($ref)) +{ + $result = $object->fetch($id, $ref); + $dir = (! empty($conf->product->dir_output[$object->entity])?$conf->product->dir_output[$object->entity]:$conf->service->dir_output[$object->entity]); +} /* @@ -54,25 +59,17 @@ $dir = (!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->ser if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) { - if ($id) - { - $product = new Product($db); - $result = $product->fetch($id); - - $result = $product->add_photo($dir, $_FILES['userfile']); - } + if ($object->id) $result = $object->add_photo($dir, $_FILES['userfile']); } if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer)) { - $product = new Product($db); - $product->delete_photo($dir."/".$_GET["file"]); + $object->delete_photo($dir."/".$_GET["file"]); } if ($action == 'addthumb' && $_GET["file"]) { - $product = new Product($db); - $product->add_thumb($dir."/".$_GET["file"]); + $object->add_thumb($dir."/".$_GET["file"]); } @@ -82,118 +79,111 @@ if ($action == 'addthumb' && $_GET["file"]) $form = new Form($db); -if ($id > 0 || ! empty($ref)) +if ($object->id) { - $product = new Product($db); - - $result = $product->fetch($id, $ref); - - llxHeader("","",$langs->trans("CardProduct".$product->type)); - - if ($result) - { - /* - * En mode visu - */ - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - $picto=($product->type==1?'service':'product'); - dol_fiche_head($head, 'photos', $titre, 0, $picto); - - /* - * Confirmation de la suppression de photo - */ - if ($_GET['action'] == 'delete') - { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$product->id.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1); - if ($ret == 'html') print '
    '; - } - - print($mesg); - - print '
    '; - - // Reference - print ''; - print ''; - print ''; - - // Libelle - print ''; - print ''; - - // Status (to sell) - print ''; - - // Status (to buy) - print ''; - - print "
    '.$langs->trans("Ref").''; - print $form->showrefnav($product,'ref','',1,'ref'); - print '
    '.$langs->trans("Label").''.$product->libelle.'
    '.$langs->trans("Status").' ('.$langs->trans("Sell").')'; - print $product->getLibStatut(2,0); - print '
    '.$langs->trans("Status").' ('.$langs->trans("Buy").')'; - print $product->getLibStatut(2,1); - print '
    \n"; - - print "\n"; - - - - /* ************************************************************************** */ - /* */ - /* Barre d'action */ - /* */ - /* ************************************************************************** */ - - print "\n
    \n"; - - if ($_GET["action"] != 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer)) - { - if (! empty($conf->global->MAIN_UPLOAD_DOC)) - { - print 'id.'">'; - print $langs->trans("AddPhoto").''; - } - else - { - print 'e'; - print $langs->trans("AddPhoto").''; - } - } - - print "\n
    \n"; - - /* - * Add a photo - */ - if ($action == 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC)) - { - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$product->id,$langs->trans("AddPhoto"),1); - } - - // Affiche photos - if ($action != 'ajout_photo') - { - $nbphoto=0; - $nbbyrow=5; - - $maxWidth = 160; - $maxHeight = 120; - - print $product->show_photos($dir,1,1000,$nbbyrow,1,1); - - if ($product->nbphoto < 1) - { - print '
    '; - print ''; print ''; - print '
    '; - print "
    ".$langs->trans("NoPhotoYet")."

    "; - print '
    '; - } - } + llxHeader("","",$langs->trans("CardProduct".$object->type)); + + /* + * En mode visu + */ + $head=product_prepare_head($object, $user); + $titre=$langs->trans("CardProduct".$object->type); + $picto=($object->type==1?'service':'product'); + dol_fiche_head($head, 'photos', $titre, 0, $picto); + + /* + * Confirmation de la suppression de photo + */ + if ($_GET['action'] == 'delete') + { + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1); + if ($ret == 'html') print '
    '; + } + + print($mesg); + + print ''; + + // Reference + print ''; + print ''; + print ''; + + // Libelle + print ''; + print ''; + + // Status (to sell) + print ''; + + // Status (to buy) + print ''; + + print "
    '.$langs->trans("Ref").''; + print $form->showrefnav($object,'ref','',1,'ref'); + print '
    '.$langs->trans("Label").''.$object->libelle.'
    '.$langs->trans("Status").' ('.$langs->trans("Sell").')'; + print $object->getLibStatut(2,0); + print '
    '.$langs->trans("Status").' ('.$langs->trans("Buy").')'; + print $object->getLibStatut(2,1); + print '
    \n"; + + print "\n"; + + + + /* ************************************************************************** */ + /* */ + /* Barre d'action */ + /* */ + /* ************************************************************************** */ + + print "\n
    \n"; + + if ($_GET["action"] != 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer)) + { + if (! empty($conf->global->MAIN_UPLOAD_DOC)) + { + print 'id.'">'; + print $langs->trans("AddPhoto").''; + } + else + { + print 'e'; + print $langs->trans("AddPhoto").''; + } + } + + print "\n
    \n"; + + /* + * Add a photo + */ + if ($action == 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC)) + { + // Affiche formulaire upload + $formfile=new FormFile($db); + $formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans("AddPhoto"),1); + } + + // Affiche photos + if ($action != 'ajout_photo') + { + $nbphoto=0; + $nbbyrow=5; + + $maxWidth = 160; + $maxHeight = 120; + + print $object->show_photos($dir,1,1000,$nbbyrow,1,1); + + if ($object->nbphoto < 1) + { + print '
    '; + print ''; print ''; + print '
    '; + print "
    ".$langs->trans("NoPhotoYet")."

    "; + print '
    '; + } } } else @@ -203,6 +193,5 @@ else llxFooter(); - $db->close(); ?> diff --git a/htdocs/product/price.php b/htdocs/product/price.php index f26346c14ce..dcb075c90dd 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -130,14 +130,14 @@ print ''; // Label print ''.$langs->trans("Label").''.$object->libelle.''; -$isphoto=$object->is_photo_available($conf->product->dir_output); +$isphoto=$object->is_photo_available($conf->product->dir_output[$object->entity]); $nblignes=5; if ($isphoto) { // Photo print ''; - print $object->show_photos($conf->product->dir_output,1,1,0,0,0,80); + print $object->show_photos($conf->product->dir_output[$object->entity],1,1,0,0,0,80); print ''; } diff --git a/htdocs/product/stats/fiche.php b/htdocs/product/stats/fiche.php index 8c0752d0c7c..fbbd37bc1df 100644 --- a/htdocs/product/stats/fiche.php +++ b/htdocs/product/stats/fiche.php @@ -111,7 +111,7 @@ if (! empty($id) || ! empty($ref)) // Generation des graphs $WIDTH=380; $HEIGHT=160; - $dir = (!empty($conf->product->dir_temp)?$conf->product->dir_temp:$conf->service->dir_temp); + $dir = (! empty($conf->product->dir_temp[$object->entity])?$conf->product->dir_temp[$object->entity]:$conf->service->dir_temp[$object->entity]); if (! file_exists($dir.'/'.$object->id)) { if (dol_mkdir($dir.'/'.$object->id) < 0) @@ -168,7 +168,7 @@ if (! empty($id) || ! empty($ref)) $px->SetShading(3); //print 'x '.$key.' '.$graphfiles[$key]['file']; - $url=DOL_URL_ROOT.'/viewimage.php?modulepart='.$graphfiles[$key]['modulepart'].'&file='.urlencode($graphfiles[$key]['file']); + $url=DOL_URL_ROOT.'/viewimage.php?modulepart='.$graphfiles[$key]['modulepart'].'&entity='.$object->entity.'&file='.urlencode($graphfiles[$key]['file']); $px->draw($dir."/".$graphfiles[$key]['file'],$url); $graphfiles[$key]['output']=$px->show(); diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php index 9445299a2d8..a8233cad6d9 100644 --- a/htdocs/viewimage.php +++ b/htdocs/viewimage.php @@ -1,7 +1,7 @@ * Copyright (C) 2005-2012 Laurent Destailleur - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,9 +48,9 @@ require("./main.inc.php"); require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); -$action = GETPOST("action"); +$action = GETPOST('action','alpha'); $original_file = GETPOST("file"); -$modulepart = GETPOST("modulepart"); +$modulepart = GETPOST('modulepart','alpha'); $urlsource = GETPOST("urlsource"); @@ -197,13 +197,13 @@ if ($modulepart) elseif (preg_match('/^productstats_/i',$modulepart)) { if ($user->rights->produit->lire || $user->rights->service->lire) $accessallowed=1; - $original_file=(!empty($conf->product->dir_temp)?$conf->product->dir_temp:$conf->service->dir_temp).'/'.$original_file; + $original_file=(!empty($conf->product->dir_temp[GETPOST('entity','int')])?$conf->product->dir_temp[GETPOST('entity','int')]:$conf->service->dir_temp[GETPOST('entity','int')]).'/'.$original_file; } // Wrapping for products or services elseif ($modulepart == 'product') { if ($user->rights->produit->lire || $user->rights->service->lire) $accessallowed=1; - $original_file=(!empty($conf->product->dir_output)?$conf->product->dir_output:$conf->service->dir_output).'/'.$original_file; + $original_file=(! empty($conf->product->dir_output[GETPOST('entity','int')])?$conf->product->dir_output[GETPOST('entity','int')]:$conf->service->dir_output[GETPOST('entity','int')]).'/'.$original_file; } // Wrapping for products or services elseif ($modulepart == 'tax') @@ -239,7 +239,7 @@ if ($modulepart) elseif ($modulepart == 'graph_product') { $accessallowed=1; - $original_file=$conf->product->dir_temp.'/'.$original_file; + $original_file=$conf->product->dir_temp[GETPOST('entity','int')].'/'.$original_file; } // Wrapping pour les code barre elseif ($modulepart == 'barcode')