Skip to content

Commit

Permalink
Fixed #05482: The surveylist in the ci_branch doesn't implement the "…
Browse files Browse the repository at this point in the history
…ajaxuser" feature

Implemented missing ajaxowneredit action as well

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11245 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
sachdeva-shubham committed Oct 23, 2011
1 parent de141a9 commit 8ea7dbd
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
71 changes: 71 additions & 0 deletions application/controllers/admin/survey.php
Expand Up @@ -695,6 +695,77 @@ function activate($iSurveyID)
self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));

}


/**
* survey::ajaxgetusers()
* This get the userlist in surveylist screen.
* @return void
*/
function ajaxgetusers()
{
header('Content-type: application/json');
$this->load->helper('database');

$query = "SELECT users_name, uid FROM ".$this->db->dbprefix."users";

$result = db_execute_assoc($query) or show_error("Couldn't execute $query");

$aUsers = array();
if($result->num_rows() > 0) {
foreach($result->result_array() as $rows)
$aUsers[] = array($rows['uid'], $rows['users_name']);
}

$ajaxoutput = json_encode($aUsers) . "\n";
echo $ajaxoutput;
}

/**
* survey::ajaxowneredit()
* This function change the owner of a survey.
* @param mixed $newowner
* @param mixed $surveyid
* @return void
*/
function ajaxowneredit($newowner,$surveyid)
{
header('Content-type: application/json');
$this->load->helper('database');
//if (isset($_REQUEST['newowner'])) {$intNewOwner=sanitize_int($_REQUEST['newowner']);}
//if (isset($_REQUEST['survey_id'])) {$intSurveyId=sanitize_int($_REQUEST['survey_id']);}
$intNewOwner = sanitize_int($newowner);
$intSurveyId = sanitize_int($surveyid);
$owner_id = $this->session->userdata('loginID');

header('Content-type: application/json');

$query = "UPDATE ".$this->db->dbprefix."surveys SET owner_id = $intNewOwner WHERE sid=$intSurveyId";
if (bHasGlobalPermission("USER_RIGHT_SUPERADMIN"))
$query .="";
else
$query .=" AND owner_id=$owner_id";

$result = db_execute_assoc($query) or show_error("Couldn't execute $query");

$query = "SELECT b.users_name FROM ".$this->db->dbprefix."surveys as a"
." INNER JOIN ".$this->db->dbprefix."users as b ON a.owner_id = b.uid WHERE sid=$intSurveyId AND owner_id=$intNewOwner;";
$result = db_execute_assoc($query) or show_error("Couldn't execute $query");
$intRecordCount = $result->num_rows();

$aUsers = array(
'record_count' => $intRecordCount,
);

if($result->num_rows() > 0) {
foreach($result->result_array() as $rows)
$aUsers['newowner'] = $rows['users_name'];
}
$ajaxoutput = json_encode($aUsers) . "\n";
echo $ajaxoutput;


}


/**
Expand Down
2 changes: 2 additions & 0 deletions application/views/admin/survey/listSurveys_view.php
@@ -1,5 +1,7 @@
<br />
<script type='text/javascript'>
var getuserurl = '<?php echo site_url('admin/survey/ajaxgetusers'); ?>';
var ownerediturl = '<?php echo site_url('admin/survey/ajaxowneredit'); ?>';
sConfirmationDeleteMessage='<?php $clang->eT("Are you sure you want to delete these surveys?",'js');?>';
sConfirmationExpireMessage='<?php $clang->eT("Are you sure you want to expire these surveys?",'js');?>';
sConfirmationArchiveMessage='<?php $clang->eT("This function creates a ZIP archive of several survey archives and can take some time - please be patient! Do you want to contine?",'js');?>';
Expand Down
10 changes: 2 additions & 8 deletions scripts/admin/admin_core.js
Expand Up @@ -217,9 +217,7 @@ $(document).ready(function(){
var survey_id = ownername_edit_id.slice(15);
var translate_to = $(this).attr('translate_to');
var initial_text = $(this).html();
$.getJSON('admin.php', {
action: 'ajaxgetusers'
},function(oData)
$.getJSON(getuserurl,'',function(oData)
{
old_owner = $($(oldThis).parent()).html();

Expand All @@ -244,11 +242,7 @@ $(document).ready(function(){
var newowner = $("#ownername_select_"+survey_id).val();
var translate_to = $(this).attr('value');

$.getJSON('admin.php',{
action: 'ajaxowneredit',
newowner: newowner,
survey_id : survey_id
}, function (data){
$.getJSON(ownerediturl+'/' + newowner + '/' + survey_id,'', function (data){

var objToUpdate = $($(oldThis).parent());

Expand Down

0 comments on commit 8ea7dbd

Please sign in to comment.