00001 <?php
00002
00006 class discount_users_ajax extends ajaxListComponent
00007 {
00008
00014 protected $_aColumns = array('container1' => array(
00015 array('oxusername', 'oxuser', 1, 0, 0),
00016 array('oxlname', 'oxuser', 0, 0, 0),
00017 array('oxfname', 'oxuser', 0, 0, 0),
00018 array('oxstreet', 'oxuser', 0, 0, 0),
00019 array('oxstreetnr', 'oxuser', 0, 0, 0),
00020 array('oxcity', 'oxuser', 0, 0, 0),
00021 array('oxzip', 'oxuser', 0, 0, 0),
00022 array('oxfon', 'oxuser', 0, 0, 0),
00023 array('oxbirthdate', 'oxuser', 0, 0, 0),
00024 array('oxid', 'oxuser', 0, 0, 1),
00025 ),
00026 'container2' => array(
00027 array('oxusername', 'oxuser', 1, 0, 0),
00028 array('oxlname', 'oxuser', 0, 0, 0),
00029 array('oxfname', 'oxuser', 0, 0, 0),
00030 array('oxstreet', 'oxuser', 0, 0, 0),
00031 array('oxstreetnr', 'oxuser', 0, 0, 0),
00032 array('oxcity', 'oxuser', 0, 0, 0),
00033 array('oxzip', 'oxuser', 0, 0, 0),
00034 array('oxfon', 'oxuser', 0, 0, 0),
00035 array('oxbirthdate', 'oxuser', 0, 0, 0),
00036 array('oxid', 'oxobject2discount', 0, 0, 1),
00037 )
00038 );
00039
00045 protected function _getQuery()
00046 {
00047 $oConfig = $this->getConfig();
00048
00049 $sUserTable = $this->_getViewName('oxuser');
00050 $oDb = oxDb::getDb();
00051 $sId = $oConfig->getRequestParameter('oxid');
00052 $sSynchId = $oConfig->getRequestParameter('synchoxid');
00053
00054
00055 if (!$sId) {
00056 $sQAdd = " from $sUserTable where 1 ";
00057 if (!$oConfig->getConfigParam('blMallUsers')) {
00058 $sQAdd .= " and oxshopid = '" . $oConfig->getShopId() . "' ";
00059 }
00060 } else {
00061
00062 if ($sSynchId && $sSynchId != $sId) {
00063 $sQAdd = " from oxobject2group left join $sUserTable on $sUserTable.oxid = oxobject2group.oxobjectid where oxobject2group.oxgroupsid = " . $oDb->quote($sId);
00064 if (!$oConfig->getConfigParam('blMallUsers')) {
00065 $sQAdd .= " and $sUserTable.oxshopid = '" . $oConfig->getShopId() . "' ";
00066 }
00067
00068 } else {
00069 $sQAdd = " from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid ";
00070 $sQAdd .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sId) . " and oxobject2discount.oxtype = 'oxuser' ";
00071 }
00072 }
00073
00074 if ($sSynchId && $sSynchId != $sId) {
00075 $sQAdd .= " and $sUserTable.oxid not in ( select $sUserTable.oxid from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid ";
00076 $sQAdd .= " and oxobject2discount.oxdiscountid = " . $oDb->quote($sSynchId) . " and oxobject2discount.oxtype = 'oxuser' ) ";
00077 }
00078
00079 return $sQAdd;
00080 }
00081
00085 public function removeDiscUser()
00086 {
00087 $oConfig = $this->getConfig();
00088
00089 $aRemoveGroups = $this->_getActionIds('oxobject2discount.oxid');
00090 if ($oConfig->getRequestParameter('all')) {
00091
00092 $sQ = $this->_addFilter("delete oxobject2discount.* " . $this->_getQuery());
00093 oxDb::getDb()->Execute($sQ);
00094
00095 } elseif ($aRemoveGroups && is_array($aRemoveGroups)) {
00096 $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aRemoveGroups)) . ") ";
00097 oxDb::getDb()->Execute($sQ);
00098 }
00099 }
00100
00104 public function addDiscUser()
00105 {
00106 $oConfig = $this->getConfig();
00107 $aChosenUsr = $this->_getActionIds('oxuser.oxid');
00108 $soxId = $oConfig->getRequestParameter('synchoxid');
00109
00110
00111 if ($oConfig->getRequestParameter('all')) {
00112 $sUserTable = $this->_getViewName('oxuser');
00113 $aChosenUsr = $this->_getAll($this->_addFilter("select $sUserTable.oxid " . $this->_getQuery()));
00114 }
00115 if ($soxId && $soxId != "-1" && is_array($aChosenUsr)) {
00116 foreach ($aChosenUsr as $sChosenUsr) {
00117 $oObject2Discount = oxNew("oxbase");
00118 $oObject2Discount->init('oxobject2discount');
00119 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00120 $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenUsr);
00121 $oObject2Discount->oxobject2discount__oxtype = new oxField("oxuser");
00122 $oObject2Discount->save();
00123 }
00124 }
00125 }
00126 }