*
 *  @author PrestaShop SA <*****@*****.**>
 *  @copyright  2007-2014 PrestaShop SA
 *  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 *  International Registered Trademark & Property of PrestaShop SA
 */
include_once 'lib/includes/includes.inc.php';
require_once dirname(__FILE__) . '/../../config/config.inc.php';
require_once dirname(__FILE__) . '/../../init.php';
include_once 'fianetsceau.php';
if (_PS_VERSION_ < '1.5') {
    $sceau = new Sceau();
} else {
    $sceau = new Sceau(Tools::getValue('id_shop'));
}
if (Tools::getValue('token') == Tools::getAdminToken($sceau->getSiteid() . $sceau->getAuthkey() . $sceau->getLogin())) {
    $category_id = Tools::getValue('category_id');
    $elem_id = Tools::getValue('elem_id');
    $module = new FianetSceau();
    $subcategory = $module->loadFianetSubCategories($category_id);
    if ($category_id == '0') {
        $select = "";
    } else {
        $select = "<select id='fianetsceau_" . $elem_id . "_subcategory' name='fianetsceau_" . $elem_id . "_subcategory'>";
        foreach ($subcategory as $value) {
            $select .= "<option value=" . $value['subcategory_id'] . ">" . $value['label'] . "</option>";
        }
        $select .= "</select>";
    }
    echo $select;
} else {
 public function getContent()
 {
     $head_msg = '';
     //if some POST datas are found
     //Get log file
     $log_content = htmlentities(SceauLogger::getLogContent());
     if (_PS_VERSION_ < '1.5') {
         $id_shop = 1;
         $fianetsceau = new Sceau();
     } else {
         $id_shop = Context::getContext()->shop->id;
         $fianetsceau = new Sceau($id_shop);
     }
     //include FIA-NET categories array
     include _PS_MODULE_DIR_ . 'fianetsceau/lib/includes/fianetcategories.inc.php';
     if (Tools::isSubmit('submitSettings')) {
         //if the form is correctly saved
         if ($this->processForm()) {
             //adds a confirmation message
             $head_msg = $this->displayConfirmation($this->l('Configuration updated.'));
         } else {
             //if errors have been encountered while validating the form
             //add an error message informing about errors that have been encountered
             $error_msg = $this->l('Some errors have been encoutered while updating configuration.');
             $error_msg .= '<ul>';
             foreach ($this->_errors as $error_label) {
                 $error_msg .= '<li>' . $error_label . '</li>';
             }
             $error_msg .= '</ul>';
             $head_msg = $this->displayError($error_msg);
         }
         //if submit form, we save data form
         $login = Tools::isSubmit('fianetsceau_login') ? Tools::getValue('fianetsceau_login') : $fianetsceau->getLogin();
         $password = Tools::isSubmit('fianetsceau_password') ? Tools::getValue('fianetsceau_password') : $fianetsceau->getPassword();
         $siteid = Tools::isSubmit('fianetsceau_siteid') ? Tools::getValue('fianetsceau_siteid') : $fianetsceau->getSiteid();
         $authkey = Tools::isSubmit('fianetsceau_authkey') ? Tools::getValue('fianetsceau_authkey') : $fianetsceau->getAuthkey();
         $status = Tools::isSubmit('fianetsceau_status') ? Tools::getValue('fianetsceau_status') : $fianetsceau->getStatus();
         $fianetsceau_logo_position = Tools::getValue('fianetsceau_logo_position');
         $fianetsceau_widget_position = Tools::getValue('fianetsceau_widget_position');
         $fianetsceau_logo = Tools::getValue('fianetsceau_logo_sizes');
         $widget_number = Tools::getValue('fianetsceau_widget_number');
         $show_status = Tools::getValue('fianetsceau_showstatus');
         $fianetsceau_default_category = Tools::getValue('fianetsceau_0_category');
         $fianetsceau_default_subcategory = Tools::getValue('fianetsceau_0_subcategory');
     } else {
         //if no submit form and 0 value in database, we put a defaut value
         $login = Configuration::get('FIANETSCEAU_LOGIN') === false ? '' : Configuration::get('FIANETSCEAU_LOGIN');
         $password = Configuration::get('FIANETSCEAU_PASSWORD') === false ? '' : Configuration::get('FIANETSCEAU_PASSWORD');
         $siteid = Configuration::get('FIANETSCEAU_SITEID') === false ? '' : Configuration::get('FIANETSCEAU_SITEID');
         $authkey = Configuration::get('FIANETSCEAU_AUTHKEY') === false ? '' : Configuration::get('FIANETSCEAU_AUTHKEY');
         $status = Configuration::get('FIANETSCEAU_STATUS') === false ? 'test' : Configuration::get('FIANETSCEAU_STATUS');
         $fianetsceau_logo_position = Configuration::get('FIANETSCEAU_LOGO_POSITION') === false ? 'left' : Configuration::get('FIANETSCEAU_LOGO_POSITION');
         $fianetsceau_widget_position = Configuration::get('FIANETSCEAU_WIDGET_POSITION') === false ? 'left' : Configuration::get('FIANETSCEAU_WIDGET_POSITION');
         $fianetsceau_logo = Configuration::get('FIANETSCEAU_LOGO_SIZE') === false ? '120' : Configuration::get('FIANETSCEAU_LOGO_SIZE');
         $widget_number = Configuration::get('FIANETSCEAU_WIDGET_NUMBER') === false ? '1' : Configuration::get('FIANETSCEAU_WIDGET_NUMBER');
         $show_status = Configuration::get('FIANETSCEAU_SHOW_STATUS_ORDER') === false ? '0' : Configuration::get('FIANETSCEAU_SHOW_STATUS_ORDER');
         $fianetsceau_default_subcategory = $this->getFianetSubCategoryId(0, $id_shop);
         $fianetsceau_default_category = $this->getFianetCategoryId($fianetsceau_default_subcategory);
     }
     //token
     $token = Tools::getAdminToken($fianetsceau->getSiteid() . $fianetsceau->getAuthkey() . $fianetsceau->getLogin());
     //listing payment type of the shop
     $payment_modules = $this->loadPaymentMethods();
     //lists all categories
     $shop_categories = $this->loadProductCategories();
     $base_url = __PS_BASE_URI__;
     $logo_sizes = array();
     foreach ($this->_fianetsceau_logo_sizes as $size => $img_name) {
         $logo_sizes[$size] = $base_url . 'modules/' . $this->name . '/img/' . $img_name;
     }
     $iso_lang_current = $this->context->language->iso_code;
     //give smarty data to the view
     $this->smarty->assign(array('head_message' => $head_msg, 'image_path' => $base_url . 'modules/' . $this->name . '/img/sceaudeconfiance.png', 'fianetsceau_login' => Tools::safeOutput($login), 'fianetsceau_password' => Tools::safeOutput($password), 'fianetsceau_siteid' => Tools::safeOutput($siteid), 'fianetsceau_authkey' => Tools::safeOutput($authkey), 'fianetsceau_status' => Tools::safeOutput($status), 'fianetsceau_statuses' => $this->_fianetsceau_statuses, 'payment_modules' => $payment_modules, 'fianetsceau_payment_types' => $this->_payment_types, 'logo_account_path' => $base_url . 'modules/' . $this->name . '/img/account.gif', 'logo_payments_path' => $base_url . 'modules/' . $this->name . '/img/payments.gif', 'fianetsceau_logo_positions' => $this->_fianetsceau_positions[$iso_lang_current], 'fianetsceau_logo_position' => Tools::safeOutput($fianetsceau_logo_position), 'fianetsceau_logo_sizes' => $logo_sizes, 'fianetsceau_logo' => (int) $fianetsceau_logo, 'fianetsceau_widget_positions' => $this->_fianetsceau_positions[$iso_lang_current], 'fianetsceau_widget_position' => Tools::safeOutput($fianetsceau_widget_position), 'fianetsceau_widget_numbers' => array_keys($this->_fianetsceau_widgets), 'widget_number' => (int) $widget_number, 'path_prefix' => $base_url . 'modules/' . $this->name . '/img', 'fianetsceaushow_status' => (int) $show_status, 'log_content' => $log_content, 'shop_categories' => $shop_categories, 'fianetsceau_default_category' => Tools::safeOutput($fianetsceau_default_category), 'fianetsceau_default_subcategory' => Tools::safeOutput($fianetsceau_default_subcategory), 'logo_categories_path' => $base_url . 'modules/' . $this->name . '/img/categories.gif', 'fianetsceau_categories' => $_fianetsceau_categories, 'fianetsceau_subcategories' => $_fianetsceau_subcategories, 'token' => $token, 'id_shop' => $id_shop));
     //view selection by prestashop 1.4 or 1.5
     return $this->display(__FILE__, '/views/templates/admin/admin.tpl');
 }