/**
  * @param array $positions
  */
 public static function savePositions($positions)
 {
     $id_shop = (int) Tools::getValue('id_shop');
     if (!$id_shop) {
         $id_shop = Context::getContext()->shop->id;
     }
     $res = true;
     $position = $positions['current'];
     foreach ($position as $hook_name => $hook_modules) {
         // return id of existed or newly added hook
         if (!($id_hook = Hook::registerDesignerHook($hook_name))) {
             continue;
         }
         // clears positions if all modules were removed from hook
         if (sizeof($hook_modules) < 1) {
             PositionController::clearHook($id_hook, $id_shop);
         }
         $i = 1;
         $value = '';
         $ids = array();
         // then prepare sql query to rehook all chosen modules(id_module, id_shop, id_hook, position)
         // position is i (autoincremented)
         foreach ($hook_modules as $module) {
             $id = explode('_', $module);
             if (sizeof($id) > 5 && $id[0] == 'hook') {
                 $id_module = $id[3];
                 if (!in_array($id_module, $ids)) {
                     $ids[] = (int) $id_module;
                     $value .= '(' . (int) $id_module . ', ' . (int) $id_shop . ', ' . (int) $id_hook . ', ' . (int) $i . '),';
                 }
             }
             $i++;
         }
         // drop all previous hooked modules
         // if value with new positions is not empty
         // when Billion Themler navigates between pages
         // TODO: modules can be deleted from hook
         if (!empty($value)) {
             $res &= PositionController::clearHook($id_hook, $id_shop);
             $value = rtrim($value, ',');
             $res &= Db::getInstance()->execute('INSERT INTO  `' . _DB_PREFIX_ . 'hook_module`
                 (id_module, id_shop, id_hook, position)
                 VALUES ' . $value);
         }
     }
     return $res;
     //die('{"hasError" : false, "errors" : ""}');
     // For Test
     //$positions = '{"displayLeftColumn":["hook_7_module_21_moduleName_blocksearch","hook_7_module_7_moduleName_blockcms","hook_7_module_8_moduleName_blockcontact","hook_7_module_122_moduleName_blockrss","hook_7_module_24_moduleName_blockspecials","hook_7_module_14_moduleName_blockmyaccount","hook_7_module_3_moduleName_blockadvertising","hook_7_module_6_moduleName_blockcategories"],"displayHome":[]}';
     //$positions = '{"displayLeftColumn":["hook_7_module_7_moduleName_blockcms","hook_7_module_21_moduleName_blocksearch","hook_7_module_8_moduleName_blockcontact","hook_7_module_122_moduleName_blockrss","hook_7_module_24_moduleName_blockspecials","hook_7_module_14_moduleName_blockmyaccount","hook_7_module_3_moduleName_blockadvertising","hook_7_module_6_moduleName_blockcategories"]}';
     //self::saveHook(json_decode($positions, true));
 }
 /**
  * Exports designer project
  */
 private function _exportTheme($content)
 {
     $changed_files = getPreviewChangedFiles($this->_themeDir);
     $positions = null;
     // Removed for a while: isset($content['positions'])    ? $content['positions']    : null;
     $theme = isset($content['themeFso']) ? $content['themeFso'] : null;
     $images = isset($content['images']) ? $content['images'] : null;
     $fonts = isset($content['iconSetFiles']) ? $content['iconSetFiles'] : null;
     $replaceInfo = array();
     $replaceInfo = array_merge_recursive($replaceInfo, (array) $this->_processFonts($this->_previewThemeDir, $fonts, $changed_files));
     $replaceInfo = array_merge_recursive($replaceInfo, (array) $this->_processImages($this->_previewThemeDir, $images, $changed_files));
     $hasReplace = isset($replaceInfo) && isset($replaceInfo['ids']) && isset($replaceInfo['paths']);
     ProviderLog::start('_fillThemeStorage');
     $this->_fillThemeStorage($theme, $changed_files, $replaceInfo, $hasReplace, $this->_previewThemeDir);
     ProviderLog::end('_fillThemeStorage');
     ProviderLog::start('_buildThemeLayoutFilesFromHtml');
     // backward for custom templates
     $this->_buildThemeLayoutFilesFromHtml($changed_files, $replaceInfo, $hasReplace);
     ProviderLog::end('_buildThemeLayoutFilesFromHtml');
     if (isset($positions)) {
         PositionController::savePositions($positions);
     }
     setPreviewChangedFiles($this->_themeDir, $this->_previewThemeDir, $changed_files);
 }