home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / admin / pref_identities.php < prev    next >
Encoding:
PHP Script  |  2003-08-20  |  9.4 KB  |  280 lines

  1. <?php
  2. /////////////////////////////////////////////////////////
  3. //    
  4. //    source/pref_identities.php
  5. //
  6. //    (C)Copyright 2000-2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
  7. //
  8. //        This file is part of IlohaMail.
  9. //        IlohaMail is free software released under the GPL 
  10. //        license.  See enclosed file COPYING for details,
  11. //        or see http://www.fsf.org/copyleft/gpl.html
  12. //
  13. /////////////////////////////////////////////////////////
  14.  
  15. /********************************************************
  16.  
  17.     AUTHOR: Ryo Chijiiwa <ryo@ilohamail.org>
  18.     FILE: source/pref_identities.php
  19.     PURPOSE:
  20.         Create/edit/delete identities
  21.     PRE-CONDITIONS:
  22.         $user - Session ID
  23.         
  24. ********************************************************/
  25.  
  26.     include("../include/super2global.inc");
  27.     include("../include/header_main.inc");
  28.     include("../include/langs.inc");
  29.     include("../include/icl.inc");    
  30.     include("../lang/".$my_prefs["lang"]."prefs.inc");
  31.     include("../lang/".$my_prefs["lang"]."pref_identities.inc");
  32.     //include("../conf/defaults.inc");
  33.     include("../include/identities.inc");
  34.     include("../include/data_manager.inc");
  35.     include("../include/pref_header.inc");
  36.     
  37.     
  38.     //authenticate
  39.     $conn=iil_Connect($host, $loginID, $password, $AUTH_MODE);
  40.     if ($conn){
  41.         if ($ICL_CAPABILITY["folders"]){
  42.             if ($my_prefs["hideUnsubscribed"]){
  43.                 $mailboxes = iil_C_ListSubscribed($conn, $my_prefs["rootdir"], "*");
  44.             }else{
  45.                 $mailboxes = iil_C_ListMailboxes($conn, $my_prefs["rootdir"], "*");
  46.             }
  47.             sort($mailboxes);
  48.         }
  49.         iil_Close($conn);
  50.     }else{
  51.         echo "Authentication failed.";
  52.         echo "</body></html>\n";
  53.         exit;
  54.     }
  55.     
  56.     //open DM connection
  57.     $dm = new DataManager_obj;
  58.     if ($dm->initialize($loginID, $host, $DB_IDENTITIES_TABLE, $DB_TYPE)){
  59.     }else{
  60.         echo "Data Manager initialization failed:<br>\n";
  61.         $dm->showError();
  62.     }
  63.  
  64.  
  65.     if (isset($add)){
  66.         if ((empty($new_name)) || (empty($new_email))) $error .= $piError[1];
  67.         else{
  68.             $new_email = eregi_replace('[^a-zA-Z0-9@_.-]', '', $new_email);
  69.             $new_replyto = eregi_replace('[^a-zA-Z0-9@_.-]', '', $new_replyto);
  70.             
  71.             $new_ident["name"] = $new_name;
  72.             $new_ident["email"] = $new_email;
  73.             $new_ident["replyto"] = $new_replyto;
  74.             $new_ident["sig"] = $new_sig;
  75.             
  76.             if ($dm->insert($new_ident)) echo "<!-- Inserted //-->";
  77.             else echo "<!-- Not inserted //-->";
  78.             
  79.             if ($new_default){
  80.                 $my_prefs["user_name"] = $new_name;
  81.                 $my_prefs["email_address"] = $new_email;
  82.                 $my_prefs["signature1"] = $new_sig;
  83.                 include("../include/save_prefs.inc");
  84.             }
  85.             
  86.             $new_name = $new_email = $new_replyto = $new_sig = "";
  87.         }
  88.     }
  89.     if (isset($edit) && ($edit_id > 0)){
  90.         //do update
  91.         $edit_email = eregi_replace('[^a-zA-Z0-9@_.-]', '', $edit_email);
  92.         $edit_replyto = eregi_replace('[^a-zA-Z0-9@_.-]', '', $edit_replyto);
  93.         
  94.         $new_ident["name"] = $edit_name;
  95.         $new_ident["email"] = $edit_email;
  96.         $new_ident["replyto"] = $edit_replyto;
  97.         $new_ident["sig"] = $edit_sig;
  98.             
  99.         if ($dm->update($edit_id, $new_ident)) echo "<!-- Updated! //-->";
  100.         else echo "<!-- Not updated //-->";
  101.         
  102.         if ($new_default){
  103.             $my_prefs["user_name"] = $edit_name;
  104.             $my_prefs["email_address"] = $edit_email;
  105.             $my_prefs["signature1"] = $edit_sig;
  106.             include("../include/save_prefs.inc");
  107.         }
  108.  
  109.         $edit_id = 0;
  110.     }
  111.     if (isset($delete) && ($edit_id > 0)){
  112.         //do delete
  113.         if ($dm->delete($edit_id)){
  114.             $edit_id = 0;
  115.             
  116.             //if default, clear it
  117.             if (strcmp($edit_name, $my_prefs["user_name"])==0
  118.                 && strcmp($edit_email, $my_prefs["email_address"])==0
  119.                 && strcmp($edit_sig, $my_prefs["signature1"])==0
  120.             ){
  121.                 $my_prefs["user_name"] = "";
  122.                 $my_prefs["email_address"] = "";
  123.                 $my_prefs["signature1"] = "";
  124.                 include("../include/save_prefs.inc");                
  125.             }
  126.             
  127.         }else $error .= "Deletion failed<br>\n";
  128.     }
  129.     
  130.     $identities_a = $dm->read();
  131.     
  132.     $error .= $dm->error;
  133.     
  134.     echo "<center>\n";
  135.     if (is_array($identities_a) && count($identities_a)>0){
  136.         echo '<p><table border="0" cellspacing="1" cellpadding="4" bgcolor="'.$my_colors["main_hilite"].'" width="95%">';
  137.         echo '<tr bgcolor="'.$my_colors["main_head_bg"].'">';
  138.         echo '<td colspan=5><span class="tblheader">'.$piStrings["identities"].'</span>';
  139.         echo '<span class="mainHeading">';
  140.         echo '  [<a href="pref_identities.php?user='.$user.'" class="mainHeading">'.$piStrings["new"].'</a>]';
  141.         echo '</span></td>';
  142.         echo '</tr>';
  143.         echo '<tr bgcolor="'.$my_colors["main_head_bg"].'">';
  144.             echo "<td></td>";
  145.             echo "<td valign=\"top\"><span class=tblheader>".$piStrings["name"]."</span></td>";
  146.             echo "<td valign=\"top\"><span class=tblheader>".$piStrings["email"]."</span></td>";
  147.             echo "<td valign=\"top\"><span class=tblheader>".$piStrings["replyto"]."</span></td>";
  148.             echo "<td valign=\"top\"><span class=tblheader>".$piStrings["sig"]."</span></td>";
  149.         echo "</tr>\n";
  150.  
  151.         if ($my_prefs["compose_inside"]) $target="list2";
  152.         else $target="_blank";
  153.  
  154.         reset($identities_a);
  155.         while ( list($k, $v) = each($identities_a) ){
  156.             $v = $identities_a[$k];
  157.             if ($my_prefs["user_name"]==$v["name"] 
  158.                 && $my_prefs["email_address"]==$v["email"] 
  159.                 && $my_prefs["signature1"]==$v["sig"])
  160.                     $v["default"] = true;
  161.             echo '<tr bgcolor="'.$my_colors["main_bg"].'">';
  162.                 echo "<td valign=\"middle\"><a href=\"pref_identities.php?user=$user&edit_id=".$v["id"]."\">".$piStrings["edit"]."</a></td>";
  163.                 $url = "compose2.php?user=$user&sender_identity_id=".$v["id"];
  164.                 echo "<td valign=\"middle\"><nobr><a href=\"$url\" target=\"$target\">";
  165.                     echo $v["name"]." ".($v["default"]?$piStrings["isdef"]:"");
  166.                     echo "</a></nobr></td>";
  167.                 echo "<td valign=\"middle\">".$v["email"]."</td>";
  168.                 echo "<td valign=\"middle\">".$v["replyto"]."</td>";
  169.                 echo "<td valign=\"middle\">".nl2br(stripslashes($v["sig"]))."</td>";
  170.             echo "</tr>\n";
  171.         }
  172.         echo "</table>";
  173.     }
  174.     ?>
  175.     
  176.             
  177.     <font color="red"><?php echo $error?></font>
  178.     <p>
  179.     
  180.     <?php
  181.         if ($edit_id>0){
  182.             reset($identities_a);
  183.             while ( list($k,$foo) = each($identities_a) ){
  184.                 if ($identities_a[$k]["id"]==$edit_id){
  185.                     $v = $identities_a[$k];
  186.                 }
  187.             }
  188.             
  189.             if ($my_prefs["user_name"]==$v["name"] 
  190.                 && $my_prefs["email_address"]==$v["email"] 
  191.                 && $my_prefs["signature1"]==$v["sig"])
  192.                     $v["default"] = true;
  193.     ?>
  194.             <form method="post" action="pref_identities.php">
  195.             <input type="hidden" name="user" value="<?php echo $user ?>">
  196.             <input type="hidden" name="edit_id" value="<?php echo $edit_id ?>">
  197.             <table border="0" cellspacing="1" cellpadding="1" bgcolor="<?php echo $my_colors["main_hilite"]?>" width="95%">
  198.             <tr bgcolor="<?php echo $my_colors["main_head_bg"]?>">
  199.             <td aling="center">
  200.                 <span class="tblheader">
  201.                     <?php echo $piStrings["edit_ident"]?>
  202.                 </span> 
  203.             </td>
  204.             </tr><tr bgcolor="<?php echo $my_colors["main_bg"]?>">
  205.             <td align="center">
  206.                 <table>
  207.                     <tr>
  208.                         <td align="right"><?php echo $piStrings["name"]?>:</td>
  209.                         <td><input type="text" name="edit_name" value="<?php echo $v["name"]?>" size="45"></td>
  210.                     </tr>
  211.                     <tr>
  212.                         <td align="right"><?php echo $piStrings["email"]?>:</td>
  213.                         <td><input type="text" name="edit_email" value="<?php echo $v["email"] ?>" size="45"></td>
  214.                     </tr>
  215.                     <tr>
  216.                         <td align="right"><?php echo $piStrings["replyto"]?>:</td>
  217.                         <td><input type="text" name="edit_replyto" value="<?php echo $v["replyto"] ?>" size="45"></td>
  218.                     </tr>
  219.                     <tr>
  220.                         <td align="right" valign="top"><?php echo $piStrings["sig"]?>:</td><td><textarea name="edit_sig" cols=50 rows=5><?php echo htmlspecialchars(stripslashes($v["sig"]))?></textarea></td>
  221.                     </tr>
  222.                     <tr>
  223.                         <td align="right" valign="top"></td>
  224.                         <td>
  225.                             <input type="checkbox" name="new_default" value="1" <?php echo ($v["default"]?"checked":"") ?>> 
  226.                             <?php echo $piStrings["setdef"]?>
  227.                         </td>
  228.                     </tr>
  229.                 </table>
  230.                 <input type="submit" name="edit" value="<?php echo $piStrings["edit"]?>">
  231.                 <input type="submit" name="delete" value="<?php echo $piStrings["delete"]?>">
  232.             </td>
  233.             </tr>
  234.             </table>
  235.             </form>
  236.     <?php
  237.         }else{
  238.     ?>
  239.             <form method="post" action="pref_identities.php">
  240.             <input type="hidden" name="user" value="<?php echo $user?>">
  241.             <input type="hidden" name="session" value="<?php echo $user?>">
  242.             <table border="0" cellspacing="1" cellpadding="1" bgcolor="<?php echo $my_colors["main_hilite"]?>" width="95%">
  243.             <tr bgcolor="<?php echo $my_colors["main_head_bg"]?>">
  244.             <td align="center"><span class="tblheader"><?php echo $piStrings["new"]?></span></td>
  245.             </tr><tr bgcolor="<?php echo $my_colors["main_bg"]?>">
  246.             <td align="center">
  247.                 <table>
  248.                     <tr>
  249.                         <td align="right"><?php echo $piStrings["name"]?>:</td>
  250.                         <td><input type="text" name="new_name" value="<?php echo stripslashes($new_name)?>" size="45"></td>
  251.                     </tr>
  252.                     <tr>
  253.                         <td align="right"><?php echo $piStrings["email"]?>:</td>
  254.                         <td><input type="text" name="new_email" value="<?php echo $new_email ?>" size="45"></td>
  255.                     </tr>
  256.                     <tr>
  257.                         <td align="right"><?php echo $piStrings["replyto"]?>:</td>
  258.                         <td><input type="text" name="new_replyto" value="<?php echo $new_replyto ?>" size="45"></td>
  259.                     </tr>
  260.                     <tr>
  261.                         <td align="right" valign="top"><?php echo $piStrings["sig"]?>:</td><td><textarea name="new_sig" cols=50 rows=5><?php echo htmlspecialchars(stripslashes($new_sig))?></textarea></td>
  262.                     </tr>
  263.                     <tr>
  264.                         <td align="right" valign="top"></td>
  265.                         <td>
  266.                             <input type="checkbox" name="new_default" value="1"> <?php echo $piStrings["setdef"]?>
  267.                         </td>
  268.                     </tr>
  269.                 </table>
  270.                 <input type="submit" name="add" value="<?php echo $piStrings["add"]?>">
  271.             </td>
  272.             </tr>
  273.             </table>
  274.             </form>
  275.             
  276.             <?php
  277.             }
  278.             ?>
  279. </BODY></HTML>
  280.