/**
 * Check if the gift certificate template is wrong file
 */
function cw_gift_wrong_template($gc_template)
{
    global $app_dir, $app_skin_dir;
    $gc_templates_dir = $app_dir . $app_skin_dir . '/addons/estore_gift/';
    return empty($gc_template) || !cw_allowed_path($gc_templates_dir, $gc_templates_dir . $gc_template) || !in_array($gc_template, cw_gift_get_templates($app_dir . $app_skin_dir));
}
    // Delete gift certificate
    if (!empty($gc_ids)) {
        $gcids = array_keys($gc_ids);
        // GC can be deleted if it's doc_id == 0 or is not exist
        db_query("DELETE gc \n        FROM {$tables['giftcerts']} gc\n        LEFT JOIN {$tables['docs']} d ON gc.doc_id=d.doc_id\n        WHERE gc.gc_id IN ('" . implode("' ,'", $gcids) . "')\n            AND (gc.doc_id=0 OR d.doc_id IS NULL)");
    }
    cw_add_top_message(cw_get_langvar_by_name("msg_adm_gcs_del"));
    cw_header_location("index.php?target=giftcerts");
}
if (in_array($mode, array('add_gc', 'modify_gc'))) {
    if (empty($country)) {
        $country = $config['General']['default_country'];
    }
    $smarty->assign('countries', cw_map_get_countries());
    $smarty->assign('states', cw_map_get_states($country));
    $smarty->assign('gc_templates', cw_gift_get_templates($app_dir . $app_skin_dir));
    $gc_readonly = "";
    if (!empty($gc_id)) {
        $giftcert = cw_query_first("SELECT * FROM {$tables['giftcerts']} where gc_id='" . $gc_id . "'");
        if ($giftcert['send_via'] != "E") {
            $giftcert['recipient_statename'] = cw_get_state($giftcert['recipient_state'], $giftcert['recipient_country']);
            $giftcert['recipient_countryname'] = cw_get_country($giftcert['recipient_country']);
        }
        $smarty->assign('giftcert', $giftcert);
        $smarty->assign('gc_id', $gc_id);
        $gc_readonly = $mode == "modify_gc" && $giftcert['status'] != "P" ? "Y" : "";
    }
} elseif ($action == 'print') {
    $giftcerts = false;
    $gc_ids = $gc_ids_p;
    if (!empty($gc_ids) && is_array($gc_ids)) {