<?php

$events_default_duration
=2;

// iCal

if (!function_exists('quoted_printable_encode')) {
  function 
quoted_printable_encode$sString ) {
      
$sString preg_replace'/[^\x21-\x3C\x3E-\x7E\x09\x20]/e''sprintf( "=%02x", ord ( "$0" ) ) ;',  $sString );
    return 
$sString;
  }
}

function 
sf_theme_events_ical_text($text) {
    
$search = array ('/"/',
        
'/,/',
        
'/\n/',
        
'/\r/',
        
'/:/',
        
'/;/',
        
'/\\\\/');
    
$replace = array ('\"',
        
'\\,',
        
'\\n',
        
'',
        
'\\:',
        
'\\;',
        
'\\\\'); 
    list(
$field$text)=explode(':',$text,2);
    
$text=utf8_decode($text);
    
$text $field.':'.preg_replace($search$replace$text); 
    
$split '';
    while (
strlen($text)>=70 && preg_match('|^([^\n]{1,70})([^= ]{3}?.*)$|s',$text,$M)) {
        
$split $split.$M[1]."\r\n ";
        
$text $M[2];
    }
    
$text str_replace("\\\r\n ","\r\n \\",$split.$text);
    return 
$text;
}

function 
sf_theme_events_ical($limit=0) {
    global 
$sf_theme_events_table$wpdb$events_default_duration;

    
# Header...    
    
header('Content-Type: text/calendar; charset=ISO-8859-1');
    
header('Cache-Control: public');
    print 
"BEGIN:VCALENDAR\r\n";
    print 
"PRODID:-//WordPress//SF Theme ".SF_THEME_VERSION."//EN\r\n";
    print 
"VERSION:2.0\r\n";
    print 
sf_theme_events_ical_text("X-WR-CALNAME:".get_bloginfo_rss('name'))."\r\n";
    print 
"X-WR-TIMEZONE:Europe/Copenhagen\r\n";
    print 
"CALSCALE:GREGORIAN\r\n";
    print 
"METHOD:PUBLISH\r\n";

    
# Timezone
    
print "BEGIN:VTIMEZONE\r\n";
    print 
"TZID:Europe/Copenhagen\r\n";
    
$tzsd=array('20051030'=>'STANDARD','20061029'=>'STANDARD','20071028'=>'STANDARD','20081026'=>'STANDARD',
            
'20050327'=>'DAYLIGHT','20060326'=>'DAYLIGHT','20070325'=>'DAYLIGHT','20080330'=>'DAYLIGHT');
    
ksort($tzsd);
    foreach (
$tzsd as $dt => $tz) {
        print 
"BEGIN:$tz\r\n";
        print 
"DTSTART:".$dt."T030000\r\n";
        print 
"TZOFFSETTO:+".("STANDARD"==$tz?"01":"02")."00\r\n";
        print 
"TZOFFSETFROM:+".("STANDARD"==$tz?"02":"01")."00\r\n";
        print 
"TZNAME:".("STANDARD"==$tz?"CET":"CEST")."\r\n";
        print 
"END:$tz\r\n";
    }
    print 
"END:VTIMEZONE\r\n";

    
# All events...
    
if ($limit) {
        
$now date('Y-m-d');
        
$where "WHERE DATE_FORMAT(begin_time,'%Y-%m-%d') >= '$now' ";
        
$limit 'LIMIT '.$wpdb->escape($limit);
    } else {
        
$where '';
        
$limit '';
    }
    
$events $wpdb->get_results("SELECT * FROM $sf_theme_events_table $where ORDER BY begin_time $limit");
    if (
is_array($events)) {
      foreach (
$events as $event) {
          print 
"BEGIN:VEVENT\r\n";
          if (
$event->title)
              print 
sf_theme_events_ical_text("SUMMARY:".strip_tags($event->title))."\r\n";
          if (
$event->description)
              print 
sf_theme_events_ical_text('DESCRIPTION:'.strip_tags($event->description))."\r\n";
          if (
$event->location) {
              print 
sf_theme_events_ical_text("LOCATION:".strip_tags($event->location))."\r\n";
              if (
class_exists('GeoPress') and is_callable(array('GeoPress','get_locations'))) {
                
$locations GeoPress::get_locations();
                foreach (
$locations as $location) {
                    if (
$location->name == $event->location) {
                        
$coords split(' '$location->coord);
                        print 
sf_theme_events_ical_text("GEO:").$coords[0].';'.$coords[1]."\r\n";
                        continue;
                    }
                }
              }
          }
          print 
"DTSTART;TZID=Europe/Copenhagen:".mysql2date('Ymd\THis',$event->begin_time)."\r\n";
          print 
"DTEND;TZID=Europe/Copenhagen:".('0000-00-00 00:00:00'!=$event->end_time?mysql2date('Ymd\THis',$event->end_time):date('Ymd\THis',mysql2date('U',$event->begin_time)+$events_default_duration*3600))."\r\n";
          print 
"CREATED:".gmdate('Ymd\THis\Z',mysql2date('U',$event->created))."\r\n";
          if (
'0000-00-00 00:00:00'!=$event->modified)
              print 
"LAST-MODIFIED:".gmdate('Ymd\THis\Z',mysql2date('U',$event->modified))."\r\n";
          print 
"UID:event".$event->ID.md5(join('',$_REQUEST)).'-'.md5(get_bloginfo('name')).'@'.preg_replace('|^http://([a-z0-9.-]+)|i','$1',get_bloginfo('home'))."\r\n";
          print 
"TRANSP:TRANSPARENT\r\n";
          print 
"CLASS:PUBLIC\r\n";
          print 
"END:VEVENT\r\n";
      }
    }
    print 
"END:VCALENDAR\r\n";
}

function 
sf_theme_events_today_count() {
    global 
$sf_theme_events_table$wpdb;

    
$now=date('Y-m-d');
    return 
$wpdb->get_var("SELECT count(*) FROM $sf_theme_events_table WHERE DATE_FORMAT(begin_time,'%Y-%m-%d') = '$now'");
}

function 
sf_theme_events_today($header=false$description=true) {
    global 
$sf_theme_events_table$wpdb;

    
$now=date('Y-m-d');
    
$events $wpdb->get_results("SELECT * FROM $sf_theme_events_table WHERE DATE_FORMAT(begin_time,'%Y-%m-%d') = '$now'");
    
    
sf_theme_events_formatted($events$header$description);
}

function 
sf_theme_events_in_the_future_count() {
    global 
$sf_theme_events_table$wpdb;

    
$now=date('Y-m-d');
    return 
$wpdb->get_var("SELECT count(*) FROM $sf_theme_events_table WHERE DATE_FORMAT(begin_time,'%Y-%m-%d') >= '$now'");
}

function 
sf_theme_events_in_the_future($limit=0$header=true$description=true) {
    global 
$sf_theme_events_table$wpdb;

    
$now=date('Y-m-d');
    
$limit $limit?'LIMIT '.$wpdb->escape($limit):'';
    
$events $wpdb->get_results("SELECT * FROM $sf_theme_events_table WHERE DATE_FORMAT(begin_time,'%Y-%m-%d') >= '$now' ORDER BY begin_time $limit");
    
    
sf_theme_events_formatted($events$header$description);
}

function 
sf_theme_events_in_the_past_count() {
    global 
$sf_theme_events_table$wpdb;

    
$now=date('Y-m-d');
    return 
$wpdb->get_var("SELECT count(*) FROM $sf_theme_events_table WHERE DATE_FORMAT(begin_time,'%Y-%m-%d') < '$now'");
}

function 
sf_theme_events_in_the_past($limit=0$header=true$description=true) {
    global 
$sf_theme_events_table$wpdb;

    
$now=date('Y-m-d');
    
$limit $limit?'LIMIT '.$wpdb->escape($limit):'';
    
$events $wpdb->get_results("SELECT * FROM $sf_theme_events_table WHERE DATE_FORMAT(begin_time,'%Y-%m-%d') < '$now' ORDER BY begin_time DESC $limit");
    
    
sf_theme_events_formatted($events$header$description);
}

function 
sf_theme_events_formatted($events$header$description) {
    global 
$events_default_duration$post;

    print 
"\n<div>";
    
$lasty=date('Y');
    
$lastm='';
    foreach (
$events as $event) {
        
$y=mysql2date('Y',$event->begin_time);
        
$m=mysql2date('n',$event->begin_time);
        
$d=mysql2date('j',$event->begin_time);
        if (
$lastm!=$m && $lastm!='' && $header)
            print 
'</ul>';
        if (
$lasty!=$y && $header)
            print 
'<h2 class="events">'.$y.'</h2>';
        if (
$lastm!=$m) {
            if (
$header) {
            print 
'<h3 class="events">';
            print 
ucfirst(mysql2date('F',$event->begin_time));
            print 
'</h3>';
            }
            if (
$header || ''==$lastm)
                print 
'<ul class="events vcalendar">';
        }
        print 
'<li class="vevent"><abbr class="dtstart date eventid'.$event->ID.'" title="'.date('Ymd\THis\Z',mysql2date('U',$event->begin_time) - (get_settings('gmt_offset') * 3600)).'">';
        print 
ucfirst(mysql2date('l',$event->begin_time));
        print 
' den ';
        print 
$d.'.</abbr> ';
        print 
' kl. ';
        print 
'<abbr class="dtend" title="'.('0000-00-00 00:00:00'!=$event->end_time?date('Ymd\THis\Z',mysql2date('U',$event->end_time) - (get_settings('gmt_offset') * 3600)):date('Ymd\THis\Z',mysql2date('U',$event->begin_time) + $events_default_duration*3600 - (get_settings('gmt_offset') * 3600))).'">';
        print 
mysql2date('G:i',$event->begin_time).'</abbr>';
        print 
': <span class="summary title">'.$event->title.'</span> ';
        if (
$header && is_page() && $post->ID==sf_theme_get_event_page(true) && is_user_logged_in())
            print 
'<a href="/wp-admin/edit.php?page=sf_theme_events&amp;action=edit&amp;id='.$event->ID.'">[redigér]</a> ';
        if (
$description && ''!=$event->description)
            print 
'<span class="description">'.$event->description.'</span> ';
        if (
$event->location) {
            if (
class_exists('GeoPress') and is_callable(array('GeoPress','get_locations'))) {
                
$locations GeoPress::get_locations();
                foreach (
$locations as $location) {
                    if (
$location->name == $event->location) {
                        
$coords split(' '$location->coord);
                        print 
'<span class="location vcard">';
                        print 
'<abbr class="geo" title="'.$coords[0].';'.$coords[1].'">';
                        print 
'<span class="fn"><a href="http://maps.google.com/?q='.$coords[0].','.$coords[1].'">';
                        print 
$event->location;
                        print 
'</a>';
                        if (!
preg_match('|^\[.+?,.+?\]$|'$location->loc) && preg_match('|^(.+?),\s+?(\d\d\d\d(\s+\S+.+)?)$|'$location->loc$L)) {
                            print 
'</span>, <span class="adr"><a href="http://findvej.dk/'.$location->loc.'"><span class="street-address">';
                            print 
$L[1];
                            print 
'</span>, <span class="postal-code">';
                            print 
$L[2];
                            print 
'</span></a>';
                        }
                        print 
'</span></abbr></span>';
                        continue;
                    }
                }
            } else
                print 
'<span class="location">'.$event->location.'</span>';
        }
        print 
'</li>';
        
$lasty=$y;
        
$lastm=$m;
    }
    if (
sizeof($events))
      print 
"</ul>";
    print 
"</div>\n";
}

// administration panel
function sf_theme_events_admin_page() {
    global 
$sf_theme_events_table$wpdb;

$wpvarstoreset = array('action','title','description','location','year','month','day','time''id');
for (
$i=0$i<count($wpvarstoreset); $i += 1) {
    
$wpvar $wpvarstoreset[$i];
    if (!isset($
$wpvar)) {
        if (empty(
$_POST["$wpvar"])) {
            if (empty(
$_GET["$wpvar"])) {
                $
$wpvar '';
            } else {
                $
$wpvar stripslashes($_GET["$wpvar"]);
            }
        } else {
            $
$wpvar stripslashes($_POST["$wpvar"]);
        }
    }
}

    
$created=0;
    
$form_header='Tilføj aktivitet:';
    
$form_year=date('Y');
    
$form_month=date('m');
    
$form_day=date('d');
    
$form_time=date('H:i');
    
$form_title='';
    
$form_description='';
    
$form_location='';
    
$form_action='add';
    
$form_submit='Tilføj';

    switch(
$action) {
    case 
'update':
    case 
'delete':
        if (
''==$id)
            die (
__('Fejl, kunne ikke finde den ønskede aktivitet.'));
        
$created=$wpdb->get_var("SELECT created FROM $sf_theme_events_table WHERE id='".$wpdb->escape($id)."'");
        
$wpdb->query("DELETE FROM $sf_theme_events_table WHERE id='".$wpdb->escape($id)."'");
        if (
'delete'==$action) {
      print 
'<div id="message" class="updated fade"><p>'.__('Aktiviteten er nu slettet fra kalenderen.').'</p></div>';
            break;
        }
    case 
'add':
        list(
$hour,$minute)=split(':',$time);
        if (!
preg_match('|^\d\d:\d\d$|',$time) || !$hour && $hour!='00' || $hour>24
                
|| !$minute && $minute!='00' || $minute>59)
            die (
__('Fejl, ugyldigt tidspunkt for aktivitet ('.$time.').'));
        if (!
preg_match('|^\d\d\d\d$|',$year) || !$year
                
|| !preg_match('|^\d\d$|',$month) || !$month || $month>12
                
|| !preg_match('|^\d\d$|',$day) || !$day || $day>31)
            die (
__('Fejl, ugyldigt dato for aktivitet ('.$year.'-'.$month.'-'.$day.').'));
        
$begin="$year-$month-$day $hour:$minute";
        
sf_theme_events_add_event($begin,$title,nl2br($description),$location,$id,$created);
        if (
'add'==$action)
      print 
'<div id="message" class="updated fade"><p>'.__('Aktiviteten er nu tilføjet kalenderen.').'</p></div>';
        else
      print 
'<div id="message" class="updated fade"><p>'.__('Aktiviteten er nu opdateret i kalenderen.').'</p></div>';
      break;
    case 
'edit':
        
$events $wpdb->get_results("SELECT * FROM $sf_theme_events_table WHERE ID='".$wpdb->escape($id)."'");
        
$event array_shift($events);
        
$form_header='Redigér aktivitet:<input type="hidden" name="id" value="'.$id.'"/>';
        
$form_year=mysql2date('Y',$event->begin_time);
        
$form_month=mysql2date('m',$event->begin_time);
        
$form_day=mysql2date('d',$event->begin_time);
        
$form_time=mysql2date('H:i',$event->begin_time);
        
$form_title=$event->title;
        
$form_description=preg_replace('|<br\s*/>|','',$event->description);
        
$form_location=$event->location;
        
$form_action='update';
        
$form_submit='Opdatér';
      break;
    } 
// switch
?>
<div class=wrap>
    <form name="event" method="post" action="<?php print add_query_arg('id'false); ?>">
        <h2><?php print $form_header?></h2>
        <fieldset>
            <p style="float: right"><a href="<?php print sf_theme_get_event_page(); ?>">Kalender</a></p>

            <p>Tidspunkt:<br />
            <input type="text" name="year" size="4" maxlength="4" value="<?php print $form_year?>"/>
            <input type="text" name="month" size="2" maxlength="2" value="<?php print $form_month?>"/>
            <input type="text" name="day" size="2" maxlength="2" value="<?php print $form_day?>"/>
            kl.
            <input type="text" name="time" size="5" maxlength="5" value="<?php print $form_time?>"/>
            </p>

            <p>Overskrift:<br />
            <input type="text" name="title" size="40" value="<?php print $form_title?>"/>
            </p>

            <p>Detaljer:<br />
            <textarea name="description" rows="5" cols="50" style="width: 99%;"><?php print $form_description?></textarea>
            </p>

            <p>Sted:<br />
    <?php 
    
if (class_exists('GeoPress') and is_callable(array('GeoPress','get_locations'))) {
        print 
'<select name="location">';
        print 
'<option value="">(intet)</option>';
        
$locations GeoPress::get_locations();
        foreach (
$locations as $location)
            print 
'<option '.($form_location==$location->name?'selected="selected" ':'').'value="'.htmlspecialchars($location->name).'">'.htmlspecialchars($location->name).'</option>';
        print 
'</select>';
    } else {
    
?>
            <input type="text" name="location" size="40" value="<?php print $form_location?>"/>
    <?php
    
}
    
?>
            </p>

            <p class="submit">
            <input type="hidden" name="action" value="<?php print $form_action?>" />
            <input type="submit" name="submit" value="<?php print $form_submit?>" />
            </p>

        </fieldset>
    </form>
<?php if ('edit'!=$action) { ?>
    <form name="events" method="post">
        <h2 title="<?php print current_time('mysql'); ?>">Fremtidige aktiviter:</h2>
        <fieldset>
<table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
    <tr>
        <th scope="col">Tidspunkt</th>
        <th scope="col">Beskrivelse</th>
        <th scope="col" colspan="2">Handling</th>
    </tr>
<?php
  $now 
date('Y-m-d');
    
$events $wpdb->get_results("SELECT * FROM $sf_theme_events_table WHERE DATE_FORMAT(begin_time,'%Y-%m-%d') >= '$now' ORDER BY begin_time");
    if (
is_array($events)) {
        
$alternate=1;
        foreach (
$events as $event) {
            print 
'<tr'.($alternate?' class="alternate"':'').'><td title="'.mysql2date(get_settings('date_format'),$event->created).' '.mysql2date(get_settings('time_format'),$event->created).('0000-00-00 00:00:00'!=$event->modified?' / '.mysql2date(get_settings('date_format'),$event->modified).' '.mysql2date(get_settings('time_format'),$event->modified):'').'">'.mysql2date(get_settings('date_format'),$event->begin_time).' '.mysql2date(get_settings('time_format'),$event->begin_time).'</td>';
            print 
'<td><strong>'.$event->title.'</strong><br/>'.$event->description.($event->location?'<br/>Sted: '.$event->location:'').'</td>';
            print 
"<td><a href='?page=sf_theme_events&amp;action=edit&amp;id=".$event->ID."' class='edit'>".__('Edit')."</a></td>";
            print 
"<td><a href='?page=sf_theme_events&amp;action=delete&amp;id=".$event->ID."' onclick=\"return confirm('Er du sikker på at du vil slette aktiviteten ".$event->title." der finder sted den ".mysql2date(get_settings('date_format'),$event->begin_time)."?');\" class='delete'>".__('Delete')."</a></td>";
            print 
'</tr>';
            
$alternate=1-$alternate;
        }
    }
?>
</table>
        </fieldset>
    </form>
<?php ?>
</div>
<?php
}

function 
sf_theme_events_add_event($begin,$title,$description,$location,$id=0,$created=0,$end=0) {
    global 
$sf_theme_events_table$wpdb;
    
    if (!
$end)
        
$end='NULL';
    else
        
$end="'".$wpdb->escape($end)."'";
    
$wpdb->query("INSERT INTO $sf_theme_events_table (ID, begin_time, end_time, title, description, location, created, modified) VALUES('".$wpdb->escape($id)."','".$wpdb->escape($begin)."','".$wpdb->escape($end)."','".$wpdb->escape($title)."','".$wpdb->escape($description)."','".$wpdb->escape($location)."','".($id?$created:current_time('mysql'))."','".($id?current_time('mysql'):0)."')");
}

function 
sf_theme_events_check_setup() {
    global 
$table_prefix$sf_theme_events_table$wpdb;

    
$sf_theme_events_table $table_prefix."events";
    
$tables=$wpdb->get_results("SHOW TABLES");
    if (!
sizeof($tables))
      return;
    
$column=array_shift($wpdb->get_col_info());
    foreach (
$tables as $table) {
        if (
$table->$column==$sf_theme_events_table)
            return;
    };
    
// The event table does not exist, create...
    
$wpdb->query("CREATE TABLE `$sf_theme_events_table` (
            ID BIGINT(20) NOT NULL auto_increment,
            begin_time DATETIME NOT NULL,
            end_time DATETIME,
            title TEXT NOT NULL,
            description TEXT NOT NULL,
            location TEXT NOT NULL,
            created DATETIME NOT NULL,
            modified DATETIME NOT NULL,
            PRIMARY KEY  (ID)
        ) TYPE=MyISAM COMMENT='SF-theme event data'"
);
}

function 
sf_theme_events_admin() {
    if (
function_exists('add_submenu_page')) {
        
add_submenu_page('edit.php''Aktiviteter''Aktiviteter'2'sf_theme_events''sf_theme_events_admin_page');
    }
};

add_action('admin_menu''sf_theme_events_admin');

function 
sf_theme_widget_events_today_init() {

    
// Check for the required plugin functions. This will prevent fatal
    // errors occurring when you deactivate the dynamic-sidebar plugin.
    
if ( !function_exists('register_sidebar_widget') )
        return;

    
// This is the function that outputs our little Google search form.
    
function sf_theme_widget_events_today($args) {
        
        
// $args is an array of strings that help widgets to conform to
        // the active theme: before_widget, before_title, after_widget,
        // and after_title are the array keys. Default tags: li and h2.
        
extract($args);
        
$options get_option('sf_theme_widget_events_today');

        
// Don't display if there are no events today...
        
if ( !sf_theme_events_today_count() )
            return;

        
// These lines generate our output. Widgets can be very complex
        // but as you can see here, they can also be very, very simple.
        
print $before_widget;
        print 
$before_title '<a href="' sf_theme_get_event_page() . '">' $options['title'] . '</a>' $after_title;
        
sf_theme_events_today(falsefalse);
        print 
$after_widget;
    }

    function 
sf_theme_widget_events_today_control() {
        
$options $newoptions get_option('sf_theme_widget_events_today');
        if ( 
$_POST["events_today-submit"] ) {
            
$newoptions['title'] = strip_tags(stripslashes($_POST["events_today-title"]));
        }
        if ( 
$options != $newoptions ) {
            
$options $newoptions;
            
update_option('sf_theme_widget_events_today'$options);
        }
        
$title htmlspecialchars($options['title'], ENT_QUOTES);
        
?>
            <label for="events_today-title"><?php _e('Title:'); ?> <input style="display: block; width: 250px;" id="events_today-title" name="events_today-title" type="text" value="<?php echo $title?>" /></label>
            <input type="hidden" id="events_today-submit" name="events_today-submit" value="1" />
        <?php
    
}

    
// This registers our widget so it appears with the other available
    // widgets and can be dragged and dropped into any active sidebars.
    
register_sidebar_widget('Aktiviteter i dag''sf_theme_widget_events_today');
    
register_widget_control('Aktiviteter i dag''sf_theme_widget_events_today_control'30090);
}


function 
sf_theme_widget_events_in_the_future_init() {

    
// Check for the required plugin functions. This will prevent fatal
    // errors occurring when you deactivate the dynamic-sidebar plugin.
    
if ( !function_exists('register_sidebar_widget') )
        return;

    
// This is the function that outputs our little Google search form.
    
function sf_theme_widget_events_in_the_future($args) {
        
        
// $args is an array of strings that help widgets to conform to
        // the active theme: before_widget, before_title, after_widget,
        // and after_title are the array keys. Default tags: li and h2.
        
extract($args);
        
$options get_option('sf_theme_widget_events_in_the_future');

        
// Don't display if there are no events today...
        
if ( !sf_theme_events_in_the_future_count() )
            return;

        
// These lines generate our output. Widgets can be very complex

        // but as you can see here, they can also be very, very simple.
        
print $before_widget;
        print 
$before_title '<a href="' sf_theme_get_event_page() . '">' $options['title'] . '</a>' $after_title;
        
sf_theme_events_in_the_future($options['count'], falsefalse);
        print 
$after_widget;
    }

    function 
sf_theme_widget_events_in_the_future_control() {
        
$options $newoptions get_option('sf_theme_widget_events_in_the_future');
        if ( 
$_POST["events_in_the_future-submit"] ) {
            
$newoptions['title'] = strip_tags(stripslashes($_POST["events_in_the_future-title"]));
            
$newoptions['count'] = strip_tags(stripslashes($_POST["events_in_the_future-count"]));
        }
        if ( 
$options != $newoptions ) {
            
$options $newoptions;
            
update_option('sf_theme_widget_events_in_the_future'$options);
        }
        
$title htmlspecialchars($options['title'], ENT_QUOTES);
        
$count htmlspecialchars($options['title'], ENT_QUOTES);
        
?>
            <label for="events_in_the_future-title" style="display:block"><?php _e('Title:'); ?></label>
            <input style="display: block; width: 250px;" id="events_in_the_future-title" name="events_in_the_future-title" type="text" value="<?php echo $title?>" />
            <label for="events_in_the_future-title" style="display:block"><?php _e('Antal:'); ?></label>
            <select id="events_in_the_future-count" name="events_in_the_future-count" value="<?php echo $options['count']; ?>">
                <?php for ( $i 1$i 10; ++$i ) echo "<option value='$i' ".($options['count']==$i "selected='selected'" '').">$i</option>"?>
            </select>
            <input type="hidden" id="events_in_the_future-submit" name="events_in_the_future-submit" value="1" />
        <?php
    
}

    
// This registers our widget so it appears with the other available
    // widgets and can be dragged and dropped into any active sidebars.
    
register_sidebar_widget('Fremtidige aktiviteter''sf_theme_widget_events_in_the_future');
    
register_widget_control('Fremtidige aktiviteter''sf_theme_widget_events_in_the_future_control'300130);
}

// Database table and setup check.
sf_theme_events_check_setup();
sf_theme_widget_events_today_init();
sf_theme_widget_events_in_the_future_init();

?>