2008-10-07 11:23:56
Theme based on urldomain code
So, I needed to have a theme based on the ulr, as we have different clients using different urls and they each want a different template...naturally. The modifications are pretty simple and only require you have the ServerName set in your web server config file for each url and to change 3 ATutor files and create one new one:
New file) include/set_theme_by_url.inc.php Sample contents:
session_start();
if(!$_SESSION['prefs']){
$_SESSION['prefs']=array();
}
switch($_SERVER['SERVER_NAME']){
case "flintstones.mydomain.com":
$_SESSION['prefs']['PREF_THEME']="flintstones";
$_SESSION['prefs']['not_default_theme']=1;
define('SITE_NAME',"Flintstones Training");
break;
default:
$_SESSION['prefs']['PREF_THEME']="jetsons";
$_SESSION['prefs']['not_default_theme']=1;
define('SITE_NAME',"Jetsons Training");
break;
}
1) include/config.inc.php, at the very bottom, add:
include("set_theme_by_url.inc.php");
2) include/vitals.inc.php, add the same as above right after the session_start() call on or about line 97
3) include/header.inc.php, add the same as above on or about line 45 (after the three savant calls) and change
$savant->assign('base_tmpl_path', $_SERVER['HTTP_HOST']);
to:
if($_SESSION['prefs']['not_default_theme']==1){
$savant->assign('base_tmpl_path', $_base_path . '/themes/'. $_SESSION['prefs']['PREF_THEME']);
}else{
$savant->assign('base_tmpl_path', $_SERVER['HTTP_HOST']);
}
Then, at the bottom where it says:
$savant->display('themes/'. $_SESSION['prefs']['PREF_THEME'] .'/include/header.tmpl.php');
change that to:
if(substr_count($_SERVER["REQUEST_URI"],"/")>1){//then it's a subdir
$savant->display('include/header.tmpl.php');
}else{
$savant->display('themes/'. $_SESSION['prefs']['PREF_THEME'] .'/include/header.tmpl.php');
}
I think that's it. I call define('SITE_NAME') in the new include file, so it's invoked before the same call in vitals.inc.php and won't get reset. Now the site theme will be constant, regardless of course theme, etc.
Let me know if anyone has any questions or suggestions to make it better.