Skip to content

Commit

Permalink
Fixed bug - delete participant, tokens and responses functionality wa…
Browse files Browse the repository at this point in the history
…s not working. Modified view so that delete dialog doesn't dissapear off the bottom of the page in some circumstances.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@12410 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
jcleeland committed Feb 9, 2012
1 parent 1906014 commit 6c0e465
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 38 deletions.
83 changes: 49 additions & 34 deletions application/models/Participants.php
Expand Up @@ -153,35 +153,6 @@ function updateRow($data)
Yii::app()->db->createCommand()->update('{{participants}}', $data, 'participant_id = :participant_id')->bindParam(":participant_id", $data["participant_id"], PDO::PARAM_INT);
}

function deleteParticipantTokenAnswer($rows)
{
$rowid = explode(",", $rows);
//$rowid = array('243148a0-bf56-4ee1-a6d2-a1f1cb5243d5');
foreach ($rowid as $row)
{
$tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = "' . $row . '"')->queryAll();
foreach ($tokens as $key => $value)
{
Yii::app()->db->createCommand()->delete('{{participants}}', 'participant_id = :participant_id')->bindParam(":participant_id", $row, PDO::PARAM_INT); //Delete from participants
if (Yii::app()->db->schema->getTable('tokens_' . Yii::app()->db->quoteValue($value['survey_id'])))
{
$tokenid = Yii::app()->db->createCommand()->select('token')->from('{{tokens_' . intval($value['survey_id']) . '}}')->where('participant_id = :participant_id')->bindParam(":participant_id", $value['participant_id'], PDO::PARAM_INT)->queryAll();
$token = $tokenid[0];
if (Yii::app()->db->schema->getTable('survey_' . intval($value['survey_id'])))
{
if (!empty($token['token']))
{
$gettoken = Yii::app()->db->createCommand()->select('*')->from('{{survey_' . intval($value['survey_id']) . '}}')->where('token = :token')->bindParam(":token", $token['token'], PDO::PARAM_STR)->queryAll();
$gettoken = $gettoken[0];
Yii::app()->db->createCommand()->delete('{{survey_' . intval($value['survey_id']) . '}}', 'token = :token')->bindParam(":token", $gettoken['token'], PDO::PARAM_STR);
}
}
Yii::app()->db->createCommand()->delete('{{tokens_' . intval($value['survey_id']) . '}}', 'participant_id = :participant_id')->bindParam(":participant_id", $value['participant_id'], PDO::PARAM_INT); // Deletes from token
}
}
}
}

/*
* This function combines the shared participant and the central participant
* table and searches for any reference of owner id or shared owner id in the rows
Expand Down Expand Up @@ -227,14 +198,18 @@ function getSurveyCount($participant_id)
}

/*
* This function deletes the row marked in the navigator
* These functions delete the row marked in the navigator
* Parameters : row id's
* Return Data : None
*/

function deleteParticipant($rows)
{
// Converting the comma seperated id's to an array to delete multiple rows
/* This function deletes the participant from the participants table,
references in the survey_links table (but not in matching tokens tables)
and then all the participants attributes. */

// Converting the comma seperated id's to an array to delete multiple rows
$rowid = explode(",", $rows);
foreach ($rowid as $row)
{
Expand All @@ -246,16 +221,20 @@ function deleteParticipant($rows)

function deleteParticipantToken($rows)
{
/* This function deletes the participant from the participants table,
the participant from any tokens table they're in (using the survey_links table to find them)
and then all the participants attributes. */

$rowid = explode(",", $rows);
foreach ($rowid as $row)
{
$tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = :row')->bindParam(":row", $row, PDO::PARAM_INT)->queryAll();
$tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = "' . $row .'"')->queryAll();

foreach ($tokens as $key => $value)
{
if (Yii::app()->db->schema->getTable('tokens_' . intval($value['survey_id'])))
{
Yii::app()->db->createCommend()->delete(Tokens::model()->tableName(), array('in', 'participant_id', $row));
Yii::app()->db->createCommand()->delete(Tokens::model()->tableName(), array('in', 'participant_id', $row));
}
}

Expand All @@ -265,7 +244,43 @@ function deleteParticipantToken($rows)
}
}

function getParticipantsSearch($condition, $page, $limit)
function deleteParticipantTokenAnswer($rows)
{
/* This function deletes the participant from the participants table,
the participant from any tokens table they're in (using the survey_links table to find them),
all responses in surveys they've been linked to,
and then all the participants attributes. */
$rowid = explode(",", $rows);
foreach ($rowid as $row)
{
//ORIGINAL LINE: $tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = "' . $row . '"')->queryAll();
$tokens = Yii::app()->db->createCommand()->select('*')->from('{{survey_links}}')->where('participant_id = :row')->bindParam(":row", $row, PDO::PARAM_INT)->queryAll();

foreach ($tokens as $key => $value)
{
if (Yii::app()->db->schema->getTable('tokens_' . Yii::app()->db->quoteValue($value['survey_id'])))
{
$tokenid = Yii::app()->db->createCommand()->select('token')->from('{{tokens_' . intval($value['survey_id']) . '}}')->where('participant_id = "' . $value['participant_id'] . '"')->queryAll();
$token = $tokenid[0];
if (Yii::app()->db->schema->getTable('survey_' . intval($value['survey_id'])))
{
if (!empty($token['token']))
{
$gettoken = Yii::app()->db->createCommand()->select('*')->from('{{survey_' . intval($value['survey_id']) . '}}')->where('token = :token')->bindParam(":token", $token['token'], PDO::PARAM_STR)->queryAll();
$gettoken = $gettoken[0];
Yii::app()->db->createCommand()->delete('{{survey_' . intval($value['survey_id']) . '}}', 'token = :token')->bindParam(":token", $gettoken['token'], PDO::PARAM_STR); // Deletes matching responses from surveys
}
}
Yii::app()->db->createCommand()->delete('{{tokens_' . intval($value['survey_id']) . '}}', 'participant_id = "' . $value['participant_id'] . '"'); // Deletes matching token table entries
}
}
Yii::app()->db->createCommand()->delete(Participants::model()->tableName(), array('in', 'participant_id', $row));
Yii::app()->db->createCommand()->delete(Survey_links::model()->tableName(), array('in', 'participant_id', $row));
Yii::app()->db->createCommand()->delete(Participant_attribute::model()->tableName(), array('in', 'participant_id', $row));
}
}

function getParticipantsSearch($condition, $page, $limit)
{
$start = $limit * $page - $limit;
if ($condition[1] == 'equal')
Expand Down
Expand Up @@ -76,6 +76,7 @@
var orTxt="<?php $clang->eT("OR") ?>";
/* End search form titles */

var exportToCSVTitle = "<?php $clang->eT("Export to CSV"); ?>";
var spTitle = "<?php $clang->eT("Sharing participants..."); ?>";
var spAddBtn = "<?php $clang->eT("Share the selected participants"); ?>";
var sfNoUser = "<?php $clang->eT("No other user in the system"); ?>";
Expand Down
15 changes: 11 additions & 4 deletions scripts/admin/displayParticipant.js
Expand Up @@ -120,7 +120,7 @@ $(document).ready(function() {
multiselect: true,
loadonce : false,
loadError : function(xhr, st, str) {
var dialog_buttons={};
var dialog_buttons={};
dialog_buttons[okBtn]=function(){
$( this ).dialog( "close" );
};
Expand Down Expand Up @@ -259,9 +259,16 @@ $(document).ready(function() {
{width : 400},
{msg:deleteMsg, width : 700,
afterShowForm: function($form) {
/* This code sets the position of the delete dialog to just below the last selected item */
/* Unless this would put the delete dialog off the page, in which case it will be pushed up a bit */
var dialog = $form.closest('div.ui-jqdialog'),
selRowId = jQuery("#displayparticipants").jqGrid('getGridParam', 'selrow'),
selRowCoordinates = $('#'+selRowId).offset();
selRowCoordinates.top=selRowCoordinates.top+25;
selRowCoordinates.left=50;
if(selRowCoordinates.top+325 > $(window).height()) {
selRowCoordinates.top=selRowCoordinates.top-325;
}
dialog.offset(selRowCoordinates);
},
beforeSubmit : function(postdata, formid) {
Expand Down Expand Up @@ -292,7 +299,7 @@ $(document).ready(function() {
'#pager',
{
caption:"",
title:"Export to CSV",
title:exportToCSVTitle,
buttonicon:'exporticon',
onClickButton:function() {
$.post(
Expand Down Expand Up @@ -371,9 +378,9 @@ $(document).ready(function() {
}
jQuery("#displayparticipants").jqGrid('setGridParam',{
url:jsonSearchUrl+'/'+searchconditions,
gridComplete: function(){
gridComplete: function(){
if(jQuery("#displayparticipants").jqGrid('getGridParam', 'records') == 0) {
var dialog_buttons={};
var dialog_buttons={};
dialog_buttons[okBtn]=function(){
$( this ).dialog( "close" );
};
Expand Down

0 comments on commit 6c0e465

Please sign in to comment.