Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

117 lines
2.9 KiB

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