Skip to content

Commit

Permalink
Dev : Random fixes/refactoring.
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@12350 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
gautamgupta committed Feb 4, 2012
1 parent 6be55f2 commit 90193c2
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 96 deletions.
62 changes: 31 additions & 31 deletions application/controllers/admin/assessments.php
Expand Up @@ -28,40 +28,40 @@ class Assessments extends Survey_Common_Action
* Routes to the correct sub-action
*
* @access public
* @param int $iSurveyId
* @param int $iSurveyID
* @return void
*/
public function index($iSurveyId)
public function index($iSurveyID)
{
$iSurveyId = sanitize_int($iSurveyId);
$iSurveyID = sanitize_int($iSurveyID);
$action = Yii::app()->request->getPost('action');

$languages = Survey::model()->findByPk($iSurveyId)->additionalLanguages;
$surveyLanguage = Survey::model()->findByPk($iSurveyId)->language;
$languages = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$surveyLanguage = Survey::model()->findByPk($iSurveyID)->language;

Yii::app()->session['FileManagerContext'] = "edit:assessments:{$iSurveyId}";
Yii::app()->session['FileManagerContext'] = "edit:assessments:{$iSurveyID}";

array_unshift($languages, $surveyLanguage); // makes an array with ALL the languages supported by the survey -> $assessmentlangs

Yii::app()->setConfig("baselang", $surveyLanguage);
Yii::app()->setConfig("assessmentlangs", $languages);

if ($action == "assessmentadd")
$this->_add($iSurveyId);
$this->_add($iSurveyID);
if ($action == "assessmentupdate")
$this->_update($iSurveyId);
$this->_update($iSurveyID);
if ($action == "assessmentdelete")
$this->_delete($iSurveyId, $_POST['id']);
$this->_delete($iSurveyID, $_POST['id']);

if (hasSurveyPermission($iSurveyId, 'assessments', 'read')) {
if (hasSurveyPermission($iSurveyID, 'assessments', 'read')) {
$clang = $this->getController()->lang;

if ($iSurveyId == '') {
if ($iSurveyID == '') {
show_error($clang->gT("No SID Provided"));
die();
}

$this->_showAssessments($iSurveyId, $action, $surveyLanguage, $clang);
$this->_showAssessments($iSurveyID, $action, $surveyLanguage, $clang);
}

}
Expand All @@ -82,24 +82,24 @@ protected function _renderWrappedTemplate($sAction = 'assessments', $aViewUrls =
parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData);
}

private function _showAssessments($iSurveyId, $action, $surveyLanguage, Limesurvey_lang $clang)
private function _showAssessments($iSurveyID, $action, $surveyLanguage, Limesurvey_lang $clang)
{
$assessments = Assessment::model()->findAllByAttributes(array('sid' => $iSurveyId));
$aData = $this->_collectGroupData($iSurveyId);
$assessments = Assessment::model()->findAllByAttributes(array('sid' => $iSurveyID));
$aData = $this->_collectGroupData($iSurveyID);
$headings = array($clang->gT("Scope"), $clang->gT("Question group"), $clang->gT("Minimum"), $clang->gT("Maximum"));
$aData['actiontitle'] = $clang->gT("Add");
$aData['actionvalue'] = "assessmentadd";
$aData['editId'] = '';

if ($action == "assessmentedit" && hasSurveyPermission($iSurveyId, 'assessments', 'update')) {
if ($action == "assessmentedit" && hasSurveyPermission($iSurveyID, 'assessments', 'update')) {
$aData = $this->_collectEditData($surveyLanguage, $aData, $clang);
}

$surveyinfo = getSurveyInfo($iSurveyId);
$surveyinfo = getSurveyInfo($iSurveyID);
$aData['clang'] = $clang;
$aData['surveyinfo'] = $surveyinfo;
$aData['imageurl'] = Yii::app()->getConfig('imageurl');
$aData['surveyid'] = $iSurveyId;
$aData['surveyid'] = $iSurveyID;
$aData['headings'] = $headings;
$aData['assessments'] = $assessments;
$aData['assessmentlangs'] = Yii::app()->getConfig("assessmentlangs");
Expand All @@ -109,14 +109,14 @@ private function _showAssessments($iSurveyId, $action, $surveyLanguage, Limesurv

Yii::app()->loadHelper('admin/htmleditor');
if ($surveyinfo['assessments']!='Y')
$urls['message'] = array('title' => $clang->gT("Assessments mode not activated"), 'message' => sprintf($clang->gT("Assessment mode for this survey is not activated. You can activate it in the %s survey settings %s (tab 'Notification & data management')."),'<a href="'.$this->getController()->createUrl('/admin/survey/editsurveysettings/surveyid/'.$iSurveyId).'">','</a>'), 'class'=> 'warningheader');
$urls['message'] = array('title' => $clang->gT("Assessments mode not activated"), 'message' => sprintf($clang->gT("Assessment mode for this survey is not activated. You can activate it in the %s survey settings %s (tab 'Notification & data management')."),'<a href="'.$this->getController()->createUrl('/admin/survey/editsurveysettings/surveyid/'.$iSurveyID).'">','</a>'), 'class'=> 'warningheader');
$urls['assessments_view'][]= $aData;
$this->_renderWrappedTemplate('', $urls, $aData);
}

private function _collectGroupData($iSurveyId)
private function _collectGroupData($iSurveyID)
{
$groups = Groups::model()->findAllByAttributes(array('sid' => $iSurveyId));
$groups = Groups::model()->findAllByAttributes(array('sid' => $iSurveyID));
foreach ($groups as $group) {
$groupId = $group->attributes['gid'];
$groupName = $group->attributes['group_name'];
Expand All @@ -142,15 +142,15 @@ private function _collectEditData($surveyLanguage, array $aData, Limesurvey_lang
/**
* Inserts an assessment to the database. Receives input from POST
*/
private function _add($iSurveyId)
private function _add($iSurveyID)
{
if (hasSurveyPermission($iSurveyId, 'assessments', 'create')) {
if (hasSurveyPermission($iSurveyID, 'assessments', 'create')) {
$first = true;
$assessmentId = -1;
$languages = Yii::app()->getConfig("assessmentlangs");
foreach ($languages as $language)
{
$aData = $this->_getAssessmentPostData($iSurveyId, $language);
$aData = $this->_getAssessmentPostData($iSurveyID, $language);

if ($first == false) {
$aData['id'] = $assessmentId;
Expand All @@ -167,15 +167,15 @@ private function _add($iSurveyId)
/**
* Updates an assessment. Receives input from POST
*/
private function _update($iSurveyId)
private function _update($iSurveyID)
{
if (hasSurveyPermission($iSurveyId, 'assessments', 'update') && isset($_POST['id'])) {
if (hasSurveyPermission($iSurveyID, 'assessments', 'update') && isset($_POST['id'])) {

$aid = sanitize_int($_POST['id']);
$languages = Yii::app()->getConfig("assessmentlangs");
foreach ($languages as $language)
{
$aData = $this->_getAssessmentPostData($iSurveyId, $language);
$aData = $this->_getAssessmentPostData($iSurveyID, $language);
Assessment::updateAssessment($aid, $language, $aData);
}
}
Expand All @@ -184,14 +184,14 @@ private function _update($iSurveyId)
/**
* Deletes an assessment.
*/
private function _delete($iSurveyId, $assessmentId)
private function _delete($iSurveyID, $assessmentId)
{
if (hasSurveyPermission($iSurveyId, 'assessments', 'delete')) {
if (hasSurveyPermission($iSurveyID, 'assessments', 'delete')) {
Assessment::model()->deleteAllByAttributes(array('id' => $assessmentId));
}
}

private function _getAssessmentPostData($iSurveyId, $language)
private function _getAssessmentPostData($iSurveyID, $language)
{
if (!isset($_POST['gid']))
$_POST['gid'] = 0;
Expand All @@ -202,7 +202,7 @@ private function _getAssessmentPostData($iSurveyId, $language)
}

return array(
'sid' => $iSurveyId,
'sid' => $iSurveyID,
'scope' => sanitize_paranoid_string($_POST['scope']),
'gid' => sanitize_int($_POST['gid']),
'minimum' => sanitize_paranoid_string($_POST['minimum']),
Expand Down
22 changes: 10 additions & 12 deletions application/controllers/admin/authentication.php
Expand Up @@ -34,9 +34,9 @@ public function index()
{
$this->_redirectIfLoggedIn();
$sIp = Yii::app()->request->getUserHostAddress();
$canLogin = $this->_userCanLogin($sIp);
$bCanLogin = $this->_userCanLogin($sIp);

if ($canLogin && !is_array($canLogin))
if ($bCanLogin && !is_array($bCanLogin))
{
if (Yii::app()->request->getPost('action'))
{
Expand All @@ -52,7 +52,8 @@ public function index()
$this->_doRedirect();
die();
}
else {
else
{
$this->_renderWrappedTemplate('authentication', 'error', $aData);
}
}
Expand All @@ -63,7 +64,7 @@ public function index()
}
else
{
$this->_renderWrappedTemplate('authentication', 'error', $canLogin);
$this->_renderWrappedTemplate('authentication', 'error', $bCanLogin);
}
}

Expand All @@ -89,10 +90,10 @@ public function forgotpassword()
}
else
{
$postuser = Yii::app()->request->getPost('user');
$sUserName = Yii::app()->request->getPost('user');
$sEmailAddr = Yii::app()->request->getPost('email');

$aFields = User::model()->findAllByAttributes(array('users_name' => $postuser, 'email' => $sEmailAddr));
$aFields = User::model()->findAllByAttributes(array('users_name' => $sUserName, 'email' => $sEmailAddr));

if (count($aFields) < 1)
{
Expand Down Expand Up @@ -142,8 +143,8 @@ private function _sendPasswordEmail($sEmailAddr, $aFields)
}
else
{
$tmp = str_replace("{NAME}", '<strong>' . $aFields[0]['users_name'] . '</strong>', $clang->gT("Email to {NAME} ({EMAIL}) failed."));
$sMessage = str_replace("{EMAIL}", $sEmailAddr, $tmp) . '<br />';
$sTmp = str_replace("{NAME}", '<strong>' . $aFields[0]['users_name'] . '</strong>', $clang->gT("Email to {NAME} ({EMAIL}) failed."));
$sMessage = str_replace("{EMAIL}", $sEmailAddr, $sTmp) . '<br />';
}

return $sMessage;
Expand Down Expand Up @@ -320,15 +321,12 @@ private function _setLanguageSettings($user)
private function _checkForUsageOfDefaultPassword()
{
$clang = $this->getController()->lang;
Yii::app()->session['pw_notify'] = false;
if (strtolower($_POST['password']) === 'password')
{
Yii::app()->session['pw_notify'] = true;
Yii::app()->session['flashmessage'] = $clang->gT('Warning: You are still using the default password (\'password\'). Please change your password and re-login again.');
}
else
{
Yii::app()->session['pw_notify'] = false;
}
}

/**
Expand Down
57 changes: 25 additions & 32 deletions application/controllers/admin/dataentry.php
Expand Up @@ -222,7 +222,7 @@ private function _handleFileUpload($surveyid, $aData)

if (!$result) {
$aData['error_msg'] = sprintf($clang->gT("Import failed on record %d"), $recordcount);
$this->_renderWrappedTemplate('warning_header', $aData);
$this->_renderWrappedTemplate('dataentry', 'warning_header', $aData);
die();
}
else
Expand All @@ -237,7 +237,7 @@ private function _handleFileUpload($surveyid, $aData)
$aData['noid'] = Yii::app()->request->getPost('noid');
$aData['insertstyle'] = Yii::app()->request->getPost('insertstyle');

$this->_renderWrappedTemplate('vvimport_upload', $aData);
$this->_renderWrappedTemplate('dataentry', 'vvimport_upload', $aData);
}

private function _getFieldInfo($aFileContents)
Expand Down Expand Up @@ -279,7 +279,7 @@ private function _moveUploadedFile($aData)
$clang->gT("An error occurred uploading your file. This may be caused by incorrect permissions in your %s folder."),
Yii::app()->getConfig('tempdir')
);
$this->_renderWrappedTemplate('warning_header', $aData);
$this->_renderWrappedTemplate('dataentry', 'warning_header', $aData);
die();
}
return $the_full_file_path;
Expand All @@ -296,7 +296,7 @@ private function _showUploadForm($aEncodings, $surveyid, $aData)
$aData['charsetsout'] = $charsetsout;
$aData['display']['menu_bars']['browse'] = $this->getController()->lang->gT("Import VV file");

$this->_renderWrappedTemplate('vvimport', $aData);
$this->_renderWrappedTemplate('dataentry', 'vvimport', $aData);
}

private function _getUploadCharset($encodingsarray)
Expand Down Expand Up @@ -372,7 +372,7 @@ function import($surveyid)
//Get the menubar
$aData['display']['menu_bars']['browse'] = $clang->gT("Quick statistics");

$this->_renderWrappedTemplate('import', $aData);
$this->_renderWrappedTemplate('dataentry', 'import', $aData);
}
//elseif (isset($surveyid) && $surveyid && isset($oldtable))
else
Expand Down Expand Up @@ -451,12 +451,8 @@ function import($surveyid)
}
Yii::app()->session['flashmessage'] = sprintf($clang->gT("%s old response(s) and according timings were successfully imported."),$iRecordCount,$iRecordCountT);
}

$aData['display']['menu_bars']['browse'] = $clang->gT("Quick statistics");

$this->_renderWrappedTemplate('', $aData);
$this->getController()->redirect("/admin/browse/index/surveyid/{$surveyid}");
}

}
}

Expand Down Expand Up @@ -1410,7 +1406,7 @@ public function editdata($subaction, $id, $surveyid, $language='')
$aDataentryoutput .= "</form>\n";

$aViewUrls['output'] = $aDataentryoutput;
$this->_renderWrappedTemplate($aViewUrls, $aData);
$this->_renderWrappedTemplate('dataentry', $aViewUrls, $aData);
}
}

Expand Down Expand Up @@ -1442,7 +1438,7 @@ public function delete()
Yii::app()->loadHelper('database');
$delresult = dbExecuteAssoc($delquery) or safeDie ("Couldn't delete record $id<br />\n");

$this->_renderWrappedTemplate('delete', $aData);
$this->_renderWrappedTemplate('dataentry', 'delete', $aData);
}
}

Expand Down Expand Up @@ -1565,7 +1561,7 @@ public function update()
."</div>\n";

$aViewUrls['output'] = $aDataentryoutput;
$this->_renderWrappedTemplate($aViewUrls, $aData);
$this->_renderWrappedTemplate('dataentry', $aViewUrls, $aData);
}
}

Expand Down Expand Up @@ -1948,7 +1944,7 @@ public function insert()

$aData['dataentrymsgs'] = $aDataentrymsgs;

$this->_renderWrappedTemplate('insert', $aData);
$this->_renderWrappedTemplate('dataentry', 'insert', $aData);
}

}
Expand Down Expand Up @@ -2603,22 +2599,18 @@ public function view($surveyid, $lang=NULL)
$aData['surveyid'] = $surveyid;
$aData['sDataEntryLanguage'] = $sDataEntryLanguage;

if ($thissurvey['active'] == "Y")
if ($thissurvey['active'] == "Y" && $thissurvey['allowsave'] == "Y")
{
if ($thissurvey['allowsave'] == "Y")
{
$slangs = Survey::model()->findByPk($surveyid)->additionalLanguages;
$sbaselang = Survey::model()->findByPk($surveyid)->language;
array_unshift($slangs,$sbaselang);
$aData['slangs'] = $slangs;
$aData['baselang'] = $baselang;
}

$slangs = Survey::model()->findByPk($surveyid)->additionalLanguages;
$sbaselang = Survey::model()->findByPk($surveyid)->language;
array_unshift($slangs,$sbaselang);
$aData['slangs'] = $slangs;
$aData['baselang'] = $baselang;
}

$aViewUrls[] = 'active_html_view';

$this->_renderWrappedTemplate($aViewUrls, $aData);
$this->_renderWrappedTemplate('dataentry', $aViewUrls, $aData);
}
}

Expand Down Expand Up @@ -2733,18 +2725,19 @@ private function _array_filter_help($qidattributes, $surveyprintlang, $surveyid)
}

/**
* Renders template(s) wrapped in header and footer
*
* @param string|array $aViewUrls View url(s)
* @param array $aData Data to be passed on. Optional.
*/
protected function _renderWrappedTemplate($aViewUrls = array(), $aData = array())
* Renders template(s) wrapped in header and footer
*
* @param string $sAction Current action, the folder to fetch views from
* @param string|array $aViewUrls View url(s)
* @param array $aData Data to be passed on. Optional.
*/
protected function _renderWrappedTemplate($sAction = 'dataentry', $aViewUrls = array(), $aData = array())
{
if (!isset($aData['display']['menu_bars']['browse']))
{
$aData['display']['menu_bars']['browse'] = $this->getController()->lang->gT("Data entry");
}
parent::_renderWrappedTemplate('dataentry', $aViewUrls, $aData);
parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData);
}

}
Expand Down

0 comments on commit 90193c2

Please sign in to comment.