<?php
	if(($num_versao_atual < 9900008 || empty($num_versao_atual) ))
	{
		global $nm_ini_sys, $obj_lic;

        //fix liga cache
        if($obj_lic->hasRightToVersion('9.9.008'))
        {
            $nm_ini_sys->SetTag('sys_tab_cache_file', 'Y');
        }
        else
        {
            $nm_ini_sys->SetTag('sys_tab_cache_file', 'N');
        }
        $nm_ini_sys->SetTag('sys_tab_cache_file_eof', '7');
        $nm_ini_sys->Save();
        //fim fix liga cache


        //fix tema ordenacao de campo
        $arr_path   = array(
            'sys'        => $nm_config['path_sys'],
            'grp'        => $nm_config['path_grp'],
            'usr'        => $nm_config['path_usr'],
        );

        $arr_list = array();
        foreach ($arr_path as $str_mod => $str_path)
        {
            if($str_mod == 'sys')
            {
                if(is_dir($str_path . "schema/"))
                {
                    $arr_schemas = array_diff(scandir($str_path. "schema/"), array('.','..', 'index.html'));
                    if(isset($arr_schemas) && is_array($arr_schemas) && !empty($arr_schemas))
                    {
                        foreach($arr_schemas as $schema)
                        {
                            if(substr($schema, -3) == 'ini')
                            {
                                $arr_list[$str_mod . '__NM__' . $schema] = $str_path . "schema/" . $schema;
                            }
                        }
                    }
                }
            }
            else
            {
                $arr_childs = array_diff(scandir($str_path), array('.','..', 'index.html'));
                if(isset($arr_childs) && is_array($arr_childs) && !empty($arr_childs))
                {
                    foreach($arr_childs as $childs)
                    {
                        if(is_dir($str_path . $childs) && is_dir($str_path . $childs . "/schema/"))
                        {
                            $arr_schemas = array_diff(scandir($str_path . $childs . "/schema/"), array('.','..', 'index.html'));
                            if(isset($arr_schemas) && is_array($arr_schemas) && !empty($arr_schemas))
                            {
                                foreach($arr_schemas as $schema)
                                {
                                    if(substr($schema, -3) == 'ini')
                                    {
                                        $arr_list[$str_mod . '__NM__' . $schema] = $str_path . $childs . "/schema/" . $schema;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if(!empty($arr_list))
        {
            foreach($arr_list as $schema)
            {
                $arr_schema = unserialize(file_get_contents($schema));

                if(!isset($arr_schema['schema']['css_grid_fieldgroup_label_color']))
                {
                    if(isset($arr_schema['schema']['css_grid_label_link_color']))
                    {
                        $arr_schema['schema']['css_grid_fieldgroup_label_color'] = $arr_schema['schema']['css_grid_label_link_color'];
                        if(strpos(strtolower($arr_schema['schema']['css_grid_fieldgroup_label_color']), "fff")!==false)
                        {
                            $arr_schema['schema']['css_grid_fieldgroup_label_color'] = $arr_schema['schema']['css_grid_label_background_color'];
                        }

                        $arr_schema['schema']['css_grid_campo_impar_label_color'] = $arr_schema['schema']['css_grid_label_link_color'];
                        $arr_schema['schema']['css_grid_campo_par_label_color'] = $arr_schema['schema']['css_grid_label_link_color'];
                        if(
                            strpos(strtolower($arr_schema['schema']['css_grid_campo_par_background_color']), "fff")!==false ||
                            strpos(strtolower($arr_schema['schema']['css_grid_campo_impar_background_color']), "fff")!==false
                        )
                        {
                            $arr_schema['schema']['css_grid_campo_impar_label_color'] = $arr_schema['schema']['css_grid_label_background_color'];
                            $arr_schema['schema']['css_grid_campo_par_label_color']   = $arr_schema['schema']['css_grid_label_background_color'];
                        }

                        file_put_contents($schema, serialize($arr_schema));
                    }
                }
            }
        }
    }
    $return = true;
?>