Удаление списков.
[mpd-web.git] / model / tracklist.php
1 <?php
2
3 function addDir($item,$mpd) {
4         $opendirs[] = $item;
5         $count=0;
6         while($count != count($opendirs)){
7                 $current = $opendirs[$count];
8                 $count++;
9
10                 $files = $mpd->GetDir($current);
11                 for($i=0;$i<count($files);$i++) {
12                         if($files[$i]['type']=="directory") {
13                                 $opendirs[]=$files[$i]['name'];
14                         } else {
15                                 $mpd->PLAdd($files[$i]['name']);
16                         }
17
18                 }
19         }       
20 }
21
22 switch($task) {
23
24   case("remove"):
25     if($item != null)
26       $mpd->PLRemove($item);
27     break;
28
29
30    case("clear"):
31      $mpd->PLClear();
32      break;
33
34    case("playitem"):
35      if($item != null){
36        $mpd->SkipTo($item);
37       }
38       break;
39
40    case("addfile"):
41       $mpd->PLAdd($item);
42       break;
43
44    case("load"):
45       $mpd->PLLoad($item);
46       break;
47
48    case("dellist"):
49       $mpd->PLDel($item);
50       break;
51
52    case("adddir"):
53       addDir($item,$mpd);
54       break;
55       
56
57     case("moveup"):
58        if($item !=0) {
59            $mpd->Move($item,$item-1);
60        }
61        break;
62
63     case("movedown"):
64        if($item !=count($mpd->playlist)-1) {
65            $mpd->Move($item,$item+1);
66        }
67        break;
68
69
70      case("removeselected"):
71         $items=$_POST['itemlist'];
72         for($i=0;$i<count($items);$i++){
73           $mpd->PLRemove($items[$i]-$i);
74         }
75         break;
76
77
78         case("addselected"):
79                 $items=$_POST['itemlist'];
80                 $dir=$_REQUEST['dir'];
81                 $files = $mpd->GetDir($dir);
82                 for($i=0;$i<count($items);$i++) {
83                         if($files[$items[$i]]['type']=="directory") {
84                                 addDir($files[$items[$i]]['name'],$mpd);
85                         } else {
86                                 $mpd->PLAdd($files[$items[$i]]['name']);
87                         }
88                 }
89                 break;
90
91         case("addall"):
92                 $dir=$_REQUEST['item'];
93                 $files = $mpd->GetDir($dir);
94                 for($i=0;$i<count($files);$i++) {
95                         if($files[$i]['type']=="directory") {
96                                 addDir($files[$i]['name'],$mpd);
97                         } else {
98                                 $mpd->PLAdd($files[$i]['name']);
99                         }
100                 }
101                 break;
102
103
104
105 }
106
107
108 ?>