Location: PHPKode > projects > NetLink > netlink_os/update_css.php
<?php
$login=$_SESSION['login'];

include("db.php");

$dbh=mysql_connect ($host,$user,$pass) or die ('MySQL Error: ' . mysql_error());
mysql_select_db ($table); 
$sql="SELECT * FROM CSS_TEMP WHERE Username='$login'";
$rs=mysql_query($sql,$dbh);
$row=mysql_fetch_array($rs);
$temp_text=$row['text'];
$temp_back=$row['background'];
$temp_alink=$row['activelink'];
$temp_vlink=$row['vlink'];
$temp_link=$row['link'];
$temp_h1=$row['h1'];
$temp_h2=$row['h2'];


$sql_text="UPDATE CSS SET text='$temp_text' WHERE Username='$login'";
$rs_text=mysql_query($sql_text,$dbh);
$sql_bg="UPDATE CSS SET background='$temp_back' WHERE Username='$login'";
$rs_bg=mysql_query($sql_bg,$dbh);
$sql_alink="UPDATE CSS SET activelink='$temp_alink' WHERE Username='$login'";
$rs_alink=mysql_query($sql_alink,$dbh);
$sql_link="UPDATE CSS SET link='$temp_link' WHERE Username='$login'";
$rs_link=mysql_query($sql_link,$dbh);
$sql_vlink="UPDATE CSS SET vlink='$temp_vlink' WHERE Username='$login'";
$rs_vlink=mysql_query($sql_vlink,$dbh);
$sql_h1="UPDATE CSS SET h1='$temp_h1' WHERE Username='$login'";
$rs_h1=mysql_query($sql_h1,$dbh);
$sql_h2="UPDATE CSS SET h2='$temp_h2' WHERE Username='$login'";
$rs_h2=mysql_query($sql_h2,$dbh);



  
#Write to CSS file

$css = "/*Main CSS File for $login*/\n\n";
$css.="body{\n";
$css.="  color: #$temp_text;\n";
$css.="  background-color: #$temp_back;\n";
$css.="}\n";
$css.="a:active{\n";
$css.="  color: #$temp_alink;\n";
$css.="}\n";
$css.="a:link{\n";
$css.="  color: #$temp_link;\n";
$css.="}\n";
$css.="a:visited{\n";
$css.="  color: #$temp_vlink;\n";
$css.="}\n";
$css.="h1{\n";
$css.="  color: #$temp_h1;\n";
$css.="}\n";
$css.="h2{\n";
$css.="  color: #$temp_h2;\n";
$css.="}\n";

$filename='Users/'.$login.'/www.css';
  
if (!$handle = fopen($filename, 'w')) {
     echo "Cannot open file ($filename)";
     exit;
}
if (fwrite($handle, $css) === FALSE) {
   echo "Cannot write to file ($filename)";
   exit;
}
if ($rs_text && $rs_bg && $rs_alink && $rs_link && $rs_vlink && $rs_h1 && $rs_h2)
{
  echo "CSS Custom Theme Updated for $login\n";
  echo "<br/><br/>\n";
  $sql="UPDATE Accounts SET theme='custom' WHERE Username='$login'";
  $rs=mysql_query($sql,$dbh);
  echo "<a href='?id=profile'>Back to $login's profile</a>";
  echo "<meta http-equiv='refresh' content='0;URL=?id=profile'>";
}
else
  echo "<span id='error'>ERROR!</span><br/><br/>An error occured. Please contact your system administrator.";

fclose($handle);

#End Write

mysql_close($dbh);
?>
Return current item: NetLink