* Copyright (C) 2005 Brice Davoleau * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006-2011 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2010 Juanjo Menent * * 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 3 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, see . */ /** * \file htdocs/categories/categorie.php * \ingroup category * \brief Page to show category tab */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $langs->load("categories"); $langs->load("products"); $socid = GETPOST('socid','int'); $id = GETPOST('id','int'); $ref = GETPOST('ref'); $type = GETPOST('type'); $mesg = GETPOST('mesg'); $removecat = GETPOST('removecat','int'); $parent=GETPOST('parent','int'); $dbtablename = ''; // For categories on third parties if (! empty($socid)) $id = $socid; if (! isset($type)) $type = 0; if ($type == 1 || $type == 2) $socid = $id; if ($id || $ref) { if ($type == 0) { $elementtype = 'product'; $objecttype = 'produit|service&categorie'; $objectid = isset($id)?$id:(isset($ref)?$ref:''); $dbtablename = 'product'; $fieldid = isset($ref)?'ref':'rowid'; } elseif ($type == 1) { $elementtype = 'fournisseur'; $objecttype = 'societe&categorie'; $objectid = isset($id)?$id:(isset($socid)?$socid:''); $dbtablename = '&societe'; $fieldid = 'rowid'; } elseif ($type == 2) { $elementtype = 'societe'; $objecttype = 'societe&categorie'; $objectid = isset($id)?$id:(isset($socid)?$socid:''); $dbtablename = '&societe'; $fieldid = 'rowid'; } elseif ($type == 3) { $elementtype = 'member'; $objecttype = 'adherent&categorie'; $objectid = isset($id)?$id:(isset($ref)?$ref:''); $dbtablename = 'adherent'; $fieldid = ! empty($ref)?'ref':'rowid'; } } // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user,$objecttype,$objectid,$dbtablename,'','',$fieldid); /* * Actions */ //Suppression d'un objet d'une categorie if ($removecat > 0) { if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer)) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $object = new Product($db); $result = $object->fetch($id, $ref); $elementtype = 'product'; } if ($type==1 && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); } if ($type==2 && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); } if ($type == 3 && $user->rights->adherent->creer) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $object = new Adherent($db); $result = $object->fetch($objectid); } $cat = new Categorie($db); $result=$cat->fetch($removecat); $result=$cat->del_type($object,$elementtype); } // Add object into a category if ($parent > 0) { if ($type==0 && ($user->rights->produit->creer || $user->rights->service->creer)) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $object = new Product($db); $result = $object->fetch($id, $ref); $elementtype = 'product'; } if ($type==1 && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); $elementtype = 'fournisseur'; } if ($type==2 && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); $elementtype = 'societe'; } if ($type==3 && $user->rights->adherent->creer) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $object = new Adherent($db); $result = $object->fetch($objectid); $elementtype = 'member'; } $cat = new Categorie($db); $result=$cat->fetch($parent); $result=$cat->add_type($object,$elementtype); if ($result >= 0) { $mesg='
'.$langs->trans("WasAddedSuccessfully",$cat->label).'
'; } else { if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') $mesg='
'.$langs->trans("ObjectAlreadyLinkedToCategory").'
'; else $mesg=$langs->trans("Error").' '.$cat->error; } } /* * View */ $form = new Form($db); /* * Fiche categorie de client et/ou fournisseur */ if ($socid) { require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $langs->load("companies"); if (! empty($conf->notification->enabled)) $langs->load("mails"); $soc = new Societe($db); $result = $soc->fetch($socid); llxHeader("","",$langs->trans("Category")); // Show tabs $head = societe_prepare_head($soc); dol_fiche_head($head, 'category', $langs->trans("ThirdParty"),0,'company'); print ''; print ''; if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field { print ''; } if ($soc->client) { print ''; } if ($soc->fournisseur) { print ''; } if (! empty($conf->barcode->enabled)) { print ''; } // Address print ''; // Zip / Town print '"; print '"; // Country if ($soc->pays) { print ''; } // Phone print ''; print ''; // EMail print ''; // Web print ''; // Assujeti a TVA ou pas print ''; print ''; print ''; print '
'.$langs->trans("ThirdPartyName").''; print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom','','&type='.$type); print '
'.$langs->trans('Prefix').''.$soc->prefix_comm.'
'; print $langs->trans('CustomerCode').''; print $soc->code_client; if ($soc->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; print '
'; print $langs->trans('SupplierCode').''; print $soc->code_fournisseur; if ($soc->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; print '
'.$langs->trans('Gencod').''.$soc->barcode.'
'.$langs->trans('Address').''.nl2br($soc->address).'
'.$langs->trans('Zip').''.$soc->cp."'.$langs->trans('Town').''.$soc->ville."
'.$langs->trans('Country').''; $img=picto_from_langcode($soc->country_code); print ($img?$img.' ':''); print $soc->pays; print '
'.$langs->trans('Phone').''.dol_print_phone($soc->tel,$soc->country_code,0,$soc->id,'AC_TEL').''.$langs->trans('Fax').''.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'
'.$langs->trans('EMail').''; print dol_print_email($soc->email,0,$soc->id,'AC_EMAIL'); print ''.$langs->trans('Web').''; print dol_print_url($soc->url); print '
'.$langs->trans('VATIsUsed').''; print yn($soc->tva_assuj); print '
'; dol_fiche_end(); dol_htmloutput_mesg($mesg); if ($soc->client) formCategory($db,$soc,2,$socid); if ($soc->client && $soc->fournisseur) print '

'; if ($soc->fournisseur) formCategory($db,$soc,1,$socid); } else if ($id || $ref) { if ($type == 0) { $langs->load("products"); /* * Fiche categorie de produit */ require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; // Produit $product = new Product($db); $result = $product->fetch($id, $ref); llxHeader("","",$langs->trans("CardProduct".$product->type)); $head=product_prepare_head($product, $user); $titre=$langs->trans("CardProduct".$product->type); $picto=($product->type==1?'service':'product'); dol_fiche_head($head, 'category', $titre,0,$picto); print ''; // Ref print ""; print ''; print ''; // Label print ''; print ''; // Status (to sell) print ''; // Status (to buy) print ''; print '
'.$langs->trans("Ref").''; print $form->showrefnav($product,'ref','',1,'ref'); print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("Status").' ('.$langs->trans("Sell").')'; print $product->getLibStatut(2,0); print '
'.$langs->trans("Status").' ('.$langs->trans("Buy").')'; print $product->getLibStatut(2,1); print '
'; dol_fiche_end(); dol_htmloutput_mesg($mesg); formCategory($db,$product,0); } if ($type == 3) { $langs->load("members"); /* * Fiche categorie d'adherent */ require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; // Produit $member = new Adherent($db); $result = $member->fetch($id, $ref); $membert = new AdherentType($db); $membert->fetch($member->typeid); llxHeader("","",$langs->trans("Member")); $head=member_prepare_head($member, $user); $titre=$langs->trans("Member"); $picto='user'; dol_fiche_head($head, 'category', $titre,0,$picto); $rowspan=5; if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan+=1; if (! empty($conf->societe->enabled)) $rowspan++; print ''; // Ref print ''; print ''; // Login if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) { print ''; } // Morphy print ''; /*print '';*/ print ''; // Type print '\n"; // Company print ''; // Civility print ''; print ''; // Nom print ''; print ''; // Prenom print ''; print ''; // Status print ''; print '
'.$langs->trans("Ref").''; print $form->showrefnav($member,'rowid'); print '
'.$langs->trans("Login").' / '.$langs->trans("Id").''.$member->login.' 
'.$langs->trans("Nature").''.$member->getmorphylib().''; print $form->showphoto('memberphoto',$member); print '
'.$langs->trans("Type").''.$membert->getNomUrl(1)."
'.$langs->trans("Company").''.$member->societe.'
'.$langs->trans("UserTitle").''.$member->getCivilityLabel().' 
'.$langs->trans("Lastname").''.$member->nom.' 
'.$langs->trans("Firstname").''.$member->prenom.' 
'.$langs->trans("Status").''.$member->getLibStatut(4).'
'; dol_fiche_end(); dol_htmloutput_mesg($mesg); formCategory($db,$member,3); } } /** * Function to output a HTML select for a category * * @param DoliDb $db Database handler * @param Object $object Object we want to see categories it can be classified into * @param int $typeid Type of category (0, 1, 2, 3) * @param int $socid Id thirdparty * @return int 0 */ function formCategory($db,$object,$typeid,$socid=0) { global $user,$langs,$form,$bc; if ($typeid == 0) $title = $langs->trans("ProductsCategoriesShort"); if ($typeid == 1) $title = $langs->trans("SuppliersCategoriesShort"); if ($typeid == 2) $title = $langs->trans("CustomersProspectsCategoriesShort"); if ($typeid == 3) $title = $langs->trans("MembersCategoriesShort"); // Formulaire ajout dans une categorie print '
'; print_fiche_titre($title,'',''); print '
'; print ''; print ''; print ''; print ''; print ''; print ''; if ($user->rights->categorie->creer) { print ''; } print ''; print '
'; print $langs->trans("ClassifyInCategory").'  '; print $form->select_all_categories($typeid); print ''; print ''; print 'id.'&type='.$typeid).'">'; print $langs->trans("CreateCat").' '; print img_picto($langs->trans("Create"),'filenew'); print ""; print '
'; print '
'; print '
'; $c = new Categorie($db); $cats = $c->containing($object->id,$typeid); if (count($cats) > 0) { if ($typeid == 0) $title=$langs->trans("ProductIsInCategories"); if ($typeid == 1) $title=$langs->trans("CompanyIsInSuppliersCategories"); if ($typeid == 2) $title=$langs->trans("CompanyIsInCustomersCategories"); if ($typeid == 3) $title=$langs->trans("MemberIsInCategories"); print "\n"; print ''; print ''; $var = true; foreach ($cats as $cat) { $ways = $cat->print_all_ways(); foreach ($ways as $way) { $var = ! $var; print ""; // Categorie print ""; // Lien supprimer print '"; print "\n"; } } print "
'.$title.':
"; //$c->id=; //print $c->getNomUrl(1); print img_object('','category').' '.$way."'; $permission=0; if ($typeid == 0) $permission=($user->rights->produit->creer || $user->rights->service->creer); if ($typeid == 1) $permission=$user->rights->societe->creer; if ($typeid == 2) $permission=$user->rights->societe->creer; if ($typeid == 3) $permission=$user->rights->adherent->creer; if ($permission) { print ""; print img_delete($langs->trans("DeleteFromCat")).' '; print $langs->trans("DeleteFromCat").""; } else { print ' '; } print "
\n"; } else if ($cats < 0) { print $langs->trans("ErrorUnknown"); } else { if ($typeid == 0) $title=$langs->trans("ProductHasNoCategory"); if ($typeid == 1) $title=$langs->trans("CompanyHasNoCategory"); if ($typeid == 2) $title=$langs->trans("CompanyHasNoCategory"); if ($typeid == 3) $title=$langs->trans("MemberHasNoCategory"); print $title; print "
"; } return 0; } llxFooter(); $db->close(); ?>