diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index c4ac5efd00f..200ca7526fb 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -22,20 +22,20 @@ */ /** - \file htdocs/categories/categorie.class.php - \ingroup categorie - \brief Fichier de la classe des categorie - \version $Id$ -*/ + * \file htdocs/categories/categorie.class.php + * \ingroup categorie + * \brief Fichier de la classe des categorie + * \version $Id$ + */ require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php"); /** - \class Categorie - \brief Classe permettant la gestion des categories -*/ + * \class Categorie + * \brief Classe permettant la gestion des categories + */ class Categorie { var $error; @@ -54,10 +54,10 @@ class Categorie /** - * Constructeur - * db : accès base de données - * id : id de la catégorie - */ + * Constructeur + * db : accès base de données + * id : id de la catégorie + */ function Categorie($db, $id=-1) { $this->db = $db; @@ -67,9 +67,9 @@ class Categorie } /** - * Charge la catégorie - * id : id de la catégorie à charger - */ + * Charge la catégorie + * id : id de la catégorie à charger + */ function fetch($id) { $sql = "SELECT rowid, label, description, fk_soc, visible, type"; @@ -117,11 +117,11 @@ class Categorie } /** - * Ajoute la catégorie dans la base de données - * retour : -1 : erreur SQL - * -2 : nouvel ID inconnu - * -3 : catégorie invalide - */ + * Ajoute la catégorie dans la base de données + * retour : -1 : erreur SQL + * -2 : nouvel ID inconnu + * -3 : catégorie invalide + */ function create() { global $conf,$langs; @@ -180,11 +180,11 @@ class Categorie } /** - * Mise à jour de la catégorie - * retour : 1 : OK - * -1 : erreur SQL - * -2 : catégorie invalide - */ + * Mise à jour de la catégorie + * retour : 1 : OK + * -1 : erreur SQL + * -2 : catégorie invalide + */ function update() { global $conf; @@ -248,10 +248,10 @@ class Categorie } /** - * Supprime la catégorie - * Les produits et sous-catégories deviennent orphelins - * si $all = false, et sont (seront :) supprimés sinon - */ + * Supprime la catégorie + * Les produits et sous-catégories deviennent orphelins + * si $all = false, et sont (seront :) supprimés sinon + */ function remove ($all = false) { @@ -291,12 +291,12 @@ class Categorie /** - * Ajout d'une sous-catégorie - * $fille : objet catégorie - * retour : 1 : OK - * -2 : $fille est déjà dans la famille de $this - * -3 : catégorie ($this ou $fille) invalide - */ + * Ajout d'une sous-catégorie + * $fille : objet catégorie + * retour : 1 : OK + * -2 : $fille est déjà dans la famille de $this + * -3 : catégorie ($this ou $fille) invalide + */ function add_fille() { @@ -315,11 +315,11 @@ class Categorie } /** - * Suppression d'une sous-catégorie (seulement "désassociation") - * $fille : objet catégorie - * retour : 1 : OK - * -3 : catégorie ($this ou $fille) invalide - */ + * Suppression d'une sous-catégorie (seulement "désassociation") + * $fille : objet catégorie + * retour : 1 : OK + * -3 : catégorie ($this ou $fille) invalide + */ function del_fille($fille) { if (!$this->check() || !$fille->check()) @@ -342,11 +342,11 @@ class Categorie } /** - * \brief Link an object to the category - * \param obj Object to link to category - * \param type Type of category - * \return int 1 : OK, -1 : erreur SQL, -2 : id non renseign, -3 : Already linked - */ + * \brief Link an object to the category + * \param obj Object to link to category + * \param type Type of category + * \return int 1 : OK, -1 : erreur SQL, -2 : id non renseign, -3 : Already linked + */ function add_type($obj,$type) { if ($this->id == -1) @@ -377,11 +377,11 @@ class Categorie } /** - * Suppresion d'un produit de la catégorie - * @param $prod est un objet de type produit - * retour : 1 : OK - * -1 : erreur SQL - */ + * Suppresion d'un produit de la catégorie + * @param $prod est un objet de type produit + * retour : 1 : OK + * -1 : erreur SQL + */ function del_type($obj,$type) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_".$type; @@ -400,11 +400,11 @@ class Categorie } /** - * \brief Retourne les produits de la catégorie - * \param field Field name for select in table. Full field name will be fk_field. - * \param class PHP Class of object to store entity - * \param table Table name for select in table. Full table name will be PREFIX_categorie_table. - */ + * \brief Retourne les produits de la catégorie + * \param field Field name for select in table. Full field name will be fk_field. + * \param class PHP Class of object to store entity + * \param table Table name for select in table. Full table name will be PREFIX_categorie_table. + */ function get_type($field,$class,$table='') { $objs = array(); @@ -440,8 +440,8 @@ class Categorie /** - * Retourne les filles de la catégorie - */ + * Retourne les filles de la catégorie + */ function get_filles () { $sql = "SELECT fk_categorie_fille FROM ".MAIN_DB_PREFIX."categorie_association "; @@ -468,8 +468,8 @@ class Categorie /** - * retourne la description d'une catégorie - */ + * retourne la description d'une catégorie + */ function get_desc ($cate) { $sql = "SELECT description FROM ".MAIN_DB_PREFIX."categorie "; @@ -482,8 +482,8 @@ class Categorie } /** - * La catégorie $fille est-elle une fille de cette catégorie ? - */ + * La catégorie $fille est-elle une fille de cette catégorie ? + */ function is_fille ($fille) { $sql = "SELECT count(fk_categorie_fille) FROM ".MAIN_DB_PREFIX."categorie_association "; @@ -498,18 +498,18 @@ class Categorie /** - * \brief Reconstruit l'arborescence des catégories sous la forme d'un tableau - * Renvoi un tableau de tableau('id','id_mere',...) trié selon - * arbre et avec: - * id = id de la categorie - * id_mere = id de la categorie mere - * id_children = tableau des id enfant - * label = nom de la categorie - * fulllabel = nom avec chemin complet de la categorie - * fullpath = chemin complet compose des id - * \param type Type de categories (0=produit, 1=fournisseur, 2=client) - * \return array Tableau de array - */ + * \brief Reconstruit l'arborescence des catégories sous la forme d'un tableau + * Renvoi un tableau de tableau('id','id_mere',...) trié selon + * arbre et avec: + * id = id de la categorie + * id_mere = id de la categorie mere + * id_children = tableau des id enfant + * label = nom de la categorie + * fulllabel = nom avec chemin complet de la categorie + * fullpath = chemin complet compose des id + * \param type Type de categories (0=produit, 1=fournisseur, 2=client) + * \return array Tableau de array + */ function get_full_arbo($type) { $this->cats = array(); @@ -583,17 +583,17 @@ class Categorie } /** - * \brief For category id_categ and its child available in this->cats, define property fullpath and fulllabel - * \param id_categ id_categ entry to update - * \param protection Deep counter to avoid infinite loop - */ + * \brief For category id_categ and its child available in this->cats, define property fullpath and fulllabel + * \param id_categ id_categ entry to update + * \param protection Deep counter to avoid infinite loop + */ function build_path_from_id_categ($id_categ,$protection=0) { dol_syslog("Categorie::build_path_from_id_categ id_categ=".$id_categ." protection=".$protection, LOG_DEBUG); //if (! empty($this->cats[$id_categ]['fullpath'])) //{ - // Already defined + // Already defined // dol_syslog("Categorie::build_path_from_id_categ fullpath and fulllabel already defined", LOG_WARNING); // return; //} @@ -634,8 +634,8 @@ class Categorie } /** - * \brief Affiche contenu de $this->cats - */ + * \brief Affiche contenu de $this->cats + */ function debug_cats() { // Affiche $this->cats @@ -653,9 +653,9 @@ class Categorie /** - * \brief Retourne toutes les catégories - * \return array Tableau d'objet Categorie - */ + * \brief Retourne toutes les catégories + * \return array Tableau d'objet Categorie + */ function get_all_categories () { $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie"; @@ -679,9 +679,9 @@ class Categorie } /** - * \brief Retourne le nombre total de catégories - * \return int Nombre de categories - */ + * \brief Retourne le nombre total de catégories + * \return int Nombre de categories + */ function get_nb_categories () { $sql = "SELECT count(rowid)"; @@ -700,8 +700,8 @@ class Categorie } /** - * Vérifie si une catégorie porte le label $label - */ + * Vérifie si une catégorie porte le label $label + */ function already_exists() { $sql = "SELECT count(c.rowid)"; @@ -731,8 +731,8 @@ class Categorie } /** - * \brief Retourne les catégories de premier niveau (qui ne sont pas filles) - */ + * \brief Retourne les catégories de premier niveau (qui ne sont pas filles) + */ function get_main_categories () { $allcats = $this->get_all_categories (); @@ -761,9 +761,9 @@ class Categorie } /** - * Retourne les chemin de la catégorie, avec les noms des catégories - * séparés par $sep (" >> " par défaut) - */ + * Retourne les chemin de la catégorie, avec les noms des catégories + * séparés par $sep (" >> " par défaut) + */ function print_all_ways ($sep = " >> ", $url='') { $ways = array (); @@ -790,8 +790,8 @@ class Categorie /** - * get_primary_way() affiche le chemin le plus court pour se rendre à un produit - */ + * get_primary_way() affiche le chemin le plus court pour se rendre à un produit + */ function get_primary_way($id, $type="") { $primary_way = Array("taille"=>-1,"chemin"=>Array()); @@ -812,8 +812,8 @@ class Categorie } /** - * print_primary_way() affiche le chemin le plus court pour se rendre à un produit - */ + * print_primary_way() affiche le chemin le plus court pour se rendre à un produit + */ function print_primary_way($id, $sep= " >> ", $url, $type="") { $primary_way = Array(); @@ -835,8 +835,8 @@ class Categorie } /** - * Retourne un tableau contenant la liste des catégories mères - */ + * Retourne un tableau contenant la liste des catégories mères + */ function get_meres () { $meres = array (); @@ -862,9 +862,9 @@ class Categorie } /** - * Retourne dans un tableau tous les chemins possibles pour arriver à la catégorie - * en partant des catégories principales, représentés par des tableaux de catégories - */ + * Retourne dans un tableau tous les chemins possibles pour arriver à la catégorie + * en partant des catégories principales, représentés par des tableaux de catégories + */ function get_all_ways () { $ways = array (); @@ -887,12 +887,12 @@ class Categorie } /** - * Return list of categories linked to element of type $type with id $typeid - * @param id Id of element - * @param type Type of link ('customer','fournisseur','societe'...) - * @param typeid Type id of link (0,1,2...) - * @return array List of category objects - */ + * Return list of categories linked to element of type $type with id $typeid + * @param id Id of element + * @param type Type of link ('customer','fournisseur','societe'...) + * @param typeid Type id of link (0,1,2...) + * @return array List of category objects + */ function containing ($id,$type,$typeid) { $cats = array (); @@ -921,9 +921,9 @@ class Categorie /** - * \brief Retourne les catégories dont l'id ou le nom correspond - * ajoute des wildcards au nom sauf si $exact = true - */ + * \brief Retourne les catégories dont l'id ou le nom correspond + * ajoute des wildcards au nom sauf si $exact = true + */ function rechercher($id, $nom, $type, $exact = false) { $cats = array (); @@ -963,18 +963,19 @@ class Categorie } /** - * \brief Renvoie nom clicable (avec eventuellement le picto) + * \brief Return name and link of category (with picto) * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul - * \param option Sur quoi pointe le lien ('', 'withdraw') + * \param option Sur quoi pointe le lien ('', 'xyz') + * \param maxlength Max length of text * \return string Chaine avec URL */ - function getNomUrl($withpicto=0,$option='') + function getNomUrl($withpicto=0,$option='',$maxlength=0) { global $langs; $result=''; - $lien = ''; + $lien = ''; $label=$this->label; $lienfin=''; @@ -984,9 +985,145 @@ class Categorie if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; + if ($withpicto != 2) $result.=$lien.dol_trunc($this->ref,$maxlength).$lienfin; return $result; } + + /** + * \brief Deplace fichier uploade sous le nom $files dans le repertoire sdir + * \param sdir Repertoire destination finale + * \param $file Nom du fichier uploade + * \param maxWidth Largeur maximum que dois faire la miniature (160 par defaut) + * \param maxHeight Hauteur maximum que dois faire la miniature (120 par defaut) + */ + function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120) + { + $dir = $sdir .'/'. get_exdir($this->id,2) . $this->id ."/"; + $dir .= "photos/"; + + if (! file_exists($dir)) + { + create_exdir($dir); + } + + if (file_exists($dir)) + { + $originImage = $dir . $file['name']; + + // Cree fichier en taille origine + $result=dol_move_uploaded_file($file['tmp_name'], $originImage, 1); + + if (file_exists($originImage)) + { + // Cree fichier en taille vignette + $this->add_thumb($originImage,$maxWidth,$maxHeight); + } + } + } + + /** + * \brief Build thumb + * \param sdir Repertoire destination finale + * \param file Chemin du fichier d'origine + * \param maxWidth Largeur maximum que dois faire la miniature (160 par defaut) + * \param maxHeight Hauteur maximum que dois faire la miniature (120 par defaut) + */ + function add_thumb($file, $maxWidth = 160, $maxHeight = 120) + { + require_once(DOL_DOCUMENT_ROOT ."/lib/images.lib.php"); + + if (file_exists($file)) + { + vignette($file,$maxWidth,$maxHeight); + } + } + + + /** + * \brief Retourne tableau de toutes les photos de la categorie + * \param dir R?pertoire ? scanner + * \param nbmax Nombre maximum de photos (0=pas de max) + * \return array Tableau de photos + */ + function liste_photos($dir,$nbmax=0) + { + $nbphoto=0; + $tabobj=array(); + + $dirthumb = $dir.'thumbs/'; + + if (file_exists($dir)) + { + $handle=opendir($dir); + + while (($file = readdir($handle)) != false) + { + if (is_file($dir.$file)) + { + $nbphoto++; + $photo = $file; + + // On determine nom du fichier vignette + $photo_vignette=''; + if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs)) + { + $photo_vignette=eregi_replace($regs[0],'',$photo).'_small'.$regs[0]; + } + + // Objet + $obj=array(); + $obj['photo']=$photo; + if ($photo_vignette && is_file($dirthumb.$photo_vignette)) $obj['photo_vignette']=$photo_vignette; + else $obj['photo_vignette']=""; + + $tabobj[$nbphoto-1]=$obj; + + // On continue ou on arrete de boucler ? + if ($nbmax && $nbphoto >= $nbmax) break; + } + } + + closedir($handle); + } + + return $tabobj; + } + + /** + * \brief Efface la photo de la categorie et sa vignette + * \param file Chemin de l'image + */ + function delete_photo($file) + { + $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine + $dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette + $filename = eregi_replace($dir,'',$file); // Nom du fichier + + // On efface l'image d'origine + unlink($file); + + // Si elle existe, on efface la vignette + if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$filename,$regs)) + { + $photo_vignette=eregi_replace($regs[0],'',$filename).'_small'.$regs[0]; + if (file_exists($dirthumb.$photo_vignette)) + { + unlink($dirthumb.$photo_vignette); + } + } + } + + /** + * \brief Load size of image file + * \param file Path to file + */ + function get_image_size($file) + { + $infoImg = getimagesize($file); // R?cup?ration des infos de l'image + $this->imgWidth = $infoImg[0]; // Largeur de l'image + $this->imgHeight = $infoImg[1]; // Hauteur de l'image + } + } ?> diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index 737090dccff..675bf77dff6 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -23,7 +23,7 @@ /** * \file htdocs/categories/index.php * \ingroup category - * \brief Page accueil espace categories + * \brief Home page of category area * \version $Id$ */ @@ -144,7 +144,7 @@ print ''; print ''; print ' '; print ' '; -print ' '; +//print ' '; print ''; @@ -249,23 +249,30 @@ foreach($fulltree as $key => $val) print ''; // Show link print ''; - if ($section == $val['id']) print ' '; + //if ($section == $val['id']) print ' '; + /* We don't want a link + $categstatic->id=$val['id']; + $categstatic->ref=$val['label']; + $categstatic->type=$type; + print $categstatic->getNomUrl(0,'',28); + */ print dol_trunc($val['label'],28); - if ($section == $val['id']) print ''; + //if ($section == $val['id']) print ''; print ''; print ''; print "\n"; + // Description print ''; print dol_trunc($categstatic->get_desc($val['id']),48); print ''; - // Edit link - print ''.img_edit().''; + // Link to category card + print ''.img_view().''; // Add link //print ''.img_edit_add().''; - print ' '; + //print ' '; print "\n"; } @@ -286,7 +293,7 @@ if ($nbofentries == 0) print ''; print ' '; print ''; - print ' '; + print ' '; print ''; } diff --git a/htdocs/categories/photos.php b/htdocs/categories/photos.php new file mode 100644 index 00000000000..994ccb179aa --- /dev/null +++ b/htdocs/categories/photos.php @@ -0,0 +1,324 @@ + + * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2005 Eric Seigne + * Copyright (C) 2005-2007 Regis Houssin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * \file htdocs/categories/photos.php + * \ingroup category + * \brief Gestion des photos d'une categorie + * \version $Id$ + */ + +require("./pre.inc.php"); + +require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); + +$langs->load("category"); +$langs->load("bills"); + +$mesg = ''; + +// Security check +if (!$user->rights->categorie->lire) accessforbidden(); + +if ($_REQUEST['id'] == "") +{ + dol_print_error('','Missing parameter id'); + exit(); +} + + +/* + * Actions + */ + +if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC)) +{ + if ($_GET["id"]) + { + $c = new Categorie($db); + $result = $c->fetch($_GET["id"]); + + $result = $c->add_photo($conf->categorie->dir_output, $_FILES['userfile']); + } +} + + +if ($_REQUEST["action"] == 'confirm_delete' && $_GET["file"] && $_REQUEST['confirm'] == 'yes' && $user->rights->categorie->creer) +{ + $c = new Categorie($db); + $c->delete_photo($conf->categorie->dir_output."/".$_GET["file"]); +} + +if ($_GET["action"] == 'addthumb' && $_GET["file"]) +{ + $c = new Category($db); + $c->add_thumb($conf->categorie->dir_output."/".$_GET["file"]); +} + + +/* + * View + */ + +llxHeader ("","",$langs->trans("Categories")); + +$c = new Categorie($db); +$c->fetch($_REQUEST['id']); + +$html = new Form($db); + +if ($_GET["id"] || $_GET["ref"]) +{ + $c = new Categorie($db); + + if ($_GET["id"]) $result = $c->fetch($_GET["id"]); + + + if ($result) + { + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/categories/viewcat.php?id='.$c->id.'&type='.$type; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/categories/photos.php?id='.$c->id.'&type='.$type; + $head[$h][1] = $langs->trans("Photos"); + $head[$h][2] = 'photos'; + $h++; + + if ($type == 0) $title=$langs->trans("ProductsCategoryShort"); + if ($type == 1) $title=$langs->trans("SuppliersCategoryShort"); + if ($type == 2) $title=$langs->trans("CustomersCategoryShort"); + + + $titre=$langs->trans("ProductsCategoryShort"); + dol_fiche_head($head, 'photos', $titre); + + /* + * Confirmation de la suppression de photo + */ + if ($_GET['action'] == 'delete') + { + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$c->id.'&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 ($c->socid) + { + $soc = new Societe($db); + $soc->fetch($c->socid); + + print ''; + + $catsMeres = $c->get_meres (); + + if ($catsMeres < 0) + { + dol_print_error(); + } + else if (count($catsMeres) > 0) + { + print ''; + } + } + else + { + print ''; + } + } + else + { + print ''; + } + + print "
'; + $ways = $c->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($c->description); + print '
'; + print $langs->trans("AssignedToTheCustomer").''; + print $soc->getNomUrl(1); + print '
'; + print $langs->trans("CategoryContents").''; + print ($c->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print '
'; + print $langs->trans("CategoryContents").''; + print ($c->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print '
'; + print $langs->trans("CategoryContents").''; + print ($c->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); + print '
\n"; + + print "\n"; + + + + /* ************************************************************************** */ + /* */ + /* Barre d'action */ + /* */ + /* ************************************************************************** */ + + print "\n
\n"; + + if ($_GET["action"] != 'ajout_photo' && $user->rights->produit->creer) + { + if (! empty($conf->global->MAIN_UPLOAD_DOC)) + { + print ''; + print $langs->trans("AddPhoto").''; + } + else + { + print 'e'; + print $langs->trans("AddPhoto").''; + } + } + + print "\n
\n"; + + /* + * Ajouter une photo + */ + if ($_GET["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='.$c->id,$langs->trans("AddPhoto"),1); + } + + // Affiche photos + // Affiche photos + if ($_GET["action"] != 'ajout_photo') + { + $nbphoto=0; + $nbbyrow=5; + + $maxWidth = 160; + $maxHeight = 120; + + $pdir = get_exdir($c->id,2) . $c->id ."/photos/"; + $dir = $conf->categorie->dir_output.'/'.$pdir; + + print '
'; + print ''; + + foreach ($c->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 + $c->get_image_size($dir.$filename); + $imgWidth = ($c->imgWidth < $maxWidth) ? $c->imgWidth : $maxWidth; + $imgHeight = ($c->imgHeight < $maxHeight) ? $c->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'] && eregi('(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$',$obj['photo']) && ($c->imgWidth > $maxWidth || $c->imgHeight > $maxHeight)) + { + print ''.img_refresh($langs->trans('GenerateThumb')).'  '; + } + if ($user->rights->categorie->creer) + { + print ''; + print img_delete().''; + } + if ($nbbyrow) print '
 
'; + print "
".$langs->trans("NoPhotoYet")."

"; + print '
'; + } + } +} +else +{ + print $langs->trans("ErrorUnknown"); +} + + + +$db->close(); + +llxFooter('$Date$ - $Revision$'); +?> diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 0a5f1749b9e..e9ebb2ec4c5 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -20,23 +20,23 @@ */ /** - \file htdocs/categories/viewcat.php - \ingroup category - \brief Page de visualisation de categorie produit - \version $Revision$ -*/ + * \file htdocs/categories/viewcat.php + * \ingroup category + * \brief Page de visualisation de categorie produit + * \version $Revision$ + */ require("./pre.inc.php"); if ($_REQUEST['id'] == "") { - dol_print_error('','Missing parameter id'); - exit(); + dol_print_error('','Missing parameter id'); + exit(); } $type=$_REQUEST['type']; -// Securite +// Security check if (! $user->rights->categorie->lire) { accessforbidden(); @@ -50,8 +50,8 @@ $c->fetch($_REQUEST['id']); /* -* Actions -*/ + * Actions + */ if ($user->rights->categorie->supprimer && $_POST["action"] == 'confirm_delete' && $_POST['confirm'] == 'yes') { @@ -88,6 +88,11 @@ $head[$h][1] = $langs->trans("Card"); $head[$h][2] = 'card'; $h++; +$head[$h][0] = DOL_URL_ROOT.'/categories/photos.php?id='.$c->id.'&type='.$type; +$head[$h][1] = $langs->trans("Photos"); +$head[$h][2] = 'photos'; +$h++; + if ($type == 0) $title=$langs->trans("ProductsCategoryShort"); if ($type == 1) $title=$langs->trans("SuppliersCategoryShort"); if ($type == 2) $title=$langs->trans("CustomersCategoryShort"); @@ -96,8 +101,8 @@ dol_fiche_head($head, 'card', $title); /* -* Confirmation suppression -*/ + * Confirmation suppression + */ if ($_GET['action'] == 'delete') { $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$c->id.'&type='.$type,$langs->trans('DeleteCategory'),$langs->trans('ConfirmDeleteCategory'),'confirm_delete'); @@ -106,22 +111,24 @@ if ($_GET['action'] == 'delete') print ''; +// Path of category print ''; - +// Description print ''; +// Visibility if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) { if ($c->socid) @@ -232,20 +239,20 @@ else } print "
'; $ways = $c->print_all_ways (); print $langs->trans("Ref").''; print ''.$langs->trans("Root").' >> '; foreach ($ways as $way) { - print $way."
\n"; + print $way."
\n"; } print '
'; print $langs->trans("Description").''; print nl2br($c->description); print '
\n"; - /* - * Boutons actions - */ - if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) - { - print "
\n"; + /* + * Boutons actions + */ + if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) + { + print "
\n"; - if ($user->rights->categorie->creer) - { - print "".$langs->trans("Create").""; - } + if ($user->rights->categorie->creer) + { + print "".$langs->trans("Create").""; + } - print "
"; - } + print "
"; + } } @@ -255,7 +262,7 @@ if ($c->type == 0) $prods = $c->get_type ("product","Product"); if ($prods < 0) { - dol_print_error(); + dol_print_error(); } else { @@ -274,7 +281,7 @@ if ($c->type == 0) print "\t\n"; print ''; if ($prod->type == 1) print img_object($langs->trans("ShowService"),"service"); - else print img_object($langs->trans("ShowProduct"),"product"); + else print img_object($langs->trans("ShowProduct"),"product"); print " ".$prod->ref."\n"; print ''.$prod->libelle."\n"; print ''.$prod->description."\n"; @@ -294,7 +301,7 @@ if ($c->type == 1) $socs = $c->get_type ("societe","Fournisseur","fournisseur"); if ($socs < 0) { - dol_print_error(); + dol_print_error(); } else { @@ -331,7 +338,7 @@ if($c->type == 2) $socs = $c->get_type ("societe","Societe"); if ($socs < 0) { - dol_print_error(); + dol_print_error(); } else { diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index ebe9f27f993..94006bf3aa0 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -526,7 +526,7 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $ print ''; // Edit link - print ''.img_edit().''; + print ''.img_view().''; // Add link //print ''.img_edit_add().''; diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 732c0c13b3e..a05f59bd5c1 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2280,7 +2280,6 @@ class Product extends CommonObject if (! file_exists($dir)) { - dol_syslog("Product Create $dir"); create_exdir($dir); } @@ -2438,20 +2437,20 @@ class Product extends CommonObject // On continue ou on arrete de boucler ? if ($nbmax && $nbphoto >= $nbmax) break; } - } + } - if ($nbbyrow && $size==1) - { - // Ferme tableau - while ($nbphoto % $nbbyrow) { - print ' '; - $nbphoto++; - } + if ($nbbyrow && $size==1) + { + // Ferme tableau + while ($nbphoto % $nbbyrow) { + print ' '; + $nbphoto++; + } - if ($nbphoto) print ''; - } + if ($nbphoto) print ''; + } - closedir($handle); + closedir($handle); } return $nbphoto; @@ -2532,12 +2531,12 @@ class Product extends CommonObject } /** - * \brief Recupere la taille de l'image - * \param file Chemin de l'image + * \brief Load size of image file + * \param file Path to file */ function get_image_size($file) { - $infoImg = getimagesize($file); // R�cup�ration des infos de l'image + $infoImg = getimagesize($file); // Get information on image $this->imgWidth = $infoImg[0]; // Largeur de l'image $this->imgHeight = $infoImg[1]; // Hauteur de l'image } diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php index 500fc5291a7..13c06ef5709 100644 --- a/htdocs/product/photos.php +++ b/htdocs/product/photos.php @@ -57,11 +57,7 @@ if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global $product = new Product($db); $result = $product->fetch($_GET["id"]); - // if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],1) > 0) - - // var_dump($_FILES); - - $product->add_photo($conf->produit->dir_output, $_FILES['userfile']); + $result = $product->add_photo($conf->produit->dir_output, $_FILES['userfile']); } } @@ -219,7 +215,7 @@ if ($_GET["id"] || $_GET["ref"]) $filename=$obj['photo']; } - // Nom affich� + // Nom affiche $viewfilename=$obj['photo']; // Taille de l'image @@ -233,7 +229,7 @@ if ($_GET["id"] || $_GET["ref"]) print '
'.$viewfilename; print '
'; - // On propose la g�n�ration de la vignette si elle n'existe pas et si la taille est sup�rieure 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'] && eregi('(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$',$obj['photo']) && ($product->imgWidth > $maxWidth || $product->imgHeight > $maxHeight)) { print ''.img_refresh($langs->trans('GenerateThumb')).'  '; diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php index 2059fda407e..72081dfe912 100644 --- a/htdocs/viewimage.php +++ b/htdocs/viewimage.php @@ -73,257 +73,268 @@ $original_file = str_replace("../","/", $original_file); $accessallowed=0; if ($modulepart) { - // Check permissions and define directory + // Check permissions and define directory - // Wrapping pour les photo utilisateurs - if ($modulepart == 'companylogo') - { - $accessallowed=1; - $original_file=$conf->mycompany->dir_output.'/logos/'.$original_file; - } + // Wrapping pour les photo utilisateurs + if ($modulepart == 'companylogo') + { + $accessallowed=1; + $original_file=$conf->mycompany->dir_output.'/logos/'.$original_file; + } - // Wrapping pour les photos utilisateurs - elseif ($modulepart == 'userphoto') - { - $accessallowed=1; - $original_file=$conf->user->dir_output.'/'.$original_file; - } + // Wrapping pour les photos utilisateurs + elseif ($modulepart == 'userphoto') + { + $accessallowed=1; + $original_file=$conf->user->dir_output.'/'.$original_file; + } - // Wrapping pour les photos adherents - elseif ($modulepart == 'memberphoto') - { - $accessallowed=1; - $original_file=$conf->adherent->dir_output.'/'.$original_file; - } + // Wrapping pour les photos adherents + elseif ($modulepart == 'memberphoto') + { + $accessallowed=1; + $original_file=$conf->adherent->dir_output.'/'.$original_file; + } - // Wrapping pour les apercu factures - elseif ($modulepart == 'apercufacture') - { - $user->getrights('facture'); - if ($user->rights->facture->lire) - { - $accessallowed=1; - } - $original_file=$conf->facture->dir_output.'/'.$original_file; - } + // Wrapping pour les apercu factures + elseif ($modulepart == 'apercufacture') + { + $user->getrights('facture'); + if ($user->rights->facture->lire) + { + $accessallowed=1; + } + $original_file=$conf->facture->dir_output.'/'.$original_file; + } - // Wrapping pour les apercu propal - elseif ($modulepart == 'apercupropal') - { - $user->getrights('propale'); - if ($user->rights->propale->lire) - { - $accessallowed=1; - } - $original_file=$conf->propale->dir_output.'/'.$original_file; - } + // Wrapping pour les apercu propal + elseif ($modulepart == 'apercupropal') + { + $user->getrights('propale'); + if ($user->rights->propale->lire) + { + $accessallowed=1; + } + $original_file=$conf->propale->dir_output.'/'.$original_file; + } - // Wrapping pour les apercu commande - elseif ($modulepart == 'apercucommande') - { - $user->getrights('commande'); - if ($user->rights->commande->lire) - { - $accessallowed=1; - } - $original_file=$conf->commande->dir_output.'/'.$original_file; - } + // Wrapping pour les apercu commande + elseif ($modulepart == 'apercucommande') + { + $user->getrights('commande'); + if ($user->rights->commande->lire) + { + $accessallowed=1; + } + $original_file=$conf->commande->dir_output.'/'.$original_file; + } - // Wrapping pour les apercu intervention - elseif ($modulepart == 'apercufichinter') - { - $user->getrights('ficheinter'); - if ($user->rights->ficheinter->lire) - { - $accessallowed=1; - } - $original_file=$conf->ficheinter->dir_output.'/'.$original_file; - } + // Wrapping pour les apercu intervention + elseif ($modulepart == 'apercufichinter') + { + $user->getrights('ficheinter'); + if ($user->rights->ficheinter->lire) + { + $accessallowed=1; + } + $original_file=$conf->ficheinter->dir_output.'/'.$original_file; + } - // Wrapping pour les images des stats propales - elseif ($modulepart == 'propalstats') - { - $user->getrights('propale'); - if ($user->rights->propale->lire) - { - $accessallowed=1; - } - $original_file=$conf->propale->dir_temp.'/'.$original_file; - } + // Wrapping pour les images des stats propales + elseif ($modulepart == 'propalstats') + { + $user->getrights('propale'); + if ($user->rights->propale->lire) + { + $accessallowed=1; + } + $original_file=$conf->propale->dir_temp.'/'.$original_file; + } - // Wrapping pour les images des stats commandes - elseif ($modulepart == 'orderstats') - { - $user->getrights('commande'); - if ($user->rights->commande->lire) - { - $accessallowed=1; - } - $original_file=$conf->commande->dir_temp.'/'.$original_file; - } - elseif ($modulepart == 'orderstatssupplier') - { - $user->getrights('fournisseur'); - if ($user->rights->fournisseur->commande->lire) - { - $accessallowed=1; - } - $original_file=$conf->fournisseur->dir_output.'/commande/temp/'.$original_file; - } + // Wrapping pour les images des stats commandes + elseif ($modulepart == 'orderstats') + { + $user->getrights('commande'); + if ($user->rights->commande->lire) + { + $accessallowed=1; + } + $original_file=$conf->commande->dir_temp.'/'.$original_file; + } + elseif ($modulepart == 'orderstatssupplier') + { + $user->getrights('fournisseur'); + if ($user->rights->fournisseur->commande->lire) + { + $accessallowed=1; + } + $original_file=$conf->fournisseur->dir_output.'/commande/temp/'.$original_file; + } - // Wrapping pour les images des stats factures - elseif ($modulepart == 'billstats') - { - $user->getrights('facture'); - if ($user->rights->facture->lire) - { - $accessallowed=1; - } - $original_file=$conf->facture->dir_temp.'/'.$original_file; - } - elseif ($modulepart == 'billstatssupplier') - { - $user->getrights('fourn'); - if ($user->rights->fournisseur->facture->lire) - { - $accessallowed=1; - } - $original_file=$conf->fournisseur->dir_output.'/facture/temp/'.$original_file; - } + // Wrapping pour les images des stats factures + elseif ($modulepart == 'billstats') + { + $user->getrights('facture'); + if ($user->rights->facture->lire) + { + $accessallowed=1; + } + $original_file=$conf->facture->dir_temp.'/'.$original_file; + } + elseif ($modulepart == 'billstatssupplier') + { + $user->getrights('fourn'); + if ($user->rights->fournisseur->facture->lire) + { + $accessallowed=1; + } + $original_file=$conf->fournisseur->dir_output.'/facture/temp/'.$original_file; + } - // Wrapping pour les images des stats expeditions - elseif ($modulepart == 'expeditionstats') - { - $user->getrights('expedition'); - if ($user->rights->expedition->lire) - { - $accessallowed=1; - } - $original_file=$conf->expedition->dir_temp.'/'.$original_file; - } + // Wrapping pour les images des stats expeditions + elseif ($modulepart == 'expeditionstats') + { + $user->getrights('expedition'); + if ($user->rights->expedition->lire) + { + $accessallowed=1; + } + $original_file=$conf->expedition->dir_temp.'/'.$original_file; + } - // Wrapping pour les images des stats produits - elseif (eregi('^productstats_',$modulepart)) - { - $user->getrights('produit'); - if ($user->rights->produit->lire || $user->rights->service->lire) - { - $accessallowed=1; - } - $original_file=$conf->produit->dir_temp.'/'.$original_file; - } + // Wrapping pour les images des stats produits + elseif (eregi('^productstats_',$modulepart)) + { + $user->getrights('produit'); + if ($user->rights->produit->lire || $user->rights->service->lire) + { + $accessallowed=1; + } + $original_file=$conf->produit->dir_temp.'/'.$original_file; + } - // Wrapping pour les produits - elseif ($modulepart == 'product') - { - $user->getrights('produit'); - if ($user->rights->produit->lire || $user->rights->service->lire) - { - $accessallowed=1; - } - $original_file=$conf->produit->dir_output.'/'.$original_file; - } + // Wrapping for products or services + elseif ($modulepart == 'product') + { + $user->getrights('produit'); + if ($user->rights->produit->lire || $user->rights->service->lire) + { + $accessallowed=1; + } + $original_file=$conf->produit->dir_output.'/'.$original_file; + } - // Wrapping pour les prelevements - elseif ($modulepart == 'prelevement') - { - $user->getrights('prelevement'); - if ($user->rights->prelevement->bons->lire) $accessallowed=1; + // Wrapping for categories + elseif ($modulepart == 'category') + { + $user->getrights('categorie'); + if ($user->rights->categorie->lire) + { + $accessallowed=1; + } + $original_file=$conf->categorie->dir_output.'/'.$original_file; + } - $original_file=$conf->prelevement->dir_output.'/receipts/'.$original_file; - } + // Wrapping pour les prelevements + elseif ($modulepart == 'prelevement') + { + $user->getrights('prelevement'); + if ($user->rights->prelevement->bons->lire) $accessallowed=1; - // Wrapping pour les graph telephonie - elseif ($modulepart == 'telephoniegraph') - { - $user->getrights('telephonie'); - if ($user->rights->telephonie->lire) - { - $accessallowed=1; - } - $original_file=$conf->telephonie->dir_temp.'/'.$original_file; - } + $original_file=$conf->prelevement->dir_output.'/receipts/'.$original_file; + } - // Wrapping pour les graph energie - elseif ($modulepart == 'energie') - { - $accessallowed=1; - $original_file=$conf->energie->dir_temp.'/'.$original_file; - } + // Wrapping pour les graph telephonie + elseif ($modulepart == 'telephoniegraph') + { + $user->getrights('telephonie'); + if ($user->rights->telephonie->lire) + { + $accessallowed=1; + } + $original_file=$conf->telephonie->dir_temp.'/'.$original_file; + } - // Wrapping pour les graph bank - elseif ($modulepart == 'bank') - { - $accessallowed=1; - $original_file=$conf->banque->dir_temp.'/'.$original_file; - } + // Wrapping pour les graph energie + elseif ($modulepart == 'energie') + { + $accessallowed=1; + $original_file=$conf->energie->dir_temp.'/'.$original_file; + } - // Wrapping pour les images wysiwyg - elseif ($modulepart == 'fckeditor') - { - $accessallowed=1; - $original_file=$conf->fckeditor->dir_output.'/'.$original_file; - } + // Wrapping pour les graph bank + elseif ($modulepart == 'bank') + { + $accessallowed=1; + $original_file=$conf->banque->dir_temp.'/'.$original_file; + } - // Wrapping pour les images wysiwyg mailing - elseif ($modulepart == 'mailing') - { - $accessallowed=1; - $original_file=$conf->mailing->dir_output.'/'.$original_file; - } + // Wrapping pour les images wysiwyg + elseif ($modulepart == 'fckeditor') + { + $accessallowed=1; + $original_file=$conf->fckeditor->dir_output.'/'.$original_file; + } - // Wrapping pour les graph energie - elseif ($modulepart == 'graph_stock') - { - $accessallowed=1; - $original_file=$conf->stock->dir_temp.'/'.$original_file; - } + // Wrapping pour les images wysiwyg mailing + elseif ($modulepart == 'mailing') + { + $accessallowed=1; + $original_file=$conf->mailing->dir_output.'/'.$original_file; + } - // Wrapping pour les graph fournisseurs - elseif ($modulepart == 'graph_fourn') - { - $accessallowed=1; - $original_file=$conf->fournisseur->dir_temp.'/'.$original_file; - } + // Wrapping pour les graph energie + elseif ($modulepart == 'graph_stock') + { + $accessallowed=1; + $original_file=$conf->stock->dir_temp.'/'.$original_file; + } - // Wrapping pour les graph des produits - elseif ($modulepart == 'graph_product') - { - $accessallowed=1; - $original_file=$conf->produit->dir_temp.'/'.$original_file; - } + // Wrapping pour les graph fournisseurs + elseif ($modulepart == 'graph_fourn') + { + $accessallowed=1; + $original_file=$conf->fournisseur->dir_temp.'/'.$original_file; + } - // Wrapping pour les code barre - elseif ($modulepart == 'barcode') - { - $accessallowed=1; + // Wrapping pour les graph des produits + elseif ($modulepart == 'graph_product') + { + $accessallowed=1; + $original_file=$conf->produit->dir_temp.'/'.$original_file; + } + + // Wrapping pour les code barre + elseif ($modulepart == 'barcode') + { + $accessallowed=1; // If viewimage is called for barcode, we try to output an image on the fly, // with not build of file on disk. - //$original_file=$conf->barcode->dir_temp.'/'.$original_file; - $original_file=''; - } + //$original_file=$conf->barcode->dir_temp.'/'.$original_file; + $original_file=''; + } - // Wrapping pour les icones de background des mailings - elseif ($modulepart == 'iconmailing') - { - $accessallowed=1; - $original_file=$conf->mailing->dir_temp.'/'.$original_file; - } + // Wrapping pour les icones de background des mailings + elseif ($modulepart == 'iconmailing') + { + $accessallowed=1; + $original_file=$conf->mailing->dir_temp.'/'.$original_file; + } - // Wrapping generique (allows any module to open a file if file is in directory - // called DOL_DATA_ROOT/modulepart). - else - { - $accessallowed=1; - $original_file=DOL_DATA_ROOT.'/'.$modulepart.'/'.$original_file; - } + // Wrapping generique (allows any module to open a file if file is in directory + // called DOL_DATA_ROOT/modulepart). + else + { + $accessallowed=1; + $original_file=DOL_DATA_ROOT.'/'.$modulepart.'/'.$original_file; + } } // Security: // Limit access if permissions are wrong if (! $accessallowed) { - accessforbidden(); + accessforbidden(); } // Security: @@ -383,11 +394,11 @@ else // Les drois sont ok et fichier trouve if ($type) { - header('Content-type: '.$type); + header('Content-type: '.$type); } else { - header('Content-type: image/png'); + header('Content-type: image/png'); } readfile($original_file);