From 921c8607d76867481fecdfa2c8c354efc13b8454 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 7 Apr 2012 10:18:09 +0200 Subject: [PATCH] Fix: multicompany sharings and uniformize code --- htdocs/categories/class/categorie.class.php | 19 +- htdocs/categories/photos.php | 433 +++++++++--------- htdocs/core/class/conf.class.php | 5 +- .../societe/doc/doc_generic_odt.modules.php | 4 +- htdocs/document.php | 17 +- htdocs/viewimage.php | 19 +- 6 files changed, 247 insertions(+), 250 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 409f7329be2..99686eed40d 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -73,7 +73,7 @@ class Categorie */ 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.= " WHERE rowid = ".$id; @@ -83,12 +83,13 @@ class Categorie { $res = $this->db->fetch_array($resql); - $this->id = $res['rowid']; - $this->label = $res['label']; - $this->description = $res['description']; - $this->socid = $res['fk_soc']; - $this->visible = $res['visible']; - $this->type = $res['type']; + $this->id = $res['rowid']; + $this->label = $res['label']; + $this->description = $res['description']; + $this->socid = $res['fk_soc']; + $this->visible = $res['visible']; + $this->type = $res['type']; + $this->entity = $res['entity']; $this->db->free($resql); } @@ -1284,6 +1285,8 @@ class Categorie */ function liste_photos($dir,$nbmax=0) { + include_once(DOL_DOCUMENT_ROOT ."/core/lib/files.lib.php"); + $nbphoto=0; $tabobj=array(); @@ -1296,7 +1299,7 @@ class Categorie { 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++; $photo = $file; diff --git a/htdocs/categories/photos.php b/htdocs/categories/photos.php index 7730347f286..d25a5520e22 100644 --- a/htdocs/categories/photos.php +++ b/htdocs/categories/photos.php @@ -51,6 +51,13 @@ if ($id == "") $result = restrictedArea($user, 'categorie', $id, '&category'); $object = new Categorie($db); +if ($id > 0) +{ + $result = $object->fetch($id); + + $upload_dir = $conf->categorie->multidir_output[$object->entity]; +} + /* * Actions @@ -58,22 +65,17 @@ $object = new Categorie($db); if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) { - if ($id) - { - $result = $object->fetch($id); - - $result = $object->add_photo($conf->categorie->dir_output, $_FILES['userfile']); - } + if ($object->id) $result = $object->add_photo($upload_dir, $_FILES['userfile']); } 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"]) { - $object->add_thumb($conf->categorie->dir_output."/".$_GET["file"]); + $object->add_thumb($upload_dir."/".$_GET["file"]); } @@ -85,215 +87,210 @@ llxHeader("","",$langs->trans("Categories")); $form = new Form($db); -if (!empty($id) || !empty($ref)) +if ($object->id) { - $result = $object->fetch($id); - - if ($result) - { - $title=$langs->trans("ProductsCategoryShort"); - if ($type == 0) $title=$langs->trans("ProductsCategoryShort"); - elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort"); - elseif ($type == 2) $title=$langs->trans("CustomersCategoryShort"); - elseif ($type == 3) $title=$langs->trans("MembersCategoryShort"); - - $head = categories_prepare_head($object,$type); - dol_fiche_head($head, 'photos', $title, 0, 'category'); - - /* - * Confirmation de la suppression de photo - */ - if ($action == 'delete') - { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1); - if ($ret == 'html') print '
'; - } - - print($mesg); - - print ''; - - // Path of category - print ''; - - // Description - print ''; - - // Visibility - /* if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) - { - if ($object->socid) - { - $soc = new Societe($db); - $soc->fetch($object->socid); - - print ''; - - $catsMeres = $object->get_meres (); - - if ($catsMeres < 0) - { - dol_print_error(); - } - else if (count($catsMeres) > 0) - { - print ''; - } - } - else - { - print ''; - } - } - else - { - print ''; - } - */ - - print "
'; - $ways = $object->print_all_ways(); - print $langs->trans("Ref").''; - print ''.$langs->trans("Root").' >> '; - foreach ($ways as $way) - { - print $way."
\n"; - } - print '
'; - print $langs->trans("Description").''; - print nl2br($object->description); - print '
'; - print $langs->trans("AssignedToTheCustomer").''; - print $soc->getNomUrl(1); - print '
'; - print $langs->trans("CategoryContents").''; - print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); - print '
'; - print $langs->trans("CategoryContents").''; - print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); - print '
'; - print $langs->trans("CategoryContents").''; - print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); - print '
\n"; - - print "\n"; - - - - /* ************************************************************************** */ - /* */ - /* Barre d'action */ - /* */ - /* ************************************************************************** */ - - print "\n
\n"; - - if ($action != 'ajout_photo' && $user->rights->produit->creer) - { - if (! empty($conf->global->MAIN_UPLOAD_DOC)) - { - print ''; - print $langs->trans("AddPhoto").''; - } - else - { - print ''; - print $langs->trans("AddPhoto").''; - } - } - - print "\n
\n"; - - /* - * Ajouter une photo - */ - if ($action == 'ajout_photo' && $user->rights->categorie->creer && ! empty($conf->global->MAIN_UPLOAD_DOC)) - { - // Affiche formulaire upload - $formfile=new FormFile($db); - $formfile->form_attach_new_file(DOL_URL_ROOT.'/categories/photos.php?id='.$object->id.'&type='.$type,$langs->trans("AddPhoto"),1); - } - - // Affiche photos - if ($action != 'ajout_photo') - { - $nbphoto=0; - $nbbyrow=5; - - $maxWidth = 160; - $maxHeight = 120; - - $pdir = get_exdir($object->id,2) . $object->id ."/photos/"; - $dir = $conf->categorie->dir_output.'/'.$pdir; - - print '
'; - print ''; - - foreach ($object->liste_photos($dir) as $key => $obj) - { - $nbphoto++; - - - if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print ''; - if ($nbbyrow) print ''; - if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print ''; - } - - // Ferme tableau - while ($nbphoto % $nbbyrow) - { - print ''; - $nbphoto++; - } - - if ($nbphoto < 1) - { - print ''; - } - - print '
'; - - print ''; - - // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine - if ($obj['photo_vignette']) - { - $filename='thumbs/'.$obj['photo_vignette']; - } - else - { - $filename=$obj['photo']; - } - - // Nom affiche - $viewfilename=$obj['photo']; - - // Taille de l'image - $object->get_image_size($dir.$filename); - $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth; - $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight; - - print ''; - - print ''; - print '
'.$viewfilename; - print '
'; - - // 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)) - { - print ''.img_picto($langs->trans('GenerateThumb'),'refresh').'  '; - } - if ($user->rights->categorie->creer) - { - print ''; - print img_delete().''; - } - if ($nbbyrow) print '
 
'; - print "
".$langs->trans("NoPhotoYet")."

"; - print '
'; - } - } + $title=$langs->trans("ProductsCategoryShort"); + if ($type == 0) $title=$langs->trans("ProductsCategoryShort"); + elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort"); + elseif ($type == 2) $title=$langs->trans("CustomersCategoryShort"); + elseif ($type == 3) $title=$langs->trans("MembersCategoryShort"); + + $head = categories_prepare_head($object,$type); + dol_fiche_head($head, 'photos', $title, 0, 'category'); + + /* + * Confirmation de la suppression de photo + */ + if ($action == 'delete') + { + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1); + if ($ret == 'html') print '
'; + } + + print($mesg); + + print ''; + + // Path of category + print ''; + + // Description + print ''; + + // Visibility + /* if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) + { + if ($object->socid) + { + $soc = new Societe($db); + $soc->fetch($object->socid); + + print ''; + + $catsMeres = $object->get_meres (); + + if ($catsMeres < 0) + { + dol_print_error(); + } + else if (count($catsMeres) > 0) + { + print ''; + } + } + else + { + print ''; + } + } + else + { + print ''; + } + */ + + print "
'; + $ways = $object->print_all_ways(); + print $langs->trans("Ref").''; + print ''.$langs->trans("Root").' >> '; + foreach ($ways as $way) + { + print $way."
\n"; + } + print '
'; + print $langs->trans("Description").''; + print nl2br($object->description); + print '
'; + print $langs->trans("AssignedToTheCustomer").''; + print $soc->getNomUrl(1); + print '
'; + print $langs->trans("CategoryContents").''; + print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print '
'; + print $langs->trans("CategoryContents").''; + print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print '
'; + print $langs->trans("CategoryContents").''; + print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print '
\n"; + + print "\n"; + + + + /* ************************************************************************** */ + /* */ + /* Barre d'action */ + /* */ + /* ************************************************************************** */ + + print "\n
\n"; + + if ($action != 'ajout_photo' && $user->rights->categorie->creer) + { + if (! empty($conf->global->MAIN_UPLOAD_DOC)) + { + print ''; + print $langs->trans("AddPhoto").''; + } + else + { + print ''; + print $langs->trans("AddPhoto").''; + } + } + + print "\n
\n"; + + /* + * Ajouter une photo + */ + if ($action == 'ajout_photo' && $user->rights->categorie->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.'&type='.$type,$langs->trans("AddPhoto"),1); + } + + // Affiche photos + if ($action != 'ajout_photo') + { + $nbphoto=0; + $nbbyrow=5; + + $maxWidth = 160; + $maxHeight = 120; + + $pdir = get_exdir($object->id,2) . $object->id ."/photos/"; + $dir = $upload_dir.'/'.$pdir; + + print '
'; + print ''; + + foreach ($object->liste_photos($dir) as $key => $obj) + { + $nbphoto++; + + + if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print ''; + if ($nbbyrow) print ''; + if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print ''; + } + + // Ferme tableau + while ($nbphoto % $nbbyrow) + { + print ''; + $nbphoto++; + } + + if ($nbphoto < 1) + { + print ''; + } + + print '
'; + + print ''; + + // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine + if ($obj['photo_vignette']) + { + $filename='thumbs/'.$obj['photo_vignette']; + } + else + { + $filename=$obj['photo']; + } + + // Nom affiche + $viewfilename=$obj['photo']; + + // Taille de l'image + $object->get_image_size($dir.$filename); + $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth; + $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight; + + print ''; + + print ''; + print '
'.$viewfilename; + print '
'; + + // 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)) + { + print ''.img_picto($langs->trans('GenerateThumb'),'refresh').'  '; + } + if ($user->rights->categorie->creer) + { + print ''; + print img_delete().''; + } + if ($nbbyrow) print '
 
'; + print "
".$langs->trans("NoPhotoYet")."

"; + print '
'; + } } else { @@ -301,8 +298,6 @@ else } - -$db->close(); - llxFooter(); +$db->close(); ?> diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index caf9c88428e..8b220b58800 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -265,10 +265,6 @@ class Conf $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 foreach($this->modules as $module) { @@ -422,6 +418,7 @@ class Conf $this->invoice=$this->facture; $this->order=$this->commande; $this->contract=$this->contrat; + $this->category=$this->categorie; // Define menu manager in setup diff --git a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php index c079a5101e0..ddf4385424a 100644 --- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php @@ -220,14 +220,14 @@ class doc_generic_odt extends ModeleThirdPartyDoc //print "file=".$file; //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 require_once(ODTPHP_PATH.'odf.php'); $odfHandler = new odf( $srctemplatepath, 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. 'DELIMITER_LEFT' => '{', 'DELIMITER_RIGHT' => '}' diff --git a/htdocs/document.php b/htdocs/document.php index 723a861ee1e..d4a91010466 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -50,10 +50,11 @@ require("./main.inc.php"); // Load $user and permissions require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); $encoding = ''; -$action = GETPOST('action','alpha'); -$original_file = GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP). -$modulepart = GETPOST('modulepart','alpha'); -$urlsource = GETPOST('urlsource','alpha'); +$action=GETPOST('action','alpha'); +$original_file=GETPOST('file','alpha'); // Do not use urldecode here ($_GET are already decoded by PHP). +$modulepart=GETPOST('modulepart','alpha'); +$urlsource=GETPOST('urlsource','alpha'); +$entity=GETPOST('entity','int'); // Security check if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart'); @@ -130,8 +131,8 @@ if ($modulepart) { $accessallowed=1; } - $original_file=$conf->societe->multidir_output[GETPOST('entity','int')].'/'.$original_file; - $sqlprotectagainstexternals = "SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX."societe WHERE rowid='".$refname."' AND entity=".$conf->entity; + $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 IN (".getEntity('societe', 1).")"; } // Wrapping for invoices @@ -299,8 +300,8 @@ if ($modulepart) { $accessallowed=1; } - if ($conf->product->enabled) $original_file=$conf->product->multidir_output[GETPOST('entity','int')].'/'.$original_file; - elseif ($conf->service->enabled) $original_file=$conf->service->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[$entity].'/'.$original_file; } // Wrapping pour les contrats diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php index 6bddaa8d268..148202b4f98 100644 --- a/htdocs/viewimage.php +++ b/htdocs/viewimage.php @@ -48,10 +48,11 @@ require("./main.inc.php"); require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); -$action = GETPOST('action','alpha'); -$original_file = GETPOST("file"); -$modulepart = GETPOST('modulepart','alpha'); -$urlsource = GETPOST("urlsource"); +$action=GETPOST('action','alpha'); +$original_file=GETPOST("file"); +$modulepart=GETPOST('modulepart','alpha'); +$urlsource=GETPOST("urlsource"); +$entity=GETPOST('entity','int'); // Security check @@ -121,7 +122,7 @@ if ($modulepart) elseif ($modulepart == 'societe') { $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 elseif ($modulepart == 'apercufacture') @@ -197,13 +198,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->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 elseif ($modulepart == 'product') { 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 elseif ($modulepart == 'tax') @@ -215,7 +216,7 @@ if ($modulepart) elseif ($modulepart == 'category') { 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 elseif ($modulepart == 'prelevement') @@ -239,7 +240,7 @@ if ($modulepart) elseif ($modulepart == 'graph_product') { $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 elseif ($modulepart == 'barcode')