home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / email / account.php next >
PHP Script  |  2004-03-08  |  9KB  |  271 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. require("../../Group-Office.php");
  14. require($GO_CONFIG->class_path."imap.class.inc");
  15. require($GO_CONFIG->class_path."email.class.inc");
  16. require($GO_LANGUAGE->get_language_file('email'));
  17. $mail = new imap();
  18. $email = new email();
  19.  
  20. $GO_SECURITY->authenticate();
  21. $GO_MODULES->authenticate('email');
  22.  
  23. $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : '';
  24. $return_to = (isset($_REQUEST['return_to']) && $_REQUEST['return_to'] != '') ? $_REQUEST['return_to'] : $_SERVER['HTTP_REFERER'];
  25. $link_back = (isset($_REQUEST['link_back']) && $_REQUEST['link_back'] != '') ? $_REQUEST['link_back'] : $_SERVER['REQUEST_URI'];
  26.  
  27. $disable_accounts = ($GO_CONFIG->get_setting('em_disable_accounts') == 'true') ? true : false;
  28.  
  29.  
  30. //delete accounts if requested
  31. if ($task == 'save_account')
  32. {
  33.     $task = 'account';
  34.     $mbroot = isset($_POST['mbroot']) ? $_POST['mbroot'] : '';
  35.     if ($_POST['name'] == "" || $_POST['mail_address'] == "" || $_POST['port'] == "" || $_POST['user'] == "" || $_POST['pass'] == "" || $_POST['host'] == "")
  36.     {
  37.         $feedback = $error_missing_field;
  38.     }else
  39.     {
  40.         $sent = $_POST['type'] == 'pop3' ? '' : $_POST['sent'];
  41.         $spam = $_POST['type'] == 'pop3' ? '' : $_POST['spam'];
  42.         $trash = $_POST['type'] == 'pop3' ? '' : $_POST['trash'];
  43.  
  44.         $auto_check = isset($_POST['auto_check']) ? '1' : '0';
  45.         if (isset($_POST['account_id']))
  46.         {
  47.             if(!$email->update_account($_POST['account_id'], $_POST['type'], $_POST['host'], $_POST['port'], $mbroot, $_POST['user'], $_POST['pass'], $_POST['name'], $_POST['mail_address'], $_POST['signature'], $sent, $spam, $trash, $auto_check))
  48.             {
  49.                 $feedback = '<p class="Error">'.$ml_connect_failed.' \''.$_POST['host'].'\' '.$ml_at_port.': '.$_POST['port'].'</p>';
  50.                 $feedback .= '<p class="Error">'.$email->last_error.'</p>';
  51.             }else
  52.             {
  53.                 header('Location: '.$return_to);
  54.                 exit();
  55.             }
  56.         }else
  57.         {
  58.             if(!$email_id = $email->add_account($GO_SECURITY->user_id, $_POST['type'], $_POST['host'], $_POST['port'], $mbroot, $_POST['user'], $_POST['pass'], $_POST['name'], $_POST['mail_address'], $_POST['signature'], $sent, $spam, $trash, $auto_check))
  59.             {
  60.                 $feedback = '<p class="Error">'.$ml_connect_failed.' \''.$_POST['host'].'\' '.$ml_at_port.': '.$_POST['port'].'</p>';
  61.                 $feedback .= '<p class="Error">'.$email->last_error.'</p>';
  62.             }else
  63.             {
  64.                 header('Location: '.$return_to);
  65.                 exit();
  66.             }
  67.         }
  68.     }
  69. }
  70.  
  71. if (isset($_REQUEST['account_id']) && $_SERVER['REQUEST_METHOD'] != "POST")
  72. {
  73.     $account = $email->get_account($_REQUEST['account_id']);
  74.     if ($account['user_id'] != $GO_SECURITY->user_id)
  75.     {
  76.         require($GO_CONFIG->root_path."error_docs/403.inc");
  77.         require($GO_THEME->theme_path."footer.inc");
  78.         exit();
  79.     }
  80.  
  81.     $page_title=$ml_edit_account;
  82.     $name = $account["name"];
  83.     $mail_address = $account["email"];
  84.     $host = $account["host"];
  85.     $type = $account["type"];
  86.     $port = $account["port"];
  87.     $user = $account["username"];
  88.     $pass = $GO_CRYPTO->decrypt($account['password']);
  89.     $signature = $account["signature"];
  90.     $mbroot = $account["mbroot"];
  91.     $spam = $account["spam"];
  92.     $trash = $account["trash"];
  93.     $sent = $account["sent"];
  94.     $auto_check = $account['auto_check'] == '1' ? true : false;
  95. }else
  96. {
  97.     $page_title=$ml_new_account;
  98.     $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : $_SESSION['GO_SESSION']['name'];
  99.     $mail_address = isset($_REQUEST['mail_address']) ? $_REQUEST['mail_address'] : $_SESSION['GO_SESSION']['email'];
  100.     $host = isset($_REQUEST['host']) ? $_REQUEST['host'] : '';
  101.     $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'pop3';
  102.     $port = isset($_REQUEST['port']) ? $_REQUEST['port'] : '110';
  103.     $user = isset($_REQUEST['user']) ? $_REQUEST['user'] : '';
  104.     $pass = isset($_REQUEST['pass']) ? $_REQUEST['pass'] : '';
  105.     $signature = isset($_REQUEST['signature']) ? $_REQUEST['signature'] : '';
  106.     $mbroot = isset($_REQUEST['mbroot']) ? $_REQUEST['mbroot'] : '';
  107.     $spam = $mbroot.$ml_spam;
  108.     $trash = $mbroot.$ml_trash;
  109.     $sent = $mbroot.$ml_sent_items;
  110.     $auto_check = isset($_REQUEST['auto_check']) ? true : false;
  111. }
  112.  
  113.  
  114. require($GO_THEME->theme_path."header.inc");
  115.  
  116. echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="email_client">';
  117. echo '<input type="hidden" name="task" value="" />';
  118. echo '<input type="hidden" name="close" value="false" />';
  119. echo '<input type="hidden" name="return_to" value="'.$return_to.'" />';
  120. echo '<input type="hidden" name="link_back" value="'.$link_back.'" />';
  121.  
  122. if (isset($_REQUEST['account_id']))
  123. {
  124.     $title = $ml_edit_account;
  125. }else
  126. {
  127.     $title = $ml_new_account;
  128. }
  129. $tabtable = new tabtable('account_tab', $title, '600', '300', '100', '', true);
  130. $tabtable->print_head();
  131.  
  132. if(isset($_REQUEST['account_id']))
  133. {
  134.     echo '<input type="hidden" value="'.$_REQUEST['account_id'].'" name="account_id" />';
  135. }
  136. if ($type  == 'pop3')
  137. {
  138.     $disabled = 'disabled';
  139. }else
  140. {
  141.  
  142.     $disabled = '';
  143. }
  144.  
  145. echo '<input type="hidden" name="spam" value="'.$spam.'" />';
  146. echo '<input type="hidden" name="sent" value="'.$sent.'" />';
  147. echo '<input type="hidden" name="trash" value="'.$trash.'" />';
  148. ?>
  149.  
  150. <script type="text/javascript">
  151.  
  152. function change_port()
  153. {
  154.     if (document.forms[0].type.value == "imap")
  155.     {
  156.         document.forms[0].port.value = "143";
  157.         document.forms[0].mbroot.disabled = false;
  158.     }else
  159.     {
  160.         document.forms[0].port.value = "110";
  161.         document.forms[0].mbroot.disabled = true;
  162.     }
  163. }
  164.  
  165. function save_account()
  166. {
  167.         document.forms[0].task.value='save_account';
  168.         document.forms[0].submit();
  169. }
  170.  
  171. </script>
  172.  
  173. <table border="0" cellpadding="10" cellspacing="0">
  174. <tr>
  175.     <td>
  176.     <table border="0" cellpadding="0" cellspacing="5">
  177.         <?php if (isset($feedback)) echo '<tr><td class="Error" colspan="2">'.$feedback.'</td></tr>'; ?>
  178.         <tr>
  179.                 <td><?php echo $strName; ?>:</td>
  180.                 <td><input name="name" type="text" class="textbox" maxlength="100" size="40" value="<?php echo $name; ?>" /></td>
  181.         </tr>
  182.         <tr>
  183.             <td><?php echo $strEmail; ?>:</td>
  184.             <td><input name="mail_address" type="text" class="textbox" maxlength="100" size="40" value="<?php echo $mail_address; ?>" /></td>
  185.         </tr>
  186.         <?php
  187.         if ($disable_accounts)
  188.         {
  189.             echo '<input type="hidden" name="host" value="'.$host.'" />';
  190.             echo '<input type="hidden" name="mbroot" value="'.$mbroot.'" />';
  191.             echo '<input type="hidden" name="type" value="'.$type.'" />';
  192.             echo '<input type="hidden" name="port" value="'.$port.'" />';
  193.             echo '<input type="hidden" name="user" value="'.$user.'" />';
  194.             echo '<input type="hidden" name="pass" value="'.$pass.'" />';
  195.         }else
  196.         {
  197.             ?>
  198.  
  199.             <tr><td colspan="2"> </td></tr>
  200.             <tr>
  201.                 <td><?php echo $ml_type; ?>/<?php echo $ml_port; ?>:</td>
  202.                     <td>
  203.                     <?php
  204.                     $dropbox = new dropbox();
  205.                     $dropbox->add_value('pop3','POP3');
  206.                     $dropbox->add_value('imap','IMAP');
  207.                     $dropbox->print_dropbox('type',$type,'onchange="javascript:change_port()"');
  208.                     ?>
  209.                      / <input name="port" type="text" class="textbox" maxlength="6" size="4" value="<?php echo $port; ?>" />
  210.                 </td>
  211.             </tr>
  212.  
  213.             <tr>
  214.                 <td><?php echo $ml_host; ?>:</td>
  215.                 <td><input name="host" type="text" class="textbox" maxlength="100" size="40" value="<?php echo $host; ?>" /></td>
  216.             </tr>
  217.             <tr>
  218.                 <?php
  219.                 echo '<td>'.$ml_root.':</td>';
  220.                 echo '<td><input type="text" class="textbox" size="40" name="mbroot" value="'.$mbroot.'" '.$disabled.' /></td>';
  221.                 ?>
  222.             </tr>
  223.             <tr><td colspan="2"> </td></tr>
  224.             <tr>
  225.                     <td><?php echo $strUsername; ?>:</td>
  226.                 <td><input name="user" type="text" class="textbox" maxlength="100" size="40" value="<?php echo $user; ?>" /></td>
  227.             </tr>
  228.                 <tr>
  229.                     <td><?php echo $strPassword; ?>:</td>
  230.                 <td><input name="pass" type="password" class="textbox" maxlength="100" size="40" value="<?php echo $pass; ?>" /></td>
  231.             </tr>
  232.             <tr><td colspan="2"> </td></tr>
  233.             <?php
  234.         }
  235.         ?>
  236.         <tr>
  237.             <td valign="top"><?php echo $ml_signature; ?>:</td>
  238.             <td><textarea name="signature" class="textbox" cols="37" rows="4"><?php echo $signature; ?></textarea></td>
  239.         </tr>
  240.         <tr>
  241.             <td colspan="2">
  242.             <?php
  243.             $checkbox = new checkbox('auto_check', '1', $ml_auto_check, $auto_check);
  244.             ?>
  245.             </td>
  246.         </tr>
  247.         </table>
  248.  
  249.     <br />
  250.     <?php
  251.     $button = new button($cmdOk, "javascript:_save('save_account', 'true');");
  252.     echo '  ';
  253.     $button = new button($cmdCancel,'javascript:document.location=\''.$return_to.'\'');
  254.     ?>
  255.     </td>
  256. </tr>
  257. </table>
  258. <script type="text/javascript" language="javascript">
  259.  
  260. function _save(task, close)
  261. {
  262.     document.forms[0].task.value = task;
  263.     document.forms[0].close.value = close;
  264.     document.forms[0].submit();
  265. }
  266. </script>
  267. <?php
  268. $tabtable->print_foot();
  269. echo '</form>';
  270. require($GO_THEME->theme_path."footer.inc");
  271. ?>