Subversion Repositories Applications.projet

Rev

Rev 392 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
// $Id: ezmlm-listinfo.php,v 1.3 2007/04/19 15:34:35 neiluj Exp $
//
// ezmlm-listinfo.php - ezmlm-php v2.0
// --------------------------------------------------------------
// Displays general list info in the format of a welcome page.
// --------------------------------------------------------------

require_once("ezmlm.php");

class ezmlm_listinfo extends ezmlm_php {

    function ezmlm_listinfo () {
        //return is_dir($this->listdir.'/archive/0') ;
    }
        function display() {
                
        if (!is_dir($this->listdir.'/archive/0')) {  // On teste si il y a au moins un message, cad le répertoire 0
            echo $this->listdir.'/archive/0' ;
            
            return false ;
        }
        
                $parser = new ezmlm_parser();
        $parser->listdir = $this->listdir ;
                
                //$this->show_info_file();
                
        
                $threads = new ezmlm_threads();
        $threads->listdir = $this->listdir ;
        $threads->listname = $this->listname ;
        $threads->forcehref = $this->forcehref ;        /// ajout alex
        $threads->listmessages() ;
                $this->show_recentmsgs();
        return true ;
        }

        function show_info_file() {
                if (@is_file($this->listdir . "/text/info")) {
                        $infofile = @file($this->listdir . "/text/info");
                        while (list($line_num, $line) = each($infofile)) {
                                print nl2br($line);
                        }
                }
        }


        function show_recentmsgs($title = "Messages récents") {
        
        if (!is_dir($this->listdir.'/archive/0')) return false;
        
        
        $html = '' ;
                $parser = new ezmlm_parser();
        $parser->listdir = $this->listdir ;
        $html .= '<table class="table_cadre">'."\n";
        $html .= '<tr><th class="col1">Num</th><th>De</th><th>Sujet</th><th>Date</th></tr>'."\n";
        $ctc = 0;
        $recent = $parser->recent_msgs();
        
        // le tableau recent est de la forme
        // $recent[numero_message][1] sujet
        // $recent[numero_message][2] date en anglais => (22 May 2006)
        // $recent[numero_message][3] le hash de l auteur
        // $recent[numero_message][4] auteur
        
        $class = array ('ligne_paire', 'ligne_impaire') ;
        
        while (list($key,$val) = each($recent)) {
            $html .= '<tr class="'.$class[$ctc].'">'."\n";
            //print '<td>'.$val->nummessage.'</td>' ;
            
            // $key contient le numero du message tel que dans les fichiers d index par ex 216
            // on retrouve le nom du repertoire et le nom du fichier
            $decimal = (string) $key;
            if ($key >= 100) {
                                        $fichier_message = substr($decimal, -2) ;
                                        $repertoire_message = substr ($decimal, 0, -2) ;
                                } else {
                                        if ($key < 10) {
                                                $fichier_message = '0'.$key;
                                        } else {
                                                $fichier_message = $decimal;
                                        }
                                        $repertoire_message = '0';
                        }
            
            $html .= '<td>'.$key.'</td>' ;
            $html .= '<td>';

            $from = $val[4];

            $html .= $this->makelink("action=show_author_msgs&actionargs[]=".$val[3],$this->decode_iso($this->protect_email($from,false)));
            $html .= "</td>\n";
            $html .= '<td><b>';
            $actionargs = preg_split("/\//", $val->msgfile);
            
            $html .= $this->makelink("action=show_msg&actionargs[]=".$repertoire_message.
                                "&actionargs[]=".$fichier_message ,$this->decode_iso($val[1]));

            $html .= "</b></td>\n";
            
            //print '<td>'.$this->date_francaise($val[2]).'</td>'."\n";
            $html .= '<td>'.$val[2].'</td>'."\n";
            $html .= "</tr>\n";

            $ctc++;
            if ($ctc == 2) { $ctc = 0; }
        }
        $html .= '</table>'."\n";
        return $html;
        }
    
    // month = yyyymm
    function show_month ($month) {        
        $html = '' ;
        
        // on ouvre chaque fichier en lecture
        if(!file_exists($this->listdir . '/archive/threads/' . $month)) {
                return false ;
        }
        
        $numeros_mails_mois = $this->calculerNumMessagesDansMois($month);

        $html .= '<table class="table_cadre">'."\n";
        $html .= '<tr><th class="col1">Num</th><th>De</th><th>Sujet</th><th>Date</th></tr>'."\n";
        $ctc = 0;
        
        $class = array ('ligne_paire', 'ligne_impaire') ;

        if(count($numeros_mails_mois) > 0) {
            $repertoire_premier_mail = (int) (reset($numeros_mails_mois) / 100) ;
        }
        
        foreach ($numeros_mails_mois as $num_message) {

            $i = $num_message;

            if ($i > 99) {
                $multiplicateur = (int) ($i / 100) ;
                // pour les mails > 99, on retranche n fois 100, ex 256 => 56 cad 256 - 2 * 100 
                $i = $i - $multiplicateur * 100 ;
            }

            if ($i < 10) $num_message = '0'.$i ; else $num_message = $i ;
            if (file_exists($this->listdir.'/archive/'.$repertoire_premier_mail.'/'.$num_message)) { 
                    $mimeDecode = new Mail_mimeDecode(file_get_contents ($this->listdir.'/archive/'.$repertoire_premier_mail.'/'.$num_message)) ;
                    $mailDecode = $mimeDecode->decode() ;

                if ($i == 99) {
                        $repertoire_premier_mail++;
                 $i = -1;
                }
            
                $html .= '<tr class="'.$class[$ctc].'">'."\n";
                $html .= '<td>'.($repertoire_premier_mail != 0 ? $repertoire_premier_mail : '').$num_message.'</td><td>';
                $hash = $this->makehash($mailDecode->headers['from']);
            
                $html .= $this->makelink("action=show_author_msgs&actionargs[]=".
                                $hash,$this->decode_iso($this->protect_email($mailDecode->headers['from'],TRUE)));
                $html .= "</td>\n";
                $html .= '<td><b>';
                $actionargs[0] = $repertoire_premier_mail ;
                $actionargs[1] = $num_message ;
            
                        if (count ($actionargs) > 1) {
                        $html .= $this->makelink("action=show_msg&actionargs[]=".
                                        $actionargs[(count($actionargs) - 2)] . 
                            "&actionargs[]=".
                            $actionargs[(count($actionargs) - 1)] ,$this->decode_iso($mailDecode->headers['subject']));
                }
                $html .= "</b></td>\n";
                        $html .= '<td>'.$this->date_francaise($mailDecode->headers['date']).'</td>'."\n";
                $html .= "</tr>\n";
                $ctc++;
                if ($ctc == 2) { $ctc = 0; }
            }
        }

        $html .= '</table>'."\n";

        return $html;
    }

    private function calculerNumMessagesDansMois($mois) {

        $fd = file_get_contents($this->listdir . '/archive/threads/'.$mois, 'r');
        $fichier = explode ("\n", $fd) ;

        $premiere_ligne = $fichier[0] ;

        $nb_lignes_fichier = count($fichier);

        $lignes_messages = array();
                
        preg_match ('/[0-9]+/', $premiere_ligne, $match) ;
        $numero_premier_mail  = $match[0] ;

        $lignes_messages[$numero_premier_mail] = $numero_premier_mail;

        foreach($fichier as $ligne) {

              if(trim($ligne == '')) { continue ;}

              $ligne_tableau = explode(' ', $ligne);
              $num_mail_sujet = explode(':',$ligne_tableau[0]);
              $num_sujet =  $num_mail_sujet[1];

              $fd_sujet = file_get_contents($this->listdir.'/archive/subjects/'.substr($num_sujet,0,2).'/'.substr($num_sujet,2,strlen($num_sujet) - 1), 'r');
              $premiere_ligne = true;

              $fichier_sujet = explode ("\n", $fd_sujet) ;
              foreach($fichier_sujet as $ligne_sujet) {

                if($premiere_ligne || trim($ligne_sujet) == '') {$premiere_ligne = false; continue; }
                  $ligne_tableau_sujet = explode(':', $ligne_sujet);
                  $num_mail =  $ligne_tableau_sujet[0];
                  $mois_ligne =  $ligne_tableau_sujet[1];
                  if($mois_ligne == $mois) {
                        if(is_numeric($num_mail)) {
                            $lignes_messages[$num_mail] = $num_mail;
                        } else {
                            $num_mail = preg_replace('/[^0-9]+/','', $num_mail) ;
                            $lignes_messages[$num_mail] = $num_mail;
                        }
                  }
              }
        }

        asort($lignes_messages);
        return $lignes_messages;
    }
}
?>