File: item_type.php

package info (click to toggle)
opendb 0.81p18-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,716 kB
  • ctags: 6,787
  • sloc: php: 50,213; sql: 3,098; sh: 272; makefile: 54; xml: 48
file content (328 lines) | stat: -rw-r--r-- 9,199 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<?php
/* 	OpenDb - Open Media Lending Database
	Copyright (C) 2001,2002 by Jason Pell

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

include_once("./functions/database.php");
include_once("./functions/logging.php");
include_once("./functions/site_plugin.php");

function is_exists_item_type($s_item_type)
{
	if(strlen($s_item_type)>0)
	{
		$query = "SELECT 'x' FROM s_item_type WHERE s_item_type = '".$s_item_type."'";
		$result = run_opendb_query($query);
		if($result && mysql_num_rows($result)>0)
		{
			mysql_free_result($result);
			return TRUE;
		}
	}
	//else
	return FALSE;
}

/*
* In order to be considered a valid s_item_type structure, several 
* s_item_attribute_type records must exist with specific s_field_type's 
* underneath it.
* 
* We are not checking that TITLE s_field_type s_item_attribute_type
* mandatory_ind is set to 'Y', because item_input.php will enforce
* that itself.  All we care about is that the item_type is actually
* structured well enough that it will work within item_input.php to
* add new records.
*/
function is_valid_item_type_structure($s_item_type)
{
	global $CONFIG_VARS;
	
	if(is_exists_item_type($s_item_type))
	{
		if(fetch_sfieldtype_item_attribute_type($s_item_type, 'TITLE'))
		{
			if(fetch_sfieldtype_item_attribute_type($s_item_type, 'STATUSTYPE'))
			{
				if(fetch_sfieldtype_item_attribute_type($s_item_type, 'STATUSCMNT'))
				{
					if(fetch_sfieldtype_item_attribute_type($s_item_type, 'CATEGORY'))
					{
						if($CONFIG_VARS['borrow.enable']!==FALSE && $CONFIG_VARS['borrow.duration_support']!==FALSE)
						{
							if(fetch_sfieldtype_item_attribute_type($s_item_type, 'DURATION'))
							{
								// At this point all the required s_field_type mappings have been
								// provided.
								return TRUE;
							}
							else //if(fetch_sfieldtype_item_attribute_type($s_item_type, 'DURATION'))
							{
								return FALSE;
							}
						}
						else //No borrow duration functionality enabled.
						{
							// At this point $borrow functionality is not enabled, so we do not
							// have to do anymore testing.
							return TRUE;
						}
					}
					else //if(fetch_sfieldtype_item_attribute_type($s_item_type, 'CATEGORY'))
					{
						return FALSE;
					}
				}
				else//if(fetch_sfieldtype_item_attribute_type($s_item_type, 'STATUSCMNT'))
				{
					return FALSE;
				}					
			}
			else //if(fetch_sfieldtype_item_attribute_type($s_item_type, 'STATUSTYPE'))
			{
				return FALSE;
			}
		}
		else //if(fetch_sfieldtype_item_attribute_type($s_item_type, 'TITLE'))
		{
			return FALSE;
		}
	}
	else //if(is_exists_item_type($s_item_type))
	{
		return FALSE;
	}
}

/*
  This function will return a <img src="" alt=""> tag if the
  image field is defined, or FALSE if not defined.  Will not
  actually check if the image exists.   It assumes that if
  you have defined an image it does exist. 
*/
function fetch_item_type_image($s_item_type)
{
	$query = "select image from s_item_type where s_item_type = '".$s_item_type."'";
	$result = run_opendb_query($query);
	if($result && mysql_num_rows($result)>0)
	{
		$found = mysql_fetch_array($result, MYSQL_ASSOC);
		if ($found)
		{
			mysql_free_result($result);
			if(strlen($found['image'])>0)
				return $found['image'];
		}
	}
	
    //else
	return FALSE;
}

function fetch_sfieldtype_item_attribute_type($s_item_type, $s_field_type)
{
	$attribute_type_r = fetch_sfieldtype_item_attribute_type_rs($s_item_type, $s_field_type);
	if($attribute_type_r)
		return $attribute_type_r['s_attribute_type'];
	else
		return FALSE;
}

function fetch_sfieldtype_item_attribute_type_r($s_item_type, $s_field_type, $all_columns=FALSE)
{
	return fetch_sfieldtype_item_attribute_type_rs($s_item_type, $s_field_type, $all_columns);
}

/*
 * Fetch the s_field_type s_attribute_type.
 * 
 * @param $all_records Specifies if we want to return all of the matches,
 * or only the first one.
 * 
 * Note assumes that the $s_field_type has been specified UPPERCASE!
*/
function fetch_sfieldtype_item_attribute_type_rs($s_item_type, $s_field_type, $all_columns=FALSE, $all_records=FALSE)
{
	$query = "SELECT siat.s_attribute_type, ".
			"siat.order_no, ".
			"sat.s_field_type ";
	
	if($all_columns)
	{
		$query .= ", if(length(siat.prompt)>0,siat.prompt,sat.prompt) as prompt,".
				"sat.description,". 
                "sat.input_type,".
                "sat.display_type ";
	}
	
	if(is_array($s_field_type))
		$sfieldtype_clause = "UPPER(sat.s_field_type) IN (".format_sql_in_clause($s_field_type).")";
	else if(strlen($s_field_type)>0)
		$sfieldtype_clause = "UPPER(sat.s_field_type) = '$s_field_type'";
	else
		$sfieldtype_clause = "LENGTH(IFNULL(sat.s_field_type,''))>0";
		
	$query .= "FROM s_item_attribute_type siat, s_attribute_type sat ".
			"WHERE siat.s_attribute_type = sat.s_attribute_type AND $sfieldtype_clause AND ".
			"siat.s_item_type = '$s_item_type' ".
			"ORDER BY order_no asc";

	// Only get one record in this case.			
	if(!$all_records)
		$query .= " LIMIT 0,1";

	$result = run_opendb_query($query);
	if($result && mysql_num_rows($result)>0)
	{
		if(!$all_records)
		{
			$found = mysql_fetch_array($result, MYSQL_ASSOC);
			mysql_free_result($result);
			return $found;
		}
		else // return all the records as a resultset.
		{
			return $result;
		}
	}
	
    //else
	return FALSE;
}

/**
  @param is_loookup.  Indicates we are using this as a lookup result, so the s_item_type
  needs to be named "value" and the description needs to be named "display"
*/
function fetch_item_type_rs($is_lookup = FALSE)
{
	$query = "select s_item_type ".($is_lookup?"as value":"").", description ".($is_lookup?"as display":"")." from s_item_type order by order_no, s_item_type";

	$result = run_opendb_query($query);
	if($result && mysql_num_rows($result)>0)
		return $result;
	else
		return FALSE;
}

//
// Return an item_record.  Currently this is:description, image
//
function fetch_item_type_r($s_item_type)
{
	// Assumes that the language.php has been included by calling script.
	global $LANG_VARS;

	$query = "select description, image from s_item_type where s_item_type = '$s_item_type'";
	$result = run_opendb_query($query);
	if($result && mysql_num_rows($result)>0)
	{
		$found = mysql_fetch_array($result, MYSQL_ASSOC);
		mysql_free_result($result);
		return $found;
	}
	else
		return FALSE;
}


//
// Item type specific site plugin functionality.
//
 
/*
	Will fetch a resultset of all s_item_types for a particular site_type.  
	
	Will set the s_item_type as value and description as display so 
	they can be used seemlessly in single_select call.
*/
function fetch_site_item_type_rs($site_type)
{
	$query = "select	DISTINCT sit.s_item_type as value,".
						"sit.description as display, ".
						"sit.order_no ".
						"from s_item_type sit,".
						"s_attribute_type sat,".
						"s_item_attribute_type siat ".
				"where 	sit.s_item_type = siat.s_item_type AND ".
						"sat.s_attribute_type = siat.s_attribute_type AND ".
						"sat.site_type = '".$site_type."' ".
						"order by 3,1";

	$result = run_opendb_query($query);
	if($result && mysql_num_rows($result)>0)
		return $result;
	else
		return FALSE;
}

/*
	Will return an array of all site-plugins that are compatible with the s_item_type.
*/
function fetch_site_type_rs($s_item_type)
{
	$query = 	"SELECT	DISTINCT sat.site_type ".
				"FROM	s_attribute_type sat,".
						"s_item_attribute_type siat ".
				"WHERE 	sat.s_attribute_type = siat.s_attribute_type AND ".
                		"length(sat.site_type)>0 AND ".
						"siat.s_item_type = '".$s_item_type."' ".
						"order by 1";

	$result = run_opendb_query($query);
	if($result && mysql_num_rows($result)>0)
    {
		while($site_type_r = mysql_fetch_array($result, MYSQL_ASSOC))
			$site_type[] = $site_type_r['site_type'];

        return $site_type;
	}        
	else
		return FALSE;
}

/*
	Checks if an s_item_type has any site plugins linked to it.
	
*/
function is_item_legal_site_type($s_item_type)
{
	$query = 	"select	sat.site_type ".
				"from 	s_attribute_type sat,".
				"		s_item_attribute_type siat ".
				"where 	sat.s_attribute_type = siat.s_attribute_type AND ".
                		"length(sat.site_type)>0 AND ".
						"siat.s_item_type = '".$s_item_type."'";

	$result = run_opendb_query($query);
	if($result && mysql_num_rows($result)>0)
	{
		while($site_type_r = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			if(is_exists_site_plugin($site_type_r['site_type']))
			{
				mysql_free_result($result);
				return TRUE;
			}
		}
		mysql_free_result($result);
	}

	//else
	return FALSE;
}
?>