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