Подтверждение удаления и прочие визуальные доработки.
[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("adddir"):
45       addDir($item,$mpd);
46       break;
47       
48
49     case("moveup"):
50        if($item !=0) {
51            $mpd->Move($item,$item-1);
52        }
53        break;
54
55     case("movedown"):
56        if($item !=count($mpd->playlist)-1) {
57            $mpd->Move($item,$item+1);
58        }
59        break;
60
61
62      case("removeselected"):
63         $items=$_POST['itemlist'];
64         for($i=0;$i<count($items);$i++){
65           $mpd->PLRemove($items[$i]-$i);
66         }
67         break;
68
69
70         case("addselected"):
71                 $items=$_POST['itemlist'];
72                 $dir=$_REQUEST['dir'];
73                 $files = $mpd->GetDir($dir);
74                 for($i=0;$i<count($items);$i++) {
75                         if($files[$items[$i]]['type']=="directory") {
76                                 addDir($files[$items[$i]]['name'],$mpd);
77                         } else {
78                                 $mpd->PLAdd($files[$items[$i]]['name']);
79                         }
80                 }
81                 break;
82
83         case("addall"):
84                 $dir=$_REQUEST['item'];
85                 $files = $mpd->GetDir($dir);
86                 for($i=0;$i<count($files);$i++) {
87                         if($files[$i]['type']=="directory") {
88                                 addDir($files[$i]['name'],$mpd);
89                         } else {
90                                 $mpd->PLAdd($files[$i]['name']);
91                         }
92                 }
93                 break;
94
95
96
97 }
98
99
100 ?>