web/privatedoc/includes/functions.php
changeset 7 7a5d38af0e65
equal deleted inserted replaced
6:06c4f682b7b2 7:7a5d38af0e65
       
     1 <?php
       
     2 
       
     3 /* liste des dossiers */
       
     4 function list_dir($base, $cur, $level=0) {
       
     5 
       
     6 	global $PHP_SELF, $BASE;
       
     7 
       
     8 	if ($dir = opendir($base)) {
       
     9     $tab = array();
       
    10     while($entry = readdir($dir)) {
       
    11       if(is_dir($base."/".$entry) && !in_array($entry, array(".",".."))) {
       
    12         $tab[] = $entry;
       
    13       }
       
    14     }
       
    15 
       
    16    	if(ereg("([0-9]{1,2})[_]([0-9]{1,2})[_]([0-9]{4})",$tab[0])){
       
    17    		$timestamp=array();
       
    18    		foreach($tab as $val):
       
    19    			list($day, $month, $year) = explode('_',$val);
       
    20    			$timestamp[] = mktime(0,0,0,$month, $day, $year);
       
    21    		endforeach;
       
    22 
       
    23    		sort($timestamp,SORT_NUMERIC);
       
    24 
       
    25    		$tab=array();
       
    26    		foreach($timestamp as $ts):
       
    27    			$tab[] = date('d_m_Y', $ts);
       
    28    		endforeach;
       
    29 
       
    30 
       
    31    	}else{
       
    32 
       
    33 	    natcasesort($tab);
       
    34    	}
       
    35     //natsort($tab);
       
    36 
       
    37     foreach($tab as $entry) {
       
    38       /* chemin relatif à la racine */
       
    39       $file = $base."/".$entry;
       
    40 
       
    41       /* marge gauche
       
    42       for($i=1; $i<=(4*$level); $i++) {
       
    43         echo "&nbsp;";
       
    44       }
       
    45       */
       
    46 
       
    47       /* l'entrée est-elle le dossier courant */
       
    48       if($file == $cur) {
       
    49         echo "<img src=\"http://www.iri.centrepompidou.fr/privatedoc/img/folder.png\" />&nbsp;".strtoupper($entry)."<br />\n";
       
    50       } else {
       
    51 
       
    52       	$display = deInterCaps($entry);
       
    53         $display = UtoWS($display);
       
    54 
       
    55       	echo "<img src=\"http://www.iri.centrepompidou.fr/privatedoc/img/folder.png\" />&nbsp; <a href=\"$PHP_SELF?dir=".rawurlencode($file)."\">".trim(strtoupper($display))."</a><br/>\n";
       
    56 
       
    57 
       
    58 
       
    59       }
       
    60       /* l'entrée est-elle dans la branche dont le dossier courant est la feuille */
       
    61       if(ereg($file."/",$cur."/")) {
       
    62         list_dir($file, $cur, $level+1);
       
    63       }
       
    64     }
       
    65     closedir($dir);
       
    66   }
       
    67 }
       
    68 
       
    69 /* liste des fichiers */
       
    70 function list_file($cur) {
       
    71 global $PHP_SELF, $BASE;
       
    72   if ($dir = opendir($cur)) {
       
    73     /* tableaux */
       
    74     $tab_dir = array();
       
    75     $tab_file = array();
       
    76     /* extraction */
       
    77     while($file = readdir($dir)) {
       
    78       if(is_dir($cur."/".$file)) {
       
    79           $tab_dir[] = $file;
       
    80       } else {
       
    81           $tab_file[] = $file;
       
    82       }
       
    83     }
       
    84 
       
    85 
       
    86     /* tri */
       
    87 
       
    88     sort($tab_dir);
       
    89 
       
    90     sort($tab_file);
       
    91 
       
    92     /* affichage */
       
    93     if(!empty($tab_file)):
       
    94     foreach($tab_dir as $elem) {
       
    95      if($elem == ".." && isset($_GET['dir'])):
       
    96         echo "<img src=\"http://www.iri.centrepompidou.fr/privatedoc/img/folder.png\" />&nbsp;<a href='javascript:history.back()' title='retour'>".$elem."</a><br />\n";
       
    97      else:
       
    98         //echo "<img src=\"dir-close.gif\" />&nbsp;".$elem."<br />\n";
       
    99      endif;
       
   100     }
       
   101     endif;
       
   102 
       
   103     $i=0;
       
   104     $tab=array();
       
   105     $path='';
       
   106     $tab = explode("/",$BASE);
       
   107 
       
   108     echo '<table width="100%" cellspacing="0" cellpadding="0">';
       
   109     foreach($tab_file as $elem) {
       
   110 
       
   111 
       
   112         $path='';
       
   113         for($j=5;$j<count($tab);$j++){
       
   114             $path .= $tab[$j]."/";
       
   115         }
       
   116 
       
   117         $path .= $elem;
       
   118 
       
   119         $temppath = substr($BASE,26);
       
   120       	$temppath .= "/";
       
   121 
       
   122         $displayElem = UtoWS($elem);
       
   123       	$iconeInfo = (strstr(strtolower($BASE),"regards"))?'<a href="javascript:void(0)" onclick="document.getElementById(\'moreinfo\').style.display=\'block\'"><img src="http://www.iri.centrepompidou.fr/privatedoc/img/information.png" alt="information" title="plus d\'information" class="image"/></a>&nbsp;&nbsp;':'';
       
   124 
       
   125       	//gestion du type de fichier
       
   126       	//si mp3 : affichage lien download et ecoute
       
   127       	//si pdf : uniquement download
       
   128       	//si zip : uniquement download
       
   129       	list($filename, $ext) = explode('.',$elem);
       
   130 
       
   131       	if($ext == 'mp3'){
       
   132 	      	echo "<tr>";
       
   133 	     	echo "<td width='80%'><img src=\"http://www.iri.centrepompidou.fr/privatedoc/img/page_white_cd.png\" border='0'/>&nbsp;<a href=\"javascript:void(0)\" onclick=\"switchMedia('".trim($temppath.$elem)."')\" >".$displayElem."</a></td>";
       
   134 	      	echo "<td>".$iconeInfo."<a href=\"javascript:void(0)\" onclick=\"switchMedia('".trim($temppath.$elem)."')\">&nbsp;&nbsp;<img src='http://www.iri.centrepompidou.fr/privatedoc/img/sound.png' border='0' title='ecouter' alt='ecouter' class='image'/></a>&nbsp;&nbsp;";
       
   135             echo "<a href=\"http://www.iri.centrepompidou.fr/documents/audio/".$path."\">&nbsp;&nbsp;<img src='http://www.iri.centrepompidou.fr/privatedoc/img/disk.png' border='0' title='télécharger' alt='télécharger' class='image'></a><br/></td>";
       
   136 	      	echo '</tr>';
       
   137       	}
       
   138       	elseif($ext == 'pdf' || $ext == 'zip'){
       
   139 
       
   140       		echo "<tr>";
       
   141 	      	echo "<td width='80%'>";
       
   142 	      	echo "<img src=\"http://www.iri.centrepompidou.fr/privatedoc/img/$ext.png\" border='0'/>&nbsp;<a href=\"http://www.iri.centrepompidou.fr/documents/audio/$path\" >".$displayElem."</a></td>";
       
   143 	      	echo "<td>".$iconeInfo."<a href=\"http://www.iri.centrepompidou.fr/documents/audio/".$path."\">&nbsp;&nbsp;<img src='http://www.iri.centrepompidou.fr/privatedoc/img/disk.png' border='0' title='télécharger' alt='télécharger' class='image'></a><br/></td>";
       
   144 	      	echo '</tr>';
       
   145 
       
   146       	}
       
   147     $i++;
       
   148     }
       
   149     echo '</table>';
       
   150     closedir($dir);
       
   151   }
       
   152 }
       
   153 
       
   154 /*remplace une majuscule par un espace*/
       
   155 function deInterCaps($var){
       
   156    return ucfirst(strtolower(ereg_replace("[A-Z]"," \\0",$var)));
       
   157 }
       
   158 
       
   159 /*remplace un underscore par un espace*/
       
   160 function UtoWS($text){
       
   161 
       
   162 	return ucfirst(strtolower(ereg_replace("[_]"," ",$text)));
       
   163 }
       
   164 ?>