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
        $settings_table = $dbase . "web_settings";
22
        $sql = "
23
            SELECT
24
                *
25
            FROM
26
                $settings_table
27
            WHERE
28
                ID=$id
29
            AND
30
                shops_ID=$shops_ID
31
        ";
32
        if ( $bestellarten )
33
        {
34
            $sql .= "
35
                AND
36
                    bestellart_id=1
37
            ";
38
        }
39
        $result = mysql_query( $sql );
40
        if ( mysql_num_rows( $result ) )
41
        {
42
            $array = mysql_fetch_assoc( $result );
43
            $tpl_source = stripslashes( $array['Inhalt'] );
44
            return true;
45
        }
46
        else
47
        {
48
            return false;
49
        }
50
    }
51
 
52
    function smarty_resource_db_timestamp( $tpl_name, &$tpl_timestamp, &$smarty )
53
    {
54
        // do database call here to populate $tpl_timestamp.
55
        /*$result=requete_SQL("select * from smarty_test where title='$tpl_name'");
56
        if (mysql_num_rows($result)) {
57
        $array=mysql_fetch_array($result);
58
        $tpl_timestamp=$array['timestamp'];
59
        return true;
60
        } else {
61
        return false;
62
        } */
63
        $tpl_timestamp = time();
64
        return true;
65
    }
66
 
67
    function smarty_resource_db_secure( $tpl_name, &$smarty )
68
    {
69
        // assume all templates are secure
70
        return true;
71
    }
72
 
73
    function smarty_resource_db_trusted( $tpl_name, &$smarty )
74
    {
75
        // not used for templates
76
    }
77
 
78
    function getBestellartenSmarty()
79
    {
80
        if ( $_SESSION["INI"] )
81
        {
82
            $dbase = $_SESSION["INI"]["dbConnect"]["order_db"];
83
        }
84
        else
85
        {
86
            $dbase = $GLOBALS["INI"]["dbConnect"]["order_db"];
87
        }
88
        if ( $dbase )
89
        {
90
            $dbase .= ".";
91
        }
92
        $art_table = $dbase . "bestellart";
93
        $settings_table = "web_settings";
94
        $query = "SELECT * FROM $art_table";
95
        $result = mysql_query( $query );
96
 
97
        if ( $result )
98
        {
99
            $query = "SHOW FIELDS FROM $settings_table LIKE 'bestellart_id'";
100
            $result = mysql_query( $query );
101
            $test = ( mysql_num_rows( $result ) );
102
            /*if ( array_search( 'bestellart_id', $test ) )
103
            {
104
            $bestellart = true;
105
            define( "BESTELLART", true );
106
            }
107
            else
108
            {
109
            $bestellart = false;
110
            define( "BESTELLART", false );
111
            }*/
112
            return (bool)$test;
113
        }
114
        return false;
115
    }
116
 
117
?>