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
|
<?php include_once('../../check_login.php'); ini_set('display_errors',0); $id =$_POST['id']; unset($_POST['id']); $code_array = formatPostData($_POST['code']); $country_array = $_POST['country']; unset($_POST['code']); unset($_POST['country']); if($id){ //update db $data = $_POST; unset($data['x']); unset($data['y']); $data['lastupdate'] = $nowdate; $data['lastupby'] = $_SESSION['cmsloginid']; $sql = mysql_install($data,'redemption_event','edit','refid'); $data['refid']=$id; $arraykey=array_keys($data); for($i=0;$i<count($arraykey);$i++){ $parameters[$i]=$data[$arraykey[$i]]; } if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } if (!$sth->execute($parameters)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } $action_title = 'Edit Success'; }else{ //refid $sql = "select max(refid) as maxid from redemption_event"; if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } if (!$sth->execute()) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } $row = $sth->fetch(PDO::FETCH_ASSOC); $id = $row{"maxid"} + 1; $_POST['refid'] = $id; //insert db $data = $_POST; unset($data['x']); unset($data['y']); $data['status'] = 1; $data['lastupdate'] = $nowdate; $data['lastupby'] = $_SESSION['cmsloginid']; $sql = mysql_install($data,'redemption_event','add'); $arraykey=array_keys($data); for($i=0;$i<count($arraykey);$i++){ $parameters[$i]=$data[$arraykey[$i]]; } if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } if (!$sth->execute($parameters)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } $action_title = 'Add Success'; } // Upload File if ($_FILES["photo_en"]['name'] <> '') { //check if image type is valid or not $filename = $_FILES["photo_en"]['name']; preg_match("/\.([^\.]+)$/", $filename, $file_ext); $newfilename = $id."_refid.".$file_ext[1]; // default length 8 move_uploaded_file($_FILES["photo_en"]['tmp_name'], "../../../file/redemption_event/".$newfilename) or die ("Could not copy the file"); $photo = $newfilename; unset($data); $data['photo_en'] = $photo; $sql = mysql_install($data,'redemption_event','edit','refid'); $data['refid'] = $id; $arraykey=array_keys($data); unset($parameters); for($i=0;$i<count($arraykey);$i++){ $parameters[$i]=$data[$arraykey[$i]]; } if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } if (!$sth->execute($parameters)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } } // $sql = "DELETE FROM redemption_event_country where event_refid = ?"; $parameters = array($id); if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } if (!$sth->execute($parameters)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } if(is_array($country_array)){ foreach($country_array as $array){ if($array){ unset($data); $data['event_refid'] = $id; $data['country'] = $array; $data['lastupdate'] = $nowdate; $sql = mysql_install($data,'redemption_event_country','add'); $arraykey=array_keys($data); unset($parameters); for($i=0;$i<count($arraykey);$i++){ $parameters[$i]=$data[$arraykey[$i]]; } if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } if (!$sth->execute($parameters)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } } } } if(is_array($code_array)){ foreach($code_array as $array){ if($array['to'] && $array['from']){ for($i2=$array['to'];$i2<=$array['from'];$i2++){ unset($data); $data['event_refid'] = $id; $data['serial_number'] = $array['defult'].$array['number'].$array['date'].sprintf("%05d",$i2); $data['lastupdate'] = $nowdate; $sql = mysql_install($data,'redemption_event_code','add'); $arraykey=array_keys($data); unset($parameters); for($i=0;$i<count($arraykey);$i++){ $parameters[$i]=$data[$arraykey[$i]]; } if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } if (!$sth->execute($parameters)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } } } } } header("Location: redemption_event_index.php?msg=".$action_title); exit();
?>
|