A tumblelog CMS built on AJAX, PHP and MySQL.

form.autosave.php 901B

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