Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1371 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(
13
        "smarty_resource_db_source",
14
        "smarty_resource_db_timestamp",
15
        "smarty_resource_db_secure",
16
        "smarty_resource_db_trusted",
17
        ) );
18
    function smarty_resource_db_source( $tpl_name, &$tpl_source, $smarty )
19
    {
20
        // do database call here to fetch your template,
21
        // populating $tpl_source
22
        list( $shops_ID, $id ) = explode( "_", $tpl_name );
23
        $bestellarten = getBestellartenSmarty();
24
        if ( $_SESSION["INI"] )
25
        {
26
            $dbase = $_SESSION["INI"]["dbConnect"]["order_db"];
27
        }
28
        else
29
        {
30
            $dbase = $GLOBALS["INI"]["dbConnect"]["order_db"];
31
        }
32
        if ( $dbase )
33
        {
34
            $dbase .= ".";
35
        }
36
        $settings_table = $dbase . "web_settings";
37
        $sql = "
38
            SELECT
39
                *
40
            FROM
41
                $settings_table
42
            WHERE
43
                ID=$id
44
            AND
45
                shops_ID=$shops_ID
46
        ";
47
        if ( $bestellarten )
48
        {
49
            $sql .= "
50
                AND
51
                    bestellart_id=1
52
            ";
53
        }
54
        if ( $GLOBALS["order_dbh"] )
55
        {
56
            $result = mysql_query( $sql, $GLOBALS["order_dbh"] );
57
        }
58
        else
59
        {
60
            $result = mysql_query( $sql );
61
        }
62
        if ( mysql_num_rows( $result ) )
63
        {
64
            $array = mysql_fetch_assoc( $result );
65
            $tpl_source = stripslashes( $array['Inhalt'] );
66
            return true;
67
        }
68
        else
69
        {
70
            return false;
71
        }
72
    }
73
 
74
    function smarty_resource_db_timestamp( $tpl_name, &$tpl_timestamp, $smarty )
75
    {
76
        // do database call here to populate $tpl_timestamp.
77
        /*$result=requete_SQL("select * from smarty_test where title='$tpl_name'");
78
        if (mysql_num_rows($result)) {
79
        $array=mysql_fetch_array($result);
80
        $tpl_timestamp=$array['timestamp'];
81
        return true;
82
        } else {
83
        return false;
84
        } */
85
        $tpl_timestamp = time();
86
        return true;
87
    }
88
 
89
    function smarty_resource_db_secure( $tpl_name, $smarty )
90
    {
91
        // assume all templates are secure
92
        return true;
93
    }
94
 
95
    function smarty_resource_db_trusted( $tpl_name, $smarty )
96
    {
97
        // not used for templates
98
    }
99
 
100
    function getBestellartenSmarty()
101
    {
102
        if ( $_SESSION["INI"] )
103
        {
104
            $dbase = $_SESSION["INI"]["dbConnect"]["order_db"];
105
        }
106
        else
107
        {
108
            $dbase = $GLOBALS["INI"]["dbConnect"]["order_db"];
109
        }
110
        if ( $dbase )
111
        {
112
            $dbase .= ".";
113
        }
114
        $art_table = $dbase . "bestellart";
115
        $settings_table = $dbase . "web_settings";
116
        $sql = "SELECT * FROM $art_table";
117
        if ( $GLOBALS["order_dbh"] )
118
        {
119
            $result = mysql_query( $sql, $GLOBALS["order_dbh"] );
120
        }
121
        else
122
        {
123
            $result = mysql_query( $sql );
124
        }
125
 
126
        if ( $result )
127
        {
128
            $sql = "SHOW FIELDS FROM $settings_table LIKE 'bestellart_id'";
129
            if ( $GLOBALS["order_dbh"] )
130
            {
131
                $result = mysql_query( $sql, $GLOBALS["order_dbh"] );
132
            }
133
            else
134
            {
135
                $result = mysql_query( $sql );
136
            }
137
            $test = ( mysql_num_rows( $result ) );
138
            /*if ( array_search( 'bestellart_id', $test ) )
139
            {
140
            $bestellart = true;
141
            define( "BESTELLART", true );
142
            }
143
            else
144
            {
145
            $bestellart = false;
146
            define( "BESTELLART", false );
147
            }*/
148
            return ( bool )$test;
149
        }
150
        return false;
151
    }
152
?>