NEW Removed unused FormOrder::selectSourcesCommande function

Also refactored select functions to avoid using HTML and encourage using Form::selectarray function
This commit is contained in:
Marcos García de La Fuente 2016-04-16 21:33:23 +02:00
parent 3722fc1014
commit 863efcbc5d
7 changed files with 91 additions and 200 deletions

View File

@ -300,17 +300,17 @@ class dolReceiptPrinter extends Escpos
function selectTypePrinter($selected='', $htmlname='printertypeid')
{
global $langs;
$error = 0;
$html = '<select class="flat" name="'.$htmlname.'">';
$html.= '<option value="1" '.($selected==1?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_DUMMY').'</option>';
$html.= '<option value="2" '.($selected==2?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_FILE_PRINT').'</option>';
$html.= '<option value="3" '.($selected==3?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_NETWORK_PRINT').'</option>';
$html.= '<option value="4" '.($selected==4?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_WINDOWS_PRINT').'</option>';
//$html.= '<option value="5" '.($selected==5?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_JAVA').'</option>';
$html.= '</select>';
$this->resprint = $html;
return $error;
$options = array(
1 => $langs->trans('CONNECTOR_DUMMY'),
2 => $langs->trans('CONNECTOR_FILE_PRINT'),
3 => $langs->trans('CONNECTOR_NETWORK_PRINT'),
4 => $langs->trans('CONNECTOR_WINDOWS_PRINT')
);
$this->resprint = Form::selectarray($htmlname, $options, $selected);
return 0;
}
@ -324,17 +324,17 @@ class dolReceiptPrinter extends Escpos
function selectProfilePrinter($selected='', $htmlname='printerprofileid')
{
global $langs;
$error = 0;
$html = '<select class="flat" name="'.$htmlname.'">';
$html.= '<option value="0" '.($selected==0?'selected="selected"':'').'>'.$langs->trans('PROFILE_DEFAULT').'</option>';
$html.= '<option value="1" '.($selected==1?'selected="selected"':'').'>'.$langs->trans('PROFILE_SIMPLE').'</option>';
$html.= '<option value="2" '.($selected==2?'selected="selected"':'').'>'.$langs->trans('PROFILE_EPOSTEP').'</option>';
$html.= '<option value="3" '.($selected==3?'selected="selected"':'').'>'.$langs->trans('PROFILE_P822D').'</option>';
$html.= '<option value="4" '.($selected==4?'selected="selected"':'').'>'.$langs->trans('PROFILE_STAR').'</option>';
$html.= '</select>';
$this->profileresprint = $html;
return $error;
$options = array(
0 => $langs->trans('PROFILE_DEFAULT'),
1 => $langs->trans('PROFILE_SIMPLE'),
2 => $langs->trans('PROFILE_EPOSTEP'),
3 => $langs->trans('PROFILE_P822D'),
4 => $langs->trans('PROFILE_STAR')
);
$this->profileresprint = Form::selectarray($htmlname, $options, $selected);
return 0;
}

View File

@ -146,9 +146,6 @@ class FormCompany
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
print '<tr><td>';
print '<select class="flat" name="'.$htmlname.'">';
if ($empty) print '<option value="">&nbsp;</option>';
dol_syslog(get_class($this).'::form_prospect_level',LOG_DEBUG);
$sql = "SELECT code, label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
@ -157,25 +154,25 @@ class FormCompany
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$options = array();
print '<option value="'.$obj->code.'"';
if ($selected == $obj->code) print ' selected';
print '>';
$level=$langs->trans($obj->code);
if ($level == $obj->code) $level=$langs->trans($obj->label);
print $level;
print '</option>';
$i++;
if ($empty) {
$options[''] = '';
}
while ($obj = $this->db->fetch_object($resql)) {
$level = $langs->trans($obj->code);
if ($level == $obj->code) {
$level = $langs->trans($obj->label);
}
$options[$obj->code] = $level;
}
print Form::selectarray($htmlname, $options, $selected);
}
else dol_print_error($this->db);
print '</select>';
print '</td>';
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';

View File

@ -27,22 +27,8 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
*/
class FormMailing extends Form
{
public $db;
public $error;
public $errors=array();
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $db;
return 1;
}
/**
* Output a select with destinaries status
*
@ -59,26 +45,14 @@ class FormMailing extends Form
require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
$mailing = new Mailing($this->db);
$array = $mailing->statut_dest;
//Cannot use form->selectarray because empty value is defaulted to -1 in this method and we use here status -1...
$out = '<select name="'.$htmlname.'" class="flat">';
$options = array();
if ($show_empty) {
$out .= '<option value=""></option>';
$options[''] = '';
}
foreach($mailing->statut_dest as $id=>$status) {
if ($selectedid==$id) {
$selected=" selected ";
}else {
$selected="";
}
$out .= '<option '.$selected.' value="'.$id.'">'.$langs->trans($status).'</option>';
}
$options = array_merge($options, $mailing->statut_dest);
$out .= '</select>';
return $out;
return Form::selectarray($htmlname, $options, $selectedid, 0, 0, 0, '', 1);
}
}

View File

@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
*
* 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
@ -21,29 +22,14 @@
* \brief File of predefined functions for HTML forms for order module
*/
require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
/**
* Class to manage HTML output components for orders
* Before adding component here, check they are not into common part Form.class.php
*/
class FormOrder
class FormOrder extends Form
{
var $db;
var $error;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $db;
return 1;
}
/**
* Return combo list of differents status of a orders
@ -53,51 +39,32 @@ class FormOrder
* @param string $hmlname Name of HTML select element
* @return void
*/
function selectSupplierOrderStatus($selected='', $short=0, $hmlname='order_status')
public function selectSupplierOrderStatus($selected='', $short=0, $hmlname='order_status')
{
$tmpsupplierorder=new CommandeFournisseur($db);
print '<select class="flat" name="'.$hmlname.'">';
print '<option value="-1">&nbsp;</option>';
$statustohow=array('0'=>'0','1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5','6'=>'6,7','9'=>'9'); // 7 is same label than 6. 8 does not exists (billed is another field)
$options = array();
foreach($statustohow as $key => $value)
{
print '<option value="'.$value.'"'.(($selected == $key || $selected == $value)?' selected':'').'>';
$tmpsupplierorder->statut=$key;
print $tmpsupplierorder->getLibStatut($short);
print '</option>';
}
print '</select>';
// 7 is same label than 6. 8 does not exists (billed is another field)
$statustohow = array(
'0' => '0',
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6,7',
'9' => '9'
);
$tmpsupplierorder = new CommandeFournisseur($this->db);
foreach ($statustohow as $key => $value) {
$tmpsupplierorder->statut = $key;
$options[$value] = $tmpsupplierorder->getLibStatut($short);
}
print Form::selectarray($hmlname, $options, $selected, 1);
}
/**
* Return list of way to order
*
* @param string $selected Id of preselected order origin
* @param string $htmlname Name of HTML select list
* @param int $addempty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
* @return array Tableau des sources de commandes
*/
function selectSourcesCommande($selected='',$htmlname='source_id',$addempty=0)
{
global $conf,$langs;
print '<select class="flat" name="'.$htmlname.'">';
if ($addempty) print '<option value="-1" selected>&nbsp;</option>';
// TODO Use the table called llx_c_input_reason
print '<option value="0"'.($selected=='0'?' selected':'').'>'.$langs->trans('OrderSource0').'</option>';
print '<option value="1"'.($selected=='1'?' selected':'').'>'.$langs->trans('OrderSource1').'</option>';
print '<option value="2"'.($selected=='2'?' selected':'').'>'.$langs->trans('OrderSource2').'</option>';
print '<option value="3"'.($selected=='3'?' selected':'').'>'.$langs->trans('OrderSource3').'</option>';
print '<option value="4"'.($selected=='4'?' selected':'').'>'.$langs->trans('OrderSource4').'</option>';
print '<option value="5"'.($selected=='5'?' selected':'').'>'.$langs->trans('OrderSource5').'</option>';
print '<option value="6"'.($selected=='6'?' selected':'').'>'.$langs->trans('OrderSource6').'</option>';
print '</select>';
}
/**
* Return list of input method (mode used to receive order, like order received by email, fax, online)
* List found into table c_input_method.
@ -107,11 +74,9 @@ class FormOrder
* @param int $addempty 0=list with no empty value, 1=list with empty value
* @return array Tableau des sources de commandes
*/
function selectInputMethod($selected='',$htmlname='source_id',$addempty=0)
public function selectInputMethod($selected='',$htmlname='source_id',$addempty=0)
{
global $conf,$langs,$form;
if (! is_object($form)) $form=new Form($this->db);
global $langs;
$listofmethods=array();
@ -121,24 +86,18 @@ class FormOrder
dol_syslog(get_class($this)."::selectInputMethod", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$i = 0;
$num = $this->db->num_rows($resql);
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$listofmethods[$obj->rowid] = $langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):$obj->label;
$i++;
}
}
else
{
if (!$resql) {
dol_print_error($this->db);
return -1;
}
print $form->selectarray($htmlname,$listofmethods,$selected,$addempty);
while ($obj = $this->db->fetch_object($resql)) {
$listofmethods[$obj->rowid] = $langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : $obj->label;
}
print Form::selectarray($htmlname,$listofmethods,$selected,$addempty);
return 1;
}

View File

@ -236,6 +236,12 @@ print '<td>'.$langs->trans('ForceBuyingPriceIfNullDetails').'</td>';
print '</tr>';
// GLOBAL DISCOUNT MANAGEMENT
$methods = array(
1 => $langs->trans('UseDiscountAsProduct'),
2 => $langs->trans('UseDiscountAsService'),
3 => $langs->trans('UseDiscountOnTotal')
);
$var=!$var;
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -243,20 +249,7 @@ print "<input type=\"hidden\" name=\"action\" value=\"remises\">";
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("MARGIN_METHODE_FOR_DISCOUNT").'</td>';
print '<td align="left">';
print '<select name="MARGIN_METHODE_FOR_DISCOUNT" class="flat">';
print '<option value="1" ';
if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1')
print 'selected ';
print '>'.$langs->trans('UseDiscountAsProduct').'</option>';
print '<option value="2" ';
if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2')
print 'selected ';
print '>'.$langs->trans('UseDiscountAsService').'</option>';
print '<option value="3" ';
if (isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT) && $conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3')
print 'selected ';
print '>'.$langs->trans('UseDiscountOnTotal').'</option>';
print '</select>';
print Form::selectarray('MARGIN_METHODE_FOR_DISCOUNT', $methods, $conf->global->MARGIN_METHODE_FOR_DISCOUNT);
print '</td>';
print '<td>';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';

View File

@ -262,43 +262,11 @@ if ($object->id)
print '<tr class="liste_titre"><td>';
$delauft_lang = (empty($lang_id)) ? $langs->getDefaultLang() : $lang_id;
$delauft_lang = empty($lang_id) ? $langs->getDefaultLang() : $lang_id;
$langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12);
print '<select class="flat" id="lang_id" name="lang_id">';
asort($langs_available);
$uncompletelanguages = array (
'da_DA',
'fi_FI',
'hu_HU',
'is_IS',
'pl_PL',
'ro_RO',
'ru_RU',
'sv_SV',
'tr_TR',
'zh_CN'
);
foreach ( $langs_available as $key => $value )
{
if ($showwarning && in_array($key, $uncompletelanguages))
{
// $value.=' - '.$langs->trans("TranslationUncomplete",$key);
}
if ($filter && is_array($filter)) {
if (! array_key_exists($key, $filter)) {
print '<option value="' . $key . '">' . $value . '</option>';
}
} else if ($delauft_lang == $key) {
print '<option value="' . $key . '" selected>' . $value . '</option>';
} else {
print '<option value="' . $key . '">' . $value . '</option>';
}
}
print '</select>';
print Form::selectarray('lang_id', $langs_available, $delauft_lang, 0, 0, 0, '', 0, 0, 0, 'ASC');
if ($conf->global->MAIN_MULTILANGS) {
print '<input type="submit" class="button" name="refresh" value="' . $langs->trans('Refresh') . '">';

View File

@ -439,12 +439,12 @@ abstract class ActionsCardCommon
if ($modCodeClient->code_auto) $this->tpl['prefix_customercode'] = $modCodeClient->verif_prefixIsUsed();
// TODO create a function
$this->tpl['select_customertype'] = '<select class="flat" name="client">';
$this->tpl['select_customertype'].= '<option value="2"'.($this->object->client==2?' selected':'').'>'.$langs->trans('Prospect').'</option>';
$this->tpl['select_customertype'].= '<option value="3"'.($this->object->client==3?' selected':'').'>'.$langs->trans('ProspectCustomer').'</option>';
$this->tpl['select_customertype'].= '<option value="1"'.($this->object->client==1?' selected':'').'>'.$langs->trans('Customer').'</option>';
$this->tpl['select_customertype'].= '<option value="0"'.($this->object->client==0?' selected':'').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
$this->tpl['select_customertype'].= '</select>';
$this->tpl['select_customertype'] = Form::selectarray('client', array(
0 => $langs->trans('NorProspectNorCustomer'),
1 => $langs->trans('Customer'),
2 => $langs->trans('Prospect'),
3 => $langs->trans('ProspectCustomer')
), $this->object->client);
// Customer
$this->tpl['customercode'] = $this->object->code_client;