0000601: Action gestion : sécurité
This commit is contained in:
parent
9a11dd9b02
commit
d86a5d4a44
12 changed files with 530 additions and 302 deletions
|
|
@ -22,90 +22,128 @@
|
|||
require_once 'class_profile_sql.php';
|
||||
global $cn;
|
||||
|
||||
//**********************************************
|
||||
// Save avail. profiles
|
||||
//**********************************************
|
||||
if (isset($_POST['change_profile']))
|
||||
{
|
||||
extract($_POST);
|
||||
try
|
||||
{
|
||||
for ($e = 0; $e < count($right); $e++)
|
||||
{
|
||||
if ($right[$e] == 'X' && $ua_id[$e]=='')
|
||||
continue;
|
||||
if ($right[$e] == 'X' && $ua_id[$e]!='')
|
||||
{
|
||||
$cn->exec_sql("delete from user_sec_action_profile where p_id=$1 and p_granted=$2", array($p_id, $ap_id[$e]));
|
||||
continue;
|
||||
}
|
||||
if ($ua_id[$e] == "")
|
||||
{
|
||||
$cn->exec_sql("insert into user_sec_action_profile (p_id,p_granted,ua_right) values($1,$2,$3)", array($p_id, $ap_id[$e], $right[$e]));
|
||||
continue;
|
||||
}
|
||||
if ($ua_id[$e] != '')
|
||||
{
|
||||
$cn->exec_sql("update user_sec_action_profile set ua_right=$3 where p_id=$1 and p_granted=$2 ", array($p_id, $ap_id[$e], $right[$e]));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $exc)
|
||||
{
|
||||
echo $exc->getTraceAsString();
|
||||
throw $exc;
|
||||
}
|
||||
}
|
||||
//**********************************************
|
||||
// Save_name
|
||||
// *********************************************
|
||||
|
||||
if ( isset($_POST['save_name']))
|
||||
if (isset($_POST['save_name']))
|
||||
{
|
||||
|
||||
extract ($_POST);
|
||||
try{
|
||||
if (strlen(trim($p_name))==0) throw new Exception("Nom ne peut être vide");
|
||||
if (isNumber($p_id)==0) throw new Exception("profile Invalide");
|
||||
$wc=(isset($with_calc))?1:0;
|
||||
$wd=(isset($with_direct_form))?1:0;
|
||||
$p_desc=(strlen(trim($p_desc))==0)?null:trim($p_desc);
|
||||
extract($_POST);
|
||||
try
|
||||
{
|
||||
if (strlen(trim($p_name)) == 0)
|
||||
throw new Exception("Nom ne peut être vide");
|
||||
if (isNumber($p_id) == 0)
|
||||
throw new Exception("profile Invalide");
|
||||
$wc = (isset($with_calc)) ? 1 : 0;
|
||||
$wd = (isset($with_direct_form)) ? 1 : 0;
|
||||
$p_desc = (strlen(trim($p_desc)) == 0) ? null : trim($p_desc);
|
||||
if ($p_id != -1)
|
||||
{
|
||||
$cn->exec_sql("update profile set p_name=$1,p_desc=$2,
|
||||
with_calc=$3, with_direct_form=$4 where p_id=$5",array($p_name,
|
||||
$p_desc,$wc,$wd,$p_id));
|
||||
with_calc=$3, with_direct_form=$4 where p_id=$5", array($p_name,
|
||||
$p_desc, $wc, $wd, $p_id));
|
||||
}
|
||||
else
|
||||
{
|
||||
$p_id=$cn->get_value ("insert into profile (p_name,
|
||||
$p_id = $cn->get_value("insert into profile (p_name,
|
||||
p_desc,with_calc,with_direct_form) values
|
||||
($1,$2,$3,$4) returning p_id",array(
|
||||
$p_name,$p_desc,$wc,$wd
|
||||
));
|
||||
($1,$2,$3,$4) returning p_id", array(
|
||||
$p_name, $p_desc, $wc, $wd
|
||||
));
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
alert($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
//************************************
|
||||
// Clone
|
||||
//************************************
|
||||
if ( isset($_POST['clone']))
|
||||
if (isset($_POST['clone']))
|
||||
{
|
||||
extract ($_POST);
|
||||
extract($_POST);
|
||||
try
|
||||
{
|
||||
$cn->start();
|
||||
$new_id=$cn->get_value("insert into profile(p_name,p_desc,with_calc,
|
||||
$new_id = $cn->get_value("insert into profile(p_name,p_desc,with_calc,
|
||||
with_direct_form)
|
||||
select 'copie de '||p_name,p_desc,with_calc,
|
||||
with_direct_form from profile where p_id=$1 returning p_id",array($p_id));
|
||||
with_direct_form from profile where p_id=$1 returning p_id", array($p_id));
|
||||
$cn->exec_sql("
|
||||
insert into profile_menu (p_id,me_code,me_code_dep,p_order,p_type_display,pm_default)
|
||||
select $1,me_code,me_code_dep,p_order,p_type_display,pm_default from profile_menu
|
||||
where p_id=$2
|
||||
",array($new_id,$p_id));
|
||||
", array($new_id, $p_id));
|
||||
$cn->commit();
|
||||
$p_id=$new_id;
|
||||
|
||||
$p_id = $new_id;
|
||||
}
|
||||
catch (Exception $exc)
|
||||
{
|
||||
echo alert($exc->getMessage());
|
||||
$cn->rollback();
|
||||
}
|
||||
|
||||
}
|
||||
//************************************
|
||||
// Delete
|
||||
//************************************
|
||||
if ( isset($_POST['delete_profil']))
|
||||
if (isset($_POST['delete_profil']))
|
||||
{
|
||||
extract ($_POST);
|
||||
extract($_POST);
|
||||
try
|
||||
{
|
||||
$cn->start();
|
||||
if ( $p_id==1 ) { throw new Exception('On ne peut effacer le profil par défaut');}
|
||||
$new_id=$cn->get_value("delete from profile
|
||||
where p_id=$1 ",array($p_id));
|
||||
if ($p_id == 1)
|
||||
{
|
||||
throw new Exception('On ne peut effacer le profil par défaut');
|
||||
}
|
||||
$new_id = $cn->get_value("delete from profile
|
||||
where p_id=$1 ", array($p_id));
|
||||
$cn->commit();
|
||||
}
|
||||
catch (Exception $exc)
|
||||
{
|
||||
echo alert($exc->getMessage());;
|
||||
echo alert($exc->getMessage());
|
||||
;
|
||||
$cn->rollback();
|
||||
}
|
||||
|
||||
}
|
||||
//************************************
|
||||
// Modify the menu or delete it
|
||||
|
|
@ -113,18 +151,16 @@ if ( isset($_POST['delete_profil']))
|
|||
if (isset($_POST['mod']))
|
||||
{
|
||||
extract($_POST);
|
||||
if (isset($delete) || isset ($del_dep))
|
||||
if (isset($delete) || isset($del_dep))
|
||||
{
|
||||
try
|
||||
{
|
||||
$cn->start();
|
||||
if ( isset ($del_dep))
|
||||
{
|
||||
$cn->exec_sql("delete from profile_menu where pm_id in (select * from get_menu_dependency($1))",
|
||||
array($pm_id));
|
||||
}
|
||||
$cn->exec_sql("delete from profile_menu where pm_id=$1",
|
||||
array($pm_id));
|
||||
if (isset($del_dep))
|
||||
{
|
||||
$cn->exec_sql("delete from profile_menu where pm_id in (select * from get_menu_dependency($1))", array($pm_id));
|
||||
}
|
||||
$cn->exec_sql("delete from profile_menu where pm_id=$1", array($pm_id));
|
||||
$cn->commit();
|
||||
}
|
||||
catch (Exception $exc)
|
||||
|
|
@ -132,11 +168,11 @@ if (isset($_POST['mod']))
|
|||
echo $exc->getMessage();
|
||||
$cn->rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
try
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* Printing cannot be a menu and do not depend of anything
|
||||
*/
|
||||
$menu_type = $cn->get_value("select me_type from menu_ref
|
||||
|
|
@ -173,9 +209,9 @@ if (isset($_POST['mod']))
|
|||
//****************************************************
|
||||
// Add a menu, module, submenu,plugin...
|
||||
//****************************************************
|
||||
if ( isset ($_POST['add_menu']))
|
||||
if (isset($_POST['add_menu']))
|
||||
{
|
||||
extract ($_POST);
|
||||
extract($_POST);
|
||||
try
|
||||
{
|
||||
$cn->start();
|
||||
|
|
@ -183,47 +219,44 @@ if ( isset ($_POST['add_menu']))
|
|||
/**
|
||||
* Printing cannot be a menu and do not depend of anything
|
||||
*/
|
||||
$menu_type=$cn->get_value("select me_type from menu_ref
|
||||
where me_code=$1",array($me_code));
|
||||
$menu_type = $cn->get_value("select me_type from menu_ref
|
||||
where me_code=$1", array($me_code));
|
||||
|
||||
if ($menu_type=='PR')
|
||||
if ($menu_type == 'PR')
|
||||
{
|
||||
$p_type='P';
|
||||
$me_code_dep=-1;
|
||||
$p_type = 'P';
|
||||
$me_code_dep = -1;
|
||||
}
|
||||
|
||||
// Module never depends of anything
|
||||
if ($p_type=='M')
|
||||
if ($p_type == 'M')
|
||||
{
|
||||
$me_code_dep=-1;
|
||||
$me_code_dep = -1;
|
||||
}
|
||||
/**
|
||||
* Check for infinite loop
|
||||
*/
|
||||
$inf=$cn->get_value("select count(*) from profile_menu
|
||||
where p_id=$1 and me_code_dep=$2 and me_code=$3",
|
||||
array($p_id,$me_code,$me_code_dep));
|
||||
if ( $inf > 0 ) throw new Exception("Boucle infinie");
|
||||
/**
|
||||
$inf = $cn->get_value("select count(*) from profile_menu
|
||||
where p_id=$1 and me_code_dep=$2 and me_code=$3", array($p_id, $me_code, $me_code_dep));
|
||||
if ($inf > 0)
|
||||
throw new Exception("Boucle infinie");
|
||||
/**
|
||||
* if me_code_dep == -1, it means it is null
|
||||
*/
|
||||
$me_code_dep=($me_code_dep==-1)?null:$me_code_dep;
|
||||
$me_code_dep = ($me_code_dep == -1) ? null : $me_code_dep;
|
||||
|
||||
$pm_default=(isset($pm_default))?1:0;
|
||||
$pm_default = (isset($pm_default)) ? 1 : 0;
|
||||
$cn->exec_sql("
|
||||
insert into profile_menu (me_code,me_code_dep,p_id,p_order,pm_default,p_type_display)
|
||||
values ($1,$2,$3,$4,$5,$6)
|
||||
",array($me_code,$me_code_dep,$p_id,$p_order,$pm_default,$p_type));
|
||||
", array($me_code, $me_code_dep, $p_id, $p_order, $pm_default, $p_type));
|
||||
|
||||
$cn->commit();
|
||||
|
||||
}
|
||||
catch (Exception $exc)
|
||||
{
|
||||
alert($exc->getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
echo '<div id="list_profile" class="content">';
|
||||
|
|
@ -240,7 +273,7 @@ $ord = (isset($_REQUEST['ord'])) ? $_REQUEST['ord'] : 'na';
|
|||
$order = $table->get_sql_order($ord);
|
||||
|
||||
$menu = new Profile_sql($cn);
|
||||
$ret = $menu->seek($order);
|
||||
$ret = $menu->seek("where p_id > 0 ".$order);
|
||||
echo '<table class="result">';
|
||||
echo '<tr>';
|
||||
echo '<th>' . $table->get_header(0) . '</th>';
|
||||
|
|
@ -263,7 +296,7 @@ for ($i = 0; $i < Database::num_row($ret); $i++)
|
|||
}
|
||||
$js = sprintf('<a href="javascript:void(0)" class="button" onclick="get_profile_detail(\'%s\',\'%s\')">', $gDossier, -1);
|
||||
echo '<tr>';
|
||||
echo "<td>".$js."Ajouter un profil </td>";
|
||||
echo "<td>" . $js . "Ajouter un profil </td>";
|
||||
echo '</tr>';
|
||||
echo '</table>';
|
||||
echo '</div>';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue