BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

viewconv.php 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. #declare(strict_types = 1);
  3. if ($ConvID = (int)$_GET['id']) {
  4. // Get conversation info
  5. $DB->query("
  6. SELECT Subject, UserID, Level, AssignedToUser, Unread, Status
  7. FROM staff_pm_conversations
  8. WHERE ID = $ConvID");
  9. list($Subject, $UserID, $Level, $AssignedToUser, $Unread, $Status) = $DB->next_record();
  10. $LevelCap = 1000;
  11. $PMLevel = $Level;
  12. $Level = min($Level, $LevelCap);
  13. if (!(
  14. ($UserID == $LoggedUser['ID'])
  15. || ($AssignedToUser == $LoggedUser['ID'])
  16. || (($Level > 0 && $Level <= $LoggedUser['EffectiveClass']) || ($Level == 0 && $IsFLS))
  17. )) {
  18. // User is trying to view someone else's conversation
  19. error(403);
  20. }
  21. // User is trying to view their own unread conversation, set it to read
  22. if ($UserID == $LoggedUser['ID'] && $Unread) {
  23. $DB->query("
  24. UPDATE staff_pm_conversations
  25. SET Unread = false
  26. WHERE ID = $ConvID");
  27. // Clear cache for user
  28. $Cache->delete_value("staff_pm_new_$LoggedUser[ID]");
  29. }
  30. View::show_header(
  31. 'Staff PM',
  32. 'staffpm,bbcode,vendor/easymde.min',
  33. 'vendor/easymde.min'
  34. );
  35. $UserInfo = Users::user_info($UserID);
  36. $UserStr = Users::format_username($UserID, true, true, true, true);
  37. $OwnerID = $UserID;
  38. $OwnerName = $UserInfo['Username']; ?>
  39. <div>
  40. <div class="header">
  41. <h2>Staff PM - <?=display_str($Subject)?>
  42. </h2>
  43. <div class="linkbox">
  44. <?php
  45. // Staff only
  46. if ($IsStaff) {
  47. ?>
  48. <a href="staffpm.php" class="brackets">My unanswered</a>
  49. <?php
  50. }
  51. // FLS/Staff
  52. if ($IsFLS) {
  53. ?>
  54. <a href="staffpm.php?view=unanswered" class="brackets">All unanswered</a>
  55. <a href="staffpm.php?view=open" class="brackets">Open</a>
  56. <a href="staffpm.php?view=resolved" class="brackets">Resolved</a>
  57. <?php
  58. // User
  59. } else {
  60. ?>
  61. <a href="staffpm.php" class="brackets">Back to inbox</a>
  62. <?php
  63. } ?>
  64. </div>
  65. </div>
  66. <br />
  67. <br />
  68. <div id="inbox">
  69. <?php
  70. // Get messages
  71. $StaffPMs = $DB->query("
  72. SELECT UserID, SentDate, Message, ID
  73. FROM staff_pm_messages
  74. WHERE ConvID = $ConvID");
  75. while (list($UserID, $SentDate, $Message, $MessageID) = $DB->next_record()) {
  76. // Set user string
  77. if ($UserID == $OwnerID) {
  78. // User, use prepared string
  79. $UserString = $UserStr;
  80. $Username = $OwnerName;
  81. } else {
  82. // Staff/FLS
  83. $UserInfo = Users::user_info($UserID);
  84. $UserString = Users::format_username($UserID, true, true, true, true);
  85. $Username = $UserInfo['Username'];
  86. } ?>
  87. <div class="box vertical_space" id="post<?=$MessageID?>">
  88. <div class="head">
  89. <a class="postid"
  90. href="staffpm.php?action=viewconv&amp;id=<?=$ConvID?>#post<?=$MessageID?>">#<?=$MessageID?></a>
  91. <strong>
  92. <?=$UserString?>
  93. </strong>
  94. <?=time_diff($SentDate, 2, true)?>
  95. <?php if ($Status != 'Resolved') { ?>
  96. - <a href="#quickpost"
  97. onclick="Quote('<?=$MessageID?>', '<?=$Username?>');"
  98. class="brackets">Quote</a>
  99. <?php } ?>
  100. </div>
  101. <div class="body"><?=Text::full_format($Message)?>
  102. </div>
  103. </div>
  104. <div align="center" style="display: none;"></div>
  105. <?php
  106. $DB->set_query_id($StaffPMs);
  107. }
  108. // Common responses
  109. if ($IsFLS && $Status != 'Resolved') {
  110. ?>
  111. <div id="common_answers" class="hidden">
  112. <div class="box vertical_space">
  113. <div class="head">
  114. <strong>Preview</strong>
  115. </div>
  116. <div id="common_answers_body" class="body">Select an answer from the drop-down to view it.</div>
  117. </div>
  118. <br />
  119. <div class="center">
  120. <select id="common_answers_select" onchange="UpdateMessage();">
  121. <option id="first_common_response">Select a message</option>
  122. <?php
  123. // List common responses
  124. $DB->query("
  125. SELECT ID, Name
  126. FROM staff_pm_responses");
  127. while (list($ID, $Name) = $DB->next_record()) {
  128. ?>
  129. <option value="<?=$ID?>"><?=$Name?>
  130. </option>
  131. <?php
  132. } ?>
  133. </select>
  134. <input type="button" value="Set message" onclick="SetMessage();" />
  135. <input type="button" value="Create new / Edit"
  136. onclick="location.href='staffpm.php?action=responses&amp;convid=<?=$ConvID?>';" />
  137. </div>
  138. </div>
  139. <?php
  140. }
  141. // Ajax assign response div
  142. if ($IsStaff) {
  143. ?>
  144. <div id="ajax_message" class="hidden center alertbar"></div>
  145. <?php
  146. }
  147. // Reply box and buttons?>
  148. <h3>Reply</h3>
  149. <div class="box pad" id="reply_box">
  150. <div id="buttons" class="center">
  151. <form class="manage_form" name="staff_messages" action="staffpm.php" method="post" id="messageform">
  152. <input type="hidden" name="action" value="takepost" />
  153. <input type="hidden" name="convid" value="<?=$ConvID?>"
  154. id="convid" />
  155. <?php
  156. if ($Status != 'Resolved') {
  157. $TextPrev = new TEXTAREA_PREVIEW(
  158. $Name = 'message',
  159. $ID = 'quickpost',
  160. $Value = '',
  161. );
  162. } ?>
  163. <br />
  164. <?php
  165. // Assign to
  166. if ($IsStaff) {
  167. // Staff assign dropdown
  168. ?>
  169. <select id="assign_to" name="assign">
  170. <optgroup label="User classes">
  171. <?php // FLS "class"
  172. $Selected = ((!$AssignedToUser && $PMLevel == 0) ? ' selected="selected"' : ''); ?>
  173. <option value="class_0" <?=$Selected?>>First Line
  174. Support</option>
  175. <?php // Staff classes
  176. foreach ($ClassLevels as $Class) {
  177. // Create one <option> for each staff user class
  178. if ($Class['Level'] >= 650) {
  179. $Selected = ((!$AssignedToUser && ($PMLevel == $Class['Level'])) ? ' selected="selected"' : ''); ?>
  180. <option
  181. value="class_<?=$Class['Level']?>"
  182. <?=$Selected?>><?=$Class['Name']?>
  183. </option>
  184. <?php
  185. }
  186. } ?>
  187. </optgroup>
  188. <optgroup label="Staff">
  189. <?php // Staff members
  190. $DB->query(
  191. "
  192. SELECT
  193. m.ID,
  194. m.Username
  195. FROM permissions AS p
  196. JOIN users_main AS m ON m.PermissionID = p.ID
  197. WHERE p.DisplayStaff = '1'
  198. ORDER BY p.Level DESC, m.Username ASC"
  199. );
  200. while (list($ID, $Name) = $DB->next_record()) {
  201. // Create one <option> for each staff member
  202. $Selected = (($AssignedToUser == $ID) ? ' selected="selected"' : ''); ?>
  203. <option value="user_<?=$ID?>" <?=$Selected?>><?=$Name?>
  204. </option>
  205. <?php
  206. } ?>
  207. </optgroup>
  208. <optgroup label="First Line Support">
  209. <?php
  210. // FLS users
  211. $DB->query("
  212. SELECT
  213. m.ID,
  214. m.Username
  215. FROM users_info AS i
  216. JOIN users_main AS m ON m.ID = i.UserID
  217. JOIN permissions AS p ON p.ID = m.PermissionID
  218. WHERE p.DisplayStaff != '1'
  219. AND i.SupportFor != ''
  220. ORDER BY m.Username ASC
  221. ");
  222. while (list($ID, $Name) = $DB->next_record()) {
  223. // Create one <option> for each FLS user
  224. $Selected = (($AssignedToUser == $ID) ? ' selected="selected"' : ''); ?>
  225. <option value="user_<?=$ID?>" <?=$Selected?>><?=$Name?>
  226. </option>
  227. <?php
  228. } ?>
  229. </optgroup>
  230. </select>
  231. <input type="button" onclick="Assign();" value="Assign" />
  232. <?php
  233. } elseif ($IsFLS) { // FLS assign button?>
  234. <input type="button" value="Assign to staff"
  235. onclick="location.href='staffpm.php?action=assign&amp;to=staff&amp;convid=<?=$ConvID?>';" />
  236. <input type="button" value="Assign to forum staff"
  237. onclick="location.href='staffpm.php?action=assign&amp;to=forum&amp;convid=<?=$ConvID?>';" />
  238. <?php
  239. }
  240. if ($Status != 'Resolved') { ?>
  241. <input type="button" value="Resolve"
  242. onclick="location.href='staffpm.php?action=resolve&amp;id=<?=$ConvID?>';" />
  243. <?php if ($IsFLS) { //Moved by request?>
  244. <input type="button" value="Common answers" data-toggle-target="#common_answers" />
  245. <?php } ?>
  246. <input type="button" id="previewbtn" value="Preview"
  247. class="hidden button_preview_<?=$TextPrev->getID()?>" />
  248. <input type="submit" value="Send message" />
  249. <?php } else { ?>
  250. <input type="button" value="Unresolve"
  251. onclick="location.href='staffpm.php?action=unresolve&amp;id=<?=$ConvID?>';" />
  252. <?php
  253. }
  254. if (check_perms('users_give_donor')) { ?>
  255. <br />
  256. <input type="button" value="Make Donor" data-toggle-target="#make_donor_form" />
  257. <?php } ?>
  258. </form>
  259. <?php if (check_perms('users_give_donor')) { ?>
  260. <div id="make_donor_form" class="hidden">
  261. <form action="staffpm.php" method="post">
  262. <input type="hidden" name="action" value="make_donor" />
  263. <input type="hidden" name="auth"
  264. value="<?=$LoggedUser['AuthKey']?>" />
  265. <input type="hidden" name="id" value="<?=$ConvID?>" />
  266. <strong>Amount: </strong>
  267. <input type="text" name="donation_amount" onkeypress="return isNumberKey(event);" />
  268. <br />
  269. <strong>Reason: </strong>
  270. <input type="text" name="donation_reason" />
  271. <br />
  272. <select name="donation_source">
  273. <option value="Flattr">Flattr</option>
  274. </select>
  275. <select name="donation_currency">
  276. <option value="EUR">EUR</option>
  277. </select>
  278. <input type="submit" value="Submit" />
  279. </form>
  280. </div>
  281. <?php } ?>
  282. </div>
  283. </div>
  284. </div>
  285. </div>
  286. <?php
  287. View::show_footer();
  288. } else {
  289. // No ID
  290. header('Location: staffpm.php');
  291. }