Skip to content

Commit

Permalink
Dev: Refactor the 'dataentry' admin controller in the LimeSurvey Yii …
Browse files Browse the repository at this point in the history
…port (GCI2011 by Ivan Penchev)

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11690 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Pieter Jan Speelmans committed Dec 19, 2011
1 parent 8924e8a commit 475c605
Show file tree
Hide file tree
Showing 14 changed files with 1,066 additions and 1,550 deletions.
2,196 changes: 657 additions & 1,539 deletions application/controllers/admin/dataentry.php

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions application/models/Saved_control.php
Expand Up @@ -47,20 +47,20 @@ function getAllRecords($condition=FALSE)
return $data;
}

function getSomeRecords($fields,$condition=FALSE)
public static function getSomeRecords($condition=FALSE)
{
foreach ($fields as $field)
{
$this->db->select($field);
}
if ($condition != FALSE)
$record = new self;
$criteria = new CDbCriteria;

if($condition != FALSE)
{
$this->db->where($condition);
foreach ($condition as $column=>$value)
{
$criteria->addCondition("$column='$value'");
}
}

$data = $this->db->get('saved_control');

return $data;
return $record->findAll($criteria);
}

public function getCountOfAll($sid)
Expand Down
72 changes: 71 additions & 1 deletion application/models/Survey_dynamic.php
Expand Up @@ -68,12 +68,82 @@ public function primaryKey()
return 'sid';
}

function insertRecords($data)
/**
* Insert records from $data array
*
* @access public
* @param array $data
* @return boolean
*/
public function insertRecords($data)
{
$record = new self;
foreach ($data as $k => $v)
{
$search = array('`', "'");
$k = str_replace($search, '', $k);
$v = str_replace($search, '', $v);
$record->$k = $v;
}
return $record->save();
}

/**
* Queries the database and returns some records or records count
* according to specified conditions
*
* @static
* @access public
* @param array $condition
* @param mixed $select
* @param boolean $return_count
* @return mixed
*/
public static function getSomeRecords($condition=FALSE, $select=FALSE, $return_count=FALSE)
{
$survey = new Survey_dynamic;
$criteria = new CDbCriteria;

if( $select != FALSE ) $criteria->select = $select;

if( $condition != FALSE )
{
foreach($condition as $column => $value)
{
$criteria->addCondition($column."=".$value."");
}
}

if( $return_count )
return $survey->count($criteria);
else
return $survey->findAll($criteria);
}

/**
* Deletes some records from survey's table
* according to specific condition
*
* @static
* @access public
* @param array $condition
* @return int
*/
public static function deleteSomeRecords($condition=FALSE)
{
$survey = new Survey_dynamic;
$criteria = new CDbCriteria;

if( $condition != FALSE )
{
foreach ($condition as $column => $value)
{
return $criteria->addCondition($column."=`".$value."`");
}
}

return $survey->deleteAll($criteria);
}

}
?>
7 changes: 7 additions & 0 deletions application/views/admin/dataentry/delete.php
@@ -0,0 +1,7 @@
<div class='header ui-widget-header'><?php echo $clang->gT("Data entry"); ?></div>
<div class='messagebox ui-corner-all'>
<div class='successheader'><?php echo $clang->gT("Record Deleted"); ?> (ID: <?php echo $id; ?>)</div>
<br /><br />
<input type='submit' value='<?php echo $clang->gT("Browse responses"); ?>' onclick="window.open('<?php echo $this->createUrl('/').'/admin/browse/surveyid/'.$surveyid.'/all'; ?>, '_top')" />
<br /><br />
</div>
1 change: 1 addition & 0 deletions application/views/admin/dataentry/edit.php
@@ -0,0 +1 @@
<?php include('includes/editdata/'.$part.'.php'); ?>
34 changes: 34 additions & 0 deletions application/views/admin/dataentry/import.php
@@ -0,0 +1,34 @@
<div class='header ui-widget-header'>
<?php echo $clang->gT("Import responses from a deactivated survey table"); ?>
</div>
<form id='importresponses' class='form30' method='post'>
<ul>
<li>
<label for='spansurveyid'><?php echo $clang->gT("Target survey ID:"); ?></label>
<span id='spansurveyid'><?php echo $surveyid; ?><input type='hidden' value='$surveyid' name='sid'></span>
</li>
<li>
<label for='oldtable'>
<?php echo $clang->gT("Source table:"); ?>
</label>
<select name='oldtable'>
<?php echo $optionElements; ?>
</select>
</li>
<li>
<label for='importtimings'>
<?php echo $clang->gT("Import also timings (if exist):"); ?>
</label>
<select name='importtimings' >
<option value='Y' selected='selected'><?php echo $clang->gT("Yes"); ?></option>
<option value='N'><?php echo $clang->gT("No"); ?></option>
</select>
</li>
</ul>
<p>
<input type='submit' value='<?php echo $clang->gT("Import Responses"); ?>' onclick='return confirm("<?php echo $clang->gT("Are you sure?","js"); ?>")'>&nbsp;
<input type='hidden' name='subaction' value='import'><br /><br />
<div class='messagebox ui-corner-all'><div class='warningheader'><?php echo $clang->gT("Warning").'</div>'.$clang->gT("You can import all old responses with the same amount of columns as in your active survey. YOU have to make sure, that this responses corresponds to the questions in your active survey."); ?></div>
</p>
</form>
<br />
5 changes: 5 additions & 0 deletions application/views/admin/dataentry/includes/editdata/edit.php
@@ -0,0 +1,5 @@
<input type='submit' value='<?php echo $clang->gT("Save"); ?>' />
<input type='hidden' name='id' value='<?php echo $id; ?>' />
<input type='hidden' name='sid' value='<?php echo $surveyid; ?>' />
<input type='hidden' name='subaction' value='update' />
<input type='hidden' name='language' value='<?php echo $sDataEntryLanguage; ?>' />
62 changes: 62 additions & 0 deletions application/views/admin/dataentry/includes/editdata/editdata.php
@@ -0,0 +1,62 @@
<script type='text/javascript'>
<!--
function saveshow(value)
{
if (document.getElementById(value).checked == true)
{
document.getElementById("closerecord").checked=false;
document.getElementById("closerecord").disabled=true;
document.getElementById("saveoptions").style.display="";
}
else
{
document.getElementById("saveoptions").style.display="none";
document.getElementById("closerecord").disabled=false;
}
}
//-->
</script>

<table>
<tr>
<td align='left'>
<input type='checkbox' class='checkboxbtn' name='closerecord' id='closerecord' />
<label for='closerecord'>".$clang->gT("Finalize response submission")."</label>
</td>
</tr>
<input type='hidden' name='closedate' value='<?php echo date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", Yii::app()->getConfig('timeadjust')); ?>' />
<tr>
<td align='left'>
<input type='checkbox' class='checkboxbtn' name='save' id='save' onclick='saveshow(this.id)' />
<label for='save'><?php echo $clang->gT("Save for further completion by survey user"); ?></label>
</td>
</tr>
</table>

<div name='saveoptions' id='saveoptions' style='display: none'>
<table align='center' class='outlinetable' cellspacing='0'>
<tr><td align='right'><?php echo $clang->gT("Identifier:"); ?></td>
<td>
<input type='text' name='save_identifier'"
<?php if (returnglobal('identifier')) { ?>
value="<?php echo stripslashes(stripslashes(returnglobal('identifier'))); ?>"
<?php } ?> />
</td>
</tr>
</table>
<input type='hidden' name='save_password' value='<?php echo returnglobal('accesscode'); ?>' />
<input type='hidden' name='save_confirmpassword' value='<?php echo returnglobal('accesscode'); ?>' />\n"
<input type='hidden' name='save_email' value='<?php echo $saver['email']; ?>' />\n"
<input type='hidden' name='save_scid' value='<?php echo $saver['scid']; ?>' />\n"
<input type='hidden' name='redo' value='yes' />\n";
</td>
</tr>
</div>
<tr>
<td align='center'>
<input type='submit' value='<?php echo $clang->gT("Submit"); ?>' />
<input type='hidden' name='sid' value='<?php echo $surveyid; ?>' />
<input type='hidden' name='subaction' value='insert' />
<input type='hidden' name='language' value='<?php echo $sDataEntryLanguage; ?>' />
</td>
</tr>
13 changes: 13 additions & 0 deletions application/views/admin/dataentry/includes/editdata/header.php
@@ -0,0 +1,13 @@
<div class='header ui-widget-header'><?php echo $clang->gT("Data entry"); ?></div>
<div class='header ui-widget-header'>
<?php
if ($subaction == "edit") {
echo sprintf($clang->gT("Editing response (ID %s)"), $id);
} else {
echo sprintf($clang->gT("Viewing response (ID %s)"), $id);
}
?>
</div>

<form method='post' action='<?php echo $this->createUrl('/admin/dataentry/sa/update'); ?>' name='editresponse' id='editresponse'>
<table id='responsedetail' width='99%' align='center' cellpadding='0' cellspacing='0'>
93 changes: 93 additions & 0 deletions application/views/admin/dataentry/insert.php
@@ -0,0 +1,93 @@
<div class='header ui-widget-header'><?php echo $clang->gT("Data entry"); ?></div>
<div class='messagebox ui-corner-all'>
<br />
<?php if(isset($save) && $errormsg): ?>
<?php echo $clang->gT("Try again"); ?>:
<form method='post'>
<table class='outlinetable' cellspacing='0' align='center'>
<tr>
<td align='right'><?php echo $clang->gT("Identifier:"); ?></td>
<td>
<input type='text' name='save_identifier' value='<?php echo $_POST['save_identifier']; ?>' />'
</td>
</tr>
<tr>
<td align='right'><?php echo $clang->gT("Password:"); ?></td>
<td>
<input type='password' name='save_password' value='<?php echo $_POST['save_password']; ?>' />
</td>
</tr>
<tr>
<td align='right'><?php echo $clang->gT("Confirm Password:"); ?></td>
<td>
<input type='password' name='save_confirmpassword' value='<?php echo $_POST['save_confirmpassword']; ?>' />
</td>
</tr>
<tr>
<td align='right'><?php echo $clang->gT("Email:"); ?></td>
<td>
<input type='text' name='save_email' value='<?php echo $_POST['save_email']; ?>' />
</td>
</tr>
<tr>
<td align='right'><?php echo $clang->gT("Start Language:"); ?></td>
<td>
<input type='text' name='save_language' value='<?php echo $_POST['save_language']; ?>' />
</td>
</tr>
<tr>
<td></td>
<td>
<input type='submit' value='<?php echo $clang->gT("Submit"); ?>' />
<input type='hidden' name='sid' value='<?php echo $surveyid; ?>' />
<input type='hidden' name='subaction' value='<?php echo $_POST['subaction']; ?>' />
<input type='hidden' name='language' value='<?php echo $lang; ?>' />
<input type='hidden' name='save' value='on' />
</td>
<?php
echo $hiddenfields;

if (isset($_POST['datestamp'])) {
echo CHtml::hiddenField('datestamp', $_POST['datestamp']);
}

if (isset($_POST['ipaddr']))
{
echo CHtml::hiddenField('ipaddr', $_POST['ipaddr']);
}
?>
</tr>
</table>
</form>
<?php endif; ?>

<?php

foreach($dataentrymsgs as $msg) {
echo $msg . "<br />\n";
}

?>

<?php if(isset($thisid)): ?>
<div class='successheader'><?php echo $clang->gT("Success"); ?></div>
<?php echo $clang->gT("The entry was assigned the following record id: ")."{$thisid}"; ?> <br /><br />
<?php endif; ?>

<?php echo $errormsg; ?>

<input type='submit' value='<?php echo $clang->gT("Add Another Record"); ?>' onclick="window.open('<?php echo Yii::app()->homeUrl.('/admin/dataentry/sa/view/surveyid/'.$surveyid.'/lang/'.$lang); ?>', '_top')" />
<br /><br />
<input type='submit' value='<?php echo $clang->gT("Return to survey administration"); ?>' onclick="window.open('<?php echo Yii::app()->homeUrl.('/admin/survey/view/'.$surveyid); ?>', '_top')" />
<br /><br />

<?php if(isset($thisid)): ?>
<input type='submit' value='<?php echo $clang->gT("View This Record"); ?>' onclick="window.open('<?php echo Yii::app()->homeUrl.('/admin/browse/sa/action/surveyid/'.$surveyid.'/id/'.$thisid); ?>', '_top')" />
<br /><br />
<?php endif; ?>

<?php if(isset($save)): ?>
<input type='submit' value='<?php echo $clang->gT("Browse Saved Responses"); ?>' onclick="window.open('<?php echo Yii::app()->homeUrl.('/admin/saved/sa/view/surveyid/'.$surveyid.'/all'); ?>', '_top')" />
<br /><br />
<?php endif; ?>
</div>
55 changes: 55 additions & 0 deletions application/views/admin/dataentry/vvimport.php
@@ -0,0 +1,55 @@
<?php
if ($tableExists) {
?>
<div class='header ui-widget-header'><?php echo $clang->gT("Import a VV survey file"); ?></div>
<form id='vvexport' enctype='multipart/form-data' method='post' action="<?php echo $this->createURL('admin/dataentry/sa/vvimport/surveyid/'.$surveyid); ?>">
<ul>
<li>
<label for='the_file'><?php echo $clang->gT("File:"); ?></label>
<input type='file' size=50 id='the_file' name='the_file' />
</li>
<li>
<label for='sid'><?php echo $clang->gT("Survey ID:"); ?></label>
<input type='text' size=10 id='sid' name='sid' value='<?php echo $surveyid; ?>' readonly='readonly' />
</li>
<li>
<label for='noid'><?php echo $clang->gT("Exclude record IDs?"); ?></label>
<input type='checkbox' id='noid' name='noid' value='noid' checked=checked onchange='form.insertmethod.disabled=this.checked;' />
</li>
<li>
<label for='insertmethod'><?php echo $clang->gT("When an imported record matches an existing record ID:"); ?></label>
<select id='insertmethod' name='insert' disabled='disabled'>
<option value='ignore' selected='selected'><?php echo $clang->gT("Report and skip the new record."); ?></option>
<option value='renumber'><?php echo $clang->gT("Renumber the new record."); ?></option>
<option value='replace'><?php echo $clang->gT("Replace the existing record."); ?></option>
</select>
</li>
<li>
<label for='finalized'><?php echo $clang->gT("Import as not finalized answers?"); ?></label>
<input type='checkbox' id='finalized' name='finalized' value='notfinalized' />
</li>
<li>
<label for='vvcharset'><?php echo $clang->gT("Character set of the file:"); ?></label>
<select id='vvcharset' name='vvcharset'>
<?php echo $charsetsout; ?>
</select>
</li>
</ul>
<p>
<input type='submit' value='<?php echo $clang->gT("Import"); ?>' />
<input type='hidden' name='action' value='vvimport' />
<input type='hidden' name='subaction' value='upload' />
</p>
</form>
<br />

<?php } else { ?>
<br />
<div class='messagebox'>
<div class='header'><?php echo $clang->gT("Import a VV response data file"); ?></div>
<div class='warningheader'><?php echo $clang->gT("Cannot import the VVExport file."); ?></div>
<?php echo $clang->gT("This survey is not active. You must activate the survey before attempting to import a VVexport file."); ?>
<br /> <br />
[<a href='<?php echo $this->createUrl('/admin/survey/view/'.$surveyid); ?>'><?php echo $clang->gT("Return to survey administration"); ?></a>]
</div>
<?php } ?>

0 comments on commit 475c605

Please sign in to comment.