Skip to content

Commit

Permalink
[ task #176 ] Allow to use ODT templates for prososal like it's done for
Browse files Browse the repository at this point in the history
invoices. Firsts works
  • Loading branch information
simnandez committed Jan 2, 2012
1 parent 1e41410 commit 2a61569
Show file tree
Hide file tree
Showing 4 changed files with 618 additions and 91 deletions.
201 changes: 110 additions & 91 deletions htdocs/admin/propale.php
Expand Up @@ -6,7 +6,7 @@
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
*
* 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
Expand Down Expand Up @@ -405,102 +405,121 @@

clearstatcache();

$var=true;
foreach ($conf->file->dol_document_root as $dirroot)
{
$dir = $dirroot . "/core/modules/propale/";

if (is_dir($dir))
{
$var=true;

$handle=opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle))!==false)
{
if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,12) == 'pdf_propale_')
{
$name = substr($file, 12, dol_strlen($file) - 24);
$classname = substr($file, 0, dol_strlen($file) -12);

$var=!$var;
print "<tr ".$bc[$var].">\n <td>";
print $name;
print "</td>\n <td>\n";
require_once($dir.$file);
$module = new $classname($db);
print $module->description;
print '</td>';

// Activate
print '<td align="center">'."\n";
if (in_array($name, $def))
{
//if ($conf->global->PROPALE_ADDON_PDF != "$name")
//{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
print img_picto($langs->trans("Activated"),'switch_on');
print '</a>';
//}
//else
//{
// print img_picto($langs->trans("Activated"),'switch_on');
//}
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
print img_picto($langs->trans("Disabled"),'switch_off');
print '</a>';
}
print "</td>";

// Default
print '<td align="center">';
if ($conf->global->PROPALE_ADDON_PDF == "$name")
{
print img_picto($langs->trans("Yes"),'on');
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
print img_picto($langs->trans("No"),'off');
print '</a>';
}
print '</td>';

// Info
$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
$htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
if ($module->type == 'pdf')
foreach (array('','/doc') as $valdir)
{
$dir = $dirroot . "/core/modules/propale".$valdir;

if (is_dir($dir))
{
$handle=opendir($dir);
if (is_resource($handle))
{
while (($file = readdir($handle))!==false)
{
$filelist[]=$file;
}
closedir($handle);

foreach($filelist as $file)
{
if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
{
$htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
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 '<tr '.$bc[$var].'><td width="100">';
print (empty($module->name)?$name:$module->name);
print "</td><td>\n";
if (method_exists($module,'info')) print $module->info($langs);
else print $module->description;
print '</td>';

// Active
if (in_array($name, $def))
{
print '<td align="center">'."\n";
print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'">';
print img_picto($langs->trans("Enabled"),'switch_on');
print '</a>';
print '</td>';
}
else
{
print "<td align=\"center\">\n";
print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
print "</td>";
}

// Defaut
print "<td align=\"center\">";
if ($conf->global->PROPALE_ADDON_PDF == "$name")
{
print img_picto($langs->trans("Default"),'on');
}
else
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
print '</td>';

// Info
$htmltooltip = ''.$langs->trans("Name").': '.$module->name;
$htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
if ($module->type == 'pdf')
{
$htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
}
$htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
$htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
$htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
$htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
$htmltooltip.='<br>'.$langs->trans("Escompte").': '.yn($module->option_escompte,1,1);
$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
$htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
$htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftInvoices").': '.yn($module->option_draft_watermark,1,1);


print '<td align="center">';
print $form->textwithpicto('',$htmltooltip,1,0);
print '</td>';

// Preview
print '<td align="center">';
if ($module->type == 'pdf')
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'bill').'</a>';
}
else
{
print img_object($langs->trans("PreviewNotAvailable"),'generic');
}
print '</td>';

print "</tr>\n";
}
}
}
$htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
$htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
$htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
$htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
$htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
//$htmltooltip.='<br>'.$langs->trans("Escompte").': '.yn($module->option_escompte,1,1);
//$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
$htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftProposal").': '.yn($module->option_draft_watermark,1,1);

print '<td align="center">';
print $form->textwithpicto('',$htmltooltip,1,0);
print '</td>';
print '<td align="center">';
print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'propal').'</a>';
print '</td>';

print "</tr>\n";
}
}
closedir($handle);
}
}
}
}
}
}
}


print '</table>';
print '<br>';

Expand Down
13 changes: 13 additions & 0 deletions htdocs/core/modules/modPropale.class.php
Expand Up @@ -4,6 +4,7 @@
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2012 Juanjo Menentr <jmenent@2byte.es>
*
* 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
Expand Down Expand Up @@ -94,6 +95,12 @@ function modPropale($DB)
$this->const[$r][3] = 'Duration of validity of business proposals';
$this->const[$r][4] = 0;
$r++;

$this->const[$r][0] = "PROPALE_ADDON_PDF_ODT_PATH";
$this->const[$r][1] = "chaine";
$this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/proposals";
$this->const[$r][3] = "";
$this->const[$r][4] = 0;

// Boxes
$this->boxes = array();
Expand Down Expand Up @@ -183,6 +190,12 @@ function init()

// Remove permissions and default values
$this->remove();

//ODT template
require_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php');
$dirodt=DOL_DATA_ROOT.'/doctemplates/proposals';
create_exdir($dirodt);
dol_copy(DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt',$dirodt.'/template_proposal.odt',0,0);

$sql = array(
"DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->const[0][2]."' AND entity = ".$conf->entity,
Expand Down

0 comments on commit 2a61569

Please sign in to comment.