-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud_irp_devices.php
106 lines (97 loc) · 4.16 KB
/
crud_irp_devices.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
<?php
/*
crud_irp_devices - This file is part of remoteDBdiscovery.
remoteDBdiscovery is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
remoteDBdiscovery is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--------
Copyright (c) 2017 Marco Sillano. All right reserved.
*/
$r=dirname(dirname(__FILE__));
include("$r/remoteDBdiscovery/libs/crudClass.php");
require_once ("$r/remoteDB/irp_commonSQL.php");
if (isset($_GET['iddevice'])){
$_POST = $_GET;
}
echo "<html><head>";
echo StyleSheet();
echo "</head><body>";
echo "<h1> Table <b>irp_devices</b>: <i>add/edit/delete records</i></h1>";
//--------------------------------------------------
// callback for input fields (new)
function crud_get_input($field){
$code = NULL;
// custom special cases
if ($field == 'brand')
$code = "[<a href='crud_irp_brands.php'>add new</a>] ".crudClass::make_select($field, "SELECT brand, brand FROM irp_brands");
if ($field == 'status')
$code = crudClass::make_radio($field, "visible,hidden",'visible') ;
if ($field == 'kind')
$code = "[<a href='crud_irp_devtypes.php'>add new</a>] ".crudClass::make_select($field, "SELECT kind, kind FROM irp_devtypes");
if ($field == 'group')
$code = "[<a href='crud_irp_mygroups.php'>add new</a>] ".crudClass::make_select($field, "SELECT `group`, `group` FROM irp_mygroups"); // group is reserved in mySQL. requires (`)
return $code;
}
//callback for update fields (edit)
function crud_get_edit($field, $value) {
$code = NULL;
if ($field == 'kind')
$code = crudClass::make_select($field, "SELECT kind, kind FROM irp_devtypes",$value);
if ($field == 'group')
$code = crudClass::make_select($field, "SELECT `group`, `group` FROM irp_mygroups",$value);
if ($field == 'status')
$code = crudClass::make_radio($field, "visible,hidden", $value);
return $code;
}
//callback for show fields (view)
function crud_get_show($field, $value) {
$code = NULL;
// special cases
if ($field == 'dev_url'){
$url = str_replace ('./doc', './../remoteDB/doc', $value); // relative url correction
$code = "<A href='$url' target='_blank' >$value</A>";
}
if ($field == 'photo')
$code = "<A href='./../remoteDB/photo/$value' target='_blank' >$value</A>";
if ($field == 'dicon')
$code = "<A href='./../remoteDB/icons/$value' target='_blank' >$value</A>";
return $code;
}
// --------------------------------------------------
$crud = new crudClass('irp_devices','brand,dev_model,kind,dev_url,group,status,photo,dicon,description','iddevice' );// Initiate the class with table information
if (isset($_POST['submit'])){
$create_sql = $crud->create();//Fetch INSERT query
sql($create_sql);
}
if (isset($_POST['update'])){
$update_sql = $crud->update();//Fetch UPDATE query
sql($update_sql);
}
if (isset($_POST['delete'])){
$delete_sql = $crud->delete();//Fetch DELETE query
sql($delete_sql);
}
if (isset($_POST['edit'])){
// edit
echo "<div class='note' align='right'>";
echo $crud->renderEditor();//Prepare data edit form
echo '</div>' ;
} else {
// or insert
echo "<div class='note' align='right'>";
echo $crud->create_form();//Prepare data entry form
echo '</div>';
}
// table
echo $crud->renderVertically();// SHOW data table
echo '<hr><center> <a href="javascript:history.go(-1)"><<< back </a> | <a href="discovery.html">discovery</a> </center><br>';
echo "</body></html>";
?>