home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / email / attach_online.php < prev    next >
PHP Script  |  2004-03-08  |  3KB  |  128 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. require("../../Group-Office.php");
  14. $GO_SECURITY->authenticate();
  15. $GO_MODULES->authenticate('email');
  16. require($GO_LANGUAGE->get_language_file('email'));
  17.  
  18. //load file management class
  19. require($GO_CONFIG->class_path."filesystem.class.inc");
  20. require($GO_CONFIG->class_path.'email.class.inc');
  21. require($GO_CONFIG->class_path.'filetypes.class.inc');
  22. $email = new email();
  23. $fs = new filesystem();
  24. $filetypes = new filetypes();
  25.  
  26. $path = stripslashes($_REQUEST['path']);
  27. $task = '';
  28.  
  29. if (!$fs->has_read_permission($GO_SECURITY->user_id, $path))
  30. {
  31.     header('Location: '.$GO_CONFIG->host.'error_docs/401.php');
  32.     exit();
  33. }
  34.  
  35. $attachments_size = 0;
  36.  
  37. if (isset($_SESSION['attach_array']))
  38. {
  39.     for($i=1;$i<=sizeof($_SESSION['attach_array']);$i++)
  40.     {
  41.         $attachments_size += $_SESSION['attach_array'][$i]->file_size;
  42.     }
  43. }
  44.  
  45. if (isset($_REQUEST['files']))
  46. {
  47.     for ($i=0;$i<count($_REQUEST['files']); $i++)
  48.     {
  49.         $attachments_size += filesize(smartstrip($_REQUEST['files'][$i]));
  50.     }
  51.     if ($attachments_size < $GO_CONFIG->max_attachment_size)
  52.     {
  53.         while ($file = smartstrip(array_shift($_REQUEST['files'])))
  54.         {
  55.             $tmp_file = $GO_CONFIG->tmpdir.md5(uniqid(time()));
  56.             if (copy($file, $tmp_file))
  57.             {
  58.                 $filename = basename($file);
  59.                 $extension = get_extension($filename);
  60.                 if (!$type = $filetypes->get_type($extension))
  61.                 {
  62.                     $type = $filetypes->add_type($extension);
  63.                 }
  64.                 $email->register_attachment($tmp_file, $filename, filesize($file), $type['mime'], 'attachment');
  65.             }
  66.         }
  67.     }else
  68.     {
  69.         $task = 'too_big';
  70.     }
  71. }else
  72. {
  73.     if (isset($path) && !is_dir($path))
  74.     {    $filesize = filesize($path);
  75.         $attachments_size += $filesize;
  76.         if ($attachments_size < $GO_CONFIG->max_attachment_size)
  77.         {
  78.             $tmp_file = $GO_CONFIG->tmpdir.md5(uniqid(time()));
  79.             if (copy($path, $tmp_file))
  80.             {
  81.                 $filename = basename($path);
  82.                 $email->register_attachment($tmp_file, $filename, $filesize);
  83.                 $task = 'attached';
  84.             }else
  85.             {
  86.                 die($strDataError);
  87.             }
  88.         }else
  89.         {
  90.             $task = 'too_big';
  91.         }
  92.     }
  93. }
  94.  
  95. if ($task == 'too_big')
  96. {
  97. ?>
  98.     <html>
  99.     <body>
  100.     <script type="text/javascript">
  101.             alert("<?php echo $ml_file_too_big.format_size($GO_CONFIG->max_attachment_size)." (".number_format($GO_CONFIG->max_attachment_size, 0, $_SESSION['GO_SESSION']['decimal_seperator'], $_SESSION['GO_SESSION']['thousands_seperator'])." bytes)."; ?>");
  102.             window.close();
  103.     </script>
  104.     </body>
  105.     </html>
  106. <?php
  107. }else
  108. {
  109.     ?>
  110.  
  111.     <html>
  112.     <body>
  113.     <script type="text/javascript">
  114.             opener.document.sendform.sendaction.value = 'attach_online';
  115.             if(opener.document.sendform.content_type.value == 'text/HTML')
  116.             {
  117.                 opener.document.sendform.onsubmit();
  118.             }
  119.             opener.document.sendform.submit();
  120.             window.close();
  121.     </script>
  122.     </body>
  123.     </html>
  124. <?php
  125.  
  126. }
  127. ?>
  128.