Skip to content

Commit

Permalink
Some coding guideline cleanups
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@12178 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Jan 24, 2012
1 parent 34c4f5a commit 9bfaf5d
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 307 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -12,7 +12,7 @@
*
* $Id$
*/
$config['versionnumber'] = "2.0yii_alpha";
$config['versionnumber'] = "2.0a2";
$config['dbversionnumber'] = 155;
$config['buildnumber'] = '';

Expand Down
122 changes: 57 additions & 65 deletions application/controllers/RegisterController.php
@@ -1,59 +1,51 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/

/**
* register
*
* @package LimeSurvey
* @copyright 2011
* @version $Id$
* @access public
*/
class RegisterController extends LSYii_Controller {

function actionAjaxregisterform($surveyid)
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/

/**
* register
*
* @package LimeSurvey
* @copyright 2011
* @version $Id$
* @access public
*/
class RegisterController extends LSYii_Controller {

function actionAJAXRegisterForm
($surveyid)
{
Yii::app()->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');
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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']);
Expand All @@ -201,7 +193,7 @@ function actionIndex($surveyid = null)
$result = $connect->Execute($query, array($postfirstname,
$postlastname,
returnGlobal('register_email'),
'OK',
'OK',
$newtoken)
// $postattribute1, $postattribute2)
Expand Down Expand Up @@ -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)))
{
Expand Down Expand Up @@ -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);
Expand All @@ -293,4 +285,4 @@ function actionIndex($surveyid = null)
doFooter();
}

}
}
8 changes: 4 additions & 4 deletions application/controllers/admin/dataentry.php
Expand Up @@ -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']]!='')
{
Expand All @@ -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];
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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");
}
Expand Down
58 changes: 8 additions & 50 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -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 '<script language="javascript" type="text/javascript">alert("HI");</script>';
*/

//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');}


/**
*
Expand Down Expand Up @@ -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
Expand All @@ -300,6 +255,7 @@ function getQuestionMapData($sField, $qsid)
return $d;
}


/**
* Generates statistics
*
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -3459,7 +3418,6 @@ function square($number)
{
$squarenumber = $number * $number;
}

return $squarenumber;
}

4 changes: 2 additions & 2 deletions application/helpers/common_helper.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/frontend_helper.php
Expand Up @@ -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)
{
Expand Down

0 comments on commit 9bfaf5d

Please sign in to comment.