home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / email / attach_inline.php < prev    next >
PHP Script  |  2004-03-08  |  3KB  |  96 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('filesystem');
  16. require($GO_LANGUAGE->get_language_file('email'));
  17.  
  18. //load file management class
  19. //load file management class
  20. require($GO_CONFIG->class_path."filesystem.class.inc");
  21. require($GO_CONFIG->class_path.'email.class.inc');
  22. require($GO_CONFIG->class_path.'filetypes.class.inc');
  23. $email = new email();
  24. $fs = new filesystem();
  25. $filetypes = new filetypes();
  26.  
  27. $path = stripslashes($_REQUEST['path']);
  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. $filesize = filesize($path);
  45. $attachments_size += $filesize;
  46.  
  47. if ($attachments_size < $GO_CONFIG->max_attachment_size)
  48. {
  49.     $GO_URL = $GO_MODULES->url.'download.php?path='.urlencode($path);
  50.     $filename = basename($path);
  51.     $content_id = md5(uniqid(time())).'@groupoffice';
  52.  
  53.     $extension = get_extension($filename);
  54.     if (!$type = $filetypes->get_type($extension))
  55.     {
  56.         $type = $filetypes->add_type($extension);
  57.     }
  58.  
  59.     $tmp_file = $GO_CONFIG->tmpdir.md5(uniqid(time()));
  60.     if (copy($path, $tmp_file))
  61.     {
  62.         $email->register_attachment($path, $filename, $filesize, $type['mime'], 'inline', $content_id);
  63.  
  64.         $url_replacement['id'] = $content_id;
  65.         $url_replacement['url'] = $GO_URL;
  66.         $_SESSION['url_replacements'][] = $url_replacement;
  67.     }else
  68.     {
  69.         die($strDataError);
  70.     }
  71. ?>
  72.  
  73.     <html>
  74.     <body>
  75.     <script type="text/javascript">
  76.         opener.editor_insertHTML('<img src="<?php echo stripslashes($GO_URL); ?>" border="0" align="absmiddle" />');
  77.         window.close();
  78.     </script>
  79.     </body>
  80.     </html>
  81. <?php
  82. }else
  83. {
  84. ?>
  85.     <html>
  86.     <body>
  87.     <script type="text/javascript">
  88.             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)."; ?>");
  89.             window.close();
  90.     </script>
  91.     </body>
  92.     </html>
  93. <?php
  94. }
  95. ?>
  96.