[EventCalendar] EventCalendar 3.1 Beta
Alex Tingle
alex at firetree.net
Fri Jul 21 23:42:16 UTC 2006
Darrell,
Hmm, I've just had a closer look, and your patch breaks things for me. The key think is that the edit_form.js script must be included AFTER the last window.onload setting. On my old version of WP, there's a bit of JS that sets the focus. Pushing edit_form.js above that means that its code is never run.
I've reverted to my original version, and things are much better. See the attached version of admin.php. If that file doesn't work for you, then perhaps you could leave it up and running somewhere and let me have a look at the HTML is produces.
-Alex
--
:: Let me solve your problems: http://www.firetree.net/consulting/
:: alex.tingle AT firetree.net +44-7901-552763
-------------- next part --------------
<?php
/*
Copyright (c) 2005, Alex Tingle. $Revision: 1.12 $
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class ec3_Admin
{
function admin_head()
{
global $ec3;
// Turn OFF advanced mode when we're in the admin screens.
$ec3->advanced=false;
?>
<!-- Added by eventcalendar3/admin.php -->
<style type='text/css' media='screen'>
@import url(<?php echo $ec3->myfiles; ?>/admin.css);
</style>
<?php
}
//
// EDIT FORM
//
function edit_form()
{
global $ec3,$wpdb,$post_ID;
if(isset($post_ID))
$schedule = $wpdb->get_results(
"SELECT * FROM $ec3->schedule WHERE post_id=$post_ID ORDER BY start");
else
$schedule = false;
?>
<!-- These scripts are only needed by edit_form screens. -->
<script type='text/javascript' src='<?php echo $ec3->myfiles; ?>/addEvent.js'></script>
<script type='text/javascript' src='<?php echo $ec3->myfiles; ?>/edit_form.js'></script>
<script type='text/javascript'>//<![CDATA[
Ec3EditForm.event_category=<?php echo $ec3->event_category; ?>;
// ]]></script>
<!-- Build the user interface for Event Calendar. -->
<fieldset id='ec3_schedule_editor' class="dbx-box">
<h3 class="dbx-handle"><?php _e('Schedule Editor','ec3'); ?></h3>
<div class="dbx-content">
<input type="hidden" id="ec3_purge" name="ec3_purge" value="0" />
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<thead><tr>
<th>Start</th>
<th>End</th>
<th>All Day</th>
<!-- th>Repeat</th -->
</tr></thead>
<tbody>
<?php if($schedule) foreach($schedule as $s): $sid=$s->sched_id; ?>
<tr valign="middle">
<td>
<input type="hidden" name="ec3_action_<?php echo $sid; ?>" value="update" />
<input type="text" name="ec3_start_<?php echo $sid; ?>" value="<?php echo $s->start; ?>" />
</td>
<td>
<input type="text" name="ec3_end_<?php echo $sid; ?>" value="<?php echo $s->end; ?>" />
</td>
<td>
<input type="checkbox" name="ec3_allday_<?php echo $sid; ?>" value="1"<?php if($s->allday) echo ' checked="checked"'; ?> />
</td>
<!-- td>
<input type="text" name="ec3_repeat_<?php echo $sid; ?>" value="<?php echo $s->rpt; ?>" />
</td -->
<td>
<input type="button" name="ec3_del_row_<?php echo $sid; ?>" value=" - " onclick="Ec3EditForm.del_row(this)" />
</td>
</tr>
<?php endforeach; ?>
<tr valign="middle" style="display:none">
<td>
<input type="hidden" name="ec3_action__" value="create" />
<input type="text" name="ec3_start__" value="" />
</td>
<td>
<input type="text" name="ec3_end__" value="" />
</td>
<td>
<input type="checkbox" name="ec3_allday__" value="1" />
</td>
<!-- td>
<input type="text" name="ec3_repeat__" value="" />
</td -->
<td>
<input type="button" name="ec3_delrow__" value=" - " onclick="Ec3EditForm.del_row(this)" />
</td>
</tr>
<tr>
<td colspan="4" style="text-align:left">
<input type="button" name="ec3_new_row" value=" + " onclick="Ec3EditForm.add_row()" />
</td>
</tr>
<tbody>
</table>
</div>
</fieldset>
<?php
} // end function edit_form()
function save_post($post_ID)
{
if(!$_POST)
return;
global $ec3,$wpdb;
// If this post is no longer an event, then purge all schedule records.
if(isset($_POST['ec3_purge']) && 1==(int)($_POST['ec3_purge']))
{
$wpdb->query("DELETE IGNORE FROM $ec3->schedule WHERE post_id=$post_ID");
return;
}
// Find all of our parameters
$updates=array();
$news =array();
$fields =array('start','end','allday','rpt');
foreach($_POST as $k => $v)
{
if(preg_match('/^ec3_(action|'.implode('|',$fields).')_(_?)([0-9]+)$/',$k,$match))
{
$sid=(int)($match[3]);
if($match[2]=='_')
$ref =& $news;
else
$ref =& $updates;
if(!isset($ref[$sid]))
$ref[$sid]=$empty;
$ref[ $sid ][ $match[1] ]=$v;
}
}
// Process updates
foreach($updates as $sid => $vals)
{
if(!array_key_exists('action',$vals)):
continue;
elseif($vals['action']=='update'):
$set=array('allday=0');
if(array_key_exists('start',$vals))
$set[]="start='".$vals['start']."'";
if(array_key_exists('end',$vals))
$set[]="end='".$vals['end']."'";
if(array_key_exists('allday',$vals))
$set[]="allday=".(int)$vals['allday'];
if(array_key_exists('rpt',$vals))
$set[]="rpt='".$vals['rpt']."'";
if(count($set)<2)
continue;
$wpdb->query(
"UPDATE IGNORE $ec3->schedule
SET ".implode(', ',$set)."
WHERE post_id=$post_ID
AND sched_id=$sid"
);
elseif($vals['action']=='delete'):
$wpdb->query(
"DELETE IGNORE FROM $ec3->schedule
WHERE post_id=$post_ID
AND sched_id=$sid"
);
endif;
}
// Process news
foreach($news as $sid => $vals)
{
if(!array_key_exists('action',$vals)):
continue;
elseif($vals['action']=='create'):
$set=array('allday'=>0);
if(array_key_exists('start',$vals))
$set['start']="'".$vals['start']."'";
if(array_key_exists('end',$vals))
$set['end']="'".$vals['end']."'";
if(array_key_exists('allday',$vals))
$set['allday']=(int)$vals['allday'];
if(array_key_exists('rpt',$vals))
$set['rpt']="'".$vals['rpt']."'";
if(count($set)<2)
continue;
$wpdb->query(
"INSERT IGNORE $ec3->schedule
(post_id,".implode(',',array_keys($set)).")
VALUES ($post_ID,".implode(', ',$set).")"
);
endif;
}
} // end function save_post()
//
// OPTIONS
//
/** Upgrade the installation, if necessary. */
function upgrade()
{
global $ec3,$wpdb;
// Check version.
$installed_version=get_settings('ec3_version');
if(strcmp($installed_version,$ec3->version)>=0)
return; // OK
// Upgrade.
$tables=$wpdb->get_results('SHOW TABLES',ARRAY_N);
if(!$tables)
die("Error upgrading database for Event Calendar plugin.");
$table_exists=false;
foreach($tables as $t)
if(preg_match("/$ec3->schedule/",$t[0]))
$table_exists=true;
if(!$table_exists)
{
$wpdb->query(
"CREATE TABLE $ec3->schedule (
sched_id BIGINT(20) AUTO_INCREMENT,
post_id BIGINT(20),
start DATETIME,
end DATETIME,
allday BOOL,
rpt VARCHAR(64),
PRIMARY KEY(sched_id)
)");
// Populate table with data from posts.
// ?? Would be nice to read 'duration' meta char for those posts
// that have it.
$wpdb->query(
"INSERT INTO $ec3->schedule
(post_id,start,end,allday,rpt)
SELECT
id AS post_id,
post_date AS start,
(post_date + INTERVAL 3 HOUR) AS end,
0 AS allday,
'' AS rpt
FROM $wpdb->posts p,$wpdb->post2cat p2c
WHERE p.id=p2c.post_id
AND category_id=$ec3->event_category
");
// Change posts' dates so that they occur in the past.
//(Do this programmatically to support old versions of MySQL that
// lack sub-selects.)
$results=$wpdb->get_results(
"SELECT ID FROM $wpdb->posts p,$wpdb->post2cat p2c
WHERE p.id=p2c.post_id AND category_id=$ec3->event_category"
);
foreach($results as $r)
{
$wpdb->query(
"UPDATE $wpdb->posts
SET post_date=post_modified,
post_date_gmt=post_modified_gmt
WHERE ID=$r->ID"
);
}
} // end if(!$table_exists)
// Record the new version number
update_option('ec3_version',$ec3->version);
echo '<div class="updated"><p><strong>'
. "Upgraded database to Event Calendar Version $ec3->version";
if($table_exists)
echo '<br />(Table already existed)';
echo "</strong></p></div>\n";
} // end function upgrade();
function admin_menu()
{
if(function_exists('add_options_page'))
{
add_options_page(
'Event Calendar Options',
'EventCalendar',
6,
basename(__FILE__),
'ec3_options_subpanel'
);
}
}
function options_subpanel()
{
$this->upgrade();
global $ec3;
if(isset($_POST['info_update']))
{
echo '<div class="updated"><p><strong>';
if(isset($_POST['ec3_event_category']))
$ec3->set_event_category( intval($_POST['ec3_event_category']) );
if(isset($_POST['ec3_num_months']))
$ec3->set_num_months( intval($_POST['ec3_num_months']) );
if(isset($_POST['ec3_show_only_events']))
$ec3->set_show_only_events( intval($_POST['ec3_show_only_events']) );
if(isset($_POST['ec3_day_length']))
$ec3->set_day_length( intval($_POST['ec3_day_length']) );
if(isset($_POST['ec3_hide_logo']))
$ec3->set_hide_logo( intval($_POST['ec3_hide_logo']) );
if(isset($_POST['ec3_advanced']))
$ec3->set_advanced( intval($_POST['ec3_advanced']) );
if(isset($_POST['ec3_nav_below']))
$ec3->set_nav_below( intval($_POST['ec3_nav_below']) );
if(isset($_POST['ec3_disable_popups']))
$ec3->set_disable_popups( intval($_POST['ec3_disable_popups']) );
_e('Options set.','ec3');
echo '</strong></p></div>';
}
?>
<div class=wrap>
<form method="post">
<h2><?php _e('Event Calendar Options','ec3'); ?></h2>
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<tr valign="middle">
<th width="33%" scope="row"><?php _e('Event category','ec3'); ?>:</th>
<td>
<select name="ec3_event_category">
<?php wp_dropdown_cats( 0, $ec3->event_category ); ?>
</select>
</td>
</tr>
<tr valign="middle">
<th width="33%" scope="row"><?php _e('Show events as blog entries','ec3'); ?>:</th>
<td>
<select name="ec3_advanced">
<option value='0'<?php if(!$ec3->advanced_setting) echo " selected='selected'" ?> >
<?php _e('Events are Normal Posts','ec3'); ?>
</option>
<option value='1'<?php if($ec3->advanced_setting) echo " selected='selected'" ?> >
<?php _e('Keep Events Separate','ec3'); ?>
</option>
</select>
</td>
</tr>
<tr valign="middle"><th width="33%" scope="row"></th>
<td><em>
<?php _e('Keep Events Separate: the Event Category page shows future events, in date order. Events do not appear on front page.','ec3'); ?>
</em></td>
</tr>
</table>
<fieldset class="options"><legend><?php _e('Calendar Display','ec3'); ?></legend>
<table width="100%" cellspacing="2" cellpadding="5" class="editform">
<tr valign="middle">
<th width="33%" scope="row"><?php _e('Number of months','ec3'); ?>:</th>
<td>
<input type="text" name="ec3_num_months" value="<?php echo $ec3->num_months; ?>" />
</td>
</tr>
<tr valign="middle">
<th width="33%" scope="row"><?php _e('Show all categories in calendar','ec3'); ?>:</th>
<td>
<select name="ec3_show_only_events">
<option value='1'<?php if($ec3->show_only_events) echo " selected='selected'" ?> >
<?php _e('Only Show Events','ec3'); ?>
</option>
<option value='0'<?php if(!$ec3->show_only_events) echo " selected='selected'" ?> >
<?php _e('Show All Posts','ec3'); ?>
</option>
</select>
</td>
</tr>
<tr valign="middle">
<th width="33%" scope="row"><?php _e('Show day names as','ec3'); ?>:</th>
<td>
<select name="ec3_day_length">
<option value='1'<?php if($ec3->day_length<3) echo " selected='selected'" ?> >
<?php _e('Single Letter','ec3'); ?>
</option>
<option value='3'<?php if(3==$ec3->day_length) echo " selected='selected'" ?> >
<?php _e('3-Letter Abbreviation','ec3'); ?>
</option>
<option value='9'<?php if($ec3->day_length>3) echo " selected='selected'" ?> >
<?php _e('Full Day Name','ec3'); ?>
</option>
</select>
</td>
</tr>
<tr valign="middle">
<th width="33%" scope="row"><?php _e('Show Event Calendar logo','ec3'); ?>:</th>
<td>
<select name="ec3_hide_logo">
<option value='0'<?php if(!$ec3->hide_logo) echo " selected='selected'" ?> >
<?php _e('Show Logo','ec3'); ?>
</option>
<option value='1'<?php if($ec3->hide_logo) echo " selected='selected'" ?> >
<?php _e('Hide Logo','ec3'); ?>
</option>
</select>
</td>
</tr>
<tr valign="middle">
<th width="33%" scope="row"><?php _e('Position of navigation links','ec3'); ?>:</th>
<td>
<select name="ec3_nav_below">
<option value='0'<?php if(!$ec3->nav_below) echo " selected='selected'" ?> >
<?php _e('Above Calendar','ec3'); ?>
</option>
<option value='1'<?php if($ec3->nav_below) echo " selected='selected'" ?> >
<?php _e('Below Calendar','ec3'); ?>
</option>
</select>
</td>
</tr>
<tr valign="middle"><th width="33%" scope="row"></th>
<td><em>
<?php _e('The navigation links are more usable when they are above the calendar, but you might prefer them below it for aesthetic reasons.','ec3'); ?>
</em></td>
</tr>
<tr valign="middle">
<th width="33%" scope="row"><?php _e('Popup event lists','ec3'); ?>:</th>
<td>
<select name="ec3_disable_popups">
<option value='0'<?php if(!$ec3->disable_popups) echo " selected='selected'" ?> >
<?php _e('Show Popups','ec3'); ?>
</option>
<option value='1'<?php if($ec3->disable_popups) echo " selected='selected'" ?> >
<?php _e('Hide Popups','ec3'); ?>
</option>
</select>
</td>
</tr>
<tr valign="middle"><th width="33%" scope="row"></th>
<td><em>
<?php _e('You might want to disable popups if you use Nicetitles.','ec3'); ?>
</em></td>
</tr>
</table>
</fieldset>
<p class="submit"><input type="submit" name="info_update" value="<?php
_e('Update options','ec3')
?> »" /></p>
</form>
<h3>EXAMPLE SIDEBAR CODE:</h3>
<pre><code> <li>
<?php ec3_get_calendar(); ?>
</li>
<li><?php _e('Events'); ?>
<?php ec3_get_events(5); ?>
</li></code></pre>
</div> <?php
} // end function options_subpanel()
}; // end class ec3_Admin
$ec3_admin=new ec3_Admin();
function ec3_options_subpanel()
{
global $ec3_admin;
$ec3_admin->options_subpanel();
}
//
// Hook in...
add_filter('admin_head', array(&$ec3_admin,'admin_head'));
add_filter('edit_form_advanced',array(&$ec3_admin,'edit_form'));
add_filter('simple_edit_form', array(&$ec3_admin,'edit_form'));
add_action('save_post', array(&$ec3_admin,'save_post'));
add_action('edit_post', array(&$ec3_admin,'save_post'));
add_action('admin_menu', array(&$ec3_admin,'admin_menu'));
?>
More information about the EventCalendar
mailing list