Fix: multicompany sharings and uniformize code

This commit is contained in:
Regis Houssin 2012-04-07 10:18:09 +02:00
parent 13624eeb86
commit 921c8607d7
6 changed files with 247 additions and 250 deletions

View File

@ -73,7 +73,7 @@ class Categorie
*/ */
function fetch($id) function fetch($id)
{ {
$sql = "SELECT rowid, label, description, fk_soc, visible, type"; $sql = "SELECT rowid, entity, label, description, fk_soc, visible, type";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
$sql.= " WHERE rowid = ".$id; $sql.= " WHERE rowid = ".$id;
@ -89,6 +89,7 @@ class Categorie
$this->socid = $res['fk_soc']; $this->socid = $res['fk_soc'];
$this->visible = $res['visible']; $this->visible = $res['visible'];
$this->type = $res['type']; $this->type = $res['type'];
$this->entity = $res['entity'];
$this->db->free($resql); $this->db->free($resql);
} }
@ -1284,6 +1285,8 @@ class Categorie
*/ */
function liste_photos($dir,$nbmax=0) function liste_photos($dir,$nbmax=0)
{ {
include_once(DOL_DOCUMENT_ROOT ."/core/lib/files.lib.php");
$nbphoto=0; $nbphoto=0;
$tabobj=array(); $tabobj=array();
@ -1296,7 +1299,7 @@ class Categorie
{ {
while (($file = readdir($handle)) != false) while (($file = readdir($handle)) != false)
{ {
if (is_file($dir.$file)) if (dol_is_file($dir.$file) && preg_match('/(\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i',$dir.$file))
{ {
$nbphoto++; $nbphoto++;
$photo = $file; $photo = $file;

View File

@ -51,6 +51,13 @@ if ($id == "")
$result = restrictedArea($user, 'categorie', $id, '&category'); $result = restrictedArea($user, 'categorie', $id, '&category');
$object = new Categorie($db); $object = new Categorie($db);
if ($id > 0)
{
$result = $object->fetch($id);
$upload_dir = $conf->categorie->multidir_output[$object->entity];
}
/* /*
* Actions * Actions
@ -58,22 +65,17 @@ $object = new Categorie($db);
if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
if ($id) if ($object->id) $result = $object->add_photo($upload_dir, $_FILES['userfile']);
{
$result = $object->fetch($id);
$result = $object->add_photo($conf->categorie->dir_output, $_FILES['userfile']);
}
} }
if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer) if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer)
{ {
$object->delete_photo($conf->categorie->dir_output."/".$_GET["file"]); $object->delete_photo($upload_dir."/".$_GET["file"]);
} }
if ($action == 'addthumb' && $_GET["file"]) if ($action == 'addthumb' && $_GET["file"])
{ {
$object->add_thumb($conf->categorie->dir_output."/".$_GET["file"]); $object->add_thumb($upload_dir."/".$_GET["file"]);
} }
@ -85,12 +87,8 @@ llxHeader("","",$langs->trans("Categories"));
$form = new Form($db); $form = new Form($db);
if (!empty($id) || !empty($ref)) if ($object->id)
{ {
$result = $object->fetch($id);
if ($result)
{
$title=$langs->trans("ProductsCategoryShort"); $title=$langs->trans("ProductsCategoryShort");
if ($type == 0) $title=$langs->trans("ProductsCategoryShort"); if ($type == 0) $title=$langs->trans("ProductsCategoryShort");
elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort"); elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort");
@ -188,11 +186,11 @@ if (!empty($id) || !empty($ref))
print "\n<div class=\"tabsAction\">\n"; print "\n<div class=\"tabsAction\">\n";
if ($action != 'ajout_photo' && $user->rights->produit->creer) if ($action != 'ajout_photo' && $user->rights->categorie->creer)
{ {
if (! empty($conf->global->MAIN_UPLOAD_DOC)) if (! empty($conf->global->MAIN_UPLOAD_DOC))
{ {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/categories/photos.php?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">'; print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
print $langs->trans("AddPhoto").'</a>'; print $langs->trans("AddPhoto").'</a>';
} }
else else
@ -211,7 +209,7 @@ if (!empty($id) || !empty($ref))
{ {
// Affiche formulaire upload // Affiche formulaire upload
$formfile=new FormFile($db); $formfile=new FormFile($db);
$formfile->form_attach_new_file(DOL_URL_ROOT.'/categories/photos.php?id='.$object->id.'&amp;type='.$type,$langs->trans("AddPhoto"),1); $formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;type='.$type,$langs->trans("AddPhoto"),1);
} }
// Affiche photos // Affiche photos
@ -224,7 +222,7 @@ if (!empty($id) || !empty($ref))
$maxHeight = 120; $maxHeight = 120;
$pdir = get_exdir($object->id,2) . $object->id ."/photos/"; $pdir = get_exdir($object->id,2) . $object->id ."/photos/";
$dir = $conf->categorie->dir_output.'/'.$pdir; $dir = $upload_dir.'/'.$pdir;
print '<br>'; print '<br>';
print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
@ -237,7 +235,7 @@ if (!empty($id) || !empty($ref))
if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>'; if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>';
if ($nbbyrow) print '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; if ($nbbyrow) print '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=categorie&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">'; print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">';
// Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
if ($obj['photo_vignette']) if ($obj['photo_vignette'])
@ -257,7 +255,7 @@ if (!empty($id) || !empty($ref))
$imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth; $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
$imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight; $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=categorie&file='.urlencode($pdir.$filename).'">'; print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename).'">';
print '</a>'; print '</a>';
print '<br>'.$viewfilename; print '<br>'.$viewfilename;
@ -266,11 +264,11 @@ if (!empty($id) || !empty($ref))
// On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight)) if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight))
{ {
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=addthumb&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').'&nbsp;&nbsp;</a>'; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->entity.'&amp;action=addthumb&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').'&nbsp;&nbsp;</a>';
} }
if ($user->rights->categorie->creer) if ($user->rights->categorie->creer)
{ {
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=delete&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->entity.'&amp;action=delete&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">';
print img_delete().'</a>'; print img_delete().'</a>';
} }
if ($nbbyrow) print '</td>'; if ($nbbyrow) print '</td>';
@ -293,7 +291,6 @@ if (!empty($id) || !empty($ref))
print '</table>'; print '</table>';
} }
}
} }
else else
{ {
@ -301,8 +298,6 @@ else
} }
$db->close();
llxFooter(); llxFooter();
$db->close();
?> ?>

View File

@ -265,10 +265,6 @@ class Conf
$rootfordata.='/'.$this->entity; $rootfordata.='/'.$this->entity;
} }
// For backward compatibility
// TODO Replace this->xxx->enabled by this->modulename->enabled to remove this code
if (isset($this->categorie->enabled)) $this->category->enabled=$this->categorie->enabled;
// Define default dir_output and dir_temp for directories of modules // Define default dir_output and dir_temp for directories of modules
foreach($this->modules as $module) foreach($this->modules as $module)
{ {
@ -422,6 +418,7 @@ class Conf
$this->invoice=$this->facture; $this->invoice=$this->facture;
$this->order=$this->commande; $this->order=$this->commande;
$this->contract=$this->contrat; $this->contract=$this->contrat;
$this->category=$this->categorie;
// Define menu manager in setup // Define menu manager in setup

View File

@ -220,14 +220,14 @@ class doc_generic_odt extends ModeleThirdPartyDoc
//print "file=".$file; //print "file=".$file;
//print "conf->societe->dir_temp=".$conf->societe->dir_temp; //print "conf->societe->dir_temp=".$conf->societe->dir_temp;
dol_mkdir($conf->societe->dir_temp); dol_mkdir($conf->societe->multidir_temp[$object->entity]);
// Open and load template // Open and load template
require_once(ODTPHP_PATH.'odf.php'); require_once(ODTPHP_PATH.'odf.php');
$odfHandler = new odf( $odfHandler = new odf(
$srctemplatepath, $srctemplatepath,
array( array(
'PATH_TO_TMP' => $conf->societe->dir_temp, 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity],
'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy.
'DELIMITER_LEFT' => '{', 'DELIMITER_LEFT' => '{',
'DELIMITER_RIGHT' => '}' 'DELIMITER_RIGHT' => '}'

View File

@ -50,10 +50,11 @@ require("./main.inc.php"); // Load $user and permissions
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$encoding = ''; $encoding = '';
$action = GETPOST('action','alpha'); $action=GETPOST('action','alpha');
$original_file = GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP). $original_file=GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP).
$modulepart = GETPOST('modulepart','alpha'); $modulepart=GETPOST('modulepart','alpha');
$urlsource = GETPOST('urlsource','alpha'); $urlsource=GETPOST('urlsource','alpha');
$entity=GETPOST('entity','int');
// Security check // Security check
if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart'); if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart');
@ -130,8 +131,8 @@ if ($modulepart)
{ {
$accessallowed=1; $accessallowed=1;
} }
$original_file=$conf->societe->multidir_output[GETPOST('entity','int')].'/'.$original_file; $original_file=$conf->societe->multidir_output[$entity].'/'.$original_file;
$sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$refname."' AND entity=".$conf->entity; $sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$refname."' AND entity IN (".getEntity('societe', 1).")";
} }
// Wrapping for invoices // Wrapping for invoices
@ -299,8 +300,8 @@ if ($modulepart)
{ {
$accessallowed=1; $accessallowed=1;
} }
if ($conf->product->enabled) $original_file=$conf->product->multidir_output[GETPOST('entity','int')].'/'.$original_file; if ($conf->product->enabled) $original_file=$conf->product->multidir_output[$entity].'/'.$original_file;
elseif ($conf->service->enabled) $original_file=$conf->service->multidir_output[GETPOST('entity','int')].'/'.$original_file; elseif ($conf->service->enabled) $original_file=$conf->service->multidir_output[$entity].'/'.$original_file;
} }
// Wrapping pour les contrats // Wrapping pour les contrats

View File

@ -48,10 +48,11 @@ require("./main.inc.php");
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$action = GETPOST('action','alpha'); $action=GETPOST('action','alpha');
$original_file = GETPOST("file"); $original_file=GETPOST("file");
$modulepart = GETPOST('modulepart','alpha'); $modulepart=GETPOST('modulepart','alpha');
$urlsource = GETPOST("urlsource"); $urlsource=GETPOST("urlsource");
$entity=GETPOST('entity','int');
// Security check // Security check
@ -121,7 +122,7 @@ if ($modulepart)
elseif ($modulepart == 'societe') elseif ($modulepart == 'societe')
{ {
$accessallowed=1; $accessallowed=1;
$original_file=$conf->societe->multidir_output[GETPOST('entity','int')].'/'.$original_file; $original_file=$conf->societe->multidir_output[$entity].'/'.$original_file;
} }
// Wrapping pour les apercu factures // Wrapping pour les apercu factures
elseif ($modulepart == 'apercufacture') elseif ($modulepart == 'apercufacture')
@ -197,13 +198,13 @@ if ($modulepart)
elseif (preg_match('/^productstats_/i',$modulepart)) elseif (preg_match('/^productstats_/i',$modulepart))
{ {
if ($user->rights->produit->lire || $user->rights->service->lire) $accessallowed=1; if ($user->rights->produit->lire || $user->rights->service->lire) $accessallowed=1;
$original_file=(!empty($conf->product->multidir_temp[GETPOST('entity','int')])?$conf->product->multidir_temp[GETPOST('entity','int')]:$conf->service->multidir_temp[GETPOST('entity','int')]).'/'.$original_file; $original_file=(!empty($conf->product->multidir_temp[$entity])?$conf->product->multidir_temp[$entity]:$conf->service->multidir_temp[$entity]).'/'.$original_file;
} }
// Wrapping for products or services // Wrapping for products or services
elseif ($modulepart == 'product') elseif ($modulepart == 'product')
{ {
if ($user->rights->produit->lire || $user->rights->service->lire) $accessallowed=1; if ($user->rights->produit->lire || $user->rights->service->lire) $accessallowed=1;
$original_file=(! empty($conf->product->multidir_output[GETPOST('entity','int')])?$conf->product->multidir_output[GETPOST('entity','int')]:$conf->service->multidir_output[GETPOST('entity','int')]).'/'.$original_file; $original_file=(! empty($conf->product->multidir_output[$entity])?$conf->product->multidir_output[$entity]:$conf->service->multidir_output[$entity]).'/'.$original_file;
} }
// Wrapping for products or services // Wrapping for products or services
elseif ($modulepart == 'tax') elseif ($modulepart == 'tax')
@ -215,7 +216,7 @@ if ($modulepart)
elseif ($modulepart == 'category') elseif ($modulepart == 'category')
{ {
if ($user->rights->categorie->lire) $accessallowed=1; if ($user->rights->categorie->lire) $accessallowed=1;
$original_file=$conf->categorie->dir_output.'/'.$original_file; $original_file=$conf->categorie->multidir_output[$entity].'/'.$original_file;
} }
// Wrapping pour les prelevements // Wrapping pour les prelevements
elseif ($modulepart == 'prelevement') elseif ($modulepart == 'prelevement')
@ -239,7 +240,7 @@ if ($modulepart)
elseif ($modulepart == 'graph_product') elseif ($modulepart == 'graph_product')
{ {
$accessallowed=1; $accessallowed=1;
$original_file=$conf->product->multidir_temp[GETPOST('entity','int')].'/'.$original_file; $original_file=$conf->product->multidir_temp[$entity].'/'.$original_file;
} }
// Wrapping pour les code barre // Wrapping pour les code barre
elseif ($modulepart == 'barcode') elseif ($modulepart == 'barcode')