Start to clean html.form class.

This commit is contained in:
Laurent Destailleur 2015-06-06 12:26:47 +02:00
parent fad44a068d
commit f42065146a
17 changed files with 126 additions and 120 deletions

View File

@ -353,7 +353,7 @@ if ($id && (empty($action) || $action == 'view'))
// Example 2 : Adding links to objects
// The class must extends CommonObject class to have this method available
//$somethingshown=$object->showLinkedObjectBlock();
//$somethingshown=$form->showLinkedObjectBlock($object);
}

View File

@ -102,7 +102,7 @@ print "</tr>\n";
$var=!$var;
print '<tr '.$bc[$var].'><td width=\"50%\">'.$langs->trans("CashDeskThirdPartyForSell").'</td>';
print '<td colspan="2">';
print $form->select_thirdparty($conf->global->CASHDESK_ID_THIRDPARTY,'socid','s.client in (1,3)',0,array(),1);
print $form->select_company($conf->global->CASHDESK_ID_THIRDPARTY,'socid','s.client in (1,3)',1,0,1,array(),0);
print '</td></tr>';
if (! empty($conf->banque->enabled))
{
@ -133,17 +133,17 @@ if (! empty($conf->stock->enabled))
if (empty($conf->productbatch->enabled)) {
print $form->selectyesno('CASHDESK_NO_DECREASE_STOCK',$conf->global->CASHDESK_NO_DECREASE_STOCK,1);
}
else
else
{
if (!$conf->global->CASHDESK_NO_DECREASE_STOCK) {
$res = dolibarr_set_const($db,"CASHDESK_NO_DECREASE_STOCK",1,'chaine',0,'',$conf->entity);
}
print $langs->trans('StockDecreaseForPointOfSaleDisabledbyBatch');
print $langs->trans('StockDecreaseForPointOfSaleDisabledbyBatch');
}
print '</td></tr>';
$disabled=$conf->global->CASHDESK_NO_DECREASE_STOCK;
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("CashDeskIdWareHouse").'</td>'; // Force warehouse (this is not a default value)
print '<td colspan="2">';

View File

@ -1712,7 +1712,7 @@ if ($action == 'create')
/*
* Linked object block
*/
$somethingshown = $object->showLinkedObjectBlock();
$somethingshown = $form->showLinkedObjectBlock($object);
print '</div><div class="fichehalfright"><div class="ficheaddleft">';

View File

@ -2310,7 +2310,7 @@ if ($action == 'create')
/*
* Linked object block
*/
$somethingshown = $object->showLinkedObjectBlock();
$somethingshown = $form->showLinkedObjectBlock($object);
print '</div><div class="fichehalfright"><div class="ficheaddleft">';
// print '</td><td valign="top" width="50%">';

View File

@ -2308,7 +2308,7 @@ if ($action == 'create' && $user->rights->commande->creer)
/*
* Linked object block
*/
$somethingshown = $object->showLinkedObjectBlock();
$somethingshown = $form->showLinkedObjectBlock($object);
print '</div><div class="fichehalfright"><div class="ficheaddleft">';
// print '</td><td valign="top" width="50%">';

View File

@ -3776,7 +3776,7 @@ if ($action == 'create')
$somethingshown = $formfile->numoffiles;
// Linked object block
$somethingshown = $object->showLinkedObjectBlock();
$somethingshown = $form->showLinkedObjectBlock($object);
$linktoelem='';

View File

@ -1874,7 +1874,7 @@ else
/*
* Linked object block
*/
$somethingshown=$object->showLinkedObjectBlock();
$somethingshown=$form->showLinkedObjectBlock($object);
print '</div><div class="fichehalfright"><div class="ficheaddleft">';

View File

@ -135,8 +135,8 @@ abstract class CommonObject
$sql = "SELECT rowid, ref, ref_ext";
$sql.= " FROM ".MAIN_DB_PREFIX.$element;
$sql.= " WHERE entity IN (".getEntity($element).")" ;
$sql.= " WHERE entity IN (".getEntity($element).")" ;
if ($id > 0) $sql.= " AND rowid = ".$db->escape($id);
else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'";
else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'";
@ -2580,88 +2580,19 @@ abstract class CommonObject
// TODO: All functions here must be redesigned and moved as they are not business functions but output functions
// --------------------
/* This is to show linked object block */
/**
* Show linked object block
* TODO Move this into html.class.php
* But for the moment we don't know if it's possible as we keep a method available on overloaded objects.
* Show linked object block.
*
* @return int
* @return int <0 if KO, >0 if OK
* @deprecated Use instead $form->shoLinkedObjectBlock($object)
*/
function showLinkedObjectBlock()
{
global $conf,$langs,$hookmanager;
global $bc;
$this->fetchObjectLinked();
// Bypass the default method
$hookmanager->initHooks(array('commonobject'));
$parameters=array();
$reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$this,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
$num = count($this->linkedObjects);
foreach($this->linkedObjects as $objecttype => $objects)
{
$tplpath = $element = $subelement = $objecttype;
if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
{
$element = $regs[1];
$subelement = $regs[2];
$tplpath = $element.'/'.$subelement;
}
// To work with non standard path
if ($objecttype == 'facture') {
$tplpath = 'compta/'.$element;
if (empty($conf->facture->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'propal') {
$tplpath = 'comm/'.$element;
if (empty($conf->propal->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'askpricesupplier') {
$tplpath = 'comm/'.$element;
if (empty($conf->askpricesupplier->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'shipping' || $objecttype == 'shipment') {
$tplpath = 'expedition';
if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'delivery') {
$tplpath = 'livraison';
if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'invoice_supplier') {
$tplpath = 'fourn/facture';
}
else if ($objecttype == 'order_supplier') {
$tplpath = 'fourn/commande';
}
global $linkedObjectBlock;
$linkedObjectBlock = $objects;
// Output template part (modules that overwrite templates must declare this into descriptor)
$dirtpls=array_merge($conf->modules_parts['tpl'],array('/'.$tplpath.'/tpl'));
foreach($dirtpls as $reldir)
{
$res=@include dol_buildpath($reldir.'/linkedobjectblock.tpl.php');
if ($res) break;
}
}
return $num;
}
global $form;
return $form->showLinkedObjectBlock($this);
}
/* This is to show add lines */
/**

View File

@ -803,11 +803,28 @@ class Form
* @param array $ajaxoptions Options for ajax_autocompleter
* @param int $forcecombo Force to use combo box
* @return string Return select box for thirdparty.
* @deprecated Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0)
*/
function select_thirdparty($selected='', $htmlname='socid', $filter='', $limit=20, $ajaxoptions=array(), $forcecombo=0)
{
global $langs,$conf;
return $this->select_thirdparty_list($selected,$htmlname,$filter,1,0,$forcecombo,array(),'',0,$limit);
}
/**
* Output html form to select a third party
*
* @param string $selected Preselected type
* @param string $htmlname Name of field in form
* @param string $filter optional filters criteras (example: 's.rowid <> x')
* @param int $showempty Add an empty field
* @param int $showtype Show third party type in combolist (customer, prospect or supplier)
* @param int $forcecombo Force to use combo box
* @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param int $limit Maximum number of elements
* @return string HTML string with select box for thirdparty.
*/
function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0)
{
$out='';
/* TODO Use ajax_autocompleter like for products (not finished)
@ -840,32 +857,12 @@ class Form
}
else
{*/
$out.=$this->select_thirdparty_list($selected,$htmlname,$filter,1,0,$forcecombo,array(),'',0,$limit);
$out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit);
//}
return $out;
}
/**
* Output html form to select a third party
*
* @param string $selected Preselected type
* @param string $htmlname Name of field in form
* @param string $filter optional filters criteras (example: 's.rowid <> x')
* @param int $showempty Add an empty field
* @param int $showtype Show third party type in combolist (customer, prospect or supplier)
* @param int $forcecombo Force to use combo box
* @param array $events Event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param int $limit Maximum number of elements
* @return string HTML string with
* @deprecated Use select_thirdparty instead
* @see select_thirdparty()
*/
function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0)
{
return $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit);
}
/**
* Output html form to select a third party
*
@ -4620,6 +4617,84 @@ class Form
}
/**
* Show linked object block.
*
* @param CommonObject $object Object we want to show links to
* @return int <0 if KO, >0 if OK
*/
function showLinkedObjectBlock($object)
{
global $conf,$langs,$hookmanager;
global $bc;
$object->fetchObjectLinked();
// Bypass the default method
$hookmanager->initHooks(array('commonobject'));
$parameters=array();
$reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
$num = count($object->linkedObjects);
foreach($object->linkedObjects as $objecttype => $objects)
{
$tplpath = $element = $subelement = $objecttype;
if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
{
$element = $regs[1];
$subelement = $regs[2];
$tplpath = $element.'/'.$subelement;
}
// To work with non standard path
if ($objecttype == 'facture') {
$tplpath = 'compta/'.$element;
if (empty($conf->facture->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'propal') {
$tplpath = 'comm/'.$element;
if (empty($conf->propal->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'askpricesupplier') {
$tplpath = 'comm/'.$element;
if (empty($conf->askpricesupplier->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'shipping' || $objecttype == 'shipment') {
$tplpath = 'expedition';
if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'delivery') {
$tplpath = 'livraison';
if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled
}
else if ($objecttype == 'invoice_supplier') {
$tplpath = 'fourn/facture';
}
else if ($objecttype == 'order_supplier') {
$tplpath = 'fourn/commande';
}
global $linkedObjectBlock;
$linkedObjectBlock = $objects;
// Output template part (modules that overwrite templates must declare this into descriptor)
$dirtpls=array_merge($conf->modules_parts['tpl'],array('/'.$tplpath.'/tpl'));
foreach($dirtpls as $reldir)
{
$res=@include dol_buildpath($reldir.'/linkedobjectblock.tpl.php');
if ($res) break;
}
}
return $num;
}
}
/**
* Return an html string with a select combo box to choose yes or no
*

View File

@ -103,7 +103,7 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh
print '<td class="nowrap" style="padding-bottom: 2px; padding-right: 4px;">';
print $langs->trans("ThirdParty").' &nbsp; ';
print '</td><td class="nowrap maxwidthonsmartphone" style="padding-bottom: 2px;">';
print $form->select_thirdparty($socid, 'socid');
print $form->select_company($socid, 'socid');
print '</td></tr>';
}

View File

@ -1505,7 +1505,7 @@ else if ($id || $ref)
/*
* Linked object block
*/
$somethingshown=$object->showLinkedObjectBlock();
$somethingshown=$form->showLinkedObjectBlock($object);
if ($genallowed && ! $somethingshown) $somethingshown=1;

View File

@ -1019,7 +1019,7 @@ if ($action == 'create')
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
dol_fiche_head('');
print '<table class="border" width="100%">';
print '<input type="hidden" name="socid" value='.$soc->id.'>';
@ -1125,7 +1125,7 @@ if ($action == 'create')
}
dol_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
print '</div>';
@ -1135,7 +1135,7 @@ if ($action == 'create')
else
{
dol_fiche_head('');
print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
print '<table class="border" width="100%">';
print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
@ -1144,7 +1144,7 @@ if ($action == 'create')
print '</table>';
dol_fiche_end();
print '<div class="center">';
print '<input type="hidden" name="action" value="create">';
print '<input type="submit" class="button" value="'.$langs->trans("CreateDraftIntervention").'">';
@ -1722,7 +1722,7 @@ else if ($id > 0 || ! empty($ref))
/*
* Linked object block
*/
$somethingshown=$object->showLinkedObjectBlock();
$somethingshown=$form->showLinkedObjectBlock($object);
//print '</td><td valign="top" width="50%">';
print '</div><div class="fichehalfright"><div class="ficheaddleft">';

View File

@ -2766,7 +2766,7 @@ elseif (! empty($object->id))
/*
* Linked object block
*/
$somethingshown=$object->showLinkedObjectBlock();
$somethingshown=$form->showLinkedObjectBlock($object);
print '</div><div class="fichehalfright"><div class="ficheaddleft">';

View File

@ -2415,7 +2415,7 @@ else
/*
* Linked object block
*/
$somethingshown=$object->showLinkedObjectBlock();
$somethingshown=$form->showLinkedObjectBlock($object);
$linktoelem='';

View File

@ -788,7 +788,7 @@ else
$shipment = new Expedition($db);
$shipment->fetch($object->origin_id);
$somethingshown=$shipment->showLinkedObjectBlock();
$somethingshown=$form->showLinkedObjectBlock($shipment);
}
if ($genallowed && ! $somethingshown) $somethingshown=1;

View File

@ -75,7 +75,7 @@ print '<br><br>'."\n";
// Test4d: form->select_thirdparty
print "Test 4d: Select thirdparty<br>\n";
print $form->select_thirdparty(0,'thirdpartytest');
print $form->select_company(0,'thirdpartytest');
print '<br><br>'."\n";

View File

@ -1849,7 +1849,7 @@ else
'name' => 'soc_origin',
'label' => $langs->trans('MergeOriginThirdparty'),
'type' => 'other',
'value' => $form->select_thirdparty('', 'soc_origin', 's.rowid != '.$object->id)
'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id)
)
);