<?php
/*
 * Copyright (c) 2004-2009 Luiz Otavio O Souza <loos.br@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* 
 * $Id: conf.php 102 2009-02-05 18:37:40Z loos-br $
 */

    require('default.array.option.inc.php');
    require('default.array.cmd.inc.php');
    require('mysql.inc.php');
    require('header.inc.php');

    $sql = "SELECT * FROM defaults LIMIT 1";

    $rs = mysql_query($sql, $mysql);
    if (!$rs)
	die('sql fail on get defaults !');

    $row = mysql_fetch_array($rs);
    if (!$row)
	die('fail to get defaults !');

    function print_option( $o, $commands ) {

        global $arrayCMD, $arrayOption;

        $c    = $o;
        $desc = $arrayOption[$c]['desc'];
        $name = $arrayOption[$c]['name'];
        $cmd  = $arrayOption[$c]['cmd'];
?>
        <tr>
          <td><input type="checkbox" value="<?php echo $name ?>" id="<?php echo $name ?>"
                <?php echo ($commands & $arrayCMD[$cmd]) ? "checked" : "" ?>
                onclick="javascript: saveCheckBox('save_default_op.php?name=<?php echo $name ?>', this)">
          </td>
          <td width="45%">
                <label for="<?php echo $name ?>"><?php echo $desc ?></label></td>
<?php
	$c    = $o + 1;
	if ($arrayOption[$c]) {

	    $desc = $arrayOption[$c]['desc'];
	    $name = $arrayOption[$c]['name'];
	    $cmd  = $arrayOption[$c]['cmd'];
?>
          <td><input type="checkbox" value="<?php echo $name ?>" id="<?php echo $name ?>"
                <?php echo ($commands & $arrayCMD[$cmd]) ? "checked" : "" ?>
                onclick="javascript: saveCheckBox('save_default_op.php?name=<?php echo $name ?>', this)">
          </td>
          <td width="45%">
                <label for="<?php echo $name ?>"><?php echo $desc ?></label></td>
        </tr>
<?php
	} else {
?>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	</tr>
<?php
	}
    }

    require("js.inc.php");
?>
<body bgcolor="#FFFFFF">

<form action="index.php" method="GET" name="form">
<div align=center>
 <div style="width: 440px; border-color: gray; border-style: solid; border-width: 1; text-align: center;">
 <p><strong>MSN Proxy - Configura&ccedil;&otilde;es</strong></p>
 <p><a href="index.php">Usuários</a></p>
 </div><br>
 <table border=0 width=440 style="border-color: gray; border-style: solid; border-width: 1;">
  <tr>
    <td bgcolor="#EBEBEB">
	<div align=right><b>IP interno do proxy</b></div><br>
	As estações precisam ter acesso as portas 1863 e de 25000 a
	30000 neste IP.
	</td>
    <td bgcolor="#EBEBEB" width=130 valign=top><input type=text name=ipint
	size=18 maxlength=15 value="<?php echo $row['internal_host'] ?>"
	onblur="saveText('save_default_op.php?name=internal_host', this)"></td>
  </tr>
  <tr>
    <td bgcolor="#EBEBEB">
	<div align=right><b>Conexão</b></div><br>
	Se desligado apenas os usuários cadastrados e ativos poderão
	utilizar o msn. Conexões não autorizadas são logadas e um
	usuário (desativado) será criado para armazenar as informações
	referentes a conexão (IP, data e hora).<br>
	</td>
    <td bgcolor="#EBEBEB" valign=top><select name="connect"
	onchange="javascript: saveSelect('save_default_op.php?name=connect', this)">
	    <option value=yes <?php echo ($row['connect'] == "YES") ? "selected" : "" ?>>Sim
	    <option value=no <?php echo ($row['connect'] == "NO") ? "selected" : "" ?>>Não
	</select>
	</td>
  </tr>
  <tr>
    <td bgcolor="#EBEBEB">
	<div align=right><b>Salvar mensagens</b></div><br>
	Desativa a gravação das mensagens dos usuarios.<br>
        </td>
    <td bgcolor="#EBEBEB" valign=top><select name="save_msg"
	onchange="javascript: saveSelect('save_default_op.php?name=save_msg', this)">
	    <option value=yes <?php echo ($row['save_msg'] == "YES") ? "selected" : "" ?>>Sim
	    <option value=no <?php echo ($row['save_msg'] == "NO") ? "selected" : "" ?>>Não
        </select>
        </td>
  </tr>
  <tr>
    <td bgcolor="#EBEBEB">
        <div align=right><b>Salvar lista de contatos</b></div><br>
        Desativa a gravação da lista de contatos dos usuarios.<br>
        </td>
    <td bgcolor="#EBEBEB" valign=top><select name="save_contacts"
	onchange="javascript: saveSelect('save_default_op.php?name=save_contacts', this)">
	    <option value=yes <?php echo($row['save_contacts'] == "YES") ? "selected" : "" ?>>Sim
	    <option value=no <?php echo ($row['save_contacts'] == "NO") ? "selected" : "" ?>>Não
        </select>
        </td>
  </tr>
  <tr>
    <td bgcolor="#EBEBEB" colspan=2 align=center>
	Outras Opções<br>
      <table border=0 width="100%">
<?php
    for ($o = 0; ; $o += 2) {

	if (!isset($arrayOption[$o]))
	    break;

	print_option($o, $row['commands']);
    }
?>
      </table>
    </td>
  </tr>
  <tr>
    <td bgcolor="#EBEBEB" colspan=2 align=center>
	<p><strong>Aviso de monitoramento</strong><br></p>
    </td>
  </tr>
  <tr>
    <td bgcolor="#EBEBEB" colspan=2 align="left">
        <p><table border=0 width="100%"><tr><td>E-mail do administrador:<br>
	<input type="text" name="warnemail" value="<?php echo $row['warnemail'] ?>"
	    size=30 onblur="saveText('save_msg.php?opt=warnemail', this)"></td>
	<td>Nome do admininstrador:<br>
	<input type="text" name="warndn" value="<?php echo $row['warndn'] ?>"
	    size=30 onblur="saveText('save_msg.php?opt=warndn', this)"></td></tr>
	</table>
	Texto enviado ao usu&aacute;rio sobre o monitoramento:<br>
	<textarea name="warnmsg" cols="50"
	    onblur="saveText('save_msg.php?opt=warnmsg', this)"><?php echo $row['warnmsg'] ?></textarea><br>

	Fonte:<br>
<?php
    $fonts = array ("Arial", "Verdana", "Comic Sans MS", "Courier");

    for ($i = 0; $i < count($fonts); $i++) {

	echo "<input type=\"radio\" name=\"warnfont\" value=\"". $fonts[$i];
	echo "\" id=\"". $fonts[$i] ."\" ";
	echo "onclick=\"saveRadio('save_msg.php?opt=msgfont', this)\"";
	if (strcasecmp($row['msgfont'], $fonts[$i]) == 0)
	    echo " checked";
	echo "><label for=\"". $fonts[$i] ."\" ";
	echo "style=\"font-family: ". $fonts[$i] ."; font-size: 10pt;\"> ";
	echo $fonts[$i] ."</label>\n";

    }

?>
	<br>
	Cor:<br>
<?php

    $colors = array (
		array("000000", "Preto"),
		array("ff0000", "Vermelho"),
		array("00ff00", "Verde"),
		array("0000ff", "Azul"),
		array("ffff00", "Amarelo"),
		array("00ffff", "Ciano"),
		array("ff00ff", "Magenta"),
		array("c0c0c0", "Cinza"),
		array("ffffff", "Branco")
		);

    for ($i = 0; $i < count($colors); $i++) {

        echo "<input type=\"radio\" name=\"warncolor\" value=\"";
	echo $colors[$i][0] ."\" id=\"". $colors[$i][0] ."\" ";
	echo "onclick=\"saveRadio('save_msg.php?opt=msgcolor', this)\"";
	if (strcasecmp($row['msgcolor'], $colors[$i][0]) == 0)
	    echo " checked";
	echo "><label for=\"". $colors[$i][0] ."\" style=\"color: #";
	echo $colors[$i][0] ."; font-size: 10pt;\"> ". $colors[$i][1];
	echo "</label>\n";

    }

?>
	</p>
    </td>
  </tr>
 </table>
</div>
</form>

</body>
</html>
<?php
    mysql_close($mysql);
?>
