Skip to content

Commit

Permalink
Fixed issue #6983: part 2, when adding a new response
Browse files Browse the repository at this point in the history
Dev: some Yii function in dataentry
  • Loading branch information
Shnoulle committed Dec 1, 2012
1 parent 48a60f9 commit 1d13d81
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 171 deletions.
119 changes: 24 additions & 95 deletions application/controllers/admin/dataentry.php
Expand Up @@ -875,22 +875,13 @@ public function editdata($subaction, $id, $surveyid, $language='')
$fname=next($fnames);
}
$ansquery = "SELECT * FROM {{answers}} WHERE language = '{$sDataEntryLanguage}' AND qid=$thisqid ORDER BY sortorder, answer";
$ansresult = dbExecuteAssoc($ansquery);
$anscount = 0;
foreach ($ansresult->readAll() as $ansrow) //Now we're getting the codes and answers
{
$answers[] = array($ansrow['code'], $ansrow['answer']);
$anscount++;
}
//now find out how many existing values there are
$chosen[]=""; //create array
if (!isset($ranklist)) {$ranklist="";}

if (isset($currentvalues))
{
$existing = count($currentvalues);
}
else {$existing=0;}
$ansresult = Yii::app()->db->createCommand($ansquery)->query()->readAll(); //Checked
$anscount= count($ansresult);
$answers= array();
foreach ($ansresult as $ansrow)
{
$answers[] = $ansrow;
}
for ($i=1; $i<=$anscount; $i++)
{
$aDataentryoutput .= "\n<li class=\"select-item\">";
Expand All @@ -907,20 +898,20 @@ public function editdata($subaction, $id, $surveyid, $language='')
$aDataentryoutput .= "\t<option value=\"\" $selected>".$clang->gT('None')."</option>\n";
foreach ($answers as $ansrow)
{
(isset($currentvalues[$i-1]) && $currentvalues[$i-1]==$ansrow[0]) ? $selected=" selected=\"selected\"" : $selected="";
$aDataentryoutput .= "\t<option value=\"".$ansrow[0]."\" $selected>".$ansrow[1]."</option>\n";
(isset($currentvalues[$i-1]) && $currentvalues[$i-1]==$ansrow['code']) ? $selected=" selected=\"selected\"" : $selected="";
$aDataentryoutput .= "\t<option value=\"".$ansrow['code']."\" $selected>".flattenText($ansrow['answer'])."</option>\n";
}
$aDataentryoutput .= "</select\n";
$aDataentryoutput .="</li>";
}
$aDataentryoutput .= '</ul>';
$aDataentryoutput .= "<div style='display:none' id='ranking-{$thisqid}-maxans'>".$anscount."</div>"
$aDataentryoutput .= "<div style='display:none' id='ranking-{$thisqid}-maxans'>{$anscount}</div>"
. "<div style='display:none' id='ranking-{$thisqid}-minans'>0</div>"
. "<div style='display:none' id='ranking-{$thisqid}-name'>javatbd".$myfname."</div>";
. "<div style='display:none' id='ranking-{$thisqid}-name'>javatbd{$myfname}</div>";
$aDataentryoutput .="<div style=\"display:none\">";
foreach ($answers as $ansrow)
{
$aDataentryoutput.="<div id=\"htmlblock-{$thisqid}-{$ansrow[0]}\">".flattenText($ansrow[1])."</div>";
$aDataentryoutput.="<div id=\"htmlblock-{$thisqid}-{$ansrow['code']}\">{$ansrow['answer']}</div>";
}
$aDataentryoutput .="</div>";
$aDataentryoutput .= '</div>';
Expand All @@ -939,6 +930,9 @@ public function editdata($subaction, $id, $surveyid, $language='')
. "});\n"
." -->\n"
."</script>\n";

unset($answers);
$fname=prev($fnames);
break;

case "M": //Multiple choice checkbox
Expand Down Expand Up @@ -2164,82 +2158,17 @@ public function view($surveyid, $lang=NULL)

$cdata['thisqid'] = $thisqid;
$cdata['anscount'] = $anscount;

foreach ($ansresult as $ansrow)
{
$answers[] = array($ansrow['code'], $ansrow['answer']);
}
for ($i=1; $i<=$anscount; $i++)
{
if (isset($fname))
{
$myfname=$fname.$i;
}
if (isset($myfname) && Yii::app()->session[$myfname])
{
$existing++;
}
}
for ($i=1; $i<=$anscount; $i++)
{
if (isset($fname))
$ansresult = Yii::app()->db->createCommand($ansquery)->query()->readAll(); //Checked
$anscount= count($ansresult);
$answers= array();
foreach ($ansresult as $ansrow)
{
$myfname = $fname.$i;
$answers[] = $ansrow;
}
if (isset($myfname) && Yii::app()->session[$myfname])
{
foreach ($answers as $ans)
{
if ($ans[0] == Yii::app()->session[$myfname])
{
$thiscode=$ans[0];
$thistext=$ans[1];
}
}
}
if (!isset($ranklist)) {$ranklist="";}
$ranklist .= "&nbsp;<font color='#000080'>$i:&nbsp;<input class='ranklist' type='text' name='RANK$i' id='RANK_$thisqid$i'";
if (isset($myfname) && Yii::app()->session[$myfname])
{
$ranklist .= " value='";
$ranklist .= $thistext;
$ranklist .= "'";
}
$ranklist .= " onFocus=\"this.blur()\" />\n";
$ranklist .= "<input type='hidden' id='d$fieldname$i' name='$fieldname$i' value='";
$chosen[]=""; //create array
if (isset($myfname) && Yii::app()->session[$myfname])
{
$ranklist .= $thiscode;
$chosen[]=array($thiscode, $thistext);
}
$ranklist .= "' /></font>\n";
$ranklist .= "<img src='".Yii::app()->getConfig('imageurl')."/cut.gif' alt='".$blang->gT("Remove this item")."' title='".$blang->gT("Remove this item")."' ";
if (!isset($existing) || $i != $existing)
{
$ranklist .= "style='display:none'";
}
$mfn=$fieldname.$i;
$ranklist .= " id='cut_$thisqid$i' onclick=\"deletethis_$thisqid(document.addsurvey.RANK_$thisqid$i.value, document.addsurvey.d$fieldname$i.value, document.addsurvey.RANK_$thisqid$i.id, this.id)\" /><br />\n\n";
}
if (!isset($choicelist)) {$choicelist="";}
$choicelist .= "<select size='$anscount' class='choicelist' name='CHOICES' id='CHOICES_$thisqid' onclick=\"rankthis_$thisqid(this.options[this.selectedIndex].value, this.options[this.selectedIndex].text)\" >\n";
foreach ($answers as $ans)
{

if (!in_array($ans, $chosen))
{
$choicelist .= "\t<option value='{$ans[0]}'>{$ans[1]}</option>\n";
}
}
$choicelist .= "</select>\n";
$cdata['choicelist'] = $choicelist;
$cdata['ranklist'] = $ranklist;
if (isset($multifields))
$cdata['multifields'] = $multifields;

$choicelist="";
$ranklist="";
$cdata['answers']=$answers;
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . 'jquery/jquery.actual/jquery.actual.min.js');
$this->getController()->_js_admin_includes(Yii::app()->getConfig('generalscripts') . 'ranking.js');
$this->getController()->_css_admin_includes(Yii::app()->getConfig('publicstyleurl') . 'ranking.css');
unset($answers);
break;
case "M": //Multiple choice checkbox (Quite tricky really!)
Expand Down
121 changes: 45 additions & 76 deletions application/views/admin/dataentry/content_view.php
Expand Up @@ -140,86 +140,55 @@
<textarea cols='40' rows='5' name='<?php echo $fieldname; ?>comment'></textarea>
<?php break;
case "R": //RANKING TYPE QUESTION ?>

<script type='text/javascript'>
<!--
function rankthis_<?php echo $thisqid; ?>($code, $value)
<div id="question<?php echo $thisqid ?>" class="ranking-answers"><ul class="answers-list">
<?php for ($i=1; $i<=$anscount; $i++)
{
$index=document.addsurvey.CHOICES_<?php echo $thisqid; ?>.selectedIndex;
for (i=1; i<=<?php echo $anscount; ?>; i++)
{
$b=i;
$b += '';
$inputname="RANK_<?php echo $thisqid; ?>"+$b;
$hiddenname="d<?php echo $fieldname; ?>"+$b;
$cutname="cut_<?php echo $thisqid; ?>"+i;
document.getElementById($cutname).style.display='none';
if (!document.getElementById($inputname).value)
{
document.getElementById($inputname).value=$value;
document.getElementById($hiddenname).value=$code;
document.getElementById($cutname).style.display='';
for (var b=document.getElementById('CHOICES_<?php echo $thisqid; ?>').options.length-1; b>=0; b--)
{
if (document.getElementById('CHOICES_<?php echo $thisqid; ?>').options[b].value == $code)
{
document.getElementById('CHOICES_<?php echo $thisqid; ?>').options[b] = null;
}
}
i=$anscount;
}
?>
<li class="select-item">
<?php
if($i==1){
echo $blang->gT('First choice');
}else{
echo $blang->gT('Next choice');
}
if (document.getElementById('CHOICES_<?php echo $thisqid; ?>').options.length == 0)
?>
<select name="<?php echo $fieldname.$i ?>" id="answer<?php echo $fieldname.$i ?>">";
<option value=""><?php echo $blang->gT('None') ?></option>
<?php
foreach ($answers as $ansrow)
{
document.getElementById('CHOICES_<?php echo $thisqid; ?>').disabled=true;
}
document.addsurvey.CHOICES_<?php echo $thisqid; ?>.selectedIndex=-1;
}
function deletethis_<?php echo $thisqid; ?>($text, $value, $name, $thisname)
{
var qid='<?php echo $thisqid; ?>';
var lngth=qid.length+4;
var cutindex=$thisname.substring(lngth, $thisname.length);
cutindex=parseFloat(cutindex);
document.getElementById($name).value='';
document.getElementById($thisname).style.display='none';
if (cutindex > 1)
{
$cut1name="cut_<?php echo $thisqid; ?>"+(cutindex-1);
$cut2name="d<?php echo $fieldname; ?>"+(cutindex);
document.getElementById($cut1name).style.display='';
document.getElementById($cut2name).value='';
}
else
{
$cut2name="d<?php echo $fieldname; ?>"+(cutindex);
document.getElementById($cut2name).value='';
}
var i=document.getElementById('CHOICES_<?php echo $thisqid; ?>').options.length;
document.getElementById('CHOICES_<?php echo $thisqid; ?>').options[i] = new Option($text, $value);
if (document.getElementById('CHOICES_<?php echo $thisqid; ?>').options.length > 0)
{
document.getElementById('CHOICES_<?php echo $thisqid; ?>').disabled=false;
}
echo "\t<option value=\"".$ansrow['code']."\">".flattenText($ansrow['answer'])."</option>\n";
}
?>
</select>
</li>
<?php
}
//-->
?>
</ul>
<div style="display:none" id="ranking-<?php echo $thisqid ?>-maxans"><?php echo $anscount ?></div>
<div style="display:none" id="ranking-<?php echo $thisqid ?>-minans">0</div>
<div style="display:none" id="ranking-<?php echo $thisqid ?>-name">javatbd<?php echo $fieldname ?></div>
<div style="display:none">
<?php foreach ($answers as $ansrow)
{
echo "<div id=\"htmlblock-{$thisqid}-{$ansrow['code']}\">{$ansrow['answer']}</div>";
}
?>
</div>
<script type='text/javascript'>
<!--
var aRankingTranslations = {
choicetitle: '<?php echo $clang->gT("Your Choices",'js') ?>',
ranktitle: '<?php echo $clang->gT("Your Ranking",'js') ?>'
};
function checkconditions(){};
$(function() {
doDragDropRank(<?php echo $thisqid ?>,0,true,true);
});
-->
</script>
<table>
<tr>
<td align='left' valign='top' width='200'>
<strong>
<?php echo $blang->gT("Your choices"); ?>:</strong><br />
<?php echo $choicelist; ?>
</td>
<td align='left'>
<strong>
<?php echo $blang->gT("Your ranking"); ?>:</strong><br />
<?php echo $ranklist; ?>
</td>
</tr>
</table>
<input type='hidden' name='multi' value='<?php echo $anscount; ?>' />
<input type='hidden' name='lastfield' value='<?php if (isset($multifields)) {echo $multifields;} ?>' />
</div>
<?php
break;
case "M": //Multiple choice checkbox (Quite tricky really!)
Expand Down Expand Up @@ -733,4 +702,4 @@ function updateJSON<?php echo $fieldname; ?>() {
} ?>
</td>
</tr>
<tr class='data-entry-separator'><td colspan='3'></td></tr>
<tr class='data-entry-separator'><td colspan='3'></td></tr>

0 comments on commit 1d13d81

Please sign in to comment.