Advertisement
Guest User

Revised Update Grid

a guest
Mar 26th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.76 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. $g = new jqgrid();
  30.  
  31. // set few params
  32. $grid["caption"] = "GHL | Todays Leads";
  33.  
  34. // $g->select_command = "Select * From tbl_leads Inner Join dbo_advisers On tbl_leads.Adviser = dbo_advisers.ContactFullName where LeadDate >= Now() - Interval 180 Day";
  35.  
  36. $g->select_command = "Select
  37.  c.client_id,
  38.  c.Adviser,
  39.  c.Client,
  40.  c.DOB,
  41.  c.Address1,
  42.  c.Address2,
  43.  c.Town,
  44.  c.postcode,
  45.  c.Phone,
  46.  c.Email,
  47.  c.Marketing,
  48.  l.id,
  49.  l.Status,
  50.  l.StatusDate,
  51.  l.CompDate,
  52.  l.NPWDate,
  53.  l.InvalidDate,
  54.  l.Source,
  55.  l.MortgageSize,
  56.  l.MortgageType,
  57.  l.PropertyValue,
  58.  l.plan_type,
  59.  l.provider,
  60.  l.product,
  61.  l.LeadDate,
  62.  l.Cost,
  63.  l.broker_fee
  64. From
  65.  tbl_lead l Inner Join
  66.  tbl_clients c On c.client_id = l.client_id";
  67.  
  68.   // this db table will be used for add,edit,delete
  69. $g->table = "tbl_lead";
  70.  
  71. // caption of column
  72. $col = array();
  73. $col["title"] = "client_id"; // caption of column
  74. $col["name"] = "client_id"; // grid column name
  75. $col["editable"] = false;
  76. $col["hidden"] = true; // hide on grid
  77. $col["width"] = "10";
  78. $cols[] = $col;
  79.  
  80. $col = array();
  81. $col["title"] = "id"; // caption of column
  82. $col["name"] = "id"; // grid column name
  83. $col["editable"] = false;
  84. $col["hidden"] = true; // hide on grid
  85. $col["width"] = "10";
  86. $cols[] = $col;
  87.  
  88. $col = array();
  89. $col["title"] = "Adviser"; // caption of column
  90. $col["name"] = "Adviser"; // grid column name
  91. $col["dbname"] = "dbo_advisers.ContactFullName"; // this is required as we need to search in name field, not id
  92. $col["editable"] = true;
  93. $col["edittype"] = "select"; // render as select # fetch data from database, with alias k for key, v for value
  94. $str = $g->get_dropdown_values("select distinct ContactFullName as k, ContactFullName as v from dbo_advisers");
  95. $col["editoptions"] = array("value"=>":;".$str);
  96. $col["searchoptions"] = array("value" => ":;".$str);
  97. $col["formatter"] = "select"; // display label, not value
  98. $cols[] = $col;
  99.  
  100. $col = array();
  101. $col["title"] = "Client"; // caption of column
  102. $col["name"] = "Client"; // grid column name
  103. $col["editable"] = true;
  104. $col["link"] = 'javascript:window.open("http://localhost/form.php/?id={client_id}","newwind","height=600,width=300"); void(0);';
  105. $cols[] = $col;
  106.  
  107. $col = array();
  108. $col["title"] = "DOB"; // caption of column
  109. $col["name"] = "DOB"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  110. $col["formatter"] = "date";
  111. $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y');
  112. $col["hidden"] = true; // hide on grid
  113. $col["editable"] = true;
  114. $col["editrules"] = array("edithidden"=>true);  // show on add
  115. $cols[] = $col;
  116.  
  117. $col = array();
  118. $col["title"] = "Address1"; // caption of column
  119. $col["name"] = "Address1"; // grid column name
  120. $col["hidden"] = true; // hide on grid
  121. $col["editable"] = true;
  122. $col["editrules"] = array("edithidden"=>true); // show on add
  123. $cols[] = $col;
  124.  
  125. $col = array();
  126. $col["title"] = "Address2"; // caption of column
  127. $col["name"] = "Address2"; // grid column name
  128. $col["hidden"] = true; // hide on grid
  129. $col["editable"] = true;
  130. $col["editrules"] = array("edithidden"=>true);  // show on add
  131. $cols[] = $col;
  132.  
  133. $col = array();
  134. $col["title"] = "Town"; // caption of column
  135. $col["name"] = "Town"; // grid column name
  136. $col["hidden"] = true; // hide on grid
  137. $col["editable"] = true;
  138. $col["editrules"] = array("edithidden"=>true);  // show on add
  139. $cols[] = $col;
  140.  
  141. $col = array();
  142. $col["title"] = "PostCode"; // caption of column
  143. $col["name"] = "postcode"; // grid column name
  144. $col["hidden"] = false; // hide on grid
  145. $col["editable"] = true;
  146. $col["editrules"] = array("edithidden"=>true);  // show on add
  147. $cols[] = $col;
  148.  
  149. $col = array();
  150. $col["title"] = "Phone"; // caption of column
  151. $col["name"] = "Phone"; // grid column name
  152. $col["editable"] = true;
  153. $cols[] = $col;
  154.  
  155. $col = array();
  156. $col["title"] = "Email"; // caption of column
  157. $col["name"] = "Email"; // grid column name
  158. $col["editable"] = true;
  159. $cols[] = $col;
  160.  
  161. $col = array();
  162. $col["title"] = "Status"; // caption of column
  163. $col["name"] = "Status"; // grid column name
  164. $col["dbname"] = "tbl_status.Status"; // this is required as we need to search in name field, not id
  165. $col["editable"] = true;
  166. $col["edittype"] = "select"; // render as select
  167. # fetch data from database, with alias k for key, v for value
  168. $str = $g->get_dropdown_values("select distinct LeadStatus as k, LeadStatus as v from tbl_status");
  169. $col["editoptions"] = array("value"=>":;".$str);
  170. $col["searchoptions"] = array("value" => ":;".$str);
  171. $col["formatter"] = "select"; // display label, not value
  172. $cols[] = $col;
  173.  
  174. $col = array();
  175. $col["title"] = "Date"; // caption of column
  176. $col["name"] = "StatusDate"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  177. $col["formatter"] = "date";
  178. $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d-m-Y');
  179. $col["hidden"] = false; // hide on grid
  180. $col["editable"] = true;
  181. $col["editrules"] = array("edithidden"=>true);  // show on add
  182. $cols[] = $col;
  183.  
  184. $col = array();
  185. $col["title"] = "Source"; // caption of column
  186. $col["name"] = "Source"; // grid column name
  187. $col["dbname"] = "tbl_source.source"; // this is required as we need to search in name field, not id
  188. $col["editable"] = true;
  189. $col["edittype"] = "select"; // render as select
  190. # fetch data from database, with alias k for key, v for value
  191. $str = $g->get_dropdown_values("select distinct Source as k, Source as v from tbl_source");
  192. $col["editoptions"] = array("value"=>":;".$str);
  193. $col["formatter"] = "select"; // display label, not value
  194. $cols[] = $col;
  195.  
  196. $col = array();
  197. $col["title"] = "Loan"; // caption of column
  198. $col["name"] = "MortgageSize"; // grid column name
  199. $col["editable"] = true;
  200. $col["hidden"] = true; // hide on grid
  201. $cols[] = $col;
  202.  
  203. $col = array();
  204. $col["title"] = "Type"; // caption of column
  205. $col["name"] = "MortgageType"; // grid column name
  206. $col["dbname"] = "tbl_mrtgtype.Status"; // this is required as we need to search in name field, not id
  207. $col["editable"] = true;
  208. $col["edittype"] = "select"; // render as select
  209. # fetch data from database, with alias k for key, v for value
  210. $str = $g->get_dropdown_values("select distinct MortgageType as k, MortgageType as v from tbl_mrtgtype");
  211. $col["editoptions"] = array("value"=>":;".$str);
  212. $col["formatter"] = "select"; // display label, not value
  213. $cols[] = $col;
  214.  
  215. $col = array();
  216. $col["title"] = "Value"; // caption of column
  217. $col["name"] = "PropertyValue"; // grid column name
  218. $col["editable"] = true;
  219. $col["hidden"] = true; // hide on grid
  220. $cols[] = $col;
  221.  
  222. $col = array();
  223. $col["title"] = "Cost"; // caption of column
  224. $col["name"] = "Cost"; // grid column name
  225. $col["editable"] = true;
  226. $cols[] = $col;
  227.  
  228. $col = array();
  229. $col["title"] = "Send";
  230. $col["name"] = "email_lead";
  231. $col["width"] = "60";
  232. $col["editable"] = true;
  233. $col["editrules"] = array("edithidden"=>true);  // show on add
  234. $col["edittype"] = "checkbox"; // render as checkbox
  235. $col["editoptions"] = array("value"=>"Yes:No"); // with these values "checked_value:unchecked_value"
  236. $col["editoptions"]["onclick"] = 'send_email(this)';
  237. $col["formatter"] = "checkbox";
  238. $col["formatoptions"]["disabled"] = true;
  239. $cols[] = $col;
  240.  
  241.  
  242. // show all other columns after single column format
  243. //$g->set_columns($cols,true);
  244.  
  245. // pass the cooked columns to grid
  246. $g->set_columns($cols);
  247.  
  248. // expand grid to screen width
  249. $grid["autowidth"] = true;
  250.  
  251. //insert data into 2 tables
  252.  
  253. //$e["js_on_select_row"] = "grid_select";
  254. $e["on_insert"] = array("add_client", null, false);
  255. $e["on_update"] = array("update_client", null, false);
  256. $g->set_events($e);
  257.  
  258. function add_client($data)
  259. {
  260.     // first insert in clients table
  261.     mysql_query("insert into tbl_clients (Adviser,Client,DOB,Address1,Address2,Town,postcode,Phone,Email,Marketing)
  262.               values ('{$data[params][Adviser]}',
  263.                   '{$data[params][Client]}',
  264.                   '{$data[params][DOB]}',
  265.                              '{$data[params][Address1]}',
  266.                              '{$data[params][Address2]}',
  267.                              '{$data[params][Town]}',
  268.                              '{$data[params][postcode]}',
  269.                              '{$data[params][Phone]}',
  270.                              '{$data[params][Email]}',
  271.                           '{$data[params][Marketing]}')");
  272.    
  273.     // get insert id
  274.     $client_id = mysql_insert_id();
  275.    
  276.     // insert in tbl_lead table
  277.     mysql_query("insert into tbl_lead (client_id,Status,StatusDate,CompDate,NPWDate,InvalidDate,Source,MortgageSize,MortgageType,PropertyValue,plan_type,provider,product,Cost,broker_fee,comms)
  278.          values ($client_id,
  279.                 '{$data[params][Status]}',
  280.                 '{$data[params][StatusDate]}',
  281.                 '{$data[params][CompDate]}',
  282.                            '{$data[params][NPWDate]}',
  283.                            '{$data[params][InvalidDate]}',
  284.                            '{$data[params][Source]}',
  285.                            '{$data[params][MortgageSize]}',
  286.                            '{$data[params][MortgageType]}',
  287.                            '{$data[params][PropertyValue]}',
  288.                            '{$data[params][plan_type]}',
  289.                            '{$data[params][provider]}',
  290.                            '{$data[params][product]}',
  291.                            '{$data[params][Cost]}',
  292.                            '{$data[params][broker_fee]}',
  293.                 '{$data[params][comms]}')");
  294.    
  295.     // all done
  296.             die;
  297. }
  298.    
  299. function update_client($data)
  300. {
  301.         // first insert in tbl_clients table
  302.        
  303.         mysql_query("update tbl_clients
  304.             set `Adviser` = '{$data[params][Adviser]}',
  305.                  Client = '{$data[params][Client]}',
  306.                  DOB =  '{$data[params][DOB]}',
  307.                             Address1 =  '{$data[params][Address1]}',
  308.                             Address2 =  '{$data[params][Address2]}',
  309.                             Town =  '{$data[params][Town]}',
  310.                             postcode =  '{$data[params][postcode]}',
  311.                             Phone =  '{$data[params][Phone]}',
  312.                              Email = '{$data[params][Email]}',
  313.                              Marketing = '{$data[params][Marketing]}' WHERE client_id = '{$data[params][client_id]}'");
  314.        
  315.         // insert in tbl_lead table
  316.         mysql_query("update tbl_lead
  317.         set client_id='{$data[params][client_id]}',
  318.             Status = '{$data[params][Status]}',
  319.             StatusDate = '{$data[params][StatusDate]}',
  320.             CompDate = '{$data[params][CompDate]}',
  321.                    NPWDate = '{$data[params][NPWDate]}',
  322.                    InvalidDate = '{$data[params][InvalidDate]}',
  323.                    Source = '{$data[params][Source]}',
  324.                    MortgageSize = '{$data[params][MortgageSize]}',
  325.                    MortgageType = '{$data[params][MortgageType]}',
  326.                    PropertyValue = '{$data[params][PropertyValue]}',
  327.                    plan_type = '{$data[params][plan_type]}',
  328.                    provider = '{$data[params][provider]}',
  329.                    product = '{$data[params][product]}',
  330.                    Cost = '{$data[params][Cost]}',
  331.                    broker_fee = '{$data[params][broker_fee]}',
  332.             comms = '{$data[params][comms]}'WHERE id = '{$data[id]}'");
  333.        
  334.         // all done
  335.         die;
  336. }
  337.  
  338. // render grid
  339. $out = $g->render("list1");
  340. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement