* Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2006-2007 Rodolphe Quiedeville * Copyright (C) 2007 Auguria SARL * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2011-2012 Juanjo Menent * Copyright (C) 2012 Christophe Battarel * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2016 Charlie Benke * Copyright (C) 2016 Ferran Marcet * * 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/product/admin/product.php * \ingroup produit * \brief Setup page of product module */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php'; // Load translation files required by the page $langs->loadLangs(array("admin","products")); // Security check if (! $user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled))) accessforbidden(); $action = GETPOST('action','alpha'); $value = GETPOST('value','alpha'); $label = GETPOST('label','alpha'); $scandir = GETPOST('scan_dir','alpha'); $type='product'; // Pricing Rules $select_pricing_rules=array( 'PRODUCT_PRICE_UNIQ'=>$langs->trans('PriceCatalogue'), // Unique price 'PRODUIT_MULTIPRICES'=>$langs->trans('MultiPricesAbility'), // Several prices according to a customer level 'PRODUIT_CUSTOMER_PRICES'=>$langs->trans('PriceByCustomer'), // Different price for each customer ); $keyforparam='PRODUIT_CUSTOMER_PRICES_BY_QTY'; if ($conf->global->MAIN_FEATURES_LEVEL >= 1 || ! empty($conf->global->$keyforparam)) $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY'] = $langs->trans('PriceByQuantity').' ('.$langs->trans("VersionExperimental").')'; // TODO If this is enabled, price must be hidden when price by qty is enabled, also price for quantity must be used when adding product into order/propal/invoice $keyforparam='PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'; if ($conf->global->MAIN_FEATURES_LEVEL >= 2 || ! empty($conf->global->$keyforparam)) $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'] = $langs->trans('MultiPricesAbility') . '+' . $langs->trans('PriceByQuantity').' ('.$langs->trans("VersionExperimental").')'; // Clean param if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) { dolibarr_set_const($db, 'PRODUIT_MULTIPRICES_LIMIT', 5, 'chaine', 0, '', $conf->entity); } $error = 0; /* * Actions */ $nomessageinsetmoduleoptions=1; include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; if ($action == 'setcodeproduct') { if (dolibarr_set_const($db, "PRODUCT_CODEPRODUCT_ADDON",$value,'chaine',0,'',$conf->entity) > 0) { header("Location: ".$_SERVER["PHP_SELF"]); exit; } else { dol_print_error($db); } } if ($action == 'other' && GETPOST('value_PRODUIT_LIMIT_SIZE') >= 0) { $res = dolibarr_set_const($db, "PRODUIT_LIMIT_SIZE", GETPOST('value_PRODUIT_LIMIT_SIZE'),'chaine',0,'',$conf->entity); if (! $res > 0) $error++; } if ($action == 'other' && GETPOST('value_PRODUIT_MULTIPRICES_LIMIT') > 0) { $res = dolibarr_set_const($db, "PRODUIT_MULTIPRICES_LIMIT", GETPOST('value_PRODUIT_MULTIPRICES_LIMIT'),'chaine',0,'',$conf->entity); if (! $res > 0) $error++; } if ($action == 'other') { $princingrules = GETPOST('princingrule','alpha'); foreach ($select_pricing_rules as $rule=>$label) // Loop on each possible mode { if ($rule == $princingrules) // We are on selected rule, we enable it { if ($princingrules == 'PRODUCT_PRICE_UNIQ') // For this case, we disable entries manually { $res = dolibarr_set_const($db, 'PRODUIT_MULTIPRICES', 0, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES_BY_QTY', 0, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'PRODUIT_CUSTOMER_PRICES', 0, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, 'PRODUCT_PRICE_UNIQ', 1, 'chaine', 0, '', $conf->entity); } else { $multirule=explode('&',$princingrules); foreach($multirule as $rulesselected) { $res = dolibarr_set_const($db, $rulesselected, 1, 'chaine', 0, '', $conf->entity); } } } else // We clear this mode { if (strpos($rule,'&')===false) { $res = dolibarr_set_const($db, $rule, 0, 'chaine', 0, '', $conf->entity); } } } $value = GETPOST('PRODUIT_SOUSPRODUITS','alpha'); $res = dolibarr_set_const($db, "PRODUIT_SOUSPRODUITS", $value,'chaine',0,'',$conf->entity); $value = GETPOST('activate_viewProdDescInForm','alpha'); $res = dolibarr_set_const($db, "PRODUIT_DESC_IN_FORM", $value,'chaine',0,'',$conf->entity); $value = GETPOST('activate_viewProdTextsInThirdpartyLanguage','alpha'); $res = dolibarr_set_const($db, "PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE", $value,'chaine',0,'',$conf->entity); $value = GETPOST('activate_mergePropalProductCard','alpha'); $res = dolibarr_set_const($db, "PRODUIT_PDF_MERGE_PROPAL", $value,'chaine',0,'',$conf->entity); $value = GETPOST('activate_usesearchtoselectproduct','alpha'); $res = dolibarr_set_const($db, "PRODUIT_USE_SEARCH_TO_SELECT", $value,'chaine',0,'',$conf->entity); $value = GETPOST('activate_useProdFournDesc', 'alpha'); $res = dolibarr_set_const($db, "PRODUIT_FOURN_TEXTS", $value,'chaine',0,'',$conf->entity); if ($value) { $sql_test = "SELECT count(desc_fourn) as cpt FROM ".MAIN_DB_PREFIX."product_fournisseur_price WHERE 1"; $resql = $db->query($sql_test); if (!$resql && $db->lasterrno == 'DB_ERROR_NOSUCHFIELD') // if the field does not exist, we create it { $sql_new = "ALTER TABLE ".MAIN_DB_PREFIX."product_fournisseur_price ADD COLUMN desc_fourn text"; $resql_new = $db->query($sql_new); } } } if ($action == 'specimen') // For products { $modele= GETPOST('module','alpha'); $product = new Product($db); $product->initAsSpecimen(); // Search template files $file=''; $classname=''; $filefound=0; $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); foreach($dirmodels as $reldir) { $file=dol_buildpath($reldir."core/modules/product/doc/pdf_".$modele.".modules.php",0); if (file_exists($file)) { $filefound=1; $classname = "pdf_".$modele; break; } } if ($filefound) { require_once $file; $module = new $classname($db); if ($module->write_file($product, $langs, '') > 0) { header("Location: ".DOL_URL_ROOT."/document.php?modulepart=product&file=SPECIMEN.pdf"); return; } else { setEventMessages($obj->error, $obj->errors, 'errors'); dol_syslog($obj->error, LOG_ERR); } } else { setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } } // Activate a model if ($action == 'set') { $ret = addDocumentModel($value, $type, $label, $scandir); } if ($action == 'del') { $ret = delDocumentModel($value, $type); if ($ret > 0) { if ($conf->global->PRODUCT_ADDON_PDF == "$value") dolibarr_del_const($db, 'PRODUCT_ADDON_PDF',$conf->entity); } } // Set default model if ($action == 'setdoc') { if (dolibarr_set_const($db, "PRODUCT_ADDON_PDF",$value,'chaine',0,'',$conf->entity)) { // La constante qui a ete lue en avant du nouveau set // on passe donc par une variable pour avoir un affichage coherent $conf->global->PRODUCT_ADDON_PDF = $value; } // On active le modele $ret = delDocumentModel($value, $type); if ($ret > 0) { $ret = addDocumentModel($value, $type, $label, $scandir); } } if ($action == 'set') { $const = "PRODUCT_SPECIAL_".strtoupper(GETPOST('spe','alpha')); $value = GETPOST('value'); if (GETPOST('value','alpha')) $res = dolibarr_set_const($db, $const, $value,'chaine',0,'',$conf->entity); else $res = dolibarr_del_const($db, $const,$conf->entity); if (! $res > 0) $error++; } if ($action == 'other') { $value = GETPOST('activate_units', 'alpha'); $res = dolibarr_set_const($db, "PRODUCT_USE_UNITS", $value, 'chaine', 0, '', $conf->entity); if (! $res > 0) $error++; } if ($action) { if (! $error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { setEventMessages($langs->trans("SetupNotError"), null, 'errors'); } } /* * View */ $formbarcode=new FormBarCode($db); $title = $langs->trans('ProductServiceSetup'); $tab = $langs->trans("ProductsAndServices"); if (empty($conf->produit->enabled)) { $title = $langs->trans('ServiceSetup'); $tab = $langs->trans('Services'); } else if (empty($conf->service->enabled)) { $title = $langs->trans('ProductSetup'); $tab = $langs->trans('Products'); } llxHeader('',$title); $linkback=''.$langs->trans("BackToModuleList").''; print load_fiche_titre($title,$linkback,'title_setup'); $head = product_admin_prepare_head(); dol_fiche_head($head, 'general', $tab, -1, 'product'); $form=new Form($db); // Module to manage product / services code $dirproduct=array('/core/modules/product/'); $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); print load_fiche_titre($langs->trans("ProductCodeChecker"), '', ''); print ''."\n"; print ''."\n"; print ' '; print ' '; print ' '; print ' '; print ' '; print "\n"; $var = true; foreach ($dirproduct as $dirroot) { $dir = dol_buildpath($dirroot,0); $handle = @opendir($dir); if (is_resource($handle)) { // Loop on each module find in opened directory while (($file = readdir($handle))!==false) { if (substr($file, 0, 16) == 'mod_codeproduct_' && substr($file, -3) == 'php') { $file = substr($file, 0, dol_strlen($file)-4); try { dol_include_once($dirroot.$file.'.php'); } catch(Exception $e) { dol_syslog($e->getMessage(), LOG_ERR); } $modCodeProduct = new $file; // Show modules according to features level if ($modCodeProduct->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($modCodeProduct->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; $var = !$var; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; if (! empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) && $conf->global->PRODUCT_CODEPRODUCT_ADDON == $file) { print '\n"; } else { $disabled = false; if (! empty($conf->multicompany->enabled) && (is_object($mc) && ! empty($mc->sharings['referent']) && $mc->sharings['referent'] == $conf->entity) ? false : true); print ''; } print ''; print ''; } } closedir($handle); } } print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Example").''.$langs->trans("Status").''.$langs->trans("ShortInfo").'
'.$modCodeProduct->name.''.$modCodeProduct->info($langs).''.$modCodeProduct->getExample($langs).''."\n"; print img_picto($langs->trans("Activated"),'switch_on'); print "'; if (! $disabled) print ''; print img_picto($langs->trans("Disabled"),'switch_off'); if (! $disabled) print ''; print ''; $s=$modCodeProduct->getToolTip($langs,null,-1); print $form->textwithpicto('',$s,1); print '
'; // Module to build doc $def = array(); $sql = "SELECT nom"; $sql.= " FROM ".MAIN_DB_PREFIX."document_model"; $sql.= " WHERE type = '".$type."'"; $sql.= " AND entity = ".$conf->entity; $resql=$db->query($sql); if ($resql) { $i = 0; $num_rows=$db->num_rows($resql); while ($i < $num_rows) { $array = $db->fetch_array($resql); array_push($def, $array[0]); $i++; } } else { dol_print_error($db); } print '
'; print load_fiche_titre($langs->trans("ProductDocumentTemplates"), '', ''); print ''; print ''; print ''; print ''; print '\n"; print '\n"; print ''; print ''; print "\n"; clearstatcache(); foreach ($dirmodels as $reldir) { foreach (array('','/doc') as $valdir) { $dir = dol_buildpath($reldir."core/modules/product".$valdir); if (is_dir($dir)) { $handle=opendir($dir); if (is_resource($handle)) { while (($file = readdir($handle))!==false) { $filelist[]=$file; } closedir($handle); arsort($filelist); foreach($filelist as $file) { if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file)) { if (file_exists($dir.'/'.$file)) { $name = substr($file, 4, dol_strlen($file) -16); $classname = substr($file, 0, dol_strlen($file) -12); require_once $dir.'/'.$file; $module = new $classname($db); $modulequalified=1; if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0; if ($modulequalified) { print ''; // Active if (in_array($name, $def)) { print ''; } else { print '"; } // Defaut print ''; // Info $htmltooltip = ''.$langs->trans("Name").': '.$module->name; $htmltooltip.='
'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); if ($module->type == 'pdf') { $htmltooltip.='
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; } $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); print ''; // Preview print ''; print "\n"; } } } } } } } } print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Status")."'.$langs->trans("Default")."'.$langs->trans("ShortInfo").''.$langs->trans("Preview").'
'; print (empty($module->name)?$name:$module->name); print "\n"; if (method_exists($module,'info')) print $module->info($langs); else print $module->description; print ''."\n"; print ''; print img_picto($langs->trans("Enabled"),'switch_on'); print ''; print ''."\n"; print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; print "'; if ($conf->global->PRODUCT_ADDON_PDF == $name) { print img_picto($langs->trans("Default"),'on'); } else { print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').''; } print ''; print $form->textwithpicto('',$htmltooltip,1,0); print ''; if ($module->type == 'pdf') { print ''.img_object($langs->trans("Preview"),'contract').''; } else { print img_object($langs->trans("PreviewNotAvailable"),'generic'); } print '
'; print "
"; /* * Other conf */ print "
"; print load_fiche_titre($langs->trans("ProductOtherConf"), '', ''); print '
'; print ''; print ''; print ''; print ''; print ''."\n"; print ''."\n"; print ''."\n"; /* * Other parameters */ $rowspan = 4; if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $rowspan++; if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) $rowspan++; if (! empty($conf->global->MAIN_MULTILANGS)) $rowspan++; if (! empty($conf->fournisseur->enabled)) $rowspan++; print ''; print ''; print ''; print ''; // multiprix nombre de prix a proposer if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { print ''; print ''; print ''; print ''; } // sousproduits activation/desactivation print ''; print ''; print ''; print ''; // Utilisation formulaire Ajax sur choix produit print ''; print ''; if (empty($conf->use_javascript_ajax)) { print ''; } else { print ''; } print ''; if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { print ''; print ''; print ''; print ''; } // Visualiser description produit dans les formulaires activation/desactivation print ''; print ''; print ''; print ''; // Activate propal merge produt card /* Kept as hidden feature only. PRODUIT_PDF_MERGE_PROPAL can be added manually. Still did not understand how this feature works. print ''; print ''; print ''; print ''; */ // Use units /* Kept as hidden feature only. PRODUCT_USE_UNITS is hidden for the moment. Because it seems to be a duplicated feature with already existing field to store unit of product print ''; print ''; print ''; print ''; */ // View product description in thirdparty language if (! empty($conf->global->MAIN_MULTILANGS)) { print ''; print ''; print ''; print ''; } if (! empty($conf->fournisseur->enabled)) { print ''; print ''; print ''; print ''; } if (! empty($conf->global->PRODUCT_CANVAS_ABILITY)) { // Add canvas feature $dir = DOL_DOCUMENT_ROOT . "/product/canvas/"; print ''; print ''."\n"; print ''."\n"; print ''."\n"; if (is_dir($dir)) { require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; $handle=opendir($dir); if (is_resource($handle)) { while (($file = readdir($handle))!==false) { if (file_exists($dir.$file.'/product.'.$file.'.class.php')) { $classfile = $dir.$file.'/product.'.$file.'.class.php'; $classname = 'Product'.ucfirst($file); require_once $classfile; $object = new $classname(); $module = $object->module; if ($conf->$module->enabled) { print ''; } } } closedir($handle); } } else { setEventMessages($dir.' '.$langs->trans("IsNotADir"), null, 'errors'); } } print '
'.$langs->trans("Parameters").''.$langs->trans("Value").' 
'.$langs->trans("PricingRule").''; $current_rule = 'PRODUCT_PRICE_UNIQ'; if (!empty($conf->global->PRODUIT_MULTIPRICES)) $current_rule='PRODUIT_MULTIPRICES'; if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) $current_rule='PRODUIT_CUSTOMER_PRICES_BY_QTY'; if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $current_rule='PRODUIT_CUSTOMER_PRICES'; if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $current_rule='PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'; print $form->selectarray("princingrule",$select_pricing_rules,$current_rule); if ( empty($conf->multicompany->enabled)) { print $langs->trans("SamePriceAlsoForSharedCompanies"); } print ''; print ''; print '
'.$langs->trans("MultiPricesNumPrices").'
'.$langs->trans("AssociatedProductsAbility").''; print $form->selectyesno("PRODUIT_SOUSPRODUITS",$conf->global->PRODUIT_SOUSPRODUITS,1); print '
'.$form->textwithpicto($langs->trans("UseSearchToSelectProduct"),$langs->trans('UseSearchToSelectProductTooltip'),1).''; print $langs->trans("NotAvailableWhenAjaxDisabled"); print ''; $arrval=array( '0'=>$langs->trans("No"), '1'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch",1).')', '2'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch",2).')', '3'=>$langs->trans("Yes").' ('.$langs->trans("NumberOfKeyToSearch",3).')', ); print $form->selectarray("activate_usesearchtoselectproduct",$arrval,$conf->global->PRODUIT_USE_SEARCH_TO_SELECT); print '
'.$langs->trans("NumberOfProductShowInSelect").'
'.$langs->trans("ViewProductDescInFormAbility").''; print $form->selectyesno("activate_viewProdDescInForm",$conf->global->PRODUIT_DESC_IN_FORM,1); print '
'.$langs->trans("MergePropalProductCard").''; print $form->selectyesno("activate_mergePropalProductCard",$conf->global->PRODUIT_PDF_MERGE_PROPAL,1); print '
'.$langs->trans("UseUnits").''; print $form->selectyesno("activate_units",$conf->global->PRODUCT_USE_UNITS,1); print '
'.$langs->trans("ViewProductDescInThirdpartyLanguageAbility").''; print $form->selectyesno("activate_viewProdTextsInThirdpartyLanguage", (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)?$conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE:0), 1); print '
'.$langs->trans("UseProductFournDesc").''; print $form->selectyesno("activate_useProdFournDesc", (! empty($conf->global->PRODUIT_FOURN_TEXTS)?$conf->global->PRODUIT_FOURN_TEXTS:0), 1); print '
'.$langs->trans("ProductSpecial").''.$langs->trans("Value").' 
'; print $object->description; print ''; $const = "PRODUCT_SPECIAL_".strtoupper($file); if ($conf->global->$const) { print img_picto($langs->trans("Active"),'tick'); print ''; print ''.$langs->trans("Disable").''; } else { print ' '; print ''.$langs->trans("Activate").''; } print '
'; print '
'; // End of page llxFooter(); $db->close();