From 442c156458f9fff7aad617acfc756dac3680f06f Mon Sep 17 00:00:00 2001
From: Martin Konecny <martin.konecny@gmail.com>
Date: Wed, 22 Aug 2012 16:08:51 -0400
Subject: [PATCH] CC-1665: Scheduled stream rebroadcasting and recording

-fixed context menu for webstreams
---
 .../application/controllers/LibraryController.php        | 9 +++++----
 .../application/controllers/WebstreamController.php      | 6 ++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php
index c29904974..e647f4b30 100644
--- a/airtime_mvc/application/controllers/LibraryController.php
+++ b/airtime_mvc/application/controllers/LibraryController.php
@@ -160,16 +160,17 @@ class LibraryController extends Zend_Controller_Action
 
         $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
 
+        $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
+
         if ($type === "audioclip") {
 
             $file = Application_Model_StoredFile::Recall($id);
 
-            $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
             if (isset($obj_sess->id) && $screen == "playlist") {
                 // if the user is not admin or pm, check the creator and see if this person owns the playlist or Block
                 if ($obj_sess->type == 'playlist') {
                     $obj = new Application_Model_Playlist($obj_sess->id);
-                } else {
+                } else if ($obj_sess->type == 'block') {
                     $obj = new Application_Model_Block($obj_sess->id);
                 }
                 if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
@@ -187,10 +188,10 @@ class LibraryController extends Zend_Controller_Action
 
             $url = $file->getRelativeFileUrl($baseUrl).'/download/true';
             $menu["download"] = array("name" => "Download", "icon" => "download", "url" => $url);
-        } elseif ($type === "playlist" || $type === "block") {
+        } else if ($type === "playlist" || $type === "block") {
             if ($type === 'playlist') {
                 $obj = new Application_Model_Playlist($id);
-            } else {
+            } else if ($type === 'block') {
                 $obj = new Application_Model_Block($id);
                 if (!$obj->isStatic()) {
                     unset($menu["play"]);
diff --git a/airtime_mvc/application/controllers/WebstreamController.php b/airtime_mvc/application/controllers/WebstreamController.php
index 10944aa7b..670fc859a 100644
--- a/airtime_mvc/application/controllers/WebstreamController.php
+++ b/airtime_mvc/application/controllers/WebstreamController.php
@@ -46,6 +46,8 @@ class WebstreamController extends Zend_Controller_Action
         $type = "stream";
         Application_Model_Library::changePlaylist($obj->getId(), $type);
         */
+        //clear the session in case an old playlist was open: CC-4196
+        Application_Model_Library::changePlaylist(null, null);
 
         $this->view->obj = new Application_Model_Webstream($webstream);
         $this->view->action = "new";
@@ -61,7 +63,11 @@ class WebstreamController extends Zend_Controller_Action
             throw new Exception("Missing parameter 'id'"); 
         }
 
+
         $webstream = CcWebstreamQuery::create()->findPK($id);
+        if ($webstream) {
+            Application_Model_Library::changePlaylist($id, "stream");
+        }
         $this->view->obj = new Application_Model_Webstream($webstream);
         $this->view->action = "edit";
         $this->view->html = $this->view->render('webstream/webstream.phtml');