}
    $data = addslashes(serialize($label_data));
    cw_array2update('layouts', array('data' => $data), "layout='{$target}'");
    cw_header_location("index.php?target={$target}&mode=layout&doc_id={$doc_id}");
}
if ($action == 'create_template' && $current_area == 'A' && $template['title']) {
    $layout_id = cw_array2insert('layouts', array('title' => $template['title'], 'layout' => 'docs_' . $docs_type));
    db_query("update {$tables['docs_info']} set layout_id='{$layout_id}'");
    cw_header_location("index.php?target={$target}&mode=layout&doc_id={$doc_id}");
}
if ($action == 'copy_layout_template' && $current_area == 'A' && $template['source_layout_id'] && $template['source_layout_id'] != $template['layout_id']) {
    cw_web_copy_layout($template['source_layout_id'], $template['layout_id']);
    cw_header_location("index.php?target={$target}&mode=layout&doc_id={$doc_id}");
}
if ($action == 'delete_template' && $current_area == 'A') {
    cw_web_delete_layout($template['layout_id']);
    db_query("update {$tables['docs_info']} set layout_id=0 where layout_id='" . $template['layout_id'] . "'");
    cw_header_location("index.php?target={$target}&mode=layout&doc_id={$doc_id}");
}
$info_type = 1;
if (in_array($current_area, array('A', 'P'))) {
    $info_type += 512 + 8192;
}
if ($docs_type == 'G') {
    $info_type += 1024;
}
if (in_array($docs_type, array('P', 'Q', 'R'))) {
    $info_type += 2048;
}
global $doc_data;
$doc_data = cw_call('cw_doc_get', array($doc_id, $info_type));
<?php

cw_load('web', 'barcode', 'product');
$saved_template_id =& cw_session_register('saved_template_id');
if ($action == 'set_template') {
    $saved_template_id = $template_id;
    cw_header_location("index.php?target={$target}");
}
if ($action == 'delete' && $saved_template_id) {
    cw_web_delete_layout($saved_template_id);
    $saved_template_id = 0;
    cw_header_location("index.php?target={$target}");
}
if ($action == 'create' && $title) {
    $saved_template_id = cw_barcode_create_template($title);
    cw_header_location("index.php?target={$target}");
}
if ($action == 'update' && $saved_template_id) {
    $data = addslashes(serialize($label_data));
    cw_array2update('layouts', array('data' => $data), "layout_id='{$saved_template_id}'");
    cw_header_location("index.php?target={$target}");
}
if ($saved_template_id) {
    $product = array('eancode' => cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'), 'display_price' => '10.00', 'display_discounted_price' => '9.00', 'list_price' => '15.00', 'supplier_code' => cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'), 'discount' => '1.00', 'productcode' => 'Product SKU', 'sn' => cw_product_generate_sku($config['barcode']['gen_product_code'], 'eancode'), 'product' => 'Product Title');
    $smarty->assign('product', $product);
    $template = cw_web_get_layout_by_id($saved_template_id);
    if ($template['layout'] != 'barcode') {
        $saved_template_id = 0;
        cw_header_location("index.php?target={$target}");
    }
    $smarty->assign('layout_data', $template);