<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Display Role Name of User]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=2161&amp;type=atom" />
	<updated>2011-09-13T06:16:33Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=2161</id>
		<entry>
			<title type="html"><![CDATA[Re: Display Role Name of User]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=10222#p10222" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Apple wrote:</cite><blockquote><p>Hi bhoo-day,</p><p>You are so great. The code really work as it is. It really save me a lot of time. Without your code, I have no way to accomplish it.<br />Thank you very much for your kindness to allow us to share the code with you.</p></blockquote></div><p>You&#039;re welcome bro.</p><p>Glad if you can make it <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[bhoo-day]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=6251</uri>
			</author>
			<updated>2011-09-13T06:16:33Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=10222#p10222</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Display Role Name of User]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=10219#p10219" />
			<content type="html"><![CDATA[<p>Hi bhoo-day,</p><p>You are so great. The code really work as it is. It really save me a lot of time. Without your code, I have no way to accomplish it.<br />Thank you very much for your kindness to allow us to share the code with you.</p>]]></content>
			<author>
				<name><![CDATA[Apple]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=8430</uri>
			</author>
			<updated>2011-09-13T04:11:06Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=10219#p10219</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Display Role Name of User]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=10195#p10195" />
			<content type="html"><![CDATA[<p>Hi Apple, </p><p>I just made some modified lines in these files. Just add the modified lines into yours. </p><p>Just see the comment &quot;MY CUSTOM CODE FOR ROLE NAME&quot;<br />I couldn&#039;t share whole file because too long and it will make you confuse to read those a lot of lines <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>For current_user.inc (location at includes/current_user.inc)</p><div class="codebox"><pre><code>class current_user
{
    var $user;
    var $loginname;
    var $username;
    var $name;
    var $company; // user&#039;s company
    var $pos;
    var $access;        
    var $timeout;
    var $last_act;
    var $role_set = false;
    var $old_db;
    var $logged;
    var $ui_mode = 0;
    
    var $prefs;
    var $cur_con; // current db connection (can be different from $company for superuser)
        
        /* custom */
        var $rolename; // MY CUSTOM CODE FOR ROLE NAME
        var $org_id;

    function current_user()
    {
        global $def_coy;
        
        $this-&gt;loginname = $this-&gt;username = $this-&gt;name = &quot;&quot;;
        $this-&gt;company = isset($def_coy)? $def_coy : 0;
        $this-&gt;logged = false;

        $this-&gt;prefs = new user_prefs();
    }

    function logged_in()
    {
        return $this-&gt;logged;
    }

    function set_company($company)
    {
        $this-&gt;company = $company;
    }

    function login($company, $loginname, $password)
    {
        global $security_areas, $security_groups, $security_headings, $path_to_root;
        
        $this-&gt;set_company($company);
        $this-&gt;logged = false;

        $Auth_Result = get_user_for_login($loginname, $password);

        if (db_num_rows($Auth_Result) &gt; 0)
        {
            $myrow = db_fetch($Auth_Result);
            $this-&gt;old_db = isset($myrow[&quot;full_access&quot;]);
            if (! @$myrow[&quot;inactive&quot;]) {
                if ($this-&gt;old_db) { 
                    // Transition code:
                    // db was not yet upgraded after source update to v.2.2
                    // give enough access for admin user to continue upgrade
                    if (!isset($security_groups) || !isset($security_headings)) {
                        echo &quot;&lt;center&gt;&lt;br&gt;&lt;br&gt;&lt;font size=&#039;5&#039; color=&#039;red&#039;&gt;&lt;b&gt;&quot;;
                        echo _(&#039;Before software upgrade you have to include old $security_groups and $security_headings arrays from old config.php file to the new one.&#039;);
                        echo &#039;&lt;br&gt;&#039;.&quot;&lt;a href=$path_to_root/index.php&gt;&quot;._(&quot;Back&quot;).&quot;&lt;/a&gt;&quot;;
                        echo &quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;/center&gt;&quot;;
                        exit;
                    }
                    $this-&gt;access = $myrow[&quot;full_access&quot;];
                    if (in_array(20, $security_groups[$this-&gt;access]))
                        // temporary access for admin users
                        $this-&gt;role_set[] = $security_areas[&#039;SA_SOFTWAREUPGRADE&#039;][0];
                    else {
                        echo &quot;&lt;center&gt;&lt;br&gt;&lt;br&gt;&lt;font size=&#039;5&#039; color=&#039;red&#039;&gt;&lt;b&gt;&quot;;
                        echo _(&#039;System is available for site admin only until full database upgrade&#039;);
                        echo &quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;/center&gt;&quot;;
                        exit;
                    }
                } else {
                    $this-&gt;role_set = array();
                    $this-&gt;access = $myrow[&quot;role_id&quot;];
                    // store area codes available for current user role
                    $role = get_security_role($this-&gt;access);
                    if (!$role) 
                        return false;
                    foreach( $role[&#039;areas&#039;] as $code )
                        // filter only area codes for enabled security sections
                        if (in_array($code&amp;~0xff, $role[&#039;sections&#039;])) 
                            $this-&gt;role_set[] = $code;
                                                
                                         $this-&gt;rolename = $role[&#039;role&#039;];  // MY CUSTOM CODE FOR ROLE NAME 
                }
                $this-&gt;name = $myrow[&quot;real_name&quot;];
                $this-&gt;pos = $myrow[&quot;pos&quot;];
                $this-&gt;org_id = $myrow[&quot;org_id&quot;];
                $this-&gt;loginname = $loginname;
                $this-&gt;username = $this-&gt;loginname;
                $this-&gt;prefs = new user_prefs($myrow);
                $this-&gt;user = @$myrow[&quot;id&quot;];
                update_user_visitdate($this-&gt;username);
                $this-&gt;logged = true;
                $this-&gt;last_act = time();
                $this-&gt;timeout = session_timeout();
            }
        }
        return $this-&gt;logged;
    }

        .....
        .....</code></pre></div><p>For security_db.inc (location at admin/db/security_db.inc)</p><div class="codebox"><pre><code>..........

function get_security_role($id)
{
    $sql = &quot;SELECT * FROM &quot;.TB_PREF.&quot;security_roles WHERE id=&quot;.(int)$id;
    $ret = db_query($sql, &quot;could not retrieve security roles&quot;);
    $row = db_fetch($ret);
    if ($row != false) {

        $row[&#039;role&#039;] = $row[&#039;role&#039;]; // MY CUSTOM CODE FOR ROLE NAME

        $row[&#039;areas&#039;] = explode(&#039;;&#039;, $row[&#039;areas&#039;]);

        $row[&#039;sections&#039;] = explode(&#039;;&#039;, $row[&#039;sections&#039;]);
    }
    return $row;
}

...................</code></pre></div><p>renderer.php (location at themes/default/renderer.php)</p><div class="codebox"><pre><code>..............
echo &quot;&lt;p id=&#039;user-info&#039;&gt;&quot; . _(&quot;Welcome&quot;) . &quot;, &quot; . $_SESSION[&quot;wa_current_user&quot;]-&gt;name .
       &quot; (&quot; . $_SESSION[&quot;wa_current_user&quot;]-&gt;rolename . &quot;)&lt;/p&gt;&quot;;
..............</code></pre></div><p>now I can access rolename via $_SESSION[&#039;wa_current_user&#039;]-&gt;rolename</p><p>Good luck brother</p><p>Feel free to ask me if you still need help <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[bhoo-day]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=6251</uri>
			</author>
			<updated>2011-09-09T07:06:24Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=10195#p10195</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Display Role Name of User]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=10177#p10177" />
			<content type="html"><![CDATA[<p>Hi bhoo-day,</p><p>I am very keen to know how you managed to add the role name to the header or footer. I would appreciate very much if you could share your code on the modification part of current_user.inc, security_db.inc and renderer.php.&nbsp; I tried to figure out the three files but stumble at there because of lack of knowledge. Please help.</p><p>Thank you very much.</p>]]></content>
			<author>
				<name><![CDATA[Apple]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=8430</uri>
			</author>
			<updated>2011-09-06T15:52:28Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=10177#p10177</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Display Role Name of User]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=9499#p9499" />
			<content type="html"><![CDATA[<p>Thanks Janusz for your reply. </p><p>So, I have successfully added a role name by modifying current_user.inc, security_db.inc and renderer.php. Now I can access it via current_user object. <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[bhoo-day]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=6251</uri>
			</author>
			<updated>2011-06-20T04:19:19Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=9499#p9499</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Display Role Name of User]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=9487#p9487" />
			<content type="html"><![CDATA[<p>Role name is not stored in current_user object. role_id is id of the role in security_roles table.<br />Janusz</p>]]></content>
			<author>
				<name><![CDATA[itronics]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=89</uri>
			</author>
			<updated>2011-06-17T21:04:33Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=9487#p9487</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Display Role Name of User]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=9485#p9485" />
			<content type="html"><![CDATA[<p>Hello everybody, </p><p>The default display of user information in FA is only name. I want to display role name as well at the top of header. It means that I have to add it inside renderer.php<br />But, in $_SESSION variabel, the information so far that I can get is [access] aka id field of security_roles db.&nbsp; </p><p>The session variabel can be seen below</p><div class="codebox"><pre><code> [wa_current_user] =&gt; current_user Object
        (
            [user] =&gt; 1
            [loginname] =&gt; admin
            [username] =&gt; admin
            [name] =&gt; Administrator
            [company] =&gt; 0
            [pos] =&gt; 1
            [access] =&gt; 2
             ............
         )</code></pre></div><p>How is the correct way to get this role name inside renderer.php?</p><p>Thanks for help <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[bhoo-day]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=6251</uri>
			</author>
			<updated>2011-06-17T10:29:12Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=9485#p9485</id>
		</entry>
</feed>
