From 5fd1a87ad44ddd01d4630d38121616c8b4581ae3 Mon Sep 17 00:00:00 2001
From: Regis Houssin <regis@dolibarr.fr>
Date: Wed, 8 Sep 2010 17:02:24 +0000
Subject: [PATCH] Works on module hook integration

---
 htdocs/core/class/commonobject.class.php      | 72 +++----------------
 htdocs/core/tpl/freeproductline_edit.tpl.php  | 55 ++++++++++++++
 .../tpl/predefinedproductline_edit.tpl.php    | 64 +++++++++++++++++
 .../tpl/predefinedproductline_view.tpl.php    | 24 +++----
 4 files changed, 138 insertions(+), 77 deletions(-)

diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index b08848882aa..0067889163d 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1408,6 +1408,14 @@ class CommonObject
 			{
 				$product_static = new Product($db);
 				
+				$product_static->type=$line->fk_product_type;
+				$product_static->id=$line->fk_product;
+				$product_static->ref=$line->ref;
+				$product_static->libelle=$line->product_label;
+				$text=$product_static->getNomUrl(1);
+				$text.= ' - '.$line->product_label;
+				$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description));
+				
 				include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_view.tpl.php');
 			}
 			else
@@ -1419,72 +1427,14 @@ class CommonObject
 		// Ligne en mode update
 		if ($this->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["lineid"] == $line->id)
 		{
-			print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'#'.$line->id.'" method="POST">';
-			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-			print '<input type="hidden" name="action" value="updateligne">';
-			print '<input type="hidden" name="id" value="'.$this->id.'">';
-			print '<input type="hidden" name="lineid" value="'.$_GET["lineid"].'">';
-			print '<tr '.$bc[$var].'>';
-			print '<td>';
-			print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
 			if ($line->fk_product > 0)
 			{
-				print '<input type="hidden" name="productid" value="'.$line->fk_product.'">';
-				print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$line->fk_product.'">';
-				if ($line->fk_product_type==1) print img_object($langs->trans('ShowService'),'service');
-				else print img_object($langs->trans('ShowProduct'),'product');
-				print ' '.$line->ref.'</a>';
-				print ' - '.nl2br($line->product_label);
-				print '<br>';
-			}
-			
-			// editeur wysiwyg
-            $nbrows=ROWS_2;
-            if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
-        	require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
-		  	$doleditor=new DolEditor('desc',$line->description,164,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
-			$doleditor->Create();
-
-			print '</td>';
-
-			// TODO a déplacer dans classe module marge
-			//if ($conf->global->PRODUIT_USE_MARKUP) print '<td align="right">'.vatrate($line->marge_tx).'%</td>';
-
-			print '<td align="right">';
-			print $html->select_tva('tva_tx',$line->tva_tx,$mysoc,$societe,'',$line->info_bits);
-			print '</td>';
-			print '<td align="right"><input size="6" type="text" class="flat" name="subprice" value="'.price($line->subprice,0,'',0).'"></td>';
-			print '<td align="right">';
-			if (($line->info_bits & 2) != 2)
-			{
-				print '<input size="2" type="text" class="flat" name="qty" value="'.$line->qty.'">';
+				include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_edit.tpl.php');
 			}
-			else print '&nbsp;';
-			print '</td>';
-			print '<td align="right" nowrap>';
-			if (($line->info_bits & 2) != 2)
-			{
-				print '<input size="1" type="text" class="flat" name="remise_percent" value="'.$line->remise_percent.'">%';
-			}
-			else print '&nbsp;';
-			print '</td>';
-			print '<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
-			print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
-			print '</tr>' . "\n";
-
-			// Start and end dates selector
-			if ($conf->service->enabled && $dateSelector)
+			else
 			{
-				print '<tr '.$bc[$var].'>';
-				print '<td colspan="9">'.$langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' ';
-				print $html->select_date($line->date_start,'date_start',$usehm,$usehm,$line->date_start?0:1,"updateligne");
-				print ' '.$langs->trans('to').' ';
-				print $html->select_date($line->date_end,'date_end',$usehm,$usehm,$line->date_end?0:1,"updateligne");
-				print '</td>';
-				print '</tr>';
+				include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_edit.tpl.php');
 			}
-
-			print "</form>\n";
 		}
 	}
 
diff --git a/htdocs/core/tpl/freeproductline_edit.tpl.php b/htdocs/core/tpl/freeproductline_edit.tpl.php
index 62c9fe7ed01..f3b34339a0a 100644
--- a/htdocs/core/tpl/freeproductline_edit.tpl.php
+++ b/htdocs/core/tpl/freeproductline_edit.tpl.php
@@ -21,6 +21,61 @@
 
 <!-- BEGIN PHP TEMPLATE freeproductline_edit.tpl.php -->
 
+<form action="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id.'#'.$line->id; ?>" method="POST">';
+<input type="hidden" name="token" value="<?php  echo $_SESSION['newtoken']; ?>">
+<input type="hidden" name="action" value="updateligne">
+<input type="hidden" name="id" value="<?php echo $this->id; ?>">
+<input type="hidden" name="lineid" value="<?php echo $_GET["lineid"]; ?>">
 
+<tr <?php echo $bc[$var]; ?>>
+	<td>
+	<a name="<?php echo $line->id; ?>"></a>
+	<?php
+	// editeur wysiwyg
+    $nbrows=ROWS_2;
+    if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
+    require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
+	$doleditor=new DolEditor('desc',$line->description,164,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
+	$doleditor->Create();
+	?>
+	</td>
+
+	<td align="right"><?php echo $html->select_tva('tva_tx',$line->tva_tx,$mysoc,$societe,'',$line->info_bits); ?></td>
+	
+	<td align="right"><input size="6" type="text" class="flat" name="subprice" value="<?php echo price($line->subprice,0,'',0); ?>"></td>
+	
+	<td align="right">
+	<?php if (($line->info_bits & 2) != 2) { ?>
+		<input size="2" type="text" class="flat" name="qty" value="<?php echo $line->qty; ?>">
+	<?php } else { ?>
+		&nbsp;
+	<?php } ?>
+	</td>
+	
+	<td align="right" nowrap>
+	<?php if (($line->info_bits & 2) != 2) { ?>
+		<input size="1" type="text" class="flat" name="remise_percent" value="<?php echo $line->remise_percent; ?>">%
+	<?php } else { ?>
+		&nbsp;
+	<?php } ?>
+	</td>
+	
+	<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="<?php echo $langs->trans("Save"); ?>">
+	<br><input type="submit" class="button" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>"></td>
+</tr>
+
+<?php if ($conf->service->enabled && $dateSelector)	{ ?>
+<tr <?php echo $bc[$var]; ?>>
+	<td colspan="9"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
+	<?php
+	echo $html->select_date($line->date_start,'date_start',$usehm,$usehm,$line->date_start?0:1,"updateligne");
+	echo ' '.$langs->trans('to').' ';
+	echo $html->select_date($line->date_end,'date_end',$usehm,$usehm,$line->date_end?0:1,"updateligne");
+	?>
+	</td>
+</tr>
+<?php } ?>
+
+</form>
 
 <!-- END PHP TEMPLATE freeproductline_edit.tpl.php -->
diff --git a/htdocs/core/tpl/predefinedproductline_edit.tpl.php b/htdocs/core/tpl/predefinedproductline_edit.tpl.php
index a26145ef494..a3727a1c4d8 100644
--- a/htdocs/core/tpl/predefinedproductline_edit.tpl.php
+++ b/htdocs/core/tpl/predefinedproductline_edit.tpl.php
@@ -21,6 +21,70 @@
 
 <!-- BEGIN PHP TEMPLATE predefinedproductline_edit.tpl.php -->
 
+<form action="<?php echo $_SERVER["PHP_SELF"].'?id='.$this->id.'#'.$line->id; ?>" method="POST">';
+<input type="hidden" name="token" value="<?php  echo $_SESSION['newtoken']; ?>">
+<input type="hidden" name="action" value="updateligne">
+<input type="hidden" name="id" value="<?php echo $this->id; ?>">
+<input type="hidden" name="lineid" value="<?php echo $_GET["lineid"]; ?>">
 
+<tr <?php echo $bc[$var]; ?>>
+	<td>
+	<a name="<?php echo $line->id; ?>"></a>
+	
+	<input type="hidden" name="productid" value="<?php echo $line->fk_product; ?>">
+	<a href="<?php echo DOL_URL_ROOT.'/product/fiche.php?id='.$line->fk_product; ?>">
+	<?php
+	if ($line->fk_product_type==1) echo img_object($langs->trans('ShowService'),'service');
+	else print img_object($langs->trans('ShowProduct'),'product');
+	echo ' '.$line->ref.'</a>';
+	echo ' - '.nl2br($line->product_label);
+	echo '<br>';
+
+	// editeur wysiwyg
+    $nbrows=ROWS_2;
+    if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
+    require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php");
+	$doleditor=new DolEditor('desc',$line->description,164,'dolibarr_details','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70);
+	$doleditor->Create();
+	?>
+	</td>
+
+	<td align="right"><?php echo $html->select_tva('tva_tx',$line->tva_tx,$mysoc,$societe,'',$line->info_bits); ?></td>
+	
+	<td align="right"><input size="6" type="text" class="flat" name="subprice" value="<?php echo price($line->subprice,0,'',0); ?>"></td>
+	
+	<td align="right">
+	<?php if (($line->info_bits & 2) != 2) { ?>
+		<input size="2" type="text" class="flat" name="qty" value="<?php echo $line->qty; ?>">
+	<?php } else { ?>
+		&nbsp;
+	<?php } ?>
+	</td>
+	
+	<td align="right" nowrap>
+	<?php if (($line->info_bits & 2) != 2) { ?>
+		<input size="1" type="text" class="flat" name="remise_percent" value="<?php echo $line->remise_percent; ?>">%
+	<?php } else { ?>
+		&nbsp;
+	<?php } ?>
+	</td>
+	
+	<td align="center" colspan="5" valign="center"><input type="submit" class="button" name="save" value="<?php echo $langs->trans("Save"); ?>">
+	<br><input type="submit" class="button" name="cancel" value="<?php echo $langs->trans("Cancel"); ?>"></td>
+</tr>
+
+<?php if ($conf->service->enabled && $dateSelector)	{ ?>
+<tr <?php echo $bc[$var]; ?>>
+	<td colspan="9"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
+	<?php
+	echo $html->select_date($line->date_start,'date_start',$usehm,$usehm,$line->date_start?0:1,"updateligne");
+	echo ' '.$langs->trans('to').' ';
+	echo $html->select_date($line->date_end,'date_end',$usehm,$usehm,$line->date_end?0:1,"updateligne");
+	?>
+	</td>
+</tr>
+<?php } ?>
+
+</form>
 
 <!-- END PHP TEMPLATE predefinedproductline_edit.tpl.php -->
diff --git a/htdocs/core/tpl/predefinedproductline_view.tpl.php b/htdocs/core/tpl/predefinedproductline_view.tpl.php
index bb085dad6eb..452d030e9f7 100644
--- a/htdocs/core/tpl/predefinedproductline_view.tpl.php
+++ b/htdocs/core/tpl/predefinedproductline_view.tpl.php
@@ -25,24 +25,16 @@
 	<td>
 	<a name="<?php echo $line->id; ?>"></a>
 	<?php
-		// Show product and description
-		$product_static->type=$line->fk_product_type;
-		$product_static->id=$line->fk_product;
-		$product_static->ref=$line->ref;
-		$product_static->libelle=$line->product_label;
-		$text=$product_static->getNomUrl(1);
-		$text.= ' - '.$line->product_label;
-		$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description));
-		echo $html->textwithtooltip($text,$description,3,'','',$i);
+	echo $html->textwithtooltip($text,$description,3,'','',$i);
 
-		// Show range
-		print_date_range($line->date_start, $line->date_end);
+	// Show range
+	print_date_range($line->date_start, $line->date_end);
 
-		// Add description in form
-		if ($conf->global->PRODUIT_DESC_IN_FORM)
-		{
-			print ($line->description && $line->description!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->description):'';
-		}
+	// Add description in form
+	if ($conf->global->PRODUIT_DESC_IN_FORM)
+	{
+		print ($line->description && $line->description!=$line->product_label)?'<br>'.dol_htmlentitiesbr($line->description):'';
+	}
 	?>
 	</td>
 
-- 
GitLab