Fix: compatibility with multicompany sharings

use new $conf->product->dir_output[$object->entity] instead
$conf->product->dir_output
This commit is contained in:
Regis Houssin 2012-04-06 22:39:40 +02:00
parent a344f079d6
commit 94788e2ccb
15 changed files with 397 additions and 426 deletions

View File

@ -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)

View File

@ -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);
}
}
}

View File

@ -587,6 +587,7 @@ class FormFile
//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');

View File

@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Meos
/* Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Meos
* Copyright (C) 2012 Regis Houssin <regis@dolibarr.fr>
*
* 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 '<div class="error">'.$mesg.'</div>';
$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 '<ul>
print '<br>'."\n";
print '<!-- Form to resize -->'."\n";
print '<form name="redim_file" action="'.$_SERVER["PHP_SELF"].'?id='.$_GET['id'].'" method="POST">';
print '<form name="redim_file" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
print '<fieldset id="redim_file">';
print '<legend>'.$langs->trans("Resize").'</legend>';
@ -159,8 +146,8 @@ print $langs->trans("NewLength").': <input class="flat" name="sizex" size="10" t
print $langs->trans("NewHeight").': <input class="flat" name="sizey" size="10" type="text" > px &nbsp; <br>';
print '<input type="hidden" name="file" value="'.$_GET['file'].'" />';
print '<input type="hidden" name="action" value="confirm_resize" />';
print '<input type="hidden" name="product" value="'.$_REQUEST['id'].'" />';
print '<input type="hidden" name="id" value="'.$_REQUEST['id'].'" />';
print '<input type="hidden" name="product" value="'.$id.'" />';
print '<input type="hidden" name="id" value="'.$id.'" />';
print '<br><input class="button" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';
print '</fieldset>';
print '<br></form>';
@ -174,7 +161,7 @@ print '<br>'."\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 '<fieldset id="redim_file">';
print '<legend>'.$langs->trans("Recenter").'</legend>';
print $langs->trans("DefineNewAreaToPick").'...<br>';
print '<br><center>';
print '<div style="border: 1px solid #888888; width: '.$width.'px;"><img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.$original_file.'" alt="" id="cropbox" /></div>';
print '<div style="border: 1px solid #888888; width: '.$width.'px;"><img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$object->entity.'&file='.$original_file.'" alt="" id="cropbox" /></div>';
print '</center><br>';
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$_GET['id'].'" method="post" onsubmit="return checkCoords();">
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post" onsubmit="return checkCoords();">
<div class="jc_coords">
'.$langs->trans("NewSizeAfterCropping").':
<label>X1 <input type="text" size="4" id="x" name="x" /></label>
@ -198,8 +185,8 @@ print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$_GET['id'].'" method="post"
<input type="hidden" id="file" name="file" value="'.urlencode($original_file).'" />
<input type="hidden" id="action" name="action" value="confirm_crop" />
<input type="hidden" id="product" name="product" value="'.$_REQUEST['id'].'" />
<input type="hidden" name="id" value="'.$_REQUEST['id'].'" />
<input type="hidden" id="product" name="product" value="'.$id.'" />
<input type="hidden" name="id" value="'.$id.'" />
<br><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Recenter")).'" />
</form>';
print '</fieldset>';
@ -208,4 +195,5 @@ print '</fieldset>';
llxFooter();
$db->close();
?>

View File

@ -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

View File

@ -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<EFBFBD>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 '<table class="border" width="100%">';
print "<tr>";
print '<td>'.$langs->trans("Ref").'</td><td>'.$product->ref.'</td>';
print '<td>'.$langs->trans("Ref").'</td><td>'.$object->ref.'</td>';
print '<td colspan="2">';
print $product->getLibStatut(2);
print $object->getLibStatut(2);
print '</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
print '<td>'.$langs->trans("SellingPrice").'</td><td>'.price($product->price).'</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->libelle.'</td>';
print '<td>'.$langs->trans("SellingPrice").'</td><td>'.price($object->price).'</td></tr>';
print "</table><br>\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 '<form name="userfile" action="photos.php?id='.$product->id.'" enctype="multipart/form-data" METHOD="POST">';
print '<form name="userfile" action="photos.php?id='.$object->id.'" enctype="multipart/form-data" METHOD="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
@ -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 '<br><table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
foreach ($product->liste_photos($dir) as $obj)
foreach ($object->liste_photos($dir) as $obj)
{
$nbphoto++;
@ -162,7 +163,7 @@ if ($_GET["id"])
print '<br>'.$langs->trans("File").': '.dol_trunc($filename,16);
if ($user->rights->produit->creer || $user->rights->service->creer)
{
print '<br><a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=delete&amp;file='.urlencode($pdir.$filename).'">'.img_delete().'</a>';
print '<br><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete&amp;file='.urlencode($pdir.$filename).'">'.img_delete().'</a>';
}
if ($nbbyrow) print '</td>';
if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '</tr>';
@ -192,11 +193,11 @@ if ($_GET["id"])
print "\n<div class=\"tabsAction\">\n";
if ($_GET["action"] == '')
if ($action == '')
{
if (($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
print '<a class="butAction" href="photos.php?action=ajout_photo&amp;id='.$product->id.'">';
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=ajout_photo&amp;id='.$object->id.'">';
print $langs->trans("AddPhoto").'</a>';
}
}
@ -210,8 +211,6 @@ else
}
$db->close();
llxFooter();
$db->close();
?>

View File

@ -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

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
/* Copyright (C) 2010-2012 Regis Houssin <regis@dolibarr.fr>
*
* 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

View File

@ -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.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
$return.= "\n";
$return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo).'" class="lightbox" target="_blank">';
$return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="lightbox" target="_blank">';
// 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.= '<!-- Show thumb -->';
$return.= '<img class="photo" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">';
$return.= '<img class="photo" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">';
}
else {
$return.= '<!-- Show original file -->';
$return.= '<img class="photo" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">';
$return.= '<img class="photo" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">';
}
$return.= '</a>'."\n";
@ -2640,7 +2641,7 @@ class Product extends CommonObject
}
if ($size == 0) { // Format origine
$return.= '<img class="photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$photo).'">';
$return.= '<img class="photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">';
if ($showfilename) $return.= '<br>'.$viewfilename;
if ($showaction)

View File

@ -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 '<tr>';
print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $form->showrefnav($product,'ref','',1,'ref');
print $form->showrefnav($object,'ref','',1,'ref');
print '</td>';
print '</tr>';
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$object->libelle.'</td></tr>';
// Status (to sell)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
print $product->getLibStatut(2,0);
print $object->getLibStatut(2,0);
print '</td></tr>';
// Status (to buy)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
print $product->getLibStatut(2,1);
print $object->getLibStatut(2,1);
print '</td></tr>';
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
@ -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();
?>

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2006 Auguria SARL <info@auguria.org>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
@ -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='<div class="error">'.$langs->trans($product->error).'</div>';
$mesg='<div class="error">'.$langs->trans($object->error).'</div>';
$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='<div class="error">'.$langs->trans("ErrorProductAlreadyExists",$product->ref);
$mesg.=' <a href="'.$_SERVER["PHP_SELF"].'?ref='.$product->ref.'">'.$langs->trans("ShowCardHere").'</a>.';
$mesg='<div class="error">'.$langs->trans("ErrorProductAlreadyExists",$object->ref);
$mesg.=' <a href="'.$_SERVER["PHP_SELF"].'?ref='.$object->ref.'">'.$langs->trans("ShowCardHere").'</a>.';
$mesg.='</div>';
//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 '<tr><td>'.$langs->trans("Duration").'</td><td><input name="duration_value" size="6" maxlength="5" value="'.$product->duree.'"> &nbsp;';
print '<tr><td>'.$langs->trans("Duration").'</td><td><input name="duration_value" size="6" maxlength="5" value="'.$object->duree.'"> &nbsp;';
print '<input name="duration_unit" type="radio" value="h">'.$langs->trans("Hour").'&nbsp;';
print '<input name="duration_unit" type="radio" value="d">'.$langs->trans("Day").'&nbsp;';
print '<input name="duration_unit" type="radio" value="w">'.$langs->trans("Week").'&nbsp;';
@ -837,13 +833,13 @@ else
// PRIX
print '<tr><td>'.$langs->trans("SellingPrice").'</td>';
print '<td><input name="price" size="10" value="'.$product->price.'">';
print $form->select_PriceBaseType($product->price_base_type, "price_base_type");
print '<td><input name="price" size="10" value="'.$object->price.'">';
print $form->select_PriceBaseType($object->price_base_type, "price_base_type");
print '</td></tr>';
// MIN PRICE
print '<tr><td>'.$langs->trans("MinPrice").'</td>';
print '<td><input name="price_min" size="10" value="'.$product->price_min.'">';
print '<td><input name="price_min" size="10" value="'.$object->price_min.'">';
print '</td></tr>';
// VAT
@ -861,7 +857,7 @@ else
print '</form>';
}
/**
/*
* Product card
*/
@ -881,12 +877,12 @@ else
dol_htmloutput_errors($mesg);
// Main official, simple, and not duplicated code
print '<form action="fiche.php" method="POST">'."\n";
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="canvas" value="'.$object->canvas.'">';
print '<table class="border" width="100%">';
print '<table class="border allwidth">';
// Ref
print '<tr><td width="15%" class="fieldrequired">'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" size="40" maxlength="32" value="'.$object->ref.'"></td></tr>';
@ -1048,7 +1044,7 @@ else
if ($ret == 'html') print '<br>';
}
$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 '<td valign="middle" align="center" width="25%" rowspan="'.$nblignes.'">';
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 '<br><br>';
if ($showbarcode) print $form->showbarcode($object);
print '</td>';
@ -1099,10 +1095,10 @@ else
print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("BarcodeType");
print '<td>';
if (($_GET['action'] != 'editbarcodetype') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcodetype&amp;id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
if (($action != 'editbarcodetype') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcodetype&amp;id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
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 '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
print $langs->trans("BarcodeValue");
print '<td>';
if (($_GET['action'] != 'editbarcode') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcode&amp;id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
if (($action != 'editbarcode') && $user->rights->barcode->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbarcode&amp;id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
print '</tr></table>';
print '</td><td colspan="2">';
if ($_GET['action'] == 'editbarcode')
if ($action == 'editbarcode')
{
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -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 '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("Modify").'</a>';
if ($object->no_button_edit <> 1) print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&amp;id='.$id.'">'.$langs->trans("Modify").'</a>';
if ($object->no_button_copy <> 1)
{
@ -1307,12 +1303,12 @@ if ($action == '' || $action == 'view')
}
else
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=clone&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=clone&amp;id='.$id.'">'.$langs->trans("ToClone").'</a>';
}
}
}
$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 '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&amp;id='.$object->id.'">'.$langs->trans("Delete").'</a>';
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=delete&amp;id='.$id.'">'.$langs->trans("Delete").'</a>';
}
}
else
@ -1345,7 +1341,7 @@ print "\n</div><br>\n";
* All the "Add to" areas
*/
if ($object->id && ($action == '' || $action == 'view') && $object->status)
if ($id && ($action == '' || $action == 'view') && $object->status)
{
print '<table width="100%" class="noborder">';
@ -1395,7 +1391,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status)
{
$objp = $db->fetch_object($result);
$var=!$var;
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addinpropal">';
print "<tr ".$bc[$var].">";
@ -1433,7 +1429,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status)
$var=true;
$otherprop = $propal->liste_array(1,1,1);
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="nobordernopadding" width="100%">';
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 '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addincommande">';
print "<tr ".$bc[$var].">";
@ -1551,7 +1547,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status)
$var=true;
$othercom = $commande->liste_array(1, $user);
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="nobordernopadding" width="100%">';
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 '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addinfacture">';
print "<tr $bc[$var]>";
@ -1691,7 +1687,7 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status)
$objp = $db->fetch_object($result);
$var=!$var;
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addinfacture">';
print "<tr ".$bc[$var].">";

View File

@ -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 '<br>';
}
print($mesg);
print '<table class="border" width="100%">';
// Reference
print '<tr>';
print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="2">';
print $form->showrefnav($product,'ref','',1,'ref');
print '</td>';
print '</tr>';
// Libelle
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td>';
print '</tr>';
// Status (to sell)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
print $product->getLibStatut(2,0);
print '</td></tr>';
// Status (to buy)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
print $product->getLibStatut(2,1);
print '</td></tr>';
print "</table>\n";
print "</div>\n";
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print "\n<div class=\"tabsAction\">\n";
if ($_GET["action"] != 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer))
{
if (! empty($conf->global->MAIN_UPLOAD_DOC))
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=ajout_photo&amp;id='.$product->id.'">';
print $langs->trans("AddPhoto").'</a>';
}
else
{
print '<a class="butActionRefused" href="#">e';
print $langs->trans("AddPhoto").'</a>';
}
}
print "\n</div>\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 '<br>';
print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; print '<tr align=center valign=middle border=1><td class="photo">';
print "<br>".$langs->trans("NoPhotoYet")."<br><br>";
print '</td></tr>';
print '</table>';
}
}
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 '<br>';
}
print($mesg);
print '<table class="border" width="100%">';
// Reference
print '<tr>';
print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="2">';
print $form->showrefnav($object,'ref','',1,'ref');
print '</td>';
print '</tr>';
// Libelle
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$object->libelle.'</td>';
print '</tr>';
// Status (to sell)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
print $object->getLibStatut(2,0);
print '</td></tr>';
// Status (to buy)
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
print $object->getLibStatut(2,1);
print '</td></tr>';
print "</table>\n";
print "</div>\n";
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print "\n<div class=\"tabsAction\">\n";
if ($_GET["action"] != 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer))
{
if (! empty($conf->global->MAIN_UPLOAD_DOC))
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=ajout_photo&amp;id='.$object->id.'">';
print $langs->trans("AddPhoto").'</a>';
}
else
{
print '<a class="butActionRefused" href="#">e';
print $langs->trans("AddPhoto").'</a>';
}
}
print "\n</div>\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 '<br>';
print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; print '<tr align=center valign=middle border=1><td class="photo">';
print "<br>".$langs->trans("NoPhotoYet")."<br><br>";
print '</td></tr>';
print '</table>';
}
}
}
else
@ -203,6 +193,5 @@ else
llxFooter();
$db->close();
?>

View File

@ -130,14 +130,14 @@ print '</tr>';
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->libelle.'</td>';
$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 '<td valign="middle" align="center" width="30%" rowspan="'.$nblignes.'">';
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 '</td>';
}

View File

@ -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();

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
*
* 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')