1 | // This module prepare by : Jaypee Tanio
|
---|
2 | // June 16, 2013
|
---|
3 |
|
---|
4 | function GetDate()
|
---|
5 | {
|
---|
6 | $('#save').click(function(){
|
---|
7 | Time = [];
|
---|
8 | Data = [];
|
---|
9 | Source = [];
|
---|
10 | Measure = [];
|
---|
11 | Table = [];
|
---|
12 | $('div#TableHolder table').each(function(){ // call all the id of the table inside div#TableHolder
|
---|
13 | id=$(this).attr('id'); //Getting all id's
|
---|
14 | Time.push('#'+id+' input#Time'); // Storing id's of each element
|
---|
15 | Data.push('#'+id+' input#txtData');
|
---|
16 | Source.push('#'+id+' select#source :selected');
|
---|
17 | Measure.push('#'+id+' select#measurement :selected');
|
---|
18 | Table.push(id);
|
---|
19 | });
|
---|
20 | GetSaveData(Time,Data,Source,Measure); // Function call of saving the data
|
---|
21 | });
|
---|
22 |
|
---|
23 | };
|
---|
24 |
|
---|
25 |
|
---|
26 | function GetSaveData(Time,Data,Source,Measure){
|
---|
27 | var checks=0;
|
---|
28 | TimeSave = [];
|
---|
29 | DataSave = [];
|
---|
30 | SourceSave = [];
|
---|
31 | MeasureSave = [];
|
---|
32 | for(i=0;i<$('div#TableHolder table').length;i++)
|
---|
33 | {
|
---|
34 | $(Time[i]).each(function(){
|
---|
35 | TimeSave.push($(this).val()); // extracting each data into a value
|
---|
36 | });
|
---|
37 | $(Data[i]).each(function(){
|
---|
38 | DataSave.push($(this).val()); // extracting each data into a value
|
---|
39 | });
|
---|
40 | $(Source[i]).each(function(){
|
---|
41 | SourceSave.push($(this).val()); // extracting each data into a value
|
---|
42 | });
|
---|
43 | $(Measure[i]).each(function(){
|
---|
44 | MeasureSave.push($(this).val()); // extracting each data into a value
|
---|
45 | });
|
---|
46 | }
|
---|
47 | if($('#save').val()=='UPDATE')
|
---|
48 | {
|
---|
49 | if(checks == 0)
|
---|
50 | {
|
---|
51 | $.ajax({
|
---|
52 | type: "POST",
|
---|
53 | cache: false,
|
---|
54 | url: "Transaction/update.php",
|
---|
55 | data: "Time="+TimeSave+'&Source='+SourceSave+'&measure='+MeasureSave+'&Data='+DataSave+'&Date='+year+'-'+month+'-'+day, //posting the data to save
|
---|
56 | success: function(data) {
|
---|
57 |
|
---|
58 | alert('Successfully Updated ! '+year+'-'+month+'-'+day);
|
---|
59 |
|
---|
60 | }
|
---|
61 | });
|
---|
62 | }
|
---|
63 | else
|
---|
64 | {
|
---|
65 |
|
---|
66 | alert("Please fill all the details!");
|
---|
67 | }
|
---|
68 | }
|
---|
69 | else
|
---|
70 | {
|
---|
71 | if(checks == 0)
|
---|
72 | {
|
---|
73 | $.ajax({
|
---|
74 | type: "POST",
|
---|
75 | cache: false,
|
---|
76 | url: "Transaction/insert.php",
|
---|
77 | data: "Time="+TimeSave+'&Source='+SourceSave+'&measure='+MeasureSave+'&Data='+DataSave+'&Date='+year+'-'+month+'-'+day, //posting the data to save
|
---|
78 | success: function(data) {
|
---|
79 |
|
---|
80 | alert('Successfully added ! '+year+'-'+month+'-'+day);
|
---|
81 |
|
---|
82 | }
|
---|
83 | });
|
---|
84 | }
|
---|
85 | else
|
---|
86 | {
|
---|
87 |
|
---|
88 | alert("Please fill all the details!");
|
---|
89 | }
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 | }; |
---|