protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     //Sue playing now/next
     $query = "SELECT audio.title AS title, audio.id AS id \n\t\t\tFROM sustschedule, audio \n\t\t\tWHERE sustschedule.audioid = audio.id \n\t\t\tORDER BY sustschedule.id asc";
     $suePlaylist = $db->getAll($query);
     foreach ($suePlaylist as $key => &$track) {
         $sql = "SELECT DISTINCT artists.name AS name \n\t\t\t\tFROM artists, audioartists \n\t\t\t\tWHERE audioartists.audioid = " . $track['id'] . " \n\t\t\t\t\tAND audioartists.artistid = artists.id";
         $artists = $db->getAll($sql);
         foreach ($artists as $artist) {
             $track['artist'] = $track['artist'] . $artist['name'] . " & ";
         }
         $track['artist'] = rtrim($track['artist'], " & ");
     }
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('Access_ViewSue', AuthUtil::getDetailedUserrealmAccess(array(58, 60, 3), $userID));
     $this->assign('Access_EditSue', AuthUtil::getDetailedUserrealmAccess(array(58, 60, 66), $userID));
     $this->assign('Access_SueStats', AuthUtil::getDetailedUserrealmAccess(array(58, 60, 2), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('storedTracks', $systemTracks);
     $this->assign('sueLastTrack', $suePlaylist[0]);
     $this->assign('sueNextTrack', $suePlaylist[1]);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $trackIDs = explode(";", $this->fieldData['trackID']);
     $tracksDetails = array();
     foreach ($trackIDs as $trackID) {
         $sql = "SELECT audio.*, albums.name AS album \n\t\t\tFROM audio, albums \n\t\t\tWHERE audio.music_album = albums.id \n\t\t\t\tAND audio.id = " . pg_escape_string($trackID);
         $trackDetails = $db->getRow($sql);
         $sql = "SELECT DISTINCT artists.name AS name \n\t\t\tFROM artists, audioartists \n\t\t\tWHERE audioartists.audioid = " . pg_escape_string($trackID) . " \n\t\t\t\tAND audioartists.artistid = artists.id";
         $trackDetails['artist'] = $db->getColumn($sql);
         $sql = "SELECT DISTINCT keywords.name AS name \n\t\t\tFROM keywords, audiokeywords \n\t\t\tWHERE audiokeywords.audioid = " . pg_escape_string($trackID) . " \n\t\t\t\tAND audiokeywords.keywordid = keywords.id";
         $trackDetails['keywords'] = $db->getColumn($sql);
         $samples = $trackDetails['length_smpl'];
         $trackDetails['length'] = $tracksLen = round($samples / 44100 / 60) . "mins " . $samples / 44100 % 60 . "secs.";
         $sql = "SELECT * FROM audiocomments \n\t\t\tWHERE audioid = " . pg_escape_string($trackID) . " \n\t\t\tORDER BY creationdate ASC";
         $trackDetails['comments'] = $db->getAll($sql);
         foreach ($trackDetails['comments'] as &$comment) {
             $comment['username'] = AuthUtil::getUsername($comment['userid']);
             $comment['comment'] = str_replace("\n", "<br>", $comment['comment']);
             $comment['ctime'] = substr($comment['creationdate'], 0, 10);
         }
         $tracksDetails[] = $trackDetails;
     }
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('RequestTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 29), $userID));
     $this->assign('Access_CommentTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 34), $userID));
     $this->assign('Access_EditTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 27), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('tracksDetails', $tracksDetails);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $scriptID = pg_escape_string($this->fieldData['scriptID']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $date = time();
     if (is_numeric($scriptID)) {
         $script_query = "SELECT bit_or(permissions) \n\t\t\t\tFROM v_tree_script\n\t\t\t\tWHERE id = {$scriptID}\n\t\t\t\t\tAND userid = {$userID}";
         $checkScripts = $db->getOne($script_query);
         if (substr($checkScripts, 0, 1) == "1") {
             if (substr($checkScripts, 1, 1) == "1") {
                 $this->assign('write', 't');
             } else {
                 $this->assign('write', 'f');
             }
             $script_sql = "SELECT * FROM scripts WHERE id = " . $scriptID;
             $script = $db->getRow($script_sql);
             $script['m'] = (int) ($script['length'] / 60);
             $script['s'] = $script['length'] - $script['m'] * 60;
             $script['niceProducer'] = AuthUtil::getUsername($script['creator']);
             $this->assign('script', $script);
         } else {
             $this->assign('error', 'You do not have permission to edit that script.');
         }
     } else {
         $this->assign('error', 'Invalid Show ID supplied');
     }
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $audioID = pg_escape_string($this->fieldData['audioID']);
     $sql = "SELECT jinglepkgid FROM audiojinglepkgs WHERE audioid = {$audioID}";
     $jinglepkgID = $db->getOne($sql);
     $sql = "SELECT name FROM jinglepkgs WHERE id = {$jinglepkgID}";
     $currentpkg = $db->getOne($sql);
     if ($currentpkg == '') {
         $currentpkg = 'Default';
     }
     $sql = "SELECT title FROM audio WHERE id = {$audioID}";
     $jinglename = $db->getOne($sql);
     $sql = "SELECT name, id FROM jinglepkgs";
     $jinglepkgs = $db->getAll($sql);
     $this->assign('access_playlist', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 33), $userID));
     $this->assign('access_sue', AuthUtil::getDetailedUserrealmAccess(array(24, 20, 3), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('jinglepkgs', $jinglepkgs);
     $this->assign('currentpkg', $currentpkg);
     $this->assign('currentpkgid', $jinglepkgID);
     $this->assign('jinglename', $jinglename);
     $this->assign('jingleID', $audioID);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $loc = 1;
     $sql = "SELECT v_tree_aw_sets.*, aw_sets_users.user_id AS userid\n                from v_tree_aw_sets LEFT OUTER JOIN aw_sets_users\n                ON aw_sets_users.set_id = v_tree_aw_sets.id\n\t\t\tWHERE v_tree_aw_sets.userid = " . $cfg['DPS']['systemUserID'] . " \n\t\t\t\tAND v_tree_aw_sets.permissions & B'" . $cfg['DPS']['fileR'] . "' = '" . $cfg['DPS']['fileR'] . "'";
     // station awsets
     $awsets = $db->getAll($sql);
     $sql = "SELECT val FROM configuration \n\t\t\tWHERE location = {$loc} \n\t\t\t\tAND parameter = 'station_aw_set'";
     $userset = $db->getOne($sql);
     foreach ($awsets as &$awset) {
         if ($userset == $awset['id']) {
             $awset['active'] = 't';
         } else {
             $awset['active'] = 'f';
         }
         $sql = "SELECT BIT_OR(permissions) \n\t\t\t\tFROM v_tree_dir \n\t\t\t\tWHERE v_tree_dir.id = {$awset['parent']}\n\t\t\t\t\tAND v_tree_dir.userid = {$cfg['DPS']['systemUserID']}";
         $awset['parentperm'] = $db->getOne($sql);
         $awset['userid'] = AuthUtil::getUsername($awset['userid']);
     }
     $this->assign('access_playlist', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 33), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('awsets', $awsets);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $count_query = "SELECT count(*) FROM requests";
     $requestedNum = $db->getOne($count_query);
     $query = "SELECT * FROM requests ORDER BY date DESC";
     $requestedResult = $db->getAll($query);
     $i = 0;
     foreach ($requestedResult as $key => &$track) {
         $track['number'] = $i;
         $track['rtime'] = date("m/d/y", $track['date']);
         $track['user'] = AuthUtil::getUsername($track['userid']);
         $i++;
     }
     $trackCount = $i;
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('CensorTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 30), $userID));
     $this->assign('RequestTrack', 't');
     $this->assign('RemoveRequestTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 29), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('requestedTracks', $requestedResult);
     $this->assign('requestedNum', $requestedNum);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $offset = $this->fieldData['dpsSearchPage'];
     if ($offset == "") {
         $offset = 0;
     } else {
         $offset--;
     }
     $searchValue = trim($this->fieldData['dpsSearchVal']);
     $searchType = $this->fieldData['dpsSearchType'];
     $letter = pg_escape_string($this->fieldData['dpsSearchLetter']);
     if ($searchType == '' && $letter != '') {
         if ($letter == "*") {
             $searchType = 'Number';
         } else {
             $searchType = 'Letter';
         }
     }
     if ($this->fieldData['dpsSortType'] != '') {
         $sesh = Session::getInstance();
         $sortType = $this->fieldData['dpsSortType'];
         $sesh->setValue("dpsSortType", $sortType);
     } else {
         $sesh = Session::getInstance();
         if ($sesh->keyExists("dpsSortType")) {
             $sortType = $sesh->getValue("dpsSortType");
         } else {
             $sortType = "title";
         }
     }
     if ($searchValue != '') {
         $searchResult = DPS::searchAudio($searchValue, $searchType, $sortType, $offset, '');
         $rNum = DPS::searchPageAudio($searchValue, $searchType, '');
         $searchInfo = "Found {$rNum} results matching your query";
     }
     $pages = ceil($rNum / $cfg['DPS']['resultLimit']);
     //fill the $pageArray array with values from 1 to $pages
     $pageArray = range(1, $pages);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('RequestTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 29), $userID));
     $this->assign('CensorTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 30), $userID));
     $this->assign('ReportTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 43), $userID));
     $this->assign('EditTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 27), $userID));
     $this->assign('DeleteTrack', AuthUtil::getDetailedUserrealmAccess(array(2, 21, 32), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('page', $offset);
     $this->assign('searchResult', $searchResult);
     $this->assign('searchInfo', $searchInfo);
     $this->assign('pages', $pageArray);
     $this->assign('searchType', $searchType);
     $this->assign('searchValue', $searchValue);
     $this->assign('sortType', $sortType);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('treeType', 'jacspmr');
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('RequestTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 29), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
 }
 protected function processValid()
 {
     global $cfg;
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     if ($this->formName == "dpsStationUpdateJinglePkgForm") {
         $jinglepkgID = pg_escape_string($this->fieldData['jinglepkgID']);
         if (is_numeric($jinglepkgID) && $jinglepkgID != "" && $jinglepkgID != "*") {
             if ($this->fieldData['name'] != '') {
                 $pkgUpdates['name'] = $this->fieldData['name'];
             }
             if ($this->fieldData['description'] != '') {
                 $pkgUpdates['description'] = $this->fieldData['description'];
             }
             if (AuthUtil::getDetailedUserrealmAccess(array(24, 20, 3), $userID)) {
                 if ($this->fieldData['enabled'] == "on") {
                     $pkgUpdates['enabled'] = 't';
                 } else {
                     $pkgUpdates['enabled'] = 'f';
                 }
             }
             $atWhere = "jinglepkgs.id = " . $jinglepkgID;
             $db->update('jinglepkgs', $pkgUpdates, $atWhere, true);
         }
     } elseif ($this->formName == "dpsStationRemJingleFromPkgForm") {
         $jingleID = pg_escape_string($this->fieldData['jingleID']);
         $jinglepkgID = pg_escape_string($this->fieldData['jinglepkgID']);
         if (AuthUtil::getDetailedUserrealmAccess(array(35, 22, 3), $userID)) {
             $sql = "SELECT id FROM audiojinglepkgs WHERE audioid = {$jingleID} AND jinglepkgid = {$jinglepkgID}";
             $rowID = $db->getOne($sql);
             if ($rowID != 0) {
                 $Where = "id = {$rowID}";
                 $db->delete('audiojinglepkgs', $Where, true);
             }
             $sql = "SELECT COUNT(*) from audiojinglepkgs WHERE jinglepkgid = {$jinglepkgID}";
             $remainingjingles = $db->getOne($sql);
             if ($remainingjingles == 0) {
                 $Where = "id = " . $jinglepkgID;
                 $db->delete('jinglepkgs', $Where, true);
             }
             $sql = "SELECT COUNT(*) from audiojinglepkgs WHERE audioid = {$jingleID}";
             $remainingpkgs = $db->getOne($sql);
             if ($remainingpkgs == 0) {
                 $sql = "SELECT id FROM jinglepkgs WHERE name = ''";
                 $defaultid = $db->getOne($sql);
                 $newpkg['audioid'] = $jingleID;
                 $newpkg['jinglepkgid'] = $defaultid;
                 $newpkg['jingletypeid'] = 1;
                 $db->insert('audiojinglepkgs', $newpkg, true);
             }
         }
     }
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $trackID = $this->fieldData['trackID'];
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     //As there is no general audio view
     $sql = "SELECT count(*) FROM v_tree_jingle \n\t\t\tWHERE id = " . pg_escape_string($trackID) . " \n\t\t\t\tAND userid = " . $userID . " \n\t\t\t\tAND permissions & B'" . $cfg['DPS']['fileW'] . "' = '" . $cfg['DPS']['fileW'] . "'";
     $check = $db->getOne($sql);
     $sql = "SELECT count(*) FROM v_tree_advert \n\t\t\tWHERE id = " . pg_escape_string($trackID) . " \n\t\t\t\tAND userid = " . $userID . " \n\t\t\t\tAND permissions & B'" . $cfg['DPS']['fileW'] . "' = '" . $cfg['DPS']['fileW'] . "'";
     $check = $check + $db->getOne($sql);
     $sql = "SELECT count(*) FROM v_tree_prerec \n\t\t\tWHERE id = " . pg_escape_string($trackID) . " \n\t\t\t\tAND userid = " . $userID . " \n\t\t\t\tAND permissions & B'" . $cfg['DPS']['fileW'] . "' = '" . $cfg['DPS']['fileW'] . "'";
     $check = $check + $db->getOne($sql);
     if ($check < 1) {
         $this->assign('authError', 't');
     } else {
         $sql = "SELECT audio.* FROM audio \n\t\t\t\tWHERE audio.id = " . pg_escape_string($trackID);
         $trackDetails = $db->getRow($sql);
         $sql = "SELECT DISTINCT artists.name AS name, artists.id AS id \n\t\t\t\tFROM artists, audioartists \n\t\t\t\tWHERE audioartists.audioid = " . pg_escape_string($trackID) . " \n\t\t\t\t\tAND audioartists.artistid = artists.id";
         $trackDetails['artist'] = $db->getAll($sql);
         $i = 0;
         foreach ($trackDetails['artist'] as &$artist) {
             $artist['number'] = $i;
             $i++;
         }
         $artistNum = $i;
         $sql = "SELECT DISTINCT keywords.name AS name, keywords.id AS id \n\t\t\t\tFROM keywords, audiokeywords \n\t\t\t\tWHERE audiokeywords.track = " . pg_escape_string($trackID) . " \n\t\t\t\t\tAND audiokeywords.keyword = keywords.id";
         $trackDetails['keywords'] = $db->getAll($sql);
         $i = 0;
         foreach ($trackDetails['keywords'] as &$keyword) {
             $keyword['number'] = $i;
             $i++;
         }
         $keywordNum = $i;
         $samples = $trackDetails['length_smpl'];
         $trackDetails['length'] = $tracksLen = floor($samples / 44100 / 60) . "mins " . $samples / 44100 % 60 . "secs.";
         $sql = "SELECT * from audiocomments \n\t\t\t\tWHERE audioid = " . pg_escape_string($trackID) . "\n\t\t\t\tORDER BY creationdate ASC";
         $trackDetails['comments'] = $db->getAll($sql);
         foreach ($trackDetails['comments'] as &$comment) {
             $comment['username'] = AuthUtil::getUsername($comment['userid']);
             $comment['comment'] = str_replace("\n", "<br>", $comment['comment']);
             $comment['ctime'] = substr($comment['creationdate'], 0, 10);
         }
         $this->assign('trackDetails', $trackDetails);
         $this->assign('keywordNum', $keywordNum);
         $this->assign('artistNum', $artistNum);
         $this->assign('trackID', $trackID);
     }
     $this->assign('access_playlist', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 33), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('studioAccess', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 34), $userID));
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     if ($userID == $cfg['Auth']['anonuserID']) {
         $this->assign('Guest', 't');
     } else {
         $this->assign('Guest', 'f');
     }
 }
 protected function processValid()
 {
     global $cfg;
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     if ($this->formName == "dpsStationMoveJingleForm") {
         $jingleID = pg_escape_string($this->fieldData['jingleID']);
         $jinglepkgID = pg_escape_string($this->fieldData['jinglepkgID']);
         if (AuthUtil::getDetailedUserrealmAccess(array(35, 22, 3), $userID)) {
             $sql = "SELECT jinglepkgid FROM audiojinglepkgs WHERE audioid = {$jingleID}";
             $oldjinglepkgID = $db->getOne($sql);
             if ($jinglepkgID == $oldjinglepkgID && $this->fieldData['newPackageName'] == '') {
                 return;
             }
             $sql = "SELECT id FROM audiojinglepkgs WHERE audioid = {$jingleID} AND jinglepkgid = {$oldjinglepkgID}";
             $rowID = $db->getOne($sql);
             if ($rowID != 0) {
                 $Where = "id = {$rowID}";
                 $db->delete('audiojinglepkgs', $Where, true);
             }
             $sql = "SELECT COUNT(*) from audiojinglepkgs WHERE jinglepkgid = {$oldjinglepkgID}";
             $remainingjingles = $db->getOne($sql);
             if ($remainingjingles == 0) {
                 $Where = "id = " . $oldjinglepkgID;
                 $db->delete('jinglepkgs', $Where, true);
             }
             if ($this->fieldData['newPackageName'] != '') {
                 $jinglePkgName = pg_escape_string($this->fieldData['newPackageName']);
                 $sql = "SELECT id FROM jinglepkgs WHERE name = '{$jinglePkgName}'";
                 $numRows = count($db->getAll($sql));
                 if ($numRows != 0) {
                     $jinglepkgID = $db->getOne($sql);
                 } else {
                     $newjinglepkg['name'] = $jinglePkgName;
                     $newjinglepkg['description'] = pg_escape_string($this->fieldData['newPackageDesc']);
                     $newjinglepkg['enabled'] = 'f';
                     $db->insert('jinglepkgs', $newjinglepkg, true);
                     $sql = "SELECT id FROM jinglepkgs WHERE name = '{$jinglePkgName}'";
                     $jinglepkgID = $db->getOne($sql);
                 }
             }
             $newpkg['audioid'] = $jingleID;
             $newpkg['jinglepkgid'] = $jinglepkgID;
             $newpkg['jingletypeid'] = 1;
             $db->insert('audiojinglepkgs', $newpkg, true);
         }
     }
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     //System Track count
     $query = "SELECT count(audio.id) FROM audio";
     $systemTracks = $db->getOne($query);
     //System Track length
     $query = "SELECT sum(audio.length_smpl) FROM audio";
     $systemSamps = $db->getOne($query);
     $days = floor($systemSamps / 44100 / 60 / 60 / 24);
     $hours = floor($systemSamps / 44100 / 60 / 60 - $days * 24);
     $mins = round($systemSamps / 44100 / 60 - $hours * 60 - $days * 24 * 60);
     $systemLength = $days . "days " . $hours . "h " . $mins . "m";
     //Sue Track count
     $query = "SELECT count(audio.id) FROM audio WHERE sustainer = 't'";
     $sueTracks = $db->getOne($query);
     //Sue Track length
     $query = "SELECT sum(audio.length_smpl) FROM audio WHERE sustainer = 't'";
     $sueSamps = $db->getOne($query);
     $days = floor($sueSamps / 44100 / 60 / 60 / 24);
     $hours = floor($sueSamps / 44100 / 60 / 60 - $days * 24);
     $mins = round($sueSamps / 44100 / 60 - $hours * 60 - $days * 24 * 60);
     $sueLength = $days . "days " . $hours . "h " . $mins . "m";
     //Sue playing now/next
     $query = "SELECT audio.title AS title, audio.id AS id \n\t\tFROM sustschedule, audio \n\t\tWHERE sustschedule.audioid = audio.id \n\t\tORDER BY sustschedule.id asc";
     $suePlaylist = $db->getAll($query);
     foreach ($suePlaylist as $key => &$track) {
         $sql = "SELECT DISTINCT artists.name as name \n\t\t\tFROM artists, audioartists \n\t\t\tWHERE audioartists.audioid = " . $track['id'] . " AND\n\t\t\t\taudioartists.artistid = artists.id";
         $artists = $db->getAll($sql);
         foreach ($artists as $artist) {
             $track['artist'] = $track['artist'] . $artist['name'] . " & ";
         }
         $track['artist'] = rtrim($track['artist'], " & ");
     }
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('Access_EditSue', AuthUtil::getDetailedUserrealmAccess(array(24, 20, 3), $userID));
     $this->assign('Access_ViewSue', AuthUtil::getDetailedUserrealmAccess(array(26, 20, 3), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('storedTracks', $systemTracks);
     $this->assign('lengthOfTracks', $systemLength);
     $this->assign('suePlaylistTracks', $sueTracks);
     $this->assign('suePlaylistLength', $sueLength);
     $this->assign('sueLastTrack', $suePlaylist[0]);
     $this->assign('sueNextTrack', $suePlaylist[1]);
     $this->assign('suePlaylist', $suePlaylist);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $loc = 1;
     $sql = "SELECT * from jinglepkgs ORDER BY name";
     $jinglepkgs = $db->getAll($sql);
     $this->assign('access_playlist', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 33), $userID));
     $this->assign('access_sue', AuthUtil::getDetailedUserrealmAccess(array(3, 20, 24), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('jinglepkgs', $jinglepkgs);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $jinglepkgID = pg_escape_string($this->fieldData['jinglepkgID']);
     $sql = "SELECT * FROM jinglepkgs WHERE id = {$jinglepkgID}";
     $jinglepkg = $db->getRow($sql);
     $sql = "SELECT audio.title, audio.id FROM audio INNER JOIN audiojinglepkgs ON audio.id = audiojinglepkgs.audioid WHERE audiojinglepkgs.jinglepkgid = {$jinglepkgID} ORDER BY audio.title";
     $jingles = $db->getAll($sql);
     $this->assign('access_playlist', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 33), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('jinglepkg', $jinglepkg);
     $this->assign('jingles', $jingles);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $count_query = "SELECT count(audio.id) \n\t\tFROM audio \n\t\tWHERE audio.flagged='t'";
     $flaggedNum = $db->getOne($count_query);
     $query = "SELECT DISTINCT audio.title AS title, audio.id AS id \n\t\tFROM audio \n\t\tWHERE audio.flagged='t'";
     $flaggedResult = $db->getAll($query);
     $i = 0;
     foreach ($flaggedResult as $key => &$track) {
         $sql = "SELECT DISTINCT artists.name AS name \n\t\t\tFROM artists, audioartists \n\t\t\tWHERE audioartists.audioid = " . $track['id'] . " \n\t\t\t\tAND audioartists.artistid = artists.id";
         $artists = $db->getAll($sql);
         foreach ($artists as $artist) {
             $track['artist'] = $track['artist'] . $artist['name'] . " & ";
         }
         $track['artist'] = rtrim($track['artist'], " & ");
         $track['searchNumber'] = $i;
         $i++;
     }
     $count_query = "SELECT count(audio.id) \n\t\tFROM audio \n\t\tWHERE audio.censor='t'";
     $censoredNum = $db->getOne($count_query);
     $query = "SELECT DISTINCT audio.title AS title, audio.id AS id \n\t\tFROM audio \n\t\tWHERE audio.censor='t'";
     $censoredResult = $db->getAll($query);
     $i = 0;
     foreach ($censoredResult as $key => &$track) {
         $sql = "SELECT DISTINCT artists.name AS name \n\t\t\tFROM artists, audioartists \n\t\t\tWHERE audioartists.audioid = " . $track['id'] . " \n\t\t\t\tAND audioartists.artistid = artists.id";
         $artists = $db->getAll($sql);
         foreach ($artists as $artist) {
             $track['artist'] = $track['artist'] . $artist['name'] . " & ";
         }
         $track['artist'] = rtrim($track['artist'], " & ");
         $track['searchNumber'] = $i;
         $i++;
     }
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('RequestTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 29), $userID));
     $this->assign('CensorTrack', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 30), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('flaggedTracks', $flaggedResult);
     $this->assign('censoredTracks', $censoredResult);
     $this->assign('flagNum', $flaggedNum);
     $this->assign('censorNum', $censoredNum);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $sql = "SELECT\n                    playlists.id, playlists.name, count(audioplaylists.id) AS count\n                FROM\n                    playlists\n                LEFT OUTER JOIN\n                    audioplaylists\n                ON\n                    playlists.id = audioplaylists.playlistid\n                GROUP BY\n                    playlists.id, playlists.name\n                ORDER BY\n                    playlists.name";
     $playlists = $db->getAll($sql);
     $playlist = null;
     $playlistID = $this->fieldData['dpsPlaylistID'];
     if ($playlistID != '') {
         $sql = "SELECT * FROM playlists WHERE id = {$playlistID}";
         $playlist = $db->getRow($sql);
     }
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('studioAccess', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 33), $userID));
     $this->assign('playlists', $playlists);
     $this->assign('playlist', $playlist);
     $this->assign('Action', $this->fieldData['dpsAction']);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $date = time();
     $show_query = "SELECT DISTINCT showplans.*, v_tree_showplan.permissions \n\t\t\tFROM showplans, v_tree_showplan \n\t\t\tWHERE showplans.id = v_tree_showplan.id AND \n\t\t\t\tv_tree_showplan.userid = {$userID} AND \n\t\t\t\tshowplans.showdate >= " . $date . " AND \n\t\t\t\tv_tree_showplan.permissions & B'" . $cfg['DPS']['fileR'] . "' = '" . $cfg['DPS']['fileR'] . "' \n\t\t\tORDER BY name asc";
     $partShows = $db->getAll($show_query);
     $show_query = "SELECT DISTINCT showplans.*, v_tree_showplan.permissions \n\t\t\tFROM showplans, v_tree_showplan \n\t\t\tWHERE showplans.id = v_tree_showplan.id AND \n\t\t\t\tv_tree_showplan.userid = {$userID} AND \n\t\t\t\tshowplans.showdate < " . $date . " AND \n\t\t\t\tv_tree_showplan.permissions & B'" . $cfg['DPS']['fileR'] . "' = '" . $cfg['DPS']['fileR'] . "' \n\t\t\tORDER BY name asc";
     $doneShows = $db->getAll($show_query);
     foreach ($partShows as &$show) {
         $show['niceAirDate'] = date("d/m/y", $show['showdate']);
         $show['niceAirTime'] = date("H:i", $show['showdate']);
         $show['niceCreateDate'] = date("d/m/y", $show['creationdate']);
         $show['niceCreateTime'] = date("H:i", $show['creationdate']);
         $show['text'] = $show['name'] . " - " . $show['niceAirDate'] . " - " . $show['niceAirTime'] . " (" . AuthUtil::getUsername($show['userid']) . ")";
         $sql = "SELECT BIT_OR(v_tree_dir.permissions) \n\t\t\t\tFROM v_tree_showplan, v_tree_dir \n\t\t\t\tWHERE v_tree_showplan.id = {$show['id']}\n\t\t\t\t\tAND v_tree_showplan.parent = v_tree_dir.id\n\t\t\t\t\tAND v_tree_dir.userid = {$userID}";
         $show['parentperm'] = $db->getOne($sql);
     }
     foreach ($doneShows as &$show) {
         $show['niceAirDate'] = date("d/m/y", $show['showdate']);
         $show['niceAirTime'] = date("H:i", $show['showdate']);
         $show['niceCreateDate'] = date("d/m/y", $show['creationdate']);
         $show['niceCreateTime'] = date("H:i", $show['creationdate']);
         $show['text'] = $show['name'] . " - " . $show['niceAirDate'] . " - " . $show['niceAirTime'] . " (" . AuthUtil::getUsername($show['userid']) . ")";
         $sql = "SELECT BIT_OR(v_tree_dir.permissions) \n\t\t\t\tFROM v_tree_showplan, v_tree_dir \n\t\t\t\tWHERE v_tree_showplan.id = {$show['id']}\n\t\t\t\t\tAND v_tree_showplan.parent = v_tree_dir.id\n\t\t\t\t\tAND v_tree_dir.userid = {$userID}";
         $show['parentperm'] = $db->getOne($sql);
     }
     $pShowCount = count($partShows);
     $dShowCount = count($doneShows);
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('partShows', $partShows);
     $this->assign('pShowCount', $pShowCount);
     $this->assign('doneShows', $doneShows);
     $this->assign('dShowCount', $dShowCount);
     $this->assign('deleteID', $this->fieldData['deleteID']);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $date = time();
     $script_query = "SELECT scripts.*, v_tree_script.permissions\n\t\t\t\tFROM v_tree_script, scripts\n\t\t\t\tWHERE v_tree_script.userid = {$userID}\n\t\t\t\t\tAND v_tree_script.id = scripts.id\n\t\t\t\t\tAND v_tree_script.permissions & B'{$cfg['DPS']['fileR']}' = '{$cfg['DPS']['fileR']}'\n\t\t\tORDER BY scripts.name asc";
     $scripts = $db->getAll($script_query);
     $scriptCount = count($scripts);
     foreach ($scripts as &$script) {
         $script['niceCreateDate'] = date("d/m/y", $script['creationdate']);
         $script['niceCreateTime'] = date("g a", $script['creationdate']);
         $script['text'] = $script['name'] . " - " . $script['niceCreateDate'] . " - " . $script['niceCreateTime'] . " (" . AuthUtil::getUsername($script['userid']) . ")";
         $sql = "SELECT BIT_OR(v_tree_dir.permissions) \n\t\t\t\tFROM v_tree_script, v_tree_dir \n\t\t\t\tWHERE v_tree_script.id = {$script['id']}\n\t\t\t\t\tAND v_tree_script.parent = v_tree_dir.id\n\t\t\t\t\tAND v_tree_dir.userid = {$userID}";
         $script['parentperm'] = $db->getOne($sql);
     }
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('scripts', $scripts);
     $this->assign('scriptCount', $scriptCount);
     $this->assign('deleteID', $this->fieldData['deleteID']);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     // user awsets
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $loc = 1;
     $sql = "SELECT usersconfigs.val FROM configs, usersconfigs\n\t\t\tWHERE configs.id = usersconfigs.configid\n\t\t\t\tAND configs.name = 'default_aw_set'\n\t\t\t\tAND usersconfigs.userid = " . $userID;
     $userset = $db->getOne($sql);
     $sql = "SELECT val FROM configuration \n\t\t\tWHERE location = {$loc}\n\t\t\t\tAND parameter='station_aw_set'";
     $stationset = $db->getOne($sql);
     if ($stationset != '') {
         $sql = "SELECT aw_sets.id as id, aw_sets.name as name,\n\t\t\t\t\taw_sets.description as desc\n\t\t\t\tFROM aw_sets\n\t\t\t\tWHERE id = {$stationset}";
         $sawset = $db->getRow($sql);
     } else {
         $sawset = "None";
     }
     $sql = "SELECT v_tree_aw_sets.*, aw_sets_users.user_id AS userid\n                FROM v_tree_aw_sets LEFT OUTER JOIN aw_sets_users\n                ON aw_sets_users.set_id = v_tree_aw_sets.id\n\t\t\tWHERE v_tree_aw_sets.userid = {$userID} \n\t\t\t\tAND v_tree_aw_sets.permissions & B'" . $cfg['DPS']['fileR'] . "' = '" . $cfg['DPS']['fileR'] . "'";
     $awsets = $db->getAll($sql);
     foreach ($awsets as &$awset) {
         if ($userset == $awset['id']) {
             $awset['active'] = 't';
         } else {
             $awset['active'] = 'f';
         }
         $sql = "SELECT BIT_OR(permissions) \n\t\t\t\tFROM v_tree_dir \n\t\t\t\tWHERE v_tree_dir.id = {$awset['parent']}\n\t\t\t\t\tAND v_tree_dir.userid = {$userID}";
         $awset['parentperm'] = $db->getOne($sql);
         $awset['userid'] = AuthUtil::getUsername($awset['userid']);
     }
     $this->assign('access_playlist', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 33), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('studioAccess', AuthUtil::getDetailedUserrealmAccess(array(3, 21, 35), $userID));
     $this->assign('awsets', $awsets);
     $this->assign('stationawset', $sawset);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $itemID = pg_escape_string($this->fieldData['itemID']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $date = time();
     if (is_numeric($itemID)) {
         $show_query = "SELECT DISTINCT BIT_OR(v_tree_showplan.permissions) \n\t\t\tFROM showitems, v_tree_showplan \n\t\t\tWHERE showitems.showplanid = v_tree_showplan.id AND \n\t\t\t\tv_tree_showplan.userid = {$userID} AND \n\t\t\t\tshowitems.id = {$itemID}";
         $checkShows = $db->getOne($show_query);
         if (substr($checkShows, 0, 1) == "1") {
             if (substr($checkShows, 1, 1) == "1") {
                 $this->assign('write', 't');
             } else {
                 $this->assign('write', 'f');
             }
             $show_sql = "SELECT showplans.* FROM showplans, showitems\n\t\t\t\t\tWHERE showitems.showplanid = showplans.id \n\t\t\t\t\tAND showitems.id = " . $itemID;
             $show = $db->getRow($show_sql);
             $show['niceAirDate'] = date("d/m/y", $show['showdate']);
             $show['niceAirTime'] = date("H:i", $show['showdate']);
             $show['niceCreateDate'] = date("d/m/y", $show['creationdate']);
             $show['niceCreateTime'] = date("H:i", $show['creationdate']);
             $items_sql = "SELECT * FROM showitems \n\t\t\t\t\tWHERE showplanid = " . $show['id'] . "\n\t\t\t\t\tORDER BY position ASC";
             $items = $db->getAll($items_sql);
             $time = $show['showdate'];
             $i = 0;
             foreach ($items as &$item) {
                 if ($item['id'] == $itemID) {
                     $item['time'] = $time;
                     $item['niceTime'] = date("H:i:s", $item['time']);
                     $item['m'] = str_pad((int) ($item['length'] / 60), 2, "0", STR_PAD_LEFT);
                     $item['s'] = str_pad($item['length'] - $item['m'] * 60, 2, "0", STR_PAD_LEFT);
                     $item['niceLength'] = $item['m'] . ":" . $item['s'];
                     if ($item['audioid'] != '') {
                         $sql = "SELECT audio.title AS title,\n\t\t\t\t\t\t\t\taudiotypes.name AS type,\n\t\t\t\t\t\t\t\taudio.length_smpl AS len\n\t\t\t\t\t\t\t\tFROM audio, audiotypes\n\t\t\t\t\t\t\t\tWHERE audio.type = audiotypes.id\n\t\t\t\t\t\t\t\tAND audio.id = " . $item['audioid'];
                         $stuff = $db->getRow($sql);
                         $item['audioTitle'] = $stuff['title'];
                         $item['nature'] = $stuff['type'];
                         $item['audioLen'] = $stuff['len'];
                         $item['niceAudioLength'] = str_pad(floor($stuff['len'] / 44100 / 60), 2, "0", STR_PAD_LEFT) . ":" . str_pad(ceil($stuff['len'] / 44100) % 60, 2, "0", STR_PAD_LEFT);
                     } else {
                         $item['nature'] = 'unknown';
                     }
                     if ($item['scriptid'] != '') {
                         $sql = "SELECT NAME, length FROM scripts\n\t\t\t\t\t\t\t\tWHERE id = " . $item['scriptid'];
                         $stuff = $db->getRow($sql);
                         $item['scriptName'] = $stuff['name'];
                         $item['sm'] = str_pad((int) ($stuff['length'] / 60), 2, "0", STR_PAD_LEFT);
                         $item['ss'] = str_pad($stuff['length'] - $item['sm'] * 60, 2, "0", STR_PAD_LEFT);
                         $item['scriptLen'] = $stuff['length'];
                         $item['niceScriptLength'] = $item['sm'] . ":" . $item['ss'];
                     }
                     break;
                 }
                 $time = $time + $item['length'];
                 $i++;
             }
             if ($show['showdate'] > $date) {
                 $this->assign('done', 'f');
             } else {
                 $this->assign('done', 't');
             }
             if ($items[$i]['length'] < $items[$i]['scriptLen'] || $items[$i]['length'] < floor($items[$i]['audioLen'] / 44100)) {
                 $this->assign('short', 't');
             }
             $this->assign('show', $show);
             $this->assign('item', $items[$i]);
         } else {
             $this->assign('error', 'You do not have permission to edit that item.');
         }
     } else {
         $this->assign('error', 'Invalid Item ID supplied');
     }
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     //System Track count
     $query = "SELECT count(audio.id) FROM audio";
     $systemTracks = $db->getOne($query);
     //System Track length
     $query = "SELECT sum(audio.length_smpl) FROM audio";
     $systemSamps = $db->getOne($query);
     $days = floor($systemSamps / 44100 / 60 / 60 / 24);
     $hours = floor($systemSamps / 44100 / 60 / 60 - $days * 24);
     $mins = round($systemSamps / 44100 / 60 - $hours * 60 - $days * 24 * 60);
     $systemLength = $days . "days " . $hours . "h " . $mins . "m";
     //Sue Track count
     $query = "SELECT count(audio.id) FROM audio WHERE sustainer = 't'";
     $sueTracks = $db->getOne($query);
     //Sue Track length
     $query = "SELECT sum(audio.length_smpl) FROM audio WHERE sustainer = 't'";
     $sueSamps = $db->getOne($query);
     $days = floor($sueSamps / 44100 / 60 / 60 / 24);
     $hours = floor($sueSamps / 44100 / 60 / 60 - $days * 24);
     $mins = round($sueSamps / 44100 / 60 - $hours * 60 - $days * 24 * 60);
     $sueLength = $days . "days " . $hours . "h " . $mins . "m";
     //Sue playing Now
     $query = "SELECT track_title, track_artist\n\t\t\tFROM log\n\t\t\tWHERE location = 0\n\t\t\tORDER BY datetime DESC LIMIT 1";
     $suePlayingNow = $db->getAll($query);
     foreach ($suePlayingNow as $key => &$track) {
         $track['artist'] = $track['track_artist'];
         $track['title'] = $track['track_title'];
     }
     //Sue playing next
     $query = "SELECT audio.title AS title, audio.id AS id \n\t\t\tFROM sustschedule, audio \n\t\t\tWHERE sustschedule.audioid = audio.id \n\t\t\tORDER BY sustschedule.id ASC LIMIT 1";
     $suePlayingNext = $db->getAll($query);
     foreach ($suePlayingNext as $key => &$track) {
         $sql = "SELECT DISTINCT artists.name as name \n\t\t\t\tFROM artists, audioartists \n\t\t\t\tWHERE audioartists.audioid = " . $track['id'] . " \n\t\t\t\tAND audioartists.artistid = artists.id";
         $artists = $db->getAll($sql);
         foreach ($artists as $artist) {
             $track['artist'] = $track['artist'] . $artist['name'] . " & ";
         }
         $track['artist'] = rtrim($track['artist'], " & ");
     }
     //Show on now
     putenv("TZ=GB");
     //$current_time = date("Y-m-d H:i:s", time());
     $current_time = time();
     $sql = "SELECT txshows.* FROM txshows , txschedule \n\t\t\tWHERE(txshows.id = txschedule.txshowid \n\t\t\tAND '{$current_time}' > txschedule.starttime \n\t\t\tAND '{$current_time}' <= txschedule.endtime);";
     $showC = $db->getRow($sql);
     if (!$showC) {
         $sql = "SELECT * FROM txshows \n\t\t\t\tWHERE id = " . pg_escape_string($cfg['DPS']['defaultShowID']);
         $showC = $db->getRow($sql);
     }
     //Show on next
     $sql = "SELECT txshows.* FROM txshows, txschedule \n\t\t\tWHERE (txshows.id = txschedule.txshowid \n\t\t\tAND '{$current_time}' < txschedule.starttime) \n\t\t\tORDER BY txschedule.starttime ASC LIMIT 1;";
     $showN = $db->getRow($sql);
     if (!$showN) {
         $sql = "SELECT * FROM txshows \n\t\t\t\tWHERE id = " . pg_escape_string($cfg['DPS']['defaultShowID']);
         $showN = $db->getRow($sql);
     }
     //Show just on
     $sql = "SELECT txshows.* FROM txshows, txschedule \n\t\t\tWHERE(txshows.id = txschedule.txshowid \n\t\t\tAND '{$current_time}' > txschedule.endtime) \n\t\t\tORDER BY txschedule.endtime DESC LIMIT 1;";
     $showL = $db->getRow($sql);
     if (!$showL) {
         $sql = "SELECT * FROM txshows \n\t\t\t\tWHERE id = " . pg_escape_string($cfg['DPS']['defaultShowID']);
         $showL = $db->getRow($sql);
     }
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $sql = "SELECT usersconfigs.val FROM configs, usersconfigs \n\t\t\tWHERE configs.id = usersconfigs.configid \n\t\t\tAND configs.name = 'user_lastlogin'\n\t\t\tAND usersconfigs.userid = " . $userID;
     $userlogin = $db->getOne($sql);
     if (is_null($userlogin)) {
         $userLastLog = "Not available";
     } else {
         $userLastLog = date("d/m/y G:i:s", intval($userlogin));
     }
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('userLastLogin', $userLastLog);
     $this->assign('storedTracks', $systemTracks);
     $this->assign('lengthOfTracks', $systemLength);
     $this->assign('suePlaylistTracks', $sueTracks);
     $this->assign('suePlaylistLength', $sueLength);
     $this->assign('sueLastTrack', $suePlayingNow[0]);
     $this->assign('sueNextTrack', $suePlayingNext[0]);
     $this->assign('scheduleCurrent', $showC);
     $this->assign('scheduleNext', $showN);
     $this->assign('scheduleLast', $showL);
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $showID = pg_escape_string($this->fieldData['showID']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $date = time();
     if (is_numeric($showID)) {
         $sql = "SELECT count(*) FROM v_tree_showplan\n\t\t\t\tWHERE id = {$showID}\n\t\t\t\t\tAND\tuserid = {$userID}\n\t\t\t\t\tAND permissions & B'" . $cfg['DPS']['fileR'] . "' = '" . $cfg['DPS']['fileR'] . "'";
         if ($db->getOne($sql) > 0) {
             $sql = "SELECT count(*) FROM v_tree_showplan\n\t\t\t\t\tWHERE id = {$showID}\n\t\t\t\t\t\tAND\tuserid = {$userID}\n\t\t\t\t\t\tAND permissions & B'" . $cfg['DPS']['fileW'] . "' = '" . $cfg['DPS']['fileW'] . "'";
             if ($db->getOne($sql) > 0) {
                 $this->assign('write', 't');
             } else {
                 $this->assign('write', 'f');
             }
             $show_sql = "SELECT showplans.*, v_tree_showplan.permissions\n                    FROM showplans, v_tree_showplan\n                    WHERE showplans.id = v_tree_showplan.id\n                        AND v_tree_showplan.userid = {$userID}\n                        AND v_tree_showplan.permissions & B'" . $cfg['DPS']['fileR'] . "' = '" . $cfg['DPS']['fileR'] . "'\n                        AND showplans.id = " . $showID;
             $show = $db->getRow($show_sql);
             $show['niceAirDate'] = date("d/m/y", $show['showdate']);
             $show['niceAirTime'] = date("H:i", $show['showdate']);
             $show['niceCreateDate'] = date("d/m/y", $show['creationdate']);
             $show['niceCreateTime'] = date("H:i", $show['creationdate']);
             $items_sql = "SELECT * FROM showitems \n\t\t\t\t\tWHERE showplanid = " . $showID . " \n\t\t\t\t\tORDER BY position asc";
             $items = $db->getAll($items_sql);
             $time = $show['showdate'];
             foreach ($items as &$item) {
                 $item['time'] = $time;
                 $item['niceTime'] = date("H:i:s", $item['time']);
                 $item['niceLength'] = str_pad((int) ($item['length'] / 60), 2, "0", STR_PAD_LEFT) . ":" . str_pad($item['length'] - (int) ($item['length'] / 60) * 60, 2, "0", STR_PAD_LEFT);
                 $item['niceEndTime'] = date("H:i:s", $item['time'] + $item['length']);
                 $time = $time + $item['length'];
                 if ($item['audioid'] != '') {
                     $sql = "SELECT audio.title AS title, audiotypes.name AS type \n\t\t\t\t\t\t\tFROM audio, audiotypes \n\t\t\t\t\t\t\tWHERE audio.type = audiotypes.id \n\t\t\t\t\t\t\t\tAND audio.id = " . $item['audioid'];
                     $stuff = $db->getRow($sql);
                     $item['audioTitle'] = $stuff['title'];
                     $item['nature'] = $stuff['type'];
                 } else {
                     $item['nature'] = 'unknown';
                 }
                 if ($item['scriptid'] != '') {
                     $sql = "SELECT name FROM scripts \n\t\t\t\t\t\t\tWHERE id = " . $item['scriptid'];
                     $item['scriptName'] = $db->getOne($sql);
                 }
             }
             $time = $time - $show['showdate'];
             $show['niceLength'] = (int) ($time / 60) . "mins " . ($time - (int) ($time / 60) * 60) . "s";
             $show['niceProducer'] = AuthUtil::getUsername($show['userid']);
             if ($show['showdate'] > $date) {
                 $this->assign('done', 'f');
             } else {
                 $this->assign('done', 't');
             }
             $this->assign('show', $show);
             $this->assign('showItems', $items);
             $this->assign('itemCount', count($items));
             $this->assign('endTime', $items[count($items) - 1]['niceEndTime']);
         } else {
             $this->assign('error', 'You do not have permission to edit that show.');
         }
     } else {
         $this->assign('error', 'Invalid Show ID supplied');
     }
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('deleteID', $this->fieldData['deleteID']);
 }
 public function userCanView($userID, $realm)
 {
     $auth = Auth::getInstance($realm);
     $realmPath = AuthUtil::getRealmPath($realm);
     return AuthUtil::getDetailedUserrealmAccess($realmPath, $auth->getUserID());
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $itemID = pg_escape_string($this->fieldData['itemID']);
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $date = time();
     if (is_numeric($itemID) && isset($itemID)) {
         // GET SHOW INFO
         $show_query = "SELECT DISTINCT BIT_OR(v_tree_showplan.permissions) \n\t\t\tFROM showitems, v_tree_showplan \n\t\t\tWHERE showitems.showplanid = v_tree_showplan.id AND \n\t\t\t\tv_tree_showplan.userid = {$userID} AND \n\t\t\t\tshowitems.id = {$itemID}";
         $checkShows = $db->getOne($show_query);
         if (substr($checkShows, 0, 1) == "1") {
             if (substr($checkShows, 1, 1) == "1") {
                 $this->assign('write', 't');
             } else {
                 $this->assign('write', 'f');
             }
             $show_sql = "SELECT showplans.* FROM showplans, showitems\n\t\t\t\t\tWHERE showitems.showplanid = showplans.id\n\t\t\t\t\tAND showitems.id = " . $itemID;
             $show = $db->getRow($show_sql);
             $show['niceAirDate'] = date("d/m/y", $show['showdate']);
             $show['niceAirTime'] = date("g a", $show['showdate']);
             $show['niceCreateDate'] = date("d/m/y", $show['creationdate']);
             $show['niceCreateTime'] = date("g a", $show['creationdate']);
             // GET ITEM INFO
             $items_sql = "SELECT * FROM showitems\n\t\t\t\t\tWHERE showplanid = " . $show['id'] . "\n\t\t\t\t\tORDER BY position ASC";
             $items = $db->getAll($items_sql);
             $time = $show['showdate'];
             $i = 0;
             foreach ($items as &$item) {
                 if ($item['id'] == $itemID) {
                     $item['time'] = $time;
                     $item['niceTime'] = date("H:i:s", $item['time']);
                     $item['niceLength'] = (int) ($item['length'] / 60) . ":" . ($item['length'] - (int) ($item['length'] / 60) * 60);
                     if ($item['audio'] != '') {
                         $sql = "SELECT audio.title AS title,\n\t\t\t\t\t\t\t\taudiotypes.name AS type,\n\t\t\t\t\t\t\t\taudio.length_smpl AS len\n\t\t\t\t\t\t\t\tFROM audio, audiotypes\n\t\t\t\t\t\t\t\tWHERE audio.type = audiotypes.id\n\t\t\t\t\t\t\t\tAND audio.id = " . $item['audio'];
                         $stuff = $db->getRow($sql);
                         $item['audioTitle'] = $stuff['title'];
                         $item['nature'] = $stuff['type'];
                         $item['niceAudioLength'] = round($stuff['len'] / 44100 / 60) . ":" . $stuff['len'] / 44100 % 60;
                     } else {
                         $item['nature'] = 'unknown';
                     }
                     if ($item['script'] != '') {
                         $sql = "SELECT name, length FROM scripts\n\t\t\t\t\t\t\t\tWHERE id = " . $item['script'];
                         $stuff = $db->getRow($sql);
                         $item['scriptName'] = $stuff['name'];
                         $item['niceScriptLength'] = (int) ($stuff['length'] / 60) . ":" . ($stuff['length'] - (int) ($stuff['length'] / 60) * 60);
                     }
                     break;
                 }
                 $time = $time + $item['length'];
                 $i++;
             }
             $this->assign('show', $show);
             $this->assign('item', $items[$i]);
             // GET LIST OF SCRIPTS
             $script_query = "SELECT scripts.*, v_tree_script.permissions\n\t\t\t\t    FROM v_tree_script, scripts\n\t\t\t\t    WHERE v_tree_script.userid = {$userID}\n\t\t\t\t\t    AND v_tree_script.id = scripts.id\n\t\t\t\t\t    AND v_tree_script.permissions & B'{$cfg['DPS']['fileR']}' = '{$cfg['DPS']['fileR']}'\n\t\t\t        ORDER BY scripts.name asc";
             $scripts = $db->getAll($script_query);
             foreach ($scripts as &$script) {
                 $script['niceCreateDate'] = date("d/m/y", $script['creationdate']);
                 $script['niceCreateTime'] = date("g a", $script['creationdate']);
                 $script['text'] = $script['name'] . " - " . $script['niceCreateDate'] . " - " . $script['niceCreateTime'];
                 $sql = "SELECT BIT_OR(v_tree_dir.permissions) \n\t\t\t    \t    FROM v_tree_script, v_tree_dir \n    \t\t\t\t    WHERE v_tree_script.id = {$script['id']}\n\t    \t\t\t\t    AND v_tree_script.parent = v_tree_dir.id\n    \t    \t\t\t\tAND v_tree_dir.userid = {$userID}";
                 $script['parentperm'] = $db->getOne($sql);
             }
             $this->assign('scripts', $scripts);
         } else {
             $this->assign('error', 'You do not have permission to edit that item.');
         }
     } else {
         $this->assign('error', 'Invalid Item ID supplied');
     }
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
 }
 protected function setupTemplate()
 {
     global $cfg;
     parent::setupTemplate();
     $db = Database::getInstance($cfg['DPS']['dsn']);
     $offset = $this->fieldData['dpsSearchPage'];
     if ($offset == "") {
         $offset = 0;
     } else {
         $offset--;
     }
     $searchValue = $this->fieldData['dpsSearchVal'];
     $searchType = $this->fieldData['dpsSearchType'];
     $letter = pg_escape_string($this->fieldData['dpsSearchLetter']);
     if ($searchType == '' && $letter != '') {
         if ($letter == "*") {
             $searchType = 'Number';
         } else {
             $searchType = 'Letter';
         }
         $searchValue = $letter;
     }
     if ($this->fieldData['dpsSortType'] != '') {
         $sesh = Session::getInstance();
         $sortType = $this->fieldData['dpsSortType'];
         $sesh->setValue("dpsSortType", $sortType);
     } else {
         $sesh = Session::getInstance();
         if ($sesh->keyExists("dpsSortType")) {
             $sortType = $sesh->getValue("dpsSortType");
         } else {
             $sortType = "title";
         }
     }
     if ($searchValue != '') {
         $searchResult = DPS::searchAudio($searchValue, $searchType, $sortType, $offset, '');
         $rNum = DPS::searchPageAudio($searchValue, $searchType, '');
         $searchInfo = "Found {$rNum} results matching your query";
     }
     $pages = 1;
     $pageArray[] = $pages;
     $rNum = $rNum - $cfg['DPS']['resultLimit'];
     while ($rNum > $cfg['DPS']['resultLimit']) {
         $pages++;
         $pageArray[] = $pages;
         $rNum = $rNum - $cfg['DPS']['resultLimit'];
     }
     //Sue playing now/next
     $query = "SELECT audio.title AS title, audio.id AS id \n\t\tFROM sustschedule, audio \n\t\tWHERE sustschedule.audioid = audio.id \n\t\tORDER BY sustschedule.id asc \n\t\tOFFSET 1 \n\t\tLIMIT 1";
     $sueNextTrack = $db->getRow($query);
     if ($sueNextTrack != '') {
         $sql = "SELECT DISTINCT artists.name AS name \n\t\t\tFROM artists, audioartists \n\t\t\tWHERE audioartists.audioid = " . $sueNextTrack['id'] . " \n\t\t\tAND audioartists.artistid = artists.id";
         $artists = $db->getAll($sql);
         foreach ($artists as $artist) {
             $sueNextTrack['artist'] = $sueNextTrack['artist'] . $artist['name'] . " & ";
         }
         $sueNextTrack['artist'] = rtrim($sueNextTrack['artist'], " & ");
     }
     $auth = Auth::getInstance();
     $userID = $auth->getUserID();
     $this->assign('Access_ViewSue', AuthUtil::getDetailedUserrealmAccess(array(26, 20, 3), $userID));
     $this->assign('Access_EditSue', AuthUtil::getDetailedUserrealmAccess(array(24, 20, 3), $userID));
     $this->assign('Admin', AuthUtil::getDetailedUserrealmAccess(array(1), $userID));
     $this->assign('Access_EditTrack', AuthUtil::getDetailedUserrealmAccess(array(27, 21, 3), $userID));
     $this->assign('Access_SueStats', AuthUtil::getDetailedUserrealmAccess(array(25, 20, 3), $userID));
     $this->assign('Access_Delete', AuthUtil::getDetailedUserrealmAccess(array(32, 21, 3), $userID));
     $this->assign('sueNextTrack', $sueNextTrack);
     $this->assign('page', $offset);
     $this->assign('searchResult', $searchResult);
     $this->assign('searchInfo', $searchInfo);
     $this->assign('pages', $pageArray);
     $this->assign('searchType', $searchType);
     $this->assign('searchValue', $searchValue);
     $this->assign('searchLetter', $letter);
     $this->assign('sortType', $sortType);
 }
Пример #29
0
 /**
  * Initialise the Page object
  * 
  * Will determine if the required request variables are present.
  * If not present an exception will be thrown and caught 
  * 
  * @var string
  */
 public function __construct()
 {
     list($usec, $sec) = explode(" ", microtime());
     $startTime = (double) $usec + (double) $sec;
     global $cfg;
     try {
         ##############
         ## Include the Auth and AuthUtil classes
         #			$modulePath  = $cfg['general']['toolkitRoot'] . '/' . $cfg['Auth']['authClassModule'];
         $modulePath = $cfg['Auth']['dir']['root'];
         $moduleName = $cfg['Auth']['authClassModule'];
         // try to include Auth
         if (!(include_once "{$modulePath}/{$moduleName}.class.php")) {
             throw new Exception("It was not possible to include Auth.class.php. I tried to find it here: {$modulePath}/{$moduleName}.class.php");
         }
         if (!class_exists("Auth")) {
             throw new Exception("The {$moduleName}.class.php ({$modulePath}/{$moduleName}.class.php) file was included but the Auth class could not be found");
         }
         // try to include AuthUtil
         if (!(include_once "{$modulePath}/AuthUtil.class.php")) {
             throw new Exception("It was not possible to include AuthUtil.class.php. I tried to find it here: {$modulePath}/AuthUtil.class.php");
         }
         if (!class_exists("AuthUtil")) {
             throw new Exception("The AuthUtil.class.php ({$modulePath}/AuthUtil.class.php) file was included but the AuthUtil class could not be found");
         }
         $db = Database::getInstance($cfg['MVC']['dsn']);
         $errors = array();
         //Load data from superglobals
         $this->loadFieldData();
         //Redirect the user to the actual site (disabled when proxypassed)
         if ($cfg['general']['proxypass'] == 'f' && $_SERVER['HTTP_HOST'] != $cfg['general']['domain']) {
             $url = $cfg['general']['protocol'] . $cfg['general']['domain'] . $cfg['general']['siteRoot'];
             header("Location: {$url}");
             exit;
         }
         //Load template ID
         if (isset($this->fieldData['templateID']) && $this->fieldData['templateID'] != '') {
             $this->templateID = $this->fieldData['templateID'];
         } elseif (isset($cfg['smarty']['defaultTemplate'])) {
             $this->templateID = MVCUtils::getTemplateID($cfg['smarty']['defaultTemplate']);
         } else {
             //Template ID is required. Therefore throw an exception
             throw new LoggedException('No template ID or default template specified', 0, self::module);
         }
         //Load form name
         if (isset($this->fieldData['formName'])) {
             $this->formName = $this->fieldData['formName'];
         } else {
             //formName is not required, so set to empty string
             //note that forms will be ignored if this is not passed
             $this->fieldData['formName'] = null;
         }
         //Load the module names
         $this->viewerModuleName = $db->getOne("SELECT modulename FROM templates WHERE templateid = ?", array($this->templateID));
         if (isset($this->fieldData['moduleName']) && $this->fieldData['moduleName'] != '') {
             $this->modelModuleName = $this->fieldData['moduleName'];
         } else {
             $this->modelModuleName = 'MVC';
         }
         ### Check that the user has permission to use the submitted form
         // get the realmid of the submitted form
         $sql = 'SELECT realmid FROM forms WHERE formname = ? AND modulename = ?';
         $realmid = $db->getOne($sql, array($this->formName, $this->modelModuleName));
         $auth = Auth::getInstance();
         // If the realm id could not found then allow access
         // (this will cause 'Model' to be used - so no processing occurs)
         if (!$realmid) {
             //Access is allowed
             $modelAccess = true;
         } else {
             //Check if the user has access to the realm associated with the form
             if (!$auth->isLoggedIn()) {
                 $auth->attemptLogin($cfg['Auth']['anonuser']);
             } else {
                 $auth->attemptLogin();
             }
             $path = AuthUtil::getRealmPath($realmid);
             if (!AuthUtil::getDetailedUserrealmAccess($path, $auth->getUserID())) {
                 //If the user does not have permission, show an error
                 $modelAccess = false;
                 $errors = array('permission' => 'You do not have permission to use the submited form');
             } else {
                 //Set access flag to false
                 $modelAccess = true;
             }
         }
         //If access to the requested form is allowed
         if ($modelAccess) {
             //If a form was submitted
             if (isset($this->formName) && !is_null($this->formName)) {
                 //Then validate the form data
                 //Store any errors in $errors
                 $errors = $this->validate();
             }
         }
         //If the user has access to the requested template
         if ($this->checkAuth()) {
             if ($modelAccess) {
                 $newModel = MVCUtils::initializeModel(array($this->templateID), $this->formName, $this->modelModuleName, $this->viewerModuleName, $this->fieldData, $errors);
             } else {
                 $this->templateID = MVCUtils::getPermErrorTemplateID();
                 $newModel = MVCUtils::initializeModel(array($this->templateID), null, 'MVC', 'Auth', $this->fieldData, $errors);
             }
             //If there are errors then these will be passed in the $errors array,
             //if there are no errors then $errors will simple be an empty array
             //If no form name was passed, $this->formName will be null
         } else {
             //The user is not authorised to access this area
             $auth = Auth::getInstance();
             //Set the template ID to that of the permission error template
             $this->templateID = MVCUtils::getPermErrorTemplateID();
             //Get the reason for failure and specify an error message
             $reason = $auth->getFailureReason();
             if (count($errors) == 0) {
                 if ($reason == 2) {
                     $errors = array('permission' => 'Your session has been inactive for too long');
                 } elseif ($reason != 0) {
                     $errors = array('permission' => 'Unfortunately, an error has occurred. Please attempt logging in again.');
                 } else {
                     $errors = array('permission' => 'You do not have permission to view this page');
                 }
             }
             //Initialise the viewer for the permission error template
             if ($auth->getUserID() == $cfg['Auth']['anonuserID'] && $cfg['Auth']['anonuserredirect'] == 'y') {
                 $permErrorTID = $cfg['Auth']['anonuserRedirectTemplateID'];
                 $newModel = MVCUtils::initializeViewer(array($permErrorTID), null, 'tkfecommon', null, $errors);
             } else {
                 $permErrorTID = MVCUtils::getTemplateID($cfg['Auth']['permissionErrorTemplate']);
                 $newModel = MVCUtils::initializeViewer(array($permErrorTID), null, 'tkfecommon', null, $errors);
             }
         }
         //Print out the page
         echo $newModel->getCode();
     } catch (Exception $e) {
         //If a problem occured then create an error page
         $ev = new ExceptionViewer($e);
         $ev->printTemplate();
         exit;
     }
     //Show the execution time if set in config file
     if ($cfg['smarty']['showExecTime']) {
         list($usec, $sec) = explode(" ", microtime());
         $endTime = (double) $usec + (double) $sec;
         $totalTime = round($endTime - $startTime, 3);
         $log = Database::getQueryLog();
         echo "Total time to parse page: {$totalTime} seconds<br />\n";
         echo "Total number of queries: " . Database::getTotalQueries();
         echo "<br />Log: ";
         print_r($log);
     }
 }
 /**
  *
  * @param array $realmPath An array of strings 
  * @param mixed $userID the ID of the user to check permission for
  * @return boolean True if access is allowed, false otherwise
  */
 public static function getPremission($realmPath, $userID)
 {
     return AuthUtil::getDetailedUserrealmAccess($realmPath, $userID);
 }