<?php
/*
 #########################################################################
 #                       xt:Commerce Shopsoftware
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #
 # Copyright 2021 xt:Commerce GmbH All Rights Reserved.
 # This file may not be redistributed in whole or significant part.
 # Content of this file is Protected By International Copyright Laws.
 #
 # ~~~~~~ xt:Commerce Shopsoftware IS NOT FREE SOFTWARE ~~~~~~~
 #
 # https://www.xt-commerce.com
 #
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #
 # @copyright xt:Commerce GmbH, www.xt-commerce.com
 #
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #
 # xt:Commerce GmbH, Maximilianstrasse 9, 6020 Innsbruck
 #
 # office@xt-commerce.com
 #
 #########################################################################
 */

defined('_VALID_CALL') or die('Direct Access is not allowed.');

function smarty_block_if_is_content($params, & $smarty)
{
	global $_content, $xtPlugin, $db;

    $is_content = false;

	$content_type = array_key_exists('type', $params) ? $params['type'] : '';
    if($content_type)
    {
        // zZ haben wir keine content_type in der db
        // wir faken hier einzig für rescission
        // alles weitere evtl in 6.8
        switch($content_type)
        {
            case 'rescission':
                $content_id = $db->GetOne("SELECT content_id FROM ".TABLE_CONTENT." WHERE content_form='rescission.php'");
                if($content_id)
                {
                    $sql = "SELECT 1 FROM " . TABLE_CONTENT . " c ";
                    $sql .= $_content->permission->_table . " ";
                    $sql .= " WHERE c.content_id = ? ";
                    $sql .= $_content->permission->_where;
                    $r = $db->GetOne($sql, array($content_id));
                    $is_content = !empty($r);
                }
                break;
            default:
                $is_content = false;
        }
    }

    return $is_content && $smarty ? $smarty : '';
}
