noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Noalyss_User Class Reference

Data & function about connected users. More...

+ Collaboration diagram for Noalyss_User:

Public Member Functions

 __construct ($p_cn, $p_id=-1, $repository=null)
 Create an user , load an existing one or if p_id == -1 search for the connected user.
 
 __toString ()
 
 Admin ()
 synomym for isAdmin,
 
 audit ($action='AUDIT', $p_module="")
 
 can_add_action ($p_profile)
 Check if the current user can add an action in the profile given in parameter.
 
 can_connect ()
 check the password and user
 
 can_delete_action ($dtoc)
 Check if the profile of the user can write AND delete for this profile.
 
 can_print ($p_action, $p_js=0)
 Check if the user can print (in menu_ref p_type_display=p) otherwise warn and exit.
 
 can_read_action ($dtoc)
 Check if the profile of the user can write for this profile.
 
 can_read_repo ($p_repo)
 Check if the profile of the user can read for this repository.
 
 can_request ($p_action, $p_js=0)
 Check if the user can access otherwise warn and exit.
 
 can_write_action ($dtoc)
 Check if the profile of the user can write for this profile.
 
 can_write_repo ($p_repo)
 Check if the profile of the user can write for this repository.
 
 Check ($silent=false, $from='')
 Check if user is active and exists in therepository Automatically redirect, it doesn't check if a user can access a folder.
 
 check_action ($p_action_id)
 Check if an user is allowed to do an action.
 
 check_dossier ($p_dossier_id, $silent=false)
 check if an user can access a folder, if he cannot display a dialog box and exit
 
 check_jrn ($p_jrn)
 check the access of an user on a ledger
 
 check_module ($p_module)
 Check if an user can access a module, return 1 if yes, otherwise 0 record in audit log This function works only if user is connected to a Folder.
 
 check_otp ($code)
 check that the OTP code is the one on smartphone returns false if the given does not match the OTP
 
 check_print ($p_action)
 Check if the user can print (in menu_ref p_type_display=p) otherwise warn and exit.
 
 generate_otp ()
 generate OTP secret to store in AC_USER.USE_OTP_SECRET
 
 get_access_mode ()
 access_mode tells what mode must be used : pc or mobile
 
 get_authent_method ()
 retrieve authent_method
 
 get_available_folder ($p_filter="")
 Get all the available folders for the users, checked with the security.
 
 get_available_repository ($p_access='R')
 return array of available repository
 
 get_exercice ()
 Return the year of current Periode it is the parm_periode.p_exercice col if an error occurs return 0.
 
 get_first_week_day ()
 first day in calendar
 
 get_folder_access ($p_dossier=0)
 return the access to a folder,
 
 get_ledger ($p_type='ALL', $p_access=3, $all=TRUE)
 get all the available ledgers for the current user
 
 get_ledger_access ($p_ledger)
 check that a user is valid and the access to the folder
 
 get_ledger_sql ($p_type='ALL', $p_access=3)
 return an sql condition for filtering the permitted ledger
 
 get_limit_current_exercice ()
 return the first date and the last date of the current exercice for the current user
 
 get_otp_secret ()
 
 get_periode ()
 Get the default periode from the user's preferences.
 
 get_preference ()
 Get the default user's preferences.
 
 get_profile ()
 return the profile (p_id)
 
 get_readable_profile ()
 return array of readable action_profile
 
 get_repository ()
 get the repository
 
 get_status_security_action ()
 Check the security on ledger for the user , it returns 1 if the security on ledgers is enabled, otherwise 0.
 
 get_status_security_ledger ()
 Check the security on ledger for the user , it returns 1 if the security on ledgers is enabled, otherwise 0.
 
 get_vat_code_preference ()
 Get preference , either the user see the numeric id for VAT or its code, if the preference doesn't exist by default , 0 is saved in ACCOUNT_REPOSITORY.
 
 get_writable_profile ()
 return array of writable action_profile
 
 getActive ()
 
 getAdmin ()
 
 getDb ()
 
 getEmail ()
 
 getFirstName ()
 
 getId ()
 
 getLogin ()
 
 getName ()
 
 getPassword ()
 
 getValid ()
 
 input_otp ($uuid="", $url="")
 FORM to enter the 6 digit enter by OTP.
 
 insert ()
 
 insert_default_global_pref ($p_type="", $p_value="")
 insert default pref if no parameter are given insert all the existing parameter otherwise only the requested
 
 is_double_identified ()
 check is the double authentication has been successful
 
 is_local_admin ($p_dossier=-1)
 Check if an user is an local administrator.
 
 isAdmin ()
 Check if an user is an admin and check also his password.
 
 load ()
 
 load_global_pref ()
 Get the global preferences from user_global_pref in the account_repository db.
 
 password_to_session ()
 store the password in session
 
 save ()
 
 save_email ($p_email)
 Save the password from PREFERENCE MODULE.
 
 save_global_preference ($key, $value)
 Save the preference , the scope is global, the settings are saved into account_repository.
 
 save_password ($p_pass1, $p_pass2)
 Save the password of the current user.
 
 save_profile ($p_id)
 
 send_code_otp ()
 send a code to the user and save the expected code + UUID in a table OTP_SEND_SECRET
 
 send_link_otp ($base_url=null)
 send an email with link to the user
 
 set_access_mode ($access_mode)
 access_mode tells what mode must be used : pc or mobile
 
 set_authent_method ($authent_method)
 
 set_folder_access ($db_id, $priv)
 save the access of a folder
 
 set_identified ()
 
 set_otp_secret ($otp_secret)
 
 set_periode ($p_periode)
 Set the selected periode in the user's preferences.
 
 set_repository (Database $repository)
 set the repository
 
 set_session_var ()
 put user_login into Postgres config (session), it can be used for tracking users activities
 
 set_status_security_action ($p_value)
 Set the flag in the table user_active_security.
 
 set_status_security_ledger ($p_value)
 Set the flag in the table user_active_security.
 
 setActive ($active)
 
 setAdmin ($admin)
 
 setDb ($db)
 
 setEmail ($email)
 
 setFirstName ($first_name)
 
 setId (int $id)
 
 setLogin (string $login)
 
 setName ($name)
 
 setPassword ($password)
 
 setValid (int $valid)
 
 show_dossier ($p_filtre="")
 Show all the available folder for the users at the login page.
 
 sql_readable_profile ()
 Compute the SQL string for the readable profile, the subselect for p_id , example p_id in $g_user->sql_readable_profile.
 
 sql_writable_profile ()
 Compute the SQL string for the writable profile, the subselect for p_id , example p_id in $g_user->sql_writable_profile.
 
 update_global_pref ($p_type, $p_value="")
 update default pref if value is not given then use the default value
 

Static Public Member Functions

static audit_admin ($p_module, $db_repository=null)
 Audit action from the administration menu.
 
static clean_session ()
 clean the sessions
 
static get_list ($p_dossier, $db_repository=null)
 return an array with all the active users who can access $p_dossier including the global admin.
 
static grant_admin_access ($p_login, $p_dossier, $db_repository=null)
 Grant access to folder, grant administrator profile , all the ledgers and all the action.
 
static remove_inexistant_user ($p_dossier, $db_repository=null)
 cleansing : remove inexistant user
 
static revoke_access ($p_login, $p_dossier, $db_repository=null)
 Remove a user and all his privileges So it cannot connect anymore and all his privileges are removed from the dossier.
 

Data Fields

 $access_mode
 MOBILE or PC depending if when connecting $login contains @mobile.
 
 $active
 1 active , 0 disables
 
 $admin
 is or is not admin
 
 $authent_method
 authentication method use for this user
 
 $db
 database connx to the folder NOT repository
 
 $email
 user's email
 
 $first_name
 
 $id
 in account_repository , ac_users.use_id
 
 $lang
 user's language
 
 $last_name
 user's last_name
 
 $login
 login lower case
 
 $name
 
 $password
 md5 of the password
 
 $theme
 user's CSS Theme
 
 $valid
 is or is not valid
 

Private Member Functions

 connect_user ()
 connect the user and set the $_SESSION variables if not set thanks the $_REQUEST
 
 set_default_periode ()
 

Private Attributes

 $otp_secret
 string use as secret for OTP
 
 $repository
 account_repository (\Database )
 

Detailed Description

Data & function about connected users.

Definition at line 34 of file noalyss_user.class.php.

Constructor & Destructor Documentation

◆ __construct()

Noalyss_User::__construct ( $p_cn,
$p_id = -1,
$repository = null )

Create an user , load an existing one or if p_id == -1 search for the connected user.

To have an empty user, give a p_id smaller than -1 or zero.

Parameters
$p_cnDatabaseCore connection
$p_idif -1 then load the current user, > 0 load the user , = 0 (or < -1 ) means an empty user
$repository( \Database default null) database to repository, if null is given the database will be defined in config.inc.php

Definition at line 64 of file noalyss_user.class.php.

65 {
66 $this->db=$p_cn;
67 if ( $repository == null ) {
68 $this->repository=new Database(0);
69 } else {
70 $this->repository=$repository;
71 }
72
73 // if p_id is not set then check the connected user
74 if ($p_id==-1)
75 {
76 $this->connect_user();
77 $this->set_session_var();
78 }
79 else // if p_id is set get data of another user
80 {
81 $this->id=$p_id;
82 $this->load();
83 }
84 }
set_session_var()
put user_login into Postgres config (session), it can be used for tracking users activities
connect_user()
connect the user and set the $_SESSION variables if not set thanks the $_REQUEST
$repository
account_repository (\Database )
$SecUser db

References $p_id, $repository, connect_user(), db, load(), and set_session_var().

+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

Noalyss_User::__toString ( )

Definition at line 113 of file noalyss_user.class.php.

113 : string
114 {
115 return "User ".print_r($this,true);
116 }

◆ Admin()

Noalyss_User::Admin ( )

synomym for isAdmin,

Deprecated

Definition at line 710 of file noalyss_user.class.php.

710 :int
711 {
712 return $this->isAdmin();
713 }
isAdmin()
Check if an user is an admin and check also his password.

◆ audit()

Noalyss_User::audit ( $action = 'AUDIT',
$p_module = "" )

Definition at line 1432 of file noalyss_user.class.php.

1433 {
1434 global $audit;
1435 $http=new \HttpInput();
1436 if ($audit)
1437 {
1438 if ($p_module==""&&isset($_REQUEST['ac']))
1439 {
1440 $p_module=$_REQUEST['ac'];
1441 }
1442 $dossier=$http->request("gDossier","string",0);
1443 if ( $dossier != 0)
1444 $p_module.=" dossier : ".$dossier;
1445
1446 $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
1447
1448 $this->repository->exec_sql($sql,
1449 array(
1450 $_SESSION[SESSION_KEY.'g_user'],
1451 $_SERVER["REMOTE_ADDR"],
1452 $p_module,
1453 $_SERVER['REQUEST_URI'],
1454 $action));
1455 }
1456 }
if(! $User->is_double_identified()) $audit
check if 2FA is completed
$_REQUEST['ac']

◆ audit_admin()

static Noalyss_User::audit_admin ( $p_module,
$db_repository = null )
static

Audit action from the administration menu.

Connect to the repository of the domain defined in config.inc.php

Parameters
$p_moduledescription of the action
$db_repository( \Database default null) database to repository, if null is given the database will be defined in config.inc.php

Definition at line 1413 of file noalyss_user.class.php.

1414 {
1415 // connect to the repository
1416 if ( $db_repository == null ) {
1417 $repo_cnx=new Database(0);
1418 } else {
1419 $repo_cnx=$db_repository;
1420 }
1421 $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
1422
1423 $repo_cnx->exec_sql($sql,
1424 array(
1425 $_SESSION[SESSION_KEY.'g_user'],
1426 $_SERVER["REMOTE_ADDR"],
1427 $p_module,
1428 $_SERVER['REQUEST_URI'],
1429 'ADMIN'));
1430 }

◆ can_add_action()

Noalyss_User::can_add_action ( $p_profile)

Check if the current user can add an action in the profile given in parameter.

Parameters
type$p_profileprofile.p_id = action_gestion.ag_dest
Returns
boolean

Definition at line 1553 of file noalyss_user.class.php.

1554 {
1555
1556 $r=$this->db->get_value(' select count(*)
1557 from user_sec_action_profile
1558 where p_granted=$2
1559 and p_id=$1', array($this->get_profile(), $p_profile));
1560 if ($r==0)
1561 {
1562 return false;
1563 }
1564 return true;
1565 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
get_profile()
return the profile (p_id)

References from, and p_id.

◆ can_connect()

Noalyss_User::can_connect ( )

check the password and user

Definition at line 120 of file noalyss_user.class.php.

121 {
122
123 $can_connect=$this->repository->get_value("select count(*) from ac_users
124 where use_active=1 and
125 use_login=$1 and use_pass=$2",
126 [$this->login,$this->password]);
127 return $can_connect;
128 }

Referenced by Check().

◆ can_delete_action()

Noalyss_User::can_delete_action ( $dtoc)

Check if the profile of the user can write AND delete for this profile.

Parameters
$dtocaction_gestion.ag_id
Returns
true if he can write otherwise false

Definition at line 1591 of file noalyss_user.class.php.

1592 {
1593 if ($this->Admin()==1)
1594 return TRUE;
1595 if ($this->get_status_security_action()==0)
1596 return TRUE;
1597 $profile=$this->get_profile();
1598 $r=$this->db->get_value(" select count(*) from action_gestion where ag_id=$1 and ag_dest in
1599 (select p_granted from user_sec_action_profile where ua_right='W' and p_id=$2) ", array($dtoc, $profile));
1600 if ($r==0)
1601 return FALSE;
1602 return true;
1603 }
get_status_security_action()
Check the security on ledger for the user , it returns 1 if the security on ledgers is enabled,...
Admin()
synomym for isAdmin,

◆ can_print()

Noalyss_User::can_print ( $p_action,
$p_js = 0 )

Check if the user can print (in menu_ref p_type_display=p) otherwise warn and exit.

Parameters
$p_actionrequested action
Returns
nothing the program exits automatically

Definition at line 1111 of file noalyss_user.class.php.

1112 {
1113 if ($this->check_print($p_action)==0)
1114 {
1115 $this->audit('FAIL');
1116 if ($p_js==1)
1117 {
1118 echo create_script("alert_box(content[59])");
1119 }
1120 else
1121 {
1122 echo '<div class="redcontent">';
1123 echo '<h2 class="error">',
1124 htmlspecialchars(_("Cette action ne vous est pas autorisée Contactez votre responsable")),
1125 '</h2>';
1126 echo '</div>';
1127 }
1128 exit(-1);
1129 }
1130 }
_("actif, passif,charge,...")
if(! isset($_GET['submit_query'])) $p_action
audit($action='AUDIT', $p_module="")
check_print($p_action)
Check if the user can print (in menu_ref p_type_display=p) otherwise warn and exit.
for($e=0; $e< count($afiche); $e++) exit
create_script($p_string)
create the HTML for adding the script tags around of the script

References h2().

+ Here is the call graph for this function:

◆ can_read_action()

Noalyss_User::can_read_action ( $dtoc)

Check if the profile of the user can write for this profile.

Parameters
$dtocaction_gestion.ag_id
Returns
true if he can write otherwise false

Definition at line 1610 of file noalyss_user.class.php.

1611 {
1612 if ($this->Admin()==1)
1613 return true;
1614 $profile=$this->get_profile();
1615 $r=$this->db->get_value(" select count(*) from action_gestion where ag_id=$1 and (ag_dest in
1616 (select p_granted from user_sec_action_profile where p_id=$2) or ag_owner=$3)",
1617 array($dtoc, $profile, $this->login));
1618 if ($r==0)
1619 return false;
1620 return true;
1621 }

◆ can_read_repo()

Noalyss_User::can_read_repo ( $p_repo)

Check if the profile of the user can read for this repository.

Parameters
$p_repostock_repository.r_id
Returns
true if he read write otherwise false

Definition at line 1649 of file noalyss_user.class.php.

1650 {
1651 if ($this->Admin()==1)
1652 return true;
1653 $profile=$this->get_profile();
1654 $r=$this->db->get_value("select count(*)
1655 from profile_sec_repository
1656 where
1657 r_id=$1
1658 and p_id =$2
1659 ", array($p_repo, $profile));
1660 if ($r==0)
1661 return false;
1662 return true;
1663 }

◆ can_request()

Noalyss_User::can_request ( $p_action,
$p_js = 0 )

Check if the user can access otherwise warn and exit.

Parameters
$p_actionrequested action
$p_js= 1 javascript, or 0 just a text or 2 to log it silently
Returns
nothing the program exits automatically

Definition at line 1061 of file noalyss_user.class.php.

1062 {
1063 if ($this->check_action($p_action)==0)
1064 {
1065 $this->audit('FAIL');
1066 if ($p_js==1)
1067 {
1068 echo create_script("alert_box(content[59])");
1069 }
1070 elseif ($p_js==2)
1071 {
1072 record_log(_("Access invalid").$p_action);
1073 }
1074 else
1075 {
1076 echo '<h2 class="error">',
1077 htmlspecialchars(_("Cette action ne vous est pas autorisée Contactez votre responsable")),
1078 '</h2>';
1079 echo '</div>';
1080 }
1081 exit(-1);
1082 }
1083 }
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
check_action($p_action_id)
Check if an user is allowed to do an action.
if( $delta< 0) elseif( $delta==0)

References h2().

+ Here is the call graph for this function:

◆ can_write_action()

Noalyss_User::can_write_action ( $dtoc)

Check if the profile of the user can write for this profile.

Parameters
$dtocaction_gestion.ag_id
Returns
true if he can write otherwise false

Definition at line 1572 of file noalyss_user.class.php.

1573 {
1574 if ($this->Admin()==1)
1575 return TRUE;
1576 if ($this->get_status_security_action()==0)
1577 return TRUE;
1578 $profile=$this->get_profile();
1579 $r=$this->db->get_value(" select count(*) from action_gestion where ag_id=$1 and ag_dest in
1580 (select p_granted from user_sec_action_profile where ua_right in ('W','O') and p_id=$2) ", array($dtoc, $profile));
1581 if ($r==0)
1582 return FALSE;
1583 return true;
1584 }

◆ can_write_repo()

Noalyss_User::can_write_repo ( $p_repo)

Check if the profile of the user can write for this repository.

Parameters
$p_repostock_repository.r_id
Returns
true if he can write otherwise false

Definition at line 1628 of file noalyss_user.class.php.

1629 {
1630 if ($this->Admin()==1)
1631 return true;
1632 $profile=$this->get_profile();
1633 $r=$this->db->get_value("select count(*)
1634 from profile_sec_repository
1635 where
1636 r_id=$1
1637 and p_id =$2
1638 and ur_right='W'", array($p_repo, $profile));
1639 if ($r==0)
1640 return false;
1641 return true;
1642 }

◆ Check()

Noalyss_User::Check ( $silent = false,
$from = '' )

Check if user is active and exists in therepository Automatically redirect, it doesn't check if a user can access a folder.

Parameters
$silentfalse, echo an error message and exit, true : exit without warning default is false

++

Definition at line 475 of file noalyss_user.class.php.

476 {
477
478 $res=0;
479 $pass5=$this->password;
480
481 $sql="select ac_users.use_login,ac_users.use_active, ac_users.use_pass,
482 use_admin,use_first_name,use_name
483 from ac_users
484 where ac_users.use_id=$1
485 and ac_users.use_active=1
486 and ac_users.use_pass=$2";
487 $ret=$this->repository->exec_sql($sql, array($this->id, $pass5));
489 if ($res>0)
490 {
492 $_SESSION[SESSION_KEY.'use_admin']=$r['use_admin'];
493 $_SESSION[SESSION_KEY.'use_name']=$r['use_name'];
494 $_SESSION[SESSION_KEY.'use_first_name']=$r['use_first_name'];
495 $_SESSION[SESSION_KEY.'isValid']=1;
496
497 $this->admin=$_SESSION[SESSION_KEY.'use_admin'];
498 $this->name=$_SESSION[SESSION_KEY.'use_name'];
499 $this->first_name=$_SESSION[SESSION_KEY.'use_first_name'];
500 $this->load_global_pref();
501 }
502 $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
503
504 if ($res==0 || $this->can_connect() == 0)
505 {
506 $this->repository->exec_sql($sql,
507 array($_SESSION[SESSION_KEY.'g_user'], $_SERVER["REMOTE_ADDR"],
508 $from, $_SERVER['REQUEST_URI'], 'FAIL'));
509 if (!$silent)
510 {
511 echo '<script> alert(\''._('Utilisateur ou mot de passe incorrect').'\')</script>';
512 redirect('index.html');
513 }
514 $this->valid=0;
515 session_unset();
516 exit-1;
517 }
518 else
519 {
520 if ($from=='LOGIN' || $from=='PORTAL')
521 {
522 $this->repository->exec_sql($sql,
523 array($_SESSION[SESSION_KEY.'g_user'], $_SERVER["REMOTE_ADDR"], $from,
524 $_SERVER['REQUEST_URI'], 'SUCCESS'));
525 }
526 $this->valid=1;
527 }
528
529 return $ret;
530 }
if(!headers_sent())
– pour utiliser unoconv démarrer un server libreoffice commande libreoffice –headless –accept="socket...
$from
$from_poste name
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
$password
md5 of the password
load_global_pref()
Get the global preferences from user_global_pref in the account_repository db.
can_connect()
check the password and user

References $from, $r, $res, $ret, $sql, can_connect(), DatabaseCore\fetch_array(), if, load_global_pref(), name, and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ check_action()

Noalyss_User::check_action ( $p_action_id)

Check if an user is allowed to do an action.

Parameters
p_action_id
Returns
  • 0 no priv

Definition at line 884 of file noalyss_user.class.php.

885 {
886 /* save it into the log */
887 global $audit;
888 if ($this->Admin()==1)
889 return 1;
890 if ($this->is_local_admin(dossier::id())==1)
891 return 1;
892 if ($this->get_status_security_action()==0)
893 return 1;
894 $Res=$this->db->exec_sql(
895 "select * from user_sec_act where ua_login=$1 and ua_act_id=$2", array($this->login, $p_action_id));
896 $Count=Database::num_row($Res);
897 if ($Count==0)
898 {
899 if (isset($audit)&&$audit==true)
900 {
901
902 $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
903 $this->repository->exec_sql($sql,
904 array($_SESSION[SESSION_KEY.'g_user'], $_SERVER["REMOTE_ADDR"], $p_action_id, $_SERVER['REQUEST_URI'],
905 'FAIL'));
906 }
907 return 0;
908 }
909 if ($Count==1)
910 return 1;
911 echo_error(_("Action invalide"));
912 record_log("User:check_action".sprintf("login %s ua_act_id %s", $this->login, $p_action_id));
913 exit();
914 }
echo_error($p_log, $p_line="", $p_message="")
log error into the /tmp/noalyss_error.log it doesn't work on windows
is_local_admin($p_dossier=-1)
Check if an user is an local administrator.

◆ check_dossier()

Noalyss_User::check_dossier ( $p_dossier_id,
$silent = false )

check if an user can access a folder, if he cannot display a dialog box and exit

Parameters
thefolder if
$silentfalse, echo an error message and exit, true : exit without warning default is false
Returns
  • L for administrator (local and global)
  • X no access
  • R regular user

Definition at line 1253 of file noalyss_user.class.php.

1254 {
1255 $this->Admin();
1256 if ($this->admin==1||$this->is_local_admin($p_dossier_id)==1)
1257 return 'L';
1258
1259
1260 $dossier=$this->repository->get_value("select 'R' from jnt_use_dos where dos_id=$1 and use_id=$2",
1261 array($p_dossier_id, $this->id));
1262 $dossier=($dossier=='')?'X':$dossier;
1263 if ($dossier=='X')
1264 {
1265 $this->audit('FAIL', "Access folder ");
1266 if (!$silent)
1267 {
1268 alert(_('Dossier non accessible'));
1269 exit();
1270 }
1271 }
1272 return $dossier;
1273 }
alert($p_msg, $buffer=false)
alert in javascript

◆ check_jrn()

Noalyss_User::check_jrn ( $p_jrn)

check the access of an user on a ledger

Parameters
$p_jrnthe ledger id
Returns
  • O only predefined operation
  • W write
  • R read only
  • X no access

Definition at line 1237 of file noalyss_user.class.php.

1238 {
1239 return $this->get_ledger_access($p_jrn);
1240 }
get_ledger_access($p_ledger)
check that a user is valid and the access to the folder

◆ check_module()

Noalyss_User::check_module ( $p_module)

Check if an user can access a module, return 1 if yes, otherwise 0 record in audit log This function works only if user is connected to a Folder.

Parameters
string$p_modulemenu_ref.me_code
Returns
0 for FORBIDDEN, 1 for GRANTED

Definition at line 855 of file noalyss_user.class.php.

856 {
857 if ( $this->access_mode == "PC") {
858
859 $acc=$this->db->get_value("select count(*) from v_all_menu where p_id = $1
860 and me_code=$2", array($this->get_profile(), $p_module));
861 } elseif ($this->access_mode=="MOBILE") {
862 $acc=$this->db->get_value("select count(*) from profile_mobile where p_id=$1 and me_code=$2",
863 array($this->get_profile(), $p_module));
864 } else {
865 throw new Exception("USER:823:ACCESS_MODE INCONNU");
866 }
867 if ($acc==0)
868 {
869 $this->audit("FAIL", $p_module);
870 return 0;
871 }
872 $this->audit("SUCCESS", $p_module);
873 return 1;
874 }

◆ check_otp()

Noalyss_User::check_otp ( $code)

check that the OTP code is the one on smartphone returns false if the given does not match the OTP

Definition at line 2161 of file noalyss_user.class.php.

2162 {
2163 $otp=new \Noalyss\OTP();
2164
2165 if ( $otp->compute_code($this->otp_secret) == $code ) {
2166 return true;
2167 }
2168 return false;
2169 }

References $code.

◆ check_print()

Noalyss_User::check_print ( $p_action)

Check if the user can print (in menu_ref p_type_display=p) otherwise warn and exit.

Parameters
$p_actionrequested action
Returns
nothing the program exits automatically

Definition at line 1091 of file noalyss_user.class.php.

1092 {
1093 global $audit;
1094 $this->audit('AUDIT', $p_action);
1095 if ($this->Admin()==1)
1096 return 1;
1097
1098 $res=$this->db->get_value("select count(*) from profile_menu
1099 join profile_user using (p_id)
1100 where user_name=$1 and me_code=$2 ", array($this->login, $p_action));
1101 return $res;
1102 }

◆ clean_session()

static Noalyss_User::clean_session ( )
static

clean the sessions

Definition at line 1923 of file noalyss_user.class.php.

1924 {
1925
1926 $aSession=$_SESSION;
1927 foreach($aSession as $key => $value) {
1928 if(DEBUGNOALYSS>1) { echo "[$key]=>[$value]";}
1929
1930 if ( strpos($key,SESSION_KEY) === 0) {
1931 unset($_SESSION[$key]);
1932 if(DEBUGNOALYSS>1) { echo "=> [$key] cleaned";}
1933 }
1934 }
1935 }

References $value.

◆ connect_user()

Noalyss_User::connect_user ( )
private

connect the user and set the $_SESSION variables if not set thanks the $_REQUEST

Definition at line 132 of file noalyss_user.class.php.

133 {
134 if (!isset($_SESSION[SESSION_KEY.'g_user']))
135 {
136 $http=new \HttpInput();
137 $user_login=$http->request("p_user", "string", "");
138 $user_password=$http->request("p_pass", "string", "");
139
140 if ($user_login!=""&&$user_password!="")
141 {
142 $_SESSION[SESSION_KEY."g_user"]=$user_login;
143 $_SESSION[SESSION_KEY."g_pass"]=md5($user_password);
144 }
145 else
146 {
147 echo '<h2 class="error">'._('Session expirée<br>Utilisateur déconnecté').'</h2>';
148 redirect('index.php', 1);
149 exit();
150 }
151
152
153 if (strpos($user_login, '@mobile')!=false)
154 {
155 $this->access_mode='MOBILE';
156 $this->login=str_ireplace("@mobile", "", $user_login);
157 }
158 else
159 {
160 $this->access_mode='PC';
161 $this->login=strtolower($user_login);
162 }
163
164 $_SESSION[SESSION_KEY."access_mode"]=$this->access_mode;
165 $_SESSION[SESSION_KEY.'g_user']=$this->login;
166 }
167 $this->login=$_SESSION[SESSION_KEY."g_user"];
168 $this->password=$_SESSION[SESSION_KEY.'g_pass'];
169
170 $this->id=-1;
171 $this->lang=(isset($_SESSION[SESSION_KEY.'g_lang']))?$_SESSION[SESSION_KEY.'g_lang']:'fr_FR.utf8';
172 $this->access_mode=$_SESSION[SESSION_KEY."access_mode"];
173
174
175 // share user login with the repository
176 $this->repository->exec_sql(sprintf("select set_config('noalyss.user_login','%s',false)",
177 Database::escape_string($_SESSION[SESSION_KEY.'g_user'])));
178
179 if ($this->can_connect() == 0 || $this->load()==-1 )
180 {
181 echo '<h2 class="error">'._('Utilisateur ou mot de passe incorrect').'</h2>';
182 $sql="insert into audit_connect (ac_user,ac_ip,ac_module,ac_url,ac_state) values ($1,$2,$3,$4,$5)";
183 $server_remote=$_SERVER['REMOTE_ADDR']?? "cmd-line";
184 $request_uri=$_SERVER['REQUEST_URI']??"REQUEST-URI";
185
186 $this->repository->exec_sql($sql,
187 array($_SESSION[SESSION_KEY.'g_user'],$server_remote, "DISCON",
188 $request_uri , 'FAIL'));
189 $this->clean_session();
190 redirect('logout.php', 1);
191 exit();
192 }
193
194 $this->load_global_pref();
195
196 $_SESSION[SESSION_KEY.'g_lang']=$this->lang;
197 $this->valid=(isset($_SESSION[SESSION_KEY.'isValid']))?1:0;
198 if (isset($_SESSION[SESSION_KEY.'g_theme']))
199 {
200 $this->theme=$_SESSION[SESSION_KEY.'g_theme'];
201 }
202 $_SESSION[SESSION_KEY.'use_admin']=$this->admin;
203 $_SESSION[SESSION_KEY.'use_name']=$this->name;
204 $_SESSION[SESSION_KEY.'use_first_name']=$this->first_name;
205 }
static escape_string($p_string)
wrapper for the function pg_escape_string
$login
login lower case
$lang
user's language
$access_mode
MOBILE or PC depending if when connecting $login contains @mobile.
redirect( $p_string, $p_time=0)
redirect with javascript

References if.

Referenced by __construct().

◆ generate_otp()

Noalyss_User::generate_otp ( )

generate OTP secret to store in AC_USER.USE_OTP_SECRET

Definition at line 1959 of file noalyss_user.class.php.

1960 {
1961 $otp=new \Noalyss\OTP();
1962 $this->otp_secret=$otp->build_secret();
1963 }

Referenced by save().

◆ get_access_mode()

Noalyss_User::get_access_mode ( )

access_mode tells what mode must be used : pc or mobile

Definition at line 210 of file noalyss_user.class.php.

211 {
212 return $this->access_mode;
213 }

◆ get_authent_method()

Noalyss_User::get_authent_method ( )

retrieve authent_method

  • 0 password
  • 1 password + code by email
  • 2 password + OTP from application

Definition at line 1970 of file noalyss_user.class.php.

1970 {
1971 return $this->authent_method;
1972 }
$authent_method
authentication method use for this user

◆ get_available_folder()

Noalyss_User::get_available_folder ( $p_filter = "")

Get all the available folders for the users, checked with the security.

Parameters
$p_filter
Returns
array containing
  • ac_dossier.dos_id
  • ac_dossier.dos_name
  • ac_dossier.dos_description

Definition at line 1367 of file noalyss_user.class.php.

1368 {
1370 $filter="";
1371 if ($this->admin==0)
1372 {
1373 // show only available folders
1374 // if user is not an admin
1375 $Res=$this->repository->exec_sql("select
1376 distinct dos_id,dos_name,dos_description
1377 from ac_users
1378 natural join jnt_use_dos
1379 natural join ac_dossier
1380 where
1381 use_login= $1
1382 and use_active = 1
1383 and ( dos_name ilike '%' || $2 || '%' or dos_description ilike '%' || $2 || '%' )
1384 order by dos_name", array($this->login, $p_filter));
1385 }
1386 else
1387 {
1388 $Res=$this->repository->exec_sql("select
1389 distinct dos_id,dos_name,dos_description from ac_dossier
1390 where
1391 dos_name ilike '%' || $1|| '%' or dos_description ilike '%' || $1 || '%'
1392 order by dos_name", array($p_filter));
1393 }
1394
1396 if ($max==0)
1397 return 0;
1398
1399 for ($i=0; $i<$max; $i++)
1400 {
1402 }
1403 return $array;
1404 }

◆ get_available_repository()

Noalyss_User::get_available_repository ( $p_access = 'R')

return array of available repository

Parameters
$p_accessR for read W for write
Returns
an array

Definition at line 1155 of file noalyss_user.class.php.

1156 {
1157 $profile=$this->get_profile();
1158 $r=array();
1159 if ($p_access=='R')
1160 {
1161 $r=$this->db->get_array("select distinct u.r_id,r_name
1162 from
1163 profile_sec_repository as u
1164 join stock_repository as s on(u.r_id=s.r_id)
1165 where
1166 p_id =$1
1167 and ur_right='W'
1168 order by 2
1169 ", array($profile));
1170 }
1171 if ($p_access=='W')
1172 {
1173 $r=$this->db->get_array("select distinct u.r_id,r_name
1174 from
1175 profile_sec_repository as u
1176 join stock_repository as s on(u.r_id=s.r_id)
1177 where
1178 p_id =$1 order by 2
1179 ", array($profile));
1180 }
1181 return $r;
1182 }

◆ get_exercice()

Noalyss_User::get_exercice ( )

Return the year of current Periode it is the parm_periode.p_exercice col if an error occurs return 0.

Definition at line 1040 of file noalyss_user.class.php.

1041 {
1042 $sql="select p_exercice from parm_periode where p_id=$1";
1043 $Ret=$this->db->exec_sql($sql,[$this->get_periode()]);
1044 if (Database::num_row($Ret)==1)
1045 {
1046 $r=Database::fetch_array($Ret, 0);
1047 return $r['p_exercice'];
1048 }
1049 else
1050 return 0;
1051 }
get_periode()
Get the default periode from the user's preferences.

◆ get_first_week_day()

Noalyss_User::get_first_week_day ( )

first day in calendar

See also
IDate\set_firstDate(

Definition at line 1908 of file noalyss_user.class.php.

1909 {
1910
1911 $result=$this->repository->get_value("select parameter_value from user_global_pref where parameter_type=$1 and user_id=$2 ",
1912 array("first_week_day", $this->login));
1913 if ($this->repository->count()==0)
1914 {
1915 $this->save_global_preference("first_week_day", 1);
1916 return 1;
1917 }
1918 return $result;
1919 }
save_global_preference($key, $value)
Save the preference , the scope is global, the settings are saved into account_repository.

References $result, and save_global_preference().

+ Here is the call graph for this function:

◆ get_folder_access()

Noalyss_User::get_folder_access ( $p_dossier = 0)

return the access to a folder,

Parameters
$p_dossierid if it is == 0 then we take the value from $_SESSION
Returns
the priv_priv
  • X no access
  • R has access (normal user)

Definition at line 541 of file noalyss_user.class.php.

542 {
543
544 if ($p_dossier==0)
545 $p_dossier=dossier::id();
546 if ($this->admin==1)
547 return 'R';
548
549 $sql="select 'R' from jnt_use_dos where use_id=$1 and dos_id=$2";
550
551 $res=$this->repository->get_value($sql, array($this->id, $p_dossier));
552
553 if ($this->repository->get_affected()==0)
554 return 'X';
555 return $res;
556 }

◆ get_ledger()

Noalyss_User::get_ledger ( $p_type = 'ALL',
$p_access = 3,
$all = TRUE )

get all the available ledgers for the current user

Parameters
$p_type= ALL or the type of the ledger (ACH,VEN,FIN,ODS)
$p_access=3 for Read or WRITE, 2 write, 1 for readonly
(boolean)$all if true show also inactive
Returns
a double array of available ledgers
[0] => [jrn_def_id]
[jrn_def_type]
[jrn_def_name]
[jrn_def_class_deb]
[jrn_def_class_cred]
[jrn_type_id]
[jrn_desc]
[uj_priv]

Definition at line 626 of file noalyss_user.class.php.

627 {
628 $p_type=strtoupper($p_type);
629 if (!in_array($p_type, ["FIN", "ALL", "ODS", "VEN", 'ACH']))
630 {
631 record_log(sprintf("UGL1, p_type %s", $p_type));
632 throw new Exception("UGL1"._("Type incorrecte"));
633 }
634 if ($all==TRUE)
635 {
636 $sql_enable="";
637 }
638 else
639 {
640 $sql_enable="and jrn_enable=1";
641 }
642 if ($this->admin!=1&&$this->is_local_admin()!=1&&$this->get_status_security_ledger()==1)
643 {
644 $sql_type=($p_type=='ALL')?'':"and jrn_def_type=upper('".sql_string($p_type)."')";
645 switch ($p_access)
646 {
647 case 3:
648 $sql_access=" and uj_priv!= 'X' ";
649 break;
650 case 2:
651 $sql_access=" and uj_priv = 'W' and jrn_enable=1 ";
652 break;
653
654 case 1:
655 $sql_access=" and ( uj_priv = 'R' or uj_priv='W') ";
656 break;
657 }
658
659 $sql="select jrn_def_id,jrn_def_type,jrn_def_code,
660 jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc,uj_priv,
661 jrn_deb_max_line,jrn_cred_max_line,jrn_def_description,jrn_enable
662 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
663 join user_sec_jrn on uj_jrn_id=jrn_def_id
664 where
665 uj_login='".$this->login."'".
666 $sql_type.$sql_access.$sql_enable.
667 " order by jrn_Def_name";
668 }
669 else
670 {
671 $sql_type=($p_type=='ALL')?' '.$sql_enable:"where jrn_def_type=upper('".sql_string($p_type)."') ".$sql_enable;
672 $sql="select jrn_def_id,jrn_def_type,jrn_def_code,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_deb_max_line,jrn_cred_max_line,
673 jrn_type_id,jrn_desc,'W' as uj_priv,jrn_def_description,jrn_enable
674 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
675 $sql_type
676 order by jrn_Def_name";
677 }
678 $res=$this->db->exec_sql($sql);
679 if (Database::num_row($res)==0)
680 return null;
682 return $array;
683 }
sql_string($p_string)
Fix the problem with the quote char for the database.
static fetch_all($ret, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_all
get_status_security_ledger()
Check the security on ledger for the user , it returns 1 if the security on ledgers is enabled,...

References ALL.

◆ get_ledger_access()

Noalyss_User::get_ledger_access ( $p_ledger)

check that a user is valid and the access to the folder

Parameters
$p_ledgerthe ledger to check
Returns
the priv_priv
  • O only predefined operation
  • W write
  • R read only
  • X no access

Definition at line 595 of file noalyss_user.class.php.

596 {
597 if ($this->admin==1||
598 $this->is_local_admin(dossier::id())==1||$this->get_status_security_ledger()==0)
599 return 'W';
600
601 $sql="select uj_priv from user_sec_jrn where uj_login=$1 and uj_jrn_id=$2";
602 $res=$this->db->get_value($sql, array($this->login, $p_ledger));
603
604 if ($res=='')
605 $res='X';
606 return $res;
607 }

◆ get_ledger_sql()

Noalyss_User::get_ledger_sql ( $p_type = 'ALL',
$p_access = 3 )

return an sql condition for filtering the permitted ledger

Parameters
$p_type= ALL or the type of the ledger (ACH,VEN,FIN,ODS)
$p_access=3 for READ or WRITE, 2 READ and write, 1 for readonly
Returns
sql condition like = jrn_def_id in (...)

Definition at line 692 of file noalyss_user.class.php.

693 {
694 $aLedger=$this->get_ledger($p_type, $p_access);
695 if (empty($aLedger))
696 return ' jrn_def_id < 0 ';
697 $sql=" jrn_def_id in (";
698 foreach ($aLedger as $row)
699 {
700 $sql.=$row['jrn_def_id'].',';
701 }
702 $sql.='-1)';
703 return $sql;
704 }
get_ledger($p_type='ALL', $p_access=3, $all=TRUE)
get all the available ledgers for the current user

References ALL, and jrn_def_id.

◆ get_limit_current_exercice()

Noalyss_User::get_limit_current_exercice ( )

return the first date and the last date of the current exercice for the current user

Returns
and array ([0] => start_date,[1] => end_date)

Definition at line 1279 of file noalyss_user.class.php.

1280 {
1282 $periode=new Periode($this->db);
1283 list($per_start, $per_end)=$periode->get_limit($current_exercice);
1284 $start=$per_start->first_day();
1285 $end=$per_end->last_day();
1286 return array($start, $end);
1287 }
get_exercice()
Return the year of current Periode it is the parm_periode.p_exercice col if an error occurs return 0.

◆ get_list()

static Noalyss_User::get_list ( $p_dossier,
$db_repository = null )
static

return an array with all the active users who can access $p_dossier including the global admin.

The list concerns the user in the repository of the "domain" defined in config.inc.php

The user must be activated

Parameters
$p_dossierdossier
Returns
an array of user's object array indices
  • use_id (id )
  • use_login (login of the user)
  • use_name
  • use_first_name
Parameters
$db_repository( \Database default null) database to repository, if null is given the database will be defined in config.inc.php
Exceptions
throwan exception if nobody can access

Definition at line 1202 of file noalyss_user.class.php.

1205 {
1206 $sql="select distinct use_id,use_login,use_first_name,use_name from ac_users
1207 left outer join jnt_use_dos using (use_id)
1208 where
1209 (dos_id=$1 and use_active=1) or (use_active=1 and use_admin=1)
1210 order by use_login,use_name";
1211
1212 // connect to the repository
1213 if ( $db_repository == null ) {
1214 $repo_cnx=new Database(0);
1215 } else {
1216 $repo_cnx=$db_repository;
1217 }
1218 $array=$repo_cnx->get_array($sql, array($p_dossier));
1219 if ($repo_cnx->size()==0)
1220 {
1221 throw new \Exception('noalyss_user.get_list error inaccessible folders',1186);
1222 }
1223 return $array;
1224 }

◆ get_otp_secret()

Noalyss_User::get_otp_secret ( )

Definition at line 1974 of file noalyss_user.class.php.

1974 {
1975 return $this->otp_secret;
1976 }
$otp_secret
string use as secret for OTP

◆ get_periode()

Noalyss_User::get_periode ( )

Get the default periode from the user's preferences.

Returns
the default periode

Definition at line 782 of file noalyss_user.class.php.

783 {
784
785 $array=$this->get_preference();
786 if (!isset($array['PERIODE']))
787 {
788 $this->set_default_periode();
789 $array=$this->get_preference();
790 }
791 return $array['PERIODE'];
792 }
get_preference()
Get the default user's preferences.

◆ get_preference()

Noalyss_User::get_preference ( )

Get the default user's preferences.

Returns
array of (parameter_type => parameter_value)

Definition at line 824 of file noalyss_user.class.php.

825 {
826 $sql="select parameter_type,parameter_value from user_local_pref where user_id=$1";
827 $Res=$this->db->exec_sql($sql, array($this->id));
828 $l_array=array();
829 for ($i=0; $i<Database::num_row($Res); $i++)
830 {
832 $type=$row['parameter_type'];
833 $l_array[$type]=$row['parameter_value'];
834 }
835 $a_global_pref=$this->repository->get_array("select parameter_type,parameter_value from user_global_pref
836 where
837 upper(user_id) = upper($1)", [$this->login]);
838 $nb_global=count($a_global_pref);
839 for ($i=0; $i<$nb_global; $i++)
840 {
841 $idx=$a_global_pref[$i]['parameter_type'];
842 $value=$a_global_pref[$i]['parameter_value'];
843 $l_array[$idx]=$value;
844 }
845
846 return $l_array;
847 }

◆ get_profile()

Noalyss_User::get_profile ( )

return the profile (p_id)

Returns
profile.p_id

Definition at line 1476 of file noalyss_user.class.php.

1477 {
1478 $profile=$this->db->get_value("select p_id from profile_user where
1479 lower(user_name)=lower($1) ", array($this->login));
1480 return $profile;
1481 }

◆ get_readable_profile()

Noalyss_User::get_readable_profile ( )

return array of readable action_profile

Definition at line 1519 of file noalyss_user.class.php.

1520 {
1521 $value=$this->db->get_array("select p_granted from ".$this->sql_readable_profile()." as m") ;
1522 $aGranted=array_column($value,"p_granted");
1523 return $aGranted;
1524 }
sql_readable_profile()
Compute the SQL string for the readable profile, the subselect for p_id , example p_id in $g_user->sq...

◆ get_repository()

Noalyss_User::get_repository ( )

get the repository

Returns
Database

Definition at line 89 of file noalyss_user.class.php.

89 :\Database {
90 return $this->repository;
91 }

References return.

◆ get_status_security_action()

Noalyss_User::get_status_security_action ( )

Check the security on ledger for the user , it returns 1 if the security on ledgers is enabled, otherwise 0.

Definition at line 1872 of file noalyss_user.class.php.

1873 {
1874 $security=$this->db->get_value("select us_action from user_active_security
1875 where
1876 us_login=$1", [$this->login]);
1877 $n_security=($security=="Y")?1:0;
1878 return $n_security;
1879 }

References db.

◆ get_status_security_ledger()

Noalyss_User::get_status_security_ledger ( )

Check the security on ledger for the user , it returns 1 if the security on ledgers is enabled, otherwise 0.

Definition at line 1836 of file noalyss_user.class.php.

1837 {
1838 $security=$this->db->get_value("select us_ledger from user_active_security
1839 where
1840 us_login=$1", [$this->login]);
1841 $n_security=($security=="Y")?1:0;
1842 return $n_security;
1843 }

References db.

◆ get_vat_code_preference()

Noalyss_User::get_vat_code_preference ( )

Get preference , either the user see the numeric id for VAT or its code, if the preference doesn't exist by default , 0 is saved in ACCOUNT_REPOSITORY.

See also
ITva_Popup\set_vat_code()
ITva_Popup

Definition at line 1943 of file noalyss_user.class.php.

1943 :int
1944 {
1945
1946
1947 $result=$this->repository->get_value("select parameter_value from user_global_pref where parameter_type=$1 and user_id=$2 ",
1948 array("vat_code", $this->login));
1949 if ($this->repository->count()==0)
1950 {
1951 $this->save_global_preference("vat_code", 0);
1952 return 0;
1953 }
1954 return $result;
1955 }

References $result, and save_global_preference().

+ Here is the call graph for this function:

◆ get_writable_profile()

Noalyss_User::get_writable_profile ( )

return array of writable action_profile

Definition at line 1509 of file noalyss_user.class.php.

1510 {
1511 $value=$this->db->get_array("select p_granted from ".$this->sql_writable_profile()." as m") ;
1512 $aGranted=array_column($value,"p_granted");
1513 return $aGranted;
1514 }
sql_writable_profile()
Compute the SQL string for the writable profile, the subselect for p_id , example p_id in $g_user->sq...

◆ getActive()

Noalyss_User::getActive ( )
Returns
mixed

Definition at line 323 of file noalyss_user.class.php.

324 {
325 return $this->active;
326 }
$active
1 active , 0 disables

◆ getAdmin()

Noalyss_User::getAdmin ( )
Returns
default|int|mixed|string|string[]|null

Definition at line 259 of file noalyss_user.class.php.

260 {
261 return $this->admin;
262 }
$admin
is or is not admin

References $admin.

◆ getDb()

Noalyss_User::getDb ( )
Returns
mixed

Definition at line 243 of file noalyss_user.class.php.

244 {
245 return $this->db;
246 }
$db
database connx to the folder NOT repository

◆ getEmail()

Noalyss_User::getEmail ( )
Returns
mixed

Definition at line 371 of file noalyss_user.class.php.

372 {
373 return $this->email;
374 }

Referenced by send_code_otp(), and send_link_otp().

◆ getFirstName()

Noalyss_User::getFirstName ( )
Returns
default|mixed|string|string[]|null

Definition at line 291 of file noalyss_user.class.php.

292 {
293 return $this->first_name;
294 }

◆ getId()

Noalyss_User::getId ( )
Returns
int|mixed

Definition at line 227 of file noalyss_user.class.php.

227 : int
228 {
229 return $this->id;
230 }
$id
in account_repository , ac_users.use_id

References $id.

◆ getLogin()

Noalyss_User::getLogin ( )
Returns
string

Definition at line 339 of file noalyss_user.class.php.

339 : string
340 {
341 return $this->login;
342 }

◆ getName()

Noalyss_User::getName ( )
Returns
default|mixed|string|string[]|null

Definition at line 307 of file noalyss_user.class.php.

308 {
309 return $this->name;
310 }

References $name.

◆ getPassword()

Noalyss_User::getPassword ( )
Returns
mixed

Definition at line 355 of file noalyss_user.class.php.

356 {
357 return $this->password;
358 }

◆ getValid()

Noalyss_User::getValid ( )
Returns
int

Definition at line 275 of file noalyss_user.class.php.

275 : int
276 {
277 return $this->valid;
278 }
$valid
is or is not valid

References $valid.

◆ grant_admin_access()

static Noalyss_User::grant_admin_access ( $p_login,
$p_dossier,
$db_repository = null )
static

Grant access to folder, grant administrator profile , all the ledgers and all the action.

Parameters
$p_login(String) login
$p_dossier(int) dossier id
$db_repository( \Database default null) database to repository, if null is given the database will be defined in config.inc.php

Definition at line 1747 of file noalyss_user.class.php.

1748 {
1749 // connect to the repository
1750 if ( $db_repository == null ) {
1751 $repo_cnx=new Database(0);
1752 } else {
1753 $repo_cnx=$db_repository;
1754 }
1755 $user=$repo_cnx->get_array("select use_id,use_login
1756 from ac_users
1757 where use_login=$1", array($p_login));
1758
1759 if (!$user)
1760 return false;
1761 $cn_dossier=new Database($p_dossier);
1762 // if not access to DB
1763 if (
1764 $repo_cnx->get_value("select count(*) from jnt_use_dos where use_id=$1 and dos_id=$2",
1765 array($user[0]['use_id'], $p_dossier))==0
1766 )
1767 {
1768 $repo_cnx->exec_sql("insert into jnt_use_dos(use_id,dos_id) values ($1,$2)",
1769 array($user[0]['use_id'], $p_dossier));
1770 }
1771 //------ Give him the admin menu
1772 if ($cn_dossier->get_value("select count(*) from profile_user where user_name=$1", array($user[0]['use_login']))==0)
1773 {
1774 $cn_dossier->exec_sql('insert into profile_user(user_name,p_id) values($1,1)', array($user[0]['use_login']));
1775 }
1776 // Grant all action + ledger to him
1777 $cn_dossier->exec_sql("delete from user_sec_act where ua_login=$1", array($p_login));
1778
1779 $cn_dossier->exec_sql("insert into user_sec_act (ua_login,ua_act_id)"
1780 ." select $1 ,ac_id from action ", array($p_login));
1781
1782 $cn_dossier->exec_sql("delete from user_sec_jrn where uj_login=$1", array($p_login));
1783 $cn_dossier->exec_sql("insert into user_sec_jrn(uj_login,uj_jrn_id,uj_priv)"
1784 ." select $1,jrn_def_id,'W' from jrn_def", array($p_login));
1785 }

References $user.

◆ input_otp()

Noalyss_User::input_otp ( $uuid = "",
$url = "" )

FORM to enter the 6 digit enter by OTP.

Parameters
$uuid(string UUID) UUID in the message, null if there is no message

Definition at line 2153 of file noalyss_user.class.php.

2154 {
2155 require_once NOALYSS_TEMPLATE."/noalyss_user-input_otp.php" ;
2156 }

References $url.

◆ insert()

Noalyss_User::insert ( )

Definition at line 455 of file noalyss_user.class.php.

456 {
457
458 $Sql="INSERT INTO ac_users(
459 use_first_name, use_name, use_login, use_active,
460 use_admin, use_pass, use_email)
461 VALUES ($1, $2, $3, $4, $5, $6, $7) returning use_id";
462
463 $this->id=$this->repository->get_value($Sql,
464 array($this->first_name, $this->last_name, $this->login, 1, $this->admin,
465 $this->password, $this->email));
466 }

◆ insert_default_global_pref()

Noalyss_User::insert_default_global_pref ( $p_type = "",
$p_value = "" )

insert default pref if no parameter are given insert all the existing parameter otherwise only the requested

Parameters
$p_typeparameter's type or nothing
$p_valueparameter value

Definition at line 973 of file noalyss_user.class.php.

974 {
975
976 $default_parameter=array("THEME"=>"classic",
977 "PAGESIZE"=>"50",
978 'TOPMENU'=>'TEXT',
979 'LANG'=>'fr_FR.utf8',
980 'csv_fieldsep'=>'0',
981 'csv_decimal'=>'0',
982 'csv_encoding'=>'utf8',
983 'first_week_day'=>1
984 );
985 $sql="insert into user_global_pref(user_id,parameter_type,parameter_value)
986 values ($1,$2,$3)";
987 if ($p_type=="")
988 {
989 foreach ($default_parameter as $name=> $value)
990 {
991 $this->repository->exec_sql($sql, array($this->login, $name, $value));
992 }
993 }
994 else
995 {
996 $value=($p_value=="")?$default_parameter[$p_type]:$p_value;
997 if ( $this->repository->get_value("select count(*) from user_global_pref where user_id=$1 and parameter_type=$2",
998 array($this->login,$p_type)) == 1)
999 {
1000 $this->repository->exec_sql("update user_global_pref set parameter_value=$1 where user_id=$2 and parameter_type=$3",
1001 array($value,$this->login,$p_type));
1002 } else {
1003 $this->repository->exec_sql($sql, array($this->login, $p_type, $value));
1004 }
1005 }
1006 }

◆ is_double_identified()

Noalyss_User::is_double_identified ( )

check is the double authentication has been successful

Returns
bool

Definition at line 1996 of file noalyss_user.class.php.

1996 {
1997
1998 if ( $this->authent_method == 0 )
1999 {
2000 $_SESSION[SESSION_KEY."db_auth"]='ok';
2001 return true;
2002 }
2003 if ( ! isset($_SESSION[SESSION_KEY."db_auth"])) {
2004 return false;
2005 }
2006 if ($_SESSION[SESSION_KEY."db_auth"] == "ok") {
2007 return true;
2008 }
2009 return false;
2010 }

References if.

◆ is_local_admin()

Noalyss_User::is_local_admin ( $p_dossier = -1)

Check if an user is an local administrator.

Deprecated
since version 6.7
Parameters
$p_dossier: dossier_id
Returns
  • 0 if no
  • 1 if yes

Definition at line 1144 of file noalyss_user.class.php.

1145 {
1146 return 0;
1147 }

◆ isAdmin()

Noalyss_User::isAdmin ( )

Check if an user is an admin and check also his password.

Returns
1 for yes 0 for no

Definition at line 720 of file noalyss_user.class.php.

720 :int
721 {
722 $this->admin=0;
723 $pass5=$this->password;
724 $sql="select count(*) from ac_users where use_login=$1
725 and use_active=1 and use_admin=1 and use_pass=$2 ";
726
727 $this->admin=$this->repository->get_value($sql, array($this->login,$pass5));
728 return $this->admin;
729 }

◆ load()

Noalyss_User::load ( )

Definition at line 390 of file noalyss_user.class.php.

390 :int
391 {
392 /* if this->id == -1, it is unknown so we have to retrieve it from
393 the database thanks it login */
394 if ($this->id<0)
395 {
396 $sql_cond=" where lower(use_login)=lower($1)";
397 $sql_array=array($this->login);
398 }
399 else
400 {
401 $sql_cond=" where use_id=$1";
402 $sql_array=array($this->id);
403 }
404 $sql="select use_id,
405 use_first_name,
406 use_name,
407 use_login,
408 use_active,
409 use_admin,
410 use_pass,
411 use_email,
412 use_auth_method,
413 use_otp_secret
414 from ac_users ";
415 $Res=$this->repository->exec_sql($sql.$sql_cond, $sql_array);
416 if (($Max=Database::num_row($Res))==0)
417 return -1;
419 $this->id=$row['use_id'];
420 $this->first_name=$row['use_first_name'];
421 $this->last_name=$row['use_name'];
422 $this->name=$row['use_name'];
423 $this->active=$row['use_active'];
424 $this->login=strtolower($row['use_login']);
425 $this->admin=$row['use_admin'];
426 $this->password=$row['use_pass'];
427 $this->email=$row['use_email'];
428 $this->authent_method=$row['use_auth_method'];
429 $this->otp_secret=$row['use_otp_secret'];
430 return $this->id;
431 }
$sql_array['query']

References $id, $Max, $Res, $row, $sql, $sql_array, DatabaseCore\fetch_array(), name, and DatabaseCore\num_row().

Referenced by __construct().

+ Here is the call graph for this function:

◆ load_global_pref()

Noalyss_User::load_global_pref ( )

Get the global preferences from user_global_pref in the account_repository db.

Note
set $SESSION[g_variable]

Definition at line 922 of file noalyss_user.class.php.

923 {
924 // Load everything in an array
925 $Res=$this->repository->exec_sql("select parameter_type,parameter_value from
926 user_global_pref
927 where user_id=$1", [$this->login]);
929 if ($Max==0)
930 {
932 $this->load_global_pref();
933 return;
934 }
935 // Load value into array
936 $line=array();
937 for ($i=0; $i<$Max; $i++)
938 {
940 $type=$row['parameter_type'];
941 $line[$type]=$row['parameter_value'];
942 }
943 // save array into g_ variable
944 $array_pref=array('g_theme'=>'THEME',
945 'g_pagesize'=>'PAGESIZE',
946 'g_topmenu'=>'TOPMENU',
947 'g_lang'=>'LANG',
948 'csv_fieldsep'=>'csv_fieldsep',
949 'csv_decimal'=>'csv_decimal',
950 'csv_encoding'=>'csv_encoding',
951 'first_week_day'=>'first_week_day');
952
953 foreach ($array_pref as $name=> $parameter)
954 {
955 if (!isset($line[$parameter]))
956 {
957 $this->insert_default_global_pref($parameter);
958 $this->load_global_pref();
959 return;
960 }
961 $_SESSION[SESSION_KEY.$name]=$line[$parameter];
962 }
963 }
insert_default_global_pref($p_type="", $p_value="")
insert default pref if no parameter are given insert all the existing parameter otherwise only the re...

Referenced by Check().

◆ password_to_session()

Noalyss_User::password_to_session ( )

store the password in session

Definition at line 1667 of file noalyss_user.class.php.

1668 {
1669 $_SESSION[SESSION_KEY.'g_pass']=$this->getPassword();
1670 }

◆ remove_inexistant_user()

static Noalyss_User::remove_inexistant_user ( $p_dossier,
$db_repository = null )
static

cleansing : remove inexistant user

Parameters
$p_dossier(int) dossier id
$db_repository( \Database default null) database to repository, if null is given the database will be defined in config.inc.php
Returns
bool : true if success , false if no change

Definition at line 1793 of file noalyss_user.class.php.

1794 {
1795 // connect to the repository
1796 if ( $db_repository == null ) {
1797 $cnx_repo=new Database(0);
1798 } else {
1799 $cnx_repo=$db_repository;
1800 }
1801 $name=$cnx_repo->format_name($p_dossier, 'dos');
1802 if ($cnx_repo->exist_database($name)==0)
1803 return false;
1804 $cnx_dossier=new Database($p_dossier);
1805 if ($cnx_dossier->exist_table('profile_user'))
1806 $a_user=$cnx_dossier->get_array('select user_name from profile_user');
1807 else
1808 return false;
1809
1810 if (!$a_user)
1811 return;
1812 $nb=count($a_user);
1813 for ($i=0; $i<$nb; $i++)
1814 {
1815 if ($cnx_repo->get_value('select count(*) from ac_users where use_login=$1', array($a_user[$i]['user_name']))==0)
1816 {
1817 if ($cnx_dossier->exist_table('user_sec_jrn'))
1818 $cnx_dossier->exec_sql("delete from user_sec_jrn where uj_login=$1", array($a_user[$i]['user_name']));
1819 $cnx_dossier->exec_sql("delete from profile_user where user_name=$1", array($a_user[$i]['user_name']));
1820 if ($cnx_dossier->exist_table('user_sec_act'))
1821 $cnx_dossier->exec_sql("delete from user_sec_act where ua_login=$1", array($a_user[$i]['user_name']));
1822 if ($cnx_dossier->exist_table('user_sec_jrn'))
1823 $cnx_dossier->exec_sql("delete from user_sec_jrn where uj_login=$1", array($a_user[$i]['user_name']));
1824 if ($cnx_dossier->exist_table('user_active_security'))
1825 $cnx_dossier->exec_sql("delete from user_active_security where us_login=$1",
1826 array($a_user[$i]['user_name']));
1827 }
1828 }
1829 return true;
1830 }

References $i, $name, and $nb.

◆ revoke_access()

static Noalyss_User::revoke_access ( $p_login,
$p_dossier,
$db_repository = null )
static

Remove a user and all his privileges So it cannot connect anymore and all his privileges are removed from the dossier.

Parameters
$p_login(String) login
$p_dossier(int) dossier id
$db_repository( \Database default null) database to repository, if null is given the database will be defined in config.inc.php

Definition at line 1716 of file noalyss_user.class.php.

1717 {
1718 // connect to the repository
1719 if ( $db_repository == null ) {
1720 $repo_cnx=new Database(0);
1721 } else {
1722 $repo_cnx=$db_repository;
1723 }
1724
1725 // Retrieve the user
1726 $user=$repo_cnx->get_array('select use_id,use_login from ac_users where use_login=$1', array($p_login));
1727 if (!$user)
1728 return false;
1729
1730 // remove him from jnt_use_dos
1731 $repo_cnx->exec_sql("delete from jnt_use_dos WHERE use_id=$1 and dos_id=$2",
1732 array($user[0]['use_id'], $p_dossier));
1733
1734 // Remove user from user's dossier
1735 $cn_dossier=new Database($p_dossier);
1736 $cn_dossier->exec_sql("delete from profile_user where user_name=$1", array($p_login));
1737 $cn_dossier->exec_sql("delete from user_sec_act where ua_login=$1", array($p_login));
1738 }

References from.

◆ save()

Noalyss_User::save ( )

Definition at line 433 of file noalyss_user.class.php.

434 {
435 if ( $this->authent_method != 0 && $this->otp_secret == null) {
436 $this->generate_otp();
437 }
438 $Sql="update ac_users set use_first_name=$1, use_name=$2
439 ,use_active=$3,use_admin=$4,use_pass=$5 ,use_email = $7
440 , use_auth_method=$8,use_otp_secret=$9
441 where use_id=$6";
442 $Res=$this->repository->exec_sql($Sql,
443 array($this->first_name //1
444 , $this->last_name // 2
445 , $this->active //3
446 , $this->admin //4
447 , $this->password //5
448 , $this->id //6
449 , $this->email //7
450 , $this->authent_method //8
451 , $this->otp_secret //9
452 ));
453 }
generate_otp()
generate OTP secret to store in AC_USER.USE_OTP_SECRET

References $Res, and generate_otp().

+ Here is the call graph for this function:

◆ save_email()

Noalyss_User::save_email ( $p_email)

Save the password from PREFERENCE MODULE.

Parameters
type$p_email

Definition at line 1700 of file noalyss_user.class.php.

1701 {
1702 $this->repository->exec_sql("update ac_users set use_email=$1 where use_login=$2",
1703 array($p_email, $_SESSION[SESSION_KEY.'g_user']));
1704 }

◆ save_global_preference()

Noalyss_User::save_global_preference ( $key,
$value )

Save the preference , the scope is global, the settings are saved into account_repository.

Parameters
$keyTHEME, LANG , PAGESIZE
$valuevalue of the key

Definition at line 801 of file noalyss_user.class.php.

802 {
803 $count=$this->repository->get_value("select count(*)
804 from
805 user_global_pref
806 where
807 parameter_type=$1 and user_id=$2", array($key, $this->login));
808 if ($count==1)
809 {
810 $this->repository->exec_sql("update user_global_pref set parameter_value=$1
811 where parameter_type=$2 and user_id=$3", array($value, $key, $this->login));
812 }
813 elseif ($count==0)
814 {
815 $this->repository->exec_sql("insert into user_global_pref(user_id,parameter_type,parameter_value)
816 values($1,$2,$3)", array($this->login, $key, $value));
817 }
818 }
$count

Referenced by get_first_week_day(), and get_vat_code_preference().

◆ save_password()

Noalyss_User::save_password ( $p_pass1,
$p_pass2 )

Save the password of the current user.

Parameters
string$p_pass1password (clear)
string$p_pass2for confirming password (clear)
See also
check_password_strength()
Returns
true : password successfully changed otherwise false

Definition at line 1678 of file noalyss_user.class.php.

1679 {
1680 if ($p_pass1==$p_pass2 && count(check_password_strength($p_pass1)['msg'])==0)
1681 {
1682
1683 $l_pass=md5($p_pass1);
1684 $this->setPassword($l_pass);
1685 $this->repository->exec_sql("update ac_users set use_pass=$1 where use_login=$2",
1686 array($l_pass, $this->login));
1687 return true;
1688 }
1689 else
1690 {
1691
1692 return false;
1693 }
1694 }
check_password_strength($password)
returns an double array with the error found and code , if the count is 0 then the password is very s...

◆ save_profile()

Noalyss_User::save_profile ( $p_id)

Definition at line 1458 of file noalyss_user.class.php.

1459 {
1460 $count=$this->db->get_value("select count(*) from profile_user where user_name=$1", array($this->login));
1461 if ($count==0)
1462 {
1463 $this->db->exec_sql("insert into profile_user(p_id,user_name)
1464 values ($1,$2)", array($p_id, $this->login));
1465 }
1466 else
1467 {
1468 $this->db->exec_sql("update profile_user set p_id=$1 where user_name=$2", array($p_id, $this->login));
1469 }
1470 }

◆ send_code_otp()

Noalyss_User::send_code_otp ( )

send a code to the user and save the expected code + UUID in a table OTP_SEND_SECRET

Returns
bool false if fails true if succeeds
Exceptions

Exception

Definition at line 2017 of file noalyss_user.class.php.

2018 {
2019 if ( $this->authent_method !=1 ) { return false; }
2020 $mail=new \Sendmail();
2021 $mail->set_format("HTML");
2022 $mail->set_from(ADMIN_WEB);
2023 $mail->mailto($this->getEmail());
2024 $mail->set_subject(_("NOALYSS : votre code secret "));
2025 $noalyss_url=NOALYSS_URL;
2026
2027
2028 if ( strlen(trim($this->otp_secret??"")) == 0 ) {
2029 throw new \Exception("noalyss_user.send_code_otp:secret empty",1945);
2030 }
2031 $otp=new \Noalyss\OTP();
2032 $code=$otp->compute_code($this->otp_secret);
2033 $message="<p>Bonjour,
2034 <br>
2035 <br>
2036 <p>Voici votre code secret utilisable pendant 10 minutes pour NOALYSS : <b> $code</b> .
2037 </p>
2038
2039 <p>
2040 Merci d'utiliser NOALYSS
2041 <br/>
2042 <br/>
2043 <br/>
2044
2045Cordialement,
2046 <br/>
2047 <br/>
2048
2049Noalyss team
2050 </p>
2051
2052 <p>
2053 <i> Si cet email est dans vos spams, ajoutez l'expéditeur dans votre carnet d'adresse</i>
2054 </p>
2055";
2056 try {
2057 $uuid= guidv4();
2058 // remove old for this user
2059 $this->repository->exec_sql("delete from otp_send_secret where use_id=$1 and os_code is not null"
2060 ,[$this->id]);
2061 // remove also old one
2062 $this->repository->exec_sql("delete from otp_send_secret where os_valid_time < now()");
2063 $now=new \DateTime();
2064 $valid=new \DateTime();
2065 $valid->modify('+10 minutes');
2066
2067 $otp_send_secret=new Otp_Send_Secret_SQL($this->repository);
2068 $otp_send_secret->set("use_id",$this->id)
2069 ->set('os_request',$uuid)
2070 ->set("os_code",$code)
2071 ->set('os_valid_time',$valid->format('d.m.Y H:i:s'));
2072 $otp_send_secret->save();
2073 $mail->set_message($message);
2074 $mail->compose();
2075 $mail->send();
2076 return $uuid;
2077 } catch (Exception $ex) {
2078 \record_log ($ex);
2079 throw new \Exception("noalyss_user.send_code_otp",1963,$ex);
2080 }
2081 }
guidv4($data=null)
generate an UUID
$ex
if(count($exist_request)> 1) $mail
Definition recover.php:100
$message
Definition recover.php:106
$noalyss_url
Definition recover.php:105

References $code, $ex, $mail, $message, $noalyss_url, $valid, _, getEmail(), guidv4(), and record_log().

+ Here is the call graph for this function:

◆ send_link_otp()

Noalyss_User::send_link_otp ( $base_url = null)

send an email with link to the user

Parameters
$base_url(string) http url to scan the QRCode, the url in the mail will be {$base_url}/index.php?otp={$uuid}

save in DB first

Definition at line 2087 of file noalyss_user.class.php.

2087 {
2088 $mail = new \Sendmail();
2089 $mail->set_format("HTML");
2090 $mail->set_from(ADMIN_WEB);
2091 $mail->mailto($this->getEmail());
2092 $mail->set_subject(_("NOALYSS : Double authentification lien pour 2FA: OTP"));
2093 $noalyss_url = $base_url??NOALYSS_URL;
2094 $uuid = guidv4();
2095 $valid_time=new \DateTime();
2096 $valid_time->add(new \DateInterval('PT12H'));
2097 $str_time=$valid_time->format('d-m-Y H:i');
2098 /**
2099 * save in DB first
2100 */
2101 $message = "<p>Bonjour,</p>
2102<p>
2103 Afin de pouvoir utiliser la double authentification avec 2FA: OTP, pourriez-vous
2104 suivre ce lien et scanner le QRCode avec votre application android freeOTP ou Google Authenticator.
2105 </p>
2106 <p>Ce lien expirera le <b>{$str_time}</b>.
2107 <br>
2108 <br>
2109 <br>
2110
2111 <a href=\"{$noalyss_url}/index.php?otp={$uuid}\">{$noalyss_url}/index.php?otp={$uuid}</a>
2112 </p>
2113
2114 <p>
2115
2116 Merci d'utiliser NOALYSS
2117 </p>
2118
2119<p>
2120Bien cordialement,
2121</p>
2122 <p>
2123 <i> Si cet email est dans vos spams, ajoutez l'expéditeur dans votre carnet d'adresse</i>
2124 </p>
2125";
2126 try {
2127
2128 // remove old for this user
2129 $this->repository->exec_sql("delete from otp_send_secret where use_id=$1 and os_code is null"
2130 ,[$this->id]);
2131 // remove also old one
2132 $this->repository->exec_sql("delete from otp_send_secret where os_valid_time < now()");
2133
2134 $otp_send_secret_sql = new \Otp_Send_Secret_SQL($this->repository);
2135 $otp_send_secret_sql->set('use_id', $this->id)
2136 ->set('os_valid_time',$valid_time->format('d-m-Y H:i'))
2137 ->set('os_request', $uuid);
2138
2139 $otp_send_secret_sql->save();
2140 $mail->set_message($message);
2141 $mail->compose();
2142 $mail->send();
2143 return $uuid;
2144 } catch (Exception $ex) {
2145 \record_log($ex);
2146 throw new \Exception("noalyss_user.send_link_otp",1998,$ex);
2147 }
2148 }

References $ex, $mail, $message, $noalyss_url, _, getEmail(), guidv4(), and record_log().

+ Here is the call graph for this function:

◆ set_access_mode()

Noalyss_User::set_access_mode ( $access_mode)

access_mode tells what mode must be used : pc or mobile

Definition at line 218 of file noalyss_user.class.php.

218 : object
219 {
220 $this->access_mode=$access_mode;
221 return $this;
222 }

References $access_mode.

◆ set_authent_method()

Noalyss_User::set_authent_method ( $authent_method)

Definition at line 1979 of file noalyss_user.class.php.

1979 {
1980 $this->authent_method = $authent_method;
1981 return $this;
1982 }

References $authent_method.

◆ set_default_periode()

Noalyss_User::set_default_periode ( )
private

Definition at line 744 of file noalyss_user.class.php.

745 {
746
747 /* get the first periode */
748 $sql='select min(p_id) as pid '
749 .' from parm_periode '
750 .' where p_closed = false and p_start = (select min(p_start) from parm_periode)';
751 $Res=$this->db->exec_sql($sql);
752
753 $pid=Database::fetch_result($Res, 0, 0);
754 /* if all the periode are closed, then we use the last closed period */
755 if ($pid==null)
756 {
757 $sql='select min(p_id) as pid '
758 .'from parm_periode '
759 .'where p_start = (select max(p_start) from parm_periode)';
760 $Res2=$this->db->exec_sql($sql);
761 $pid=Database::fetch_result($Res2, 0, 0);
762 if ($pid==null)
763 {
764 throw new Exception(_("Aucune période trouvéee !!!"));
765 }
766
767 $pid=Database::fetch_result($Res2, 0, 0);
768 }
769
770 $sql=sprintf("insert into user_local_pref (user_id,parameter_value,parameter_type)
771 values ('%s','%d','PERIODE')", $this->id, $pid);
772 $Res=$this->db->exec_sql($sql);
773 }
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all

References from, and p_id.

◆ set_folder_access()

Noalyss_User::set_folder_access ( $db_id,
$priv )

save the access of a folder

Parameters
$db_idthe dossier id
$privboolean, true then it is granted, false it is removed

Definition at line 563 of file noalyss_user.class.php.

564 {
565
566 if ($priv)
567 {
568 // the access is granted
569 $jnt=$this->repository->get_value("select jnt_id from jnt_use_dos where dos_id=$1 and use_id=$2", array($db_id, $this->id));
570
571 if ($this->repository->size()==0)
572 {
573
574 $Res=$this->repository->exec_sql("insert into jnt_use_dos(dos_id,use_id) values($1,$2)", array($db_id, $this->id));
575 }
576 }
577 else
578 {
579 // Access is revoked
580 $this->repository->exec_sql('delete from jnt_use_dos where use_id = $1 and dos_id = $2 ', array($this->id, $db_id));
581 }
582 }
$priv

References from.

◆ set_identified()

Noalyss_User::set_identified ( )

Definition at line 1988 of file noalyss_user.class.php.

1989 {
1990 $_SESSION[SESSION_KEY."db_auth"]='ok';
1991 }

◆ set_otp_secret()

Noalyss_User::set_otp_secret ( $otp_secret)

Definition at line 1984 of file noalyss_user.class.php.

1984 {
1985 $this->otp_secret = $otp_secret;
1986 return $this;
1987 }

References $otp_secret.

◆ set_periode()

Noalyss_User::set_periode ( $p_periode)

Set the selected periode in the user's preferences.

Parameters
$p_periodeperiode
-$p_user

Definition at line 738 of file noalyss_user.class.php.

739 {
740 $sql="update user_local_pref set parameter_value=$1 where user_id=$2 and parameter_type='PERIODE'";
741 $Res=$this->db->exec_sql($sql, [$p_periode, $this->id]);
742 }

◆ set_repository()

Noalyss_User::set_repository ( Database $repository)

set the repository

Returns
Database

Definition at line 96 of file noalyss_user.class.php.

96 {
97 $this->repository = $repository;
98 return $this;
99 }

References $repository.

◆ set_session_var()

Noalyss_User::set_session_var ( )

put user_login into Postgres config (session), it can be used for tracking users activities

Returns
void

Definition at line 105 of file noalyss_user.class.php.

106 {
107 $this->db->exec_sql(sprintf("select set_config('noalyss.user_login','%s',false)",
108 Database::escape_string($_SESSION[SESSION_KEY.'g_user'])));
109 $this->repository->exec_sql(sprintf("select set_config('noalyss.user_login','%s',false)",
110 Database::escape_string($_SESSION[SESSION_KEY.'g_user'])));
111
112 }

References db, and DatabaseCore\escape_string().

Referenced by __construct().

+ Here is the call graph for this function:

◆ set_status_security_action()

Noalyss_User::set_status_security_action ( $p_value)

Set the flag in the table user_active_security.

Parameters
int$p_value1==enable , 0 = disable @exceptions invalid value

Definition at line 1886 of file noalyss_user.class.php.

1887 {
1888 if ($p_value!=0&&$p_value!=1)
1889 throw new Exception(_("Valeur invalide"));
1890 $exist=$this->db->get_value("select count(*) from user_active_security where us_login=$1", [$this->login]);
1891 $flag=($p_value==1)?"Y":"N";
1892 if ($exist==0)
1893 {
1894 $this->db->exec_sql("insert into user_active_security (us_login,us_action,us_ledger) values ($1,$2,$3)",
1895 [$this->login, $flag, 'Y']);
1896 }
1897 else
1898 {
1899 $this->db->exec_sql("update user_active_security set us_action=$1 where us_login = $2",
1900 [$flag, $this->login]);
1901 }
1902 }
$flag
Definition install.php:535

References $flag, _, and db.

◆ set_status_security_ledger()

Noalyss_User::set_status_security_ledger ( $p_value)

Set the flag in the table user_active_security.

Parameters
int$p_value1==enable , 0 = disable @exceptions invalid value

Definition at line 1850 of file noalyss_user.class.php.

1851 {
1852 if ($p_value!=0&&$p_value!=1)
1853 throw new Exception(_("Valeur invalide"));
1854 $exist=$this->db->get_value("select count(*) from user_active_security where us_login=$1", [$this->login]);
1855 $flag=($p_value==1)?"Y":"N";
1856 if ($exist==0)
1857 {
1858 $this->db->exec_sql("insert into user_active_security (us_login,us_ledger,us_action) values ($1,$2,$3)",
1859 [$this->login, $flag, 'Y']);
1860 }
1861 else
1862 {
1863 $this->db->exec_sql("update user_active_security set us_ledger=$1 where us_login = $2",
1864 [$flag, $this->login]);
1865 }
1866 }

References $flag, _, and db.

◆ setActive()

Noalyss_User::setActive ( $active)
Parameters
mixed$active

Definition at line 331 of file noalyss_user.class.php.

331 : void
332 {
333 $this->active=$active;
334 }

References $active.

◆ setAdmin()

Noalyss_User::setAdmin ( $admin)
Parameters
default | int | mixed | string | string[] | null$admin

Definition at line 267 of file noalyss_user.class.php.

267 : void
268 {
269 $this->admin=$admin;
270 }

References $admin.

◆ setDb()

Noalyss_User::setDb ( $db)
Parameters
mixed$db

Definition at line 251 of file noalyss_user.class.php.

251 : void
252 {
253 $this->db=$db;
254 }

References $db, and db.

◆ setEmail()

Noalyss_User::setEmail ( $email)
Parameters
mixed$email

Definition at line 379 of file noalyss_user.class.php.

379 : void
380 {
381 $this->email=$email;
382 }

References $email.

◆ setFirstName()

Noalyss_User::setFirstName ( $first_name)
Parameters
default | mixed | string | string[] | null$first_name

Definition at line 299 of file noalyss_user.class.php.

299 : void
300 {
301 $this->first_name=$first_name;
302 }

References $first_name.

◆ setId()

Noalyss_User::setId ( int $id)
Parameters
int | mixed$id

Definition at line 235 of file noalyss_user.class.php.

235 : void
236 {
237 $this->id=$id;
238 }

References $id.

◆ setLogin()

Noalyss_User::setLogin ( string $login)
Parameters
string$login

Definition at line 347 of file noalyss_user.class.php.

347 : void
348 {
349 $this->login=$login;
350 }

References $login.

◆ setName()

Noalyss_User::setName ( $name)
Parameters
default | mixed | string | string[] | null$name

Definition at line 315 of file noalyss_user.class.php.

315 : void
316 {
317 $this->name=$name;
318 }

References $name, and name.

◆ setPassword()

Noalyss_User::setPassword ( $password)
Parameters
mixed$password

Definition at line 363 of file noalyss_user.class.php.

363 : void
364 {
365 $this->password=$password;
366 }

References $password.

◆ setValid()

Noalyss_User::setValid ( int $valid)
Parameters
int$valid

Definition at line 283 of file noalyss_user.class.php.

283 : void
284 {
285 $this->valid=$valid;
286 }

References $valid.

◆ show_dossier()

Noalyss_User::show_dossier ( $p_filtre = "")

Show all the available folder for the users at the login page.

For the special case 'E' go directly to extension and bypasse the dashboard

Parameters
$p_filtreuser
Returns
table in HTML

Definition at line 1298 of file noalyss_user.class.php.

1299 {
1300 $p_array=$this->get_available_folder($p_filtre);
1301
1302 $result="";
1303
1304 $result.="<TABLE id=\"folder\" class=\"result\">";
1305 $result.="<tr>";
1306 $result.="<th>";
1307 $result.=_("Id");
1308 $result.="</th>";
1309 $result.="<th>";
1310 $result.=_("Nom");
1311 $result.="</th>";
1312 $result.="<th>";
1313 $result.=_("Description");
1314 $result.="</th>";
1315 $result.="</tr>";
1316 if ($p_array==0)
1317 {
1318 $result.="<tr>";
1319 $result.='<td style="width:auto" colspan=3>';
1320 $result.=_("Aucun dossier disponible");
1321 $result.='</td>';
1322 $result.="</tr>";
1323 return $result;
1324 }
1325
1326 for ($i=0; $i<sizeof($p_array); $i++)
1327 {
1328
1329 $id=$p_array[$i]['dos_id'];
1330 $name=$p_array[$i]['dos_name'];
1331 $desc=$p_array[$i]['dos_description'];
1332 if ($i%2==0)
1333 $tr="odd";
1334 else
1335 $tr="even";
1336 $target="do.php?gDossier=$id";
1337
1338 $result.="<TR class=\"$tr\">";
1339
1340 $result.=td($id, ' class="num" ');
1341 $result.="<TD class=\"$tr\">";
1342 $result.="<A class=\"dossier\" HREF=\"$target\">";
1343 $result.=" <B>".h($name)."</B>";
1344 $result.="</A>";
1345 $result.="</TD>";
1346 $desc=($desc=="")?"<i>Aucune description</i>":h($desc);
1347 $desc="<A class=\"dossier\" HREF=\"$target\">$desc</A>";
1348 $result.="<TD class=\"$tr\" >".$desc;
1349 $result.="</TD>";
1350 $result.="</TR>";
1351 }
1352 $result.="</TABLE>";
1353 return $result;
1354 }
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
h( $row[ 'oa_description'])
get_available_folder($p_filter="")
Get all the available folders for the users, checked with the security.

References style, and td().

+ Here is the call graph for this function:

◆ sql_readable_profile()

Noalyss_User::sql_readable_profile ( )

Compute the SQL string for the readable profile, the subselect for p_id , example p_id in $g_user->sql_readable_profile.

The administrator can read all the profiles

Returns
SQL string with the subselect for p_id

Definition at line 1532 of file noalyss_user.class.php.

1533 {
1534 if ($this->admin!=1)
1535 {
1536 $sql=" (select p_granted "
1537 ." from user_sec_action_profile "
1538 ." where ua_right in ('W','R','O') and p_id=".$this->get_profile().") ";
1539 }
1540 else
1541 {
1542 $sql="(select p_id p_granted from profile)";
1543 }
1544 return $sql;
1545 }

◆ sql_writable_profile()

Noalyss_User::sql_writable_profile ( )

Compute the SQL string for the writable profile, the subselect for p_id , example p_id in $g_user->sql_writable_profile.

The administrator can access all the profiles R = Read Only W = Write and delete O = write and not delete

Returns
SQL string with the subselect for p_id

Definition at line 1491 of file noalyss_user.class.php.

1492 {
1493 if ($this->admin!=1)
1494 {
1495 $sql=" (select p_granted "
1496 ." from user_sec_action_profile "
1497 ." where ua_right in ('W','O') and p_id=".$this->get_profile().") ";
1498 }
1499 else
1500 {
1501 $sql="(select p_id p_granted from profile)";
1502 }
1503 return $sql;
1504 }

◆ update_global_pref()

Noalyss_User::update_global_pref ( $p_type,
$p_value = "" )

update default pref if value is not given then use the default value

Parameters
$p_typeparameter's type
$p_valueparameter's value value of the type

Definition at line 1015 of file noalyss_user.class.php.

1016 {
1017 $default_parameter=array("THEME"=>"classic",
1018 "PAGESIZE"=>"50",
1019 "LANG"=>'fr_FR.utf8',
1020 'TOPMENU'=>'SELECT',
1021 'csv_fieldsep'=>'0',
1022 'csv_decimal'=>'0',
1023 'csv_encoding'=>'utf8',
1024 'first_week_day'=>1
1025 );
1026 $Sql="update user_global_pref set parameter_value=$1
1027 where parameter_type=$2 and
1028 user_id=$3";
1029 $value=($p_value=="")?$default_parameter[$p_type]:$p_value;
1030 $this->repository->exec_sql($Sql, array($value, $p_type, $this->login));
1031 }

Field Documentation

◆ $access_mode

Noalyss_User::$access_mode

MOBILE or PC depending if when connecting $login contains @mobile.

Definition at line 49 of file noalyss_user.class.php.

Referenced by set_access_mode().

◆ $active

Noalyss_User::$active

1 active , 0 disables

Definition at line 45 of file noalyss_user.class.php.

Referenced by setActive().

◆ $admin

Noalyss_User::$admin

is or is not admin

Definition at line 40 of file noalyss_user.class.php.

Referenced by setAdmin().

◆ $authent_method

Noalyss_User::$authent_method

authentication method use for this user

Definition at line 52 of file noalyss_user.class.php.

Referenced by set_authent_method().

◆ $db

Noalyss_User::$db

database connx to the folder NOT repository

Definition at line 39 of file noalyss_user.class.php.

Referenced by setDb().

◆ $email

Noalyss_User::$email

user's email

Definition at line 48 of file noalyss_user.class.php.

Referenced by setEmail().

◆ $first_name

Noalyss_User::$first_name

Definition at line 42 of file noalyss_user.class.php.

Referenced by setFirstName().

◆ $id

Noalyss_User::$id

in account_repository , ac_users.use_id

Definition at line 37 of file noalyss_user.class.php.

Referenced by setId().

◆ $lang

Noalyss_User::$lang

user's language

Definition at line 50 of file noalyss_user.class.php.

◆ $last_name

Noalyss_User::$last_name

user's last_name

Definition at line 43 of file noalyss_user.class.php.

◆ $login

Noalyss_User::$login

login lower case

Definition at line 46 of file noalyss_user.class.php.

Referenced by setLogin().

◆ $name

Noalyss_User::$name

Definition at line 44 of file noalyss_user.class.php.

Referenced by remove_inexistant_user(), and setName().

◆ $otp_secret

Noalyss_User::$otp_secret
private

string use as secret for OTP

Definition at line 53 of file noalyss_user.class.php.

Referenced by set_otp_secret().

◆ $password

Noalyss_User::$password

md5 of the password

Definition at line 47 of file noalyss_user.class.php.

Referenced by setPassword().

◆ $repository

Noalyss_User::$repository
private

account_repository (\Database )

Definition at line 54 of file noalyss_user.class.php.

Referenced by __construct(), and set_repository().

◆ $theme

Noalyss_User::$theme

user's CSS Theme

Definition at line 51 of file noalyss_user.class.php.

◆ $valid

Noalyss_User::$valid

is or is not valid

Definition at line 41 of file noalyss_user.class.php.

Referenced by send_code_otp(), and setValid().


The documentation for this class was generated from the following file: