/login.php

http://swifttide.googlecode.com/ · PHP · 107 lines · 88 code · 3 blank · 16 comment · 5 complexity · c27799fd76cb591b4f6699671bb3a20d MD5 · raw file

  1. <?php
  2. //*
  3. // login.php
  4. // All Sections
  5. // Process login for user
  6. //*
  7. // Include configuration
  8. include_once "configuration.php";
  9. session_start();
  10. //Check if the user comes from the index page
  11. // if(!$_SERVER['HTTP_REFERER'] == "http://www.swifttide.info/SMS/index.php"){
  12. // header("Location: index.php?action=notauth");
  13. // exit();
  14. // };
  15. if($_SESSION['tryattempts']>=_MAX_ATTEMPTS){
  16. header("Location: index.php?action=attempt");
  17. exit();
  18. };
  19. //Inizialize database functions
  20. include_once "ez_sql.php";
  21. //Include global functions
  22. include_once "common.php";
  23. //Gather form posts
  24. $username= get_param("username");
  25. $password= get_param("password");
  26. //Validate fields
  27. if(!strlen($username)){
  28. set_session("tryattempts", ($_SESSION['tryattempts']+1));
  29. header("Location: index.php?action=errlog");
  30. exit();
  31. };
  32. if(!strlen($password)){
  33. set_session("tryattempts", ($_SESSION['tryattempts']+1));
  34. header("Location: index.php?action=errlog");
  35. exit();
  36. };
  37. //Check if uname/pwd match
  38. $sSQL="SELECT * FROM web_users WHERE web_users_username =" . tosql($username, "Text") . " AND web_users_password=" . tosql($password, "Text")." and active = 1";
  39. if($isuser=$db->get_row($sSQL)){
  40. $current_year=$db->get_var("SELECT current_year FROM tbl_config WHERE id=1");
  41. $user_type=$isuser->web_users_type;
  42. $user_id=$isuser->web_users_id;
  43. $year_name=$db->get_var("SELECT school_years_desc FROM school_years WHERE school_years_id=$current_year");
  44. switch ($user_type){
  45. case "A" :
  46. set_session("UserType", "A");
  47. set_session("UserId", $user_id);
  48. set_session("CurrentYear", $current_year);
  49. set_session("YearName", $year_name);
  50. $redirurl="admin_main_menu.php";
  51. break;
  52. case "T" :
  53. $tid=$isuser->web_users_relid;
  54. $teacher=$db->get_row("SELECT * FROM teachers WHERE teachers_id=$tid");
  55. $tlname=$teacher->teachers_lname;
  56. $tfname=$teacher->teachers_fname;
  57. $tschool=$teacher->teachers_school;
  58. set_session("UserType", "T");
  59. set_session("UserId", $user_id);
  60. set_session("teacherid", $tid);
  61. set_session("tfname", $tfname);
  62. set_session("tlname", $tlname);
  63. set_session("tschool", $tschool);
  64. set_session("CurrentYear", $current_year);
  65. set_session("YearName", $year_name);
  66. $redirurl="teachers_menu.php";
  67. break;
  68. case "N" :
  69. $tid=$isuser->web_users_relid;
  70. $teacher=$db->get_row("SELECT * FROM teachers WHERE teachers_id=$tid");
  71. $tlname=$teacher->teachers_lname;
  72. $tfname=$teacher->teachers_fname;
  73. $tschool=$teacher->teachers_school;
  74. set_session("UserType", "N");
  75. set_session("UserId", $user_id);
  76. set_session("tfname", $tfname);
  77. set_session("tlname", $tlname);
  78. set_session("tschool", $tschool);
  79. set_session("CurrentYear", $current_year);
  80. set_session("YearName", $year_name);
  81. $redirurl="health_menu.php";
  82. break;
  83. case "C" :
  84. $cid=$isuser->web_users_relid;
  85. $contact=$db->get_row("SELECT studentcontact_lname, studentcontact_fname FROM studentcontact WHERE studentcontact_id=$cid");
  86. $clname=$contact->studentcontact_lname;
  87. $cfname=$contact->studentcontact_fname;
  88. set_session("UserType", "C");
  89. set_session("UserId", $cid);
  90. set_session("cfname", $cfname);
  91. set_session("clname", $clname);
  92. set_session("CurrentYear", $current_year);
  93. set_session("YearName", $year_name);
  94. $redirurl="contacts_menu.php";
  95. break;
  96. };
  97. header("Location: " . $redirurl);
  98. exit;
  99. }else{
  100. set_session("tryattempts", ($_SESSION['tryattempts']+1));
  101. header("Location: index.php?action=errlog");
  102. exit;
  103. };
  104. ?>