Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:LimeSurvey/LimeSurvey.git int…
Browse files Browse the repository at this point in the history
…o develop

# Conflicts:
#	application/helpers/frontend_helper.php
  • Loading branch information
Shnoulle committed Dec 8, 2016
2 parents 1f46d1a + 8efed2a commit 9811bd7
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 3 deletions.
86 changes: 85 additions & 1 deletion application/controllers/admin/update.php
Expand Up @@ -69,14 +69,98 @@ public function index()
$updateModel = new UpdateForm();
$serverAnswer = $updateModel->getUpdateInfo($buttons);
$aData['serverAnswer'] = $serverAnswer;

$aData['fullpagebar']['update'] = true;
$this->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'comfortupdate/comfortupdate.js');
$this->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'comfortupdate/buildComfortButtons.js');
$this->registerScriptFile( 'ADMIN_SCRIPT_PATH', 'comfortupdate/displayComfortStep.js');

$this->_renderWrappedTemplate('update', '_updateContainer', $aData);
}

public function managekey()
{
$buttons = 1;
$updateModel = new UpdateForm();
$serverAnswer = $updateModel->getUpdateInfo($buttons);
$aData['serverAnswer'] = $serverAnswer;
$aData['fullpagebar']['saveandclosebutton']['form'] = true;
$aData['fullpagebar']['closebutton']['url'] = 'admin/update';
$aData['updateKey'] = $updateKey = SettingGlobal::model()->findByPk('update_key');

//$this->controller->renderPartial('//admin/update/updater/welcome/_subscribe', array('serverAnswer' => $serverAnswer), false, false);
if(!$updateKey) {
$this->_renderWrappedTemplate('update/manage/', 'subscribe', $aData);
}else{
$this->_renderWrappedTemplate('update/manage/', 'manage_key', $aData);
}

}

public function manage_submitkey()
{
$buttons = 1;
$updateModel = new UpdateForm();
$serverAnswer = $updateModel->getUpdateInfo($buttons);
$aData['serverAnswer'] = $serverAnswer;
$aData['fullpagebar']['saveandclosebutton']['form'] = true;
$aData['fullpagebar']['closebutton']['url'] = 'admin/update';
$aData['updateKey'] = $updateKey = SettingGlobal::model()->findByPk('update_key');

if (Permission::model()->hasGlobalPermission('superadmin'))
{
if ( Yii::app()->request->getPost('keyid') )
{
// We trim it, just in case user added a space...
$submittedUpdateKey = trim(Yii::app()->request->getPost('keyid'));

$updateModel = new UpdateForm();
$check = $updateModel->checkUpdateKeyonServer($submittedUpdateKey);
if ($check->result )
{
// If the key is validated by server, we update the local database with this key
$updateKey = $updateModel->setUpdateKey($submittedUpdateKey);
Yii::app()->session['flashmessage'] = gT("Your key has been updated and validated! You can now use ComfortUpdate.");
$aData['updateKey'] = $updateKey = SettingGlobal::model()->findByPk('update_key');
// then, we render the what returned the server (views and key infos or error )
$this->_renderWrappedTemplate('update/manage/', 'manage_key', $aData);
}
else
{
switch ($check->error)
{
case 'out_of_updates':
$title = "Your update key is out of update !";
$message = "you should first renew this key before using it, or try to enter a new one !";
$buttons = 1;
break;

case 'expired':
$title = "Your update key has expired!";
$message = "you should first renew this key before using it, or try to enter a new one !";
$buttons = 1;
break;

case 'not_found':
$title = "Unknown update key !";
$message = "Your key is unknown by the update server.";
$buttons = 3;
break;

case 'key_null':
$title = "key can't be null !";
$message = "";
$buttons = 3;
break;
}

App()->setFlashMessage('<strong>'.gT($title).'</strong> '.gT($message),'error');
$this->_renderWrappedTemplate('update/manage/', 'subscribe', $aData);
}

}
}
}

/**
* This function return the update buttons for stable branch
* @return html the button code
Expand Down
32 changes: 32 additions & 0 deletions application/helpers/frontend_helper.php
Expand Up @@ -2521,3 +2521,35 @@ function getSideBodyClass($sideMenustate = false)

return $class;
}


/**
* Render the question view.
* @deprecated this function was not used here , we render , not renderPartial
* By default, it just renders the required core view from application/views/survey/...
* If the Survey template is configured to overwrite the question views, then the function will check if the required view exist in the template directory
* and then will use this one to render the question.
*
* @param string $sView name of the view to be rendered.
* @param array $aData data to be extracted into PHP variables and made available to the view script
* @param boolean $bReturn whether the rendering result should be returned instead of being displayed to end users (should be always true)
*/
function doFRender($sView, $aData, $bReturn=true)
{
global $thissurvey;
if(isset($thissurvey['template']))
{
$sTemplate = $thissurvey['template'];
$oTemplate = Template::model()->getInstance($sTemplate); // we get the template configuration
if($oTemplate->overwrite_question_views===true && Yii::app()->getConfig('allow_templates_to_overwrite_views')) // If it's configured to overwrite the views
{
$requiredView = $oTemplate->viewPath.ltrim($sView, '/'); // Then we check if it has its own version of the required view
if( file_exists($requiredView.'.php') ) // If it the case, the function will render this view
{
Yii::setPathOfAlias('survey.template.view', $requiredView); // to render a view from an absolute path outside of application/, path alias must be used.
$sView = 'survey.template.view'; // See : http://www.yiiframework.com/doc/api/1.1/CController#getViewFile-detail
}
}
}
return Yii::app()->getController()->renderPartial($sView, $aData, $bReturn);
}
4 changes: 2 additions & 2 deletions application/models/Timing.php
Expand Up @@ -51,7 +51,7 @@ public static function model($iSurveyId = null)
}
return self::$_models[$iSurveyId];
}
new Exception('iSurveyId missing in static call.');
throw new Exception('iSurveyId missing in static call.');
}


Expand Down Expand Up @@ -84,4 +84,4 @@ public function getMetaData()

}

?>
?>
7 changes: 7 additions & 0 deletions application/views/admin/super/fullpagebar_view.php
Expand Up @@ -56,6 +56,13 @@
</a>
<?php endif;?>

<?php if(isset($fullpagebar['update'])):?>
<a href="<?php echo $this->createUrl('admin/update/sa/managekey/');?>" class="btn btn-default">
<span class="fa fa-key text-success"></span>
<?php eT("Manage your key");?>
</a>
<?php endif;?>

<!-- Return -->
<?php if(isset($fullpagebar['returnbutton']['url'])):?>
<a class="btn btn-default" href="<?php echo $this->createUrl($fullpagebar['returnbutton']['url']); ?>" role="button">
Expand Down
33 changes: 33 additions & 0 deletions application/views/admin/update/manage/manage_key.php
@@ -0,0 +1,33 @@
<div class="col-lg-12 list-surveys" id="comfortUpdateGeneralWrap">
<h3>
<span id="comfortUpdateIcon" class="icon-shield text-success"></span>
<?php eT('ComfortUpdate'); ?>
<?php if(YII_DEBUG):?>
<small>server:<em class="text-warning"> <?php echo Yii::app()->getConfig("comfort_update_server_url");?></em></small>
<?php endif;?>
</h3>

<?php if($updateKey): ?>
ok
<?php else:?>
<div class="jumbotron message-box ">
<h2 class="text-success">Pwet</h2>
<p class="lead">
<?php eT('The LimeSurvey ComfortUpdate is a great feature to easily update to the latest version of LimeSurvey. To use it you will need an update key.');?>
</p>
<p>
<?php
$aopen = '<a href="https://www.limesurvey.org/en/your-account/your-details" target="_blank">';
$aclose = '</a>';
?>
<?php echo sprintf(gT("You can get a free trial update key from %syour account on the limesurvey.org website%s."),$aopen, $aclose); ?>
<?php
$aopen = '<a href="https://www.limesurvey.org/en/cb-registration/registers">';
$aclose = '</a>';
?><br>
<?php echo sprintf(gT("If you don't have an account on limesurvey.org, please %sregister first%s."),$aopen, $aclose);?></p>

</p>
</div>
<?php endif;?>
</div>
53 changes: 53 additions & 0 deletions application/views/admin/update/manage/subscribe.php
@@ -0,0 +1,53 @@
<?php
/**
* This file display the subscribe view
* The javascript inject it inside the div#updaterContainer, in the _updater view. (like any steps)
*/
?>
<div class="col-sm-12 list-surveys" id="comfortUpdateGeneralWrap">
<h3><span id="comfortUpdateIcon" class="icon-shield text-success"></span><?php eT("Subscribe to ComfortUpdate!");?></h3>

<div class="" style="width: 75%; margin: auto;">
<br/>
<p>
<?php eT('The LimeSurvey ComfortUpdate is a great feature to easily update to the latest version of LimeSurvey. To use it you will need an update key.');?></p><p>
<?php
$aopen = '<a href="https://www.limesurvey.org/en/your-account/your-details" target="_blank">';
$aclose = '</a>';
?>
<?php echo sprintf(gT("You can get a free trial update key from %syour account on the limesurvey.org website%s."),$aopen, $aclose); ?>
<?php
$aopen = '<a href="https://www.limesurvey.org/en/cb-registration/registers">';
$aclose = '</a>';
?><br>
<?php echo sprintf(gT("If you don't have an account on limesurvey.org, please %sregister first%s."),$aopen, $aclose);?></p>

<?php
echo CHtml::beginForm(App()->createUrl('/admin/update/sa/manage_submitkey'), 'post', array("id"=>""));
?>
<div class="form-group">
<?php
echo CHtml::label(gT('Enter your update key:'),'inputKey', array('class'=>'col-sm-2'));
?>
<div class='col-sm-2'>
<?php
echo CHtml::textField('keyid', '', array("id"=>"inputKey",'class'=>'form-control'));
?>
</div>
</div>
<?php
echo CHtml::submitButton('submit', array("class"=>"btn btn-default", "id"=>"submitKeyButton"));
?>
<a class="btn btn-default" href="<?php echo Yii::app()->createUrl("admin/update"); ?>" role="button" aria-disabled="false">
<?php eT("Cancel"); ?>
</a>
<?php echo CHtml::endForm();?>

</div>

<!-- this javascript code manage the step changing. It will catch the form submission, then load the ComfortUpdate for the required build -->
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl; ?>/scripts/admin/comfortupdate/comfortUpdateNextStep.js"></script>
<script>
$('#submitKeyForm').comfortUpdateNextStep({'step': 0});
</script>
</div>

0 comments on commit 9811bd7

Please sign in to comment.