-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_event.php
150 lines (128 loc) · 5.02 KB
/
edit_event.php
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
<?php
// retrieve one product will be here
// get ID of the product to be edited
$id = isset($_GET['id']) ? $_GET['id'] : die('ERROR: missing ID.');
// include database and object files
include_once 'config/database.php';
include_once 'objects/event.php';
include_once 'objects/teks_berjalan.php';
// get database connection
$database = new Database();
$db = $database->getConnection();
// prepare objects
$event = new Event($db);
$teks = new Teks($db);
// set ID property of product to be edited
$event->id = $id;
// read the details of product to be edited
$event->readOne();
// set page header
$page_title = "Edit Event";
include_once "header.php";
// contents will be here
echo "<div class='right-button-margin'>";
echo "<a href='index.php' class='btn btn-default pull-right'>Home</a>";
echo "</div>";
?>
<!-- 'update product' form will be here -->
<!-- post code will be here -->
<?php
// if the form was submitted
if($_POST){
// set product property values
$event->nama = $_POST['nama'];
$event->keterangan = $_POST['keterangan'];
$event->image = $_POST['image'];
$image=!empty($_FILES["image"]["name"])
? sha1_file($_FILES['image']['tmp_name']) . "-" . basename($_FILES["image"]["name"]) : "";
if(!empty($image)){
echo 'heiii';
$event->image = $image;
}else{
echo 'heiii lo';
$event->image = $_POST['gambar'];
}
$event->tgl_mulai = $_POST['tgl_mulai'];
$event->tgl_siap = $_POST['tgl_siap'];
// update the product
if($event->update()){
echo "<div class='alert alert-success alert-dismissable'>";
echo "Event Telah Diubah.";
echo "</div>";
if(!empty($image)){
echo $event->uploadPhoto();
}else{
$event->image = $_POST['gambar'];
}
}
// if unable to update the product, tell the user
else{
echo "<div class='alert alert-danger alert-dismissable'>";
echo "Gagal mengedit.";
echo "</div>";
}
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"] . "?id={$id}");?>" method="post" enctype="multipart/form-data">
<table class='table table-hover table-responsive table-bordered'>
<tr>
<td>Nama</td>
<td><input type='text' name='nama' value='<?php echo $event->nama; ?>' class='form-control' /></td>
</tr>
<tr>
<td>Keterangan</td>
<td><textarea name='keterangan' class='form-control'><?php echo $event->keterangan; ?></textarea></td>
</tr>
<tr>
<td>Gambar</td>
<td colspan ='2'><img src='uploads/<?= $event->image; ?>' style='width:300px;' /><input type="hidden" name="gambar" value='<?= $event->image; ?>'/><input type="file" name="image"/></td>
</tr>
<tr>
<td>Tanggal Event</td>
<td>
<div class="form-group">
<label> Mulai : </label> <br>
<div class="input-group date form_date col-md-5" data-date="" data-date-format="yyyy-mm-dd" data-link-field="dtp_input1" data-link-format="yyyy-mm-dd">
<input class="form-control" size="10" type="text" name="tgl_mulai" value="<?php echo $event->tgl_mulai; ?>">
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
<input type="hidden" id="dtp_input1" value=""/> <br>
<label> Sampai : </label> <br>
<div class="input-group date form_date col-md-5" data-date="" data-date-format="yyyy-mm-dd" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
<input class="form-control" size="10" type="text" name="tgl_siap" value="<?php echo $event->tgl_siap; ?>">
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
<input type="hidden" id="dtp_input2" value=""/>
</div></td>
</tr>
<tr>
<td>Status</td>
<td colspan='2'>
<select class='form-control' name='status'>
<?php
$status = $event->status;
if($status == '1'){
?>
<option value='0' selected >Aktif</option>
<option value='1'>Tidak Aktif</option>
<?
}else{
?>
<option value='0'>Aktif</option>
<option value='1' selected>Tidak Aktif</option>
</select>
<? } ?>
</td>
</tr>
<tr>
<td></td>
<td>
<button type="submit" class="btn btn-primary">Update</button>
</td>
</tr>
</table>
</form>
<?php
// set page footer
include_once "footer.php";
?>