Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * PHP Grid Component
- *
- * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
- * @version 1.4.6
- * @license: see license.txt included in package
- */
- // set up DB
- //DENY REQUESTS IF IPTABLES IS DOWN
- include('security.php');
- $conn = mysql_connect("localhost", "xxxxxx", "xxxxxxx");
- mysql_select_db("inv");
- // set your db encoding -- for ascent chars (if required)
- mysql_query("SET NAMES 'utf8'");
- function get_switches() {
- $res = mysql_query("select distinct name as v , id as k from switches");
- $data = "";
- while ($row = mysql_fetch_array($res, MYSQL_NUM)) {
- $data .= "$row[1]:$row[0];";
- }
- return array("value" => substr($data,0,-1));
- }
- // include and create object
- include("inc/jqgrid_dist.php");
- $g = new jqgrid();
- // set few params
- $grid["caption"] = "xxxxxxxxxxxxx.com Inventory";
- $grid["multiselect"] = true;
- $grid["autofilter"] = false;
- $grid["height"] = "70%"; // defaults to 900
- $grid["autowidth"] = true;
- $grid["altRows"] = true;
- $grid["cellEdit"] = false;
- $grid["rowNum"] = 30;
- $grid["sortname"] = 'id';
- $grid["sortorder"] = "asc";
- $grid["add_options"]["afterShowForm"] = 'function(formid) { jQuery("#Slot").focus(); }';
- $grid["cellEdit"] = false;
- $g->set_options($grid);
- // set database table for CRUD operations
- $g->table = "servers";
- // subqueries are also supported now (v1.2)
- $g->select_command = "select servers.id,servers.rack,slot,hostname,ip,switches.name as switch,switch_port from servers inner join switches on servers.switch=switches.id";
- $g->set_actions(array(
- "add"=>false, // allow/disallow add
- "edit"=>true, // allow/disallow edit
- "delete"=>true, // allow/disallow delete
- "rowactions"=>false, // show/hide row wise edit/del/save option
- "export"=>true, // show/hide export to excel option
- "autofilter" => true, // show/hide autofilter for search
- "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
- )
- );
- $col = array();
- $col["title"] = "id";
- $col["name"] = "id";
- $col["dbname"] = "servers.id";
- $col["search"] = false;
- $col["align"] = "center";
- $col["hidden"] = true;
- $cols[] = $col;
- $col = array();
- $col["title"] = "Rack";
- $col["name"] = "rack";
- $col["dbname"] = "servers.rack";
- $col["align"] = "center";
- $col["width"] = 15;
- $col["editable"] = true;
- $cols[] = $col;
- $col = array();
- $col["title"] = "Slot";
- $col["name"] = "slot";
- $col["dbname"] = "servers.slot";
- $col["align"] = "center";
- $col["width"] = 15;
- $col["editable"] = true;
- $col["edittype"] = "select";
- $col["editoptions"] = array("value" => "1:Port 1;2:Port 2;3:Port 3;4:Port 4;5:Port 5;6:Port 6;7:Port 7;8:Port 8;9:Port 9;10:Port 10;11:Port 11;12:Port 12;13:Port 13;14:Port 14;15:Port 15;16:Port 16;17:Port 17;18:Port 18;19:Port 19;20:Port 20;21:Port 21;22:Port 22;23:Port 23;24:Port 24");
- $cols[] = $col;
- $col = array();
- $col["title"] = "HostName";
- $col["name"] = "hostname";
- $col["dbname"] = "servers.hostname";
- $col["editable"] = true;
- $cols[] = $col;
- $col = array();
- $col["title"] = "ip";
- $col["hidden"] = true;
- $col["name"] = "ip";
- $col["dbname"] = "servers.ip";
- $col["editable"] = true;
- $cols[] = $col;
- $col = array();
- $col["title"] = "Switch Name";
- $col["name"] = "switch";
- $col["dbname"] = "switches.id";
- $col["width"] = 30;
- $col["align"] = "center";
- $col["editable"] = true;
- $col["viewable"] = true;
- $col["autofilter"] = true;
- $col["edittype"] = "select";
- $col["editoptions"] = get_switches();
- $cols[] = $col;
- $col = array();
- $col["title"] = "Switch Port";
- $col["name"] = "switch_port";
- $col["width"] = 25;
- $col["align"] = "center";
- $col["editable"] = true;
- $col["viewable"] = true;
- $col["edittype"] = "select";
- $col["editoptions"] = array("value" => "1:Port 1;2:Port 2;3:Port 3;4:Port 4;5:Port 5;6:Port 6;7:Port 7;8:Port 8;9:Port 9;10:Port 10;11:Port 11;12:Port 12;13:Port 13;14:Port 14;15:Port 15;16:Port 16;17:Port 17;18:Port 18;19:Port 19;20:Port 20;21:Port 21;22:Port 22;23:Port 23;24:Port 24");
- $cols[] = $col;
- $g->set_columns($cols);
- // render grid
- $out = $g->render("list2");
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
- <html>
- <head>
- <link rel="stylesheet" type="text/css" media="screen" href="js/themes/redmond/jquery-ui.custom.css"></link>
- <link rel="stylesheet" type="text/css" media="screen" href="js/jqgrid/css/ui.jqgrid.css"></link>
- <link href="css/humanity/jquery-ui-1.10.3.custom.css" rel="stylesheet">
- <script src="js/jquery.min.js" type="text/javascript"></script>
- <script src="js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
- <script src="js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
- <script src="js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
- </head>
- <body bgcolor="#F2F2F2">
- <script>
- var opts = {
- 'ondblClickRow': function (id) {
- var rowid = jQuery(this).jqGrid('getGridParam','selrow'); // returns null if no row is selected (single row)
- jQuery(this).jqGrid('editGridRow', rowid);
- }
- };
- </script>
- <div style="margin:10px">
- <?php echo $out?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement