Welcome to WebmasterWorld Guest from 18.205.176.85

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

changing whole template after user login

changing whole template after user login

     
1:45 pm on Apr 17, 2011 (gmt 0)

New User

5+ Year Member

joined:Apr 17, 2011
posts:1
votes: 0


Hello everyone,

I'm really new to php, there
I must recognize that my php skills are near to none.I started to learn it, but i'm still way too far from the skills needed to achieve what i need. So, here i am, asking for your help.
I try to modify an script to load a different template after an user is logged in, depending on the user rights on the website.

Basicaly, i have 2 templates (template1 and template2) , every template is into an different directory ("basepath/template/template1" and "basepath/template/template2" ) and 3 user types (member, agent, admin) and of course guest users, but they don't need to login, so i didn't count them too.

I need to load for example template1 if user is agent and/or admin, else (for guests and members) i need to load template2.

What i have so far is:



function get_user_type($user)
{
// grabs the main info for a given user
global $conn, $config, $lang;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$display = '';

$user = $misc->make_db_extra_safe($user);
$sql = "SELECT userdb_is_agent,userdb_is_admin FROM " . $config['table_prefix'] . "userdb WHERE (userdb_id = $user)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}
// get main listings data
while (!$recordSet->EOF) {
$agent = $misc->make_db_unsafe ($recordSet->fields['userdb_is_agent']);
$admin = $misc->make_db_unsafe ($recordSet->fields['userdb_is_admin']);
$recordSet->MoveNext();
} // end while
if($admin=='yes'){

CODE TO LOAD TEMPLATE 1 HERE

}elseif($agent=='yes'){

CODE TO LOAD TEMPLATE 1 HERE

}
CODE TO LOAD TEMPLATE 2 HERE

}




I have no clue how to load the template using the path to that template. I suppose somehow a session handler is also needed and there is something already into the core of the script i used (open-realty 2.5.8):


if (isset($_SESSION["template"]))
{
$config["template"] = $_SESSION["template"];
} else {
$config["template"] = $misc->make_db_unsafe($recordSet->fields["controlpanel_template"]);
}


I just need to know if any modification is necessary to this one too..

If someone can help me up with, if not a line of code, at least an idea, this would be great

Thank you all,

Marin
2:40 am on May 17, 2011 (gmt 0)

Full Member

10+ Year Member

joined:June 1, 2007
posts:201
votes: 0


Maybe you could look into the switch statment this is not going to work but can give you an idea of how to use it


function get_user_type($user)
{
// grabs the main info for a given user
global $conn, $config, $lang;
require_once($config['basepath'] . '/include/misc.inc.php');
$misc = new misc();
$display = '';

$user = $misc->make_db_extra_safe($user);
$sql = "SELECT userdb_is_agent,userdb_is_admin FROM " . $config['table_prefix'] . "userdb WHERE (userdb_id = $user)";
$recordSet = $conn->Execute($sql);
if ($recordSet === false) {
$misc->log_error($sql);
}

// get main listings data
while (!$recordSet->EOF) {
$agent = $misc->make_db_unsafe ($recordSet->fields['userdb_is_agent']);
$admin = $misc->make_db_unsafe ($recordSet->fields['userdb_is_admin']);
$recordSet->MoveNext();
} // end while

if ($admin == 'yes') {
$type = "admin";
//CODE TO LOAD TEMPLATE 1 HERE
} elseif ($agent == 'yes') {
$type = "agent";
//CODE TO LOAD TEMPLATE 1 HERE
} else {
$type = "default";
//CODE TO LOAD TEMPLATE 2 HERE
}

switch($type"]) {
case 'admin':
include "basepath/template/template1";
break;
case 'agent':
include "basepath/template/template1";
break;
default:
include "basepath/template/template2";
break;
}


Regards,
Brandon