Skip to content

Commit

Permalink
Dev: use config to get default template
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Nov 28, 2017
1 parent 52895eb commit f044d7a
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 74 deletions.
5 changes: 3 additions & 2 deletions application/controllers/PrintanswersController.php
Expand Up @@ -26,7 +26,7 @@ class PrintanswersController extends LSYii_Controller
/* @var string : Default layout when using render : leave at bare actually : just send content */
public $layout = 'survey';
/* @var string the template name to be used when using layout */
public $sTemplate = 'default';
public $sTemplate;
/* @var string[] Replacement data when use templatereplace function in layout, @see templatereplace $replacements */
public $aReplacementData = array();
/* @var array Global data when use templatereplace function in layout, @see templatereplace $redata */
Expand Down Expand Up @@ -79,7 +79,8 @@ function actionView($surveyid, $printableexport = false)

//Survey is not finished or don't exist
if (!isset($_SESSION['survey_'.$iSurveyID]['srid']))
//display "sorry but your session has expired"

//display "sorry but your session has expired"
$this->sTemplate = $oTemplate->sTemplateName;
$error = $this->renderPartial("/survey/system/errorWarning", array(
'aErrors'=>array(
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/RegisterController.php
Expand Up @@ -27,7 +27,7 @@ class RegisterController extends LSYii_Controller
/* @var string : Default layout when using render : leave at bare actually : just send content */
public $layout = 'survey';
/* @var string the template name to be used when using layout */
public $sTemplate = 'default';
public $sTemplate;
/* @var string[] Replacement data when use templatereplace function in layout, @see templatereplace $replacements */
public $aReplacementData = array();
/* @var array Global data when use templatereplace function in layout, @see templatereplace $redata */
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/SurveyController.php
Expand Up @@ -20,7 +20,7 @@ class SurveyController extends LSYii_Controller
/* @var string : Default layout when using render : leave at bare actually : just send content */
public $layout = 'bare';
/* @var string the template name to be used when using layout */
public $sTemplate = 'default';
public $sTemplate;
/* @var string[] Replacement data when use templatereplace function in layout, @see templatereplace $replacements */
public $aReplacementData = array();
/* @var array Global data when use templatereplace function in layout, @see templatereplace $redata */
Expand Down Expand Up @@ -131,7 +131,7 @@ function renderExitMessage($iSurveyId, $sType, $aMessages = array(), $aUrl = nul
$aReplacementData['message'] = $message;
$aReplacementData['URL'] = $url;
$aReplacementData['title'] = $error; // Adding this to replacement data : allow to update title (for example) : @see https://bugs.limesurvey.org/view.php?id=9106 (but need more)

$oSurvey = Survey::model()->findByPk($iSurveyId);
$oTemplate = $oSurvey->templateModel;

Expand Down
13 changes: 3 additions & 10 deletions application/controllers/SurveysController.php
Expand Up @@ -9,7 +9,7 @@ class SurveysController extends LSYii_Controller
/* @var string : Default layout when using render : leave at bare actually : just send content */
public $layout = 'public';
/* @var string the template name to be used when using layout */
public $sTemplate = 'default';
public $sTemplate;
/* @var string[] Replacement data when use templatereplace function in layout, @see templatereplace $replacements */
public $aReplacementData = array();
/* @var array Global data when use templatereplace function in layout, @see templatereplace $redata */
Expand All @@ -27,15 +27,8 @@ public function actionPublicList($lang = null)
}


$oTemplate = Template::model()->getInstance(Yii::app()->getConfig("defaulttheme"));
//$oTemplate->registerAssets();


$oTemplate = Template::model()->getInstance(Yii::app()->getConfig("defaulttheme"));
$this->sTemplate = $oTemplate->sTemplateName;
//Yii::app()->clientScript->registerPackage( 'survey-template' );
//Yii::app()->clientScript->registerPackage( 'survey-template-'.$oTemplate->sTemplateName );
//var_dump('survey-template-'.$oTemplate->sTemplateName);


$aData = array(
'publicSurveys' => Survey::model()->active()->open()->public()->with('languagesettings')->findAll(),
Expand Down Expand Up @@ -81,4 +74,4 @@ public function actionError()
}
}

}
}
8 changes: 1 addition & 7 deletions application/controllers/admin/printablesurvey.php
Expand Up @@ -77,13 +77,7 @@ function index($surveyid, $lang = null)
$surveyexpirydate = '';
}
//Fix $templatename : control if print_survey.pstpl exist
$oTemplate = Template::model()->getTemplateConfiguration($templatename);
if ($oTemplate->pstplPath.DIRECTORY_SEPARATOR.'print_survey.pstpl') {
} elseif (is_file(getTemplatePath(Yii::app()->getConfig("defaulttheme")).DIRECTORY_SEPARATOR.'print_survey.pstpl')) {
$templatename = Yii::app()->getConfig("defaulttheme");
} else {
$templatename = "default";
}
$oTemplate = Template::model()->getTemplateConfiguration($templatename);

$sFullTemplatePath = $oTemplate->path;
$sFullTemplateUrl = Template::model()->getTemplateURL($templatename)."/";
Expand Down
10 changes: 4 additions & 6 deletions application/controllers/admin/themes.php
Expand Up @@ -165,7 +165,7 @@ public function upload()
false,
false
);

} else if ($action == 'templateupload') {
if (Yii::app()->getConfig('demoMode')) {
Yii::app()->user->setFlash('error', gT("Demo mode: Uploading templates is disabled."));
Expand Down Expand Up @@ -374,7 +374,7 @@ public function index($editfile = '', $screenname = 'welcome', $templatename = '
if (!Template::checkIfTemplateExists($templatename)) {
// Redirect to the default template
Yii::app()->setFlashMessage(sprintf(gT('Theme %s does not exist.'), htmlspecialchars($templatename, ENT_QUOTES)), 'error');
$this->getController()->redirect(array('admin/themes/sa/view/', 'templatename'=>'default'));
$this->getController()->redirect(array('admin/themes/sa/view/', 'templatename'=> Yii::app()->getConfig("defaulttheme") ));
}

/* Keep Bootstrap Package clean after loading template : because template can update boostrap */
Expand All @@ -384,14 +384,12 @@ public function index($editfile = '', $screenname = 'welcome', $templatename = '
$aViewUrls = $this->_initialise($templatename, $screenname, $editfile, true, true);
} catch (Exception $ex) {
Yii::app()->user->setFlash('error', $ex->getMessage());
$this->getController()->redirect(array('admin/themes/sa/view/', 'templatename'=>'default'));
$this->getController()->redirect(array('admin/themes/sa/view/', 'templatename'=>Yii::app()->getConfig("defaulttheme") ));
}

App()->getClientScript()->reset();
Yii::app()->clientScript->packages['bootstrap'] = $aBootstrapPackage;
// App()->getClientScript()->registerScriptFile( App()->getConfig('adminscripts') . 'admin_core.js');
App()->getClientScript()->registerScriptFile(App()->getConfig('adminscripts').'templates.js');
// App()->getClientScript()->registerScriptFile( App()->getConfig('adminscripts') . 'notifications.js');
App()->getClientScript()->registerPackage('ace');
App()->getClientScript()->registerPackage('jsuri');
$aData['fullpagebar']['returnbutton'] = true;
Expand Down Expand Up @@ -555,7 +553,7 @@ public function delete($templatename)
$globalDefaultIsGettingDeleted = Yii::app()->getConfig('defaulttheme') == $templatename;

if ($globalDefaultIsGettingDeleted) {
setGlobalSetting('defaulttheme', 'default');
setGlobalSetting('defaulttheme', Yii::app()->getConfig("defaulttheme"));
}

foreach ($surveys as $s) {
Expand Down
67 changes: 34 additions & 33 deletions application/helpers/remotecontrol/remotecontrol_handle.php
Expand Up @@ -26,12 +26,12 @@ public function __construct(AdminController $controller)
*
* Using this function you can create a new XML-RPC/JSON-RPC session key.
* This is mandatory for all following LSRC2 function calls.
*
*
* * In case of success : Return the session key in string
* * In case of error:
* * for protocol-level errors (invalid format etc), an error message.
* * For invalid username and password, returns a null error and the result body contains a 'status' name-value pair with the error message.
*
*
* @access public
* @param string $username
* @param string $password
Expand Down Expand Up @@ -79,7 +79,7 @@ public function release_session_key($sSessionKey)
* Get a global setting
*
* Function to query site settings. Can only be used by super administrators.
*
*
* @access public
* @param string $sSessionKey Auth Credentials
* @param string $sSetttingName Name of the setting to get
Expand Down Expand Up @@ -108,7 +108,7 @@ public function get_site_settings($sSessionKey, $sSetttingName)

/**
* Add an empty survey with minimum details
*
*
* This just tries to create an empty survey with the minimal settings.
*
* Failure status: Invalid session key, No permission, Faulty parameters, Creation Failed result
Expand All @@ -133,7 +133,8 @@ public function add_survey($sSessionKey, $iSurveyID, $sSurveyTitle, $sSurveyLang
return array('status' => 'Faulty parameters');
}

$aInsertData = array('template' => 'default',
$aInsertData = array(
'template' => App()->getConfig('defaulttheme'),
'owner_id' => Yii::app()->session['loginID'],
'active' => 'N',
'language'=>$sSurveyLanguage,
Expand Down Expand Up @@ -179,7 +180,7 @@ public function add_survey($sSessionKey, $iSurveyID, $sSurveyTitle, $sSurveyLang
* Delete a survey.
*
* Failure status: Invalid session key, No permission
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID The ID of the Survey to be deleted
Expand All @@ -206,7 +207,7 @@ public function delete_survey($sSessionKey, $iSurveyID)
* Allow importing lss, csv, xls or survey zip archive in BASE 64 encoded.
*
* Failure status: Invalid session key, No permission, The import error
*
*
* @access public
* @param string $sSessionKey Auth Credentials
* @param string $sImportData String containing the BASE 64 encoded data of a lss, csv, txt or survey lsa archive
Expand Down Expand Up @@ -298,14 +299,14 @@ public function copy_survey($sSessionKey, $iSurveyID_org, $sNewname)
return array('status' => 'OK', 'newsid'=>$aImportResults['newsid']);
}
}

/**
* RPC Routine to get survey properties.
* Get properties of a survey
* Get properties of a survey
*
* All internal properties of a survey are available.
* @see \Survey for the list of available properties
*
*
* Failure status : Invalid survey ID, Invalid session key, No permission, No valid Data
*
* @access public
Expand Down Expand Up @@ -366,7 +367,7 @@ public function get_survey_properties($sSessionKey, $iSurveyID, $aSurveySettings
* In case of partial success : return an array with key as properties and value as boolean , true if saved with success.
*
* Failure status : Invalid survey ID, Invalid session key, No permission, No valid Data
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param integer $iSurveyID - ID of the Survey
Expand Down Expand Up @@ -471,7 +472,7 @@ public function activate_survey($sSessionKey, $iSurveyID)
* Export statistics of a survey to a user.
*
* Allow to export statistics available Returns string - base64 encoding of the statistics.
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID ID of the Survey
Expand Down Expand Up @@ -617,9 +618,9 @@ public function export_timeline($sSessionKey, $iSurveyID, $sType, $dStart, $dEnd

/**
* Get survey summary, regarding token usage and survey participation.
*
*
* Returns the requested value as string, or all status in an array
*
*
* Available status are
* * For Survey stats
* * completed_responses
Expand All @@ -632,14 +633,14 @@ public function export_timeline($sSessionKey, $iSurveyID, $sType, $dStart, $dEnd
* * token_opted_out
* * token_completed
* All available status can be sent using `all`
*
*
* Failure status : No available data, No such property, Invalid session key, No permission
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID ID of the Survey to get summary
* @param string $sStatName (optional) Name of the summary option, or all to send all in an array (all by default)
* @return string|array in case of success the requested value or an array of all values
* @return string|array in case of success the requested value or an array of all values
*/
public function get_summary($sSessionKey, $iSurveyID, $sStatName = 'all')
{
Expand Down Expand Up @@ -886,7 +887,7 @@ public function get_language_properties($sSessionKey, $iSurveyID, $aSurveyLocale
* Some properties can not be set
* * surveyls_language
* * surveyls_survey_id
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param integer $iSurveyID - ID of the Survey
Expand Down Expand Up @@ -1211,7 +1212,7 @@ public function get_group_properties($sSessionKey, $iGroupID, $aGroupSettings =
* Some attribute can not be set
* * sid
* * gid
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param integer $iGroupID - ID of the Survey
Expand Down Expand Up @@ -1433,7 +1434,7 @@ public function import_question($sSessionKey, $iSurveyID, $iGroupID, $sImportDat
}

libxml_disable_entity_loader($bOldEntityLoaderState); // Put back entity loader to its original state, to avoid contagion to other applications on the server


try {
$oQuestion->save();
Expand All @@ -1453,10 +1454,10 @@ public function import_question($sSessionKey, $iSurveyID, $iGroupID, $sImportDat

/**
* Get properties of a question in a survey.
*
*
* @see \Question for available properties.
* Some more properties are available_answers, subquestions, attributes, attributes_lang, answeroptions, defaultvalue
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iQuestionID ID of the question to get properties
Expand Down Expand Up @@ -1594,7 +1595,7 @@ public function get_question_properties($sSessionKey, $iQuestionID, $aQuestionSe
* * language
* * type
* * question_order in some condition (with dependecies)
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param integer $iQuestionID - ID of the question
Expand Down Expand Up @@ -1786,7 +1787,7 @@ public function delete_participants($sSessionKey, $iSurveyID, $aTokenIDs)
* Get settings of a token/participant of a survey.
*
* Allow to request for a specific participant. If more than one participant is returned with specified attribute(s) an error is returned.
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID ID of the Survey to get token properties
Expand Down Expand Up @@ -1946,7 +1947,7 @@ public function list_groups($sSessionKey, $iSurveyID)

/**
* Return the ids and propertries of token/participants of a survey.
*
*
* if $bUnused is true, user will get the list of uncompleted tokens (token_return functionality).
* Parameters iStart and iLimit are used to limit the number of results of this call.
*
Expand All @@ -1955,7 +1956,7 @@ public function list_groups($sSessionKey, $iSurveyID)
* * token : the token for this participant
* * participant_info : an array with firstname, lastname and email
* Parameter $aAttributes can be used to add more attribute in participant_info array
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID ID of the Survey to list participants
Expand Down Expand Up @@ -2140,7 +2141,7 @@ public function set_quota_properties($sSessionKey, $iQuotaId, $aQuotaData)
*
* If user is admin he can get surveys of every user (parameter sUser) or all surveys (sUser=null)
* Else only the surveys belonging to the user requesting will be shown.
*
*
* Returns array with
* * `sid` the ids of survey
* * `surveyls_title` the title of the survey
Expand Down Expand Up @@ -2189,13 +2190,13 @@ public function list_surveys($sSessionKey, $sUsername = null)
}
}

/**
/**
* Get list the ids and info of users.
*
*
* Returns array of ids and info.
*
* Failure status : No users found, Invalid session key, No permission (super admin is required)
*
*
* @param string $sSessionKey Auth credentials
* @param int $uid Optional parameter user id.
* @return array The list of users in case of success
Expand Down Expand Up @@ -2282,14 +2283,14 @@ public function activate_tokens($sSessionKey, $iSurveyID, $aAttributeFields = ar
* Returns array of results of sending
*
* Default behaviour is to send register emails to not invited, not reminded, not completed and in valid frame date participant.
*
*
* $overrideAllConditions replaces this default conditions for selecting the participants. A typical use case is to select only one participant
* ````
* $overrideAllConditions = Array();
* $overrideAllConditions[] = 'tid = 2';
* $response = $myJSONRPCClient->mail_registered_participants( $sessionKey, $survey_id, $overrideAllConditions );
* ````
*
*
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID ID of the Survey that participants belong
Expand Down Expand Up @@ -2948,7 +2949,7 @@ public function get_uploaded_files($sSessionKey, $iSurveyID, $sToken)
$uploaded_files = array();
foreach ($oResponse->getFiles() as $aFile) {
$sFileRealName = Yii::app()->getConfig('uploaddir')."/surveys/".$iSurveyID."/files/".$aFile['filename'];

if (!file_exists($sFileRealName)) {
return array('status' => 'Could not find uploaded files');
}
Expand Down

0 comments on commit f044d7a

Please sign in to comment.