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 / main.php < prev    next >
Encoding:
PHP Script  |  2003-12-14  |  23.1 KB  |  669 lines

  1. <?php
  2. /////////////////////////////////////////////////////////
  3. //    
  4. //    source/main.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/main.php
  19.     PURPOSE:
  20.         1.  List specified number of messages in specified order from given folder.
  21.         2.  Provide interface to read messages (link subjects to source/read_message.php)
  22.         3.  Provide interface to send messasge to senders (link "From" field to source/compose.php)
  23.         4.  Provide interface to move or delete messages
  24.         5.  Provide interface to view messages not currently listed.
  25.         6.  Provide functionality to move, delete messages and expunge folders.
  26.     PRE-CONDITIONS:
  27.         $user - Session ID
  28.         $folder - Folder name
  29.         [$sort_field] - Field to sort by {"subject", "from", "to", "size", "date"}
  30.         [$sort_order] - Order, "ASC" or "DESC"
  31.         [$start] - Show specified number of messages starting with this index
  32.  
  33. ********************************************************/
  34.  
  35. $exec_start_time = microtime();
  36.  
  37. include("../include/stopwatch.inc");
  38. $clock = new stopwatch;
  39.  
  40. $clock->register("start");
  41.  
  42. include("../include/super2global.inc");
  43. $clock->register("pre-header");
  44. include("../include/header_main.inc");
  45. $clock->register("post-header");
  46. include("../include/ryosdates.inc");
  47. include("../include/icl.inc");
  48. include("../include/main.inc");
  49. include("../include/cache.inc");
  50. $clock->register("includes done");
  51.  
  52.     if (!isset($folder)){
  53.         echo "Error: folder not specified";
  54.         exit;
  55.     }
  56.     include("../lang/".$my_prefs["lang"]."defaultFolders.inc");
  57.     include("../lang/".$my_prefs["lang"]."main.inc");
  58.     include("../lang/".$my_prefs["lang"]."dates.inc");
  59.  
  60.     //initialize some vars
  61.     if (!isset($hideseen)) $hideseen=0;
  62.     if (!isset($showdeleted)) $showdeleted=0;
  63.     if (strcmp($folder, $my_prefs["trash_name"])==0) $showdeleted=1;
  64.     if (empty($my_prefs["main_cols"])) $my_prefs["main_cols"]="camfsdz";
  65.     
  66.     $clock->register("pre-connect");
  67.     
  68.     //connect to mail server
  69.     $conn = iil_Connect($host, $loginID, $password, $AUTH_MODE);
  70.     if (!$conn){
  71.         echo "Connection failed: $iil_error <br> ";
  72.         exit;
  73.     }
  74.     
  75.     $clock->register("post-connect");
  76.         
  77.     echo "\n<!-- ICLMessages:\n".$conn->message."-->\n";
  78.     
  79.     //move columns
  80.     //$MOVE_FIELDS = 1;
  81.     if ($MOVE_FIELDS){
  82.         $report = $mainErrors[8];
  83.         if ($move_col && $move_direction){
  84.             //echo "Moving fields <br>\n";
  85.             $col_pos = strpos($my_prefs["main_cols"], $move_col);
  86.             if ($col_pos !== false){
  87.                 if ($move_direction=="right") $move_direction = 1;
  88.                 else if ($move_direction=="left") $move_direction = -1;
  89.                 $partner_col = $my_prefs["main_cols"][$col_pos+$move_direction];
  90.                 //echo "Shift is $move_direction switching with $partner_col <br>\n";
  91.                 if ($partner_col){
  92.                     $my_prefs["main_cols"][$col_pos+$move_direction] = $move_col;
  93.                     $my_prefs["main_cols"][$col_pos] = $partner_col;
  94.                     include("../include/save_prefs.inc");
  95.                 }
  96.             }
  97.         }
  98.     }
  99.     
  100.  
  101.     //default names for toolbar input fields, used in main_tools.inc as well
  102.     $main_tool_fields = array("expunge", "empty_trash", "delete_selected",
  103.                                 "mark_read", "mark_unread", "moveto", "move_selected");
  104.  
  105.     //if toolbar displayed at top & bottom, bottom fields will have '_2' appened
  106.     //at the end of field name.  we deal with that here
  107.     reset($main_tool_fields); 
  108.     while ( list($k,$tool_field)=each($main_tool_fields) ){
  109.         $tool_var_name = $tool_field."_2";
  110.         $tool_var_val = $$tool_var_name;
  111.         if (!empty($tool_var_val)) $$tool_field = $tool_var_val;
  112.     }                                        
  113.     
  114.     //actions (flagging, deleting, moving, etc)
  115.     if ($move_selected) $submit = "File";
  116.     if ($delete_selected) $submit = "Delete";
  117.     if ($empty_trash) $submit = "Expunge";
  118.     if ($mark_read) $submit = "Read";
  119.     if ($mark_unread) $submit = "Unread";
  120.     
  121.     if (isset($submit)){
  122.         $messages="";
  123.         
  124.         /* compose an IMAP message list string including all checked items */
  125.         if ((is_array($uids)) && (implode("",$uids)!="")){
  126.             $checkboxes = iil_C_Search($conn, $folder, "UID ".implode(",", $uids));
  127.         }
  128.         if (is_array($checkboxes)){
  129.                $messages = implode(",", $checkboxes);
  130.                $num_checked = count($checkboxes);
  131.         }
  132.         
  133.         /* "Move to trash" is same as "Delete" */
  134.         if (($submit=="File") && (strcmp($moveto, $my_prefs["trash_name"])==0)) $submit="Delete";
  135.            
  136.         /*  delete all */
  137.         if ($delete_all == 2 ){
  138.             $messages .= "1:".$delete_all_num;
  139.         }
  140.                     
  141.         /* delete items */
  142.         $delete_success = false;
  143.         if (($submit=="Delete")||(strcmp($submit,$mainStrings[10])==0)){
  144.             //if folders and trash specified, move to trash
  145.             if ($ICL_CAPABILITY["folders"]){
  146.                 if (strcmp($folder, $my_prefs["trash_name"])!=0){
  147.                     if (!empty($my_prefs["trash_name"])){
  148.                         if (iil_C_Move($conn, $messages, $folder, $my_prefs["trash_name"]) >= 0){
  149.                             $delete_success = true;
  150.                         }else{
  151.                             $report = $mainErrors[2].":".$messages;
  152.                         }
  153.                     }
  154.                 }else{
  155.                     $report = $mainErrors[3].":".$messages;
  156.                 }
  157.             }
  158.  
  159.             //otherwise, just mark as deleted
  160.             if (!$delete_success){
  161.                 if (iil_C_Delete($conn, $folder, $messages) > 0) $delete_success = true;
  162.             }
  163.             
  164.             //if deleted, format success report
  165.             if ($delete_success){
  166.                 $report =  str_replace("%n", $num_checked, $mainMessages["delete"]);
  167.             }
  168.         }
  169.         
  170.         /*  move items */
  171.         if (($submit=="File")||(strcmp($submit,$mainStrings[12])==0)){
  172.             if (strcasecmp($folder, $my_prefs["trash_name"])==0){
  173.                 iil_C_Undelete($conn, $folder, $messages);
  174.             }
  175.             if (iil_C_Move($conn, $messages, $folder, $moveto) >= 0){
  176.                 $report = str_replace("%n", $num_checked, $mainMessages["move"]);
  177.                 $report = str_replace("%f", $moveto, $report);
  178.                 if (strcasecmp($folder, $my_prefs["trash_name"])==0){
  179.                     iil_C_Delete($conn, $folder, $messages);
  180.                 }
  181.             }else{
  182.                 $report = $mainErrors[4];
  183.             }
  184.         }
  185.             
  186.             
  187.         /* empty trash  command */
  188.         if (($submit=="Expunge") && ($expunge==1)){
  189.             if ($folder==$my_prefs["trash_name"]){
  190.                 if (!iil_C_ClearFolder($conn, $folder)){
  191.                     echo $mainErrors[6]." (".$conn->error.")<br>\n";
  192.                 }
  193.             }else{
  194.                 $error .= "Folder $folder is not trash (trash is ".$my_prefs["trash_name"].")<br>\n";
  195.             }
  196.         }
  197.         
  198.         /* expunge non-trash folders automatically */
  199.         if (strcasecmp($folder,$my_prefs["trash_name"])!=0){
  200.             iil_C_Expunge($conn, $folder);
  201.         }
  202.         
  203.         /* mark as unread */
  204.         if ($submit=="Unread"){
  205.             iil_C_Unseen($conn, $folder, $messages);
  206.             $reload_folders = true;
  207.             $selected_boxes = $checkboxes;
  208.         }
  209.         
  210.         /* mark as read */
  211.         if ($submit=="Read"){
  212.             iil_C_Flag($conn, $folder, $messages, "SEEN");
  213.             $reload_folders = true;
  214.             $selected_boxes = $checkboxes;
  215.         }
  216.     } //end if submit
  217.         
  218.         
  219.     /* If search results were moved or deleted, stop execution here. */
  220.     if (isset($search_done)){
  221.         echo "<p>Request completed.\n";
  222.         echo "</body></html>";
  223.         exit;
  224.     }
  225.     
  226.     /* initialize sort field and sort order 
  227.         (set to default prefernce values if not specified */
  228.     
  229.     if (empty($sort_field)) $sort_field=$my_prefs["sort_field"];
  230.     if (empty($sort_order)) $sort_order=$my_prefs["sort_order"];
  231.  
  232.     
  233.     /* figure out which/how many messages to fetch */
  234.     if ((empty($start)) || (!isset($start))) $start = 0;
  235.     $num_show=$my_prefs["view_max"];
  236.     if ($num_show==0) $num_show=50;
  237.     $next_start=$start+$num_show;
  238.     $prev_start=$start-$num_show;
  239.     if ($prev_start<0) $prev_start=0;
  240.     //echo "<p>Start: $start";
  241.     
  242.     /* flush, so the browser can't start renderin and user sees some feedback */
  243.     flush();
  244.     
  245.     $clock->register("pre-count");
  246.  
  247.     /* retreive message list (search, or list all in folder) */
  248.     if ((!empty($search)) || (!empty($search_criteria))){
  249.         include("../lang/".$my_prefs["lang"]."search_errors.inc");
  250.         $criteria="";
  251.         $error="";
  252.         $date = $month."/".$day."/".$year;
  253.         if (empty($search_criteria)){
  254.             // check criteria
  255.             if ($date_operand=="ignore"){
  256.                 if ($field=="-"){
  257.                     $error=$searchErrors["field"];
  258.                 }
  259.                 if (empty($string)){
  260.                     $error=$searchErrors["empty"];
  261.                 }
  262.             }else if ((empty($date))||($date=="mm/dd/yyyy")){
  263.                 $error=$searchErrors["date"];
  264.             }
  265.             if (!empty($date)){
  266.                 $date_a=explode("/", $date);
  267.                 $date=iil_FormatSearchDate($date_a[0], $date_a[1], $date_a[2]);
  268.             }
  269.         }
  270.         if ($error==""){
  271.             // format search string
  272.             if (empty($search_criteria)){
  273.                 $criteria="ALL";
  274.                 if ($field!="-") $criteria.=" $field \"$string\"";
  275.                 if ($date_operand!="ignore") $criteria.=" $date_operand $date";
  276.                 $search_criteria = $criteria;
  277.             }else{
  278.                 $search_criteria = stripslashes($search_criteria);
  279.                 $criteria = $search_criteria;
  280.             }
  281.             
  282.             echo "Searching \"$criteria\" in $folder<br>\n"; flush();
  283.             
  284.             // search
  285.             $messages_a=iil_C_Search($conn, $folder, $criteria);
  286.             $total_num=count($messages_a);
  287.             if (is_array($messages_a)) $messages_str=implode(",", $messages_a);
  288.             else $messages_str="";
  289.             echo "found: {".$messages_str."} <br>\n"; flush();
  290.         }else{
  291.             $headers=false;
  292.         }
  293.     }else{
  294.         $total_num=iil_C_CountMessages($conn, $folder);
  295.         if ($total_num > 0) $messages_str="1:".$total_num;
  296.         else $messages_str="";
  297.         $index_failed = false;        
  298.     }
  299.     
  300.     $clock->register("post count");
  301.     
  302.     echo "<!-- Total num: $total_num //-->\n"; flush();
  303.         
  304.         
  305.     /* if there are more messages than will be displayed,
  306.              create an index array, sort, 
  307.              then figure out which messages to fetch 
  308.     */
  309.     if (($total_num - $num_show) > 0){
  310.         //attempt ot read from cache
  311.         $read_cache = false;
  312.         if (file_exists(realpath($CACHE_DIR))){
  313.             $cache_path = $CACHE_DIR.ereg_replace("[\\/]", "", $loginID.".".$host);
  314.             $index_a = main_ReadCache($cache_path, $folder, $messages_str, $sort_field, $read_cache);
  315.         }
  316.         //if there are "recent" messages, ignore cache
  317.         if ($ICL_CAPABILITY["radar"]){
  318.             $recent=iil_C_CheckForRecent($conn, $folder);
  319.             if ($recent > 0) $read_cache = false;
  320.         }
  321.         
  322.         //if not read from cache, go to server
  323.         if (!$read_cache){
  324.             $index_a=iil_C_FetchHeaderIndex($conn, $folder, $messages_str, $sort_field);
  325.             $clock->register("post index: no cache");
  326.         }else{
  327.             $clock->register("post index: cache");
  328.         }
  329.         
  330.         if ($index_a===false){
  331.             //echo "iil_C_FetchHeaderIndex failed<br>\n";
  332.             if (strcasecmp($sort_field,"date")==0){
  333.                 if (strcasecmp($sort_order, "ASC")==0){
  334.                     $messages_str = $start.":".($start + $num_show);
  335.                 }else{
  336.                     $messages_str = ($total_num - $start - $num_show).":".($total_num - $start);
  337.                 }
  338.                 //echo $messages_str; flush();
  339.                 $index_failed = false;
  340.             }else{
  341.                 $index_failed = true;
  342.             }
  343.         }else{
  344.             if ((!$read_cache) && (file_exists(realpath($CACHE_DIR))))
  345.                 main_WriteCache($cache_path, $folder, $sort_field, $index_a, $messages_str);
  346.  
  347.             if (strcasecmp($sort_order, "ASC")==0) asort($index_a);
  348.             else if (strcasecmp($sort_order, "DESC")==0) arsort($index_a);
  349.             
  350.             reset($index_a);
  351.             $i=0;
  352.             while (list($key, $val) = each ($index_a)){
  353.                 if (($i >= $start) && ($i < $next_start)) $id_a[$i]=$key;
  354.                 $i++;
  355.             }
  356.             if (is_array($id_a)) $messages_str=implode(",", $id_a);
  357.  
  358.         }
  359.         
  360.         
  361.         echo "<!-- Indexed: $index_a //-->"; flush();
  362.     }
  363.     
  364.     $clock->register("post index");
  365.  
  366.     /* fetch headers */
  367.     if ($messages_str!=""){
  368.         //echo "Messages: $messages_str <br>\n";
  369.         $headers=iil_C_FetchHeaders($conn, $folder, $messages_str);
  370.         $headers=iil_SortHeaders($headers, $sort_field, $sort_order);  //if not from index array
  371.     }else{
  372.         $headers=false;
  373.     }
  374.     
  375.     $clock->register("post headers");
  376.     echo "<!-- Headers fetched: $headers //-->\n"; flush();
  377.     
  378.     /* if indexing failed, we need to get messages within range */
  379.     if ($index_failed){
  380.         $i = 0;
  381.         $new_header_a=array();
  382.         reset($headers);
  383.         while ( list($k, $h) = each($headers) ){
  384.             if (($i >= $start) && ($i < $next_start)){
  385.                 $new_header_a[$k] = $headers[$k];
  386.                 //echo "<br>Showing $i : ".$h->id;
  387.             }
  388.             $i++;
  389.         }
  390.         $headers = $new_header_a;
  391.     }
  392.         
  393.     /*  start form */
  394.     echo "\n<form name=\"messages\" method=\"POST\" action=\"main.php\">\n";            
  395.  
  396.     /* Show folder name, num messages, page selection pop-up */
  397.     
  398.     if ($headers==false) $headers=array();
  399.     echo "<table width=\"100%\" cellpadding=2 cellspacing=0><tr bgcolor=\"".$my_colors["main_head_bg"]."\">\n";
  400.     echo "<td align=left valign=bottom>\n";
  401.         $disp_folderName = $defaults[$folder];
  402.         if (empty($disp_folderName)){
  403.             $disp_folderName = $folder;
  404.             if (iil_StartsWith($disp_folderName, $my_prefs["rootdir"])){
  405.                 $disp_folderName = substr($disp_folderName, strlen($my_prefs["rootdir"])+1);
  406.             }
  407.         }
  408.         if (empty($search)){
  409.             echo "<span class=\"bigTitle\">";
  410.             echo urldecode($disp_folderName);
  411.             echo "</span>\n";
  412.         }
  413.         echo "<span class=\"mainHeadingSmall\">\n";
  414.         if (strcasecmp("INBOX", $folder)==0)
  415.             echo "[<a href=\"main.php?user=$user&folder=$folder\" class=\"mainHeadingSmall\">".$mainStrings[17]."</a>]";
  416.         if (strcmp($folder,$my_prefs["trash_name"])!=0)
  417.             echo "[<a href=\"main.php?user=$user&folder=$folder&delete_all=1\" class=\"mainHeadingSmall\">".$mainStrings[18]."</a>]";
  418.         echo "</span>\n";
  419.     echo "</td>\n";
  420.     echo "<td align=\"right\" valign=\"bottom\" class=\"mainHeadingSmall\">";
  421.         //show quota
  422.         if ($my_prefs["show_quota"]=="m"){
  423.             $quota = iil_C_GetQuota($conn);
  424.             include("../lang/".$my_prefs["lang"]."quota.inc");
  425.             if ($quota) echo $quotaStr["label"].LangInsertStringsFromAK($quotaStr["full"], $quota);
  426.             else echo $quotaStr["label"].$quotaStr["unknown"];
  427.         }
  428.     echo "</td>\n";
  429.     echo "</tr></table>";
  430.     
  431.     /* Confirm "delete all" request */
  432.     if ($delete_all==1){
  433.         echo "<p>".str_replace("%f", $folder, $mainErrors[7]);
  434.         echo "<span class=\"small\">[<a href=\"main.php?user=$user&folder=$folder&delete_all=2&delete_all_num=$total_num&submit=Delete\">";
  435.             echo $mainStrings[18]."</a>]</span>";
  436.         echo "<span class=\"small\">[<a href=\"main.php?user=$user&folder=$folder\">".$mainStrings[19]."</a>]</span>";
  437.     }
  438.     
  439.     
  440.     /* Show error messages, and reports */
  441.     if (!empty($error)) echo "<p><center><span style=\"color: red\">$error</span></center>";
  442.     //if ((empty($error)) && (empty($report))) echo "<p>";
  443.  
  444.  
  445.     $c_date["day"]=GetCurrentDay();
  446.     $c_date["month"]=GetCurrentMonth();
  447.     $c_date["year"]=GetCurrentYear();
  448.  
  449.     if (count($headers)>0) {
  450.         if (!isset($start)) $start=0;
  451.         $i=0;
  452.  
  453.         if (sizeof($headers)>0){            
  454.             /*  show "To" field or "From" field? */
  455.             if ($folder==$my_prefs["sent_box_name"]){
  456.                 $showto=true;
  457.                 $fromheading=$mainStrings[7];
  458.             }else{
  459.                 $fromheading=$mainStrings[8];
  460.             }            
  461.  
  462.  
  463.             /*  show num msgs and any notices */
  464.             echo "<table width=\"100%\"><tr>";
  465.             echo "<td valign=bottom align=\"left\"><span class=\"mainLightSmall\">";
  466.  
  467.             echo str_replace("%p", ($num_show>$total_num?$total_num:$num_show), str_replace("%n", $total_num, $mainStrings[0]))." ";
  468.             
  469.             echo "</span</td>";
  470.             echo "<td align=center><span class=\"mainLightSmall\">";
  471.             if (!empty($report)) echo $report;
  472.             echo "</span></td>\n";
  473.             echo "<td valign=bottom align=right class=\"mainLightSmall\">";
  474.             //page controls
  475.             $num_items=$total_num;
  476.             if ($num_items > $num_show){
  477.                 if ($prev_start < $start){
  478.                     $args = "&sort_field=$sort_field&sort_order=$sort_order&start=$prev_start";
  479.                     if (!empty($search_criteria)) $args .= "&search_criteria=".urlencode($search_criteria);
  480.                     echo "[<a href=\"main.php?user=$sid&folder=".urlencode($folder).$args."\" class=\"mainLightSmall\">";
  481.                     echo $mainStrings[2]." $num_show".$mainStrings[3]."</a>]";
  482.                 }
  483.  
  484.                 if ($next_start<$num_items){
  485.                     $num_next_str = $num_show;
  486.                     if (($num_items - $next_start) < $num_show) $num_next_str = $num_items - $next_start;
  487.                     $args = "&sort_field=$sort_field&sort_order=$sort_order&start=$next_start";
  488.                     if (!empty($search_criteria)) $args .= "&search_criteria=".urlencode($search_criteria);
  489.                     echo "[<a href=\"main.php?user=$sid&folder=".urlencode($folder).$args."\" class=\"mainLightSmall\">";
  490.                     echo $mainStrings[4]." $num_next_str".$mainStrings[5]."</a>]";
  491.                 }
  492.  
  493.                 echo "<select name=start class=\"small\">\n";
  494.                     $c=0;
  495.                     while ($c < $total_num){
  496.                         $c2=($c + $num_show);
  497.                         if ($c2 > $total_num) $c2=$total_num;
  498.                         echo "<option value=".$c.($c==$start?" SELECTED":"").">".($c+1)."-".$c2."\n";
  499.                         $c = $c + $num_show;
  500.                     }
  501.                 echo "</select>";
  502.                 echo "<input type=submit value=\"".$mainStrings[16]."\">";
  503.                 
  504.             }
  505.             echo "</td>\n";
  506.             echo "</tr></table>\n";
  507.  
  508.             $clock->register("pre list");
  509.  
  510.             /***
  511.             Show tool bar
  512.             ***/
  513.             if (strpos($my_prefs["main_toolbar"], "t")!==false){
  514.                 include("../include/main_tools.inc");
  515.             }
  516.  
  517.             /* main list */
  518.             $num_cols = strlen($my_prefs["main_cols"]);
  519.             echo "\n<!-- MAIN LIST //-->\n";
  520.             echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"".$my_colors["main_hilite"]."\">\n";
  521.             echo "<tr bgcolor=\"".$my_colors["main_head_bg"]."\">\n";
  522.                 $check_link="<SCRIPT type=\"text/javascript\" language=JavaScript1.2><!-- Make old browsers think this is a comment.\n";
  523.                 $check_link.="document.write(\"<a href=javascript:SelectAllMessages(true) class='tblheader'><b>+</b></a><span class=tblheader>|</span><a href=javascript:SelectAllMessages(false) class=tblheader><b>-</b></a>\")";
  524.                 $check_link.="\n--></SCRIPT><NOSCRIPT>";
  525.                 $check_link.="<a href=\"main.php?folder=".urlencode($folder)."&start=$start&user=$user&sort_field=$sort_field&sort_order=$sort_order&check_all=1\"><b>+</b></a>|";
  526.                  $check_link.="<a href=\"main.php?folder=".urlencode($folder)."&start=$start&user=$user&sort_field=$sort_field&sort_order=$sort_order&uncheck_all=1\"><b>-</b></a>";
  527.                 $check_link.="</NOSCRIPT>";
  528.                 $tbl_header["c"] = "\n<td>$check_link</td>";
  529.                 $tbl_header["s"] = "\n<td>".FormFieldHeader("subject", $mainStrings[6])."</td>";
  530.                 if ($showto)
  531.                     $tbl_header["f"] = "\n<td>".FormFieldHeader("to", $fromheading)."</td>";
  532.                 else
  533.                     $tbl_header["f"] = "\n<td>".FormFieldHeader("from", $fromheading)."</td>";
  534.                 $tbl_header["d"] = "\n<td>".FormFieldHeader("date", $mainStrings[9])."</td>";
  535.                 $tbl_header["z"] = "\n<td>".FormFieldHeader("size", $mainStrings[14])."</td>";
  536.                 $tbl_header["a"] = "<td><img src=\"themes/".$my_prefs["theme"]."/images/att.gif\"></td>";
  537.                 $tbl_header["m"] = "<td><img src=\"themes/".$my_prefs["theme"]."/images/reply.gif\"></td>";
  538.                 for ($i=0;$i<$num_cols;$i++) echo $tbl_header[$my_prefs["main_cols"][$i]];
  539.             echo "\n</tr>\n";
  540.             if ($MOVE_FIELDS){
  541.                 echo "<tr bgcolor=\"".$my_colors["main_head_bg"]."\">\n";
  542.                 $base_url = "main.php?folder=".urlencode($folder)."&start=$start&user=$user&sort_field=$sort_field&sort_order=$sort_order";
  543.                 $base_url.= "&MOVE_FIELDS=1";
  544.                 for ($i=0;$i<$num_cols;$i++) echo ShowFieldControls($my_prefs["main_cols"][$i], $base_url, $i, $num_cols);
  545.                 echo "</tr>\n";
  546.             }
  547.             $display_i=0;
  548.             $prev_id = "";
  549.             while (list ($key,$val) = each ($headers)) {
  550.                 //$next_id = $headers[key($headers)]->id;
  551.                 $header = $headers[$key];
  552.                 $id = $header->id;
  553.                 $seen = ($header->seen?"Y":"N");
  554.                 $deleted = ($header->deleted?"D":"");
  555.                 if ((($showdeleted==0)&&($deleted!="D")) || ($showdeleted)){
  556.                     if (($hideseen==0)||($seen=="N")){
  557.                         $display_i++;
  558.                         //echo "\n<tr ".(($i % 2)==0?"bgcolor=\"$bgc\"":"").">\n";
  559.                         
  560.                         echo "\n<tr bgcolor=\"".$my_colors["main_bg"]."\">\n";
  561.                         
  562.                         //show checkbox
  563.                         $row["c"] = "<td><input type=\"checkbox\" name=\"checkboxes[]\" value=\"$id\" ";
  564.                         $row["c"].= (isset($check_all)?"CHECKED":"");
  565.                         if (!isset($uncheck_all)) $row["c"].=(($spam) && (isSpam($header->Subject)>0) ? "CHECKED":"");
  566.                         if (is_array($selected_boxes) && in_array($id, $selected_boxes)) $row["c"].="CHECKED";
  567.                         $row["c"].= "></td>\n";
  568.                         //echo $row["c"];
  569.                         
  570.                         //show subject
  571.                         $subject=trim(chop($header->subject));
  572.                         if (empty($subject)) $subject=$mainStrings[15];
  573.                         $args = "user=$user&folder=".urlencode($folder)."&id=$id&uid=".$header->uid."&start=$start";
  574.                         $args.= "&num_msgs=$total_num&sort_field=$sort_field&sort_order=$sort_order";
  575.                         $row["s"] = "<td><a href=\"read_message.php?".$args."\" ";
  576.                         $row["s"].= ($my_prefs["view_inside"]!=1?"target=\"scr".$user.urlencode($folder).$id."\"":"").">".($seen=="N"?"<B>":"");
  577.                         $row["s"].= encodeUTFSafeHTML(LangDecodeSubject($subject, $my_prefs["charset"])).($seen=="N"?"</B>":"")."</a></td>\n";
  578.                         //echo $row["s"];
  579.                         
  580.                         //show sender||recipient
  581.                         if ($showto) $row["f"] = "<td>".LangDecodeAddressList($header->to, $my_prefs["charset"], $user)."</td>\n";                        
  582.                         else $row["f"] = "<td>".LangDecodeAddressList($header->from, $my_prefs["charset"], $user)."</td>\n";
  583.                         //echo $row["f"];
  584.  
  585.                         //show date/time
  586.                         $timestamp = $header->timestamp;
  587.                         $timestamp = $timestamp + ((int)$my_prefs["timezone"] * 3600);
  588.                         $row["d"] = "<td><nobr>".ShowShortDate($timestamp, $lang_datetime)." </nobr></td>\n";
  589.                         //echo $row["d"];
  590.  
  591.                         //show size
  592.                         $row["z"] = "<td><nobr>".ShowBytes($header->size)."</nobr></td>\n";
  593.  
  594.                         //attachments?
  595.                         $row["a"] = "<td>";
  596.                         if (preg_match("/multipart\/m/i", $header->ctype)==TRUE){
  597.                             $row["a"].= "<img src=\"themes/".$my_prefs["theme"]."/images/att.gif\">";
  598.                         }
  599.                         $row["a"].= "</td>\n";
  600.                         //echo $row["a"];
  601.  
  602.                         //show flags
  603.                         $row["m"] = "<td>".($header->deleted?"D":"").($header->answered?"<img src=\"themes/".$my_prefs["theme"]."/images/reply.gif\">":" ")."</td>\n";
  604.                         //echo $row["a"];
  605.                         
  606.                         for ($i=0;$i<$num_cols;$i++) echo $row[$my_prefs["main_cols"][$i]];
  607.                         
  608.                         echo "</tr>\n";
  609.                         flush();
  610.                     }
  611.                 }
  612.                 $i++;
  613.             }
  614.             echo "</table>";
  615.  
  616.             flush();
  617.             
  618.             $clock->register("post list: $i");
  619.             
  620.             echo "<input type=\"hidden\" name=\"user\" value=\"$user\">\n";
  621.             echo "<input type=\"hidden\" name=\"folder\" value=\"$folder\">\n";
  622.             echo "<input type=hidden name=\"sort_field\" value=\"".$sort_field."\">\n";
  623.             echo "<input type=hidden name=\"sort_order\" value=\"".$sort_order."\">\n";
  624.             if (isset($search)) echo "<input type=hidden name=search_done value=1>\n";
  625.             echo "<input type=\"hidden\" name=\"max_messages\" value=\"".$display_i."\">\n";
  626.             
  627.             /***
  628.             Show tool bar
  629.             ***/
  630.             if (strpos($my_prefs["main_toolbar"], "b")!==false){
  631.                 $clock->register("pre tools include");
  632.                 include("../include/main_tools.inc");
  633.                 $clock->register("post tools include");
  634.             }
  635.             
  636.             echo "</form>\n";
  637.             
  638.             if (($folder=="INBOX")&&($ICL_CAPABILITY["radar"])){
  639.                 /*** THIS JavaScript code does NOT run reliably!! ***/
  640.                 echo "\n<script language=\"JavaScript\">\n";
  641.                 echo "if (parent.radar)";
  642.                 echo "  parent.radar.location=\"radar.php?user=".$user."\";\n";
  643.                 echo "</script>\n";
  644.             }
  645.             if (($ICL_CAPABILITY["folders"]) && ($my_prefs["list_folders"]) && ($my_prefs["showNumUnread"]) && ($reload_folders)){
  646.                 echo "\n<script language=\"JavaScript\">\n";
  647.                 echo "parent.list1.location=\"folders.php?user=".$user."\";\n";
  648.                 echo "</script>\n";
  649.             }
  650.         }else{
  651.             if (!empty($search)) echo "<p><center>".$mainErrors[0]."</center>";
  652.             else echo "<p><center><span class=mainLight>".$mainErrors[1]."</span></center>";
  653.         }
  654.     }else{
  655.         if (!empty($search)) echo "<p><center><span class=mainLight>".$mainErrors[0]."</span></center>";
  656.         else echo "<p><center><span class=mainLight>".$mainErrors[1]."</span></center>";
  657.     }
  658.     
  659.     iil_Close($conn);
  660.  
  661. $clock->register("done");
  662. $exec_finish_time = microtime();
  663. echo '<!-- execution time: '.$exec_start_time.' ~ '.$exec_finish_time.' -->';
  664. echo "\n<!--\n";
  665. $clock->dump();
  666. echo "\n//-->\n";
  667. ?>
  668. </BODY></HTML>
  669.