<?php
require_once $config['site_path'] . "/lang/" . $config["lang"] . ".php";

$import_calc = <<<EOD
global \$table;
if (\$user['group_id']!=1)
{
  if (\$user['sub_admin']==1)
  {
    if (\$line['Группа доступа']==1)
    {
      if (\$table['user_table_fields']['group_id'])
      {
        data_update(\$event['table_id'], array("f".\$table['user_table_fields']['group_id']=>0), "id=".\$event['line_id']); 
      }
    }
  }
}
EOD;

$sqlQuery = "SELECT * FROM " . $config['table_prefix'] . "tables WHERE user_table_link!=''";
$result = run_query($sqlQuery);
while ($table = sql_fetch_assoc($result)) {
    $user_table_link = unserialize($table['user_table_link']);
    if ($user_table_link['group_id'] && !$user_table_link['calcs']['import']) {
        run_query("INSERT INTO " . $config['table_prefix'] . "calc (table_id, name, calculate) VALUES ('" . $table['id'] . "', '" . $lang['import_link_user'] . "', '" . mysqli_escape_string($sql_global_link, $import_calc) . "')");
        $calc_id = sql_insert_id();
        run_query("INSERT INTO " . $config['table_prefix'] . "calc_cond (calc_id, type, param) VALUES ('" . $calc_id . "', '5', '" . $table['id'] . "')");
        $user_table_link['calcs']['import'] = $calc_id;
        $table_save = serialize($user_table_link);
        run_query("UPDATE " . $config['table_prefix'] . "tables SET user_table_link='" . $table_save . "' WHERE id='" . $table['id'] . "' LIMIT 1");
    }
}