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

// Setting the title
$GLOBALS[page_title] = "Rename Folders/Files";

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




// all the action buttons
$contents .= <<<ENDcontents

	<table cellpadding="1" cellspacing="1" border="0"><tr>
		<td><form method="post" action="$GLOBALS[url_path]$PHP_SELF">
		<input type="hidden" name="op" value="undorn">
		<input type="hidden" name="id" value="$id">
		<input type="hidden" name="r_path" value="$ss_path">
		<input type="submit" value="cancel"></form></td>

		<td><form method="post" action="$GLOBALS[url_path]$PHP_SELF">
		<input type="hidden" name="op" value="ren_dest">
		<input type="hidden" name="id" value="$id">
		<input type="hidden" name="r_path" value="$ss_path">
		<input type="submit" value="change"><br><br></td>

	</tr></table>
	<input type="hidden" name="r_path" value="$ss_path">
	<input type="hidden" name="s_path" value="$ss_song">


ENDcontents;

// Top title for the displaying of the folders and files
$contents .= <<<ENDcontents

	<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>
		<td><B>NAME</B></td>
		<td align=right>&nbsp;</td>
		<td align=right>&nbsp;</td>
		<td align=right>&nbsp;</td>
		<td align=right>&nbsp;</td>
	</tr>

ENDcontents;


if($HTTP_POST_VARS[op]){
	switch($HTTP_POST_VARS[op]){
		case undorn:
			$os->purge_record("$HTTP_POST_VARS[id]", "tmp_movefile");
			header("Location: $GLOBALS[url_path]/folders.php?r_path=$ss_path");
		break;

		case ren_dest:
			$query = "SELECT move_array FROM tmp_movefile WHERE id='$HTTP_POST_VARS[id]'";
			if(!$result_arr = $adb->fetch_numeric($query)) header("Location: $GLOBALS[url_path]/$PHP_SELF?error=no_src_items_to_rename");
			else{
				$real_array = OVERSEER::decipher($result_arr[0][0],$GLOBALS[secret_key]);

				// rename the folders
				while(list($key,$val) = @each($real_array[0])){
					$val = $p_path.rawurldecode($val);
					list(, $vall) = each($dest[0]);
					$des = $p_path."/".end(explode("/",$vall));
					array_shift($dest[0]);
					$exec_string = "mv -f \"$val\" \"$des\"";
					if($des == $val) continue;
					else exec("$exec_string");
				}//eo while

				// rename the files over
				while(list($key,$val) = @each($real_array[1])){
					$src = $p_path.rawurldecode($val);
					list(, $vall) = each($dest[1]);
					$des = $w_path."/".rawurldecode($vall);
					$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]/folders.php?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]);

if($HTTP_GET_VARS[id] xor $HTTP_POST_VARS[id]){
	if($HTTP_GET_VARS[id]) $ss_id = $HTTP_GET_VARS[id];
	else $ss_id = $HTTP_POST_VARS[id];

	$query = "SELECT id FROM tmp_movefile where user_name='$session_array[user_name]'";
	if($os->num_rows($query)){

		$query = "SELECT move_array FROM tmp_movefile WHERE id='$ss_id'";
		$result_array = $os->fetch_numeric($query);
		$real_array = OVERSEER::decipher($result_array[0][0],$GLOBALS[secret_key]);

		// a cheap simple func to compare values.
		function chk_ren($a, $b){
			while(list(, $valr) = @each($b)){
				$c = $GLOBALS[p_path].rawurldecode($valr);
				if($a == $c) return true;
			}
			return false;
		}

		// Create varible for the directories.
		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");

			if(is_array($real_array[0])){
				reset($real_array[0]);
				if(!chk_ren($val, $real_array[0])){
					$contents .= "<tr bgcolor=\"$bgc\">\n";
					$contents .= "\t<td colspan=\"100%\">&nbsp;<img src=\"$GLOBALS[img_path]/folder.gif\" border=\"0\">&nbsp;$key</td>\n";
					$contents .= "</tr>";
				}else{
					$GLOBALS[contents] .= "<tr bgcolor=\"$bgc\">\n";
					$GLOBALS[contents] .= "\t<td colspan=\"100%\">&nbsp;<img src=\"$GLOBALS[img_path]/folder.gif\" border=\"0\">&nbsp;<input type=\"text\" name=\"dest[0][$key]\" value=\"$key\" size=\"50\"></td>\n";
					$GLOBALS[contents] .= "</tr>";
				}
			}
			$clr++;
		}//eo directories varible

		// Create varible 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);

			// md5 for the stream app.
			//$md5song = md5($val);

			if(!chk_ren($val, $real_array[1])){
				$contents .= "<tr bgcolor=\"$bgc\">\n";
				$contents .= "\t<td colspan=\"100%\">&nbsp;<img src=\"$GLOBALS[img_path]/mp32.gif\" border=\"0\">&nbsp;$key</td>\n";
				$contents .= "</tr>";
			}else{
				$GLOBALS[contents] .= "<tr bgcolor=\"$bgc\">\n";
				$GLOBALS[contents] .= "\t<td colspan=\"100%\">&nbsp;<img src=\"$GLOBALS[img_path]/mp32.gif\" border=\"0\">&nbsp;<input type=\"text\" name=\"dest[1][$key]\" value=\"$key\"></td>\n";
				$GLOBALS[contents] .= "</tr>";
			}
			$clr++;
		}

		// Cleaning up the end of the page
		$contents .= "</table>\n";

	}else $GLOBALS[contents] = "error: nothing to move.<br>\n";
}




// an array for the draw_page function.
$page_table = array("$GLOBALS[page_title]"=>"$contents");


draw_header("$GLOBALS[page_title]");
draw_nav($nav_array);
draw_sect($page_table);
draw_footer();
ob_end_flush();
?>
Return current item: Mummi (Multi-user MOD_MP3 Interface)