<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: settings.php,v 1.7.2.2 2004/04/18 12:45:44 ajvwaay Exp $



/*************************************************************************/
 #  Mailbox 0.9.2a   by Sivaprasad R.L (http://netlogger.net)              #
 #                                                                        #
 #          --  A pop3 client addon for phpnuked websites --              #
 #                                                                        #
 # 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., 675 Mass Ave, Cambridge, MA 02139, USA.              #
 #                                                                        #
 #             Copyright (C) by Sivaprasad R.L                            #
 #                                                                        #
/*************************************************************************/

  global $mainfile, $op, $domain;

  if(!$user) {
    header ("Location: user.php");
    exit();
  }

//  if(!isset($mainfile)) include "mainfile.php";
  include "header.php";
  include "mailheader.php";
  include "class.rc4crypt.php";
  $index = 2;
  global $defaultpopserver, $singleaccount, $numaccounts, $singleaccountname;

  if(isset($popserver)) {
      global $user, $type;
      $auser = base64_decode($user);
      $userdata = explode(":", $auser);
      $userid = $userdata[0];

      $rc4 = new rc4crypt();
      $spasswd = $rc4->encrypt($uname,$passwd);

      if(isset($leavemsg) && $leavemsg == "Y") $delete = "N"; else $delete = "Y";
      if($submit == translate("delete")) {
          $query = "Delete from ".$mpnTables['popsettings']." where id = $id";
      } else if($type == "new") {
          $query = "Insert into ".$mpnTables['popsettings']." (account,uid,popserver,uname,passwd,port,numshow,deletefromserver) values
          ('$account','$userid','$popserver','$uname','$spasswd',$port,$numshow,'$delete')";
      } else {
          $query = "Update ".$mpnTables['popsettings']." set account='$account', popserver = '$popserver', uname = '$uname', passwd = '$spasswd', port = $port, numshow = $numshow, deletefromserver = '$delete' where id = $id";
      }
      $res = mysql_query($query);

      if (!$res) {
          echo translate("error:") . " $query";
      }
  }

  $port = 110;
  $show = 10;
  $checkbox = "";
  $acc_count = 0;
  $showflag=true;

  global $user;
  $user1 = base64_decode($user);
  $userdata = explode(":", $user1);
  $userid = $userdata[0];

  $query = "Select * from ".$mpnTables['popsettings']." where uid = $userid";
  if(($res2 = mysql_query($query)) && (mysql_num_rows($res2) > 0) ) {
      $acc_count = mysql_num_rows($res2);
      $rc = new rc4crypt();
      while($row = mysql_fetch_array($res2)) {
          $id = $row['id'];
          $account = $row['account'];
          $popserver = $row['popserver'];
          $port = $row['port'];
          $uname = $row['uname'];
          $passwd = $rc->encrypt($uname,$row['passwd']);
          $delete = $row['deletefromserver'];
          $show = $row['numshow'];
          if($delete == "Y") $checkbox = "CHECKED";
          showSettings($account,$popserver, $uname,$passwd, $port,$show,$checkbox,$id);
          if($popserver == $defaultpopserver) $showflag = false;
      }
  }

  if(($defaultpopserver != "") && $showflag) {
      showSingle($defaultpopserver, $singleaccountname);
  }

  if( !$singleaccount  && ($numaccounts == -1) || ($acc_count < $numaccounts)){
      showNew();
  }

 include "mailfooter.php";

     function showSettings($account,$popserver, $uname,$passwd, $port,$show,$checkbox,$id) {
        global $bgcolor1, $bgcolor2, $bgcolor3;
        echo "
        <br><table width=95% align=center>
        <form method=post action=\"settings.php\" name=formpost>
        <tr><td bgcolor=\"$bgcolor2\" width=20%><b><font color=\"$bgcolor3\">$account</font></b></td><td>&nbsp</td></tr>
        <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Pop Server") . " &nbsp;&nbsp; </td><Td><input type=text name=popserver value=\"$popserver\" size=20> </td></tr>
        <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Username") . " &nbsp;&nbsp;</td><Td><input type=text name=uname size=20 value=\"$uname\"> </td></tr>
        <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Password") . " &nbsp;&nbsp;</td><Td><input type=password name=passwd size=20 value=\"$passwd\"> </td></tr>
        <tr bgcolor=\"$bgcolor1\"><td>&nbsp;</td><td>" . translate("(all passwords are encrypted and stored securely)") . "</td></tr>
        <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Port") . " &nbsp;&nbsp; </td><Td><input type=text name=port size=4  value=\"$port\"> </td></tr>
        <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Show in inbox:") . "&nbsp;&nbsp; </td><Td><input type=text name=numshow size=3  value=\"$show\"value=\"10\"> " . translate("Messages") . " </td></tr>
<!--        <tr bgcolor=\"$bgcolor1\"><td align=right><input type=checkbox name=leavemesg value=\"Y\" $checkbox>&nbsp;&nbsp;&nbsp;&nbsp;</td><Td>" . translate("Leave messages in server") . "</td></tr> -->
        <tr bgcolor=\"$bgcolor1\"><td align=top><input class='button' type=submit name=submit value='" . translate("save") . "'></td>
        <td  align=top><input class='button' type=submit name=submit value='" . translate("delete") . "'></td></tr>
        <input type=hidden name=id value=\"$id\">
        <input type=hidden name=type value=\"$account\">
        <input type=hidden name=account value=\"$account\">
        </form>
        </table><br>";
     }

     function showNew() {
         global $bgcolor1, $bgcolor2, $bgcolor3;
         echo "
              <br><table width=95% align=center>
              <form method=post action=\"settings.php\" name=formpost>
              <tr><td bgcolor=\"$bgcolor2\" width=20%><b><font color=\"$bgcolor3\">" . translate("New Mail Account") . " </font></b></td><td>&nbsp</td></tr>
              <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Account name") . " &nbsp;&nbsp; </td><Td><input type=text name=account value=\"\" size=20> </td></tr>
              <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Pop Server") . " &nbsp;&nbsp; </td><Td><input type=text name=popserver value=\"\" size=20> </td></tr>
              <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Username") . " &nbsp;&nbsp;</td><Td><input type=text name=uname size=20 value=\"\"> </td></tr>
              <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Password") . " &nbsp;&nbsp;</td><Td><input type=password name=passwd size=20 value=\"\"> </td></tr>
              <tr bgcolor=\"$bgcolor1\"><td colspan=2>&nbsp;</td></tr>
              <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Port") . " &nbsp;&nbsp; </td><Td><input type=text name=port size=4  value=\"110\"> </td></tr>
              <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Show in inbox:") . "&nbsp;&nbsp; </td><Td><input type=text name=numshow size=3  value=\"10\"> " . translate("Messages") . " </td></tr>
<!--               <tr bgcolor=\"$bgcolor1\"><td align=right><input type=checkbox name=leavemesg value=\"Y\" CHECKED>&nbsp;&nbsp;&nbsp;&nbsp;</td><Td>" . translate("Leave messages in server") . "</td></tr> //-->
              <input type=hidden name=type value=\"new\">
              <tr bgcolor=\"$bgcolor1\"><td colspan=2><input class='button' type=submit name=submit value='" . translate("Add New") . "'></form><br></td></tr>
              </table>";
     }

     function showSingle($defaultpopserver, $singleaccountname) {
         global $bgcolor1, $bgcolor2, $bgcolor3;
         echo "
              <br><table width=95% align=center>
              <form method=post action=\"settings4.php\" name=formpost>
              <tr><td bgcolor=\"$bgcolor2\" width=20%><b><font color=\"$bgcolor3\">$singleaccountname</font></b></td><td>&nbsp</td></tr>
              <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Username") . " &nbsp;&nbsp;</td><Td><input type=text name=uname size=20 value=\"\"> </td></tr>
              <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Password") . " &nbsp;&nbsp;</td><Td><input type=password name=passwd size=20 value=\"\"> </td></tr>
              <tr bgcolor=\"$bgcolor1\"><td align=right> " . translate("Show in inbox:") . "&nbsp;&nbsp; </td><Td><input type=text name=numshow size=3  value=\"10\"> " . translate("Messages") . " </td></tr>
              <tr bgcolor=\"$bgcolor1\"><td colspan=2><input class='button' type=submit name=submit value='" . translate("Add") . "'><br></td></tr>
              <input type=hidden name=type value=\"new\"> <input type=hidden name=port value=110><input type=hidden name=account value=\"$singleaccountname\">
              <input type=hidden name=popserver value=\"$defaultpopserver\"></form>
              </table>";
     }

?>
