Plugin may be invisible when JS is not detected
[squirrelmail.git] / plugins / newmail / setup.php
index 0deb4dac1c3ce3019806f310bd3b53e1e0652137..456eb88ff7767028c25867acf7bea1659531cd1f 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * newmail.php
  *
- * Copyright (c) 1999-2004 The SquirrelMail Project Team
+ * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Copyright (c) 2000 by Michael Huttinger
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  */
 
 /**
+ * sqm_baseuri function for setups that don't load it by default
  */
 include_once(SM_PATH . 'functions/display_messages.php');
 
+/** Load plugin functions */
+include_once(SM_PATH . 'plugins/newmail/functions.php');
+
 /**
  * Checks if mailbox contains new messages.
  *
@@ -105,7 +109,7 @@ function newmail_optpage_register_block() {
  * Save newmail plugin settings
  */
 function newmail_sav() {
-    global $data_dir, $username;
+    global $data_dir, $username, $_FILES;
 
     if ( sqgetGlobalVar('submit_newmail', $submit, SQ_POST) ) {
         $media_enable = '';
@@ -114,25 +118,67 @@ function newmail_sav() {
         $media_recent = '';
         $media_changetitle = '';
         $media_sel = '';
+        $popup_width = '';
+        $popup_height = '';
 
         sqgetGlobalVar('media_enable',      $media_enable,      SQ_POST);
         sqgetGlobalVar('media_popup',       $media_popup,       SQ_POST);
         sqgetGlobalVar('media_allbox',      $media_allbox,      SQ_POST);
         sqgetGlobalVar('media_recent',      $media_recent,      SQ_POST);
         sqgetGlobalVar('media_changetitle', $media_changetitle, SQ_POST);
+        sqgetGlobalVar('popup_width',       $popup_width,       SQ_POST);
+        sqgetGlobalVar('popup_height',      $popup_height,      SQ_POST);
+
+        // sanitize height and width
+        $popup_width = (int) $popup_width;
+        if ($popup_width<=0) $popup_width=200;
+        $popup_height = (int) $popup_height;
+        if ($popup_height<=0) $popup_height=130;
 
         setPref($data_dir,$username,'newmail_enable',$media_enable);
         setPref($data_dir,$username,'newmail_popup', $media_popup);
         setPref($data_dir,$username,'newmail_allbox',$media_allbox);
         setPref($data_dir,$username,'newmail_recent',$media_recent);
         setPref($data_dir,$username,'newmail_changetitle',$media_changetitle);
+        setPref($data_dir,$username,'newmail_popup_width',$popup_width);
+        setPref($data_dir,$username,'newmail_popup_height',$popup_height);
 
         if( sqgetGlobalVar('media_sel', $media_sel, SQ_POST) &&
-            ($media_sel == '(none)' || $media_sel == '(local media)') ) {
+            $media_sel == '(none)' ) {
             removePref($data_dir,$username,'newmail_media');
         } else {
             setPref($data_dir,$username,'newmail_media',$media_sel);
         }
+
+        // process uploaded file
+        if (isset($_FILES['media_file']['tmp_name']) && $_FILES['media_file']['tmp_name']!='') {
+            // set temp file and get media file name
+            $newmail_tempmedia=getHashedDir($username, $data_dir) . "/$username.tempsound";
+            $newmail_mediafile=getHashedFile($username, $data_dir, $username . '.sound');
+            if (move_uploaded_file($_FILES['media_file']['tmp_name'], $newmail_tempmedia)) {
+                // new media file is in $newmail_tempmedia
+                if (file_exists($newmail_mediafile)) unlink($newmail_mediafile);
+                if (! rename($newmail_tempmedia,$newmail_mediafile)) {
+                    // remove (userfile), if file rename fails
+                    removePref($data_dir,$username,'newmail_media');
+                } else {
+                    // store media type
+                    if (isset($_FILES['media_file']['type']) && isset($_FILES['media_file']['name'])) {
+                        setPref($data_dir,$username,'newmail_userfile_type',
+                           newmail_get_mediatype($_FILES['media_file']['type'],$_FILES['media_file']['name']));
+                    } else {
+                        removePref($data_dir,$username,'newmail_userfile_type');
+                    }
+                    // store file name
+                    if (isset($_FILES['media_file']['name'])) {
+                        setPref($data_dir,$username,'newmail_userfile_name',basename($_FILES['media_file']['name']));
+                    } else {
+                        setPref($data_dir,$username,'newmail_userfile_name','mediafile.unknown');
+                    }
+
+                }
+            }
+        }
     }
 }
 
@@ -143,13 +189,20 @@ function newmail_pref() {
     global $username,$data_dir;
     global $newmail_media,$newmail_enable,$newmail_popup,$newmail_allbox;
     global $newmail_recent, $newmail_changetitle;
+    global $newmail_userfile_type, $newmail_userfile_name;
+    global $newmail_popup_width, $newmail_popup_height;
 
     $newmail_recent = getPref($data_dir,$username,'newmail_recent');
     $newmail_enable = getPref($data_dir,$username,'newmail_enable');
     $newmail_media = getPref($data_dir, $username, 'newmail_media', '(none)');
     $newmail_popup = getPref($data_dir, $username, 'newmail_popup');
+    $newmail_popup_width = getPref($data_dir, $username, 'newmail_popup_width',200);
+    $newmail_popup_height = getPref($data_dir, $username, 'newmail_popup_height',130);
     $newmail_allbox = getPref($data_dir, $username, 'newmail_allbox');
     $newmail_changetitle = getPref($data_dir, $username, 'newmail_changetitle');
+
+    $newmail_userfile_type = getPref($data_dir, $username, 'newmail_userfile_type');
+    $newmail_userfile_name = getPref($data_dir,$username,'newmail_userfile_name','');
 }
 
 /**
@@ -170,6 +223,9 @@ function newmail_set_loadinfo() {
 function newmail_plugin() {
     global $username, $newmail_media, $newmail_enable, $newmail_popup,
         $newmail_recent, $newmail_changetitle, $imapConnection, $PHP_SELF;
+    global $newmail_mmedia, $newmail_allowsound;
+    global $newmail_userfile_type;
+    global $newmail_popup_width, $newmail_popup_height;
 
     if ($newmail_enable == 'on' ||
         $newmail_popup == 'on' ||
@@ -234,25 +290,26 @@ function newmail_plugin() {
                 "</script>\n";
         }
 
-        if ($totalNew > 0 && $newmail_enable == 'on' && $newmail_media != '' ) {
-            echo '<embed src="'.htmlspecialchars($newmail_media) .
-                "\" hidden=\"true\" autostart=\"true\">\n";
+        // create media output if there are new email messages
+        if ($newmail_allowsound && $totalNew > 0 && $newmail_enable == 'on' && $newmail_media != '' ) {
+            echo newmail_create_media_tags($newmail_media);
         }
+
         if ($totalNew > 0 && $newmail_popup == 'on') {
+            // Idea by:  Nic Wolfe (Nic@TimelapseProductions.com)
+            // Web URL:  http://fineline.xs.mw
+            // More code from Tyler Akins
             echo "<script language=\"JavaScript\">\n".
                 "<!--\n".
                 "function PopupScriptLoad() {\n".
                 'window.open("'.sqm_baseuri().'plugins/newmail/newmail.php?numnew='.$totalNew.
                 '", "SMPopup",'.
-                "\"width=200,height=130,scrollbars=no\");\n".
+                "\"width=$newmail_popup_width,height=$newmail_popup_height,scrollbars=no\");\n".
                 "if (BeforePopupScript != null)\n".
                 "BeforePopupScript();\n".
                 "}\n".
                 "BeforePopupScript = window.onload;\n".
                 "window.onload = PopupScriptLoad;\n".
-                // Idea by:  Nic Wolfe (Nic@TimelapseProductions.com)
-                // Web URL:  http://fineline.xs.mw
-                // More code from Tyler Akins
                 "// End -->\n".
                 "</script>\n";
         }