001.
<?php
002.
class
MyClass{
003.
public
function
selQuery(
$sqlTxt
){
004.
if
(preg_match(
'/SELECT/'
,
strtoupper
(
$sqlTxt
))){
005.
$result
= mysql_query(
$sqlTxt
);
006.
$num
= mysql_num_rows(
$result
);
007.
if
(
$num
> 0){
008.
$arrRec
=
array
();
009.
while
(
$rs
= mysql_fetch_assoc(
$result
)){
010.
array_push
(
$arrRec
,
$rs
);
011.
}
012.
return
$arrRec
;
013.
}
else
{
014.
echo
null;
015.
}
016.
}
else
{
017.
echo
null;
018.
}
019.
}
020.
021.
public
function
query(
$sql
){
022.
if
(@mysql_query(
$sql
))
023.
return
true;
024.
else
025.
return
false;
026.
}
027.
028.
public
function
chkUniqData(
$tablename
,
$field
,
$data
){
029.
$result
= mysql_query(
"Select $field From $tablename Where $field = '$data'"
);
030.
$num
= mysql_num_rows(
$result
);
031.
if
(
$num
>= 1)
032.
return
false;
033.
else
034.
return
true;
035.
}
036.
037.
public
function
random_id(
$len
){
038.
srand((double)microtime()*10000000);
039.
$chars
=
"0123456789"
;
040.
$ret_str
=
""
;
041.
$count
= 0;
042.
$chars2
=
""
;
043.
while
(
$count
<
strlen
(
$chars
)){
044.
for
(
$i
=0;
$i
<
$len
;
$i
++){
045.
$chars2
.=
$chars
[
$count
];
046.
}
047.
$count
++;
048.
}
049.
$num
=
strlen
(
$chars2
);
050.
for
(
$i
= 0;
$i
<
$len
;
$i
++)
051.
{
052.
$ret_str
.=
$chars2
[rand()%
$num
];
053.
$ret_str
.=
""
;
054.
}
055.
return
$ret_str
;
056.
}
057.
058.
public
function
getDateFormat(
$timestamp
,
$type
=
"d"
){
059.
$d
=
date
(
"d"
,
$timestamp
);
060.
$m
=
date
(
"m"
,
$timestamp
);
061.
$y
=
date
(
"Y"
,
$timestamp
)+543;
062.
$h
=
date
(
"H"
,
$timestamp
);
063.
$i
=
date
(
"i"
,
$timestamp
);
064.
$s
=
date
(
"s"
,
$timestamp
);
065.
$thai_m
=
array
(
"มกราคม"
,
"กุมภาพันธ์"
,
"มีนาคม"
,
"เมษายน"
,
"พฤษภาคม"
,
"มิถุนายน"
,
"กรกฏาคม"
,
"สิงหาคม"
,
066.
"กันยายน"
,
"ตุลาคม"
,
"พฤศจิกายน"
,
"ธันวาคม"
);
067.
if
(
$type
==
"d"
){
068.
return
$d
.
" "
.
$thai_m
[
$m
-1].
" "
.
$y
;
069.
}
else
if
(
$type
==
"dt"
){
070.
return
$d
.
" "
.
$thai_m
[
$m
-1].
" "
.
$y
.
", เวลา "
.
$h
.
":"
.
$i
.
"น."
;
071.
}
072.
}
073.
074.
public
function
uploadPhoto(
$arrFile
,
$name
,
$dirnm
,
$limit
=0,
$option
=
'w'
){
075.
$array_last
=
explode
(
"."
,
$arrFile
[
'name'
]);
076.
$c
=
count
(
$array_last
)-1;
077.
$filename
=
strtolower
(
$array_last
[
$c
]);
078.
$photo_name
=
$name
.
'.'
.
$filename
;
079.
$chk
=false;
080.
$arrAuthorList
=
array
(
'jpg'
,
'jpeg'
,
'gif'
,
'png'
);
081.
foreach
(
$arrAuthorList
as
$key
){
082.
if
(
$key
==
$filename
){
083.
$chk
=true;
084.
break
;
085.
}
086.
}
087.
if
(
$chk
){
088.
copy
(
$arrFile
[
'tmp_name'
],
$dirnm
.
$photo_name
);
089.
$images
=
$dirnm
.
$photo_name
;
090.
$img_size
=
GetimageSize
(
$images
);
091.
if
(
$option
==
'w'
AND
$limit
>0){
092.
if
(
$img_size
[0]>
$limit
){
093.
$img_width
=
$limit
;
094.
$img_height
=
round
(
$img_width
*
$img_size
[1]/
$img_size
[0]);
095.
}
else
{
096.
$img_width
=
$img_size
[0];
097.
$img_height
=
$img_size
[1];
098.
}
099.
}
else
if
(
$option
==
'h'
AND
$limit
>0){
100.
if
(
$img_size
[1]>
$limit
){
101.
$img_height
=
$limit
;
102.
$img_width
=
round
(
$img_height
*
$img_size
[0]/
$img_size
[1]);
103.
}
else
{
104.
$img_width
=
$img_size
[0];
105.
$img_height
=
$img_size
[1];
106.
}
107.
}
else
{
108.
$img_width
=
$img_size
[0];
109.
$img_height
=
$img_size
[1];
110.
}
111.
112.
if
(
$filename
==
"jpg"
or
$filename
==
"jpeg"
){
113.
$newImg
=ImageCreateFromJPEG(
$images
);
114.
$newX
=ImagesX(
$newImg
);
115.
$newY
=ImagesY(
$newImg
);
116.
$images_fin
=ImageCreateTrueColor(
$img_width
,
$img_height
);
117.
ImageCopyResampled(
$images_fin
,
$newImg
, 0, 0, 0, 0,
$img_width
+1,
$img_height
+1,
$newX
,
$newY
);
118.
ImageJPEG(
$images_fin
,
$dirnm
.
$photo_name
);
119.
}
else
if
(
$filename
==
"gif"
){
120.
$newImg
=ImageCreateFromGIF(
$images
);
121.
$newX
=ImagesX(
$newImg
);
122.
$newY
=ImagesY(
$newImg
);
123.
$images_fin
=ImageCreateTrueColor(
$img_width
,
$img_height
);
124.
ImageCopyResampled(
$images_fin
,
$newImg
, 0, 0, 0, 0,
$img_width
+1,
$img_height
+1,
$newX
,
$newY
);
125.
ImageGIF(
$images_fin
,
$dirnm
.
$photo_name
);
126.
}
else
if
(
$filename
==
"png"
){
127.
$newImg
=ImageCreateFromPNG(
$images
);
128.
$newX
=ImagesX(
$newImg
);
129.
$newY
=ImagesY(
$newImg
);
130.
$images_fin
=ImageCreateTrueColor(
$img_width
,
$img_height
);
131.
ImageCopyResampled(
$images_fin
,
$newImg
, 0, 0, 0, 0,
$img_width
+1,
$img_height
+1,
$newX
,
$newY
);
132.
ImagePNG(
$images_fin
,
$dirnm
.
$photo_name
);
133.
}
134.
135.
ImageDestroy(
$newImg
);
136.
ImageDestroy(
$images_fin
);
137.
138.
unlink(
$arrFile
[
'tmp_name'
]);
139.
return
$photo_name
;
140.
}
else
{
141.
return
null;
142.
}
143.
}
144.
145.
public
function
randomNum(
$num
){
146.
srand((double)microtime()*10000000);
147.
$n
= rand()%
$num
;
148.
return
$n
;
149.
}
150.
151.
public
function
randNonUniqe(
$num
){
152.
srand((double)microtime()*10000000);
153.
$a
=
array
();
154.
while
(
count
(
$a
) <
$num
) {
155.
$n
= rand()%
$num
;
156.
if
(!in_array(
$n
,
$a
))
array_push
(
$a
,
$n
);
157.
}
158.
return
$a
;
159.
}
160.
161.
public
function
getItemsFromCart(
$cart
){
162.
if
(isset(
$cart
)) {
163.
$items
=
explode
(
','
,
$cart
);
164.
$contents
=
array
();
165.
foreach
(
$items
as
$item
) {
166.
$contents
[
$item
] = (isset(
$contents
[
$item
])) ?
$contents
[
$item
] + 1 : 1;
167.
}
168.
return
$contents
;
169.
}
else
{
170.
return
""
;
171.
}
172.
}
173.
}
174.
?>