Work on generic odt generation
This commit is contained in:
parent
9ba22b150e
commit
16214e7e30
@ -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 '<select class="flat" name="'.$htmlname.'">';
|
||||
if ($showempty)
|
||||
|
||||
@ -159,6 +159,7 @@ class FormFile
|
||||
|
||||
$filename = dol_sanitizeFileName($filename);
|
||||
$headershown=0;
|
||||
$showempty=0;
|
||||
$i=0;
|
||||
|
||||
print "\n".'<!-- Start show_document -->'."\n";
|
||||
@ -170,6 +171,7 @@ class FormFile
|
||||
$modellist=array();
|
||||
if ($modulepart == 'company')
|
||||
{
|
||||
$showempty=1;
|
||||
if (is_array($genallowed)) $modellist=$genallowed;
|
||||
else
|
||||
{
|
||||
@ -320,11 +322,13 @@ class FormFile
|
||||
print '<table class="border" summary="listofdocumentstable" width="100%">';
|
||||
|
||||
print '<tr '.$bc[$var].'>';
|
||||
|
||||
// Model
|
||||
if (! empty($modellist))
|
||||
{
|
||||
print '<td align="center">';
|
||||
print $langs->trans('Model').' ';
|
||||
print $html->selectarray('model',$modellist,$modelselected,0,0,1);
|
||||
print $html->selectarray('model',$modellist,$modelselected,$showempty,0,0);
|
||||
print '</td>';
|
||||
}
|
||||
else
|
||||
@ -333,8 +337,9 @@ class FormFile
|
||||
print $langs->trans("Files");
|
||||
print '</td>';
|
||||
}
|
||||
print '<td align="center">';
|
||||
|
||||
// Language code (if multilang)
|
||||
print '<td align="center">';
|
||||
if($conf->global->MAIN_MULTILANGS && ! $forcenomultilang)
|
||||
{
|
||||
include_once(DOL_DOCUMENT_ROOT.'/html.formadmin.class.php');
|
||||
@ -347,6 +352,8 @@ class FormFile
|
||||
print ' ';
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Button
|
||||
print '<td align="center" colspan="'.($delallowed?'2':'1').'">';
|
||||
print '<input class="button" ';
|
||||
//print ((is_array($modellist) && sizeof($modellist))?'':' disabled="true"') // Always allow button "Generate" (even if no model activated)
|
||||
@ -356,7 +363,9 @@ class FormFile
|
||||
$langs->load("errors");
|
||||
print ' '.img_warning($langs->trans("WarningNoDocumentModelActivated"));
|
||||
}
|
||||
print '</td></tr>';
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -160,22 +160,22 @@ print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
|
||||
*/
|
||||
$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 "<tr $bc[$var]>";
|
||||
print '<td nowrap="nowrap">';
|
||||
$product_static->id=$objp->rowid;
|
||||
$product_static->ref=$objp->ref;
|
||||
$product_static->type=$objp->fk_product_type;
|
||||
print $product_static->getNomUrl(1,'',16);
|
||||
print "</td>\n";
|
||||
print '<td>'.dol_trunc($objp->label,32).'</td>';
|
||||
print "<td>";
|
||||
print dol_print_date($objp->datem,'day');
|
||||
print "</td>";
|
||||
print '<td align="right" nowrap="nowrap">';
|
||||
print $product_static->LibStatut($objp->envente,5);
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
$var=!$var;
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td nowrap="nowrap">';
|
||||
$product_static->id=$objp->rowid;
|
||||
$product_static->ref=$objp->ref;
|
||||
$product_static->type=$objp->fk_product_type;
|
||||
print $product_static->getNomUrl(1,'',16);
|
||||
print "</td>\n";
|
||||
print '<td>'.dol_trunc($objp->label,32).'</td>';
|
||||
print "<td>";
|
||||
print dol_print_date($objp->datem,'day');
|
||||
print "</td>";
|
||||
print '<td align="right" nowrap="nowrap">';
|
||||
print $product_static->LibStatut($objp->envente,5);
|
||||
print "</td>";
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
$db->free();
|
||||
|
||||
@ -1390,13 +1390,13 @@ else
|
||||
|
||||
|
||||
|
||||
print '<table width="100%"><tr><td width="50%" valign="top">';
|
||||
print '<table width="100%"><tr><td valign="top" width="50%">';
|
||||
print '<a name="builddoc"></a>'; // 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 '</td><td>';
|
||||
|
||||
print '</td></tr>';
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
print '</table>';
|
||||
|
||||
print '<br>';
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user