PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/b0.1/php_web/report_old/Core.php

https://github.com/tsnoad/Irondata
PHP | 291 lines | 184 code | 19 blank | 88 comment | 37 complexity | bc88940700a16af75f9c4afee4d36c76 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Core.php
  4. *
  5. * Contains the Core object.
  6. *
  7. * @author Andrew White
  8. * @package Core
  9. * @version 1.2
  10. * @date 28-07-2006
  11. */
  12. /**
  13. * The Core object is the heart of the report generator. It calls other modules and generates
  14. * response HTML and XML to send to the user.
  15. *
  16. * @author Andrew White
  17. * @package Core
  18. * @version 1.2
  19. * @date 28-07-2006
  20. */
  21. class Core extends Common_Functions {
  22. /**
  23. * This will load the approprate saveReport function for each report type.
  24. *
  25. * @return string The passed through HTML.
  26. */
  27. function saveReports() {
  28. $module = $this->loadModule($_GET['report_type']);
  29. if($module->saveReport($_GET['saved_report'], $_GET['suffix'], $_SESSION['reports'][$_GET['saved_report']]['report_name']) == true) {
  30. $main .= $module->displayReport($_GET['saved_report']);
  31. }
  32. return $main;
  33. }
  34. /**
  35. * This will load the approprate displayReport function for each report type.
  36. *
  37. * @return string The passed through HTML.
  38. */
  39. function displayReports() {
  40. $module = $this->loadModule($_GET['report_type']);
  41. $main = $module->displayReport($_GET['saved_report'], $_GET['id']);
  42. return $main;
  43. }
  44. /**
  45. * This will load the approprate deleteReport function for each report type.
  46. *
  47. * @return string The passed through HTML.
  48. */
  49. function deleteReports() {
  50. $module = $this->loadModule($_GET['report_type']);
  51. $main = $module->deleteReport($_GET['saved_report'], $_GET['id']);
  52. return $main;
  53. }
  54. /**
  55. * This will load the approprate makeRule function for each report type. If the report was valid
  56. * it will return true otherwise false. If it is false it will print an error message to the screen.
  57. *
  58. * @return string An error message (if any)
  59. */
  60. function saveRules() {
  61. global $conf;
  62. $module = $this->loadModule($_GET['report_type']);
  63. $rules = $module->makeRules($_POST);
  64. if ($rules == false) {
  65. $main = "That report template was invalid. Possible reasons include; <br/><ul><li>An SQL query that starts with something other than \"select\"</li></ul><br/>";
  66. } else {
  67. $report = addRule($_REQUEST['saved_report'], $rules, $_REQUEST['report_type'], $_REQUEST['publish_report']);
  68. if(!$report) {
  69. $main = "The report was not added. The report name is probably already taken.";
  70. } else {
  71. $_GET['saved_report'] = $report;
  72. }
  73. }
  74. return $main;
  75. }
  76. /**
  77. * This will load the approprate showRules function for each report type.
  78. *
  79. * @return string The passed through HTML.
  80. */
  81. function editRules($rules=NULL) {
  82. $module = $this->loadModule($_GET['report_type']);
  83. $main = $module->showRules($rules);
  84. return $main;
  85. }
  86. /**
  87. * Runs the report, and presents the output to the user.
  88. *
  89. * @return string HTML output from the report generator.
  90. */
  91. function displaySavedReport() {
  92. $rules = getRules($_GET['saved_report']);
  93. if ($_GET['run']=='true') {
  94. if ($this->authCheck('functions', 'Run Report Templates', 'access') || $this->authCheck('reports', $_GET['saved_report'], 'owner')) {
  95. $module = $this->loadModule($_GET['report_type']);
  96. $main = $module->runReport($rules);
  97. } else {
  98. return $this->denied();
  99. }
  100. } else {
  101. $module = $this->loadModule($_GET['report_type']);
  102. $main = $module->displayReport($_SESSION['current_report']);
  103. }
  104. return $main;
  105. }
  106. /**
  107. * This iterates through all the available options from the reports (index.php)
  108. * page. If an option is not in this this or the user doesn't have permission to
  109. * perform the action they will be directed to a permission denied screen.
  110. *
  111. * @global string $maintitle
  112. * @global string $mainicons
  113. * @global string $mainiconURL
  114. * @return string The HTML to be displayed to the user.
  115. */
  116. function main() {
  117. global $maintitle;
  118. global $mainicons;
  119. global $mainiconURL;
  120. $main = "";
  121. if (!$_GET) {
  122. include("help.php");
  123. $main = $help;
  124. $maintitle = "Welcome ".$_SESSION['displayname']."";
  125. $mainicons = false;
  126. } else {
  127. if ($_REQUEST['show_unpub']) {
  128. $_SESSION['unpublished'] = true;
  129. include("help.php");
  130. $main = $help;
  131. $maintitle = "Welcome ".$_SESSION['displayname']."";
  132. $mainicons = false;
  133. return $main;
  134. }
  135. if ($_REQUEST['hide_unpub']) {
  136. $_SESSION['unpublished'] = false;
  137. include("help.php");
  138. $main = $help;
  139. $maintitle = "Welcome ".$_SESSION['displayname']."";
  140. $mainicons = false;
  141. return $main;
  142. }
  143. if ($_REQUEST['show_map']) {
  144. foreach ($_SESSION['dbs'] as $i => $db) {
  145. #check if they have permission to see any of the tables in this database
  146. if ($_SESSION['curDB'] == $db['db_id']) {
  147. $main = '<img src="maps/'.$db['psql_name'].'.png" />';
  148. $maintitle = $db['db_name'];
  149. }
  150. }
  151. /*ob_start();echo "<pre>\n";print_r($_SESSION['dbs']);echo "\n</pre>\n";$main = ob_get_contents();ob_end_clean();
  152. $maintitle = "i 4m a 1337 h4Xx0rz!!1";*/
  153. $mainicons = false;
  154. return $main;
  155. }
  156. $report_name = $_SESSION['report'][$query]['report_name'];
  157. /* There is a possiblity of a URL hack attack, ie guess at report_id.
  158. * This will be fixed later
  159. */
  160. switch($_REQUEST['command']) {
  161. case 'changedb':
  162. // Change the current source database
  163. $maintitle = "New Current Database";
  164. $mainicons = false;
  165. $main = makeChange();
  166. break;
  167. case 'save_template':
  168. // Save a trend line currently being edited
  169. if($this->authCheck('functions','Create Report Templates','access') || $this->authCheck('reports', $_GET['saved_report'], 'owner')) {
  170. $mainicons = true;
  171. $maintitle = 'Report: ' . $_POST['save_as'];
  172. $saverules = $this->saveRules();
  173. $main .= $saverules;
  174. if($saverules=='') {
  175. $main .= "<h3>Template saved successfully.</h3>";
  176. }
  177. $mainiconURL = "index.php?report_type=".$_GET['report_type']."&saved_report=".$_GET['saved_report'];
  178. } else {
  179. $maintitle = "Permission Denied";
  180. $main = $this->denied();
  181. }
  182. break;
  183. case 'save_report':
  184. // Save the results of a database query, ie. the output
  185. if($this->authCheck('functions','Run Report Templates','access') || $this->authCheck('reports', $_GET['saved_report'], 'owner')) {
  186. $mainicons = true;
  187. $maintitle = 'Report: ' . $report_name;
  188. $mainiconURL = "index.php?report_type=".$_GET['report_type']."&saved_report=".$_GET['saved_report'];
  189. $main .= $this->saveReports();
  190. $main .= "<h3>Report saved successfully.</h3>";
  191. } else {
  192. $maintitle = "Permission Denied";
  193. $main = $this->denied();
  194. }
  195. break;
  196. case 'view_report':
  197. // View a saved query; exposes the menu to edit the query, run it,
  198. // and displays saved query results
  199. $maintitle = 'Report: ' . $_SESSION['reports'][$_GET['saved_report']]['report_name'];
  200. $mainicons = true;
  201. $mainiconURL = "index.php?report_type=".$_GET['report_type']."&saved_report=".$_GET['saved_report'];
  202. $main .= $this->displayReports();
  203. break;
  204. case 'delete_template':
  205. // Delete the currently viewed report template
  206. if($this->authCheck('functions', 'Delete Report Templates', 'access') || $this->authCheck('reports', $_GET['saved_report'], 'owner')) {
  207. $mainicons = false;
  208. $main .= deleteRule($_GET['saved_report']);
  209. $main .= "<h3>Template deleted.</h3>";
  210. } else {
  211. $maintitle = "Permission Denied";
  212. $main = $this->denied();
  213. }
  214. break;
  215. /*
  216. case 'delete_report':
  217. // Delete the currently viewed report template
  218. if($this->authCheck('functions', 'Delete Report Output', 'access')) {
  219. $main .= "<h3>Report deleted.</h3>";
  220. $mainicons = true;
  221. $mainiconURL = "index.php?report_type=".$_GET['report_type']."&saved_report=".$_GET['saved_report'];
  222. $main .= $this->deleteReports();
  223. } else {
  224. $maintitle = "Permission Denied";
  225. $main = $this->denied();
  226. }
  227. break;
  228. */
  229. case 'new':
  230. // Create a new query
  231. $_GET['saved_report'] = null;
  232. if($this->authCheck('functions', 'Create Report Templates', 'access')) {
  233. $mainicons = false;
  234. $maintitle = "Report: Generator";
  235. $main .= $this->editRules();
  236. } else {
  237. $maintitle = "Permission Denied";
  238. $main = $this->denied();
  239. }
  240. break;
  241. case 'edit_template':
  242. //TODO
  243. if($this->authCheck('functions', 'Edit Report Templates', 'access') || $this->authCheck('reports', $_GET['saved_report'], 'owner')) {
  244. $mainicons = true;
  245. $maintitle = "Report: ".$_SESSION['reports'][$_GET['saved_report']]['report_name']."";
  246. $mainiconURL = "index.php?report_type=".$_GET['report_type']."&saved_report=".$_GET['saved_report'];
  247. $rules = getRules($_GET['saved_report']);
  248. $main .= $this->editRules($rules);
  249. } else {
  250. $maintitle = "Permission Denied";
  251. $main = $this->denied();
  252. }
  253. break;
  254. case 'run_report':
  255. if($this->authCheck('functions', 'Run Report Templates', 'access') || $this->authCheck('reports', $_GET['saved_report'], 'owner')) {
  256. $maintitle = "Report: ".$_SESSION['reports'][$_GET['saved_report']]['report_name']."";
  257. $mainicons = true;
  258. $mainiconURL = "index.php?report_type=".$_GET['report_type']."&saved_report=".$_GET['saved_report'];
  259. $_GET['run'] = 'true';
  260. $main .= $this->displaySavedReport();
  261. } else {
  262. $maintitle = "Permission Denied";
  263. $main = $this->denied();
  264. }
  265. break;
  266. }
  267. }
  268. $menutitle = "Reports:";
  269. return $main;
  270. }
  271. }
  272. ?>