-
Notifications
You must be signed in to change notification settings - Fork 2
/
item.php
117 lines (105 loc) · 2.7 KB
/
item.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
<?php
set_include_path('backbone:components:content:render:model:scripts:styles:images');
require_once('Item.php');
require_once('View.php');
require_once('Page.php');
require_once('Template.php');
require_once('Image.php');
require_once('RedirectBrowserException.php');
require_once('Breadcrumb.php');
require_once('User.php');
$tmpl = new Template();
$tmpl->itemid = isset($_GET['id']) ? $_GET['id'] : -1;
$tmpl->action = isset($_GET['action']) ? $_GET['action'] : null;
$tmpl->code = isset($_GET['code']) ? $_GET['code'] : -1;
$tmpl->item = Item::getByID($tmpl->itemid);
switch( $tmpl->action )
{
case 'add':
$page = new Page(1, "OrderUp - Create New Item");
break;
case 'edit':
checkLogin(array(1,2));
$page = new Page(1, "OrderUp - Edit Existing Item");
$img = new Image("../images/".$tmpl->item->image, "../images/" . preg_replace('#(\.[\w]+)#', '_50x50$1', $tmpl->item->image));
if( !$img->check() )
{
$img->resize(50, 50, false);
$img->output();
$img->clean();
}
break;
case 'delete':
checkLogin(array(1,2));
$page = new Page(1, "OrderUp - Delete Existing Item");
break;
case null:
default:
$page = new Page(1, "OrderUp - View Item");
break;
}
if( !$tmpl->item )
{
if( $tmpl->code == -1 && $tmpl->action == null )
{
$tmpl->code = 0;
}
unset($tmpl->item);
}
else
{
$tmpl->breadcrumb = new Breadcrumb('item', $tmpl->item->itemid);
View::add($_SESSION['userid'], $tmpl->item->itemid);
$usr = User::getByID($_SESSION['userid']);
$tmp = array_slice($usr->Predict->recommend($tmpl->item), 0, 6);
$tmpl->recommendations = array();
foreach( $tmp as $rec )
{
array_push($tmpl->recommendations, Item::getByID($rec['itemid']));
}
}
switch( $tmpl->code )
{
case 0:
$tmpl->message = "Could not find item.";
$tmpl->css = "error";
break;
case 10:
$tmpl->message = "Deleting item succeeded.";
$tmpl->css = "okay";
break;
case 11:
$tmpl->message = "Deleting item failed.";
$tmpl->css = "error";
break;
case 13:
$tmpl->message = "Adding item succeeded.";
$tmpl->css = "okay";
break;
case 14:
$tmpl->message = "Updating item succeeded.";
$tmpl->css = "okay";
break;
default:
break;
}
$page->run();
$html = $tmpl->build('item.html');
$css = $tmpl->build('item.css');
$js = $tmpl->build('item.js');
$appContent = array(
'html' => $html,
'css' => array( 'code' => $css,
'link' => 'item'
),
'js' => $js
);
print $page->build($appContent);
function checkLogin($roles)
{
if( !in_array($_SESSION['roleid'], $roles) )
{
throw new RedirectBrowserException("login.php?code=10");
}
}
?>