<?php
/*
This file is part of Thomas Bley's moregroupware webmail2/calendar2/admin2 module. (tb-mgw)

More information:
-----------------

Simple Groupware Solutions Thomas Bley
Fichtenstr. 23
Germany, 85640 Putzbrunn

Contact:
--------

info@simple-groupware.de

http://www.simple-groupware.de


Copyright 2002-2003 Thomas Bley
tb-mgw is distributed under the terms of the GNU General Public License 

tb-mgw 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.

tb-mgw 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 tb-mgw; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// Attachments_Funcs
// Moregroupware.org

$myEnv["module"] = "webmail2";
$myEnv["stdsmenu"] = false;
$myEnv["output"] = "html";

include("../../config.inc.php");
include(INCLUDEPATH . "container.inc.php");
include(WM2_INC_DIR.'virusscan_inc.php');

error_reporting  (E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

checkdir(CACHE_FOLDER."sendmail/",true);

$myvars = array("function","slcsil");
foreach ($myvars as $thevar) {
  ${$thevar} = rawurlencode(stripslashes(myquote((isset($_GET[$thevar])) ? $_GET[$thevar] : (isset($_POST[$thevar]) ? $_POST[$thevar] : ""))));
}
$output = false;
if ($function == "upload") {
  $target = CACHE_FOLDER."sendmail/" . session_id() . "######" . urlencode($_FILES["userfile"]["name"]);
  $result = move_uploaded_file($_FILES["userfile"]["tmp_name"], $target);
  
  if ($MGW->settings["wm2_performvirusscan"]) {
    $MGW->settings["wm2_antivirusprog"] = str_replace("\\","/",$MGW->settings["wm2_antivirusprog"]);
    if (file_exists($target)) {
      if (file_exists($MGW->settings["wm2_antivirusprog"])) {
        list($virusfound,$text) = scan_file($target);
        if ($virusfound) {
          unlink($target);
          $output = true;
          echo '
            <body bgcolor="#E1E1E1"><table width="100%" height="100%" border="0" cellpadding="1" bgcolor="#434343" cellspacing="0"><tr><td valign="middle">
            <table bgcolor="#F3F3F3" border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td>

    		<center>
            <table bgcolor="#B6B6B6" cellpadding="1" cellspacing="0" border="0"><tr><td>
	    	<table border="0" cellpadding="5" cellspacing="0" bgcolor="#ffffff"><tr><td align="center" valign="middle">
            <br>
		    <img src="templates/default/media/virus2.gif" alt="" border="0"><br>
    		<font color="#ff0000"><b>'.$hashmap["virusscan_virus_found"].'</b></font><br>
	    	<a href="javascript:showalert();"><font color="#006633">'.$hashmap["virusscan_show_logfile"].'</font></a><br>
		    <script>
    		function showalert() {
	    	    mystring="";
		    	newWindow = window.open(mystring, \'teammember\', \'width=640,height=440,toolbar=no,menubar=no,scrollbars=yes\');
    	  ';
	      echo 'newWindow.document.write("'.addslashes($text).'<br>");'."\n";
    	  echo '		
	    	}
		    </script>
            <br>
    		</td></tr></table>
            </td></tr></table>
            <br>
	    	</center>
    	  ';
		  exit;
        }
		echo '<script>window.location="attachments.php?import=no&'.SID.'"</script>';
		exit;
      } else { 
        $output = true;
        echo '
            <body bgcolor="#E1E1E1"><table width="100%" height="100%" border="0" cellpadding="1" bgcolor="#434343" cellspacing="0"><tr><td valign="middle">
            <table bgcolor="#F3F3F3" border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td>
        ';
        echo '
    		<center>
            <table bgcolor="#B6B6B6" cellpadding="1" cellspacing="0" border="0"><tr><td>
	    	<table border="0" cellpadding="5" cellspacing="0" bgcolor="#ffffff"><tr><td align="center" valign="middle">
                <font color="#FF0000">
                <b>'.$hashmap["webmail2_virus_scanner_not_found"].'</b>
                </font>
                <br>
    		</td></tr></table>
            </td></tr></table>
            <br>
        ';
        unlink($target);
      }
    }
  }

  if($result and file_exists($target)) {
    Header("Location: attachments.php?import=no&".SID);
  } else {
    if (!$output) {
      echo '<body bgcolor="#E1E1E1"><table width="100%" height="100%" border="0" cellpadding="1" bgcolor="#434343" cellspacing="0"><tr><td valign="middle">
        <table bgcolor="#F3F3F3" border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td>
      ';
    }
    echo '
            <center>
            <table bgcolor="#B6B6B6" cellpadding="1" cellspacing="0" border="0"><tr><td>
	    	<table border="0" cellpadding="5" cellspacing="0" bgcolor="#ffffff"><tr><td align="center" valign="middle">
            <br>
    ';
    echo "<div align='center'><h2>".$hashmap["attachments_funcs_upload_failed"]."</h2><p>";
    echo "<a href='attachments.php?import=no&'".SID."><font color='#006633'>".$hashmap["attachments_funcs_back"]."</font></a></div>\n";
    echo '
            <br>
            </center>
    		</td></tr></table>
            </td></tr></table>
            </td></tr></table>
            </td></tr></table>
    ';
  } // end if

} elseif ($function == "delete") {
  $slcsil = urldecode($slcsil);
  if (file_exists(CACHE_FOLDER."sendmail/" . $slcsil) and is_file(CACHE_FOLDER."sendmail/" . $slcsil)) {unlink(CACHE_FOLDER."sendmail/" . $slcsil);}
  Header("Location: attachments.php?import=no&".SID);
}
?>
