<?php
//require_once('includes/checksession.php');
require_once('includes/connection.php');
require_once('includes/template.php');
/*require_once('includes/func.getUserID.php');
$id_user = getUserID($connection);
if (!$id_user){
	echo 'Error: login';
	exit();
}*/

openHeader('Project XYZ', '/project-xyz/styles/styles.css');
openBody('Categorias disponibles','mainPage', $connection);

$query = <<<EOD
SELECT *
FROM categories_photos cp, photos p
WHERE p.id_photo=cp.id_photo
AND p.status_photo=1
ORDER BY cp.id_category_photo ASC
EOD;

if(!($res = mysql_query($query, $connection))){
	echo 'KO';
	exit();
}

$array_cat_photo = array();

while ($file = mysql_fetch_assoc($res)){

$array_cat_photo[$file['id_category']] = $file['name_photo'];
}

$query = <<<EOD
SELECT *
FROM categories
WHERE status = 1
ORDER BY name_category
EOD;

$res = mysql_query($query,$connection);
$categoryList = '';
while ($category = mysql_fetch_assoc($res)){
$photo = $array_cat_photo[$category['id_category']];
$id_category = $category['id_category'];
	$categoryList .= <<<EOD

{$category['name_category']}

EOD;
}
?>

<?php
echo $categoryList;
?>

<?php
closeBody();
?>


Currency.create currency: 'USD'
Currency.create currency: 'EUR'

OptionType.create option_type: 'ETO'
OptionType.create option_type: 'OTC'

QuoteName.create quote_name: 'IPE Brent'
QuoteName.create quote_name: 'IPE Gas Oil'
QuoteName.create quote_name: 'NYMEX WTI'
QuoteName.create quote_name: 'NYMEX Heat'
QuoteName.create quote_name: 'NYMEX Brent'
QuoteName.create quote_name: 'NYMEX RBOB'
QuoteName.create quote_name: 'ICE WTI'
QuoteName.create quote_name: 'ICE RBOB'
QuoteName.create quote_name: 'ICE Heat'


// # Client API
// RESTful API for the Client resource
var Promise = require('bluebird'),
    _ = require('lodash'),
    pipeline = require('../utils/pipeline'),
    apiUtils = require('./utils'),
    models = require('../models'),
    common = require('../lib/common'),
    docName = 'clients',
    clients;

/**
 * ### Clients API Methods
 *
 * **See:** [API Methods](events.js.html#api%20methods)
 */
clients = {

    /**
     * ## Read
     * @param {{id}} options
     * @return {Promise<Client>} Client
     */
    read: function read(options) {
        var attrs = ['id', 'slug'],
            tasks;

        /**
         * ### Model Query
         * Make the call to the Model layer
         * @param {Object} options
         * @returns {Object} options
         */
        function doQuery(options) {
            // only User Agent (type = `ua`) clients are available at the moment.
            options.data = _.extend(options.data, {type: 'ua'});

            return models.Client.findOne(options.data, _.omit(options, ['data']))
                .then(function onModelResponse(model) {
                    if (!model) {
                        return Promise.reject(new common.errors.NotFoundError({
                            message: common.i18n.t('common.api.clients.clientNotFound')
                        }));
                    }

                    return {
                        clients: [model.toJSON(options)]
                    };
                });
        }

        // Push all of our tasks into a `tasks` array in the correct order
        tasks = [
            apiUtils.validate(docName, {attrs: attrs}),
            // TODO: add permissions
            // utils.handlePublicPermissions(docName, 'read'),
            doQuery
        ];

        // Pipeline calls each task passing the result of one to be the arguments for the next
        return pipeline(tasks, options);
    }
};

module.exports = clients;