First, to be able to use the
$active_modules variable, you have to have an entry in the xcart_modules table for your module. Also, you need to stay consistent with naming of the module directories, styleswitch vs StyleSwitch (and it needs to match your entry into xcart_modules).
Just a note, you don't *need* to configure this as a module, imho, as you could just set it up as a straight include, but that's up to you.
Second, you're trying to include a PHP file in Smarty, which you cannot do (it won't work properly), at least using the method that you're using (
this is the proper method), but even then, you don't need to include that php file from smarty, as you already have it included from home.php, and the file has already created a variable for use with smarty.
Sooooo...
modules/StyleSwitch/styleswitch.php:
PHP Code:
<?php
if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); }
$switchid = false;
if( $current_category['parentid'] > 0 ) {
/* Get array of all cats */
$all_cats = func_query("SELECT categoryid, parentid FROM xcart_categories");
/* Build 2-dim array of parent->child cats */
$all_cat_arr = array();
foreach($all_cats AS $_cat) {
$all_cat_arr[$_cat['parentid']][] = $_cat['categoryid'];
}
/* Get absolute parent */
$switchid = _get_absolute_parent($current_category['parentid'], $all_cat_arr);
}
if( !$switchid ){
$switchid = $current_category['categoryid'];
}
switch ($switchid) {
case '15':
$StyleSwitch = '<style type="text/css">';
$StyleSwitch .= 'body {background-image: url(images/lolalayout/bg-15.gif);}';
$StyleSwitch .= '.background { background-image: url(images/lolalayout/15.gif);}';
$StyleSwitch .= '</style>';
$smarty->assign('StyleSwitch', $StyleSwitch);
break;
case '5':
$StyleSwitch = '<style type="text/css">';
$StyleSwitch .= 'body {background-image: url(images/lolalayout/bg-5.gif);}';
$StyleSwitch .= '.background { background: #000000;}';
$StyleSwitch .= '</style>';
$smarty->assign('StyleSwitch', $StyleSwitch);
break;
}
function _get_absolute_parent($catid, $all_cats) {
reset($all_cats);
foreach($all_cats AS $_parentcat=>$_children) {
if( in_array($catid, $_children) ) {
if($_parentcat == 0) {
return $catid;
}
return _get_absolute_parent($_parentcat, $all_cats);
}
}
/* else, failed */
return false;
}
?>
home.php (before line:
func_display("customer/home.tpl",$smarty);):
PHP Code:
if ($active_modules['StyleSwitch'])
include $xcart_dir . '/modules/StyleSwitch/styleswitch.php';
home.tpl (before line:
</head>):
Code:
{if $StyleSwitch ne ""}{$StyleSwitch}{/if}
NOTE: I haven't tested this yet, but should point you in the right direction...