SHARE
TWEET

Untitled

joshtrier Jun 4th, 2013 139 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * PHP Grid Component
  4.  *
  5.  * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  6.  * @version 1.4.6
  7.  * @license: see license.txt included in package
  8.  */
  9.  
  10. // set up DB
  11.  
  12. //DENY REQUESTS IF IPTABLES IS DOWN
  13. include('security.php');
  14.  
  15.  
  16. $conn = mysql_connect("localhost", "xxxxxx", "xxxxxxx");
  17. mysql_select_db("inv");
  18.  
  19. // set your db encoding -- for ascent chars (if required)
  20. mysql_query("SET NAMES 'utf8'");
  21.  
  22. function get_switches() {
  23.  $res = mysql_query("select distinct name as v , id as k from switches");
  24.  $data = "";
  25.  while ($row = mysql_fetch_array($res, MYSQL_NUM)) {
  26.   $data .= "$row[1]:$row[0];";
  27.  }
  28.  return array("value" => substr($data,0,-1));
  29. }
  30. // include and create object
  31. include("inc/jqgrid_dist.php");
  32. $g = new jqgrid();
  33.  
  34. // set few params
  35. $grid["caption"] = "xxxxxxxxxxxxx.com Inventory";
  36. $grid["multiselect"] = true;
  37. $grid["autofilter"] = false;
  38. $grid["height"] = "70%"; // defaults to 900
  39. $grid["autowidth"] = true;
  40. $grid["altRows"] = true;
  41. $grid["cellEdit"] = false;
  42. $grid["rowNum"] = 30;
  43. $grid["sortname"] = 'id';
  44. $grid["sortorder"] = "asc";
  45. $grid["add_options"]["afterShowForm"] = 'function(formid) { jQuery("#Slot").focus(); }';
  46. $grid["cellEdit"] = false;
  47. $g->set_options($grid);
  48.  
  49. // set database table for CRUD operations
  50. $g->table = "servers";
  51. // subqueries are also supported now (v1.2)
  52. $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";
  53.  
  54. $g->set_actions(array( 
  55. "add"=>false, // allow/disallow add
  56. "edit"=>true, // allow/disallow edit
  57. "delete"=>true, // allow/disallow delete
  58. "rowactions"=>false, // show/hide row wise edit/del/save option
  59. "export"=>true, // show/hide export to excel option
  60. "autofilter" => true, // show/hide autofilter for search
  61. "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  62. )
  63. );
  64.  
  65. $col = array();
  66. $col["title"] = "id";
  67. $col["name"] = "id";
  68. $col["dbname"] = "servers.id";
  69. $col["search"] = false;
  70. $col["align"] = "center";
  71. $col["hidden"] = true;
  72. $cols[] = $col;
  73. $col = array();
  74. $col["title"] = "Rack";
  75. $col["name"] = "rack";
  76. $col["dbname"] = "servers.rack";
  77. $col["align"] = "center";
  78. $col["width"] = 15;
  79. $col["editable"] = true;
  80. $cols[] = $col;
  81. $col = array();
  82. $col["title"] = "Slot";
  83. $col["name"] = "slot";
  84. $col["dbname"] = "servers.slot";
  85. $col["align"] = "center";
  86. $col["width"] = 15;
  87. $col["editable"] = true;
  88. $col["edittype"] = "select";
  89. $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");
  90. $cols[] = $col;
  91. $col = array();
  92. $col["title"] = "HostName";
  93. $col["name"] = "hostname";
  94. $col["dbname"] = "servers.hostname";
  95. $col["editable"] = true;
  96. $cols[] = $col;
  97. $col = array();
  98. $col["title"] = "ip";
  99. $col["hidden"] = true;
  100. $col["name"] = "ip";
  101. $col["dbname"] = "servers.ip";
  102. $col["editable"] = true;
  103. $cols[] = $col;
  104.  
  105.  
  106. $col = array();
  107. $col["title"] = "Switch Name";
  108. $col["name"] = "switch";
  109. $col["dbname"] = "switches.id";
  110. $col["width"] = 30;
  111. $col["align"] = "center";
  112. $col["editable"] = true;
  113. $col["viewable"] = true;
  114. $col["autofilter"] = true;
  115.  
  116. $col["edittype"] = "select";
  117. $col["editoptions"] = get_switches();
  118.  
  119. $cols[] = $col;
  120.  
  121.  
  122. $col = array();
  123. $col["title"] = "Switch Port";
  124. $col["name"] = "switch_port";
  125. $col["width"] = 25;
  126. $col["align"] = "center";
  127. $col["editable"] = true;
  128. $col["viewable"] = true;
  129. $col["edittype"] = "select";
  130. $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");
  131. $cols[] = $col;
  132.  
  133.  
  134. $g->set_columns($cols);
  135. // render grid
  136. $out = $g->render("list2");
  137. ?>
  138. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  139. <html>
  140. <head>
  141.         <link rel="stylesheet" type="text/css" media="screen" href="js/themes/redmond/jquery-ui.custom.css"></link>    
  142.         <link rel="stylesheet" type="text/css" media="screen" href="js/jqgrid/css/ui.jqgrid.css"></link>       
  143.         <link href="css/humanity/jquery-ui-1.10.3.custom.css" rel="stylesheet">
  144.        
  145.         <script src="js/jquery.min.js" type="text/javascript"></script>
  146.         <script src="js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  147.         <script src="js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>       
  148.         <script src="js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  149. </head>
  150. <body bgcolor="#F2F2F2">
  151. <script>
  152. var opts = {
  153.     'ondblClickRow': function (id) {
  154.         var rowid = jQuery(this).jqGrid('getGridParam','selrow'); // returns null if no row is selected  (single row)
  155.         jQuery(this).jqGrid('editGridRow', rowid);
  156.     }
  157. };
  158. </script>
  159.         <div style="margin:10px">
  160.         <?php echo $out?>
  161.         </div>
  162. </body>
  163. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top