Skip to content

Commit

Permalink
Fixed issue: DB Update codes for database failed_login_attempts were …
Browse files Browse the repository at this point in the history
…under a different version number.

Dev Moved a blocked of code to create failed_login_attempts under block 145.

New feature: Changing owner of survey.
Dev Can now change the owner of the survey and the surveys get transferred to a different user if a user is being deleted.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@9550 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Kshitij Parajulik committed Nov 28, 2010
1 parent d2e668c commit fae9c4d
Show file tree
Hide file tree
Showing 11 changed files with 469 additions and 271 deletions.
14 changes: 12 additions & 2 deletions admin/admin.php
Expand Up @@ -422,12 +422,16 @@
include('access_denied.php');
}
}
elseif ($action=='ajaxowneredit' || $action == 'ajaxgetusers'){

include('surveylist.php');
}
if (!isset($assessmentsoutput) && !isset($statisticsoutput) && !isset($browseoutput) &&
!isset($savedsurveyoutput) && !isset($listcolumnoutput) && !isset($conditionsoutput) &&
!isset($importoldresponsesoutput) && !isset($exportroutput) && !isset($vvoutput) &&
!isset($tokenoutput) && !isset($exportoutput) && !isset($templatesoutput) && !isset($translateoutput) && //<AdV>
!isset($iteratesurveyoutput) && (substr($action,0,4)!= 'ajax') && ($action!='update') &&
(isset($surveyid) || $action == "" || preg_match('/^(listsurveys|personalsettings|statistics|copysurvey|importsurvey|editsurveysettings|editsurveylocalesettings|updatesurveysettings|updatesurveysettingsandeditlocalesettings|updatedefaultvalues|ordergroups|dataentry|newsurvey|listsurveys|globalsettings|editusergroups|editusergroup|exportspss|surveyrights|quotas|editusers|login|browse|vvimport|vvexport|setuserrights|modifyuser|setusertemplates|deluser|adduser|userrights|usertemplates|moduser|addusertogroup|deleteuserfromgroup|globalsettingssave|savepersonalsettings|addusergroup|editusergroupindb|usergroupindb|delusergroup|mailusergroup|mailsendusergroup)$/',$action)))
(isset($surveyid) || $action == "" || preg_match('/^(personalsettings|statistics|copysurvey|importsurvey|editsurveysettings|editsurveylocalesettings|updatesurveysettings|updatesurveysettingsandeditlocalesettings|updatedefaultvalues|ordergroups|dataentry|newsurvey|globalsettings|editusergroups|editusergroup|exportspss|surveyrights|quotas|editusers|login|browse|vvimport|vvexport|setuserrights|modifyuser|setusertemplates|deluser|adduser|userrights|usertemplates|moduser|addusertogroup|deleteuserfromgroup|globalsettingssave|savepersonalsettings|addusergroup|editusergroupindb|usergroupindb|finaldeluser|delusergroup|mailusergroup|mailsendusergroup)$/',$action)))
{
if ($action=='editsurveysettings' || $action=='editsurveylocalesettings')
{
Expand All @@ -437,6 +441,12 @@
include('html.php');
}

if ($action == "listsurveys"){
include('html_functions.php');
include('html.php');
include('surveylist.php');
}

if ($action == 'dataentry')
{
if (bHasSurveyPermission($surveyid, 'responses','read') || bHasSurveyPermission($surveyid, 'responses','create') || bHasSurveyPermission($surveyid, 'responses','update'))
Expand Down Expand Up @@ -515,7 +525,7 @@
}


if ($action=='adduser' || $action=='deluser' || $action=='moduser' || $action=='setusertemplates' || $action=='usertemplates' || //Still to check
if ($action=='adduser' || $action=='deluser'|| $action=='finaldeluser' || $action=='moduser' || $action=='setusertemplates' || $action=='usertemplates' || //Still to check
$action=='userrights' || $action=='modifyuser' || $action=='editusers' ||
$action=='addusergroup' || $action=='editusergroup' || $action=='mailusergroup' ||
$action=='delusergroup' || $action=='usergroupindb' || $action=='mailsendusergroup' ||
Expand Down
214 changes: 0 additions & 214 deletions admin/html.php
Expand Up @@ -20,220 +20,6 @@
if (isset($_POST['uid'])) {$postuserid=sanitize_int($_POST['uid']);}
if (isset($_POST['ugid'])) {$postusergroupid=sanitize_int($_POST['ugid']);}

if ($action == "listsurveys")
{
$js_admin_includes[]='../scripts/jquery/jquery.tablesorter.min.js';
$js_admin_includes[]='scripts/listsurvey.js';
$query = " SELECT a.*, c.*, u.users_name FROM ".db_table_name('surveys')." as a "
." INNER JOIN ".db_table_name('surveys_languagesettings')." as c ON ( surveyls_survey_id = a.sid AND surveyls_language = a.language ) AND surveyls_survey_id=a.sid and surveyls_language=a.language "
." INNER JOIN ".db_table_name('users')." as u ON (u.uid=a.owner_id) ";

if ($_SESSION['USER_RIGHT_SUPERADMIN'] != 1)
{
$query .= "WHERE a.sid in (select sid from ".db_table_name('survey_permissions')." where uid={$_SESSION['loginID']} and permission='survey' and read_p=1) ";
}

$query .= " ORDER BY surveyls_title";

$result = db_execute_assoc($query) or safe_die($connect->ErrorMsg()); //Checked

if($result->RecordCount() > 0) {
$listsurveys= "<br /><table class='listsurveys'><thead>
<tr>
<th colspan='7'>&nbsp;</th>
<th colspan='3'>".$clang->gT("Responses")."</th>
<th colspan='2'>&nbsp;</th>
</tr>
<tr>
<th>".$clang->gT("Status")."</th>
<th>".$clang->gT("SID")."</th>
<th>".$clang->gT("Survey")."</th>
<th>".$clang->gT("Date created")."</th>
<th>".$clang->gT("Owner") ."</th>
<th>".$clang->gT("Access")."</th>
<th>".$clang->gT("Anonymized responses")."</th>
<th>".$clang->gT("Full")."</th>
<th>".$clang->gT("Partial")."</th>
<th>".$clang->gT("Total")."</th>
<th>".$clang->gT("Tokens available")."</th>
<th>".$clang->gT("Response rate")."</th>
</tr></thead>
<tfoot><tr class='header ui-widget-header'>
<td colspan=\"12\">&nbsp;</td>".
"</tr></tfoot>
<tbody>";
$gbc = "evenrow";
$dateformatdetails=getDateFormatData($_SESSION['dateformat']);

while($rows = $result->FetchRow())
{
if($rows['anonymized']=="Y")
{
$privacy=$clang->gT("Yes") ;
}
else $privacy =$clang->gT("No") ;


if (tableExists('tokens_'.$rows['sid']))
{
$visibility = $clang->gT("Closed");
}
else
{
$visibility = $clang->gT("Open");
}

if($rows['active']=="Y")
{
if ($rows['expires']!='' && $rows['expires'] < date_shift(date("Y-m-d H:i:s"), "Y-m-d", $timeadjust))
{
$status=$clang->gT("Expired") ;
}
elseif ($rows['startdate']!='' && $rows['startdate'] > date_shift(date("Y-m-d H:i:s"), "Y-m-d", $timeadjust))
{
$status=$clang->gT("Not yet active") ;
}
else {
$status=$clang->gT("Active") ;
}
// Complete Survey Responses - added by DLR
$gnquery = "SELECT count(id) FROM ".db_table_name("survey_".$rows['sid'])." WHERE submitdate IS NULL";
$gnresult = db_execute_num($gnquery); //Checked
while ($gnrow = $gnresult->FetchRow())
{
$partial_responses=$gnrow[0];
}
$gnquery = "SELECT count(id) FROM ".db_table_name("survey_".$rows['sid']);
$gnresult = db_execute_num($gnquery); //Checked
while ($gnrow = $gnresult->FetchRow())
{
$responses=$gnrow[0];
}

}
else $status =$clang->gT("Inactive") ;


$datetimeobj = new Date_Time_Converter($rows['datecreated'] , "Y-m-d H:i:s");
$datecreated=$datetimeobj->convert($dateformatdetails['phpdate']);

if (in_array($rows['owner_id'],getuserlist('onlyuidarray')))
{
$ownername=$rows['users_name'] ;
}
else
{
$ownername="---";
}

$questionsCount = 0;
$questionsCountQuery = "SELECT * FROM ".db_table_name('questions')." WHERE sid={$rows['sid']} AND language='".$rows['language']."'"; //Getting a count of questions for this survey
$questionsCountResult = $connect->Execute($questionsCountQuery); //Checked
$questionsCount = $questionsCountResult->RecordCount();

$listsurveys.="<tr>";

if ($rows['active']=="Y")
{
if ($rows['expires']!='' && $rows['expires'] < date_shift(date("Y-m-d H:i:s"), "Y-m-d", $timeadjust))
{
$listsurveys .= "<td><img src='$imageurl/expired.png' "
. "alt='".$clang->gT("This survey is active but expired.")."' /></td>";
}
else
{
if (bHasSurveyPermission($rows['sid'],'surveyactivation','update'))
{
$listsurveys .= "<td><a href=\"#\" onclick=\"window.open('$scriptname?action=deactivate&amp;sid={$rows['sid']}', '_top')\""
. " title=\"".$clang->gTview("This survey is active - click here to deactivate this survey.")."\" >"
. "<img src='$imageurl/active.png' alt='".$clang->gT("This survey is active - click here to deactivate this survey.")."' /></a></td>\n";
} else
{
$listsurveys .= "<td><img src='$imageurl/active.png' "
. "alt='".$clang->gT("This survey is currently active.")."' /></td>\n";
}
}
} else {
if ( $questionsCount > 0 && bHasSurveyPermission($rows['sid'],'surveyactivation','update') )
{
$listsurveys .= "<td><a href=\"#\" onclick=\"window.open('$scriptname?action=activate&amp;sid={$rows['sid']}', '_top')\""
. " title=\"".$clang->gTview("This survey is currently not active - click here to activate this survey.")."\" >"
. "<img src='$imageurl/inactive.png' title='' alt='".$clang->gT("This survey is currently not active - click here to activate this survey.")."' /></a></td>\n" ;
} else
{
$listsurveys .= "<td><img src='$imageurl/inactive.png'"
. " title='".$clang->gT("This survey is currently not active.")."' alt='".$clang->gT("This survey is currently not active.")."' />"
. "</td>\n";
}
}

$listsurveys.="<td align='center'><a href='".$scriptname."?sid=".$rows['sid']."'>{$rows['sid']}</a></td>";
$listsurveys.="<td align='left'><a href='".$scriptname."?sid=".$rows['sid']."'>{$rows['surveyls_title']}</a></td>".
"<td>".$datecreated."</td>".
"<td>".$ownername."</td>".
"<td>".$visibility."</td>" .
"<td>".$privacy."</td>";

if ($rows['active']=="Y")
{
$complete = $responses - $partial_responses;
$listsurveys .= "<td>".$complete."</td>";
$listsurveys .= "<td>".$partial_responses."</td>";
$listsurveys .= "<td>".$responses."</td>";
}else{
$listsurveys .= "<td>&nbsp;</td>";
$listsurveys .= "<td>&nbsp;</td>";
$listsurveys .= "<td>&nbsp;</td>";
}

if ($rows['active']=="Y" && tableExists("tokens_".$rows['sid']))
{
//get the number of tokens for each survey
$tokencountquery = "SELECT count(tid) FROM ".db_table_name("tokens_".$rows['sid']);
$tokencountresult = db_execute_num($tokencountquery); //Checked
while ($tokenrow = $tokencountresult->FetchRow())
{
$tokencount = $tokenrow[0];
}

//get the number of COMLETED tokens for each survey
$tokencompletedquery = "SELECT count(tid) FROM ".db_table_name("tokens_".$rows['sid'])." WHERE completed!='N'";
$tokencompletedresult = db_execute_num($tokencompletedquery); //Checked
while ($tokencompletedrow = $tokencompletedresult->FetchRow())
{
$tokencompleted = $tokencompletedrow[0];
}

//calculate percentage

//prevent division by zero problems
if($tokencompleted != 0 && $tokencount != 0)
{
$tokenpercentage = round(($tokencompleted / $tokencount) * 100, 1);
}
else
{
$tokenpercentage = 0;
}

$listsurveys .= "<td>".$tokencount."</td>";
$listsurveys .= "<td>".$tokenpercentage."%</td>";
}
else
{
$listsurveys .= "<td>&nbsp;</td>";
$listsurveys .= "<td>&nbsp;</td>";
}

$listsurveys .= "</tr>" ;
}

$listsurveys.="</tbody>";
$listsurveys.="</table><br />" ;
}
else $listsurveys="<p><strong> ".$clang->gT("No Surveys available - please create one.")." </strong><br /><br />" ;
}

if ($action == "personalsettings")
{

Expand Down
2 changes: 1 addition & 1 deletion admin/install/create-postgres.sql
Expand Up @@ -435,7 +435,7 @@ CREATE TABLE prefix_failed_login_attempts (
number_attempts integer NOT NULL
);

ALTER TABLE ONLY failed_login_attempts ADD CONSTRAINT failed_login_attempts_pkey PRIMARY KEY ("id");
ALTER TABLE ONLY prefix_failed_login_attempts ADD CONSTRAINT prefix_failed_login_attempts_pkey PRIMARY KEY ("id");

--
-- Secondary indexes
Expand Down
47 changes: 47 additions & 0 deletions admin/scripts/admin_core.js
@@ -1,4 +1,5 @@
//$Id$

$(document).ready(function(){
setupAllTabs();
if(typeof(userdateformat) !== 'undefined')
Expand Down Expand Up @@ -189,6 +190,52 @@ $(document).ready(function(){
speed: 500,
expires: 5000
});

var old_owner = '';

$(".ownername_edit").live('click',function(){
var oldThis = this;
var ownername_edit_id = $(this).attr('id');
var survey_id = ownername_edit_id.slice(15);
$.getJSON('admin.php', {
action: 'ajaxgetusers'
},function(oData)
{
old_owner = $($(oldThis).parent()).html();
old_owner = (old_owner.split(" "))[0];
$($(oldThis).parent()).html('<select class="ownername_select" id="ownername_select_'+survey_id+'"></select>'
+ '<input class="ownername_button" id="ownername_button_'+survey_id+'" type="button" value="Update">');
$(oData).each(function(key,value){
$('#ownername_select_'+survey_id).
append($("<option id='opt_"+value[1]+"'></option>").
attr("value",value[0]).
text(value[1]));
});
$("#ownername_select_"+survey_id+ " option[id=opt_"+old_owner+"]").attr("selected","selected");
});
});

$(".ownername_button").live('click',function(){
var oldThis = this;
var ownername_select_id = $(this).attr('id');
var survey_id = ownername_select_id.slice(17);
var newowner = $("#ownername_select_"+survey_id).val();

$.getJSON('admin.php',{
action: 'ajaxowneredit',
newowner: newowner,
survey_id : survey_id
}, function (data){
var objToUpdate = $($(oldThis).parent());
if (data.record_count>0)
$(objToUpdate).html(data.newowner);
else
$(objToUpdate).html(old_owner);

$(objToUpdate).html($(objToUpdate).html() + '(<a id="ownername_edit_69173" class="ownername_edit" href="#">Edit</a>)' );
});
});

});


Expand Down

0 comments on commit fae9c4d

Please sign in to comment.