Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(-1 ^ E_NOTICE);
- $printers = array();
- if (($handle = fopen("printers.csv", "r")) !== FALSE)
- {
- while (($data = fgetcsv($handle, 1000, ';','"')) !== FALSE)
- {
- $printer = trim(strtolower($data[1]));
- $user = trim(strtolower($data[0]));
- if($user != 'EMP_INSTUSER' and $user != 'Administrator')
- {
- if(substr($printer,0,2) == '\\\\' and !in_array($printer,$printers))
- {
- $printers[] = $printer;
- }
- if(substr($printer,0,2) == '\\\\')
- {
- $user_count[$printer]++;
- }
- }
- }
- }
- fclose($handle);
- sort($printers);
- $i = 0;
- while($i <= max($user_count))
- {
- foreach($printers as $p)
- {
- $csv[$i][$p] = '';
- }
- $i++;
- }
- foreach($user_count as $printer => $val)
- $user_count[$printer] = 0;
- if (($handle = fopen("printers.csv", "r")) !== FALSE) {
- while (($data = fgetcsv($handle, 1000, ';','"')) !== FALSE) {
- $printer = trim(strtolower($data[1]));
- $user = trim(strtolower($data[0]));
- if(array_key_exists($printer,$user_count))
- {
- $csv[$user_count[$printer]][$printer] = $user;
- $user_count[$printer]++;
- }
- }
- }
- #echo_array($user_count, max($user_count));
- #echo_array($csv);
- ?>
- <table>
- <tr>
- <th>Row</th>
- <?foreach($printers as $printer) echo '<th>'.$printer.'</th>'?>
- </tr>
- <?
- foreach($csv as $row => $values)
- {
- echo '<tr>';
- echo '<td>'.$row.'</td>';
- foreach($values as $val) echo '<td>'.$val.'</td>';
- echo '</tr>';
- }
- ?>
- </table>
- <?
- $fp = fopen('./printers_list.csv', 'w');
- fputcsv($fp, $printers,';');
- foreach ($csv as $fields) {
- fputcsv($fp, $fields,';');
- }
- fclose($fp);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement