00001 <?php
00002
00006 class payment_country_ajax extends ajaxListComponent
00007 {
00008
00014 protected $_aColumns = array('container1' => array(
00015 array('oxtitle', 'oxcountry', 1, 1, 0),
00016 array('oxisoalpha2', 'oxcountry', 1, 0, 0),
00017 array('oxisoalpha3', 'oxcountry', 0, 0, 0),
00018 array('oxunnum3', 'oxcountry', 0, 0, 0),
00019 array('oxid', 'oxcountry', 0, 0, 1)
00020 ),
00021 'container2' => array(
00022 array('oxtitle', 'oxcountry', 1, 1, 0),
00023 array('oxisoalpha2', 'oxcountry', 1, 0, 0),
00024 array('oxisoalpha3', 'oxcountry', 0, 0, 0),
00025 array('oxunnum3', 'oxcountry', 0, 0, 0),
00026 array('oxid', 'oxobject2payment', 0, 0, 1)
00027 )
00028 );
00029
00035 protected function _getQuery()
00036 {
00037
00038 $sCountryTable = $this->_getViewName('oxcountry');
00039 $oDb = oxDb::getDb();
00040 $sCountryId = $this->getConfig()->getRequestParameter('oxid');
00041 $sSynchCountryId = $this->getConfig()->getRequestParameter('synchoxid');
00042
00043
00044 if (!$sCountryId) {
00045
00046 $sQAdd = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
00047 } else {
00048
00049 $sQAdd = " from oxobject2payment left join $sCountryTable on $sCountryTable.oxid=oxobject2payment.oxobjectid ";
00050 $sQAdd .= "where $sCountryTable.oxactive = '1' and oxobject2payment.oxpaymentid = " . $oDb->quote($sCountryId) . " and oxobject2payment.oxtype = 'oxcountry' ";
00051 }
00052
00053 if ($sSynchCountryId && $sSynchCountryId != $sCountryId) {
00054 $sQAdd .= "and $sCountryTable.oxid not in ( ";
00055 $sQAdd .= "select $sCountryTable.oxid from oxobject2payment left join $sCountryTable on $sCountryTable.oxid=oxobject2payment.oxobjectid ";
00056 $sQAdd .= "where oxobject2payment.oxpaymentid = " . $oDb->quote($sSynchCountryId) . " and oxobject2payment.oxtype = 'oxcountry' ) ";
00057 }
00058
00059 return $sQAdd;
00060 }
00061
00065 public function addPayCountry()
00066 {
00067 $aChosenCntr = $this->_getActionIds('oxcountry.oxid');
00068 $soxId = $this->getConfig()->getRequestParameter('synchoxid');
00069
00070 if ($this->getConfig()->getRequestParameter('all')) {
00071 $sCountryTable = $this->_getViewName('oxcountry');
00072 $aChosenCntr = $this->_getAll($this->_addFilter("select $sCountryTable.oxid " . $this->_getQuery()));
00073 }
00074 if ($soxId && $soxId != "-1" && is_array($aChosenCntr)) {
00075 foreach ($aChosenCntr as $sChosenCntr) {
00076 $oObject2Payment = oxNew('oxbase');
00077 $oObject2Payment->init('oxobject2payment');
00078 $oObject2Payment->oxobject2payment__oxpaymentid = new oxField($soxId);
00079 $oObject2Payment->oxobject2payment__oxobjectid = new oxField($sChosenCntr);
00080 $oObject2Payment->oxobject2payment__oxtype = new oxField("oxcountry");
00081 $oObject2Payment->save();
00082 }
00083 }
00084 }
00085
00089 public function removePayCountry()
00090 {
00091 $aChosenCntr = $this->_getActionIds('oxobject2payment.oxid');
00092 if ($this->getConfig()->getRequestParameter('all')) {
00093
00094 $sQ = $this->_addFilter("delete oxobject2payment.* " . $this->_getQuery());
00095 oxDb::getDb()->Execute($sQ);
00096
00097 } elseif (is_array($aChosenCntr)) {
00098 $sQ = "delete from oxobject2payment where oxobject2payment.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aChosenCntr)) . ") ";
00099 oxDb::getDb()->Execute($sQ);
00100 }
00101 }
00102 }