PageRenderTime 69ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_user/user.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 285 lines | 221 code | 40 blank | 24 comment | 52 complexity | da4094e30fc9c01977f21f3c33293df7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: user.php 5995 2006-12-13 02:52:43Z friesengeist $
  4. * @package Joomla
  5. * @subpackage Users
  6. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // no direct access
  15. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  16. // Editor usertype check
  17. $access = new stdClass();
  18. $access->canEdit = $acl->acl_check( 'action', 'edit', 'users', $my->usertype, 'content', 'all' );
  19. $access->canEditOwn = $acl->acl_check( 'action', 'edit', 'users', $my->usertype, 'content', 'own' );
  20. require_once ( $mainframe->getPath( 'front_html' ) );
  21. switch( $task ) {
  22. case 'UserDetails':
  23. userEdit( $option, $my->id, _UPDATE );
  24. break;
  25. case 'saveUserEdit':
  26. // check to see if functionality restricted for use as demo site
  27. if ( $_VERSION->RESTRICT == 1 ) {
  28. mosRedirect( 'index.php?mosmsg=Functionality Restricted' );
  29. } else {
  30. userSave( $option, $my->id );
  31. }
  32. break;
  33. case 'CheckIn':
  34. CheckIn( $my->id, $access, $option );
  35. break;
  36. case 'cancel':
  37. mosRedirect( 'index.php' );
  38. break;
  39. default:
  40. HTML_user::frontpage();
  41. break;
  42. }
  43. function userEdit( $option, $uid, $submitvalue) {
  44. global $database, $mainframe;
  45. global $mosConfig_absolute_path;
  46. // security check to see if link exists in a menu
  47. $link = 'index.php?option=com_user&task=UserDetails';
  48. $query = "SELECT id"
  49. . "\n FROM #__menu"
  50. . "\n WHERE link LIKE '%$link%'"
  51. . "\n AND published = 1"
  52. ;
  53. $database->setQuery( $query );
  54. $exists = $database->loadResult();
  55. if ( !$exists ) {
  56. mosNotAuth();
  57. return;
  58. }
  59. require_once( $mosConfig_absolute_path .'/administrator/components/com_users/users.class.php' );
  60. if ($uid == 0) {
  61. mosNotAuth();
  62. return;
  63. }
  64. $row = new mosUser( $database );
  65. $row->load( (int)$uid );
  66. $row->orig_password = $row->password;
  67. $row->name = trim( $row->name );
  68. $row->email = trim( $row->email );
  69. $row->username = trim( $row->username );
  70. $file = $mainframe->getPath( 'com_xml', 'com_users' );
  71. $params =& new mosUserParameters( $row->params, $file, 'component' );
  72. HTML_user::userEdit( $row, $option, $submitvalue, $params );
  73. }
  74. function userSave( $option, $uid) {
  75. global $database, $my, $mosConfig_frontend_userparams;
  76. $user_id = intval( mosGetParam( $_POST, 'id', 0 ));
  77. // do some security checks
  78. if ($uid == 0 || $user_id == 0 || $user_id != $uid) {
  79. mosNotAuth();
  80. return;
  81. }
  82. // simple spoof check security
  83. josSpoofCheck();
  84. $row = new mosUser( $database );
  85. $row->load( (int)$user_id );
  86. $orig_password = $row->password;
  87. $orig_username = $row->username;
  88. if (!$row->bind( $_POST, 'gid usertype' )) {
  89. echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  90. exit();
  91. }
  92. $row->name = trim($row->name);
  93. $row->email = trim($row->email);
  94. $row->username = trim($row->username);
  95. mosMakeHtmlSafe($row);
  96. if (isset($_POST['password']) && $_POST['password'] != '') {
  97. if (isset($_POST['verifyPass']) && ($_POST['verifyPass'] == $_POST['password'])) {
  98. $row->password = trim($row->password);
  99. $salt = mosMakePassword(16);
  100. $crypt = md5($row->password.$salt);
  101. $row->password = $crypt.':'.$salt;
  102. } else {
  103. echo "<script> alert(\"".addslashes( _PASS_MATCH )."\"); window.history.go(-1); </script>\n";
  104. exit();
  105. }
  106. } else {
  107. // Restore 'original password'
  108. $row->password = $orig_password;
  109. }
  110. if ($mosConfig_frontend_userparams == '1' || $mosConfig_frontend_userparams == 1 || $mosConfig_frontend_userparams == NULL) {
  111. // save params
  112. $params = mosGetParam( $_POST, 'params', '' );
  113. if (is_array( $params )) {
  114. $txt = array();
  115. foreach ( $params as $k=>$v) {
  116. $txt[] = "$k=$v";
  117. }
  118. $row->params = implode( "\n", $txt );
  119. }
  120. }
  121. if (!$row->check()) {
  122. echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  123. exit();
  124. }
  125. if (!$row->store()) {
  126. echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
  127. exit();
  128. }
  129. // check if username has been changed
  130. if ( $orig_username != $row->username ) {
  131. // change username value in session table
  132. $query = "UPDATE #__session"
  133. . "\n SET username = " . $database->Quote($row->username)
  134. . "\n WHERE username = " . $database->Quote( $orig_username )
  135. . "\n AND userid = " . (int) $my->id
  136. . "\n AND gid = " . (int) $my->gid
  137. . "\n AND guest = 0"
  138. ;
  139. $database->setQuery( $query );
  140. $database->query();
  141. }
  142. mosRedirect( 'index.php', _USER_DETAILS_SAVE );
  143. }
  144. function CheckIn( $userid, $access, $option ){
  145. global $database;
  146. global $mosConfig_db;
  147. $nullDate = $database->getNullDate();
  148. if (!($access->canEdit || $access->canEditOwn || $userid > 0)) {
  149. mosNotAuth();
  150. return;
  151. }
  152. // security check to see if link exists in a menu
  153. $link = 'index.php?option=com_user&task=CheckIn';
  154. $query = "SELECT id"
  155. . "\n FROM #__menu"
  156. . "\n WHERE link LIKE '%$link%'"
  157. . "\n AND published = 1"
  158. ;
  159. $database->setQuery( $query );
  160. $exists = $database->loadResult();
  161. if ( !$exists ) {
  162. mosNotAuth();
  163. return;
  164. }
  165. $lt = mysql_list_tables($mosConfig_db);
  166. $k = 0;
  167. echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
  168. while (list($tn) = mysql_fetch_array($lt)) {
  169. // only check in the jos_* tables
  170. if (strpos( $tn, $database->_table_prefix ) !== 0) {
  171. continue;
  172. }
  173. $lf = mysql_list_fields($mosConfig_db, "$tn");
  174. $nf = mysql_num_fields($lf);
  175. $checked_out = false;
  176. $editor = false;
  177. for ($i = 0; $i < $nf; $i++) {
  178. $fname = mysql_field_name($lf, $i);
  179. if ( $fname == "checked_out") {
  180. $checked_out = true;
  181. } else if ( $fname == "editor") {
  182. $editor = true;
  183. }
  184. }
  185. if ($checked_out) {
  186. if ($editor) {
  187. $query = "SELECT checked_out, editor"
  188. . "\n FROM `$tn`"
  189. . "\n WHERE checked_out > 0"
  190. . "\n AND checked_out = " . (int) $userid
  191. ;
  192. $database->setQuery( $query );
  193. } else {
  194. $query = "SELECT checked_out"
  195. . "\n FROM `$tn`"
  196. . "\n WHERE checked_out > 0"
  197. . "\n AND checked_out = " . (int) $userid
  198. ;
  199. $database->setQuery( $query );
  200. }
  201. $res = $database->query();
  202. $num = $database->getNumRows( $res );
  203. if ($editor) {
  204. $query = "UPDATE `$tn`"
  205. . "\n SET checked_out = 0, checked_out_time = " . $database->Quote( $nullDate ) . ", editor = NULL"
  206. . "\n WHERE checked_out > 0"
  207. . "\n AND checked_out = " . (int) $userid
  208. ;
  209. $database->setQuery( $query );
  210. } else {
  211. $query = "UPDATE `$tn`"
  212. . "\n SET checked_out = 0, checked_out_time = " . $database->Quote( $nullDate )
  213. . "\n WHERE checked_out > 0"
  214. . "\n AND checked_out = " . (int) $userid
  215. ;
  216. $database->setQuery( $query );
  217. }
  218. $res = $database->query();
  219. if ($res == 1) {
  220. if ($num > 0) {
  221. echo "\n<tr class=\"row$k\">";
  222. echo "\n <td width=\"250\">";
  223. echo _CHECK_TABLE;
  224. echo " - $tn</td>";
  225. echo "\n <td>";
  226. echo _CHECKED_IN;
  227. echo "<b>$num</b>";
  228. echo _CHECKED_IN_ITEMS;
  229. echo "</td>";
  230. echo "\n</tr>";
  231. }
  232. $k = 1 - $k;
  233. }
  234. }
  235. }
  236. ?>
  237. <tr>
  238. <td colspan="2">
  239. <b><?php echo _CONF_CHECKED_IN; ?></b>
  240. </td>
  241. </tr>
  242. </table>
  243. <?php
  244. }
  245. ?>