Ticket #3834: 3834_diff.2.patch

File 3834_diff.2.patch, 44.2 KB (added by Joe Ripley <vitaminjoe@…>, 17 years ago)

Re-posting the patch to correct a couple small typos. I should really check these things out a bit more thoroughly before posting.

  • mythplugins/mythweb/modules/weather/set_screen.php

     
     1<?php
     2/**
     3 * Weather Screen settings
     4 *
     5 * @url         $URL$
     6 * @date        $Date$
     7 * @version     $Revision$
     8 * @author      $Author$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Weather
     13 *
     14/**/
     15
     16    require_once 'includes/objects/WeatherScreen.php';
     17
     18// Load all of the known mythtv frontend hosts
     19    $Settings_Hosts = array();
     20    $sh = $db->query('SELECT DISTINCT hostname
     21                      FROM weathersourcesettings
     22                      ORDER BY hostname');
     23    while (list($host) = $sh->fetch_row()) {
     24        if (empty($host))
     25            continue;
     26        $Settings_Hosts[$host] = $host;
     27    }
     28    $sh->finish();
     29
     30// Initialize Screens
     31    rebuild_active_screens();
     32    rebuild_inactive_screens();
     33
     34// Make sure we have a valid host selected
     35    if (!isset($Settings_Hosts[$_SESSION['settings']['host']]))
     36        $_SESSION['settings']['host'] = reset(array_keys($Settings_Hosts));
     37
     38// Add to Active Screens
     39    else if (isset($_POST['add']) && isset($_POST['host'])) {
     40            if (isset($_POST['inactive_screen'])) {
     41                $screen = new WeatherScreen(null);
     42                $screen->initNew($_POST['inactive_screen'], $_POST['host']);
     43
     44                rebuild_active_screens();
     45            }
     46        $_SESSION['settings']['host'] = $_POST['host'];
     47    }
     48
     49// Delete from Active Screens
     50    else if (isset($_POST['delete']) && isset($_POST['host'])) {
     51        if (isset($_POST['active_screen'])) {
     52            $screen = new WeatherScreen($_POST['active_screen']);
     53            $screen->deleteScreen();
     54
     55            rebuild_active_screens();
     56        }
     57        $_SESSION['settings']['host'] = $_POST['host'];
     58    }
     59
     60// Move screen
     61    else if ((isset($_POST['move_u']) || isset($_POST['move_d'])) && isset($_POST['host'])) {
     62        if (isset($_POST['active_screen'])) {
     63            $screen = new WeatherScreen($_POST['active_screen']);
     64            if (isset($_POST['move_u'])) $screen->move("up");
     65            if (isset($_POST['move_d'])) $screen->move("down");
     66
     67            rebuild_active_screens();
     68        }
     69    }
     70
     71// Edit Active Screen
     72    else if (isset($_POST['edit']) && isset($_POST['host'])) {
     73        // Cancel editting
     74        if (isset($_POST['cancel_edit']))  {
     75            unset($_SESSION['weather']['edit']);
     76            unset($_SESSION['weather']['search']);
     77        }
     78        // Edit screen
     79        if (isset($_POST['active_screen'])) {
     80            $_SESSION['weather']['edit'] = $_POST['active_screen'];
     81        }
     82        // Search locations
     83        if (isset($_POST['edit_search']) && (strlen($_POST['weather_search'])>0)) {
     84            $_SESSION['weather']['search'] = $_POST['weather_search'];
     85        }
     86        // Save changes
     87        if (isset($_POST['save_edit'])) {
     88            $screen = new WeatherScreen($_POST['edit']);
     89            // Save location changes
     90            if (isset($_POST['weather_location']) && isset($_POST['weather_use_results'])) {
     91                $matches = array();
     92                if (preg_match('/\(\((\d*)\)\)(.*)/', $_POST['weather_location'], $matches)) {
     93                    $screen->updateLocation($matches[1], $matches[2]);
     94                }
     95            }
     96            // Save unit changes
     97            if (isset($_POST['weather_units']))
     98                $screen->updateUnits($_POST['weather_units']);
     99
     100            // Save clears out search and edit functions
     101            unset($_SESSION['weather']['edit']);
     102            unset($_SESSION['weather']['search']);
     103        }
     104
     105        $_SESSION['settings']['host'] = $_POST['host'];
     106    }
     107
     108/**
     109 * refreshes the active screens array
     110/**/
     111    function rebuild_active_screens() {
     112        global $db;
     113        $_SESSION['weather']['active'] = array();
     114
     115        $sh = $db->query('SELECT screen_id, draworder
     116                          FROM weatherscreens
     117                          WHERE hostname=?
     118                          ORDER BY draworder', $_SESSION['settings']['host']);
     119
     120        // Populate active screens
     121        while(list($screen_id, $draworder) = $sh->fetch_row())
     122            $_SESSION['weather']['active'][$draworder] = $screen_id;
     123
     124        $sh->finish();
     125    }
     126
     127/**
     128 * refreshes the inactive screens array
     129/**/
     130    function rebuild_inactive_screens() {
     131        global $db;
     132
     133        // Clear old inactive list
     134        unset($_SESSION['weather']['inactive']);
     135        if (!isset($_SESSION['weather']['inactive']))
     136            $_SESSION['weather']['inactive'] = array();
     137
     138        $sh = $db->query('SELECT types
     139                          FROM weathersourcesettings
     140                          WHERE hostname=?', $_SESSION['settings']['host']);
     141
     142        // Populate inactive screens
     143        //
     144        // TODO Hardcoding these variables is probably a no-no.  But all of this
     145        //      stuff is coded into the XML theme (weather-ui.xml).  Having the
     146        //      module parse that seems overkill.
     147        while(list($types) = $sh->fetch_row()) {
     148            $scratch = explode(',', $types);
     149            foreach ($scratch as $item) {
     150                if ($item == 'cclocation')   $type_list[$item] = 'Current Conditions';
     151                if ($item == '3dlocation')   $type_list[$item] = 'Three Day Forecast';
     152                if ($item == '6dlocation')   $type_list[$item] = 'Six Day Forecast';
     153                if ($item == 'smdesc')       $type_list[$item] = 'Static Map';
     154                if ($item == 'amdesc')       $type_list[$item] = 'Animated Map';
     155                if ($item == 'swlocation')   $type_list[$item] = 'Severe Weather Alerts';
     156                if ($item == '18hrlocation') $type_list[$item] = '18 Hour Forecast';
     157            }
     158        }
     159        $sh->finish();
     160
     161        // Return if no types are found
     162        if (!isset($type_list)) { return; }
     163
     164        foreach ($type_list as $key => $value)
     165            array_push($_SESSION['weather']['inactive'], $type_list[$key]);
     166
     167        sort($_SESSION['weather']['inactive']);
     168    }
     169
     170/**
     171 * displays a list of inactive screens as a <select> list
     172/**/
     173    function display_inactive_screens() {
     174        if (!isset($_SESSION['weather']['inactive'])) return;
     175       
     176        if (count($_SESSION['weather']['inactive']) <= 0)
     177            echo '<p><b>Warning!!</b> No types were found in weathersourcesettings for hostname ('. $_SESSION['settings']['host'] .')</p>';
     178
     179        else {
     180            echo '<select name="inactive_screen">' ."\n";
     181            foreach ($_SESSION['weather']['inactive'] as $screen)
     182                if (! $screen->active)
     183                    echo '    <option>'. $screen ."</option>\n";
     184            echo '</select>' ."\n";
     185        }
     186    }
     187   
     188
     189/**
     190 * displays a list of active screens as a <select> list
     191/**/
     192    function display_active_screens() {
     193        if (!isset($_SESSION['weather']['active'])) return;
     194       
     195        echo "<ol>\n";
     196        foreach ($_SESSION['weather']['active'] as $screen_id) {
     197            $screen = new WeatherScreen($screen_id);
     198            echo ' <li><input type="radio" name="active_screen" value="'. $screen->screen_id .'" id="active-screen-'. $screen->screen_id .'">';
     199            echo '<label for="active-screen-'. $screen->screen_id .'">'. $screen->container ."</label></li>\n";
     200        }
     201        echo "</ol>";
     202    }
  • mythplugins/mythweb/modules/weather/handler.php

     
    1414/**/
    1515
    1616// Load the weather classes
    17     require_once 'includes/objects/WeatherSite.php';
    18     require_once 'includes/objects/Forecast.php';
     17    require_once 'includes/objects/WeatherScreen.php';
     18    $WeatherScreens = array();
    1919
    20 // Default unit preference is not metric
    21     if (empty($_SESSION['weather']['siunits'])) {
    22         $_SESSION['weather']['siunits'] = 'NO';
    23     }
     20// Get configured WeatherScreens from the database
     21    $sh = $db->query('SELECT screen_id, draworder
     22                      FROM weatherscreens
     23                      WHERE hostname=?',
     24                      $_SESSION['settings']['host']);
    2425
    25 /**
    26  * @global  array   $GLOBALS['Weather_Types']
    27  * @name    $Weather_Types
    28 /**/
    29     global $Weather_Types;
    30     $Weather_Types = array();
    31 
    32 // Load the weather data
    33     foreach (file(modules_path.'/'.module.'/weathertypes.dat') as $line) {
    34         list($id, $name, $img) = explode(',', $line);
    35         $Weather_Types[$id] = array($img, $name);
     26    while(list($screen_id, $draworder) = $sh->fetch_row()) {
     27        $WeatherScreens[$draworder] = new WeatherScreen($screen_id);
     28        $WeatherScreens[$draworder]->getData();
    3629    }
    3730
    38 /**
    39  * @global  array   $GLOBALS['WeatherSites']
    40  * @name    $WeatherSites
    41 /**/
    42     global $WeatherSites;
    43     $WeatherSites = array();
    44 
    45 // Build a list of the known weather sites, starting with the session prefs
    46     if ($_SESSION['weather']['locale'])
    47         $WeatherSites[$_SESSION['weather']['locale']] = new WeatherSite($_SESSION['weather']['locale'],
    48                                                                         t('MythWeb Session'),
    49                                                                         $_SESSION['weather']['siunits']);
    50 // Pull from the database next
    51     $sh = $db->query('SELECT data, hostname FROM settings WHERE value="locale"');
    52     while (list($locale, $host) = $sh->fetch_row()) {
    53     // New data site
    54         if (empty($WeatherSites[$locale])) {
    55             $siunits = $db->query_col('SELECT data
    56                                          FROM settings
    57                                         WHERE value="SIUnits" AND hostname=?',
    58                                       $host);
    59             $WeatherSites[$locale] = new WeatherSite($locale, $host, $siunits);
    60         }
    61     // Add the hostname to sites we've already seen
    62         else {
    63             $WeatherSites[$locale]->hosts[] = $host;
    64         }
    65 
    66     }
     31    ksort($WeatherScreens);
    6732    $sh->finish();
    6833
    6934// Print the weather page template
  • mythplugins/mythweb/modules/weather/includes/objects/WeatherScreen.php

     
     1<?php
     2/**
     3 * WeatherScreen class for MythWeb's Weather module
     4 *
     5 * @url         $URL$
     6 * @date        $Date$
     7 * @version     $Revision$
     8 * @author      $Author$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Weather
     13 *
     14/**/
     15
     16class WeatherScreen {
     17
     18    var $screen_id;
     19    var $draworder;
     20    var $container;
     21    var $host;
     22    var $units;
     23    var $active;
     24
     25    var $data = array();
     26    var $search = array();
     27
     28    function WeatherScreen($screen_id) {
     29        global $db;
     30
     31        $this->screen_id = $screen_id;
     32        $this->setActive();
     33
     34        if ($this->active) {
     35            $sh = $db->query('SELECT draworder, container, hostname, units
     36                              FROM weatherscreens
     37                              WHERE screen_id=?',
     38                              $this->screen_id);
     39
     40            list($draworder, $container, $hostname, $units) = $sh->fetch_row();
     41
     42            $this->draworder = $draworder;
     43            $this->container = $container;
     44            $this->host      = $hostname;
     45            $this->units     = $units;
     46        }
     47    }
     48
     49    function setActive() {
     50        if ($this->checkScreenID()) $this->active = 1;
     51        else $this->active = 0;
     52    }
     53
     54    function deleteScreen() {
     55        global $db;
     56
     57        if (! $this->checkScreenID()) return;
     58
     59        $db->query('DELETE
     60                    FROM weatherscreens
     61                    WHERE screen_id=?
     62                    AND hostname=?',
     63                    $this->screen_id, $this->host);
     64
     65        $db->query('DELETE
     66                    FROM weatherdatalayout
     67                    WHERE weatherscreens_screen_id=?',
     68                    $this->screen_id);
     69
     70        $this->active = 0;
     71        $this->renumDrawOrder();
     72
     73        return;
     74    }
     75
     76    function initNew($container, $hostname) {
     77        global $db;
     78
     79        // Get next draworder
     80        $draworder = $db->query_col('SELECT MAX(draworder)
     81                                     FROM weatherscreens
     82                                     WHERE hostname=?', $hostname);
     83
     84        if ($draworder >= 0) $draworder++;
     85        else $draworder = 0;
     86
     87        // Insert screen
     88        $db->query('INSERT INTO weatherscreens
     89                       SET screen_id=NULL,
     90                           draworder=?,
     91                           container=?,
     92                           hostname=?,
     93                           units=0',
     94                    $draworder, $container, $hostname);
     95
     96        $this->setActive();
     97        $this->renumDrawOrder();
     98    }
     99
     100    function renumDrawOrder( ) {
     101        global $db;
     102        $i = 0;
     103       
     104        $sh = $db->query('SELECT screen_id
     105                          FROM weatherscreens
     106                          WHERE hostname=?
     107                          ORDER BY draworder',
     108                          $this->host);
     109
     110        while(list($id) = $sh->fetch_row()) {
     111            $db->query('UPDATE weatherscreens
     112                        SET draworder=?
     113                        WHERE hostname=?
     114                        AND screen_id=?',
     115                        $i, $this->host, $id);
     116            $i++;
     117        }
     118    }
     119
     120    function move( $direction ) {
     121        global $db;
     122
     123        if ($direction == 'up')   $i = -1;
     124        if ($direction == 'down') $i =  1;
     125
     126        $db->query('UPDATE weatherscreens
     127                    SET draworder=?
     128                    WHERE draworder=?
     129                    AND hostname=?',
     130                    $this->draworder, ($this->draworder+$i), $this->host);
     131
     132        $db->query('UPDATE weatherscreens
     133                    SET draworder=?
     134                    WHERE screen_id=?
     135                    AND hostname=?',
     136                    ($this->draworder+$i), $this->screen_id, $this->host);
     137
     138        $this->renumDrawOrder();
     139    }
     140
     141    function checkScreenID( ) {
     142        global $db;
     143   
     144        // Sanity check on screen_id
     145        if ($this->screen_id >= 0) {
     146            $count = $db->query_col('SELECT count(screen_id) FROM weatherscreens
     147                                     WHERE screen_id=?', $this->screen_id);
     148            if ($count == 0) return false;
     149            else return true;
     150        }
     151        return false;
     152    }
     153
     154    function runSearch( $needle ) {
     155        global $db;
     156        if (! $this->checkScreenID()) { return; }
     157
     158        // Build container name to types hash
     159        //
     160        // TODO This is not the way to do this.  All of this data is stored
     161        //      in the weather-ui.xml file.  Parsing it to get type descriptions
     162        //      seems overkill.
     163
     164        $type_hash['Animated Map']          = 'amdesc';
     165        $type_hash['Static Map']            = 'smdesc';
     166        $type_hash['Current Conditions']    = 'cclocation';
     167        $type_hash['Six Day Forecast']      = '6dlocation';
     168        $type_hash['Three Day Forecast']    = '3dlocation';
     169        $type_hash['Severe Weather Alerts'] = 'swlocation';
     170        $type_hash['18 Hour Forecast']      = '18hrlocation';
     171       
     172        // Run scripts that supply $this->container and search for $needle
     173        $sh = $db->query('SELECT sourceid, path, types
     174                          FROM weathersourcesettings
     175                          WHERE hostname=?',
     176                          $this->host);
     177
     178        while (list($source_id, $script, $types) = $sh->fetch_row()) {
     179            $types_arr = explode(',', $types);
     180            foreach ($types_arr as $type) {
     181                if ($type_hash[$this->container] == $type) {
     182                    $results = $this->runScript($script, "-l \"$needle\"");
     183                    if (count($results))
     184                        $this->search[$source_id] = $results;
     185                }
     186            }
     187        }
     188
     189        $sh->finish();
     190    }
     191
     192    function getData( ) {
     193        global $db;
     194        if (! $this->checkScreenID()) { return; }
     195
     196        // Find script file for this screen_id
     197        $sh = $db->query('SELECT DISTINCT weathersourcesettings.path
     198                          FROM weathersourcesettings, weatherdatalayout
     199                          WHERE weatherdatalayout.weatherscreens_screen_id=?
     200                          AND weathersourcesettings_sourceid=weathersourcesettings.sourceid', $this->screen_id);
     201
     202        list($script)  = $sh->fetch_row();
     203        if (!isset($script)) return;
     204
     205        // Find location
     206        $sh = $db->query('SELECT DISTINCT location from weatherdatalayout
     207                          WHERE weatherscreens_screen_id='. $this->screen_id);
     208        list($location) = $sh->fetch_row();
     209
     210        // Generate args and run the script
     211        $units = $this->units == 0 ? 'SI' : 'ENG';
     212        $output_array = $this->runScript($script, '-u '. $units .' -d '. getcwd() .'/'. cache_dir ." $location");
     213
     214        // Query db data items
     215        $sh = $db->query('SELECT weatherdatalayout.dataitem
     216                          FROM weatherdatalayout,weathersourcesettings
     217                          WHERE weatherscreens_screen_id='. $this->screen_id .'
     218                          AND weathersourcesettings_sourceid=weathersourcesettings.sourceid');
     219
     220        // Populate data array
     221        while(list($dataitem) = $sh->fetch_row()) {
     222            $this->data[$dataitem] = $output_array[$dataitem];
     223        }
     224    }
     225
     226    function runScript( $script, $args ) {
     227        $cwd = getcwd();
     228        $output_array = array();
     229
     230        // Separate path and filename of script
     231        $scratch = explode('/', $script);
     232        $script  = array_pop($scratch);
     233        $path    = implode('/', $scratch);
     234
     235        if (chdir($path)) {
     236            $command = "$script $args";
     237            $output = `./$command`;
     238        } else {
     239            custom_error("Could not change active directory to $path.\n");
     240        }
     241
     242        if (! chdir($cwd)) {
     243            custom_error("Could not change active directory to $cwd.\n");
     244        }
     245
     246        // Split script output into an array
     247        $scratch = preg_split('/\n/', $output);
     248        foreach ($scratch as $line) {
     249            list($key, $var) = preg_split('/::/', $line);
     250            if (strlen($key)) { $output_array[$key] = trim($var); }
     251        }
     252
     253        return $output_array;
     254    }
     255
     256    function updateLocation ( $source_id, $loc ) {
     257        global $db;
     258        if (! $this->checkScreenID()) { return; }
     259        if (strlen($loc) <= 0) { return; }
     260
     261        // Does this location have settings?
     262        $has_settings = $db->query_col('SELECT COUNT(weathersourcesettings_sourceid)
     263                                        FROM weatherdatalayout
     264                                        WHERE weatherscreens_screen_id=?',
     265                                        $this->screen_id);
     266       
     267        if ($has_settings) {
     268            $db->query('UPDATE weatherdatalayout
     269                        SET location=?, weathersourcesettings_sourceid=?
     270                        WHERE weatherscreens_screen_id=?',
     271                        $loc, $source_id, $this->screen_id);
     272        } else {
     273            $types = $db->query_col('SELECT types
     274                                     FROM weathersourcesettings
     275                                     WHERE sourceid=?',
     276                                     $source_id);
     277
     278            foreach(explode(',', $types) as $type) {
     279                $db->query('INSERT INTO weatherdatalayout
     280                            ( location, dataitem, weatherscreens_screen_id, weathersourcesettings_sourceid )
     281                            VALUES ( ?, ?, ?, ? )',
     282                            $loc, $type, $this->screen_id, $source_id);
     283            }
     284        }
     285    }
     286
     287    function updateUnits( $units ) {
     288        global $db;
     289        if (! $this->checkScreenID()) { return; }
     290        if ( ($units < 0) || ($units > 1) ) { return; }
     291
     292        $db->query('UPDATE weatherscreens
     293                    SET units=?
     294                    WHERE screen_id=?
     295                    AND hostname=?',
     296                    $units, $this->screen_id, $this->host);
     297
     298    }
     299}
     300 
  • mythplugins/mythweb/modules/weather/init.php

     
    1515
    1616// Settings options
    1717    $Settings['weather'] = array('name'    => t('Weather'),
    18                                  'choices' => array('prefs'  => t('Preferences'),
    19                                                    ),
    20                                  'default' => 'prefs',
     18                                 'choices' => array('screen' => 'Screen Settings'),
     19                                 'default' => 'screen',
    2120                                );
    2221
    2322// First, we should check to see that MythWeather is configured.
    24     $has_weather = $_SESSION['locale']
    25                     ? true
    26                     : $db->query_col('SELECT COUNT(data)
    27                                         FROM settings
    28                                        WHERE value="locale"');
     23    $has_weather = $db->query_col('SELECT COUNT(screen_id)
     24                                        FROM weatherscreens');
    2925
    30 
    31 
    3226// If weather is enabled, add it to the list.
    3327    if ($has_weather) {
    3428        $Modules['weather'] = array('path'        => 'weather',
  • mythplugins/mythweb/modules/weather/tmpl/default/set_screen.php

     
     1<?php
     2/**
     3 * Display/save MythWeather Screen settings
     4 *
     5 * @url         $URL$
     6 * @date        $Date$
     7 * @version     $Revision$
     8 * @author      $Author$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Weather
     13 *
     14/**/
     15?>
     16
     17<?php
     18
     19// Edit screen ------------------------------------------------------------
     20if (isset($_SESSION['weather']['edit'])) {
     21    $screen = new WeatherScreen($_SESSION['weather']['edit']);
     22    $screen->getData();
     23
     24    if (isset($_SESSION['weather']['search']))
     25        $screen->runSearch($_SESSION['weather']['search']);
     26?>
     27
     28<form class="form" method="post" action="<?php echo form_action ?>">
     29<input type="hidden" name="host" value="<?php echo html_entities($_SESSION['settings']['host']) ?>" />
     30<input type="hidden" name="edit" value="<?php echo $screen->screen_id ?>" />
     31
     32<table border="0" cellspacing="0" cellpadding="0">
     33<tr>
     34    <td colspan="2"><?php echo t('Edit Screen') ?></td>
     35</tr>
     36<tr>
     37    <th>Screen Name</th>
     38    <td><?php echo $screen->container ?></td>
     39</tr>
     40<tr>
     41    <th>Location</th>
     42    <td><?php
     43            foreach($screen->data as $key => $value) {
     44                if (preg_match('/location/', $key)) echo $value;
     45                if (preg_match('/desc/', $key)) echo $value;
     46            }
     47
     48        ?></td>
     49</tr>
     50
     51<?php if (isset($_SESSION['weather']['search'])) { ?>
     52<tr>
     53    <th>Search Results</th>
     54    <?php if (count($screen->search)) { ?>
     55    <td><select name="weather_location" size="1"><?php
     56        foreach($screen->search as $key => $value) {
     57            foreach ($value as $location => $description) {
     58                echo '<option value="(('. $key .'))'. $location .'">'. htmlentities($description) ."</option>\n";
     59            }
     60        }
     61        ?></select>
     62    </td>
     63</tr>
     64<tr>
     65    <th><input type="checkbox" name="weather_use_results"></th>
     66    <td>Use selected location</td>
     67</tr>
     68    <?php } else { ?>
     69    <td>Nothing found for &quot;<i><?php echo $_SESSION['weather']['search'] ?></i>&quot;</td>
     70    <?php } } ?>
     71</tr>
     72<tr>
     73    <th>Change Location</th>
     74    <td><input type="text" name="weather_search" size="15" value="<?php echo $_SESSION['weather']['search'] ?>"> <input type="submit" class="submit" name="edit_search" value="<?php echo t('Search') ?>"></td>
     75</tr>
     76<tr>
     77    <th>Units</th>
     78    <td><select name="weather_units">
     79            <option value="0" <?php echo $screen->units == 0 ? 'SELECTED' : '' ?>>SI</option>
     80            <option value="1" <?php echo $screen->units == 1 ? 'SELECTED' : '' ?>>English</option>
     81        </select>
     82    </td>
     83</tr>
     84<tr>
     85    <th></th>
     86    <td>
     87        <input type="submit" class="submit" name="save_edit" value="<?php echo t('Save') ?>">
     88        <input type="submit" class="submit" name="cancel_edit" value="<?php echo t('Cancel') ?>">
     89    </td>
     90</tr>
     91</table>
     92
     93</form>
     94
     95<?php // Define screens ----------------------------------------------------------
     96} else {
     97?>
     98
     99<form class="form" method="post" action="<?php echo form_action ?>">
     100<input type="hidden" name="host" value="<?php echo html_entities($_SESSION['settings']['host']) ?>" />
     101
     102<table border="0" cellspacing="0" cellpadding="0">
     103<tr>
     104    <td colspan="2"><?php echo t('Inactive Screens') ?></td>
     105</tr>
     106<tr class="-sep">
     107    <td> <?php display_inactive_screens() ?> </td>
     108    <?php if (count($_SESSION['weather']['inactive']) > 0) { ?>
     109    <td><input type="submit" class="submit" name="add" value="<?php echo t('Add To Active Screens') ?>"></td>
     110    <?php } ?>
     111</tr>
     112</table>
     113
     114<table border="0" cellspacing="0" cellpadding="0">
     115<tr>
     116    <td colspan="2"><?php echo t('Active Screens') ?></td>
     117</tr>
     118<tr>
     119    <td><?php display_active_screens() ?></th>
     120    <td>
     121        <table border="0" cellspacing="0" cellpadding="0">
     122            <tr><td><input type="submit" class="submit" name="move_u" value="<?php echo t('Up') ?>"></td></tr>
     123            <tr><td><input type="submit" class="submit" name="move_d" value="<?php echo t('Down') ?>"></td></tr>
     124            <tr><td><input type="submit" class="submit" name="edit" value="<?php echo t('Edit') ?>"></td></tr>
     125            <tr><td><input type="submit" class="submit" name="delete" value="<?php echo t('Delete') ?>"></td></tr>
     126        </table>
     127    </td>
     128</tr>
     129</table>
     130
     131</form>
     132<?php }
     133
  • mythplugins/mythweb/modules/weather/tmpl/default/welcome.php

     
    99 * @license     GPL
    1010 *
    1111 * @package     MythWeb
     12 * @subpackage  Weather
    1213 *
    1314/**/
    1415
     
    2324    ####
    2425
    2526// Close the div
    26          "</div>\n";
    27  No newline at end of file
     27         "</div>\n";
  • mythplugins/mythweb/modules/weather/tmpl/default/weather.am.php

     
     1<?php
     2/**
     3 * Display template for Animated Maps for the Weather module
     4 a
     5 * @url         $URL$
     6 * @date        $Date$
     7 * @version     $Revision$
     8 * @author      $Author$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Weather
     13 *
     14/**/
     15?>
     16    <div class="radar">
     17        <h2><?php echo $screen->data["amdesc"] ?></h2>
     18
     19        <div class="radar_image"><center>
     20        <script type='text/javascript'>
     21        <!--
     22
     23        images  = new Array();
     24        imageNum = 0;
     25        speed = 3;
     26        delay = 300;
     27<?php
     28            $matches = array();
     29            $image = array_pop(split('/', $screen->data["animatedimage"]));
     30            preg_match("/(.*)-\%1-(\d*)-(\d*)x(\d*)/", $image, $matches);
     31       
     32            echo "imageTotal = ". $matches[2] .";\n";
     33            for ($i=0; $i<$matches[2]; $i++)  {
     34                echo "images[$i] = new Image();\n";
     35                echo "images[$i].src = \"/". cache_dir ."/". $matches[1] ."-$i\";\n";
     36            }
     37?>
     38        function nextFrame (inc) {
     39            // display next frame from images array
     40            imageNum += inc;
     41            if (imageNum >= imageTotal) {
     42                imageNum = 0;
     43            }
     44   
     45            imageCurrent = imageNum;
     46            document.animation.src = images[imageCurrent].src;
     47        }
     48
     49        function animate() {
     50            // start animation loop
     51            nextFrame(1);
     52        }
     53
     54        function setDelay(i) {
     55            speed = i;
     56            delay =  speed * 100;
     57            if (delay == 0) delay = 50;
     58        }
     59
     60        output  = '<form name="animap" id="animap" action="get">'
     61        output += '<b>Slower</b> '
     62<?php
     63        for ($i=6;$i>=0;$i-=1)  {
     64            echo "output += '<input type=\"radio\" name=\"speedRadio\" value=\"". $i. "\" onClick=\"setDelay(". $i .")\"";
     65            if ($i == 3) { echo " checked"; }
     66            echo ">'\n";
     67        }
     68?>
     69
     70        output += ' <b>Faster</b><br>'
     71        output += '<img name="animation" src="<?php echo "/". cache_dir ."/". $matches[1] ."-0" ?>" alt="Animation" onload="setTimeout(\'animate()\', delay)" />'
     72        output += '</form>'
     73        document.write(output);
     74
     75        // -->
     76        </script>
     77        </center>
     78        </div>
     79    </div>
     80
  • mythplugins/mythweb/modules/weather/tmpl/default/weather.sm.php

     
     1<?php
     2/**
     3 * Display template for Static Maps for the Weather module
     4 a
     5 * @url         $URL$
     6 * @date        $Date$
     7 * @version     $Revision$
     8 * @author      $Author$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Weather
     13 *
     14/**/
     15?>
     16
     17<?php
     18    $image = array_pop(split('/', $screen->data['map']));
     19    $matches = array();
     20    preg_match('/(.*)-\d*x\d*/', $image, $matches);
     21?>
     22
     23
     24
     25    <div class="radar">
     26        <h2><?php echo $screen->data["smdesc"] ?></h2>
     27
     28        <div class="radar_image">
     29            <center>
     30                <img name="static_map" src="<?php echo '/'. cache_dir .'/'. $matches[1] ?>" alt="Static Map" />
     31            </center>
     32        </div>
     33    </div>
     34
  • mythplugins/mythweb/modules/weather/tmpl/default/weather.18h.php

     
     1<?php
     2/**
     3 * Display template for 18 Hour Forecast for the Weather module
     4 *
     5 * @url         $URL$
     6 * @date        $Date$
     7 * @version     $Revision$
     8 * @author      $Author$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Weather
     13 *
     14/**/
     15?>
     16    <p class="host"><?php
     17        echo t('Host') .": ".  $screen->host;
     18    ?></p>
     19    <p class="location"><?php
     20        echo $screen->data["18hrlocation"]
     21    ?></p>
     22
     23    <div class="forecast clearfix">
     24        <h2><?php echo $screen->container ?></h2>
     25
     26        <?php
     27            for($i=0;$i<6;$i++) {
     28        ?>
     29
     30        <div class="daily_forecast">
     31            <h3><?php echo $screen->data["time-$i"] ?></h3>
     32            <img src="<?php echo skin_url ?>img/weather/<?php echo $screen->data["18icon-$i"] ?>" class="alpha_png" />
     33
     34            <div class="temps">
     35                <div class="high">
     36                    <p class="temp">
     37                        <?php echo $screen->data["temp-$i"] == 'NA' ? '' : $screen->data["temp-$i"] ?>&deg;<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup>
     38                    </p>
     39                </div>
     40            </div>
     41        </div>
     42        <?php } ?>
     43    </div>
     44
  • mythplugins/mythweb/modules/weather/tmpl/default/weather.php

     
    99 * @license     GPL
    1010 *
    1111 * @package     MythWeb
     12 * @subpackage  Weather
    1213 *
    1314/**/
    1415
     
    2122// Print the page header
    2223    require 'modules/_shared/tmpl/'.tmpl.'/header.php';
    2324
    24 // Print Information for each of the known weather sites.
    25     foreach ($WeatherSites as $accid => $site) {
     25// Print Information for each of the screensa
    2626?>
    2727<div class="weather_site">
    28     <p class="host"><?php
    29         echo tn('Host', 'Hosts', count($site->hosts)), ': ',
    30              implode(', ', $site->hosts);
    31     ?></p>
    32     <p class="location"><?php
    33             echo "$site->acid: $site->city, ",
    34                  ($site->subdiv ? "$site->subdiv, " : ''),
    35                  $site->country;
    36     ?></p>
    37 
    38     <div class="current_conditions clearfix">
    39         <h2><?php echo t('Current Conditions') ?>:</h2>
    40 
    41         <div class="overview">
    42             <img src="<?php echo skin_url ?>img/weather/<?php echo $site->ConditionImage ?>" class="alpha_png" />
    43             <h3><?php echo $site->ConditionText ?></h3>
    44             <p class="temp">
    45                 <?php echo $site->Temperature ?>&deg;<sup><?php echo (strcasecmp($site->use_metric, 'YES') == 0) ? 'C' : 'F' ?></sup>
    46             </p>
    47         </div>
    48 
    49         <table border="0" cellspacing="0" cellpadding="0">
    50         <tr>
    51             <th><?php echo t('Humidity') ?></th>
    52             <td><?php echo $site->Humidity ?>%</td>
    53         </tr><tr>
    54             <th><?php echo t('Pressure') ?></th>
    55             <td><?php echo $site->BarometricPressure; if($site->use_metric == "YES") echo " cm"; else echo " in" ?> </td>
    56         </tr><tr>
    57             <th><?php echo t('Wind') ?></th>
    58             <td><?php echo $site->WindDirection . t(' at ') .  $site->WindSpeed; if($site->use_metric == "YES") echo " kph"; else echo " mph" ?></td>
    59         </tr><tr>
    60             <th><?php echo t('Visibility') ?></th>
    61             <td><?php echo $site->Visibility; if($site->use_metric == "YES") echo " km"; else echo " mi" ?></td>
    62         </tr><tr>
    63             <th><?php echo t('Wind Chill') ?></th>
    64             <td class="temp"><?php echo $site->Real.'&deg;<sup>';
    65                       echo (strcasecmp($site->use_metric, 'YES') == 0) ? 'C' : 'F';
    66                 ?></sup></td>
    67         </tr><tr>
    68             <th><?php echo t('UV Index') ?></th>
    69             <td><?php
    70                     echo $site->UV . " (";
    71                     if     ($site->UV < 3)  echo t('UV Minimal');
    72                     elseif ($site->UV < 6)  echo t('UV Moderate');
    73                     elseif ($site->UV < 8)  echo t('UV High');
    74                     else                    echo t('UV Extreme');
    75                 ?>)</td>
    76         </tr>
    77         </table>
    78     </div>
    79 
    80     <div class="forecast clearfix">
    81         <h2><?php echo t('Forecast') ?>:</h2>
    82 
    8328<?php
    84             for ($i=0; $i<6; $i++) {
    85                 $forecast = $site->Forecast[$i];
    86                 if (!$forecast)
    87                     break;
     29    foreach ($WeatherScreens as $screen) {
     30        if ($screen->container == 'Current Conditions')
     31            require tmpl_dir.'weather.cc.php';
     32        if ($screen->container == '18 Hour Forecast')
     33            require tmpl_dir.'weather.18h.php';
     34        if ($screen->container == 'Three Day Forecast')
     35            require tmpl_dir.'weather.3d.php';
     36        if ($screen->container == 'Six Day Forecast')
     37            require tmpl_dir.'weather.6d.php';
     38        if ($screen->container == 'Static Map')
     39            require tmpl_dir.'weather.sm.php';
     40        if ($screen->container == 'Animated Map')
     41            require_once tmpl_dir.'weather.am.php';
     42    }
    8843?>
    89         <div class="daily_forecast">
    90             <h3><?php
    91 
    92                 $today = date("m/d/Y");
    93                 $tomorrow = date("m/d/Y", mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")));
    94 
    95                 switch($forecast->dayofweek) {
    96                     case 0:  $day = t('Sunday');        break;
    97                     case 1:  $day = t('Monday');        break;
    98                     case 2:  $day = t('Tuesday');       break;
    99                     case 3:  $day = t('Wednesday');     break;
    100                     case 4:  $day = t('Thursday');      break;
    101                     case 5:  $day = t('Friday');        break;
    102                     case 6:  $day = t('Saturday');      break;
    103                     default: $day = $forecast->date;    break;
    104                 }
    105 
    106                 if ($forecast->date == $today)
    107                     echo t('Today')." ($day)";
    108                 elseif ($forecast->date == $tomorrow)
    109                     echo t('Tomorrow')." ($day)";
    110                 else
    111                     echo $day;
    112 
    113                 ?></h3>
    114 
    115             <img src="<?php echo skin_url ?>img/weather/<?php echo $forecast->DescImage ?>" class="alpha_png" />
    116 
    117             <h3><?php echo $forecast->DescText ?></h3>
    118 
    119             <div class="temps">
    120                 <div class="low">
    121                     <p><?php echo t('Low') ?></p>
    122                     <p class="temp">
    123                         <?php echo $forecast->LowTemperature ?>&deg;<sup><?php echo (strcasecmp($site->use_metric, 'YES') == 0) ? 'C' : 'F' ?></sup>
    124                     </p>
    125                 </div>
    126                 <div class="high">
    127                     <p><?php echo t('High') ?></p>
    128                     <p class="temp">
    129                         <?php echo $forecast->HighTemperature ?>&deg;<sup><?php echo (strcasecmp($site->use_metric, 'YES') == 0) ? 'C' : 'F' ?></sup>
    130                     </p>
    131                 </div>
    132             </div>
    133         </div>
    134 <?php       } ?>
    135 
    136     </div>
    137 
    138     <div class="radar">
    139 
    140         <h2><?php echo t('Radar') ?>:</h2>
    141 
    142         <div class="radar_image">
    143             <img src="<?php echo $site->RadarImage ?>" />
    144         </div>
    145 
    146     </div>
    147 
    148     <p class="last_updated">
    149         <?php echo t('Last Updated') ?>: <?php echo $site->LastUpdated ?>
    150     </p>
    15144</div>
     45
    15246<?php
    153     }
    15447
    15548// Print the page footer
    15649    require 'modules/_shared/tmpl/'.tmpl.'/footer.php';
  • mythplugins/mythweb/modules/weather/tmpl/default/weather.cc.php

     
     1<?php
     2/**
     3 * Display template for Current Conditions for the Weather module
     4 *
     5 * @url         $URL$
     6 * @date        $Date$
     7 * @version     $Revision$
     8 * @author      $Author$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Weather
     13 *
     14/**/
     15?>
     16    <p class="host"><?php
     17        echo t('Host') .": ".  $screen->host;
     18    ?></p>
     19    <p class="location"><?php
     20        echo $screen->data["cclocation"]
     21    ?></p>
     22
     23    <div class="current_conditions clearfix">
     24        <h2><?php echo t($screen->container) ?></h2>
     25
     26        <div class="overview">
     27            <img src="<?php echo skin_url ?>img/weather/<?php echo $screen->data["weather_icon"] ?>" class="alpha_png" />
     28            <h3><?php echo $screen->data["weather"] ?></h3>
     29            <p class="temp">
     30                <?php echo $screen->data["temp"] ?>&deg;<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup>
     31            </p>
     32        </div>
     33
     34        <table border="0" cellspacing="0" cellpadding="0">
     35        <tr>
     36            <th><?php echo t('Humidity') ?></th>
     37            <td><?php echo $screen->data["relative_humidity"] ?>%</td>
     38        </tr><tr>
     39            <th><?php echo t('Pressure') ?></th>
     40            <td><?php echo $screen->data["pressure"]; echo $screen->units == 0 ? ' mb' : ' in' ?></td>
     41        </tr><tr>
     42            <th><?php echo t('Wind') ?></th>
     43            <td><?php echo $screen->data["wind_dir"] . t(' at ') . $screen->data["wind_spdgst"]; echo $screen->units == 0 ? ' km/h' : ' mph' ?></td>
     44        </tr><tr>
     45            <th><?php echo t('Visibility') ?></th>
     46            <td><?php echo $screen->data["visibility"]; echo $screen->units == 0 ? ' km' : ' mi' ?></td>
     47        </tr><tr>
     48            <th><?php echo t('Wind Chill') ?></th>
     49            <td><?php echo $screen->data["appt"] . '&deg;<sup>'; echo $screen->units == 0 ? 'C' : 'F' ?></sup></td>
     50        </tr><tr>
     51            <td colspan="2"><?php echo $screen->data["observation_time"] ?></td>
     52        </tr>
     53        </table>
     54    </div>
     55
  • mythplugins/mythweb/modules/weather/tmpl/default/weather.3d.php

     
     1<?php
     2/**
     3 * Display template for Three Day Forecast for the Weather module
     4 *
     5 * @url         $URL$
     6 * @date        $Date$
     7 * @version     $Revision$
     8 * @author      $Author$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Weather
     13 *
     14/**/
     15?>
     16    <p class="host"><?php
     17        echo t('Host') .": ".  $screen->host;
     18    ?></p>
     19    <p class="location"><?php
     20        echo $screen->data["3dlocation"]
     21    ?></p>
     22
     23    <div class="forecast clearfix">
     24        <h2><?php echo $screen->container ?></h2>
     25
     26        <?php
     27            for($i=0;$i<3;$i++) {
     28        ?>
     29
     30        <div class="daily_forecast">
     31            <h3><?php echo $screen->data["date-$i"] ?></h3>
     32            <img src="<?php echo skin_url ?>img/weather/<?php echo $screen->data["icon-$i"] ?>" class="alpha_png" />
     33
     34            <div class="temps">
     35                <div class="low">
     36                    <p><?php echo t('Low') ?></p>
     37                    <p class="temp">
     38                        <?php echo $screen->data["low-$i"] == 'NA' ? '' : $screen->data["low-$i"] ?>&deg;<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup>
     39                    </p>
     40                </div>
     41
     42                <div class="high">
     43                    <p><?php echo t('High') ?></p>
     44                    <p class="temp">
     45                        <?php echo $screen->data["high-$i"] == 'NA' ? '' : $screen->data["high-$i"] ?>&deg;<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup>
     46                    </p>
     47                </div>
     48            </div>
     49        </div>
     50        <?php } ?>
     51    </div>
     52
  • mythplugins/mythweb/modules/weather/tmpl/default/weather.6d.php

     
     1<?php
     2/**
     3 * Display template for Six Day Forecast for the Weather module
     4 *
     5 * @url         $URL$
     6 * @date        $Date$
     7 * @version     $Revision$
     8 * @author      $Author$
     9 * @license     GPL
     10 *
     11 * @package     MythWeb
     12 * @subpackage  Weather
     13 *
     14/**/
     15?>
     16    <p class="host"><?php
     17        echo t('Host') .": ".  $screen->host;
     18    ?></p>
     19    <p class="location"><?php
     20        echo $screen->data["6dlocation"]
     21    ?></p>
     22
     23    <div class="forecast clearfix">
     24        <h2><?php echo $screen->container ?></h2>
     25
     26        <?php
     27            for($i=0;$i<6;$i++) {
     28        ?>
     29
     30        <div class="daily_forecast">
     31            <h3><?php echo $screen->data["date-$i"] ?></h3>
     32            <img src="<?php echo skin_url ?>img/weather/<?php echo $screen->data["icon-$i"] ?>" class="alpha_png" />
     33
     34            <div class="temps">
     35                <div class="low">
     36                    <p><?php echo t('Low') ?></p>
     37                    <p class="temp">
     38                        <?php echo $screen->data["low-$i"] == 'NA' ? '' : $screen->data["low-$i"] ?>&deg;<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup>
     39                    </p>
     40                </div>
     41
     42                <div class="high">
     43                    <p><?php echo t('High') ?></p>
     44                    <p class="temp">
     45                        <?php echo $screen->data["high-$i"] == 'NA' ? '' : $screen->data["high-$i"] ?>&deg;<sup><?php echo $screen->units == 0 ? 'C' : 'F' ?></sup>
     46                    </p>
     47                </div>
     48            </div>
     49        </div>
     50        <?php } ?>
     51    </div>
     52