session_functions.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:39k
源码类别:

电子政务应用

开发平台:

Java

  1. <?php
  2. // +-------------------------------------------------------------+
  3. // | DeskPRO v [2.0.1 Production]
  4. // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
  5. // | Supplied by WTN-WDYL
  6. // | Nullified by WTN-WDYL
  7. // | Distribution via WebForum, ForumRU and associated file dumps
  8. // +-------------------------------------------------------------+
  9. // | DESKPRO IS NOT FREE SOFTWARE
  10. // +-------------------------------------------------------------+
  11. // | License ID : Full Enterprise License =) ...
  12. // | License Owner : WTN-WDYL Team
  13. // +-------------------------------------------------------------+
  14. // | $RCSfile: session_functions.php,v $
  15. // | $Date: 2004/02/10 01:34:25 $
  16. // | $Revision: 1.45 $
  17. // +-------------------------------------------------------------+
  18. // | File Details:
  19. // | - Session handling functions
  20. // +-------------------------------------------------------------+
  21. error_reporting(E_ALL ^ E_NOTICE);
  22. /*****************************************************
  23. function delete_cookies
  24. -----DESCRIPTION: -----------------------------------
  25. - delete all cookies for user/admin/tech zone
  26. *****************************************************/
  27. function delete_cookies() {
  28. if (defined('USERZONE')) {
  29. dp_setcookie("dp_user_sessionid", "", -1);
  30. dp_setcookie("dp_user_userid", "", -1);
  31. dp_setcookie("dp_user_password", "", -1);
  32. } elseif (defined('ADMINZONE')) {
  33. dp_setcookie("dp_admin_sessionid", "", -1);
  34. dp_setcookie("dp_admin_userid", "", -1);
  35. dp_setcookie("dp_admin_password", "", -1);
  36. } elseif (defined('TECHZONE')) {
  37. dp_setcookie("dp_tech_sessionid", "", -1);
  38. dp_setcookie("dp_tech_userid", "", -1);
  39. dp_setcookie("dp_tech_password", "", -1);
  40. }
  41. }
  42. /*****************************************************
  43. function update_cookies
  44. -----DESCRIPTION: -----------------------------------
  45. - deletes the session from the db
  46. - sets an empty cookie
  47. -----ARGUMENTS: -------------------------------------
  48. sessionid : the users sessionid
  49. -----RETURNS:----------------------------------------
  50. returns the full, updated session array
  51. *****************************************************/
  52. function update_cookies($zone = NULL) {
  53. global $_COOKIE;
  54. if (defined('USERZONE')) {
  55. $check = 'dp_admin_remember';
  56. } elseif (defined('ADMINZONE')) {
  57. $check = 'dp_tech_remember';
  58. } elseif (defined('TECHZONE')) {
  59. $check = 'dp_user_remember';
  60. }
  61. if ($_COOKIE[$check]) {
  62. $ever = 'ever';
  63. } else {
  64. $ever = NULL;
  65. }
  66. if ($zone == "admin") {
  67. dp_setcookie('dp_admin_remember', $_COOKIE['dp_admin_remember'], $ever);
  68. dp_setcookie('dp_admin_sessionid', $_COOKIE['dp_admin_sessionid'], $ever);
  69. dp_setcookie('dp_admin_userid', $_COOKIE['dp_admin_userid'], $ever);
  70. dp_setcookie('dp_admin_password', $_COOKIE['dp_admin_password'], $ever);
  71. } elseif ($zone == "tech") {
  72. dp_setcookie('dp_tech_remember', $_COOKIE['dp_tech_remember'], $ever);
  73. dp_setcookie('dp_tech_sessionid', $_COOKIE['dp_tech_sessionid'], $ever);
  74. dp_setcookie('dp_tech_userid', $_COOKIE['dp_tech_userid'], $ever);
  75. dp_setcookie('dp_tech_password', $_COOKIE['dp_tech_password'], $ever);
  76. } else {
  77. dp_setcookie('dp_user_remember', $_COOKIE['dp_user_remember'], $ever);
  78. dp_setcookie('dp_user_sessionid', $_COOKIE['dp_user_sessionid'], $ever);
  79. dp_setcookie('dp_user_userid', $_COOKIE['dp_user_userid'], $ever);
  80. dp_setcookie('dp_user_password', $_COOKIE['dp_user_password'], $ever);
  81. }
  82. }
  83. /*****************************************************
  84. function logout_tech_session
  85. ----- DESCRIPTION: -----------------------------------
  86. - Delete tech session, log session timeout in tech_timelog
  87. ----- ARGUMENTS: -------------------------------------
  88. sessionid: The session ID
  89. techid: The technician's ID
  90. ----- RETURNS:----------------------------------------
  91. - Nothing
  92. *****************************************************/
  93. function logout_tech_session($sessionid, $techid) {
  94. global $db;
  95. $time = mktime() - $settings['session_adjust'];
  96. $db->query("INSERT INTO tech_timelog (techid, activity, stamp) VALUES ('$techid', 'Logged out -- session expired', '$time')");
  97. $db->query("DELETE FROM tech_session WHERE sessionid = '$sessionid'");
  98. delete_cookies();
  99. return;
  100. }
  101. /*****************************************************
  102. function delete_session
  103. -----DESCRIPTION: -----------------------------------
  104. - deletes the session from the db
  105. - deletes cookies
  106. -----ARGUMENTS: -------------------------------------
  107. sessionid : the users sessionid
  108. -----RETURNS:----------------------------------------
  109. returns the full, updated session array
  110. *****************************************************/
  111. function delete_session($sessionid='') {
  112. global $db;
  113. if (!$sessionid) {
  114. global $session;
  115. $sessionid = $session[sessionid];
  116. }
  117. if (defined('USERZONE')) {
  118. $table = 'user_session';
  119. } elseif (defined('ADMINZONE')) {
  120. $table = 'tech_session';
  121. } elseif (defined('TECHZONE')) {
  122. $table = 'tech_session';
  123. }
  124. $db->query("DELETE FROM $table WHERE sessionid = '" . mysql_escape_string($sessionid) . "'");
  125. delete_cookies();
  126. return;
  127. }
  128. /*****************************************************
  129. function update_session
  130. -----DESCRIPTION: -----------------------------------
  131. - updates a specific session variable
  132. -----ARGUMENTS: -------------------------------------
  133. action : the session variable we are updating
  134. value : the new value for the session variable
  135. -----RETURNS:----------------------------------------
  136. returns the full, updated session array
  137. *****************************************************/
  138. function update_session($action, $value) {
  139. global $db, $session;
  140. // in case there is no session
  141. if (!is_array($session)) { 
  142. $session = make_session($value);
  143. }
  144. if (defined('USERZONE')) {
  145. $table = 'user_session';
  146. $type = 'user';
  147. } else {
  148. $table = 'tech_session';
  149. $type = 'tech';
  150. }
  151. if ($action == "user") {
  152. if ($session[userid] != $value) {
  153. $db->query("UPDATE $table SET ".$type."id = '" . mysql_escape_string($value) . "' WHERE sessionid = '$session[sessionid]'");
  154. $session[userid] = $value;
  155. }
  156. }
  157. if ($action == "language") {
  158. if ($session[language] != $value) {
  159. $db->query("UPDATE $table SET language = '" . mysql_escape_string($value) . "' WHERE sessionid = '$session[sessionid]'");
  160. $session[language] = $value;
  161. }
  162. }
  163. $session[user_type] = 'user';
  164. return $session;
  165. }
  166. /*****************************************************
  167. function prune_sessions
  168. ----- DESCRIPTION: -----------------------------------
  169. - Expire old sessions
  170. ----- ARGUMENTS: -------------------------------------
  171. - None
  172. ----- RETURNS:----------------------------------------
  173. - Nothing
  174. *****************************************************/
  175. function prune_sessions () {
  176. // We only actually do this on a one-in-ten chance, because it's pointless
  177. // to trim down the DB on every page load, but it needs to be done fairly
  178. // often.
  179. if (!rand(0,9)) {
  180. global $db, $settings;
  181. if ($settings['cookie_lifespan'] > $settings['session_length']) {
  182. $time = mktime() - $settings['cookie_lifespan'];
  183. } else {
  184. $time = mktime() - $settings['session_length'];
  185. }
  186. // Expire user sessions
  187. $db->query("DELETE FROM user_session WHERE lastactivity <= '$time'");
  188. // Fetch tech sessions
  189. $db->query("SELECT sessionid, techid FROM tech_session WHERE lastactivity <= '$time'");
  190. while ($res = $db->row_array()) {
  191. logout_tech_session($res['sessionid'], $res['techid']);
  192. }
  193. }
  194. }
  195. /*****************************************************
  196. function validate_session
  197. ----- DESCRIPTION: -----------------------------------
  198. - checks if a session is still valid
  199. ----- ARGUMENTS: -------------------------------------
  200. sessionid : the users sessionid
  201. userid (opt) : [optional] userid
  202. ----- RETURNS:----------------------------------------
  203. null if the session is invalud
  204. the full session array if the session is valid
  205. *****************************************************/
  206. function validate_session($sessionid='', $userid='') {
  207. global $db, $settings, $_REQUEST, $_COOKIE, $_POST, $_GET;
  208. // cookies / tables based on where we are
  209. if (defined('USERZONE')) {
  210. $table = 'user';
  211. $session_table = 'user_session';
  212. } elseif (defined('ADMINZONE')) {
  213. $table = 'admin';
  214. $session_table = 'tech_session';
  215. } elseif (defined('TECHZONE')) {
  216. $table = 'tech';
  217. $session_table = 'tech_session';
  218. }
  219. /* SESSION ID SOURCE PREFERENCE:
  220. Session ID is always taken from the first of the sources in this list
  221. (checked in listed order), ignoring others if present.
  222. 1) Sessionid sent in function definition
  223. 2) Posted session value (a POST method, i.e. submitted form)
  224. 3) URL Variable (GET method, as in file.php?s=sessionidstring)
  225. 4) Cookie (client-side cookie data) */
  226. if (!$sessionid) {
  227. if ($_POST['s']) {
  228. $sessionid = $_POST['s'];
  229. } elseif ($_GET['s']) {
  230. $sessionid = $_GET['s'];
  231. } elseif ($_COOKIE['dp_' . $table. '_sessionid']) {
  232. $sessionid = $_COOKIE['dp_' . $table . '_sessionid'];
  233. }
  234. }
  235. // Check we have a session
  236. if (strlen($sessionid) != 32) { 
  237.   return null;
  238. }
  239. // different time lengths for validation because sessions are less secure than cookies
  240. if ($_COOKIE[dp_sessionid] OR $_COOKIE['dp_' . $table . 'userid'] OR $_COOKIE['dp_' . $table . '_password']) {
  241. $time = mktime() - $settings[cookie_lifespan];
  242. } else {
  243. $time = mktime() - $settings[session_length];
  244. }
  245. // validate session
  246. // note we check the HTTP_USER_AGENT as well to provide some extra security with url sessions
  247. $session = $db->query_return("
  248. SELECT * FROM $session_table
  249. WHERE sessionid = '" . mysql_escape_string($sessionid) . "'
  250. AND lastactivity > '$time'
  251. AND useragent = '" . mysql_escape_string($_SERVER['HTTP_USER_AGENT']) . "'
  252. ");
  253. // failed validation
  254. if (!$db->num_rows()) {
  255. return null;
  256. // update last activity and do activity log
  257. if ($location = find_location($session)) {
  258. if (!stristr($_SERVER['PHP_SELF'], '/tech/home/footer')) {
  259. $db->query("
  260. UPDATE $session_table SET 
  261. lastactivity = '" . mktime() . "', 
  262. location = '" . mysql_escape_string($location) . "' 
  263. WHERE sessionid = '$sessionid'
  264. ");
  265. // If a technician/admin update, also log the activity.
  266. if (defined('ADMINZONE') OR defined('TECHZONE')) { 
  267. $db->query("
  268. INSERT INTO tech_timelog 
  269. (techid, activity, stamp) 
  270. VALUES ('$session[techid]', '" . mysql_escape_string($location) . "', '" . time() . "')
  271. ");
  272. }
  273. }
  274. }
  275. if (stristr($_SERVER['PHP_SELF'], 'autoload.php')) {
  276. $db->query("UPDATE $session_table SET lastactivity = '" . mktime() . "' WHERE sessionid = '$sessionid'");
  277. }
  278. return $session;
  279. }
  280. /*****************************************************
  281. function make_session
  282. ----- DESCRIPTION: -----------------------------------
  283. - creates a session, deleting the given user's other
  284.   sessions (if any)
  285. ----- ARGUMENTS: -------------------------------------
  286. userid : the userid
  287. language (opt) : language choice
  288. ----- RETURNS:----------------------------------------
  289. the full session array
  290. *****************************************************/
  291. function make_session($userid='', $language='') {
  292. global $db;
  293. if (defined('USERZONE')) {
  294. $table = 'user_session';
  295. $type = 'user';
  296. } else {
  297. $table = 'tech_session';
  298. $type = 'tech';
  299. }
  300. $time = mktime();
  301. $sessionid = md5(uniqid(rand(),1));
  302. if (defined('TECHZONE')) {
  303. $tech = 1;
  304. } elseif (defined('ADMINZONE')) {
  305. $tech = 0;
  306. }
  307. $db->query("INSERT INTO $table SET
  308. sessionid = '" . mysql_escape_string($sessionid) . "',
  309. lastactivity = '$time',
  310. location = 'Logging in',
  311. useragent = '" . mysql_escape_string($_SERVER['HTTP_USER_AGENT']) . "',
  312. ".$type."id = '" . mysql_escape_string($userid) . "'"
  313. . iff($type == 'tech', ", techzone = '$tech'")
  314. );
  315. // need to delete any other sessions set for this user
  316. if ($userid) {
  317. $db->query("
  318. DELETE FROM $table 
  319. WHERE ".$type."id = '" . mysql_escape_string($userid) . "' 
  320. AND sessionid != '" . mysql_escape_string($sessionid) . "'"
  321. . iff($type == 'tech', "AND techzone = '$tech'")
  322. );
  323. }
  324. $location = find_location($session);
  325. return array(
  326. 'user_type' => $type,
  327. 'sessionid' => $sessionid,
  328. 'language' => $language,
  329. 'lastactivity' => $time,
  330. 'location' => $location,
  331. 'userid' => $userid
  332. );
  333. }
  334. /*****************************************************
  335. function find_location
  336. ----- DESCRIPTION: -----------------------------------
  337. - if tech/admin we find where we are; pass in 
  338.   $session array
  339. ----- RETURNS:----------------------------------------
  340. the location
  341. *****************************************************/
  342. function find_location($session) {
  343. global $db;
  344. if ($session[user_type] == 'tech') {
  345. if (stristr($_SERVER['PHP_SELF'], '/admin/backup.php')) {
  346. $location = "Admin::Backup";
  347. } elseif (stristr($_SERVER['PHP_SELF'], '/admin/ban.php')) {
  348. switch ($_REQUEST['do']) {
  349. case 'update_email':
  350. $location = 'Admin::Bans::Adding/Editing E-mail';
  351. break;
  352. case 'update_ip':
  353. $location = 'Admin::Bans::Adding/Editing IP Address';
  354. break;
  355. case 'email':
  356. $location = 'Admin::Bans::Add E-mail Form';
  357. break;
  358. case 'ip':
  359. $location = 'Admin::Bans::Add/Edit IP Form';
  360. break;
  361. case 'ip':
  362. $location = 'Admin::Bans::Add/Edit IP Form';
  363. break;
  364. }
  365. } elseif (stristr($_SERVER['PHP_SELF'], '/admin/category.php')) {
  366. switch ($_REQUEST['do']) {
  367. case 'settings':
  368. $location = 'Admin::Categories::View Category Settings';
  369. break;
  370. case 'cat_orders':
  371. $location = 'Admin::Categories::Updating Category Ordering';
  372. break;
  373. case 'delete':
  374. $location = 'Admin::Categories::Delete Category Form';
  375. break;
  376. case 'delete2':
  377. $location = 'Admin::Categories::Deleting Category';
  378. break;
  379. case 'add':
  380. $location = 'Admin::Categories::Add Category Form';
  381. break;
  382. case 'edit':
  383. $location = 'Admin::Categories::Edit Category Form';
  384. break;
  385. case 'add2':
  386. $location = 'Admin::Categories::Adding Category';
  387. break;
  388. case 'edit2':
  389. $location = 'Admin::Categories::Editing Category';
  390. break;
  391. case 'edit2':
  392. $location = 'Admin::Categories::Viewing Categories';
  393. break;
  394. }
  395. } elseif (stristr($_SERVER['PHP_SELF'], '/admin/chat.php')) {
  396. switch ($_REQUEST['do']) {
  397. case 'update':
  398. $location = 'Admin::Chat::Update Settings Form';
  399. break;
  400. case 'list':
  401. $location = 'Admin::Chat::Viewing Chat Room Settings';
  402. break;
  403. case 'add':
  404. $location = 'Admin::Chat::Add Chat Room Form';
  405. break;
  406. }
  407. } elseif (stristr($_SERVER['PHP_SELF'], '/admin/cron.php')) {
  408. switch ($_REQUEST['do']) {
  409. case 'list':
  410. case 'view':
  411. $location = 'Admin::Cron::Viewing Scheduled Tasks';
  412. break;
  413. case 'update':
  414. case 'update2':
  415. $location = 'Admin::Cron::Updating Task(s)';
  416. break;
  417. }
  418. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/diagnose.php')) {
  419. switch ($_REQUEST['do']) {
  420. case 'mysql_vars':
  421. $location = 'Admin::Sanity Check::MySQL Vars';
  422. break;
  423. case 'mysql_status':
  424. $location = 'Admin::Sanity Check::MySQL Status';
  425. break;
  426. case 'table_status':
  427. $location = 'Admin::Sanity Check::Table Status';
  428. break;
  429. }
  430. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/email.php')) {
  431. switch ($_REQUEST['do']) {
  432. case 'update':
  433. $location = 'Admin::E-mail Gateway::Updating Settings';
  434. break;
  435. case 'list':
  436. case 'view':
  437. $location = 'Admin::E-mail Gateway::Listing Gateway Accounts';
  438. break;
  439. case 'config':
  440. $location = 'Admin::E-mail Gateway::Viewing Settings';
  441. break;
  442. case 'add2':
  443. $location = 'Admin::E-mail Gateway::Adding Gateway Account';
  444. break;
  445. case 'delete':
  446. $location = 'Admin::E-mail Gateway::Deleting Gateway Account';
  447. break;
  448. case 'add':
  449. case 'edit':
  450. $location = 'Admin::E-mail Gateway::Add/Edit Gateway Account Form';
  451. break;
  452. }
  453. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/emailtemplates.php')) {
  454. switch ($_REQUEST['do']) {
  455. case 'view':
  456. $location = 'Admin::E-mail Gateway::Viewing Templates';
  457. break;
  458. case 'edit2':
  459. $location = 'Admin::E-mail Gateway::Editing Template';
  460. break;
  461. case 'newcustom2':
  462. $location = 'Admin::E-mail Gateway::Adding Custom Template';
  463. break;
  464. case 'editcustom':
  465. $location = 'Admin::E-mail Gateway::Edit Custom Template Form';
  466. break;
  467. case 'newcustom':
  468. $location = 'Admin::E-mail Gateway::New Custom Template Form';
  469. break;
  470. case 'delete':
  471. $location = 'Admin::E-mail Gateway::Deleting Custom Template';
  472. break;
  473. case 'delete_all':
  474. $location = 'Admin::E-mail Gateway::Deleting ALL Custom Templates';
  475. break;
  476. case 'restore':
  477. $location = 'Admin::E-mail Gateway::Restoring Custom Template from Backup';
  478. break;
  479. case 'preg_replace':
  480. $location = 'Admin::E-mail Gateway::Search/Replace Form';
  481. break;
  482. case 'xhtml':
  483. $location = 'Admin::E-mail Gateway::XHTML Redirection';
  484. break;
  485. case 'xhtml2':
  486. $location = 'Admin::E-mail Gateway::XHTML Update';
  487. break;
  488. case 'preg_replace2':
  489. $location = 'Admin::E-mail Gateway::Search/Replace Execution';
  490. break;
  491. case 'find':
  492. $location = 'Admin::E-mail Gateway::Search Form';
  493. break;
  494. case 'find2':
  495. $location = 'Admin::E-mail Gateway::Search Execution';
  496. break;
  497. case 'translate2':
  498. $location = 'Admin::E-mail Gateway::Translation Execution';
  499. break;
  500. case 'translate':
  501. $location = 'Admin::E-mail Gateway::Translation Form';
  502. break;
  503. case 'export':
  504. $location = 'Admin::E-mail Gateway::Exporting Template';
  505. break;
  506. }
  507. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/errors.php')) {
  508. switch ($_REQUEST['do']) {
  509. case '':
  510. $location = 'Admin::E-mail Gateway::Viewing Errors';
  511. break;
  512. case 'source':
  513. $location = 'Admin::E-mail Gateway::Viewing Error Details';
  514. break;
  515. }
  516. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/escalate.php')) {
  517. switch ($_REQUEST['do']) {
  518. case 'delete':
  519. $location = 'Admin::Escalations::Deleting Escalation';
  520. break;
  521. case 'new2':
  522. $location = 'Admin::Escalations::Adding New Escalation';
  523. break;
  524. case 'edit2':
  525. $location = 'Admin::Escalations::Editing Escalation';
  526. break;
  527. case 'new':
  528. case 'edit':
  529. $location = 'Admin::Escalations::Add/Edit Escalation Form';
  530. break;
  531. case 'view':
  532. $location = 'Admin::Escalations::Viewing Escalations';
  533. break;
  534. }
  535. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/filters.php')) {
  536. switch ($_REQUEST['do']) {
  537. default:
  538. $location = 'Admin::Filters::Other';
  539. break;
  540. }
  541. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/help.php')) {
  542. $location = 'Admin::Help::Viewing Help Topic';
  543. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/index.php')) {
  544. $location = 'Admin::Main Page';
  545. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/languages.php')) {
  546. switch ($_REQUEST['do']) {
  547. case 'update':
  548. $location = 'Admin::Languages::Updating Language';
  549. break;
  550. case 'add':
  551. $location = 'Admin::Languages::Add Language Form';
  552. break;
  553. case 'new2':
  554. $location = 'Admin::Languages::Adding Language';
  555. break;
  556. case 'delete':
  557. $location = 'Admin::Languages::Deleting Language';
  558. break;
  559. case 'view':
  560. $location = 'Admin::Languages::Viewing Languages';
  561. break;
  562. }
  563. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/payment.php')) {
  564. switch ($_REQUEST['do']) {
  565. default:
  566. $location = 'Admin::Payments';
  567. break;
  568. }
  569. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/priority.php')) {
  570. switch ($_REQUEST['do']) {
  571. case 'settings':
  572. $location = 'Admin::Priorities::Viewing Priority Settings';
  573. break;
  574. case 'pri_orders':
  575. $location = 'Admin::Priorities::Re-Ordering Priorities';
  576. break;
  577. case 'delete':
  578. $location = 'Admin::Priorities::Delete Priority Form';
  579. break;
  580. case 'delete2':
  581. $location = 'Admin::Priorities::Deleting Priority';
  582. break;
  583. case 'add':
  584. case 'edit':
  585. $location = 'Admin::Priorities::Add/Edit Priority Form';
  586. break;
  587. case 'edit2':
  588. $location = 'Admin::Priorities::Editing Priority';
  589. break;
  590. case 'add2':
  591. $location = 'Admin::Priorities::Adding Priority';
  592. break;
  593. case 'view':
  594. $location = 'Admin::Priorities::Viewing Priorities';
  595. break;
  596. }
  597. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/replace.php')) {
  598. switch ($_REQUEST['do']) {
  599. case 'add':
  600. $location = 'Admin::Replacement Variables::Add Form';
  601. break;
  602. case 'add2':
  603. $location = 'Admin::Replacement Variables::Adding';
  604. break;
  605. case 'delete':
  606. $location = 'Admin::Replacement Variables::Deleting';
  607. break;
  608. case 'view':
  609. $location = 'Admin::Replacement Variables::Viewing';
  610. break;
  611. }
  612. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/reports.php')) {
  613. switch ($_REQUEST['do']) {
  614. case 'viewreports':
  615. $location = 'Admin::Reports::Listing Reports';
  616. break;
  617. case 'deletereports':
  618. $location = 'Admin::Reports::Deleting Report';
  619. break;
  620. case 'viewstats':
  621. $location = 'Admin::Reports::Listing Statistics';
  622. break;
  623. case 'editreport':
  624. case 'newreport':
  625. $location = 'Admin::Reports::Add/Edit Report Form';
  626. break;
  627. case 'newreport2':
  628. case 'editreport2':
  629. $location = 'Admin::Reports::Adding/Editing Report';
  630. break;
  631. case 'newstat2':
  632. case 'editstat2':
  633. $location = 'Admin::Reports::Adding/Editing Statistic';
  634. break;
  635. case 'editstat':
  636. case 'newstat':
  637. $location = 'Admin::Reports::Add/Edit Statistic';
  638. break;
  639. }
  640. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/runreport.php')) {
  641. $location = 'Admin::Reports::Running Report';
  642. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/settings.php')) {
  643. switch ($_REQUEST['do']) {
  644. case 'update':
  645. $location = 'Admin::Settings::Updating Setting';
  646. break;
  647. case 'list':
  648. $location = 'Admin::Settings::Listing Settings';
  649. break;
  650. }
  651. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/spam.php')) {
  652. switch ($_REQUEST['do']) {
  653. case 'delete2':
  654. $location = 'Admin::Spam::Deleting Spam Entry';
  655. break;
  656. case 'edit':
  657. case 'add':
  658. $location = 'Admin::Spam::Add/Edit Spam Entry';
  659. break;
  660. case 'edit2':
  661. $location = 'Admin::Spam::Editing Spam Entry';
  662. break;
  663. case 'add2':
  664. $location = 'Admin::Spam::Adding Spam Entry';
  665. break;
  666. case 'view':
  667. $location = 'Admin::Spam::Viewing Spam Entries';
  668. break;
  669. }
  670. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/stats.php')) {
  671. $location = 'Admin::Stats::Viewing Ticket Statistics';
  672. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/online.php')) {
  673. $location = 'Admin::Stats::Viewing Technician Activity Log';
  674. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/tech.php')) {
  675. switch ($_REQUEST['do']) {
  676. case 'email':
  677. $location = 'Admin::Spam::E-mail Techs Form';
  678. break;
  679. case 'email2':
  680. $location = 'Admin::Spam::E-mailing Techs';
  681. break;
  682. case 'add':
  683. $location = 'Admin::Spam::Add Tech Form';
  684. break;
  685. case 'submit':
  686. case 'update':
  687. $location = 'Admin::Spam::Adding/Editing Tech';
  688. break;
  689. case 'add2':
  690. case 'edit':
  691. case 'redo':
  692. $location = 'Admin::Spam::Add/Edit Tech Form';
  693. break;
  694. case 'delete':
  695. $location = 'Admin::Spam::Deleting Tech';
  696. break;
  697. case 'disable':
  698. $location = 'Admin::Spam::Disabling Tech';
  699. break;
  700. case 'enable':
  701. $location = 'Admin::Spam::Enabling Tech';
  702. break;
  703. case 'view':
  704. $location = 'Admin::Spam::Viewing Tech';
  705. break;
  706. case 'cats':
  707. $location = 'Admin::Spam::Viewing Technician Category Assignments';
  708. break;
  709. }
  710. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/techemail.php')) {
  711. switch ($_REQUEST['do']) {
  712. case 'settings':
  713. $location = 'Admin::Technician E-mail::Updating Settings';
  714. break;
  715. default:
  716. $location = 'Admin::Technician E-mail::Viewing Settings';
  717. break;
  718. }
  719. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/templates.php')) {
  720. switch ($_REQUEST['do']) {
  721. case 'view':
  722. $location = 'Admin::Templates::Viewing Templates';
  723. break;
  724. case 'editcustom2':
  725. $location = 'Admin::Templates::Editing Custom Template';
  726. break;
  727. case 'edit2':
  728. $location = 'Admin::Templates::Editing Template';
  729. break;
  730. case 'add':
  731. $location = 'Admin::Templates::Add Template Form';
  732. break;
  733. case 'add2':
  734. $location = 'Admin::Templates::Adding Template';
  735. break;
  736. case 'edit':
  737. $location = 'Admin::Templates::Edit Template Form';
  738. break;
  739. case 'editcustom':
  740. $location = 'Admin::Templates::Edit Custom Template Form';
  741. break;
  742. case 'delete':
  743. $location = 'Admin::Templates::Deleting Custom Template';
  744. break;
  745. case 'restore':
  746. $location = 'Admin::Templates::Restoring Template From Backup';
  747. break;
  748. case 'preg_replace':
  749. $location = 'Admin::Templates::Search/Replace Template Form';
  750. break;
  751. case 'xhtml':
  752. $location = 'Admin::Templates::XHTML Redirect';
  753. break;
  754. case 'xhtml2':
  755. $location = 'Admin::Templates::XHTML Update';
  756. break;
  757. case 'preg_replace2':
  758. $location = 'Admin::Templates::Search/Replace Execution';
  759. break;
  760. case 'find':
  761. $location = 'Admin::Templates::Search Form';
  762. break;
  763. case 'find2':
  764. $location = 'Admin::Templates::Search Execution';
  765. break;
  766. case 'export':
  767. $location = 'Admin::Templates::Export Form';
  768. break;
  769. }
  770. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/ticket_fields.php')) {
  771. switch ($_REQUEST['do']) {
  772. case 'new3':
  773. case 'update':
  774. $location = 'Admin::Ticket Fields::Adding/Editing Field';
  775. break;
  776. case 'edit':
  777. case 'new2':
  778. $location = 'Admin::Ticket Fields::Add/Edit Field Form';
  779. break;
  780. case 'add':
  781. $location = 'Admin::Ticket Fields::Add Field Form';
  782. break;
  783. case 'delete':
  784. $location = 'Admin::Ticket Fields::Deleting Field';
  785. break;
  786. case 'view':
  787. $location = 'Admin::Ticket Fields::Viewing Fields';
  788. break;
  789. }
  790. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/user_fields.php')) {
  791. switch ($_REQUEST['do']) {
  792. case 'new3':
  793. case 'update':
  794. $location = 'Admin::User Fields::Adding/Editing Field';
  795. break;
  796. case 'edit':
  797. case 'new2':
  798. $location = 'Admin::User Fields::Add/Edit Field Form';
  799. break;
  800. case 'add':
  801. $location = 'Admin::User Fields::Add Field Form';
  802. break;
  803. case 'delete':
  804. $location = 'Admin::User Fields::Deleting Field';
  805. break;
  806. case 'view':
  807. $location = 'Admin::User Fields::Viewing Fields';
  808. break;
  809. }
  810. } elseif (stristr($_SERVER['PHP_SELF'], 'admin/user_fields.php')) {
  811. switch ($_REQUEST['do']) {
  812. case 'update':
  813. $location = 'Admin::Words::Updating Word';
  814. break;
  815. case 'view':
  816. $location = 'Admin::Words::Viewing Words';
  817. break;
  818. }
  819. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/calendar/edit.php')) {
  820. $location = "Tech::Calendar::Editing Event <A HREF="../tech/calendar/viewtask.php?id=$_REQUEST[id]">$_REQUEST[id]</A>";
  821. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/calendar/index.php')) {
  822. $location = "Tech::Calendar::Viewing Calendar";
  823. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/calendar/new.php')) {
  824. $location = "Tech::Calendar::Creating New Event";
  825. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/calendar/search.php')) {
  826. $location = "Tech::Calendar::Searching Events";
  827. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/calendar/viewtask.php')) {
  828. $location = "Tech::Calendar::Viewing Event <A HREF="../tech/calendar/viewtask.php?id=$_REQUEST[id]">$_REQUEST[id]</A>";
  829. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/email/index.php')) {
  830. switch ($_REQUEST['do']) {
  831. case 'send':
  832. $location = 'Tech::E-mails::Send E-mail Form';
  833. break;
  834. case 'send2':
  835. $location = 'Tech::E-mails::Sending E-mail';
  836. break;
  837. case 'mark_read':
  838. case 'mark_unread':
  839. $location = 'Tech::E-mails::Setting Read/Unread State';
  840. break;
  841. case 'delete':
  842. case 'delete2':
  843. $location = 'Tech::E-mails::Deleting E-Mail';
  844. break;
  845. case 'view':
  846. $location = "Tech::E-mails::Viewing E-Mail <A HREF="../tech/email/index.php?do=view&id=$_REQUEST[id]">$_REQUEST[id]</A>";
  847. break;
  848. case 'reply':
  849. $location = 'Tech::E-mails::Composing Response';
  850. break;
  851. }
  852. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/faq/actions.php')) {
  853. $location = "Tech::FAQ::Updating/Maintaining Entry";
  854. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/faq/add.php')) {
  855. $location = "Tech::FAQ::Adding Category";
  856. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/faq/category.php')) {
  857. $location = "Tech::FAQ::Maintaining Categories";
  858. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/faq/category.php')) {
  859. $location = "Tech::FAQ::Maintaining Categories";
  860. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/faq/index.php')) {
  861. switch ($_REQUEST['do']) {
  862. case 'pdf':
  863. $location = 'Tech::FAQ::Generating PDF';
  864. break;
  865. case 'edit_categories':
  866. $location = 'Tech::FAQ::Editing Categories';
  867. break;
  868. case 'edit_articles':
  869. $location = 'Tech::FAQ::Editing Article(s)';
  870. break;
  871. case 'navigate':
  872. $location = 'Tech::FAQ::Viewing Categories';
  873. break;
  874. }
  875. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/faq/view.php')) {
  876. $location = "Tech::FAQ::Viewing/Maintaining Articles";
  877. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/home/index.php')) {
  878. $location = "Tech::Home Page";
  879. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/home/reports.php')) {
  880. $location = "Tech::Viewing Own Stats";
  881. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/news/technews.php')) {
  882. switch ($_REQUEST['do']) {
  883. case 'new2':
  884. case 'new':
  885. $location = 'Tech::News::Adding Tech News Item';
  886. break;
  887. case 'edit2':
  888. case 'edit':
  889. $location = 'Tech::News::Editing Tech News Item';
  890. break;
  891. case 'delete2':
  892. case 'delete':
  893. $location = 'Tech::News::Deleting Tech News Item';
  894. break;
  895. case 'list':
  896. $location = 'Tech::News::Viewing Tech News Items';
  897. break;
  898. }
  899. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/news/usernews.php')) {
  900. switch ($_REQUEST['do']) {
  901. case 'new2':
  902. case 'new':
  903. $location = 'Tech::News::Adding Tech News Item';
  904. break;
  905. case 'edit2':
  906. case 'edit':
  907. $location = 'Tech::News::Editing Tech News Item';
  908. break;
  909. case 'delete2':
  910. case 'delete':
  911. $location = 'Tech::News::Deleting Tech News Item';
  912. break;
  913. case 'list':
  914. $location = 'Tech::News::Viewing Tech News Items';
  915. break;
  916. }
  917. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/settings')) {
  918. $location = 'Tech::Personal Settings';
  919. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/teamwork/index.php')) {
  920. $location = 'Tech::Private Messaging::Viewing Messages';
  921. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/teamwork/pms.php')) {
  922. switch ($_REQUEST['do']) {
  923. case 'actions':
  924. $location = 'Tech::Private Messaging::Updating Messages';
  925. break;
  926. case 'read':
  927. $location = 'Tech::Private Messaging::Reading Message';
  928. break;
  929. case 'add':
  930. case 'send':
  931. $location = 'Tech::Private Messaging::Sending Message';
  932. break;
  933. case 'view':
  934. $location = 'Tech::Private Messaging::Viewing Message List';
  935. break;
  936. }
  937. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/tickets/addattachments.php')) {
  938. $location = 'Tech::Tickets::Adding Attachment';
  939. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/tickets/index.php')) {
  940. $location = 'Tech::Tickets::Index Page';
  941. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/tickets/load_results.php')) {
  942. $location = 'Tech::Tickets::Viewing Search Results';
  943. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/tickets/new.php')) {
  944. $location = 'Tech::Tickets::Creating New Ticket';
  945. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/tickets/new.php')) {
  946. $location = 'Tech::Tickets::Creating New Ticket';
  947. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/tickets/quick_reply.php')) {
  948. $location = 'Tech::Tickets::Managing Quick Replies';
  949. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/tickets/ticketactions.php')) {
  950. switch ($_REQUEST['do']) {
  951. case 'process':
  952. $location = 'Tech::Tickets::Mass-Updating Tickets';
  953. break;
  954. case 'store':
  955. case 'unstore':
  956. $location = "Tech::Tickets::Updating Saved Tickets List (Ticket #$_REQUEST[id])";
  957. break;
  958. case 'lock':
  959. case 'unlock':
  960. $location = "Tech::Tickets::Updating Ticket Lock Status (Ticket #$_REQUEST[id])";
  961. break;
  962. case 'awaiting_tech':
  963. case 'awaiting_user':
  964. $location = "Tech::Tickets::Updating Ticket Awaiting Response Status (Ticket #$_REQUEST[id])";
  965. break;
  966. case 'remove_ownership':
  967. $location = "Tech::Tickets::Removing Ownership (Ticket #$_REQUEST[id])";
  968. break;
  969. case 'close':
  970. $location = "Tech::Tickets::Closing (Ticket #$_REQUEST[id])";
  971. break;
  972. case 'open':
  973. $location = "Tech::Tickets::Re-opening (Ticket #$_REQUEST[id])";
  974. break;
  975. case 'delete':
  976. $location = "Tech::Tickets::Deleting (Ticket #$_REQUEST[id])";
  977. break;
  978. case 'merge':
  979. $location = 'Tech::Tickets::Merging ticket #' . htmlspecialchars($_REQUEST['fromticket']) . 'into ticket #' . htmlspecialchars($_REQUEST['toticket']) .
  980. '(Ticket #' . htmlspecialchars($_REQUEST['ticket_stay']['id']) . ')';
  981. break;
  982. case 'delete':
  983. $location = "Tech::Tickets::Deleting (Ticket #$_REQUEST[id])";
  984. break;
  985. }
  986. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/ticket/ticketedit.php')) {
  987. $location = "Tech::Tickets::Editing Ticket Metadata (ticket #$_REQUEST[id])";
  988. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/ticket/ticketreply.php')) {
  989. $location = "Tech::Tickets::Replying (or Noting) Ticket (ticket #$_REQUEST[id])";
  990. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/tickets/ticketsearch.php')) {
  991. $location = 'Tech::Tickets::Searching Tickets';
  992. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/tickets/ticketview.php')) {
  993. $location = "Tech::Tickets::Viewing Ticket (ticket #<A HREF="../tech/tickets/ticketview.php?id=$_REQUEST[id]">$_REQUEST[id]</A>)";
  994. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/users/actions.php')) {
  995. switch ($_REQUEST['do']) {
  996. case 'update_fields':
  997. $location = "Tech::Users::Updating User $_REQUEST[id]";
  998. break;
  999. case 'delete':
  1000. $location = "Tech::Users::Deleting User $_REQUEST[id]";
  1001. break;
  1002. }
  1003. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/users/index.php')) {
  1004. switch ($_REQUEST['do']) {
  1005. case 'approve':
  1006. $location = "Tech::Users::Approving User $_REQUEST[id]";
  1007. break;
  1008. case 'delete':
  1009. $location = "Tech::Users::Deleting User $_REQUEST[id]";
  1010. break;
  1011. default:
  1012. $location = "Tech::Users::Viewing Unapproved Users";
  1013. break;
  1014. }
  1015. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/users/new.php')) {
  1016. switch ($_REQUEST['do']) {
  1017. case 'new2':
  1018. case 'new':
  1019. $location = "Tech::Users::Adding New User";
  1020. break;
  1021. case 'massadd2':
  1022. case 'massadd':
  1023. $location = "Tech::Users::Mass Adding New Users";
  1024. break;
  1025. case 'edit':
  1026. $location = "Editing User $_REQUEST[id]";
  1027. break;
  1028. }
  1029. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/users/notes.php')) {
  1030. switch ($_REQUEST['do']) {
  1031. case 'add':
  1032. case 'add2':
  1033. $location = "Tech::Users::Adding New Note to User $user[id]";
  1034. break;
  1035. case 'edit2':
  1036. case 'edit':
  1037. $location = "Tech::Users::Editing Note $_REQUEST[id]";
  1038. break;
  1039. case 'delete':
  1040. $location = "Tech::Users::Deleting Note $_REQUEST[id]";
  1041. break;
  1042. }
  1043. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/users/online.php')) {
  1044. $location = 'Tech::Tickets::Viewing Online Users';
  1045. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/users/quickfind.php')) {
  1046. $location = 'Tech::Tickets::Searching Users';
  1047. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/users/search.php')) {
  1048. $location = 'Tech::Tickets::Searching Users';
  1049. } elseif (stristr($_SERVER['PHP_SELF'], 'tech/users/view.php')) {
  1050. $location = "Tech::Tickets::Viewing User $_REQUEST[id]";
  1051. } else {
  1052. $location = substr($_SERVER['REQUEST_URI'], 255);
  1053. }
  1054. } else {
  1055. $session[user_type] = 'user';
  1056. switch (basename($_SERVER['PHP_SELF'], '.php')) {
  1057. case 'index':
  1058. $location = 'Home page';
  1059. break;
  1060. case 'ticketlist':
  1061. $location = 'Viewing tickets list';
  1062. break;
  1063. case 'view':
  1064. if ($_REQUEST['ticketref']) {
  1065. $data = $_REQUEST['ticketref'];
  1066. } else {
  1067. $data = $_REQUEST['id'];
  1068. }
  1069. $location = "Viewing ticket #$data";
  1070. break;
  1071. case 'newticket':
  1072. $location = 'Creating a new ticket';
  1073. break;
  1074. case 'faq':
  1075. switch ($_REQUEST['do']) {
  1076. case 'search':
  1077. $location = "Viewing FAQ (searching)";
  1078. break;
  1079. case 'subscriptions':
  1080. $location = "Viewing FAQ (subscriptions)";
  1081. break;
  1082. case 'new':
  1083. $location = "Drafting new FAQ article";
  1084. break;
  1085. default:
  1086. $location = "Viewing FAQ";
  1087. break;
  1088. }
  1089. break;
  1090. case 'profile':
  1091. $location = 'Viewing profile/settings';
  1092. break;
  1093. default:
  1094. $location = 'Logged in';
  1095. break;
  1096. }
  1097. }
  1098. return $location;
  1099. }