forked from sivann/itdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditfiletypes.php
More file actions
105 lines (80 loc) · 3.22 KB
/
Copy patheditfiletypes.php
File metadata and controls
105 lines (80 loc) · 3.22 KB
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
<?php
if (!isset($initok)) {echo "do not run this script directly";exit;}
/* Spiros Ioannou 2009 , sivann _at_ gmail.com */
//echo "<pre>"; print_r($_GET); print_r($_POST);
$internaltypes="10";
$formvars=array("id", "typedesc");
//form submitted
if (isset($_GET['deltype']) && $_GET['deltype']<=$internaltypes) { //delete an entry
echo "Type '{$_GET['deltype']}' cannot be deleted: internal type";
}
elseif (isset($_GET['deltype'])) { //delete an item entry
$deltype=$_GET['deltype'];
$sql="SELECT count(id) count from files WHERE type=$deltype";
$sth=db_execute($dbh,$sql);
$r=$sth->fetch(PDO::FETCH_ASSOC);
$count=$r['count'];
if ($count>0) {
echo t("<b>Warning! There are $count file(s) of this file type registered. Type not deleted!</b>");
}
else {
$sql="DELETE from filetypes where id=".$_GET['deltype'];
$sth=db_exec($dbh,$sql);
echo "<script>document.location='$scriptname?action={$_GET['action']}'</script>";
echo "<a href='$scriptname?action={$_GET['action']}'>Go here</a></body></html>";
}
}
//if came here from a form post, update db with new values
if (isset($_POST['typedesc'])) {
$nrows=count($_POST['id']); //number of rows
for ($rn=0;$rn<$nrows;$rn++) {
$id=$_POST['id'][$rn];
if (($id == "new") && (strlen($_POST['typedesc'][$rn])>1) ) {//new item -- insert
$sql="INSERT into filetypes ".
"(typedesc) ".
" values (".
"'".($_POST['typedesc'][$rn])."')";
}
elseif ($id!="new" && strlen($_POST['typedesc'][$rn])){ //existing item -- update
$sql="UPDATE filetypes set ".
" typedesc='".($_POST['typedesc'][$rn])."' ".
" WHERE id=$id";
}
else {continue;}
db_exec($dbh,$sql);
}//for
} //if
//if (!isset ($_GET['itemid']) || !strlen($_GET['itemid'])) {echo "$scriptname: wrong arguments";exit;}
$sql="SELECT * from filetypes order by id";
/// make db query
$sth=db_execute($dbh,$sql);
?>
<form method=post name='actionaddfrm'>
<h1><?php te("Edit File Types");?></h1>
<table class=brdr>
<tr><th> </th><th><?php te("Description");?></th></tr>
<?php
$i=0;
while ($r=$sth->fetch(PDO::FETCH_ASSOC)) {
$i++;
$dbid=$r['id'];
$dbtypedesc=$r['typedesc'];
if ($dbid>$internaltypes)
echo "\n<tr><td title='Delete [ID: ".$dbid."]'><a href='javascript:delconfirm(\"[ID: {$dbid}] $dbtypedesc\",\"$scriptname?action=$action&deltype=$dbid\");'>".
"<img src='images/delete.png' border=0></a></td>";
else
echo "\n\n<tr><td title='internal type ($dbid), cannot be deleted or changed.'></td>";
echo "<td nowrap><input type=hidden name='id[]' value='".$r['id']."' readonly size=3>\n";
if ($dbid<=$internaltypes) echo "<input size=15 maxlen=20 type=text name='typedesc[]' readonly value=\"".$r['typedesc']."\"></td>\n";
if ($dbid>$internaltypes) echo "<input size=15 maxlen=20 type=text name='typedesc[]' value=\"".$r['typedesc']."\"></td>\n";
echo "</tr>\n\n";
}
//empty line to add new items at bottom
echo "<tr><td><input type=hidden name='id[]' value='new' readonly size=3>New:</td>\n";
echo "<td><input size=15 maxlen=20 type=text name='typedesc[]' ></td>\n";
?>
<tr><td colspan=2><button type="submit"><img src="images/save.png" alt="Save" > <?php te("Save");?></button></td></tr>
</table>
</form>
</body>
</html>