<commit_before><?php
require_once dirname(__FILE__).'/accesscheck.php';


$attributes = array();
ob_end_flush();

function readentry($file) {
  if (ereg('\.\.',$file)) return;
  if (!ereg('data/',$file)) return;
  $fp = fopen($file,"r");
  $found = "";
  while (!feof ($fp)) {
    $buffer = fgets($fp, 4096);
    if (!ereg("#",$buffer)) {
      $found = $buffer;
      fclose($fp);
      return $found;
    }
  }
  fclose ($fp);
  return "";
}

$dir = opendir("data");
while ($file = readdir($dir)) {
  if (is_file("data/$file")) {
    $entry = readentry("data/$file");
    $attributes[$entry] = $file;
  }
}
closedir($dir);

if (!empty($_POST['selected']) && is_array($_POST['selected'])) {
  $selected = $_POST['selected'];
  while(list($key,$val) = each($selected)) {
    $entry = readentry("data/$val");
    list($name,$desc) = explode(":",$entry);
    print "<br/><br/>".$GLOBALS['I18N']->get('loading')." $desc<br/>\n";
    $lc_name = str_replace(" ","", strtolower(str_replace(".txt","",$val)));
    $lc_name = ereg_replace("[^[:alnum:]]","",$lc_name);

    if ($lc_name == "") Fatal_Error($GLOBALS['I18N']->get('name_empty')." $lc_name");
    Sql_Query("select * from {$tables['attribute']} where tablename = \"$lc_name\"");
    if (Sql_Affected_Rows()) Fatal_Error($GLOBALS['I18N']->get('name_not_unique'));

    $query = sprintf('insert into %s (name,type,required,tablename) values("%s","%s",%d,"%s")',
    $tables["attribute"],addslashes($name),"select",1,$lc_name);
    Sql_Query($query);
    $insertid = Sql_Insert_Id($tables['attribute'], 'id');

    $query = "create table $table_prefix"."listattr_$lc_name (id integer not null primary key auto_increment, name varchar(255) unique,listorder integer default 0)";
    Sql_Query($query);
    $fp = fopen("data/$val","r");
    $header = "";
    while (!feof ($fp)) {
      $buffer = fgets($fp, 4096);
      if (!ereg("#",$buffer)) {
        if (!$header)
          $header = $buffer;
        else if (trim($buffer) != "")
          Sql_Query(sprintf('insert into %slistattr_%s (name) values("%s")',$table_prefix,$lc_name,trim($buffer)));
      }
    }
    fclose ($fp);
  }
  print $GLOBALS['I18N']->get('done')."<br/><br/>";
  
  print PageLink2("attributes",$GLOBALS['I18N']->get('return to editing attributes'));
  
#@@@@ not sure about this one:  print '<p class="button">'.PageLink2("attributes",$GLOBALS['I18N']->get('continue')).'</p>';

} else {

?>


<?php echo formStart(' class="defaultsAdd"')?>
<?php
reset($attributes);
while (list($key,$attribute) = each ($attributes)) {
  if (strstr($key,':')) {
    list($name,$desc) = explode(":",$key);
    if ($name && $desc) {
      printf('<input type="checkbox" name="selected[]" value="%s" />%s<br/>', $attribute,$desc);
    }
  }
}
print '<input class="submit" type="submit" value="'.$GLOBALS['I18N']->get('add').'" /></form>';

}<commit_msg>remove deprecated calls<commit_after><?php
require_once dirname(__FILE__).'/accesscheck.php';


$attributes = array();
@ob_end_flush();

function readentry($file) {
  if (preg_match('/\.\./',$file)) return;
  if (!preg_match('/data/',$file)) return;
  $fp = fopen($file,"r");
  $found = "";
  while (!feof ($fp)) {
    $buffer = fgets($fp, 4096);
    if (strpos($buffer,"#") === false) {
      $found = $buffer;
      fclose($fp);
      return $found;
    }
  }
  fclose ($fp);
  return "";
}

$dir = opendir("data");
while ($file = readdir($dir)) {
  if (is_file("data/$file")) {
    $entry = readentry("data/$file");
    $attributes[$entry] = $file;
  }
}
closedir($dir);

if (!empty($_POST['selected']) && is_array($_POST['selected'])) {
  $selected = $_POST['selected'];
  while(list($key,$val) = each($selected)) {
    $entry = readentry("data/$val");
    list($name,$desc) = explode(":",$entry);
    print "<br/><br/>".$GLOBALS['I18N']->get('loading')." $desc<br/>\n";
    $lc_name = str_replace(" ","", strtolower(str_replace(".txt","",$val)));
    $lc_name = preg_replace("/[\W]/","",$lc_name);

    if ($lc_name == "") Fatal_Error($GLOBALS['I18N']->get('name_empty')." $lc_name");
    Sql_Query("select * from {$tables['attribute']} where tablename = \"$lc_name\"");
    if (Sql_Affected_Rows()) Fatal_Error($GLOBALS['I18N']->get('name_not_unique'));

    $query = sprintf('insert into %s (name,type,required,tablename) values("%s","%s",%d,"%s")',
    $tables["attribute"],addslashes($name),"select",1,$lc_name);
    Sql_Query($query);
    $insertid = Sql_Insert_Id($tables['attribute'], 'id');

    $query = "create table $table_prefix"."listattr_$lc_name (id integer not null primary key auto_increment, name varchar(255) unique,listorder integer default 0)";
    Sql_Query($query);
    $fp = fopen("data/$val","r");
    $header = "";
    while (!feof ($fp)) {
      $buffer = fgets($fp, 4096);
      if (strpos($buffer,"#") === false) {
        if (!$header)
          $header = $buffer;
        else if (trim($buffer) != "")
          Sql_Query(sprintf('insert into %slistattr_%s (name) values("%s")',$table_prefix,$lc_name,trim($buffer)));
      }
    }
    fclose ($fp);
  }
  print $GLOBALS['I18N']->get('done')."<br/><br/>";
  
  print PageLinkButton("attributes",$GLOBALS['I18N']->get('return to editing attributes'));
  
#@@@@ not sure about this one:  print '<p class="button">'.PageLink2("attributes",$GLOBALS['I18N']->get('continue')).'</p>';

} else {

?>


<?php echo formStart(' class="defaultsAdd"')?>
<?php
reset($attributes);
while (list($key,$attribute) = each ($attributes)) {
  if (strstr($key,':')) {
    list($name,$desc) = explode(":",$key);
    if ($name && $desc) {
      printf('<input type="checkbox" name="selected[]" value="%s" />%s<br/>', $attribute,$desc);
    }
  }
}
print '<input class="submit" type="submit" value="'.$GLOBALS['I18N']->get('add').'" /></form>';

}
{'fraction_non_alphanumeric': 0.25229596257147807, 'fraction_numerical': 0.00987697106220759, 'mean_word_length': 4.471090047393365, 'pattern_counts': {'":': 4, '<': 31, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '232063', 'n_tokens_mistral': 2089, 'n_tokens_neox': 2055, 'n_words': 356}