Merged 2.5.x into saas

This commit is contained in:
Duncan Sommerville 2014-11-05 17:36:58 -05:00
commit 4d263ce897
26 changed files with 2618 additions and 1649 deletions

View file

@ -6,7 +6,7 @@ class LocaleController extends Zend_Controller_Action
public function init()
{
}
public function datatablesTranslationTableAction()
{
$this->view->layout()->disableLayout();

View file

@ -16,15 +16,16 @@ class LoginController extends Zend_Controller_Action
$request = $this->getRequest();
$response = $this->getResponse();
$stationLocale = Application_Model_Preference::GetDefaultLocale();
//Enable AJAX requests from www.airtime.pro for the sign-in process.
CORSHelper::enableATProCrossOriginRequests($request, $response);
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA'));
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', $stationLocale));
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity())
{
if ($auth->hasIdentity()) {
$this->_redirect('Showbuilder');
}
@ -130,7 +131,9 @@ class LoginController extends Zend_Controller_Action
$this->view->headScript()->appendFile($baseUrl.'js/airtime/login/password-restore.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$request = $this->getRequest();
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA'));
$stationLocale = Application_Model_Preference::GetDefaultLocale();
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', $stationLocale));
if (!Application_Model_Preference::GetEnableSystemEmail()) {
$this->_redirect('login');
@ -174,7 +177,9 @@ class LoginController extends Zend_Controller_Action
public function passwordRestoreAfterAction()
{
$request = $this->getRequest();
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA'));
$stationLocale = Application_Model_Preference::GetDefaultLocale();
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', $stationLocale));
//uses separate layout without a navigation.
$this->_helper->layout->setLayout('login');
@ -192,8 +197,10 @@ class LoginController extends Zend_Controller_Action
$form = new Application_Form_PasswordChange();
$auth = new Application_Model_Auth();
$user = CcSubjsQuery::create()->findPK($user_id);
$stationLocale = Application_Model_Preference::GetDefaultLocale();
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', 'en_CA'));
Application_Model_Locale::configureLocalization($request->getcookie('airtime_locale', $stationLocale));
//check validity of token
if (!$auth->checkToken($user_id, $token, 'password.restore')) {

View file

@ -73,12 +73,6 @@ class UserController extends Zend_Controller_Action
$user->setJabber($formData['jabber']);
$user->save();
// Language and timezone settings are saved on a per-user basis
// By default, the default language, and timezone setting on
// preferences page is what gets assigned.
Application_Model_Preference::SetUserLocale();
Application_Model_Preference::SetUserTimezone();
$form->reset();
$this->view->form = $form;
@ -87,7 +81,7 @@ class UserController extends Zend_Controller_Action
} else {
$this->view->successMessage = "<div class='success'>"._("User updated successfully!")."</div>";
}
$this->_helper->json->sendJson(array("valid"=>"true", "html"=>$this->view->render('user/add-user.phtml')));
} else {
$this->view->form = $form;

View file

@ -53,13 +53,11 @@ class Application_Form_Login extends Zend_Form
$locale->setMultiOptions(Application_Model_Locale::getLocales());
$locale->setDecorators(array('ViewHelper'));
$this->addElement($locale);
$this->setDefaults(array(
"locale" => Application_Model_Locale::getUserLocale()
));
$recaptchaNeeded = false;
if (Application_Model_LoginAttempts::getAttempts($_SERVER['REMOTE_ADDR']) >= 3) {
$recaptchaNeeded = true;
}
if ($recaptchaNeeded) {
// recaptcha
$this->addRecaptcha();
}

View file

@ -62,5 +62,22 @@ class Application_Model_Locale
textdomain('airtime');
}
/**
* We need this function for the case where a user has logged out, but
* has an airtime_locale cookie containing their locale setting.
*
* If the user does not have an airtime_locale cookie set, we default
* to the station locale.
*
* When the user logs in, the value set in the login form will be passed
* into the airtime_locale cookie. This cookie is also updated when
* a user updates their user settings.
*/
public static function getUserLocale() {
$request = Zend_Controller_Front::getInstance()->getRequest();
$locale = $request->getCookie('airtime_locale', Application_Model_Preference::GetLocale());
return $locale;
}
}

View file

@ -4,45 +4,44 @@ require_once 'Cache.php';
class Application_Model_Preference
{
private static function getUserId()
{
//pass in true so the check is made with the autoloader
//we need this check because saas calls this function from outside Zend
if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
$userId = null;
}
else {
$auth = Zend_Auth::getInstance();
$userId = $auth->getIdentity()->id;
}
return $userId;
}
private static function getUserId()
{
//pass in true so the check is made with the autoloader
//we need this check because saas calls this function from outside Zend
if (!class_exists("Zend_Auth", true) || !Zend_Auth::getInstance()->hasIdentity()) {
$userId = null;
} else {
$auth = Zend_Auth::getInstance();
$userId = $auth->getIdentity()->id;
}
return $userId;
}
/**
*
* @param boolean $isUserValue is true when we are setting a value for the current user
*/
private static function setValue($key, $value, $isUserValue = false)
{
$cache = new Cache();
$cache = new Cache();
try {
$con = Propel::getConnection(CcPrefPeer::DATABASE_NAME);
$con->beginTransaction();
$userId = self::getUserId();
if ($isUserValue && is_null($userId)) {
throw new Exception("User id can't be null for a user preference {$key}.");
}
if ($isUserValue && is_null($userId))
throw new Exception("User id can't be null for a user preference {$key}.");
Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref");
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = :key";
." WHERE keystr = :key";
$paramMap = array();
$paramMap[':key'] = $key;
@ -64,37 +63,33 @@ class Application_Model_Preference
//this case should not happen.
throw new Exception("Invalid number of results returned. Should be ".
"0 or 1, but is '$result' instead");
}
elseif ($result == 1) {
} else if ($result == 1) {
// result found
if (!$isUserValue) {
// system pref
$sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = :value"
." WHERE keystr = :key";
}
else {
." SET subjid = NULL, valstr = :value"
." WHERE keystr = :key";
} else {
// user pref
$sql = "UPDATE cc_pref"
. " SET valstr = :value"
. " WHERE keystr = :key AND subjid = :id";
. " SET valstr = :value"
. " WHERE keystr = :key AND subjid = :id";
$paramMap[':id'] = $userId;
}
}
else {
} else {
// result not found
if (!$isUserValue) {
// system pref
$sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES (:key, :value)";
}
else {
." VALUES (:key, :value)";
} else {
// user pref
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES (:id, :key, :value)";
." VALUES (:id, :key, :value)";
$paramMap[':id'] = $userId;
}
@ -109,8 +104,7 @@ class Application_Model_Preference
$con);
$con->commit();
}
catch (Exception $e) {
} catch (Exception $e) {
$con->rollback();
header('HTTP/1.0 503 Service Unavailable');
Logging::info("Database error: ".$e->getMessage());
@ -118,26 +112,22 @@ class Application_Model_Preference
}
$cache->store($key, $value, $isUserValue, $userId);
//Logging::info("SAVING {$key} {$userId} into cache. = {$value}");
}
private static function getValue($key, $isUserValue = false)
{
$cache = new Cache();
$cache = new Cache();
try {
$userId = self::getUserId();
if ($isUserValue && is_null($userId)) {
throw new Exception("User id can't be null for a user preference.");
}
$userId = self::getUserId();
if ($isUserValue && is_null($userId))
throw new Exception("User id can't be null for a user preference.");
$res = $cache->fetch($key, $isUserValue, $userId);
if ($res !== false) {
//Logging::info("returning {$key} {$userId} from cache. = {$res}");
return $res;
}
// If the value is already cached, return it
$res = $cache->fetch($key, $isUserValue, $userId);
if ($res !== false) return $res;
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
@ -147,7 +137,7 @@ class Application_Model_Preference
$paramMap[':key'] = $key;
//For user specific preference, check if id matches as well
if ($isUserValue) {
if ($isUserValue) {
$sql .= " AND subjid = :id";
$paramMap[':id'] = $userId;
}
@ -157,8 +147,7 @@ class Application_Model_Preference
//return an empty string if the result doesn't exist.
if ($result == 0) {
$res = "";
}
else {
} else {
$sql = "SELECT valstr FROM cc_pref"
." WHERE keystr = :key";
@ -248,53 +237,53 @@ class Application_Model_Preference
public static function SetDefaultCrossfadeDuration($duration)
{
self::setValue("default_crossfade_duration", $duration);
self::setValue("default_crossfade_duration", $duration);
}
public static function GetDefaultCrossfadeDuration()
{
$duration = self::getValue("default_crossfade_duration");
$duration = self::getValue("default_crossfade_duration");
if ($duration === "") {
// the default value of the fade is 00.5
return "0";
}
if ($duration === "") {
// the default value of the fade is 00.5
return "0";
}
return $duration;
return $duration;
}
public static function SetDefaultFadeIn($fade)
{
self::setValue("default_fade_in", $fade);
self::setValue("default_fade_in", $fade);
}
public static function GetDefaultFadeIn()
{
$fade = self::getValue("default_fade_in");
$fade = self::getValue("default_fade_in");
if ($fade === "") {
// the default value of the fade is 00.5
return "00.5";
}
if ($fade === "") {
// the default value of the fade is 00.5
return "00.5";
}
return $fade;
return $fade;
}
public static function SetDefaultFadeOut($fade)
{
self::setValue("default_fade_out", $fade);
self::setValue("default_fade_out", $fade);
}
public static function GetDefaultFadeOut()
{
$fade = self::getValue("default_fade_out");
$fade = self::getValue("default_fade_out");
if ($fade === "") {
// the default value of the fade is 00.5
return "00.5";
}
if ($fade === "") {
// the default value of the fade is 00.5
return "00.5";
}
return $fade;
return $fade;
}
public static function SetDefaultFade($fade)
@ -556,9 +545,8 @@ class Application_Model_Preference
{
// When a new user is created they will get the default timezone
// setting which the admin sets on preferences page
if (is_null($timezone)) {
if (is_null($timezone))
$timezone = self::GetDefaultTimezone();
}
self::setValue("user_timezone", $timezone, true);
}
@ -567,8 +555,7 @@ class Application_Model_Preference
$timezone = self::getValue("user_timezone", true);
if (!$timezone) {
return self::GetDefaultTimezone();
}
else {
} else {
return $timezone;
}
}
@ -580,8 +567,7 @@ class Application_Model_Preference
if (!is_null($userId)) {
return self::GetUserTimezone();
}
else {
} else {
return self::GetDefaultTimezone();
}
}
@ -612,9 +598,8 @@ class Application_Model_Preference
{
// When a new user is created they will get the default locale
// setting which the admin sets on preferences page
if (is_null($locale)) {
if (is_null($locale))
$locale = self::GetDefaultLocale();
}
self::setValue("user_locale", $locale, true);
}
@ -624,8 +609,7 @@ class Application_Model_Preference
if (!is_null($userId)) {
return self::GetUserLocale();
}
else {
} else {
return self::GetDefaultLocale();
}
}
@ -648,7 +632,7 @@ class Application_Model_Preference
public static function SetUniqueId($id)
{
self::setValue("uniqueId", $id);
self::setValue("uniqueId", $id);
}
public static function GetUniqueId()
@ -902,7 +886,7 @@ class Application_Model_Preference
public static function SetAirtimeVersion($version)
{
self::setValue("system_version", $version);
self::setValue("system_version", $version);
}
public static function GetAirtimeVersion()
@ -1416,12 +1400,11 @@ class Application_Model_Preference
return self::getValue("enable_replay_gain", false);
}
public static function getReplayGainModifier(){
public static function getReplayGainModifier() {
$rg_modifier = self::getValue("replay_gain_modifier");
if ($rg_modifier === "") {
if ($rg_modifier === "")
return "0";
}
return $rg_modifier;
}
@ -1432,19 +1415,19 @@ class Application_Model_Preference
}
public static function SetHistoryItemTemplate($value) {
self::setValue("history_item_template", $value);
self::setValue("history_item_template", $value);
}
public static function GetHistoryItemTemplate() {
return self::getValue("history_item_template");
return self::getValue("history_item_template");
}
public static function SetHistoryFileTemplate($value) {
self::setValue("history_file_template", $value);
self::setValue("history_file_template", $value);
}
public static function GetHistoryFileTemplate() {
return self::getValue("history_file_template");
return self::getValue("history_file_template");
}
public static function getDiskUsage()

View file

@ -390,33 +390,22 @@ class Application_Service_ShowFormService
}
/**
*
* Before we send the form data in for validation, there
* are a few fields we may need to adjust first
*
* @param $formData
*/
public function preEditShowValidationCheck($formData)
{
$validateStartDate = true;
$validateStartTime = true;
// If the start date or time were disabled, don't validate them
$validateStartDate = $formData['start_date_disabled'] === "false";
$validateStartTime = $formData['start_time_disabled'] === "false";
//CcShowDays object of the show currently being edited
$currentShowDay = $this->ccShow->getFirstCcShowDay();
//DateTime object
$dt = $currentShowDay->getLocalStartDateAndTime();
if (!array_key_exists('add_show_start_date', $formData)) {
//Changing the start date was disabled, since the
//array key does not exist. We need to repopulate this entry from the db.
$formData['add_show_start_date'] = $dt->format("Y-m-d");
if (!array_key_exists('add_show_start_time', $formData)) {
$formData['add_show_start_time'] = $dt->format("H:i");
$validateStartTime = false;
}
$validateStartDate = false;
}
$formData['add_show_record'] = $currentShowDay->getDbRecord();
//if the show is repeating, set the start date to the next
@ -440,11 +429,9 @@ class Application_Service_ShowFormService
$ccShowInstance = CcShowInstancesQuery::create()
->filterByDbShowId($this->ccShow->getDbId())
->filterByDbModifiedInstance(false)
->filterByDbEnds(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN)
->orderByDbStarts()
->limit(1)
->filterByDbStarts(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN)
->findOne();
$starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone("UTC"));
$ends = new DateTime($ccShowInstance->getDbEnds(), new DateTimeZone("UTC"));
$showTimezone = $this->ccShow->getFirstCcShowDay()->getDbTimezone();
@ -455,6 +442,7 @@ class Application_Service_ShowFormService
return array($starts, $ends);
}
/**
*
* Validates show forms