<?
// Setting the title
$GLOBALS[page_title] = "Folder Viewer";
// Include files
include "common.php";
include "$GLOBALS[lib_path]/filesys.inc";
include "$GLOBALS[lib_path]/audio.inc";
include "$GLOBALS[lib_path]/audio-db.inc";
include "$GLOBALS[lib_path]/design.inc";
$adb = new AUDIO_DB;
$adb->connect("$GLOBALS[dbhost]","$GLOBALS[dbusername]","$GLOBALS[dbuserpassword]","$GLOBALS[dbname]");
// 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='$session_array[user_name]' AND user_type='1'")) $nav_array = array_merge($GLOBALS[admin_navbox_array], $os->get_navbox_array($session_array[user_name]));
else $nav_array = array_merge($GLOBALS[basic_navbox_array], $os->get_navbox_array($session_array[user_name]));
// ============================================================================
// use the class
$ap = new AUDIO_PARSER();
// url decoded string for path
$rr_path = stripslashes(rawurldecode($r_path));
// url encoded string for path
$ss_path = rawurlencode($rr_path);
// allowed file extensions
$ext=array(mp3,mp2,mp1,ogg);
// The hidden part of the path
$p_path = "$GLOBALS[audio_folder]/$session_array[user_name]";
// Combine the hidden path with the relitive path.
$w_path = $ap->create_path($p_path, $rr_path);
// the parent folder.
$back_path = rawurlencode($ap->up_dir($rr_path));
// An array that binds the ISO-8859-1 funky chars to their associated HTML tags.
$GLOBALS[char_tbl] = get_html_translation_table(HTML_ENTITIES);
// A fix for white-spaces.
$GLOBALS[char_tbl][" "] = " ";
// check to see if a button was clicked
if($HTTP_POST_VARS[op]){
switch($HTTP_POST_VARS[op]){
case sync:
$adb->insert_tmp_syncfile($session_array[user_name], $HTTP_POST_VARS[fold]);
$t_var = md5($GLOBALS[current_utime]);
header("Location: $GLOBALS[url_path]/filesync.php?id=$t_var&r_path=$ss_path");
break;
case delete:
while(list($key,$val) = @each($HTTP_POST_VARS[fold][0])){
exec("rm -R ".$ap->create_path($p_path, rawurldecode($val)));
}
while(list($key,$val) = @each($HTTP_POST_VARS[fold][1])){
unlink($p_path . rawurldecode($val));
}
break;
case rename:
$adb->insert_tmp_movefile($session_array[user_name], $HTTP_POST_VARS[fold]);
$t_var = md5($GLOBALS[current_utime]);
header("Location: $GLOBALS[url_path]/rename.php?id=$t_var&r_path=$ss_path");
break;
case move:
$adb->insert_tmp_movefile($session_array[user_name], $HTTP_POST_VARS[fold]);
$t_var = md5($GLOBALS[current_utime]);
header("Location: $GLOBALS[url_path]/move.php?id=$t_var&r_path=$ss_path");
break;
case undomv:
$os->purge_record("$HTTP_POST_VARS[id]", "tmp_movefile");
header("Location: $GLOBALS[url_path]$PHP_SELF?r_path=$ss_path");
break;
case dest:
$query = "SELECT move_array FROM tmp_movefile WHERE id='$HTTP_POST_VARS[id]'";
if(!$result_array = $adb->fetch_numeric($query)) header("Location: $GLOBALS[url_path]/$PHP_SELF?error=no_src_items_to_move");
else{
$real_array = OVERSEER::decipher($result_array[0][0],$GLOBALS[secret_key]);
// move the folders
while(list($key,$val) = @each($real_array[0])){
$val = $p_path.rawurldecode($val);
$des = $p_path.rawurldecode($dest)."/".end(explode("/",$val));
$exec_string = "mv -f \"$val\" \"$des\"";
if($des == $val) continue;
else exec("$exec_string");
// $post_query = "SELECT * FROM audio_files WHERE file_path LIKE '$val%'";
// $post_result = $adb->fetch_numeric($post_query);
// while(list($key2, $val2) = each($post_result)){
// $post2_query = "UPDATE audio_files SET file_path='$val2' WHERE file_owner='$session_array[user_name]' AND file_path='$val'";
// $adb->num_rows($post2_query)
// }//eo while
}//eo while
// copy the files over
while(list($key,$val) = @each($real_array[1])){
$src = $p_path.rawurldecode($val);
$des = $p_path.rawurldecode($dest);
$exec_string = "mv -f \"$src\" \"$des\"";
if($des == $src) continue;
else exec("$exec_string");
}//eo while
// finish up by purging the tmp records, and redirect the user.
$os->purge_record("$HTTP_POST_VARS[id]", "tmp_movefile");
header("Location: $GLOBALS[url_path]$PHP_SELF?r_path=$ss_path");
}
break;
}//eo switch
}
// Read this folder, non-recurisvly.
$fc = $ap->rdir($w_path,f,$ext);
// sort the array
$fc[0] = FILESYS::sorty($fc[0]);
$fc[1] = FILESYS::sorty($fc[1]);
// Starting the build of the page contents.
// all the action buttons
$contents .= <<<ENDcontents
<font size="$GLOBALS[body_font_size]">
<table cellpadding="1" cellspacing="1" border="0"><tr>
<td><form method="get" action="$GLOBALS[url_path]$PHP_SELF">
<input type="hidden" name="r_path" value="$back_path">
<input type="submit" value="up"></form></td>
<td><form method="post" action="$GLOBALS[url_path]/mkdir.php">
<input type="hidden" name="op" value="mkdir">
<input type="hidden" name="r_path" value="$ss_path">
<input type="hidden" name="redirect" value="$PHP_SELF">
<input type="submit" value="mkdir"></form></td>
<form method="post" action="$GLOBALS[url_path]$PHP_SELF"><td>
<input type="submit" name="op" value="sync"><br><br></td>
<td><input type="submit" name="op" value="delete"><br><br></td>
<td><input type="submit" name="op" value="rename"><br><br></td>
<td><input type="submit" name="op" value="move"><br><br></td>
</tr></table>
<input type="hidden" name="r_path" value="$ss_path">
<input type="hidden" name="s_path" value="$ss_song">
</font>
ENDcontents;
// NOTE TO SELF:
// 1.> Ability to turn off page numbering on any page with the prefrence remembered
// 2.> A checkbox that is able to say "check all entries, not just the ones displayed"
// This is good for when you want to sync all the files but don't want to remember
// which page you were on the last time you synced your files.
// Doing a check on the current folder. If empty then your at the root of your
// user folder else your in an other folder.
$cur_path = $rr_path;
if(empty($cur_path)) $cur_path = "/ (root folder)";
//-- Page Number System code --//
// Setting up the current page number
if(empty($HTTP_GET_VARS[cur_page])) $cur_page = 1;
else $cur_page = $HTTP_GET_VARS[cur_page];
// need to get the total number of entries the folders array has.. for pagenumbering
$jj=0;
// Creating and using tmp arrays to do out counting.. if we use the real arrays
// then they get corrupted and not able to read later on in the page
$tmp_fc0 = $fc[0];
$tmp_fc1 = $fc[1];
while(list($key, $val) = @each($tmp_fc0)) $jj++;
while(list($key, $val) = @each($tmp_fc1)) $jj++;
$GLOBALS[real_return_array_count] = $jj;
// display the page number table here
$contents00 = draw_pagenumbers($cur_page, $GLOBALS[rpp]);
// Top title for the displaying of the folders and files
$contents .= <<<ENDcontents
<font size="$GLOBALS[body_font_size]">
<b>Current Folder:</b> $cur_path<br>
$contents00
<table width="100%" cellpadding="0" cellspacing="1" border="0"><tr bgcolor="$GLOBALS[bg_clr02]">
<td><input type="checkbox" ONCLICK="check(this.form)"> <B>NAME</B></td>
<td align=right>SIZE</td>
<td align=right>ID3</td>
<td align=right>DB</td>
</tr>
ENDcontents;
// Setting up the internal array of folders.
$aa=0;
while(list($key, $val) = each($fc[0])){
//create the multi-colored rows
if(($clr & 1)==1) $bgc = "#cccccc";
elseif(($clr & 1)!=1) $bgc = "#eeeeee";
// url clean path for the folder
$dir_val = rawurlencode("$rr_path" . "/$key");
// convert funky chars into html tags.
$key = strtr($key, $GLOBALS[char_tbl]);
$folder_size = round(exec("du -b -s \"$val\" | awk '{ print $1 }'") / 1000000, 2);
$new_contents00 = "";
$new_contents00 .= "<tr bgcolor=\"$bgc\">\n";
$new_contents00 .= "\t<td><input type=\"checkbox\" name=\"fold[0][$key]\" value=\"$dir_val\"><font size=\"1\"> <a href=\"$PHP_SELF?r_path=$dir_val\"><img src=\"$GLOBALS[img_path]/folder.gif\" border=\"0\" ALT=\"\"> $key</a></font></td>\n";
$new_contents00 .= "\t<td align=\"right\"><font size=\"1\">$folder_size MB</font></td>\n";
$new_contents00 .= "\t<td align=\"right\"><font size=\"1\"> </font></td>\n";
$new_contents00 .= "\t<td align=\"right\"><font size=\"1\"> </font></td>\n";
$new_contents00 .= "</tr>";
$new_array00[$aa] = $new_contents00;
$clr++;
$aa++;
}//eo while
// Setting up internal array for the files
while(list($key, $val) = each($fc[1])){
//create the multi-colored rows
if(($clr & 1)==1) $bgc = "#cccccc";
elseif(($clr & 1)!=1) $bgc = "#eeeeee";
// url clean path for the fielname.
$ss_song = rawurlencode($key);
// convert funky chars into html tags.
$key = strtr($key, $GLOBALS[char_tbl]);
// md5 for the stream app.
$md5song = md5("$val");
if($adb->chk_path_md5($md5song)) $mtch = "<img src=\"$img_path/cyl.gif\" border=\"0\" ALT=\"DB match found\">";
else $mtch = " ";
$ap->open_file("$val");
if($id3v2_array = $ap->get_id3v2()) $idv2mtch = " <img src=\"$img_path/v2.gif\" border=\"0\" ALT=\"ID3v2 Detected\">";
else $idv2mtch = " ";
if($id3v2_array = $ap->get_id3v1()) $idv1mtch = "<img src=\"$img_path/v1.gif\" border=\"0\" ALT=\"ID3v1 Detected\">";
else $idv1mtch = " ";
$Mb_a = round($ap->fs_filesize / 1000000, 2);
//echo "key = $key<br>\n";
//echo "val = $val<br>\n";
//echo "md5 = $md5song<br>\n";
$new_contents01 = "";
$new_contents01 .= "<tr bgcolor=\"$bgc\">\n";
$new_contents01 .= "\t<td><input type=\"checkbox\" name=\"fold[1][$ss_song]\" value=\"$ss_path/$ss_song\"><font size=\"1\"> <A HREF=\"$GLOBALS[url_path]/file.php?r_path=$ss_path&song=$ss_song\"><img src=\"$img_path/mp32.gif\" border=\"0\" ALT=\"Audio File\"> $key</a></font></td>\n";
$new_contents01 .= "\t<td align=\"right\"><font size=\"1\">$Mb_a MB</font></td>\n";
$new_contents01 .= "\t<td align=\"right\"><font size=\"1\">$idv1mtch$idv2mtch</font></td>\n";
$new_contents01 .= "\t<td align=\"right\"><font size=\"1\">$mtch</font></td>\n";
$new_contents01 .= "</tr>";
$new_array00[$aa] = $new_contents01;
$clr++;
$aa++;
}//eo while
// Split the array into chunks..
$final_array = $adb->array_chunk($new_array00, $GLOBALS[rpp], TRUE);
while(list($key, $val) = @each($final_array[$cur_page-1])){
$contents .= $val;
}
// display the page number table here
$contents00 = draw_pagenumbers($cur_page, $GLOBALS[rpp]);
// Cleaning up the end of the page
$contents .= "</table>$contents00</font>\n";
// an array for the draw_page function.
$page_table = array("$GLOBALS[page_title]"=>"$contents");
$js_script = <<<ENDjs_script
<SCRIPT TYPE="text/javascript">
<!--
var checkflag = "false";
function check(field) {
if(checkflag == "false"){
for (i = 0; i < field.length; i++){
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
}else{
for (i = 0; i < field.length; i++){
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}
// -->
</script>
ENDjs_script;
draw_header("$GLOBALS[page_title]","","$js_script");
draw_nav($nav_array);
draw_sect($page_table);
draw_footer();
ob_end_flush();
?>