Skip to content

Commit

Permalink
Fixed issue #12476: Quicktranslation tabs not working
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Jun 20, 2017
1 parent 3920788 commit 8f6d874
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 185 deletions.
272 changes: 134 additions & 138 deletions application/controllers/admin/translate.php
Expand Up @@ -138,116 +138,107 @@ private function _translateSave($iSurveyID, $tolang, $baselang, $tab_names)
*/
private function _displayUntranslatedFields($iSurveyID, $tolang, $baselang, $tab_names, $baselangdesc, $tolangdesc)
{
// Define aData
$aData['surveyid'] = $iSurveyID;
$aData['tab_names'] = $tab_names;
$aData['tolang'] = $tolang;
$aData['baselang'] = $baselang;
$aData['baselangdesc'] = $baselangdesc;
$aData['tolangdesc'] = $tolangdesc;

foreach( $tab_names as $type )
{
$aData['amTypeOptions'][] = $this->setupTranslateFields($type);
}

//This is for the tab navbar
$aData['amTypeOptions'] = array_map(array($this,'setupTranslateFields'),$tab_names);
$aViewUrls['translateformheader_view'][] = $aData;

//Set the output as empty
$aViewUrls['output'] = '';
// Define content of each tab
$count = 0;
foreach( $tab_names as $type )

//iterate through all tabs
$allTabNames = count($tab_names);
for($i=0;$i<$allTabNames;$i++ )
{
$type= $tab_names[$i];
$amTypeOptions = $this->setupTranslateFields($type);
$type2 = $amTypeOptions["associated"];
// Setup form
$evenRow = FALSE; //deprecated => using css

$all_fields_empty = TRUE;

$resultbase = $this->query($type, "querybase", $iSurveyID, $tolang, $baselang);
$resultto = $this->query($type, "queryto", $iSurveyID, $tolang, $baselang);

$type2 = $amTypeOptions["associated"];
$associated = FALSE;
if ( ! empty($type2) )
{
$associated = TRUE;
//get type otions again again
$amTypeOptions2 = $this->setupTranslateFields($type2);
$resultbase2 = $this->query($type, "querybase", $iSurveyID, $tolang, $baselang);
$resultto2 = $this->query($type, "queryto", $iSurveyID, $tolang, $baselang);
}
// Setup form
// start a counter in order to number the input fields for each record
$i = 0;
$evenRow = FALSE;
$all_fields_empty = TRUE;

$resultbase = $this->query($type, "querybase", $iSurveyID, $tolang, $baselang);
$resultto = $this->query($type, "queryto", $iSurveyID, $tolang, $baselang);
$aData['baselangdesc'] = $baselangdesc;
$aData['tolangdesc'] = $tolangdesc;
$aData['type'] = $type;

if($count<1)
{
$aData['activeTab']=true;
$count++;
}
else
{
$aData['activeTab']=false;
}

$aData['activeTab']=($i<1);
$aData['translateTabs'] = $this->displayTranslateFieldsHeader($baselangdesc, $tolangdesc, $type);
$aViewUrls['output'] .= $this->getController()->renderPartial("/admin/translate/translatetabs_view", $aData, true);
foreach ( $resultbase as $rowfrom )

for($j=0;$j<count($resultbase);$j++)
{
$rowfrom = $resultbase[$j];
$textfrom = htmlspecialchars_decode($rowfrom[$amTypeOptions["dbColumn"]]);
$textto = $resultto[$i][$amTypeOptions["dbColumn"]];

$textto = $resultto[$j][$amTypeOptions["dbColumn"]];
if ( $associated )
{
$textfrom2 = htmlspecialchars_decode($resultbase2[$i][$amTypeOptions2["dbColumn"]]);
$textto2 = $resultto2[$i][$amTypeOptions2["dbColumn"]];
$textfrom2 = htmlspecialchars_decode($resultbase2[$j][$amTypeOptions2["dbColumn"]]);
$textto2 = $resultto2[$j][$amTypeOptions2["dbColumn"]];
}

$gid = ( $amTypeOptions["gid"] == TRUE ) ? $gid = $rowfrom['gid'] : NULL;
$qid = ( $amTypeOptions["qid"] == TRUE ) ? $qid = $rowfrom['qid'] : NULL;

$textform_length = strlen(trim($textfrom));
if ( $textform_length > 0 )
{
$all_fields_empty = FALSE;
}

$aData['textfrom'] = $textfrom;
$aData['textfrom2'] = $textfrom2;
$aData['textto'] = $textto;
$aData['textto2'] = $textto2;
$aData['rowfrom'] = $rowfrom;
$aData['rowfrom2'] = $resultbase2;
$aData['evenRow'] = $evenRow;
$aData['gid'] = $gid;
$aData['qid'] = $qid;
$aData['amTypeOptions'] = $amTypeOptions;
$aData['amTypeOptions2'] = $amTypeOptions2;
$aData['i'] = $i;
$aData['type'] = $type;
$aData['type2'] = $type2;
$aData['associated'] = $associated;

$evenRow = !($evenRow);
$all_fields_empty = !( $textform_length > 0 );

$aData = $aData + array(
'textfrom' => $this->_cleanup($textfrom, array()),
'textfrom2' => $this->_cleanup($textfrom2, array()),
'textto' => $this->_cleanup($textto, array()),
'textto2' => $this->_cleanup($textto2, array()),
'rowfrom' => $rowfrom,
'rowfrom2' => $resultbase2,
'evenRow' => $evenRow,
'gid' => $gid,
'qid' => $qid,
'amTypeOptions' => $amTypeOptions,
'amTypeOptions2' => $amTypeOptions2,
'i' => $j,
'type' => $type,
'type2' => $type2,
'associated' => $associated,
);
$aData['translateFields'] = $this->displayTranslateFields($iSurveyID, $gid, $qid, $type,
$amTypeOptions, $baselangdesc, $tolangdesc, $textfrom, $textto, $i, $rowfrom, $evenRow);
$amTypeOptions, $baselangdesc, $tolangdesc, $textfrom, $textto, $j, $rowfrom, $evenRow);
if ($associated && strlen(trim((string)$textfrom2)) > 0)
{
$evenRow = !($evenRow);
$aData['translateFields'] .= $this->displayTranslateFields($iSurveyID, $gid, $qid, $type2,
$amTypeOptions2, $baselangdesc, $tolangdesc, $textfrom2, $textto2, $i, $resultbase2[$i], $evenRow);
$amTypeOptions2, $baselangdesc, $tolangdesc, $textfrom2, $textto2, $j, $resultbase2[$j], $evenRow);
}

$aViewUrls['output'] .= $this->getController()->renderPartial("/admin/translate/translatefields_view", $aData, true);

$i++;
} // end while

$aData['all_fields_empty'] = $all_fields_empty;
$aData['translateFieldsFooter'] = $this->displayTranslateFieldsFooter();
$aData['bReadOnly']=!Permission::model()->hasSurveyPermission($iSurveyID, 'translations', 'update');
$aViewUrls['output'] .= $this->getController()->renderPartial("/admin/translate/translatefieldsfooter_view", $aData, true);
} // end foreach

// Submit buttonrender
$aViewUrls['translatefooter_view'][] = $aData;

// var_dump($aViewUrls);
return $aViewUrls;
}

Expand Down Expand Up @@ -410,6 +401,12 @@ private function _getLanguageList($iSurveyID, $tolang)
return $language_list;
}

private function _cleanup($string, $options=array()){
$oTidy = new tidy;
$cleansedString = $oTidy->repairString($string);
return $cleansedString;
}

/**
* setupTranslateFields() creates a customised array with database query
* information for use by survey translation
Expand Down Expand Up @@ -827,21 +824,21 @@ private function displayTranslateFieldsHeader($baselangdesc, $tolangdesc, $type)
{

$translateoutput = "";
$translateoutput .= CHtml::openTag('table', array('class'=>'translate'));
if ($type=='question' || $type=='subquestion' || $type=='question_help' || $type=='answer')
{
$translateoutput.='<colgroup width="8%" />';
}
$translateoutput .= '<colgroup width="37" />';
$translateoutput .= '<colgroup width="55%" />';
$translateoutput .= CHtml::openTag('tr');
if ($type=='question' || $type=='subquestion' || $type=='question_help' || $type=='answer')
{
$translateoutput .= CHtml::tag('th', array(), CHtml::tag('b', array(), gT('Question code / ID')));
}
$translateoutput .= CHtml::tag('th', array(), CHtml::tag('b', array(), $baselangdesc));
$translateoutput .= CHtml::tag('th', array(), CHtml::tag('b', array(), $tolangdesc));
$translateoutput .= CHtml::closeTag("tr");
$translateoutput .= CHtml::openTag('div', array('class'=>'container-fluid'));
// if ($type=='question' || $type=='subquestion' || $type=='question_help' || $type=='answer')
// {
// $translateoutput.='<colgroup width="8%" />';
// }
//$translateoutput .= '<colgroup width="37" />';
//$translateoutput .= '<colgroup width="55%" />';
$translateoutput .= CHtml::openTag('div', array('class' => 'row'));
if ($type=='question' || $type=='subquestion' || $type=='question_help' || $type=='answer')
{
$translateoutput .= CHtml::tag('div', array('class'=>'col-md-2'), CHtml::tag('b', array(), gT('Question code / ID')));
}
$translateoutput .= CHtml::tag('div', array('class'=>'col-sm-5'), CHtml::tag('b', array(), $baselangdesc));
$translateoutput .= CHtml::tag('div', array('class'=>'col-sm-5'), CHtml::tag('b', array(), $tolangdesc));
$translateoutput .= CHtml::closeTag("div");

return $translateoutput;
}
Expand All @@ -866,67 +863,64 @@ private function displayTranslateFields($iSurveyID, $gid, $qid, $type, $amTypeOp
$baselangdesc, $tolangdesc, $textfrom, $textto, $i, $rowfrom, $evenRow)
{
$translateoutput = "";
$translateoutput .= CHtml::openTag('tr', array('class' => ( $evenRow ) ? 'odd' : 'even'));

$value1 = ( ! empty($amTypeOptions["id1"]) ) ? $rowfrom[$amTypeOptions["id1"]] : "";
$value2 = ( ! empty($amTypeOptions["id2"]) ) ? $rowfrom[$amTypeOptions["id2"]] : "";
$iScaleID = ( ! empty($amTypeOptions["scaleid"]) ) ? $rowfrom[$amTypeOptions["scaleid"]] : "";

// Display text in original language
// Display text in foreign language. Save a copy in type_oldvalue_i to identify changes before db update
if ($type=='answer')
{
//print_r($rowfrom->attributes);die();
$translateoutput .= "<td>".htmlspecialchars($rowfrom->questions->title)." ({$rowfrom->questions->qid})</td>\n";
}
if ($type=='question_help' || $type=='question')
{
//print_r($rowfrom->attributes);die();
$translateoutput .= "<td>".htmlspecialchars($rowfrom->title)." ({$rowfrom->qid})</td>\n";
}
else if ($type=='subquestion')
{
//print_r($rowfrom->attributes);die();
$translateoutput .= "<td>".htmlspecialchars($rowfrom->parents->title)." ({$rowfrom->parents->qid})</td>\n";
}

$translateoutput .= CHtml::tag(
'td',
array(
'class' => '_from_',
'id' => "${type}_from_${i}"
),
showJavaScript($textfrom)
);
$translateoutput .= CHtml::openTag('td');
$translateoutput .= CHtml::hiddenField("{$type}_id1_{$i}", $value1);
$translateoutput .= CHtml::hiddenField("{$type}_id2_{$i}", $value2);
if (is_numeric($iScaleID)) $translateoutput .= CHtml::hiddenField("{$type}_scaleid_{$i}", $iScaleID);

$nrows = max($this->calc_nrows($textfrom), $this->calc_nrows($textto));

$translateoutput .= CHtml::hiddenField("{$type}_oldvalue_{$i}", $textto);
$translateoutput .= CHtml::textArea("{$type}_newvalue_{$i}", $textto,
array(
'class' => 'col-sm-10',
'cols' => '75',
'rows' => $nrows,
)
);

$htmleditor_data = array(
"edit" . $type ,
$type . "_newvalue_" . $i,
htmlspecialchars($textto),
$iSurveyID,
$gid,
$qid,
"translate" . $amTypeOptions["HTMLeditorType"]
);
$translateoutput .= $this->_loadEditor($amTypeOptions, $htmleditor_data);

$translateoutput .= CHtml::closeTag("td");
$translateoutput .= CHtml::closeTag("tr");
$translateoutput .= CHtml::openTag('div', array('class'=>'row'));
$value1 = ( ! empty($amTypeOptions["id1"]) ) ? $rowfrom[$amTypeOptions["id1"]] : "";
$value2 = ( ! empty($amTypeOptions["id2"]) ) ? $rowfrom[$amTypeOptions["id2"]] : "";
$iScaleID = ( ! empty($amTypeOptions["scaleid"]) ) ? $rowfrom[$amTypeOptions["scaleid"]] : "";
// Display text in original language
// Display text in foreign language. Save a copy in type_oldvalue_i to identify changes before db update
if ($type=='answer')
{
//print_r($rowfrom->attributes);die();
$translateoutput .= CHtml::tag("div",array("class"=>'col-sm-2'), htmlspecialchars($rowfrom->questions->title)." (".$rowfrom->questions->qid.")");
}
if ($type=='question_help' || $type=='question')
{
//print_r($rowfrom->attributes);die();
$translateoutput .= CHtml::tag("div",array("class"=>'col-sm-2'),htmlspecialchars($rowfrom->title)." ({$rowfrom->qid})");
}
else if ($type=='subquestion')
{
//print_r($rowfrom->attributes);die();
$translateoutput .= CHtml::tag("div",array("class"=>'col-sm-2'),htmlspecialchars($rowfrom->parents->title)." ({$rowfrom->parents->qid})");
}

$translateoutput .= CHtml::tag(
'div',
array(
'class' => '_from_ col-sm-5',
'id' => "${type}_from_${i}"
),
showJavaScript($textfrom)
);

$translateoutput .= CHtml::openTag('div', array('class'=>'col-sm-5'));

$translateoutput .= CHtml::hiddenField("{$type}_id1_{$i}", $value1);
$translateoutput .= CHtml::hiddenField("{$type}_id2_{$i}", $value2);
if (is_numeric($iScaleID)) $translateoutput .= CHtml::hiddenField("{$type}_scaleid_{$i}", $iScaleID);
$nrows = max($this->calc_nrows($textfrom), $this->calc_nrows($textto));
$translateoutput .= CHtml::hiddenField("{$type}_oldvalue_{$i}", $textto);
$translateoutput .= CHtml::textArea("{$type}_newvalue_{$i}", $textto,
array(
'class' => 'col-sm-10',
'cols' => '75',
'rows' => $nrows,
)
);
$htmleditor_data = array(
"edit" . $type ,
$type . "_newvalue_" . $i,
htmlspecialchars($textto),
$iSurveyID,
$gid,
$qid,
"translate" . $amTypeOptions["HTMLeditorType"]
);
$translateoutput .= $this->_loadEditor($amTypeOptions, $htmleditor_data);

$translateoutput .= CHtml::closeTag("div");
$translateoutput .= CHtml::closeTag("div");

return $translateoutput;
}
Expand Down Expand Up @@ -978,7 +972,9 @@ private function calc_nrows( $subject )
*/
private function displayTranslateFieldsFooter()
{
$translateoutput = CHtml::closeTag("table");
$translateoutput = CHtml::closeTag("div");
$translateoutput = CHtml::closeTag("div");
$translateoutput = CHtml::closeTag("div");

return $translateoutput;
}
Expand Down
17 changes: 5 additions & 12 deletions application/views/admin/translate/translatefields_view.php
@@ -1,13 +1,6 @@
<?php
if (strlen(trim((string)$textfrom)) > 0)
{
// Display translation fields
echo $translateFields;
}
else
{
?>
<?php if (strlen(trim((string)$textfrom)) > 0) : ?>
<?=tidy_repair_string($translateFields)?>
<?php else: ?>
<input type='hidden' name='<?php echo $type; ?>_newvalue[<?php echo $i; ?>]' value='<?php echo $textto; ?>' />
<?php
}
?>
<?php endif;?>
<?php // Display translation fields ?>
18 changes: 9 additions & 9 deletions application/views/admin/translate/translatefieldsfooter_view.php
@@ -1,10 +1,10 @@
<?php echo $translateFieldsFooter; ?>
</div>
<?php if ($all_fields_empty) { ?>
<p><?php eT("Nothing to translate on this page");?></p><br />
<?php } ?>
<input type='hidden' name='<?php echo $type;?>_size' value='<?php echo $i ?>' />
<?php if ($associated) { ?>
<input type='hidden' name='<?php echo $type2;?>_size' value='<?php echo $i;?>' />
<?php } ?>
<?php echo $translateFieldsFooter; ?>
</div>
<?php if ($all_fields_empty): ?>
<p><?php eT("Nothing to translate on this page");?></p><br />
<?php endif;?>
<input type='hidden' name='<?php echo $type;?>_size' value='<?php echo $i ?>' />
<?php if ($associated) :?>
<input type='hidden' name='<?php echo $type2;?>_size' value='<?php echo $i;?>' />
<?php endif;?>
</div>

0 comments on commit 8f6d874

Please sign in to comment.