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
|
<?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"); require("function_resizethumb.php");
$menuid = htmlspecialchars($_POST["menuid"],ENT_QUOTES); //$backgroundsort = htmlspecialchars($_POST["backgroundsort"],ENT_QUOTES); $nowdate = date("Y-m-d H:i:s"); //print_r($_POST);
$sql = "select max(backgroundid) as maxid "; $sql .= "from background "; $result=mysql_query($sql); $row = mysql_fetch_array($result,MYSQL_ASSOC); $backgroundid = $row{maxid}+1;
// Upload File if ($_FILES['backgroundimage']['name'] <> '') { if (($_FILES["backgroundimage"]["type"] == "image/bmp") || ($_FILES["backgroundimage"]["type"] == "image/BMP") || ($_FILES["backgroundimage"]["type"] == "image/gif") || ($_FILES["backgroundimage"]["type"] == "image/GIF") || ($_FILES["backgroundimage"]["type"] == "image/jpg") || ($_FILES["backgroundimage"]["type"] == "image/JPG") || ($_FILES["backgroundimage"]["type"] == "image/jpeg") || ($_FILES["backgroundimage"]["type"] == "image/JPEG") || ($_FILES["backgroundimage"]["type"] == "image/pjpeg") || ($_FILES["backgroundimage"]["type"] == "image/PJEG") || ($_FILES["backgroundimage"]["type"] == "image/png") || ($_FILES["backgroundimage"]["type"] == "image/x-png") || ($_FILES["backgroundimage"]["type"] == "image/PNG") || ($_FILES["backgroundimage"]["type"] == "image/X-PNG")) { move_uploaded_file ($_FILES['backgroundimage']['tmp_name'], "../images/background/id_".$backgroundid."_".$_FILES['backgroundimage']['name']) or die ("Could not copy the file: background");
$backgroundimageimg = "../images/background/id_".$backgroundid."_".$_FILES['backgroundimage']['name']; createthumb($backgroundimageimg, $backgroundimageimg, 1430, 592); $backgroundimage = "id_".$backgroundid."_".$_FILES['backgroundimage']['name']; } else { // upload error ?> <script language="javascript"> alert("Files must be JPEG, GIF, or PNG"); history.back(); </script> <?php exit; }
} else { $backgroundimage = ""; }
// Sort if ($backgroundsort == '' || $backgroundsort == '0') { $sql = "select max(backgroundsort) as maxid "; $sql .= "from background "; $sql .= "where menuid = $menuid "; $result=mysql_query($sql); $row = mysql_fetch_array($result,MYSQL_ASSOC); $backgroundsort = $row{maxid}+1; } if( mysql_num_rows(mysql_query("SELECT backgroundid FROM background WHERE backgroundsort=$backgroundsort AND menuid = $menuid ")) > 0){ mysql_query("UPDATE background SET backgroundsort= backgroundsort+1 WHERE backgroundsort >=$backgroundsort AND menuid = $menuid "); } $sql = "insert into background (backgroundid, menuid, backgroundimage, backgroundsort, backgroundstatus, creationday, modifyday, cmsloginid) values ('$backgroundid', '$menuid', '$backgroundimage', '$backgroundsort', '1', '$nowdate', '$nowdate', '".$_SESSION['cmsloginid']."')"; mysql_query($sql); if( mysql_errno() > 0 ){ echo 'Add background Error:<br />'. mysql_error() .'<br />SQL: '. $sql; exit; }
mysql_close($dbh);
header("Location: background_index.php?menuid=".$menuid."&msg=Add Successful"); ?>
|