234cc9459d13b5871f03b2df32735d9ce069d0ba
[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("adddir"):
49       addDir($item,$mpd);
50       break;
51       
52
53     case("moveup"):
54        if($item !=0) {
55            $mpd->Move($item,$item-1);
56        }
57        break;
58
59     case("movedown"):
60        if($item !=count($mpd->playlist)-1) {
61            $mpd->Move($item,$item+1);
62        }
63        break;
64
65
66      case("removeselected"):
67         $items=$_POST['itemlist'];
68         for($i=0;$i<count($items);$i++){
69           $mpd->PLRemove($items[$i]-$i);
70         }
71         break;
72
73
74         case("addselected"):
75                 $items=$_POST['itemlist'];
76                 $dir=$_REQUEST['dir'];
77                 $files = $mpd->GetDir($dir);
78                 for($i=0;$i<count($items);$i++) {
79                         if($files[$items[$i]]['type']=="directory") {
80                                 addDir($files[$items[$i]]['name'],$mpd);
81                         } else {
82                                 $mpd->PLAdd($files[$items[$i]]['name']);
83                         }
84                 }
85                 break;
86
87         case("addall"):
88                 $dir=$_REQUEST['item'];
89                 $files = $mpd->GetDir($dir);
90                 for($i=0;$i<count($files);$i++) {
91                         if($files[$i]['type']=="directory") {
92                                 addDir($files[$i]['name'],$mpd);
93                         } else {
94                                 $mpd->PLAdd($files[$i]['name']);
95                         }
96                 }
97                 break;
98
99
100
101 }
102
103
104 ?>