Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sucs-site
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laurence Sebastian Bowes
sucs-site
Commits
79a8e3d6
Commit
79a8e3d6
authored
16 years ago
by
Tim Clark
Browse files
Options
Downloads
Patches
Plain Diff
Adds the junk system
parent
b4f97741
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/junk.php
+147
-0
147 additions, 0 deletions
components/junk.php
templates/junk.tpl
+106
-0
106 additions, 0 deletions
templates/junk.tpl
with
253 additions
and
0 deletions
components/junk.php
0 → 100644
+
147
−
0
View file @
79a8e3d6
<?php
// Set defaults
$mode
=
"list"
;
$admin
=
false
;
$admin_group
=
"staff"
;
$admin
=
isset
(
$session
->
groups
[
$admin_group
]);
// If your an admin and the path ends in Edit/ then a number put it into edit mode
// create canedit rules
$canedit
=
isset
(
$pathlist
[(
$component
[
depth
]
/
2
)
+
1
]);
$canedit
=
$canedit
&&
isset
(
$pathlist
[(
$component
[
depth
]
/
2
)
+
2
]);
$canedit
=
$canedit
&&
$pathlist
[(
$component
[
depth
]
/
2
)
+
1
]
==
'Edit'
;
$canedit
=
$canedit
&&
is_numeric
(
$pathlist
[(
$component
[
depth
]
/
2
)
+
2
]);
$canedit
=
$canedit
&&
$admin
;
// Apply canedit rules
if
(
$canedit
){
$id
=
$pathlist
[(
$component
[
depth
]
/
2
)
+
2
];
$items
=
$DB
->
GetAll
(
"SELECT id, title, category, description, donated_by, status FROM inventory WHERE id=? AND requested_by IS NULL"
,
$id
);
if
(
sizeof
(
$items
)
===
1
){
$item
=
$items
[
0
];
$smarty
->
assign
(
"item"
,
$item
);
$mode
=
"edit"
;
}
}
// If your an admin and the path ends in Add put it into add mode
// create canadd rules
$canadd
=
isset
(
$pathlist
[(
$component
[
depth
]
/
2
)
+
1
]);
$canadd
=
$canadd
&&
$pathlist
[(
$component
[
depth
]
/
2
)
+
1
]
==
'Add'
;
$canadd
=
$canadd
&&
$admin
;
// Apply canadd rules
if
(
$canadd
){
$mode
=
"add"
;}
// Process actions before retriving the data
// List request data
if
(
$session
->
loggedin
&&
isset
(
$_REQUEST
[
'action'
]))
{
// Junk Requests
if
(
$_REQUEST
[
'action'
]
==
"Request"
)
{
// Request Item if its available
$query
=
"UPDATE inventory SET requested_by=?, requested_on=now() WHERE id=? AND requested_by IS NULL"
;
$DB
->
Query
(
$query
,
array
(
$session
->
username
,
$_REQUEST
[
'item'
]));
}
elseif
(
$_REQUEST
[
'action'
]
==
"Un-Request"
)
{
// Un-Request Item
if
(
$admin
){
// if your admin just do it
$query
=
"UPDATE inventory SET requested_by=null, requested_on=null WHERE id=?"
;
$array
=
array
(
$_REQUEST
[
'item'
]);
}
else
{
// if not admin check if you requested it first
$query
=
"UPDATE inventory SET requested_by=null, requested_on=null WHERE id=? AND requested_by=?"
;
$array
=
array
(
$_REQUEST
[
'item'
],
$session
->
username
);
}
$DB
->
Query
(
$query
,
$array
);
}
elseif
(
$_REQUEST
[
'action'
]
==
"Take"
&&
$admin
){
// Take item, if your admin
$query
=
"UPDATE inventory SET taken_on=now() WHERE id=? AND requested_by IS NOT NULL"
;
$DB
->
Query
(
$query
,
$_REQUEST
[
'item'
]);
}
elseif
(
$_REQUEST
[
'action'
]
==
"Remove"
&&
$admin
){
// Remove item, if your admin and its been taken
$query
=
"DELETE FROM inventory WHERE id=? AND taken_on IS NOT NULL"
;
$DB
->
Query
(
$query
,
$_REQUEST
[
'item'
]);
}
elseif
(
$_REQUEST
[
'action'
]
==
"Not Junk"
&&
$admin
){
// Mark item as not junk if its not been requested and your admin
$query
=
"UPDATE inventory SET status='unknown' WHERE id=? AND requested_by IS NULL"
;
$DB
->
Query
(
$query
,
$_REQUEST
[
'item'
]);
}
elseif
(
$_REQUEST
[
'action'
]
==
"Junk"
&&
$admin
){
// Mark item as junk, if your admin
$query
=
"UPDATE inventory SET status='junk' WHERE id=?"
;
$DB
->
Query
(
$query
,
$_REQUEST
[
'item'
]);
}
}
// Update/Add item
if
(
$session
->
loggedin
&&
$admin
&&
(
isset
(
$_REQUEST
[
'update'
])
||
isset
(
$_REQUEST
[
'add'
])))
{
// Update/Add item if title and category are filled in else error
if
(
$_REQUEST
[
'title'
]
!=
""
&&
$_REQUEST
[
'category'
]
!=
""
)
{
// if the description is blank, return null
if
(
$_REQUEST
[
'description'
]
==
""
){
$description
=
null
;
}
else
{
$description
=
$_REQUEST
[
'description'
];
}
// if the donated_by is blank, return null
if
(
$_REQUEST
[
'donated_by'
]
==
""
){
$donated_by
=
null
;
}
else
{
$donated_by
=
$_REQUEST
[
'donated_by'
];
}
// run the query
if
(
isset
(
$_REQUEST
[
'update'
])){
$query
=
"UPDATE inventory SET title=?, category=?, description=?, donated_by=?, status=? WHERE id=?"
;
$array
=
array
(
$_REQUEST
[
'title'
],
$_REQUEST
[
'category'
],
$description
,
$donated_by
,
$_REQUEST
[
'status'
],
$_REQUEST
[
'id'
]);
message_flash
(
"Item Updated"
);
}
elseif
(
isset
(
$_REQUEST
[
'add'
])){
$query
=
"INSERT INTO inventory (title, category, description, donated_by, status) VALUES (?, ?, ?, ?, ?)"
;
$array
=
array
(
$_REQUEST
[
'title'
],
$_REQUEST
[
'category'
],
$description
,
$donated_by
,
$_REQUEST
[
'status'
]);
message_flash
(
"Item Added"
);
}
$DB
->
Query
(
$query
,
$array
);
}
else
{
trigger_error
(
"Required field(s) missing"
,
E_USER_WARNING
);
}
}
if
(
$mode
==
'list'
){
// Get junk from database, and give admin the full list
if
(
$admin
==
true
){
$junk
=
$DB
->
GetAll
(
"SELECT * FROM inventory ORDER BY category"
);
}
else
{
$junk
=
$DB
->
GetAll
(
"SELECT * FROM inventory WHERE status = 'junk' ORDER BY category"
);
}
$smarty
->
assign
(
"junk"
,
$junk
);
// Check there is some junk
if
(
sizeof
(
$junk
)
<
1
)
{
$mode
=
"nojunk"
;
}
}
// Generate output
$smarty
->
assign
(
"statuses"
,
array
(
"unknown"
,
"in use"
,
"wanted"
,
"junk"
));
$smarty
->
assign
(
"componentpath"
,
$baseurl
.
$component
[
path
]);
$smarty
->
assign
(
"mode"
,
$mode
);
$smarty
->
assign
(
"admin"
,
$admin
);
$output
=
$smarty
->
fetch
(
"junk.tpl"
);
$smarty
->
assign
(
"title"
,
"Junk List"
);
$smarty
->
assign
(
"body"
,
$output
);
?>
This diff is collapsed.
Click to expand it.
templates/junk.tpl
0 → 100644
+
106
−
0
View file @
79a8e3d6
{
if
$mode
==
'list'
}
{
foreach
name
=
junk
from
=
$junk
item
=
junk
}
<div
class=
"box"
>
<div
class=
"boxhead"
>
<h3>
{
$junk.title
}
</h3>
</div>
<div
class=
"boxcontent"
>
<p>
<h3>
{
$junk.category
}
</h3>
{
$junk.description
}
{
if
$junk.donated_by
!=
null
}
<br
/><strong>
Donated by:
</strong>
{
$junk.donated_by
}
{/
if
}
{
if
$session
->
loggedin
}
{
if
$admin
||
$junk.status
==
'junk'
}
<form
action=
"
{
$url
}
"
method=
"POST"
>
<input
type=
"hidden"
name=
"item"
value=
"
{
$junk.id
}
"
/>
{
if
$junk.status
==
'junk'
}
{
if
$junk.requested_by
==
null
}
<input
type=
"submit"
name=
"action"
value=
"Request"
/>
{
elseif
(
$junk.requested_by
==
$session
->
username
||
$admin
)
&&
$junk.taken_on
==
null
}
<input
type=
"submit"
name=
"action"
value=
"Un-Request"
/>
{/
if
}
{
if
$admin
}
{
if
$junk.requested_by
!=
null
&&
$junk.taken_on
==
null
}
<input
type=
"submit"
name=
"action"
value=
"Take"
/>
{
elseif
$junk.taken_on
!=
null
}
<input
type=
"submit"
name=
"action"
value=
"Remove"
/>
{
elseif
$junk.requested_by
==
null
}
<input
type=
"submit"
name=
"action"
value=
"Not Junk"
/>
{/
if
}
{/
if
}
{
elseif
$admin
}
<input
type=
"submit"
name=
"action"
value=
"Junk"
/>
{/
if
}
</form>
{/
if
}
{/
if
}
</p>
{
if
$admin
&&
$junk.requested_by
==
null
}
<div
class=
"edit"
>
<a
href=
"
{
$componentpath
}
/Edit/
{
$junk.id
}
"
>
Edit
</a>
<div
class=
"clear"
></div>
</div>
{/
if
}
</div>
<div
class=
"boxfoot"
><p>
{
if
$junk.status
!=
'junk'
}
Not Junk
{
elseif
$junk.requested_by
==
null
}
Available
{
elseif
$junk.taken_on
==
null
}
Requested by
{
$junk.requested_by
}
on
{
$junk.requested_on
|
date_format
:
"%e %b %Y"
}
{
else
}
Taken by
{
$junk.requested_by
}
on
{
$junk.taken_on
|
date_format
:
"%e %b %Y"
}
{/
if
}
</p></div>
</div>
{/
foreach
}
{
if
$admin
}
<div
class=
"edit"
>
<a
href=
"
{
$componentpath
}
/Add"
>
Add
</a>
<div
class=
"clear"
></div>
</div>
{/
if
}
{
elseif
(
$mode
==
'edit'
||
$mode
==
'add'
)
&&
$admin
}
<fieldset>
<legend>
{
if
$mode
==
'edit'
}
Edit
{
else
}
New
{/
if
}
Item
</legend>
<form
action=
"
{
$componentpath
}
"
method=
"POST"
>
<input
type=
"hidden"
name=
"id"
value=
"
{
$item.id
}
"
/>
<div
class=
"row"
>
<label
for=
"title"
>
Title*
</label>
<span
class=
"textinput"
><input
type=
"text"
name=
"title"
{
if
$mode
==
'edit'
}
value=
"
{
$item.title
}
"
{/
if
}
/></span>
</div>
<div
class=
"row"
>
<label
for=
"category"
>
Category*
</label>
<span
class=
"textinput"
><input
type=
"text"
name=
"category"
{
if
$mode
==
'edit'
}
value=
"
{
$item.category
}
"
{/
if
}
/></span>
</div>
<div
class=
"row"
>
<label
for=
"description"
>
Description
</label>
<span
class=
"textinput"
><textarea
name=
"description"
cols=
"25"
rows=
"3"
>
{
if
$mode
==
'edit'
}{
$item.description
}{/
if
}
</textarea></span>
</div>
<div
class=
"row"
>
<label
for=
"donated_by"
>
Donated by
</label>
<span
class=
"textinput"
><input
type=
"text"
name=
"donated_by"
{
if
$mode
==
'edit'
}
value=
"
{
$item.donated_by
}
"
{/
if
}
/></span>
</div>
<div
class=
"row"
>
<label
for=
"status"
>
Status
</label>
<span
class=
"textinput"
>
<select
name=
"status"
>
{
foreach
name
=
statuses
from
=
$statuses
item
=
status
}
<option
{
if
(
$status
==
$item.status
)
&&
(
$mode
==
'edit'
)
}
selected=
"selected"
{/
if
}
>
{
$status
}
</option>
{
foreachelse
}
<option>
unknown
</option>
{/
foreach
}
</select>
</span>
</div>
<div
class=
"row"
>
<span
class=
"textinput"
><input
type=
"submit"
name=
"
{
if
$mode
==
'edit'
}
update
{
else
}
add
{/
if
}
"
value=
"
{
if
$mode
==
'edit'
}
Update
{
else
}
Add
{/
if
}
"
/></span>
<div
class=
"note row"
>
* denotes require fields
</div>
</div>
<div
class=
"clear"
></div>
</form>
</fieldset>
{/
if
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment