PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_comprofiler/controller/controller.user.php

https://github.com/Shigaru/shigaru
PHP | 154 lines | 105 code | 26 blank | 23 comment | 31 complexity | 7ceaa062e10a5b93523e08efa49e0cbd MD5 | raw file
  1. <?php
  2. /**
  3. * Joomla/Mambo Community Builder
  4. * @version $Id: controller.user.php 1486 2011-07-12 00:15:02Z beat $
  5. * @package Community Builder
  6. * @subpackage admin.comprofiler.php : user controller
  7. * @author Beat
  8. * @copyright (C) Beat, www.joomlapolis.com
  9. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU/GPL version 2
  10. */
  11. // ensure this file is being included by a parent file
  12. if ( ! ( defined( '_VALID_CB' ) || defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); }
  13. class CBController_user {
  14. function _importNeeded() {
  15. cbimport( 'cb.tabs' );
  16. if ( class_exists( 'JFactory' ) ) { // Joomla 1.5 : for string WARNREG_EMAIL_INUSE used in error js popup.
  17. $lang =& JFactory::getLanguage();
  18. $lang->load( "com_users" );
  19. }
  20. cbimport( 'cb.params' );
  21. }
  22. function _importNeededSave() {
  23. // backend only:
  24. cbimport( 'cb.adminfilesystem' );
  25. cbimport( 'cb.imgtoolbox' );
  26. }
  27. function editUser( $uid = '0', $option = 'users' ) {
  28. global $_CB_framework, $_PLUGINS;
  29. $this->_importNeeded();
  30. $msg = checkCBpermissions( array($uid), "edit", true );
  31. if ($msg) {
  32. echo "<script type=\"text/javascript\"> alert('".$msg."'); window.history.go(-1);</script>\n";
  33. exit;
  34. }
  35. $_PLUGINS->loadPluginGroup('user');
  36. $cbUser =& CBuser::getInstance( $uid );
  37. $cmsUserExists = ( $uid != 0 ) && ( $cbUser !== null );
  38. if ( ! $cmsUserExists ) {
  39. $cbUser =& CBuser::getInstance( null );
  40. }
  41. $user =& $cbUser->getUserData();
  42. /*
  43. $user = new moscomprofilerUser( $_CB_database );
  44. $cmsUserExists = $user->load( (int) $uid );
  45. */
  46. $comprofilerExists = ( $user->user_id != null );
  47. if ( $cmsUserExists && $comprofilerExists ) {
  48. // Edit existing CB user:
  49. $newCBuser = '0';
  50. } else {
  51. $newCBuser = '1';
  52. if ( $cmsUserExists ) {
  53. // Edit existing CMS (but new CB) user:
  54. $user->approved = '1';
  55. $user->confirmed = '1';
  56. } else {
  57. // New user:
  58. $user->block = '0';
  59. $user->approved = '1';
  60. $user->confirmed = '1';
  61. $user->sendEmail = '0';
  62. $user->gid = $_CB_framework->acl->get_group_id( $_CB_framework->getCfg( 'new_usertype' ), 'ARO' );
  63. $user->gids = array( $user->gid );
  64. }
  65. }
  66. $null = null;
  67. $usersView = _CBloadView( 'user' );
  68. $usersView->edituser( $user, $option, $newCBuser, $null );
  69. }
  70. function saveUser( $option ) {
  71. global $_CB_framework, $_CB_database, $_POST, $_PLUGINS;
  72. $this->_importNeeded();
  73. $this->_importNeededSave();
  74. if ( ! ( isset( $_POST['approved'] ) && isset( $_POST['confirmed'] ) && isset( $_POST['username'] ) ) ) {
  75. echo "<script type=\"text/javascript\"> alert('" . addslashes( CBTxt::T('Not Authorized') ) ."'); window.history.go(-1);</script>\n";
  76. exit;
  77. }
  78. // Check rights to access:
  79. $myGid = userGID( $_CB_framework->myId() );
  80. $userIdPosted = (int) cbGetParam($_POST, "id", 0 );
  81. if ( $userIdPosted == 0 ) {
  82. $_POST['id'] = null;
  83. }
  84. $adminGroups = $_CB_framework->acl->mapGroupNamesToValues( array( 'Administrator', 'Superadministrator' ) );
  85. if ( $userIdPosted != 0 ) {
  86. $msg = checkCBpermissions( array( $userIdPosted ), 'save', in_array( $myGid, $adminGroups ) );
  87. } else {
  88. $msg = checkCBpermissions( null, 'save', in_array( $myGid, $adminGroups ) );
  89. }
  90. if ($msg) {
  91. echo "<script type=\"text/javascript\"> alert('" . addslashes( $msg ) . "'); window.history.go(-1);</script>\n";
  92. exit;
  93. }
  94. $_PLUGINS->loadPluginGroup('user');
  95. // Get current user state:
  96. if ( $userIdPosted != 0 ) {
  97. $userComplete = CBuser::getUserDataInstance( (int) $userIdPosted );
  98. if ( ! ( $userComplete && $userComplete->id ) ) {
  99. echo "<script type=\"text/javascript\"> alert('" . addslashes( _UE_USER_PROFILE_NOT ) . "'); window.history.go(-1);</script>\n";
  100. return;
  101. }
  102. } else {
  103. $userComplete = new moscomprofilerUser( $_CB_database );
  104. }
  105. // Store new user state:
  106. $saveResult = $userComplete->saveSafely( $_POST, $_CB_framework->getUi(), 'edit' );
  107. if ( ! $saveResult ) {
  108. $regErrorMSG = $userComplete->getError();
  109. $msg = checkCBpermissions( array( $userComplete->id ), "edit", true );
  110. if ($msg) {
  111. echo "<script type=\"text/javascript\"> alert('" . addslashes( $msg ) ."'); window.history.go(-1);</script>\n";
  112. exit;
  113. }
  114. echo "<script type=\"text/javascript\">alert('" . str_replace( '\\\\n', '\\n', addslashes( strip_tags( str_replace( '<br />', '\\n', $regErrorMSG ) ) ) ) . "'); </script>\n";
  115. global $_CB_Backend_task;
  116. $_CB_Backend_task = 'edit'; // so the toolbar comes up...
  117. $_PLUGINS->loadPluginGroup( 'user' ); // resets plugin errors
  118. $usersView = _CBloadView( 'user' );
  119. $usersView->edituser( $userComplete, $option, ( $userComplete->user_id != null ? '0' : '1' ), $_POST );
  120. // echo "<script type=\"text/javascript\">alert('" . addslashes( str_replace( '<br />', '\n', $userComplete->getError() ) ) . "'); window.history.go(-1);</script>\n";
  121. return;
  122. }
  123. // Checks-in the row:
  124. $userComplete->checkin();
  125. cbRedirect( $_CB_framework->backendUrl( "index.php?option=$option&task=showusers" ), sprintf(CBTxt::T('Successfully Saved User: %s'), $userComplete->username) );
  126. }
  127. } // class CBController_user
  128. ?>