//print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)"); if ($newcode) { $array_selected[$_GET["field"]] = $newpos; $array_selected[$newcode] = $pos; $_SESSION["export_selected_fields"] = $array_selected; } } if ($step == 1 || $action == 'cleanselect') { $_SESSION["export_selected_fields"] = array(); $_SESSION["export_filtered_fields"] = array(); $array_selected = array(); $array_filtervalue = array(); } if ($action == 'builddoc') { // Build export file $result = $objexport->build_file($user, GETPOST('model', 'alpha'), $datatoexport, $array_selected, $array_filtervalue); if ($result < 0) { setEventMessage($objexport->error, 'errors'); $sqlusedforexport = $objexport->sqlusedforexport; } else { setEventMessage($langs->trans("FileSuccessfullyBuilt")); $sqlusedforexport = $objexport->sqlusedforexport; } } // Delete file if ($step == 5 && $action == 'confirm_deletefile' && $confirm == 'yes') { $file = $upload_dir . "/" . GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). $ret = dol_delete_file($file); if ($ret) { setEventMessage($langs->trans("FileWasRemoved", GETPOST('file')));
/** * Test export function * * @return void */ public function testExportSociete() { global $conf,$user,$langs,$db; $sql = ""; $datatoexport='societe_1'; $array_selected = array("s.rowid"=>1, "s.nom"=>2); // Mut be fields found into declaration of dataset $model='csv'; $objexport=new Export($db); $result=$objexport->load_arrays($user,$datatoexport); // Build export file $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $sql); $expectedresult=1; $this->assertEquals($result,$expectedresult); return true; }
} } //print("Switch pos=$pos (code=".$_GET["field"].") and newpos=$newpos (code=$newcode)"); if ($newcode) { $array_selected[$_GET["field"]] = $newpos; $array_selected[$newcode] = $pos; $_SESSION["export_selected_fields"] = $array_selected; } } if ($step == 1 || $action == 'cleanselect') { $_SESSION["export_selected_fields"] = array(); $array_selected = array(); } if ($action == 'builddoc') { // Build export file $result = $objexport->build_file($user, $_POST['model'], $datatoexport, $array_selected); if ($result < 0) { $mesg = '<div class="error">' . $objexport->error . '</div>'; } else { $mesg = '<div class="ok">' . $langs->trans("FileSuccessfullyBuilt") . '</div>'; $sqlusedforexport = $objexport->sqlusedforexport; } } if ($action == 'deleteprof') { if ($_GET["id"]) { $objexport->fetch($_GET["id"]); $result = $objexport->delete($user); } } if ($action == 'add_export_model') { if ($export_name) {
/** * Test export function for all dataset predefined into modules * * @depends testExportPersonalizedWithFilter * @return void */ public function testExportModulesDatasets() { global $conf, $user, $langs, $db; $model = 'csv'; $filterdatatoexport = ''; //$filterdatatoexport=''; //$array_selected = array("s.rowid"=>1, "s.nom"=>2); // Mut be fields found into declaration of dataset // Load properties of arrays to make export $objexport = new Export($db); $result = $objexport->load_arrays($user, $filterdatatoexport); // This load ->array_export_xxx properties for datatoexport // Loop on each dataset foreach ($objexport->array_export_code as $key => $datatoexport) { $exportfile = $conf->export->dir_temp . '/' . $user->id . '/export_' . $datatoexport . '.csv'; print "Process export for dataset " . $datatoexport . " into " . $exportfile . "\n"; dol_delete_file($exportfile); // Generate $array_selected $i = 0; $array_selected = array(); foreach ($objexport->array_export_fields[$key] as $key => $val) { $array_selected[$key] = $i++; } //var_dump($array_selected); // Build export file $sql = ""; $result = $objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); $expectedresult = 1; $this->assertEquals($result, $expectedresult, 'Call build_file to export ' . $exportfile . ' failed'); $result = dol_is_file($exportfile); $this->assertTrue($result, $expectedresult, 'File ' . $exportfile . ' not found'); } return true; }