Hello

I have a ticket helpdesk script that I am converting to make it completely skinnable. For this, there is a file called header.php which includes the link to a css file. The code is below

<link rel="stylesheet" href="<?php print $GLOBALS["URL"];?>/templates/gothica/aquarius.css" type="text/css" />

I want that the path to css file be stored in a db parameter, and this value should be fetched from db and passed to the php file.
If it is not possible to pass it from db. then pass the value from a config file

Is this possible, and if so, how to code it.

Thanks
Arvind.

Member Avatar for diafol

A config file is easy:

//change this to the necessary folder
$hdk_root = '/helpdesk';
$hdk_defaultcss = 'aquarius.css';


//other app config variables to follow

All files to include the config file

echo "<link href=\"{$hdk_root}/css/{$hdk_defaultcss}\" ....

This could be set manually by an install script. However if you need to be able to swap the css file once the app is installed, you can do this via textfile, cookie or via db. My personal preference would be via DB.

create a 'config' table and fields 'id' (autoincrement), 'key' (varchar), 'data' (varchar)

when the user swaps a css file the 'data' field where key = 'cssfile' changes to the name of the css file.

The header.php file check for a value in the DB where key = 'cssfile', if it's blank, then use the default value from the config file, otherwise use the value in the 'data' field.

//retrieve the data from the db and then:

if($rsd['data'] != ''){
  $cssfile = stripslashes($rsd['data']);
}else{
  $cssfile = $hdk_defaultcss;
} 
echo "<link href=\"{$hdk_root}/css/{$cssfile}\" ....

A cookie could be used just as easily with setcookie() function and $_COOKIE[] variable. However, cookies can be eaten or scrubbed inadvertently.

Just a quick note, you'll need a page refresh to display the changed skin, unless you use js (and possibly ajax). However a page refresh shouldn't cause to much hassle. If you use a dropdown to choose a skin, it could be set to submit a form with the onchange attribute (js). However, this may be frowned upon with regard to accessibility.

commented: concise answer to the problem +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.