0001438: Remplacement de HtmlInput par HttpInput

This commit is contained in:
Dany De Bontridder 2017-06-05 19:56:43 +02:00
parent aa55ed6894
commit 074bcac3c3
15 changed files with 216 additions and 99 deletions

View file

@ -44,6 +44,7 @@ require_once NOALYSS_INCLUDE.'/lib/class_iradio.php';
require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
require_once NOALYSS_INCLUDE.'/class/class_user.php';
mb_internal_encoding("UTF-8");
$var = array('gDossier', 'op');

View file

@ -20,15 +20,27 @@
// Copyright 2014 Author Dany De Bontridder danydb@aevalys.eu
// require_once '.php';
if (!defined('ALLOWED'))
die('Appel direct ne sont pas permis');
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
ob_start();
try
{
$ag_id=$http->get("ag_id");
}
catch (Exception $exc)
{
echo $exc->getMessage();
error_log($exc->getTraceAsString());
return;
}
$ag_id=HtmlInput::default_value_get("ag_id", "0");
require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
if ($ag_id == 0 ) throw new Exception('ag_id is null');
require_once('class/class_acc_ledger.php');
$r=HtmlInput::title_box(_("Détail fiche"), 'search_card');
$r.='<form id="search_card1_frm" method="GET" onsubmit="action_add_concerned_card(this);return false;">';
@ -42,7 +54,7 @@ $r.='</span>';
$r.=dossier::hidden().HtmlInput::hidden('op', 'add_concerned_card');
$r.=HtmlInput::request_to_hidden(array('ag_id'));
$r.='</form>';
$query=HtmlInput::default_value_get("query", "");
$query=$http->get("query", "string","");
$sql_array['query']=$query;
$sql_array['typecard']='all';

View file

@ -40,14 +40,22 @@ if (!defined('ALLOWED'))
if ($g_user->check_module('CFGPRO')==0)
die();
$type=HtmlInput::default_value_get('type', 'XX');
$p_level=HtmlInput::default_value_get('p_level', 0);
$dep=HtmlInput::default_value_get('dep', 0);
if ($type=='XX')
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
try
{
throw new Exception('invalid call');
$type=$http->get('type');
$p_level=$http->get('p_level', "string",0);
$dep=$http->get('dep', "string",0);
}
catch (Exception $exc)
{
echo $exc->getMessage();
error_log($exc->getTraceAsString());
return;
}
// if type == menu the
if ($type=='me')
{

View file

@ -32,22 +32,19 @@ if ($g_user->Admin()==0)
die();
}
set_language();
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
// From admin, grant the access to a folder to an
// user
if ($op=='folder_add') // operation
{
$cn=new Database();
$user_id=HtmlInput::default_value_get("p_user", 0); // get variable
$dossier_id=HtmlInput::default_value_get("p_dossier", 0); // get variable
if ($user_id==0||$dossier_id==0||isNumber($user_id)==0||$dossier_id==0)
{
$content=_('Erreur paramètre');
$status="NOK";
}
else
try
{
$user_id=$http->get("p_user", "number"); // get variable
$dossier_id=$http->get("p_dossier", "number"); // get variable
$user=new User($cn, $user_id);
$user->set_folder_access($dossier_id, true);
$dossier=new Dossier($dossier_id);
@ -58,6 +55,15 @@ if ($op=='folder_add') // operation
"</td>";
$status='OK';
}
catch (Exception $exc)
{
error_log($exc->getTraceAsString());
$content=_('Erreur paramètre');
$status="NOK";
return;
}
//----------------------------------------------------------------
// Answer in XML
header('Content-type: text/xml; charset=UTF-8');
@ -75,22 +81,23 @@ if ($op=='folder_add') // operation
// user
if ($op=='folder_remove') // operation
{
$cn=new Database();
$user_id=HtmlInput::default_value_get("p_user", 0); // get variable
$dossier_id=HtmlInput::default_value_get("p_dossier", 0); // get variable
if ($user_id==0||$dossier_id==0||isNumber($user_id)==0||$dossier_id==0)
{
$content=_('Erreur paramètre');
$status="NOK";
}
else
try
{
$cn=new Database();
$user_id=$http->get("p_user", "number"); // get variable
$dossier_id=$http->get("p_dossier", "number"); // get variable
$user=new User($cn, $user_id);
$user->set_folder_access($dossier_id, false);
$content="";
$status='OK';
}
catch (Exception $exc)
{
error_log($exc->getTraceAsString());
$content=_('Erreur paramètre');
$status="NOK";
}
//----------------------------------------------------------------
// Answer in XML
header('Content-type: text/xml; charset=UTF-8');
@ -114,16 +121,10 @@ if ($op=='folder_display') // operation
{
$cn=new Database();
$user_id=HtmlInput::default_value_get("p_user", 0); // get variable
$p_filter=HtmlInput::default_value_get('p_filter', '');
if ($user_id==0||isNumber($user_id)==0)
{
$content=_('Erreur paramètre');
$status="NOK";
}
else
try
{
$user_id=$http->get("p_user", "number"); // get variable
$p_filter=$http->get('p_filter', "string",'');
ob_start();
$user=new User($cn, $user_id);
$a_dossier=Dossier::show_dossier('X', $user->id, $p_filter, MAX_FOLDER_TO_SHOW);
@ -151,7 +152,19 @@ if ($op=='folder_display') // operation
require NOALYSS_TEMPLATE.'/folder_display.php';
$content=ob_get_clean();
$status='OK';
}
catch (Exception $exc)
{
error_log($exc->getTraceAsString());
$content=_('Erreur paramètre');
$status="NOK";
}
//----------------------------------------------------------------
// Answer in XML
header('Content-type: text/xml; charset=UTF-8');
@ -170,13 +183,19 @@ if ($op=='folder_display') // operation
// the p_dossier parameter is mandatory
if (in_array($op, array('modele_drop', 'modele_modify', 'folder_modify', 'folder_drop')))
{
$dossier=HtmlInput::default_value_get('p_dossier', 0);
$content=_('Erreur paramètre');
$status="NOK";
// check if we receive a valid parameter
if ($dossier==0||isNumber($dossier)==0)
try
{
//----------------------------------------------------------------
$dossier=$http->get('p_dossier', "number");
$content=_('Erreur paramètre');
$status="NOK";
}
catch (Exception $exc)
{
error_log($exc->getTraceAsString());
$content=_('Erreur paramètre');
$status="NOK";
//----------------------------------------------------------------
// Answer in XML
header('Content-type: text/xml; charset=UTF-8');
$dom=new DOMDocument('1.0', 'UTF-8');
@ -189,7 +208,9 @@ if (in_array($op, array('modele_drop', 'modele_modify', 'folder_modify', 'folder
$dom->appendChild($root);
echo $dom->saveXML();
exit();
}
// Modify the description or the name of folder
if ($op=='folder_modify')
{

View file

@ -26,11 +26,23 @@
*/
// Copyright (2014) Author Dany De Bontridder danydb@aevalys.eu
if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
$amount=HtmlInput::default_value_get("amount", 0);
$table_id=HtmlInput::default_value_get("t", "");
$ledger=HtmlInput::default_value_get('led',0);
if ($table_id == "" || isNumber($amount) == 0 || isNumber($ledger) == 0) die ('Invalid Parameter');
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
try
{
$amount=$http->get("amount", "number");
$table_id=$http->get("t");
$ledger=$http->get('led',"number");
}
catch (Exception $exc)
{
error_log($exc->getTraceAsString());
return;
}
require_once 'class/class_anc_key.php';

View file

@ -29,22 +29,25 @@
if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
require_once NOALYSS_INCLUDE.'/class/class_anc_key.php';
ob_start();
/////
$key=HtmlInput::default_value_get('key',0);
$amount=HtmlInput::default_value_get('amount',0);
$target=HtmlInput::default_value_get('t','');
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
if ( isNumber($key)== 0
|| isNumber($amount) ==0
|| $target==''
)
try
{
die ('Invalid parameter');
$key=$http->get('key',"number");
$amount=$http->get('amount',"number");
$target=$http->get('t');
}
catch (Exception $exc)
{
echo $exc->getMessage();
error_log($exc->getTraceAsString());
return;
}
$compute_key=new Anc_Key($key);
$row=str_replace('t', "", $target);
$pos=strrpos($target,"t");
$row=substr($target,$pos+1);
$compute_key->fill_table($target,$amount);
echo <<<EOF

View file

@ -37,6 +37,11 @@ require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
require_once NOALYSS_INCLUDE.'/class/class_anc_account.php';
require_once NOALYSS_INCLUDE.'/class/class_anc_plan.php';
require_once NOALYSS_INCLUDE.'/lib/function_javascript.php';
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
$texte=new IText('plabel');
$texte->value=$http->get('plabel',"string","");
echo HtmlInput::title_box(_("Recherche activité"), $ctl);
@ -44,8 +49,6 @@ echo HtmlInput::title_box(_("Recherche activité"), $ctl);
echo '<FORM id="anc_search_form" METHOD="GET" onsubmit="search_anc_form(this);return false">';
echo '<span>'._('Recherche').':';
$texte=new IText('plabel');
$texte->value=HtmlInput::default_value('plabel',"", $_GET);
echo $texte->input();
echo '</span>';
echo dossier::hidden();

View file

@ -19,11 +19,14 @@
// Copyright Author Dany De Bontridder danydb@aevalys.eu
if ( !defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
require_once NOALYSS_INCLUDE.'/class/class_calendar.php';
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
ob_start();
if ( $notitle== 0 ) echo HtmlInput::title_box(_("Calendrier"), "calendar_zoom_div");
$cal=new Calendar();
$in=HtmlInput::default_value_get('in',"");
$notitle=HtmlInput::default_value_get('notitle',"0");
$in=$http->get('in',"string","");
$notitle=$http->get('notitle',"string","0");
if ( $in == "") {
$in=$cal->get_preference();
}

View file

@ -30,18 +30,20 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
// Security
if ( $g_user->check_module('CFGPRO') == 0 ) die();
// Check parameter
$module=HtmlInput::default_value_get("dep", "");
$p_level=HtmlInput::default_value_get("p_level", 0);
$p_id=HtmlInput::default_value_get('p_profile',-1);
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
if ($module == ""
|| $p_id == -1
|| isNumber($p_id) == 0
|| isNumber($p_level) == 0
)
ob_start();
try
{
echo _('Paramètre invalide');
$module=$http->get("dep");
$p_level=$http->get("p_level", "number",0);
$p_id=$http->get('p_profile',"number");
}
catch (Exception $exc)
{
error_log($exc->getTraceAsString());
return;
}

View file

@ -25,6 +25,10 @@
*/
if (!defined('ALLOWED'))
die('Appel direct ne sont pas permis');
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
if ($op=='action_show')
{
/**
@ -51,19 +55,16 @@ if ($op=='action_save')
/**
* save info from the get
*/
$date_event=HtmlInput::default_value_get("date_event", -1);
$dest=HtmlInput::default_value_get("dest", "");
$event_group=HtmlInput::default_value_get("event_group", 0);
$event_priority=HtmlInput::default_value_get("event_priority", 0);
$title=HtmlInput::default_value_get("title_event", NULL);
$summary=HtmlInput::default_value_get("summary", "");
$type_event=HtmlInput::default_value_get('type_event', -1);
$hour_event=HtmlInput::default_value_get('hour_event', null);
/*
* Check if data are valid
*/
try
{
$date_event=$http->get("date_event","string","");
$dest=$http->get("dest","string", "");
$event_group=$http->get("event_group", "string",0);
$event_priority=$http->get("event_priority", "string",0);
$title=$http->get("title_event","string", NULL);
$summary=$http->get("summary","string", "");
$type_event=$http->get('type_event', "string",-1);
$hour_event=$http->get('hour_event', "string",null);
if ($date_event==-1||isDate($date_event)==0)
throw new Exception(_('Date invalide'));
if (trim($dest)=="")

View file

@ -34,11 +34,14 @@ if ( $g_user->check_module('CFGPRO') == 0 ) die();
require_once NOALYSS_INCLUDE.'/database/class_profile_sql.php';
require_once NOALYSS_INCLUDE.'/class/class_profile_menu.php';
require_once NOALYSS_INCLUDE.'/lib/class_html_input.php';
$p_id=HtmlInput::default_value_request('p_id', -1);
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
$p_id=$http->request('p_id',"string", -1);
$profile=new Profile_sql($cn,$p_id);
$gDossier=Dossier::id();
$add_impression=HtmlInput::button("add", _("Ajout Menu"),"onclick=\"add_menu({dossier:$gDossier,p_id:$p_id,type:'pr'})\"");
$call_tab=HtmlInput::default_value_post('tab', 'profile_gen_div');
$call_tab=$http->post('tab', "string",'profile_gen_div');
$a_tab=array('profile_gen_div'=>'tabs','profile_menu_div'=>'tabs','profile_print_div'=>'tabs','profile_gestion_div'=>'tabs','profile_repo_div'=>'tabs');
$a_tab[$call_tab]='tabs_selected';
?>

View file

@ -40,6 +40,9 @@ require_once NOALYSS_INCLUDE.'/class/class_anc_operation.php';
require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
require_once NOALYSS_INCLUDE.'/class/class_own.php';
require_once NOALYSS_INCLUDE.'/lib/class_iconcerned.php';
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
/**
* Check if we receive the needed data (jr_id...)
*/
@ -51,11 +54,20 @@ if ( ! isset ($_REQUEST['act'])|| ! isset ($_REQUEST['jr_id'])
global $g_user,$cn,$g_parameter;
mb_internal_encoding("UTF-8");
try
{
$action=$http->request('act');
$jr_id=$http->request('jr_id');
$div=$http->request('div'); /* the div source and target for javascript */
$gDossier=dossier::id();
}
catch (Exception $exc)
{
error_log($exc->getTraceAsString());
return;
}
$action=$_REQUEST['act'];
$jr_id=$_REQUEST['jr_id'];
$div=$_REQUEST['div']; /* the div source and target for javascript */
$gDossier=dossier::id();
/**
*if $_SESSION['g_user'] is not set : echo a warning
*/
@ -87,7 +99,7 @@ EOF;
// check if the user can access the ledger where the operation is (view) and
// if he can modify it
$op=new Acc_Operation($cn);
$op->jr_id=$_REQUEST['jr_id'];
$op->jr_id=$jr_id;
$ledger=$op->get_ledger();
if ($ledger=="")
{
@ -146,10 +158,7 @@ case 'rmop':
{
$cn->start();
$oLedger=new Acc_Ledger($cn,$ledger);
$oLedger->jr_id=HtmlInput::default_value_request('jr_id',0);
if ( $oLedger->jr_id == 0 ||
isNumber($oLedger->jr_id) == 0)
throw new Exception (_('Donnée invalide'));
$oLedger->jr_id=$jr_id=$http->request('jr_id',"number");
$oLedger->delete();
$cn->commit();
echo _("Opération Effacée");

View file

@ -21,12 +21,23 @@
// require_once '.php';
if ( ! defined ('ALLOWED') ) die(_('Non autorisé'));
require_once NOALYSS_INCLUDE.'/lib/class_http_input.php';
$http=new HttpInput();
// Security
if ($g_user->check_module('CFGPRO')==0)
die();
$p_profile_menu_id=HtmlInput::default_value_get('p_profile_menu_id', 0);
if ( $p_profile_menu_id == 0 ||isNumber($p_profile_menu_id)==0) throw new Exception(_('Donnée invalide'));
try
{
$p_profile_menu_id=$http->get('p_profile_menu_id', "number");
}
catch (Exception $exc)
{
error_log($exc->getTraceAsString());
return;
}
// Delete menu + children
$cn->exec_sql('delete from profile_menu where pm_id = $1 or pm_id_dep=$1',array($p_profile_menu_id));

View file

@ -327,6 +327,14 @@ class Anc_Key
$array['val']=$val;
$anc_operation=new Anc_Operation($cn);
// find the div thanks the target which looks like "det4t0"
// det4 is the div id and t0 is the row
if (strpos($p_target, "et")){
// cut off t[0-9]
$pos=strrpos($p_target,"t");
$anc_operation->in_div=substr($p_target,0,$pos);
}
echo $anc_operation->display_form_plan($array, 1, 1, $number, $p_amount,'',false);
}

View file

@ -37,12 +37,20 @@ class HttpInput
{
// no check on string
if ( $p_type=="string") return;
// Check if number
if ( $p_type=="number"
&& isNumber($this->array[$p_name]) == 0
)
throw new Exception(_("Valeur invalide")."[ $p_name ] = {$this->array[$p_name]}"
throw new Exception(_("Type invalide")."[ $p_name ] = {$this->array[$p_name]}"
,EXC_PARAM_TYPE);
if ( $p_type=="date") return;
// Check if date dd.mm.yyyy
if ( $p_type=="date") {
if (isDate($this->array[$p_name])=!$this->array[$p_name]) {
throw new Exception(_("Type invalide")."[ $p_name ] = {$this->array[$p_name]}"
,EXC_PARAM_TYPE);
}
}
}
catch (Exception $ex)
{
@ -142,6 +150,18 @@ class HttpInput
}
}
/**
* Extract variable name from an exception message. If an exception is thrown
* then thanks this function it is possible to know what variable triggers
* the exception
* @param type $p_string
* @return string like "[variable]"
*/
function extract_variable($p_string) {
if ( preg_match("/\[.*\]/",$p_string,$found) == 1 ) {
return $found[0];
}
}
}
?>