Skip to content

Commit 5c12243

Browse files
committed
Update the rage-edit page.
1 parent 475ae8e commit 5c12243

1 file changed

Lines changed: 45 additions & 89 deletions

File tree

www/admin/rage-edit.php

Lines changed: 45 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,59 @@
11
<?php
2-
32
require_once './config.php';
43

5-
$page = new AdminPage();
6-
$tvrage = new TvRage();
7-
$id = 0;
8-
9-
// set the current action
10-
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view';
11-
12-
switch($action)
13-
{
14-
case 'update':
15-
$tvrage->refreshRageInfo($_GET["id"]);
16-
17-
if(isset($_GET['from']) && !empty($_GET['from']))
18-
{
19-
header("Location:".$_GET['from']);
20-
exit;
21-
}
22-
23-
header("Location:".WWW_TOP."/rage-edit.php?id=".$_GET["id"]);
24-
exit;
25-
26-
27-
case 'submit':
28-
if ($_POST["id"] == "")
29-
{
30-
$imgbytes = "";
31-
if($_FILES['imagedata']['size'] > 0)
32-
{
33-
$fileName = $_FILES['imagedata']['name'];
34-
$tmpName = $_FILES['imagedata']['tmp_name'];
35-
$fileSize = $_FILES['imagedata']['size'];
36-
$fileType = $_FILES['imagedata']['type'];
37-
38-
//
39-
// check the uploaded file is actually an image.
40-
//
41-
$file_info = getimagesize($tmpName);
42-
if(!empty($file_info))
43-
{
44-
$fp = fopen($tmpName, 'r');
45-
$imgbytes = fread($fp, filesize($tmpName));
46-
fclose($fp);
47-
}
48-
}
49-
50-
$tvrage->add($_POST["rageID"], $_POST["releasetitle"], $_POST["description"], $_POST["genre"], $_POST['country'], $imgbytes);
4+
$page = new AdminPage();
5+
$tvRage = new TvRage(['Settings' => $page->settings]);
6+
7+
$rage = [
8+
'id' => '', 'description' => '', 'releasetitle' => '', 'genre' => '',
9+
'rageid' => '', 'country' => '', 'imgdata' => ''
10+
];
11+
12+
switch ((isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view')) {
13+
case 'submit':
14+
if ($_POST["id"] == '') {
15+
$tvRage->add($_POST["rageid"], $_POST["releasetitle"], $_POST["description"],
16+
$_POST["genre"], $_POST['country'], getImage()
17+
);
18+
} else {
19+
$tvRage->update($_POST["id"], $_POST["rageid"], $_POST["releasetitle"],
20+
$_POST["description"], $_POST["genre"], $_POST['country'], getImage()
21+
);
5122
}
52-
else
53-
{
54-
$imgbytes = "";
55-
if($_FILES['imagedata']['size'] > 0)
56-
{
57-
$fileName = $_FILES['imagedata']['name'];
58-
$tmpName = $_FILES['imagedata']['tmp_name'];
59-
$fileSize = $_FILES['imagedata']['size'];
60-
$fileType = $_FILES['imagedata']['type'];
61-
62-
//
63-
// check the uploaded file is actually an image.
64-
//
65-
$file_info = getimagesize($tmpName);
66-
if(!empty($file_info))
67-
{
68-
$fp = fopen($tmpName, 'r');
69-
$imgbytes = fread($fp, filesize($tmpName));
70-
fclose($fp);
71-
}
72-
}
7323

74-
$tvrage->update($_POST["id"], $_POST["rageID"], $_POST["releasetitle"], $_POST["description"], $_POST["genre"], $_POST['country'], $imgbytes);
75-
}
76-
77-
if(isset($_POST['from']) && !empty($_POST['from']))
78-
{
79-
header("Location:".$_POST['from']);
24+
if (isset($_POST['from']) && !empty($_POST['from'])) {
25+
header("Location:" . $_POST['from']);
8026
exit;
8127
}
8228

83-
header("Location:".WWW_TOP."/rage-list.php");
84-
break;
85-
case 'view':
86-
default:
87-
88-
if (isset($_GET["id"]))
89-
{
90-
$page->title = "Tv Rage Edit";
91-
$id = $_GET["id"];
29+
header("Location:" . WWW_TOP . "/rage-list.php");
30+
break;
9231

93-
$rage = $tvrage->getByID($id);
94-
$page->smarty->assign('rage', $rage);
95-
}
96-
97-
break;
32+
case 'view':
33+
default:
34+
if (isset($_GET["id"])) {
35+
$page->title = "Tv Rage Edit";
36+
$rage = $tvRage->getByID($_GET["id"]);
37+
}
38+
break;
9839
}
9940

100-
$page->title="Add/Edit TV Rage Show Data";
41+
$page->smarty->assign('rage', $rage);
42+
43+
$page->title = "Add/Edit TV Rage Show Data";
10144
$page->content = $page->smarty->fetch('rage-edit.tpl');
10245
$page->render();
10346

47+
function getImage() {
48+
$imgBytes = '';
49+
if ($_FILES['imagedata']['size'] > 0) {
50+
$tmpName = $_FILES['imagedata']['tmp_name'];
51+
// Check the uploaded file is actually an image.
52+
if (!empty(getimagesize($tmpName))) {
53+
$fp = fopen($tmpName, 'r');
54+
$imgBytes = fread($fp, filesize($tmpName));
55+
fclose($fp);
56+
}
57+
}
58+
return $imgBytes;
59+
}

0 commit comments

Comments
 (0)