~bentokitdevs/retromod/playlist

« back to all changes in this revision

Viewing changes to edit.php

  • Committer: ken
  • Date: 2010-04-24 07:20:54 UTC
  • Revision ID: svn-v4:8010c1e9-5c09-0410-80af-c3f6856d18d6:branches/playlist:1732
Created new branch for playlist component. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
 
 
4
 
 
5
include_once('db.php'); 
 
6
include_once('datecontrol.php'); 
 
7
 
 
8
$moduleID = globalize('moduleID');
 
9
$modulecategory = globalize('modulecategory');
 
10
$module_script = globalize('module_script');
 
11
 
 
12
$action = globalize('action');
 
13
$programID = globalize('programID');
 
14
$gridID = globalize('gridID');
 
15
$date = globalize('date');
 
16
$playlistID = globalize('playlistID');
 
17
$startTime = globalize('startTime');
 
18
$endTime = globalize('endTime');
 
19
 
 
20
$page = new page();
 
21
$page->header(); 
 
22
 
 
23
$dbh = sysdb::open();
 
24
 
 
25
$store = new playlistsStorage();
 
26
 
 
27
echo '<div class="float_left">';
 
28
echo '<h1>Edit Playlist</h1>';
 
29
 
 
30
if ($action != '') {
 
31
        switch($action) {
 
32
                case 'reorder':
 
33
                        reprioritizeItems(globalize('itemID'), globalize('shift_value'));
 
34
                        break;
 
35
                case 'remove':
 
36
                        removeItem(globalize('itemID'));
 
37
                        break;
 
38
        }
 
39
}
 
40
 
 
41
 
 
42
// Check for musiclibrary component dependency.
 
43
if (file_exists(ROOT_COMPONENTS.'musiclibrary/moduleconfig.php')) {
 
44
        require_once(ROOT_COMPONENTS.'musiclibrary/moduleconfig.php');
 
45
        $remoteStore = new musicStorage();
 
46
        require_once(ROOT_COMPONENTS.'musiclibrary/TrackD.php');
 
47
        $trackObj = new TrackD();
 
48
        
 
49
        
 
50
    $artist = globalize('artist');
 
51
    $track = globalize('track');
 
52
        
 
53
        if ($track != '') {
 
54
                // Add track to playlist.
 
55
                
 
56
                if ($playlistID == '') {
 
57
                        // Fetch the playlistID.
 
58
                        $query = <<<EOQ
 
59
                                SELECT {$store->field_playlists_playlist_playlistID} AS playlistID
 
60
                                FROM {$store->table_playlists_playlist}
 
61
                                WHERE {$store->field_playlists_playlist_date} = '$date'
 
62
                                AND {$store->field_playlists_playlist_gridID} = '$gridID'
 
63
EOQ;
 
64
                        $result = sysdb::query($query);
 
65
                        if (sysdb::num_rows($result) <= 0) {
 
66
                                // Create one.
 
67
                                $query = "INSERT INTO {$store->table_playlists_playlist} (gridID, date) VALUES ('$gridID', '$date')";
 
68
                                sysdb::query($query);
 
69
 
 
70
                                // Fetch the newly inserted playlistID.
 
71
                                $query = <<<EOQ
 
72
                                        SELECT {$store->field_playlists_playlist_playlistID} AS playlistID
 
73
                                        FROM {$store->table_playlists_playlist}
 
74
                                        WHERE {$store->field_playlists_playlist_date} = '$date'
 
75
                                        AND {$store->field_playlists_playlist_gridID} = '$gridID'
 
76
EOQ;
 
77
                                $result = sysdb::query($query);
 
78
                        }
 
79
                        $line = sysdb::fetch_assoc($result);
 
80
                        $playlistID = $line['playlistID'];
 
81
                }
 
82
                // Add playlist item to storage.
 
83
                $query = <<<EOQ
 
84
                        SELECT COALESCE(MAX({$store->field_playlists_item_priority}),0) + 1
 
85
                        FROM {$store->table_playlists_item}
 
86
                        WHERE {$store->field_playlists_item_playlistID} = '$playlistID'
 
87
EOQ;
 
88
                $priority = sysdb::queryOne($query);
 
89
 
 
90
                $query = <<<EOQ
 
91
                        INSERT INTO {$store->table_playlists_item} (
 
92
                                playlistID, 
 
93
                                id, 
 
94
                                type, 
 
95
                                priority
 
96
                        ) VALUES (
 
97
                                '$playlistID',
 
98
                                '$track',
 
99
                                'track',
 
100
                                '$priority'
 
101
                        )
 
102
EOQ;
 
103
                sysdb::query($query);
 
104
 
 
105
                $artist = '';
 
106
                $track = '';
 
107
        }
 
108
 
 
109
        echo '<h2>';
 
110
        module::link_to_script('Back to Program','playlists.php',array('editProgramID'=>$programID),true,true,'Down');
 
111
        echo '</h2>';
 
112
        
 
113
        echo '<h2>Add Track</h2>';
 
114
        echo '<form action="'.module::form_action().'" method="post">';
 
115
        echo module::form_attributes();
 
116
        if ($playlistID != '')
 
117
                echo '<input type="hidden" name="playlistID" value="'.$playlistID.'" />';
 
118
        if ($programID != '')
 
119
                echo '<input type="hidden" name="programID" value="'.$programID.'" />';
 
120
        if ($date != '')
 
121
                echo '<input type="hidden" name="date" value="'.$date.'" />';
 
122
        if ($gridID != '')
 
123
                echo '<input type="hidden" name="gridID" value="'.$gridID.'" />';
 
124
        if ($startTime != '')
 
125
                echo '<input type="hidden" name="startTime" value="'.$startTime.'" />';
 
126
        if ($endTime != '')
 
127
                echo '<input type="hidden" name="endTime" value="'.$endTime.'" />';
 
128
        echo '<select name="artist" onChange="this.form.submit();">';
 
129
        echo '<option value="">Select Artist</option>';
 
130
        $query = "SELECT $remoteStore->field_ganges_artist_id AS artistId, $remoteStore->field_ganges_artist_name AS artistName FROM $remoteStore->table_ganges_artist ";
 
131
        $artistresult = sysdb::query($query);
 
132
        while ($artistline = sysdb::fetch_assoc($artistresult)) {
 
133
                echo '<option value="'.$artistline['artistId'].'"';
 
134
                if ($artist == $artistline['artistId']) echo ' selected="selected"';
 
135
                echo '>'.$artistline['artistName'].'</option>';
 
136
        }
 
137
        echo '</select>';    
 
138
        if ($artist != '') {
 
139
                $query = "SELECT $remoteStore->field_ganges_track_id AS trackId, $remoteStore->field_ganges_track_name AS trackName FROM $remoteStore->table_ganges_track WHERE $remoteStore->field_ganges_track_artist = '$artist' ORDER BY trackName";
 
140
                $trackresult = sysdb::query($query);
 
141
                echo '<select name="track" onChange="this.form.submit();">';
 
142
                echo '<option value="">Select Track</option>';
 
143
                if (sysdb::num_rows($trackresult) > 0) {
 
144
                        while ($trackline = sysdb::fetch_assoc($trackresult)) {
 
145
                                echo '<option value="'.$trackline['trackId'].'">'.$trackline['trackName'].'</option>';
 
146
                        }
 
147
                }
 
148
                echo '</select>';    
 
149
        }
 
150
        echo '</form>'; 
 
151
}
 
152
 
 
153
if ($date != '') {
 
154
        // Collect the playlist information.
 
155
        $query = "SELECT * FROM $store->table_playlists_playlist WHERE date = '$date' AND gridID = '$gridID'";
 
156
        $result = sysdb::query($query);
 
157
        if (sysdb::num_rows($result) <= 0) {
 
158
                $playlistID = '';
 
159
                $query = "SELECT * FROM $store->table_playlists_playlist WHERE 1=0";
 
160
                $tresult = sysdb::query($query);
 
161
        } else {
 
162
                $line = sysdb::fetch_assoc($result);
 
163
                $playlistID = $line['playlistID'];
 
164
                
 
165
                $tquery = <<<EOQ
 
166
                        SELECT I.*
 
167
                        FROM ($store->table_playlists_item I, 
 
168
                                $store->table_playlists_playlist P)
 
169
                        WHERE P.playlistID = I.playlistID
 
170
                        AND P.playlistID = '$playlistID'
 
171
                        ORDER BY priority
 
172
EOQ;
 
173
                $tresult = sysdb::query($tquery);
 
174
        }
 
175
 
 
176
}
 
177
echo '<form action="'.module::form_action().'" method="POST">';
 
178
echo module::form_attributes();
 
179
if ($playlistID != '')
 
180
        echo '<input type="hidden" name="playlistID" value="'.$playlistID.'" />';
 
181
if ($programID != '')
 
182
        echo '<input type="hidden" name="programID" value="'.$programID.'" />';
 
183
if ($date != '')
 
184
        echo '<input type="hidden" name="date" value="'.$date.'" />';
 
185
if ($gridID != '')
 
186
        echo '<input type="hidden" name="gridID" value="'.$gridID.'" />';
 
187
if ($startTime != '')
 
188
        echo '<input type="hidden" name="startTime" value="'.$startTime.'" />';
 
189
if ($endTime != '')
 
190
        echo '<input type="hidden" name="endTime" value="'.$endTime.'" />';
 
191
echo '<h2>Playlist Details</h2>';
 
192
echo '<table class="modulebox">';
 
193
echo '<tr>';
 
194
echo '<th>Artist</th>';
 
195
echo '<th>Track</th>';
 
196
echo '<th>Duration</th>';
 
197
echo '<th>Running</th>';
 
198
echo '<th>Priority</th>';
 
199
echo '<th></th>';
 
200
echo '</tr>';
 
201
 
 
202
$runtime = strtotime($startTime);
 
203
 
 
204
echo '<tr class="greyed">';
 
205
echo "<td></td>";
 
206
echo "<td></td>";
 
207
echo "<td></td>";
 
208
echo '<td>'.date("H:i:s", strtotime($startTime)).'</td>';
 
209
echo "<td></td>";
 
210
echo "<td></td>";
 
211
echo '</tr>'."\n";
 
212
                        
 
213
if ( sysdb::num_rows($tresult) > 0) {
 
214
        while ($tline = sysdb::fetch_assoc($tresult)) {
 
215
                if ($tline['type'] == 'track') {
 
216
                        $query = <<<EOQ
 
217
                                SELECT T.$remoteStore->field_ganges_track_name AS trackName,
 
218
                                        A.$remoteStore->field_ganges_artist_name AS artistName,
 
219
                                        T.$remoteStore->field_ganges_track_length
 
220
                                FROM ($remoteStore->table_ganges_track T, 
 
221
                                        $remoteStore->table_ganges_artist A
 
222
                                )
 
223
                                WHERE T.$remoteStore->field_ganges_track_id = '{$tline['id']}'
 
224
                                AND T.$remoteStore->field_ganges_track_audio_artist = A.$remoteStore->field_ganges_artist_id
 
225
EOQ;
 
226
                        $result = sysdb::query($query);
 
227
                        $line = sysdb::fetch_assoc($result);
 
228
                        
 
229
                        echo '<tr>';
 
230
                        echo "<td>".$line['artistName']."</td>";
 
231
                        echo "<td>".$line['trackName']."</td>";
 
232
                        $duration = date("i:s", round($line['length'] / 1000, 0));
 
233
                        echo "<td>".$duration."</td>";
 
234
                        $runtime = $runtime + ($line['length'] / 1000);
 
235
                        echo "<td>".date("H:i:s", $runtime)."</td>";
 
236
                        echo '<td>';
 
237
                        echo '<span class="link_up_small">';
 
238
                        module::link_to_script('Up','edit.php',array(
 
239
                                'action'=>'reorder',
 
240
                                'gridID'=>$gridID,
 
241
                                'programID'=>$programID,
 
242
                                'date'=>$date,
 
243
                                'startTime'=>$startTime,
 
244
                                'endTime'=>$endTime,
 
245
                                'itemID'=>$tline['itemID'],
 
246
                                'shift_value'=>'-1'
 
247
                                ),true,true,'Up');
 
248
                        echo '</span>';
 
249
                        echo '<span class="link_down_small">';
 
250
                        module::link_to_script('Down','edit.php',array(
 
251
                                'action'=>'reorder',
 
252
                                'gridID'=>$gridID,
 
253
                                'programID'=>$programID,
 
254
                                'date'=>$date,
 
255
                                'startTime'=>$startTime,
 
256
                                'endTime'=>$endTime,
 
257
                                'itemID'=>$tline['itemID'],
 
258
                                'shift_value'=>'1'
 
259
                                ),true,true,'Down');
 
260
                        echo '</span>';
 
261
                        echo '</td>';
 
262
//                      echo '<td>'.$tline['priority'].'</td>';
 
263
                        // echo '<td>'.$tline['type'].'</td>';
 
264
                        // echo '<td>'.$tline['id'].'</td>';
 
265
                        echo '<td>';
 
266
                        echo '<span class="link_delete_small">';
 
267
                        module::link_to_script('Remove','edit.php',array(
 
268
                                'action'=>'remove',
 
269
                                'itemID'=>$tline['itemID']
 
270
                                ),true,true,'Remove');
 
271
                        echo '</span>';
 
272
                        echo '</td>';
 
273
                        echo '</tr>'."\n";
 
274
                }
 
275
        }
 
276
} else {
 
277
        echo '<tr>';
 
278
        echo '<td colspan="6">No tracks in playlist yet.</td>';
 
279
        echo '</tr>'."\n";
 
280
}
 
281
 
 
282
echo '<tr class="greyed">';
 
283
echo "<td></td>";
 
284
echo "<td></td>";
 
285
echo "<td></td>";
 
286
echo '<td>'.date("H:i:s", strtotime($endTime)).'</td>';
 
287
echo "<td></td>";
 
288
echo "<td></td>";
 
289
echo '</tr>'."\n";
 
290
                        
 
291
echo '</table>'."\n";
 
292
 
 
293
?>
 
294
<!--
 
295
<table width="100%">
 
296
  <tr>
 
297
    <?php //if ($programID != '') { ?>
 
298
      <td align="left">
 
299
        <input name="action" type="submit" value="save" />
 
300
      </td>
 
301
      <td align="right">
 
302
        <input name="action" type="submit" value="delete" />
 
303
      </td>
 
304
    <?php //} ?>
 
305
    <?php //if ($action == '' && $programID == '') { ?>
 
306
      <td align="left">
 
307
        <input name="action" type="submit" value="create" />
 
308
      </td>
 
309
      <td align="right">
 
310
        &nbsp;
 
311
      </td>
 
312
    <?php //} ?>
 
313
</table>
 
314
-->
 
315
 
 
316
<?php
 
317
echo '</div>';
 
318
echo '</form>';
 
319
sysdb::close($dbh); 
 
320
$page->footer(); 
 
321
?>
 
 
b'\\ No newline at end of file'