<?
// Setting the title of the page
$GLOBALS[page_title] = "Schema Manager";
// Include files
include "common.php";
include "$GLOBALS[lib_path]/filesys.inc";
include "$GLOBALS[lib_path]/design.inc";
// Set the user navbars.
if(!$HTTP_COOKIE_VARS[login_active]) $nav_array = array(main);
elseif($os->num_rows("SELECT user_name FROM users WHERE user_name='$result_array[user_name]' AND user_type='1'")) $nav_array = array(user_main, user_admin);
else $nav_array = array(user_main);
// Checking to see if the DB exists, if so, remove it and recreate | else create it
// start loading and creating the schema files
//$scm = new SCHEMA_DB();
$fp = new FILESYS();
// Check to see which action was passed on which table then redirect when done
if($HTTP_GET_VARS[op]){
switch($HTTP_GET_VARS[op]){
// update button was clicked.. update the database with the new scm files
case update:
// this will cycle through the checked checkboxes
while(list($keyf, $valf)=@each($fold[0])){
$keyf = stripslashes(rawurldecode($keyf));
$valf = stripslashes(rawurldecode($valf));
//$fold_tree = array(0=>array(),1=>array());
//$fold_tree[1][$keyf] = "$GLOBALS[audio_folder]/$GLOBALS[user_name]/$valf";
//$lucifer = $this->walk_tree($fold_tree, mp3_to_sql);
//echo "backup val: $valf<br>";
echo "<b>loading file: $GLOBALS[schema_path]/$valf<br></b>\n";
// Opening the file for use
$scm_file = $fp->open_file("$GLOBALS[schema_path]/$valf");
$contents = $fp->get_file_data($scm_file);
$fp->close_file($scm_file);
// Pushing the contents into the db
echo "<b>Pusing contents........</b>";
echo "$contents<br>";
// Tell is failed or success
//if(!$os->query($contents)) echo "<b>FAILED..........<br><br></b>";
//else echo "<b>SUCCESS.....<br><br></b>";
}
break;
// Restore button was clicked
case restore:
while(list($key,$val) = @each($HTTP_GET_VARS[fold][0])){
//exec("rm -R ".$ap->create_path($p_path, rawurldecode($val)));
}
break;
// Will display selected table
case view:
// This section will display contents on the selected table dependent on the options specified.
$keyf = stripslashes(rawurldecode($keyf));
$valf = stripslashes(rawurldecode($valf));
$scm_file = $fp->open_file("$GLOBALS[schema_path]/$HTTP_GET_VARS[scm_file]");
$contents = $fp->get_scm_data($scm_file);
$fp->close_file($scm_file);
$GLOBALS[contents01] .= "Below is the contents of <b>$HTTP_GET_VARS[scm_file]</b><hr>\n";
$GLOBALS[contents01] .= "<form method=\"get\" action=\"$PHP_SELF\">\n";
$GLOBALS[contents01] .= "<textarea cols=\"70\" rows=\"20\" name=\"scm_edit\" value=\"$scm_contents\">$contents</textarea>\n";
$GLOBALS[contents01] .= "<br><input type=\"submit\" name=\"op\" value=\"save\"></form>\n";
break;
case save;
$keyf = stripslashes(rawurldecode($keyf));
$valf = stripslashes(rawurldecode($valf));
$scm_file = $fp->open_file("$GLOBALS[schema_path]/$HTTP_GET_VARS[scm_file]");
$contents = $fp->set_scm_data($HTTP_GET_VARS[scm_edit]);
$fp->close_file($scm_file);
echo "saved: $contents<br>\n";
break;
}//eo switch
}else{
// This is the first page to be displayed
// Get the files from the schema folder
// allowed file extensions
$ext=array(scm);
// The hidden part of the path
$p_path = "$GLOBALS[schema_path]";
// Combine the hidden path with the relitive path.
$w_path = $fp->create_path($p_path, $rr_path);
// Read this folder, non-recurisvly.
$fc = $fp->rdir($w_path,f,$ext);
// sort the array
//$fc[0] = sorty($fc[0]);
$fc[1] = $fp->sorty($fc[1]);
// Starting page..
$GLOBALS[contents01] = <<<ENDcontents01
Below is a list of database schmea files. You can make edits to those files here and update the database
in no time. Click schema name to edit its contents.<hr>
<table width="100%" border="0" cellpadding="1" cellspacing="1"><tr bgcolor="#aaaaaa">
<td align="left"><b>Schema Name</b></td><td align="middle"><b>Entries</b></td><td align="middle"><b>Size</b></td>
</tr>
<form method="get" action="$PHP_SELF">
ENDcontents01;
// Display schema files
while(list($key_1, $val_l) = each($fc[1])){
//create the multi-colored rows
if(($clr & 1)==1) $bgc = "#cccccc";
elseif(($clr & 1)!=1) $bgc = "#eeeeee";
// Counter for the other arrays that diaply entries, status and such
$counter++;
// Starting the buffer of the table data
$GLOBALS[contents01] .= "<tr bgcolor=\"$bgc\" align=\"left\">\n";
$GLOBALS[contents01] .= "\t<td width=\"100%\"><input type=\"checkbox\" name=\"fold[0][$key_1]\" value=\"$key_1\"><a href=\"$GLOBALS[url_admin_path]/scmman.php?op=view&scm_file=$key_1\"><img src=\"$GLOBALS[img_path]/cyl.gif\" border=\"0\"> $key_1</td><td align=\"middle\">$array_data[Rows]</td><td align=\"right\">$array_data[Data_length]</td>";
$GLOBALS[contents01] .= "</tr>";
// add to the coloring
$clr++;
}
// Finishing the rest of the page buffer
$GLOBALS[contents01] .= <<<ENDcontents01
</table>
<hr>
<input type="hidden" name="op" value="update">
<input type="hidden" name="table" value="$val_1">
<input type="submit" value="Update">
</form>
ENDcontents01;
}//eo else no op
// an array for the draw_page function.
$contents = array("$GLOBALS[page_title]"=>"$GLOBALS[contents01]");
draw_header("$GLOBALS[page_title]");
draw_nav($nav_array);
draw_sect($contents);
draw_footer();
?>