00001 <?php
00002
00009 class User_Payment extends oxAdminDetails
00010 {
00015 protected $_blDelete = false;
00016
00023 public function render()
00024 {
00025 parent::render();
00026
00027
00028 $oPaymentTypes = oxNew( "oxlist" );
00029 $oPaymentTypes->init( "oxpayment");
00030 $oPaymentTypes->getList();
00031
00032 $soxId = oxConfig::getParameter( "oxid");
00033 if ( $soxId != "-1" && isset( $soxId)) {
00034
00035 $oUser = oxNew( "oxuser" );
00036 $oUser->load( $soxId);
00037
00038
00039 $soxPaymentId = oxConfig::getParameter( "oxpaymentid");
00040 if ( (!$soxPaymentId || $this->_blDelete) && isset( $oUser->oPayments[0]))
00041 $soxPaymentId = $oUser->oPayments[0]->oxuserpayments__oxid->value;
00042 if ( $soxPaymentId != "-1" && isset( $soxPaymentId)) {
00043 $oUserPayment = oxNew( "oxuserpayment" );
00044 $oUserPayment->load( $soxPaymentId);
00045 $sTemplate = $oUserPayment->oxuserpayments__oxvalue->value;
00046
00047
00048 foreach ( $oPaymentTypes as $oPayment ) {
00049 if ( $oPayment->oxpayments__oxid->value == $oUserPayment->oxuserpayments__oxpaymentsid->value) {
00050 $oPayment->selected = 1;
00051
00052 if ( !$sTemplate )
00053 $sTemplate = $oPayment->oxpayments__oxvaldesc->value;
00054 break;
00055 }
00056 }
00057 $oUserPayment->setDynValues( oxUtils::getInstance()->assignValuesFromText( $sTemplate ) );
00058 $this->_aViewData["edit"] = $oUserPayment;
00059
00060 }
00061 if ( !$soxPaymentId)
00062 $soxPaymentId = "-1";
00063 $this->_aViewData["oxpaymentid"] = $soxPaymentId;
00064
00065 $this->_aViewData["paymenttypes"] = $oPaymentTypes;
00066
00067
00068 $oUserPayments = $oUser->getUserPayments();
00069 foreach ( $oUserPayments as $oPayment ) {
00070 if ( $oPayment->oxuserpayments__oxid->value == $soxPaymentId ) {
00071 $oPayment->selected = 1;
00072 break;
00073 }
00074 }
00075
00076 $this->_aViewData["edituser"] = $oUser;
00077 }
00078
00079 if (!$this->_allowAdminEdit($soxId))
00080 $this->_aViewData['readonly'] = true;
00081
00082
00083 return "user_payment.tpl";
00084 }
00085
00091 public function save()
00092 {
00093
00094 $soxId = oxConfig::getParameter( "oxid");
00095 if (!$this->_allowAdminEdit($soxId))
00096 return;
00097
00098 if ( $sRedirect = $this->autosave() ) {
00099 return $sRedirect;
00100 }
00101
00102 $aParams = oxConfig::getParameter( "editval");
00103 $aDynvalues = oxConfig::getParameter( "dynvalue");
00104
00105 if ( isset($aDynvalues)) {
00106
00107 $aParams['oxuserpayments__oxvalue'] = oxUtils::getInstance()->assignValuesToText( $aDynvalues);
00108 }
00109
00110 $oAdress = oxNew( "oxuserpayment" );
00111
00112 if ( $aParams['oxuserpayments__oxid'] == "-1")
00113 $aParams['oxuserpayments__oxid'] = null;
00114
00115 $oAdress->assign( $aParams);
00116 $oAdress->save();
00117
00118 return $this->autosave();
00119 }
00120
00126 public function delPayment()
00127 {
00128 $aParams = oxConfig::getParameter( "editval" );
00129 $soxId = oxConfig::getParameter( "oxid" );
00130 if (!$this->_allowAdminEdit($soxId))
00131 return;
00132
00133 $oAdress = oxNew( "oxuserpayment" );
00134
00135 if ( $aParams['oxuserpayments__oxid'] != "-1") {
00136 $oAdress->load( $aParams['oxuserpayments__oxid']);
00137 $oAdress->delete();
00138 $this->_blDelete = true;
00139 }
00140 }
00141 }