Skip to content

Commit

Permalink
Fixed issue #8902: CPD Editing shared Participants results in duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Mar 27, 2014
1 parent b949d4d commit afd5100
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 68 deletions.
92 changes: 31 additions & 61 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -461,25 +461,28 @@ function editAttributeInfo()
*/
function delParticipant()
{
$selectoption = Yii::app()->request->getPost('selectedoption');
$iParticipantId = Yii::app()->request->getPost('participant_id');
if (Permission::model()->hasGlobalPermission('participantpanel','delete'))
{
$selectoption = Yii::app()->request->getPost('selectedoption');
$iParticipantId = Yii::app()->request->getPost('participant_id');

//echo $selectoption." -- ".$iParticipantId."<br />"; die();
//echo $selectoption." -- ".$iParticipantId."<br />"; die();

// Deletes from participants only
if ($selectoption == 'po')
{
Participant::model()->deleteParticipants($iParticipantId);
}
// Deletes from central and token table
elseif ($selectoption == 'ptt')
{
Participant::model()->deleteParticipantToken($iParticipantId);
}
// Deletes from central , token and assosiated responses as well
elseif ($selectoption == 'ptta')
{
Participant::model()->deleteParticipantTokenAnswer($iParticipantId);
// Deletes from participants only
if ($selectoption == 'po')
{
Participant::model()->deleteParticipants($iParticipantId);
}
// Deletes from central and token table
elseif ($selectoption == 'ptt')
{
Participant::model()->deleteParticipantToken($iParticipantId);
}
// Deletes from central , token and assosiated responses as well
elseif ($selectoption == 'ptta')
{
Participant::model()->deleteParticipantTokenAnswer($iParticipantId);
}
}
}

Expand All @@ -488,43 +491,23 @@ function delParticipant()
*/
function editParticipant()
{
$operation = Yii::app()->request->getPost('oper');

//In case the uid is not editable, then user id is not posted and hence the current user is added in the uid
if (Yii::app()->request->getPost('owner_uid') == '')
{
$oid = Yii::app()->session['loginID'];
}
//otherwise the one which is posted is added
else
{
$oid = Yii::app()->request->getPost('owner_uid');
}
if (Yii::app()->request->getPost('language') == '')
{
$lang = Yii::app()->session['adminlang'];
}
else
{
$lang = Yii::app()->request->getPost('language');
}
$sOperation = Yii::app()->request->getPost('oper');

// if edit it will update the row
if ($operation == 'edit')
if ($sOperation == 'edit' && Permission::model()->hasGlobalPermission('participantpanel','update') && Participant::model()->is_owner(Yii::app()->request->getPost('id')))
{
$aData = array(
'participant_id' => Yii::app()->request->getPost('id'),
'firstname' => Yii::app()->request->getPost('firstname'),
'lastname' => Yii::app()->request->getPost('lastname'),
'email' => Yii::app()->request->getPost('email'),
'language' => Yii::app()->request->getPost('language'),
'blacklisted' => Yii::app()->request->getPost('blacklisted'),
'owner_uid' => $oid
'blacklisted' => Yii::app()->request->getPost('blacklisted')
);
Participant::model()->updateRow($aData);
}
// if add it will insert a new row
elseif ($operation == 'add')
elseif ($sOperation == 'add' && Permission::model()->hasGlobalPermission('participantpanel','create'))
{
$uuid = $this->gen_uuid();
$aData = array(
Expand All @@ -534,8 +517,8 @@ function editParticipant()
'email' => Yii::app()->request->getPost('email'),
'language' => Yii::app()->request->getPost('language'),
'blacklisted' => Yii::app()->request->getPost('blacklisted'),
'owner_uid' => $oid,
'created_by' => $oid
'owner_uid' => Yii::app()->session['loginID'],
'created_by' => Yii::app()->session['loginID']
);
Participant::model()->insertParticipant($aData);
}
Expand Down Expand Up @@ -950,22 +933,6 @@ function getAttribute_json()
echo ls_json_encode($aData);
}

/*
* Gets the data from the form for add participants and pass it to the participants model
*/
function storeParticipants()
{
$aData = array('participant_id' => uniqid(),
'firstname' => Yii::app()->request->getPost('firstname'),
'lastname' => Yii::app()->request->getPost('lastname'),
'email' => Yii::app()->request->getPost('email'),
'language' => Yii::app()->request->getPost('language'),
'blacklisted' => Yii::app()->request->getPost('blacklisted'),
'owner_uid' => Yii::app()->request->getPost('owner_uid'));

Participant::model()->insertParticipant($aData);
}

/*
* Responsible for showing the additional attribute for central database
*/
Expand Down Expand Up @@ -1074,8 +1041,11 @@ function editAttributevalue()
{
$pid = explode('_',Yii::app()->request->getPost('participant_id'));
$iAttributeId = Yii::app()->request->getPost('attid');
$aData = array('participant_id' => $pid[0], 'attribute_id' => $iAttributeId, 'value' => Yii::app()->request->getPost('attvalue'));
ParticipantAttributeName::model()->editParticipantAttributeValue($aData);
if (Permission::model()->hasGlobalPermission('participantpanel','update') && Participant::model()->is_owner($pid[0]))
{
$aData = array('participant_id' => $pid[0], 'attribute_id' => $iAttributeId, 'value' => Yii::app()->request->getPost('attvalue'));
ParticipantAttributeName::model()->editParticipantAttributeValue($aData);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion application/models/Participant.php
Expand Up @@ -282,7 +282,7 @@ private function getParticipantsSelectCommand($count = false, $attid, $search =
$aAllAttributes = ParticipantAttributeName::model()->getAllAttributes();
foreach ($aAllAttributes as $aAttribute)
{
if(strpos($search->condition,'attribute'.$aAttribute['attribute_id'])!==false)
if(!is_null($search) && strpos($search->condition,'attribute'.$aAttribute['attribute_id'])!==false)
{
$attid[]=$aAttribute;
}
Expand Down
Expand Up @@ -171,6 +171,8 @@
var ajaxUrl = "<?php echo Yii::app()->getConfig('adminimageurl') . "/ajax-loader.gif" ?>";
var redUrl = "<?php echo Yii::app()->getController()->createUrl("admin/participants/sa/displayParticipants"); ?>";
var searchconditions = "<?php echo $sSearchCondition; ?>";
var bEditPermission = <?php echo (Permission::model()->hasGlobalPermission('participantpanel','update'))? 'true' : 'false'; ?>;
var bDeletePermission = <?php echo (Permission::model()->hasGlobalPermission('participantpanel','delete'))? 'true' : 'false'; ?>;
var colNames = '["participant_id","can_edit","<?php $clang->eT("First name") ?>","<?php $clang->eT("Last name") ?>","<?php $clang->eT("Email") ?>","<?php $clang->eT("Blacklisted") ?>","<?php $clang->eT("Surveys") ?>","<?php $clang->eT("Language") ?>","<?php $clang->eT("Owner name") ?>"<?php echo $columnNames; ?>]';
var colModels = '[{ "name":"participant_id", "index":"participant_id", "width":100, "align":"center", "sorttype":"int", "sortable": true, "editable":false, "hidden":true},';
colModels += '{ "name":"can_edit", "index":"can_edit", "width":10, "align":"center", "sorttype":"int", "sortable": true, "editable":false, "hidden":true},';
Expand Down Expand Up @@ -331,7 +333,7 @@
</div>
<div id="notauthorised" title="notauthorised" style="display:none">
<p>
<?php $clang->eT("This is a shared participant and you are not authorised to edit it"); ?></p>
<?php $clang->eT("You do not have the permission to edit this participant."); ?></p>

</div>

Expand Down
10 changes: 5 additions & 5 deletions scripts/admin/participantdisplay.js
Expand Up @@ -137,8 +137,8 @@ $(document).ready(function() {
});
},
ondblClickRow: function(id) {
var can_edit = $('#displayparticipants').getCell(id, 'can_edit');
if(can_edit == 'false') {
var can_edit = ($('#displayparticipants').getCell(id, 'can_edit')=='true') && bEditPermission;
if(!can_edit) {
var dialog_buttons={};
dialog_buttons[okBtn]=function() {
$( this ).dialog( "close" );
Expand Down Expand Up @@ -716,8 +716,8 @@ $(document).ready(function() {
var parid = id.split('_');
var participant_id = $("#displayparticipants_"+parid[0]+"_t").getCell(id,'participant_id');
var lsel = parid[0];
var can_edit = $('#displayparticipants').getCell(participant_id,'can_edit');
if(can_edit == 'false') {
var can_edit = ($('#displayparticipants').getCell(participant_id,'can_edit')=='true' && bEditPermission);
if(!can_edit) {
var dialog_buttons={};
dialog_buttons[okBtn]=function(){
$( this ).dialog( "close" );
Expand Down Expand Up @@ -753,7 +753,7 @@ $(document).ready(function() {
jQuery("tr#"+id+" .ui-inline-edit").hide();
jQuery("tr#"+id+" .ui-inline-save, tr#"+id+" .ui-inline-cancel").show();
}
jQuery("#displayparticipants_"+parid[0]+"_t").jqGrid('editRow',id,true);
//jQuery("#displayparticipants_"+parid[0]+"_t").jqGrid('editRow',id,true);
}
}

Expand Down

0 comments on commit afd5100

Please sign in to comment.