Location: PHPKode > projects > Mummi (Multi-user MOD_MP3 Interface) > mummi.0.6/htroot/folders.php

// 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;

// 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
// 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][" "] = "&nbsp;";

// check to see if a button was clicked
		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");

		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));

		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");

		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");

		case undomv:
			$os->purge_record("$HTTP_POST_VARS[id]", "tmp_movefile");
			header("Location: $GLOBALS[url_path]$PHP_SELF?r_path=$ss_path");

		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");
				$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");
	}//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>
<input type="hidden" name="r_path" value="$ss_path">
<input type="hidden" name="s_path" value="$ss_song">

//	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
// 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>
	<table width="100%" cellpadding="0" cellspacing="1" border="0"><tr bgcolor="$GLOBALS[bg_clr02]">
		<td><input type="checkbox" ONCLICK="check(this.form)">&nbsp;<B>NAME</B></td>
		<td align=right>SIZE</td>
		<td align=right>ID3</td>
		<td align=right>DB</td>


// Setting up the internal array of folders.
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\">&nbsp;<a href=\"$PHP_SELF?r_path=$dir_val\"><img src=\"$GLOBALS[img_path]/folder.gif\" border=\"0\" ALT=\"\">&nbsp;$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\">&nbsp;</font></td>\n";
	$new_contents00 .= "\t<td align=\"right\"><font size=\"1\">&nbsp;</font></td>\n";

	$new_contents00 .= "</tr>";

		$new_array00[$aa] = $new_contents00;

}//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 = "&nbsp;";

	if($id3v2_array = $ap->get_id3v2()) $idv2mtch = "&nbsp;<img src=\"$img_path/v2.gif\" border=\"0\" ALT=\"ID3v2 Detected\">";
	else $idv2mtch = "&nbsp;";

	if($id3v2_array = $ap->get_id3v1()) $idv1mtch = "<img src=\"$img_path/v1.gif\" border=\"0\" ALT=\"ID3v1 Detected\">";
	else $idv1mtch = "&nbsp;";

	$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\">&nbsp;<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\">&nbsp;$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;

}//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";
		for (i = 0; i < field.length; i++){
			field[i].checked = false;
		checkflag = "false";
		return "Check All";
// -->


Return current item: Mummi (Multi-user MOD_MP3 Interface)