OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
user_main.php
Go to the documentation of this file.
1 <?php
2 
8 class User_Main extends oxAdminDetails
9 {
10  private $_sSaveError = null;
11 
19  public function render()
20  {
21  $myConfig = $this->getConfig();
22  $soxId = $this->getEditObjectId();
23 
25 
26  // malladmin stuff
27  $oAuthUser = oxNew( 'oxuser' );
28  $oAuthUser->loadAdminUser();
29  $blisMallAdmin = $oAuthUser->oxuser__oxrights->value == "malladmin";
30 
31  // all usergroups
32  $sViewName = getViewName( "oxgroups", $this->_iEditLang );
33  $oGroups = oxNew( "oxlist" );
34  $oGroups->init( "oxgroups" );
35  $oGroups->selectString( "select * from {$sViewName} order by {$sViewName}.oxtitle" );
36 
37  // User rights
38  $aUserRights = array();
39  $oLang = oxRegistry::getLang();
40  $iTplLang = $oLang->getTplLanguage();
41 
42  $iPos = count( $aUserRights );
43  $aUserRights[$iPos] = new stdClass();
44  $aUserRights[$iPos]->name = $oLang->translateString( "user", $iTplLang );
45  $aUserRights[$iPos]->id = "user";
46 
47  if ( $blisMallAdmin ) {
48  $iPos = count( $aUserRights );
49  $aUserRights[$iPos] = new stdClass();
50  $aUserRights[$iPos]->id = "malladmin";
51  $aUserRights[$iPos]->name = $oLang->translateString( "Admin", $iTplLang );
52  }
53 
54 
55  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
56  if ( $soxId != "-1" && isset( $soxId ) ) {
57  // load object
58  $oUser = oxNew( "oxuser" );
59  $oUser->load( $soxId);
60  $this->_aViewData["edit"] = $oUser;
61 
62  if ( !( $oUser->oxuser__oxrights->value == "malladmin" && !$blisMallAdmin ) ) {
63  // generate selected right
64  reset( $aUserRights );
65  while ( list(, $val ) = each( $aUserRights ) ) {
66  if ( $val->id == $oUser->oxuser__oxrights->value) {
67  $val->selected = 1;
68  break;
69  }
70  }
71  }
72  }
73 
74  // passing country list
75  $oCountryList = oxNew( "oxCountryList" );
76  $oCountryList->loadActiveCountries( $oLang->getObjectTplLanguage() );
77 
78  $this->_aViewData["countrylist"] = $oCountryList;
79 
80  $this->_aViewData["allgroups"] = $oGroups;
81 
82  $this->_aViewData["rights"] = $aUserRights;
83 
84  if ($this->_sSaveError) {
85  $this->_aViewData["sSaveError"] = $this->_sSaveError;
86  }
87 
88  if (!$this->_allowAdminEdit($soxId))
89  $this->_aViewData['readonly'] = true;
90  if ( oxConfig::getParameter("aoc") ) {
91  $oUserMainAjax = oxNew( 'user_main_ajax' );
92  $this->_aViewData['oxajax'] = $oUserMainAjax->getColumns();
93 
94  return "popups/user_main.tpl";
95  }
96  return "user_main.tpl";
97  }
98 
104  public function save()
105  {
106  parent::save();
107 
108  //allow admin information edit only for MALL admins
109  $soxId = $this->getEditObjectId();
110  if ( $this->_allowAdminEdit( $soxId ) ) {
111 
112  $aParams = oxConfig::getParameter( "editval");
113 
114  // checkbox handling
115  if ( !isset( $aParams['oxuser__oxactive'] ) ) {
116  $aParams['oxuser__oxactive'] = 0;
117  }
118 
119  $oUser = oxNew( "oxuser" );
120  if ( $soxId != "-1" ) {
121  $oUser->load( $soxId );
122  } else {
123  $aParams['oxuser__oxid'] = null;
124  }
125 
126  //setting new password
127  if ( ( $sNewPass = oxConfig::getParameter( "newPassword" ) ) ) {
128  $oUser->setPassword( $sNewPass );
129  }
130 
131  //FS#2167 V checks for already used email
132  if ( $oUser->checkIfEmailExists( $aParams['oxuser__oxusername'] ) ) {
133  $this->_sSaveError = 'EXCEPTION_USER_USEREXISTS';
134  return;
135  }
136 
137  $oUser->assign( $aParams );
138 
139 
140  // A. changing field type to save birth date correctly
141  $oUser->oxuser__oxbirthdate->fldtype = 'char';
142 
143  try {
144  $oUser->save();
145 
146  // set oxid if inserted
147  $this->setEditObjectId( $oUser->getId() );
148  } catch ( Exception $oExcp ) {
149  $this->_sSaveError = $oExcp->getMessage();
150  }
151  }
152  }
153 }