Location: PHPKode > projects > PHPmyCDMouse > phpmycdmouse_031/sysiconadd.php
<?
/*
   Copyright (C) 2003  by Uwe Thiel, Germany

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
    USA.
*/
session_start();
$Access = $_SESSION["Access"];

if (!$Access[ChangeSystemIcons]) header("Location: index.php");


require("./config.inc.php");
require($Header);
require("./functioninc/catpopup.js");
require("./functioninc/icon.func");


$Action = $_GET["Action"];
if (!isset($Action)) $Action =$_POST["Action"];
$abbruch = $_POST["abbruch"];
$ext=$_POST["ext"];
$id=$_GET["id"];




clearstatcache();  # Clear the statcache of File-Functions (like is_dir or is_link and so on).



if (isset($abbruch)) { # If Cancel is clicked after AddCD, then the global Variables must be unset, because they were filled with data after AddCD
    unset($Action);
    deletevars();
                     }




$submit=$_POST["submit"];

if ($submit) {

    $iconname=$_FILES["icon"]["name"];
    $iconsize=$_FILES["icon"]["size"];
    $icontype=$_FILES["icon"]["type"];
    $iconbin=$_FILES["icon"]["tmp_name"];
    $description=$_POST["Icon_Description"];

           if ((isset($description))&&($description != "")&&(isset($iconbin))&&($iconbin !="")) {


	   if (isset($description)) {


#	        $bindata = base64_encode(fread(fopen($iconbin, "r"), filesize($iconbin)));
	        $fp=fopen($iconbin, "r");
		if ($fp) {
		 $bindata = base64_encode(fread($fp, filesize($iconbin)));
		 if ($bindata) {
		 $newiconentry=new CD_DB;
                 $newiconentrySQL="INSERT INTO SystemIcons (Iconname,Iconsize,Icontype,Image_bin,Description) VALUES ('$iconname','$iconsize','$icontype','$bindata','$description')";
		 $newiconentry->query($newiconentrySQL);
		 $iconid=$newiconentry->insertid();

		  } ##of if ($bindata)
		  else echo "<div class=\"Alert\">Cannot read uploaded Icon-File! Database NOT updated!</div>";
		 if (!fclose($fp)) echo "<div class=\"Alert\">Warning! Cannot close opened Icon-File!</div>";
		} ##of if($fp)
		else {
		      echo "<div class=\"Alert\">Cannot open uploaded Icon-File! Database NOT updated!</div>";
		      ?>
		      <form method="post" name="backform" action="<?=$_SERVER["PHP_SELF"]?>"
		      <input type="submit" name="Back" value="Back"></form>
		      <?
		      fclose($fp); die();
		      }



	   } ######of isset($extarray && isset....)

?>
<script type="text/javascript">
window.opener.top.mainwindow.location.reload(true);
window.close();
</script>

<?
  } ####of if (isset($extension) && ($extension!="")&&(isset($description))&& ($decription != ""))) #########
   else {

   $message="<div class=\"Alert\">You must enter an file,extension AND description.</div>";
   $submit=false;

        } ###of else if(isset($extension) &&...



} #####of if($submit)
if (!$submit) {

?>
    <h1> Add a new system icon to database </h1><br><br>
    <? echo $message;?>
    <form method="post" name=iconform action="<?=$_SERVER["PHP_SELF"]?>" enctype="multipart/form-data">
    <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
    <br>File to upload/store in database:<br>
    <input type="file" name="icon"  value="<?=$iconname?>" size="40">
    <p>Icon Description (e.g. "Binary Data"):<br>
    <input type="text" name="Icon_Description" value="<?=$description?>" size="40">
    <br><br><p><input type="submit" name="submit" value="submit"><input type=button name=Cancel value=cancel onClick="window.close()">
    </form>


<? } ######of if (!$submit)


require($Footer);
?>
Return current item: PHPmyCDMouse