public static function generateFilesImport(IConnection $connect, $objCampaign, $folioID, $path_file, $fileType = "BOTH", $create_dir = false) { try { global $arrayDefaultHeadFieldAltitude, $servers_altitude, $database; $arrayFileDAT = array(); $arrayFileTYP = array(); if ($create_dir) { mkdir($path_file); } $nameFile = $objCampaign->getShortName() . "_" . $folioID; $rs = Customfields::getCustomFieldsListCustom($connect, $objCampaign->getCode(), 'cxc_estado=' . BLOCK_FIELD_PROTOCOL); while (@($field = $connect->getRows($rs))) { $fields_custom[$field['campo']] = array("type" => $field['tipo'], "length" => $field['longitud']); } foreach ($fields_custom as $name => $attribs) { switch (strtolower(trim($attribs['type']))) { case 'date': $arrayFileDAT[] = "DATE_FORMAT(custom.{$name},'%Y-%m-%d') "; $arrayFileTYP[] = "{$name} {$attribs['type']}"; break; case 'datetime': $arrayFileDAT[] = "DATE_FORMAT(custom.{$name},'%Y-%m-%d %T') "; $arrayFileTYP[] = "{$name} {$attribs['type']}"; break; case 'time': $arrayFileDAT[] = "custom.{$name} "; $arrayFileTYP[] = "{$name} {$attribs['type']}"; break; case 'int': $arrayFileDAT[] = "custom.{$name}"; $arrayFileTYP[] = "{$name} number(10,0)"; break; case 'double': $arrayFileDAT[] = "custom.{$name}"; $arrayFileTYP[] = "{$name} number(10,2)"; break; case 'varchar': $arrayFileDAT[] = "custom.{$name}"; $arrayFileTYP[] = "{$name} char({$attribs['length']})"; break; default: $arrayFileDAT[] = "custom.{$name}"; $arrayFileTYP[] = "{$name} {$attribs['type']}({$attribs['length']})"; break; } $i++; } //Generando file .dat if ($fileType == "DAT" || $fileType == "BOTH") { $rsData = CampaignData::getDataForFileDat($connect, $folioID, $arrayFileDAT, $objCampaign->getShortName(), "SE"); $file = $path_file . DIRECTORY_SEPARATOR . $nameFile . ".dat"; $pointer = fopen($file, "w+"); if ($pointer !== FALSE) { while ($field = $connect->getRows($rsData)) { foreach ($field as $value) { fputs($pointer, $value . "|"); } fputs($pointer, chr(13) . chr(10)); } fclose($pointer); } else { throw new MyException("Error no se pudo crear archivo .DAT"); } } //Generando file .typ if ($fileType == "TYP" || $fileType == "BOTH") { $file = $path_file . DIRECTORY_SEPARATOR . $nameFile . ".typ"; $pointer = fopen($file, "w+"); if ($pointer === FALSE) { throw new MyException("Error no se pudo crear archivo .TYP"); } $i = 0; $arrayHeadLength = array(); if (strtolower(COUNTRY_KEY) == 'ec') { $serverAtt = trim($objCampaign->getServerAltitude()) == "" ? SERVER_NORMAL : trim($objCampaign->getServerAltitude()); $connectSQL = Util::createConnection(ENGINE_SQLSERVER, $database[$servers_altitude["{$serverAtt}"]['altitude']]); $connectSQL->connect(); $rsDataAltitude = Altitude::getTableSchemaTypeData($connectSQL, $objCampaign->getShortName()); while ($data = $connectSQL->getRows($rsDataAltitude)) { $arrayHeadLength[$data['columna']]['tipo'] = $data['type']; $arrayHeadLength[$data['columna']]['longitud'] = $data['longitud']; } } foreach ($arrayDefaultHeadFieldAltitude as $key => $value) { if ($i != 0) { fputs($pointer, chr(13) . chr(10)); } else { $i = 1; } if (startsWith("*", $value)) { $value = str_replace("*", "", $value); if ($arrayHeadLength[$value]['tipo'] == 'varchar') { $value = $value . " char({$arrayHeadLength[$value]['longitud']})"; } } fputs($pointer, $value); } fputs($pointer, chr(13) . chr(10)); $i = 0; foreach ($arrayFileTYP as $value) { if ($i != 0) { fputs($pointer, chr(13) . chr(10)); } else { $i = 1; } fputs($pointer, $value); } fclose($pointer); } return $nameFile; } catch (MyException $ex) { throw $ex; } }