001.
<?php
require_once
(
'Connections/library.php'
); ?>
002.
<?php
003.
if
(!function_exists(
"GetSQLValueString"
)) {
004.
function
GetSQLValueString(
$theValue
,
$theType
,
$theDefinedValue
=
""
,
$theNotDefinedValue
=
""
)
005.
{
006.
$theValue
= get_magic_quotes_gpc() ?
stripslashes
(
$theValue
) :
$theValue
;
007.
008.
$theValue
= function_exists(
"mysql_real_escape_string"
) ? mysql_real_escape_string(
$theValue
) : mysql_escape_string(
$theValue
);
009.
010.
switch
(
$theType
) {
011.
case
"text"
:
012.
$theValue
= (
$theValue
!=
""
) ?
"'"
.
$theValue
.
"'"
:
"NULL"
;
013.
break
;
014.
case
"long"
:
015.
case
"int"
:
016.
$theValue
= (
$theValue
!=
""
) ?
intval
(
$theValue
) :
"NULL"
;
017.
break
;
018.
case
"double"
:
019.
$theValue
= (
$theValue
!=
""
) ?
"'"
. doubleval(
$theValue
) .
"'"
:
"NULL"
;
020.
break
;
021.
case
"date"
:
022.
$theValue
= (
$theValue
!=
""
) ?
"'"
.
$theValue
.
"'"
:
"NULL"
;
023.
break
;
024.
case
"defined"
:
025.
$theValue
= (
$theValue
!=
""
) ?
$theDefinedValue
:
$theNotDefinedValue
;
026.
break
;
027.
}
028.
return
$theValue
;
029.
}
030.
}
031.
032.
$editFormAction
=
$_SERVER
[
'PHP_SELF'
];
033.
if
(isset(
$_SERVER
[
'QUERY_STRING'
])) {
034.
$editFormAction
.=
"?"
. htmlentities(
$_SERVER
[
'QUERY_STRING'
]);
035.
}
036.
037.
if
((isset(
$_POST
[
"MM_update"
])) && (
$_POST
[
"MM_update"
] ==
"form1"
)) {
038.
$updateSQL
= sprintf(
"UPDATE book SET book_id=%s, book_name=%s, book_author=%s, book_booktype=%s, book_press=%s, book_page=%s, book_timeprint=%s WHERE book_isbn=%s"
,
039.
GetSQLValueString(
$_POST
[
'hiddenField'
],
"int"
),
040.
GetSQLValueString(
$_POST
[
'book_name'
],
"text"
),
041.
GetSQLValueString(
$_POST
[
'book_author'
],
"text"
),
042.
GetSQLValueString(
$_POST
[
'book_booktype'
],
"int"
),
043.
GetSQLValueString(
$_POST
[
'book_press'
],
"text"
),
044.
GetSQLValueString(
$_POST
[
'book_page'
],
"text"
),
045.
GetSQLValueString(
$_POST
[
'book_timeprint'
],
"text"
),
046.
GetSQLValueString(
$_POST
[
'txtUsername'
],
"text"
));
047.
048.
mysql_select_db(
$database_library
,
$library
);
049.
$Result1
= mysql_query(
$updateSQL
,
$library
)
or
die
(mysql_error());
050.
}
051.
052.
if
((isset(
$_POST
[
"MM_update"
])) && (
$_POST
[
"MM_update"
] ==
"form1"
)) {
053.
$updateSQL
= sprintf(
"UPDATE book_number SET book_isbn=%s, book_number_number=%s, book_copy=%s WHERE id=%s"
,
054.
GetSQLValueString(
$_POST
[
'txtUsername'
],
"text"
),
055.
GetSQLValueString(
$_POST
[
'book_number_number'
],
"text"
),
056.
GetSQLValueString(
$_POST
[
'book_coppy'
],
"text"
),
057.
GetSQLValueString(
$_POST
[
'hiddenField2'
],
"int"
));
058.
059.
mysql_select_db(
$database_library
,
$library
);
060.
$Result1
= mysql_query(
$updateSQL
,
$library
)
or
die
(mysql_error());
061.
}
062.
063.
mysql_select_db(
$database_library
,
$library
);
064.
$query_Recordset1
=
"SELECT * FROM booktype"
;
065.
$Recordset1
= mysql_query(
$query_Recordset1
,
$library
)
or
die
(mysql_error());
066.
$row_Recordset1
= mysql_fetch_assoc(
$Recordset1
);
067.
$totalRows_Recordset1
= mysql_num_rows(
$Recordset1
);
068.
069.
$colname_Recordset2
=
"-1"
;
070.
if
(isset(
$_GET
[
'book_id'
])) {
071.
$colname_Recordset2
=
$_GET
[
'book_id'
];
072.
}
073.
mysql_select_db(
$database_library
,
$library
);
074.
$query_Recordset2
= sprintf(
"SELECT * FROM book WHERE book_id = %s"
, GetSQLValueString(
$colname_Recordset2
,
"int"
));
075.
$Recordset2
= mysql_query(
$query_Recordset2
,
$library
)
or
die
(mysql_error());
076.
$row_Recordset2
= mysql_fetch_assoc(
$Recordset2
);
077.
$totalRows_Recordset2
= mysql_num_rows(
$Recordset2
);
078.
079.
$colname_Recordset3
=
"-1"
;
080.
if
(isset(
$_GET
[
'id'
])) {
081.
$colname_Recordset3
=
$_GET
[
'id'
];
082.
}
083.
mysql_select_db(
$database_library
,
$library
);
084.
$query_Recordset3
= sprintf(
"SELECT * FROM book_number WHERE id = %s"
, GetSQLValueString(
$colname_Recordset3
,
"int"
));
085.
$Recordset3
= mysql_query(
$query_Recordset3
,
$library
)
or
die
(mysql_error());
086.
$row_Recordset3
= mysql_fetch_assoc(
$Recordset3
);
087.
$totalRows_Recordset3
= mysql_num_rows(
$Recordset3
);
088.
089.
mysql_select_db(
$database_library
,
$library
);
090.
$query_Recordset4
=
"SELECT * FROM press"
;
091.
$Recordset4
= mysql_query(
$query_Recordset4
,
$library
)
or
die
(mysql_error());
092.
$row_Recordset4
= mysql_fetch_assoc(
$Recordset4
);
093.
$totalRows_Recordset4
= mysql_num_rows(
$Recordset4
);
096.
<head>
097.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
098.
<title>Untitled Document</title>
099.
<script type=
"text/javascript"
>
100.
<!--
101.
function
MM_goToURL() {
102.
var
i, args=MM_goToURL.arguments; document.MM_returnValue = false;
103.
for
(i=0; i<(args.length-1); i+=2)
eval
(args[i]+
".location='"
+args[i+1]+
"'"
);
104.
}
105.
106.
</script>
107.
</head>
108.
109.
<body>
110.
<form id=
"form1"
name=
"form1"
method=
"POST"
action=
"<?php echo $editFormAction; ?>"
>
111.
<table width=
"50%"
border=
"0"
align=
"center"
cellpadding=
"0"
cellspacing=
"0"
>
112.
<tr>
113.
<td height=
"47"
colspan=
"3"
><div align=
"center"
class
=
"style14"
>แก้ไขข้อมูลหนังสือ</div></td>
114.
</tr>
115.
<tr>
116.
<td width=
"35%"
class
=
"style13"
>ISBN</td>
117.
<td width=
"59%"
><label>
118.
<input name=
"txtUsername"
type=
"text"
id=
"txtUsername"
onchange=
"JavaScript:doCallAjax2('txtUsername','book_name','book_number_number','book_coppy','book_author','book_page','book_timeprint','book_type','book_press');"
onkeypress=
"return chkNumber(this)"
value=
"<?php echo $row_Recordset2['book_isbn']; ?>"
/>
119.
</label></td>
120.
<td width=
"6%"
> </td>
121.
</tr>
122.
<tr>
123.
<td
class
=
"style13"
>ชื่อหนังสือ</td>
124.
<td><label>
125.
<input name=
"book_name"
type=
"text"
id=
"book_name"
value=
"<?php echo $row_Recordset2['book_name']; ?>"
/>
126.
</label></td>
127.
<td> </td>
128.
</tr>
129.
<tr>
130.
<td
class
=
"style13"
>เลขทะเบียน</td>
131.
<td><label>
132.
<input name=
"book_number_number"
type=
"text"
id=
"book_number_number"
onblur=
"JavaScript:doCallAjax();"
value=
"<?php echo $row_Recordset3['book_number_number']; ?>"
/>
133.
<span id=
"mySpan"
></span> </label></td>
134.
<td> </td>
135.
</tr>
136.
<tr>
137.
<td
class
=
"style13"
>ฉบับ</td>
138.
<td><input name=
"book_coppy"
type=
"text"
id=
"book_coppy"
value=
"<?php echo $row_Recordset3['book_copy']; ?>"
/></td>
139.
<td> </td>
140.
</tr>
141.
<tr>
142.
<td
class
=
"style13"
>ชื่อผู้แต่ง</td>
143.
<td><label>
144.
<input name=
"book_author"
type=
"text"
id=
"book_author"
value=
"<?php echo $row_Recordset2['book_author']; ?>"
/>
145.
</label></td>
146.
<td> </td>
147.
</tr>
148.
<tr>
149.
<td
class
=
"style13"
>จำนวนหน้า</td>
150.
<td><label>
151.
<input name=
"book_page"
type=
"text"
id=
"book_page"
onkeypress=
"return chkNumber(this)"
value=
"<?php echo $row_Recordset2['book_page']; ?>"
/>
152.
</label></td>
153.
<td> </td>
154.
</tr>
155.
<tr>
156.
<td
class
=
"style13"
>ครั้งที่พิมพ์</td>
157.
<td><label>
158.
<input name=
"book_timeprint"
type=
"text"
id=
"book_timeprint"
onkeypress=
"return chkNumber(this)"
value=
"<?php echo $row_Recordset2['book_timeprint']; ?>"
/>
159.
</label></td>
160.
<td> </td>
161.
</tr>
162.
<tr>
163.
<td
class
=
"style13"
>ประเภทหนังสือ</td>
164.
<td><label>
165.
<select name=
"book_booktype"
id=
"book_booktype"
title=
"<?php echo $row_Recordset3['book_booktype']; ?>"
>
166.
<option value=
"0"
<?php
if
(!(
strcmp
(0,
$row_Recordset2
[
'book_booktype'
]))) {
echo
"selected=\"selected\""
;} ?>>= กรุณาเลือก =</option>
167.
<?php
168.
do
{
169.
?>
170.
<?php
171.
}
while
(
$row_Recordset1
= mysql_fetch_assoc(
$Recordset1
));
172.
$rows
= mysql_num_rows(
$Recordset1
);
173.
if
(
$rows
> 0) {
174.
mysql_data_seek(
$Recordset1
, 0);
175.
$row_Recordset1
= mysql_fetch_assoc(
$Recordset1
);
176.
}
177.
?>
178.
<?php
179.
do
{
180.
?>
181.
<option value=
"<?php echo $row_Recordset1['booktype_id']?>"
<?php
if
(!(
strcmp
(
$row_Recordset1
[
'booktype_id'
],
$row_Recordset2
[
'book_booktype'
]))) {
echo
"selected=\"selected\""
;} ?>><?php
echo
$row_Recordset1
[
'booktype_name'
]?></option>
182.
<?php
183.
}
while
(
$row_Recordset1
= mysql_fetch_assoc(
$Recordset1
));
184.
$rows
= mysql_num_rows(
$Recordset1
);
185.
if
(
$rows
> 0) {
186.
mysql_data_seek(
$Recordset1
, 0);
187.
$row_Recordset1
= mysql_fetch_assoc(
$Recordset1
);
188.
}
189.
?>
190.
</select>
191.
</label></td>
192.
<td> </td>
193.
</tr>
194.
<tr>
195.
<td
class
=
"style13"
>สำนักพิมพ์</td>
196.
<td><label>
197.
<select name=
"book_press"
id=
"book_press"
title=
"<?php echo $row_Recordset3['book_press']; ?>"
>
198.
<option value=
"0"
<?php
if
(!(
strcmp
(0,
$row_Recordset2
[
'book_press'
]))) {
echo
"selected=\"selected\""
;} ?>>= กรุณาเลือก =</option>
199.
<?php
200.
do
{
201.
?>
202.
<?php
203.
}
while
(
$row_Recordset4
= mysql_fetch_assoc(
$Recordset4
));
204.
$rows
= mysql_num_rows(
$Recordset4
);
205.
if
(
$rows
> 0) {
206.
mysql_data_seek(
$Recordset4
, 0);
207.
$row_Recordset4
= mysql_fetch_assoc(
$Recordset4
);
208.
}
209.
?>
210.
<?php
211.
do
{
212.
?>
213.
<option value=
"<?php echo $row_Recordset4['press_id']?>"
<?php
if
(!(
strcmp
(
$row_Recordset4
[
'press_id'
],
$row_Recordset2
[
'book_press'
]))) {
echo
"selected=\"selected\""
;} ?>><?php
echo
$row_Recordset4
[
'press_name'
]?></option>
214.
<?php
215.
}
while
(
$row_Recordset4
= mysql_fetch_assoc(
$Recordset4
));
216.
$rows
= mysql_num_rows(
$Recordset4
);
217.
if
(
$rows
> 0) {
218.
mysql_data_seek(
$Recordset4
, 0);
219.
$row_Recordset4
= mysql_fetch_assoc(
$Recordset4
);
220.
}
221.
?>
222.
</select>
223.
</label></td>
224.
<td> </td>
225.
</tr>
226.
<tr>
227.
<td> </td>
228.
<td> </td>
229.
<td> </td>
230.
</tr>
231.
<tr>
232.
<td colspan=
"3"
><div align=
"center"
>
233.
<label>
234.
<input type=
"submit"
name=
"acc"
id=
"acc"
value=
"ตกลง"
/>
235.
</label>
236.
<label>
237.
<input name=
"btn_can"
type=
"button"
id=
"btn_can"
onclick=
"MM_goToURL('parent','administrator_book.php');return document.MM_returnValue"
value=
"ยกเลิก"
/>
238.
</label>
239.
</div></td>
240.
</tr>
241.
</table>
242.
<input name=
"hiddenField"
type=
"hidden"
id=
"hiddenField"
value=
"<?php echo $row_Recordset2['book_id']; ?>"
/>
243.
<input name=
"hiddenField2"
type=
"hidden"
id=
"hiddenField2"
value=
"<?php echo $row_Recordset3['id']; ?>"
/>
244.
<input type=
"hidden"
name=
"MM_update"
value=
"form1"
/>
245.
</form>
246.
</body>
247.
</html>
248.
<?php
249.
mysql_free_result(
$Recordset1
);
250.
251.
mysql_free_result(
$Recordset2
);
252.
253.
mysql_free_result(
$Recordset3
);
254.
255.
mysql_free_result(
$Recordset4
);
256.
?>