part=array();
foreach($v as $i)
{
if(preg_match('/^[0-9]+$/',$i))
$this->part[]=intval($i);
elseif(preg_match('/^dev/',$i))
$this->part[]=-1000;
elseif(preg_match('/^_/',$i))
$this->part[]=-500;
elseif(preg_match('/^a(lpha)?/',$i))
$this->part[]=-3;
elseif(preg_match('/^b(eta)?/',$i))
$this->part[]=-2;
elseif(preg_match('/^rc?/',$i))
$this->part[]=-1;
elseif(empty($i))
$this->part[]=0;
else
$this->part[]=$i;
}
}
/** Compares this version with $other. */
function cmp($other)
{
for($i=0; $i < max(count($this->part),count($other->part)); $i++)
{
// Fill in empty pieces.
if( !isset($this->part[$i]) )
$this->part[$i] = 0;
if( !isset($other->part[$i]) )
$other->part[$i] = 0;
// Compare
if( $this->part[$i] > $other->part[$i] )
return 1;
if( $this->part[$i] < $other->part[$i] )
return -1;
}
// They really are equal.
return 0;
}
};
class ec3_Admin
{
function filter_admin_head()
{
global $ec3;
// Turn OFF advanced mode when we're in the admin screens.
$ec3->advanced=false;
?>
get_results(
"SELECT
sched_id,
DATE_FORMAT(start,'%Y-%m-%d %H:%i') AS start,
DATE_FORMAT(end,'%Y-%m-%d %H:%i') AS end,
allday,
rpt
FROM $ec3->schedule WHERE post_id=$post_ID ORDER BY start");
else
$schedule = false;
if(function_exists('wp_create_nonce'))
{
echo '';
}
?>
save_post_called) && $this->save_post_called[$post_ID])
return;
if(!isset($this->save_post_called))
$this->save_post_called=array();
$this->save_post_called[$post_ID]=true;
global $ec3,$wpdb;
// Use this to check the DB before DELETE/UPDATE. Should use
// ...IGNORE, but some people insist on using ancient version of MySQL.
$count_where="SELECT COUNT(0) FROM $ec3->schedule WHERE";
// If this post is no longer an event, then purge all schedule records.
if(isset($_POST['ec3_rows']) && '0'==$_POST['ec3_rows'])
{
if($wpdb->get_var("$count_where post_id=$post_ID"))
$wpdb->query("DELETE FROM $ec3->schedule WHERE post_id=$post_ID");
return;
}
// Find all of our parameters
$sched_entries=array();
$fields =array('start','end','allday','rpt');
foreach($_POST as $k => $v)
{
if(preg_match('/^ec3_(action|'.implode('|',$fields).')_(_?)([0-9]+)$/',$k,$match))
{
$sid=intval($match[3]);
if(!isset( $sched_entries[$sid] ))
$sched_entries[ $sid ]=array('allday' => 0);
$sched_entries[ $sid ][ $match[1] ] = $v;
}
}
foreach($sched_entries as $sid => $vals)
{
// Bail out if the input data looks suspect.
if(!array_key_exists('action',$vals) || count($vals)<3)
continue;
// Save the value of 'action' and remove it. Leave just the column vals.
$action=$vals['action'];
unset($vals['action']);
// Reformat the column values for SQL:
foreach($vals as $k => $v)
if('allday'==$k)
$vals[$k]=intval($v);
else
$vals[$k]="'".$wpdb->escape($v)."'";
$sid_ok=$wpdb->get_var("$count_where post_id=$post_ID AND sched_id=$sid");
// Execute the SQL.
if($action=='delete' && $sid>0 && $sid_ok):
$wpdb->query(
"DELETE FROM $ec3->schedule
WHERE post_id=$post_ID
AND sched_id=$sid"
);
elseif($action=='update' && $sid>0 && $sid_ok):
$wpdb->query(
"UPDATE $ec3->schedule
SET sequence=sequence+1, ".$this->implode_assoc(', ',$vals)."
WHERE post_id=$post_ID
AND sched_id=$sid"
);
elseif($action=='create'):
$wpdb->query(
"INSERT INTO $ec3->schedule
(post_id, ".implode(', ',array_keys($vals)).")
VALUES ($post_ID, ".implode(', ',array_values($vals)).")"
);
endif;
}
// Force all end dates to be >= start dates.
$wpdb->query("UPDATE $ec3->schedule SET end=start WHERE end$value)
$result[]=$key."=".$value;
return implode($glue,$result);
}
/** Clear events for the post. */
function action_delete_post($post_ID)
{
global $ec3,$wpdb;
$wpdb->query("DELETE FROM $ec3->schedule WHERE post_id=$post_ID");
}
//
// OPTIONS
//
/** Upgrade the installation, if necessary. */
function upgrade_database()
{
global $ec3,$wpdb;
// Check version - return if no upgrade required.
$installed_version=get_option('ec3_version');
if($installed_version==$ec3->version)
return;
$v0 = new ec3_Version($installed_version);
$v1 = new ec3_Version($ec3->version);
if( $v0->cmp($v1) > 0 )
return; // Installed version later than this one ?!?!
// Upgrade.
$message = sprintf(__('Upgraded database to %1$s Version %2$s','ec3'),
'Event-Calendar',$ec3->version
) . '.';
$tables=$wpdb->get_results('SHOW TABLES',ARRAY_N);
if(!$tables)
{
die(sprintf(__('Error upgrading database for %s plugin.','ec3'),
'Event-Calendar'
));
}
$table_exists=false;
foreach($tables as $t)
if(preg_match("/$ec3->schedule/",$t[0]))
$table_exists=true;
if($table_exists)
{
$message .= ' '.__('Table already existed','ec3').'.';
}
else
{
$message .= ' '
. sprintf(__('Created table %s','ec3'),$ec3->schedule).'.';
$wpdb->query(
"CREATE TABLE $ec3->schedule (
sched_id BIGINT(20) AUTO_INCREMENT,
post_id BIGINT(20),
sequence BIGINT(20),
start DATETIME,
end DATETIME,
allday BOOL,
rpt VARCHAR(64),
PRIMARY KEY(sched_id)
)");
// Force the special upgrade page if we are coming from v3.0
if( $ec3->event_category &&
( empty($v0) || $v0[0]<3 || ($v0[0]==3 && $v0[1]==0) ) )
{
update_option('ec3_upgrade_posts',1);
}
} // end if(!$table_exists)
// Sequence column is new in v3.2.dev-01
$v32dev01 = new ec3_Version('3.2.dev-01');
if( $v0->cmp($v32dev01) < 0 )
{
$message .= ' '
. sprintf(__('Added SEQUENCE column to table %s','ec3'),$ec3->schedule)
. '.';
$wpdb->query(
"ALTER TABLE $ec3->schedule ADD COLUMN sequence BIGINT(20) DEFAULT 1"
);
}
// Option ec3_show_event_box is new in v3.2.dev-02
$hide_event_box=get_option('ec3_hide_event_box');
if($hide_event_box!==false)
{
if(intval($hide_event_box))
$ec3->set_show_event_box(2);
else
$ec3->set_show_event_box(0);
update_option('ec3_hide_event_box',false);
}
// Record the new version number
update_option('ec3_version',$ec3->version);
// Display an informative message.
echo '
';
echo $message;
echo "
\n";
} // end function upgrade_database();
function action_admin_menu()
{
global $ec3;
add_options_page(
__('Event Calendar Options','ec3'),
'Event-Calendar',
6,
'ec3_admin',
'ec3_options_subpanel'
);
if(empty($ec3->event_category))
return; // Until EC is properly configured, only show the options page.
if(function_exists('add_meta_box'))
{
add_meta_box(
'ec3_schedule_editor', // HTML id for container div
__('Event Editor','ec3'),
'ec3_event_editor_box', // callback function
'post', // page type
'advanced', // context
'high' // priority
);
}
else
{
global $ec3_admin;
// Old (pre WP2.5) functionality.
add_filter('simple_edit_form', array(&$ec3_admin,'filter_edit_form'));
if($ec3->wp_have_dbx)
add_filter('dbx_post_advanced', array(&$ec3_admin,'filter_edit_form'));
else
add_filter('edit_form_advanced',array(&$ec3_admin,'filter_edit_form'));
}
}
function options_subpanel()
{
global $ec3;
if(isset($_POST['info_update']))
{
echo '