diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 2adad9cde3..38e577f967 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2008-08-20 Evi Vanoost + + * godmode/profiles/profile_list.php: HTML overhaul (close tags, put + brackets and quotes in the right places. Now uses new functions + instead of the old ones + + * include/locale.class.php: Updated and added functions. See internals + for updated functions. It now allows to put a translated array of + languages, countries and currency instead of the built-in english one + 2008-08-19 Esteban Sanchez * include/locale.class.php: Fixes in Translate_Locale() to work diff --git a/pandora_console/godmode/profiles/profile_list.php b/pandora_console/godmode/profiles/profile_list.php index 78afc572bc..fd03ea3c86 100644 --- a/pandora_console/godmode/profiles/profile_list.php +++ b/pandora_console/godmode/profiles/profile_list.php @@ -1,9 +1,16 @@ , 2003-2007 -// Raul Mateos , 2005-2007 +// Pandora FMS - the Flexible monitoring system +// ============================================ +// Copyright (c) 2004-2008 Sancho Lerena, +// Copyright (c) 2005-2008 Artica Soluciones Tecnologicas + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation version 2 +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. // Global variables require ("include/config.php"); @@ -17,285 +24,267 @@ if (! give_acl ($config['id_user'], 0, "PM")) { return; } +//Page title definitation. Will be overridden by Edit and Create Profile +$page_title = __('Profiles defined in Pandora'); + // Profile deletion -if (isset($_GET["delete_profile"])){ // if any parameter is modified - $id_perfil= entrada_limpia($_GET["delete_profile"]); +if (isset ($_GET["delete_profile"])){ // if any parameter is modified + $id_profile = safe_input ($_GET["delete_profile"]); + // Delete profile - $query_del1="DELETE FROM tperfil WHERE id_perfil = '".$id_perfil."'"; - $query_del2="DELETE FROM tusuario_perfil WHERE id_perfil = '".$id_perfil."'"; - $resq1=mysql_query($query_del1); - if (! $resq1) - echo "

".__('There was a problem deleting profile')."

"; - else - echo "

".__('Profile successfully deleted')."

"; - $resq1=mysql_query($query_del2); - unset($id_perfil); // forget it to show list -} -// Profile creation -elseif (isset($_GET["new_profile"])){ // create a new profile + $query = "DELETE FROM tperfil WHERE id_perfil = '".$id_profile."'"; + $ret = process_sql ($query); + if ($ret === false) { + echo '

'.__('There was a problem deleting the profile').'

'; + } else { + echo '

'.__('Profile successfully deleted').'

'; + } + + //Delete profile from user data + $query = "DELETE FROM tusuario_perfil WHERE id_perfil = '".$id_profile."'"; + process_sql ($query); + + unset($id_profile); // forget it to show list +} elseif (isset ($_GET["new_profile"])) { // create a new profile $id_perfil = -1; $name = ""; - $incident_view = "0"; - $incident_edit = "0"; - $incident_create = "0"; - $incident_management = "0"; - $agent_view = "0"; - $agent_edit ="0"; - $alert_edit = "0"; - $user_management = "0"; - $db_management = "0"; - $alert_management = "0"; - $pandora_management = "0"; -} elseif (isset($_GET["edit_profile"])){ // Edit profile (read data to show in form) - // Profile edit - $id_perfil= entrada_limpia($_GET["edit_profile"]); - $query_del1="SELECT * FROM tperfil WHERE id_perfil = '".$id_perfil."'"; - $resq1=mysql_query($query_del1); - $rowq1=mysql_fetch_array($resq1); - if (!$rowq1){ - echo "

".__('There was a problem loading profile')."

"; - echo ""; - include ("general/footer.php"); - exit; - } - else - - $name = $rowq1["name"]; - $incident_view = $rowq1["incident_view"]; - $incident_edit = $rowq1["incident_edit"]; - $incident_management = $rowq1["incident_management"]; - $agent_view = $rowq1["agent_view"]; - $agent_edit =$rowq1["agent_edit"]; - $alert_edit = $rowq1["alert_edit"]; - $user_management = $rowq1["user_management"]; - $db_management = $rowq1["db_management"]; - $alert_management = $rowq1["alert_management"]; - $pandora_management = $rowq1["pandora_management"]; -} elseif (isset($_GET["update_data"])){ // Update or Create a new record (writes on DB) - // Profile edit - $incident_view = "0"; - $incident_edit = "0"; - $incident_create = "0"; - $incident_management = "0"; - $agent_view = "0"; - $agent_edit ="0"; - $alert_edit = "0"; - $user_management = "0"; - $db_management = "0"; - $alert_management = "0"; - $pandora_management = "0"; - $id_perfil= entrada_limpia($_POST["id_perfil"]); - $name = entrada_limpia($_POST["name"]); + $incident_view = 0; + $incident_edit = 0; + $incident_management = 0; + $agent_view = 0; + $agent_edit = 0; + $alert_edit = 0; + $user_management = 0; + $db_management = 0; + $alert_management = 0; + $pandora_management = 0; + $page_title = __('Create profile'); +} elseif (isset ($_GET["edit_profile"])) { // Edit profile (read data to show in form) + $id_perfil = safe_input ($_GET["edit_profile"]); + $row = get_db_row_sql("SELECT * FROM tperfil WHERE id_perfil = '".$id_perfil."'"); - if (isset ($_POST["incident_view"]))$incident_view = entrada_limpia($_POST["incident_view"]); - if (isset ($_POST["incident_edit"])) $incident_edit = entrada_limpia($_POST["incident_edit"]); - if (isset ($_POST["incident_management"])) $incident_management = entrada_limpia($_POST["incident_management"]); - if (isset ($_POST["agent_view"])) $agent_view = entrada_limpia($_POST["agent_view"]); - if (isset ($_POST["agent_edit"])) $agent_edit =entrada_limpia($_POST["agent_edit"]); - if (isset ($_POST["alert_edit"])) $alert_edit = entrada_limpia($_POST["alert_edit"]); - if (isset ($_POST["user_management"])) $user_management = entrada_limpia($_POST["user_management"]); - if (isset ($_POST["db_management"])) $db_management = entrada_limpia($_POST["db_management"]); - if (isset ($_POST["alert_management"])) $alert_management = entrada_limpia($_POST["alert_management"]); - if (isset ($_POST["pandora_management"])) $pandora_management = entrada_limpia($_POST["pandora_management"]); + if ($row === false) { + echo '

'.__('There was a problem loading profile').'

'; //Error and close open table + include ("general/footer.php"); + exit; + } else { + $name = $row["name"]; + $incident_view = $row["incident_view"]; + $incident_edit = $row["incident_edit"]; + $incident_management = $row["incident_management"]; + $agent_view = $row["agent_view"]; + $agent_edit =$row["agent_edit"]; + $alert_edit = $row["alert_edit"]; + $user_management = $row["user_management"]; + $db_management = $row["db_management"]; + $alert_management = $row["alert_management"]; + $pandora_management = $row["pandora_management"]; + unset ($row); //clean up variables + } + + $page_title = __('Update profile'); + +} elseif (isset ($_GET["update_data"])) { // Update or Create a new record (writes on DB) + // Profile edit + $id_profile = (int) get_parameter_post ("id_perfil",-1); + $name = get_parameter_post ("name"); + + $incident_view = (bool) get_parameter_post ("incident_view",0); + $incident_edit = (bool) get_parameter_post ("incident_edit",0); + $incident_management = (bool) get_parameter_post ("incident_management",0); + $agent_view = (bool) get_parameter_post ("agent_view",0); + $agent_edit = (bool) get_parameter_post ("agent_edit",0); + $alert_edit = (bool) get_parameter_post ("alert_edit",0); + $user_management = (bool) get_parameter_post ("user_management",0); + $db_management = (bool) get_parameter_post ("db_management",0); + $alert_management = (bool) get_parameter_post ("alert_management",0); + $pandora_management = (bool) get_parameter_post ("pandora_management",0); // update or insert ?? - if ($id_perfil == -1) { // INSERT - $query = "INSERT INTO tperfil (name,incident_view,incident_edit,incident_management, agent_view,agent_edit,alert_edit,user_management,db_management,alert_management,pandora_management) VALUES + if ($id_profile == -1) { // INSERT + $query = "INSERT INTO tperfil + (name,incident_view,incident_edit,incident_management,agent_view,agent_edit,alert_edit,user_management,db_management,alert_management,pandora_management) + VALUES ('".$name."','".$incident_view."','".$incident_edit."','".$incident_management."','".$agent_view."','".$agent_edit."','".$alert_edit."','".$user_management."','".$db_management."','".$alert_management."','".$pandora_management."')"; // echo "DEBUG: ".$query; - $res = mysql_query($query); - if ($res) - echo "

".__('Profile successfully created')."

"; - else { - echo "

".__('There was a problem creating profile')."

"; + $ret = process_sql ($query); + if ($ret !== false) { + echo '

'.__('Profile successfully created').'

'; + } else { + echo '

'.__('There was a problem creating this profile').'

'; } - } else { // UPDATE - $query ="UPDATE tperfil SET - name = '$name', - incident_view = $incident_view, - incident_edit = $incident_edit, - incident_management = $incident_management, - agent_view = $agent_view, - agent_edit = $agent_edit, - alert_edit = $alert_edit, - user_management = $user_management, - db_management = $db_management, - alert_management = $alert_management, - pandora_management = $pandora_management - WHERE id_perfil = $id_perfil "; + $query = "UPDATE tperfil SET + name = '".$name."', + incident_view = '".$incident_view."', + incident_edit = '".$incident_edit."', + incident_management = '".$incident_management."', + agent_view = '".$agent_view."', + agent_edit = '".$agent_edit."', + alert_edit = '".$alert_edit."', + user_management = '".$user_management."', + db_management = '".$db_management."', + alert_management = '".$alert_management."', + pandora_management = '".$pandora_management."' + WHERE id_perfil = '".$id_profile."'"; // echo "DEBUG: ".$query; - $res=mysql_query($query); - echo "

".__('Profile successfully updated')."

"; + $ret = process_sql ($query); + if ($ret !== false) { + echo '

'.__('Profile successfully updated').'

'; + } else { + echo '

'; + } } - unset($id_perfil); + unset ($id_profile); } -echo '

'.__('Profile management').' > '; -echo (isset($_GET["new_profile"])) ? - (__('Create profile').'

'): - ( - (isset($_GET["edit_profile"]))? - (__('Update profile').'>'): - (__('Profiles defined in Pandora').'') - ); + +echo '

'.__('Profile management').' > '.$page_title.'

'; + // Form to manage date if (isset ($id_perfil)){ // There are values defined, let's show form with data for INSERT or UPDATE - echo ""; - echo ""; - echo ""; - echo ""; - echo " - - - - - - - - - - - - - - - - - - - - - - - "; - echo "
".__('Profile name')." -
".__('View incidents')." -
".__('Edit incidents')." -
".__('Manage incidents')." -
".__('View agents')." -
".__('Edit agents')." -
".__('Edit alerts')." -
".__('Manage users')." -
".__('Manage Database')." -
".__('Manage alerts')." -
".__('Pandora management')." -
"; - echo ""; - echo "
"; - - if (isset($_GET["new_profile"])){ - echo " - "; + echo ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
'.__('Profile name').'
'.__('View incidents').'
'.__('Edit incidents').'
'.__('Manage incidents').'
'.__('View agents').'
'.__('Edit agents').'
'.__('Edit alerts').'
'.__('Manage users').'
'.__('Manage Database').'
'.__('Manage alerts').'
'.__('Pandora management').'
'; + echo '
'; + if (isset ($_GET["new_profile"])) { + echo ''; + } elseif (isset ($_GET["edit_profile"])) { + echo ''; } - if (isset($_GET["edit_profile"])){ - echo " - "; - } - echo "
"; - + echo '
'; } else { // View list data + echo ''; + + $result = get_db_all_rows_in_table ("tperfil"); + echo ''; + $color = 1; - echo "
'.__('Profiles').'IR'; + print_help_tip (__('Read Incidents')); + echo 'IW'; + print_help_tip (__('Create Incidents')); + echo 'IM'; + print_help_tip (__('Manage Incidents')); + echo 'AR'; + print_help_tip (__('Read Agent Information')); + echo 'AW'; + print_help_tip (__('Manage Agents')); + echo 'LW'; + print_help_tip (__('Edit Alerts')); + echo 'UM'; + print_help_tip (__('Manage User Rights')); + echo 'DM'; + print_help_tip (__('Database Management')); + echo 'LM'; + print_help_tip (__('Alerts Management')); + echo 'PM'; + print_help_tip (__('Pandora System Management')); + echo ''.__('Delete').'
"; - - $sql = "SELECT * FROM tperfil"; - $result = mysql_query ($sql); - echo ""; - echo ""; - - while (profile = mysql_fetch_array ($result)) { - $id_perfil = profile["id_perfil"]; - $nombre=profile["name"]; - $incident_view = profile["incident_view"]; - $incident_edit = profile["incident_edit"]; - $incident_management = profile["incident_management"]; - $agent_view = profile["agent_view"]; - $agent_edit =profile["agent_edit"]; - $alert_edit = profile["alert_edit"]; - $user_management = profile["user_management"]; - $db_management = profile["db_management"]; - $alert_management = profile["alert_management"]; - $pandora_management = profile["pandora_management"]; + foreach ($result as $profile) { + $id_perfil = $profile["id_perfil"]; + $nombre = $profile["name"]; + $incident_view = $profile["incident_view"]; + $incident_edit = $profile["incident_edit"]; + $incident_management = $profile["incident_management"]; + $agent_view = $profile["agent_view"]; + $agent_edit = $profile["agent_edit"]; + $alert_edit = $profile["alert_edit"]; + $user_management = $profile["user_management"]; + $db_management = $profile["db_management"]; + $alert_management = $profile["alert_management"]; + $pandora_management = $profile["pandora_management"]; if ($color == 1) { $tdcolor = "datos"; $color = 0; - } - else { + } else { $tdcolor = "datos2"; $color = 1; } - echo ""; + echo ' + + + + + '; } - echo "
".__('Profiles'); - echo "IR"; - print_help_tip (__('System incidents reading')); - echo "IW"; - print_help_tip (__('System incidents writing')); - echo "IM"; - print_help_tip (__('System incidents management')); - echo "AR"; - print_help_tip (__('Agents reading')); - echo "AW"; - print_help_tip (__('Agents management')); - echo "LW"; - print_help_tip (__('Alerts edition')); - echo "UM"; - print_help_tip (__('Users management')); - echo "DM"; - print_help_tip (__('Database management')); - echo "LM"; - print_help_tip (__('Alerts anagement')); - echo "PM"; - print_help_tip (__('Pandora system management')); - echo "".__('Delete')."
".$nombre.""; - - echo ""; - if ($incident_view == 1) echo ""; - - echo ""; - if ($incident_edit == 1) echo ""; - - echo ""; - if ($incident_management == 1) echo ""; - - echo ""; - if ($agent_view == 1) echo ""; - - echo ""; - if ($agent_edit == 1) echo ""; - - echo ""; - if ($alert_edit == 1) echo ""; - - echo ""; - if ($user_management == 1) echo ""; - - echo ""; - if ($db_management == 1) echo ""; - - echo ""; - if ($alert_management == 1) echo ""; - - echo ""; - if ($pandora_management == 1) echo ""; - echo "
+ '.$nombre.' + + '.(($incident_view == 1) ? '' : '').' + + '.(($incident_edit == 1) ? '' : '').' + + '.(($incident_management == 1) ? '' : '').' + + '.(($agent_view == 1) ? '' : '').' + + '.(($agent_edit == 1) ? '' : '').' + + '.(($alert_edit == 1) ? '' : '').' + + '.(($user_management == 1) ? '' : '').' + + '.(($db_management == 1) ? '' : '').' + + '.(($alert_management == 1) ? '' : '').' + + '.(($pandora_management == 1) ? '' : '').' + + + +
"; - echo ''; - echo ''; - echo '
'; - echo "
"; - echo ""; - echo "
"; + echo ' +
+
+ +
+
'; } ?> diff --git a/pandora_console/include/locale.class.php b/pandora_console/include/locale.class.php index c4a7bf9d9a..2a72fc11e4 100644 --- a/pandora_console/include/locale.class.php +++ b/pandora_console/include/locale.class.php @@ -675,6 +675,8 @@ class Set_Locale { $backup_locale = "en_US"; } elseif(in_array("es_ES",$this->locales)) { $backup_locale = "es_ES"; + } else { + $backup_locale = "POSIX"; } if($backup_locale == "" || !in_array($backup_locale,$this->locales)) { @@ -732,12 +734,73 @@ class Set_Locale { function Get_Locales_SelectBox () { foreach ($this->locales as $iter_locale) { - echo ''; + echo ''; + } + } + + //Input: Language code (en, es, nl) -> should be lower case to + //distinguish from country code + //Output: Language name + function Get_Language_Name ($code) { + if (array_key_exists (mb_strtolower($code),$this->lang_codes)) { + return mb_convert_case($this->lang_codes[$code], MB_CASE_TITLE, "UTF-8"); + } + return false; + } + + //Input: Country code (BE, NL, US) -> should be upper case to + //distinguish from language code + //Output: Country name + function Get_Country_Name ($code) { + if (array_key_exists (mb_strtoupper($code),$this->country_codes)) { + return mb_convert_case($this->country_codes[$code], MB_CASE_TITLE, "UTF-8"); + } + return false; + } + + //Input: Money code (USD, EUR) -> should be upper case because of + //international standards + //Output: Money name + function Get_Currency_Name ($code) { + if (array_key_exists (mb_strtoupper($code),$this->currency_codes)) { + return $this->currency_codes[$code]; + } + return false; + } + + function Put_Translated_Language ($array) { + if(!is_array ($array)) { + return false; + } + $this->lang_codes = $array; + return true; + } + + function Put_Translated_Country ($array) { + if(!is_array ($array)) { + return false; + } + $this->country_codes = $array; + } + + function Put_Translated_Currency ($array) { + if(!is_array ($array)) { + return false; + } + $this->currency_codes = $array; + } + + function Translate_Locale_HTML ($locale) { + if(is_array($locale)) { + $locale = array_walk($locale,'Translate_Locale_HTML'); + } else { + $locale = $this->Translate_Locale ($locale); + return htmlentities ($locale); } } function Translate_Locale ($locale) { - if($locale == "UTF-8" || $locale == "C" || $locale == "POSIX") { + if ($locale == "UTF-8" || $locale == "C" || $locale == "POSIX") { return $locale; //Pure UTF-8, C or POSIX is not localized to a country } @@ -748,20 +811,15 @@ class Set_Locale { $char = isset($country_char[1]) ? $country_char[1] : ""; unset ($lang_country, $country_char); - if (in_array($lang,array_keys($this->lang_codes))) { - $lang = $this->lang_codes[$lang]; - } else { - // __("Unknown"); - $lang = "Unknown"; - } + $lang = $this->Get_Language_Name ($lang); + $cntr = $this->Get_Country_Name ($cntr); - if (in_array($cntr,array_keys($this->country_codes))) { - $cntr = ucwords(strtolower($this->country_codes[$cntr])); - } else { - // __("Unknown"); + if($lang === false) + $lang = "Unknown"; + + if($cntr === false) $cntr = "Unknown"; - } - + if($char != "") { $char = " - ".$char; } @@ -770,12 +828,10 @@ class Set_Locale { } function Translate_Currency ($currency) { - $currency = trim($currency); - - if(in_array($currency,array_keys($this->currency_codes))) { - return $this->currency_codes[$currency]; - } - return "Unknown"; + $currency = $this->Get_Currency_Name (trim($currency)); + if($currency === false) + return "Unknown"; + return $currency; } //This private function comes back with the precision of a specific @@ -866,7 +922,7 @@ class Set_Locale { } elseif($out == "SHORT") { $currency = $this->MONFORMAT['currency_symbol']; } elseif($out == "LONG") { - $currency = $this->Translate_Currency($currency); + $currency = $this->Translate_Currency($this->MONFORMAT['int_curr_symbol']); } else { $currency = $this->MONFORMAT['int_curr_symbol']; } @@ -962,5 +1018,6 @@ class Set_Locale { } return $output; } - } +} + ?>