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');
require_once('./includes/class_logging.php');
+$notif = new NotificationCenter;
+$notif->set_bug_data($bug);
+
// ###################################################################
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]");
$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
}
}
+ // ###################################################################
+ /**
+ * 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