Location: PHPKode > scripts > txtSQL MailBox > txtsql-mailbox/settings.php
<?
 /*************************************************************************/
 # txtSQL MailBox 0.1 by Nexami Engeo (http://www.n-e-x.co.uk)     #
 # txtSQL MailBox is based on phpMailBox 1.1     #
 # Lasy Modified : 5th April, 2005  22:50 GMT   #
 # txtSQL MailBox 0.1 is Copyright (C) by John Urquhart Ferguson     #
 # All previous licensing applies     #
 #
 # More information on the txtSQL project can be found at: http://txtsql.sourceforge.net)
 #
 #  phpMailbox 1.1   by Sivaprasad R.L (http://netlogger.net/phpmailbox)  #
 #                                                                        #
 #          --  A php pop3 client --              			  #
 #                                                                        #
 # 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.              #
 #                                                                        #
 #             phpMailBox 1.1 is Copyright (C) by Sivaprasad R.L                            #
 #                                                                        #
/*************************************************************************/

  include "mailheader.php";
  include "class.inc";

  global $defaultpopserver, $singleaccount, $numaccounts, $singleaccountname, $domain;
  session_start();
  $port = 110;

  if(isset($popserver)) {
      global $uid, $type;

      $userid = $uid;

      $rc4 = new rc4crypt();
      $spasswd = $rc4->endecrypt($uname,$passwd,"en");

      if($leavemsg == "Y") $delete = "N"; else $delete = "Y";
      if($submit == "delete") {
	      //Old MySQL code
          //$query = "Delete from popsettings where id = '$id'";
		  
		  //New txtSQL code
		  $res = $sql->query('DELETE FROM popsettings WHERE id = '.$id.'');
		  
	  $what = "deleted";
      } else if($type == "new") {
  	  //srand((double)microtime()*1000000);
	  //$id = strtoupper(md5(rand(0,9999)));
          //Old MySQL code
          //$query = "Insert into popsettings (id,account,uid,popserver,uname,passwd,port,numshow,deletefromserver,fromemail,fromname) values
          //('$id','$newaccount','$userid','$popserver','$uname','$spasswd',$port,$numshow,'$delete','$fromemail','$fromname')";
		  
		  //New txtSQL code
		  $sql->insert(array('db'     => $sqlDB,
                             'table'  => 'popsettings',
                             'values' => array(
							             'account' => $newaccount,
										 'uid' => $userid,
										 'popserver' => $popserver,
										 'uname' => $uname,
										 'passwd' => $spasswd,
										 'port' => $port,
										 'numshow' => $numshow,
										 'deletefromserver' => $delete,
										 'fromemail' => $fromemail,
										 'fromname' => $fromname))) or die();
		  $res = TRUE;
	
	  $what = "added";
      } else {
	      //Old MySQL code
          //$query = "Update popsettings set account='$account', popserver = '$popserver', uname = '$uname', passwd = '$spasswd', port = $port, numshow = $numshow, deletefromserver = '$delete', fromemail = '$fromemail', fromname = '$fromname' where id = '$id'";
		  
		  //New txtSQL code
		  $values = array('account'          => '"'.$account.'"',
                          'popserver'        => '"'.$popserver.'"',
						  'uname'            => '"'.$uname.'"',
						  'passwd'           => '"'.$spasswd.'"',
						  'port'             => ''.$port.'',
						  'numshow'          => ''.$numshow.'',
						  'deletefromserver' => '"'.$delete.'"',
						  'fromemail'        => '"'.$fromemail.'"',
						  'fromname'         => '"'.$fromname.'"');
						  
		  if( !$sql->update(array('db'     => $sqlDB,
                                  'table'  => 'popsettings',
                                  'where'  => array('id = '.$id.''),
                                  'values' => $values)) )
		  {
		     die('An error occurred, txtSQL said: '.$sql->get_last_error());
		  } 
		  else 
		  {
		     $res = TRUE;
		  }
  
	  $what = "updated";
      }

      //echo $query;
	  
	  //Old MySQl code
      //$res = mysql_query($query);
	  

      if(!$res) {
          echo "Error in form submission!!";
	  exit();
      } else {
         echo "<center><h3>Account has been ".$what." successfully</h3><br>
	       <form action='settings.php'><input type=button name=done value=\"Done\" onClick=\"document.location ='mailbox.php';\"> &nbsp;&nbsp;&nbsp;
	       <input type=submit name=add value='Add Account'>
 	       </form></center>";	
	 exit();
      }
  }

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

  global $uid;
  $userid = $uid;

  //Old MySQL code
  //$query = "Select * from popsettings where uid = '$userid'";
  
  //New txtSQL code
  $query = 'SELECT * FROM popsettings WHERE uid = "'.$userid.'"';
  $res2 = $sql->query($query);
  
  //Old MySQL code
  /*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];
          $acc = $row[account];
          $popserver = $row[popserver];
          $port = $row[port];
          $uname = $row[uname];
          $passwd = $rc->endecrypt($uname,$row[passwd],"de");
          $delete = $row[deletefromserver];
          $show = $row[numshow];
	  $fromemail = $row[fromemail];
  	  $fromname = $row[fromname];
          if($delete == "Y") $checkbox = "CHECKED";
          showSettings($acc,$popserver, $uname,$passwd, $port,$show,$checkbox,$id,$fromemail,$fromname);
          if($popserver == $defaultpopserver) $showflag = false;
      }
  }*/

  //New txtSQL code
  if( sizeof($res2) > 0 ) {
      $acc_count = sizeof($res2);
      $rc = new rc4crypt();
	  foreach ( $res2 as $key => $row ) {
          $id = $row["id"];
          $acc = $row["account"];
          $popserver = $row["popserver"];
          $port = $row["port"];
          $uname = $row["uname"];
          $passwd = $rc->endecrypt($uname,$row["passwd"],"de");
          $delete = $row["deletefromserver"];
          $show = $row["numshow"];
	      $fromemail = $row["fromemail"];
  	      $fromname = $row["fromname"];
          if($delete == "Y") $checkbox = "CHECKED";
          showSettings($acc,$popserver, $uname,$passwd, $port,$show,$checkbox,$id,$fromemail,$fromname);
          if($popserver == $defaultpopserver) $showflag = false;
      }
  }
  
  if( !$singleaccount  && (($numaccounts == -1) || ($acc_count < $numaccounts))){
      showNew();
  }

 include "mailfooter.php";

?>

<?
     function showSettings($account,$popserver, $uname,$passwd, $port,$show,$checkbox,$id,$fromemail,$fromname) {
        global $defaultpopserver;
        echo "
        <br><table width=95% align=center>
        <form method=post action=\"settings.php\" name=formsave>
        <tr><td class=\"bgrowcolor3\" width=20%><b class=\"font2\">".$account."</b></td><td>&nbsp</td></tr>";

	if($defaultpopserver != $popserver) {
            echo "<tr class=\"bgrowcolor1\"><td align=right> Pop Server &nbsp;&nbsp; </td><Td><input type=text name=popserver value=\"".$popserver."\" size=20> </td></tr>
                  <tr class=\"bgrowcolor1\"><td align=right> Username &nbsp;&nbsp;</td><Td><input type=text name=uname size=20 value=\"".$uname."\"> </td></tr>
                  <tr class=\"bgrowcolor1\"><td align=right> Password &nbsp;&nbsp;</td><Td><input type=password name=passwd size=20 value=\"".$passwd."\"> </td></tr>
                  <tr class=\"bgrowcolor1\"><td>&nbsp;</td><td>(all passwords are encrypted and stored securely)</td></tr>";
	} else {
		echo "<input type=hidden name=popserver value=\"".$popserver."\">";
	}

	echo "
        <tr class=\"bgrowcolor1\"><td align=right> From Email :&nbsp;&nbsp; </td><Td><input type=text name=fromemail size=20  value=\"".$fromemail."\"></td></tr>
        <tr class=\"bgrowcolor1\"><td align=right> From Name  :&nbsp;&nbsp; </td><Td><input type=text name=fromname size=20  value=\"".$fromname."\"></td></tr>
        <tr class=\"bgrowcolor1\"><td align=right> Show &nbsp;&nbsp; </td><Td><input type=text name=numshow size=3  value=\"".$show."\"value=\"10\"> messages in inbox </td></tr>
        <tr class=\"bgrowcolor1\"><td align=top><input type=submit name=submit value='save'></td>
        <td  align=top><input type=submit name=submit value='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() {
 	 $account = "";
         echo "
              <br><table width=95% align=center>
              <form method=post action=\"settings.php\" name=formnew>
              <tr><td class=\"bgrowcolor3\" width=20%><b class=\"font2\">New Mail Account</b></td><td>&nbsp</td></tr>
              <tr class=\"bgrowcolor1\"><td align=right> Account name &nbsp;&nbsp; </td><Td><input type=text name=newaccount value=\"\" size=20> (eg: Yahoo!) </td></tr>
              <tr class=\"bgrowcolor1\"><td align=right> Pop Server &nbsp;&nbsp; </td><Td><input type=text name=popserver value=\"\" size=20> (eg: pop.mail.yahoo.com) </td></tr>
              <tr class=\"bgrowcolor1\"><td align=right> Username &nbsp;&nbsp;</td><Td><input type=text name=uname size=20 value=\"\"> </td></tr>
              <tr class=\"bgrowcolor1\"><td align=right> Password &nbsp;&nbsp;</td><Td><input type=password name=passwd size=20 value=\"\"> </td></tr>
	      <tr class=\"bgrowcolor1\"><td align=right> From Email :&nbsp;&nbsp; </td><Td><input type=text name=fromemail size=20  value=\"\"></td></tr>
              <tr class=\"bgrowcolor1\"><td align=right> From Name  :&nbsp;&nbsp; </td><Td><input type=text name=fromname size=20  value=\"\"></td></tr>

              <tr class=\"bgrowcolor1\"><td colspan=2>&nbsp;</td></tr>
              <tr class=\"bgrowcolor1\"><td align=right> Show  &nbsp;&nbsp; </td><Td><input type=text name=numshow size=3  value=\"10\"> messages in inbox </td></tr>
              <input type=hidden name=type value=\"new\">
              <tr class=\"bgrowcolor1\"><td colspan=2><input type=submit name=submit value='Add New'></form><br></td></tr>
              </table>";
     }
?>
Return current item: txtSQL MailBox