/
site_delete.php
121 lines (107 loc) · 4.67 KB
/
site_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
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
<?php
// delete_site.php - Form for deleting site, moves any associated records to another site the user chooses
//
// SiT (Support Incident Tracker) - Support call tracking system
// Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
//
// Author: Ivan Lucas <ivanlucas[at]users.sourceforge.net>
// This Page Is Valid XHTML 1.0 Transitional!
$permission = 55; // Delete Sites/Contacts
require ('core.php');
require (APPLICATION_LIBPATH . 'functions.inc.php');
// This page requires authentication
require (APPLICATION_LIBPATH . 'auth.inc.php');
// External variables
$id = cleanvar($_REQUEST['id']);
$destinationid = cleanvar($_REQUEST['destinationid']);
if (empty($id))
{
include (APPLICATION_INCPATH . 'htmlheader.inc.php');
echo "<h2>{$strDeleteSite}</h2>";
echo "<form action='{$_SERVER['PHP_SELF']}?action=delete' method='post'>";
echo "<table align='center'>";
echo "<tr><th>{$strSite}:</th><td>".site_drop_down('id', 0)."</td></tr>";
echo "</table>";
echo "<p><input name='submit' type='submit' value='{$strDelete}' /></p>";
echo "</form>";
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
}
else
{
if (empty($destinationid))
{
include (APPLICATION_INCPATH . 'htmlheader.inc.php');
echo "<h2>{$strDeleteSite}</h2>";
$sql="SELECT * FROM `{$dbSites}` WHERE id='$id' LIMIT 1";
$siteresult = mysql_query($sql);
$site = mysql_fetch_object($siteresult);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
echo "<table align='center' class='vertical'>";
echo "<tr><th>{$strSite}:</th><td><h3>{$site->name}</h3></td></tr>";
echo "<tr><th>{$strDepartment}:</th><td>{$site->department}</td></tr>";
echo "<tr><th>{$strAddress1}:</th><td>{$site->address1}</td></tr>";
echo "</table>";
// Look for associated contacts
$sql = "SELECT COUNT(id) FROM `{$dbContacts}` WHERE siteid='$id'";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
list($numcontacts) = mysql_fetch_row($result);
if ($numcontacts > 0)
{
echo "<p align='center' class='warning'>".sprintf($strNumContactsAssignedToSite, $numcontacts)."</p>";
}
// Look for associated maintenance contracts
$sql = "SELECT COUNT(id) FROM `{$dbMaintenance}` WHERE site='$id'";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
list($numcontracts) = mysql_fetch_row($result);
if ($numcontracts>0)
{
echo "<p align='center' class='warning'>".sprintf($strNumContractsAssignedToSite, $numcontracts)."</p>";
}
if ($numcontacts > 0 OR $numcontracts > 0)
{
echo "<p align='center'>{$strInOrderToDelete}</p>";
echo "<form action='{$_SERVER['PHP_SELF']}?action=delete' method='post'>";
echo "<table align='center'>";
echo "<tr><th>{$strSite}:</th><td>".site_drop_down('destinationid', 0)."</td></tr>";
echo "</table>";
echo "<input type='hidden' name='id' value='$id' />";
echo "<p><input name='submit' type='submit' value='{$strDelete}' /></p>";
echo "</form>";
}
else
{
$sql = "DELETE FROM `{$dbSites}` WHERE id='$id' LIMIT 1";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR);
else
{
// FIXME html headers need sorting here, we don't want the header before we do this
html_redirect("sites.php?search_string=A");
}
}
include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
}
else
{
// Records need moving before we delete
// Move contacts
$sql = "UPDATE `{$dbContacts}` SET siteid='$destinationid' WHERE siteid='$id'";
mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR);
// Move contracts
$sql = "UPDATE `{$dbMaintenance}` SET site='$destinationid' WHERE site='$id'";
mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR);
$sql = "DELETE FROM `{$dbSites}` WHERE id='$id' LIMIT 1";
$result = mysql_query($sql);
if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR);
journal(CFG_LOGGING_NORMAL, 'Site Deleted', "Site $id was deleted", CFG_JOURNAL_SITES, $id);
html_redirect("sites.php?search_string=A");
}
}
?>