-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
142 lines (133 loc) · 5.06 KB
/
index.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
<?php
/**
* Last updated $Date: 2007-03-09 14:26:08 +0000 (Fri, 09 Mar 2007) $
* by $Author: andybrock $
*
* This file is $Revision: 331 $
* $HeadURL: https://svn.sf.net/svnroot/camranbss/camra/nbss/version2/admin/pubs/index.php $
**/
$title='Pub Admin';
$access = array('admin','sysadmin');
include('../../includes/base.php');
include(DOCROOT.'/skin/header.php');
?>
<h2>Pub Administration</h2>
<?php
if ( $request->get('post', 'town_id') ) {$town_id = $request->get('post', 'town_id');}
elseif ( $request->get('get', 'town_id') ) {$town_id = $request->get('get', 'town_id');}
else {$town_id = '';}
if ( $request->get('get', 'pub_id') ) {$pub_id = $request->get('get', 'pub_id');}
elseif ( $request->get('post', 'pub_id') ) {$pub_id = $request->get('post', 'pub_id');}
else {$pub_id = '';}
$form = new Form('pubadmin'.$town_id.'-'.$pub_id);
$form->class = 'neoAdminForm';
$form->validationerrormsg = 'Please complete the following fields correctly.<br>Click on name to jump to error.';
if ($form->submitted)
{
$pub = array(
'id'=>$pub_id,
'town_id'=>$town_id,
'brewery_id'=>$request->get('post', 'brewery_id'),
'name'=>$request->get('post', 'name'),
'notes'=>$request->get('post', 'notes'),
'active'=>($request->get('post', 'active')!=1?0:1) );
if ( 0 == $form->submiterrors )
{
if ( 'updatePub'==$form->submittedaction )
{
if ('new' == $pub_id)
{
$sql = "INSERT INTO ".$config->get('database', 'tablePrefix')."pub (name, town_id, brewery_id, notes, active) VALUES ('{$pub['name']}', {$pub['town_id']}, {$pub['brewery_id']}, '{$pub['notes']}', {$pub['active']});";
$mesg = 'Created new pub: '.$pub['name'];
}
else
{
$sql = "UPDATE ".$config->get('database', 'tablePrefix')."pub SET name='{$pub['name']}', town_id={$pub['town_id']}, brewery_id={$pub['brewery_id']}, notes='{$pub['notes']}', active={$pub['active']} WHERE id={$pub['id']};";
$mesg = 'Updated pub: '.$pub['name'];
}
getQueryResults($sql);
header('Location: '.$config->get('web','root').'/admin/pubs/?mesg=Updated+pub+list&town_id='.$town_id);
exit;
}
}
}
else
{
/* Form has not been submitted */
if ( ''!=$town_id )
{
$town = reset(getQueryResults('SELECT * FROM '.$config->get('database', 'tablePrefix').'town WHERE id='.$town_id));
if ( !isset($pub) )
{
$pub = array('id'=>'new', 'town_id'=>$town_id, 'name'=>'', 'abv'=>'', 'og'=>'', 'notes'=>'');
}
}
else
{
$towns=getQueryResults('SELECT id, name FROM '.$config->get('database', 'tablePrefix').'town WHERE active=1 ORDER BY name;');
}
}
if ( isset($towns) )
{
$form->addField('town_id', 'select');
$form->addLabel('Select town');
$form->addOptions(array(''=>'Select town first'));
$form->addOptions($towns, 'id', 'name');
$form->addField('selectTown', 'submit', 'Select this town');
$form->addInputClass('btnSubmit');
}
else
{
print('<h3>pubs for '.$town['name'].'</h3>');
if ( ''!=$pub_id )
{
if ( 'new'!=$pub_id )
{
$pub = reset(getQueryResults('SELECT * FROM '.$config->get('database', 'tablePrefix').'pub WHERE id='.$pub_id));
}
$form->addField('town_id', 'hidden', $town_id);
$form->addField('pub_id', 'hidden', $pub_id);
$form->addField('name', 'text', $pub['name']);
$form->addLabel('pub Name');
$form->addFieldValidation('required');
$form->addField('brewery_id', 'select', $pub['brewery_id']);
$form->addLabel('Brewery Owned?');
$form->addOptions(array('0'=>'None/Freehold'));
$form->addOptions(getQueryResults('SELECT id,name FROM '.$config->get('database', 'tablePrefix').'brewery ORDER by name'), 'id', 'name');
$form->addField('active', 'checkbox', $pub['active']);
$form->addLabel('Active', null, 'right');
$form->addOptions(array(1,0));
$form->addField('notes', 'textarea', $pub['notes']);
$form->addLabel('Notes');
if ( 'new' == $pub_id )
{
$form->addField('updatePub', 'submit', 'Create pub');
}
else
{
$form->addField('updatePub', 'submit', 'Update pub');
}
$form->addInputClass('btnSubmit');
$form->addField('resetForm', 'reset', 'Reset Form');
$form->addInputClass('btnReset');
$form->addContent('<div class="reset"><a class="btnReset fleft" href="'.$config->get('web','root').'/admin/pubs/?town_id='.$town_id.'">Cancel & Pick another pub</a></div>');
}
else
{
$pubs = getQueryResults('SELECT * FROM '.$config->get('database', 'tablePrefix').'pub WHERE town_id='.$town_id);
?>
<div class="reset"><a class="btnReset fleft" href="<?php echo $config->get('web', 'root')?>/admin/pubs/?town_id=<?php echo $town_id;?>&pub_id=new">Add new pub</a></div>
<div class="reset"><a class="btnReset fleft" href="<?php echo $config->get('web', 'root')?>/admin/pubs/">Go back to the town list</a></div>
<p class="clear">Or edit existing pubs:</p>
<?php
print('<ul>');
foreach ($pubs as $ipub)
{
print('<li><a href="?town_id='.$town_id.'&pub_id='.$ipub['id'].'">'.$ipub['name'].'</a></li>');
}
print('</ul>');
}
}
print $form->display().$form->submiterrormsg;
include(DOCROOT.'/skin/footer.php');
?>