<?php header ('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
require_once "C:/Archivos de programa/NuSphere/TechPlat/apache/htdocs/castellon/cmsAdmin/lib/viewer_functions.php";

list($categorias_empresasRecords, $selectedCategory)=getCategories(array
    (
    'tableName' => 'categorias_empresas',
    'selectedCategoryNum' => 'subcat',
    ));

list($empresasRecords, $empresasMetaData)=getRecords(array
    (
    'tableName' => 'empresas',
    'orderBy' => 'title ASC, cat, subcat',
    'perPage' => '15',
    ));
?>
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv = "content-type" content = "text/html;charset=UTF-8" />

        <meta name = "keywords" content = ""></meta>

        <meta name = "description" content = ""></meta>

        <meta http-equiv = "imagetoolbar" content = "no" />

        <link rel = "stylesheet" href = "css/screen.css" media = "screen" />

        <script type = "text/javascript" src = "js/jquery.js">
        </script>

        <script type = "text/javascript" src = "js/easy.js">
        </script>

        <script type = "text/javascript" src = "js/main.js">
        </script>
    </head>

    <body>
        <div id = "container">
            <div class = "row row1">
                <div class = "col2">
                    <!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
                    <h1>Empresas</h1>

                <?php if (isset($selectedCategory['breadcrumb'])): ?>

                    <h5><?php echo $selectedCategory['breadcrumb']; ?></h5>

                    <?php
                endif
                    ?>

                    <?php
                foreach ($empresasRecords as $record):
                    $cate=$record['subcat'];
                    list($categoria_empresasRecords, $categoria_empresasMetaData)=getRecords(array
                        (
                        'tableName' => 'categorias_empresas',
                        'where' => "num='$cate'",
                        'limit' => '1',
                        ));
                    ?>

                    <a href = "<?php echo $record['_link'] ?>">

                <?php echo $record['title'] ?></a>

                    <br />

                <?php if (!isset($selectedCategory['breadcrumb'])): ?>

                    <small>

                    <?php
                    if (isset($categoria_empresasRecords[0]["breadcrumb"]))
                        {
                        echo $categoria_empresasRecords[0]["breadcrumb"];
                        }
                    else
                        {
                        echo "Empresa no catalogada en la base de datos";
                        }
                    ?>

                    </small>

                    <br />

                    <?php
                endif
                    ?>

                    <?php
                endforeach
                    ?>

                <?php if (!$empresasRecords): ?>

                    No records were found!

                    <br />

                    <br />

                    <?php
                    endif
                    ?>
                    <!-- /STEP2: Display Records -->

                    <br />
                    <!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") -->

                    <?php if ($empresasMetaData['totalPages'] > 1): ?>

                        <?php if ($empresasMetaData['prevPage']): ?>

                        <a href = "<?php echo $empresasMetaData['prevPageLink'] ?>">&lt;&lt; anterior</a>

                        <?php else: ?>

                        &lt;&lt; anterior

                        <?php
                        endif
                        ?>

                        - p&aacute;gina

                        <?php echo $empresasMetaData['page'] ?>

                        de

                        <?php echo $empresasMetaData['totalPages'] ?>

                        -

                        <?php if ($empresasMetaData['nextPage']): ?>

                        <a href = "<?php echo $empresasMetaData['nextPageLink'] ?>">siguiente &gt;&gt;</a>

                        <?php else: ?>

                        siguiente &gt;&gt;

                        <?php
                        endif
                        ?>

                    <?php
                    endif
                    ?>
                <!-- /STEP3: Display Page Links -->
                </div>

                <div class = "col3">
                    <h2>Buscador</h2>

                    <form method = "POST" action = "<?php echo $_SERVER['PHP_SELF'] ?>">
                        <fieldset>
                            <div>
                                <label for = "nombre">Nombre de Empresa</label>

                                <input type = "text"
                                  name = "title_keyword"
                                  value = "<?php if (isset($_POST['title_keyword'])) { echo $_POST['title_keyword'];} ?>">
                            </div>

                            <div>
                                <label for = "poblacion">Poblaci&oacute;n</label>

                                <input type = "text"
                                  name = "poblacion_keyword"
                                  value = "<?php if (isset($_POST['poblacion_keyword'])) { echo $_POST['poblacion_keyword'];} ?>">
                            </div>

                            <div class = "submit">
                                <button type = "submit">Buscar</button>
                            </div>
                        </fieldset>
                    </form>

                    <?php
                    list($categorias_empresasRecords, $selectedCategory)=
                      getCategories(array('tableName' => 'categorias_empresas',));
                    ?>

                    <h2>Filtrar por producto</h2>

                    <p>
                        Pulsa sobre el men&uacute; para ver los productos de cada categor&iacute;a.
                    </p>

                    <ul>
                        <li><a href = "?">Mostrar todas las empresas</a></li>

                        <?php
                        foreach ($categorias_empresasRecords as $categoryRecord):
                        ?>

                            <?php echo $categoryRecord['_listItemStart'] ?>

                        <?php /* <!-- si es un child ponemos enlace --> */
                            if ($categoryRecord['parentNum'] <> 0):
                        ?>

                                <?php if ($categoryRecord['_isSelected']): ?><b>

                                <?php
                                endif
                                ?><a href = "?subcat=<?php echo $categoryRecord['num'] ?>">

                                <?php echo $categoryRecord['name'] ?></a>

                                <?php if ($categoryRecord['_isSelected']): ?></b>

                                <?php
                                endif
                                ?>&nbsp;

                                <?php
                                $sub2=$categoryRecord['num'];
                                $res=mysql_select_count_from('empresas', "subcat='$sub2' GROUP BY cat");

                                if (!isset($res))
                                    {
                                    $res=0;
                                    }

                                echo "<small>(" . $res . ")</small>";
                                ?>

                            <?php else: ?>

                        <?php
                                if (isset($selectedCategory['parentNum'])
                                  && $selectedCategory['parentNum'] == $categoryRecord['num']):
                        ?>

                        <?php
                                    echo '<div  style="cursor: pointer;" class="selected">' . $categoryRecord['name']
                        ?>

                        <?php
                                    $sub=$categoryRecord['num'];
                                    $resu=mysql_select_count_from('empresas', "cat='$sub' GROUP BY cat");

                                    if (!isset($resu))
                                        {
                                        $resu=0;
                                        }

                                    echo "<small>(" . $resu . ")</small></div>";
                        ?>

                                <?php else: ?>

                        <?php
                                    $sub=$categoryRecord['num'];
                                    $resu=mysql_select_count_from('empresas', "cat='$sub' GROUP BY cat");

                                    if (!isset($resu))
                                        {
                                        $resu=0;
                                        }

                                    echo '<div  style="cursor: pointer;" class="toggle">' . $categoryRecord['name']
                                      . '&nbsp;<small>(' . $resu . ')</small></div>'
                        ?>

                        <?php
                                endif
                        ?>

                        <?php
                            endif
                        ?>

                            <?php echo $categoryRecord['_listItemEnd'] ?>

                        <?php
                        endforeach
                        ?>
                    </ul>
                </div>
            </div>
        </div>
    </body>
</html>

