r865: Finished notifications for new attachments
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 4 Jun 2006 17:18:20 +0000 (17:18 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 4 Jun 2006 17:18:20 +0000 (17:18 +0000)
attachment.php
includes/class_notification.php

index ab2dcf1aae6b9dfdf10e349114445eff8544c65f..41e66c1bc3221d1d2a4ae851d480e757c7ccd0eb 100755 (executable)
@@ -30,6 +30,7 @@ $focus['showreport'] = 'focus';
 
 require_once('./global.php');
 require_once('./includes/class_api_error.php');
+require_once('./includes/class_notification.php');
 require_once('./includes/api_attachment.php');
 require_once('./includes/api_comment.php');
 
@@ -52,6 +53,9 @@ if (!$bug)
 
 require_once('./includes/class_logging.php');
 
+$notif = new NotificationCenter;
+$notif->set_bug_data($bug);
+
 // ###################################################################
 
 if ($_POST['do'] == 'insert')
@@ -107,8 +111,11 @@ if ($_POST['do'] == 'insert')
        {
                $attachapi->insert();
                
-               // mark obsoletes
                $obsoletes = $bugsys->input_clean('obsoletes', TYPE_UINT);
+               
+               $notif->send_new_attachment_notice($attachapi->values, $obsoletes, $attachapi->insertid);
+               
+               // mark obsoletes
                if (is_array($obsoletes) AND sizeof($obsoletes) > 0)
                {
                        $db->query("UPDATE " . TABLE_PREFIX . "attachment SET obsolete = 1 WHERE attachmentid IN (" . implode(',', $obsoletes) . ") AND !obsolete AND bugid = $bug[bugid]");
@@ -133,11 +140,15 @@ if ($_POST['do'] == 'insert')
                        $comment->set('comment',        $bugsys->in['comment']);
                        $comment->set('dateline',       $attachapi->values['dateline']);
                        $comment->insert();
+                       
+                       $notif->send_new_comment_notice($comment->values);
                }
                
                // update the last post data
                $db->query("UPDATE " . TABLE_PREFIX . "bug SET lastposttime = " . $attachapi->values['dateline'] . ", hiddenlastposttime = " . $attachapi->values['dateline'] . ", lastpostby = " . $bugsys->userinfo['userid'] . ", hiddenlastpostby = " . $bugsys->userinfo['userid'] . " WHERE bugid = $bug[bugid]");
                
+               print_r($notif);
+               
                $message->redirect($lang->string('The attachment has been added to the bug.'), "showreport.php?bugid=$bug[bugid]");
        }
        else
index 6eee92bc0d3500752f41f4e2236e059a97a89066..e07b0d48707163032af3ad32b75cc32d2e289c02 100644 (file)
@@ -423,6 +423,42 @@ $this->registry->lang->string('The %1$s field changed from "%2$s" to "%3$s".'),
                }
        }
        
+       // ###################################################################
+       /**
+       * Sends appropriate users a notice when a new attachment has been
+       * added.
+       *
+       * @access       public
+       *
+       * @param        array   AttachmentAPI->values array
+       * @param        array   List of all attachments made obsolete
+       * @param        array   Newly-inserted attachment ID
+       */
+       function send_new_attachment_notice($attachment, $obsolete, $id)
+       {
+               $userlist = $this->fetch_users_with_on_bit('newattachment');
+               foreach ($userlist AS $userid => $user)
+               {
+                       $this->notices["$userid"][] = sprintf(
+$this->registry->lang->string('%1$s has uploaded a new attachment:
+============================================
+File name: %2$s
+Description: %3$s
+File size: %4$s Bytes
+Makes obsolete: %5$s
+View: %6$s
+============================================'),
+                               
+                               construct_user_display($this->registry->userinfo, false),
+                               $attachment['filename'],
+                               $attachment['description'],
+                               $attachment['filesize'],
+                               implode(', ', (array)$obsolete),
+                               $this->registry->options['trackerurl'] . '/viewattachment.php?attachmentid=' . $id
+                       );
+               }
+       }
+       
        // ###################################################################
        /**
        * Generates an array of users who have a given email notification flag