Merge lp:~shnoulle/quexs/deduplicate into lp:quexs

Proposed by Shnoulle
Status: Merged
Approved by: Adam Zammit
Approved revision: 644
Merged at revision: 644
Proposed branch: lp:~shnoulle/quexs/deduplicate
Merge into: lp:quexs
Diff against target: 223 lines (+68/-38)
3 files modified
admin/import.php (+10/-4)
admin/updatesample.php (+8/-3)
functions/functions.import.php (+50/-31)
To merge this branch: bzr merge lp:~shnoulle/quexs/deduplicate
Reviewer Review Type Date Requested Status
Adam Zammit Approve
Review via email: mp+411031@code.launchpad.net

Commit message

Allow to check existing primary phone when import or update sample

Description of the change

Add checkbox (checked) to disable create duplicate primary phone when create or update sample
Use this checkbox when addi ng row for sample

To post a comment you must log in.
Revision history for this message
Adam Zammit (adamzammit) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'admin/import.php'
2--- admin/import.php 2015-09-15 17:20:26 +0000
3+++ admin/import.php 2021-10-29 16:32:31 +0000
4@@ -57,10 +57,10 @@
5 $error = verify_fields($sfields);
6
7 $description = $_POST['description'];
8-
9+ $deduplicate = !empty($_POST['deduplicate']);
10 if ($error == "")
11 { //verified so upload
12- if (import_file($_POST['filename'],$description,$sfields))
13+ if (import_file($_POST['filename'],$description,$sfields, 2, $deduplicate))
14 {
15 print "<div class='well text-primary col-md-offset-2'><p>" . T_("Successfully imported sample") . "&emsp;<h3>$description</h3></p></div>";
16 }
17@@ -86,7 +86,7 @@
18 echo "<a href='' onclick='history.back();return false;' class='btn btn-default pull-left' ><i class='fa fa-chevron-left fa-lg text-primary'></i>&emsp;" . T_("Go back") . "</a>";
19
20
21- print "<form action='' method='post' class='col-md-10 form-group col-md-offset-1'>";
22+ print "<form action='' method='post' class='col-md-10 form-horizontal col-md-offset-1'>";
23
24 $tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO");
25 move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
26@@ -97,7 +97,13 @@
27 <input type="hidden" name="description" value="<?php if (isset($_POST['description'])) print($_POST['description']); ?>"/>
28 <input type="hidden" name="filename" value="<?php echo $tmpfname; ?>"/>
29 <div class="form-group">
30- <label class="col-md-4 control-label" for="submit"></label>
31+ <label class="col-sm-4 control-label" for="deduplicate"><?php echo T_("Filter out duplicates on primary phone number? "); ?></label>
32+ <div class="col-sm-4" style="height: 30px;">
33+ <input name="deduplicate" id="deduplicate" type="checkbox" checked="checked" data-toggle="toggle" data-on="<?php echo T_("Yes"); ?>" data-off="<?php echo T_("No"); ?>" data-width="80" />
34+ </div>
35+ </div>
36+ <div class="form-group">
37+ <div class="col-md-4 control-label"></div>
38 <div class="col-md-4">
39 <button id="submit" type="submit" name="import_form" class="btn btn-primary"><i class="fa fa-plus-square-o fa-lg"></i>&emsp;<?php echo T_("Add sample"); ?></button>
40 </div>
41
42=== modified file 'admin/updatesample.php'
43--- admin/updatesample.php 2017-08-07 02:07:36 +0000
44+++ admin/updatesample.php 2021-10-29 16:32:31 +0000
45@@ -51,12 +51,12 @@
46
47 $tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO");
48 move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
49-
50+ $deduplicate = !empty($_POST['deduplicate']);
51 $valid = verify_file($tmpfname,$import_id);
52
53 if ($valid)
54 { //verified so upload
55- if (update_file($tmpfname,$import_id))
56+ if (update_file($tmpfname,$import_id, $deduplicate))
57 {
58 print "<div class='well text-primary col-md-offset-2'><p>" . T_("Successfully updated sample") . "&emsp;<h3>$description</h3></p></div>";
59 }
60@@ -122,7 +122,12 @@
61
62 </div>
63 </div>
64-
65+ <div class="form-group">
66+ <label class="col-sm-4 control-label" for="deduplicate"><?php echo T_("Filter out duplicates on primary phone number? "); ?></label>
67+ <div class="col-sm-4" style="height: 30px;">
68+ <input name="deduplicate" id="deduplicate" type="checkbox" checked="checked" data-toggle="toggle" data-on="<?php echo T_("Yes"); ?>" data-off="<?php echo T_("No"); ?>" data-width="80" />
69+ </div>
70+ </div>
71 <!-- Button -->
72 <div class="form-group">
73 <label class="col-md-4 control-label" for="submit"></label>
74
75=== modified file 'functions/functions.import.php'
76--- functions/functions.import.php 2019-05-21 06:14:48 +0000
77+++ functions/functions.import.php 2021-10-29 16:32:31 +0000
78@@ -231,7 +231,7 @@
79 /**
80 * Add records to an existing sample
81 */
82-function update_file($file,$import_id)
83+function update_file($file,$import_id, $deduplicate= false)
84 {
85 global $db;
86
87@@ -256,7 +256,7 @@
88 $count++;
89 }
90
91- add_to_sample($file,$import_id,$selected_type,$selected_name,$sirv_id,2);
92+ add_to_sample($file,$import_id,$selected_type,$selected_name,$sirv_id,2, $deduplicate);
93
94 return $db->CompleteTrans();
95 }
96@@ -267,12 +267,14 @@
97 * @param string $file File name to open
98 * @param string $description A description of the sample
99 * @param array $fields Which fields to import and what type they are assigned to
100+ * @param integer $firstrow
101+ * @param boolean $deduplicate
102 *
103 * @see verify_fields()
104 * @see display_table()
105 *
106 */
107-function import_file($file, $description, $fields, $firstrow = 2)
108+function import_file($file, $description, $fields, $firstrow = 2, $deduplicate = false)
109 {
110 //import into database
111
112@@ -315,18 +317,25 @@
113 }
114 }
115
116- add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstrow);
117+ add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstrow,$deduplicate);
118
119 return $db->CompleteTrans();
120 }
121
122 /**
123 * add_to_sample
124- *
125+ * @param $file
126+ * @param $id
127+ * @param $selected_type
128+ * @param $selected_name
129+ * @param $sirv_id
130+ * @param $firstrow
131+ * @param boolean $deduplicate check primary phone before import
132+ *
133 * Add records to the sample file
134 *
135 */
136-function add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstrow)
137+function add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstrow, $deduplicate = false)
138 {
139 global $db;
140
141@@ -353,6 +362,7 @@
142 {
143 //determine if there is a phone number - if not - do not import
144 $numberavail = 0;
145+ $duplicate = 0;
146 foreach($selected_type as $key => $val)
147 {
148 if ($val == 2 || $val == 3)
149@@ -365,7 +375,7 @@
150 }
151 }
152 }
153-
154+
155 if ($numberavail == 1)
156 {
157 //insert into sample field
158@@ -396,33 +406,42 @@
159 $ppid = array_search('3', $selected_type);
160
161 $dppid = only_numbers($data[$ppid - 1]);
162-
163- $sql = "INSERT INTO sample (sample_id,import_id,Time_zone_name,phone)
164- VALUES (NULL,'$id','$tzone','$dppid')";
165-
166- $db->Execute($sql);
167-
168- $sid = $db->Insert_Id();
169+ $duplicate = false;
170+ if($deduplicate) {
171+ $countSql = "SELECT COUNT(*) as count FROM sample WHERE import_id='$id' and phone='$dppid'";
172+ $count = $db->GetRow($countSql);
173+ if(!empty($count) && $count['count']) {
174+ $duplicate = true;
175+ }
176+ }
177+ if(!$duplicate) {
178+ $sql = "INSERT INTO sample (sample_id,import_id,Time_zone_name,phone)
179+ VALUES (NULL,'$id','$tzone','$dppid')";
180
181-
182- /**
183- * insert into sample_var field
184- */
185- foreach($selected_name as $key => $val)
186- {
187- if (isset($data[$key -1 ]))
188- $dkey = $db->Quote($data[$key - 1]);
189- else
190- $dkey = $db->Quote("");
191-
192- $sql = "INSERT INTO sample_var (sample_id,var_id,val)
193- VALUES ('$sid','{$sirv_id[$key]}',{$dkey})";
194-
195 $db->Execute($sql);
196-
197+
198+ $sid = $db->Insert_Id();
199+
200+
201+ /**
202+ * insert into sample_var field
203+ */
204+ foreach($selected_name as $key => $val)
205+ {
206+ if (isset($data[$key -1 ]))
207+ $dkey = $db->Quote($data[$key - 1]);
208+ else
209+ $dkey = $db->Quote("");
210+
211+ $sql = "INSERT INTO sample_var (sample_id,var_id,val)
212+ VALUES ('$sid','{$sirv_id[$key]}',{$dkey})";
213+
214+ $db->Execute($sql);
215+
216+ }
217+
218+ $imported++;
219 }
220-
221- $imported++;
222 }
223 }
224

Subscribers

People subscribed via source and target branches

to all changes: