File(s) status

N.B.: Versions in bold letters are current versions of your files.

<?php

### Control uploaded file ###

if (file_exists($_FILES[‘tracking_id_list’][‘tmp_name’])) { # If file exists

    if ($_FILES[‘tracking_id_list’][‘size’] == 0) { # If not empty

        echo ‘<strong><span style= »color: #ff0000; »>Empty file.</span></strong><br><form action= »index.php?option=com_content&amp;view=article&amp;catid=87&amp;id=240″ method= »POST » enctype= »multipart/form-data »><input type= »hidden » name= »MAX_FILE_SIZE » value= »2097152″ />File: <input type= »file » name= »tracking_id_list » /><input type= »submit » value= »Send » /> (Max size = 2Mo)</form>’;

    } elseif ($_FILES[‘tracking_id_list’][‘size’] >= 2097152) { # If not out of memory

        echo ‘<strong><span style= »color: #ff0000; »>File out of maximum size.</span></strong><br><form action= »index.php?option=com_content&amp;view=article&amp;catid=87&amp;id=240″ method= »POST » enctype= »multipart/form-data »><input type= »hidden » name= »MAX_FILE_SIZE » value= »2097152″ />File: <input type= »file » name= »tracking_id_list » /><input type= »submit » value= »Send » /> (Max size = 2Mo)</form>’;

    } elseif (strrchr($_FILES[‘tracking_id_list’][‘name’], ‘.’) != ‘.txt’) { # If right format

        echo ‘<strong><span style= »color: #ff0000; »>Wrong file format.</span></strong><br><form action= »index.php?option=com_content&amp;view=article&amp;catid=87&amp;id=240″ method= »POST » enctype= »multipart/form-data »><input type= »hidden » name= »MAX_FILE_SIZE » value= »2097152″ />File: <input type= »file » name= »tracking_id_list » /><input type= »submit » value= »Send » /> (Max size = 2Mo)</form>’;

    } else {

        $file = fopen($_FILES[‘tracking_id_list’][‘tmp_name’],’r’); # If OK, open file

    }

} else {

    echo ‘<strong><span style= »color: #ff0000; »>No file.</span></strong><br><form action= »index.php?option=com_content&amp;view=article&amp;catid=87&amp;id=240″ method= »POST » enctype= »multipart/form-data »><input type= »hidden » name= »MAX_FILE_SIZE » value= »2097152″ />File: <input type= »file » name= »tracking_id_list » /><input type= »submit » value= »Send » /> (Max size = 2Mo)</form>’;

}

    

### Formatting files status ###

if ($file) { # Control if file exists

    try { $bdd = new PDO(‘mysql:host=localhost;dbname=joomla_df’, ‘joomla_df’, ‘#Fmq8w4IP6’); } # Database connexion

    catch (Exception $e) { die(‘Error: ‘ . $e->getMessage()); }

    echo ‘<table style= »width: 100%; font-size: 11px; border: 0px; »><tbody>’; # Create table to display results

    while (!feof($file)) { # Investigating file line by line

        $id_pattern = ‘/^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/’; # Defining tracking ID pattern

        if(preg_match($id_pattern, fgets($file), $match)){ # Control pattern and select only ID string

            $id = $match[0];

            $req = $bdd -> query(‘SELECT * FROM jos_IPSL_db WHERE tracking_ID = « ‘ . $id . ‘ »‘); # SQL query to find file

            $data = $req -> fetch(PDO::FETCH_ASSOC);

            $req -> closeCursor();

            $req = $bdd -> query(‘SELECT * FROM jos_IPSL_db WHERE errata_id = « ‘ . $data[‘errata_id’] . ‘ »‘); # SQL quary to find all file versions

            $nrows = $req -> rowCount();

            $infos = $req -> fetchAll(PDO::FETCH_ASSOC);

            $req -> closeCursor();

            # Formating results

            echo ‘<tr>

            <td bgcolor= »#ffcc99″ style= »height: 20px; »><span style= »font-size: small; »><em>Filename:<em></span></td>

            <td bgcolor= »#ffcc99″ style= »text-align: right; »><span style= »; font-size: small; »>’ . $data[‘filename’] . ‘</span></td>

            </tr>’;

            echo ‘<tr>

            <td valign= »top » style= »height: 100px; »><em><p>Tracking ID:</p><p>Versioning:</p><p>History:</p></em></td>

            <td valign= »top » style= »text-align: right; »><p>’ . $data[‘tracking_id’] . ‘</p><p>Current version <em><strong>’ . $data[‘version’] . ‘</em> ‘;

            if( ($data[‘errata’] != « U ») && ($data[‘version’] != $infos[($nrows -1)][‘version’]) ){ # Test for latest version (i.e., uniq or last)

                echo ‘<span style= »color: #ff0000; »>IS NOT</span>’;

            } else {

                echo ‘<span style= »color: #ff00ff; »>IS</span>’;

            }

            echo ‘</strong> the latest.</p><p align= »left »>’;

            # Group ALL versions (symbolic linked and modified)

            $string = $infos[0][‘linked’];

            for ($i = 1; $i <= ($nrows – 1); $i++) {

                $string = $string . ‘/’ . $infos[$i][‘linked’];

            }

            $all_versions = array_merge(array_unique(explode(‘/’, $string))); # Delete duplicates and index table

            $nb_versions = count($all_versions);

            if ($nb_versions == 1) {

                echo  ‘<span style= »color: #ff0000; »><strong>No other version is available for this file.</strong></br>’;

            } else {

                for ($i = 0; $i <= ($nb_versions – 1); $i++) { # Loop along ALL versions

                    $req = $bdd -> query(‘SELECT * FROM jos_IPSL_db WHERE errata_id = « ‘ . $data[‘errata_id’] . ‘ » AND version = « ‘ . $all_versions[$i] . ‘ »‘); # SQL query to match modified files/versions

                    $test = $req -> fetch();

                    if(!$test) { # If NULL query version is symbolic link

                        echo $all_versions[$i] . ‘ is a symbolic link to previous version.<br>’;

                    } else { # If not, version corresponds to modified file

                        if($all_versions[$i] == $data[‘version’]) { # Display current version in bold letters

                            echo ‘<strong>’ . $all_versions[$i] . ‘</strong>’;

                        } else {

                            echo $all_versions[$i];

                        }

                        $errata = explode(‘/’, $infos[$i][‘errata’]); # Separate and define errata number

                        $nb_errata = count($errata);

                        if (($errata[0] == « U ») || ($errata[0] == « F »)) { # If first or uniq version, displays it

                            echo ‘ is the original/first version’;

                        } else { # If not, display errata link for each number

                            echo ‘ corrects issue(s) ‘;

                            for ($j = 0; $j <= ($nb_errata – 1); $j++) { # Loog along errata numbers

                                echo ‘ <a href= »index.php?option=com_content&amp;view=article&amp;catid=87&amp;id=’ . (209+$errata[$j]) . ‘ » target= »_blank »>#’ . $errata[$j]. ‘</a>’; # HTML link

                            }

                        }

                        echo ‘.<br>’;

                    }

                }

            }

            $req -> closeCursor();

            echo ‘</p></td></tr>’;

        }

    }

    echo ‘</tbody></table>’; # End table for results

    fclose($file); # Close file

}

?>


<< Back to table