diff --git a/application/models/Participants.php b/application/models/Participants.php index d7074284e7f..b064a5524a4 100644 --- a/application/models/Participants.php +++ b/application/models/Participants.php @@ -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 @@ -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) { @@ -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)); } } @@ -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') diff --git a/application/views/admin/participants/displayParticipants_view.php b/application/views/admin/participants/displayParticipants_view.php index c6fc24bbad5..6ac576605bf 100644 --- a/application/views/admin/participants/displayParticipants_view.php +++ b/application/views/admin/participants/displayParticipants_view.php @@ -76,6 +76,7 @@ var orTxt="eT("OR") ?>"; /* End search form titles */ + var exportToCSVTitle = "eT("Export to CSV"); ?>"; var spTitle = "eT("Sharing participants..."); ?>"; var spAddBtn = "eT("Share the selected participants"); ?>"; var sfNoUser = "eT("No other user in the system"); ?>"; diff --git a/scripts/admin/displayParticipant.js b/scripts/admin/displayParticipant.js index baa2e4f9417..57f129a724a 100644 --- a/scripts/admin/displayParticipant.js +++ b/scripts/admin/displayParticipant.js @@ -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" ); }; @@ -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) { @@ -292,7 +299,7 @@ $(document).ready(function() { '#pager', { caption:"", - title:"Export to CSV", + title:exportToCSVTitle, buttonicon:'exporticon', onClickButton:function() { $.post( @@ -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" ); };