A tumblelog CMS built on AJAX, PHP and MySQL.

form.autosave.php 940B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. if(!defined('entry'))define('entry', true);
  3. require('../entry.php');
  4. global $conf;
  5. session_start();
  6. function isAjax() {
  7. return isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
  8. $_SERVER ['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
  9. }
  10. function saveForm() {
  11. $type = getMethod();
  12. $id = ($type=='GET') ? $_GET['autosaveid'] : $_POST['autosaveid'];
  13. $_SESSION[$id] = $_SERVER['QUERY_STRING'];
  14. echo gmdate('H:i | d/m/y',time()+transform_offset($conf->offsetTime));
  15. }
  16. function loadForm() {
  17. $type = getMethod();
  18. $id = ($type=='GET') ? $_GET['autosaveid'] : $_POST['autosaveid'];
  19. if(isset($_SESSION[$id]))
  20. echo $_SESSION[$id];
  21. }
  22. function isLoad() {
  23. $type = getMethod();
  24. if($type=='GET' and isset($_GET['autosave'])) return true;
  25. elseif(isset($_POST['autosave'])) return true;
  26. return false;
  27. }
  28. function getMethod() {
  29. return $_SERVER['REQUEST_METHOD'];
  30. }
  31. if(isAjax()) {
  32. if(isLoad()) loadForm();
  33. else saveForm();
  34. }
  35. exit;
  36. ?>