/[cvs]/nfo/site/htdocs/inc/cms/cms.php.inc
ViewVC logotype

Contents of /nfo/site/htdocs/inc/cms/cms.php.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Mon Sep 6 00:15:28 2004 UTC (20 years ago) by rabit
Branch: MAIN
Changes since 1.4: +237 -9 lines
+ Function: cms_query(); U code and query format.

1 <?php
2 /*------------------------------------------------------------------------------
3 --- www.netfrag.org
4 --- Content management functions include file.
5 --------------------------------------------------------------------------------
6 --- rabit, 01:04 27.08.2004
7 --- $Id: cms.php.inc,v 1.4 2004/08/31 09:42:06 joko Exp $
8 ------------------------------------------------------------------------------*/
9
10 function cms_getcontent($type, $keyname, $language_id = 0) {
11
12 $sql = "SELECT contents.content, contents.description, UNIX_TIMESTAMP(contents.timestamp), languages.name, users.name, contents.keyname FROM contents, languages, users WHERE contents.type='$type' AND contents.keyname='$keyname'" . ($language_id ? " AND languages.id='$language_id'" : '') . " AND users.id=contents.creator_id AND languages.id=contents.language_id LIMIT 0,1;";
13
14 $res = mysql_query($sql);
15 if(!$res) return false;
16
17 $row = mysql_fetch_row($res);
18
19 $contentdata = array(
20 'content' => $row[0],
21 'description' => $row[1],
22 'unixtime' => $row[2],
23 'language_name' => $row[3],
24 'creator_name' => $row[4],
25 'keyname' => $row[5],
26 );
27
28 return $contentdata;
29
30 }
31
32 //----------------------------------------------------------
33
34 function cms_getlist($types, $keynames, $daterange = '', $languageids = '', $languages = '') {
35
36 $sql = "SELECT contents.id, contents.description, UNIX_TIMESTAMP(contents.timestamp), languages.id, languages.name, users.name FROM contents, languages, users WHERE contents.type='$types' AND contents.keyname='$keynames' AND users.id=contents.creator_id AND languages.id=contents.language_id;";
37
38 $res = common_dbc_query($sql);
39
40 $rowcount = 0;
41
42 while($row = mysql_fetch_row($res)) $rows[$rowcount++] = $row;
43
44 return $rows;
45
46 }
47
48 //----------------------------------------------------------
49
50 function cms_getindex($type) {
51
52 $sql = "SELECT contents.id, contents.keyname, contents.description, UNIX_TIMESTAMP(contents.timestamp) as timestamp, languages.id, languages.name as lang, users.name as creator FROM contents, languages, users WHERE contents.type='$type' AND users.id=contents.creator_id AND languages.id=contents.language_id;";
53
54 $res = common_dbc_query($sql);
55
56 $rowcount = 0;
57
58 while($row = mysql_fetch_assoc($res)) $rows[$rowcount++] = $row;
59
60 return $rows;
61
62 }
63
64 //----------------------------------------------------------
65
66 function cms_query($querycmd, &$response) {
67
68 //------------------
69
70 $operationindices = array(
71 'LIST' => 0,
72 'GET' => 1
73 );
74
75 //------------------
76
77 $sourceindices = array(
78 'contenttypes' => 0,
79 'languages' => 1,
80 'contents' => 2
81 );
82
83 //------------------
84
85 $querycmd = str_replace("\r\n", ' ', $querycmd);
86 $querycmd = str_replace("\n", ' ', $querycmd);
87
88 $querycmd = trim($querycmd);
89
90 $d1 = strpos($querycmd, ' ');
91 $operation = substr($querycmd, 0, $d1);
92
93 if(isset($operationindices[$operation])) {
94
95 $operationindex = $operationindices[$operation];
96
97 } else {
98
99 $response = cms_create_respose(1, null, null, null, $querycmd, $operation);
100
101 return false;
102
103 }
104
105 switch($operationindex) {
106
107 case 0: // "LIST"
108
109 $d2 = strpos($querycmd, ' WITH ', $d1 + 1);
110
111 if($d2) {
112
113 $source = substr($querycmd, $d1 + 1, $d2 - $d1 - 1);
114 $conditionlist = substr($querycmd, $d2 + 6);
115
116 } else {
117
118 $source = substr($querycmd, $d1 + 1);
119 $conditionlist = '';
120
121 }
122
123 if(isset($sourceindices[$source])) {
124
125 $sourceindex = $sourceindices[$source];
126
127 } else {
128
129 $response = cms_create_respose(2, null, null, null, $querycmd, $operation, $source, $conditionlist);
130
131 return false;
132
133 }
134
135 $sqlconditions = '';
136
137 if($conditionlist) {
138
139 $conditions = split(',', $conditionlist);
140
141 $sqlconditions .= ' WHERE';
142
143 for($c = 0; $c < count($conditions); $c++) {
144
145 list($conditionname, $conditionvalue) = split('=', $conditions[$c]);
146 $condition = trim($conditionname) . '=\'' . trim($conditionvalue) . '\'';
147 $sqlconditions .= ($c ? ' AND' : '') . ' ' . $condition;
148
149 }
150
151 }
152
153 $sql = 'SELECT id FROM ' . $source . $sqlconditions . ';';
154
155 $res = common_dbc_query($sql);
156
157 $columnnames = array('id');
158 $resultlist = array();
159
160 while($row = mysql_fetch_row($res)) array_push($resultlist, $row);
161
162 $response = cms_create_respose(0, $resultlist, $columnnames, 0, $querycmd, $operation, $source, $conditionlist);
163
164 return true;
165
166 break;
167
168 case 1: // "GET"
169
170 $d2 = strpos($querycmd, 'FROM') + 4;
171 $idlist = trim(substr($querycmd, $d1, $d2 - $d1 - 4));
172 $source = trim(substr($querycmd, $d2));
173
174 if(isset($sourceindices[$source])) {
175
176 $sourceindex = $sourceindices[$source];
177
178 } else {
179
180 $response = cms_create_respose(2, null, null, null, $querycmd, $operation, $source);
181
182 return false;
183
184 }
185
186 switch($sourceindex) {
187
188 case 0: // "contenttypes"
189
190 $fieldlist = 'id, name';
191 $columnnames = array('id', 'name');
192
193 break;
194
195 case 1: // "languages"
196
197 $fieldlist = 'id, name, abbreviation';
198 $columnnames = array('id', 'name', 'abbreviation');
199
200 break;
201
202 case 2: // "contents"
203
204 $fieldlist = 'id, keyname, type, creator_id, language_id, description, content';
205 $columnnames = array('id', 'keyname', 'contenttype', 'creator_id', 'language_id', 'description', 'content');
206
207 break;
208
209 }
210
211 $sqlconditions = '';
212
213 if($idlist) {
214
215 $ids = split(',', $idlist);
216
217 $sqlconditions .= ' WHERE';
218
219 for($i = 0; $i < count($ids); $i++) {
220
221 $condition = ' id=\'' . intval(trim($ids[$i])) . '\'';
222 $sqlconditions .= ($i ? ' OR' : '') . $condition;
223
224 }
225
226 } else {
227
228 // ERROR
229
230 }
231
232 $sql = "SELECT $fieldlist FROM " . $source . $sqlconditions . ';';
233 $res = common_dbc_query($sql);
234 $resultlist = array();
235
236 while($row = mysql_fetch_row($res)) array_push($resultlist, $row);
237
238 $response = cms_create_respose(0, $resultlist, $columnnames, 0, $querycmd, $operation, $source);
239 // $response = cms_create_respose(0, $resultlist, $columnnames, 0, $sql, $operation, $source);
240
241 return true;
242
243 break;
244
245 }
246
247 }
248
249 //----------------------------------------------------------
250
251 function cms_create_respose(
252 $errornumber,
253 $resultlist,
254 $columnnames,
255 $firstrow = 0,
256 $querycmd = '',
257 $operation = '',
258 $source = '',
259 $conditionlist = ''
260 ) {
261
262 //------------------
263
264 $errortexts = array(
265 0 => 'No error',
266 1 => 'Unknown base operation',
267 2 => 'Unknown data source name'
268 );
269
270 //------------------
271
272 $response = array(
273
274 // Result information:
275 0 => array(
276 'error' => $errornumber,
277 'errortext' => $errortexts[$errornumber],
278 'columncount' => (isset($columnnames) ? count($columnnames) : null),
279 'firstrow' => $firstrow,
280 'rowcount' => count($resultlist),
281 'querycmd' => $querycmd,
282 'operation' => $operation,
283 'source' => $source,
284 'conditionlist' => $conditionlist
285 ),
286
287 // Result list:
288 1 => $resultlist,
289
290 // Column names:
291 2 => $columnnames
292
293 );
294
295 return $response;
296
297 }
298
299 //------------------------------------------------------------------------------
300
301 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed