示例#1
0
 function page_index()
 {
     // $item_id = $this->api->stickyGET('item_id');
     $form = $this->add('Form');
     $form->template->loadTemplateFromString("<form method='POST' action='" . $this->api->url(null, array('cut_page' => 1)) . "' enctype='multipart/form-data'>\n\t\t\t<input type='file' name='csv_barcode_file'/>\n\t\t\t<label> Remove All borcode  <input type='checkbox' name='remove_old'/></label>\n\t\t\t<input type='submit' value='Upload'/>\n\t\t\t</form>");
     if ($_FILES['csv_barcode_file']) {
         if ($_FILES["csv_barcode_file"]["error"] > 0) {
             $this->add('View_Error')->set("Error: " . $_FILES["csv_barcode_file"]["error"]);
         } else {
             $mimes = ['text/comma-separated-values', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.ms-excel', 'application/vnd.msexcel', 'text/anytext'];
             if (!in_array($_FILES['csv_barcode_file']['type'], $mimes)) {
                 $this->add('View_Error')->set('Only CSV Files allowed');
                 return;
             }
             $importer = new \xepan\base\CSVImporter($_FILES['csv_barcode_file']['tmp_name'], true, ',');
             $data = $importer->get();
             // var_dump($data);
             // exit;
             foreach ($data as $row) {
                 if ($row['name']) {
                     $barcode = $this->add('xepan\\commerce\\Model_BarCode');
                     $barcode->addCondition('name', $row['name']);
                     $barcode->tryLoadAny();
                     if (!$barcode->loaded()) {
                         $barcode->save();
                     }
                 }
             }
             $this->add('View_Info')->set(count($data) . ' Recored Imported');
             $this->js(true)->univ()->closeDialog();
         }
     }
 }
示例#2
0
 function page_index()
 {
     $item_id = $this->api->stickyGET('item_id');
     $form = $this->add('Form');
     $form->template->loadTemplateFromString("<form method='POST' action='" . $this->api->url(null, array('cut_page' => 1, 'item_id' => $item_id)) . "' enctype='multipart/form-data'>\n\t\t\t<input type='file' name='csv_qty_set_file'/>\n\t\t\t<label> Remove old qty sets <input type='checkbox' name='remove_old'/></label>\n\t\t\t<input type='submit' value='Upload'/>\n\t\t\t</form>");
     if ($_FILES['csv_qty_set_file']) {
         if ($_FILES["csv_qty_set_file"]["error"] > 0) {
             $this->add('View_Error')->set("Error: " . $_FILES["csv_qty_set_file"]["error"]);
         } else {
             $mimes = ['text/comma-separated-values', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.ms-excel', 'application/vnd.msexcel', 'text/anytext'];
             if (!in_array($_FILES['csv_qty_set_file']['type'], $mimes)) {
                 $this->add('View_Error')->set('Only CSV Files allowed');
                 return;
             }
             $importer = new \xepan\base\CSVImporter($_FILES['csv_qty_set_file']['tmp_name'], true, ',');
             $data = $importer->get();
             $item = $this->add('xepan\\commerce\\Model_Item')->load($item_id);
             if ($_POST['remove_old']) {
                 // Remove all Quantity sets if said so
                 $qs = $this->add('xepan\\commerce\\Model_Item_Quantity_Set');
                 $qs->deleteQtySetAndCondition($item);
                 // via sql
             }
             $qs = $this->add('xepan\\commerce\\Model_Item_Quantity_Set');
             // foreach ($data as $row) { // field like Qty ... Cst 1, Cst 2 ... Price
             $qs->insertQtysetAndCondition($item, $data);
             $this->add('View_Info')->set(count($data) . ' Recored Imported');
             $this->js(true)->univ()->closeDialog();
         }
     }
 }
示例#3
0
文件: lead.php 项目: xepan/marketing
 function page_import_execute()
 {
     ini_set('max_execution_time', 0);
     $form = $this->add('Form');
     $form->template->loadTemplateFromString("<form method='POST' action='" . $this->api->url(null, array('cut_page' => 1)) . "' enctype='multipart/form-data'>\n\t\t\t<input type='file' name='csv_lead_file'/>\n\t\t\t<input type='submit' value='Upload'/>\n\t\t\t</form>");
     if ($_FILES['csv_lead_file']) {
         if ($_FILES["csv_lead_file"]["error"] > 0) {
             $this->add('View_Error')->set("Error: " . $_FILES["csv_lead_file"]["error"]);
         } else {
             $mimes = ['text/comma-separated-values', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.ms-excel', 'application/vnd.msexcel', 'text/anytext'];
             if (!in_array($_FILES['csv_lead_file']['type'], $mimes)) {
                 $this->add('View_Error')->set('Only CSV Files allowed');
                 return;
             }
             $importer = new \xepan\base\CSVImporter($_FILES['csv_lead_file']['tmp_name'], true, ',');
             $data = $importer->get();
             try {
                 $this->api->db->beginTransaction();
                 $lead = $this->add('xepan\\marketing\\Model_Lead');
                 $lead->addLeadFromCSV($data);
                 $this->api->db->commit();
                 $this->add('View_Info')->set(count($data) . ' Recored Imported');
             } catch (\Exception_StopInit $e) {
             } catch (\Exception $e) {
                 if ($this->app->db->intransaction()) {
                     $this->api->db->rollback();
                 }
                 throw $e;
             }
         }
     }
 }