function add_normalizer($sid, $dataSource_dir, $dataSource_dirPath)
{
    $ktrManagers = unserialize($_SESSION["ktrArguments_{$sid}"]["ktrManagers"]);
    $dataMatchingUserInputs = $_POST["dataMatchingUserInputs"];
    if (!isset($_POST["dataMatchingUserInputs"])) {
        throw new Exception("Invalid arguments");
    }
    foreach ($ktrManagers as $filename => &$ktrManager) {
        $dataMatchingUserInputsForATable = array();
        $baseHeader = $_SESSION["ktrArguments_{$sid}"][$filename]['baseHeader'];
        $sheetNamesRowsColumns = $_SESSION["ktrArguments_{$sid}"][$filename]["sheetNamesRowsColumns"];
        $replaceCount = 1;
        foreach ($dataMatchingUserInputs as &$value) {
            if ($value["tableName"] == $filename) {
                $value["originalDname"] = str_replace("{$filename}.", '', $value["originalDname"], $replaceCount);
                $dataMatchingUserInputsForATable[] = $value;
            }
        }
        $ktrManager->createTemplate($sheetNamesRowsColumns, $baseHeader, $dataMatchingUserInputsForATable);
    }
    $_SESSION["ktrArguments_{$sid}"]["ktrManagers"] = serialize($ktrManagers);
    UtilsForWizard::processDataMatchingUserInputsWithTableNameStoreDB($sid, $_POST["dataMatchingUserInputs"]);
}
 static function getUnits($selectedValue)
 {
     $queryEngine = new QueryEngine();
     $types = $queryEngine->simpleQuery->getUnits($selectedValue);
     $typesHtml = UtilsForWizard::generateUnitsInHtml($types);
     return $typesHtml;
 }
 public static function getJoinQuery($sids, $cols, $perPage, $pageNo)
 {
     global $db;
     $finalQuery = "";
     $finalQueryJoinWherePart = "";
     if (count($sids) == 1) {
         $sid = UtilsForWizard::getWordUntilFirstDot($sids[0]);
         $tableName = UtilsForWizard::stripWordUntilFirstDot($sids[0]);
         $sourceType = ExternalMSSQL::GetSourceType($sid);
         if ($sourceType == "data file") {
             return ExternalMSSQL::wrapInLimit($pageNo, $perPage, $tableName);
         } else {
             $colsString = "'" . implode("','", $cols) . "'";
             $query = ExternalMSSQL::makeQueryToRotateTable($sid, $tableName, $colsString);
             $finalQuery = $query;
             return ExternalMSSQL::wrapInLimit($pageNo, $perPage, "(" . $finalQuery . ") as b");
         }
     } else {
         for ($i = 0; $i < count($sids) - 1; $i++) {
             $sidFrom = UtilsForWizard::getWordUntilFirstDot($sids[$i]);
             $tableNameFrom = UtilsForWizard::stripWordUntilFirstDot($sids[$i]);
             $sourceTypeFrom = ExternalMSSQL::GetSourceType($sidFrom);
             if ($sourceTypeFrom == "data file") {
                 $colsResult = ExternalMSSQL::getAllTableNameDotColumnsBySid($sidFrom, $tableNameFrom);
                 $colsRenamed = $colsResult->colsRenamed;
                 $finalQuery .= "(select {$colsRenamed} from {$tableNameFrom}) as rot{$i}, ";
             } else {
                 $colsString = "'" . implode("','", $cols) . "'";
                 $query = ExternalMSSQL::makeQueryToRotateTable($sidFrom, $tableNameFrom, $colsString, $perPage, $pageNo);
                 $finalQuery .= "({$query}) as rot{$i}, ";
             }
             $sidTo = UtilsForWizard::getWordUntilFirstDot($sids[$i + 1]);
             $tableNameTo = UtilsForWizard::stripWordUntilFirstDot($sids[$i + 1]);
             $sourceTypeTo = ExternalMSSQL::GetSourceType($sidTo);
             $finalQueryJoinWherePart .= ExternalMSSQL::getWhereJoinPart($i, $sidFrom, $tableNameFrom, $sidTo, $tableNameTo, $sourceTypeFrom, $sourceTypeTo);
         }
         $sidFrom = UtilsForWizard::getWordUntilFirstDot($sids[count($sids) - 1]);
         $tableNameFrom = UtilsForWizard::stripWordUntilFirstDot($sids[count($sids) - 1]);
         $sourceType = ExternalMSSQL::GetSourceType($sidFrom);
         if ($sourceType == "data file") {
             $colsResult = ExternalMSSQL::getAllTableNameDotColumnsBySid($sidFrom, $tableNameFrom);
             $colsRenamed = $colsResult->colsRenamed;
             $finalQuery .= "(select {$colsRenamed} from {$tableNameFrom}) as rot" . (count($sids) - 1);
         } else {
             $colsString = "'" . implode("','", $cols) . "'";
             $query = ExternalMSSQL::makeQueryToRotateTable($sidFrom, $tableNameFrom, $colsString, $perPage, $pageNo);
             $finalQuery .= "({$query}) as rot" . (count($sids) - 1);
         }
         if ($finalQueryJoinWherePart != "") {
             $finalQueryJoinWherePart = substr($finalQueryJoinWherePart, 0, -4);
         }
         $finalQuery = "select * from {$finalQuery} where {$finalQueryJoinWherePart}";
         return ExternalMSSQL::wrapInLimit($pageNo, $perPage, "(" . $finalQuery . ") as b");
     }
 }
function Execute($sid, DatabaseHandler $dbHandler, $userId)
{
    $inputData = $_POST;
    try {
        $queryEngine = new QueryEngine();
        $queryEngine->simpleQuery->addSourceDBInfo($sid, $dbHandler->getHost(), $dbHandler->getPort(), $dbHandler->getUser(), $dbHandler->getPassword(), $dbHandler->getDatabase(), $dbHandler->getDriver(), $dbHandler->getIsImpoted(), $dbHandler->getLinkedServerName());
        UtilsForWizard::processDataMatchingUserInputsStoreDB($sid, $inputData["dataMatchingUserInputs"]);
        $queryEngine->simpleQuery->setSourceTypeBySid($sid, 'database');
        $resultJson = new stdClass();
        $resultJson->isSuccessful = true;
        $resultJson->message = 'Success!';
        echo json_encode($resultJson);
        // If a dump file is uploaded, start importing data in the background.
        if (isset($_SESSION["dump_file_{$sid}"])) {
            ExecutionManager::callChildProcessToImportDumpFile($sid, $userId, $dbHandler, $_SESSION["dump_file_{$sid}"]);
        }
        unset($_SESSION["dump_file_{$sid}"]);
    } catch (Exception $e) {
        $resultJson = new stdClass();
        $resultJson->isSuccessful = false;
        $resultJson->message = $e->getMessage();
        echo json_encode($resultJson);
    }
}