diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 19fe71b1..a152161f 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -4162,14 +4162,14 @@ class Admin_DataController extends Zend_Controller_Action } //文件列表 - if($ac == "files"){ + elseif($ac == "files"){ $file = new Dataimport\File; $this->_helper->json($file->getUploadFiles()); return true; } //刪除上傳的文件 - if($ac == "delete"){ + elseif($ac == "delete"){ $file = $this->_getParam('file'); $fileHandle = new Dataimport\File; $this->_helper->json(['success'=>$fileHandle->deleteFile($file)]); @@ -4178,14 +4178,14 @@ class Admin_DataController extends Zend_Controller_Action //預處理 //判斷文件類型,初步識別文件內容 - if($ac == "prepare"){ + elseif($ac == "prepare"){ $this->_helper->viewRenderer('dataimport-preprocess'); $file = $this->_getParam('file'); if(empty($file)) { - view::Post($this,"參數錯誤",-1); + view::Post($this,"参数错误",-1); return true; } @@ -4217,10 +4217,10 @@ class Admin_DataController extends Zend_Controller_Action } //檢查文件是否規則 - if($ac == "check"){ + elseif($ac == "check"){ $file = $this->_getParam('file'); if(empty($file)){ - $this->_helper->json(['error'=>'參數錯誤']); + $this->_helper->json(['error'=>'参数错误']); return true; } @@ -4237,14 +4237,14 @@ class Admin_DataController extends Zend_Controller_Action } //選擇導入目標 - if($ac == "target") + elseif($ac == "target") { $this->_helper->viewRenderer('dataimport-target'); $this->view->file = $file = $this->_getParam('file'); if(empty($file)){ - view::Post($this,"參數錯誤",-1); + view::Post($this,"参数错误",-1); return true; } @@ -4253,20 +4253,37 @@ class Admin_DataController extends Zend_Controller_Action } //获得数据表 - if($ac == "gettables") + elseif($ac == "gettables") { $schema = $this->_getParam('schema'); if(empty($schema)){ - $this->_helper->json(['error'=>'參數錯誤']); + $this->_helper->json(['error'=>'参数错误']); return true; } $tableControl = new Visual\DataTableControl; $this->_helper->json($tableControl->readTables($schema)); return true; } + + //获取表格字段名称和类型 + elseif($ac=="getfields") + { + $schema = $this->_getParam('schema'); + $table = $this->_getParam('table'); + if(empty($schema) || empty($table)){ + $this->_helper->json(['error'=>'参数错误']); + return true; + } + $tableControl = new Visual\DataTableControl; + $fields = $tableControl->readFields($schema . "." .$table); + if ($fields[0]['column_name']=='id') unset($fields[0]); + $this->_helper->json($fields); + return true; + } //检查能否写入数据表 和 导入数据 - if($ac == "checktables" || $ac == "import"){ + elseif($ac == "checktables" || $ac == "import") + { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); @@ -4274,7 +4291,7 @@ class Admin_DataController extends Zend_Controller_Action $schema = $this->_getParam('schema'); $file = $this->_getParam('file'); if(empty($table) || empty($schema) || empty($file)){ - $this->_helper->json(['error'=>'參數錯誤']); + $this->_helper->json(['error'=>'参数错误']); return true; } @@ -4289,6 +4306,7 @@ class Admin_DataController extends Zend_Controller_Action { $tableControl = new Visual\DataTableControl; $fields = $tableControl->readFields($schema . "." .$table); + if ($fields[0]['column_name']=='id') unset($fields[0]); $status = $processing->checkTableField($fields); $this->_helper->json($status); @@ -4296,7 +4314,13 @@ class Admin_DataController extends Zend_Controller_Action } elseif($ac == "import"){ - $status = $processing->import($schema . "." .$table); + $tableControl = new Visual\DataTableControl; + $fields = $tableControl->readFields($schema . "." .$table); + $status = $processing->import($schema . "." .$table,$fields[0]['column_name']=='id'); + if($status===true) + { + $fileHandle->deleteFile($file); + } $this->_helper->json($status); return true; } diff --git a/application/admin/views/scripts/data/dataimport-target.phtml b/application/admin/views/scripts/data/dataimport-target.phtml index 9344d9e6..4562d61e 100644 --- a/application/admin/views/scripts/data/dataimport-target.phtml +++ b/application/admin/views/scripts/data/dataimport-target.phtml @@ -24,7 +24,8 @@ $this->headTitle()->setSeparator(' - ');