/** We consider public file as assigned file */
 foreach ($db_files_public as $file_id) {
     $assigned[] = $file_id;
 }
 /** Read the temp folder and list every allowed file */
 if ($handle = opendir($work_folder)) {
     while (false !== ($filename = readdir($handle))) {
         $filename_path = $work_folder . '/' . $filename;
         if (!is_dir($filename_path)) {
             if ($filename != "." && $filename != "..") {
                 /** Check types of files that are not on the database */
                 if (!array_key_exists($filename, $db_files)) {
                     $file_object = new PSend_Upload_File();
                     $new_filename = $file_object->safe_rename_on_disc($filename, $work_folder);
                     /** Check if the filetype is allowed */
                     if ($file_object->is_filetype_allowed($new_filename)) {
                         /** Add it to the array of available files */
                         $new_filename_path = $work_folder . '/' . $new_filename;
                         //$files_to_add[$new_filename] = $new_filename_path;
                         $files_to_add[] = array('path' => $new_filename_path, 'name' => $new_filename, 'reason' => 'not_on_db');
                     }
                 } else {
                     /**
                      * These following files EXIST on DB ($db_files)
                      * but not on the assigned table ($assigned)
                      */
                     if (!in_array($db_files[$filename], $assigned)) {
                         $files_to_add[] = array('path' => $filename_path, 'name' => $filename, 'reason' => 'not_assigned');
                     }
                 }
             }
        $file_original = $file;
        $location = $work_folder . '/' . $file;
        /**
         * Check that the file is indeed present on the folder.
         * If not, it is added to the failed files array.
         */
        if (file_exists($location)) {
            /** Generate a safe filename */
            //$file = $this_upload->safe_rename($file);
            /**
             * Remove the extension from the file name and replace every
             * underscore with a space to generate a valid upload name.
             */
            $filename_no_ext = substr($file, 0, strrpos($file, '.'));
            $file_title = str_replace('_', ' ', $filename_no_ext);
            if ($this_upload->is_filetype_allowed($file)) {
                if (in_array($file, $urls_db_files)) {
                    $statement = $dbh->prepare("SELECT filename, description FROM " . TABLE_FILES . " WHERE url = :url");
                    $statement->bindParam(':url', $file);
                    $statement->execute();
                    while ($row = $statement->fetch()) {
                        $file_title = $row["filename"];
                        $description = $row["description"];
                    }
                }
                ?>
								<div class="file_editor <?php 
                if ($i % 2) {
                    echo 'f_e_odd';
                }
                ?>