Location: PHPKode > projects > Mummi (Multi-user MOD_MP3 Interface) > mummi.0.6/htroot/filesync.php
<?
set_time_limit(0);
// Setting the title
$GLOBALS[page_title] = "DB sync file";

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

$GLOBALS[ap] = new AUDIO_PARSER();


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


// url decoded string for path
$rr_path = stripslashes(rawurldecode($r_path));
$rr_song = stripslashes(rawurldecode($song));


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




// The function that inserts data to the database.
function mp3_to_sql($filepath){

	ignore_user_abort(true);


	//echo "starting mp3_to_sql: $filepath<br>\n";


	// is this a file?
	if(!is_file($filepath)){
		clearstatcache();
		//echo "is not a file: $filepath<br>\n";
		return false;
	}else clearstatcache();
	$path_md5 = md5("$filepath");
	if($GLOBALS[adb]->chk_path_md5($path_md5)) return false;






	// Start the work.
	$GLOBALS[ap]->open_file("$filepath");

	$file_path = $GLOBALS[ap]->up_dir($filepath);
	$file_name = $GLOBALS[ap]->node_name($filepath);
	$file_size = $GLOBALS[ap]->fs_filesize;
	$data_md5 = $GLOBALS[ap]->file_data_md5($filepath);
	$file_owner = $GLOBALS[session_array][user_name];
	$file_type = "mp3";
	$created = $GLOBALS[current_utime];
	$modified = $GLOBALS[current_utime];


	$id3v2_array = $GLOBALS[ap]->get_id3v2();
	$mp3_array = $GLOBALS[ap]->sync_mp3($id3v2_array[size]);
	$id3v1_array = $GLOBALS[ap]->get_id3v1();



	//echo "filepath = $filepath<br>\n";
	//echo "file_path = $file_path<br>\n";
	//echo "file_name = $file_name<br>\n";
	//echo "id3v2 size = $id3v2_array[size]<br>\n";
	//echo "file_size = $file_size<br>\n";
	//echo "owner = $file_owner<br>\n";
	//echo "path_md5 = $path_md5<br>\n";
	//echo "data_md5 = $data_md5<br><br>\n";




	switch($id3v2_array[major]){
		case 2:
			$id3_v22 = 1;

			// fix this so the genre, and other info passes to the DB

			//$GLOBALS[adb]->insert_id3v22($path_md5, $id3v2_array[major], $id3v2_array[minor], $id3v2_array[size], $id3v2_array[tags][COMM], $id3v2_array[tags][IPLS], $id3v2_array[tags][LINK], $id3v2_array[tags][MCDI], $id3v2_array[tags][PCNT], $id3v2_array[tags][POPM], $id3v2_array[tags][TALB], $id3v2_array[tags][TCOM], $id3v2_array[tags][TCON], $id3v2_array[tags][TCOP], $id3v2_array[tags][TENC], $id3v2_array[tags][TIT1], $id3v2_array[tags][TIT2], $id3v2_array[tags][TIT3], $id3v2_array[tags][TLEN], $id3v2_array[tags][TMED], $id3v2_array[tags][TOPE], $id3v2_array[tags][TPE1], $id3v2_array[tags][TPE2], $id3v2_array[tags][TPE3], $id3v2_array[tags][TRCK], $id3v2_array[tags][TYER], $id3v2_array[tags][USLT], $id3v2_array[tags][WOAR], $id3v2_array[tags][WXXX]);
		break;
		case 3:
			$id3_v23 = 1;
			$GLOBALS[adb]->insert_id3v23($path_md5, $id3v2_array[major], $id3v2_array[minor], $id3v2_array[size], $id3v2_array[tags][COMM], $id3v2_array[tags][IPLS], $id3v2_array[tags][LINK], $id3v2_array[tags][MCDI], $id3v2_array[tags][PCNT], $id3v2_array[tags][POPM], $id3v2_array[tags][TALB], $id3v2_array[tags][TCOM], $id3v2_array[tags][TCON], $id3v2_array[tags][TCOP], $id3v2_array[tags][TENC], $id3v2_array[tags][TIT1], $id3v2_array[tags][TIT2], $id3v2_array[tags][TIT3], $id3v2_array[tags][TLEN], $id3v2_array[tags][TMED], $id3v2_array[tags][TOPE], $id3v2_array[tags][TPE1], $id3v2_array[tags][TPE2], $id3v2_array[tags][TPE3], $id3v2_array[tags][TRCK], $id3v2_array[tags][TYER], $id3v2_array[tags][USLT], $id3v2_array[tags][WOAR], $id3v2_array[tags][WXXX]);
		break;
		case 4:
			$id3_v24 = 1;
			//$GLOBALS[adb]->insert_id3v24($path_md5, $id3v2_array[major], $id3v2_array[minor], $id3v2_array[size], $id3v2_array[tags][COMM], $id3v2_array[tags][IPLS], $id3v2_array[tags][LINK], $id3v2_array[tags][MCDI], $id3v2_array[tags][PCNT], $id3v2_array[tags][POPM], $id3v2_array[tags][TALB], $id3v2_array[tags][TCOM], $id3v2_array[tags][TCON], $id3v2_array[tags][TCOP], $id3v2_array[tags][TENC], $id3v2_array[tags][TIT1], $id3v2_array[tags][TIT2], $id3v2_array[tags][TIT3], $id3v2_array[tags][TLEN], $id3v2_array[tags][TMED], $id3v2_array[tags][TOPE], $id3v2_array[tags][TPE1], $id3v2_array[tags][TPE2], $id3v2_array[tags][TPE3], $id3v2_array[tags][TRCK], $id3v2_array[tags][TYER], $id3v2_array[tags][USLT], $id3v2_array[tags][WOAR], $id3v2_array[tags][WXXX]);
		break;
	}
	if(is_array($id3v1_array)){
		$id3_v11 = 1;

		//fix?
		$title = addslashes("$title");
		$artist = addslashes("$artist");
		$album = addslashes("$album");
		$comment = addslashes("$comment");

		$GLOBALS[adb]->insert_id3v11($path_md5,$id3v1_array[title],$id3v1_array[artist],$id3v1_array[album],$id3v1_array[comment],$id3v1_array[year],$id3v1_array[track],$id3v1_array[genre_id]);
	}
	$GLOBALS[adb]->insert_audio_files($file_path, $file_name, $file_size, $path_md5, $data_md5, $GLOBALS[session_array][user_name], $file_type, $id3_v11, $id3_v22, $id3_v23, $id3_v24, $created, $modified);

	$GLOBALS[adb]->insert_mod_mp3_main($id3v1_array[title], "$file_path/$file_name", $path_md5, $id3v1_array[artist], $id3v1_array[album], $id3v1_array[comment], $id3v1_array[track], $id3v1_array[year], $id3v1_array[genre_id]);

	$GLOBALS[adb]->insert_mp3_files($path_md5,$mp3_array[version],$mp3_array[layer],$mp3_array[crc],$mp3_array[bitrate],$mp3_array[freq],$mp3_array[pad],$mp3_array[private],$mp3_array[channel_mode],$mp3_array[copyright],$mp3_array[original],$mp3_array[emphasis],$mp3_array[framesize],$mp3_array[frames],$mp3_array[seconds],$mp3_array[header],$mp3_array[fps]);

	if(!empty($id3v1_array[genre])) $GLOBALS[adb]->insert_mod_mp3_tokens($path_md5, $id3v1_array[genre]);



	ignore_user_abort(false);
	return true;
}//eo mp3_to_sql function


















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


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

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

					// sync the folders
					while(list(,$val) = @each($real_array[0])){
						$val = $p_path.rawurldecode($val);
						$fold_tree = $ap->rdir($val,r,$ext);
						$return_array[0] = $ap->walk_rdir_array($fold_tree, mp3_to_sql);

					}//eo while

					// sync the files
					while(list($key,$val) = @each($real_array[1])){

						$val = $p_path.rawurldecode($val);
						$fold_tree[1][$key] = "$val";
						$return_array[1] = $ap->walk_rdir_array($fold_tree, mp3_to_sql);



					}//eo while

					// finish up by purging the tmp records, and redirect the user.
					$os->purge_record("$HTTP_POST_VARS[id]", "tmp_syncfile");
					$query ="SELECT file_name,id3_v11,id3_v22,id3_v23,id3_v24 ".
							"FROM audio_files ".
							"WHERE created ='$GLOBALS[current_utime]' ".
							"AND file_owner='$session_array[user_name]'";
					//echo "$query<br>\n";
					$syn_set = $adb->fetch_assoc($query);

					//create the multi-colored rows
					if(($clr & 1)==1) $bgc = "#cccccc";
					elseif(($clr & 1)!=1) $bgc = "#eeeeee";

					$contents .="<table width=\"100%\" cellpadding=\"0\" cellspacing=\"1\" border=\"1\">".
								"<tr bgcolor=\"$bgc\">\n".
								"\t<td align=\"left\">NAME</td>\n".
								"\t<td align=\"left\">id3_v11</td>\n".
								"\t<td align=\"left\">id3_v22</td>\n".
								"\t<td align=\"left\">id3_v23</td>\n".
								"\t<td align=\"left\">id3_v24</td>\n".
								"</tr>";
					while(list($g,$h) = @each($syn_set)){
						$contents .= "<tr bgcolor=\"$bgc\">\n";
						$contents .= "\t<td align=\"left\">$h[file_name]</td>\n";
						$contents .= "\t<td align=\"left\">$h[id3_v11]</td>\n";
						$contents .= "\t<td align=\"left\">$h[id3_v22]</td>\n";
						$contents .= "\t<td align=\"left\">$h[id3_v23]</td>\n";
						$contents .= "\t<td align=\"left\">$h[id3_v24]</td>\n";
						$contents .= "</tr>";
					}//eo while
					$contents .= "</table>";
				}
			break;
		}//eo switch






	}else{













// 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="undosync">
		<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="sync_dest">
		<input type="hidden" name="id" value="$id">
		<input type="hidden" name="r_path" value="$ss_path">
		<input type="submit" value="continue"><br><br></td>

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


ENDcontents;








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

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


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

	<br>Please make sure these are the items you want to add in the database.<br>

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



			while(list($key,$val) = @each($real_array[0])){
				//create the multi-colored rows
				if(($clr & 1)==1) $bgc = "#cccccc";
				elseif(($clr & 1)!=1) $bgc = "#eeeeee";
				$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>";
				$clr++;
			}

			while(list($key,$val) = @each($real_array[1])){

				//create the multi-colored rows
				if(($clr & 1)==1) $bgc = "#cccccc";
				elseif(($clr & 1)!=1) $bgc = "#eeeeee";

				// url decoded string for path
				$key = stripslashes(rawurldecode($key));
				$val = stripslashes(rawurldecode($val));

				// url clean path for the fielname.
				$ss_song = rawurlencode($key);

				// convert funky chars into html tags.
				$key = strtr($key, $GLOBALS[char_tbl]);

				if($adb->chk_path_md5($md5song)) $mtch =  "match found<br>\n";

				//echo "key = $key<br>\n";
				//echo "val = $p_path$val<br>\n";
				//echo "md5 = $md5song<br>\n";

				$contents .= "<tr bgcolor=\"$bgc\">\n";
				$contents .= "\t<td colspan=\"100%\">&nbsp;<img src=\"$GLOBALS[img_path]/mp32.gif\" border=\"0\">&nbsp;$key<b>$mtch</b></td>\n";
				$contents .= "<input type=\"hidden\" name=\"dest[0][$ss_song]\" value=\"$ss_song\">\n";
				$contents .= "</tr>";

				$clr++;
			}

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

		}else{
			$GLOBALS[contents] = "error.<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)