* @copyright Australian Consortium for Social and Political Research Incorporated (ACSPRI) 2013 * @package queXS * @subpackage admin * @link http://www.acspri.org.au/software queXS was writen for ACSPRI * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2 * */ /** * Configuration file */ include_once(dirname(__FILE__).'/../config.inc.php'); /** * Database */ include_once(dirname(__FILE__).'/../db.inc.php'); /** * Authentication file */ include ("auth-admin.php"); /** * XHTML functions */ include_once(dirname(__FILE__).'/../functions/functions.xhtml.php'); $css = array( "../include/bootstrap/css/bootstrap.min.css", "../include/bootstrap/css/bootstrap-theme.min.css", "../include/font-awesome/css/font-awesome.css", "../include/bootstrap-toggle/css/bootstrap-toggle.min.css", "../css/custom.css" ); $js_head = array( "../include/jquery/jquery.min.js", "../include/bootstrap/js/bootstrap.min.js", "../include/bootstrap-toggle/js/bootstrap-toggle.min.js", ); $js_foot = array( "../js/bootstrap-confirmation.js", "../js/custom.js" ); if (isset($_POST['ren'])) { $sample_import_id = intval($_POST['sample_import_id']); unset($_POST['ren']); unset($_POST['sample_import_id']); $sql = "UPDATE sample_import SET description = " . $db->qstr($_POST['description']) . " WHERE sample_import_id = $sample_import_id"; $db->Execute($sql); $_GET['edit'] = $sample_import_id; } if (isset($_POST['ed'])) { $sample_import_id = intval($_POST['sample_import_id']); unset($_POST['ed']); unset($_POST['sample_import_id']); // print_r($_POST). "
"; //посмотрим чего отравляется if (isset($_POST['del']) && isset($_POST['type']) ) { $a = array(); $b = array(); $cert = array(); $a = $_POST['type']; //echo "

type before unset->>"; foreach($_POST['type'] as $key => $val) { echo ' | ', $key,' => ',$val,' | '; }; print "

"; foreach($_POST['del'] as $p) { unset ($_POST['type'][$p]); $deleted[] = $p; } $b = $_POST['type']; $cert = array_diff_assoc($a, $b); foreach($cert as $key => $val ) { if ($val == 3 || $val==4 || $val == 5 || $val == 6 || $val == 7){ echo "
", T_("Attention!! It's not recommended to delete string '$key'.
Please BE Careful and check again strings to delete."), "
"; } /* else { echo "
", T_("You can delete string '$key'. "), "
"; } */ } //echo "

del ->>"; foreach($_POST['del'] as $key => $val) { echo ' | ', $key,' => ',$val,' | '; }; print "

"; } if (isset($_POST['type'])){ //check that we have correct var types and quantity $prph = 0; $pcd = 0; $st = 0; $fn = 0; $eml =0; $ln =0; foreach($_POST['type'] as $key => $val) { if ($val == 3) $prph++; else if ($val == 5) $pcd++; else if ($val == 4) $st++; else if ($val == 6) $fn++; else if ($val == 7) $ln++; else if ($val == 8) $eml++; } /* if($prph == 1) {$ch1 = true;} else { echo "
", T_("Please check that One and One Only Primary Phone number is selected"), "
";} if (( ($pcd +$st) <= 2 )&&($pcd == 1 || $st == 1)) {$ch2 = true;} else { echo "
", T_("Please check selected types for Postcode and/or State"), "
";} // ! need to add DB tables check for existing timezone data in tables and additional check if prefix_timezone selected if (( ($fn + $ln) <= 2 )&&($fn == 1 || $ln == 1)) {$ch3 = true;} else { echo "
", T_("Please check selected types for Firstname and/or Lastname"), "
";} if ($eml < 2) {$ch4 = true;} else { echo "
", T_("Too many e-mail fields. Please check selected types for E-mail."), "
"; } if ($ch1 && $ch2 && $ch3 && $ch4) */$typecheck = true; //echo $ch1,$ch2,$ch3,$ch4, "typecheck=",$typecheck, "
" ; if ($typecheck){ foreach($_POST['type'] as $p => $val) { $sql = "UPDATE sample_import_var_restrict SET `type` = $val WHERE `var_id` = $p"; $db->Execute($sql); } if (isset($_POST['del'])) { $db->StartTrans(); foreach($_POST["del"] as $p) { $sql = "DELETE FROM `sample_import_var_restrict` WHERE var_id = $p"; $db->Execute($sql); echo "
", T_(" String $p DELETED"), "
"; $sql = "DELETE FROM `sample_var` WHERE var_id = $p AND sample_id IN (SELECT sample_id FROM `sample` WHERE import_id = $sample_import_id)"; $db->Execute($sql); echo "
", T_(" Sample_Var data for variable $p DELETED from this sample"), "
"; } unset($_POST['del']); $db->CompleteTrans(); } } else { echo "
", T_("Smth wrong with selected field types.
Please check again var types selection and/or fields that you supposed to delete."), "
"; //exit (); } } if (isset($_POST['var'])){ foreach($_POST['var'] as $p => $val) {// echo '| ',$p,' => ',$val,'+ '; $v = str_replace(" ", "_", $val); $sql = "UPDATE sample_import_var_restrict SET `var` = '$v' WHERE sample_import_id = $sample_import_id AND `var_id` = $p"; $db->Execute($sql); } unset($_POST['var']); } if (isset($_POST['see'])){ $sql = "UPDATE sample_import_var_restrict SET `restrict` = 1 WHERE sample_import_id = $sample_import_id"; $db->Execute($sql); foreach($_POST['see'] as $p => $val) {// echo $p,' => ',$val,' + '; $sql = "UPDATE sample_import_var_restrict SET `restrict` = 0 WHERE sample_import_id = $sample_import_id AND `var_id` = $val"; $db->Execute($sql); } unset($_POST['see']); } unset($_POST['type']); $_GET['edit'] = $sample_import_id; } if (isset($_GET['delete_sample'])){ $sample_import_id = $_GET['delete_sample']; // -->check questionnaire_sample - unassign sample if assigned $sql = "SELECT questionnaire_id FROM `questionnaire_sample` WHERE sample_import_id = $sample_import_id"; $rs = $db->GetAll($sql); if (count($rs) != 0){ echo "
", T_("Sample $sample_import_id is still assigned to questionnaire.
Please unassign sample prior to delete."), "
"; } else{ //get the string list of sample_id's $sql = "SELECT sample_id FROM `sample` where import_id = $sample_import_id"; $rs = $db->GetAll($sql); for($i=0;$i<=count($rs)-1;$i++){ $samimdel[] = $rs[$i]['sample_id'] ;} $samimdel_s = implode(",",$samimdel); $db->StartTrans(); //del from questionnaire_sample_exclude_priority $sql = "DELETE FROM `questionnaire_sample_exclude_priority` WHERE sample_id IN ($samimdel_s)"; $db->Execute($sql); //del from questionnaire_sample_quota $sql = "DELETE FROM `questionnaire_sample_quota` WHERE sample_import_id = $sample_import_id"; $db->Execute($sql); //del from questionnaire_sample_quota_row $sql = "DELETE FROM `questionnaire_sample_quota_row` WHERE sample_import_id = $sample_import_id"; $db->Execute($sql); //del from questionnaire_sample_quota_row_exclude $sql = "DELETE FROM `questionnaire_sample_quota_row_exclude` WHERE sample_id IN ($samimdel_s)"; $db->Execute($sql); //del from questionnaire_sample_timeslot $sql = "DELETE FROM `questionnaire_sample_timeslot` WHERE sample_import_id = $sample_import_id"; $db->Execute($sql); //delete from sample_var $sql = "DELETE FROM `sample_var` WHERE sample_id IN ($samimdel_s)"; $db->Execute($sql); //del from sample_import_var_restrict $sql = "DELETE FROM `sample_import_var_restrict` WHERE sample_import_id = $sample_import_id"; $db->Execute($sql); //del from sample $sql = "DELETE FROM `sample` WHERE import_id = $sample_import_id"; $db->Execute($sql); //del from sample_import $sql = "DELETE FROM `sample_import` WHERE sample_import_id = $sample_import_id"; $db->Execute($sql); $db->CompleteTrans(); if (mysql_errno() == 0){echo "
", T_("Sample $sample_import_id was deleted."), "
"; } else {echo "
ERROR ".mysql_errno()." ".mysql_error()."\n
";} } unset($_GET['delete_sample']); $samimdel_s = ''; } if (isset($_GET['edit']) ) { $subtitle=T_("Rename, Set viewing permissions & Manage sample variables") ; xhtml_head(T_("Sample management"),true,$css,$js_head,false,false,false,$subtitle); echo "
 " . T_("Go back") . "
"; $sample_import_id = intval($_GET['edit']); $sql = "SELECT * FROM sample_import WHERE sample_import_id = $sample_import_id"; $sd = $db->GetRow($sql); if($sd['enabled'] == 1) $dis = "disabled"; else $dis = false;// -> disable edit and delete if sample is enabled $sql = "SELECT type, description FROM sample_var_type"; $rd = $db->GetAll($sql); $selected = "selected=\"selected\""; $sql = "SELECT sir.var_id, CONCAT('') as var, CONCAT ('') as type, sv.val, CONCAT('') as see, CONCAT('') as del, sir.restrict IS NULL as existss FROM sample_import as si, sample_var as sv, sample as s, sample_import_var_restrict as sir, sample_var_type as svt WHERE si.sample_import_id = $sample_import_id AND sir.sample_import_id = si.sample_import_id AND sir.var_id = sv.var_id AND sv.sample_id = s.sample_id AND s.import_id = si.sample_import_id AND svt.type = sir.type GROUP BY sir.var_id"; $rs = $db->GetAll($sql); print "

" . T_("Sample") . ": " . $sd['description'] . " ID $sample_import_id

"; print "
 " . T_("Search this sample") . "
"; print "
"; if($sd['enabled'] == 0){ ?>

/>

" . T_("Select which fields from this sample to deidentify.

Deidentified fields will be permanently deleted from the sample.") . "

"; } else { print ""; /*check `Time_zone_name` and `phone` values for deidentified records*/ $sql = "SELECT `sample`.sample_id FROM `sample` LEFT JOIN `sample_var` ON (`sample`.sample_id = `sample_var`.sample_id) WHERE `sample_var`.sample_id IS NULL AND `sample`.import_id = $sample_import_id AND (`sample`.Time_zone_name !='' || `sample`.phone !='')"; $rs = $db->GetAll($sql); if (!empty($rs)) { $num = count($rs); print "

" . T_("There're still $num records for `Time_zone_name` and `phone` values for deidentified records") . "

"; print "
"; } } unset ($rs); /*check if there's sample_var data not matching sample_import_var_restrict.var_id */ $sql = "SELECT `sv`.var_id, `sv`.var, `sv`.type FROM `sample_var` as sv LEFT JOIN `sample_import_var_restrict` as sivr ON (`sivr`.var_id = `sv`.var_id) WHERE `sivr`.var_id IS NULL AND `sv`.sample_id IN (SELECT sample_id FROM `sample` WHERE import_id = $sample_import_id) GROUP BY `sv`.var_id"; $rs = $db->GetAll($sql); if (!empty($rs)) { $count = count($rs); //print_r($rs); print "

" . T_("Fix this sample ") . "

"; print "

" . $count . " var id's not match

"; /* print "
"; */ print "
"; /* if (isset($_POST['restore___'])){ $sql = "INSERT INTO sample_import_var_restrict (`sample_import_id`,`var_id`,`var`,`type`,`restrict`) VALUES ($sample_import_id,' ',' ',' ',1)"; $db->Execute($sql); unset($_POST['restore___']); } if (isset($_POST['delvarf___'])){ $sql = ""; $db->Execute($sql); unset($_POST['delvarf___']); } */ unset($rs); } if (isset($_POST['dtzph'])){ /*delete `Time_zone_name` and `phone` values for deidentified records*/ $db->StartTrans(); $sql = "UPDATE `sample` LEFT JOIN `sample_var` ON (`sample`.sample_id = `sample_var`.sample_id) SET `Time_zone_name`='',`phone`='' WHERE `sample_var`.sample_id IS NULL AND `sample`.import_id = $sample_import_id"; $db->Execute($sql); unset($_POST['dtzph']); $db->CompleteTrans(); } xhtml_foot($js_foot); exit(); } if (isset($_GET['sampledisable'])) { $id = intval($_GET['sampledisable']); $sql = "UPDATE sample_import SET enabled = 0 WHERE sample_import_id = '$id'"; $db->Execute($sql); } if (isset($_GET['sampleenable'])) { $id = intval($_GET['sampleenable']); $sql = "UPDATE sample_import SET enabled = 1 WHERE sample_import_id = '$id'"; $db->Execute($sql); } $sql = "SELECT CONCAT(' ',sample_import_id,' ') as id, CASE WHEN enabled = 0 THEN CONCAT('  " . TQ_("Disabled") . " ') ELSE CONCAT('  " . TQ_("Enabled") . " ') END as status, CASE WHEN enabled = 0 THEN CONCAT('" . TQ_("Enable") . " ') ELSE CONCAT('  " . TQ_("Disable") . " ') END as enabledisable, CASE WHEN enabled = 1 THEN CONCAT('') ELSE CONCAT(' + + ') END as did, CASE WHEN enabled = 1 THEN CONCAT('') ELSE CONCAT('') END as delsample, CONCAT('') as ssearch, CONCAT('') as calls, CONCAT('

',description,' 

') as description, CONCAT('

',(SELECT COUNT( DISTINCT`sample_var`.sample_id) FROM `sample_var`, `sample` WHERE `sample`.sample_id = `sample_var`.sample_id AND `sample`.import_id = sample_import_id ),' 

') as cnt FROM sample_import ORDER BY sample_import_id DESC"; $rs = $db->GetAll($sql); $subtitle=T_("Sample list"); xhtml_head(T_("Sample management"),true,$css,$js_head,false,false,false,$subtitle); echo "
 " . T_("Go back") . "  " . T_("Import a sample file") . "
"; $columns = array("id","description","cnt","status","enabledisable","calls","did","ssearch","delsample"); //"vp","rname", //$titles = array(T_("ID"),T_("Sample"),T_("Records"), T_("Call History"),T_("Enable/Disable"), T_("Status"), T_("Deidentify"), T_("View"), T_("Rename"), T_("Search"), T_("Delete sample")); xhtml_table($rs,$columns, false, "table-hover table-condensed "); xhtml_foot($js_foot); ?>