From edf64c2e764b5abc4f81a1e90113f2f2c1281829 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 4 Jun 2006 17:18:20 +0000 Subject: [PATCH] r865: Finished notifications for new attachments --- attachment.php | 13 +++++++++++- includes/class_notification.php | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/attachment.php b/attachment.php index ab2dcf1..41e66c1 100755 --- a/attachment.php +++ b/attachment.php @@ -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 diff --git a/includes/class_notification.php b/includes/class_notification.php index 6eee92b..e07b0d4 100644 --- a/includes/class_notification.php +++ b/includes/class_notification.php @@ -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 -- 2.22.5