Advertisement
GL29

PhpGrid.org

May 8th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.79 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 2.0.0
  7. * @license: see license.txt included in package
  8. */
  9.  
  10. include_once("config.php");
  11.  
  12. include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
  13.  
  14. // Database config file to be passed in phpgrid constructor
  15. $db_conf = array(
  16. "type" => PHPGRID_DBTYPE,
  17. "server" => PHPGRID_DBHOST,
  18. "user" => PHPGRID_DBUSER,
  19. "password" => PHPGRID_DBPASS,
  20. "database" => PHPGRID_DBNAME
  21. );
  22.  
  23.  
  24. // master Grid 01
  25. $g = new jqgrid($db_conf);
  26.  
  27. // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
  28. $opt["detail_grid_id"] = "list2,list3";
  29. $opt["height"] = "200";
  30. $opt["width"] = "1020";
  31.  
  32. $g->set_options($opt);
  33.  
  34. // you can provide custom SQL query to display data
  35.  
  36. $g->select_command = " SELECT m.cie_id, m.cie_name, m.phone, m.town, m.postcode,
  37. s.status_name as status_id, m.address, c.local_name as country_id, m.contact_name, m.email, m.website, m.source, m.frtmap_code, op.operator_name, g.group_name as group_id
  38. FROM crm_main m INNER JOIN crm_country c ON c.country_id = m.country_id INNER JOIN crm_operators op ON op.computer_name = m.created_by
  39. INNER JOIN crm_group g ON g.group_id = m.group_id
  40. INNER JOIN crm_status s ON s.status_id = m.status_id
  41. ";
  42.  
  43.  
  44.  
  45. $grid["caption"] = "BRINOR CUSTOMER PROSPECT RELATION MANAGEMENT SYSTEM";
  46. $grid["rownumbers"] = true;
  47. $grid["rownumWidth"] = 16;
  48. $grid["resizable"] = false; // defaults to false
  49. $grid["autoresize"] = false; // defaults to false
  50.  
  51. $grid["loadtext"] = "Loading your customer list ;-)";
  52.  
  53. $grid["toolbar"] = "both";
  54. $grid["multiselect"] = false;
  55. $grid["altRows"] = true;
  56.  
  57. // Date will be sorted desc, and ID asc.
  58. $grid["sortname"] = "cie_name ASC,cie_id";
  59. $grid["sortorder"] = "ASC";
  60.  
  61. $grid["scroll"] = true; ///// SCROLL INSTEAD OF PAGE SELECTION
  62. $grid["cellEdit"] = false; /// Editing like Excel
  63. $grid["toppager"] = true;
  64.  
  65. // export XLS file
  66. // export to excel parameters
  67. $grid["export"] = array("format"=>"pdf", "filename"=>"my-file", "sheetname"=>"test");
  68.  
  69. $grid["add_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'400', 'top'=>'200', 'left'=>'400');
  70. $grid["edit_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'400', 'top'=>'200', 'left'=>'400');
  71. $grid["view_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'400', 'top'=>'200', 'left'=>'400');
  72.  
  73.  
  74.  
  75.  
  76. $g->set_options($grid);
  77. //
  78. $eg1["js_on_load_complete"] = "grid_onload";
  79. $eg1["on_after_insert"] = array("after_insert_client", null, true);
  80. $eg1["on_update"] = array("update_client", null, true);
  81.  
  82. $g->set_events($eg1);
  83.  
  84.  
  85. function after_insert_client($data)
  86. {
  87. // these lines will push data array in error box to debug
  88. //ob_start();
  89. //print_r($data);
  90. //phpgrid_error(ob_get_clean());
  91.  
  92. $computer = gethostname();
  93. $date = date("Y-m-d");
  94. $str="UPDATE crm_main SET created_by='$computer', created_date='$date' WHERE cie_id ={$data["cie_id"]}";
  95. mysql_query($str);
  96. }
  97.  
  98. function update_client($data)
  99. {
  100. // these lines will push data array in error box to debug
  101. //ob_start();
  102. //print_r($data);
  103. //phpgrid_error(ob_get_clean());
  104.  
  105. $computer = gethostname();
  106. $date = date("Y-m-d");
  107. $str="UPDATE crm_main SET updated_by='$computer', updated_date='$date' WHERE cie_id ={$data["cie_id"]}";
  108. mysql_query($str);
  109. }
  110.  
  111.  
  112.  
  113. /////////////////////////////////
  114. ////////////////////////////////
  115.  
  116. $g->set_actions(array(
  117. "add"=>true, // allow/disallow add
  118. "edit"=>true, // allow/disallow edit
  119. "delete"=>true, // allow/disallow delete
  120. "rowactions"=>false, // show/hide row wise edit/del/save option
  121. "export"=>true, // show/hide export to excel option
  122. "autofilter" => true, // show/hide autofilter for search
  123. "search" => "advance", // show single/multi field search condition (e.g. simple or advance)
  124. "showhidecolumns" => true
  125. )
  126. );
  127.  
  128. /////////////////////////////////
  129. /////////////////////////////////
  130.  
  131. $col = array();
  132. $col["title"] = "ID"; // caption of column
  133. $col["name"] = "cie_id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  134. $col["width"] = "10";
  135. $col["hidden"] = true; // HIDE this column
  136. //$col["editrules"] = array("edithidden"=>true);
  137. $col["align"] = "center"; // this column is not editable
  138. $col["editable"] = false; // this column is not editable
  139. $col["search"] = false; // this column is not searchable
  140. $cols[] = $col;
  141.  
  142.  
  143. ////////////////
  144. ////////////////
  145.  
  146. # Custom made column to show link, must have default value as it's not db driven
  147. $col = array();
  148. $col["title"] = "Details";
  149. $col["name"] = "more_options";
  150. $col["width"] = "30";
  151. $col["align"] = "center";
  152. $col["search"] = false;
  153. $col["sortable"] = false;
  154. # no new line in this html, only space. otherwise it may break ui of grid
  155. $buttons_html = "<input type='button' value='Edit' onclick='open_edit(this)'>";
  156. $col["default"] = $buttons_html;
  157. $cols[] = $col;
  158.  
  159.  
  160. ///////////////////////
  161. ///////////////////////
  162.  
  163. $col = array();
  164. $col["title"] = "Customer";
  165. $col["name"] = "cie_name";
  166. $col["width"] = "30";
  167. $col["editable"] = true; // this column is not editable
  168. $col["align"] = "center"; // this column is not editable
  169. $col["search"] = true; // this column is not searchable
  170. $col["editoptions"] = array("size"=>50);
  171. $col["editrules"] = array("required"=>true); // and is required
  172. $cols[] = $col;
  173.  
  174. //////////
  175. /////////
  176.  
  177. $col = array();
  178. $col["title"] = "Town";
  179. $col["name"] = "town";
  180. $col["width"] = "30";
  181. $col["sortable"] = true; // this column is not sortable
  182. $col["search"] = true; // this column is not searchable
  183. $col["editable"] = true;
  184. $col["editoptions"] = array("size"=>50);
  185. $cols[] = $col;
  186.  
  187. //////////
  188. /////////
  189.  
  190. $col = array();
  191. $col["title"] = "Postcode";
  192. $col["name"] = "postcode";
  193. $col["width"] = "25";
  194. $col["align"] = "center"; // this column is not editable
  195. $col["sortable"] = false; // this column is not sortable
  196. $col["search"] = true; // this column is not searchable
  197. $col["editable"] = true;
  198. $col["editoptions"] = array("size"=>12);
  199. $col["hidden"] = true; // HIDE this column
  200. $col["editrules"] = array("edithidden"=>true);
  201. $cols[] = $col;
  202.  
  203. //////////
  204. /////////
  205.  
  206. $col = array();
  207. $col["title"] = "Country";
  208. $col["name"] = "country_id";
  209. $col["width"] = "50";
  210. $col["align"] = "center"; // this column is not editable
  211. $col["sortable"] = true; // this column is not sortable
  212. $col["search"] = true; // this column is not searchable
  213.  
  214. $col["dbname"] = "c.country_id"; // this is required as we need to search in name field, not id
  215. $col["editable"] = true;
  216.  
  217. # fetch data from database, with alias k for key, v for value
  218. $str = $g->get_dropdown_values("select distinct country_id as k, local_name as v from crm_country where type = 'CO' ORDER BY local_name");
  219.  
  220. $col["edittype"] = "select"; // render as select
  221. $col["editoptions"] = array("value"=>$str, "defaultValue" => "United Kingdom");
  222. $col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('{$col["name"]}'); },200); }";
  223.  
  224. $col["stype"] = "select"; // render as select
  225. $col["searchoptions"] = array("value"=>$str);
  226. $col["searchoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('gs_{$col["name"]}'); },200); }";
  227.  
  228. $cols[] = $col;
  229.  
  230. //////////
  231. /////////
  232.  
  233. $col = array();
  234. $col["title"] = "Address";
  235. $col["name"] = "address";
  236. $col["width"] = "60";
  237. $col["sortable"] = false; // this column is not sortable
  238. $col["search"] = false; // this column is not searchable
  239. $col["editable"] = true;
  240. $col["edittype"] = "textarea"; // render as textarea on edit
  241. $col["editoptions"] = array("rows"=>4, "cols"=>51); // with these attributes
  242. $col["hidden"] = true; // HIDE this column
  243. $col["editrules"] = array("edithidden"=>true);
  244. $cols[] = $col;
  245.  
  246. //////////
  247. /////////
  248.  
  249. $col = array();
  250. $col["title"] = "Contact Name";
  251. $col["name"] = "contact_name";
  252. $col["width"] = "50";
  253. $col["editable"] = true; // this column is not editable
  254. $col["align"] = "center"; // this column is not editable
  255. $col["search"] = true; // this column is not searchable
  256. $cols[] = $col;
  257.  
  258. //////////
  259.  
  260.  
  261. $col = array();
  262. $col["title"] = "Phone";
  263. $col["name"] = "phone";
  264. $col["width"] = "35";
  265. $col["align"] = "center"; // this column is not editable
  266. $col["sortable"] = false; // this column is not sortable
  267. $col["search"] = true; // this column is not searchable
  268. $col["editable"] = true;
  269. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  270. $cols[] = $col;
  271.  
  272.  
  273. //////////
  274. /////////
  275.  
  276. $col = array();
  277. $col["title"] = "Email";
  278. $col["name"] = "email";
  279. $col["width"] = "50";
  280. $col["align"] = "center"; // this column is not editable
  281. $col["sortable"] = false; // this column is not sortable
  282. $col["search"] = true; // this column is not searchable
  283. $col["editable"] = true;
  284. $col["editoptions"] = array("size"=>50); // with default display of textbox with size 20
  285. $col["formatter"] = "function(cellval,options,rowdata){ return '<a href=\"mailto:'+cellval+'\">'+cellval+'</a>'; }";
  286. $col["unformat"] = "function(cellval,options,cell){ return $('a', cell).attr('href').replace('mailto:',''); }";
  287. $cols[] = $col;
  288.  
  289.  
  290. //////////
  291. /////////
  292.  
  293. $col = array();
  294. $col["title"] = "Website";
  295. $col["name"] = "website";
  296. $col["width"] = "50";
  297. $col["align"] = "center"; // this column is not editable
  298. $col["sortable"] = false; // this column is not sortable
  299. $col["search"] = true; // this column is not searchable
  300. $col["editable"] = true;
  301. $col["editoptions"] = array("size"=>50); // with default display of textbox with size 20
  302. $col["formatter"] = "function(cellval,options,rowdata){ return '<a target=\"_blank\" href=\"http://'+cellval+'\">'+cellval+'</a>'; }";
  303. $col["unformat"] = "function(cellval,options,cell){ return $('a', cell).attr('href').replace('http://',''); }";
  304. $cols[] = $col;
  305.  
  306.  
  307. //////////
  308. /////////
  309.  
  310. $col = array();
  311. $col["title"] = "Group";
  312. $col["name"] = "group_id";
  313. $col["width"] = "50";
  314. $col["align"] = "center"; // this column is not editable
  315. $col["sortable"] = true; // this column is not sortable
  316. $col["search"] = true; // this column is not searchable
  317.  
  318. $col["dbname"] = "g.group_id"; // this is required as we need to search in name field, not id
  319. $col["editable"] = true;
  320.  
  321. # fetch data from database, with alias k for key, v for value
  322. $str = $g->get_dropdown_values("select distinct group_id as k, group_name as v from crm_group ORDER BY group_name");
  323.  
  324. $col["edittype"] = "select"; // render as select
  325. $col["editoptions"] = array("value"=>$str, "defaultValue" => "Default Group");
  326. $col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('{$col["name"]}'); },200); }";
  327.  
  328. $col["stype"] = "select"; // render as select
  329. $col["searchoptions"] = array("value"=>$str);
  330. $col["searchoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('gs_{$col["name"]}'); },200); }";
  331.  
  332. $cols[] = $col;
  333.  
  334. ////////////////////////
  335. ////////////////////////
  336.  
  337. $col = array();
  338. $col["title"] = "Source";
  339. $col["name"] = "source";
  340. $col["width"] = "30";
  341. $col["align"] = "center"; // this column is not editable
  342. $col["sortable"] = false; // this column is not sortable
  343. $col["search"] = true; // this column is not searchable
  344. $col["editable"] = true;
  345. $col["editoptions"] = array("size"=>30); // with default display of textbox with size 20
  346. $col["hidden"] = true; // HIDE this column
  347. $col["editrules"] = array("edithidden"=>true);
  348. $cols[] = $col;
  349.  
  350.  
  351. //////////
  352. /////////
  353.  
  354. $col = array();
  355. $col["title"] = "FRTMAP";
  356. $col["name"] = "frtmap_code";
  357. $col["width"] = "25";
  358. $col["align"] = "center"; // this column is not editable
  359. $col["sortable"] = false; // this column is not sortable
  360. $col["search"] = true; // this column is not searchable
  361. $col["editable"] = true;
  362. $col["editoptions"] = array("size"=>10); // with default display of textbox with size 20
  363. $col["hidden"] = true; // HIDE this column
  364. $col["editrules"] = array("edithidden"=>true);
  365. $cols[] = $col;
  366.  
  367.  
  368. ////////////////////////
  369. ////////////////////////
  370.  
  371. $col = array();
  372. $col["title"] = "Operator";
  373. $col["name"] = "operator_name";
  374. $col["width"] = "20";
  375. $col["align"] = "center"; // this column is not editable
  376. $col["sortable"] = true; // this column is not sortable
  377. $col["search"] = true; // this column is not searchable
  378. $col["editable"] = false;
  379. $col["hidden"] = true; // HIDE this column
  380. //$col["editrules"] = array("edithidden"=>true);
  381. $cols[] = $col;
  382.  
  383.  
  384. //////////
  385. /////////
  386.  
  387. $col = array();
  388. $col["title"] = "Status";
  389. $col["name"] = "status_id";
  390. $col["width"] = "20";
  391. $col["align"] = "center"; // this column is not editable
  392. $col["sortable"] = true; // this column is not sortable
  393. $col["search"] = true; // this column is not searchable
  394.  
  395. $col["dbname"] = "s.status_id"; // this is required as we need to search in name field, not id
  396. $col["editable"] = true;
  397.  
  398. # fetch data from database, with alias k for key, v for value
  399. $str = $g->get_dropdown_values("select distinct status_id as k, status_name as v from crm_status ORDER BY status_id");
  400.  
  401. $col["edittype"] = "select"; // render as select
  402. $col["editoptions"] = array("value"=>$str, "defaultValue" => "Live");
  403. $col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('{$col["name"]}'); },200); }";
  404.  
  405. $col["stype"] = "select"; // render as select
  406. $col["searchoptions"] = array("value"=>$str);
  407. $col["searchoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('gs_{$col["name"]}'); },200); }";
  408.  
  409.  
  410.  
  411. $cols[] = $col;
  412.  
  413.  
  414.  
  415.  
  416. /////////
  417. /////////
  418. // pass the cooked columns to grid
  419. $g->set_columns($cols);
  420.  
  421. /////////////////////////////////
  422. /////////////////////////////////
  423.  
  424. $g->table = "crm_main";
  425. $out_master = $g->render("list1");
  426.  
  427.  
  428.  
  429.  
  430.  
  431. ////////////////////////////////////////////////////////////////
  432. ////////////////////////////////////////////////////////////////
  433. // Grid 02
  434. $g2 = new jqgrid($db_conf);
  435.  
  436.  
  437.  
  438. $opt = array();
  439. $opt["sortname"] = 'note_id'; // by default sort grid by this field
  440. $opt["sortorder"] = "desc"; // ASC or DESC
  441. $opt["height"] = "100";
  442. $opt["width"] = "400";
  443. $opt["caption"] = "Company Notes"; // caption of grid
  444. $opt["multiselect"] = false; // allow you to multi-select through checkboxes
  445. $opt["toolbar"] = top;
  446. $opt["rownumbers"] = true;
  447. $opt["rownumWidth"] = 12;
  448. $opt["resizable"] = false;
  449. $opt["autoresize"] = false;
  450. $opt["scroll"] = true;
  451. $opt["loadtext"] = "Loading Notes ;-)";
  452. //$opt["cellEdit"] = true;
  453. $opt["reloadedit"] = false;
  454.  
  455. $opt["add_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'400', 'top'=>'200', 'left'=>'200');
  456. $opt["edit_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'400', 'top'=>'200', 'left'=>'200');
  457. $opt["view_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'400', 'top'=>'200', 'left'=>'200');
  458.  
  459.  
  460.  
  461.  
  462. $g2->set_options($opt);
  463.  
  464. $cols = array();
  465.  
  466.  
  467. $g2->set_actions(array(
  468. "add"=>true, // allow/disallow add
  469. "edit"=>true, // allow/disallow edit
  470. "delete"=>true, // allow/disallow delete
  471. "rowactions"=>false, // show/hide row wise edit/del/save option
  472. "export"=>false, // show/hide export to excel option
  473. "autofilter" => false, // show/hide autofilter for search
  474. "search" => "simple", // show single/multi field search condition (e.g. simple or advance)
  475. "showhidecolumns" => false
  476. )
  477. );
  478.  
  479. // receive id, selected row of parent grid
  480. $id = intval($_GET["rowid"]);
  481. // and use in sql for filteration
  482. $g2->select_command = "SELECT note_id, note, cie_id FROM crm_notes WHERE cie_id='$id'";
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489. $eg2["on_after_insert"] = array("after_insert_note_Grid02", null, true);
  490. $eg2["on_update"] = array("update_note_Grid02", null, true);
  491. $eg2["on_insert"] = array("add_noteGrid2", null, true);
  492. $g2->set_events($eg2);
  493.  
  494. function after_insert_note_Grid02($data)
  495. {
  496. $computer = gethostname();
  497. $date = date("Y-m-d");
  498. $str="UPDATE crm_notes SET created_by='$computer', created_date='$date' WHERE cie_id ={$data["cie_id"]}";
  499. mysql_query($str);
  500. }
  501.  
  502. function update_note_Grid02($data)
  503. {
  504. $computer = gethostname();
  505. $date = date("Y-m-d");
  506. $str="UPDATE crm_notes SET updated_by='$computer', updated_date='$date' WHERE cie_id ={$data["cie_id"]}";
  507. mysql_query($str);
  508. }
  509.  
  510.  
  511. function add_noteGrid2($data)
  512. {
  513. $id = intval($_GET["rowid"]);
  514. $data["params"]["cie_id"] = $id;
  515. }
  516.  
  517.  
  518.  
  519.  
  520. /////////////////////////////////
  521. /////////////////////////////////
  522.  
  523. $col = array();
  524. $col["title"] = "ID"; // caption of column
  525. $col["name"] = "note_id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  526. $col["width"] = "5";
  527. $col["hidden"] = true; // HIDE this column
  528. //$col["editrules"] = array("edithidden"=>true);
  529. $col["align"] = "center"; // this column is not editable
  530. $col["editable"] = false; // this column is not editable
  531. $col["search"] = false; // this column is not searchable
  532. $cols[] = $col;
  533.  
  534.  
  535. ///////////////////////
  536. ///////////////////////
  537.  
  538. //# Custom made column to show link, must have default value as it's not db driven
  539. $col = array();
  540. $col["title"] = "Details";
  541. $col["name"] = "more_options";
  542. $col["width"] = "30";
  543. $col["align"] = "center";
  544. $col["search"] = false;
  545. $col["sortable"] = false;
  546. # no new line in this html, only space. otherwise it may break ui of grid
  547. $buttons_htmlGrid2 = "<input type='button' value='Edit' onclick='open_editGrid2(this)'>";
  548. $col["default"] = $buttons_htmlGrid2;
  549. $cols[] = $col;
  550.  
  551.  
  552. ///////////////////////
  553. ///////////////////////
  554.  
  555. $col = array();
  556. $col["title"] = "Cie ID";
  557. $col["name"] = "cie_id";
  558. $col["width"] = "5";
  559. $col["editable"] = false; // this column is not editable
  560. $col["align"] = "center"; // this column is not editable
  561. $col["search"] = false; // this column is not searchable
  562. $col["hidden"] = true; // HIDE this column
  563. $cols[] = $col;
  564.  
  565.  
  566. //////////
  567. /////////
  568.  
  569. $col = array();
  570. $col["title"] = "Note";
  571. $col["name"] = "note";
  572. $col["width"] = "60";
  573. $col["sortable"] = false; // this column is not sortable
  574. $col["search"] = false; // this column is not searchable
  575. $col["editable"] = true;
  576. $col["edittype"] = "textarea"; // render as textarea on edit
  577. $col["editoptions"] = array("rows"=>4, "cols"=>51); // with these attributes
  578. $col["hidden"] = false; // HIDE this column
  579. $col["editrules"] = array("edithidden"=>true);
  580. $col["editrules"] = array("required"=>true); // and is required
  581.  
  582. $cols[] = $col;
  583.  
  584. //////////
  585. /////////
  586.  
  587. /////////
  588.  
  589. // pass the cooked columns to grid
  590. $g2->set_columns($cols);
  591.  
  592. // generate grid output, with unique grid name as 'list1'
  593. $g2->table = "crm_notes";
  594. $out_list2 = $g2->render("list2");
  595.  
  596.  
  597.  
  598.  
  599. ////// END Detail Grid 02
  600. ////////////////////////////////////////////////////////////////
  601. ////////////////////////////////////////////////////////////////
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608. ////////////////////////////////////////////////////////////////
  609. ////////////////////////////////////////////////////////////////
  610. // Grid 03 - PHONE LOG TABLE
  611. $g3 = new jqgrid($db_conf);
  612.  
  613.  
  614.  
  615. $opt = array();
  616. $opt["sortname"] = 'log_id'; // by default sort grid by this field
  617. $opt["sortorder"] = "desc"; // ASC or DESC
  618. $opt["height"] = "100";
  619. $opt["width"] = "600";
  620. $opt["caption"] = "Company Phone Log"; // caption of grid
  621. $opt["multiselect"] = false; // allow you to multi-select through checkboxes
  622. $opt["toolbar"] = top;
  623. $opt["rownumbers"] = true;
  624. $opt["rownumWidth"] = 12;
  625. $opt["resizable"] = false;
  626. $opt["autoresize"] = false;
  627. $opt["scroll"] = true;
  628. $opt["loadtext"] = "Loading Phone Log ;-)";
  629. //$opt["cellEdit"] = true;
  630. $opt["reloadedit"] = false;
  631.  
  632. $opt["add_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'400', 'top'=>'200', 'left'=>'400');
  633. $opt["edit_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'400', 'top'=>'200', 'left'=>'400');
  634. $opt["view_options"] = array("recreateForm" => true, "closeAfterEdit"=>true, 'width'=>'400', 'top'=>'200', 'left'=>'400');
  635.  
  636.  
  637.  
  638.  
  639. $g3->set_options($opt);
  640.  
  641. $cols = array();
  642.  
  643.  
  644. $g3->set_actions(array(
  645. "add"=>true, // allow/disallow add
  646. "edit"=>true, // allow/disallow edit
  647. "delete"=>true, // allow/disallow delete
  648. "rowactions"=>false, // show/hide row wise edit/del/save option
  649. "export"=>false, // show/hide export to excel option
  650. "autofilter" => false, // show/hide autofilter for search
  651. "search" => "simple", // show single/multi field search condition (e.g. simple or advance)
  652. "showhidecolumns" => true
  653. )
  654. );
  655.  
  656. // receive id, selected row of parent grid
  657. $id = intval($_GET["rowid"]);
  658. // and use in sql for filteration
  659. $g3->select_command = "SELECT log_id, cie_id, log_date, log_notes, follow_up_date, created_by, checked FROM crm_log WHERE cie_id='$id'";
  660.  
  661.  
  662. $eg3["on_after_insert"] = array("after_insert_log_Grid03", null, true);
  663. $eg3["on_update"] = array("update_log_Grid03", null, true);
  664. $eg3["on_insert"] = array("add_logGrid3", null, true);
  665. $g3->set_events($eg3);
  666.  
  667.  
  668. function after_insert_log_Grid03($data)
  669. {
  670. $computer = gethostname();
  671. $date = date("Y-m-d");
  672. $str="UPDATE crm_log SET created_by='$computer', created_date='$date' WHERE cie_id ={$data["cie_id"]}";
  673. mysql_query($str);
  674. }
  675.  
  676. function update_log_Grid03($data)
  677. {
  678. $computer = gethostname();
  679. $date = date("Y-m-d");
  680. $str="UPDATE crm_log SET updated_by='$computer', update_date='$date' WHERE cie_id='$id'";
  681. mysql_query($str);
  682. }
  683.  
  684. function add_logGrid3($data)
  685. {
  686. $id = intval($_GET["rowid"]);
  687. $data["params"]["cie_id"] = $id;
  688. }
  689.  
  690. /////////////////////////////////
  691. /////////////////////////////////
  692.  
  693. $col = array();
  694. $col["title"] = "ID"; // caption of column
  695. $col["name"] = "log_id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  696. $col["width"] = "5";
  697. $col["hidden"] = true; // HIDE this column
  698. //$col["editrules"] = array("edithidden"=>true);
  699. $col["align"] = "center"; // this column is not editable
  700. $col["editable"] = false; // this column is not editable
  701. $col["search"] = false; // this column is not searchable
  702. $cols[] = $col;
  703.  
  704.  
  705. ////////////////
  706. ////////////////
  707.  
  708. //# Custom made column to show link, must have default value as it's not db driven
  709. $col = array();
  710. $col["title"] = "Details";
  711. $col["name"] = "more_options";
  712. $col["width"] = "30";
  713. $col["align"] = "center";
  714. $col["search"] = false;
  715. $col["sortable"] = false;
  716. # no new line in this html, only space. otherwise it may break ui of grid
  717. $buttons_htmlGrid3 = "<input type='button' value='Edit' onclick='open_editGrid3(this)'>";
  718. $col["default"] = $buttons_htmlGrid3;
  719. $cols[] = $col;
  720.  
  721.  
  722. ///////////////////////
  723. ///////////////////////
  724.  
  725. $col = array();
  726. $col["title"] = "Cie ID";
  727. $col["name"] = "cie_id";
  728. $col["width"] = "5";
  729. $col["editable"] = false; // this column is not editable
  730. $col["align"] = "center"; // this column is not editable
  731. $col["search"] = false; // this column is not searchable
  732. $col["hidden"] = true; // HIDE this column
  733. $cols[] = $col;
  734.  
  735.  
  736. //////////
  737. /////////
  738.  
  739. $col = array();
  740. $col["title"] = "Call Log";
  741. $col["name"] = "log_notes";
  742. $col["width"] = "60";
  743. $col["sortable"] = false; // this column is not sortable
  744. $col["search"] = false; // this column is not searchable
  745. $col["editable"] = true;
  746. $col["edittype"] = "textarea"; // render as textarea on edit
  747. $col["editoptions"] = array("rows"=>4, "cols"=>51); // with these attributes
  748. $col["hidden"] = false; // HIDE this column
  749. $col["editrules"] = array("edithidden"=>true);
  750. $cols[] = $col;
  751.  
  752.  
  753. //////////
  754. /////////
  755.  
  756. $col = array();
  757. $col["title"] = "Log Date";
  758. $col["name"] = "log_date";
  759. $col["width"] = "30";
  760. $col["editable"] = false; // this column is editable
  761. $col["search"] = true; // this column is not searchable
  762. $col["editrules"] = array("required"=>true); // and is required
  763. $col["hidden"] = false; // HIDE this column
  764.  
  765. $cols[] = $col;
  766.  
  767. //////////
  768. /////////
  769.  
  770. $col = array();
  771. $col["title"] = "Follow Up Date";
  772. $col["name"] = "follow_up_date";
  773. $col["width"] = "30";
  774. $col["editable"] = true; // this column is editable
  775. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  776. $col["editrules"] = array("required"=>false, "edithidden"=>true); // and is required
  777. # format as date
  778. $col["formatter"] = "date";
  779. # opts array can have these options: http://api.jqueryui.com/datepicker/
  780. $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d.m.Y', "opts" => array("changeYear" => true, "dateFormat"=>'yy-mm-dd', "minDate"=>"16-04-01"));
  781.  
  782. // to perfor contains search, uncomment following - will disable datepicker
  783. // $col["searchoptions"]["sopt"] = array("cn");
  784. // search date in format Jan 23, 2008
  785. // $col["dbname"] = "date_format(invdate,'%b %d, %Y')";
  786.  
  787. $cols[] = $col;
  788.  
  789. ////////////////////////
  790. ////////////////////////
  791.  
  792. $col = array();
  793. $col["title"] = "Operator";
  794. $col["name"] = "created_by";
  795. $col["width"] = "20";
  796. $col["align"] = "center"; // this column is not editable
  797. $col["sortable"] = true; // this column is not sortable
  798. $col["search"] = true; // this column is not searchable
  799. $col["editable"] = false;
  800. $col["hidden"] = false; // HIDE this column
  801. //$col["editrules"] = array("edithidden"=>true);
  802. $cols[] = $col;
  803.  
  804.  
  805. //////////
  806. /////////
  807.  
  808. /////////
  809.  
  810.  
  811. // pass the cooked columns to grid
  812. $g3->set_columns($cols);
  813.  
  814. // generate grid output, with unique grid name as 'list1'
  815. $g3->table = "crm_log";
  816. $out_list3 = $g3->render("list3");
  817.  
  818.  
  819.  
  820.  
  821. ////// END Detail Grid 03
  822. ////////////////////////////////////////////////////////////////
  823. ////////////////////////////////////////////////////////////////
  824. ?>
  825.  
  826.  
  827. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  828. <html>
  829. <head>
  830. <link rel="stylesheet" type="text/css" media="screen" href="lib/js/themes/redmond/jquery-ui.custom.css"></link>
  831. <link rel="stylesheet" type="text/css" media="screen" href="lib/js/jqgrid/css/ui.jqgrid.css"></link>
  832.  
  833. <script src="lib/js/jquery.min.js" type="text/javascript"></script>
  834. <script src="lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  835. <script src="lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  836. <script src="lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  837.  
  838. <!--link href="lib/js/integration/select2/select2.css" rel="stylesheet"/>
  839. <script src="lib/js/integration/select2/select2.min.js"></script-->
  840.  
  841. <link rel="stylesheet" href="//cdn.jsdelivr.net/select2/3.5.2/select2.css">
  842. <script src="//cdn.jsdelivr.net/select2/3.5.2/select2.min.js"></script>
  843.  
  844. </head>
  845. <body>
  846. <div style="margin:10px">
  847.  
  848.  
  849. <?php echo $out_master ?>
  850. <br>
  851.  
  852. <div style="float:left">
  853. <?php echo $out_list2?>
  854. </div>
  855.  
  856. <div style="float:left; margin-left:20px">
  857. <?php echo $out_list3?>
  858. </div>
  859.  
  860. </div>
  861.  
  862. <script>
  863. function open_edit(o)
  864. {
  865. var rowid = jQuery(o).closest('tr').attr('id');
  866. jQuery("#list1").jqGrid().setSelection(rowid);
  867. jQuery("#edit_list1").click();
  868. }
  869. </script>
  870.  
  871.  
  872. <script>
  873. function open_editGrid2(o)
  874. {
  875. var rowid = jQuery(o).closest('tr').attr('id');
  876. jQuery("#list2").jqGrid().setSelection(rowid);
  877. jQuery("#edit_list2").click();
  878. }
  879. </script>
  880.  
  881.  
  882. <script>
  883. function open_editGrid3(o)
  884. {
  885. var rowid = jQuery(o).closest('tr').attr('id');
  886. jQuery("#list3").jqGrid().setSelection(rowid);
  887. jQuery("#edit_list3").click();
  888. }
  889. </script>
  890.  
  891.  
  892. <script>
  893. function link_select2(id)
  894. {
  895. $('select[name='+id+'].editable, select[id='+id+']').select2({width:'95%', dropdownCssClass: 'ui-widget ui-jqdialog', onSelect: function(){ jQuery(this).trigger('change'); }});
  896. $(document).unbind('keypress').unbind('keydown');
  897. }
  898. </script>
  899.  
  900. <script>
  901. function grid_onload(ids)
  902. {
  903. // get row ids from grid (with id: list1)
  904. var ids = $("#list1").jqGrid('getDataIDs');
  905. setTimeout( function(){ jQuery("#list1").jqGrid('setSelection', ids[0], true); },100);
  906. }
  907. </script>
  908.  
  909.  
  910. </body>
  911. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement