Quick Search:

View

Revision:

Diff

Diff from 1852 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/admin/includes/applications/configuration/classes/configuration.php

Annotated File View

hpdl
1852
1 <?php
2 /*
3   $Id: configuration.php 1852 2009-02-28 03:24:48Z hpdl $
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2009 osCommerce
9
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
13 */
14
15   class osC_Configuration_Admin {
16     public static function get($id) {
17       global $osC_Database;
18
19       $Qcfg = $osC_Database->query('select * from :table_configuration where configuration_id = :configuration_id');
20       $Qcfg->bindTable(':table_configuration', TABLE_CONFIGURATION);
21       $Qcfg->bindInt(':configuration_id', $id);
22       $Qcfg->execute();
23
24       $result = $Qcfg->toArray();
25
26       $Qcfg->freeResult();
27
28       return $result;
29     }
30
31     public static function getAll($group_id) {
32       global $osC_Database;
33
34       $Qcfg = $osC_Database->query('select * from :table_configuration where configuration_group_id = :configuration_group_id order by sort_order');
35       $Qcfg->bindTable(':table_configuration', TABLE_CONFIGURATION);
36       $Qcfg->bindInt(':configuration_group_id', $group_id);
37       $Qcfg->execute();
38
39       $result = array('entries' => array());
40
41       while ( $Qcfg->next() ) {
42         $result['entries'][] = $Qcfg->toArray();
43
44         if ( !osc_empty($Qcfg->value('use_function')) ) {
45           $result['entries'][sizeof($result['entries'])-1]['configuration_value'] = osc_call_user_func($Qcfg->value('use_function'), $Qcfg->value('configuration_value'));
46         }
47       }
48
49       $result['total'] = $Qcfg->numberOfRows();
50
51       $Qcfg->freeResult();
52
53       return $result;
54     }
55
56     public static function find($search) {
57       global $osC_Database;
58
59       $in_group = array();
60
61       foreach ( osc_toObjectInfo(self::getAllGroups())->get('entries') as $group ) {
62         $in_group[] = $group['configuration_group_id'];
63       }
64
65       $result = array('entries' => array());
66
67       $Qcfg = $osC_Database->query('select * from :table_configuration where (configuration_key like :configuration_key or configuration_value like :configuration_value) and configuration_group_id in (:configuration_group_id) order by configuration_key');
68       $Qcfg->bindTable(':table_configuration', TABLE_CONFIGURATION);
69       $Qcfg->bindValue(':configuration_key', '%' . $search . '%');
70       $Qcfg->bindValue(':configuration_value', '%' . $search . '%');
71       $Qcfg->bindRaw(':configuration_group_id', implode(',', $in_group));
72       $Qcfg->execute();
73
74       while ( $Qcfg->next() ) {
75         $result['entries'][] = $Qcfg->toArray();
76
77         if ( !osc_empty($Qcfg->value('use_function')) ) {
78           $result['entries'][sizeof($result['entries'])-1]['configuration_value'] = osc_call_user_func($Qcfg->value('use_function'), $Qcfg->value('configuration_value'));
79         }
80       }
81
82       $result['total'] = $Qcfg->numberOfRows();
83
84       $Qcfg->freeResult();
85
86       return $result;
87     }
88
89     public static function save($parameter) {
90       global $osC_Database;
91
92       $Qcfg = $osC_Database->query('select configuration_id from :table_configuration where configuration_key = :configuration_key');
93       $Qcfg->bindTable(':table_configuration', TABLE_CONFIGURATION);
94       $Qcfg->bindValue(':configuration_key', key($parameter));
95       $Qcfg->execute();
96
97       if ( $Qcfg->numberOfRows() === 1 ) {
98         $Qupdate = $osC_Database->query('update :table_configuration set configuration_value = :configuration_value, last_modified = now() where configuration_key = :configuration_key');
99         $Qupdate->bindTable(':table_configuration', TABLE_CONFIGURATION);
100         $Qupdate->bindValue(':configuration_value', $parameter[key($parameter)]);
101         $Qupdate->bindValue(':configuration_key', key($parameter));
102         $Qupdate->setLogging($_SESSION['module'], $Qcfg->valueInt('configuration_id'));
103         $Qupdate->execute();
104
105         if ( $Qupdate->affectedRows() ) {
106           osC_Cache::clear('configuration');
107
108           return true;
109         }
110       }
111
112       return false;
113     }
114
115     public static function getAllGroups() {
116       global $osC_Database;
117
118       $Qgroups = $osC_Database->query('select * from :table_configuration_group where visible = 1 order by sort_order, configuration_group_title');
119       $Qgroups->bindTable(':table_configuration_group', TABLE_CONFIGURATION_GROUP);
120       $Qgroups->execute();
121
122       $result = array('entries' => array());
123
124       while ( $Qgroups->next() ) {
125         $result['entries'][] = $Qgroups->toArray();
126       }
127
128       $result['total'] = $Qgroups->numberOfRows();
129
130       $Qgroups->freeResult();
131
132       return $result;
133     }
134
135     public static function getGroupTitle($id) {
136       global $osC_Database;
137
138       $Qcg = $osC_Database->query('select configuration_group_title from :table_configuration_group where configuration_group_id = :configuration_group_id');
139       $Qcg->bindTable(':table_configuration_group', TABLE_CONFIGURATION_GROUP);
140       $Qcg->bindInt(':configuration_group_id', $id);
141       $Qcg->execute();
142
143       $result = $Qcg->value('configuration_group_title');
144
145       $Qcg->freeResult();
146
147       return $result;
148     }
149   }
150 ?>