diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 62679c8b0..ee3bb7096 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -34,7 +34,13 @@ $front->registerPlugin(new RabbitMqPlugin()); //localization configuration $codeset = 'UTF-8'; -$lang = Application_Model_Preference::GetLocale().'.'.$codeset; +$auth = Zend_Auth::getInstance(); +if ($auth->hasIdentity()) { + $id = $auth->getIdentity()->id; + $lang = Application_Model_Preference::GetCurrentUserLocale($id).'.'.$codeset; +} else { + $lang = Application_Model_Preference::GetLocale().'.'.$codeset; +} putenv("LC_ALL=$lang"); putenv("LANG=$lang"); diff --git a/airtime_mvc/application/controllers/UserController.php b/airtime_mvc/application/controllers/UserController.php index d5ee57e2f..e2f6fcfae 100644 --- a/airtime_mvc/application/controllers/UserController.php +++ b/airtime_mvc/application/controllers/UserController.php @@ -72,6 +72,11 @@ class UserController extends Zend_Controller_Action $user->setJabber($formData['jabber']); $user->save(); + // Language settings are saved on a per-user basis + // By default, the general language setting on preferences + // page is what gets assigned. + Application_Model_Preference::SetUserLocale($user->getId()); + $form->reset(); $this->view->form = $form; @@ -150,6 +155,7 @@ class UserController extends Zend_Controller_Action $user->setSkype($formData['cu_skype']); $user->setJabber($formData['cu_jabber']); $user->save(); + Application_Model_Preference::SetUserLocale($user->getId(), $formData['cu_locale']); $this->view->successMessage = "
"._("User updated successfully!")."
"; } $this->view->form = $form; diff --git a/airtime_mvc/application/forms/EditUser.php b/airtime_mvc/application/forms/EditUser.php index b4906b9e7..c775eb023 100644 --- a/airtime_mvc/application/forms/EditUser.php +++ b/airtime_mvc/application/forms/EditUser.php @@ -29,6 +29,7 @@ class Application_Form_EditUser extends Zend_Form $login->setLabel(_('Username:')); $login->setValue($userData["login"]); $login->setAttrib('class', 'input_text'); + $login->setAttrib('readonly', 'readonly'); $login->setRequired(true); $login->addValidator($notEmptyValidator); $login->addFilter('StringTrim'); @@ -96,6 +97,12 @@ class Application_Form_EditUser extends Zend_Form $jabber->setDecorators(array('viewHelper')); $this->addElement($jabber); + $locale = new Zend_Form_Element_Select("cu_locale"); + $locale->setLabel(_("Language")); + $locale->setMultiOptions(Application_Model_Locale::getLocales()); + $locale->setValue(Application_Model_Preference::GetUserLocale($currentUser->getId())); + $locale->setDecorators(array('ViewHelper')); + $this->addElement($locale); /* $saveBtn = new Zend_Form_Element_Button('cu_save_user'); $saveBtn->setAttrib('class', 'btn btn-small right-floated'); diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 326ab6bea..eef140cca 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -3,7 +3,12 @@ class Application_Model_Preference { - private static function setValue($key, $value, $isUserValue = false) + /** + * + * @param integer $userId is not null when we are setting a locale for a specific user + * @param boolean $isUserValue is true when we are setting a value for the current user + */ + private static function setValue($key, $value, $isUserValue = false, $userId = null) { try { //called from a daemon process @@ -22,9 +27,12 @@ class Application_Model_Preference $paramMap[':key'] = $key; //For user specific preference, check if id matches as well - if ($isUserValue) { + if ($isUserValue && is_null($userId)) { $sql .= " AND subjid = :id"; $paramMap[':id'] = $id; + } else if (!is_null($userId)) { + $sql .= " AND subjid= :id"; + $paramMap[':id'] = $userId; } $result = Application_Common_Database::prepareAndExecute($sql, $paramMap, 'column'); @@ -42,7 +50,11 @@ class Application_Model_Preference $sql = "UPDATE cc_pref" . " SET valstr = :value" . " WHERE keystr = :key AND subjid = :id"; - $paramMap[':id'] = $id; + if (is_null($userId)) { + $paramMap[':id'] = $id; + } else { + $paramMap[':id'] = $userId; + } } } else { // result not found @@ -54,7 +66,11 @@ class Application_Model_Preference // user pref $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" ." VALUES (:id, :key, :value)"; - $paramMap[':id'] = $id; + if (is_null($userId)) { + $paramMap[':id'] = $id; + } else { + $paramMap[':id'] = $userId; + } } } $paramMap[':key'] = $key; @@ -428,16 +444,37 @@ class Application_Model_Preference { return self::getValue("timezone"); } - + + // This is the language setting on preferences page public static function SetLocale($locale) { self::setValue("locale", $locale); } - + public static function GetLocale() { return self::getValue("locale"); } + + public static function GetCurrentUserLocale($id) + { + return self::getValue("user_".$id."_locale", true); + } + + public static function SetUserLocale($userId, $locale = null) + { + // When a new user is created they will get the default locale + // setting which the admin sets on preferences page + if (is_null($locale)) { + $locale = self::GetLocale(); + } + self::setValue("user_".$userId."_locale", $locale, true, $userId); + } + + public static function GetUserLocale($userId) + { + return self::getValue("user_".$userId."_locale"); + } public static function SetStationLogo($imagePath) { diff --git a/airtime_mvc/application/views/scripts/form/edit-user.phtml b/airtime_mvc/application/views/scripts/form/edit-user.phtml index 927fd8a6d..3f0be44c3 100644 --- a/airtime_mvc/application/views/scripts/form/edit-user.phtml +++ b/airtime_mvc/application/views/scripts/form/edit-user.phtml @@ -114,6 +114,20 @@ +
+ +
+
+ element->getElement('cu_locale') ?> + element->getElement('cu_locale')->hasErrors()) : ?> + + +
diff --git a/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml b/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml index 0ab387ca1..4b1a38839 100644 --- a/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml +++ b/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml @@ -18,7 +18,7 @@ md["MDATA_KEY_ISRC"]);?> md["MDATA_KEY_URL"]);?> md["MDATA_KEY_LANGUAGE"]);?> - md["MDATA_KEY_FILEPATH"]);?> +md["MDATA_KEY_FILEPATH"]);?> diff --git a/airtime_mvc/build/sql/defaultdata.sql b/airtime_mvc/build/sql/defaultdata.sql index bd1c64939..894a9a42e 100644 --- a/airtime_mvc/build/sql/defaultdata.sql +++ b/airtime_mvc/build/sql/defaultdata.sql @@ -319,6 +319,8 @@ INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s3_channels', 'ste -- added in 2.3 INSERT INTO cc_pref("keystr", "valstr") VALUES('locale', 'en_CA'); +INSERT INTO cc_pref("subjid", "keystr", "valstr") VALUES(1, 'user_1_locale', 'en_CA'); + INSERT INTO cc_locale (locale_code, locale_lang) VALUES ('zh_CN', 'Chinese'); INSERT INTO cc_locale (locale_code, locale_lang) VALUES ('en_CA', 'English'); INSERT INTO cc_locale (locale_code, locale_lang) VALUES ('en_US', 'English - US'); diff --git a/airtime_mvc/public/js/airtime/dashboard/dashboard.js b/airtime_mvc/public/js/airtime/dashboard/dashboard.js index 7f86f705d..78f37be8c 100644 --- a/airtime_mvc/public/js/airtime/dashboard/dashboard.js +++ b/airtime_mvc/public/js/airtime/dashboard/dashboard.js @@ -460,7 +460,7 @@ $(document).ready(function() { clearTimeout(timer); }); - $('.tipsy').live('mouseout', function() { + $('.tipsy').live('blur', function() { timer = setTimeout("$('#current-user').tipsy('hide')", 500); }); @@ -488,7 +488,7 @@ $(document).ready(function() { }); - $('#current-user').bind('mouseout', function() { + $('#current-user').bind('blur', function() { timer = setTimeout("$('#current-user').tipsy('hide')", 500); }); diff --git a/python_apps/media-monitor2/media/metadata/process.py b/python_apps/media-monitor2/media/metadata/process.py index 38e036175..ccaa1f41c 100644 --- a/python_apps/media-monitor2/media/metadata/process.py +++ b/python_apps/media-monitor2/media/metadata/process.py @@ -169,7 +169,7 @@ def normalize_mutagen(path): md['sample_rate'] = getattr(m.info, 'sample_rate', 0) md['mime'] = m.mime[0] if len(m.mime) > 0 else u'' md['path'] = normpath(path) - + # silence detect(set default queue in and out) try: command = ['silan', '-f', 'JSON', md['path']] @@ -181,7 +181,7 @@ def normalize_mutagen(path): except Exception: logger = logging.getLogger() logger.info('silan is missing') - + if 'title' not in md: md['title'] = u'' return md