From db0c8740b9321742a092727c1c6c6ca1d644183e Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 4 Feb 2016 16:17:45 +0100 Subject: [PATCH] add administration feature of products docs --- htdocs/product/admin/product.php | 226 ++++++++++++++++++++++++++++++- 1 file changed, 224 insertions(+), 2 deletions(-) diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 57f6577f789..15b113ffffb 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -7,6 +7,7 @@ * Copyright (C) 2011-2012 Juanjo Menent * Copyright (C) 2012 Christophe Battarel * Copyright (C) 2012 Cedric Salvador + * Copyright (C) 2016 Charlie Benke * * 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 @@ -42,6 +43,9 @@ if (! $user->admin || (empty($conf->product->enabled) && empty($conf->service->e $action = GETPOST('action','alpha'); $value = GETPOST('value','alpha'); +$type = GETPOST('type','alpha'); +$label = GETPOST('label','alpha'); +$scandir = GETPOST('scandir','alpha'); // Pricing Rules $select_pricing_rules=array( @@ -98,12 +102,13 @@ if ($action == 'setModuleOptions') if (! $error) { $db->commit(); - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + //setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { $db->rollback(); - setEventMessages($langs->trans("Error"), null, 'errors'); + // message yet present at the bottom if($action) + //setEventMessages($langs->trans("Error"), null, 'errors'); } } @@ -171,6 +176,86 @@ if ($action == 'other') $value = GETPOST('activate_usesearchtoselectproduct','alpha'); $res = dolibarr_set_const($db, "PRODUIT_USE_SEARCH_TO_SELECT", $value,'chaine',0,'',$conf->entity); } + +if ($action == 'specimen') // For products +{ + $modele= GETPOST('module','alpha'); + + $inter = new Fichinter($db); + $inter->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($inter,$langs) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=products&file=SPECIMEN.pdf"); + return; + } + else + { + setEventMessage($obj->error,'errors'); + dol_syslog($obj->error, LOG_ERR); + } + } + else + { + setEventMessage($langs->trans("ErrorModuleNotFound"),'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')); @@ -314,6 +399,143 @@ foreach ($dirproduct as $dirroot) } print ''; + +print '
'; +print_titre($langs->trans("ModelModulesProduct")); + +// Load array def with activated templates +$def = array(); +$sql = "SELECT nom"; +$sql.= " FROM ".MAIN_DB_PREFIX."document_model"; +$sql.= " WHERE type = 'product'"; +$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 ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +$var=true; +foreach ($dirproduct as $dirroot) +{ + $dir = dol_buildpath($dirroot.'core/modules/product/doc/',0); + $handle=@opendir($dir); + if (is_resource($handle)) + { + while (($file = readdir($handle))!==false) + { + if (preg_match('/\.modules\.php$/i',$file)) + { + $name = substr($file, 4, dol_strlen($file) -16); + $classname = substr($file, 0, dol_strlen($file) -12); + + try { + dol_include_once($dirroot.'core/modules/product/doc/'.$file); + } + catch(Exception $e) + { + dol_syslog($e->getMessage(), LOG_ERR); + } + + $module = new $classname($db); + + $modulequalified=1; + if (! empty($module->version)) { + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified=0; + else if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified=0; + } + + if ($modulequalified) + { + $var = !$var; + print ''; + + // Activate / Disable + if (in_array($name, $def)) + { + print ""; + } + else + { + if (versioncompare($module->phpmin,versionphparray()) > 0) + { + print ""; + } + else + { + 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("Height").'/'.$langs->trans("Width").': '.$module->page_hauteur.'/'.$module->page_largeur; + } + $htmltooltip.='

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip.='
'.$langs->trans("WatermarkOnDraft").': '.yn((! empty($module->option_draft_watermark)?$module->option_draft_watermark:''), 1, 1); + + print ''; + + // Preview + print ''; + + print "\n"; + } + } + } + closedir($handle); + } +} +print '
'.$langs->trans("Name").''.$langs->trans("Description").''.$langs->trans("Status").''.$langs->trans("ShortInfo").''.$langs->trans("Preview").'
'; + print $module->name; + print "\n"; + if (method_exists($module,'info')) print $module->info($langs); + else print $module->description; + print '\n"; + print 'scandir.'&label='.urlencode($module->name).'">'; + print img_picto($langs->trans("Enabled"),'switch_on'); + print ''; + print "\n"; + print img_picto(dol_escape_htmltag($langs->trans("ErrorModuleRequirePHPVersion",join('.',$module->phpmin))),'switch_off'); + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').''; + print "'; + print $form->textwithpicto('',$htmltooltip,1,0); + print ''; + if ($module->type == 'pdf') + { + $linkspec=''.img_object($langs->trans("Preview"),'bill').''; + } + else + { + $linkspec=img_object($langs->trans("PreviewNotAvailable"),'generic'); + } + print $linkspec; + print '
'; + /* * Other conf */