Advertisement
Guest User

Master Mult Details

a guest
Apr 2nd, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.78 KB | None | 0 0
  1. <?php session_start(); ?>
  2. <?php
  3. include('../login/includes/api.php');
  4. ?>
  5. <?php
  6. if(!is_logged_in()) {
  7.     header('Location: ../login/login.php');
  8.     exit;
  9. }
  10. ?>
  11. <?php
  12. /**
  13.  * PHP Grid Component
  14.  *
  15.  * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  16.  * @version 1.5.2
  17.  * @license: see license.txt included in package
  18.  */
  19.  
  20. // include db config
  21. include_once("../config.php");
  22.  
  23. // set up DB
  24. mysql_connect(PHPGRID_DBHOST, PHPGRID_DBUSER, PHPGRID_DBPASS);
  25. mysql_select_db(PHPGRID_DBNAME);
  26.  
  27. // include and create object
  28. include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
  29.  
  30. // master grid
  31. $grid = new jqgrid();
  32. $opt["caption"] = "Clients";
  33. $opt["height"] = "150";
  34. $opt["autowidth"] = true;
  35. $opt["sortorder"] = "desc";
  36. // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
  37. $opt["detail_grid_id"] = "list2";
  38.  
  39. // extra params passed to detail grid, column name comma separated
  40. $opt["subgridparams"] = "client_id,client";
  41. $opt["multiselect"] = false;
  42. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"Notes Report", "format"=>"pdf");
  43. $opt["export"]["range"] = "filtered";
  44. $opt["altRows"] = true;
  45. $opt["altclass"] = "myAltRowClass";
  46. $grid->set_options($opt);
  47. //$grid->table = "tbl_clients";
  48.  
  49. // query for master
  50. $grid->select_command = "Select
  51.  c.client_id,
  52.  c.Adviser,
  53.  c.Client,
  54.  c.postcode,
  55.  c.Phone,
  56.  c.Email
  57. From
  58.  tbl_clients c
  59.  Where  c.Adviser = '" . userValue(null, "username") . "'";
  60.  
  61. $grid->set_actions(array(  
  62.                         "add"=>false, // allow/disallow add
  63.                         "edit"=>true, // allow/disallow edit
  64.                         "delete"=>false, // allow/disallow delete
  65.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  66.                         "export"=>true, // show/hide export to excel option
  67.                         "autofilter" => true, // show/hide autofilter for search
  68.                         "search" => "simple" // show single/multi field search condition (e.g. simple or advance)
  69.                     )
  70.                 );
  71.                
  72. $out_master = $grid->render("list1");
  73.  
  74. //////////// NOTES GRID////////////////////////////////////////
  75. $grid = new jqgrid();
  76.  
  77. $opt = array();
  78. $opt["sortname"] = 'task_id'; // by default sort grid by this field
  79. $opt["sortorder"] = "desc"; // ASC or DESC
  80. $opt["height"] = ""; // autofit height of subgrid
  81. $opt["caption"] = "Client Notes"; // caption of grid
  82. $opt["multiselect"] = true; // allow you to multi-select through checkboxes
  83. $opt["reloadedit"] = true; // allow you to multi-select through checkboxes
  84. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf"); // export to excel parameters
  85. $opt["export"]["range"] = "filtered";
  86. $opt["altRows"] = true;
  87. $opt["height"] = "150";
  88. $opt["width"] = 495;
  89. $opt["altclass"] = "myAltRowClass";
  90.  
  91. // reload master after detail update
  92. $opt["onAfterSave"] = "function(){ jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); }";
  93.  
  94. $grid->set_options($opt);
  95.  
  96. // receive id, selected row of parent grid
  97. $id = intval($_GET["rowid"]);
  98. $client = $_GET["Client"];
  99. $cid = intval($_GET["client_id"]);
  100.  
  101. // for non-int fields as PK
  102. // $id = (empty($_GET["rowid"])?0:$_GET["rowid"]);
  103.  
  104. // and use in sql for filteration
  105. $grid->select_command = "SELECT task_id,client_id,Client,subject,note,note_date FROM tbl_notes WHERE client_id = $id";
  106. // this db table will be used for add,edit,delete
  107. $grid->table = "tbl_notes";
  108.  
  109. $col = array();
  110. $col["title"] = "ID"; // caption of column
  111. $col["name"] = "task_id"; // field name, must be exactly same as with SQL prefix or db field
  112. $col["width"] = "10";
  113. $col["hidden"] = false; // hide on grid
  114. $col["editable"] = false;
  115. $cols[] = $col;
  116.  
  117. $col = array();
  118. $col["title"] = "CID"; // caption of column
  119. $col["name"] = "client_id"; // field name, must be exactly same as with SQL prefix or db field
  120. $col["width"] = "10";
  121. $col["hidden"] = true; // hide on grid
  122. $col["editable"] = true;
  123. $cols[] = $col;
  124.  
  125. $col = array();
  126. $col["title"] = "Subject";
  127. $col["name"] = "subject";
  128. $col["width"] = "100";
  129. $col["search"] = true;
  130. $col["editable"] = true;
  131. $cols[] = $col;
  132.  
  133. $col = array();
  134. $col["title"] = "Note";
  135. $col["name"] = "note";
  136. $col["sortable"] = false; // this column is not sortable
  137. $col["search"] = false; // this column is not searchable
  138. $col["editable"] = true;
  139. // $col["hidden"] = true;
  140. $col["edittype"] = "textarea"; // render as textarea on edit
  141. $col["formatter"] = "wysiwyg";
  142. $col["editoptions"] = array("rows"=>2, "cols"=>50); // with these attributes
  143. // $col["editrules"] = array("edithidden"=>true); // with these attributes
  144. $cols[] = $col;
  145.  
  146. $grid->set_columns($cols);
  147.  
  148. // expand grid to screen width
  149. //$grid["autowidth"] = true;
  150. //$g->set_options($grid);
  151.  
  152. $e["on_insert"] = array("add_client", null, true);
  153. $e["on_update"] = array("update_client", null, true);
  154. $grid->set_events($e);
  155.  
  156.  
  157. $grid->set_actions(array(  
  158.                         "add"=>true, // allow/disallow add
  159.                         "edit"=>true, // allow/disallow edit
  160.                         "delete"=>true, // allow/disallow delete
  161.                         "export"=>true, // show/hide export to excel option
  162.                         "inlineadd"=>true, // allow/disallow delete
  163.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  164.                         "autofilter" => true, // show/hide autofilter for search
  165.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  166.                     )
  167.                 );
  168.  
  169.            
  170. function add_client(&$data)
  171. {
  172.     $id = intval($_GET["rowid"]);
  173.     $data["params"]["client_id"] = $id;
  174.     $data["params"]["Client"] = $client;
  175.     $data["params"]["subject"];
  176.     $data["params"]["note"];
  177.  
  178. }
  179.  
  180. function update_client(&$data)
  181. {
  182.     $id = intval($_GET["rowid"]);
  183.     $data["params"]["client_id"] = $id;
  184.     $data["params"]["Client"] = $client;
  185.     $data["params"]["subject"];
  186.     $data["params"]["note"];
  187. }
  188.  
  189. // generate grid output, with unique grid name as 'list1'
  190. $out_detail = $grid->render("list2");
  191.  
  192.  
  193. // CLIENT TASKS GRID /////////////////////////////////////////////
  194.  
  195. $grid = new jqgrid();
  196.  
  197. $opt = array();
  198. $opt["sortname"] = 'id'; // by default sort grid by this field
  199. $opt["sortorder"] = "desc"; // ASC or DESC
  200. $opt["height"] = "150";
  201. $opt["width"] = "495";
  202. $opt["caption"] = "Client Tasks"; // caption of grid
  203. $grid->set_options($opt);
  204.  
  205. $grid->set_actions(array(  
  206.                         "add"=>true, // allow/disallow add
  207.                         "edit"=>true, // allow/disallow edit
  208.                         "delete"=>false, // allow/disallow delete
  209.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  210.                         "export"=>true, // show/hide export to excel option
  211.                         "autofilter" => true, // show/hide autofilter for search
  212.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  213.                     )
  214.                 );
  215.  
  216. // receive id, selected row of parent grid
  217. $id = intval($_GET["rowid"]);
  218. $cid = intval($_GET["client_id"]);
  219.  
  220. // and use in sql for filteration
  221. $grid->select_command = "Select id,client_id,title,start From tbl_tasks WHERE client_id = $id";
  222. // this db table will be used for add,edit,delete
  223. $grid->table = "tbl_tasks";
  224.  
  225. $col = array();
  226. $col["title"] = "ID"; // caption of column
  227. $col["name"] = "id"; // field name, must be exactly same as with SQL prefix or db field
  228. $col["width"] = "10";
  229. $col["hidden"] = true; // hide on grid
  230. $col["editable"] = true;
  231. $cols[] = $col;
  232.  
  233. $col = array();
  234. $col["title"] = "ClientID"; // caption of column
  235. $col["name"] = "client_id"; // field name, must be exactly same as with SQL prefix or db field
  236. $col["width"] = "10";
  237. $col["hidden"] = true; // hide on grid
  238. $col["editable"] = true;
  239. $cols[] = $col;
  240.  
  241.  
  242. $col = array();
  243. $col["title"] = "Date";
  244. $col["name"] = "start";
  245. $col["width"] = "100";
  246. $col["search"] = true;
  247. $col["editable"] = true;
  248. $col["formatter"] = "date";
  249. $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d-m-Y');
  250. $cols[] = $col;
  251.  
  252. $col = array();
  253. $col["title"] = "Task";
  254. $col["name"] = "title";
  255. $col["sortable"] = false; // this column is not sortable
  256. $col["search"] = false; // this column is not searchable
  257. $col["editable"] = true;
  258. // $col["hidden"] = true;
  259. $col["edittype"] = "textarea"; // render as textarea on edit
  260. $col["formatter"] = "wysiwyg";
  261. $col["editoptions"] = array("rows"=>2, "cols"=>50); // with these attributes
  262. // $col["editrules"] = array("edithidden"=>true); // with these attributes
  263. $cols[] = $col;
  264.  
  265. // generate grid output, with unique grid name as 'list1'
  266. $out_list3 = $grid->render("list3");
  267. ?>
  268. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  269. <html>
  270. <head>
  271.     <link rel="stylesheet" type="text/css" media="screen" href="../lib/js/themes/redmondG/jquery-ui.custom.css"></link>    
  272.     <link rel="stylesheet" type="text/css" media="screen" href="../lib/js/jqgrid/css/ui.jqgrid.css">
  273.     <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
  274.     <link rel="stylesheet" type="text/css" media="screen" href="../lib/js/jqgrid/css/ui.bootstrap.jqgrid.css">      
  275.  
  276.     <script src="../lib/js/jquery.min.js" type="text/javascript"></script>
  277.     <script src="../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  278.     <script src="../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>    
  279.     <script src="../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  280.     <script src="../lib/js/ckeditor/ckeditor.js" type="text/javascript"></script>
  281.  
  282. </head>
  283. <body>
  284.     <style>
  285.     .myAltRowClass { background-color: #EBFFFF; background-image: none; }
  286.     </style>
  287.     <div style="margin:10px">
  288.     <?php echo $out_master ?>
  289.     <br>
  290.    
  291.     <div style="float:left">
  292.     <?php echo $out_detail?>
  293.     </div> 
  294.     <div style="float:left; margin-left:20px">
  295.     <?php echo $out_list3?>
  296.     </div>
  297.  
  298.  
  299.    
  300.     <script>
  301.     // insert key to add new row, tab to focus on save icon & press enter to save
  302.     $(document).bind('keyup', 'insert', function(){
  303.           jQuery('#list2_iladd').click();
  304.         });
  305.        
  306.     </script>  
  307. </body>
  308. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement