<?php

//////////////////////////////////////////////////////////
        include("config/includes/linkleiste");
echo "<link rel=stylesheet type=\"text/css\" href=\"config/includes/style.css\">\n";
//////////////////////////////////////////////////////////

 if($burned == true)
	{
	unlink("config/tables/burn_path");
	}
include("config/includes/configuration");
//////////////////////////////////////
//// Bilder von der Kamera holen!

if($mount == yes)
	{
	echo "<head>\n<meta http-equiv=\"refresh\" content=\"1; URL=index.php?mount=go\">\n</head>\n";
	echo "<br><br><div align=\"center\"><font size=4 color =#FF0000>Die Camera wird eingebunden und die Bilder werden auf die Festplatte kopiert.<br>Das kann ein wenig dauern...<br><br>Bitte warten Sie....</font></div>";
	exit;
	}
if($mount == go)
	{
	$mount_it ="mount $mount_file";
	system("$mount_it",$return_var);
	if($return_var != 0)
		{
		echo "<br><br><div align=\"center\"><font size=4 color =#FF0000>Die Camera konnt nicht eingebunden werden...</font></div><br>";
		echo "<div align=\"center\"><form action=\"index.php\" method=\"post\">\n<input type=\"submit\" value=\"Ok\">\n</form></div>\n";		exit;
		}
	else
		{
		$find_new_pics = "find $mount_file -name '*jpg'";
		$all_new_pics = `$find_new_pics`;
		$all_new_pics = explode("\n",$all_new_pics);
		if(count($all_new_pics)>0)
			{
			for($x=0; $x<count($all_new_pics)-1; $x++)
				{
				$file = "config/includes/pics_name";
				list($pics_count) = @file($file);
				$pics_count++;
				$fp = fopen("$file","w");
				fwrite($fp,$pics_count);
				fclose($fp);

				$date = filemtime("$all_new_pics[$x]");
				$pic_date = date("d m y H i",$date);
				$pics_date = ereg_replace(" ",".",$pic_date);

				######## jpg's auf die Platte kopieren!

				$execute = "cp -p $all_new_pics[$x] tmp/jpg/jpg_pic$pics_count.jpg";
				exec("$execute");
				
				######## !jpg's auf die Platte kopieren
				
				######## tif's auf die Platte kopieren!
				
				$blank_name = explode("/",$all_new_pics[$x]);
				$parts = count($blank_name)-1;
				$blank_name = explode(".",$blank_name[$parts]);
				
				$find_tif_pic = "find $mount_file -name $blank_name[0].tif";
				$search_tif_pic = `$find_tif_pic`;
				$search_tif_pic = explode("\n",$search_tif_pic);
				$search_tif_pic = $search_tif_pic[0];
				if(empty($search_tif_pic)){}
				else
					{
					$copy_tif_pic = "cp -p $search_tif_pic tmp/tif/tif_pic$pics_count.tif";
					exec("$copy_tif_pic");
					}

				######## /tif's auf die Platte kopieren

				######## Thumbnail erstellen!

				$info = getimagesize("tmp/jpg/jpg_pic$pics_count.jpg");
				$old_width = "$info[0]";
				$old_high = "$info[1]";
				$faktor = $old_width / $new_width;
				$new_high= $old_high / $faktor;
				$image = imagecreatefromjpeg("tmp/jpg/jpg_pic$pics_count.jpg");
				$image1 = imagecreate($new_width,$new_high);
				imagecopyresized($image1, $image, 0,0, 0,0,$new_width,$new_high, $old_width,$old_high);
				imagejpeg($image1,"tmp/thumbs/thumb_pic$pics_count.jpg");
				
				########## /Thumbnail erstellen
				}
			}
		else
			{
			echo "<br><br><div align=\"center\"><font size=4 color =#FF0000>Keine Bilder gefunden...</font></div><br><br>";
			echo "<div align=\"center\"><form action=\"index.php\" method=\"post\">\n<input type=\"submit\" value=\"Ok\">\n</form></div>\n<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>\n";
			}
		$umount_it = "umount $mount_file";
		exec(`$umount_it`);
		echo "<div align=center><font class=h1><br><br>Die Bilder sind auf die Festplatte kopiert!</font>\n";
		echo "<br><br><font class=anweis>Sie können die Kamera abschalten und abklemmen...</font><br><br><br>\n";
		echo "<div align=\"center\"><form action=\"index.php\" method=\"post\">\n<input type=\"submit\" value=\"Ok\">\n</form></div>\n<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>\n";
		}
	}
//////////////////////
/// /bilder von der Kamera holen

// Diese Verzeichnis wird ausgelesen

$verzeichnis = "tmp/thumbs";
$verzeichnis2 = "tmp/jpg";
//////////////////////////////////////////////////////////

$array = array();
$verz=opendir ($verzeichnis);
while ($new = readdir ($verz)) {
if($new != "." && $new != ".."){
  array_push($array,"$new");
}}
closedir($verz);

$count = count($array);

	echo "<br><table width=\"100%\" border=\"0\">\n";
	echo "   <tr>\n";
	echo "      <td width=\"30%\">\n";
	echo "         <a href=\"index.php?mount=yes\"><img src=\"gifs/cam.gif\" width=\"160\" border=\"0\"><br>Bilder von der Camera laden</a>\n";
	echo "            </td>\n";
	echo "      <td width=\"50%\">";
	echo "         <div align=center><font class=h1>Bilder in die Tabellen integrieren</font><br>\n";

	if($count > 0)
		{
		echo "         <font class=titel>(Der Ordner beinhaltet <u>$count</u> Dateien)</font><br><br>\n";
		}
	else
		{
		echo "         <font class=titel>(Keine Bilder in den temporären Verzeichnissen)</font><br><br>\n";
		}
	if($count > 0)
		{
		if($alles == " checked")
			{
			echo "         <form action=index.php?jump=yes method=post class=action><input type=submit value=\"Alles wieder abwählen\"></form>\n";
			}
		else
			{
			echo "         <form action=index.php?jump=yes method=post class=action><input type=hidden name=alles value=\" checked\"><input type=submit value=\"Alle auswählen\"></form>\n";
			}
		if(isset($jump))
			{
			echo"         <font class=text> &nbsp; <a href=#unten>(jump down)</a></font><br>\n";
			}
		}
	echo "         </div>";
	echo "            </td>\n";
	echo "      <td width=\"20%\" valign=\"bottom\">\n";
	if(($REMOTE_ADDR == $computer) || ($REMOTE_ADDR == $localhost))
		{
		echo "         <div align=\"center\"><a href=\"copy.php\"><img src=\"gifs/folder.gif\" border=\"0\"><br><nobr>Bilder aus einem</nobr><br><nobr>Verzeichnis holen</nobr></a></div>\n";
		}
	echo "            </td>\n";
	echo "   </tr>\n";
	echo "</table>\n";




if(isset($mount)){}

else
        {
        if(file_exists("config/includes/tabs")) {}

        else
		{
		echo "<div align=center><font class=anweis>Zuerst muß (mindestens) ein Bereich wie z.B \"Privat\" angelegt werden,<br>\n";
                echo "in den die Bilder verschoben werden:<form action=new_part.php#bereich class=action><nobr><input type=submit value=\"Bereich anlegen\"></form></font></div><br><br>\n";
                exit;
		}



        echo "<form action=move.php method=post>\n";
        echo "<center><table class=rahmenverz width=60% cellspacing=5 cellpadding=4>\n";
        $x = -1;
        $y = 0;
        $anker = -2;
        while ($y < $count)
                {
                $x++;
                $y++;
                $anker++;
                $checked = $array[$x];
                $dat_ident = split("[_]",$array[$x]);
	        $ident = "$dat_ident[1]";

                if(in_array($checked,$_POST))
                        {
                        echo "<tr><td class=verz width=50%><font class=anweis><a name=$x>Verschieben?&nbsp&nbsp&nbsp&nbsp</a></font>&nbsp&nbsp&nbsp&nbsp\n";
                        echo "<input type=checkbox name=$x value=$array[$x] checked></td>\n";
                        }
                else
                        {
                        echo "<tr><td class=verz width=50%><font class=anweis><a name=$x>Verschieben?&nbsp&nbsp&nbsp&nbsp</a></font>&nbsp&nbsp&nbsp&nbsp\n";
                        echo "<input type=checkbox name=$x value=$array[$x]$alles></td>\n";
                        }
                echo "<td class=verz align=center><a href=pic_show.php?kopier_bereich=Vorschau&pic=$ident&anker=$anker>\n";
                echo "<img src=$verzeichnis/$array[$x] border=\"0\"></a></td></tr>\n";

                }
        echo "</table>\n";
        }

if(file_exists("config/includes/tabs") && ($count > 0))
	{
	echo "<br><br><div align=center><font class=anweis><a name=\"unten\">Die ausgewählten Bilder verschieben nach:</a>&nbsp </font>\n";
	echo "<select name=bereich>\n";
	$sector = file("config/includes/tabs");
	usort($sector,"strnatcasecmp");
	for($x=0;$x<count($sector);$x++)
		{
		echo "<option>$sector[$x]</option>\n";
		}
	echo "</select> <font class=anweis>&nbsp;&nbsp<a href=new_part.php>Neuen Bereich anlegen</a><br><br></font>\n";
	echo "<input type=submit value=\"Los gehts!\"></form></div><br><br>\n";
	}

?>
