From b813144edb102c4c9b13407836042eae220761dd Mon Sep 17 00:00:00 2001 From: arnaud Date: Fri, 6 Jan 2017 16:44:09 +0100 Subject: [PATCH 1/4] NEW generation ODT --- htdocs/admin/user.php | 43 +++- .../core/class/commondocgenerator.class.php | 16 ++ htdocs/core/class/commonobject.class.php | 1 + htdocs/core/class/html.formfile.class.php | 29 ++- htdocs/core/lib/functions2.lib.php | 1 - .../modules/product/modules_product.class.php | 37 ++++ .../core/modules/user/modules_user.class.php | 62 ++++++ htdocs/product/admin/product.php | 192 ++++++++++++++++++ htdocs/product/card.php | 70 +++++++ htdocs/product/class/product.class.php | 35 ++++ htdocs/user/card.php | 35 ++++ 11 files changed, 516 insertions(+), 5 deletions(-) create mode 100644 htdocs/core/modules/user/modules_user.class.php diff --git a/htdocs/admin/user.php b/htdocs/admin/user.php index f76762c8334..fcb062457a9 100644 --- a/htdocs/admin/user.php +++ b/htdocs/admin/user.php @@ -40,11 +40,48 @@ if (! $user->admin) accessforbidden(); $extrafields = new ExtraFields($db); +$type='user'; /* * Action */ -if (preg_match('/set_(.*)/',$action,$reg)) + +// Activate a model +if ($action == 'set_default') +{ + $ret = addDocumentModel($value, $type, $label, $scandir); + $res = true; +} + +elseif ($action == 'del_default') +{ + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + if ($conf->global->USER_ADDON_PDF_ODT == "$value") dolibarr_del_const($db, 'USER_ADDON_PDF_ODT',$conf->entity); + } + $res = true; +} + +// Set default model +elseif ($action == 'setdoc') +{ + if (dolibarr_set_const($db, "USER_ADDON_PDF_ODT",$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_ODT = $value; + } + + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } + $res = true; +} +elseif (preg_match('/set_(.*)/',$action,$reg)) { $code=$reg[1]; if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) @@ -58,7 +95,7 @@ if (preg_match('/set_(.*)/',$action,$reg)) } } -if (preg_match('/del_(.*)/',$action,$reg)) +elseif (preg_match('/del_(.*)/',$action,$reg)) { $code=$reg[1]; if (dolibarr_del_const($db, $code, $conf->entity) > 0) @@ -72,7 +109,7 @@ if (preg_match('/del_(.*)/',$action,$reg)) } } //Set hide closed customer into combox or select -if ($action == 'sethideinactiveuser') +elseif ($action == 'sethideinactiveuser') { $status = GETPOST('status','alpha'); diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 9b233ef6b74..51977bcb356 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -317,6 +317,22 @@ abstract class CommonDocGenerator return $array_other; } + + + + function get_substitutionarray_each_var_object(&$object,$outputlangs,$recursive=true) { + foreach($object as $key => $value) { + if(!is_array($value) && !is_object($value)) { + $array_other['object_'.$key] = $value; + } + if(is_array($value) && $recursive){ + foreach($value as $key2 => $val) { + $array_other[$key][$key2] = $this->get_substitutionarray_each_var_object($val,$outputlangs,false); + } + } + } + return $array_other; + } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 3279d372a0e..f8ab4f34467 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3589,6 +3589,7 @@ abstract class CommonObject $modele=$tmp[0]; $srctemplatepath=$tmp[1]; } + // Search template files $file=''; $classname=''; $filefound=0; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index a973c2622cc..ded716c1766 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -299,7 +299,7 @@ class FormFile $headershown=0; $showempty=0; $i=0; - + $titletoshow=$langs->trans("Documents"); if (! empty($title)) $titletoshow=$title; @@ -402,6 +402,33 @@ class FormFile $modellist=ModelePDFProjects::liste_modeles($this->db); } } + elseif ($modulepart == 'product') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php'; + $modellist=ModelePDFProduct::liste_modeles($this->db); + } + } + elseif ($modulepart == 'user') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.php'; + $modellist=ModelePDFProduct::liste_modeles($this->db); + } + } + elseif ($modulepart == 'group') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_group.php'; + $modellist=ModelePDFProduct::liste_modeles($this->db); + } + } elseif ($modulepart == 'project_task') { if (is_array($genallowed)) $modellist=$genallowed; diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 82449ac63cb..19279296ce9 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1444,7 +1444,6 @@ function getListOfModels($db,$type,$maxfilenamelength=0) $const=$obj->description; $dirtoscan.=($dirtoscan?',':'').preg_replace('/[\r\n]+/',',',trim($conf->global->$const)); - $listoffiles=array(); // Now we add models found in directories scanned diff --git a/htdocs/core/modules/product/modules_product.class.php b/htdocs/core/modules/product/modules_product.class.php index e08ea074bbd..d7138af84a8 100644 --- a/htdocs/core/modules/product/modules_product.class.php +++ b/htdocs/core/modules/product/modules_product.class.php @@ -24,6 +24,43 @@ * \class ModeleProductCode * \brief Parent class for product code generators */ + +/** + * \file htdocs/core/modules/contract/modules_contract.php + * \ingroup contract + * \brief File with parent class for generating contracts to PDF and File of class to manage contract numbering + */ + + require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; + +/** + * Parent class to manage intervention document templates + */ +abstract class ModelePDFProduct extends CommonDocGenerator +{ + var $error=''; + + + /** + * Return list of active generation modules + * + * @param DoliDB $db Database handler + * @param integer $maxfilenamelength Max length of value to show + * @return array List of templates + */ + static function liste_modeles($db,$maxfilenamelength=0) + { + global $conf; + + $type='product'; + $liste=array(); + + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $liste=getListOfModels($db,$type,$maxfilenamelength); + return $liste; + } +} + abstract class ModeleProductCode { var $error=''; diff --git a/htdocs/core/modules/user/modules_user.class.php b/htdocs/core/modules/user/modules_user.class.php new file mode 100644 index 00000000000..3e94ece9372 --- /dev/null +++ b/htdocs/core/modules/user/modules_user.class.php @@ -0,0 +1,62 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2012 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 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 . + * or see http://www.gnu.org/ + */ + + +/** + * \class ModeleProductCode + * \brief Parent class for product code generators + */ + +/** + * \file htdocs/core/modules/contract/modules_contract.php + * \ingroup contract + * \brief File with parent class for generating contracts to PDF and File of class to manage contract numbering + */ + + require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; + +/** + * Parent class to manage intervention document templates + */ +abstract class ModelePDFUser extends CommonDocGenerator +{ + var $error=''; + + + /** + * Return list of active generation modules + * + * @param DoliDB $db Database handler + * @param integer $maxfilenamelength Max length of value to show + * @return array List of templates + */ + static function liste_modeles($db,$maxfilenamelength=0) + { + global $conf; + + $type='user'; + $liste=array(); + + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $liste=getListOfModels($db,$type,$maxfilenamelength); + return $liste; + } +} \ No newline at end of file diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 8a561c0e53e..10da8463058 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -43,6 +43,7 @@ if (! $user->admin || (empty($conf->product->enabled) && empty($conf->service->e $action = GETPOST('action','alpha'); $value = GETPOST('value','alpha'); +$type='product'; // Pricing Rules $select_pricing_rules=array( @@ -110,6 +111,42 @@ if ($action == 'setModuleOptions') } } +// Activate a model +if ($action == 'set_default') +{ + $ret = addDocumentModel($value, $type, $label, $scandir); + $res = true; +} + +if ($action == 'del_default') +{ + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + if ($conf->global->PRODUCT_ADDON_PDF_ODT == "$value") dolibarr_del_const($db, 'PRODUCT_ADDON_PDF_ODT',$conf->entity); + } + $res = true; +} + +// Set default model +if ($action == 'setdoc') +{ + if (dolibarr_set_const($db, "PRODUCT_ADDON_PDF_ODT",$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_ODT = $value; + } + + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } + $res = true; +} + 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); @@ -228,6 +265,8 @@ else if (empty($conf->service->enabled)) llxHeader('',$title); +$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + $linkback=''.$langs->trans("BackToModuleList").''; print load_fiche_titre($title,$linkback,'title_setup'); @@ -317,6 +356,159 @@ foreach ($dirproduct as $dirroot) } print ''; + +// Defini tableau def des modeles +$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 ''; +print ''; +print ''; +print '\n"; +print '\n"; +print ''; +print ''; +print "\n"; + +clearstatcache(); + +$var=true; +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) + { + $var = !$var; + 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("PaymentMode").': '.yn($module->option_modereg,1,1); + $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); + $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); + $htmltooltip.='
'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,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 */ diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 59ccdb79a1f..7a0ebca0ace 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -38,6 +38,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; @@ -517,6 +518,40 @@ if (empty($reshook)) $action=''; } } + if ($action == 'builddoc' && $user->rights->produit->creer) { + /*if (GETPOST('model')) { + $object->setDocModel($user, GETPOST('model')); + }*/ + + // Define output language + $outputlangs = $langs; + if (! empty($conf->global->MAIN_MULTILANGS)) { + $outputlangs = new Translate("", $conf); + $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); + $outputlangs->setDefaultLang($newlang); + } + $ret = $object->fetch($id); // Reload to get new records + $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result <= 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; + } + } + + // Remove file in doc form + if ($action == 'remove_file' && $user->rights->contrat->creer) { + if ($object->id > 0) { + require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + + $langs->load("other"); + $upload_dir = $conf->contrat->dir_output; + $file = $upload_dir . '/' . GETPOST('file'); + $ret = dol_delete_file($file, 0, 0, 0, $object); + if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); + else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors'); + } + } // Add product into object @@ -770,6 +805,7 @@ else $title = $langs->trans('ProductServiceCard'); llxHeader('', $title, $helpurl); $form = new Form($db); +$formfile = new FormFile($db); $formproduct = new FormProduct($db); @@ -1829,5 +1865,39 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status) } +print '
'; + +/* + * Documents generes +*/ +$filename = dol_sanitizeFileName($object->ref); +$filedir = $conf->produit->dir_output . "/" . dol_sanitizeFileName($object->ref); +$urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; +$genallowed = $user->rights->produit->creer; +$delallowed = $user->rights->produit->supprimer; + +$var = true; + +$somethingshown = $formfile->show_documents('product', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); + +// Linked object block +$somethingshown = $form->showLinkedObjectBlock($object); + +// Show links to link elements +$linktoelem = $form->showLinkToObjectBlock($object); +if ($linktoelem) print '
'.$linktoelem; + + +print '
'; + +// List of actions on element +include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; +$formactions = new FormActions($db); +$somethingshown = $formactions->showactions($object, 'product', $socid); + + +print '
'; + + llxFooter(); $db->close(); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 1d8d17d6c8f..2c4eb128413 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3191,6 +3191,41 @@ class Product extends CommonObject return $result; } + + /** + * Create a document onto disk according to template module. + * + * @param string $modele Force model to use ('' to not force) + * @param Translate $outputlangs Object langs to use for output + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @return int 0 if KO, 1 if OK + */ + public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) + { + global $conf,$user,$langs; + + $langs->load("products"); + + // Positionne le modele sur le nom du modele a utiliser + if (! dol_strlen($modele)) + { + if (! empty($conf->global->PRODUCT_ADDON_PDF)) + { + $modele = $conf->global->PRODUCT_ADDON_PDF; + } + else + { + $modele = 'strato'; + } + } + + $modelpath = "core/modules/product/doc/"; + + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + /** * Return label of status of object * diff --git a/htdocs/user/card.php b/htdocs/user/card.php index b0425b182e0..ce6ef3f992f 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -35,6 +35,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; @@ -589,6 +590,7 @@ if (empty($reshook)) { $form = new Form($db); $formother=new FormOther($db); $formcompany = new FormCompany($db); +$formfile = new FormFile($db); llxHeader('',$langs->trans("UserCard")); @@ -2275,8 +2277,41 @@ else print ''; } + print '
'; + /* + * Documents generes + */ + $filename = dol_sanitizeFileName($object->ref); + $filedir = $conf->user->dir_output . "/" . dol_sanitizeFileName($object->ref); + $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; + $genallowed = $user->rights->user->creer; + $delallowed = $user->rights->user->supprimer; + + $var = true; + + $somethingshown = $formfile->show_documents('user', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); + + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($object); + + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object); + if ($linktoelem) print '
'.$linktoelem; + + + print '
'; + + // List of actions on element + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; + $formactions = new FormActions($db); + $somethingshown = $formactions->showactions($object, 'user', $socid); + + + print '
'; + if (! empty($conf->ldap->enabled) && ! empty($object->ldap_sid)) $ldap->close; } + } if (! empty($conf->api->enabled) && ! empty($conf->use_javascript_ajax)) From abeba95de9740d1cecaed4f872ff799326e15c13 Mon Sep 17 00:00:00 2001 From: arnaud Date: Thu, 2 Mar 2017 15:13:42 +0100 Subject: [PATCH 2/4] New USER odt --- htdocs/admin/user.php | 194 +++++++++++++++++++++- htdocs/core/class/html.formfile.class.php | 4 +- htdocs/core/lib/admin.lib.php | 2 +- htdocs/user/card.php | 9 +- htdocs/user/class/user.class.php | 34 ++++ 5 files changed, 235 insertions(+), 8 deletions(-) diff --git a/htdocs/admin/user.php b/htdocs/admin/user.php index fcb062457a9..d237ca3e727 100644 --- a/htdocs/admin/user.php +++ b/htdocs/admin/user.php @@ -35,11 +35,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $langs->load("admin"); $langs->load("members"); $langs->load("users"); - if (! $user->admin) accessforbidden(); $extrafields = new ExtraFields($db); +$action = GETPOST('action','alpha'); +$value = GETPOST('value','alpha'); $type='user'; /* @@ -47,7 +48,36 @@ $type='user'; */ // Activate a model -if ($action == 'set_default') + +// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) +if ($action == 'setModuleOptions') +{ + $post_size=count($_POST); + + $db->begin(); + + for($i=0;$i < $post_size;$i++) + { + if (array_key_exists('param'.$i,$_POST)) + { + $param=GETPOST("param".$i,'alpha'); + $value=GETPOST("value".$i,'alpha'); + if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + $db->rollback(); + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} +elseif ($action == 'set_default') { $ret = addDocumentModel($value, $type, $label, $scandir); $res = true; @@ -70,7 +100,7 @@ elseif ($action == 'setdoc') { // 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_ODT = $value; + $conf->global->USER_ADDON_PDF_ODT = $value; } // On active le modele @@ -175,6 +205,164 @@ print ''; print ''; + + +$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + +$form=new Form($db); + +// Defini tableau def des modeles +$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 ''; +print ''; +print ''; +print '\n"; +print '\n"; +print ''; +print ''; +print "\n"; + +clearstatcache(); + +$var=true; +foreach ($dirmodels as $reldir) +{ + foreach (array('','/doc') as $valdir) + { + $dir = dol_buildpath($reldir."core/modules/user".$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) + { + $var = !$var; + 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("PaymentMode").': '.yn($module->option_modereg,1,1); + $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); + $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); + $htmltooltip.='
'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,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->USER_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 "
"; + dol_fiche_end(); llxFooter(); diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index ded716c1766..f60faa84426 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -416,8 +416,8 @@ class FormFile if (is_array($genallowed)) $modellist=$genallowed; else { - include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.php'; - $modellist=ModelePDFProduct::liste_modeles($this->db); + include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php'; + $modellist=ModelePDFUser::liste_modeles($this->db); } } elseif ($modulepart == 'group') diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index ffb09b2b3ab..56c48a33173 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -1270,7 +1270,7 @@ function addDocumentModel($name, $type, $label='', $description='') $sql.= ($label?"'".$db->escape($label)."'":'null').", "; $sql.= (! empty($description)?"'".$db->escape($description)."'":"null"); $sql.= ")"; - + dol_syslog("admin.lib::addDocumentModel", LOG_DEBUG); $resql=$db->query($sql); if ($resql) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index ce6ef3f992f..53634de159c 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -580,6 +580,11 @@ if (empty($reshook)) { setEventMessages($ldap->error, $ldap->errors, 'errors'); } } + + // Actions to build doc + $upload_dir = $conf->user->dir_output; + $permissioncreate=$user->rights->user->user->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } @@ -2284,8 +2289,8 @@ else $filename = dol_sanitizeFileName($object->ref); $filedir = $conf->user->dir_output . "/" . dol_sanitizeFileName($object->ref); $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; - $genallowed = $user->rights->user->creer; - $delallowed = $user->rights->user->supprimer; + $genallowed = $user->rights->user->user->creer; + $delallowed = $user->rights->user->user->supprimer; $var = true; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 1ee07e0a7af..f77a7fbc9df 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2622,5 +2622,39 @@ class User extends CommonObject } } + /** + * Create a document onto disk according to template module. + * + * @param string $modele Force model to use ('' to not force) + * @param Translate $outputlangs Object langs to use for output + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @return int 0 if KO, 1 if OK + */ + public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) + { + global $conf,$user,$langs; + + $langs->load("user"); + + // Positionne le modele sur le nom du modele a utiliser + if (! dol_strlen($modele)) + { + if (! empty($conf->global->USER_ADDON_PDF)) + { + $modele = $conf->global->USER_ADDON_PDF; + } + else + { + $modele = 'bluesky'; + } + } + + $modelpath = "core/modules/user/doc/"; + + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } From cff9fa0e6b4f4c13909f703f2cd646336cd48437 Mon Sep 17 00:00:00 2001 From: arnaud Date: Fri, 3 Mar 2017 12:01:58 +0100 Subject: [PATCH 3/4] FIX user odt --- .../core/class/commondocgenerator.class.php | 29 ++++++++++++++----- .../core/modules/user/modules_user.class.php | 28 ++++++++++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 51977bcb356..1d4cb508fb9 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -320,16 +320,29 @@ abstract class CommonDocGenerator + /** + * Define array with couple subtitution key => subtitution value + * + * @param Object $object Dolibarr Object + * @param Translate $outputlangs Language object for output + * @param boolean $recursive Want to fetch child array or child object + * @return array Array of substitution key->code + */ function get_substitutionarray_each_var_object(&$object,$outputlangs,$recursive=true) { - foreach($object as $key => $value) { - if(!is_array($value) && !is_object($value)) { - $array_other['object_'.$key] = $value; - } - if(is_array($value) && $recursive){ - foreach($value as $key2 => $val) { - $array_other[$key][$key2] = $this->get_substitutionarray_each_var_object($val,$outputlangs,false); + $array_other = array(); + if(!empty($object)) { + foreach($object as $key => $value) { + if(!is_array($value) && !is_object($value)) { + $array_other['object_'.$key] = $value; } - } + if(is_array($value) && $recursive){ + if(!empty($value)) { + foreach($value as $key2 => $val) { + $array_other[$key][$key2] = $this->get_substitutionarray_each_var_object($val,$outputlangs,false); + } + } + } + } } return $array_other; } diff --git a/htdocs/core/modules/user/modules_user.class.php b/htdocs/core/modules/user/modules_user.class.php index 3e94ece9372..43660da1adb 100644 --- a/htdocs/core/modules/user/modules_user.class.php +++ b/htdocs/core/modules/user/modules_user.class.php @@ -55,6 +55,34 @@ abstract class ModelePDFUser extends CommonDocGenerator $type='user'; $liste=array(); + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $liste=getListOfModels($db,$type,$maxfilenamelength); + return $liste; + } +} + +/** + * Parent class to manage intervention document templates + */ +abstract class ModelePDFUserGroup extends CommonDocGenerator +{ + var $error=''; + + + /** + * Return list of active generation modules + * + * @param DoliDB $db Database handler + * @param integer $maxfilenamelength Max length of value to show + * @return array List of templates + */ + static function liste_modeles($db,$maxfilenamelength=0) + { + global $conf; + + $type='usergroup'; + $liste=array(); + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $liste=getListOfModels($db,$type,$maxfilenamelength); return $liste; From 4a7e3fb3872d0e85613227f5d1b454cae5c5a0a8 Mon Sep 17 00:00:00 2001 From: arnaud Date: Wed, 8 Mar 2017 11:34:21 +0100 Subject: [PATCH 4/4] NEW odt usergroup --- htdocs/admin/usergroup.php | 316 ++++++++++++++++++ .../core/class/commondocgenerator.class.php | 16 +- htdocs/core/class/conf.class.php | 5 + htdocs/core/class/html.formfile.class.php | 6 +- htdocs/core/lib/usergroups.lib.php | 5 + .../core/modules/user/modules_user.class.php | 28 -- .../usergroup/modules_usergroup.class.php | 62 ++++ htdocs/install/mysql/tables/llx_user.sql | 1 + htdocs/install/mysql/tables/llx_usergroup.sql | 5 +- htdocs/user/class/usergroup.class.php | 34 ++ htdocs/user/group/card.php | 40 ++- 11 files changed, 475 insertions(+), 43 deletions(-) create mode 100644 htdocs/admin/usergroup.php create mode 100644 htdocs/core/modules/usergroup/modules_usergroup.class.php diff --git a/htdocs/admin/usergroup.php b/htdocs/admin/usergroup.php new file mode 100644 index 00000000000..72365726d25 --- /dev/null +++ b/htdocs/admin/usergroup.php @@ -0,0 +1,316 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004 Sebastien Di Cintio + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2015 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/admin/usergroup.php + * \ingroup core + * \brief Page to setup usergroup module + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + +$langs->load("admin"); +$langs->load("members"); +$langs->load("users"); +if (! $user->admin) accessforbidden(); + +$extrafields = new ExtraFields($db); + +$action = GETPOST('action','alpha'); +$value = GETPOST('value','alpha'); +$type='group'; + +/* + * Action + */ + +// Activate a model + +// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) +if ($action == 'setModuleOptions') +{ + $post_size=count($_POST); + + $db->begin(); + + for($i=0;$i < $post_size;$i++) + { + if (array_key_exists('param'.$i,$_POST)) + { + $param=GETPOST("param".$i,'alpha'); + $value=GETPOST("value".$i,'alpha'); + if ($param) $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + $db->rollback(); + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} +elseif ($action == 'set_default') +{ + $ret = addDocumentModel($value, $type, $label, $scandir); + $res = true; +} + +elseif ($action == 'del_default') +{ + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + if ($conf->global->USERGROUP_ADDON_PDF_ODT == "$value") dolibarr_del_const($db, 'USERGROUP_ADDON_PDF_ODT',$conf->entity); + } + $res = true; +} + +// Set default model +elseif ($action == 'setdoc') +{ + if (dolibarr_set_const($db, "USERGROUP_ADDON_PDF_ODT",$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->USERGROUP_ADDON_PDF_ODT = $value; + } + + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } + $res = true; +} +elseif (preg_match('/set_(.*)/',$action,$reg)) +{ + $code=$reg[1]; + if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + dol_print_error($db); + } +} + +elseif (preg_match('/del_(.*)/',$action,$reg)) +{ + $code=$reg[1]; + if (dolibarr_del_const($db, $code, $conf->entity) > 0) + { + header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + dol_print_error($db); + } +} +/* + * View + */ + +$help_url='EN:Module_Users|FR:Module_Utilisateurs|ES:Módulo_Usuarios'; +llxHeader('',$langs->trans("UsersSetup"),$help_url); + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("UsersSetup"),$linkback,'title_setup'); + + +$head=user_admin_prepare_head(); + +dol_fiche_head($head,'usergroupcard', $langs->trans("MenuUsersAndGroups"), 0, 'user'); + + +$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + +$form=new Form($db); + +// Defini tableau def des modeles +$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 ''; +print ''; +print ''; +print '\n"; +print '\n"; +print ''; +print ''; +print "\n"; + +clearstatcache(); + +$var=true; +foreach ($dirmodels as $reldir) +{ + foreach (array('','/doc') as $valdir) + { + $dir = dol_buildpath($reldir."core/modules/usergroup".$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) + { + $var = !$var; + 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("PaymentMode").': '.yn($module->option_modereg,1,1); + $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1); + $htmltooltip.='
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1); + $htmltooltip.='
'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,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->USERGROUP_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 "
"; + +dol_fiche_end(); + +llxFooter(); +$db->close(); diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 1d4cb508fb9..9c3bc5b131e 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -332,19 +332,17 @@ abstract class CommonDocGenerator $array_other = array(); if(!empty($object)) { foreach($object as $key => $value) { - if(!is_array($value) && !is_object($value)) { - $array_other['object_'.$key] = $value; - } - if(is_array($value) && $recursive){ - if(!empty($value)) { - foreach($value as $key2 => $val) { - $array_other[$key][$key2] = $this->get_substitutionarray_each_var_object($val,$outputlangs,false); - } + if(!empty($value)) { + if(!is_array($value) && !is_object($value)) { + $array_other['object_'.$key] = $value; + } + if(is_array($value) && $recursive){ + $array_other['object_'.$key] = $this->get_substitutionarray_each_var_object($value,$outputlangs,false); } } } } - return $array_other; + return $array_other; } diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 0bd28092bff..8a5172c182b 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -106,6 +106,7 @@ class Conf $this->propal = new stdClass(); $this->facture = new stdClass(); $this->contrat = new stdClass(); + $this->usergroup = new stdClass(); $this->adherent = new stdClass(); $this->bank = new stdClass(); $this->notification = new stdClass(); @@ -309,6 +310,10 @@ class Conf // For backward compatibility $this->user->dir_output=$rootforuser."/users"; $this->user->dir_temp=$rootforuser."/users/temp"; + + // UserGroup + $this->usergroup->dir_output=$rootforuser."/usergroups"; + $this->usergroup->dir_temp=$rootforuser."/usergroups/temp"; // For propal storage $this->propal->dir_output=$rootfordata."/propale"; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index f60faa84426..2dbbd9545db 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -420,13 +420,13 @@ class FormFile $modellist=ModelePDFUser::liste_modeles($this->db); } } - elseif ($modulepart == 'group') + elseif ($modulepart == 'usergroup') { if (is_array($genallowed)) $modellist=$genallowed; else { - include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_group.php'; - $modellist=ModelePDFProduct::liste_modeles($this->db); + include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php'; + $modellist=ModelePDFUserGroup::liste_modeles($this->db); } } elseif ($modulepart == 'project_task') diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php index ed95bdc4023..117f7a1e86e 100644 --- a/htdocs/core/lib/usergroups.lib.php +++ b/htdocs/core/lib/usergroups.lib.php @@ -207,6 +207,11 @@ function user_admin_prepare_head() $head[$h][2] = 'card'; $h++; + $head[$h][0] = DOL_URL_ROOT.'/admin/usergroup.php'; + $head[$h][1] = $langs->trans("Group"); + $head[$h][2] = 'usergroupcard'; + $h++; + $head[$h][0] = DOL_URL_ROOT.'/user/admin/user_extrafields.php'; $head[$h][1] = $langs->trans("ExtraFields"); $head[$h][2] = 'attributes'; diff --git a/htdocs/core/modules/user/modules_user.class.php b/htdocs/core/modules/user/modules_user.class.php index 43660da1adb..3e94ece9372 100644 --- a/htdocs/core/modules/user/modules_user.class.php +++ b/htdocs/core/modules/user/modules_user.class.php @@ -55,34 +55,6 @@ abstract class ModelePDFUser extends CommonDocGenerator $type='user'; $liste=array(); - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $liste=getListOfModels($db,$type,$maxfilenamelength); - return $liste; - } -} - -/** - * Parent class to manage intervention document templates - */ -abstract class ModelePDFUserGroup extends CommonDocGenerator -{ - var $error=''; - - - /** - * Return list of active generation modules - * - * @param DoliDB $db Database handler - * @param integer $maxfilenamelength Max length of value to show - * @return array List of templates - */ - static function liste_modeles($db,$maxfilenamelength=0) - { - global $conf; - - $type='usergroup'; - $liste=array(); - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $liste=getListOfModels($db,$type,$maxfilenamelength); return $liste; diff --git a/htdocs/core/modules/usergroup/modules_usergroup.class.php b/htdocs/core/modules/usergroup/modules_usergroup.class.php new file mode 100644 index 00000000000..f7d4778efe1 --- /dev/null +++ b/htdocs/core/modules/usergroup/modules_usergroup.class.php @@ -0,0 +1,62 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2005-2012 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 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 . + * or see http://www.gnu.org/ + */ + + +/** + * \class ModeleProductCode + * \brief Parent class for product code generators + */ + +/** + * \file htdocs/core/modules/contract/modules_contract.php + * \ingroup contract + * \brief File with parent class for generating contracts to PDF and File of class to manage contract numbering + */ + + require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; + +/** + * Parent class to manage intervention document templates + */ +abstract class ModelePDFUserGroup extends CommonDocGenerator +{ + var $error=''; + + + /** + * Return list of active generation modules + * + * @param DoliDB $db Database handler + * @param integer $maxfilenamelength Max length of value to show + * @return array List of templates + */ + static function liste_modeles($db,$maxfilenamelength=0) + { + global $conf; + + $type='usergroup'; + $liste=array(); + + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $liste=getListOfModels($db,$type,$maxfilenamelength); + return $liste; + } +} \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_user.sql b/htdocs/install/mysql/tables/llx_user.sql index e334ae1f802..5530622ac1d 100644 --- a/htdocs/install/mysql/tables/llx_user.sql +++ b/htdocs/install/mysql/tables/llx_user.sql @@ -62,6 +62,7 @@ create table llx_user fk_member integer, fk_user integer, -- Hierarchic parent note text DEFAULT NULL, + model_pdf varchar(255) DEFAULT NULL, datelastlogin datetime, datepreviouslogin datetime, egroupware_id integer, diff --git a/htdocs/install/mysql/tables/llx_usergroup.sql b/htdocs/install/mysql/tables/llx_usergroup.sql index 156c6eda364..9afe72f3b24 100644 --- a/htdocs/install/mysql/tables/llx_usergroup.sql +++ b/htdocs/install/mysql/tables/llx_usergroup.sql @@ -25,7 +25,8 @@ create table llx_usergroup entity integer DEFAULT 1 NOT NULL, -- multi company id datec datetime, tms timestamp, - note text + note text, + model_pdf varchar(255) DEFAULT NULL, )ENGINE=innodb; -- @@ -35,4 +36,4 @@ create table llx_usergroup -- 1 : first company group -- 2 : second company group -- 3 : etc... --- \ No newline at end of file +-- diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index 50237b0ef61..96f2d3aa7bc 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -818,5 +818,39 @@ class UserGroup extends CommonObject $this->datem=time(); $this->members=array($user->id); // Members of this group is just me } + + /** + * Create a document onto disk according to template module. + * + * @param string $modele Force model to use ('' to not force) + * @param Translate $outputlangs Object langs to use for output + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @return int 0 if KO, 1 if OK + */ + public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) + { + global $conf,$user,$langs; + + $langs->load("user"); + + // Positionne le modele sur le nom du modele a utiliser + if (! dol_strlen($modele)) + { + if (! empty($conf->global->USERGROUP_ADDON_PDF)) + { + $modele = $conf->global->USERGROUP_ADDON_PDF; + } + else + { + $modele = 'grass'; + } + } + + $modelpath = "core/modules/usergroup/doc/"; + + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); + } } diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index 716db97b911..cc496152f4f 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -28,6 +28,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; if(! empty($conf->multicompany->enabled)) dol_include_once('/multicompany/class/actions_multicompany.class.php'); // Defini si peux lire/modifier utilisateurs et permisssions @@ -220,6 +221,8 @@ llxHeader('',$langs->trans("GroupCard")); $form = new Form($db); $fuserstatic = new User($db); +$form = new Form($db); +$formfile = new FormFile($db); if ($action == 'create') { @@ -495,6 +498,42 @@ else } print ""; print "
"; + + // Actions to build doc + $upload_dir = $conf->usergroup->dir_output; + $permissioncreate=$user->rights->user->user->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + + /* + * Documents generes + */ + $filename = dol_sanitizeFileName($object->ref); + $filedir = $conf->usergroup->dir_output . "/" . dol_sanitizeFileName($object->ref); + $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; + $genallowed = $user->rights->user->user->creer; + $delallowed = $user->rights->user->user->supprimer; + + $var = true; + + $somethingshown = $formfile->show_documents('usergroup', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); + + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($object); + + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object); + if ($linktoelem) print '
'.$linktoelem; + + + print '
'; + + // List of actions on element + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; + $formactions = new FormActions($db); + $somethingshown = $formactions->showactions($object, 'usergroup', $socid); + + + print '
'; } /* @@ -551,7 +590,6 @@ else print ''; } - } }