<?php
if (!defined('ADMIN_FILE') || !is_admin_modul($aid, "Album")) die("Illegal File Access");
include_once("modules/Album/admin/language/lang-".$currentlang.".php");

include_once("config/config_album.php");

function navigationAdmin($url) {
	GraphicAdmin();
	title(""._ALBUM_NAME."");
	OpenTable();
	print $url;
	CloseTable();
}

function getThumbnail($img, $galloc) {
	global $gallerypath, $imagepath, $prefix, $db;
	$ext = substr($img, (strrpos($img,'.') +  1));
	$name_gif = str_replace(".$ext", ".gif", $img);
	$name_jpg = str_replace(".$ext", ".jpg", $img);
	if (file_exists("$gallerypath/$galloc/thumb/$name_gif")) {
		$thumb = "$gallerypath/$galloc/thumb/$name_gif";
	} elseif (file_exists("$gallerypath/$galloc/thumb/$name_jpg")) {
		$thumb = "$gallerypath/$galloc/thumb/$name_jpg";
	} else {
		$row = $db->sql_fetchrow($db->sql_query("SELECT thumbnail from $prefix"._album_media_types." where extension='$ext'"));
		$thumbnail = $row[thumbnail];
		$thumb = "$imagepath/$thumbnail";
	}
	return $thumb;
}

function showoptions() {
	global $prefix, $admin_file, $db;
	head();;
	GraphicAdmin();
	title(""._ALBUM_NAME."");
	OpenTable();
	$result = $db->sql_query("SELECT COUNT(pid) AS total FROM $prefix"._album_pictures_newpicture."");
	$wait = $db->sql_fetchrow($result);
	echo "<a href=\"".$admin_file.".php?op=album&do=Configure\">"._GALGENERALSETTINGS."</a><br>"._GALGENERALSETTINGSDESC."<br><br>\n"
	."<a href=\"".$admin_file.".php?op=album&do=editallcategories\">"._GALEDITCATEGORIES."</a><br>"._GALEDITCATEGORIESDESC."<br><br>\n"
	."<a href=\"".$admin_file.".php?op=album&do=editmedia\">"._GALEDITMEDIA."</a><br>"._GALEDITMEDIADESC."<br><br>\n"
	."<a href=\"".$admin_file.".php?op=album&do=editmediatypes\">"._GALEDITMEDIATYPE."</a><br>"._GALEDITMEDIATYPEDESC."<br><br>\n"
	."<a href=\"".$admin_file.".php?op=album&do=edittemplate\">"._GALEDITTEMPLATE."</a><br>"._GALEDITTEMPLATEDESC."<br><br>\n"
	."<a href=\"".$admin_file.".php?op=album&do=editmedia&type=new\">"._GALADDNEWMEDIA."</a><br>"._GALADDNEWMEDIADESC."<br><br>\n"
	."<a href=\"".$admin_file.".php?op=album&do=quickaddpics\">"._GALBATCHBUILD."</a><br>"._GALBATCHBUILDDESC."<br><br>\n"
	."<a href=\"".$admin_file.".php?op=album&do=validnew&type=checknew\">"._GALPOSTEDMEDIA.' ('.sprintf(_GALWAITING, $wait[total]).")</a><br>"._GALPOSTEDMEDIADESC."<br>\n";
	CloseTable();
	foot();
}

function indent($gid) {
	global $prefix, $db;
	$tab = 0;
	list($parent) = $db->sql_fetchrow($db->sql_query("SELECT parent FROM $prefix"._album_categories." WHERE gallid=$gid"));
	while ($parent != -1) {
		list($parent) = $db->sql_fetchrow($db->sql_query("SELECT parent FROM $prefix"._album_categories." WHERE gallid=$parent"));
		$tab ++;
	}
	return $tab;
}

function listcategories($dir){
	global $prefix, $gallerypath, $db;
	$dossier = opendir($dir);
	$category = "";
	while ($file = readdir($dossier)) {
		if ($file != "." && $file != ".." && $file!="thumb") {
			if (is_dir($dir."/".$file)) {
				$galloc  = substr($dir."/".$file, strlen("$gallerypath/"));
				$result = $db->sql_query("select gallid from $prefix"._album_categories." where galloc='$galloc'");
				if ($db->sql_numrows($result)>0) {
					list($gid) = $db->sql_fetchrow($result);
					$category .= "$gid ";
				}
				$category .= listcategories("$dir/$file");
			}
		}
	}
	return $category;
}


function rebuild_totals() {
	global $prefix, $db;
	$result = $db->sql_query("SELECT gallid FROM $prefix"._album_categories." WHERE visible>0 ORDER BY gallid");
	while($row = $db->sql_fetchrow($result)) {
		$total = $db->sql_fetchrow($db->sql_query("SELECT COUNT(pid) AS total FROM $prefix"._album_pictures." WHERE gid=$row[gallid]"));
		$catTotal[$row[gallid]] = $total[total];
	}
	$result = $db->sql_query("SELECT gallid, parent FROM $prefix"._album_categories." WHERE visible>0 ORDER BY parent DESC");
	while($row = $db->sql_fetchrow($result)) {
		if($row[parent]) {
			$t[$row[parent]] = ($t[$row[parent]] + $catTotal[$row[gallid]]) + $t[$row[gallid]];
		}
	}
	$result = $db->sql_query("SELECT gallid, parent FROM $prefix"._album_categories." WHERE visible>0 ORDER BY parent DESC");
	while($row = $db->sql_fetchrow($result)) {
		$t[$row[gallid]] = $t[$row[gallid]] + $catTotal[$row[gallid]];
	}
	$result = $db->sql_query("SELECT gallid FROM $prefix"._album_categories." ORDER BY gallid");
	while($row = $db->sql_fetchrow($result)) {
		$t[$row[gallid]] = intval($t[$row[gallid]]);
	}
	if (is_array($t)) {
		foreach($t as $k=>$v) {
			$db->sql_query("UPDATE $prefix"._album_categories." SET total=$v WHERE gallid=$k");
		}
	}
}

function rebuild_lastadd() {
	global $prefix, $db;
	$result = $db->sql_query("SELECT gallid FROM $prefix"._album_categories." ORDER BY gallid");
	while($row = $db->sql_fetchrow($result)) {
		$high = $db->sql_fetchrow($db->sql_query("SELECT COUNT(pid) AS total, TO_DAYS(date) AS days FROM $prefix"._album_pictures." WHERE gid=$row[gallid] GROUP BY date ORDER BY date DESC"));
		if($high[total]) {
			$db->sql_query("UPDATE $prefix"._album_categories." SET lastadd=FROM_DAYS($high[days]) WHERE gallid=$row[gallid]");
		} else {
			$db->sql_query("UPDATE $prefix"._album_categories." SET lastadd=0 WHERE gallid=$row[gallid]");
		}
	}
	$result = $db->sql_query("SELECT gallid, parent, TO_DAYS(lastadd) AS days FROM $prefix"._album_categories." WHERE visible>0 ORDER BY parent DESC");
	while($row = $db->sql_fetchrow($result)) {
		if($row[parent]) {
			$prow = $db->sql_fetchrow($db->sql_query("SELECT TO_DAYS(lastadd) AS days FROM $prefix"._album_categories." WHERE gallid=$row[parent]"));
			if($row[days] > $prow[days]) {
				$db->sql_query("UPDATE $prefix"._album_categories." SET lastadd=FROM_DAYS($row[days]) WHERE gallid=$row[parent]");
			}
		}
	}
}

function changeStatus($gid, $visible) {
	global $prefix, $db;
	$sql = "UPDATE $prefix"._album_categories." SET visible=$visible WHERE gallid=$gid";
	$db->sql_query($sql);
	$sql= "SELECT gallid FROM $prefix"._album_categories." WHERE parent=$gid";
	$result = $db->sql_query($sql);
	while ($row = $db->sql_fetchrow($result)) {
		changeStatus($row[gallid], $visible);
	}
	$db->sql_freeresult($result);
}
switch($op) {
	case "album":
	switch($do) {
		case "Configure":
		include("modules/Album/admin/settings.php");
		AlbumConfig();
		break;

		case "AlbumConfigSave":
		include("modules/Album/admin/settings.php");
		AlbumConfigSave();
		Header("Location: ".$admin_file.".php?op=album&do=Configure");
		break;

		case "editallcategories":
		include("modules/Album/admin/editallcategories.php");
		editallcategories();
		break;

		case "editcategory":
		if (isset($type) && $type!="") {
			switch ($type) {
				case "save":
				global $db, $admin_file;
				if (isset($category) && $category!="") {
					$sql = "UPDATE $prefix"._album_categories." SET ";
					$sql .= "thumbwidth='$thumbwidth', ";
					$sql .= "gallname='$categoryname', ";
					$sql .= "gallimg='$image', ";
					$sql .= "description='$description_cat', ";
					$sql .= "template='$xtemplate', ";
					$sql .= "visible='$visible', ";
					$sql .= "numcol='$numcol' ";
					$sql .= "WHERE gallid=$category";
					$db->sql_query($sql);
				}
				rebuild_totals();
				rebuild_lastadd();
				Header("Location: ".$admin_file.".php?op=album&do=editallcategories");
				break;

				case "create":
				global $db, $admin_file;
				include ("modules/Album/admin/fileFunctions.php");
				$categoryloc = traite_nom_fichier($categoryloc);
				if ($parent!=-1) $categoryloc = "$parentloc/$categoryloc";
				$wdir = "/";
				$makeDir_return = makeDir($gallerypath, $categoryloc);
				$userfile = $_FILES['userfile']['tmp_name'];
				if ($makeDir_return=="OK") {
					if (!isset($userfile) || $userfile == "" || $userfile == "none") {
						$userfile = $imagepath."/gallery.gif";
						$userfile_name = "gallery.gif";
						$userfile_size = 10;
						if (!copy($userfile, "$gallerypath/$categoryloc/$userfile_name")) {
							$upload_return = _GALUPLOADERROR3;
						} else {
							$upload_return = "OK";
						}
					} else {
						$userfile_name = $_FILES['userfile']['name'];
						$userfile_size = $_FILES['userfile']['size'];
						$upload_return = UploadFile($gallerypath.$wdir.$categoryloc, $userfile, $userfile_name, $userfile_size);
					}
					if ($upload_return == "OK") {
						$sql = "INSERT INTO $prefix"._album_categories." (gallid, gallname, gallimg, galloc, description, parent, visible, template, numcol, total, lastadd) VALUES (NULL, '$categoryname', '$userfile_name', '$categoryloc', '$description_cat', '$parent', '$visible', '2', '$numcol', '0', now())";
						$db->sql_query($sql);
					} else {
						head();
						GraphicAdmin();
						title(""._ALBUM_NAME."");
						OpenTable();
						echo '<center>'.$upload_return.'<br><br>'._GOBACK.'</center>';
						CloseTable();
						foot();
					}
					rebuild_totals();
					rebuild_lastadd();
				} else {
					head();
					GraphicAdmin();
					title(""._ALBUM_NAME."");
					OpenTable();
					echo '<center>'.$makeDir_return.'<br><br>'._GOBACK.'</center>';
					CloseTable();
					foot();;
				}
				Header("Location: ".$admin_file.".php?op=album&do=editallcategories");
				break;

				case "move":
				global $db, $admin_file;
				include("modules/Album/admin/movecategory.php");
				$basedir = "$gallerypath";
				$wdir = "/";
				if (!isset($confirmed) || $confirmed=="") {
					movecategory($category);
				} else {
					list($oldloc) = $db->sql_fetchrow($db->sql_query("SELECT galloc FROM $prefix"._album_categories." WHERE gallid=$oldlocation"));
				}
				list($newloc) = $db->sql_fetchrow($db->sql_query("SELECT galloc FROM $prefix"._album_categories." WHERE gallid=$newparent"));
				$dir = substr (strrchr ($oldloc, "/"), 1);
				if ($dir=="") {
					if ($newloc!="") {
						$db->sql_query("UPDATE $prefix"._album_categories." SET thumbwidth='$thumbwidth', parent=$newparent, galloc='$newloc/$oldloc' WHERE gallid=$oldlocation");
						rmove($basedir.$wdir.$oldloc,$basedir.$wdir.$newloc.$wdir.$oldloc);
					} else {
						$db->sql_query("UPDATE $prefix"._album_categories." SET thumbwidth='$thumbwidth', parent=$newparent, galloc='$oldloc' WHERE gallid=$oldlocation");
						rmove($basedir.$wdir.$oldloc,$basedir.$wdir.$oldloc);
					}
				} else {
					if ($newloc!="") {
						$db->sql_query("UPDATE $prefix"._album_categories." SET thumbwidth='$thumbwidth', parent=$newparent, galloc='$newloc/$dir' WHERE gallid=$oldlocation");
						rmove($basedir.$wdir.$oldloc,$basedir.$wdir.$newloc.$wdir.$dir);
					} else {
						$db->sql_query("UPDATE $prefix"._album_categories." SET thumbwidth='$thumbwidth', parent=$newparent, galloc='$dir' WHERE gallid=$oldlocation");
						rmove($basedir.$wdir.$oldloc,$basedir.$wdir.$dir);
					}
				}
				rebuild_totals();
				rebuild_lastadd();
				Header("Location: ".$admin_file.".php?op=album&do=editallcategories");
				break;
	
				case "delete":
				global $admin_file;
				include("modules/Album/admin/deletecategory.php");
				deletecategory($category);
				rebuild_totals();
				rebuild_lastadd();
				Header("Location: ".$admin_file.".php?op=album&do=editallcategories");
				break;
	
				case "status":
				global $admin_file;
				changeStatus($category, $visible);
				rebuild_totals();
				rebuild_lastadd();
				Header("Location: ".$admin_file.".php?op=album&do=editallcategories");
				break;
			}
		} else {
			include("modules/Album/admin/editcategory.php");
			editcategory($category, $parent);
		}
		break;
		
		case "edittemplate":
		global $db, $admin_file;
		if (isset($delete) && $delete!="") {
			$sql = "DELETE FROM $prefix"._album_template_types." WHERE id=$template";
			$db->sql_query($sql);
			Header("Location: ".$admin_file.".php?op=album&do=edittemplate");
		} else {
			if (isset($type) && $type!="") {
				switch ($type) {
					case "edit":
					include("modules/Album/admin/edittemplate.php");
					edittemplate($template);
					break;

					case "save":
					global $db, $admin_file;
					$sql = "UPDATE $prefix"._album_template_types." SET title='$xtemplatename', templateCategory='$xtemplateCat', templatePictures='$xtemplatePic', templateCSS='$xtemplateCSS' WHERE id=$templateid";
					$db->sql_query($sql);
					Header("Location: ".$admin_file.".php?op=album&do=edittemplate");
					break;

					case "create":
					global $db, $admin_file;
					$sql = "INSERT INTO $prefix"._album_template_types." (id, title, type, templateCategory, templatePictures, templateCSS) VALUES (NULL, '$xtemplatename', $xtype, '$xtemplateCat', '$xtemplatePic', '$xtemplateCSS')";
					$db->sql_query($sql);
					Header("Location: ".$admin_file.".php?op=album&do=edittemplate");
					break;
				
					default:
					include("modules/Album/admin/edittemplate.php");
					edittemplate($template);
					break;
				}
			} else {
				include("modules/Album/admin/editalltemplates.php");
				editalltemplates();
			}
			break;
		}
		case "editmedia":
		$limit=5;
		if (isset($type) && $type!="") {
			switch ($type) {
				case "edit":
				include("modules/Album/public/imageFunctions.php");
				include ("modules/Album/admin/fileFunctions.php");
				include ("modules/Album/admin/editmedia.php");
				editmedia($category);
				break;

				case "new":
				global $db, $admin_file;
				include ("modules/Album/admin/fileFunctions.php");
				if (isset($add) && $add=="Insert") {
					list($galloc) = $db->sql_fetchrow($db->sql_query("SELECT galloc FROM $prefix"._album_categories." WHERE gallid=$Category"));
					$wdir = "/";
					$userfile_name = $_FILES['userfile']['name'];
					$userfile_name = traite_nom_fichier($userfile_name);
					$ext = substr($userfile_name, (strrpos($userfile_name,'.') +  1));
					$result = $db->sql_query("SELECT filetype FROM $prefix"._album_media_types." WHERE extension='$ext'");
					if ($db->sql_numrows($result) == 0) {
						head();
						GraphicAdmin();
						title(""._ALBUM_NAME."");
						OpenTable();
						echo '<center>'._GALTYPENOTSUPPORTED.'<br><br>'._GOBACK.'</center>';
						CloseTable();
						foot();
					} else {
						$userfile = $_FILES['userfile']['tmp_name'];
						$userfile_size = $_FILES['userfile']['size'];
						list($type) = $db->sql_fetchrow($result);
						$upload_return = UploadFile($gallerypath.$wdir.$galloc, $userfile, $userfile_name, $userfile_size);
						if ($upload_return=="OK") {
							switch($type) {
								case 1:
								if ($ext!="bmp" && $ext!="BMP") $size = @getimagesize($gallerypath.$wdir.$galloc.$wdir.$userfile_name);
								break;
								case 3 :
								$size[0] = 320;
								$size[1] = 240;
								break;
								default:
								$size[0] = 0;
								$size[1] = 0;
								break;
							}
							if ($ext!="bmp" && $ext!="BMP") {
								$sql = "insert into $prefix"._album_pictures." (pid, gid, img, counter, submitter, date, name, description, votes, rate, extension, width, height) values(NULL, $Category, '$userfile_name', 0, '$Submitter', now(), '$MediaName', '$Description', 0, 0, '$ext', ".$size[0].", ".$size[1].")";
							} else {
								$sql = "insert into $prefix"._album_pictures." (pid, gid, img, counter, submitter, date, name, description, votes, rate, extension, width, height) values(NULL, $Category, '$userfile_name', 0, '$Submitter', now(), '$MediaName', '$Description', 0, 0, '$ext', 0, 0)";
							}
							$db->sql_query($sql);
						} else {
							head();
							GraphicAdmin();
							title(""._ALBUM_NAME."");
							OpenTable();
							echo '<center>'.$upload_return.'<br><br>'._GOBACK.'</center>';
							CloseTable();
							foot();
						}
						Header("Location: ".$admin_file.".php?op=album");
					}
				} else {
					include ("modules/Album/admin/createmedia.php");
					createmedia();
				}
				rebuild_totals();
				rebuild_lastadd();
				break;

				case "existing":
				global $db, $admin_file;
				for ($i=0; $i<$limit; $i++) {
					$task = "Task$i";
					if (isset($$task)) {
						switch ($$task) {
							case "Save":
							$file = "FileName$i";
							$fileid = "FileId$i";
							$desc = "Description$i";
							$name = "FileName$i";
							$mname = "MediaName$i";
							$date = "Date$i";
							$cat = "Category$i";
							$oldcat = "OldCategory$i";
							$submitter = "Submitter$i";
							$width = "Width$i";
							$height = "Height$i";
							$sql  = "UPDATE $prefix"._album_pictures." ";
							$sql .= "SET gid=".$$cat.", ";
							$sql .= "submitter='".$$submitter."', date='".$$date."', img='".$$name."', ";
							$sql .= "name='".$$mname."', description = '".$$desc."', ";
							$sql .= "width='".$$width."', height='".$$height."' ";
							$sql .= "WHERE pid=".$$fileid;
							$okcat =1;
							$basedir = "modules/Album";
							$wdir = "/";
							if ($$cat != $$oldcat) {
								list($oldloc) = $db->sql_fetchrow($db->sql_query("SELECT galloc from $prefix"._album_categories." WHERE gallid=".$$oldcat));
								list($newloc) =  $db->sql_fetchrow($db->sql_query("SELECT galloc from $prefix"._album_categories." WHERE gallid=".$$cat));
								if (rename($gallerypath.$wdir.$oldloc.$wdir.$$name,$gallerypath.$wdir.$newloc.$wdir.$$name)) {
									$okcat = 1;
									$thumb = getThumbnail($$name, $oldloc);
									if (!strstr($thumb,$imagepath)) {
										$thumb = substr (strrchr ($thumb, "/"), 1);
										if (rename($gallerypath.$wdir.$oldloc.$wdir."thumb/".$thumb,$gallerypath.$wdir.$newloc.$wdir."thumb/".$thumb)) {
											$okcat = 1;
										} else {
											$okcat = 0;
										}
									}
								} else {
									$okcat = 0;
								}
							}
							if ($okcat) $db->sql_query($sql);
							rebuild_totals();
							rebuild_lastadd();
							break;

							case "Delete":
							global $db, $admin_file;
							$file = "FileName$i";
							$cat = "Category$i";
							$fileid = "FileId$i";
							list($galloc) = $db->sql_fetchrow($db->sql_query("SELECT galloc FROM $prefix"._album_categories." WHERE gallid=".$$cat));
							$basedir = "$gallerypath";
							$wdir = "/";
							if (file_exists($basedir.$wdir.$galloc.$wdir.$$file)) {
								unlink($basedir.$wdir.$galloc.$wdir.$$file);
							}
							$thumb = getThumbnail($$file, $galloc);
							if (!strstr($thumb, $imagepath)) if (file_exists($thumb)) unlink($thumb);
							$sql  = "DELETE FROM $prefix"._album_pictures." WHERE pid=".$$fileid;
							$db->sql_query($sql);
							rebuild_totals();
							rebuild_lastadd();
							break;
						}
					}
				}
				rebuild_totals();
				rebuild_lastadd();
				Header("Location: ".$admin_file.".php?op=album&do=editmedia");
				break;
			}
		} else {
			include ("modules/Album/admin/maineditmedia.php");
			maineditmedia();
		}
		break;
	
		case "quickaddpics":
		include ("modules/Album/admin/quickaddmedia.php");
		quickaddpics($gallid, $recursive, $submitter, $desc_pic, $desc_cat);
		rebuild_totals();
		rebuild_lastadd();
		break;

		case "validnew":
		global $temppath, $db, $admin_file;
		$limit=6;
		if (isset($type) && $type!="") {
			switch($type) {
				case "validate":
				global $admin_file, $db;
				for ($i=0; $i<$limit; $i++) {
					$task = "Task$i";
					if (isset($$task)) {
						switch ($$task) {
							case "Validate":
							global $db;
							$fileid = "FileId$i";
							$desc = "Description$i";
							$name = "FileName$i";
							$oldname = "OldFileName$i";
							$mname = "MediaName$i";
							$date = "Date$i";
							$cat = "Category$i";
							$submitter = "Submitter$i";
							$width = "Width$i";
							$height = "Height$i";
							$basedir = "modules/Album";
							$wdir = "/";
							list($newloc) = $db->sql_fetchrow($db->sql_query("SELECT galloc FROM $prefix"._album_categories." WHERE gallid=".$$cat));
							if(!file_exists($basedir.$wdir."gallery".$wdir.$newloc.$wdir.$$name)) {
								if (rename($temppath.$wdir.$$oldname,$basedir.$wdir."album".$wdir.$newloc.$wdir.$$name)) {
									$ext = substr($$name, (strrpos($$name,'.') +  1));
									$sql  = "INSERT INTO $prefix"._album_pictures." (pid, gid, img, counter, submitter, date, name, description, votes, rate, extension, width, height) VALUES(NULL, ".$$cat.", '".$$name."', 0, '".$$submitter."', '".$$date."', '".$$mname."', '".$$desc."', 0, 0, '".$ext."', ".$$width.", ".$$height.")";
									$db->sql_query($sql);
									$sql = "DELETE FROM $prefix"._album_pictures_newpicture." WHERE pid=".$$fileid;
									$db->sql_query($sql);
									rebuild_totals();
									rebuild_lastadd();
								} else {
									head();
									GraphicAdmin();
									title(""._ALBUM_NAME."");
									OpenTable();
									echo '<center>Move Failed.<br><br>'._GOBACK.'</center>';
									CloseTable();
									foot();
								}
							} else {
								head();
								GraphicAdmin();
								title(""._ALBUM_NAME."");
								OpenTable();
								echo '<center>File already exists.<br><br>'._GOBACK.'</center>';
								CloseTable();
								foot();
							}
							break;

							case "Delete":
							global $db;
							$file = "FileName$i";
							$fileid = "FileId$i";
							$basedir = $temppath;
							$wdir = "/";
							if (file_exists($basedir.$wdir.$$file)) unlink($basedir.$wdir.$$file);
							$sql  = "DELETE FROM $prefix"._album_pictures_newpicture." WHERE pid=".$$fileid;
							$db->sql_query($sql);
							rebuild_totals();
							rebuild_lastadd();
							break;
						}
					}
				}
				Header("Location: ".$admin_file.".php?op=album&do=validnew&type=checknew");
				break;

				case "checknew":
				include ("modules/Album/admin/validnewmedia.php");
				validnew();
				rebuild_totals();
				rebuild_lastadd();
				break;
			}
		} else {
			Header("Location: ".$admin_file.".php");
		}
		break;

		case "editmediatypes" :
		include ("modules/Album/admin/editmediatypes.php");
		if (isset($type) && $type!="") {
			switch($type) {
				case "edit":
				global $admin_file, $db;
				if (isset($save)) {
					$sql = "UPDATE $prefix"._album_media_types." SET extension='$extension', description='$description', filetype=$class, displaytag='$code', thumbnail='$thumbnail' WHERE extension='$oldext'";
				}
				if (isset($delete)) {
					$sql = "DELETE FROM $prefix"._album_media_types." WHERE extension='$oldext'";
				}
				$db->sql_query($sql);
				Header("Location: ".$admin_file.".php?op=album&do=editmediatypes");
				break;

				case "new":
				global $admin_file, $db;
				$sql = "INSERT INTO $prefix"._album_media_types." (extension, description,filetype, displaytag, thumbnail) VALUES ('$extension','$description', $class, '$code', '$thumbnail')";
				$db->sql_query($sql);
				Header("Location: ".$admin_file.".php?op=album&do=editmediatypes");
				break;
			}
		} else {
			editmediatypes();
		}
		break;

		default:
		showoptions();
		break;
	}
}
?>