PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/includes/report_module.php

http://torrentpier2.googlecode.com/
PHP | 191 lines | 143 code | 27 blank | 21 comment | 27 complexity | b46639ac528f0c158b0f301092324621 MD5 | raw file
  1. <?php
  2. if (!defined('BB_ROOT')) die(basename(__FILE__));
  3. class report_module
  4. {
  5. var $subjects_auth = array();
  6. //
  7. // Returns module info for the ACP
  8. //
  9. function info()
  10. {
  11. return array(
  12. 'title' => $this->lang['MODULE_TITLE'],
  13. 'explain' => $this->lang['MODULE_EXPLAIN']);
  14. }
  15. //
  16. // Generates a return link based on the subject_url() method
  17. //
  18. function return_link($id)
  19. {
  20. global $lang;
  21. if (method_exists($this, 'subject_url') && isset($this->lang['CLICK_RETURN']))
  22. {
  23. return '<br /><br />' . sprintf($this->lang['CLICK_RETURN'], '<a href="' . $this->subject_url($id) . '">', '</a>');
  24. }
  25. else
  26. {
  27. return '';
  28. }
  29. }
  30. //
  31. // Returns report reasons of the module
  32. //
  33. function reasons_obtain()
  34. {
  35. global $lang;
  36. $sql = 'SELECT report_reason_id, report_reason_desc
  37. FROM ' . BB_REPORTS_REASONS . '
  38. WHERE report_module_id = ' . (int) $this->id . '
  39. ORDER BY report_reason_order';
  40. if (!$result = DB()->sql_query($sql))
  41. {
  42. message_die(GENERAL_ERROR, 'Could not obtain report reasons', '', __LINE__, __FILE__, $sql);
  43. }
  44. $rows = array();
  45. while ($row = DB()->sql_fetchrow($result))
  46. {
  47. $rows[$row['report_reason_id']] = (isset($lang[$row['report_reason_desc']])) ? $lang[$row['report_reason_desc']] : $row['report_reason_desc'];
  48. }
  49. DB()->sql_freeresult($result);
  50. return (!empty($rows)) ? $rows : false;
  51. }
  52. //
  53. // Checks module authorisation
  54. //
  55. function auth_check($auth_names, $userdata = null)
  56. {
  57. if (!isset($userdata))
  58. {
  59. global $userdata;
  60. }
  61. if ($userdata['user_id'] == GUEST_UID)
  62. {
  63. return false;
  64. }
  65. //
  66. // Set "virtual" column
  67. //
  68. if (!isset($this->data['auth_delete_view']))
  69. {
  70. if ($this->data['auth_delete'] == REPORT_AUTH_CONFIRM)
  71. {
  72. $this->data['auth_delete_view'] = REPORT_AUTH_MOD;
  73. }
  74. else
  75. {
  76. $this->data['auth_delete_view'] = $this->data['auth_delete'];
  77. }
  78. }
  79. switch ($userdata['user_level'])
  80. {
  81. case ADMIN:
  82. return true;
  83. break;
  84. case MOD:
  85. $auth_value = REPORT_AUTH_MOD;
  86. break;
  87. case GROUP_MEMBER:
  88. case USER:
  89. $auth_value = REPORT_AUTH_USER;
  90. break;
  91. default:
  92. return false;
  93. break;
  94. }
  95. if (!is_array($auth_names))
  96. {
  97. $auth_names = array($auth_names);
  98. }
  99. //
  100. // Check authorisation
  101. //
  102. foreach ($auth_names as $auth_name)
  103. {
  104. if ($this->data[$auth_name] > $auth_value)
  105. {
  106. return false;
  107. }
  108. }
  109. return true;
  110. }
  111. //
  112. // Checks the authorisation to view the specified report subjects
  113. //
  114. function subjects_auth_check(&$report_subjects, $userdata = null)
  115. {
  116. if (!method_exists($this, 'subjects_auth_obtain') || empty($report_subjects))
  117. {
  118. return true;
  119. }
  120. if (!isset($userdata))
  121. {
  122. global $userdata;
  123. }
  124. if ($userdata['user_level'] == ADMIN)
  125. {
  126. return true;
  127. }
  128. else if ($userdata['user_level'] != MOD)
  129. {
  130. return false;
  131. }
  132. report_prepare_subjects($report_subjects);
  133. $user_id = $userdata['user_id'];
  134. if (!isset($this->subject_auth[$user_id]))
  135. {
  136. $this->subject_auth[$user_id] = array();
  137. $this->subjects_auth_obtain($user_id, $report_subjects);
  138. }
  139. else
  140. {
  141. $check_ids = array();
  142. foreach ($report_subjects as $report_id => $report_subject)
  143. {
  144. if (!isset($this->subjects_auth[$user_id][$report_subject[0]]))
  145. {
  146. $check_ids[] = $report_subjects[$report_id];
  147. }
  148. }
  149. if (!empty($check_ids))
  150. {
  151. $this->subjects_auth_obtain($user_id, $check_ids);
  152. }
  153. }
  154. $subjects_count = count($report_subjects);
  155. foreach ($report_subjects as $report_id => $report_subject)
  156. {
  157. if (!$this->subjects_auth[$user_id][$report_subject[0]])
  158. {
  159. unset($report_subjects[$report_id]);
  160. }
  161. }
  162. return ($subjects_count == count($report_subjects));
  163. }
  164. }