PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/usr/local/www/newadmin/index.php

https://github.com/gcummins/searchsite_backend
PHP | 380 lines | 303 code | 37 blank | 40 comment | 43 complexity | f7e6b0359751556fef1da69f670506cc MD5 | raw file
  1. <?php
  2. define('APP_NAME', 'DH Admin');
  3. session_start();
  4. // Include the configuration settings
  5. include_once "configuration.php";
  6. include_once "newconfig.php";
  7. include_once "includes/db.class.php";
  8. // Include generic, multipurpose functions
  9. include_once "includes/functions.php";
  10. // Include the functions to verify that the user is authenticated
  11. include_once "includes/authuser.php";
  12. // Include the logging functions
  13. include_once "includes/log.php";
  14. // Connect to the database server
  15. include_once "includes/connect.php";
  16. // Include the error_handling functions
  17. include_once "includes/errorHandler.php";
  18. // Include the module error handling functions
  19. include_once "modules/includes/error_handler.php";
  20. // Include the permission-checking functions
  21. include_once "includes/permissions.php";
  22. // Connect to the databases
  23. $dealhuntingDatabase = new DatabaseConnection(DEALHUNTING_DB_HOST, DEALHUNTING_DB_USERNAME, DEALHUNTING_DB_PASSWORD, DEALHUNTING_DB_NAME);
  24. $adminDatabase = new DatabaseConnection(ADMINPANEL_DB_SERVER, ADMINPANEL_DB_USERNAME, ADMINPANEL_DB_PASSWORD, ADMINPANEL_DB_NAME);
  25. $feedDatabase = new DatabaseConnection(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME);
  26. // Determine if a specific module has been requested
  27. $module = false;
  28. $page = false;
  29. if (isset($_REQUEST['module']) && !empty($_REQUEST['module']))
  30. {
  31. $module = (int)$_REQUEST['module'];
  32. // Determine if the user is allowed to access this module
  33. if (isPermitted('view', $module))
  34. {
  35. // Get the name of the requested module
  36. $query = "SELECT `name` FROM modules WHERE id=$module LIMIT 1;";
  37. $result = mysql_query($query, $adminLink) or returnError(902, $query, 'true', $adminLink);
  38. $row = mysql_fetch_object($result);
  39. if (!mysql_num_rows($result))
  40. {
  41. returnError(777, "The requested module does not exist, or the 'modules' table in the database contains inaccurate information for module $module. Please contact an administrator.", false);
  42. returnToMainPage();
  43. }
  44. $moduleName = $row->name;
  45. // Determine if a CSS file exists and is readable for this module.
  46. $cssfilename = ADMINPANEL_APP_PATH . '/' . ADMINPANEL_MODULE_DIRECTORY . '/' . $moduleName . '/css/style.css';
  47. $cssfilename_ie6 = ADMINPANEL_APP_PATH . '/' . ADMINPANEL_MODULE_DIRECTORY . '/' . $moduleName . '/css/style_ie6.css';
  48. $cssIncludeString = '';
  49. if (is_readable($cssfilename))
  50. {
  51. $cssIncludeString = "<link rel=\"stylesheet\" href=\"" . ADMINPANEL_WEB_PATH . '/' . ADMINPANEL_MODULE_DIRECTORY . '/' . $moduleName . '/css/style.css' . "\" type=\"text/css\" />";
  52. }
  53. if (is_readable($cssfilename_ie6))
  54. {
  55. $cssIncludeString .= "\n<!--[if lt IE 7]>"
  56. . "\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"" . ADMINPANEL_WEB_PATH . '/' . ADMINPANEL_MODULE_DIRECTORY . '/' . $moduleName . "/css/style_ie6.css\" />"
  57. . "\n<![endif]-->";
  58. }
  59. // Determine if a Javascript file exists and is readable for this module.
  60. $jsfilename = ADMINPANEL_APP_PATH . '/' . ADMINPANEL_MODULE_DIRECTORY . '/' . $moduleName . '/js/script.js';
  61. if (is_readable($jsfilename))
  62. {
  63. $jsIncludeString = "<script type=\"text/javascript\" src=\"" . ADMINPANEL_WEB_PATH . '/' . ADMINPANEL_MODULE_DIRECTORY . '/' . $moduleName . '/js/script.js' . "\"></script>";
  64. }
  65. }
  66. else
  67. {
  68. // The user is not allowed to access this module. Set the $module
  69. // variable to null so that the default page will be displayed
  70. $module = null;
  71. }
  72. }
  73. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  74. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  75. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  76. <head>
  77. <title>DealHunting Administration</title>
  78. <?php
  79. // Load an alternate theme, if available
  80. if (is_file(ADMINPANEL_APP_PATH . '/css/' . ADMINPANEL_THEME . '.css'))
  81. {
  82. ?> <link rel="stylesheet" type="text/css" href="<?php echo ADMINPANEL_WEB_PATH; ?>/css/<?php echo ADMINPANEL_THEME; ?>.css" />
  83. <?php
  84. if (is_file(ADMINPANEL_APP_PATH . '/css/' . ADMINPANEL_THEME . '_ie6.css'))
  85. {
  86. // Load an IE6-specific stylesheet for this theme
  87. ?>
  88. <!--[if lt IE 7]>
  89. <link rel="stylesheet" type="text/css" href="<?php echo ADMINPANEL_WEB_PATH; ?>/css/<?php echo ADMINPANEL_THEME; ?>_ie6.css" />
  90. <![endif]-->
  91. <!--[if IE]>
  92. <link rel="stylesheet" type="text/css" href="<?php echo ADMINPANEL_WEB_PATH; ?>/css/<?php echo ADMINPANEL_THEME; ?>_ie.css" />
  93. <![endif]-->
  94. <?php
  95. }
  96. }
  97. else
  98. {
  99. // Load the default theme
  100. ?> <link rel="stylesheet" type="text/css" href="<?php echo ADMINPANEL_WEB_PATH; ?>/css/index.css" />
  101. <?php
  102. if (is_file(ADMINPANEL_APP_PATH . '/css/index_ie6.css'))
  103. {
  104. // Load an IE6-specific stylesheet
  105. ?>
  106. <!--[if lt IE 7]>
  107. <link rel="stylesheet" type="text/css" href="<?php echo ADMINPANEL_WEB_PATH; ?>/css/index_ie6.css" />
  108. <![endif]-->
  109. <!--[if IE]>
  110. <link rel="stylesheet" type="text/css" href="<?php echo ADMINPANEL_WEB_PATH; ?>/css/index_ie.css" />
  111. <![endif]--><?php
  112. }
  113. }
  114. ?>
  115. <link rel="stylesheet" type="text/css" href="<?php echo ADMINPANEL_WEB_PATH; ?>/css/jquery-ui-themeroller.css" />
  116. <?php
  117. if (isset($cssIncludeString))
  118. {
  119. echo "$cssIncludeString\n";
  120. }
  121. ?>
  122. <script type="text/javascript" src="<?php echo ADMINPANEL_WEB_PATH; ?>/js/jquery.min.js"></script>
  123. <script type="text/javascript" src="<?php echo ADMINPANEL_WEB_PATH; ?>/js/jquery-ui-personalized-1.5.2.min.js"></script>
  124. <script type="text/javascript" src="<?php echo ADMINPANEL_WEB_PATH; ?>/js/XMLHttpRequest.js"></script>
  125. <script type="text/javascript" src="<?php echo ADMINPANEL_WEB_PATH; ?>/js/index.js"></script>
  126. <?php
  127. if (isset($jsIncludeString))
  128. {
  129. echo "$jsIncludeString\n";
  130. }
  131. ?>
  132. <script type="text/javascript">
  133. window.onload = rewriteExternalLinks;
  134. <?php
  135. /* Menu Switching Code */
  136. if (ADMINPANEL_MENU_TYPE == 'outlook')
  137. {
  138. ?>
  139. var arrMenuHeadings = Array();
  140. var currentMenuIndex = false;
  141. <?php
  142. // Load a list of available menus
  143. $query = "SELECT id, name, display_name FROM " . DB_NAME . ".menu_sections ORDER BY `order` ASC;";
  144. if (false === ($result = mysql_query($query, $adminLink)))
  145. {
  146. //logError('Loading Menu Sections', '', $adminLink, true, mysql_error($adminLink));
  147. returnError(902, $query, true, $adminLink);
  148. }
  149. $counter = 0;
  150. while($row = mysql_fetch_object($result))
  151. {
  152. ?>arrMenuHeadings[<?php echo $counter; ?>] = new objMenuHeadings(<?php echo $row->id; ?>, '<?php echo $row->name; ?>', '<?php echo $row->display_name; ?>');
  153. <?php
  154. $counter++;
  155. }
  156. }
  157. /* End Menu Switching Code */
  158. ?>
  159. </script>
  160. </head>
  161. <body >
  162. <table class="bodytable">
  163. <tr id="bluebar_tr">
  164. <td colspan="2">
  165. <div id="bluebar" style="background: url('<?php echo ADMINPANEL_WEB_PATH; ?>/images/bar.gif') repeat-x top left;">
  166. <a href="logout.php"><img id="bluebar_close" src="<?php echo ADMINPANEL_WEB_PATH; ?>/images/close.gif" alt="Close Window"/></a>
  167. <img id="bluebar_question" src="<?php echo ADMINPANEL_WEB_PATH; ?>/images/question.gif" alt="Access Help" />
  168. <img id="bluebar_icon" src="<?php echo ADMINPANEL_WEB_PATH; ?>/images/icon.gif" alt="DealHunting Icon"/>
  169. <span id="bluebar_title">Adlistings Control Panel</span>
  170. </div>
  171. </td>
  172. </tr>
  173. <tr>
  174. <td id="td_leftbar_container" valign="top" style="height: <?php echo ($_SESSION['page_height'] - 33); ?>px"><?php
  175. /* Menu Switching Code, part two */
  176. if (ADMINPANEL_MENU_TYPE == 'outlook')
  177. {
  178. ?>
  179. <table id="leftbar">
  180. <!-- The following lines are simply to make this valid XHTML. A table must include at least one set of TR and TD tags -->
  181. <tr>
  182. <td></td>
  183. </tr>
  184. </table><?php
  185. }
  186. else
  187. {
  188. ?>
  189. <div id="leftbar">&nbsp;</div><?php
  190. }
  191. /* End Menu Switching Code, part two */
  192. ?>
  193. </td>
  194. <td id="pagecontent" valign="top">
  195. <div id="errorPane">
  196. <p id="errorPaneText"></p>
  197. <span id="errorRightCorner">&nbsp;</span>
  198. <span id="errorLeftCorner">&nbsp;</span>
  199. </div><?php
  200. // Determine which page should be loaded.
  201. // We will first look up the module number provided, and load the
  202. // default page for that module.
  203. $pageFound = false;
  204. if ($module)
  205. {
  206. // Get the module name and the default page
  207. $query = "SELECT name, display_name FROM modules WHERE id=$module LIMIT 1;";
  208. $result = mysql_query($query, $adminLink) or handle_error("Query failed: $query. MySQL said: <em>" . mysql_error($adminLink) . "</em>");
  209. if (mysql_num_rows($result))
  210. {
  211. // A module name was found
  212. $moduleRow = mysql_fetch_object($result);
  213. $moduleName = $moduleRow->name;
  214. $moduleDisplayName = $moduleRow->display_name;
  215. // Now attempt to get the default page for this module
  216. $query = "SELECT script_name, title FROM modules_pages WHERE module_id=$module AND `default`=1 LIMIT 1;";
  217. $result = mysql_query($query, $adminLink) or handle_error("Query failed: $query. MySQL said: <em>" . mysql_error($adminLink) . "</em>");
  218. if (mysql_num_rows($result))
  219. {
  220. $pageRow = mysql_fetch_object($result);
  221. $pageName = $pageRow->script_name;
  222. $pageFound = true;
  223. }
  224. }
  225. }
  226. if ($pageFound)
  227. {
  228. // Include the script that contains this module.
  229. include ADMINPANEL_APP_PATH . '/modules/' . $moduleName . '/' . $pageName;
  230. }
  231. else if (isset($_REQUEST['httpderror']) && (int)$_REQUEST['httpderror'])
  232. {
  233. switch ((int)$_REQUEST['httpderror'])
  234. {
  235. case 404:
  236. echo "The page you requested was not found. Please check the URL and try again, or use one of the links on the left.";
  237. break;
  238. case 403:
  239. echo "This application encountered a Permission Denied error while attempting to process your request.";
  240. break;
  241. case 500:
  242. echo "This application encountered an internal script error while attempting to process your request.";
  243. break;
  244. default:
  245. echo "An unknown HTTP error was specified. Please use one of the links on the left to access this application.";
  246. break;
  247. }
  248. }
  249. else
  250. {
  251. ?>
  252. <div id="logo" style="background: url('<?php echo ADMINPANEL_WEB_PATH; ?>/images/dh.jpg') no-repeat left top;">
  253. <!-- <span id="business_name">Batea</span><br />
  254. <span id="logo_tag"><?php //echo $tagline; ?></span> -->
  255. </div><?php
  256. }
  257. // Start error message display processing
  258. $sysmessage = null;
  259. $sysmtype = 'error';
  260. if (array_key_exists('sysmessage', $_SESSION) && !empty($_SESSION['sysmessage']))
  261. {
  262. $sysmessage = $_SESSION['sysmessage'];
  263. // Clear the message so it is not displayed again
  264. unset($_SESSION['sysmessage']);
  265. if (array_key_exists('sysmtype', $_SESSION) && $_SESSION['sysmtype'] == 'info')
  266. {
  267. $sysmtype = 'information';
  268. // Clear the entry so it is not used again
  269. unset($_SESSION['sysmtype']);
  270. }
  271. }
  272. elseif (array_key_exists('sysmessage', $_REQUEST) && !empty($_REQUEST['sysmessage']))
  273. {
  274. $sysmessage = htmlentities($_REQUEST['sysmessage']);
  275. if (array_key_exists('sysmtype', $_REQUEST) && !empty($_REQUEST['sysmtype']))
  276. {
  277. if ($_REQUEST['sysmtype'] == 'info')
  278. {
  279. $sysmtype = 'information';
  280. }
  281. }
  282. }
  283. // End error message display processing
  284. ?>
  285. <script type="text/javascript">
  286. errorMessage = '<?php echo addslashes($sysmessage); ?>';
  287. errorType = '<?php echo $sysmtype; ?>';
  288. if (errorMessage != '')
  289. {
  290. showError(errorMessage, errorType, '<?php echo ADMINPANEL_WEB_PATH; ?>');
  291. }
  292. </script>
  293. </td>
  294. </tr>
  295. </table>
  296. <script type="text/javascript">
  297. <?php
  298. /* Menu Switching Code, part three */
  299. if (ADMINPANEL_MENU_TYPE == 'outlook')
  300. {
  301. ?>
  302. createMenuBar(null, <?php echo ($module) ? $module : 'null'; ?>, '<?php echo ADMINPANEL_WEB_PATH; ?>', <?php echo $_SESSION['page_height']; ?>);
  303. <?php
  304. }
  305. else
  306. {
  307. // Determine the name of the active menu
  308. if ($module)
  309. {
  310. $query = "SELECT menu_sections.display_name as menuName FROM `modules`LEFT JOIN menu_sections on menu_sections.id=modules.menu_section WHERE modules.id=$module;";
  311. }
  312. else
  313. {
  314. $query = "SELECT display_name as menuName FROM `menu_sections` ORDER BY `order` LIMIT 1;";
  315. }
  316. $result = mysql_query($query, $adminLink) or returnError(902, $query, true, $adminLink);
  317. $row = mysql_fetch_object($result);
  318. $formattedMenuName = str_replace(array(' ', '.', '-'), '', $row->menuName);
  319. ?>
  320. createMenuBar_css('<?php echo ADMINPANEL_WEB_PATH; ?>', <?php echo ($module) ? $module : 0; ?>, '<?php echo $formattedMenuName; ?>');<?php
  321. }
  322. /* End Menu Switching Code */
  323. ?>
  324. </script>
  325. <!-- Fake modal dialog box, populated as needed by the modules. -->
  326. <div id="modalContainer">
  327. <div id="edit_div"></div>
  328. <div class="translucentbackground"></div>
  329. </div>
  330. <div id="modalContainer_banners">
  331. <div id="banner_selection_div"></div>
  332. </div>
  333. <!-- End Fake Modal Dialog Box, displayed as needed by the modules. -->
  334. <!-- "Script Busy" Indicator -->
  335. <div id="scriptBusyContainer">
  336. <div id="scriptBusyInnerDiv">
  337. <span id="scriptBusyOutput"></span><br />
  338. <div id="scriptBusyImageDiv"><img src="images/progress_bar.gif" alt="Loading -- Please Wait" /></div>
  339. </div>
  340. </div>
  341. <!-- End "Script Busy" Indicator -->
  342. </body>
  343. </html>