Location: PHPKode > projects > Changelog > changelog/admin/index.php
<?php
/*
	Changelog
	~~~~~~~~~~
	Author	: Thomas Whitecotton
	Email	: hide@address.com
	Website	: http://www.ciamosbase.com

*/
include("admin_header.php");

function home() {
	
	global $db, $sysConfig, $sysModule, $myts;
	
	OpenTable(); 
	
	echo "
	<h4>"._MT_FILES_N_FOLDERS."</h4>
	<table  width='100%' border='0' cellpadding='0' cellspacing='0'>
		<tr class='bg2' align='center'>
			<td align='center'>
				<table width='100%' border='0' cellpadding='4' cellspacing='1' align='center'>
					<form name='editfolder' action='index.php?op=editfolder' method='post'>
						<tr class='bg3'>
							<td nowrap>
								"._MT_ADD_FILE2DIR."
							</td>
							<td nowrap>
								"._MT_ADD_SUBDIR."
							</td>
							<td nowrap>
								"._MT_FILE_DIR_NAME."
							</td>
							<td nowrap>
								"._MT_EDIT_FILE_DIR."
							</td>
						</tr>
						<tr class='bg3'>
							<td nowrap>
								<a href='index.php?op=add&fid=0&name=Top%20Level%20Directory' title='Add a File'>
										<img src=".SYS_URL._MT_ADD_IMAGE." alt='+' title='Add a File'>
										Add File
								</a>
							</td>
							<td nowrap>
								<a href='index.php?op=addfolder&fid=0&name=Top%20Level%20Directory' title='Add a Directory'>
										<img src=".SYS_URL._MT_ADD_IMAGE." alt='+' title='Add a Directory'>
										Add Directory
								</a>
							</td>
							<td nowrap>
								<img src=".SYS_URL._MT_TOPLEVER_IMAGE." alt='[ ]' title='Top Level Directory'>
								Top Level Directory
							</td>
							<td nowrap>
							</td>
						</tr>";
								$query = $db->query("SELECT fid,name,folder FROM ".$db->prefix("changelog_folders")." ORDER BY name ASC");
								while (list($fid,$name,$folder)=$db->fetch_row($query)) {
									if ($folder == 0) {
										print('
						<tr class="bg3">
							<td class="bg1" nowrap>
										<a href="index.php?op=add&fid='.$fid.'&name='.$name.'" title="Add a File">
										<img src='.SYS_URL._MT_ADD_IMAGE.' alt="+" title="Add a File">
										Add File
										</a>							
							</td>
							<td class="bg1" nowrap>
										<a href="index.php?op=addfolder&fid='.$fid.'&name='.$name.'" title="Add a Folder">
										<img src='.SYS_URL._MT_ADD_IMAGE.' alt="+" title="Add a Folder">
										Add Folder
										</a>
							</td>
							<td class="bg1" nowrap>
										<a href="changelog.php?folderid='.$fid.'" title='.$name.'>
										<img src='.SYS_URL._MT_FOLDER_IMAGE.' alt="[ ]" title='.$name.'> ');
										echo $name.'
										</a>
							</td>
							<td class="bg1" nowrap>
										<img alt="[~]" title="Edit" src="' . SYS_URL .'/modules/contact/images/editicon.gif" onclick=\'location="index.php?op=editfolder&fid='.$fid.'"\'>
										<a href="index.php?op=editfolder&fid='.$fid.'" title="Edit">
											Edit
										</a>
							</td>
						</tr>'; 
									}
								}
								$query = $db->query("SELECT cid,name,folder FROM ".$db->prefix("changelog_files")." ORDER BY name ASC");
								while (list($cid,$name,$folder) = $db->fetch_row($query)) {
									if ($folder == 0) {
							print('
						<tr class="bg3">
							<td class="bg1" nowrap>
							</td>
							<td class="bg1" nowrap>
							</td>
							<td class="bg1" nowrap>
								<img src="' . SYS_URL .'/modules/changelog/images/file.gif" alt="[~]" title='.$name.'> '.$name.'<br>
							</td>
							<td class="bg1" nowrap>
 								<img  alt="[~]" title="Edit" src="' . SYS_URL .'/modules/contact/images/editicon.gif" onclick=\'location="index.php?op=edit&cid='.$cid.'&fid=0"\'>
								<a href="index.php?op=edit&cid='.$cid.'&fid=0" title="Edit">
									Edit
								</a>
							</td>
						</tr>');
								}	}
		echo "		</form>
				</table>
			</td>
		</tr>
	</table>";
	CloseTable();
}

function add() {

	include_once(SYS_ROOT_PATH."/class/sysformloader.php");
    include_once(SYS_ROOT_PATH."/class/syslists.php");

    global $db, $myts, $sys_request, $sysConfig, $sysUser;

	$fid  = $sys_request['fid'];
	$fname = $sys_request['name'];
	
	$name			= new SysFormText("File Name", "name", 50, 100, "Name");
	$changes		= new SysFormTextArea("Changes", "changes", "Changes", 10, 50);
	$folderid		= new SysFormText("<b>ID:</b>", "folder", 10, 10, $fid);
	$folderdetails	= new SysFormLabel("(Use <font color=red>0</font> if its a top level file)");
    $folder         = new SysFormElementTray("Parent Directory <br>(".$fname.")", "<br />");
    $folder->addElement($folderid);
    $folder->addElement($folderdetails);
    $submit_button	= new SysFormButton("", "button", "Add", "submit");
    
	$form = new SysThemeForm(_MT_ADD_FILE, "insert", "index.php?op=insert");
    $form->addElement($name);
	$form->addElement($changes);
	$form->addElement($folder);
	$form->addElement($submit_button);

    OpenTable();
    $form->display();
    CloseTable();
}

function addfolder() {
        
	include_once(SYS_ROOT_PATH."/class/sysformloader.php");
    include_once(SYS_ROOT_PATH."/class/syslists.php");

    global $db, $myts, $sys_request, $sysConfig, $sysUser;

	$fid  = $sys_request['fid'];
	$fname = $sys_request['name'];

	$name			= new SysFormText("Directory Name", "name", 50, 100, "Name");
	$folderid		= new SysFormText("<b>ID:</b>", "folder", 10, 10, $fid);
	$folderdetails	= new SysFormLabel("(Use <font color=red>0</font> if its a top level folder)");
    $folder         = new SysFormElementTray("Parent Directory <br>(".$fname.")", "<br />");
    $folder->addElement($folderid);
    $folder->addElement($folderdetails);
    $submit_button	= new SysFormButton("", "button", "Add", "submit");

	$form = new SysThemeForm(_MT_ADD_FOLDER, "insert", "index.php?op=insertfolder");
    $form->addElement($name);
	$form->addElement($folder);
	$form->addElement($submit_button);

    OpenTable();
    $form->display();
    CloseTable();
}

function edit() {
	
	include_once(SYS_ROOT_PATH."/class/sysformloader.php");
    include_once(SYS_ROOT_PATH."/class/syslists.php");

    global $db, $myts, $sys_request, $sysConfig, $sysUser;

	$cid = $sys_request['cid'];
	$fid = $sys_request['fid'];
	if(!isset($sys_request['fname'])) {
		$fname = "File is currently top level.";
	} else {
		$fname = "
		<a href='changelog.php?folderid=".$fid."'>
			<img src=".SYS_URL._MT_FOLDER_IMAGE." alt='[ ]' title=".$sys_request['fname'].">
			".$sys_request['fname']."
		</a>";
	}

	$sql = "SELECT name,changes,folder FROM ".$db->prefix("changelog_files")." WHERE cid ='" .$cid . "'";
	$result = $db->query($sql);
	list($rname,$changes,$folder) = $db->fetch_row($result);

	$name			= new SysFormText("File Name", "name", 50, 100, $rname);
	$cid			= new SysFormHidden("cid", $cid);
	$changes		= new SysFormTextArea("Changes", "changes", $changes, 10, 50);
	$folderid		= new SysFormText("<b>ID:</b>", "folder", 10, 10, $folder);
	$folderdetails	= new SysFormLabel("(Use <font color=red>0</font> if its a top level file)");
    $folder         = new SysFormElementTray("Parent Directory <br>(".$fname.")", "<br />");
    $folder->addElement($folderid);
    $folder->addElement($folderdetails);
    $submit_button	= new SysFormButton("", "submit", "Update", "submit");

	$form = new SysThemeForm(_MT_EDIT_FILE, "save", "index.php?op=save");
    $form->addElement($name);
	$form->addElement($cid);
	$form->addElement($changes);
	$form->addElement($folder);
	$form->addElement($submit_button);

    OpenTable();
    $form->display();
    CloseTable();
}

function editfolder() {
	
	include_once(SYS_ROOT_PATH."/class/sysformloader.php");
    include_once(SYS_ROOT_PATH."/class/syslists.php");

    global $db, $myts, $sys_request, $sysConfig, $sysUser;

	$rid  = $sys_request['fid'];
	if(!isset($sys_request['fname'])) {
		$fname = "Folder is currently top level.";
	} else {
		$fname = "
		<a href='changelog.php?folderid=".$rid."' title=".$sys_request['fname'].">
			<img src=".SYS_URL._MT_FOLDER_IMAGE." alt='[ ]' title=".$sys_request['fname'].">
			".$sys_request['fname']."
		</a>"; 
	}

	$sql = "SELECT name,folder FROM ".$db->prefix("changelog_folders")." WHERE fid ='" .$rid . "'";
	$result = $db->query($sql);
	list($rname,$folder) = $db->fetch_row($result);

	$name			= new SysFormText("Directory Name", "name", 50, 100, $rname);
	$fid			= new SysFormHidden("fid", $rid);
	$folderid		= new SysFormText("<b>ID:</b>", "folder", 10, 10, $folder);
	$folderdetails	= new SysFormLabel("(Use <font color=red>0</font> if its a top level folder)");
    $folder         = new SysFormElementTray("Parent Directory <br>".$fname, "<br />");
    $folder->addElement($folderid);
    $folder->addElement($folderdetails);
    $submit_button	= new SysFormButton("", "submit", "Update", "submit");

	$form = new SysThemeForm(_MT_EDIT_FOLDER, "insert", "index.php?op=savefolder");
    $form->addElement($name);
	$form->addElement($fid);
	$form->addElement($folder);
	$form->addElement($submit_button);

    OpenTable();
    $form->display();
    CloseTable();
}

function delete() {
        
	global $db, $sys_request, $myts, $sysConfig;

    $cid = $sys_request["cid"];

	$sql = "DELETE FROM ".$db->prefix("changelog_files")." WHERE cid ='" . $cid . "'";
	$result = $db->query($sql);

	redirect_header(SYS_URL . '/modules/changelog/admin/index.php', 3, _MD_DELETED);
	exit(); 
}

function deletefolder() {

    global $db, $sys_request, $myts, $sysConfig;

    $fid = $sys_request["fid"];

	$sql = "DELETE FROM ".$db->prefix("changelog_folders")." WHERE fid ='" . $fid . "'";
	$result = $db->query($sql);

	redirect_header(SYS_URL . '/modules/changelog/admin/index.php', 3, _MD_DELETED);
	exit(); 
}

function insert() {

    global $db, $sys_request, $myts, $sysConfig;

    $changes         = $sys_request["changes"];
    $name            = $sys_request["name"];
	$folder			 = $sys_request["folder"];

    $sql = "INSERT INTO ".$db->prefix("changelog_files")." set name='" . addslashes($name) . "'"
    . ", changes='" . addslashes($changes) . "'"
	. ", folder='" . ($folder) . "'";
    $result = $db->query($sql);

    redirect_header(SYS_URL . '/modules/changelog/admin/changelog.php?folderid='.$folder, 2, _MD_INSERTED);
    exit();
}

function insertfolder() {

    global $db, $sys_request, $myts, $sysConfig;

    $name              = $sys_request["name"];
    $folder            = $sys_request["folder"];

    $sql = "INSERT INTO ".$db->prefix("changelog_folders")." set name='" . addslashes($name) . "'"
	. ", folder='" . ($folder) . "'";
    $result = $db->query($sql);

    redirect_header(SYS_URL . '/modules/changelog/admin/changelog.php?folderid='.$folder, 2, _MD_INSERTED_FOLDER);
    exit();
}

function update() {

    global $db, $sys_request, $myts, $sysConfig;

    $changes         = $sys_request["changes"];
    $name            = $sys_request["name"];
    $cid             = $sys_request["cid"];
	$folder			 = $sys_request["folder"];

    $sql = "UPDATE ".$db->prefix("changelog_files")." set changes='" . $changes . "'"
    . ", name='" . $name . "'"
	. ", folder='" . $folder . "' WHERE cid='" . $cid . "'";
    $result = $db->query($sql);

    redirect_header(SYS_URL . '/modules/changelog/admin/index.php', 3, _MD_UPDATED);
    exit();
}

function updatefolder() {

    global $db, $sys_request, $myts, $sysConfig;

    $fid               = $sys_request["fid"];
    $name              = $sys_request["name"];
    $folder            = $sys_request["folder"];

	if($folder != 0) {
		$query = @$db->query("SELECT folder FROM ".$db->prefix("changelog_folders")." WHERE fid ='".$folder."'");
		while (list($dir)=$db->fetch_row($query)) {
			if ($dir == $fid) {
				redirect_header(SYS_URL . '/modules/changelog/admin/index.php', 4, _MD_NOSELF);
				exit();
			}
		}
		if(!$dir) {
			redirect_header(SYS_URL . '/modules/changelog/admin/index.php', 3, _MD_NOFOLDER);
			exit();
		}
	}
    $sql = "UPDATE ".$db->prefix("changelog_folders")." set name='" . $name . "'"
	. ", folder='" . $folder . "' WHERE fid='" . $fid . "'";
    $result = $db->query($sql);

    redirect_header(SYS_URL . '/modules/changelog/admin/index.php', 3, _MD_UPDATED);
    exit();
}

switch($op) {

	case "add":
		sys_cp_header();
		add();
		sys_cp_footer();
    break;

	case "addfolder":
		sys_cp_header();
		addfolder();
		sys_cp_footer();
    break;

	case "edit":
		sys_cp_header();
        edit();
        sys_cp_footer();
    break;

    case "editfolder":
        sys_cp_header();
        editfolder();
        sys_cp_footer();
    break;

    case "delete":
        delete();
    break;

    case "deletefolder":
        deletefolder();
    break;

    case "insert":
        insert();
    break;

    case "insertfolder":
        insertfolder();
    break;

    case "save":
        update();
    break;

    case "savefolder":
        updatefolder();
    break;

    default:
        sys_cp_header();
        home();
        sys_cp_footer();
    break;
}
?>
Return current item: Changelog