Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.10 KB | None | 0 0
  1. <?php
  2. /**
  3. * PHP Grid Component
  4. *
  5. * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  6. * @version 1.5.2
  7. * @license: see license.txt included in package
  8. */
  9.  
  10. // include db config
  11. include_once("../../config.php");
  12.  
  13. // set up DB
  14. mysql_connect(PHPGRID_DBHOST, PHPGRID_DBUSER, PHPGRID_DBPASS);
  15. mysql_select_db(PHPGRID_DBNAME);
  16.  
  17. // include and create object
  18. include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
  19.  
  20. // you can customize your own columns ...
  21.  
  22. $col = array();
  23. $col["title"] = "Id"; // caption of column
  24. $col["name"] = "id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  25. $col["width"] = "10";
  26. # $col["hidden"] = true; // hide column by default
  27. $cols[] = $col;
  28.  
  29. $col = array();
  30. $col["title"] = "Client";
  31. $col["name"] = "name";
  32. $col["width"] = "100";
  33. $col["editable"] = true; // this column is not editable
  34. $col["align"] = "center"; // this column is not editable
  35. $col["search"] = false; // this column is not searchable
  36. $cols[] = $col;
  37.  
  38. $col = array();
  39. $col["title"] = "Client_id";
  40. $col["name"] = "client_id";
  41. $col["width"] = "100";
  42. $col["editable"] = true; // this column is not editable
  43. $col["hidden"] = true; // this column is not editable
  44. $cols[] = $col;
  45.  
  46. $col = array();
  47. $col["title"] = "Gender";
  48. $col["name"] = "gender";
  49. $col["width"] = "100";
  50. $col["editable"] = true; // this column is not editable
  51. $col["align"] = "center"; // this column is not editable
  52. $col["search"] = false; // this column is not searchable
  53. $cols[] = $col;
  54.  
  55. $col = array();
  56. $col["title"] = "Company";
  57. $col["name"] = "company";
  58. $col["width"] = "100";
  59. $col["editable"] = true; // this column is not editable
  60. $col["align"] = "center"; // this column is not editable
  61. $col["search"] = false; // this column is not searchable
  62. $cols[] = $col;
  63.  
  64.  
  65. $col = array();
  66. $col["title"] = "Note";
  67. $col["name"] = "note";
  68. # $col["width"] = "300"; // not specifying width will expand to fill space
  69. $col["sortable"] = false; // this column is not sortable
  70. $col["search"] = false; // this column is not searchable
  71. $col["editable"] = true;
  72. $col["edittype"] = "textarea"; // render as textarea on edit
  73. $col["editoptions"] = array("rows"=>2, "cols"=>20); // with these attributes
  74. $col["editrules"] = array("edithidden"=>true);
  75. $cols[] = $col;
  76.  
  77. $col = array();
  78. $col["title"] = "Date";
  79. $col["name"] = "invdate";
  80. $col["width"] = "50";
  81. $col["editable"] = true; // this column is editable
  82. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  83. $col["editrules"] = array("required"=>true); // required:true(false), number:true(false), minValue:val, maxValue:val
  84. $col["formatter"] = "datetime"; // format as date
  85. $cols[] = $col;
  86.  
  87.  
  88. $col = array();
  89. $col["title"] = "Total";
  90. $col["name"] = "total";
  91. $col["width"] = "50";
  92. $col["editable"] = true;
  93. // default render is textbox
  94. $col["editoptions"] = array("value"=>'10');
  95.  
  96. $cols[] = $col;
  97.  
  98. $col = array();
  99. $col["title"] = "Closed";
  100. $col["name"] = "closed";
  101. $col["width"] = "50";
  102. $col["editable"] = true;
  103. $col["edittype"] = "checkbox"; // render as checkbox
  104. $col["editoptions"] = array("value"=>"Yes:No"); // with these values "checked_value:unchecked_value"
  105. $cols[] = $col;
  106.  
  107.  
  108. $g = new jqgrid();
  109.  
  110. // $grid["url"] = ""; // your paramterized URL -- defaults to REQUEST_URI
  111. $grid["rowNum"] = 10; // by default 20
  112. $grid["sortname"] = 'id'; // by default sort grid by this field
  113. $grid["sortorder"] = "desc"; // ASC or DESC
  114. $grid["caption"] = "Invoice Data"; // caption of grid
  115. $grid["autowidth"] = true; // expand grid to screen width
  116. $grid["multiselect"] = true; // allow you to multi-select through checkboxes
  117. $grid["scroll"] = true; // allow you to multi-select through checkboxes
  118. $g->set_options($grid);
  119.  
  120. $g->set_actions(array(
  121. "add"=>true, // allow/disallow add
  122. "edit"=>true, // allow/disallow edit
  123. "delete"=>true, // allow/disallow delete
  124. "rowactions"=>true, // show/hide row wise edit/del/save option
  125. "export"=>true, // show/hide export to excel option
  126. "autofilter" => true, // show/hide autofilter for search
  127. "search" => "simple", // show single/multi field search condition (e.g. simple or advance)
  128. "showhidecolumns" => false // show single/multi field search condition (e.g. simple or advance)
  129. )
  130. );
  131.  
  132. // you can provide custom SQL query to display data
  133. $g->select_command = "Select
  134. i.id,
  135. i.invdate,
  136. c.name,
  137. c.client_id,
  138. c.gender,
  139. i.note,
  140. i.total,
  141. i.closed,
  142. c.company
  143. From
  144. invheader i Inner Join
  145. clients c On c.client_id = i.client_id";
  146.  
  147. // this db table will be used for add,edit,delete
  148. $g->table = "invheader";
  149.  
  150. // pass the cooked columns to grid
  151. $g->set_columns($cols);
  152.  
  153.  
  154. $e["on_insert"] = array("add_client", null, false);
  155. $e["on_update"] = array("update_client", null, false);
  156. $g->set_events($e);
  157.  
  158. function add_client($data)
  159. {
  160. // first insert in clients table
  161. mysql_query("insert into clients (name, gender,company)
  162. values ('{$data[params][name]}',
  163. '{$data[params][gender]}',
  164. '{$data[params][company]}')");
  165.  
  166. // get insert id
  167. $client_id = mysql_insert_id();
  168.  
  169. // insert in invheader table
  170. mysql_query("insert into invheader (client_id, note, invdate, total, closed)
  171. values ($client_id,
  172. '{$data[params][note]}',
  173. '{$data[params][invdate]}',
  174. '{$data[params][total]}',
  175. '{$data[params][closed]}')");
  176.  
  177. // all done
  178. die;
  179. }
  180.  
  181. function update_client($data)
  182. {
  183. // first insert in clients table
  184.  
  185. mysql_query("update clients set `name` = '{$data[params][name]}',
  186. gender = '{$data[params][gender]}',
  187. company = '{$data[params][company]}' WHERE client_id = '{$data[params][client_id]}'");
  188.  
  189. // insert in invheader table
  190. mysql_query("update invheader
  191. set client_id='{$data[params][client_id]}',
  192. note = '{$data[params][note]}',
  193. invdate = '{$data[params][invdate]}',
  194. total = '{$data[params][total]}',
  195. closed = '{$data[params][closed]}' WHERE id = '{$data[id]}'");
  196.  
  197. // all done
  198. die;
  199. }
  200.  
  201.  
  202. // generate grid output, with unique grid name as 'list1'
  203. $out = $g->render("list1");
  204. ?>
  205. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  206. <html>
  207. <head>
  208. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  209. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  210.  
  211. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  212. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  213. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  214. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  215. </head>
  216. <body>
  217. <div style="margin:10px">
  218. <?php echo $out?>
  219. </div>
  220. </body>
  221. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement