Automatically exported from code.google.com/p/planningalerts
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

118 lines
3.0 KiB

  1. <?php
  2. require_once ("config.php");
  3. require_once ("user.php");
  4. require_once ("stats.php");
  5. $index_page = new index_page;
  6. class index_page {
  7. //Properties
  8. var $warnings = "";
  9. var $onloadscript = "";
  10. var $postcode = "";
  11. var $email = "";
  12. var $alert_area_size = "m";
  13. var $email_warn = false;
  14. var $postcode_warn = false;
  15. //Constructor
  16. function index_page() {
  17. //check for postback vs load
  18. if (isset($_POST["_is_postback"])) {
  19. $this->unbind();
  20. $this->process();
  21. }else{
  22. $this->setup();
  23. $this->bind();
  24. }
  25. }
  26. //setup
  27. function setup (){
  28. }
  29. //Bind
  30. function bind() {
  31. //page vars
  32. $form_action = $_SERVER['PHP_SELF'];
  33. $this->onloadscript = "setFocus('txtEmail');";
  34. //smarty
  35. $smarty = new Smarty;
  36. $smarty->force_compile = true;
  37. $smarty->compile_dir = SMARTY_COMPILE_DIRECTORY;
  38. $smarty->assign("stats", stats::get_stats());
  39. $smarty->assign("menu_item", "signup");
  40. $smarty->assign("postcode", $this->postcode);
  41. $smarty->assign("email", $this->email);
  42. $smarty->assign("alert_area_size", $this->alert_area_size);
  43. $smarty->assign("page_title","Email alerts of planning applications near you");
  44. $smarty->assign("warnings", $this->warnings);
  45. $smarty->assign("email_warn", $this->email_warn);
  46. $smarty->assign("postcode_warn", $this->postcode_warn);
  47. $smarty->assign("onloadscript", $this->onloadscript);
  48. $smarty->assign("small_zone_size",SMALL_ZONE_SIZE);
  49. $smarty->assign("medium_zone_size",MEDIUM_ZONE_SIZE);
  50. $smarty->assign("large_zone_size",LARGE_ZONE_SIZE);
  51. //Render
  52. $smarty->display('index.tpl');
  53. }
  54. function unbind (){
  55. //Get postcode and setup the group
  56. $this->postcode = $_POST['txtPostcode'];
  57. $this->email = $_POST['txtEmail'];
  58. $this->alert_area_size = $_POST['radAlertAreaSize'];
  59. }
  60. function validate (){
  61. if($this->email =="" || !valid_email($this->email)){
  62. $this->email_warn = true;
  63. $this->warnings .= " Please enter a valid email address.";
  64. }
  65. if($this->postcode =="" || !is_postcode($this->postcode)){
  66. $this->postcode_warn = true;
  67. $this->warnings .= " Please enter a valid postcode.";
  68. }
  69. if($this->alert_area_size != "s" && $this->alert_area_size != "m" && $this->alert_area_size != "l"){
  70. $this->warnings .= " Please select an area for the alerts.";
  71. }
  72. return $this->warnings =="";
  73. }
  74. function process (){
  75. if($this->validate()){
  76. $user = new user();
  77. //Populate new user
  78. $user->populate_new($this->email, $this->postcode, $this->alert_area_size);
  79. //Save
  80. $user->save(true);
  81. //send to check mail page
  82. $base_url = BASE_URL;
  83. header("Location: {$base_url}/checkmail.php");
  84. }else{
  85. $this->bind();
  86. }
  87. }
  88. }
  89. ?>