-
Notifications
You must be signed in to change notification settings - Fork 6
/
listing_delete.php
95 lines (76 loc) · 2.81 KB
/
listing_delete.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
<?php
include_once("includes/inc.global.php");
$cUser->MustBeLoggedOn();
$p->site_section = LISTINGS;
if ($_REQUEST["type"]==OFFER_LISTING)
$p->page_title = _("Delete Offered Listings");
else
$p->page_title = _("Delete Wanted Listings");
include_once("classes/class.listing.php");
include("includes/inc.forms.php");
$message = "";
// First, need to change the default form template so checkbox comes before the label
$renderer->setElementTemplate('<TR><TD><LABEL>{element}<!-- BEGIN required --><font> *</font><!-- END required --></FONT><!-- BEGIN error --><font color=RED size=2> *{error}*</font><br /><!-- END error --> <FONT SIZE=2>{label}</FONT></LABEL></TD></TR>');
$form->addElement('hidden','mode',$_REQUEST['mode']);
$member = new cMember;
if($_REQUEST["mode"] == "admin") {
$cUser->MustBeLevel(1);
$member->LoadMember($_REQUEST["member_id"]);
}
else {
$member = $cUser;
}
$title_list = new cTitleList($_REQUEST['type']);
$titles = $title_list->MakeTitleArray($member->member_id);
$listings_exist = false;
while (list($key, $title) = each ($titles)) {
$form->addElement('checkbox', $key, $title);
$listings_exist=true;
}
if ($listings_exist) {
$form->addElement('static', null, null);
$form->addElement('submit', 'btnSubmit', _("Delete"));
} else {
if($_REQUEST["mode"] == "self")
if ($_REQUEST["type"]==OFFER_LISTING)
$message = _("You don't currently have any Offered listings.");
else
$message = _("You don't currently have any Wanted listings.");
else
if ($_REQUEST["type"]==OFFER_LISTING)
$message = $member->PrimaryName()." "._("doesn't currently have any Offered listings.");
else
$message = $member->PrimaryName()." "._("doesn't currently have any Wanted listings.");
}
if ($form->validate()) { // Form is validated so processes the data
$form->freeze();
$form->process('process_data', false);
} else {
$p->DisplayPage($form->toHtml() ."<BR>". $message); // just display the form
}
function process_data ($values) {
global $p, $cErr, $member, $cUser;
$list = "";
$deleted = 0;
$listing = new cListing;
while (list ($key, $value) = each ($values)) {
$affected = 0;
if(is_numeric($key)) // Two of the values are hidden fields. Need to skip those.
// Check that we only delete the member's listings
$listing->LoadListing($key);
if ($listing->member->member_id == $member->member_id)
$affected = $listing->DeleteListing($key);
else
$cErr->InternalError($cUser->member_id
." tried to delete listing ". $listing->listing_id ." owned by ". $listing->member->member_id);
$deleted += $affected;
}
if($deleted == 1)
$list .= _("1 listing deleted").".";
elseif($deleted > 1)
$list .= $deleted . " "._("listings deleted");
else
$cErr->Error(_("There was an error deleting the listings. Did you check any boxes?"));
$p->DisplayPage($list);
}
?>