diff --git a/application/config/version.php b/application/config/version.php index 819a0a70448..e4d867ee110 100644 --- a/application/config/version.php +++ b/application/config/version.php @@ -12,7 +12,7 @@ * * $Id$ */ -$config['versionnumber'] = "2.0yii_alpha"; +$config['versionnumber'] = "2.0a2"; $config['dbversionnumber'] = 155; $config['buildnumber'] = ''; diff --git a/application/controllers/RegisterController.php b/application/controllers/RegisterController.php index 5c71cd02cf9..d111c40aead 100644 --- a/application/controllers/RegisterController.php +++ b/application/controllers/RegisterController.php @@ -1,59 +1,51 @@ loadHelper('database'); Yii::app()->loadHelper('replacements'); $redata = compact(array_keys(get_defined_vars())); $thistpl = Yii::app()->getConfig("standardtemplaterootdir").'/default'; $surveyid = sanitize_int($surveyid); - $squery = "SELECT a.expires, a.startdate - FROM {{surveys}} AS a - WHERE a.sid = $surveyid "; - - - $sresult = dbExecuteAssoc($squery) or show_error("Couldn't execute $squery"); - - - $row = $sresult->read(); - + $row = Survey::model()->find('sid=:sid',array(':sid' => $surveyid)) or show_error("Can't find survey data"); $data['sid'] = $surveyid; - $data['startdate'] = $row['startdate']; - $data['enddate'] = $row['expires']; + $data['startdate'] = $row->startdate; + $data['enddate'] = $row->expires; Yii::import('application.libraries.Limesurvey_lang'); - Yii::app()->lang = new Limesurvey_lang($baselang); + Yii::app()->lang = new Limesurvey_lang($baselang); echo templatereplace(file_get_contents("$thistpl/register.pstpl"),array(),$redata,'register.php',false,NULL,$data); } /** - * register::index() - * Process register form data and take appropriate action - * @return - */ + * register::index() + * Process register form data and take appropriate action + * @return + */ function actionIndex($surveyid = null) { Yii::app()->loadHelper('database'); @@ -81,18 +73,18 @@ function actionIndex($surveyid = null) Yii::app()->setSessionName("LimeSurveyRuntime-$surveyid"); } - Yii::app()->session->setCookieParams(array(0, Yii::app()->getConfig('relativeurl').'/')); + Yii::app()->session->setCookieParams(array(0, Yii::app()->getConfig('relativeurl').'/')); // Get passed language from form, so that we dont loose this! if (!isset($postlang) || $postlang == "" || !$postlang ) { $baselang = Survey::model()->findByPk($surveyid)->language; Yii::import('application.libraries.Limesurvey_lang'); - Yii::app()->lang = new Limesurvey_lang($baselang); + Yii::app()->lang = new Limesurvey_lang($baselang); $clang = Yii::app()->lang; } else { Yii::import('application.libraries.Limesurvey_lang'); - Yii::app()->lang = new Limesurvey_lang($postlang); + Yii::app()->lang = new Limesurvey_lang($postlang); $clang = Yii::app()->lang; $baselang = $postlang; } @@ -148,22 +140,22 @@ function actionIndex($surveyid = null) $mayinsert = false; - // Get the survey settings for token length - //$this->load->model("surveys_model"); - $tlresult = Survey::model()->findAllByAttributes(array("sid"=>$surveyid)); - if (isset($tlresult[0])) { - $tlrow = $tlresult[0]; - } - else - { - $tlrow = $tlresult; - } - $tokenlength = $tlrow['tokenlength']; - //if tokenlength is not set or there are other problems use the default value (15) - if(!isset($tokenlength) || $tokenlength == '') - { - $tokenlength = 15; - } + // Get the survey settings for token length + //$this->load->model("surveys_model"); + $tlresult = Survey::model()->findAllByAttributes(array("sid"=>$surveyid)); + if (isset($tlresult[0])) { + $tlrow = $tlresult[0]; + } + else + { + $tlrow = $tlresult; + } + $tokenlength = $tlrow['tokenlength']; + //if tokenlength is not set or there are other problems use the default value (15) + if(!isset($tokenlength) || $tokenlength == '') + { + $tokenlength = 15; + } while ($mayinsert != true) { @@ -178,7 +170,7 @@ function actionIndex($surveyid = null) $starttime = sanitize_xss_string(Yii::app()->request->getPost('startdate')); $endtime = sanitize_xss_string(Yii::app()->request->getPost('enddate')); /*$postattribute1=sanitize_xss_string(strip_tags(returnGlobal('register_attribute1'))); - $postattribute2=sanitize_xss_string(strip_tags(returnGlobal('register_attribute2'))); */ + $postattribute2=sanitize_xss_string(strip_tags(returnGlobal('register_attribute2'))); */ // Insert new entry into tokens db Tokens_dynamic::sid($thissurvey['sid']); @@ -201,7 +193,7 @@ function actionIndex($surveyid = null) $result = $connect->Execute($query, array($postfirstname, $postlastname, returnGlobal('register_email'), - 'OK', + 'OK', $newtoken) // $postattribute1, $postattribute2) @@ -246,7 +238,7 @@ function actionIndex($surveyid = null) $subject=ReplaceFields($subject, $fieldsarray); $html = ""; //Set variable - $sitename = Yii::app()->getConfig('sitename'); + $sitename = Yii::app()->getConfig('sitename'); if (SendEmailMessage($message, $subject, Yii::app()->request->getPost('register_email'), $from, $sitename,$useHtmlEmail,getBounceEmail($surveyid))) { @@ -276,7 +268,7 @@ function actionIndex($surveyid = null) sendCacheHeaders(); doHeader(); - Yii::app()->lang = $clang; + Yii::app()->lang = $clang; foreach(file("$thistpl/startpage.pstpl") as $op) { echo templatereplace($op); @@ -293,4 +285,4 @@ function actionIndex($surveyid = null) doFooter(); } - } +} diff --git a/application/controllers/admin/dataentry.php b/application/controllers/admin/dataentry.php index d01cda5a91e..349c9db21ff 100644 --- a/application/controllers/admin/dataentry.php +++ b/application/controllers/admin/dataentry.php @@ -682,7 +682,7 @@ public function editdata($subaction, $id, $surveyid, $language='') break; case "D": //DATE $thisdate=''; - $dateformatdetails = aGetDateFormatDataForQid($qidattributes, $surveyid) + $dateformatdetails = getDateFormatDataForQID($qidattributes, $surveyid) ; if ($idrow[$fname['fieldname']]!='') { @@ -693,7 +693,7 @@ public function editdata($subaction, $id, $surveyid, $language='') $thisdate = ''; } - if(bCanShowDatePicker($dateformatdetails)) + if(canShowDatePicker($dateformatdetails)) { $goodchars = str_replace( array("m","d","y", "H", "M"), "", $dateformatdetails['dateformat']); $goodchars = "0123456789".$goodchars[0]; @@ -1508,7 +1508,7 @@ public function update() else { $qidattributes = getQuestionAttributeValues($irow['qid'], $irow['type']); - $dateformatdetails = aGetDateFormatDataForQid($qidattributes, $thissurvey); + $dateformatdetails = getDateFormatDataForQID($qidattributes, $thissurvey); $items = array($thisvalue,$dateformatdetails['phpdate']); $this->getController()->loadLibrary('Date_Time_Converter'); @@ -1775,7 +1775,7 @@ public function insert() { Yii::app()->loadLibrary('Date_Time_Converter'); $qidattributes = getQuestionAttributeValues($irow['qid'], $irow['type']); - $dateformatdetails = aGetDateFormatDataForQid($qidattributes, $thissurvey); + $dateformatdetails = getDateFormatDataForQID($qidattributes, $thissurvey); $datetimeobj = new Date_Time_Converter($_POST[$fieldname],$dateformatdetails['phpdate']); $insert_data[$fieldname] = $datetimeobj->convert("Y-m-d H:i:s"); } diff --git a/application/helpers/admin/statistics_helper.php b/application/helpers/admin/statistics_helper.php index 4f51d876e87..688be19219b 100644 --- a/application/helpers/admin/statistics_helper.php +++ b/application/helpers/admin/statistics_helper.php @@ -13,52 +13,6 @@ * $Id$ */ -/* -* We need this later: -* 1 - Array Dual Scale -* 5 - 5 Point Choice -* A - Array (5 Point Choice) -* B - Array (10 Point Choice) -* C - Array (Yes/No/Uncertain) -* D - Date -* E - Array (Increase, Same, Decrease) -* F - Array -* G - Gender -* H - Array by column -* I - Language Switch -* K - Multiple Numerical Input -* L - List (Radio) -* M - Multiple choice -* N - Numerical Input -* O - List With Comment -* P - Multiple choice with comments -* Q - Multiple Short Text -* R - Ranking -* S - Short Free Text -* T - Long Free Text -* U - Huge Free Text -* X - Boilerplate Question -* Y - Yes/No -* ! - List (Dropdown) -* : - Array multiple drop down -* ; - Array multiple texts -* | - File Upload - - -Debugging help: -echo ''; -*/ - -//split up results to extend statistics -> NOT WORKING YET! DO NOT ENABLE THIS! -//$showcombinedresults = 0; - - - - - -//don't call this script directly! -if (isset($_REQUEST['homedir'])) {die('You cannot start this script directly');} - /** * @@ -276,6 +230,7 @@ function createChart($qid, $sid, $type, $lbl, $gdata, $grawdata, $cache) return $cachefilename; } + /** * Return data to populate a Google Map * @param string$sField Field name @@ -300,6 +255,7 @@ function getQuestionMapData($sField, $qsid) return $d; } + /** * Generates statistics * @@ -2567,7 +2523,7 @@ function generate_statistics($surveyid, $allfields, $q2show='all', $usegraph=0, //edit labels and put them into antoher array $lbl[] = wordwrap(flattenText("$al[1] ($row[0])"), 25, "\n"); // NMO 2009-03-24 - $lblrtl[] = utf8_strrev(wordwrap(flattenText("$al[1] )$row[0]("), 25, "\n")); // NMO 2009-03-24 + $lblrtl[] = UTF8Strrev(wordwrap(flattenText("$al[1] )$row[0]("), 25, "\n")); // NMO 2009-03-24 } //end while -> loop through results @@ -3446,9 +3402,12 @@ function generate_statistics($surveyid, $allfields, $q2show='all', $usegraph=0, } -////XXXXXX***// -//simple function to square a value +/** +* Simple function to square a value +* +* @param mixed $number Value to square +*/ function square($number) { if($number == 0) @@ -3459,7 +3418,6 @@ function square($number) { $squarenumber = $number * $number; } - return $squarenumber; } diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index 2b0a3365315..3349707beb3 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -1762,7 +1762,7 @@ function getExtendedAnswer($surveyid, $action, $fieldcode, $value, $format='') case 'D': if (trim($value)!='') { $qidattributes = getQuestionAttributeValues($fields['qid']); - $dateformatdetails = aGetDateFormatDataForQid($qidattributes, $surveyid); + $dateformatdetails = getDateFormatDataForQID($qidattributes, $surveyid); $value=convertDateTimeFormat($value,"Y-m-d H:i:s",$dateformatdetails['phpdate']); } break; @@ -2850,7 +2850,7 @@ function buildLabelSetCheckSumArray() /** * Returns a flat array with all question attributes for the question only (and the qid we gave it)! * @param $iQID The question ID -* @return array{attribute=>value, attribute=>value} or false if the question ID does not exist (anymore) +* @return array$bOrderByNative=>value, attribute=>value} or false if the question ID does not exist (anymore) */ function getQuestionAttributeValues($iQID) { diff --git a/application/helpers/frontend_helper.php b/application/helpers/frontend_helper.php index b3a698b8238..e0316a5bc15 100644 --- a/application/helpers/frontend_helper.php +++ b/application/helpers/frontend_helper.php @@ -950,7 +950,7 @@ function aCheckInput($surveyid, $move,$backok=null) { // $_SESSION['survey_'.$surveyid][$fieldinfo['fieldname']] now contains the crappy value parsed by // Date_Time_Converter in save.php. We can leave it there. We just do validation here. - $dateformatdetails = aGetDateFormatDataForQid($qidattributes, $thissurvey); + $dateformatdetails = getDateFormatDataForQID($qidattributes, $thissurvey); $datetimeobj = DateTime::createFromFormat($dateformatdetails['phpdate'], $_POST[$field]); if(!$datetimeobj) { diff --git a/application/helpers/surveytranslator_helper.php b/application/helpers/surveytranslator_helper.php index 9e6527f2e7b..61f432aca45 100644 --- a/application/helpers/surveytranslator_helper.php +++ b/application/helpers/surveytranslator_helper.php @@ -1,4 +1,5 @@ -lang; @@ -533,7 +533,7 @@ function getRadixPointData($format=-1) * @returns string * */ - function sPhpdateFromDateformat($sDateformat) + function getPHPDateFromDateFormat($sDateformat) { // Note that order is relevant (longer strings first) $aFmts = array( @@ -590,7 +590,7 @@ function sPhpdateFromDateformat($sDateformat) * @returns string * */ - function sJsdateFromDateformat($sDateformat) + function getJSDateFromDateFormat($sDateformat) { // The only difference from dateformat is that Jsdate does not support truncated years return str_replace("yyyy", "yy", $sDateformat); @@ -605,20 +605,20 @@ function sJsdateFromDateformat($sDateformat) * @returns array * */ - function aGetDateFormatDataForQid($aQidAttributes, $mThisSurvey) + function getDateFormatDataForQID($aQidAttributes, $mThisSurvey) { if (trim($aQidAttributes['date_format'])!='') { $aDateFormatDetails = array(); $aDateFormatDetails['dateformat'] = trim($aQidAttributes['date_format']); - $aDateFormatDetails['phpdate'] = sPhpdateFromDateformat($aDateFormatDetails['dateformat']); - $aDateFormatDetails['jsdate'] = sJsdateFromDateformat($aDateFormatDetails['dateformat']); + $aDateFormatDetails['phpdate'] = getPHPDateFromDateFormat($aDateFormatDetails['dateformat']); + $aDateFormatDetails['jsdate'] = getJSDateFromDateFormat($aDateFormatDetails['dateformat']); } else { if(!is_array($mThisSurvey)) { - $mThisSurvey = array('surveyls_dateformat' => aGetDateFormatForSid($mThisSurvey)); + $mThisSurvey = array('surveyls_dateformat' => getDateFormatForSID($mThisSurvey)); } $aDateFormatDetails = getDateFormatData($mThisSurvey['surveyls_dateformat']); } @@ -634,7 +634,7 @@ function aGetDateFormatDataForQid($aQidAttributes, $mThisSurvey) * @returns integer * */ - function aGetDateFormatForSid($surveyid, $languagecode='') + function getDateFormatForSID($surveyid, $languagecode='') { if (!isset($languagecode) || $languagecode=='') { @@ -659,7 +659,7 @@ function aGetDateFormatForSid($surveyid, $languagecode='') * @returns integer * */ - function bCanShowDatePicker($dateformatdetails, $dateformats=null) + function canShowDatePicker($dateformatdetails, $dateformats=null) { if(is_null($dateformats)) { @@ -744,8 +744,8 @@ function getLanguageDetails($codetosearch) } } - function getLanguageDataRestricted($orderbynative=false) { - $aLanguageData=getLanguageData($orderbynative); + function getLanguageDataRestricted($bOrderByNative=false) { + $aLanguageData=getLanguageData($bOrderByNative); if (trim(Yii::app()->getConfig('restrictToLanguages'))!='') { @@ -760,7 +760,8 @@ function getLanguageDataRestricted($orderbynative=false) { return $aArray; } - function user_sort($a, $b) { + + function userSort($a, $b) { // smarts is all-important, so sort it first if($a['description'] >$b['description']) { @@ -771,7 +772,8 @@ function user_sort($a, $b) { } } - function user_sort_native($a, $b) { + + function userSortNative($a, $b) { // smarts is all-important, so sort it first if($a['nativedescription'] >$b['nativedescription']) { @@ -783,27 +785,17 @@ function user_sort_native($a, $b) { } - /* // future languages - // Afrikaans - $supportedLanguages['za']['nativedescription'] = 'Afrikaans'; - // Irish - $supportedLanguages['ie']['nativedescription'] = 'Gaeilge'; - // Serbian - $supportedLanguages['yu']['nativedescription'] = 'Srpski'; - */ - - /** * This function support the ability NOT to reverse numbers (for example when you output * a phrase as a parameter for a SWF file that can't handle RTL languages itself, but * obviously any numbers should remain the same as in the original phrase). - * Note that it can be used just as well for UTF-8 usages if you want the numbers to remain intact + * Note that it can be used just as well for UTF-8 usages if you want the numbers to remain intact * * @param string $str * @param boolean $reverse_numbers * @return string */ - function utf8_strrev($str, $reverse_numbers=false) { + function UTF8Strrev($str, $reverse_numbers=false) { preg_match_all('/./us', $str, $ar); if ($reverse_numbers) return join('',array_reverse($ar[0])); diff --git a/application/models/Survey.php b/application/models/Survey.php index 7c2cc0ff0bb..fe1f9a0b0c8 100644 --- a/application/models/Survey.php +++ b/application/models/Survey.php @@ -40,18 +40,18 @@ public function primaryKey() return 'sid'; } - /** - * Returns the static model of Settings table - * - * @static - * @access public - * @param string $class - * @return CActiveRecord - */ - public static function model($class = __CLASS__) - { - return parent::model($class); - } + /** + * Returns the static model of Settings table + * + * @static + * @access public + * @param string $class + * @return CActiveRecord + */ + public static function model($class = __CLASS__) + { + return parent::model($class); + } /** * Returns this model's relations @@ -120,11 +120,11 @@ public function getAdditionalLanguages() } /** - * Returns the additional token attributes - * - * @access public - * @return array - */ + * Returns the additional token attributes + * + * @access public + * @return array + */ public function getTokenAttributes() { // !!! Legacy records support @@ -139,13 +139,13 @@ public function getTokenAttributes() $fieldname = substr($attdescription, 0, strpos($attdescription, '=')); $desc = substr($attdescription, strpos($attdescription, '=') + 1); $fields[$fieldname] = array( - 'description' => $desc, - 'mandatory' => 'N', - 'show_register' => 'N', + 'description' => $desc, + 'mandatory' => 'N', + 'show_register' => 'N', ); $languagesettings[$fieldname] = $desc; } - $ls = Surveys_languagesettings::model()->findByAttributes(array('surveyls_survey_id' => $this->sid, 'surveyls_language' => $this->language)); + $ls = Surveys_languagesettings::model()->findByAttributes(array('surveyls_survey_id' => $this->sid, 'surveyls_language' => $this->language)); self::model()->updateByPk($this->sid, array('attributedescriptions' => serialize($fields))); $ls->surveyls_attributecaptions = serialize($languagesettings); $ls->save(); @@ -184,34 +184,34 @@ public function insertNewSurvey($data, $xssfiltering = false) if (isset($data['expires']) && trim($data['expires']) == '') $data['expires'] = null; - if($xssfiltering) - { - $filter = new CHtmlPurifier(); - $filter->options = array('URI.AllowedSchemes'=>array( - 'http' => true, - 'https' => true, - )); - $data["admin"] = $filter->purify($data["admin"]); - $data["adminemail"] = $filter->purify($data["adminemail"]); - $data["bounce_email"] = $filter->purify($data["bounce_email"]); - $data["faxto"] = $filter->purify($data["faxto"]); - } + if($xssfiltering) + { + $filter = new CHtmlPurifier(); + $filter->options = array('URI.AllowedSchemes'=>array( + 'http' => true, + 'https' => true, + )); + $data["admin"] = $filter->purify($data["admin"]); + $data["adminemail"] = $filter->purify($data["adminemail"]); + $data["bounce_email"] = $filter->purify($data["bounce_email"]); + $data["faxto"] = $filter->purify($data["faxto"]); + } $survey = new self; - foreach ($data as $k => $v) - $survey->$k = $v; - $survey->save(); + foreach ($data as $k => $v) + $survey->$k = $v; + $survey->save(); return $data['sid']; } /** - * Deletes a survey and all its data - * - * @access public - * @param int $iSurveyID - * @param bool @recursive - * @return void - */ + * Deletes a survey and all its data + * + * @access public + * @param int $iSurveyID + * @param bool @recursive + * @return void + */ public function deleteSurvey($iSurveyID, $recursive=true) { Survey::model()->deleteByPk($iSurveyID); diff --git a/application/models/Survey_dynamic.php b/application/models/Survey_dynamic.php index 19e0754a266..154a68c1644 100644 --- a/application/models/Survey_dynamic.php +++ b/application/models/Survey_dynamic.php @@ -1,118 +1,118 @@ $v) - { - $search = array('`', "'"); - $k = str_replace($search, '', $k); - $v = str_replace($search, '', $v); - $record->$k = $v; - } - return $record->save(); - } + /** + * Insert records from $data array + * + * @access public + * @param array $data + * @return boolean + */ + public function insertRecords($data) + { + $record = new self; + foreach ($data as $k => $v) + { + $search = array('`', "'"); + $k = str_replace($search, '', $k); + $v = str_replace($search, '', $v); + $record->$k = $v; + } + return $record->save(); + } - /** - * Deletes some records from survey's table - * according to specific condition - * - * @static - * @access public - * @param array $condition - * @return int - */ - public static function deleteSomeRecords($condition=FALSE) - { - $survey = new Survey_dynamic; - $criteria = new CDbCriteria; + /** + * Deletes some records from survey's table + * according to specific condition + * + * @static + * @access public + * @param array $condition + * @return int + */ + public static function deleteSomeRecords($condition=FALSE) + { + $survey = new Survey_dynamic; + $criteria = new CDbCriteria; - if( $condition != FALSE ) - { - foreach ($condition as $column => $value) - { - return $criteria->addCondition($column."=`".$value."`"); - } - } + if( $condition != FALSE ) + { + foreach ($condition as $column => $value) + { + return $criteria->addCondition($column."=`".$value."`"); + } + } - return $survey->deleteAll($criteria); - } + return $survey->deleteAll($criteria); + } -} + } ?> diff --git a/application/views/admin/dataentry/content_view.php b/application/views/admin/dataentry/content_view.php index e4ed237e13c..4851659d8c6 100644 --- a/application/views/admin/dataentry/content_view.php +++ b/application/views/admin/dataentry/content_view.php @@ -35,8 +35,8 @@