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_db_source",
13
        "smarty_resource_db_timestamp", "smarty_resource_db_secure",
14
        "smarty_resource_db_trusted" ) );
15
    function smarty_resource_db_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
        $bestellarten = getBestellartenSmarty();
21
        if ( $_SESSION["INI"] )
22
        {
23
            $dbase = $_SESSION["INI"]["dbConnect"]["order_db"];
24
        }
25
        else
26
        {
27
            $dbase = $GLOBALS["INI"]["dbConnect"]["order_db"];
28
        }
29
        if ( $dbase )
30
        {
31
            $dbase .= ".";
32
        }
33
        $settings_table = $dbase . "web_settings";
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
        if ( $GLOBALS["order_dbh"] )
52
        {
53
            $result = mysql_query( $sql, $GLOBALS["order_dbh"] );
54
        }
55
        else
56
        {
57
            $result = mysql_query( $sql );
58
        }
59
        if ( mysql_num_rows( $result ) )
60
        {
61
            $array = mysql_fetch_assoc( $result );
62
            $tpl_source = stripslashes( $array['Inhalt'] );
63
            return true;
64
        }
65
        else
66
        {
67
            return false;
68
        }
69
    }
70
 
71
    function smarty_resource_db_timestamp( $tpl_name, &$tpl_timestamp, $smarty )
72
    {
73
        // do database call here to populate $tpl_timestamp.
74
        /*$result=requete_SQL("select * from smarty_test where title='$tpl_name'");
75
        if (mysql_num_rows($result)) {
76
        $array=mysql_fetch_array($result);
77
        $tpl_timestamp=$array['timestamp'];
78
        return true;
79
        } else {
80
        return false;
81
        } */
82
        $tpl_timestamp = time();
83
        return true;
84
    }
85
 
86
    function smarty_resource_db_secure( $tpl_name, $smarty )
87
    {
88
        // assume all templates are secure
89
        return true;
90
    }
91
 
92
    function smarty_resource_db_trusted( $tpl_name, $smarty )
93
    {
94
        // not used for templates
95
    }
96
 
97
    function getBestellartenSmarty()
98
    {
99
        if ( $_SESSION["INI"] )
100
        {
101
            $dbase = $_SESSION["INI"]["dbConnect"]["order_db"];
102
        }
103
        else
104
        {
105
            $dbase = $GLOBALS["INI"]["dbConnect"]["order_db"];
106
        }
107
        if ( $dbase )
108
        {
109
            $dbase .= ".";
110
        }
111
        $art_table = $dbase . "bestellart";
112
        $settings_table = $dbase . "web_settings";
113
        $query = "SELECT * FROM $art_table";
114
        $result = mysql_query( $query );
115
 
116
        if ( $result )
117
        {
118
            $query = "SHOW FIELDS FROM $settings_table LIKE 'bestellart_id'";
119
            $result = mysql_query( $query );
120
            $test = ( mysql_num_rows( $result ) );
121
            /*if ( array_search( 'bestellart_id', $test ) )
122
            {
123
            $bestellart = true;
124
            define( "BESTELLART", true );
125
            }
126
            else
127
            {
128
            $bestellart = false;
129
            define( "BESTELLART", false );
130
            }*/
131
            return ( bool )$test;
132
        }
133
        return false;
134
    }
135
?>