<?php
/**
 * Administrative User Interface.
 *
 * Provides links for administrators to get to other administrative areas of the site
 *
 * $Id: admin.php,v 1.69 2004/12/01 18:05:59 yalnifj Exp $
 *
 * phpGedView: Genealogy Viewer
 * Copyright (C) 2002 to 2003	John Finlay and Others
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * @package PhpGedView
 * @subpackage Admin
 */

/** 
 * load the main configuration and context
 */
require "config.php";
if (!userGedcomAdmin(getUserName())) {
	header("Location: login.php?url=admin.php");
	exit;
}

require $PGV_BASE_DIRECTORY . $confighelpfile["english"];
if (file_exists($PGV_BASE_DIRECTORY . $confighelpfile[$LANGUAGE])) require $PGV_BASE_DIRECTORY . $confighelpfile[$LANGUAGE];

if (!isset($action)) $action="";
if ($action=="phpinfo") {
	phpinfo();
	exit;
}

print_header($pgv_lang["administration"]);

$d_pgv_changes = "";
if (count($pgv_changes) > 0) $d_pgv_changes = "<a href=\"#\" onclick=\"window.open('gdbi_changes.php','','width=600,height=600,resizable=1,scrollbars=1'); return false;\">" . $pgv_lang["accept_changes"] . "</a>\n";
$d_php_info = "<a href=\"admin.php?action=phpinfo\">" . $pgv_lang["show_phpinfo"] . "</a>";

if (!isset($logfilename)) $logfilename = "";
$file_nr = 0;
$dir_var = opendir ($INDEX_DIRECTORY);
while ($file = readdir ($dir_var))
{
  if (strpos($file, ".log") > 0){$dir_array[$file_nr] = $file; $file_nr++;}
}
closedir($dir_var);
$d_logfile_str  = "<form action=\"admin.php\" method=\"post\">";
$d_logfile_str .= $pgv_lang["view_logs"] . ": ";
$d_logfile_str .= "\n<select name=\"logfilename\">\n";
$ct = count($dir_array);
for($x = 0; $x < $file_nr; $x++)

{
  $ct--;
  $d_logfile_str .= "<option value=\"";
  $d_logfile_str .= $dir_array[$ct];
  if ($dir_array[$ct] == $logfilename) $d_logfile_str .= "\" selected=\"selected";
  $d_logfile_str .= "\">";
  $d_logfile_str .= $dir_array[$ct];
  $d_logfile_str .= "</option>\n";
}
$d_logfile_str .= "</select>\n";
$d_logfile_str .= "<input type=\"submit\" name=\"logfile\" value=\" &gt; \" />";
$d_logfile_str .= "</form>";

$usermanual_filename = "docs/english/PGV-manual-en.html";
$d_LangName = "lang_name_" . "english";
$doc_lang = $pgv_lang[$d_LangName];
$new_usermanual_filename = "docs/" . $languages[$LANGUAGE] . "/PGV-manual-" . $language_settings[$LANGUAGE]["lang_short_cut"] . ".html";
if (file_exists($new_usermanual_filename)){$usermanual_filename = $new_usermanual_filename; $d_LangName = "lang_name_" . $languages[$LANGUAGE]; $doc_lang = $pgv_lang[$d_LangName];}

$d_img_module_str = "&nbsp;";
if (file_exists($PGV_BASE_DIRECTORY."img_editconfig.php")) $d_img_module_str = "<a href=\"img_editconfig.php?action=edit\">".$pgv_lang["img_admin_settings"]."</a><br />";

$err_write = file_is_writeable("config.php");

$users = getUsers();
$verify_msg = false;
foreach($users as $user) {
	if (!$user["verified_by_admin"] && $user["verified"])  {
		$verify_msg = true;
	}
}
?>
<div class="center"><!--center-->
  <table class="facts_table, <?php print $TEXT_DIRECTION ?>">
    <tr>
      <td colspan="2" class="facts_label03"><?php print "<h2>PhpGedView v" . $VERSION . " " . $VERSION_RELEASE . "<br />" . $pgv_lang["administration"]. "</h2>".$pgv_lang["system_time"]." ".get_changed_date(date("j M Y"))." - ".date($TIME_FORMAT); ?>
      <?php if ($err_write) print "<br /><span class=\"error\">".$pgv_lang["config_still_writable"]."</span><br /><br />";
	  if ($verify_msg) print "<br /><span class=\"error\">".$pgv_lang["admin_verification_waiting"]."</span><br /><br />";?>
      </td>
    </tr>
    <tr>
      <td colspan="2" class="facts_value" style="text-align:center; "><?php print $pgv_lang["select_an_option"]; ?></td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td class="facts_value"><a href="readme.txt" target="manual"><?php print $pgv_lang["readme_documentation"];?></a></td>
      <td class="facts_value"><a href="editlang.php"><?php print $pgv_lang["edit_langdiff"];?></a></td>
    </tr>
    <tr>
      <td class="facts_value"><?php if (userIsAdmin(getUserName())) { ?><a href="editconfig.php"><?php print $pgv_lang["configuration"];?></a><?php } else { print "&nbsp;"; } ?></td>
	  <td class="facts_value"><a href="gdbi_merge.php"><?php print $pgv_lang["merge_records"]; ?></a></td>
    </tr>
    <tr>
      <td class="facts_value"><a href="editgedcoms.php"><?php print $pgv_lang["manage_gedcoms"];?></a></td>
      <td class="facts_value"><?php print $d_img_module_str; ?></td>
    </tr>
    <tr>
      <td class="facts_value"><?php if (userIsAdmin(getUserName())) { ?><a href="useradmin.php"><?php print $pgv_lang["user_admin"];?></a><?php } else { print "&nbsp;"; } ?></td>
      <td class="facts_value"><?php print "&nbsp;";?></td>
    </tr>
    <tr>
      <td class="facts_value"><a href="uploadmedia.php"><?php print $pgv_lang["upload_media"];?></a></td>
      <td class="facts_value"><?php print $d_php_info; ?></td>
    </tr>
    <tr>
      <td class="facts_value"><?php if ($d_pgv_changes != "") print $d_pgv_changes; else print "&nbsp;"; ?></td>
      <td class="facts_value"><a href="http://phpgedview.sourceforge.net/registry.php" target="_blank"><?php print $pgv_lang["pgv_registry"];?></a></td>
   </tr>
    <tr>
      <td class="facts_value"><?php if (userIsAdmin(getUserName())) { ?><a href="usermigrate.php"><?php print $pgv_lang["um_header"];?></a><?php } else { print "&nbsp;"; } ?></td>
      <td class="facts_value"><?php if (userIsAdmin(getUserName())) { print $d_logfile_str; } else { print "&nbsp;"; } ?></td>
   </tr>
  </table>
<!--/center--></div>

<?php
  if (isset($logfilename) and ($logfilename != ""))
  {
    print "<hr><table align=\"center\" width=\"70%\"><tr><td class=\"listlog\">";
    print "<strong>" . $pgv_lang["logfile_content"] . " [" . $INDEX_DIRECTORY . $logfilename . "]</strong><br /><br />";
    $lines=file($INDEX_DIRECTORY . $logfilename);
    $num = sizeof($lines); for ($i = 0; $i < $num ; $i++)
    {
      print $lines[$i] . "<br />";
    }
    print "</td></tr></table><hr>";
  }
?>
<br /><br />
<?php
print_footer();
?>

