* LiveZilla is a registered trademark.
* 
* Improper changes to this file may cause critical errors.
***************************************************************************************/
define("IN_LIVEZILLA", true);
if (!defined("LIVEZILLA_PATH")) {
    define("LIVEZILLA_PATH", "./");
}
header("Content-Type: text/html; charset=UTF-8");
require LIVEZILLA_PATH . "_definitions/definitions.inc.php";
require LIVEZILLA_PATH . "_definitions/definitions.protocol.inc.php";
require LIVEZILLA_PATH . "_lib/functions.global.inc.php";
require LIVEZILLA_PATH . "_definitions/definitions.dynamic.inc.php";
require LIVEZILLA_PATH . "_lib/functions.index.inc.php";
require LIVEZILLA_PATH . "_lib/objects.global.users.inc.php";
CacheManager::Flush();
languageSelect();
@set_error_handler("handleError");
initDataProvider();
defineURL("index.php");
$scheme = getScheme();
$html = getFile(TEMPLATE_HTML_INDEX);
$errorbox = null;
$errors['write'] = getFolderPermissions();
$errors['php_version'] = getPhpVersion();
$errors['mysql'] = getMySQL();
$errors['disabled'] = getDisabledFunctions();
if (!empty($errors['write']) || !empty($errors['php_version']) || !empty($errors['mysql']) || !empty($errors['disabled'])) {
    $errorbox = getFile(TEMPLATE_HTML_INDEX_ERRORS);
    $errorbox = str_replace("<!--write_access-->", $errors['write'], $errorbox);
    if (strlen($errors['write']) > 0 && !empty($errors['php_version'])) {
 static function UpdateConfiguration($id = 0)
 {
     if (OperatorRequest::IsValidated() && Is::Defined("VALIDATED_FULL_LOGIN") && OperatorRequest::IsAdministrator(true)) {
         Logging::SecurityLog("ServerManager::UpdateConfiguration", "", CALLER_SYSTEM_ID);
         if (Is::Defined("STATS_ACTIVE") && !empty($_POST["p_reset_stats"])) {
             Server::$Statistic->ResetAll();
         }
         $int = 0;
         if (DB_CONNECTION) {
             DBManager::Execute(true, "UPDATE `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_TYPES . "` SET `delete`='1';");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_LOCALIZATIONS . "`;");
             while (!empty($_POST["p_cfg_cct_id_" . $int])) {
                 $cct = new CommercialChatBillingType($_POST["p_cfg_cct_id_" . $int], $_POST["p_cfg_cct_mnoc_" . $int], $_POST["p_cfg_cct_mtloc_" . $int], $_POST["p_cfg_cct_tae_" . $int], $_POST["p_cfg_cct_tvbo_" . $int], $_POST["p_cfg_cct_svbo_" . $int], $_POST["p_cfg_cct_evbo_" . $int], $_POST["p_cfg_cct_citl_" . $int], $_POST["p_cfg_cct_p_" . $int]);
                 $cct->Save();
                 $iint = 0;
                 while (!empty($_POST["p_cfg_cctli_id_" . $int . "_" . $iint])) {
                     $cctl = new CommercialChatVoucherLocalization($_POST["p_cfg_cctli_id_" . $int . "_" . $iint], $_POST["p_cfg_cctli_itl_" . $int . "_" . $iint], $_POST["p_cfg_cctli_t_" . $int . "_" . $iint], $_POST["p_cfg_cctli_d_" . $int . "_" . $iint], $_POST["p_cfg_cctli_terms_" . $int . "_" . $iint], $_POST["p_cfg_cctli_emvc_" . $int . "_" . $iint], $_POST["p_cfg_cctli_emvp_" . $int . "_" . $iint], $_POST["p_cfg_cctli_emvu_" . $int . "_" . $iint], $_POST["p_cfg_cctli_exr_" . $int . "_" . $iint]);
                     $cctl->Save($_POST["p_cfg_cct_id_" . $int]);
                     $iint++;
                 }
                 $int++;
             }
             $int = 0;
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_PROVIDERS . "`;");
             while (!empty($_POST["p_cfg_ccpp_id_" . $int])) {
                 $ccpp = new CommercialChatPaymentProvider($_POST["p_cfg_ccpp_id_" . $int], $_POST["p_cfg_ccpp_n_" . $int], $_POST["p_cfg_ccpp_a_" . $int], $_POST["p_cfg_ccpp_u_" . $int], $_POST["p_cfg_ccpp_l_" . $int]);
                 $ccpp->Save();
                 $int++;
             }
             $int = 0;
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_MAILBOXES . "`;");
             while (!empty($_POST["p_cfg_es_i_" . $int])) {
                 $acc = new Mailbox($int, true);
                 $acc->Save();
                 $int++;
             }
             $int = 0;
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_FEEDBACK_CRITERIA_CONFIG . "`;");
             while (isset($_POST["p_cfg_fc_i_" . $int])) {
                 $fc = new FeedbackCriteria($int, true);
                 $fc->Save();
                 $int++;
             }
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_COMMERCIAL_CHAT_TYPES . "` WHERE `delete`='1';");
             DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_CONFIG . "`;");
             foreach ($_POST as $key => $value) {
                 if (strpos($key, "p_cfg_g_") === 0) {
                     $skey = str_replace("p_cfg_g_", "", $key);
                     $value = base64_decode($value);
                     DBManager::Execute(true, "REPLACE INTO `" . DB_PREFIX . DATABASE_CONFIG . "` (`key`,`value`) VALUES ('" . DBManager::RealEscape($skey) . "','" . DBManager::RealEscape($value) . "');");
                 }
             }
             CacheManager::Flush();
         }
         if (isset($_POST["p_available"])) {
             ServerManager::UpdateAvailability(!empty($_POST["p_available"]));
         }
         //$id = IOStruct::CreateFile($file,base64_decode($_POST["p_upload_value"]),true);
     }
     GeoTracking::SpanRemove(true);
     CacheManager::Flush();
     Server::$Response->SetStandardResponse($id, "");
 }