Removed many global variables from config.default.php to GL Setup, Company Setup...
[fa-stable.git] / includes / current_user.inc
index 90a91a9c079b68e45344f3ed0609b87c9eddf2a8..26b288a1e884463a22dd677521f04f205c041a25 100644 (file)
@@ -22,6 +22,7 @@ class current_user
        var $loginname;
        var $username;
        var $name;
+       var $email;
        var $company; // user's company
        var $pos;
        var $access;
@@ -53,12 +54,12 @@ class current_user
 
        function set_company($company)
        {
-               $this->company = $company;
+               $this->company = (int)$company;
        }
 
        function login($company, $loginname, $password)
        {
-               global $security_areas, $security_groups, $security_headings, $path_to_root, $dflt_lang;
+               global $security_areas, $security_groups, $security_headings, $path_to_root, $dflt_lang, $login_delay;
 
                $this->set_company($company);
            $this->logged = false;
@@ -76,7 +77,8 @@ class current_user
                if (!isset($Auth_Result))       // if not used: standard method
                        $Auth_Result = get_user_auth($loginname, md5($password));
 
-               write_login_filelog($loginname, $Auth_Result);
+               if ($login_delay > 0)
+                       write_login_filelog($loginname, $Auth_Result);
 
                if ($Auth_Result)
                {
@@ -129,6 +131,7 @@ class current_user
                    $this->username = $this->loginname;
                    $this->prefs = new user_prefs($myrow);
                    $this->user = @$myrow["id"];
+                $this->email = @$myrow["email"];
                        update_user_visitdate($this->username);
                        $this->logged = true;
                                $this->last_act = time();
@@ -138,6 +141,32 @@ class current_user
                return $this->logged;
        }
 
+       function reset_password($company, $email) {
+               global $app_title;
+
+               $this->set_company($company);
+               $this->logged = false;
+
+               set_global_connection();
+
+               $myrow = get_user_by_email($email);
+
+               if ($myrow['id'] != "") {
+
+                       $bytes = openssl_random_pseudo_bytes(8, $cstrong);
+                       $password   = base64_encode($bytes);
+
+                       $hash = md5($password);
+
+                       update_user_password($myrow['id'], $myrow['user_id'], $hash);
+
+                       mail($myrow['email'], _("New password for")." ".$app_title, $password);
+
+                       return true;
+               }
+               return false;
+    }
+
        function check_user_access()
        {
                global $security_groups;
@@ -518,6 +547,25 @@ function user_transaction_days()
     return $_SESSION["wa_current_user"]->prefs->transaction_days();
 }
 
+function user_save_report_selections()
+{
+    return $_SESSION["wa_current_user"]->prefs->save_report_selections();
+}
+
+function user_use_date_picker()
+{
+    return $_SESSION["wa_current_user"]->prefs->use_date_picker();
+}
+
+function user_def_print_destination()
+{
+    return $_SESSION["wa_current_user"]->prefs->def_print_destination();
+}
+
+function user_def_print_orientation()
+{
+    return $_SESSION["wa_current_user"]->prefs->def_print_orientation();
+}
 
 function user_check_access($sec_area)
 {
@@ -630,6 +678,14 @@ function array_search_key($needle, $haystack, $valuekey=null)
        return @$keys[0];
 }
 
+// Recalculate report columns if orientation is landscape.
+function recalculate_cols(&$cols)
+{
+       $factor = (user_pagesize() == "A4" ? 1.4 : 1.3);
+       foreach($cols as $key => $col)
+               $cols[$key] = intval($col * $factor); 
+}
+
 function flush_dir($path, $wipe = false) 
 {
        $dir = opendir($path);