PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/coopcoffeebeans/alt_adminpw.php

https://github.com/gypsyfarm/gypsyfarm
PHP | 159 lines | 111 code | 42 blank | 6 comment | 16 complexity | 19e374be96f8d216b49478ca73ee8168 MD5 | raw file
  1. <?php
  2. session_start();
  3. require("../functions.php");
  4. require("../tables.php");
  5. // check security
  6. // check session variable
  7. if (isset($_SESSION['valid_user']))
  8. {
  9. $contact_id = $_SESSION['contact_id'];
  10. $valid_user = $_SESSION['valid_user'];
  11. }
  12. else
  13. {
  14. header("Location: http://www.coopcoffeesbeans.com/badlogin.php");
  15. }
  16. echo "\n";
  17. $alt_contact_id = $_REQUEST['Company_Name'];
  18. echo '<form method="post" action="alt_adminpw.php">';
  19. echo '<input type=hidden name="Company_Name" Id="Company_Name" value="'.$alt_contact_id.'" >';
  20. echo "\n";
  21. $db_conn = mysql_connect('mysql.coopcoffeesbeans.com', 'greenbeans3', 'annh401');
  22. mysql_select_db('cbeans', $db_conn);
  23. $query ="select a.name as pwname, a.pass, a.cust_id as contact_id, cc.company, cc.name, a.user_type
  24. FROM $tbl_auth a, $tbl_coop_contact cc
  25. WHERE a.cust_id = cc.contact_id
  26. AND a.cust_id=$alt_contact_id";
  27. echo '<font size=3><a href="../index.php">Back to the main Menu</a></font><br>';
  28. echo '<font size=3><a href="../logout.php">Log Out</a></font><br><br> ';
  29. // provide form to log in
  30. if (!isset($_REQUEST['button']))
  31. {
  32. //logo();
  33. $result = mysql_query($query, $db_conn);
  34. $row = mysql_fetch_array($result);
  35. echo "<br><center><h1 >Password Update</h1></center><br>";
  36. $contact_name = $row['company'];
  37. echo "<font size=4 color=black>You are about to change the login password for $contact_name </font>";
  38. echo '<table>';
  39. echo '<tr><td colspan=2>Contact Name is : '.$row['name'].'</td></tr>';
  40. echo '<tr><td>sign on Name:</td>';
  41. echo '<td><input name="pwname" disabled value="'.$row['pwname'].'"></td></tr>';
  42. echo '<tr><td>User Type:</td>';
  43. echo '<td>';
  44. echo '<select name="User Type" disabled >';
  45. echo '<br><option value="">';
  46. echo "\n";
  47. echo '<option value="1" ';
  48. if ($row['user_type'] == 1)
  49. {
  50. echo ' selected ';
  51. }
  52. echo ' >Customer';
  53. echo "\n";
  54. echo '<option value="2" ';
  55. if ($row['user_type'] == 2)
  56. {
  57. echo ' selected ';
  58. }
  59. echo ' >Bill';
  60. echo "\n";
  61. echo '<option value="3" ';
  62. if ($row['user_type'] == 3)
  63. {
  64. echo ' selected ';
  65. }
  66. echo ' >Bank';
  67. echo "\n";
  68. echo '<option value="4" ';
  69. if ($row['user_type'] == 4)
  70. {
  71. echo ' selected ';
  72. }
  73. echo ' >Warehouse';
  74. echo "\n";
  75. echo "</select>";
  76. echo '</td></tr>';
  77. echo '<tr><td colspan=2><br></td></tr>';
  78. echo '<tr><td>Enter New Password:</td>';
  79. echo '<td><input type="password" name="New_Password:"></td></tr>';
  80. echo '<tr><td>Confirm New Password:</td>';
  81. echo '<td><input type="password" name="Confirm_Password:"></td></tr>';
  82. echo '<tr><td align="center">';
  83. echo '<input type="submit" name="button" value="Save Password"> ';
  84. echo '</td><td align="center">';
  85. echo '<input type="submit" name="button" value="Cancel">';
  86. echo '</td></tr>';
  87. echo '</table>';
  88. }
  89. If ($_REQUEST['button'] == 'Save Password'){
  90. logo();
  91. echo "<br><center><h1 >Update Password</h1></center><br><br><br><br>";
  92. echo '<font size=3><a href="../index.php">Back to Main Menu</font><br>';
  93. echo '<font size=3><a href="../logout.php">Log out</a></font><br>';
  94. $New=$_REQUEST['New_Password:'];
  95. $Confirm=$_REQUEST['Confirm_Password:'];
  96. $password = $_REQUEST['current'];
  97. //If its right and the new matches the confirm and at least one of them is set then update the password
  98. if ( isset($Confirm) and isset($New) and ($New == $Confirm) ) {
  99. $db_conn = mysql_connect('mysql.coopcoffeesbeans.com', 'greenbeans3', 'annh401');
  100. mysql_select_db('cbeans', $db_conn);
  101. $query = "UPDATE $tbl_auth SET pass = password( '$New' ) WHERE cust_id = '$alt_contact_id' LIMIT 1 ";
  102. $result = mysql_query($query, $db_conn);
  103. echo '<br><font size=4 color=Red>Your password has been changed. Please make a note of it,</font><br>';
  104. echo '<font size=4 color=Red>you will need it the next time you log in.</font>';
  105. }
  106. else {
  107. echo '<font size=3><a href="alt_adminpw.php">Back to Change Password</a></font><br>';
  108. echo '<br><br><font size=4 color=red>The new password and the confirmation do not match, you must have a typo!</font>';
  109. }
  110. }
  111. echo '</form>';
  112. //They just canceled out of the page altogether
  113. If ($_REQUEST['button'] == 'Cancel'){
  114. header("Location: http://www.coopcoffeesbeans.com/demo/index.php");
  115. echo 'You have chosen cancel';
  116. }
  117. ?>