js you have the javascript code
* - SELECT the options are passed via this->value, this array is
* build thanks the make_array function, each array (of the
* array) aka row must contains a field value and a field label
* - PASSWORD
* - CHECKBOX
* - RADIO
* - TEXTAREA
* - RICHTEXT
* - FILE
* - SPAN
*/
class HtmlInput
{
var $type; /*!< $type type of the widget */
var $name; /*!< $name field NAME of the INPUT */
var $value; /*!< $value what the INPUT contains */
var $readOnly; /*!< $readonly true : we cannot change value */
var $size; /*!< $size size of the input */
var $selected; /*!< $selected for SELECT RADIO and CHECKBOX the selected value */
var $table; /*!< $table =1 add the table tag */
var $label; /*!< $label the question before the input */
var $disabled; /*!< $disabled poss. value == true or nothing, to disable INPUT*/
var $extra; /*!< $extra different usage, it depends of the $type */
var $extra2; /*!< $extra2 different usage,
it depends of the $type */
var $javascript; /*!< $javascript is the javascript to add to the widget */
var $ctrl; /*!<$ctrl is the control to update (see js_search_card_control) */
var $tabindex;
function __construct($p_name="",$p_value="",$p_id="")
{
$this->name=$p_name;
$this->readOnly=false;
$this->size=20;
$this->width=50;
$this->heigh=20;
$this->value=$p_value;
$this->selected="";
$this->table=0;
$this->disabled=false;
$this->javascript="";
$this->extra="";
$this->extra2="all";
$this->attribute=array();
$this->id=$p_id;
}
function setReadOnly($p_read)
{
$this->readOnly=$p_read;
}
/*!\brief set the extra javascript property for the INPUT field
*\param $p_name name of the parameter
*\param $p_value default value of this parameter
*/
public function set_attribute($p_name,$p_value)
{
$this->attribute[]=array($p_name,$p_value);
$this->$p_name=$p_value;
}
/**
* Set the value of input (IText, INum,...)
* @param type $p_string
*/
function set_value($p_string)
{
$this->value=$p_string;
}
/**
* Return the value of input (IText, INum,...)
*/
function get_value()
{
return $this->value;
}
/**
*@brief you can add attribute to this in javascript
* this function is a wrapper and create a script (in js) to modify
* "this" (in javascript) with the value of obj->attribute from PHP
*@return return string with the javascript code
*/
public function get_js_attr()
{
require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
$attr="";
if ( count($this->attribute) == 0) return "";
/* Add properties at the widget */
for ($i=0;$i< count($this->attribute);$i++)
{
list($name,$value)=$this->attribute[$i];
$tmp1=sprintf("$('%s').%s='%s';",
$this->name,
$name,
$value);
$attr.=$tmp1;
}
$attr=create_script($attr);
return $attr;
}
/**
* Make a JSON object, this method create a javascript object
* with the attribute set, it returns a javascript string with the object
* @param $p_name : name of the object, can be null. If the name is not null, return
* $p_name={} otherwise only the object {}
* @return javascript string with the object
* @note: there is not check on the key->value, so you could need to escape
* special char as quote, single-quote...
* @deprecated
* @code
$a=new IButton()
$a->set_attribute('prop','1');
$a->set_attribute('prop','2');
$a->set_attribute('prop','3');
$string = $a->make_object('property');
echo $string => property={'prop':'1','prop2':'2','prop3':'3'};
$string = $a->make_object(null);
echo $string => {'prop':'1','prop2':'2','prop3':'3'};
@endcode
*/
public function make_object_deprecated($p_name=null)
{
$name=($p_name != null)?$p_name.'=':'';
if ( count($this->attribute) == 0) return $name."{}";
$ret=$name."{";
$and='';
for ($i=0;$i< count($this->attribute);$i++)
{
list($name,$value)=$this->attribute[$i];
$tmp1=sprintf($and."'%s':'%s'",
$name,
$value);
$ret.=$tmp1;
$and=',';
}
$ret.='}';
return $ret;
}
//#####################################################################
/* Debug
*/
function debug()
{
echo "Type ".$this->type."
";
echo "name ".$this->name."
";
echo "value". $this->value."
";
$readonly=($this->readonly==false)?"false":"true";
echo "read only".$readonly."
";
}
static function submit ($p_name,$p_value,$p_javascript="",$p_class="smallbutton")
{
return '';
}
static function button ($p_name,$p_value,$p_javascript="",$p_class="smallbutton")
{
return '';
}
static function reset ($p_value)
{
return '';
}
static function hidden($p_name,$p_value,$p_id="")
{
if ($p_id=="") $p_id=$p_name;
return '';
}
static function extension()
{
return self::hidden('plugin_code',$_REQUEST['plugin_code']);
}
/*!\brief create a button with a ref
*\param $p_label the text
*\param $p_value the location of the window,
*\param $p_name the id of the span
*\param $p_javascript javascript for this button
*\return string with htmlcode
*/
static function button_anchor($p_label,$p_value,$p_name="",$p_javascript="",$p_class="button")
{
$r=sprintf(' %s',
$p_name,
$p_value,
$p_javascript,
$p_label);
return $r;
}
static function infobulle($p_comment)
{
$r='';
$r.='';
$r.='';
return $r;
}
static function warnbulle($p_comment)
{
$r='
';
return $r;
}
static function errorbulle($p_comment)
{
global $g_failed;
$r=sprintf(' %s ',
$p_comment,
$p_comment,
$g_failed);
return $r;
}
/**
* return a string containing the html code for calling the modifyOperation
*/
static function detail_op($p_jr_id,$p_mesg)
{
return sprintf('%s',
$p_jr_id,dossier::id(),$p_mesg);
}
/**
* @brief return an anchor to view the detail of an action
* @param $ag_id
* @param $p_mesg
* @param $p_modify let you modify an operation
*
*/
static function detail_action($ag_id,$p_mesg,$p_modify=1)
{
return sprintf('%s',
$ag_id,dossier::id(),$p_modify,$p_mesg);
}
/**
* return a string containing the html code for calling the modifyModeleDocument
*/
static function detail_modele_document($p_id,$p_mesg)
{
return sprintf('%s',
$p_id,dossier::id(),$p_mesg);
}
/**
* return a string containing the html code for calling the removeStock
*/
static function remove_stock($p_id,$p_mesg)
{
return sprintf('%s',
$p_id,dossier::id(),$p_mesg);
}
/**
* display a div with the history of the card
*/
static function history_card($f_id,$p_mesg,$p_style="")
{
$view_history= sprintf('%s',
$p_style,$f_id, dossier::id(), $p_mesg);
return $view_history;
}
/**
* display a div with the history of the card
*/
static function history_card_button($f_id,$p_mesg)
{
static $e=0;
$e++;
$js= sprintf('onclick="view_history_card(\'%s\',\'%s\')"',
$f_id, dossier::id());
$view_history=HtmlInput::button("hcb"+$e,$p_mesg,$js);
return $view_history;
}
/**
* display a div with the history of the account
*/
static function history_account($p_account,$p_mesg,$p_style="")
{
$view_history= sprintf('%s',
$p_style,$p_account, dossier::id(), $p_mesg);
return $view_history;
}
/**
* return the html code to create an hidden div and a button
* to show this DIV. This contains all the available ledgers
* for the user in READ or RW
*@param $selected is an array of checkbox
*@param $div div suffix
*@note the choosen ledger are stored in the array r_jrn (_GET)
*/
static function select_ledger($p_type,$p_selected,$div='')
{
global $g_user;
$r = '';
/* security : filter ledger on user */
$p_array = $g_user->get_ledger($p_type, 3);
ob_start();
/* create a hidden div for the ledger */
echo '
'.'';
}
else
if ( $p_mod == 'custom')
{$r=''.$p_js."";} else
if ( $p_mod == 'none') {$r="" ; }
else
die (__FILE__.":".__LINE__._('Paramètre invaide'));
if ( $p_draggable=="y") {
$drag=sprintf(' ❉ ',
$p_div,
$p_div);
$r.=$drag;
}
$r.=h2($p_name,' class="title" ');
return $r;
}
/**
* @brief let you create only a link and set an id on it.
* After create a javascript for getting the event
* onclick = function() {...}
* @param type $p_text Text to display
* @param type $p_id id of the link
* @param type $type title of the link
* @code
* echo HtmlInput::anchor_empty('go','go_id');
*
* @endcode
*/
static function anchor_empty($p_text,$p_id,$p_title="")
{
$p_url="javascript:void(0)";
$str=sprintf('%s',
$p_id,$p_title,$p_text);
return $str;
}
/**
*Return a simple anchor with a url or a javascript
* if $p_js is not null then p_url will be javascript:void(0)
* we don't add the event onclick. You must give p_url OR p_js
* default CSS class=line
* @param string $p_text text of the anchor
* @param string $p_url url
* @param string $p_js javascript
* @param string $p_style is the visuable effect (class, style...)
*/
static function anchor($p_text,$p_url="",$p_js="",$p_style=' class="line" ')
{
if ($p_js != "")
{
$p_url="javascript:void(0)";
} else {
$p_url=sprintf('href="%s"',$p_url);
}
$str=sprintf('%s',
$p_style,$p_url,$p_js,$p_text);
return $str;
}
/**
*Create an ISelect object containing the available repository for reading
* or writing
* @remark $g_user global.
*
* @param $p_cn db object
* @param $p_name name of the select
* @param $p_mode is 'R' for reading, 'W' for writinh
* @return ISelect
* @throws Exception if p_mode is wrong
*/
static function select_stock( $p_cn, $p_name,$p_mode)
{
global $g_user;
if ( ! in_array($p_mode,array('R','W') ) )
{
throw new Exception (__FILE__.":".__LINE__." $p_mode invalide");
}
$profile=$g_user->get_profile();
$sel=new ISelect($p_name);
if ($p_mode == 'W')
{
$sel->value=$p_cn->make_array("
select r_id,r_name
from stock_repository join profile_sec_repository using (r_id)
where
ur_right='W' and p_id=".sql_string($profile).
" order by 2" );
return $sel;
}
if ($p_mode == 'R')
{
$sel->value=$p_cn->make_array("
select r_id,r_name
from stock_repository join profile_sec_repository using (r_id)
where
p_id=".sql_string($profile).
" order by 2" );
return $sel;
}
}
static function filter_table_form($p_table_id,$p_col,$start_row,$p_name,$p_old_value)
{
$r= "
";
$r.=' ';
return $r;
}
static function filter_table($p_table_id,$p_col,$start_row)
{
$r= "
";
$r.=' ';
return $r;
}
static function show_reconcile($p_div, $let,$span="")
{
$r = '' . $let.$span . '';
return $r;
}
/**
* Zoom the calendar
* @param type $obj objet json for the javascript
* @see calendar_zoom in scripts.js
*/
static function calendar_zoom($obj)
{
$button=new ISmallButton("calendar", _("Calendrier"));
$button->javascript="calendar_zoom($obj)";
return $button->input();
}
/**
*
* @param type $p_array indice
* - div div name
* - type ALL, VEN, ACH or ODS
* - all_type 1 yes 0 no
*
*/
static function button_choice_ledger($p_array)
{
extract ($p_array, EXTR_SKIP);
$bledger_param = json_encode(array(
'dossier' => $_REQUEST['gDossier'],
'type' => $type,
'all_type' => $all_type,
'div' => $div,
'class'=>'inner_box'
));
$bledger_param = str_replace('"', "'", $bledger_param);
$bledger = new ISmallButton('l');
$bledger->label = _("choix des journaux");
$bledger->javascript = " show_ledger_choice($bledger_param)";
$f_ledger = $bledger->input();
$hid_jrn = "";
if (isset($_REQUEST[$div . 'nb_jrn']))
{
for ($i = 0; $i < $_REQUEST[$div . 'nb_jrn']; $i++)
{
if (isset($_REQUEST[$div . "r_jrn"][$i]))
$hid_jrn.=HtmlInput::hidden($div . 'r_jrn[' . $i . ']', $_REQUEST[$div . "r_jrn"][$i]);
}
$hid_jrn.=HtmlInput::hidden($div . 'nb_jrn', $_REQUEST[$div . 'nb_jrn']);
} else
{
$hid_jrn = HtmlInput::hidden($div . 'nb_jrn', 0);
}
echo $f_ledger;
echo '';
echo $hid_jrn;
echo '';
}
/**
* @brief Returns HTML code for displaying a icon with a link to a receipt document from
* the ledger
* @param $p_jr_id jrn.jr_id
* @param $p_name name in the link , if the name is empty then we show the icon
* @return nothing or HTML Code for a link to the document
*/
static function show_receipt_document($p_jr_id,$p_name="")
{
global $cn;
$image=$p_name;
// Check the jr_id has a receipt document
$array=$cn->get_array('select jr_def_id,jr_pj_name,jr_grpt_id from jrn where jr_id=$1',array($p_jr_id));
if (count($array)==0) return "";
if ($array[0]['jr_pj_name'] == "") return "";
$str_dossier=Dossier::get();
// Name is empty then use an image
if ( $p_name == "") {
$image='
';
}
// Build the url
$href=http_build_query(array('gDossier'=>Dossier::id(),'jr_id'=>$p_jr_id,'act'=>'RAW:receipt'));
$r=sprintf('%s', $href, $image);
return $r;
}
/**
*
* @param type $p_operation_jr_id action_gestion_operation.ago_id
*/
static function button_action_remove_operation($p_operation)
{
$rmOperation=sprintf("javascript:confirm_box(null,'"._('Voulez-vous effacer cette relation ')."',function () {remove_operation('%s','%s');});",
dossier::id(),
$p_operation);
$js= ''.SMALLX.'';
return $js;
}
static function button_action_add_concerned_card($p_agid)
{
$dossier=Dossier::id();
$javascript= <<