* Copyright (C) 2005 Brice Davoleau * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006-2015 Laurent Destailleur * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2010 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2015 Marcos García * * 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'); $removecat = GETPOST('removecat','int'); $parent=GETPOST('parent','int'); $dbtablename = ''; // For categories on third parties if (! empty($socid)) $id = $socid; if (! isset($type)) $type = Categorie::TYPE_PRODUCT; if ($type == Categorie::TYPE_SUPPLIER || $type == Categorie::TYPE_CUSTOMER) $socid = $id; if ($id || $ref) { if ($type == Categorie::TYPE_PRODUCT) { $elementtype = 'product'; $objecttype = 'produit|service&categorie'; $objectid = isset($id)?$id:(isset($ref)?$ref:''); $dbtablename = 'product'; $fieldid = isset($ref)?'ref':'rowid'; } elseif ($type == Categorie::TYPE_SUPPLIER) { $elementtype = 'fournisseur'; $objecttype = 'societe&categorie'; $objectid = isset($id)?$id:(isset($socid)?$socid:''); $dbtablename = '&societe'; $fieldid = 'rowid'; } elseif ($type == Categorie::TYPE_CUSTOMER) { $elementtype = 'societe'; $objecttype = 'societe&categorie'; $objectid = isset($id)?$id:(isset($socid)?$socid:''); $dbtablename = '&societe'; $fieldid = 'rowid'; } elseif ($type == Categorie::TYPE_MEMBER) { $elementtype = 'member'; $objecttype = 'adherent&categorie'; $objectid = isset($id)?$id:(isset($ref)?$ref:''); $dbtablename = 'adherent'; $fieldid = ! empty($ref)?'ref':'rowid'; } elseif ($type == Categorie::TYPE_CONTACT) { $elementtype = 'societe'; $objecttype = 'contact'; $objectid = isset($id)?$id:(isset($ref)?$ref:''); $dbtablename = 'socpeople&societe'; $fieldid = ! empty($ref)?'ref':'rowid'; } } // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user,$objecttype,$objectid,$dbtablename,'','',$fieldid); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('categorycard','globalcard')); /* * Actions */ $parameters=array('id'=>$socid); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) { // Remove element from category if ($removecat > 0) { if ($type == Categorie::TYPE_PRODUCT && ($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 == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer) { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; $object = new Fournisseur($db); $result = $object->fetch($objectid); $elementtype = 'fournisseur'; } if ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); $elementtype = 'societe'; } if ($type == Categorie::TYPE_MEMBER && $user->rights->adherent->creer) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $object = new Adherent($db); $result = $object->fetch($objectid); $elementtype = 'member'; } if ($type == Categorie::TYPE_CONTACT && $user->rights->societe->creer) { require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $object = new Contact($db); $result = $object->fetch($objectid); $elementtype = 'contact'; } $cat = new Categorie($db); $result=$cat->fetch($removecat); $result=$cat->del_type($object,$elementtype); if ($result < 0) { setEventMessages($cat->error, $cat->errors, 'errors'); } } // Add object into a category if ($parent > 0) { if ($type == Categorie::TYPE_PRODUCT && ($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 == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer) { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; $object = new Fournisseur($db); $result = $object->fetch($objectid); $elementtype = 'fournisseur'; } if ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer) { $object = new Societe($db); $result = $object->fetch($objectid); $elementtype = 'societe'; } if ($type == Categorie::TYPE_MEMBER && $user->rights->adherent->creer) { require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $object = new Adherent($db); $result = $object->fetch($objectid); $elementtype = 'member'; } if ($type == Categorie::TYPE_CONTACT && $user->rights->societe->creer) { require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; $object = new Contact($db); $result = $object->fetch($objectid); $elementtype = 'contact'; } $cat = new Categorie($db); $result=$cat->fetch($parent); $result=$cat->add_type($object,$elementtype); if ($result >= 0) { setEventMessages($langs->trans("WasAddedSuccessfully",$cat->label), null, 'mesgs'); } else { if ($cat->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { setEventMessages($langs->trans("ObjectAlreadyLinkedToCategory"), null, 'warnings'); } else { setEventMessages($cat->error, $cat->errors, 'errors'); } } } } /* * 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); $title=$langs->trans("Category"); if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$soc->name." - ".$title; llxHeader("",$title); // Show tabs $head = societe_prepare_head($soc); dol_fiche_head($head, 'category', $langs->trans("ThirdParty"),0,'company'); print ''; print ''; // Alias names (commercial, trademark or alias names) 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->country) { print ''; } // EMail print ''; // Web print ''; // Phone print ''; print ''; print '
'.$langs->trans("ThirdPartyName").''; print $form->showrefnav($soc,'socid','',($user->societe_id?0:1),'rowid','nom','','&type='.$type); print '
'.$langs->trans('AliasNames').''; print $soc->name_alias; 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').''; dol_print_address($soc->address,'gmap','thirdparty',$soc->id); print '
'.$langs->trans('Zip').''.$soc->zip."'.$langs->trans('Town').''.$soc->town."
'.$langs->trans('Country').''; //$img=picto_from_langcode($soc->country_code); $img=''; print ($img?$img.' ':''); print $soc->country; print '
'.$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('Phone').''.dol_print_phone($soc->phone,$soc->country_code,0,$soc->id,'AC_TEL').''.$langs->trans('Fax').''.dol_print_phone($soc->fax,$soc->country_code,0,$soc->id,'AC_FAX').'
'; dol_fiche_end(); if ($soc->client) formCategory($db,$soc,2,$socid,$user->rights->societe->creer); if ($soc->client && $soc->fournisseur) print '

'; if ($soc->fournisseur) formCategory($db,$soc,1,$socid,$user->rights->societe->creer); } else if ($id || $ref) { if ($type == Categorie::TYPE_PRODUCT) { $langs->load("products"); /* * Category card for product */ require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; // Product $product = new Product($db); $result = $product->fetch($id, $ref); llxHeader("","",$langs->trans("CardProduct".$product->type)); $head=product_prepare_head($product); $titre=$langs->trans("CardProduct".$product->type); $picto=($product->type== Product::TYPE_SERVICE?'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->label.'
'.$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(); formCategory($db,$product,0,$socid,($user->rights->produit->creer || $user->rights->service->creer)); } if ($type == Categorie::TYPE_MEMBER) { $langs->load("members"); /* * Category card for member */ 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); $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 ''; // Lastname print ''; print ''; // Firstname print ''; print ''; // Status print ''; print '
'.$langs->trans("Ref").''; print $form->showrefnav($member,'id','','1','rowid','ref','','&type='.$type); 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->lastname.' 
'.$langs->trans("Firstname").''.$member->firstname.' 
'.$langs->trans("Status").''.$member->getLibStatut(4).'
'; dol_fiche_end(); formCategory($db,$member,3,0,$user->rights->adherent->creer); } if ($type == Categorie::TYPE_CONTACT) { $langs->load("contact"); /* * Category card for contact */ require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; // Produit $object = new Contact($db); $result = $object->fetch($id, $ref); $object->fetch_thirdparty(); llxHeader("","",$langs->trans("Contact")); $head=contact_prepare_head($object); $titre=$langs->trans("ContactsAddresses"); $picto='contact'; dol_fiche_head($head, 'category', $titre,0,$picto); $rowspan=5; if (! empty($conf->societe->enabled)) $rowspan++; print ''; // Ref print ''; print ''; // Name print ''; print ''; // Company if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { print ''; } // Civility print ''; // Role print ''; // Address print ''; // Zip/Town print ''; // Country print ''; // State if (empty($conf->global->SOCIETE_DISABLE_STATE)) { print ''; } // Phone print ''; print ''; print ''; print ''; // Email print ''; if (! empty($conf->mailing->enabled)) { $langs->load("mails"); print ''; print ''; } else { print ''; } print ''; // Instant message and no email print ''; if (!empty($conf->mailing->enabled)) { print ''; } else { print ''; } print ''; print ''; // Note Public print ''; // Note Private print ''; // Other attributes $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields); } print '
'.$langs->trans("Ref").''; print $form->showrefnav($object,'rowid'); print '
'.$langs->trans("Lastname").' / '.$langs->trans("Label").''.$object->lastname.''.$langs->trans("Firstname").''.$object->firstname.'
'.$langs->trans("Company").''; if (!empty($object->thirdparty->id)) { print $object->thirdparty->getNomUrl(1); } else { print $langs->trans("ContactNotLinkedToCompany"); } print '
'.$langs->trans("UserTitle").''; print $object->getCivilityLabel(); print '
'.$langs->trans("PostOrFunction").''.$object->poste.'
'.$langs->trans("Address").''; dol_print_address($object->address,'gmap','contact',$object->id); print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''; print $object->zip; if ($object->zip) print ' '; print $object->town.'
'.$langs->trans("Country").''; $img=picto_from_langcode($object->country_code); if ($img) print $img.' '; print $object->country; print '
'.$langs->trans('State').''.$object->state.'
'.$langs->trans("PhonePro").''.dol_print_phone($object->phone_pro,$object->country_code,$object->id,$object->socid,'AC_TEL').''.$langs->trans("PhonePerso").''.dol_print_phone($object->phone_perso,$object->country_code,$object->id,$object->socid,'AC_TEL').'
'.$langs->trans("PhoneMobile").''.dol_print_phone($object->phone_mobile,$object->country_code,$object->id,$object->socid,'AC_TEL').''.$langs->trans("Fax").''.dol_print_phone($object->fax,$object->country_code,$object->id,$object->socid,'AC_FAX').'
'.$langs->trans("EMail").''.dol_print_email($object->email,$object->id,$object->socid,'AC_EMAIL').''.$langs->trans("NbOfEMailingsReceived").''.$object->getNbOfEMailings().' 
'.$langs->trans("IM").''.$object->jabberid.''.$langs->trans("No_Email").''.yn($object->no_email).' 
'.$langs->trans("ContactVisibility").''; print $object->LibPubPriv($object->priv); print '
'.$langs->trans("NotePublic").''; print nl2br($object->note_public); print '
'.$langs->trans("NotePrivate").''; print nl2br($object->note_private); print '
'; dol_fiche_end(); formCategory($db,$object,4,$socid, $user->rights->societe->creer); } } /** * Function to output a form to add object into 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 * @param int $showclassifyform 1=Add form to 'Classify', 0=Do not show form to 'Classify' * @return int 0 */ function formCategory($db,$object,$typeid,$socid=0,$showclassifyform=1) { global $user,$langs,$form,$bc; $title='NotDefined'; if ($typeid == Categorie::TYPE_PRODUCT) $title = $langs->trans("ProductsCategoriesShort"); if ($typeid == Categorie::TYPE_SUPPLIER) $title = $langs->trans("SuppliersCategoriesShort"); if ($typeid == Categorie::TYPE_CUSTOMER) $title = $langs->trans("CustomersProspectsCategoriesShort"); if ($typeid == Categorie::TYPE_MEMBER) $title = $langs->trans("MembersCategoriesShort"); if ($typeid == Categorie::TYPE_CONTACT) $title = $langs->trans("ContactCategoriesShort"); $linktocreate=''; if ($showclassifyform && $user->rights->categorie->creer) { $linktocreate='id.'&type='.$typeid).'">'; $linktocreate.=$langs->trans("CreateCat").' '; $linktocreate.=img_picto($langs->trans("Create"),'filenew'); $linktocreate.=""; } print '
'; print load_fiche_titre($title,$linktocreate,''); // Form to add record into a category if ($showclassifyform) { print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'; print ''.$langs->trans("ClassifyInCategory").'  '; print $form->select_all_categories($typeid,'auto'); print '
'; print '
'; print '
'; } $c = new Categorie($db); $cats = $c->containing($object->id,$typeid); if (count($cats) > 0) { if ($typeid == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductIsInCategories"); if ($typeid == Categorie::TYPE_SUPPLIER) $title=$langs->trans("CompanyIsInSuppliersCategories"); if ($typeid == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CompanyIsInCustomersCategories"); if ($typeid == Categorie::TYPE_MEMBER) $title=$langs->trans("MemberIsInCategories"); if ($typeid == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactIsInCategories"); print "\n"; print ''; print ''; $var = true; foreach ($cats as $cat) { $ways = $cat->print_all_ways(); foreach ($ways as $way) { $var = ! $var; print ""; // Categorie print ""; // Link to delete from category print '"; print "\n"; } } print "
'.$title.':
".img_object('','category').' '.$way."'; $permission=0; if ($typeid == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer); if ($typeid == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer; if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer; if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer; if ($typeid == Categorie::TYPE_CONTACT) $permission=$user->rights->societe->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 == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductHasNoCategory"); if ($typeid == Categorie::TYPE_SUPPLIER) $title=$langs->trans("CompanyHasNoCategory"); if ($typeid == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CompanyHasNoCategory"); if ($typeid == Categorie::TYPE_MEMBER) $title=$langs->trans("MemberHasNoCategory"); if ($typeid == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactHasNoCategory"); print $title; print "
"; } return 0; } llxFooter(); $db->close();