Array('self' => 'add|edit'), 'OnCountryChange' => Array('self' => 'add|edit'), ); $this->permMapping = array_merge($this->permMapping, $permissions); } /** * Define alternative event processing method names * * @return void * @see kEventHandler::$eventMethods * @access protected */ protected function mapEvents() { parent::mapEvents(); // ensure auto-adding of approve/decine and so on events $zones_events = Array ( 'OnAddLocation' => 'DestinationAction', 'OnRemoveLocation' => 'DestinationAction', 'OnLoadZoneForm' => 'DestinationAction', /*'OnCountryChange' => 'DestinationAction',*/ 'OnNew' => 'DestinationAction' ); $this->eventMethods = array_merge($this->eventMethods, $zones_events); } /** * Apply custom processing to item * * @param kEvent $event * @param string $type * @return void * @access protected */ protected function customProcessing(kEvent $event, $type) { $zone_object =& $event->getObject(); /* @var $zone_object kDBItem */ if ( $type == 'after' ) { $dst_object = $this->Application->recallObject('taxdst'); /* @var $dst_object kDBItem */ if ( $event->Name == 'OnUpdate' ) { $sql = 'DELETE FROM ' . $dst_object->TableName . ' WHERE TaxZoneId = ' . $zone_object->GetID(); $this->Conn->Query($sql); } else { $temp = $this->Application->GetVar('taxdst', Array ()); foreach ($temp as $key => $value) { $temp[$key]['TaxZoneId'] = $zone_object->GetID(); } $this->Application->SetVar('taxdst', $temp); } $this->Application->HandleEvent(new kEvent('taxdst:OnCreate')); } } /** * Enter description here... * * @param kEvent $event */ function OnTypeChange($event) { $this->Application->DeleteVar('taxdst'); $event->CallSubEvent('OnPreSave'); $event->redirect = false; } /** * Enter description here... * * @param kEvent $event */ function DestinationAction($event) { $event->redirect = false; $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); if($items_info) { foreach($items_info as $item_id => $field_values) { // this is to receive $item_id } } $object =& $event->getObject( Array('skip_autoload' => true) ); $object->Load($item_id); $object->SetFieldsFromHash($field_values); $object->SetDBField('TaxZoneID', $item_id); $destination = $this->Application->recallObject('taxdst'); $tax_object = $this->Application->recallObject('tax'); switch($event->Name) { case 'OnAddLocation': $temp = $this->Application->GetVar('taxdst'); $zip = $this->Application->GetVar('zip_input') ? $this->Application->GetVar('zip_input') : $this->Application->GetVar('zip_dropdown'); $exist=0; switch ($object->GetDBField('Type')) { case 1: $location_id = $this->Application->GetVar('country'); break; case 2: $location_id = $this->Application->GetVar('state'); break; default: $location_id = $this->Application->GetVar('StatesCountry'); foreach($temp as $temp_id => $temp_val){ if ($temp_val['DestValue']==$zip){ $exist=1; break; } } } if ($exist == 0){ $new_id = (int)$this->Conn->GetOne('SELECT MIN('.$destination->IDField.') FROM '.$destination->TableName); if($new_id > 0) $new_id = 0; do { $new_id--; } while ($this->check_array($this->Application->GetVar('taxdst'), 'TaxZoneDestId', $new_id)); if( ($location_id && !$this->check_array($temp, 'StdDestId', $location_id)) || ($zip && !$this->check_array($temp, 'DestValue', $zip)) ) { if($tax_object->GetDBField('Type') == 3 && $zip ==''){ continue; } $temp[$new_id]['TaxZoneDestId'] = $new_id; $temp[$new_id]['StdDestId'] = $location_id; $temp[$new_id]['DestValue'] = $zip ? $zip : ''; $this->Application->SetVar('taxdst', $temp); } } break; case 'OnRemoveLocation': $temp = $this->Application->GetVar('taxdst'); $selected_destinations = explode(',', $this->Application->GetVar('selected_destinations')); foreach ($selected_destinations as $dest) { unset( $temp[$dest] ); if (strlen($dest)>0){ $sql = 'DELETE FROM '.$destination->TableName.' WHERE TaxZoneDestId ='.$dest; $this->Conn->Query($sql); } } $this->Application->SetVar('taxdst', $temp); break; case 'OnLoadZoneForm': $sql = 'SELECT * FROM '.$destination->TableName.' WHERE TaxZoneId='.$item_id; $res = $this->Conn->Query($sql); $temp = Array(); foreach ($res as $dest_record) { $temp[$dest_record['TaxZoneDestId']]['TaxZoneDestId'] = $dest_record['TaxZoneDestId']; $temp[$dest_record['TaxZoneDestId']]['StdDestId'] = $dest_record['StdDestId']; $temp[$dest_record['TaxZoneDestId']]['DestValue'] = $dest_record['DestValue']; } $this->Application->SetVar('taxdst', $temp); //$object =& $event->getObject(); //$object->SetDBField('ShippingTypeID', $this->Application->GetVar('s_id')); break; case 'OnNew': //$object =& $event->getObject(); //$object->SetDBField('ShippingTypeID', $this->Application->GetVar('s_id')); break; case 'OnCountryChange': $this->Application->DeleteVar('taxdst'); break; default: } $event->CallSubEvent("OnPreSave"); } function OnCountryChange($event) { $destinations = &$this->Application->recallObject('taxdst'); $queryDel="DELETE FROM ".$destinations->TableName." WHERE TaxZoneId=".(int)$this->Application->GetVar('tax_id'); $this->Conn->Query($queryDel); $this->Application->DeleteVar('taxdst'); $event->CallSubEvent('OnPreSave'); $event->redirect = false; } }