function ParsePeriod($string)
{
    $arrayz = ParsePeriodForSearch($string);
    $sep = "";
    foreach ($arrayz as $year) {
        $exiz = $exiz . $sep . $year;
        $sep = ",";
    }
    return $exiz;
}
function render_user_listarResultados($param)
{
    $col = GetCols('documentos');
    $tbl = GetTable('documentos');
    list($db) = Getdb();
    if (vwSessionGetVar('search') == "new") {
        list($cond1, $cond2, $cond3, $cond4, $cond5, $cond6, $cond7, $cond8) = vwVarFromInput('cond1', 'cond2', 'cond3', 'cond4', 'cond5', 'cond6', 'cond7', 'cond8');
        list($aid, $sid, $signatura, $folios, $siglos, $periodo, $resumen, $notas) = vwVarFromInput('aid', 'sid', 'signatura', 'folios', 'siglos', 'periodo', 'resumen', 'notas');
        $ft1 = true;
        $ft2 = true;
        $condiciones = array();
        if (trim($aid) != "") {
            $semaforo = true;
            if ($cond1 != "REQ") {
                $semaforo = false;
            }
            $condiciones[] = array("condicion" => "{$col['aid']}=" . trim($aid), "requerido" => $semaforo);
        }
        if (trim($sid) != "") {
            $semaforo = true;
            if ($cond2 != "REQ") {
                $semaforo = false;
            }
            $condiciones[] = array("condicion" => "{$col['sid']}=" . trim($sid), "requerido" => $semaforo);
        }
        if (trim($signatura) != "") {
            $semaforo = true;
            if ($cond3 != "REQ") {
                $semaforo = false;
            }
            $condiciones[] = array("condicion" => "{$col['signatura']} like '%" . htmlentities(trim($signatura), ENT_QUOTES) . "%'", "requerido" => $semaforo);
        }
        if (trim($folios) != "") {
            $semaforo = true;
            if ($cond4 != "REQ") {
                $semaforo = false;
            }
            $condiciones[] = array("condicion" => "{$col['folios']} like '%" . htmlentities(trim($folios), ENT_QUOTES) . "%'", "requerido" => $semaforo);
        }
        if (trim($siglos) != "") {
            $semaforo = true;
            if ($cond5 != "REQ") {
                $semaforo = false;
            }
            $condiciones[] = array("condicion" => "{$col['siglos']} like '%" . htmlentities(trim($siglos), ENT_QUOTES) . "%'", "requerido" => $semaforo);
        }
        if (trim($periodo) != "") {
            $semaforo = true;
            if ($cond6 != "REQ") {
                $semaforo = false;
            }
            $items = ParsePeriodForSearch($periodo);
            $condicion = "";
            $prev = "";
            $semaforo1 = false;
            foreach ($items as $item) {
                if (!$semaforo1) {
                    $semaforo1 = true;
                    $prev = " OR ";
                }
                $condicion = $condicion . $prev . " {$col['periodo']} like '%{$item}%'";
                $semaforo1 = true;
            }
            if (trim($condicion) != "") {
                $condiciones[] = array("condicion" => "({$condicion})", "requerido" => $semaforo);
            }
        }
        if (trim($resumen) != "") {
            $resumen = str_replace("'", "", $resumen);
            $semaforo = true;
            if ($cond7 != "REQ") {
                $semaforo = false;
            }
            $condiciones[] = array("condicion" => " MATCH ({$col['resumen']}) AGAINST ('" . htmlentities(trim($resumen), ENT_NOQUOTES) . "' IN BOOLEAN MODE)", "requerido" => $semaforo);
            $ft1 = " MATCH ({$col['resumen']}) AGAINST ('" . htmlentities(trim($resumen), ENT_NOQUOTES) . "' IN BOOLEAN MODE) AS puntuaje1";
        }
        if (trim($notas) != "") {
            $notas = str_replace("'", "", $notas);
            $semaforo = true;
            if ($cond8 != "REQ") {
                $semaforo = false;
            }
            $condiciones[] = array("condicion" => " MATCH ({$col['notas']}) AGAINST ('" . htmlentities(trim($notas), ENT_NOQUOTES) . "' IN BOOLEAN MODE)", "requerido" => $semaforo);
            $ft2 = " MATCH ({$col['notas']}) AGAINST ('" . htmlentities(trim($notas), ENT_NOQUOTES) . "' IN BOOLEAN MODE) AS puntuaje2";
        }
        $sqlwhere = "";
        $semaforo = false;
        foreach ($condiciones as $condicion) {
            if (!$semaforo) {
                $sqlwhere = $condicion['condicion'];
                $semaforo = true;
            } else {
                switch ($condicion['requerido']) {
                    case false:
                        $sqlwhere = $sqlwhere . " OR {$condicion['condicion']}";
                        break;
                    case true:
                        $sqlwhere = "({$sqlwhere}) AND {$condicion['condicion']}";
                        break;
                }
            }
        }
        if ($ft1 != true || $ft2 != true) {
            if ($ft1 != true && $ft2 != true) {
                $sql2 = "SELECT *, {$ft1},{$ft2} FROM {$tbl} WHERE {$sqlwhere} ORDER BY puntuaje1 desc, puntuaje2 desc;";
            } else {
                if ($ft2 == true) {
                    $sql2 = "SELECT *, {$ft1} FROM {$tbl} WHERE {$sqlwhere};";
                } else {
                    $sql2 = "SELECT *, {$ft2} FROM {$tbl} WHERE {$sqlwhere};";
                }
            }
        } else {
            $sql2 = "SELECT * FROM {$tbl} WHERE {$sqlwhere} ";
        }
        vwSessionSetVar('sqlsearch', $sql2);
        //vwSessionSetVar('sqlbase',$sqlbase);
        vwSessionSetVar('sqlwhere', $sqlwhere);
        vwSessionSetVar('search', "no");
    } else {
        $sql2 = vwSessionGetVar('sqlsearch');
        $sqlwhere = vwSessionGetVar('sqlwhere');
    }
    $sf = $param['start'] + 0;
    $rs = $db->SelectLimit($sql2, 25, $sf);
    if ($rs === false) {
        $mensaje = "Ha generado una busqueda incorrecta, revise los datos introducidos";
    } else {
        $items = $rs->GetRows();
        if (trim($items[0][$col['aid']] < 1)) {
            $mensaje = "No hay registros que cumplan sus criterios de busqueda";
        }
    }
    /* Aqui comienza el uso del nuevo Lister .... */
    $Cols = array(array("dbname" => $col['aid'], "showcall" => array("funcion" => 'cbzArchivos', "valor" => $col['aid'])), array("dbname" => $col['sid'], "showcall" => array("funcion" => 'cbzSecciones', "valor" => $col['sid'])), array("dbname" => $col['periodo'], "showcall" => array("funcion" => 'cbzPeriodo', "valor" => $col['periodo'])), array("dbname" => "EXTRA", "showcall" => array("funcion" => 'cbzRecursos', "valor" => $col['did'])));
    $options = array(array('funcion' => 'cbzMasInfo', 'valor' => $col['did']));
    $lister = new freeLister("usrListado", "freeLister1.css", "resultDocs.tpl", $col['did'], 25, $Cols, $options, $sqlwhere, $sql2);
    $lister->SetStart($param['start'] + 0);
    $z = $lister->render();
    return $z;
}