user_main.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class User_Main extends oxAdminDetails
00009 {
00010     private $_sSaveError = null;
00011 
00019     public function render()
00020     {
00021         $myConfig = $this->getConfig();
00022         $soxId = $this->getEditObjectId();
00023 
00024         parent::render();
00025 
00026         // malladmin stuff
00027         $oAuthUser = oxNew( 'oxuser' );
00028         $oAuthUser->loadAdminUser();
00029         $blisMallAdmin = $oAuthUser->oxuser__oxrights->value == "malladmin";
00030 
00031             // all usergroups
00032             $sViewName = getViewName( "oxgroups", $this->_iEditLang );
00033             $oGroups = oxNew( "oxlist" );
00034             $oGroups->init( "oxgroups" );
00035             $oGroups->selectString( "select * from {$sViewName} order by {$sViewName}.oxtitle" );
00036 
00037         // User rights
00038         $aUserRights = array();
00039         $oLang = oxRegistry::getLang();
00040         $iTplLang = $oLang->getTplLanguage();
00041 
00042         $iPos = count( $aUserRights );
00043         $aUserRights[$iPos] = new stdClass();
00044         $aUserRights[$iPos]->name = $oLang->translateString( "user", $iTplLang );
00045         $aUserRights[$iPos]->id   = "user";
00046 
00047         if ( $blisMallAdmin ) {
00048             $iPos = count( $aUserRights );
00049             $aUserRights[$iPos] = new stdClass();
00050             $aUserRights[$iPos]->id   = "malladmin";
00051             $aUserRights[$iPos]->name = $oLang->translateString( "Admin", $iTplLang );
00052         }
00053 
00054 
00055         $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00056         if ( $soxId != "-1" && isset( $soxId ) ) {
00057             // load object
00058             $oUser = oxNew( "oxuser" );
00059             $oUser->load( $soxId);
00060             $this->_aViewData["edit"] =  $oUser;
00061 
00062             if ( !( $oUser->oxuser__oxrights->value == "malladmin" && !$blisMallAdmin ) ) {
00063                 // generate selected right
00064                 reset( $aUserRights );
00065                 while ( list(, $val ) = each( $aUserRights ) ) {
00066                     if ( $val->id == $oUser->oxuser__oxrights->value) {
00067                         $val->selected = 1;
00068                         break;
00069                     }
00070                 }
00071             }
00072         }
00073 
00074         // passing country list
00075         $oCountryList = oxNew( "oxCountryList" );
00076         $oCountryList->loadActiveCountries( $oLang->getObjectTplLanguage() );
00077 
00078         $this->_aViewData["countrylist"] = $oCountryList;
00079 
00080             $this->_aViewData["allgroups"] =  $oGroups;
00081 
00082         $this->_aViewData["rights"] =  $aUserRights;
00083 
00084         if ($this->_sSaveError) {
00085             $this->_aViewData["sSaveError"] = $this->_sSaveError;
00086         }
00087 
00088         if (!$this->_allowAdminEdit($soxId))
00089             $this->_aViewData['readonly'] = true;
00090         if ( oxConfig::getParameter("aoc") ) {
00091             $oUserMainAjax = oxNew( 'user_main_ajax' );
00092             $this->_aViewData['oxajax'] = $oUserMainAjax->getColumns();
00093 
00094             return "popups/user_main.tpl";
00095         }
00096         return "user_main.tpl";
00097     }
00098 
00104     public function save()
00105     {
00106         parent::save();
00107 
00108         //allow admin information edit only for MALL admins
00109         $soxId = $this->getEditObjectId();
00110         if ( $this->_allowAdminEdit( $soxId ) ) {
00111 
00112             $aParams = oxConfig::getParameter( "editval");
00113 
00114             // checkbox handling
00115             if ( !isset( $aParams['oxuser__oxactive'] ) ) {
00116                 $aParams['oxuser__oxactive'] = 0;
00117             }
00118 
00119             $oUser = oxNew( "oxuser" );
00120             if ( $soxId != "-1" ) {
00121                 $oUser->load( $soxId );
00122             } else {
00123                 $aParams['oxuser__oxid'] = null;
00124             }
00125 
00126             //setting new password
00127             if ( ( $sNewPass = oxConfig::getParameter( "newPassword" ) ) ) {
00128                 $oUser->setPassword( $sNewPass );
00129             }
00130 
00131             //FS#2167 V checks for already used email
00132             if ( $oUser->checkIfEmailExists( $aParams['oxuser__oxusername'] ) ) {
00133                 $this->_sSaveError = 'EXCEPTION_USER_USEREXISTS';
00134                 return;
00135             }
00136 
00137             $oUser->assign( $aParams );
00138 
00139 
00140             // A. changing field type to save birth date correctly
00141             $oUser->oxuser__oxbirthdate->fldtype = 'char';
00142 
00143             try {
00144                 $oUser->save();
00145 
00146                 // set oxid if inserted
00147                 $this->setEditObjectId( $oUser->getId() );
00148             } catch ( Exception $oExcp ) {
00149                 $this->_sSaveError = $oExcp->getMessage();
00150             }
00151         }
00152     }
00153 }