29 require_once NOALYSS_INCLUDE.
'/constant.php';
30 require_once NOALYSS_INCLUDE.
'/lib/user_common.php';
31 require_once NOALYSS_INCLUDE.
'/lib/ac_common.php';
65 return "User ".print_r($this,
true);
73 $can_connect=
$cn->get_value(
"select count(*) from ac_users
74 where use_active=1 and
75 use_login=$1 and use_pass=$2",
76 [$this->login,$this->password]);
84 if (!isset($_SESSION[SESSION_KEY.
'g_user']))
86 $http=new \HttpInput();
87 $user_login=
$http->request(
"p_user",
"string",
"");
92 $_SESSION[SESSION_KEY.
"g_user"]=$user_login;
97 echo
'<h2 class="error">'._(
'Session expirée<br>Utilisateur déconnecté').
'</h2>';
103 if (strpos($user_login,
'@mobile')!=
false)
105 $this->access_mode=
'MOBILE';
106 $this->login=str_ireplace(
"@mobile",
"", $user_login);
110 $this->access_mode=
'PC';
111 $this->login=strtolower($user_login);
117 $this->login=$_SESSION[SESSION_KEY.
"g_user"];
118 $this->password=$_SESSION[SESSION_KEY.
'g_pass'];
121 $this->lang=(isset($_SESSION[SESSION_KEY.
'g_lang']))?$_SESSION[SESSION_KEY.
'g_lang']:
'fr_FR.utf8';
122 $this->access_mode=$_SESSION[SESSION_KEY.
"access_mode"];
127 echo
'<h2 class="error">'._(
'Utilisateur ou mot de passe incorrect').
'</h2>';
128 $sql=
"insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
130 array($_SESSION[SESSION_KEY.
'g_user'], $_SERVER[
"REMOTE_ADDR"],
"DISCON",
131 $_SERVER[
'REQUEST_URI'],
'FAIL'));
139 $_SESSION[SESSION_KEY.
'g_lang']=$this->lang;
140 $this->valid=(isset($_SESSION[SESSION_KEY.
'isValid']))?1:0;
141 if (isset($_SESSION[SESSION_KEY.
'g_theme']))
143 $this->theme=$_SESSION[SESSION_KEY.
'g_theme'];
339 $sql_cond=
" where lower(use_login)=lower($1)";
344 $sql_cond=
" where use_id=$1";
361 $this->
id=
$row[
'use_id'];
362 $this->first_name=
$row[
'use_first_name'];
363 $this->last_name=
$row[
'use_name'];
365 $this->active=
$row[
'use_active'];
366 $this->login=strtolower(
$row[
'use_login']);
367 $this->admin=
$row[
'use_admin'];
368 $this->password=
$row[
'use_pass'];
369 $this->email=
$row[
'use_email'];
376 $Sql=
"update ac_users set use_first_name=$1, use_name=$2
377 ,use_active=$3,use_admin=$4,use_pass=$5 ,use_email = $7 where use_id=$6";
380 array($this->first_name, $this->last_name, $this->active, $this->admin, $this->password,
381 $this->
id, $this->email));
387 $Sql=
"INSERT INTO ac_users(
388 use_first_name, use_name, use_login, use_active,
389 use_admin, use_pass, use_email)
390 VALUES ($1, $2, $3, $4, $5, $6, $7) returning use_id";
393 $this->
id=
$cn->get_value($Sql,
394 array($this->first_name, $this->last_name, $this->login, 1, $this->admin,
395 $this->password, $this->email));
412 $sql=
"select ac_users.use_login,ac_users.use_active, ac_users.use_pass,
413 use_admin,use_first_name,use_name
415 where ac_users.use_id=$1
416 and ac_users.use_active=1
417 and ac_users.use_pass=$2";
418 $ret=
$cn->exec_sql(
$sql, array($this->
id, $pass5));
423 $_SESSION[SESSION_KEY.
'use_admin']=
$r[
'use_admin'];
424 $_SESSION[SESSION_KEY.
'use_name']=
$r[
'use_name'];
425 $_SESSION[SESSION_KEY.
'use_first_name']=
$r[
'use_first_name'];
426 $_SESSION[SESSION_KEY.
'isValid']=1;
428 $this->admin=$_SESSION[SESSION_KEY.
'use_admin'];
429 $this->
name=$_SESSION[SESSION_KEY.
'use_name'];
430 $this->first_name=$_SESSION[SESSION_KEY.
'use_first_name'];
433 $sql=
"insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
438 array($_SESSION[SESSION_KEY.
'g_user'], $_SERVER[
"REMOTE_ADDR"],
439 $from, $_SERVER[
'REQUEST_URI'],
'FAIL'));
442 echo
'<script> alert(\''._(
'Utilisateur ou mot de passe incorrect').
'\')</script>
';
443 redirect('index.html
');
451 if ($from=='LOGIN
' || $from=='PORTAL
')
454 array($_SESSION[SESSION_KEY.'g_user
'], $_SERVER["REMOTE_ADDR"], $from,
455 $_SERVER['REQUEST_URI
'], 'SUCCESS
'));
472 function get_folder_access($p_dossier=0)
476 $p_dossier=dossier::id();
481 $sql="select 'R
' from jnt_use_dos where use_id=$1 and dos_id=$2";
483 $res=$cn->get_value($sql, array($this->id, $p_dossier));
485 if ($cn->get_affected()==0)
495 function set_folder_access($db_id, $priv)
501 // the access is granted
502 $jnt=$cn->get_value("select jnt_id from jnt_use_dos where dos_id=$1 and use_id=$2", array($db_id, $this->id));
507 $Res=$cn->exec_sql("insert into jnt_use_dos(dos_id,use_id) values($1,$2)", array($db_id, $this->id));
513 $cn->exec_sql('
delete from jnt_use_dos where use_id = $1 and dos_id = $2
', array($this->id, $db_id));
529 function get_ledger_access($p_ledger)
531 if ($this->admin==1||
532 $this->is_local_admin(dossier::id())==1||$this->get_status_security_ledger()==0)
535 $sql="select uj_priv from user_sec_jrn where uj_login=$1 and uj_jrn_id=$2";
536 $res=$this->db->get_value($sql, array($this->login, $p_ledger));
560 function get_ledger($p_type='
ALL', $p_access=3, $disable=TRUE)
562 $p_type=strtoupper($p_type);
563 if (!in_array($p_type, ["FIN", "ALL", "ODS", "VEN", 'ACH
']))
565 record_log(sprintf("UGL1, p_type %s", $p_type));
566 throw new Exception("UGL1"._("Type incorrecte"));
574 $sql_enable="and jrn_enable=1";
576 if ($this->admin!=1&&$this->is_local_admin()!=1&&$this->get_status_security_ledger()==1)
578 $sql_type=($p_type=='ALL')?'':"and jrn_def_type=upper('".sql_string($p_type)."')";
582 $sql_access=" and uj_priv!= 'X
' ";
585 $sql_access=" and uj_priv = 'W
' and jrn_enable=1 ";
589 $sql_access=" and ( uj_priv = 'R
' or uj_priv='W
') ";
593 $sql="select jrn_def_id,jrn_def_type,
594 jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc,uj_priv,
595 jrn_deb_max_line,jrn_cred_max_line,jrn_def_description,jrn_enable
596 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
597 join user_sec_jrn on uj_jrn_id=jrn_def_id
599 uj_login='".$this->login."'".
600 $sql_type.$sql_access.$sql_enable.
601 " order by jrn_Def_name";
605 $sql_type=($p_type=='ALL')?' '.$sql_enable:"where jrn_def_type=upper('".sql_string($p_type)."') ".$sql_enable;
606 $sql="select jrn_def_id,jrn_def_type,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_deb_max_line,jrn_cred_max_line,
607 jrn_type_id,jrn_desc,'W
' as uj_priv,jrn_def_description,jrn_enable
608 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
610 order by jrn_Def_name";
612 $res=$this->db->exec_sql($sql);
613 if (Database::num_row($res)==0)
615 $array=Database::fetch_all($res);
626 function get_ledger_sql($p_type='
ALL', $p_access=3)
628 $aLedger=$this->get_ledger($p_type, $p_access);
630 return ' jrn_def_id < 0
';
631 $sql=" jrn_def_id in (";
632 foreach ($aLedger as $row)
634 $sql.=$row['jrn_def_id
'].',
';
646 return $this->isAdmin();
657 $pass5=$this->password;
658 $sql="select count(*) from ac_users where use_login=$1
659 and use_active=1 and use_admin=1 ";
662 $this->admin=$cn->get_value($sql, array($this->login));
673 function set_periode($p_periode)
675 $sql="update user_local_pref set parameter_value=$1 where user_id=$2 and parameter_type='PERIODE
'";
676 $Res=$this->db->exec_sql($sql, [$p_periode, $this->id]);
679 private function set_default_periode()
682 /* get the first periode */
683 $sql='select min(
p_id) as pid
'
684 .' from parm_periode
'
685 .' where p_closed =
false and p_start = (select min(p_start)
from parm_periode)
';
686 $Res=$this->db->exec_sql($sql);
688 $pid=Database::fetch_result($Res, 0, 0);
689 /* if all the periode are closed, then we use the last closed period */
692 $sql='select min(
p_id) as pid
'
693 .'from parm_periode
'
694 .'where p_start = (select max(p_start)
from parm_periode)
';
695 $Res2=$this->db->exec_sql($sql);
696 $pid=Database::fetch_result($Res2, 0, 0);
699 throw new Exception(_("Aucune période trouvéee !!!"));
702 $pid=Database::fetch_result($Res2, 0, 0);
705 $sql=sprintf("insert into user_local_pref (user_id,parameter_value,parameter_type)
706 values ('%s
','%d
','PERIODE
')", $this->id, $pid);
707 $Res=$this->db->exec_sql($sql);
717 function get_periode()
720 $array=$this->get_preference();
721 if (!isset($array['PERIODE
']))
723 $this->set_default_periode();
724 $array=$this->get_preference();
726 return $array['PERIODE
'];
734 function get_mini_report()
736 $array=$this->get_preference();
737 $fr_id=(isset($array['MINIREPORT
']))?$array['MINIREPORT
']:0;
744 function set_mini_report($p_id)
746 $count=$this->db->get_value("select count(*) from user_local_pref where user_id=$1 and parameter_type=$2",
747 array($this->id, 'MINIREPORT
'));
750 $sql="update user_local_pref set parameter_value=$1 where user_id=$2 and parameter_type='MINIREPORT
'";
751 $Res=$this->db->exec_sql($sql, array($p_id, $this->id));
755 $sql="insert into user_local_pref (user_id,parameter_type,parameter_value)".
756 "values($1,'MINIREPORT
',$2)";
757 $Res=$this->db->exec_sql($sql, array($this->id, $p_id));
767 function save_global_preference($key, $value)
769 $repo=new Database();
770 $count=$repo->get_value("select count(*)
774 parameter_type=$1 and user_id=$2", array($key, $this->login));
777 $repo->exec_sql("update user_global_pref set parameter_value=$1
778 where parameter_type=$2 and user_id=$3", array($value, $key, $this->login));
782 $repo->exec_sql("insert into user_global_pref(user_id,parameter_type,parameter_value)
783 values($1,$2,$3)", array($this->login, $key, $value));
791 function get_preference()
793 $sql="select parameter_type,parameter_value from user_local_pref where user_id=$1";
794 $Res=$this->db->exec_sql($sql, array($this->id));
796 for ($i=0; $i<Database::num_row($Res); $i++)
798 $row=Database::fetch_array($Res, $i);
799 $type=$row['parameter_type
'];
800 $l_array[$type]=$row['parameter_value
'];
802 $repo=new Database();
803 $a_global_pref=$repo->get_array("select parameter_type,parameter_value from user_global_pref
805 upper(user_id) = upper($1)", [$this->login]);
806 $nb_global=count($a_global_pref);
807 for ($i=0; $i<$nb_global; $i++)
809 $idx=$a_global_pref[$i]['parameter_type
'];
810 $value=$a_global_pref[$i]['parameter_value
'];
811 $l_array[$idx]=$value;
823 function check_module($p_module)
825 if ( $this->access_mode == "PC") {
827 $acc=$this->db->get_value("select count(*) from v_all_menu where p_id = $1
828 and me_code=$2", array($this->get_profile(), $p_module));
829 } elseif ($this->access_mode=="MOBILE") {
830 $acc=$this->db->get_value("select count(*) from profile_mobile where p_id=$1 and me_code=$2",
831 array($this->get_profile(), $p_module));
833 throw new Exception("USER:823:ACCESS_MODE INCONNU");
837 $this->audit("FAIL", $p_module);
840 $this->audit("SUCCESS", $p_module);
852 function check_action($p_action_id)
854 /* save it into the log */
856 if ($this->Admin()==1)
858 if ($this->is_local_admin(dossier::id())==1)
860 if ($this->get_status_security_action()==0)
862 $Res=$this->db->exec_sql(
863 "select * from user_sec_act where ua_login=$1 and ua_act_id=$2", array($this->login, $p_action_id));
864 $Count=Database::num_row($Res);
867 if (isset($audit)&&$audit==true)
870 $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
872 array($_SESSION[SESSION_KEY.'g_user
'], $_SERVER["REMOTE_ADDR"], $p_action_id, $_SERVER['REQUEST_URI
'],
879 echo_error(_("Action invalide"));
880 record_log("User:check_action".sprintf("login %s ua_act_id %s", $this->login, $p_action_id));
890 function load_global_pref()
893 // Load everything in an array
894 $Res=$cn->exec_sql("select parameter_type,parameter_value from
896 where user_id=$1", [$this->login]);
897 $Max=Database::num_row($Res);
900 $this->insert_default_global_pref();
901 $this->load_global_pref();
904 // Load value into array
906 for ($i=0; $i<$Max; $i++)
908 $row=Database::fetch_array($Res, $i);
909 $type=$row['parameter_type
'];
910 $line[$type]=$row['parameter_value
'];
912 // save array into g_ variable
913 $array_pref=array('g_theme
'=>'THEME
',
914 'g_pagesize
'=>'PAGESIZE
',
915 'g_topmenu
'=>'TOPMENU
',
917 'csv_fieldsep
'=>'csv_fieldsep
',
918 'csv_decimal
'=>'csv_decimal
',
919 'csv_encoding
'=>'csv_encoding
',
920 'first_week_day
'=>'first_week_day
');
922 foreach ($array_pref as $name=> $parameter)
924 if (!isset($line[$parameter]))
926 $this->insert_default_global_pref($parameter);
927 $this->load_global_pref();
930 $_SESSION[SESSION_KEY.$name]=$line[$parameter];
942 function insert_default_global_pref($p_type="", $p_value="")
945 $default_parameter=array("THEME"=>"classic",
948 'LANG
'=>'fr_FR.utf8
',
951 'csv_encoding
'=>'utf8
',
955 $sql="insert into user_global_pref(user_id,parameter_type,parameter_value)
959 foreach ($default_parameter as $name=> $value)
961 $cn->exec_sql($sql, array($this->login, $name, $value));
966 $value=($p_value=="")?$default_parameter[$p_type]:$p_value;
967 if ( $cn->get_value("select count(*) from user_global_pref where user_id=$1 and parameter_type=$2",
968 array($this->login,$p_type)) == 1)
970 $cn->exec_sql("update user_global_pref set parameter_value=$1 where user_id=$2 and parameter_type=$3",
971 array($value,$this->login,$p_type));
973 $cn->exec_sql($sql, array($this->login, $p_type, $value));
985 function update_global_pref($p_type, $p_value="")
987 $default_parameter=array("THEME"=>"classic",
989 "LANG"=>'fr_FR.utf8
',
993 'csv_encoding
'=>'utf8
',
997 $Sql="update user_global_pref set parameter_value=$1
998 where parameter_type=$2 and
1000 $value=($p_value=="")?$default_parameter[$p_type]:$p_value;
1001 $cn->exec_sql($Sql, array($value, $p_type, $this->login));
1005 /* * \brief Return the year of current Periode
1006 * it is the parm_periode.p_exercice col
1007 * if an error occurs return 0
1010 function get_exercice()
1012 $sql="select p_exercice from parm_periode where p_id=$1";
1013 $Ret=$this->db->exec_sql($sql,[$this->get_periode()]);
1014 if (Database::num_row($Ret)==1)
1016 $r=Database::fetch_array($Ret, 0);
1017 return $r['p_exercice
'];
1023 /* * \brief Check if the user can access
1024 * otherwise warn and exit
1025 * \param $p_action requested action
1026 * \param $p_js = 1 javascript, or 0 just a text or 2 to log it silently
1027 * \return nothing the program exits automatically
1030 function can_request($p_action, $p_js=0)
1032 if ($this->check_action($p_action)==0)
1034 $this->audit('FAIL
');
1037 echo create_script("alert_box(content[59])");
1041 record_log(_("Access invalid").$p_action);
1045 echo '<
h2 class=
"error">
',
1046 htmlspecialchars(_("Cette action ne vous est pas autorisée Contactez votre responsable")),
1060 function check_print($p_action)
1063 $this->audit('AUDIT
', $p_action);
1064 if ($this->Admin()==1)
1067 $res=$cn->get_value("select count(*) from profile_menu
1068 join profile_user using (p_id)
1069 where user_name=$1 and me_code=$2 ", array($this->login, $p_action));
1073 /* * \brief Check if the user can print (in menu_ref p_type_display=p)
1074 * otherwise warn and exit
1075 * \param $p_action requested action
1076 * \return nothing the program exits automatically
1079 function can_print($p_action, $p_js=0)
1081 if ($this->check_print($p_action)==0)
1083 $this->audit('FAIL
');
1086 echo create_script("alert_box(content[59])");
1090 echo '<div
class=
"redcontent">
';
1091 echo '<
h2 class=
"error">
',
1092 htmlspecialchars(_("Cette action ne vous est pas autorisée Contactez votre responsable")),
1112 function is_local_admin($p_dossier=-1)
1123 function get_available_repository($p_access='R
')
1125 $profile=$this->get_profile();
1129 $r=$this->db->get_array("select distinct u.r_id,r_name
1131 profile_sec_repository as u
1132 join stock_repository as s on(u.r_id=s.r_id)
1137 ", array($profile));
1141 $r=$this->db->get_array("select distinct u.r_id,r_name
1143 profile_sec_repository as u
1144 join stock_repository as s on(u.r_id=s.r_id)
1147 ", array($profile));
1167 static function get_list($p_dossier)
1169 $sql="select distinct use_id,use_login,use_first_name,use_name from ac_users
1170 left outer join jnt_use_dos using (use_id)
1172 (dos_id=$1 and use_active=1) or (use_active=1 and use_admin=1)
1173 order by use_login,use_name";
1175 $repo=new Database();
1176 $array=$repo->get_array($sql, array($p_dossier));
1177 if ($repo->size()==0)
1178 throw new Exception('Error inaccessible folder
');
1193 function check_jrn($p_jrn)
1195 return $this->get_ledger_access($p_jrn);
1209 function check_dossier($p_dossier_id, $silent=false)
1212 if ($this->admin==1||$this->is_local_admin($p_dossier_id)==1)
1216 $dossier=$cn->get_value("select 'R
' from jnt_use_dos where dos_id=$1 and use_id=$2",
1217 array($p_dossier_id, $this->id));
1218 $dossier=($dossier=='')?'X
':$dossier;
1221 $this->audit('FAIL
', "Access folder ");
1224 alert(_('Dossier non accessible
'));
1235 function get_limit_current_exercice()
1237 $current_exercice=$this->get_exercice();
1238 $periode=new Periode($this->db);
1239 list($per_start, $per_end)=$periode->get_limit($current_exercice);
1240 $start=$per_start->first_day();
1241 $end=$per_end->last_day();
1242 return array($start, $end);
1254 function show_dossier($p_filtre="")
1256 $p_array=$this->get_available_folder($p_filtre);
1260 $result.="<TABLE id=\"folder\" class=\"result\">";
1269 $result.=_("Description");
1275 $result.='<
td style=
"width:auto" colspan=3>
';
1276 $result.=_("Aucun dossier disponible");
1282 for ($i=0; $i<sizeof($p_array); $i++)
1285 $id=$p_array[$i]['dos_id
'];
1286 $name=$p_array[$i]['dos_name
'];
1287 $desc=$p_array[$i]['dos_description
'];
1292 $target="do.php?gDossier=$id";
1294 $result.="<TR class=\"$tr\">";
1296 $result.=td($id, ' class=
"num" ');
1297 $result.="<TD class=\"$tr\">";
1298 $result.="<A class=\"dossier\" HREF=\"$target\">";
1299 $result.=" <B>".h($name)."</B>";
1302 $desc=($desc=="")?"<i>Aucune description</i>":h($desc);
1303 $desc="<A class=\"dossier\" HREF=\"$target\">$desc</A>";
1304 $result.="<TD class=\"$tr\" >".$desc;
1308 $result.="</TABLE>";
1323 function get_available_folder($p_filter="")
1327 if ($this->admin==0)
1329 // show only available folders
1330 // if user is not an admin
1331 $Res=$cn->exec_sql("select
1332 distinct dos_id,dos_name,dos_description
1334 natural join jnt_use_dos
1335 natural join ac_dossier
1339 and ( dos_name ilike '%
' || $2 || '%
' or dos_description ilike '%
' || $2 || '%
' )
1340 order by dos_name", array($this->login, $p_filter));
1344 $Res=$cn->exec_sql("select
1345 distinct dos_id,dos_name,dos_description from ac_dossier
1347 dos_name ilike '%
' || $1|| '%
' or dos_description ilike '%
' || $1 || '%
'
1348 order by dos_name", array($p_filter));
1351 $max=Database::num_row($Res);
1355 for ($i=0; $i<$max; $i++)
1357 $array[]=Database::fetch_array($Res, $i);
1366 static function audit_admin($p_module)
1369 $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
1373 $_SESSION[SESSION_KEY.'g_user
'],
1374 $_SERVER["REMOTE_ADDR"],
1376 $_SERVER['REQUEST_URI
'],
1380 function audit($action='AUDIT
', $p_module="")
1385 if ($p_module==""&&isset($_REQUEST['ac
']))
1387 $p_module=$_REQUEST['ac
'];
1390 if (isset($_REQUEST['gDossier
']))
1391 $p_module.=" dossier : ".$_REQUEST['gDossier
'];
1392 $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
1396 $_SESSION[SESSION_KEY.'g_user
'],
1397 $_SERVER["REMOTE_ADDR"],
1399 $_SERVER['REQUEST_URI
'],
1404 function save_profile($p_id)
1406 $count=$this->db->get_value("select count(*) from profile_user where user_name=$1", array($this->login));
1409 $this->db->exec_sql("insert into profile_user(p_id,user_name)
1410 values ($1,$2)", array($p_id, $this->login));
1414 $this->db->exec_sql("update profile_user set p_id=$1 where user_name=$2", array($p_id, $this->login));
1422 function get_profile()
1424 $profile=$this->db->get_value("select p_id from profile_user where
1425 lower(user_name)=lower($1) ", array($this->login));
1437 function sql_writable_profile()
1439 if ($this->admin!=1)
1441 $sql=" (select p_granted "
1442 ." from user_sec_action_profile "
1443 ." where ua_right in ('W
','O
') and p_id=".$this->get_profile().") ";
1447 $sql="(select p_id p_granted from profile)";
1455 function get_writable_profile()
1457 $value=$this->db->get_array("select p_granted from ".$this->sql_writable_profile()." as m") ;
1458 $aGranted=array_column($value,"p_granted");
1465 function get_readable_profile()
1467 $value=$this->db->get_array("select p_granted from ".$this->sql_readable_profile()." as m") ;
1468 $aGranted=array_column($value,"p_granted");
1478 function sql_readable_profile()
1480 if ($this->admin!=1)
1482 $sql=" (select p_granted "
1483 ." from user_sec_action_profile "
1484 ." where ua_right in ('W
','R
','O
') and p_id=".$this->get_profile().") ";
1488 $sql="(select p_id p_granted from profile)";
1499 function can_add_action($p_profile)
1501 $r=$this->db->get_value(' select count(*)
1502 from user_sec_action_profile
1504 and
p_id=$1
', array($this->get_profile(), $p_profile));
1517 function can_write_action($dtoc)
1519 if ($this->Admin()==1)
1521 if ($this->get_status_security_action()==0)
1523 $profile=$this->get_profile();
1524 $r=$this->db->get_value(" select count(*) from action_gestion where ag_id=$1 and ag_dest in
1525 (select p_granted from user_sec_action_profile where ua_right in ('W
','O
') and p_id=$2) ", array($dtoc, $profile));
1536 function can_delete_action($dtoc)
1538 if ($this->Admin()==1)
1540 if ($this->get_status_security_action()==0)
1542 $profile=$this->get_profile();
1543 $r=$this->db->get_value(" select count(*) from action_gestion where ag_id=$1 and ag_dest in
1544 (select p_granted from user_sec_action_profile where ua_right='W
' and p_id=$2) ", array($dtoc, $profile));
1555 function can_read_action($dtoc)
1557 if ($this->Admin()==1)
1559 $profile=$this->get_profile();
1560 $r=$this->db->get_value(" select count(*) from action_gestion where ag_id=$1 and (ag_dest in
1561 (select p_granted from user_sec_action_profile where p_id=$2) or ag_owner=$3)",
1562 array($dtoc, $profile, $this->login));
1573 function can_write_repo($p_repo)
1575 if ($this->Admin()==1)
1577 $profile=$this->get_profile();
1578 $r=$this->db->get_value("select count(*)
1579 from profile_sec_repository
1583 and ur_right='W
'", array($p_repo, $profile));
1594 function can_read_repo($p_repo)
1596 if ($this->Admin()==1)
1598 $profile=$this->get_profile();
1599 $r=$this->db->get_value("select count(*)
1600 from profile_sec_repository
1604 ", array($p_repo, $profile));
1612 function password_to_session()
1614 $_SESSION[SESSION_KEY.'g_pass
']=$this->getPassword();
1622 function save_password($p_pass1, $p_pass2)
1624 if ($p_pass1==$p_pass2)
1626 $repo=new Database();
1627 $l_pass=md5($p_pass1);
1628 $this->setPassword($l_pass);
1629 $repo->exec_sql("update ac_users set use_pass=$1 where use_login=$2",
1630 array($l_pass, $this->login));
1644 function save_email($p_email)
1646 $repo=new Database();
1647 $repo->exec_sql("update ac_users set use_email=$1 where use_login=$2",
1648 array($p_email, $_SESSION[SESSION_KEY.'g_user
']));
1657 static function revoke_access($p_login, $p_dossier)
1659 // connect to the repository
1660 $repo_cnx=new Database();
1662 // Retrieve the user
1663 $user=$repo_cnx->get_array('select use_id,use_login
from ac_users where use_login=$1
', array($p_login));
1667 // remove him from jnt_use_dos
1668 $repo_cnx->exec_sql("delete from jnt_use_dos WHERE use_id=$1 and dos_id=$2",
1669 array($user[0]['use_id
'], $p_dossier));
1671 // Remove user from user's dossier
1672 $cn_dossier=
new Database($p_dossier);
1673 $cn_dossier->exec_sql(
"delete from profile_user where user_name=$1", array($p_login));
1674 $cn_dossier->exec_sql(
"delete from user_sec_act where ua_login=$1", array($p_login));
1684 $user=$repo_cnx->get_array(
"select use_id,use_login
1686 where use_login=$1", array($p_login));
1690 $cn_dossier=
new Database($p_dossier);
1693 $repo_cnx->get_value(
"select count(*) from jnt_use_dos where use_id=$1 and dos_id=$2",
1694 array($user[0][
'use_id'], $p_dossier))==0
1697 $repo_cnx->exec_sql(
"insert into jnt_use_dos(use_id,dos_id) values ($1,$2)",
1698 array($user[0][
'use_id'], $p_dossier));
1701 if ($cn_dossier->get_value(
"select count(*) from profile_user where user_name=$1", array($user[0][
'use_login']))==0)
1703 $cn_dossier->exec_sql(
'insert into profile_user(user_name,p_id) values($1,1)', array($user[0][
'use_login']));
1706 $cn_dossier->exec_sql(
"delete from user_sec_act where ua_login=$1", array($p_login));
1708 $cn_dossier->exec_sql(
"insert into user_sec_act (ua_login,ua_act_id)"
1709 .
" select $1 ,ac_id from action ", array($p_login));
1711 $cn_dossier->exec_sql(
"delete from user_sec_jrn where uj_login=$1", array($p_login));
1712 $cn_dossier->exec_sql(
"insert into user_sec_jrn(uj_login,uj_jrn_id,uj_priv)"
1713 .
" select $1,jrn_def_id,'W' from jrn_def", array($p_login));
1719 $name=$cnx_repo->format_name($p_dossier,
'dos');
1720 if ($cnx_repo->exist_database(
$name)==0)
1722 $cnx_dossier=
new Database($p_dossier);
1723 if ($cnx_dossier->exist_table(
'profile_user'))
1724 $a_user=$cnx_dossier->get_array(
'select user_name from profile_user');
1733 if ($cnx_repo->get_value(
'select count(*) from ac_users where use_login=$1', array($a_user[
$i][
'user_name']))==0)
1735 if ($cnx_dossier->exist_table(
'user_sec_jrn'))
1736 $cnx_dossier->exec_sql(
"delete from user_sec_jrn where uj_login=$1", array($a_user[
$i][
'user_name']));
1737 $cnx_dossier->exec_sql(
"delete from profile_user where user_name=$1", array($a_user[
$i][
'user_name']));
1738 if ($cnx_dossier->exist_table(
'user_sec_act'))
1739 $cnx_dossier->exec_sql(
"delete from user_sec_act where ua_login=$1", array($a_user[
$i][
'user_name']));
1740 if ($cnx_dossier->exist_table(
'user_sec_jrn'))
1741 $cnx_dossier->exec_sql(
"delete from user_sec_jrn where uj_login=$1", array($a_user[
$i][
'user_name']));
1742 if ($cnx_dossier->exist_table(
'user_active_security'))
1743 $cnx_dossier->exec_sql(
"delete from user_active_security where us_login=$1",
1744 array($a_user[
$i][
'user_name']));
1755 $security=$this->
db->get_value(
"select us_ledger from user_active_security
1757 us_login=$1", [$this->login]);
1758 $n_security=($security==
"Y")?1:0;
1769 if ($p_value!=0&&$p_value!=1)
1770 throw new Exception(_(
"Valeur invalide"));
1771 $exist=$this->
db->get_value(
"select count(*) from user_active_security where us_login=$1", [$this->login]);
1772 $flag=($p_value==1)?
"Y":
"N";
1775 $this->
db->exec_sql(
"insert into user_active_security (us_login,us_ledger,us_action) values ($1,$2,$3)",
1776 [$this->login, $flag,
'Y']);
1780 $this->
db->exec_sql(
"update user_active_security set us_ledger=$1 where us_login = $2",
1781 [$flag, $this->login]);
1791 $security=$this->
db->get_value(
"select us_action from user_active_security
1793 us_login=$1", [$this->login]);
1794 $n_security=($security==
"Y")?1:0;
1805 if ($p_value!=0&&$p_value!=1)
1806 throw new Exception(_(
"Valeur invalide"));
1807 $exist=$this->
db->get_value(
"select count(*) from user_active_security where us_login=$1", [$this->login]);
1808 $flag=($p_value==1)?
"Y":
"N";
1811 $this->
db->exec_sql(
"insert into user_active_security (us_login,us_action,us_ledger) values ($1,$2,$3)",
1812 [$this->login, $flag,
'Y']);
1816 $this->
db->exec_sql(
"update user_active_security set us_action=$1 where us_login = $2",
1817 [$flag, $this->login]);
1827 $result=$repocn->get_value(
"select parameter_value from user_global_pref where parameter_type=$1 and user_id=$2 ",
1828 array(
"first_week_day", $this->login));
1829 if ($repocn->count()==0)
1842 $aSession=$_SESSION;
1843 foreach($aSession as $key =>
$value) {
1844 if(DEBUGNOALYSS>1) { echo
"[$key]=>[$value]";}
1846 if ( strpos($key,SESSION_KEY) === 0) {
1847 unset($_SESSION[$key]);
1848 if(DEBUGNOALYSS>1) { echo
"=> [$key] cleaned";}