Advertisement
Guest User

Untitled

a guest
Jul 8th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. error_reporting(-1 ^ E_NOTICE);
  3. $printers = array();
  4. if (($handle = fopen("printers.csv", "r")) !== FALSE)
  5. {
  6.     while (($data = fgetcsv($handle, 1000, ';','"')) !== FALSE)
  7.     {
  8.         $printer = trim(strtolower($data[1]));
  9.         $user = trim(strtolower($data[0]));
  10.  
  11.         if($user != 'EMP_INSTUSER' and $user != 'Administrator')
  12.         {
  13.  
  14.             if(substr($printer,0,2) == '\\\\' and !in_array($printer,$printers))
  15.             {
  16.                 $printers[] = $printer;
  17.             }
  18.            
  19.             if(substr($printer,0,2) == '\\\\')
  20.             {
  21.                 $user_count[$printer]++;
  22.             }
  23.         }
  24.     }
  25. }
  26. fclose($handle);
  27. sort($printers);
  28. $i = 0;
  29.  
  30. while($i <= max($user_count))
  31. {
  32.     foreach($printers as $p)
  33.     {
  34.         $csv[$i][$p] = '';
  35.     }
  36.     $i++;
  37. }
  38.  
  39. foreach($user_count as $printer => $val)
  40.     $user_count[$printer] = 0;
  41.  
  42. if (($handle = fopen("printers.csv", "r")) !== FALSE) {
  43.     while (($data = fgetcsv($handle, 1000, ';','"')) !== FALSE) {
  44.         $printer = trim(strtolower($data[1]));
  45.         $user = trim(strtolower($data[0]));
  46.         if(array_key_exists($printer,$user_count))
  47.         {
  48.             $csv[$user_count[$printer]][$printer] = $user;
  49.             $user_count[$printer]++;
  50.         }
  51.     }
  52. }
  53. #echo_array($user_count, max($user_count));
  54. #echo_array($csv);
  55. ?>
  56.  
  57. <table>
  58.   <tr>
  59.   <th>Row</th>
  60.   <?foreach($printers as $printer) echo '<th>'.$printer.'</th>'?>
  61.   </tr>
  62. <?
  63. foreach($csv as $row => $values)
  64. {
  65.     echo '<tr>';
  66.     echo '<td>'.$row.'</td>';
  67.     foreach($values as $val) echo '<td>'.$val.'</td>';
  68.     echo '</tr>';
  69. }
  70. ?>
  71. </table>
  72.  
  73. <?
  74. $fp = fopen('./printers_list.csv', 'w');
  75. fputcsv($fp, $printers,';');
  76. foreach ($csv as $fields) {
  77.     fputcsv($fp, $fields,';');
  78. }
  79.  
  80. fclose($fp);
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement