From 16214e7e301ade6f40cad392d962f846f4b32d4a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Feb 2010 18:37:29 +0000 Subject: [PATCH] Work on generic odt generation --- htdocs/html.formadmin.class.php | 2 +- htdocs/html.formfile.class.php | 19 +++-- .../societe/doc/doc_generic_odt.modules.php | 2 +- .../modules/societe/modules_societe.class.php | 2 +- htdocs/lib/functions2.lib.php | 36 +++++++- htdocs/product/index.php | 82 +++++++++---------- htdocs/soc.php | 11 +-- htdocs/translate.class.php | 4 +- 8 files changed, 101 insertions(+), 57 deletions(-) diff --git a/htdocs/html.formadmin.class.php b/htdocs/html.formadmin.class.php index ef4167cee68..05e7544d8cb 100644 --- a/htdocs/html.formadmin.class.php +++ b/htdocs/html.formadmin.class.php @@ -58,7 +58,7 @@ class FormAdmin { global $langs; - $langs_available=$langs->get_available_languages(); + $langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12); print 'load("errors"); print ' '.img_warning($langs->trans("WarningNoDocumentModelActivated")); } - print ''; + print ''; + + print ''; } // Get list of files @@ -364,10 +373,10 @@ class FormFile $filter = ''; if ($iconPDF==1) { - $png = '|\.png$'; + $png = '\.png$'; $filter = $filename.'.pdf'; } - $file_list=dol_dir_list($filedir,'files',0,$filter,'\.meta$'.$png,'date',SORT_DESC); + $file_list=dol_dir_list($filedir,'files',0,$filter,'\.meta$'.($png?'|'.$png:''),'date',SORT_DESC); // Affiche en-tete tableau si non deja affiche if (sizeof($file_list) && ! $headershown && !$iconPDF) diff --git a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php index a94b0b3901c..e85b8afd135 100644 --- a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php @@ -102,7 +102,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc else { $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.odt'); - $listoffiles=array_merge($listoffiles,$tmpfiles); + if (sizeof($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); } } $texte.= $form->textwithpicto($textbis,$langs->trans("ListOfDirectoriesForModelGenODT"),1,'help'); diff --git a/htdocs/includes/modules/societe/modules_societe.class.php b/htdocs/includes/modules/societe/modules_societe.class.php index bffa343b431..9697bfdcd2b 100644 --- a/htdocs/includes/modules/societe/modules_societe.class.php +++ b/htdocs/includes/modules/societe/modules_societe.class.php @@ -46,7 +46,7 @@ class ModeleThirdPartyDoc $type='company'; $liste=array(); - $dirtoscan=$conf->global->COMPANY_ADDON_PDF_ODTPATH; + $dirtoscan=preg_replace('/\r\n/',',',trim($conf->global->COMPANY_ADDON_PDF_ODTPATH)); include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php'); $liste=getListOfModels($db,$type,$dirtoscan); diff --git a/htdocs/lib/functions2.lib.php b/htdocs/lib/functions2.lib.php index 8e06a6293fd..8d0049ea72c 100644 --- a/htdocs/lib/functions2.lib.php +++ b/htdocs/lib/functions2.lib.php @@ -1015,7 +1015,8 @@ function picto_from_langcode($codelang) * \brief Return list of activated modules of doc generation * \param $db Database handler * \param $type Type of models (company, invoice, ...) - * \param $dirodts List of directories to scan for templates + * \param $dirodts List of directories to scan for templates (dir1,dir2,dir3...) + * \return array array(key=>label) */ function getListOfModels($db,$type,$dirtoscan='') { @@ -1035,6 +1036,15 @@ function getListOfModels($db,$type,$dirtoscan='') while ($i < $num) { $obj = $db->fetch_object($resql); + + // We exclude from list generic modules that use directory scans. + // We will add them after. + if (preg_match('/_odt$/',$obj->id)) + { + $i++; + continue; + } + $liste[$obj->id]=$obj->label?$obj->label:$obj->lib; $i++; } @@ -1045,5 +1055,29 @@ function getListOfModels($db,$type,$dirtoscan='') return -1; } + // Now we add models found in directories scanned + if ($dirtoscan) + { + $listofdir=explode(',',$dirtoscan); + $listoffiles=array(); + foreach($listofdir as $key=>$tmpdir) + { + $tmpdir=trim($tmpdir); + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); + if (! $tmpdir) { unset($listofdir[$key]); continue; } + if (! is_dir($tmpdir)) $textbis.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); + else + { + $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.odt'); + if (sizeof($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); + } + } + + foreach($listoffiles as $record) + { + $liste[$record['fullname']]=dol_trunc($record['name'],24,'middle'); + } + } + return $liste; } diff --git a/htdocs/product/index.php b/htdocs/product/index.php index 4354459a076..9f6fd278662 100644 --- a/htdocs/product/index.php +++ b/htdocs/product/index.php @@ -160,22 +160,22 @@ print ''; */ $max=15; $sql = "SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.envente,"; -$sql.= " ".$db->pdate("tms")." as datem"; +$sql.= " p.tms as datem"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; -if ($conf->categorie->enabled && !$user->rights->categorie->voir) -{ - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid"; -} $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_subproduct as sp ON p.rowid = sp.fk_product_subproduct"; $sql.= " WHERE sp.fk_product_subproduct IS NULL"; $sql.= " AND p.entity = ".$conf->entity; -if ($conf->categorie->enabled && !$user->rights->categorie->voir) $sql.= " AND COALESCE(c.visible,1)=1 "; +/*if ($conf->categorie->enabled && !$user->rights->categorie->voir) +{ + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cp.fk_categorie = c.rowid"; + $sql.= " AND COALESCE(c.visible,1)=1 "; +}*/ if ($type != '') $sql.= " AND p.fk_product_type = ".$type; -$sql.= " ORDER BY p.tms DESC "; +$sql.= $db->order("p.tms","DESC"); $sql.= $db->plimit($max,0); +//print $sql; $result = $db->query($sql) ; - if ($result) { $num = $db->num_rows($result); @@ -196,41 +196,41 @@ if ($result) while ($i < $num) { - $objp = $db->fetch_object($result); + $objp = $db->fetch_object($result); - //Multilangs - if ($conf->global->MAIN_MULTILANGS) - { - $sql = "SELECT label"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql.= " WHERE fk_product=".$objp->rowid; - $sql.= " AND lang='". $langs->getDefaultLang() ."'"; + //Multilangs + if ($conf->global->MAIN_MULTILANGS) + { + $sql = "SELECT label"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql.= " WHERE fk_product=".$objp->rowid; + $sql.= " AND lang='". $langs->getDefaultLang() ."'"; - $resultd = $db->query($sql); - if ($resultd) - { - $objtp = $db->fetch_object($resultd); - if ($objtp && $objtp->label != '') $objp->label = $objtp->label; - } - } + $resultd = $db->query($sql); + if ($resultd) + { + $objtp = $db->fetch_object($resultd); + if ($objtp && $objtp->label != '') $objp->label = $objtp->label; + } + } - $var=!$var; - print ""; - print ''; - $product_static->id=$objp->rowid; - $product_static->ref=$objp->ref; - $product_static->type=$objp->fk_product_type; - print $product_static->getNomUrl(1,'',16); - print "\n"; - print ''.dol_trunc($objp->label,32).''; - print ""; - print dol_print_date($objp->datem,'day'); - print ""; - print ''; - print $product_static->LibStatut($objp->envente,5); - print ""; - print "\n"; - $i++; + $var=!$var; + print ""; + print ''; + $product_static->id=$objp->rowid; + $product_static->ref=$objp->ref; + $product_static->type=$objp->fk_product_type; + print $product_static->getNomUrl(1,'',16); + print "\n"; + print ''.dol_trunc($objp->label,32).''; + print ""; + print dol_print_date($objp->datem,'day'); + print ""; + print ''; + print $product_static->LibStatut($objp->envente,5); + print ""; + print "\n"; + $i++; } $db->free(); diff --git a/htdocs/soc.php b/htdocs/soc.php index 42d413abfc9..a8288d63bbe 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -1390,13 +1390,13 @@ else - print '
'; + print ''; + print ''; + print ''; + print ''; print '
'; print ''; // ancre /* * Documents generes */ - $filedir=$conf->societe->dir_output; + $filedir=$conf->societe->dir_output.'/'.$soc->id; $urlsource=$_SERVER["PHP_SELF"]."?socid=".$soc->id; $genallowed=$user->rights->societe->creer; $delallowed=$user->rights->societe->supprimer; @@ -1405,9 +1405,10 @@ else $somethingshown=$formfile->show_documents('company','',$filedir,$urlsource,$genallowed,$delallowed,'','',0,0,28,0,'',0,'',$soc->default_lang); - print ''; - - print '
'; + print '
'; print '
'; diff --git a/htdocs/translate.class.php b/htdocs/translate.class.php index 46cd950426a..0c766473826 100644 --- a/htdocs/translate.class.php +++ b/htdocs/translate.class.php @@ -509,7 +509,7 @@ class Translate { * \param langdir Directory to scan * \return array List of languages */ - function get_available_languages($langdir=DOL_DOCUMENT_ROOT) + function get_available_languages($langdir=DOL_DOCUMENT_ROOT,$maxlength=0) { // We scan directory langs to detect available languages $handle=opendir($langdir."/langs"); @@ -520,7 +520,7 @@ class Translate { { $this->load("languages"); - $langs_available[$dir] = $this->trans('Language_'.$dir).' - '.$dir; + $langs_available[$dir] = $dir.': '.dol_trunc($this->trans('Language_'.$dir),$maxlength); } } return $langs_available;