public function actionImportCSV()
 {
     ini_set('max_execution_time', 300);
     $this->layout = '//layouts/column2';
     $model = new UserImportForm();
     $failed_to_insert = array();
     $exist_postcode = array();
     $next_kg = -1;
     $first_kg = -1;
     $min_trans = -1;
     $max_trans = -1;
     $zone_id = -1;
     $district_id = -1;
     if (isset($_POST['UserImportForm'])) {
         $model->attributes = $_POST['UserImportForm'];
         if ($model->validate()) {
             $csvFile = CUploadedFile::getInstance($model, 'file');
             $tempLoc = $csvFile->getTempName();
             $rawdatas = file($tempLoc);
             try {
                 $connection = Yii::app()->db;
                 $transaction = $connection->beginTransaction();
                 $sql = "INSERT INTO rate_domestic (service_id, origin_id, first_kg, next_kg, min_transit_time,max_transit_time,zone_id,district_id) VALUES(:service_id, :origin_id, :first_kg, :next_kg, :min_transit_time, :max_transit_time,:zone_id,:district_id)";
                 $command = $connection->createCommand($sql);
                 $command->bindValue(":service_id", $model->service_id, PDO::PARAM_INT);
                 $command->bindValue(":origin_id", $model->origin_id, PDO::PARAM_INT);
                 $command->bindParam(':zone_id', $zone_id);
                 $command->bindParam(':district_id', $district_id);
                 $command->bindParam(':first_kg', $first_kg);
                 $command->bindParam(':next_kg', $next_kg);
                 $command->bindParam(':min_transit_time', $min_trans);
                 $command->bindParam(':max_transit_time', $max_trans);
                 foreach ($rawdatas as $rates) {
                     $rate = explode(',', $rates);
                     if (!in_array($rate[0], $exist_postcode, true)) {
                         $exist_postcode[] = $rate[0];
                         //							var_dump($rate[1]);
                         //							if (!is_numeric($rate[1]) || !is_numeric($rate[2]) || !is_numeric($rate[3]))
                         //							{
                         //								$failed_to_insert[] = $rate[0];
                         //								continue;
                         //							}
                         $postcode_data = Area::getZoneID($rate[0]);
                         $checkZoneId = RateDomestic::checkZoneId($model->service_id, $model->origin_id, $postcode_data['zone_id']);
                         if ($checkZoneId) {
                             continue;
                         }
                         $first_kg = $rate[1];
                         $next_kg = $rate[2];
                         $min_trans = $rate[3];
                         $max_trans = $rate[4];
                         $zone_id = $postcode_data['zone_id'];
                         $district_id = $postcode_data['district_id'];
                         if (!!$postcode_data) {
                             $exec = $command->execute();
                         }
                     }
                 }
                 $transaction->commit();
             } catch (Exception $e) {
                 CVarDumper::dump($e, 10, TRUE);
                 exit;
                 $transaction->rollBack();
             }
         }
     }
     $this->render("importcsv", array('model' => $model));
 }