some fix for contract model and clean code

This commit is contained in:
Grand Philippe 2013-08-26 14:29:46 +02:00
parent 67892575be
commit 7a64ad1a26
4 changed files with 184 additions and 181 deletions

View File

@ -190,23 +190,6 @@ else if ($action == 'set_CONTRAT_DRAFT_WATERMARK')
} }
} }
elseif ($action == 'set_CONTRAT_PRINT_PRODUCTS')
{
$val = GETPOST('CONTRAT_PRINT_PRODUCTS','alpha');
$res = dolibarr_set_const($db, "CONTRAT_PRINT_PRODUCTS",($val == 'on'),'bool',0,'',$conf->entity);
if (! $res > 0) $error++;
if (! $error)
{
setEventMessage($langs->trans("SetupSaved"));
}
else
{
setEventMessage($langs->trans("Error"),'errors');
}
}
/* /*
* View * View
*/ */
@ -215,7 +198,6 @@ $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
llxHeader(); llxHeader();
$dir=DOL_DOCUMENT_ROOT."/core/modules/contract/";
$form=new Form($db); $form=new Form($db);
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>'; $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
@ -244,10 +226,15 @@ print "</tr>\n";
clearstatcache(); clearstatcache();
$dir = "../core/modules/contract/"; foreach ($dirmodels as $reldir)
$handle = opendir($dir);
if (is_resource($handle))
{ {
$dir = dol_buildpath($reldir."core/modules/contract/");
if (is_dir($dir))
{
$handle = opendir($dir);
if (is_resource($handle))
{
$var=true; $var=true;
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
@ -256,9 +243,9 @@ if (is_resource($handle))
{ {
$file = substr($file, 0, dol_strlen($file)-4); $file = substr($file, 0, dol_strlen($file)-4);
require_once DOL_DOCUMENT_ROOT ."/core/modules/contract/".$file.'.php'; require_once $dir.$file.'.php';
$module = new $file; $module = new $file($db);
// Show modules according to features level // Show modules according to features level
if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
@ -267,8 +254,7 @@ if (is_resource($handle))
if ($module->isEnabled()) if ($module->isEnabled())
{ {
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$module->nom."</td>\n"; print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
print '<td>';
print $module->info(); print $module->info();
print '</td>'; print '</td>';
@ -287,7 +273,7 @@ if (is_resource($handle))
} }
else else
{ {
print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
print img_picto($langs->trans("Disabled"),'switch_off'); print img_picto($langs->trans("Disabled"),'switch_off');
print '</a>'; print '</a>';
} }
@ -322,6 +308,8 @@ if (is_resource($handle))
} }
} }
closedir($handle); closedir($handle);
}
}
} }
print '</table><br>'; print '</table><br>';
@ -372,7 +360,9 @@ clearstatcache();
$var=true; $var=true;
foreach ($dirmodels as $reldir) foreach ($dirmodels as $reldir)
{ {
$dir = dol_buildpath($reldir."core/modules/contract/doc/"); foreach (array('','/doc') as $valdir)
{
$dir = dol_buildpath($reldir."core/modules/contract".$valdir);
if (is_dir($dir)) if (is_dir($dir))
{ {
@ -381,73 +371,103 @@ foreach ($dirmodels as $reldir)
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,4) == 'pdf_') $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); $name = substr($file, 4, dol_strlen($file) -16);
$classname = substr($file, 0, dol_strlen($file) -12); $classname = substr($file, 0, dol_strlen($file) -12);
$var=!$var; require_once $dir.'/'.$file;
print '<tr '.$bc[$var].'><td>';
echo "$name";
print "</td><td>\n";
require_once $dir.$file;
$module = new $classname($db); $module = new $classname($db);
print $module->description;
$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>'; print '</td>';
// Active // Active
if (in_array($name, $def)) if (in_array($name, $def))
{ {
print "<td align=\"center\">\n"; print '<td align="center">'."\n";
print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&value='.$name.'">';
print img_picto($langs->trans("Enabled"),'switch_on'); print img_picto($langs->trans("Enabled"),'switch_on');
print '</a>'; print '</a>';
print "</td>"; print '</td>';
} }
else else
{ {
print "<td align=\"center\">\n"; 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 '<a href="'.$_SERVER["PHP_SELF"].'?action=set&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
print "</td>"; print "</td>";
} }
// Default // Defaut
print "<td align=\"center\">"; print '<td align="center">';
if ($conf->global->CONTRACT_ADDON_PDF == "$name") if ($conf->global->CONTRACT_ADDON_PDF == $name)
{ {
print img_picto($langs->trans("Default"),'on'); print img_picto($langs->trans("Default"),'on');
} }
else 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 '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
} }
print '</td>'; print '</td>';
// Info // Info
$htmltooltip = ''.$langs->trans("Name").': '.$module->name; $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
$htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown")); $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>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
}
$htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>'; $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
$htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1); $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("PaymentMode").': '.yn($module->option_modereg,1,1);
$htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,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("MultiLanguage").': '.yn($module->option_multilang,1,1);
$htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1); $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
print '<td align="center">'; print '<td align="center">';
print $form->textwithpicto('',$htmltooltip,-1,0); print $form->textwithpicto('',$htmltooltip,1,0);
print '</td>'; print '</td>';
// Preview // Preview
$link='<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'contract').'</a>';
print '<td align="center">'; print '<td align="center">';
print $link; if ($module->type == 'pdf')
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'contract').'</a>';
}
else
{
print img_object($langs->trans("PreviewNotAvailable"),'generic');
}
print '</td>'; print '</td>';
print '</tr>'; print "</tr>\n";
}
}
}
} }
} }
closedir($handle);
} }
} }
} }
@ -492,25 +512,8 @@ print '<input size="50" class="flat" type="text" name="CONTRAT_DRAFT_WATERMARK"
print '</td><td align="right">'; print '</td><td align="right">';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print "</td></tr>\n"; print "</td></tr>\n";
// print products on fichinter
$var=! $var;
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="set_CONTRAT_PRINT_PRODUCTS">';
print '<tr '.$bc[$var].'><td>';
print $langs->trans("PrintProductsOnContract").' ('.$langs->trans("PrintProductsOnContractDetails").')</td>';
print '<td align="center"><input type="checkbox" name="CONTRAT_PRINT_PRODUCTS" ';
if ($conf->global->CONTRAT_PRINT_PRODUCTS)
print 'checked="checked" ';
print '/>';
print '</td><td align="right">';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print "</td></tr>\n";
print '</form>'; print '</form>';
print '</table>'; print '</table>';
print '<br>'; print '<br>';

View File

@ -57,7 +57,7 @@ class modContrat extends DolibarrModules
$this->picto='contract'; $this->picto='contract';
// Data directories to create when module is enabled // Data directories to create when module is enabled
$this->dirs = array("/contracts/temp"); $this->dirs = array("/contract/temp");
// Dependances // Dependances
$this->depends = array("modSociete","modService"); $this->depends = array("modSociete","modService");