A tumblelog CMS built on AJAX, PHP and MySQL.

user.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /* ===========================
  3. gelato CMS development version
  4. http://www.gelatocms.com/
  5. gelato CMS is a free software licensed under GPL (General public license)
  6. =========================== */
  7. ?>
  8. <?php
  9. require_once('../config.php');
  10. include("../classes/functions.php");
  11. include("../classes/user.class.php");
  12. require_once("../classes/configuration.class.php");
  13. $user = new user();
  14. $conf = new configuration();
  15. $isEdition = isset($_GET["edit"]);
  16. $userId = ($isEdition) ? $_GET["edit"] : NULL;
  17. if ($user->isAdmin()) {
  18. if (isset($_GET["delete"])) {
  19. $user->deleteUser($_GET['delete']);
  20. header("Location: admin.php?delete=true");
  21. die();
  22. }
  23. if(isset($_POST["btnAdd"])) {
  24. unset($_POST["btnAdd"]);
  25. if (isset($_POST["repass"])) {
  26. unset($_POST["repass"]);
  27. }
  28. if (isset($_POST["btnVerifyUser"])) {
  29. unset($_POST["btnVerifyUser"]);
  30. }
  31. if (isset($_POST["password"])) {
  32. $_POST["password"] = md5($_POST["password"]);
  33. }
  34. if (isset($_POST["id_user"])) {
  35. $user->modifyUser($_POST, $_POST["id_user"]);
  36. } else {
  37. $user->addUser($_POST);
  38. }
  39. } else {
  40. if ($isEdition) {
  41. $register = $user->getUserByID($userId);
  42. }
  43. ?>
  44. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  45. <html xmlns="http://www.w3.org/1999/xhtml">
  46. <head>
  47. <title>gelato :: add user</title>
  48. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  49. <link rel="shortcut icon" href="<?php echo $conf->urlGelato;?>/images/favicon.ico" />
  50. <script language="javascript" type="text/javascript" src="<?php echo $conf->urlGelato;?>/admin/scripts/mootools.js"></script>
  51. <script language="javascript" type="text/javascript">
  52. function validateFrmAddUser() {
  53. if ($('login').value == "") {
  54. alert("The username field cannot be left blank.");
  55. document.frm_add.login.select();
  56. return false;
  57. }
  58. if ($('password').value == "") {
  59. alert("The password field cannot be left blank.");
  60. document.frm_add.password.select();
  61. return false;
  62. }
  63. if ($('password').value != $('repass').value) {
  64. alert("The password must match,\nplease verify them.");
  65. document.frm_add.password.focus();
  66. return false;
  67. }
  68. return true;
  69. }
  70. function verifyExistingUser() {
  71. $('div-process').style.display="block";
  72. el = $('target');
  73. el.style.display="block";
  74. var path = 'ajax.php?action=verify&login='+$('login').value;
  75. new Ajax(path, {
  76. onComplete:function(e) {
  77. el.setHTML(e);
  78. $('div-process').style.display="none";
  79. }
  80. }).request();
  81. return false;
  82. }
  83. </script>
  84. <style type="text/css" media="screen">
  85. @import "<?php echo $conf->urlGelato;?>/admin/css/style.css";
  86. </style>
  87. </head>
  88. <body>
  89. <div id="div-process" style="display:none;">Processing request...</div>
  90. <div id="cont">
  91. <div id="head">
  92. <h1><a href="<?php echo $conf->urlGelato;?>/" title="gelato :: home">gelato cms</a></h1>
  93. <ul id="nav">
  94. <li><a href="<?php echo $conf->urlGelato;?>/" title="Take me to the tumblelog">Back to the Tumblelog</a></li>
  95. </ul>
  96. </div>
  97. <div id="main">
  98. <div class="box">
  99. <ul class="menu manage">
  100. <h3>Start session</h3>
  101. <li><a href="index.php">Post</a></li>
  102. <li><a href="admin.php">Users</a></li>
  103. <li class="selected"><a><?php echo ($isEdition) ? "Edit" : "Add"; ?></a></li>
  104. </ul>
  105. <div class="tabla">
  106. <form action="user.php" method="post" onSubmit="return validateFrmAddUser();" name="frm_add" class="newpost">
  107. <fieldset>
  108. <ul>
  109. <?php
  110. if ($isEdition) {
  111. ?>
  112. <input type="hidden" name="id_user" id="id_user" value="<?php echo $userId;?>" />
  113. <?php
  114. }
  115. ?>
  116. <li>
  117. <label for="login">user:</label>
  118. <input class="txt" name="login" id="login" type="text" autocomplete="off" value="<?php echo isset($register["login"])?$register["login"]:"";?>" />
  119. <?php
  120. if (!$isEdition) {
  121. ?>
  122. <script language="javascript" type="text/javascript">
  123. document.write("<br /><input class='submit_normal_azul' name='btnVerifyUser' id='btnVerifyUser' type='button' value='Check availability' onclick='verifyExistingUser()' />");
  124. </script>
  125. <?php
  126. }
  127. ?>
  128. </li>
  129. <li>
  130. <div id="target" style="display:none;"></div>
  131. </li>
  132. <li>
  133. <label for="pass">password:</label>
  134. <input class="txt" name="password" id="password" type="password" />
  135. </li>
  136. <li>
  137. <label for="repass">retype password:</label>
  138. <input class="txt" name="repass" id="repass" type="password" />
  139. </li>
  140. <li>
  141. <label for="name">name:</label>
  142. <input class="txt" name="name" id="name" type="text" value="<?php echo isset($register["name"])?$register["name"]:"";?>" />
  143. </li>
  144. <li>
  145. <label for="email">e-mail:</label>
  146. <input class="txt" name="email" id="email" type="text" value="<?php echo isset($register["email"])?$register["email"]:"";?>" />
  147. </li>
  148. <li>
  149. <label for="website">website:</label>
  150. <input class="txt" name="website" id="website" type="text" value="<?php echo isset($register["website"])?$register["website"]:"";?>" />
  151. </li>
  152. <li>
  153. <label for="about">about:</label><br />
  154. <textarea rows="5" cols="50" name="about" id="about" tabindex="7"><?php echo isset($register["about"])?$register["about"]:"";?></textarea>
  155. </li>
  156. <li>
  157. <input name="btnAdd" type="submit" value="<?php echo ($isEdition) ? "Modify" : "Add"; ?> user" />
  158. </li>
  159. </ul>
  160. </fieldset>
  161. </form>
  162. </div>
  163. <div class="footer-box">&nbsp;</div>
  164. </div>
  165. </div>
  166. <div id="foot">
  167. <a href="http://www.gelatocms.com/" title="gelato CMS">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
  168. </div>
  169. </div>
  170. </body>
  171. </html>
  172. <?php
  173. }
  174. } else {
  175. header("Location: ".$conf->urlGelato."/login.php");
  176. }
  177. ?>