Skip to content

Commit

Permalink
Fixed issue #08444: Participant DB : CSV Import Fails To Display All …
Browse files Browse the repository at this point in the history
…Fields

Dev: This part need complete rewriting actually ...
Dev: quick fix to import with only email
Dev: fix lot of HTML issue
  • Loading branch information
Shnoulle committed Dec 17, 2013
1 parent b5ff0a9 commit 1e23dcc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 51 deletions.
53 changes: 42 additions & 11 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -1144,6 +1144,25 @@ function attributeMapCSV()
'filterbea' => $filterblankemails,
'participant_id_exists' => in_array('participant_id', $fieldlist)
);
App()->getClientScript()->registerCssFile(Yii::app()->getConfig('adminstyleurl') . "attributeMapCSV.css");
App()->getClientScript()->registerPackage('qTip2');
App()->getClientScript()->registerPackage('jquery-nestedSortable');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig('adminscripts') . "attributeMapCSV.js");

$sAttributeMapJS="var copyUrl = '".App()->createUrl("admin/participants/sa/uploadCSV")."';\n"
."var displayParticipants = '".App()->createUrl("admin/participants/sa/displayParticipants")."';\n"
."var mapCSVcancelled = '".App()->createUrl("admin/participants/sa/mapCSVcancelled")."';\n"
."var characterset = '".sanitize_paranoid_string($_POST['characterset'])."';\n"
."var okBtn = '".$clang->gT("OK")."';\n"
."var processed = '".$clang->gT("Summary")."';\n"
."var summary = '".$clang->gT("Upload summary")."';\n"
."var notPairedErrorTxt = '".$clang->gT("You have to pair this field with an existing attribute.")."';\n"
."var onlyOnePairedErrorTxt = '".$clang->gT("Only one CSV attribute is mapped with central attribute.")."';\n"
."var cannotAcceptErrorTxt='".$clang->gT("This list cannot accept token attributes.")."';\n"
."var separator = '".sanitize_paranoid_string($_POST['separatorused'])."';\n"
."var thefilepath = '".$sRandomFileName."';\n"
."var filterblankemails = '".$filterblankemails."';\n";
App()->getClientScript()->registerScript("sAttributeMapJS",$sAttributeMapJS,CClientScript::POS_BEGIN);
$this->_renderWrappedTemplate('participants', 'attributeMapCSV', $aData);
}
}
Expand All @@ -1153,11 +1172,12 @@ function attributeMapCSV()
*/
function uploadCSV()
{
$clang = $this->getController()->lang;
unset(Yii::app()->session['summary']);
$characterset = Yii::app()->request->getPost('characterset');
$separator = Yii::app()->request->getPost('separatorused');
$newarray = Yii::app()->request->getPost('newarray');
$mappedarray = Yii::app()->request->getPost('mappedarray');
$mappedarray = Yii::app()->request->getPost('mappedarray',false);
$filterblankemails = Yii::app()->request->getPost('filterbea');
$overwrite = Yii::app()->request->getPost('overwrite');
$sFilePath = Yii::app()->getConfig('tempdir') . '/' . basename(Yii::app()->request->getPost('fullfilepath'));
Expand All @@ -1174,7 +1194,10 @@ function uploadCSV()
$invalidformatlist = array();
$invalidattribute = array();
$invalidparticipantid = array();

$aGlobalErrors=array();
/* If no mapped array */
if(!$mappedarray)
$mappedarray=array();
/* Adjust system settings to read file with MAC line endings */
@ini_set('auto_detect_line_endings', true);
/* Open the uploaded file into an array */
Expand Down Expand Up @@ -1207,7 +1230,7 @@ function uploadCSV()
}
foreach ($tokenlistarray as $buffer) //Iterate through the CSV file line by line
{
$buffer = @mb_convert_encoding($buffer, "UTF-8", $uploadcharset);
$buffer = @mb_convert_encoding($buffer, "UTF-8", $uploadcharset);
$firstname = "";
$lastname = "";
$email = "";
Expand All @@ -1219,6 +1242,7 @@ function uploadCSV()
$buffer = removeBOM($buffer);
$attrid = ParticipantAttributeName::model()->getAttributeID();
$allowedfieldnames = array('participant_id', 'firstname', 'lastname', 'email', 'language', 'blacklisted');
$aFilterDuplicateFields = array('firstname', 'lastname', 'email');
if (!empty($mappedarray))
{
foreach ($mappedarray as $key => $value)
Expand Down Expand Up @@ -1262,7 +1286,11 @@ function uploadCSV()
$recordcount = count($tokenlistarray);
break;
}
} else {
foreach($aFilterDuplicateFields as $sFilterDuplicateField){
if(!in_array($sFilterDuplicateField, $firstline))
$aGlobalErrors[]=sprintf($clang->gT("No %s in header, create empty value for all records."),$sFilterDuplicateField);
}
} else {
// After looking at the first line, we now import the actual values
$line = convertCSVRowToArray($buffer, $separator, '"');

Expand All @@ -1278,10 +1306,14 @@ function uploadCSV()
{
unset($writearray[$column]);
}
// Add aFilterDuplicateFields not in CSV to writearray : quick fix
foreach($aFilterDuplicateFields as $sFilterDuplicateField){
if(!in_array($sFilterDuplicateField, $firstline))
$writearray[$sFilterDuplicateField]="";
}
$invalidemail = false;
$dupfound = false;
$thisduplicate = 0;
$filterduplicatefields = array('firstname', 'lastname', 'email');

//Check for duplicate participants
$aData = array(
Expand All @@ -1299,7 +1331,7 @@ function uploadCSV()
$aData = "firstname = ".Yii::app()->db->quoteValue($writearray['firstname'])." AND lastname = ".Yii::app()->db->quoteValue($writearray['lastname'])." AND email = ".Yii::app()->db->quoteValue($writearray['email'])." AND owner_uid = '".Yii::app()->session['loginID']."'";
}
//End of HACK
$aData = Participant::model()->checkforDuplicate($aData, "participant_id");
$aData = Participant::model()->checkforDuplicate($aData, "participant_id");
if ($aData !== false) {
$thisduplicate = 1;
$dupcount++;
Expand Down Expand Up @@ -1365,7 +1397,7 @@ function uploadCSV()
unset($writearray['validuntil']);
}
$dontimport=false;
if (($filterblankemails == "accept" && $writearray['email'] == "") || $writearray['firstname'] == "" || $writearray['lastname'] == "") {
if (($filterblankemails == "accept" && $writearray['email'] == "")) {
//The mandatory fields of email, firstname and lastname
//must be filled, but one or more are empty
$mandatory++;
Expand Down Expand Up @@ -1405,7 +1437,6 @@ function uploadCSV()
}

unlink($sFilePath);
$clang = $this->getController()->lang;
$aData = array();
$aData['clang'] = $clang;
$aData['recordcount'] = $recordcount - 1;
Expand All @@ -1416,11 +1447,11 @@ function uploadCSV()
$aData['invalidemaillist'] = $invalidemaillist;
$aData['mandatory'] = $mandatory;
$aData['invalidattribute'] = $invalidattribute;
$aData['mandatory'] = $mandatory;
$aData['invalidparticipantid'] = $invalidparticipantid;
$aData['overwritten'] = $overwritten;
$aData['dupreason'] = $dupreason;
$this->getController()->render('/admin/participants/uploadSummary_view', $aData);
$aData['aGlobalErrors'] = $aGlobalErrors;
$this->getController()->renderPartial('/admin/participants/uploadSummary_view', $aData);
}

function summaryview()
Expand Down Expand Up @@ -1762,4 +1793,4 @@ function blacklistParticipant()

}

?>
?>
24 changes: 0 additions & 24 deletions application/views/admin/participants/attributeMapCSV_view.php
@@ -1,25 +1,3 @@
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->getConfig('adminstyleurl') . "attributeMapCSV.css" ?>" />
<script src="<?php echo Yii::app()->getConfig('generalscripts') . "jquery/jquery.qtip.js" ?>" type="text/javascript"></script>
<script src="<?php echo Yii::app()->getConfig('generalscripts') . "jquery/jquery.ui.nestedSortable.js" ?>" type="text/javascript"></script>
<script src="<?php echo Yii::app()->getConfig('adminscripts') . "attributeMapCSV.js" ?>" type="text/javascript"></script>
<script type="text/javascript">

var copyUrl = "<?php echo $this->createUrl("admin/participants/sa/uploadCSV"); ?>";
var displayParticipants = "<?php echo $this->createUrl("admin/participants/sa/displayParticipants"); ?>";
var mapCSVcancelled = "<?php echo $this->createUrl("admin/participants/sa/mapCSVcancelled"); ?>";
var characterset = "<?php echo sanitize_paranoid_string($_POST['characterset']); ?>";
var okBtn = "<?php $clang->eT("OK") ?>";
var processed = "<?php $clang->eT("Summary") ?>";
var summary = "<?php $clang->eT("Upload summary") ?>";
var notPairedErrorTxt = "<?php $clang->eT("You have to pair this field with an existing attribute.") ?>";
var onlyOnePairedErrorTxt = "<?php $clang->eT("Only one CSV attribute is mapped with central attribute.") ?>";
var cannotAcceptErrorTxt="<?php $clang->eT("This list cannot accept token attributes.") ?>";
var separator = "<?php echo sanitize_paranoid_string($_POST['separatorused']); ?>";
var thefilepath = "<?php echo $fullfilepath ?>";
var filterblankemails = "<?php echo $filterbea ?>";
</script>
</head>
<body>
<div class='header ui-widget-header'><strong><?php printf($clang->ngT("Select which fields to import as attributes with your participant.","Select which fields to import as attributes with your %s participants.",$linecount), $linecount); ?></strong></div>
<div class="main">
<div id="csvattribute" class='container'>
Expand Down Expand Up @@ -71,5 +49,3 @@
<div id="processing" title="<?php $clang->eT("Processing...") ?>" style="display:none">
<img src="<?php echo Yii::app()->getConfig('adminimageurl') . '/ajax-loader.gif'; ?>" alt="<?php $clang->eT('Loading...'); ?>" title="<?php $clang->eT('Loading...'); ?>" />
</div>
</body>
</html>
18 changes: 2 additions & 16 deletions application/views/admin/participants/uploadSummary_view.php
@@ -1,14 +1,3 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->getConfig('adminstyleurl') . "adminstyle.css" ?>" />
<script src="<?php echo Yii::app()->getConfig('generalscripts') . "/jquery/jquery.js" ?>" type="text/javascript"></script>
<script src="<?php echo Yii::app()->getConfig('adminscripts') . "/uploadsummary.js" ?>" type="text/javascript"></script>
<script type="text/javascript">var redUrl = "<?php echo $this->createUrl("admin/participants/sa/displayParticipants"); ?>";</script>
</head>
<body>
<?php
$uploadSummary = "<div class='header ui-widget-header'>" . $clang->gT("CPDB CSV summary") . "</div><div class='messagebox ui-corner-all'>";
$uploadSummary .= "<div class='uploadsummary'>\n";
Expand Down Expand Up @@ -83,9 +72,6 @@
echo $errorinupload['error'];
$uploadSummary .= "<div class='warningheader'>" . $errorinupload['error'] . "</div>";
}

foreach($aGlobalErrors as $sGlobalError)
echo "<script> \$notifycontainer.notify('create', 'error-notify', { message:'{$sGlobalError}'});</script>";
echo $uploadSummary;
?>

</body>
</html>

0 comments on commit 1e23dcc

Please sign in to comment.