2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

New feature: Deduplicate sample import on primary phone number

This commit is contained in:
Adam Zammit
2021-11-05 13:54:47 +11:00
3 changed files with 69 additions and 39 deletions

View File

@@ -57,10 +57,10 @@ if (isset($_POST['import_form']))
$error = verify_fields($sfields); $error = verify_fields($sfields);
$description = $_POST['description']; $description = $_POST['description'];
$deduplicate = !empty($_POST['deduplicate']);
if ($error == "") if ($error == "")
{ //verified so upload { //verified so upload
if (import_file($_POST['filename'],$description,$sfields)) if (import_file($_POST['filename'],$description,$sfields, 2, $deduplicate))
{ {
print "<div class='well text-primary col-md-offset-2'><p>" . T_("Successfully imported sample") . "&emsp;<h3>$description</h3></p></div>"; print "<div class='well text-primary col-md-offset-2'><p>" . T_("Successfully imported sample") . "&emsp;<h3>$description</h3></p></div>";
} }
@@ -86,7 +86,7 @@ else if (isset($_POST['import_file']))
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>"; 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>";
print "<form action='' method='post' class='col-md-10 form-group col-md-offset-1'>"; print "<form action='' method='post' class='col-md-10 form-horizontal col-md-offset-1'>";
$tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO"); $tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO");
move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname); move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
@@ -97,7 +97,13 @@ else if (isset($_POST['import_file']))
<input type="hidden" name="description" value="<?php if (isset($_POST['description'])) print($_POST['description']); ?>"/> <input type="hidden" name="description" value="<?php if (isset($_POST['description'])) print($_POST['description']); ?>"/>
<input type="hidden" name="filename" value="<?php echo $tmpfname; ?>"/> <input type="hidden" name="filename" value="<?php echo $tmpfname; ?>"/>
<div class="form-group"> <div class="form-group">
<label class="col-md-4 control-label" for="submit"></label> <label class="col-sm-4 control-label" for="deduplicate"><?php echo T_("Filter out duplicates on primary phone number? "); ?></label>
<div class="col-sm-4" style="height: 30px;">
<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" />
</div>
</div>
<div class="form-group">
<div class="col-md-4 control-label"></div>
<div class="col-md-4"> <div class="col-md-4">
<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> <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>
</div> </div>

View File

@@ -51,12 +51,12 @@ if (isset($_POST['import_file']))
$tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO"); $tmpfname = tempnam(TEMPORARY_DIRECTORY, "FOO");
move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname); move_uploaded_file($_FILES['file']['tmp_name'],$tmpfname);
$deduplicate = !empty($_POST['deduplicate']);
$valid = verify_file($tmpfname,$import_id); $valid = verify_file($tmpfname,$import_id);
if ($valid) if ($valid)
{ //verified so upload { //verified so upload
if (update_file($tmpfname,$import_id)) if (update_file($tmpfname,$import_id, $deduplicate))
{ {
print "<div class='well text-primary col-md-offset-2'><p>" . T_("Successfully updated sample") . "&emsp;<h3>$description</h3></p></div>"; print "<div class='well text-primary col-md-offset-2'><p>" . T_("Successfully updated sample") . "&emsp;<h3>$description</h3></p></div>";
} }
@@ -122,7 +122,12 @@ else
</div> </div>
</div> </div>
<div class="form-group">
<label class="col-sm-4 control-label" for="deduplicate"><?php echo T_("Filter out duplicates on primary phone number? "); ?></label>
<div class="col-sm-4" style="height: 30px;">
<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" />
</div>
</div>
<!-- Button --> <!-- Button -->
<div class="form-group"> <div class="form-group">
<label class="col-md-4 control-label" for="submit"></label> <label class="col-md-4 control-label" for="submit"></label>

View File

@@ -231,7 +231,7 @@ function get_first_row($file)
/** /**
* Add records to an existing sample * Add records to an existing sample
*/ */
function update_file($file,$import_id) function update_file($file,$import_id, $deduplicate= false)
{ {
global $db; global $db;
@@ -256,7 +256,7 @@ function update_file($file,$import_id)
$count++; $count++;
} }
add_to_sample($file,$import_id,$selected_type,$selected_name,$sirv_id,2); add_to_sample($file,$import_id,$selected_type,$selected_name,$sirv_id,2, $deduplicate);
return $db->CompleteTrans(); return $db->CompleteTrans();
} }
@@ -267,12 +267,14 @@ function update_file($file,$import_id)
* @param string $file File name to open * @param string $file File name to open
* @param string $description A description of the sample * @param string $description A description of the sample
* @param array $fields Which fields to import and what type they are assigned to * @param array $fields Which fields to import and what type they are assigned to
* @param integer $firstrow
* @param boolean $deduplicate
* *
* @see verify_fields() * @see verify_fields()
* @see display_table() * @see display_table()
* *
*/ */
function import_file($file, $description, $fields, $firstrow = 2) function import_file($file, $description, $fields, $firstrow = 2, $deduplicate = false)
{ {
//import into database //import into database
@@ -315,18 +317,25 @@ function import_file($file, $description, $fields, $firstrow = 2)
} }
} }
add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstrow); add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstrow,$deduplicate);
return $db->CompleteTrans(); return $db->CompleteTrans();
} }
/** /**
* add_to_sample * add_to_sample
* @param $file
* @param $id
* @param $selected_type
* @param $selected_name
* @param $sirv_id
* @param $firstrow
* @param boolean $deduplicate check primary phone before import
* *
* Add records to the sample file * Add records to the sample file
* *
*/ */
function add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstrow) function add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstrow, $deduplicate = false)
{ {
global $db; global $db;
@@ -353,6 +362,7 @@ function add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstro
{ {
//determine if there is a phone number - if not - do not import //determine if there is a phone number - if not - do not import
$numberavail = 0; $numberavail = 0;
$duplicate = 0;
foreach($selected_type as $key => $val) foreach($selected_type as $key => $val)
{ {
if ($val == 2 || $val == 3) if ($val == 2 || $val == 3)
@@ -396,7 +406,15 @@ function add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstro
$ppid = array_search('3', $selected_type); $ppid = array_search('3', $selected_type);
$dppid = only_numbers($data[$ppid - 1]); $dppid = only_numbers($data[$ppid - 1]);
$duplicate = false;
if($deduplicate) {
$countSql = "SELECT COUNT(*) as count FROM sample WHERE import_id='$id' and phone='$dppid'";
$count = $db->GetRow($countSql);
if(!empty($count) && $count['count']) {
$duplicate = true;
}
}
if(!$duplicate) {
$sql = "INSERT INTO sample (sample_id,import_id,Time_zone_name,phone) $sql = "INSERT INTO sample (sample_id,import_id,Time_zone_name,phone)
VALUES (NULL,'$id','$tzone','$dppid')"; VALUES (NULL,'$id','$tzone','$dppid')";
@@ -425,6 +443,7 @@ function add_to_sample($file,$id,$selected_type,$selected_name,$sirv_id,$firstro
$imported++; $imported++;
} }
} }
}
$row++; $row++;
} }