Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
3 lars 1
<?php
2
    /*
3
    * Smarty plugin
4
    * -------------------------------------------------------------
5
    * File:     resource.db.php
6
    * Type:     resource
7
    * Name:     db
8
    * Purpose:  Fetches templates from a database
9
    * -------------------------------------------------------------
10
    */
11
    // register the resource name "db"
12
    $this->register_resource( "db", array( "smarty_resource_mdb2_source",
13
        "smarty_resource_mdb2_timestamp", "smarty_resource_mdb2_secure",
14
        "smarty_resource_mdb2_trusted" ) );
15
    function smarty_resource_mdb2_source( $tpl_name, &$tpl_source, &$smarty )
16
    {
17
        // do database call here to fetch your template,
18
        // populating $tpl_source
19
        list( $shops_ID, $id ) = explode( "_", $tpl_name );
20
        if ( $_SESSION["INI"] )
21
        {
22
            $dbase = $_SESSION["INI"]["dbConnect"]["order_db"];
23
        }
24
        else
25
        {
26
            $dbase = $GLOBALS["INI"]["dbConnect"]["order_db"];
27
        }
28
        if ( $dbase )
29
        {
30
            $dbase .= ".";
31
        }
32
        $settings_table = "web_settings";
33
        $bestellarten = getBestellartenSmarty();
34
        $sql = "
35
            SELECT
36
                *
37
            FROM
38
                $settings_table
39
            WHERE
40
                ID=$id
41
            AND
42
                shops_ID=$shops_ID
43
        ";
44
        if ( $bestellarten )
45
        {
46
            $sql .= "
47
                AND
48
                    bestellart_id=1
49
            ";
50
        }
51
        $result = $GLOBALS["db"]->query( $sql );
52
        if ( $result->numRows() )
53
        {
54
            $array = $result->FetchRow();
55
            $tpl_source = stripslashes( $array['inhalt'] );
56
            return true;
57
        }
58
        else
59
        {
60
            return false;
61
        }
62
    }
63
 
64
    function smarty_resource_mdb2_timestamp( $tpl_name, &$tpl_timestamp, &$smarty )
65
    {
66
        // do database call here to populate $tpl_timestamp.
67
        /*$result=requete_SQL("select * from smarty_test where title='$tpl_name'");
68
        if (mysql_num_rows($result)) {
69
        $array=mysql_fetch_array($result);
70
        $tpl_timestamp=$array['timestamp'];
71
        return true;
72
        } else {
73
        return false;
74
        } */
75
        $tpl_timestamp = time();
76
        return true;
77
    }
78
 
79
    function smarty_resource_mdb2_secure( $tpl_name, &$smarty )
80
    {
81
        // assume all templates are secure
82
        return true;
83
    }
84
 
85
    function smarty_resource_mdb2_trusted( $tpl_name, &$smarty )
86
    {
87
        // not used for templates
88
    }
89
 
90
    function getBestellartenSmarty()
91
    {
92
        if ( $_SESSION["INI"] )
93
        {
94
            $dbase = $_SESSION["INI"]["dbConnect"]["order_db"];
95
        }
96
        else
97
        {
98
            $dbase = $GLOBALS["INI"]["dbConnect"]["order_db"];
99
        }
100
        if ( $dbase )
101
        {
102
            $dbase .= ".";
103
        }
104
        $art_table = $dbase . "bestellart";
105
        $settings_table = "web_settings";
106
        $query = "SELECT * FROM bestellart";
107
        $result = $GLOBALS["db"]->query( $query );
108
 
109
        if ( !PEAR::isError( $result ) )
110
        {
111
            $query = "SHOW FIELDS FROM web_settings LIKE 'bestellart_id'";
112
            $result = $GLOBALS["db"]->query( $query );
113
            $test = ( $result->NumRows() );
114
            /*if ( array_search( 'bestellart_id', $test ) )
115
            {
116
            $bestellart = true;
117
            define( "BESTELLART", true );
118
            }
119
            else
120
            {
121
            $bestellart = false;
122
            define( "BESTELLART", false );
123
            }*/
124
            return ( bool )$test;
125
        }
126
	else
127
	{
128
		echo $result->getUserInfo();
129
	}
130
        return false;
131
    }
132
?>