Perf: Avoid to isntantiate object 'form' into 'subform' classes when

already available.
Qual: Better information into xdebug page.
This commit is contained in:
Laurent Destailleur 2014-05-01 16:26:57 +02:00
parent ee6cac8294
commit b56f59b313
11 changed files with 59 additions and 44 deletions

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2009-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -53,13 +53,27 @@ if (function_exists('socket_create'))
$port = ini_get('xdebug.remote_port')?ini_get('xdebug.remote_port'):9000; $port = ini_get('xdebug.remote_port')?ini_get('xdebug.remote_port'):9000;
print "<strong>Current xdebug setup:</strong><br>\n"; print "<strong>Current xdebug setup:</strong><br>\n";
print "* Remote debug setup:<br>\n";
print 'xdebug.remote_enable = '.ini_get('xdebug.remote_enable')."<br>\n";
print 'xdebug.remote_host = '.$address."<br>\n"; print 'xdebug.remote_host = '.$address."<br>\n";
print 'xdebug.remote_port = '.$port."<br>\n"; print 'xdebug.remote_port = '.$port."<br>\n";
print 'xdebug.profiler_output_dir = '.ini_get('xdebug.profiler_output_dir')."<br>\n"; print "* Profiler setup ";
if (function_exists('xdebug_get_profiler_filename')) print xdebug_get_profiler_filename()?"(currently on into file ".xdebug_get_profiler_filename().")":"(currently off)";
else print "(currenlty not available)";
print ":<br>\n";
print 'xdebug.profiler_enable = '.ini_get('xdebug.profiler_enable')."<br>\n"; print 'xdebug.profiler_enable = '.ini_get('xdebug.profiler_enable')."<br>\n";
print 'xdebug.profiler_enable_trigger = '.ini_get('xdebug.profiler_enable_trigger')."<br>\n"; print 'xdebug.profiler_enable_trigger = '.ini_get('xdebug.profiler_enable_trigger')."<br>\n";
print 'xdebug.profiler_output_dir = '.ini_get('xdebug.profiler_output_dir')."<br>\n";
print 'xdebug.profiler_output_name = '.ini_get('xdebug.profiler_output_name')."<br>\n";
print 'xdebug.profiler_append = '.ini_get('xdebug.profiler_append')."<br>\n";
print "<br>\n"; print "<br>\n";
echo "To run a debug session, add parameter<br>";
echo "* XDEBUG_SESSION_START=aname on your URL. To stop, remove cookie XDEBUG_SESSION_START.<br>\n";
echo "To run a profiler session (when xdebug.profiler_enable_trigger=1), add parameter<br>\n";
echo "* XDEBUG_PROFILE=aname on each URL.<br>";
print "<br>";
print "<strong>Test debugger server (Eclipse for example):</strong><br>\n"; print "<strong>Test debugger server (Eclipse for example):</strong><br>\n";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (empty($socket)) die('Unable to prepare a socket'); if (empty($socket)) die('Unable to prepare a socket');
@ -94,7 +108,6 @@ xdebug.auto_trace=0
XDebug with same port than in php.ini<br> XDebug with same port than in php.ini<br>
Allow Remote debug=yes or prompt<br>'."\n"; Allow Remote debug=yes or prompt<br>'."\n";
print "<br>\n"; print "<br>\n";
echo "Then, to run a debug session (when xdebug.profiler_enable_trigger=1), add parameter XDEBUG_SESSION_START=aname on your URL. To stop, remove cookie XDEBUG_SESSION_START.\n";
} }
else else
{ {

View File

@ -195,9 +195,8 @@ $langs->load("cashdesk");
<tr> <tr>
<td> <td>
<input class="bouton_mode_reglement" type="submit" name="btnModeReglement" value="<?php echo $langs->trans("Reported"); ?>" onclick="javascript: verifClic('DIF');" /> <input class="bouton_mode_reglement" type="submit" name="btnModeReglement" value="<?php echo $langs->trans("Reported"); ?>" onclick="javascript: verifClic('DIF');" />
<?php echo $langs->trans("DateEcheance"); ?> :
<?php <?php
$form=new Form($db); echo $langs->trans("DateEcheance").' :';
print $form->select_date(-1,'txtDatePaiement'); print $form->select_date(-1,'txtDatePaiement');
?> ?>
<!-- <input class="texte2" type="text" id="txtDatePaiement" name="txtDatePaiement" value="" /> <!-- <input class="texte2" type="text" id="txtDatePaiement" name="txtDatePaiement" value="" />

View File

@ -14,7 +14,6 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/ */
$langs->load("main"); $langs->load("main");
@ -105,7 +104,6 @@ $langs->load("main");
<p class="note_label"> <p class="note_label">
<?php <?php
echo $langs->trans("BankToPay"). "<br>"; echo $langs->trans("BankToPay"). "<br>";
$form = new Form($db);
$form->select_comptes($selected,'cashdeskbank',0,$filtre); $form->select_comptes($selected,'cashdeskbank',0,$filtre);
?> ?>
</p> </p>

View File

@ -27,6 +27,7 @@
* \brief File of class to manage extra fields * \brief File of class to manage extra fields
*/ */
/** /**
* Class to manage standard extra fields * Class to manage standard extra fields
*/ */
@ -581,7 +582,7 @@ class ExtraFields
*/ */
function showInputField($key,$value,$moreparam='',$keyprefix='') function showInputField($key,$value,$moreparam='',$keyprefix='')
{ {
global $conf,$langs,$db; global $conf,$langs;
$label=$this->attribute_label[$key]; $label=$this->attribute_label[$key];
$type =$this->attribute_type[$key]; $type =$this->attribute_type[$key];
@ -612,17 +613,18 @@ class ExtraFields
{ {
$tmp=explode(',',$size); $tmp=explode(',',$size);
$newsize=$tmp[0]; $newsize=$tmp[0];
if(!class_exists('Form'))
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
$formstat = new Form($db);
$showtime = in_array($type,array('datetime')) ? 1 : 0; $showtime = in_array($type,array('datetime')) ? 1 : 0;
// Do not show current date when field not required (see select_date() method)
if(!$required && $value == '')
$value = '-1';
$out = $formstat->select_date($value, 'options_'.$key.$keyprefix, $showtime, $showtime, $required, '', 1, 1, 1, 0, 1); // Do not show current date when field not required (see select_date() method)
// TODO Missing to add $moreparam if (!$required && $value == '') $value = '-1';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
global $form;
if (! is_object($form)) $form=new Form($this->db);
// TODO Must also support $moreparam
$out = $form->select_date($value, 'options_'.$key.$keyprefix, $showtime, $showtime, $required, '', 1, 1, 1, 0, 1);
} }
elseif (in_array($type,array('int'))) elseif (in_array($type,array('int')))
{ {

View File

@ -3783,7 +3783,7 @@ class Form
/** /**
* Show a select form from an array * Return a HTML select string, built from an array of key+value.
* *
* @param string $htmlname Name of html select area * @param string $htmlname Name of html select area
* @param array $array Array with key+value * @param array $array Array with key+value
@ -3799,7 +3799,7 @@ class Form
* @param string $morecss Add more class to css styles * @param string $morecss Add more class to css styles
* @return string HTML select string * @return string HTML select string
*/ */
function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='') static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='')
{ {
global $langs; global $langs;

View File

@ -217,12 +217,13 @@ class FormActions
*/ */
function select_type_actions($selected='',$htmlname='actioncode',$excludetype='',$onlyautoornot=0) function select_type_actions($selected='',$htmlname='actioncode',$excludetype='',$onlyautoornot=0)
{ {
global $langs,$user; global $langs,$user,$form;
if (! is_object($form)) $form=new Form($db);
require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
$caction=new CActionComm($this->db); $caction=new CActionComm($this->db);
$form=new Form($this->db);
// Suggest a list with manual events or all auto events // Suggest a list with manual events or all auto events
$arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot); $arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);

View File

@ -257,7 +257,9 @@ class FormFile
*/ */
function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='') function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='')
{ {
global $langs,$conf,$hookmanager,$user,$bc; global $langs,$conf,$hookmanager,$user,$form,$bc;
if (! is_object($form)) $form=new Form($this->db);
// filedir = $conf->...->dir_ouput."/".get_exdir(id) // filedir = $conf->...->dir_ouput."/".get_exdir(id)
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -446,7 +448,6 @@ class FormFile
$headershown=1; $headershown=1;
$form = new Form($this->db);
$buttonlabeltoshow=$buttonlabel; $buttonlabeltoshow=$buttonlabel;
if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate'); if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate');

View File

@ -219,7 +219,9 @@ class FormMail
*/ */
function get_form($addfileaction='addfile',$removefileaction='removefile') function get_form($addfileaction='addfile',$removefileaction='removefile')
{ {
global $conf, $langs, $user, $hookmanager; global $conf, $langs, $user, $hookmanager, $form;
if (! is_object($form)) $form=new Form($this->db);
$langs->load("other"); $langs->load("other");
$langs->load("mails"); $langs->load("mails");
@ -248,8 +250,6 @@ class FormMail
if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]); if (! empty($_SESSION["listofnames"])) $listofnames=explode(';',$_SESSION["listofnames"]);
if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]); if (! empty($_SESSION["listofmimes"])) $listofmimes=explode(';',$_SESSION["listofmimes"]);
$form=new Form($this->db);
$out.= "\n<!-- Debut form mail -->\n"; $out.= "\n<!-- Debut form mail -->\n";
if ($this->withform == 1) if ($this->withform == 1)
{ {

View File

@ -97,7 +97,7 @@ class FormOrder
/** /**
* Return list of input method (mode used to receive order, like order received by email, fax, online) * Return list of input method (mode used to receive order, like order received by email, fax, online)
* List found into table c_input_method * List found into table c_input_method.
* *
* @param string $selected Id of preselected input method * @param string $selected Id of preselected input method
* @param string $htmlname Name of HTML select list * @param string $htmlname Name of HTML select list
@ -106,11 +106,11 @@ class FormOrder
*/ */
function selectInputMethod($selected='',$htmlname='source_id',$addempty=0) function selectInputMethod($selected='',$htmlname='source_id',$addempty=0)
{ {
global $conf,$langs; global $conf,$langs,$form;
$listofmethods=array();
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; if (! is_object($form)) $form=new Form($this->db);
$form=new Form($this->db);
$listofmethods=array();
$sql = "SELECT rowid, code, libelle as label"; $sql = "SELECT rowid, code, libelle as label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_input_method"; $sql.= " FROM ".MAIN_DB_PREFIX."c_input_method";

View File

@ -900,7 +900,8 @@ class FormOther
/** /**
* Show a HTML Tab with boxes of a particular area including personalized choices of user * Show a HTML Tab with boxes of a particular area including personalized choices of user.
* Class 'Form' must be known.
* *
* @param User $user Object User * @param User $user Object User
* @param String $areacode Code of area for pages (0=value for Home page) * @param String $areacode Code of area for pages (0=value for Home page)
@ -933,9 +934,8 @@ class FormOther
if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')'; if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
$arrayboxtoactivatelabel[$box->id]=$label; // We keep only boxes not shown for user, to show into combo list $arrayboxtoactivatelabel[$box->id]=$label; // We keep only boxes not shown for user, to show into combo list
} }
// Class Form must have been already loaded
$form=new Form($db); $selectboxlist=Form::selectarray('boxcombo', $arrayboxtoactivatelabel,'',1);
$selectboxlist=$form->selectarray('boxcombo', $arrayboxtoactivatelabel,'',1);
} }
// Javascript code for dynamic actions // Javascript code for dynamic actions

View File

@ -83,20 +83,21 @@ class FormSms
} }
/** /**
* Show the form to input an sms * Show the form to input an sms.
* *
* @param string $width Width of form * @param string $width Width of form
* @return void * @return void
*/ */
function show_form($width='180px') function show_form($width='180px')
{ {
global $conf, $langs, $user; global $conf, $langs, $user, $form;
if (! is_object($form)) $form=new Form($this->db);
$langs->load("other"); $langs->load("other");
$langs->load("mails"); $langs->load("mails");
$langs->load("sms"); $langs->load("sms");
$form=new Form($this->db);
$soc=new Societe($this->db); $soc=new Societe($this->db);
if (!empty($this->withtosocid) && $this->withtosocid > 0) if (!empty($this->withtosocid) && $this->withtosocid > 0)
{ {