Location: PHPKode > projects > W00t Gallery > wG3b3/a_css.php
<?php /*

w00t Gallery - PHP Community Image Gallery
Copyright (C) 2007 Stuart Rankin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

hide@address.com

----------------------------------------------------------------------------------------------------------

*/

if($call_confirm == "a_css"){


// FUNCTION - List Styles

function list_styles(){

$sql = "SELECT css_id FROM ".$GLOBALS['db_pref']."css";

$num_styles = mysql_num_rows(mysql_query($sql));

if($num_styles > 0){

?>

<select name="css">

<?php

$sql = "SELECT * FROM ".$GLOBALS['db_pref']."css ORDER BY css_id ASC";

$query = mysql_query($sql);

while($result = mysql_fetch_assoc($query)){

$selected = "";

$css_ids = stripslashes($result['css_id']);

if($css_ids == $GLOBALS['css_id']){

$selected = " selected=\"selected\"";

}

echo "<option".$selected." value=\"".$css_ids."\">".$css_ids."</option>";

}

?>

</select>

<?php

}

}

// END FUNCTION


if($_POST['create']){

// ADD NEW

$new_css = mysql_real_escape_string($_POST['css']);

if($new_css <> ""){

$sql = "SELECT * FROM ".$GLOBALS['db_pref']."css WHERE css_id = '".$new_css."'";

$result = mysql_fetch_assoc(mysql_query($sql));

if(!$result){

$handle = @fopen("css/".$new_css.".css", "w+");

if($handle){

$sql = "INSERT INTO ".$GLOBALS['db_pref']."css (css_id) VALUES ('".$new_css."')";

mysql_query($sql);

if(mysql_error()){

$err = "<p class=\"bad\">A database error occured: ".mysql_error()."</p>";

}else{

$def_css = file_get_contents("css/".$GLOBALS['css_id'].".css");

fwrite($handle, $def_css);

$css = $new_css;

$err = "<p class=\"good\">New style created successfully</p>";

}

}else{

$err = "<p class=\"bad\">An error occured while creating the file</p>";

}

}else{

$err = "<p class=\"bad\">The specified style already exists</p>";

}

}else{

$err = "<p class=\"bad\">You must specify a name for the new style</p>";

}

}elseif($_POST['del']){

// DELETE

$del_css = mysql_real_escape_string($_POST['css']);

$sql = "DELETE FROM ".$GLOBALS['db_pref']."css WHERE css_id = '".$del_css."'";

mysql_query($sql);

if(mysql_error()){

$err = "<p class=\"bad\">A database error occured: ".mysql_error()."</p>";

}else{

$worx = @unlink("css/".$del_css.".css");

if($worx){

$err = "<p class=\"good\">Style deleted successfully</p>";

}else{

$err = "<p class=\"bad\">An error occured while deleting the file</p>";

}

}

// SAVE EDIT

}elseif($_POST['edit'] && $_POST['css'] <> ""){

$handle = @fopen("css/".$_POST['css'].".css", "w+");

if($handle){

$content = stripslashes($_POST['css_text']);

fwrite($handle, $content);

$err = "<p class=\"good\">Style updated successfully</p>";

}else{

$err = "<p class=\"bad\">An error occured while creating the file</p>";

}

}

html_head("Edit Styles");

if($css == ""){

$css = $GLOBALS['css_id'];

if($_GET['css'] <> ""){

if(file_exists("css/".$_GET['css'].".css")){

$css = $_GET['css'];

}

}

}

if($err <> ""){

echo $err;

}

?>

<table cellspacing="0" cellpadding="15">

<tr align="center">

<td width="50%">

<fieldset><legend>Create</legend>

<form style="margin: 0" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?a=css">

<input type="hidden" name="create" value="1" />

<input type="text" maxlength="64" name="css" /> <input type="submit" value="Create" />

</form>

</td>

<td width="50%">

<fieldset><legend class="bad">Delete</legend>

<form style="margin: 0" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?a=css">

<input type="hidden" name="del" value="1" />

<?php

list_styles();

?> <input type="submit" value="Delete" />

</form>

</td>

</tr>

<tr align="center">

<td colspan="2">

<fieldset><legend>Edit</legend>

<table cellpadding="5">

<tr align="center">

<td width="50%"><font class="field">Currently Editing:</font> <font class="bold"><?php echo $css; ?></font></td>

<td width="50%">

<form style="margin: 0" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<input type="hidden" name="a" value="css" />

<?php

list_styles();

?> <input type="submit" value="Edit" />

</form>

</td>

</tr>

<tr>

<td align="center" colspan="2">

<form style="margin: 0" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?a=css">

<input type="hidden" name="edit" value="1" />
<input type="hidden" name="css" value="<?php echo $css; ?>" />

<textarea name="css_text" cols="95" rows="20"><?php

echo stripslashes(@file_get_contents("css/".$css.".css"));

?></textarea>

<br />

<input type="submit" value="Save" />

</form>

</td>

</tr>

</table>

</td>

</tr>

</table>

<?php

html_end();


$call_confirm = "";

}else{

header("Location: index.php");

die("<meta http-equiv=\"refresh\" content=\"0;url=index.php\" />Access Denied");

}

?>
Return current item: W00t Gallery