Merge branch 'saas' into saas-media-refactor

This commit is contained in:
Duncan Sommerville 2015-03-02 16:02:34 -05:00
commit 6082738439
6 changed files with 61 additions and 12 deletions

View File

@ -36,19 +36,33 @@ class ProvisioningHelper
$this->parsePostParams();
//For security, the Airtime Pro provisioning system creates the database for the user.
// $this->setNewDatabaseConnection();
$this->setNewDatabaseConnection();
//if ($this->checkDatabaseExists()) {
// throw new Exception("ERROR: Airtime database already exists");
//}
if (!$this->checkDatabaseExists()) {
throw new Exception("ERROR: $this->dbname database does not exist.");
}
//We really want to do this check because all the Propel-generated SQL starts with "DROP TABLE IF EXISTS".
//If we don't check, then a second call to this API endpoint would wipe all the tables!
if ($this->checkTablesExist()) {
throw new Exception("ERROR: airtime tables already exists");
}
//$this->createDatabase();
//All we need to do is create the database tables.
$this->createDatabaseTables();
$this->initializeMusicDirsTable($this->instanceId);
} catch (Exception $e) {
http_response_code(400);
Logging::error($e->getMessage());
echo $e->getMessage();
Logging::error($e->getMessage()
);
echo $e->getMessage() . PHP_EOL;
return;
}
@ -67,6 +81,19 @@ class ProvisioningHelper
return isset($result[0]);
}
private function checkTablesExist()
{
try {
$result = self::$dbh->query("SELECT 1 FROM cc_files LIMIT 1");
} catch (Exception $e) {
// We got an exception == table not found
echo($e . PHP_EOL);
return FALSE;
}
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
return $result !== FALSE;
}
private function parsePostParams()
{
$this->dbuser = $_POST['dbuser'];
@ -84,9 +111,11 @@ class ProvisioningHelper
private function setNewDatabaseConnection()
{
self::$dbh = new PDO("pgsql:host=" . $this->dbhost
. ";dbname=postgres"
. ";dbname=" . $this->dbname
. ";port=5432" . ";user=" . $this->dbuser
. ";password=" . $this->dbpass);
//Turn on PDO exceptions because they're off by default.
//self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$err = self::$dbh->errorInfo();
if ($err[1] != null) {
throw new PDOException("ERROR: Could not connect to database");

View File

@ -38,6 +38,7 @@ class PreferenceController extends Zend_Controller_Action
if ($form->isValid($values))
{
Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view);
Application_Model_Preference::SetStationDescription($values["stationDescription"]);
Application_Model_Preference::SetDefaultCrossfadeDuration($values["stationDefaultCrossfadeDuration"]);
Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]);
Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]);
@ -49,7 +50,11 @@ class PreferenceController extends Zend_Controller_Action
$logoUploadElement = $form->getSubForm('preferences_general')->getElement('stationLogo');
$logoUploadElement->receive();
$imagePath = $logoUploadElement->getFileName();
Application_Model_Preference::SetStationLogo($imagePath);
// Only update the image logo if the new logo is non-empty
if (!empty($imagePath) && $imagePath != "") {
Application_Model_Preference::SetStationLogo($imagePath);
}
Application_Model_Preference::SetUploadToSoundcloudOption($values["UploadToSoundcloudOption"]);
Application_Model_Preference::SetSoundCloudDownloadbleOption($values["SoundCloudDownloadbleOption"]);

View File

@ -49,6 +49,13 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
$stationLogoUpload->setAttrib('accept', 'image/*');
$this->addElement($stationLogoUpload);
$stationLogoRemove = new Zend_Form_Element_Button('stationLogoRemove');
$stationLogoRemove->setLabel(_('Remove'));
$stationLogoRemove->setAttrib('class', 'btn');
$stationLogoRemove->setAttrib('id', 'logo-remove-btn');
$stationLogoRemove->setAttrib('onclick', 'removeLogo();');
$this->addElement($stationLogoRemove);
//Default station crossfade duration
$this->addElement('text', 'stationDefaultCrossfadeDuration', array(
'class' => 'input_text',

View File

@ -7,10 +7,12 @@
<?php echo $this->element->getElement('stationLogo')->render() ?>
<button id="logo-remove-btn" value="Remove" class="btn">Remove</button>
<?php echo $this->element->getElement('stationLogoRemove')->render() ?>
<!-- <button id="logo-remove-btn" value="Remove" class="btn">Remove</button>-->
<div id="Logo-img-container">
<img onError="this.onerror = '';this.style.visibility='hidden';$('#logo-remove-btn').hide();" id="logo-img" onload='resizeImg(this, 450, 450);' src="data:image/png;base64,<?php echo $this->element->getView()->logoImg ?>" />
<img onError="this.onerror = '';this.style.visibility='hidden';$('#logo-remove-btn').hide();$('[id^=stationLogoRemove]').each(function(i,v){v.style.width=v.style.height=v.style.margin=v.style.padding='0px';});" id="logo-img" onload='resizeImg(this, 450, 450);' src="data:image/png;base64,<?php echo $this->element->getView()->logoImg ?>" />
</div>
<?php echo $this->element->getElement('locale')->render() ?>

View File

@ -2197,12 +2197,17 @@ dd.radio-inline-list, .preferences dd.radio-inline-list, .stream-config dd.radio
height: 120px;
}
.preferences #stationLogoRemove-label {
display: none;
}
.preferences #logo-remove-btn {
float: right;
margin-bottom: 4px;
}
.preferences #Logo-img-container {
float: left;
margin-top: 30px;
}
#show_time_info {

View File

@ -115,6 +115,11 @@ function setSoundCloudCheckBoxListener() {
});
}
function removeLogo() {
$.post(baseUrl+'Preference/remove-logo', function(json){});
location.reload();
}
$(document).ready(function() {
$('.collapsible-header').live('click',function() {
@ -123,10 +128,6 @@ $(document).ready(function() {
return false;
}).next().hide();
$('#logo-remove-btn').click(function() {
$.post(baseUrl+'Preference/remove-logo', function(json){});
});
/* No longer using AJAX for this form. Zend + our code makes it needlessly hard to deal with. -- Albert
$('#pref_save').live('click', function() {
var data = $('#pref_form').serialize();