Skip to content

Commit

Permalink
Refactor the 'saved' admin controller - GCI Task #7228219 by gautamgupta
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11681 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
GautamGupta committed Dec 18, 2011
1 parent b663408 commit bdee7b6
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 149 deletions.
170 changes: 56 additions & 114 deletions application/controllers/admin/saved.php
@@ -1,4 +1,4 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey (tm)
* Copyright (C) 2011 The LimeSurvey Project Team / Carsten Schmitz
Expand All @@ -13,149 +13,91 @@
* $Id: saved.php 11128 2011-10-08 22:23:24Z dionet $
*/

/**
* saved
*
* @package LimeSurvey
* @author
* @copyright 2011
* @version $Id: saved.php 11128 2011-10-08 22:23:24Z dionet $
* @access public
*/
class saved extends Survey_Common_Action {
/**
* Saved controller
*
* @package LimeSurvey
* @copyright 2011
* @version $Id: saved.php 11128 2011-10-08 22:23:24Z dionet $
* @access public
*/
class saved extends Survey_Common_Action
{

/**
* saved::view()
* Load viewing of unsaved responses screen.
* @param mixed $surveyid
* @return
* @param mixed $sa Sub Action
*/

public function run($sa)
public function run($sa)
{
if ($sa == 'delete')
$this->route('delete', array());
$this->route('view', array());
if ($sa == 'view')
{
$this->route('view', array('surveyid'));
}
elseif ($sa == 'delete')
{
$this->route('delete', array('surveyid', 'srid', 'scid'));
}
}

public function view()
public function view($iSurveyId)
{
@$surveyid = $_REQUEST['surveyid'];
if (!empty($_REQUEST['sid'])) $surveyid = (int)$_REQUEST['sid'];
$surveyid = sanitize_int($surveyid);
$this->_js_admin_includes(Yii::app()->baseUrl.'scripts/jquery/jquery.tablesorter.min.js');
$this->_js_admin_includes(Yii::app()->baseUrl.'scripts/admin/saved.js');
$iSurveyId = sanitize_int($iSurveyId);
$clang = $this->getController()->lang;

$this->_js_admin_includes(Yii::app()->baseUrl . 'scripts/jquery/jquery.tablesorter.min.js');
$this->_js_admin_includes(Yii::app()->baseUrl . 'scripts/admin/saved.js');
$this->getController()->_getAdminHeader();

if(bHasSurveyPermission($surveyid,'responses','read'))
if (bHasSurveyPermission($iSurveyId, 'responses', 'read'))
{
$clang = $this->getController()->lang;
$thissurvey=getSurveyInfo($surveyid);

$savedsurveyoutput = "<div class='menubar'>\n"
. "<div class='menubar-title ui-widget-header'><span style='font-weight:bold;'>\n";
$savedsurveyoutput .= $clang->gT("Saved Responses")."</span> ".$thissurvey['name']." (ID: $surveyid)</div>\n"
. "<div class='menubar-main'>\n"
. "<div class='menubar-left'>\n";

$savedsurveyoutput .= $this->_savedmenubar($surveyid);

$savedsurveyoutput .= "</div></div></div>\n";

$savedsurveyoutput .= "<div class='header ui-widget-header'>".$clang->gT("Saved Responses:") . " ". getSavedCount($surveyid)."</div><p>";

$data['display'] = $savedsurveyoutput;
$this->getController()->render('/survey_view',$data);
$this->_showSavedList($surveyid);
$aThisSurvey = getSurveyInfo($iSurveyId);
$aData['sSurveyName'] = $aThisSurvey['name'];
$aData['iSurveyId'] = $iSurveyId;
$aData['clang'] = $clang;
$this->getController()->render('/admin/saved/savedbar_view', $aData);
$this->_showSavedList($iSurveyId);
}

$this->getController()->_loadEndScripts();


$this->getController()->_getAdminFooter("http://docs.limesurvey.org", $this->getController()->lang->gT("LimeSurvey online manual"));


$this->getController()->_getAdminFooter('http://docs.limesurvey.org', $clang->gT('LimeSurvey online manual'));
}

/**
* saved::delete()
* Function responsible to delete saved responses.
* @return
*/
public function delete()
public function delete($iSurveyId, $iSurveyResponseId, $iSavedControlId)
{
@$surveyid=$_REQUEST['sid'];
@$srid=$_REQUEST['srid'];
@$scid=$_REQUEST['scid'];
@$subaction=$_REQUEST['subaction'];
$surveytable = "{{survey_".$surveyid."}}";
$clang = $this->getController()->lang;

if ($subaction == "delete" && $surveyid && $scid)
{
$query = "DELETE FROM {{saved_control}}
WHERE scid=$scid
AND sid=$surveyid
";
Yii::app()->loadHelper('database');
if ($result = db_execute_assoc($query))
{
//If we were succesful deleting the saved_control entry,
//then delete the rest
$query = "DELETE FROM {$surveytable} WHERE id={$srid}";
$result = db_execute_assoc($query) or die("Couldn't delete");
Saved_control::model()->deleteAllByAttributes(array('scid' => $iSavedControlId, 'sid' => $iSurveyId)) or die($clang->gT("Couldn't delete"));
Yii::app()->db->createCommand()->delete("{{survey_{$iSurveyId}}}", 'id=:id', array('id' => $iSurveyResponseId)) or die($clang->gT("Couldn't delete"));

}
else
{
safe_error("Couldn't delete<br />$query<br />");
}
}
$this->getController()->redirect("admin/saved/view/surveyid/".$surveyid,'refresh');
$this->getController()->redirect($this->getController()->createUrl("admin/saved/sa/view/surveyid/{$iSurveyId}"));
}

/**
* saved::_showSavedList()
* Load saved list.
* @param mixed $surveyid
* @return
* @param mixed $iSurveyId Survey id
*/
private function _showSavedList($surveyid)
private function _showSavedList($iSurveyId)
{
Yii::app()->loadHelper('database');

$query = "SELECT scid, srid, identifier, ip, saved_date, email, access_code\n"
."FROM {{saved_control}}\n"
."WHERE sid=$surveyid\n"
."ORDER BY saved_date desc";
$result = db_execute_assoc($query) or safe_die ("Couldn't summarise saved entries<br />$query<br />");
if ($result->count() > 0)
$clang = $this->getController()->lang;
$aResults = Saved_control::model()->findAll(array(
'select' => array('scid', 'srid', 'identifier', 'ip', 'saved_date', 'email', 'access_code'),
'condition' => 'sid=:sid',
'order' => 'saved_date desc',
'params' => array(':sid' => $iSurveyId),
)) or die($clang->gT("Couldn't summarise saved entries"));

if (!empty($aResults))
{
$aData['clang'] = $clang;
$aData['aResults'] = $aResults;
$aData['iSurveyId'] = $iSurveyId;

$data['result'] = $result;
$data['clang'] = $this->getController()->lang;
$data['surveyid'] = $surveyid;

$this->getController()->render('/admin/saved/savedlist_view',$data);
$this->getController()->render('/admin/saved/savedlist_view', $aData);
}
}


/**
* saved::_savedmenubar()
* Load menu bar of saved controller.
* @param mixed $surveyid
* @return
*/
private function _savedmenubar($surveyid)
{
//BROWSE MENU BAR
$clang = $this->getController()->lang;
if (!isset($surveyoptions)) {$surveyoptions="";}
$surveyoptions .= "<a href='".Yii::app()->baseUrl.'admin/survey/view/surveyid/'.$surveyid."' title='".$clang->gTview("Return to survey administration")."' >" .
"<img name='Administration' src='".Yii::app()->getConfig('imageurl')."/home.png' alt='".$clang->gT("Return to survey administration")."' align='left'></a>\n";

return $surveyoptions;
}


}
}
18 changes: 18 additions & 0 deletions application/views/admin/saved/savedbar_view.php
@@ -0,0 +1,18 @@
<div class='menubar'>
<div class='menubar-title ui-widget-header'>
<span style='font-weight:bold;'><?php $clang->eT('Saved Responses'); ?></span>
<?php echo $sSurveyName . ' ' . sprintf($clang->gT('ID: %s'), $iSurveyId); ?>
</div>
<div class='menubar-main'>
<div class='menubar-left'>

<a href="<?php echo $this->createUrl("admin/survey/sa/view/surveyid/{$iSurveyId}"); ?>" title="<?php $clang->eT('Return to survey administration'); ?>">
<img name="<?php $clang->eT('Administration'); ?>" src="<?php echo Yii::app()->getConfig('imageurl'); ?>/home.png" alt="<?php echo $clang->eT('Return to survey administration'); ?>" align='left'>
</a>

</div>
</div>
</div>
<div class='header ui-widget-header'>
<?php $clang->eT('Saved Responses:'); ?> <?php echo getSavedCount($iSurveyId); ?>
</div>
79 changes: 44 additions & 35 deletions application/views/admin/saved/savedlist_view.php
@@ -1,35 +1,44 @@
<table class='browsetable' align='center'>
<thead><tr><th>SCID</th><th>
<?php echo $clang->gT("Actions"); ?></th><th>
<?php echo $clang->gT("Identifier"); ?></th><th>
<?php echo $clang->gT("IP address"); ?></th><th>
<?php echo $clang->gT("Date Saved"); ?></th><th>
<?php echo $clang->gT("Email address"); ?></th>
</tr></thead><tbody>
<?php foreach($result->readAll() as $row)
{ ?>
<tr>
<td><?php echo $row['scid']; ?></td>
<td align='center'>

<?php if (bHasSurveyPermission($surveyid,'responses','update'))
{ ?>
<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='image' src='<?php echo Yii::app()->getConfig('imageurl'); ?>/token_edit.png' title='
<?php echo $clang->gT("Edit entry"); ?>' onclick="window.open('<?php echo $_SERVER['PHP_SELF']."?action=dataentry&amp;subaction=edit&amp;id={$row['srid']}&amp;sid={$surveyid}"?>', '_top')" />
<?php }
if (bHasSurveyPermission($surveyid,'responses','delete'))
{ ?>
<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='image' src='<?php echo Yii::app()->getConfig('imageurl'); ?>/token_delete.png' title='
<?php echo $clang->gT("Delete entry"); ?>' onclick="if (confirm('<?php echo $clang->gT("Are you sure you want to delete this entry?","js"); ?>')) { <?php echo get2post($this->createUrl("admin/saved/sa/delete?action=saved&amp;sid=$surveyid&amp;subaction=delete&amp;scid={$row['scid']}&amp;srid={$row['srid']}")); ?>}" />
<?php } ?>

</td>
<td> <?php echo $row['identifier']; ?></td>
<td> <?php echo $row['ip']; ?></td>
<td> <?php echo $row['saved_date']; ?></td>
<td><a href='mailto: <?php echo $row['email']; ?>'> <?php echo $row['email']; ?></td>

</tr>
<?php } ?>
</tbody></table><br />&nbsp

<p>
<table class='browsetable' align='center'>
<thead>
<tr>
<th><?php $clang->eT('ID'); ?></th>
<th><?php $clang->eT('Actions'); ?></th>
<th><?php $clang->eT('Identifier'); ?></th>
<th><?php $clang->eT('IP address'); ?></th>
<th><?php $clang->eT('Date Saved'); ?></th>
<th><?php $clang->eT('Email address'); ?></th>
</tr>
</thead>

<tbody>
<?php foreach($aResults as $oResult)
{ ?>
<tr>
<td><?php echo $oResult->scid; ?></td>
<td align='center'>

<?php if (bHasSurveyPermission($iSurveyId,'responses','update'))
{ ?>
<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='image' src='<?php echo Yii::app()->getConfig('imageurl'); ?>/token_edit.png'
title='<?php $clang->eT('Edit entry'); ?>' onclick="window.open('<?php echo $this->createUrl("admin/dataentry/sa/editdata/subaction/edit/surveyid/{$iSurveyId}/id/{$oResult->srid}"); ?>', '_top')" />
<?php }
if (bHasSurveyPermission($iSurveyId,'responses','delete'))
{ ?>
<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='image' src='<?php echo Yii::app()->getConfig('imageurl'); ?>/token_delete.png'
title='<?php $clang->eT('Delete entry'); ?>' onclick="if (confirm('<?php $clang->eT('Are you sure you want to delete this entry?', 'js'); ?>')) { window.open('<?php echo $this->createUrl("admin/saved/sa/delete/surveyid/{$iSurveyId}/srid/{$oResult->srid}/scid/{$oResult->scid}"); ?>', '_top'); }" />
<?php } ?>

</td>

<td><?php echo $oResult->identifier; ?></td>
<td><?php echo $oResult->ip; ?></td>
<td><?php echo $oResult->saved_date; ?></td>
<td><a href='mailto: <?php echo $oResult->email; ?>'> <?php echo $oResult->email; ?></td>

</tr>
<?php } ?>
</tbody>
</table>
<br />&nbsp
</p>

0 comments on commit bdee7b6

Please sign in to comment.