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
|
<?php include 'config.php';
// Check if the user is logged in
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) { header("Location: login.php"); exit; } require("configure.php");
$pdtitleen = check_input($_POST["pdtitleen"]); $pdtitletc = check_input($_POST["pdtitletc"]); $pddescen = preg_replace("/'/","\'",$_POST["pddescen"]); $pddesctc = preg_replace("/'/","\'",$_POST["pddesctc"]); $pdspecen = preg_replace("/'/","\'",$_POST["pdspecen"]); $pdspectc = preg_replace("/'/","\'",$_POST["pdspectc"]);
$nowdate = date("Y-m-d H:i:s");
$sql = "select max(pdid) as maxid "; $sql .= "from product_detail "; $result=mysql_query($sql); $row = mysql_fetch_array($result,MYSQL_ASSOC); $pdid = $row{maxid}+1;
$pdcatidSelect = $_POST['pdcatidSelect']; //check the product category if empty or not if(empty($_POST['pdcatidSelect'])){ echo "<script>alert('You must select at least one product category for this product!'); history.back(); </script>"; exit; }
//insert the record to the product_cat_item table
$cntpdcatid = count($pdcatidSelect); $i=1; foreach($_POST['pdcatidSelect'] as $pdcatidbox){ $pdcatid[$i++] = $pdcatidbox; }
// Delete Project Category db $sql3 = "DELETE FROM product_cat_item WHERE pdid='$pdid'"; mysql_query($sql3);
for($i=1;$i<=$cntpdcatid;$i++){ if(strlen($pdcatid[$i])> 0){ // Sort $sql = "select max(psort) as maxid "; $sql .= "from product_cat_item WHERE pdcatid = '".$pdcatid[$i]."' "; $result=mysql_query($sql); $row = mysql_fetch_array($result,MYSQL_ASSOC); $psort = $row{maxid}+1;
$sql2 = "insert into product_cat_item (pdid, pdcatid, psort) values ('$pdid', '".$pdcatid[$i]."', '$psort')"; mysql_query($sql2); } }
//record the material logo for that product $material_logo_array = $_POST["material_logo"];
$material_logo = sizeof($material_logo_array); // Delete Project Category db $sql5 = "DELETE FROM prod_mate_logo WHERE pdid='$pdid'"; mysql_query($sql5);
for($i=0;$i<$material_logo;$i++){
$sql2 = "insert into product_material_logo (pdid, material_logoid) values ('$pdid', '".$material_logo_array[$i]."')"; mysql_query($sql2);
}
// copy image $filelimit = 2 * 1048576; //Filelimit in 2MB $x=1;
if ($_FILES['pdimgen']['name'] <> '') { if ($_FILES['pdimgen']['size'] < $filelimit ){
if (($_FILES['pdimgen']["type"] == "image/gif") || ($_FILES['pdimgen']["type"] == "image/GIF") || ($_FILES['pdimgen']["type"] == "image/jpg") || ($_FILES['pdimgen']["type"] == "image/JPG") || ($_FILES['pdimgen']["type"] == "image/jpeg") || ($_FILES['pdimgen']["type"] == "image/JPEG") || ($_FILES['pdimgen']["type"] == "image/pjpeg") || ($_FILES['pdimgen']["type"] == "image/PJEG") || ($_FILES['pdimgen']["type"] == "image/png") || ($_FILES['pdimgen']["type"] == "image/x-png") || ($_FILES['pdimgen']["type"] == "image/PNG") || ($_FILES['pdimgen']["type"] == "image/X-PNG")) {
$filename=$_FILES['pdimgen']['name']; preg_match("/\.([^\.]+)$/", $filename, $file_ext);
copy ($_FILES['pdimgen']['tmp_name'], "../images/product/product_".$pdid.".".$file_ext[1]) or die ("Could not copy the file: Project Photo");
$imagelarge = "../images/product/product_".$pdid.".".$file_ext[1]; //createthumb($imagelarge, $imagelarge, 600, 600);
$pdimgen = "../images/product/product_".$pdid.".".$file_ext[1]; $pdimgen = htmlspecialchars($pdimgen,ENT_QUOTES);
$x++; }
} else { // upload error ?> <script language="javascript"> alert("Files must be JPEG, GIF, or PNG and under 2MB in size"); history.back(); </script> <?php exit; } } else { $pdimgen = ""; }
// End copy image
// copy image $filelimit = 2 * 1048576; //Filelimit in 2MB $x=1;
if ($_FILES['pdimgtc']['name'] <> '') { if ($_FILES['pdimgtc']['size'] < $filelimit ){
if (($_FILES['pdimgtc']["type"] == "image/gif") || ($_FILES['pdimgtc']["type"] == "image/GIF") || ($_FILES['pdimgtc']["type"] == "image/jpg") || ($_FILES['pdimgtc']["type"] == "image/JPG") || ($_FILES['pdimgtc']["type"] == "image/jpeg") || ($_FILES['pdimgtc']["type"] == "image/JPEG") || ($_FILES['pdimgtc']["type"] == "image/pjpeg") || ($_FILES['pdimgtc']["type"] == "image/PJEG") || ($_FILES['pdimgtc']["type"] == "image/png") || ($_FILES['pdimgtc']["type"] == "image/x-png") || ($_FILES['pdimgtc']["type"] == "image/PNG") || ($_FILES['pdimgtc']["type"] == "image/X-PNG")) {
$filename=$_FILES['pdimgtc']['name']; preg_match("/\.([^\.]+)$/", $filename, $file_ext);
copy ($_FILES['pdimgtc']['tmp_name'], "../images/product/product_".$pdid.".".$file_ext[1]) or die ("Could not copy the file: Project Photo");
$imagelarge = "../images/product/product_".$pdid.".".$file_ext[1]; //createthumb($imagelarge, $imagelarge, 600, 600);
$pdimgtc = "../images/product/product_".$pdid.".".$file_ext[1]; $pdimgtc = htmlspecialchars($pdimgtc,ENT_QUOTES);
$x++; }
} else { // upload error ?> <script language="javascript"> alert("Files must be JPEG, GIF, or PNG and under 2MB in size"); history.back(); </script> <?php exit; } } else { $pdimgtc = ""; }
// End copy image
$sql = "insert into product_detail (pdimgen,pdimgtc,pdid, pdtitleen, pdtitletc, pddescen, pddesctc,pdspecen, pdspectc, pdstatus, createdate, lastupdate, createby, lastupby) values ('$pdimgen','$pdimgtc','$pdid', '$pdtitleen', '$pdtitletc', '$pddescen', '$pddesctc','$pdspecen', '$pdspectc', '1', '$nowdate', '$nowdate', '".$_SESSION['cmsloginid']."','".$_SESSION['cmsloginid']."')"; mysql_query($sql); if( mysql_errno() > 0 ){ echo 'Add Product Detail Error:<br />'. mysql_error() .'<br />SQL: '. $sql; exit; }
mysql_close($dbh);
header("Location: product_detail_index.php?msg=Add Successful"); ?>
|