forked from eromba/taskstep
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit_types.php
104 lines (92 loc) · 3.82 KB
/
edit_types.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
<?php
include("includes/header.php");
$type = (isset($_GET['type'])) ? $_GET['type'] : '';
$getcmd = (isset($_GET['cmd'])) ? $_GET['cmd'] : '';
$postcmd = (isset($_POST['cmd'])) ? $_POST['cmd'] : '';
//actual mysql editing
if($postcmd == "edit" && isset($_POST["submit"]))
{
$eid = $_POST["id"];
$enewtitle = addslashes($_POST["title"]);
$updatequery = mysql_query("UPDATE {$type}s SET title='$enewtitle' WHERE id=$eid");
if($updatequery) echo "<div id='updated' class='fade'><img src='images/pencil_go.png' alt=''/> ".$l_msg_updated[$type]."</div>";
if($_POST["tasks"]){
$eoldtitle = $_POST["oldtitle"];
mysql_query("UPDATE items SET $type='$enewtitle' WHERE $type='$eoldtitle'");
}
}
//adding in mysql
if($postcmd == "add" && isset($_POST["add"]))
{
$title = addslashes($_POST["newtitle"]);
$result = MYSQL_QUERY("INSERT INTO {$type}s (id,title) VALUES ('NULL', '$title')");
echo "<div id='updated' class='fade'><img src='images/add.png' alt=''/> ".$l_msg_added[$type]."</div>";
}
//deleting in mysql
if($getcmd=="delete")
{
$delid = $_GET["id"];
$delquery = mysql_query("DELETE FROM {$type}s WHERE id=$delid");
if($delquery) echo "<div id='deleted' class='fade'><img src='images/bin.png' alt='' /> ".$l_msg_deleted[$type]."</div>";
}
//if the GET cmd has not been initialized, display a list of everything
if(!$getcmd || $getcmd == "delete")
{
echo "<p>".$l_dbp_l2[$type]."</p>";
echo "<div id='editlist'><a href='edit_types.php?type=$type&cmd=add' class='listlinkssmart'><img src='images/add.png' alt='' /> ".$l_dbp_add[$type]."</a>";
$result = mysql_query("SELECT * FROM {$type}s ORDER BY title");
while($r=mysql_fetch_array($result))
{
$title=$r["title"];
$id=$r["id"];
echo "<a href='edit_types.php?type=$type&cmd=edit&id=$id' class='listlinkssmart'><img src='images/pencil.png' alt='' /> $title</a>";
}
echo "</div>";
}
//Edit form
elseif($getcmd == "edit")
{
//DEBUG NB: quick error trap
if(!$_GET["id"])
{
echo "<div class='error' style='font-size:9pt; padding:5px; '><img src='images/exclamation.png' alt='' style='vertical-align:-3px;' /> ".$l_msg_noid."</div>";
echo "<span class='linkback'><a href='edit_types.php?type=$type' class='linkback'>Return to editing {$type}s</a></span></div>";
die;
}
$editid = $_GET["id"];
//DEBUG echo "This would produce an edit form for the context with id $editid <br />";
$editquery = mysql_query("SELECT * FROM {$type}s WHERE id=$editid");
while($r=mysql_fetch_array($editquery))
{
$edittitle = $r["title"];
$editid2 = $r["id"];
}
//DEBUG echo "The MySQL code has matched this to the context with the following: <br />";
//DEBUG echo "ID: $editid2 <br />";
//DEBUG echo "Title: $edittitle <br />";
?>
<form action="edit_types.php?type=<?php echo $type ?>" method="post">
<input type="hidden" name="id" value="<?php echo $editid2; ?>" />
<input type="hidden" name="oldtitle" value="<?php echo $edittitle; ?>" />
<?php echo $l_forms_title ?> <input type="text" name="title" value="<?php echo $edittitle; ?>" size="30" /><br /><br />
<input type="hidden" name="cmd" value="edit">
<input type="checkbox" name="tasks" checked> <?php echo $l_msg_updateassoctasks; ?><br />
<br />
<input type="submit" name="submit" value="<?php echo $l_dbp_edit[$type]; ?>" />
</form>
<?php
echo "<br /><a href='edit_types.php?type=$type&cmd=delete&id=$editid2'><img src='images/bin_empty.png' alt='' /> ".$l_dbp_del[$type]."</a>";
}
//Add form
elseif($getcmd == "add")
{?>
<form action="edit_types.php?type=<?php echo $type ?>" method="post">
<?php echo $l_forms_title ?> <input type="text" name="newtitle" value="<?php echo $l_dbp_new[$type];?>" size="30" /><br />
<br />
<input type="hidden" name="cmd" value="add" />
<input type="submit" name="add" value="<?php echo $l_dbp_add[$type]; ?>" />
</form>
<?php
}
include('includes/footer.php');
?>