00001 <?php
00002
00009 class User_Address extends oxAdminDetails
00010 {
00014 protected $_blDelete = false;
00015
00023 public function render()
00024 {
00025 parent::render();
00026
00027 $soxId = oxConfig::getParameter( "oxid");
00028 if ( $soxId != "-1" && isset( $soxId)) {
00029
00030 $oUser = oxNew( "oxuser" );
00031 $oUser->load( $soxId);
00032
00033
00034 $soxAddressId = isset($this->sSavedOxid)?$this->sSavedOxid:oxConfig::getParameter( "oxaddressid");
00035 if ( $soxAddressId != "-1" && isset( $soxAddressId ) ) {
00036 $oAdress = oxNew( "oxbase" );
00037 $oAdress->init( "oxaddress" );
00038 $oAdress->load( $soxAddressId );
00039 $this->_aViewData["edit"] = $oAdress;
00040 }
00041
00042 $this->_aViewData["oxaddressid"] = $soxAddressId;
00043
00044
00045 $oAddressList = $oUser->getUserAddresses();
00046 foreach ( $oAddressList as $oAddress ) {
00047 if ( $oAddress->oxaddress__oxid->value == $soxAddressId ) {
00048 $oAddress->selected = 1;
00049 break;
00050 }
00051 }
00052
00053 $this->_aViewData["edituser"] = $oUser;
00054 }
00055
00056 $oCountryList = oxNew( "oxCountryList" );
00057 $oCountryList->loadActiveCountries( oxLang::getInstance()->getTplLanguage() );
00058
00059 $this->_aViewData["countrylist"] = $oCountryList;
00060
00061 if (!$this->_allowAdminEdit($soxId))
00062 $this->_aViewData['readonly'] = true;
00063
00064 return "user_address.tpl";
00065 }
00066
00072 public function save()
00073 {
00074
00075 if ( !$this->_allowAdminEdit( oxConfig::getParameter( "oxid" ) ) )
00076 return false;
00077
00078 if ( $sRedirect = $this->autosave() ) {
00079 return $sRedirect;
00080 }
00081
00082 $aParams = oxConfig::getParameter( "editval");
00083
00084 $oAdress = oxNew( "oxbase" );
00085 $oAdress->init( "oxaddress" );
00086
00087 if ( $aParams['oxaddress__oxid'] == "-1")
00088 $aParams['oxaddress__oxid'] = null;
00089
00090 if ( isset($aParams['oxaddress__oxcompany']))
00091 oxConfig::checkSpecialChars($aParams['oxaddress__oxcompany']);
00092
00093 $oAdress->assign( $aParams);
00094 $oAdress->save();
00095
00096 $this->sSavedOxid = $oAdress->getId();
00097
00098 return $this->autosave();
00099 }
00100
00106 public function delAddress()
00107 {
00108 $aParams = oxConfig::getParameter( "editval" );
00109 if ( !$this->_allowAdminEdit( oxConfig::getParameter( "oxid" ) ) )
00110 return false;
00111
00112 $oAdress = oxNew( "oxbase" );
00113 $oAdress->init( "oxaddress" );
00114
00115 if ( $aParams['oxaddress__oxid'] != "-1") {
00116 $oAdress->load( $aParams['oxaddress__oxid']);
00117 $oAdress->delete();
00118 $this->_blDelete = true;
00119 }
00120 }
00121 }