<commit_before>
<div id="configurecontent"></div>

<?php
require_once dirname(__FILE__).'/accesscheck.php';
/*
if ($_GET["firstinstall"] || $_SESSION["firstinstall"]) {
  $_SESSION["firstinstall"] = 1;
  print "<p class="x">" . $GLOBALS['I18N']->get('checklist for installation') . "</p>";
  require "setup.php";
}
*/

if (isset($_GET['resetdefault']) && $_GET['resetdefault'] == 'yes') {
  Sql_Query(sprintf('delete from %s where editable and item in ("%s")',$GLOBALS['tables']['config'],join('","',array_keys($default_config))));
  $_SESSION['action_result'] = s('The settings have been reset to the phpList default');
  Redirect('configure');
}

if (empty($_REQUEST['id'])) {
  $id = '';
} else {
  $id = $_REQUEST['id'];
  if (!isset($default_config[$id])) {
    print $GLOBALS['I18N']->get('invalid request');
    return;
  }
}
#print '<div class="actions">'.PageLinkButton('configure&resetdefault=yes',s('Reset to default')).'</div>';

if (empty($_GET['id'])) {
    ## @@TODO might be an idea to allow reset on an "id" as well
    $button = new ConfirmButton(
       s('Are you sure you want to reset the configuration to the default?'),
       PageURL2("configure&resetdefault=yes","reset",""),
       s('Reset to default'));
     
    print '<div class="fright">'.$button->show(). '</div>';
    print Info(s('You can edit all of the values in this page, and click the "save changes" button once to save all the changes you made.'),1);
}

$configCategories = array();
$configTypes = array();

foreach ($default_config as $item => $details) {
  if (empty($details['category'])) {
    $details['category'] = 'other';
  }
  if (empty($details['type'])) {
    $details['type'] = 'undefined';
  }
  if (!isset($configCategories[$details['category']])) {
    $configCategories[$details['category']] = array();
  }
  if (!isset($configTypes[$details['type']])) {
    $configTypes[$details['type']] = array();
  }
  $configTypes[$details['type']][] = $item;
  $configCategories[$details['category']][] = $item;
}
#var_dump($configCategories);
#var_dump($configTypes);

print formStart(' class="configForm" ');
# configure options
reset($default_config);
if (!empty($_REQUEST['save'])) {
  if (!verifyToken()) {
    print Error(s('Invalid security token, please reload the page and try again'));
    return;
  }
  $info = $default_config[$id];
  $haserror = 0;
  if (is_array($_POST['values'])) {
    foreach ($_POST['values'] as $id => $value) {
      if (isset($default_config[$id])) {
        $info = $default_config[$id];
        if ($id == "website" || $id == "domain") {
          $value = str_replace("[DOMAIN]","",$value);
          $value = str_replace("[WEBSITE]","",$value);
        }
        if (empty($value) && !$info['allowempty']) {
          Error($info['description']. ' ' . $GLOBALS['I18N']->get('cannot be empty'));
          $haserror = 1;
        } else {
          SaveConfig($id,$value);
        }
      }
    }
    if (!$haserror) {
      print '<div class="actionresult">'.s('Changes Saved').'</div>';
      unset($id);
    }
        
#    Redirect("configure");
#    exit;
  }
}

if (empty($id)) {
  $alternate = 1;

  foreach ($configCategories as $configCategory => $configItems) {
    $some = 0;
    $categoryHTML = '<fieldset id="'.$configCategory.'">';
    $categoryHTML .= '<legend>'.s($configCategory).' '.s('settings').'</legend>';
  
    foreach ($configItems as $configItem) {
      
      $dbvalue = getConfig($configItem);
      if (isset($dbvalue)) {
        $value = $dbvalue;
      } else {
        $value = $default_config[$configItem]['value'];
      }
      if (!in_array($configItem,$GLOBALS['noteditableconfig'])) {
        $some = 1;
        
        $resourceLink = sprintf('<a class="resourcereference" href="http://resources.phplist.com/%s/config:%s" target="_blank">?</a>',$_SESSION['adminlanguage']['iso'],$configItem);
        ## disable this until the resources wiki is organised properly
        $resourceLink = '';
        
        $categoryHTML .= sprintf('<div class="shade%d"><div class="configEdit"><a href="%s" class="ajaxable">%s</a> <b>%s</b> %s</div>',$alternate,PageURL2("configure","","id=$configItem"),s('edit'),$default_config[$configItem]['description'],$resourceLink);
        $categoryHTML .= sprintf('<div id="edit_%s" class="configcontent">%s</div></div>',$configItem,nl2br(htmlspecialchars(stripslashes($value))));
        if ($alternate == 1) {
          $alternate = 2;
        } else {
          $alternate = 1;
        }
      }
    }
    $categoryHTML .= '</fieldset>';
    if ($some) {
      print $categoryHTML;
    }<commit_msg>add title on edit link, as it's not obvious<commit_after>
<div id="configurecontent"></div>

<?php
require_once dirname(__FILE__).'/accesscheck.php';
/*
if ($_GET["firstinstall"] || $_SESSION["firstinstall"]) {
  $_SESSION["firstinstall"] = 1;
  print "<p class="x">" . $GLOBALS['I18N']->get('checklist for installation') . "</p>";
  require "setup.php";
}
*/

if (isset($_GET['resetdefault']) && $_GET['resetdefault'] == 'yes') {
  Sql_Query(sprintf('delete from %s where editable and item in ("%s")',$GLOBALS['tables']['config'],join('","',array_keys($default_config))));
  $_SESSION['action_result'] = s('The settings have been reset to the phpList default');
  Redirect('configure');
}

if (empty($_REQUEST['id'])) {
  $id = '';
} else {
  $id = $_REQUEST['id'];
  if (!isset($default_config[$id])) {
    print $GLOBALS['I18N']->get('invalid request');
    return;
  }
}
#print '<div class="actions">'.PageLinkButton('configure&resetdefault=yes',s('Reset to default')).'</div>';

if (empty($_GET['id'])) {
    ## @@TODO might be an idea to allow reset on an "id" as well
    $button = new ConfirmButton(
       s('Are you sure you want to reset the configuration to the default?'),
       PageURL2("configure&resetdefault=yes","reset",""),
       s('Reset to default'));
     
    print '<div class="fright">'.$button->show(). '</div>';
    print Info(s('You can edit all of the values in this page, and click the "save changes" button once to save all the changes you made.'),1);
}

$configCategories = array();
$configTypes = array();

foreach ($default_config as $item => $details) {
  if (empty($details['category'])) {
    $details['category'] = 'other';
  }
  if (empty($details['type'])) {
    $details['type'] = 'undefined';
  }
  if (!isset($configCategories[$details['category']])) {
    $configCategories[$details['category']] = array();
  }
  if (!isset($configTypes[$details['type']])) {
    $configTypes[$details['type']] = array();
  }
  $configTypes[$details['type']][] = $item;
  $configCategories[$details['category']][] = $item;
}
#var_dump($configCategories);
#var_dump($configTypes);

print formStart(' class="configForm" ');
# configure options
reset($default_config);
if (!empty($_REQUEST['save'])) {
  if (!verifyToken()) {
    print Error(s('Invalid security token, please reload the page and try again'));
    return;
  }
  $info = $default_config[$id];
  $haserror = 0;
  if (is_array($_POST['values'])) {
    foreach ($_POST['values'] as $id => $value) {
      if (isset($default_config[$id])) {
        $info = $default_config[$id];
        if ($id == "website" || $id == "domain") {
          $value = str_replace("[DOMAIN]","",$value);
          $value = str_replace("[WEBSITE]","",$value);
        }
        if (empty($value) && !$info['allowempty']) {
          Error($info['description']. ' ' . $GLOBALS['I18N']->get('cannot be empty'));
          $haserror = 1;
        } else {
          SaveConfig($id,$value);
        }
      }
    }
    if (!$haserror) {
      print '<div class="actionresult">'.s('Changes Saved').'</div>';
      unset($id);
    }
        
#    Redirect("configure");
#    exit;
  }
}

if (empty($id)) {
  $alternate = 1;

  foreach ($configCategories as $configCategory => $configItems) {
    $some = 0;
    $categoryHTML = '<fieldset id="'.$configCategory.'">';
    $categoryHTML .= '<legend>'.s($configCategory).' '.s('settings').'</legend>';
  
    foreach ($configItems as $configItem) {
      
      $dbvalue = getConfig($configItem);
      if (isset($dbvalue)) {
        $value = $dbvalue;
      } else {
        $value = $default_config[$configItem]['value'];
      }
      if (!in_array($configItem,$GLOBALS['noteditableconfig'])) {
        $some = 1;
        
        $resourceLink = sprintf('<a class="resourcereference" href="http://resources.phplist.com/%s/config:%s" target="_blank">?</a>',$_SESSION['adminlanguage']['iso'],$configItem);
        ## disable this until the resources wiki is organised properly
        $resourceLink = '';
        
        $categoryHTML .= sprintf('<div class="shade%d"><div class="configEdit"><a href="%s" class="ajaxable" title="%s">%s</a> <b>%s</b> %s</div>',$alternate,PageURL2("configure","","id=$configItem"),s('edit this value'),s('edit'),$default_config[$configItem]['description'],$resourceLink);
        $categoryHTML .= sprintf('<div id="edit_%s" class="configcontent">%s</div></div>',$configItem,nl2br(htmlspecialchars(stripslashes($value))));
        if ($alternate == 1) {
          $alternate = 2;
        } else {
          $alternate = 1;
        }
      }
    }
    $categoryHTML .= '</fieldset>';
    if ($some) {
      print $categoryHTML;
    }
{'fraction_non_alphanumeric': 0.21217672413793104, 'fraction_numerical': 0.004094827586206897, 'mean_word_length': 3.784020618556701, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 69, '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': '5884362', 'n_tokens_mistral': 2955, 'n_tokens_neox': 2908, 'n_words': 603}