Skip to content

Commit

Permalink
Merge branch '2.05' of github.com:LimeSurvey/LimeSurvey into 2.05
Browse files Browse the repository at this point in the history
Conflicts:
	application/controllers/InstallerController.php
  • Loading branch information
SamMousa committed Mar 26, 2013
2 parents c0e4712 + 462c66d commit 1bf48a4
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 208 deletions.
2 changes: 1 addition & 1 deletion application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)
);

if (!file_exists(APPPATH . 'config/config.php')) {
if (!file_exists(dirname(__FILE__) . '/config.php')) {
$userConfig = require(dirname(__FILE__) . '/config-sample-mysql.php');
} else {
$userConfig = require(dirname(__FILE__) . '/config.php');
Expand Down
100 changes: 57 additions & 43 deletions application/controllers/InstallerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ private function stepWelcome()

if (isset(Yii::app()->session['installerLang']))
{
$currentLanguage=Yii::app()->session['installerLang'];
$sCurrentLanguage=Yii::app()->session['installerLang'];
}
else
$currentLanguage='en';
$sCurrentLanguage='en';

foreach(getLanguageData(true, $currentLanguage) as $langkey => $languagekind)
foreach(getLanguageData(true, $sCurrentLanguage) as $sKey => $aLanguageInfo)
{
$languages[htmlspecialchars($langkey)] = sprintf('%s - %s', $languagekind['nativedescription'], $languagekind['description']);
$languages[htmlspecialchars($sKey)] = sprintf('%s - %s', $aLanguageInfo['nativedescription'], $aLanguageInfo['description']);
}
$aData['languages']=$languages;
$this->render('/installer/welcome_view',$aData);
Expand Down Expand Up @@ -184,9 +184,8 @@ private function stepLicense()
*/
public function stepViewLicense()
{
$filename = dirname(BASEPATH) . '/docs/license.txt';
header('Content-Type: text/plain; charset=UTF-8');
readfile($filename);
readfile(dirname(BASEPATH) . '/docs/license.txt');
exit;
}

Expand Down Expand Up @@ -344,22 +343,22 @@ private function stepDatabaseConfiguration()
}

//$aData array won't work here. changing the name
$values['title'] = $clang->gT('Database settings');
$values['descp'] = $clang->gT('Database settings');
$values['classesForStep'] = array('off','off','off','off','on','off');
$values['progressValue'] = 60;
$aValues['title'] = $clang->gT('Database settings');
$aValues['descp'] = $clang->gT('Database settings');
$aValues['classesForStep'] = array('off','off','off','off','on','off');
$aValues['progressValue'] = 60;

//it store text content
$values['adminoutputText'] = '';
$aValues['adminoutputText'] = '';
//it store the form code to be displayed
$values['adminoutputForm'] = '';
$aValues['adminoutputForm'] = '';

//if DB exist, check if its empty or up to date. if not, tell user LS can create it.
if (!$bDBExists)
{
Yii::app()->session['databaseDontExist'] = true;

$values['adminoutputText'].= "\t<tr bgcolor='#efefef'><td align='center'>\n"
$aValues['adminoutputText'].= "\t<tr bgcolor='#efefef'><td align='center'>\n"
."<strong>".$clang->gT("Database doesn't exist!")."</strong><br /><br />\n"
.$clang->gT("The database you specified does not exist:")."<br /><br />\n<strong>".$model->dbname."</strong><br /><br />\n"
.$clang->gT("LimeSurvey can attempt to create this database for you.")."<br /><br />\n";
Expand All @@ -375,8 +374,8 @@ private function stepDatabaseConfiguration()
Yii::app()->session['populatedatabase'] = true;

//$this->connection->database = $model->dbname;
// //$this->connection->createCommand("USE DATABASE `".$model->dbname."`")->execute();
$values['adminoutputText'].= sprintf($clang->gT('A database named "%s" already exists.'),$model->dbname)."<br /><br />\n"
// //$this->connection->createCommand("USE DATABASE `".$model->dbname."`")->execute();
$aValues['adminoutputText'].= sprintf($clang->gT('A database named "%s" already exists.'),$model->dbname)."<br /><br />\n"
.$clang->gT("Do you want to populate that database now by creating the necessary tables?")."<br /><br />";

$values['next'] = array(
Expand All @@ -392,12 +391,12 @@ private function stepDatabaseConfiguration()
//$this->connection->createCommand("USE DATABASE `$databasename`")->execute();
/* @todo Implement Upgrade */
//$output=CheckForDBUpgrades();
if ($output== '') {$values['adminoutput'].='<br />'.$clang->gT('LimeSurvey database is up to date. No action needed');}
else {$values['adminoutput'].=$output;}
$values['adminoutput'].= "<br />" . sprintf($clang->gT('Please <a href="%s">log in</a>.', 'unescaped'), $this->createUrl("/admin"));
if ($output== '') {$aValues['adminoutput'].='<br />'.$clang->gT('LimeSurvey database is up to date. No action needed');}
else {$aValues['adminoutput'].=$output;}
$aValues['adminoutput'].= "<br />" . sprintf($clang->gT('Please <a href="%s">log in</a>.', 'unescaped'), $this->createUrl("/admin"));
}
$values['clang'] = $clang;
$this->render('/installer/dbsettings_view', $values);
$aValues['clang'] = $clang;
$this->render('/installer/dbsettings_view', $aValues);
} else {
$this->render('/installer/dbconfig_view', $aData);
}
Expand Down Expand Up @@ -436,7 +435,7 @@ function stepCreateDb()

$aData['adminoutputForm'] = '';
// Yii doesn't have a method to create a database
$createDb = true; // We are thinking positive
$bCreateDB = true; // We are thinking positive
switch ($sDatabaseType)
{
case 'mysqli':
Expand All @@ -447,7 +446,7 @@ function stepCreateDb()
}
catch(Exception $e)
{
$createDb=false;
$bCreateDB=false;
}
break;
case 'mssql':
Expand All @@ -458,7 +457,7 @@ function stepCreateDb()
}
catch(Exception $e)
{
$createDb=false;
$bCreateDB=false;
}
break;
case 'postgres':
Expand All @@ -478,13 +477,13 @@ function stepCreateDb()
}
catch(Exception $e)
{
$createDb=false;
$bCreateDB=false;
}
break;
}

//$this->load->dbforge();
if ($createDb) //Database has been successfully created
if ($bCreateDB) //Database has been successfully created
{
$sDsn = self::_getDsn($sDatabaseType, $sDatabaseLocation, $sDatabasePort, $sDatabaseName, $sDatabaseUser, $sDatabasePwd);
$this->connection = new CDbConnection($sDsn, $sDatabaseUser, $sDatabasePwd);
Expand Down Expand Up @@ -629,7 +628,22 @@ private function stepOptionalConfiguration()
if ($this->connection->getActive() == true) {
$password_hash=hash('sha256', $defaultpass);
try {
$this->connection->createCommand()->insert('{{users}}', array('users_name' => $defaultuser, 'password' => $password_hash, 'full_name' => $siteadminname, 'parent_id' => 0, 'lang' => $defaultlang, 'email' => $siteadminemail, 'create_survey' => 1, 'create_user' => 1, 'participant_panel' => 1, 'delete_user' => 1, 'superadmin' => 1, 'configurator' => 1, 'manage_template' => 1, 'manage_label' => 1));
$user=new User;
$user->users_name=$defaultuser;
$user->password=$password_hash;
$user->full_name=$siteadminname;
$user->parent_id=0;
$user->lang=$defaultlang;
$user->email=$siteadminemail;
$user->save();

$permission=new Permission;
$permission->sid=0;
$permission->uid=$user->uid;
$permission->permission='global_superadmin';
$permission->read_p=1;
$permission->save();

$this->connection->createCommand()->insert("{{settings_global}}", array('stg_name' => 'SessionName', 'stg_value' => self::_getRandomString()));

foreach(array('sitename', 'siteadminname', 'siteadminemail', 'siteadminbounce', 'defaultlang') as $insert) {
Expand Down Expand Up @@ -706,23 +720,23 @@ private function _check_requirements(&$data)
*/
function check_HTML_image($result)
{
$label = array('wrong', 'right');
return sprintf('<img src="%s/installer/images/tick-%s.png" alt="Found" />', Yii::app()->baseUrl, $label[$result]);
$aLabelYesNo = array('wrong', 'right');
return sprintf('<img src="%s/installer/images/tick-%s.png" alt="Found" />', Yii::app()->baseUrl, $aLabelYesNo[$result]);
}


function is_writable_recursive($dir)
function is_writable_recursive($sDirectory)
{
$folder = opendir($dir);
while($file = readdir( $folder ))
if($file != '.' && $file != '..' &&
( !is_writable( $dir."/".$file ) ||
( is_dir( $dir."/".$file ) && !is_writable_recursive( $dir."/".$file ) ) ))
$sFolder = opendir($sDirectory);
while($sFile = readdir( $sFolder ))
if($sFile != '.' && $sFile != '..' &&
( !is_writable( $sDirectory."/".$sFile ) ||
( is_dir( $sDirectory."/".$sFile ) && !is_writable_recursive( $sDirectory."/".$sFile ) ) ))
{
closedir($folder);
closedir($sFolder);
return false;
}
closedir($folder);
closedir($sFolder);
return true;
}

Expand Down Expand Up @@ -984,13 +998,13 @@ function _writeConfigFile()
."| EXPLANATION OF VARIABLES"."\n"
."| -------------------------------------------------------------------"."\n"
."|" ."\n"
."| 'connectionString' Hostname, database, port and database type for " ."\n"
."| the connection. Driver example: mysql. Currently supported:" ."\n"
."| mysql, pgsql, mssql, sqlite, oci" ."\n"
."| 'username' The username used to connect to the database" ."\n"
."| 'password' The password used to connect to the database" ."\n"
."| 'tablePrefix' You can add an optional prefix, which will be added" ."\n"
."| to the table name when using the Active Record class" ."\n"
."| 'connectionString' Hostname, database, port and database type for " ."\n"
."| the connection. Driver example: mysql. Currently supported:" ."\n"
."| mysql, pgsql, mssql, sqlite, oci" ."\n"
."| 'username' The username used to connect to the database" ."\n"
."| 'password' The password used to connect to the database" ."\n"
."| 'tablePrefix' You can add an optional prefix, which will be added" ."\n"
."| to the table name when using the Active Record class" ."\n"
."|" ."\n"
."*/" ."\n"
. "return array(" . "\n"
Expand Down
87 changes: 78 additions & 9 deletions application/controllers/admin/tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@ function index($iSurveyId)
*/
function bounceprocessing($iSurveyId)
{
// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$iSurveyId = sanitize_int($iSurveyId);
$clang = $this->getController()->lang;
$bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
if (!$bTokenExists) //If no tokens table exists
{
$clang->eT("No token table.");
return;
}
$iSurveyId = sanitize_int($iSurveyId);
$clang = $this->getController()->lang;
$thissurvey = getSurveyInfo($iSurveyId);

if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'update'))
Expand Down Expand Up @@ -884,12 +883,6 @@ function delete($iSurveyID)
*/
function addDummies($iSurveyId, $subaction = '')
{
// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
if (!$bTokenExists) //If no tokens table exists
{
self::_newtokentable($iSurveyId);
}
$iSurveyId = sanitize_int($iSurveyId);
$clang = $this->getController()->lang;
if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'create'))
Expand All @@ -898,6 +891,11 @@ function addDummies($iSurveyId, $subaction = '')
$this->getController()->redirect(array("/admin/survey/sa/view/surveyid/{$iSurveyId}"));
}

$bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
if (!$bTokenExists) //If no tokens table exists
{
self::_newtokentable($iSurveyId);
}
$this->getController()->loadHelper("surveytranslator");

if (!empty($subaction) && $subaction == 'add')
Expand Down Expand Up @@ -1060,6 +1058,17 @@ function managetokenattributes($iSurveyId)
$aData['surveyid'] = $iSurveyId;
$aData['tokenfields'] = getAttributeFieldNames($iSurveyId);
$aData['tokenfielddata'] = $aData['thissurvey']['attributedescriptions'];
// Prepare token fiel list for dropDownList
$tokenfieldlist=array();
foreach($aData['tokenfields'] as $tokenfield){
if (isset($aData['tokenfielddata'][$tokenfield]))
$descrition = $aData['tokenfielddata'][$tokenfield]['description'];
else
$descrition = "";
$descrition=sprintf($clang->gT("Attribute %s (%s)"),str_replace("attribute_","",$tokenfield),$descrition);
$tokenfieldlist[]=array("id"=>$tokenfield,"descrition"=>$descrition);
}
$aData['tokenfieldlist'] = $tokenfieldlist;
$languages = array_merge((array) Survey::model()->findByPk($iSurveyId)->language, Survey::model()->findByPk($iSurveyId)->additionalLanguages);
$captions = array();
foreach ($languages as $language)
Expand Down Expand Up @@ -1113,6 +1122,66 @@ function updatetokenattributes($iSurveyId)

}

/**
* Delete token attributes
*/
function deletetokenattributes($iSurveyId)
{
$clang = $this->getController()->lang;
$iSurveyId = sanitize_int($iSurveyId);
// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
if (!$bTokenExists) //If no tokens table exists
{
Yii::app()->session['flashmessage'] = $clang->gT("No token table.");
$this->getController()->redirect($this->getController()->createUrl("/admin/survey/sa/view/surveyid/{$iSurveyId}"));
}
if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'update') && !Permission::model()->hasSurveyPermission($iSurveyID, 'surveysettings', 'update'))
{
Yii::app()->session['flashmessage'] = $clang->gT("You do not have sufficient rights to access this page.");
$this->getController()->redirect($this->getController()->createUrl("/admin/survey/sa/view/surveyid/{$iSurveyId}"));
}

$aData['thissurvey'] = getSurveyInfo($iSurveyId);
$aData['surveyid'] = $iSurveyId;
$confirm=Yii::app()->request->getPost('confirm','');
$cancel=Yii::app()->request->getPost('cancel','');
$tokenfields = getAttributeFieldNames($iSurveyId);
$sAttributeToDelete=Yii::app()->request->getPost('deleteattribute','');
tracevar($sAttributeToDelete);
if(!in_array($sAttributeToDelete,$tokenfields)) $sAttributeToDelete=false;
tracevar($sAttributeToDelete);
if ($cancel=='cancel')
{
Yii::app()->getController()->redirect(Yii::app()->getController()->createUrl("/admin/tokens/sa/managetokenattributes/surveyid/$iSurveyId"));
}
elseif ($confirm!='confirm' && $sAttributeToDelete)
{
$this->_renderWrappedTemplate('token', array('tokenbar', 'message' => array(
'title' => sprintf($clang->gT("Delete token attribute %s"),$sAttributeToDelete),
'message' => "<p>".$clang->gT("If you remove this attribute, you will lose all information.") . "</p>\n"
. CHtml::form(array("admin/tokens/sa/deletetokenattributes/surveyid/{$iSurveyId}"), 'post',array('id'=>'attributenumber'))
. CHtml::hiddenField('deleteattribute',$sAttributeToDelete)
. CHtml::hiddenField('sid',$iSurveyId)
. CHtml::htmlButton($clang->gT('Delete attribute'),array('type'=>'submit','value'=>'confirm','name'=>'confirm'))
. CHtml::htmlButton($clang->gT('Cancel'),array('type'=>'submit','value'=>'cancel','name'=>'cancel'))
. CHtml::endForm()
)), $aData);
}
elseif($sAttributeToDelete)
{
Yii::app()->db->createCommand(Yii::app()->db->getSchema()->dropColumn("{{tokens_".intval($iSurveyId)."}}", $sAttributeToDelete))->execute();
LimeExpressionManager::SetDirtyFlag();
Yii::app()->session['flashmessage'] = sprintf($clang->gT("Attribute %s was deleted."), $sAttributeToDelete);
Yii::app()->getController()->redirect(Yii::app()->getController()->createUrl("/admin/tokens/sa/managetokenattributes/surveyid/$iSurveyId"));
}
else
{
Yii::app()->session['flashmessage'] = $clang->gT("The selected attribute was invalid.");
Yii::app()->getController()->redirect(Yii::app()->getController()->createUrl("/admin/tokens/sa/managetokenattributes/surveyid/$iSurveyId"));
}
}

/**
* updatetokenattributedescriptions action
*/
Expand Down
2 changes: 2 additions & 0 deletions application/helpers/update/updatedb_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,8 @@ function db_upgrade_all($oldversion) {
if ($oldversion < 167)
{
addColumn('{{surveys_languagesettings}}', 'attachments', 'text');
addColumn('{{users}}', 'created', 'datetime');
addColumn('{{users}}', 'modified', 'datetime');
Yii::app()->db->createCommand()->update('{{settings_global}}',array('stg_value'=>167),"stg_name='DBVersion'");
}

Expand Down

0 comments on commit 1bf48a4

Please sign in to comment.