From a7f7dd8090da849a541f7f2bd7cc9ffbb26f4c56 Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Thu, 23 Nov 2017 15:49:21 +0100 Subject: [PATCH] Dev Fixed problematic comments --- .scrutinizer.yml | 10 ++- .../controllers/InstallerController.php | 3 +- application/controllers/admin/surveyadmin.php | 7 +- .../controllers/admin/surveypermission.php | 7 +- application/controllers/admin/tokens.php | 31 +++----- application/controllers/admin/useraction.php | 6 +- application/core/LSYii_Validators.php | 16 ++-- application/helpers/admin/import_helper.php | 74 +++++++++++------ application/helpers/export_helper.php | 19 +++-- application/helpers/frontend_helper.php | 6 +- application/helpers/qanda_helper.php | 79 ++++++------------- application/helpers/userstatistics_helper.php | 44 +++-------- application/models/Participant.php | 4 +- 13 files changed, 140 insertions(+), 166 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 3e91dae6989..d7ffe8f2054 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,5 +1,5 @@ filter: - excluded_paths: [framework/*, locale/*, docs/*, fonts/*, third_party/*, application/libraries/admin/pclzip/*, application/extensions/*, application/views/*, application/third_party/*, images/*, styles/*, styles-public/*, templates/*, themes/*, tmp/*, upload/*] + excluded_paths: [framework/*, locale/*, docs/*, fonts/*, third_party/*, application/helpers/adodb/*, application/libraries/admin/http//*, application/libraries/admin/pclzip/*, application/extensions/*, application/views/*, application/third_party/*, images/*, styles/*, styles-public/*, templates/*, themes/*, tmp/*, upload/*] paths: [application/*] checks: php: @@ -7,4 +7,10 @@ checks: duplication: true one_class_per_file: true coding_style: - php: { } \ No newline at end of file + php: { } + +# braces: +# classes_functions: +# class: new-line +# function: new-line +# closure: new-line \ No newline at end of file diff --git a/application/controllers/InstallerController.php b/application/controllers/InstallerController.php index 991933b7f8a..1b115cda59a 100644 --- a/application/controllers/InstallerController.php +++ b/application/controllers/InstallerController.php @@ -372,8 +372,7 @@ private function stepDatabaseConfiguration() 'name' => '', ); } - elseif ($bDBExistsButEmpty) //&& !(returnGlobal('createdbstep2')==gT("Populate database"))) - { + elseif ($bDBExistsButEmpty) { Yii::app()->session['populatedatabase'] = true; //$this->connection->database = $model->dbname; diff --git a/application/controllers/admin/surveyadmin.php b/application/controllers/admin/surveyadmin.php index b4773160047..03815fea90b 100644 --- a/application/controllers/admin/surveyadmin.php +++ b/application/controllers/admin/surveyadmin.php @@ -657,8 +657,8 @@ public function deactivate($iSurveyID = null) { Yii::app()->user->setFlash('error', $message); } - if ($success === false) // TODO: What if two plugins change this? - { + if ($success === false) { + // @todo: What if two plugins change this? $aData['nostep'] = true; $this->_renderWrappedTemplate('survey', 'deactivateSurvey_view', $aData); return; @@ -944,8 +944,7 @@ public function editSurvey_json() { $operation = Yii::app()->request->getPost('oper'); $iSurveyIDs = Yii::app()->request->getPost('id'); - if ($operation == 'del') // If operation is delete , it will delete, otherwise edit it - { + if ($operation == 'del') { // If operation is delete , it will delete, otherwise edit it foreach (explode(',', $iSurveyIDs) as $iSurveyID) { if (Permission::model()->hasSurveyPermission($iSurveyID, 'survey', 'delete')) diff --git a/application/controllers/admin/surveypermission.php b/application/controllers/admin/surveypermission.php index 06f07a20be2..41c048b950b 100644 --- a/application/controllers/admin/surveypermission.php +++ b/application/controllers/admin/surveypermission.php @@ -122,8 +122,7 @@ public function index($iSurveyID) if (Permission::model()->hasSurveyPermission($iSurveyID, 'surveysecurity', 'update')) { - if ($PermissionRow['uid'] != Yii::app()->user->getId() || Permission::model()->hasGlobalPermission('superadmin', 'read')) // Can not update own security - { + if ($PermissionRow['uid'] != Yii::app()->user->getId() || Permission::model()->hasGlobalPermission('superadmin', 'read')) { // Can not update own security $surveysecurity .= CHtml::form(array("admin/surveypermission/sa/set/surveyid/{$iSurveyID}"), 'post', array('style'=>"display:inline;")) .""; $surveysecurity .= \CHtml::hiddenField('action', 'setsurveysecurity'); @@ -468,8 +467,8 @@ function set($surveyid) } elseif ($action == "setusergroupsurveysecurity") { - if (!Permission::model()->hasGlobalPermission('superadmin', 'read') && !in_array($postusergroupid, getUserGroupList(null, 'simplegidarray'))) // User can not change own security (except for superadmin ?) - { + if (!Permission::model()->hasGlobalPermission('superadmin', 'read') && !in_array($postusergroupid, getUserGroupList(null, 'simplegidarray'))) { + // User can not change own security (except for superadmin ?) $this->getController()->error('Access denied'); } } diff --git a/application/controllers/admin/tokens.php b/application/controllers/admin/tokens.php index 3c006b1f4f0..bb1ac543bb8 100644 --- a/application/controllers/admin/tokens.php +++ b/application/controllers/admin/tokens.php @@ -56,8 +56,7 @@ public function index($iSurveyId) // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY - if (!$survey->hasTokensTable) //If no tokens table exists - { + if (!$survey->hasTokensTable) { //If no tokens table exists self::_newtokentable($iSurveyId); } else @@ -220,8 +219,7 @@ public function bounceprocessing($iSurveyId) } $readbounce = imap_body($mbox, $sMessageID, FT_UID); // Put read - if (isset($thissurvey['bounceremove']) && $thissurvey['bounceremove']) // TODO Y or just true, and a imap_delete - { + if (isset($thissurvey['bounceremove']) && $thissurvey['bounceremove']) { // TODO Y or just true, and a imap_delete $deletebounce = imap_delete($mbox, $sMessageID, FT_UID); // Put delete } } @@ -432,7 +430,7 @@ public function editMultiple() // Email if (trim(Yii::app()->request->getPost('email', 'lskeep')) != 'lskeep') { - $isValid = preg_match('/^([a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+))(,([a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)))*$/', Yii::app()->request->getPost('email')); + $isValid = preg_match('/^([a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+))(,([a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)))*$/', Yii::app()->request->getPost('email')); if ($isValid) { $aData['email'] = 'lskeep'; } else { @@ -1049,8 +1047,7 @@ public function managetokenattributes($iSurveyId) } // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY $bTokenExists = $survey->hasTokensTable; - if (!$bTokenExists) //If no tokens table exists - { + if (!$bTokenExists) { //If no tokens table exists self::_newtokentable($iSurveyId); } Yii::app()->loadHelper("surveytranslator"); @@ -1434,8 +1431,7 @@ public function email($iSurveyId, $tokenids = null) $to[] = ($emrow['firstname']." ".$emrow['lastname']." <{$sEmailaddress}>"); } - foreach ($emrow as $attribute => $value) // LimeExpressionManager::loadTokenInformation use $oToken->attributes - { + foreach ($emrow as $attribute => $value) { $fieldsarray['{'.strtoupper($attribute).'}'] = $value; } @@ -1665,8 +1661,7 @@ public function exportdialog($iSurveyId) // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY $iSurveyId = sanitize_int($iSurveyId); - if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'export'))//EXPORT FEATURE SUBMITTED BY PIETERJAN HEYSE - { + if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'export')) { Yii::app()->session['flashmessage'] = gT("You do not have permission to access this page."); $this->getController()->redirect(array("/admin/survey/sa/view/surveyid/{$iSurveyId}")); } @@ -2051,8 +2046,7 @@ public function import($iSurveyId) App()->getClientScript()->registerScriptFile(App()->getConfig('adminscripts').'tokensimport.js'); $aEncodings = aEncodingsArray(); - if (Yii::app()->request->isPostRequest) // && Yii::app()->request->getPost('subaction')=='upload') - { + if (Yii::app()->request->isPostRequest) { $sUploadCharset = Yii::app()->request->getPost('csvcharset'); if (!array_key_exists($sUploadCharset, $aEncodings))// Validate sUploadCharset { @@ -2077,12 +2071,10 @@ public function import($iSurveyId) { Yii::app()->setFlashMessage(sprintf(gT("Sorry, this file is too large. Only files up to %01.2f MB are allowed."), getMaximumFileUploadSize() / 1024 / 1024), 'error'); } - elseif (strtolower($oFile->getExtensionName()) != 'csv')// && !in_array($oFile->getType(),$aCsvMimetypes) - { + elseif (strtolower($oFile->getExtensionName()) != 'csv') { Yii::app()->setFlashMessage(gT("Only CSV files are allowed."), 'error'); } - elseif (!@$oFile->saveAs($sFileName)) //!@move_uploaded_file($sFileTmpName, $sFileName)) - { + elseif (!@$oFile->saveAs($sFileName)) { Yii::app()->setFlashMessage(sprintf(gT("Upload file not found. Check your permissions and path (%s) for the upload directory"), $sPath), 'error'); } else @@ -2283,8 +2275,9 @@ public function import($iSurveyId) { if ($aWriteArray[$key] == "") unset($aWriteArray[$key]); - if (substr($value, 0, 1) == '"' && substr($value, -1) == '"')// Fix CSV quote - $value = substr($value, 1, -1); + if (substr($value, 0, 1) == '"' && substr($value, -1) == '"') { // Fix CSV quote + $value = substr($value, 1, -1); + } } // Some default value : to be moved to Token model rules in future release ? // But think we have to accept invalid email etc ... then use specific scenario diff --git a/application/controllers/admin/useraction.php b/application/controllers/admin/useraction.php index b9553f5ec17..9e6c8196662 100644 --- a/application/controllers/admin/useraction.php +++ b/application/controllers/admin/useraction.php @@ -192,8 +192,7 @@ public function deluser() $postuserid = $this->_getPostOrParam("uid"); $postuser = flattenText($this->_getPostOrParam("user")); - if ($oInitialAdmin && $oInitialAdmin->uid == $postuserid) // it's the original superadmin !!! - { + if ($oInitialAdmin && $oInitialAdmin->uid == $postuserid) { // it's the original superadmin !!! Yii::app()->setFlashMessage(gT("Initial Superadmin cannot be deleted!"), 'error'); $this->getController()->redirect(array("admin/user/sa/index")); return; @@ -282,8 +281,7 @@ public function deleteFinalUser($result, $transfer_surveys_to) $postuser = flattenText(Yii::app()->request->getPost("user")); // Never delete initial admin (with findByAttributes : found the first user without parent) $oInitialAdmin = User::model()->findByAttributes(array('parent_id' => 0)); - if ($oInitialAdmin && $oInitialAdmin->uid == $postuserid) // it's the original superadmin !!! - { + if ($oInitialAdmin && $oInitialAdmin->uid == $postuserid) { // it's the original superadmin !!! Yii::app()->setFlashMessage(gT("Initial Superadmin cannot be deleted!"), 'error'); $this->getController()->redirect(array("admin/user/sa/index")); } diff --git a/application/core/LSYii_Validators.php b/application/core/LSYii_Validators.php index f5d8fd6965e..eccfc37460d 100644 --- a/application/core/LSYii_Validators.php +++ b/application/core/LSYii_Validators.php @@ -44,9 +44,9 @@ class LSYii_Validators extends CValidator { public function __construct() { - if (Yii::app()->getConfig('DBVersion') < 172) // Permission::model exist only after 172 DB version + if (Yii::app()->getConfig('DBVersion') < 172) { // Permission::model exist only after 172 DB version return $this->xssfilter = ($this->xssfilter && Yii::app()->getConfig('filterxsshtml')); - + } $this->xssfilter = ($this->xssfilter && Yii::app()->getConfig('filterxsshtml') && !Permission::model()->hasGlobalPermission('superadmin', 'read')); return null; } @@ -146,17 +146,17 @@ public function xssFilter($value) /** Construction of new string with unfiltered EM and filtered HTML **/ $sNewValue = ""; foreach ($aValues as $key=>$aValue) { - if ($aValue[2] == "STRING") - $sNewValue .= $bCountIsOk ? $aFilteredValues[$key][0] : $filter->purify($aValue[0]); // If EM is broken : can throw invalid $key - else { + if ($aValue[2] == "STRING") { + $sNewValue .= $bCountIsOk ? $aFilteredValues[$key][0] : $filter->purify($aValue[0]); // If EM is broken : can throw invalid $key + } else { $sExpression = trim($aValue[0], '{}'); $sNewValue .= "{"; $aParsedExpressions = $oExpressionManager->Tokenize($sExpression, true); foreach ($aParsedExpressions as $aParsedExpression) { - if ($aParsedExpression[2] == 'DQ_STRING') - $sNewValue .= "\"".$filter->purify($aParsedExpression[0])."\""; // This disallow complex HTML construction with XSS - elseif ($aParsedExpression[2] == 'SQ_STRING') + if ($aParsedExpression[2] == 'DQ_STRING') { + $sNewValue .= "\"".$filter->purify($aParsedExpression[0])."\""; // This disallow complex HTML construction with XSS + } elseif ($aParsedExpression[2] == 'SQ_STRING') $sNewValue .= "'".$filter->purify($aParsedExpression[0])."'"; else $sNewValue .= $aParsedExpression[0]; diff --git a/application/helpers/admin/import_helper.php b/application/helpers/admin/import_helper.php index 4b95a01631e..1357558287a 100644 --- a/application/helpers/admin/import_helper.php +++ b/application/helpers/admin/import_helper.php @@ -116,7 +116,9 @@ function XMLImportGroup($sFullFilePath, $iNewSID) } $iOldSID = $insertdata['sid']; $insertdata['sid'] = $iNewSID; - if (!isset($aGIDReplacements[$insertdata['gid']]) || trim($insertdata['title']) == '') continue; // Skip questions with invalid group id + if (!isset($aGIDReplacements[$insertdata['gid']]) || trim($insertdata['title']) == '') { // Skip questions with invalid group id + continue; + } $insertdata['gid'] = $aGIDReplacements[$insertdata['gid']]; $oldqid = $insertdata['qid']; unset($insertdata['qid']); // save the old qid @@ -153,10 +155,14 @@ function XMLImportGroup($sFullFilePath, $iNewSID) $insertdata[(string) $key] = (string) $value; } $insertdata['sid'] = $iNewSID; - if (!isset($aGIDReplacements[$insertdata['gid']])) continue; // Skip questions with invalid group id + if (!isset($aGIDReplacements[$insertdata['gid']])) { // Skip questions with invalid group id + continue; + } $insertdata['gid'] = $aGIDReplacements[(int) $insertdata['gid']]; ; $oldsqid = (int) $insertdata['qid']; unset($insertdata['qid']); // save the old qid - if (!isset($aQIDReplacements[(int) $insertdata['parent_qid']])) continue; // Skip subquestions with invalid parent_qids + if (!isset($aQIDReplacements[(int) $insertdata['parent_qid']])) { // Skip questions with invalid parent qid + continue; + } $insertdata['parent_qid'] = $aQIDReplacements[(int) $insertdata['parent_qid']]; // remap the parent_qid // now translate any links @@ -193,7 +199,9 @@ function XMLImportGroup($sFullFilePath, $iNewSID) foreach ($row as $key=>$value) { $insertdata[(string) $key] = (string) $value; } - if (!isset($aQIDReplacements[(int) $insertdata['qid']])) continue; // Skip questions with invalid group id + if (!isset($aQIDReplacements[(int) $insertdata['qid']])) { // Skip questions with invalid group id + continue; + } $insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']]; // remap the parent_qid @@ -215,7 +223,9 @@ function XMLImportGroup($sFullFilePath, $iNewSID) $insertdata[(string) $key] = (string) $value; } unset($insertdata['qaid']); - if (!isset($aQIDReplacements[(int) $insertdata['qid']])) continue; // Skip questions with invalid group id + if (!isset($aQIDReplacements[(int) $insertdata['qid']])) { // Skip questions with invalid group id + continue; + } $insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']]; // remap the parent_qid @@ -245,7 +255,9 @@ function XMLImportGroup($sFullFilePath, $iNewSID) } $insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']]; // remap the qid if ($insertdata['sqid'] > 0) { - if (!isset($aQIDReplacements[(int) $insertdata['sqid']])) continue; // If SQID is invalid skip the default value + if (!isset($aQIDReplacements[(int) $insertdata['sqid']])) { // Skip questions with invalid subquestion id + continue; + } $insertdata['sqid'] = $aQIDReplacements[(int) $insertdata['sqid']]; // remap the subquestion id } @@ -268,16 +280,22 @@ function XMLImportGroup($sFullFilePath, $iNewSID) if (isset($aQIDReplacements[$insertdata['qid']])) { $insertdata['qid'] = $aQIDReplacements[$insertdata['qid']]; // remap the qid } - else continue; // a problem with this answer record -> don't consider + else { // a problem with this answer record -> don't consider + continue; + } if (isset($aQIDReplacements[$insertdata['cqid']])) { $insertdata['cqid'] = $aQIDReplacements[$insertdata['cqid']]; // remap the qid } - else continue; // a problem with this answer record -> don't consider + else { // a problem with this answer record -> don't consider + continue; + } list($oldcsid, $oldcgid, $oldqidanscode) = explode("X", $insertdata["cfieldname"], 3); - if ($oldcgid != $oldgid) // this means that the condition is in another group (so it should not have to be been exported -> skip it + if ($oldcgid != $oldgid) { + // this means that the condition is in another group (so it should not have to be been exported -> skip it continue; + } unset($insertdata["cid"]); @@ -1284,7 +1302,9 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = NULL, $sNewSurveyName = NUL $insertdata[(string) $key] = (string) $value; } $insertdata['qid'] = $aQIDReplacements[(int) $insertdata['qid']]; // remap the qid - if (isset($aQIDReplacements[(int) $insertdata['sqid']])) $insertdata['sqid'] = $aQIDReplacements[(int) $insertdata['sqid']]; // remap the subquestion id + if (isset($aQIDReplacements[(int) $insertdata['sqid']])) { // remap the subquestion id + $insertdata['sqid'] = $aQIDReplacements[(int) $insertdata['sqid']]; + } if ($insertdata) XSSFilterArray($insertdata); // now translate any links @@ -1308,20 +1328,26 @@ function XMLImportSurvey($sFullFilePath, $sXMLdata = NULL, $sNewSurveyName = NUL if (isset($aQIDReplacements[$insertdata['qid']])) { $insertdata['qid'] = $aQIDReplacements[$insertdata['qid']]; // remap the qid } - else continue; // a problem with this answer record -> don't consider + else { // a problem with this answer record -> don't consider + continue; + } if ($insertdata['cqid'] != 0) { if (isset($aQIDReplacements[$insertdata['cqid']])) { $oldcqid = $insertdata['cqid']; //Save for cfield transformation $insertdata['cqid'] = $aQIDReplacements[$insertdata['cqid']]; // remap the qid } - else continue; // a problem with this answer record -> don't consider + else { // a problem with this answer record -> don't consider + continue; + } list($oldcsid, $oldcgid, $oldqidanscode) = explode("X", $insertdata["cfieldname"], 3); // replace the gid for the new one in the cfieldname(if there is no new gid in the $aGIDReplacements array it means that this condition is orphan -> error, skip this record) - if (!isset($aGIDReplacements[$oldcgid])) - continue; + if (!isset($aGIDReplacements[$oldcgid])){ + continue; + } + } unset($insertdata["cid"]); @@ -1632,8 +1658,9 @@ function XMLImportResponses($sFullFilePath, $iSurveyID, $aFieldReMap = array()) if (!$oXMLReader->isEmptyElement) { $oXMLReader->read(); - if (in_array($sFieldname, $DestinationFields)) // some old response tables contain invalid column names due to old bugs + if (in_array($sFieldname, $DestinationFields)) { // some old response tables contain invalid column names due to old bugs $aInsertData[$sFieldname] = $oXMLReader->value; + } $oXMLReader->read(); } else { @@ -1822,15 +1849,14 @@ function CSVImportResponses($sFullFilePath, $iSurveyId, $aOptions = array()) } if ($oSurvey) { // First rule for id and submitdate - if (is_int($iIdKey)) // Rule for id: only if id exists in vvimport file - { + if (is_int($iIdKey)) { // Rule for id: only if id exists in vvimport file if (!$bExistingsId) // If not exist : allways import it { $oSurvey->id = $aResponses[$iIdKey]; $iMaxId = ($aResponses[$iIdKey] > $iMaxId) ? $aResponses[$iIdKey] : $iMaxId; } - elseif ($aOptions['sExistingId'] == 'replace' || $aOptions['sExistingId'] == 'replaceanswers')// Set it depending with some options - { + elseif ($aOptions['sExistingId'] == 'replace' || $aOptions['sExistingId'] == 'replaceanswers') { + // Set it depending with some options $oSurvey->id = $aResponses[$iIdKey]; } } @@ -1879,8 +1905,8 @@ function CSVImportResponses($sFullFilePath, $iSurveyId, $aOptions = array()) $aResponsesInserted[] = $aResponses[$iIdReponsesKey]; } } - else // Actually can not be, leave it if we have a $oSurvey->validate() in future release - { + else { + // Actually can not be, leave it if we have a $oSurvey->validate() in future release $oTransaction->rollBack(); $aResponsesError[] = $aResponses[$iIdReponsesKey]; } @@ -2171,8 +2197,7 @@ function TSVImportSurvey($sFullFilePath) // when a multi-lang tsv-file without information on the group id/number (old style) is imported, // we make up this information by giving a number 0..[numberofgroups-1] per language. // the number and order of groups per language should be the same, so we can also import these files - if ($lastglang != $glang) //reset counter on language change - { + if ($lastglang != $glang) { //reset counter on language change $iGroupcounter = 0; } $lastglang = $glang; @@ -2318,8 +2343,7 @@ function TSVImportSurvey($sFullFilePath) { ; // these are fake rows to show naming of comment and filecount fields } - elseif ($sqname == 'other' && $lastother == "Y") // If last question have other to Y : it's not a real SQ row - { + elseif ($sqname == 'other' && $lastother == "Y") { // If last question have other to Y : it's not a real SQ row if ($qtype == "!" || $qtype == "L") { // only used to set default value for 'other' in these cases diff --git a/application/helpers/export_helper.php b/application/helpers/export_helper.php index f64c4beadfe..af2660c38a2 100644 --- a/application/helpers/export_helper.php +++ b/application/helpers/export_helper.php @@ -377,7 +377,7 @@ function SPSSGetValues($field = array(), $qidattributes = null, $language) { $answers['size'] = $size; return $answers; } else { - /* Not managed (currently): url, IP, … */ + /* Not managed (currently): url, IP, … */ return; } } @@ -722,12 +722,16 @@ function buildXMLFromQuery($xmlwriter, $Query, $tagname = '', $excludes = array( foreach ($Row as $Key=>$Value) { if (!isset($exclude[$Key])) { - if (!(is_null($Value))) // If the $value is null don't output an element at all - { - if (is_numeric($Key[0])) $Key = '_'.$Key; // mask invalid element names with an underscore + if (!(is_null($Value))) { // If the $value is null don't output an element at all + if (is_numeric($Key[0])) { + // mask invalid element names with an underscore + $Key = '_'.$Key; + } $Key = str_replace('#', '-', $Key); - if (!$xmlwriter->startElement($Key)) safeDie('Invalid element key: '.$Key); - // Remove invalid XML characters + if (!$xmlwriter->startElement($Key)) { // Remove invalid XML characters + safeDie('Invalid element key: '.$Key); + } + if ($Value !== '') { $Value = str_replace(']]>', ']] >', $Value); $xmlwriter->writeCData(preg_replace('/[^\x9\xA\xD\x20-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', '', $Value)); @@ -768,8 +772,7 @@ function surveyGetXMLStructure($iSurveyID, $xmlwriter, $exclude = array()) WHERE {{assessments}}.sid=$iSurveyID"; buildXMLFromQuery($xmlwriter, $query); - if (!isset($exclude['conditions'])) - { + if (!isset($exclude['conditions'])) { //Condition table $cquery = "SELECT DISTINCT {{conditions}}.* FROM {{conditions}}, {{questions}} diff --git a/application/helpers/frontend_helper.php b/application/helpers/frontend_helper.php index d877b58a17d..1d3c2bd0181 100644 --- a/application/helpers/frontend_helper.php +++ b/application/helpers/frontend_helper.php @@ -35,16 +35,14 @@ function loadanswers() $oCriteria->join = "LEFT JOIN {{saved_control}} ON t.id={{saved_control}}.srid"; $oCriteria->condition = "{{saved_control}}.sid=:sid"; $aParams = array(':sid'=>$surveyid); - if (isset($scid)) //Would only come from email : we don't need it .... - { + if (isset($scid)) { //Would only come from email : we don't need it .... $oCriteria->addCondition("{{saved_control}}.scid=:scid"); $aParams[':scid'] = $scid; } $oCriteria->addCondition("{{saved_control}}.identifier=:identifier"); $aParams[':identifier'] = $sLoadName; - if (in_array(Yii::app()->db->getDriverName(), array('mssql', 'sqlsrv', 'dblib'))) - { + if (in_array(Yii::app()->db->getDriverName(), array('mssql', 'sqlsrv', 'dblib'))) { // To be validated with mssql, think it's not needed $oCriteria->addCondition("(CAST({{saved_control}}.access_code as varchar(64))=:md5_code OR CAST({{saved_control}}.access_code as varchar(64))=:sha256_code)"); } else diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php index 1e5a82d7c07..ea2045d1f18 100644 --- a/application/helpers/qanda_helper.php +++ b/application/helpers/qanda_helper.php @@ -268,8 +268,7 @@ function retrieveAnswers($ia) } - if (isset($values)) //Break apart $values array returned from switch - { + if (isset($values)) { //Break apart $values array returned from switch //$answer is the html code to be printed //$inputnames is an array containing the names of each input field list($answer, $inputnames) = $values; @@ -342,8 +341,7 @@ function retrieveAnswers($ia) // START: work-around step 1 $qtitle_custom = preg_replace('/(]+>)(<\/embed>)/i', '\1NOT_EMPTY\2', $qtitle_custom); // END work-around step 1 - while ($c > 0) // This recursively strips any empty tags to minimise rendering bugs. - { + while ($c > 0) { // This recursively strips any empty tags to minimise rendering bugs. $oldtitle = $qtitle_custom; $qtitle_custom = preg_replace('/<([^ >]+)[^>]*>[\r\n\t ]*<\/\1>[\r\n\t ]*/isU', '', $qtitle_custom, -1); // I removed the $count param because it is PHP 5.1 only. @@ -352,8 +350,7 @@ function retrieveAnswers($ia) // START work-around step 2 $qtitle_custom = preg_replace('/(]+>)NOT_EMPTY(<\/embed>)/i', '\1\2', $qtitle_custom); // END work-around step 2 - while ($c > 0) // This recursively strips any empty tags to minimise rendering bugs. - { + while ($c > 0) { // This recursively strips any empty tags to minimise rendering bugs. $oldtitle = $qtitle_custom; $qtitle_custom = preg_replace('/((?: |\r\n|\n\r|\r|\n| )*)+$/i', '', $qtitle_custom, -1); // I removed the $count param because it is PHP 5.1 only. $c = ($qtitle_custom != $oldtitle) ? 1 : 0; @@ -428,8 +425,7 @@ function mandatory_popup($ia, $notanswered = null) //This sets the mandatory popup message to show if required //Called from question.php, group.php or survey.php if ($notanswered === null) {unset($notanswered); } - if (isset($notanswered) && is_array($notanswered)) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED - { + if (isset($notanswered) && is_array($notanswered)) { //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED global $mandatorypopup, $popup; //POPUP WARNING if (!isset($mandatorypopup) && ($ia[4] == 'T' || $ia[4] == 'S' || $ia[4] == 'U')) @@ -845,8 +841,7 @@ function do_5pointchoice($ia) ), true); } - if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) // Add "No Answer" option if question is not mandatory - { + if ($ia[6] != "Y" && SHOW_NO_ANSWER == 1) { // Add "No Answer" option if question is not mandatory $checkedState = ''; if (!$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]) { @@ -925,8 +920,7 @@ function do_date($ia) { $mindate = $date_min.'-01-01'; // backward compatibility: if only a year is given, add month and day } - elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $date_min))// it's a YYYY-MM-DD date (use http://www.yiiframework.com/doc/api/1.1/CDateValidator ?) - { + elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $date_min)) { // it's a YYYY-MM-DD date (use http://www.yiiframework.com/doc/api/1.1/CDateValidator ?) $mindate = $date_min; } elseif ($date_time_em) @@ -953,8 +947,7 @@ function do_date($ia) { $maxdate = $date_max.'-12-31'; // backward compatibility: if only a year is given, add month and day } - elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $date_max))// it's a YYYY-MM-DD date (use http://www.yiiframework.com/doc/api/1.1/CDateValidator ?) - { + elseif (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $date_max)) { // it's a YYYY-MM-DD date (use http://www.yiiframework.com/doc/api/1.1/CDateValidator ?) $maxdate = $date_max; } elseif ($date_time_em) @@ -1849,9 +1842,7 @@ function do_listwithcomment($ia) $inputnames[] = $ia[1]; $inputnames[] = $ia[1].'comment'; - } - else //Dropdown list - { + } else { //Dropdown list $sOptions = ''; foreach ($ansresult as $ansrow) { @@ -3611,8 +3602,7 @@ function do_shortfreetext($ia) function getLatLongFromIp($sIPAddress) { $ipInfoDbAPIKey = Yii::app()->getConfig("ipInfoDbAPIKey"); - if ($ipInfoDbAPIKey)// ipinfodb.com need a key - { + if ($ipInfoDbAPIKey) { // ipinfodb.com needs a key $oXML = simplexml_load_file("http://api.ipinfodb.com/v3/ip-city/?key=$ipInfoDbAPIKey&ip=$sIPAddress&format=xml"); if ($oXML->{'statusCode'} == "OK") { $lat = (float) $oXML->{'latitude'}; @@ -3665,8 +3655,7 @@ function do_longfreetext($ia) $drows = 5; } - if (trim($aQuestionAttributes['text_input_width']) != '') // text_input_width can not be empty, except with old survey (wher can be empty or up to 12 see bug #11743 - { + if (trim($aQuestionAttributes['text_input_width']) != '') { // text_input_width can not be empty, except with old survey (wher can be empty or up to 12 see bug #11743 $col = ($aQuestionAttributes['text_input_width'] <= 12) ? $aQuestionAttributes['text_input_width'] : 12; $extraclass .= " col-sm-".trim($col); $withColumn = true; @@ -3920,8 +3909,7 @@ function do_array_5point($ia) $columnswidth = 100 - $answerwidth; $colCount = 5; // number of columns - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory ++$colCount; // add another column } @@ -3964,8 +3952,7 @@ function do_array_5point($ia) $sColumns .= doRender('/survey/questions/answer/arrays/5point/columns/col', array('cellwidth'=>$cellwidth), true); } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory $sColumns .= doRender('/survey/questions/answer/arrays/5point/columns/col', array('cellwidth'=>$cellwidth), true); } @@ -3996,8 +3983,7 @@ function do_array_5point($ia) ), true); } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory $sHeaders .= doRender('/survey/questions/answer/arrays/5point/rows/cells/header_answer', array( 'class'=>'answer-text noanswer-text', 'content'=>gT('No answer'), @@ -4126,8 +4112,7 @@ function do_array_10point($ia) $answerwidth = 33; } $cellwidth = 10; // number of columns - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory ++$cellwidth; // add another column } $cellwidth = round(((100 - $answerwidth) / $cellwidth), 1); // convert number of columns to percentage of table width @@ -4153,8 +4138,7 @@ function do_array_10point($ia) $sColumns .= doRender('/survey/questions/answer/arrays/10point/columns/col', array('odd_even'=>$odd_even, 'cellwidth'=>$cellwidth), true); } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory $odd_even = alternation($odd_even); $sColumns .= doRender('/survey/questions/answer/arrays/10point/columns/col', array('odd_even'=>$odd_even, 'cellwidth'=>$cellwidth), true); } @@ -4172,8 +4156,7 @@ function do_array_10point($ia) ), true); } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory $sHeaders .= doRender('/survey/questions/answer/arrays/10point/rows/cells/header_answer', array( 'class'=>'answer-text noanswer-text', 'content'=>gT('No answer'), @@ -4269,8 +4252,7 @@ function do_array_yesnouncertain($ia) $answerwidth = (trim($aQuestionAttributes['answer_width']) != '') ? $aQuestionAttributes['answer_width'] : 33; $cellwidth = 3; // number of columns - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory ++$cellwidth; // add another column } @@ -4298,8 +4280,7 @@ function do_array_yesnouncertain($ia) $sColumns .= doRender('/survey/questions/answer/arrays/yesnouncertain/columns/col', array('odd_even'=>$odd_even, 'cellwidth'=>$cellwidth), true); } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory $odd_even = alternation($odd_even); $sColumns .= doRender('/survey/questions/answer/arrays/yesnouncertain/columns/col', array('odd_even'=>$odd_even, 'cellwidth'=>$cellwidth, 'no_answer'=>true), true); } @@ -4373,8 +4354,7 @@ function do_array_increasesamedecrease($ia) $cellwidth = 3; // number of columns $inputnames = array(); - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory ++$cellwidth; // add another column } @@ -4403,8 +4383,7 @@ function do_array_increasesamedecrease($ia) $odd_even = alternation($odd_even); $sColumns .= doRender('/survey/questions/answer/arrays/increasesamedecrease/columns/col', array('odd_even'=>$odd_even, 'cellwidth'=>$cellwidth), true); } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory $odd_even = alternation($odd_even); $sColumns .= doRender('/survey/questions/answer/arrays/increasesamedecrease/columns/col', array('odd_even'=>$odd_even, 'cellwidth'=>$cellwidth), true); } @@ -4573,8 +4552,7 @@ function do_array($ia) ), true); } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory and we can show "no answer" - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory and we can show "no answer" $sHeaders .= doRender('/survey/questions/answer/arrays/array/no_dropdown/rows/cells/header_answer', array( 'class' => 'answer-text noanswer-text', 'content' => gT('No answer'), @@ -4677,8 +4655,7 @@ function do_array($ia) ), true); } - if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) //Question is not mandatory - { + if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) { //Question is not mandatory $odd_even = alternation($odd_even); $sColumns .= doRender('/survey/questions/answer/arrays/array/no_dropdown/columns/col', array( 'class' => 'col-no-answer '.$odd_even, @@ -5991,8 +5968,7 @@ function do_array_dual($ia) $aData['aSubQuestions'][$i]['sessionfname0'] = ''; } - if (count($labelans1) > 0) // if second label set is used - { + if (count($labelans1) > 0) { // if second label set is used if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1])) { //$answer .= $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1]; @@ -6004,8 +5980,7 @@ function do_array_dual($ia) } } - foreach ($labelcode0 as $j => $ld) // First label set - { + foreach ($labelcode0 as $j => $ld) { // First label set if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0]) && $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0] == $ld) { $aData['labelcode0_checked'][$ansrow['title']][$ld] = CHECKED; @@ -6016,8 +5991,7 @@ function do_array_dual($ia) } } - if (count($labelans1) > 0) // if second label set is used - { + if (count($labelans1) > 0) { // if second label set is used if ($shownoanswer)// No answer for accessibility and no javascript (but hide hide even with no js: need reworking) { if (!isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0]) || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname0] == "") @@ -6033,8 +6007,7 @@ function do_array_dual($ia) array_push($inputnames, $myfname1); - foreach ($labelcode1 as $j => $ld) // second label set - { + foreach ($labelcode1 as $j => $ld) { // second label set if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1]) && $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$myfname1] == $ld) { $aData['labelcode1_checked'][$ansrow['title']][$ld] = CHECKED; diff --git a/application/helpers/userstatistics_helper.php b/application/helpers/userstatistics_helper.php index 244d6b9197a..992655e6851 100644 --- a/application/helpers/userstatistics_helper.php +++ b/application/helpers/userstatistics_helper.php @@ -395,8 +395,7 @@ function buildSelects($allfields, $surveyid, $language) { */ if ($pv != "sid" && $pv != "display" && $firstletter != "M" && $firstletter != "P" && $firstletter != "T" && $firstletter != "Q" && $firstletter != "D" && $firstletter != "N" && $firstletter != "K" && $firstletter != "|" && - $pv != "summary" && substr($pv, 0, 2) != "id" && substr($pv, 0, 9) != "datestamp") //pull out just the fieldnames - { + $pv != "summary" && substr($pv, 0, 2) != "id" && substr($pv, 0, 9) != "datestamp") { //pull out just the fieldnames //put together some SQL here $thisquestion = Yii::app()->db->quoteColumnName($pv)." IN ("; @@ -672,8 +671,7 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql, } //S - Short Free Text and T - Long Free Text - elseif ($firstletter == "T" || $firstletter == "S") //Short and long text - { + elseif ($firstletter == "T" || $firstletter == "S") { //Short and long text //search for key $fld = substr($rt, 1, strlen($rt)); $fielddata = $fieldmap[$fld]; @@ -764,8 +762,7 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql, } } - else if ($firstletter == "|") // File UPload - { + else if ($firstletter == "|") { // File Upload //get SGQ data list($qsid, $qgid, $qqid) = explode("X", substr($rt, 1, strlen($rt)), 3); @@ -886,8 +883,7 @@ protected function buildOutputList($rt, $language, $surveyid, $outputType, $sql, //N = numerical input //K = multiple numerical input - elseif ($firstletter == "N" || $firstletter == "K") //NUMERICAL TYPE - { + elseif ($firstletter == "N" || $firstletter == "K") { //NUMERICAL TYPE //Zero handling if (!isset($excludezeros)) //If this hasn't been set, set it to on as default: { @@ -1741,13 +1737,11 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi // . "OR cast(".sanitize_int($rt)." as varchar) = '' " . "cast(".Yii::app()->db->quoteColumnName($rt)." as varchar) = '' " . "OR cast(".Yii::app()->db->quoteColumnName($rt)." as varchar) = ' ' )"; - } - else - // $query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE (".sanitize_int($rt)." IS NULL " + } else { $query = "SELECT count(*) FROM {{survey_$surveyid}} WHERE ( " - // . "OR ".sanitize_int($rt)." = '' " . " ".Yii::app()->db->quoteColumnName($rt)." = '' " . "OR ".Yii::app()->db->quoteColumnName($rt)." = ' ') "; + } } } @@ -2596,21 +2590,11 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi } } - if ($outputType == 'pdf') //XXX TODO PDF + if ($outputType == 'pdf') { - //$tablePDF = array(); $tablePDF = array_merge_recursive($tablePDF, $footPDF); $this->pdf->headTable($headPDF, $tablePDF); - //$this->pdf->tableintopdf($tablePDF); - - // if(isset($footPDF)) - // foreach($footPDF as $foot) - // { - // $footA = array($foot); - // $this->pdf->tablehead($footA); - // } - if (isset($headPDF2)) - { + if (isset($headPDF2)) { $this->pdf->headTable($headPDF2, $tablePDF2); } } @@ -2687,8 +2671,7 @@ protected function displayResults($outputs, $results, $rt, $outputType, $surveyi if ($bShowGraph == true) { $cachefilename = createChart($qqid, $qsid, $bShowPieChart, $lbl, $gdata, $grawdata, $MyCache, $sLanguage, $outputs['qtype']); - if ($cachefilename) // Add the image only if constructed - { + if ($cachefilename) { // Add the image only if constructed //introduce new counter if (!isset($ci)) {$ci = 0; } @@ -3074,8 +3057,7 @@ public function generate_statistics($surveyid, $allfields, $q2show = 'all', $use $outputs = $this->buildOutputList($rt, $language, $surveyid, $outputType, $sql, $sLanguageCode); $sOutputHTML .= $outputs['statisticsoutput']; //2. Collect and Display results ####################################################################### - if (isset($outputs['alist']) && $outputs['alist']) //Make sure there really is an answerlist, and if so: - { + if (isset($outputs['alist']) && $outputs['alist']) { //Make sure there really is an answerlist, and if so: $display = $this->displayResults($outputs, $results, $rt, $outputType, $surveyid, $sql, $usegraph, $browse, $sLanguageCode); $sOutputHTML .= $display['statisticsoutput']; $aStatisticsData = array_merge($aStatisticsData, $display['astatdata']); @@ -3250,8 +3232,7 @@ function _listcolumn($surveyid, $column, $sortby = "", $sortmethod = "", $sortty { $search['condition'] = Yii::app()->db->quoteColumnName($column)." != ''"; $sDBDriverName = Yii::app()->db->getDriverName(); - if ($sDBDriverName == 'sqlsrv' || $sDBDriverName == 'mssql' || $sDBDriverName == 'dblib') // ADAPTED JV: added condition for dblib - { + if ($sDBDriverName == 'sqlsrv' || $sDBDriverName == 'mssql' || $sDBDriverName == 'dblib') { $search['condition'] = "CAST(".Yii::app()->db->quoteColumnName($column)." as varchar) != ''"; } @@ -3269,8 +3250,7 @@ function _listcolumn($surveyid, $column, $sortby = "", $sortmethod = "", $sortty if ($sortby != '') { - if ($sDBDriverName == 'sqlsrv' || $sDBDriverName == 'mssql' || $sDBDriverName == 'dblib') // ADAPTED JV: added condition for dblib - { + if ($sDBDriverName == 'sqlsrv' || $sDBDriverName == 'mssql' || $sDBDriverName == 'dblib') { $sortby = "CAST(".Yii::app()->db->quoteColumnName($sortby)." as varchar)"; } else diff --git a/application/models/Participant.php b/application/models/Participant.php index 0a821653887..fe6ca9e78e1 100644 --- a/application/models/Participant.php +++ b/application/models/Participant.php @@ -1323,7 +1323,9 @@ public function getParticipantsSearchMultipleCondition($condition) 'language', 'owner_uid', 'owner_name'); - if (!in_array($sFieldname, $aSafeFieldNames)) continue; // Skip invalid fieldname + if (!in_array($sFieldname, $aSafeFieldNames)) { // Skip invalid fieldname + continue; + } $command->addCondition(Yii::app()->db->quoteColumnName($sFieldname).' '.$operator.' '.$param, $booloperator); }