<commit_before><?php

function mktimeDate ($date)
{
    $arrayAux = getdate( strtotime( $date ) );

    $mktDate = mktime( $arrayAux["hours"], $arrayAux["minutes"], $arrayAux["seconds"], $arrayAux["mon"], $arrayAux["mday"], $arrayAux["year"] );

    return $mktDate;
}

function cronArraySet ($str, $filter)
{
    $arrayAux = explode( "|", $str );

    $date = "";
    $workspace = "";
    $action = "";
    $status = "";
    $description = trim( $arrayAux[0] );

    if (count( $arrayAux ) > 1) {
        $date = (isset( $arrayAux[0] )) ? trim( $arrayAux[0] ) : "";
        $workspace = (isset( $arrayAux[1] )) ? trim( $arrayAux[1] ) : "";
        $action = (isset( $arrayAux[2] )) ? trim( $arrayAux[2] ) : "";
        $status = (isset( $arrayAux[3] )) ? trim( $arrayAux[3] ) : "";
        $description = (isset( $arrayAux[4] )) ? trim( $arrayAux[4] ) : "";
    }

    $mktDate = (! empty( $date )) ? mktimeDate( $date ) : 0;

    //Filter
    $sw = 1;

    if ($filter["workspace"] != "ALL" && $workspace != $filter["workspace"]) {
        $sw = 0;
    }

    if ($filter["status"] != "ALL") {
        switch ($filter["status"]) {
            case "COMPLETED":
                if ($status != "action") {
                    $sw = 0;
                }
                break;
            case "FAILED":
                if ($status == "action") {
                    $sw = 0;
                }
                break;
        }
    }

    if (! empty( $filter["dateFrom"] ) && $mktDate > 0) {
        if (! (mktimeDate( $filter["dateFrom"] ) <= $mktDate)) {
            $sw = 0;
        }
    }

    if (! empty( $filter["dateTo"] ) && $mktDate > 0) {
        if (! ($mktDate <= mktimeDate( $filter["dateTo"] . " 23:59:59" ))) {
            $sw = 0;
        }
    }

    $arrayData = array ();

    if ($sw == 1) {
        $arrayData = array ("DATE" => $date,"WORKSPACE" => $workspace,"ACTION" => $action,"STATUS" => $status,"DESCRIPTION" => $description
        );
    }

    return $arrayData;
}

function cronDataGet ($filter, $r, $i)
{
    $r = $r + 1; //+ 1, to determine the next page
    $i = $i + 1;

    $arrayData = array ();
    $strAux = null;
    $numRec = 0;
    $cont = 0;

    $file = PATH_DATA . "log" . PATH_SEP . "cron.log";

    if (file_exists( $file )) {
        $fh = fopen( $file, "r" );

        for ($pos = 0; fseek( $fh, $pos, SEEK_END ) !== - 1; $pos --) {
            $char = fgetc( $fh );

            if ($char == "\n") {
                $strAux = trim( $strAux );

                if (! empty( $strAux )) {
                    $arrayAux = cronArraySet( $strAux, $filter );

                    if (count( $arrayAux ) > 0) {
                        $cont = $cont + 1;

                        if ($cont >= $i && count( $arrayData ) + 1 <= $r) {
                            $arrayData[] = $arrayAux;
                            $numRec = $cont;
                        }
                    }
                }

                if (count( $arrayData ) == $r) {
                    break;
                }

                $strAux = null;
                $char = null;
            }

            $strAux = $char . $strAux;
        }

        $strAux = trim( $strAux );

        if (! empty( $strAux )) {
            $arrayAux = cronArraySet( $strAux, $filter );

            if (count( $arrayAux ) > 0) {
                $cont = $cont + 1;

                if ($cont >= $i && count( $arrayData ) + 1 <= $r) {
                    $arrayData[] = $arrayAux;
                    $numRec = $cont;
                }
            }
        }

        fclose( $fh );
    }

    //Delete element
    $r = $r - 1;

    if (count( $arrayData ) > $r) {
        $arrayAux = array_pop( $arrayData );
    }

    return array ($numRec,$arrayData
    );
}

$option = (isset( $_REQUEST["option"] )) ? $_REQUEST["option"] : null;

$response = array ();

switch ($option) {
    case "LST":<commit_msg>BUG 11214 "No se realiza la paginacion correcta en..." SOLVED<commit_after><?php

function mktimeDate ($date)
{
    $arrayAux = getdate( strtotime( $date ) );

    $mktDate = mktime( $arrayAux["hours"], $arrayAux["minutes"], $arrayAux["seconds"], $arrayAux["mon"], $arrayAux["mday"], $arrayAux["year"] );

    return $mktDate;
}

function cronArraySet ($str, $filter)
{
    $arrayAux = explode( "|", $str );

    $date = "";
    $workspace = "";
    $action = "";
    $status = "";
    $description = trim( $arrayAux[0] );

    if (count( $arrayAux ) > 1) {
        $date = (isset( $arrayAux[0] )) ? trim( $arrayAux[0] ) : "";
        $workspace = (isset( $arrayAux[1] )) ? trim( $arrayAux[1] ) : "";
        $action = (isset( $arrayAux[2] )) ? trim( $arrayAux[2] ) : "";
        $status = (isset( $arrayAux[3] )) ? trim( $arrayAux[3] ) : "";
        $description = (isset( $arrayAux[4] )) ? trim( $arrayAux[4] ) : "";
    }

    $mktDate = (! empty( $date )) ? mktimeDate( $date ) : 0;

    //Filter
    $sw = 1;

    if ($filter["workspace"] != "ALL" && $workspace != $filter["workspace"]) {
        $sw = 0;
    }

    if ($filter["status"] != "ALL") {
        switch ($filter["status"]) {
            case "COMPLETED":
                if ($status != "action") {
                    $sw = 0;
                }
                break;
            case "FAILED":
                if ($status == "action") {
                    $sw = 0;
                }
                break;
        }
    }

    if (! empty( $filter["dateFrom"] ) && $mktDate > 0) {
        if (! (mktimeDate( $filter["dateFrom"] ) <= $mktDate)) {
            $sw = 0;
        }
    }

    if (! empty( $filter["dateTo"] ) && $mktDate > 0) {
        if (! ($mktDate <= mktimeDate( $filter["dateTo"] . " 23:59:59" ))) {
            $sw = 0;
        }
    }

    $arrayData = array ();

    if ($sw == 1) {
        $arrayData = array ("DATE" => $date,"WORKSPACE" => $workspace,"ACTION" => $action,"STATUS" => $status,"DESCRIPTION" => $description
        );
    }

    return $arrayData;
}

function cronDataGet ($filter, $r, $i)
{
    $i = $i + 1;

    $arrayData = array ();
    $strAux = null;
    $numRec = 0;
    $cont = 0;

    $file = PATH_DATA . "log" . PATH_SEP . "cron.log";

    if (file_exists($file)) {
        $arrayFileData = file($file);

        for ($k = 0; $k <= count($arrayFileData) - 1; $k++) {
            $strAux = $arrayFileData[$k];

            if (!empty($strAux)) {
                $arrayAux = cronArraySet($strAux, $filter);

                if (count($arrayAux) > 0) {
                    $cont = $cont + 1;

                    if ($cont >= $i && count($arrayData) + 1 <= $r) {
                        $arrayData[] = $arrayAux;
                    }
                }
            }
        }
    }

    $numRec = $cont;

    return array($numRec, $arrayData);
}

$option = (isset( $_REQUEST["option"] )) ? $_REQUEST["option"] : null;

$response = array ();

switch ($option) {
    case "LST":
{'fraction_non_alphanumeric': 0.19570890113076253, 'fraction_numerical': 0.012032473180632067, 'mean_word_length': 1.6172230652503794, 'pattern_counts': {'":': 6, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4812638', 'n_tokens_mistral': 2487, 'n_tokens_neox': 2322, 'n_words': 497}