diff --git a/application/controllers/admin/conditionsaction.php b/application/controllers/admin/conditionsaction.php index 15942152875..34d6232ce39 100644 --- a/application/controllers/admin/conditionsaction.php +++ b/application/controllers/admin/conditionsaction.php @@ -22,9 +22,9 @@ */ class conditionsaction extends Survey_Common_Action { - function index($subaction, $surveyid=null, $gid=null, $qid=null) + function index($subaction, $iSurveyID=null, $gid=null, $qid=null) { - $surveyid = sanitize_int($surveyid); + $iSurveyID = sanitize_int($iSurveyID); $gid = sanitize_int($gid); $qid = sanitize_int($qid); @@ -35,7 +35,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) if( !empty($_POST['subaction']) ) $subaction=Yii::app()->request->getPost('subaction'); //BEGIN Sanitizing POSTed data - if ( !isset($surveyid) ) { $surveyid = returnGlobal('sid'); } + if ( !isset($iSurveyID) ) { $iSurveyID = returnGlobal('sid'); } if ( !isset($qid) ) { $qid = returnGlobal('qid'); } if ( !isset($gid) ) { $gid = returnGlobal('gid'); } if ( !isset($p_scenario)) {$p_scenario=returnGlobal('scenario');} @@ -120,7 +120,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $br = CHtml::openTag('br /'); //MAKE SURE THAT THERE IS A SID - if (!isset($surveyid) || !$surveyid) + if (!isset($iSurveyID) || !$iSurveyID) { $conditionsoutput = $clang->gT("You have not selected a survey").str_repeat($br, 2); $conditionsoutput .= CHtml::submitButton($clang->gT("Main admin screen"), array( @@ -130,37 +130,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) return; } - // MAKE SURE THAT THERE IS A QID - if ( !isset($qid) || !$qid ) - { - $conditionsoutput = $clang->gT("You have not selected a question").str_repeat($br, 2); - $conditionsoutput .= CHtml::submitButton($clang->gT("Main admin screen"), array( - 'onclick' => "window.open('".$this->getController()->createUrl("admin/")."', '_top')" - )).$br; - safeDie($conditionsoutput); - return; - } - - // If we made it this far, then lets develop the menu items - // add the conditions container table - - $extraGetParams = ""; - if (isset($qid) && isset($gid)) - { - $extraGetParams = "/gid/{$gid}/qid/{$qid}"; - } - - $conditionsoutput_action_error = ""; // defined during the actions - - $markcidarray = Array(); - if ( isset($_GET['markcid']) ) - { - $markcidarray = explode("-", $_GET['markcid']); - } - - //BEGIN PROCESS ACTIONS - // ADD NEW ENTRY IF THIS IS AN ADD if (isset($p_subaction) && $p_subaction == "resetsurveylogic") { @@ -174,16 +144,16 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) if (!isset($_GET['ok'])) { - $this->getController()->_getAdminHeader(); $button_yes = CHtml::submitButton($clang->gT("Yes"), array( - 'onclick' => "window.open('".$this->getController()->createUrl("admin/survey/resetsurveylogic/surveyid/$surveyid")."?ok=Y"."', '_top')" + 'onclick' => "window.open('".$this->getController()->createUrl("admin/conditions/index/subaction/resetsurveylogic/surveyid/$iSurveyID")."?ok=Y"."', '_top')" )); $button_cancel = CHtml::submitButton($clang->gT("Cancel"), array( - 'onclick' => "window.open('".$this->getController()->createUrl("admin/survey/view/surveyid/$surveyid")."', '_top')" + 'onclick' => "window.open('".$this->getController()->createUrl("admin/survey/view/surveyid/$iSurveyID")."', '_top')" )); - $messagebox_content = $clang->gT("You are about to delete all conditions on this survey's questions")."($surveyid)" + $messagebox_content = $clang->gT("You are about to delete all conditions on this survey's questions")."($iSurveyID)" . $br . $clang->gT("We recommend that before you proceed, you export the entire survey from the main administration screen.") + . $br . $clang->gT("Continue?") . $br . $button_yes . $button_cancel; $this->_renderWrappedTemplate('conditions', array('message' => array( @@ -194,22 +164,48 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) } else { - LimeExpressionManager::RevertUpgradeConditionsToRelevance($surveyid); - Conditions::model()->deleteRecords('qid in (select qid from {{questions}} where sid=$surveyid)'); - - $resetsurveylogicoutput .= CHtml::openTag('tr'); - $resetsurveylogicoutput .= CHtml::openTag('tr', array('align'=>'center')).$br; - $resetsurveylogicoutput .= CHtml::openTag('strong'); - $resetsurveylogicoutput .= $clang->gT("All conditions in this survey have been deleted.").str_repeat($br, 2); - $resetsurveylogicoutput .= submitButton($clang->gT("Continue"), array( - 'onclick' => "window.open('".$this->getController()->createUrl('/admin/survey/view/surveyid/'.$surveyid)."', '_top')" - )); - $resetsurveylogicoutput .= CHtml::closeTag('strong').CHtml::closeTag('td'); - $resetsurveylogicoutput .= CHtml::closeTag('tr'); - $aData['conditionsoutput'] = $resetsurveylogicoutput; + LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID); + Conditions::model()->deleteRecords("qid in (select qid from {{questions}} where sid={$iSurveyID})"); + Yii::app()->session['flashmessage']=$clang->gT("All conditions in this survey have been deleted."); + $this->getController()->redirect($this->getController()->createUrl('/admin/survey/view/surveyid/'.$iSurveyID)); + } } + + + // MAKE SURE THAT THERE IS A QID + if ( !isset($qid) || !$qid ) + { + $conditionsoutput = $clang->gT("You have not selected a question").str_repeat($br, 2); + $conditionsoutput .= CHtml::submitButton($clang->gT("Main admin screen"), array( + 'onclick' => "window.open('".$this->getController()->createUrl("admin/")."', '_top')" + )).$br; + safeDie($conditionsoutput); + return; + } + + + // If we made it this far, then lets develop the menu items + // add the conditions container table + + $extraGetParams = ""; + if (isset($qid) && isset($gid)) + { + $extraGetParams = "/gid/{$gid}/qid/{$qid}"; + } + + $conditionsoutput_action_error = ""; // defined during the actions + + $markcidarray = Array(); + if ( isset($_GET['markcid']) ) + { + $markcidarray = explode("-", $_GET['markcid']); + } + + //BEGIN PROCESS ACTIONS + // ADD NEW ENTRY IF THIS IS AN ADD + if (isset($p_subaction) && $p_subaction == "insertcondition") { if (( !isset($p_canswers) && @@ -511,7 +507,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) ); } } - LimeExpressionManager::UpgradeConditionsToRelevance($surveyid); // do for whole survey, since don't know which questions affected. + LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID); // do for whole survey, since don't know which questions affected. } //END PROCESS ACTIONS @@ -521,10 +517,10 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) //BEGIN: GATHER INFORMATION // 1: Get information for this question if (!isset($qid)) { $qid = returnGlobal('qid'); } - if (!isset($surveyid)) { $surveyid = returnGlobal('sid'); } - $thissurvey = getSurveyInfo($surveyid); + if (!isset($iSurveyID)) { $iSurveyID = returnGlobal('sid'); } + $thissurvey = getSurveyInfo($iSurveyID); - $qresult = Questions::model()->with('groups')->findByAttributes(array('qid' => $qid, 'parent_qid' => 0, 'language' => Survey::model()->findByPk($surveyid)->language)); + $qresult = Questions::model()->with('groups')->findByAttributes(array('qid' => $qid, 'parent_qid' => 0, 'language' => Survey::model()->findByPk($iSurveyID)->language)); $questiongroupname = $qresult->groups->group_name; $questiontitle = $qresult['title']; $questiontext = $qresult['question']; @@ -538,9 +534,9 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $qresult = Questions::model()->with(array( 'groups' => array( 'condition' => 'groups.language = :lang', - 'params' => array(':lang' => Survey::model()->findByPk($surveyid)->language), + 'params' => array(':lang' => Survey::model()->findByPk($iSurveyID)->language), ), - ))->findAllByAttributes(array('parent_qid' => 0, 'sid' => $surveyid, 'language' => Survey::model()->findByPk($surveyid)->language)); + ))->findAllByAttributes(array('parent_qid' => 0, 'sid' => $iSurveyID, 'language' => Survey::model()->findByPk($iSurveyID)->language)); $qrows = array(); foreach ($qresult as $k => $v) $qrows[$k] = array_merge($v->attributes, $v->groups->attributes); @@ -590,9 +586,9 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $result = Questions::model()->with(array( 'groups' => array( 'condition' => 'groups.language = :lang', - 'params' => array(':lang' => Survey::model()->findByPk($surveyid)->language), + 'params' => array(':lang' => Survey::model()->findByPk($iSurveyID)->language), ), - ))->findAllByAttributes(array('qid' => $ql, 'parent_qid' => 0, 'sid' => $surveyid, 'language' => Survey::model()->findByPk($surveyid)->language)); + ))->findAllByAttributes(array('qid' => $ql, 'parent_qid' => 0, 'sid' => $iSurveyID, 'language' => Survey::model()->findByPk($iSurveyID)->language)); $thiscount = count($result); @@ -620,9 +616,9 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $result = Questions::model()->with(array( 'groups' => array( 'condition' => 'groups.language = :lang', - 'params' => array(':lang' => Survey::model()->findByPk($surveyid)->language), + 'params' => array(':lang' => Survey::model()->findByPk($iSurveyID)->language), ), - ))->findAllByAttributes(array('qid' => $pq, 'parent_qid' => 0, 'sid' => $surveyid, 'language' => Survey::model()->findByPk($surveyid)->language)); + ))->findAllByAttributes(array('qid' => $pq, 'parent_qid' => 0, 'sid' => $iSurveyID, 'language' => Survey::model()->findByPk($iSurveyID)->language)); $postcount = count($result); @@ -671,7 +667,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $rows['type'] == "H" ) { - $aresult = Questions::model()->findAllByAttributes(array('parent_qid'=>$rows['qid'], 'language' => Survey::model()->findByPk($surveyid)->language), array('order' => 'question_order ASC')); + $aresult = Questions::model()->findAllByAttributes(array('parent_qid'=>$rows['qid'], 'language' => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'question_order ASC')); foreach ($aresult as $arows) { @@ -710,7 +706,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $fresult = Answers::model()->findAllByAttributes(array( 'qid' => $rows['qid'], - "language" => Survey::model()->findByPk($surveyid)->language, + "language" => Survey::model()->findByPk($iSurveyID)->language, 'scale_id' => 0, ), array('order' => 'sortorder, code')); @@ -759,13 +755,13 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $fquery = "SELECT sq.*, q.other" ." FROM {{questions sq}}, {{questions q}}" - ." WHERE sq.sid=$surveyid AND sq.parent_qid=q.qid " + ." WHERE sq.sid=$iSurveyID AND sq.parent_qid=q.qid " . "AND q.language=:lang" ." AND sq.language=:lang" ." AND q.qid=:qid AND sq.scale_id=0 ORDER BY sq.question_order"; - $sLanguage=Survey::model()->findByPk($surveyid)->language; + $sLanguage=Survey::model()->findByPk($iSurveyID)->language; $y_axis_db = Yii::app()->db->createCommand($fquery) ->bindParam(":lang", $sLanguage, PDO::PARAM_STR) ->bindParam(":qid", $rows['qid'], PDO::PARAM_INT) @@ -774,7 +770,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) // Get the X-Axis $aquery = "SELECT sq.* FROM {{questions q}}, {{questions sq}} - WHERE q.sid=$surveyid + WHERE q.sid=$iSurveyID AND sq.parent_qid=q.qid AND q.language=:lang AND sq.language=:lang @@ -812,7 +808,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) } //if A,B,C,E,F,H elseif ($rows['type'] == "1") //Multi Scale { - $aresult = Questions::model()->findAllByAttributes(array('parent_qid' => $rows['qid'], 'language' => Survey::model()->findByPk($surveyid)->language), array('order' => 'question_order desc')); + $aresult = Questions::model()->findAllByAttributes(array('parent_qid' => $rows['qid'], 'language' => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'question_order desc')); foreach ($aresult as $arows) { @@ -828,7 +824,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $cquestions[] = array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title']."#1"); // first label - $lresult = Answers::model()->findAllByAttributes(array('qid' => $rows['qid'], 'scale_id' => 0, 'language' => Survey::model()->findByPk($surveyid)->language), array('order' => 'sortorder, answer')); + $lresult = Answers::model()->findAllByAttributes(array('qid' => $rows['qid'], 'scale_id' => 0, 'language' => Survey::model()->findByPk($iSurveyID)->language), array('order' => 'sortorder, answer')); foreach ($lresult as $lrows) { $canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title']."#0", "{$lrows['code']}", "{$lrows['code']}"); @@ -838,7 +834,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $lresult = Answers::model()->findAllByAttributes(array( 'qid' => $rows['qid'], 'scale_id' => 1, - 'language' => Survey::model()->findByPk($surveyid)->language, + 'language' => Survey::model()->findByPk($iSurveyID)->language, ), array('order' => 'sortorder, answer')); foreach ($lresult as $lrows) @@ -858,7 +854,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) { $aresult = Questions::model()->findAllByAttributes(array( "parent_qid" => $rows['qid'], - "language" =>Survey::model()->findByPk($surveyid)->language, + "language" =>Survey::model()->findByPk($iSurveyID)->language, ), array('order' => 'question_order desc')); foreach ($aresult as $arows) @@ -880,7 +876,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $aresult = Answers::model()->findAllByAttributes(array( "qid" => $rows['qid'], "scale_id" => 0, - "language" => Survey::model()->findByPk($surveyid)->language, + "language" => Survey::model()->findByPk($iSurveyID)->language, ), array('order' => 'sortorder, answer')); $acount = count($aresult); @@ -912,7 +908,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $aresult = Questions::model()->findAllByAttributes(array( "parent_qid" => $rows['qid'], - "language" => Survey::model()->findByPk($surveyid)->language, + "language" => Survey::model()->findByPk($iSurveyID)->language, ), array('order' => 'question_order desc')); foreach ($aresult as $arows) @@ -981,7 +977,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $aresult = Answers::model()->findAllByAttributes(array( 'qid' => $rows['qid'], 'scale_id' => 0, - 'language' => Survey::model()->findByPk($surveyid)->language, + 'language' => Survey::model()->findByPk($iSurveyID)->language, ), array('order' => 'sortorder, answer')); foreach ($aresult as $arows) @@ -1041,7 +1037,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) } $questionNavOptions .= CHtml::tag('option', array( - 'value' => $this->getController()->createUrl("/admin/conditions/index/subaction/editconditionsform/surveyid/$surveyid/gid/{$row['gid']}/qid/{$row['qid']}")), + 'value' => $this->getController()->createUrl("/admin/conditions/index/subaction/editconditionsform/surveyid/$iSurveyID/gid/{$row['gid']}/qid/{$row['qid']}")), $questionselecter ); } @@ -1059,7 +1055,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) } $questionNavOptions .= CHtml::tag('option', array( - 'value'=>$this->getController()->createUrl("/admin/conditions/index/subaction/editconditionsform/surveyid/$surveyid/gid/$gid/qid/$qid"), + 'value'=>$this->getController()->createUrl("/admin/conditions/index/subaction/editconditionsform/surveyid/$iSurveyID/gid/$gid/qid/$qid"), 'selected'=>'selected'), $questiontitle .': '. $questiontextshort); $questionNavOptions .= CHtml::closeTag('optgroup'); @@ -1079,7 +1075,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $questionselecter = htmlspecialchars(mb_strcut(html_entity_decode($question,ENT_QUOTES,'UTF-8'), 0, 35, 'UTF-8'))."..."; } $questionNavOptions .= CHtml::tag('option', array( - 'value' => $this->getController()->createUrl("/admin/conditions/index/subaction/editconditionsform/surveyid/$surveyid/gid/{$row['gid']}/qid/{$row['qid']}")), + 'value' => $this->getController()->createUrl("/admin/conditions/index/subaction/editconditionsform/surveyid/$iSurveyID/gid/{$row['gid']}/qid/{$row['qid']}")), $row['title'].':'.$questionselecter ); } @@ -1141,7 +1137,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) $aViewUrls = array(); $aData['clang'] = $clang; - $aData['surveyid'] = $surveyid; + $aData['surveyid'] = $iSurveyID; $aData['qid'] = $qid; $aData['gid'] = $gid; $aData['imageurl'] = $imageurl; @@ -1261,7 +1257,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) ."AND c.scenario=:scenario " ."AND c.cfieldname NOT LIKE '{%' " // avoid catching SRCtokenAttr conditions ."ORDER BY g.group_order, q.question_order, c.cfieldname"; - $sLanguage=Survey::model()->findByPk($surveyid)->language; + $sLanguage=Survey::model()->findByPk($iSurveyID)->language; $result=Yii::app()->db->createCommand($query) ->bindValue(":scenario", $scenarionr['scenario']) ->bindValue(":qid", $qid, PDO::PARAM_INT) @@ -1335,7 +1331,7 @@ function index($subaction, $surveyid=null, $gid=null, $qid=null) } $aViewUrls['output'] .= "\t