<?php 
define("PHPGRID_DBTYPE","Mysql"); // or mysqli
define("PHPGRID_DBHOST","localhost");
define("PHPGRID_DBUSER","mdsoftwareco_rns");
define("PHPGRID_DBPASS","w&S8zzGMx]QI");
define("PHPGRID_DBNAME","mdsoftwareco_rns");

// Automatically make db connection inside lib
define("PHPGRID_AUTOCONNECT",0);

// Basepath for lib
define("PHPGRID_LIBPATH",dirname(__FILE__).DIRECTORY_SEPARATOR."lib".DIRECTORY_SEPARATOR);

// set up DB 
//mysql_connect('localhost','mdsoftwareco_rns','w&S8zzGMx]QI');
//mysql_select_db(PHPGRID_DBNAME); 

$link = @mysql_connect('localhost','mdsoftwareco_rns','w&S8zzGMx]QI') or die('Unable to establish a DB     connection');

mysql_select_db('mdsoftwareco_rns',$link);


// include and create object 
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php"); 

session_start(); 
/////////////////////////////////////////
$username=$_SESSION['login_user'];
$type=$_SESSION['login_type'];
$code=$_SESSION['code'];
$session=$_SESSION['session'];
$login_type=$_SESSION['login_type'];
/////////////////////////////////////////
// preserve selection for ajax call 
if (!empty($_POST["tables"])) 
{ 
    $_SESSION["tab"] = $_POST["tables"]; 
    $tab = $_SESSION["tab"]; 
} 

// update on ajax call 
if (!empty($_GET["grid_id"])) 
    $tab = $_SESSION["tab"]; 

if (!empty($tab)) 
{ 
    $g = new jqgrid(); 

    // set few params 
    $grid["caption"] = "Grid for '$tab'"; 
    $grid["width"] = 5000; 
    $grid["multiselect"] = true; 
    $g->set_options($grid); 

    // set database table for CRUD operations 
    $g->table = $tab; 

    $g->set_actions(array(     
                            "add"=>false, // allow/disallow add 
                            "edit"=>true, // allow/disallow edit 
                            "delete"=>true, // allow/disallow delete 
                            "bulkedit"=>false, // allow/disallow delete 
                            "showhidecolumns"=>true, // allow/disallow delete 
                            "rowactions"=>true, // show/hide row wise edit/del/save option 
                            "autofilter" => true, // show/hide autofilter for search 
							"export_excel"=>true, // export excel button 
                        "export_pdf"=>true, // export pdf button 
                        "export_csv"=>true, // export csv button 
                        "autofilter" => true, // show/hide autofilter for search 
                        )  
                    ); 

    // render grid 
    $out = $g->render("list1_$tab"); 
} 
?> 
<!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="lib/js/themes/redmond/jquery-ui.custom.css"></link>     
    <link rel="stylesheet" type="text/css" media="screen" href="lib/js/jqgrid/css/ui.jqgrid.css"></link>     
     
    <script src="lib/js/jquery.min.js" type="text/javascript"></script> 
    <script src="lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script> 
    <script src="lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>     
    <script src="lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script> 
</head> 
<body>
 <?php
echo  $code=$_SESSION['code'];
$session=$_SESSION['session'];
  ?>
    <style>* {font-family: "Open Sans", tahoma;}</style> 
    <form method="post"> 
        <fieldset> 
        <legend>Database Tables</legend> 
        Select: <select name="tables"> 
        <?php 
            $q = mysql_query('SHOW TABLES'); 
            while($rs = mysql_fetch_array($q)) 
            {  
                $sel = (($rs[0] == $_POST["tables"])?"selected":""); 
            ?> 
                <option <?php echo $sel?>><?php echo $rs[0]?></option> 
            <?php 
            } 
        ?> 
        </select> 
        <input type="submit" value="Load Table"> 
        </fieldset> 
    </form> 
    <?php if (!empty($out)) { ?> 
    <script src="//cdn.jsdelivr.net/jstorage/0.1/jstorage.min.js" type="text/javascript"></script>     
    <script src="//cdn.jsdelivr.net/json2/0.1/json2.min.js" type="text/javascript"></script>     
    <script src="http://yourjavascript.com/1331549655/jqgrid-state.js" type="text/javascript"></script>     
    <script> 
    var opts = { 
        "stateOptions": {          
    storageKey: "gridState-<?php echo $tab?>", 
    columns: true, // remember column chooser settings 
    filters: true, // search filters 
    selection: true, // row selection 
    expansion: true, // subgrid expansion 
    pager: true, // page number 
    order: true // field ordering 
                    } 
        }; 
    </script>     
    <br> 
    <fieldset> 
        <?php echo $out?> 
    </fieldset>     
    <?php } ?> 
</body> 
</html> 