<?php
// +----------------------------------------------------------------------+
// | Fantastic File Database |
// +----------------------------------------------------------------------+
// | By Tony Baird |
// | Copyright (c) 2003 Fantastic Scripts |
// | http://fscripts.com |
// +----------------------------------------------------------------------+
// | Fantastic File Database Can be modified freely as long as copyright |
// | is intact and this is left at the top of every source file |
// +----------------------------------------------------------------------+
// | skin.php |
// | Date Started: March 30, 2003 |
// | Last Modified: March 30, 2003 |
// +----------------------------------------------------------------------+
Class Skin {
//*************************************************/
// Just seing what we are doing
//*************************************************/
function Skin() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin;
if ($_REQUEST['action']=="add_skin") {
$this->AddSkinForm();
}elseif (isset($_REQUEST['add_skin'])) {
$this->AddSkin();
}elseif ($_REQUEST['action']=="edit_skin") {
$this->SkinList();
}elseif ($_REQUEST['action']=="delete_skin_confirm") {
$this->ConfirmDeleteSkin();
}elseif ($_REQUEST['action']=="delete_skin") {
$this->DeleteSkin();
}elseif ($_REQUEST['action']=="edit_skin_form") {
$this->EditSkinForm();
}elseif (isset($_REQUEST['edit_skin'])) {
$this->EditSkin();
}
}
//*************************************************/
// Add Skin Form
//*************************************************/
function AddSkinForm() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
$tpl->LoadTemplate("add_skin_form","Admin/templates/$admin_skin/add_skin_form.tpl");
$tpl->ParseTemplate("add_skin_form",$add_skin_form_array,"No");
$tpl->PrintTemplate("add_skin_form");
}
//*************************************************/
// Actually Adds Skin
//*************************************************/
function AddSkin() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
if (empty($_POST['skin_name'])) {
$error .="Missing Skin Name<br>";
}
if (empty($_POST['skin_directory_name'])) {
$error .="Missing Skin Directory Name<br>";
}
if ($error) {
$admin->Error($error);
}
// Copying Default Skin Templates
$this->CopySkin($CONFIG['templates_path']."default/",$CONFIG['templates_path'].$_POST['skin_directory_name']."/");
$ffdb->slash_array($_POST);
$add_skin_array = array(
'skin_name' => $_POST['skin_name'],
'skin_directory'=>$_POST['skin_directory_name'],
);
$mysql->MakeInsertString($add_skin_array);
$mysql->Query("INSERT INTO ffdb_skins ($mysql->insert_fields) VALUES ($mysql->insert_values)");
$admin->Success("Skin Added Successfully");
}
//*************************************************/
// Skin List
//*************************************************/
function SkinList() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$tpl->LoadTemplate("edit_skin_list","Admin/templates/$admin_skin/edit_skin_list.tpl");
$mysql->Query("SELECT * FROM ffdb_skins WHERE skin_name!='default' ORDER BY skin_name");
while ($show_skin=mysql_fetch_array($mysql->result_id)) {
$has_skins=1;
$edit_skin_list_array=Array(
'skin_name'=>$show_skin[skin_name],
'skin_directory'=>$show_skin[skin_directory],
'skin_id'=>$show_skin[skin_id]
);
$tpl->ParseTemplate("edit_skin_list",$edit_skin_list_array,"Yes");
}
if ($has_skins==1) {
$tpl->PrintTemplate("edit_skin_list");
} else {
$admin->Error("There are currently no skins other than the default add a skin than you can edit it");
}
}
//*************************************************/
// Confirm Delete Skin
//*************************************************/
function ConfirmDeleteSkin() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_skins WHERE skin_id=".$_REQUEST['id']."");
$show_skin=mysql_fetch_array($mysql->result_id);
$admin->Confirm("Are you sure you want to delete $show_skin[skin_name]?<br>","admin.php?action=delete_skin&id=$show_skin[skin_id]");
}
//*************************************************/
// Deletes Skin
//*************************************************/
function DeleteSkin() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_skins WHERE skin_id=".$_REQUEST['id']."");
$show_skin=mysql_fetch_array($mysql->result_id);
$this->RemoveDirectory($CONFIG['templates_path'].$show_skin['skin_directory']."/");
$mysql->Query("DELETE FROM ffdb_skins WHERE skin_id=$show_skin[skin_id]");
$admin->Success("Skin deleted successfully");
}
//*************************************************/
// Edit Skin Form
//*************************************************/
function EditSkinForm() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
$tpl->LoadTemplate("edit_skin_form","Admin/templates/$admin_skin/edit_skin_form.tpl");
$mysql->Query("SELECT * FROM ffdb_skins WHERE skin_name!='default' AND skin_id=".$_REQUEST['id']."");
$show_skin=mysql_fetch_array($mysql->result_id);
$edit_skin_form_array=Array(
'skin_name'=>$show_skin[skin_name],
'skin_directory'=>$show_skin[skin_directory],
'skin_id'=>$show_skin[skin_id]
);
$tpl->ParseTemplate("edit_skin_form",$edit_skin_form_array,"No");
$tpl->PrintTemplate("edit_skin_form");
}
//*************************************************/
// Actually Edits Skin
//*************************************************/
function EditSkin() {
global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
$mysql->Query("SELECT * FROM ffdb_skins WHERE skin_id=".$_REQUEST['id']."");
$show_skin=mysql_fetch_array($mysql->result_id);
if ($show_skin[skin_directory] !=$_POST['skin_directory_name']) {
$this->CopySkin($CONFIG['templates_path']."$show_skin[skin_directory]/",$CONFIG['templates_path'].$_POST['skin_directory_name']."/");
$this->RemoveDirectory($CONFIG['templates_path'].$show_skin['skin_directory']."/");
}
$update_skin_array = array(
'skin_name' => $_POST['skin_name'],
'skin_directory'=>$_POST['skin_directory_name'],
);
$mysql->MakeUpdateString($update_skin_array);
$mysql->Query("UPDATE ffdb_skins SET $mysql->update_string WHERE skin_id=".$_REQUEST['id']."");
$admin->Success("Skin updated successfully");
}
function RemoveDirectory ($del_path) {
$this_path = getcwd();
if (is_dir($del_path)) {
chdir($del_path);
$handle=opendir('.');
while (($file = readdir($handle))!==false) {
if (($file != ".") && ($file != "..")) {
if (is_dir($file)) {
$this->RemoveDirectory($file."/");
}
if (is_file($file)) {
chdir($this_path);
unlink($del_path.$file);
chdir($del_path);
}
}
}
closedir($handle);
}
chdir($this_path);
rmdir( ereg_replace("/","\\",$del_path) );
return;
}
//*************************************************/
// Copys Skin Directory
//*************************************************/
function CopySkin($from_path,$to_path) {
mkdir($to_path, 0777);
$this_path = getcwd();
if (is_dir($from_path)) {
chdir($from_path);
$handle=opendir('.');
while (($file = readdir($handle))!==false) {
if ($file != "." && $file != "..") {
if (is_dir($file)) {
rec_copy ($from_path.$file."/", $to_path.$file."/");
chdir($from_path);
}
if (is_file($file)){
copy($from_path.$file, $to_path.$file);
}
}
}
closedir($handle);
chdir("..");
chdir("..");
}
}
}
?>