access != "admin") || $isAdmin) ? "" : "disabled "; foreach ($field->attribute as $attribute) $attributesString .= $attribute['key']. "='$attribute' "; if (is_array($custom_fields) and array_key_exists((string)$field['key'], $custom_fields)) $fieldValue = (string)$custom_fields[(string)$field['key']]; else $fieldValue = (string)$field->default_value; $idString = "id='".clean_id_string($field['key'])."'"; $nameString = "name='fields[".$field['key']."]'"; $fieldType = $field['type']; if ($fieldType == "select") { $inputElementString = ""; } else { if ($fieldType == "checkbox_key_value") { if ($fieldValue) // convert the XML object to string $attributesString .= "checked='checked' "; $fieldValue = $field['key']; $fieldType = "checkbox"; } else if ($fieldType == "checkbox") { if ($fieldValue) // convert the XML object to string $attributesString .= "checked='checked' "; } $inputElementString = ""; } echo "$inputElementString\n"; } function exec_ogp_module() { global $db,$view,$custom_fields,$isAdmin; $home_id = $_GET['home_id']; $isAdmin = $db->isAdmin( $_SESSION['user_id'] ); if( $isAdmin ) { $home_info = $db->getGameHome($home_id); $custom_fileds_access_enabled = TRUE; } else { $home_info = $db->getUserGameHome($_SESSION['user_id'],$home_id); $custom_fileds_access_enabled = preg_match("/c/",$home_info['access_rights']) > 0 ? TRUE : FALSE; } if( !$home_info OR !$custom_fileds_access_enabled ) return; //get used custom value or get default $customFieldsFromDB = $db->getCustomFields($home_id); $custom_fields = $customFieldsFromDB !== false ? json_decode($customFieldsFromDB, True) : array(); $server_xml = read_server_config(SERVER_CONFIG_LOCATION.$home_info['home_cfg_file']); include_once('includes/lib_remote.php'); $remote = new OGPRemoteLibrary($home_info['agent_ip'],$home_info['agent_port'],$home_info['encryption_key'],$home_info['timeout']); echo "

".get_lang('editing_home_called')." \"".htmlentities($home_info['home_name'])."\"

"; echo "

"; echo "<< ".get_lang('back_to_game_monitor').""; echo "

"; if(isset($_POST['update_settings'])) { $save_field = $_POST['fields']; $updatedSettings = array(); foreach($server_xml->custom_fields->field as $field) { if (array_key_exists((string)$field['key'], (array)$custom_fields)){ $origValue = (string)$custom_fields[(string)$field['key']]; }else{ $origValue = ""; } $found = 0; foreach ($save_field as $key => $value ) { if($key == (string)$field['key']){ $found++; // If locked by an admin, ignore the value posted by the user $lockedByAdmin = false; if(property_exists($field, 'access') && $field->access == "admin") { $lockedByAdmin = true; if(!$isAdmin){ $value = $origValue; // Set it to the old saved value (which was last set by an admin) or set it to its default value } } if (strlen(trim($value)) > 0) { $updatedSettings[$key] = $value; } break; } } if($found == 0 && !empty($origValue)){ $updatedSettings[(string)$field['key']] = $origValue; } } if(is_array($updatedSettings) && count($updatedSettings) > 0){ $db->changeCustomFields($home_info['home_id'],json_encode($updatedSettings)); }else{ $db->changeCustomFields($home_info['home_id'],""); } print_success(get_lang('settings_updated')); $view->refresh("?m=user_games&p=custom_fields&home_id=".$home_id); } $ft = new FormTable(); $ft->start_form("", "post", "autocomplete=\"off\""); $ft->start_table(); foreach($server_xml->custom_fields->field as $field) { renderCustomFields($field, $home_info['home_id']); } $ft->end_table(); $ft->add_button("submit","update_settings",get_lang('update_settings')); $ft->end_form(); } ?>