custom_fields.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. require_once("modules/config_games/server_config_parser.php");
  25. require_once('includes/form_table_class.php');
  26. function renderCustomFields($field, $home_id)
  27. {
  28. global $db;
  29. $attributesString = "";
  30. foreach ($field->attribute as $attribute)
  31. $attributesString .= $attribute['key']. "='$attribute' ";
  32. //get used custom value or get default
  33. $custom_fields = json_decode($db->getCustomFields($home_id), True);
  34. if (is_array($custom_fields) and array_key_exists((string)$field['key'], $custom_fields))
  35. $fieldValue = (string)$custom_fields[(string)$field['key']];
  36. else
  37. $fieldValue = (string)$field->default_value;
  38. $idString = "id='".clean_id_string($field['key'])."'";
  39. $nameString = "name='fields[".$field['key']."]'";
  40. $fieldType = $field['type'];
  41. if ($fieldType == "select")
  42. {
  43. $inputElementString = "<select $idString $nameString>";
  44. foreach ($field->option as $option)
  45. {
  46. $optionValue = (string)($option['value']);
  47. $selectedString = ($optionValue == $fieldValue) ? "selected='selected'" : "";
  48. $valueString = "value=\"".str_replace('"', "&quot;", strip_real_escape_string($optionValue))."\"";
  49. $inputElementString .= "<option $selectedString $valueString>$option</option>";
  50. }
  51. $inputElementString .="</select>";
  52. } else
  53. {
  54. if ($fieldType == "checkbox_key_value") {
  55. if ($fieldValue) // convert the XML object to string
  56. $attributesString .= "checked='checked' ";
  57. $fieldValue = $field['key'];
  58. $fieldType = "checkbox";
  59. }
  60. else if ($fieldType == "checkbox")
  61. {
  62. if ($fieldValue) // convert the XML object to string
  63. $attributesString .= "checked='checked' ";
  64. }
  65. $inputElementString = "<input $idString $nameString ".
  66. "type='$fieldType' value=\"".str_replace('"', "&quot;", strip_real_escape_string($fieldValue))."\" $attributesString/>";
  67. }
  68. echo "<tr><td class='right'><label for='".clean_id_string($field['key'])."'>".$field['key'].
  69. ":</label></td><td class='left'>$inputElementString<label for='".clean_id_string($field['key'])."'>";
  70. if ( !empty($field->caption) )
  71. echo $field->caption;
  72. if ( !empty($field->desc) )
  73. echo "<br/><span class='info'>(".$field->desc.")</span>";
  74. echo "</label></td></tr>\n";
  75. }
  76. function exec_ogp_module()
  77. {
  78. global $db,$view;
  79. $home_id = $_GET['home_id'];
  80. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  81. if( $isAdmin )
  82. {
  83. $home_info = $db->getGameHome($home_id);
  84. $custom_fileds_access_enabled = TRUE;
  85. }
  86. else
  87. {
  88. $home_info = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  89. $custom_fileds_access_enabled = preg_match("/c/",$home_info['access_rights']) > 0 ? TRUE : FALSE;
  90. }
  91. if( !$home_info OR !$custom_fileds_access_enabled )
  92. return;
  93. $server_xml = read_server_config(SERVER_CONFIG_LOCATION.$home_info['home_cfg_file']);
  94. include('includes/lib_remote.php');
  95. $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']);
  96. echo "<h2>".get_lang('editing_home_called')." \"".htmlentities($home_info['home_name'])."\"</h2>";
  97. echo "<p>";
  98. echo "<a href='?m=gamemanager&p=game_monitor&home_id=$home_id'>&lt;&lt; ".get_lang('back_to_game_monitor')."</a>";
  99. if ( $isAdmin )
  100. {
  101. echo " &nbsp; ";
  102. echo "<a href='?m=user_games'>&lt;&lt; ".get_lang('back_to_game_servers')."</a>";
  103. }
  104. echo " &nbsp; ";
  105. echo "<a href='?m=user_games&p=edit&home_id=$home_id'>&lt;&lt; ".get_lang('back_to_edit_server')."</a>";
  106. echo "</p>";
  107. if(isset($_POST['update_settings']))
  108. {
  109. $save_field = $_POST['fields'];
  110. $db->changeCustomFields($home_info['home_id'],json_encode($save_field));
  111. print_success(get_lang('settings_updated'));
  112. $view->refresh("?m=user_games&p=custom_fields&home_id=".$home_id);
  113. }
  114. $ft = new FormTable();
  115. $ft->start_form("", "post", "autocomplete=\"off\"");
  116. $ft->start_table();
  117. foreach($server_xml->custom_fields->field as $field)
  118. {
  119. renderCustomFields($field, $home_info['home_id']);
  120. }
  121. $ft->end_table();
  122. $ft->add_button("submit","update_settings",get_lang('update_settings'));
  123. $ft->end_form();
  124. }
  125. ?>