Skip to content

Commit

Permalink
Fix/port URL parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronschmitz committed Aug 16, 2012
1 parent 3ea62e7 commit a86bce5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 104 deletions.
85 changes: 8 additions & 77 deletions application/controllers/admin/database.php
Expand Up @@ -35,14 +35,10 @@ function index($sa = null)

$action=Yii::app()->request->getPost('action');
$clang = $this->getController()->lang;
$postsid=returnGlobal('sid');
$postgid=returnGlobal('gid');
$postqid=returnGlobal('qid');
$postqaid=returnGlobal('qaid');
$databaseoutput = '';
$surveyid = returnGlobal('sid');
$gid = returnGlobal('gid');
$qid = returnGlobal('qid');
$surveyid = Yii::app()->request->getPost('sid');
$gid = Yii::app()->request->getPost('gid');
$qid = Yii::app()->request->getPost('qid');
// if $action is not passed, check post data.

if(Yii::app()->getConfig('filterxsshtml') && Yii::app()->session['USER_RIGHT_SUPERADMIN'] != 1)
Expand Down Expand Up @@ -113,7 +109,7 @@ function index($sa = null)
{
if (Yii::app()->request->getPost('defaultanswerscale_0_'.$language.'_0'))
{
$this->_updateDefaultValues($postqid,0,0,'',$language,Yii::app()->request->getPost('defaultanswerscale_0_'.$language.'_0'),true);
$this->_updateDefaultValues($qid,0,0,'',$language,Yii::app()->request->getPost('defaultanswerscale_0_'.$language.'_0'),true);
}
}
}
Expand Down Expand Up @@ -145,13 +141,6 @@ function index($sa = null)
$qproperties=$q->questionProperties();
$scalecount=$qproperties['answerscales'];

$count=0;
$invalidCode = 0;
$duplicateCode = 0;

//require_once("../classes/inputfilter/class.inputfilter_clean.php");
//$myFilter = new InputFilter('','',1,1,1);

//First delete all answers
Answers::model()->deleteAllByAttributes(array('qid'=>$qid));

Expand Down Expand Up @@ -210,9 +199,6 @@ function index($sa = null)

LimeExpressionManager::UpgradeConditionsToRelevance($surveyid);

if ($invalidCode == 1) $databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Answers with a code of 0 (zero) or blank code are not allowed, and will not be saved","js")."\")\n //-->\n</script>\n";
if ($duplicateCode == 1) $databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Duplicate codes found, these entries won't be updated","js")."\")\n //-->\n</script>\n";

Yii::app()->session['flashmessage']= $clang->gT("Answer options were successfully saved.");

if ($databaseoutput != '')
Expand All @@ -239,8 +225,7 @@ function index($sa = null)

$resrow = Questions::model()->with('question_types')->findByAttributes(array('qid'=>$qid));
$q = createQuestion($resrow->question_types['class']);
$qproperties=$q->questionProperties();
$scalecount=$qproperties['answerscales'];
$scalecount=$q->questionProperties('subquestions');

$clang = $this->getController()->lang;
// First delete any deleted ids
Expand Down Expand Up @@ -281,28 +266,7 @@ function index($sa = null)
$oldcodes[$postkey[2]][]=$postvalue;
}
}
$count=0;
$invalidCode = 0;
$duplicateCode = 0;
$dupanswers = array();
/*
for ($scale_id=0;$scale_id<$scalecount;$scale_id++)
{
// Find duplicate codes and add these to dupanswers array
$foundCat=array_count_values($codes);
foreach($foundCat as $key=>$value){
if($value>=2){
$dupanswers[]=$key;
}
}
}
*/
//require_once("../classes/inputfilter/class.inputfilter_clean.php");
//$myFilter = new InputFilter('','',1,1,1);


//$insertqids=array(); //?
$insertqid =array();
for ($scale_id=0;$scale_id<$scalecount;$scale_id++)
{
Expand All @@ -326,7 +290,7 @@ function index($sa = null)
{
if (!isset($insertqid[$scale_id][$position]))
{
$insertqid[$position]=Questions::model()->insertRecords(array('sid'=>$surveyid, 'gid'=>$gid, 'question_order'=>$position+1,'title'=>$codes[$scale_id][$position],'question'=>$subquestionvalue,'parent_qid'=>$qid,'language'=>$language,'scale_id'=>$scale_id));
$insertqid[$scale_id][$position]=Questions::model()->insertRecords(array('sid'=>$surveyid, 'gid'=>$gid, 'question_order'=>$position+1,'title'=>$codes[$scale_id][$position],'question'=>$subquestionvalue,'parent_qid'=>$qid,'language'=>$language,'scale_id'=>$scale_id));
}
else
{
Expand Down Expand Up @@ -474,7 +438,7 @@ function index($sa = null)
$oldqid = $qr1['qid'];
unset($qr1['qid']);
}
$qr1['gid'] = $postgid;
$qr1['gid'] = $gid;
$iInsertID = Questions::model()->insertRecords($qr1);
if (!isset($qr1['qid']))
{
Expand Down Expand Up @@ -779,39 +743,6 @@ function index($sa = null)
Questions::model()->deleteAllByAttributes(array('parent_qid' => $qid), 'scale_id >= :scale_id', array(':scale_id' => $iSubquestionScales));

Yii::app()->session['flashmessage'] = $clang->gT("Question was successfully saved.");
// }
// else
// {
//
// // There are conditions constraints: alert the user
// $errormsg="";
// if (!is_null($array_result['notAbove']))
// {
// $errormsg.=$clang->gT("This question relies on other question's answers and can't be moved above groupId:","js")
// . " " . $array_result['notAbove'][0][0] . " " . $clang->gT("in position","js")." ".$array_result['notAbove'][0][1]."\\n"
// . $clang->gT("See conditions:")."\\n";
//
// foreach ($array_result['notAbove'] as $notAboveCond)
// {
// $errormsg.="- cid:". $notAboveCond[3]."\\n";
// }
//
// }
// if (!is_null($array_result['notBelow']))
// {
// $errormsg.=$clang->gT("Some questions rely on this question's answers. You can't move this question below groupId:","js")
// . " " . $array_result['notBelow'][0][0] . " " . $clang->gT("in position","js")." ".$array_result['notBelow'][0][1]."\\n"
// . $clang->gT("See conditions:")."\\n";
//
// foreach ($array_result['notBelow'] as $notBelowCond)
// {
// $errormsg.="- cid:". $notBelowCond[3]."\\n";
// }
// }
//
// $databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"$errormsg\")\n //-->\n</script>\n";
// $gid= $oldgid; // group move impossible ==> keep display on oldgid
// }
}
else
{
Expand Down Expand Up @@ -895,7 +826,7 @@ function index($sa = null)
'surveyls_numberformat' => Yii::app()->request->getPost('numberformat_'.$langname)
);

Surveys_languagesettings::model()->updateByPk(array('surveyls_survey_id'=>$postsid, 'surveyls_language'=>$langname), $data);
Surveys_languagesettings::model()->updateByPk(array('surveyls_survey_id'=>$surveyid, 'surveyls_language'=>$langname), $data);
}
}
Yii::app()->session['flashmessage'] = $clang->gT("Survey text elements successfully saved.");
Expand Down
24 changes: 18 additions & 6 deletions application/controllers/admin/surveyadmin.php
Expand Up @@ -172,9 +172,21 @@ function editsurveysettings($iSurveyID)
$aData = array_merge($aData, $this->_tabPanelIntegration($esrow));
$aData = array_merge($aData, $this->_tabResourceManagement($iSurveyID));

$oResult = Questions::model()->getQuestionsWithSubQuestions($iSurveyID, $esrow['language'], "({{questions}}.type = 'T' OR {{questions}}.type = 'Q' OR {{questions}}.type = 'S')"); //AJS

$aData['questions'] = $oResult;
$oResult = Questions::model()->with('groups')->with('question_types')->with('parents')->findAllByAttributes(array('sid' => $iSurveyID, 'language' => $esrow['language']), array('index' => 'qid', 'order' => 'group_order, t.question_order'));
foreach ($oResult as $result)
{
$q = createQuestion(empty($result->question_types['class']) ? $oResult[$result['parent_qid']]->question_types['class'] : $result->question_types['class'] );
if ($q->questionProperties('subquestions') && $result['parent_qid'])
{
$questions[] = array('qid' => $result['parent_qid'], 'sqid' => $result['qid'], 'title' => $result->parents['title'], 'question' => $result->parents['question'], 'sqquestion' => $result['question']);
}
else if ($q->questionProperties('hasdefaultvalues') && !$q->questionProperties('subquestions'))
{
$questions[] = array('qid' => $result['qid'], 'title' => $result['title'], 'question' => $result['question']);
}
}

$aData['questions'] = $questions;
$aData['display']['menu_bars']['surveysummary'] = "editsurveysettings";
$aData['data'] = $aData;

Expand Down Expand Up @@ -1376,18 +1388,18 @@ function getUrlParamsJSON($iSurveyID)
Yii::app()->loadHelper('database');
$oResult = dbExecuteAssoc("select '' as act, up.*,q.title, sq.title as sqtitle, q.question, sq.question as sqquestion from {{survey_url_parameters}} up
left join {{questions}} q on q.qid=up.targetqid
left join {{questions}} sq on q.qid=up.targetqid
left join {{questions}} sq on sq.qid=up.targetsqid
where up.sid={$iSurveyID}");
$i = 0;

foreach ($oResult->readAll() as $oRow)
{
$aData->rows[$i]['id'] = $oRow['id'];
$oRow['title'] = $oRow['title'] . ': ' . ellipsize(flattenText($oRow['question'], false, true), 43, .70);
$oRow['title'] .= ': ' . ellipsize(flattenText($oRow['question'], false, true), 43, .70);

if ($oRow['sqquestion'] != '')
{
echo (' - ' . ellipsize(flattenText($oRow['sqquestion'], false, true), 30, .75));
$oRow['title'] .= (' - ' . ellipsize(flattenText($oRow['sqquestion'], false, true), 30, .75));
}
unset($oRow['sqquestion']);
unset($oRow['sqtitle']);
Expand Down
19 changes: 0 additions & 19 deletions application/models/Questions.php
Expand Up @@ -214,25 +214,6 @@ function getSubQuestions($parent_qid)
->query();
}

function getQuestionsWithSubQuestions($iSurveyID, $sLanguage, $sCondition = FALSE)
{
$command = Yii::app()->db->createCommand()
->select('{{questions}}.*, q.qid as sqid, q.title as sqtitle, q.question as sqquestion, ' . '{{groups}}.*')
->from($this->tableName())
->leftJoin('{{questions}} q', "q.parent_qid = {{questions}}.qid AND q.language = {{questions}}.language")
->join('{{groups}}', "{{groups}}.gid = {{questions}}.gid AND {{questions}}.language = {{groups}}.language");
$command->where("({{questions}}.sid = '$iSurveyID' AND {{questions}}.language = '$sLanguage' AND {{questions}}.parent_qid = 0)");
if ($sCondition != FALSE)
{
$command->where("({{questions}}.sid = :iSurveyID AND {{questions}}.language = :sLanguage AND {{questions}}.parent_qid = 0) AND {$sCondition}")
->bindParam(":iSurveyID", $iSurveyID, PDO::PARAM_STR)
->bindParam(":sLanguage", $sLanguage, PDO::PARAM_STR);
}
$command->order("{{groups}}.group_order asc, {{questions}}.question_order asc");

return $command->query()->readAll();
}

/**
* Insert an array into the questions table
* Returns false if insertion fails, otherwise the new QID
Expand Down
4 changes: 2 additions & 2 deletions application/views/admin/survey/editSurvey_view.php
Expand Up @@ -36,8 +36,8 @@
<li><label for='targetquestion'><?php $clang->eT('Target (sub-)question:'); ?></label><select name='targetquestion' id='targetquestion' size='1'>
<option value=''><?php $clang->eT('(No target question)'); ?></option>
<?php foreach ($questions as $question){?>
<option value='<?php echo $question['qid'].'-'.$question['sqid'];?>'><?php echo $question['title'].': '.ellipsize(flattenText($question['question'],true,true),43,.70);
if ($question['sqquestion']!='')
<option value='<?php echo $question['qid'].'-'.(isset($question['sqid'])?$question['sqid']:'');?>'><?php echo $question['title'].': '.ellipsize(flattenText($question['question'],true,true),43,.70);
if (isset($question['sqquestion']))
{
echo ' - '.ellipsize(flattenText($question['sqquestion'],true,true),30,.75);
}
Expand Down

0 comments on commit a86bce5

Please sign in to comment.