sNews Forum

sNews 1.6 (previous version) => 3rd Party Integration and bridges => Topic started by: mike1 on November 18, 2007, 06:53:51 am

Title: [ADDON] phpEventCalendar
Post by: mike1 on November 18, 2007, 06:53:51 am
Integrating phpEventCalendar http://www.ikemcg.com/pec (http://www.ikemcg.com/pec)

REMEMBER - BACKUP.  I may have missed something in the instructions (it works fine for me)
1.  Download the modified calendar package
 

2.  Unpack the files into a subdirectory named cal (it MUST be cal, or you will have to modify the package/directions) under snews (e.g if snews is installed in root directory, then directory is root/cal, or if snews is installed in subdirectory, then its root/snews/cal)

3.  Fill out config.php with your snews database information (no need to install it in another database).  Be sure to keep the prefix as pec (If you do change the prefix, you will need to edit the new search function).

4.  Add the following functions to snews.php.
NOTE: The additional cal_pages function is only necessary if you wish to have a .current class added on for css purposes. If you do not wish to have such a class, you can choose to leave the function out of snews.php (but be sure to change cal_pages to pages in default.php in the calendar package, and hard link the calendar yourself in the current pages() function)
      (http://GONE[/url)
Code: [Select]
function cal_pages() {
$categorySEF = get_id('category'); $pageSEF = get_id('article'); $home = l('home_sef');
echo '<li><a href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></li>';
echo '<li><a href="'.db('website').'archive/" title="'.l('archive').'">'.l('archive').'</a></li>';
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$title = $r['title'];
if ($r['id'] != s('display_page')) {echo '<li><a href="'.db('website').l('home_sef').'/'.$r['seftitle'].'/" title="'.$title.'">'.$title.'</a></li>';}
}
echo '<li><a class="current" href="'.db('website').'cal/" title="'.l('events').'">'.l('events').'</a></li>';
echo '<li><a href="'.db('website').'contact/" title="'.l('contact').'">'.l('contact').'</a></li>';
echo '<li><a href="'.db('website').'sitemap/" title="'.l('sitemap').'">'.l('sitemap').'</a></li>';
}

Code: [Select]
function cal_breadcrumbs() {
$link = '<a href="'.db('website').'';
if ($_SESSION[db('website').'Logged_In'] == token()) {echo $link.'administration/" title="'.l('administration').'">'.l('administration').'</a> '.l('divider').' ';}
$categorySEF = get_id('category'); $articleSEF = get_id('article'); $home = l('home_sef');
echo (empty($categorySEF) || $categorySEF == $home || !empty($articleSEF)) ? $link.'" title="'.l('home').'">'.l('home').'</a>' : l('home');
echo ' '.l('divider').' '.(!empty($articleSEF) ? $link.$categorySEF.'/" title="'.l('events').'">'.l('events').'</a>' : l('events'));
}

Code: [Select]
function cal_title() {
$title = s('website_title');
$title .= ' - Calendar';
echo '<title>'.$title.'</title>';
echo '<meta http-equiv="Content-Type" content="text/html; charset='.s('charset').'" />';
echo '<meta name="description" content="'.(!empty($dmeta) ? $dmeta : s('website_description')).'" />';
echo '<meta name="keywords" content="'.(!empty($kmeta) ? $kmeta : s('website_keywords')).'" />';
if ($_SESSION[db('website').'Logged_In'] == token()) {js();}
}

5.  Replace current function search() with this
Code: [Select]
function search() {
$search_query = clean(cleanXSS($_POST['search_query']));
echo '<h2>'.l(search_results).'</h2>';
if (strlen($search_query) < 4 || $search_query == l('search_keywords')) {echo '<p>'.l(charerror).'</p>';}
else {
$keywords = explode(' ', $search_query);
$keyCount = count($keywords);
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND published = 1 AND";
if ($keyCount > 1) {
for ($i = 0; $i < $keyCount - 1; $i++) {$query = $query." (title LIKE '%$keywords[$i]%' || text LIKE '%$keywords[$i]%') &&";}
$j = $keyCount - 1;
$query = $query." (title LIKE '%$keywords[$j]%' || text LIKE '%$keywords[$j]%')";}
else {$query = $query." (title LIKE '%$keywords[0]%' || text LIKE '%$keywords[0]%')";}
$query1 = "SELECT * FROM pec_mssgs WHERE";
if ($keyCount > 1) {
for ($i = 0; $i < $keyCount - 1; $i++) {$query1 = $query1." (title LIKE '%$keywords[$i]%' || text LIKE '%$keywords[$i]%') &&";}
$j = $keyCount - 1;
$query1 = $query1." (title LIKE '%$keywords[$j]%' || text LIKE '%$keywords[$j]%')";}
else {$query1 = $query1." (title LIKE '%$keywords[0]%' || text LIKE '%$keywords[0]%')";}
$query = $query." ORDER BY id DESC";
$query1 = $query1." ORDER BY y DESC, m DESC, d DESC";
$result = mysql_query($query);
$result1 = mysql_query($query1);
$numrows = mysql_num_rows($result);
$numrows1 = mysql_num_rows($result1);
if (!$numrows and !$numrows1) {echo '<p>'.l('noresults').' <strong>'.stripslashes($search_query).'</strong>.</p>';}
else {
$totalnumrows = $numrows + $numrows1;
echo '<p><strong>'.$totalnumrows.'</strong> '.l('resultsfound').' <strong>'.stripslashes($search_query).'</strong>.</p>';
if ($numrows > 0) {
echo '<strong>Articles</strong>';
while ($r = mysql_fetch_array($result)) {
$date = date(s('date_format'), strtotime($r['date']));
echo '<p><a href="'.db('website').find_cat_sef($r['category']).'/'.$r['seftitle'].'/">'.$r['title'].'</a> - '.$date.'</p>';}}
if ($numrows1 > 0) {
echo '<strong>Events</strong><br />';
while ($r1 = mysql_fetch_array($result1)) {
echo '<p class=\"title_txt\"><a href=javascript:openPosting('
. $r1 ["id"]. ")>"
. $r1['title'] . "</a>&nbsp;-&nbsp;"
.$r1['m']. "."
.$r1['d']. "."
.$r1['y'].
"</p>"
;}}
}
}
echo '<p><br /><a href="'.db('website').'">'.l('backhome').'</a></p>';
$searched = true;
}

6.  In your SNEWS index.php, change
Code: [Select]
<?php title(); ?> to
Code: [Select]
<?php title(); search_javascript();?>
7.  After
Code: [Select]
// dependancy limiter
function dependancy() {
var category = document.forms['post']['define_category'];
var page = document.getElementById('def_page');
page.style.display = category.options[category.selectedIndex].value == '-1' ? 'inline' : 'none';
}
add
Code: [Select]
//Event Posting
function postMessage(day, month, year) {
eval(
"page" + day + " = window.open('cal/eventform.php?d=" + day + "&m=" +
month + "&y=" + 2007 + "', 'postScreen', 'toolbar=0,scrollbars=1," +
"location=0,statusbar=0,menubar=0,resizable=1,width=340,height=400');"
);
}

8.  in administration form change
Code: [Select]
echo '<p><a href="files/" title="'.l('files').'">'.l('files').'</a></p></fieldset>';to
Code: [Select]
echo '<p><a href="files/" title="'.l('files').'">'.l('files').'</a></p>';
echo '<p><a href="javascript: postMessage()" title="Add Event">Add Event</a></p></fieldset>';

9.  Add new language variable
Code: [Select]
$l['events'] = 'Calendar';
10.  Upload everything to server and run createtables.php
11.  Delete createtables.php
12.  UPDATE 11/20.  Add Calendar link to Sitemap
Code: [Select]
echo $link.'cal/">'.l('events').'</a><br />';That should be it.  I may have missed something, so please backup everything before you start.  If i did miss anything, let me know.
13.  UPDATE 11/23.  in your SNEWS index.php change 
Code: [Select]
<?php session_start(); include('snews.php'); ?>to
Code: [Select]
<?php session_start(); include('snews.php'); include('cal/functions.php'); ?>14.  UPDATE 11/23 in snews.php, hardlink the calendar in pages() function
Code: [Select]
echo '<li><a href="'.db('website').'cal/" title="'.l('events').'"><span>'.l('events').'</span></a></li>';15.  UPDATE 11/23.  I have made an error in default.php.  in the package, change
in default.php, change
Code: [Select]
<?php cal_title(); javaScript() ?>to
Code: [Select]
<?php cal_title(); javaScript(); ?>
NOTES:
1.  Calendar doesn't have SEF friendly URLs.
2.  Calendar has unpatched vulnerability http://secunia.com/advisories/25915/ (http://secunia.com/advisories/25915/) (if anyone knows how to fix this, I'm all ears)
UPDATE 11/18
I have updated the cal.zip package to pass the id parameter (eventdisplay.php) through the clean(cleanXSS)) snews functions which should rectify the problem.
3.  I would love for this to not use pop-ups as much as the next guy, so if anyone has suggestions or mods, I'm all ears (I believe it would require a significant rewrite).
4.  If anyone sees inefficiencies that they can fix, once again, I'm all ears :)
5.  I will try to add recurring events to the package
6.  Doesn't validate
7.  You can add events one of 2 ways.  Either click add event in the snews admin panel after you login, or you can login to snews, and then navigate to your calendar, and click on the dates.
Title: Re: [ADDON] phpEventCalendar
Post by: philmoz on November 18, 2007, 11:54:59 am
since you are fitting snews.php with some code, you could try (I believe it will work) removing your step 6, and making the last line of the title() function
Code: [Select]
search_javascript();
just a thought
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 18, 2007, 02:41:00 pm
since you are fitting snews.php with some code, you could try (I believe it will work) removing your step 6, and making the last line of the title() function
Code: [Select]
search_javascript();
just a thought

The cal_title function here is for the calendar's default.php (in the modified package).  If I were to remove step 6, i would just have to add another step adding the javascript to the snews index.php title function (rather than the calendar functions.pgp).  Theoretically, I'm sure you,re right, but the current way just means less copying/pasting (if I understand what youre saying).
Title: Re: [ADDON] phpEventCalendar
Post by: philmoz on November 19, 2007, 12:17:21 pm
indeed, but the line you are altering in index.php is
<?php title(); ?>
which is the default snews title function.
My point being, that since you are editing snews.php to add these custom functions, it would be just as easy to make the snews.php title() function call the search_javascript() function, so end of default title() would be like
Code: [Select]
...
if ($_SESSION[db('website').'Logged_In'] == token()) {js();}
search_javascript();
}
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 19, 2007, 06:42:03 pm
fair enough.  I'll try to make that change (and a few other changes to make the calendar more Addonish as opposed to Modish) sometime if theres interest (if not, the current method is good enough for me).
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 23, 2007, 07:05:00 pm
I use snewsMEMU and trying til include the PEC into the scrpit. I have tryed to go trought it a couple of times, and all the inclutions seems to bee fine. Everything gets white when i add the search_javascript into the default title function and on the top of the index.php. I have tried both of the inclution alternatives. so please help a fella..
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 23, 2007, 09:37:31 pm
Nice catch.  I forgot an include in the SNEWS index.php file (i have updated the original post, step 13)
Place this right after the snews.php include but before the ?>
Code: [Select]
include('cal/functions.php');
A word of caution, I completely removed the calendar's authentication.  The only way you can add events to the calendar is if you are logged into snews (so basically single sign-on for both snews and the calendar).  I do not know how this will work in MU (so low level users may get access to editing the calendar).  In all honesty, I doubt that this will work with the MU version without some changes (although please do let me know if no changes are needed).

In the SU snews, there is a single authentication statement to check if the admin is logged in (if $session blah ==token()).  This is probably different for the MU version.  Depending on what level of user you want to be able to add/edit events, you MAY have to change the function.  However, let me know if the default package works first.  If it doesnt, I may delve into the MU version (finals are coming up, so I may not be as helpful though).
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 23, 2007, 10:12:33 pm
Yes... as Mike1 notes... the user authentication strings are different in MU than they are in SU versions... but they should be fairly easy to figure out. If not... I am sure bakercad will give you assistance if you showl him what you need to change.
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 23, 2007, 10:53:08 pm
should be a fairly easy change

in eventdisplay.php, eventform.php, eventsubmit.php, and functions.php, wherever I have inserted
Code: [Select]
if ($_SESSION[db('website').'Logged_In'] == token() {change to
Code: [Select]
if ($_SESSION[db('website').'Logged_In'] == token() && get_identity($_SESSION['id'], 'level') < '4') {where you change 4 to the level of user you want to be able to edit the calendar (the only numbers you should use are 4, 3, or 2).

NOT TESTED :)
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 24, 2007, 12:12:55 am
Thanx for everything, but I still have the same problem exept that I now can se the original page index.  The index in Cal is stil unavalable og white. I have not started on the mod in the MU section yet, but I will after I got the hang of the problem with the inclution of phpEventCalendar.


www.xclusive.name <---- it seems like everything is workin fine, since I don't have any errors.. Please help me get this to work.
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 24, 2007, 01:01:22 am
can you post your calendar index.php and default.php files?

also, Keyrocks changed snews.php to core.php in his package.  you will have to make the change in the include statements in the cal package (index.php, eventdisplay.php, eventsubmit.php, eventform.php).
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 24, 2007, 01:16:26 am
Code: [Select]
<?php
session_start
();
require(
"config.php");
require(
"./lang/lang." LANGUAGE_CODE ".php");
require(
"functions.php");
include(
"../snewsMU.php");

# testing whether var set necessary to suppress notices when E_NOTICES on
$month 
(isset($_GET['month'])) ? (int) $_GET['month'] : null;
$year =
(isset($_GET['year'])) ? (int) $_GET['year'] : null;

# set month and year to present if month 
# and year not received from query string
$m = (!$month) ? date("n") : $month;
$y = (!$year)  ? date("Y") : $year;

$scrollarrows scrollArrows($m$y);

require(
"./templates/" TEMPLATE_NAME ".php");
?>




Code: [Select]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<?php cal_title(); javaScript() ?>
<link rel="stylesheet" type="text/css" href="css/default.css">
    <link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body>
<div class="wrap">
<div id="logo">
<h1><?php echo s('website_title'); ?></h1>
</div>

<ul id="menu">
<?php cal_pages(); ?>
</ul>

<div id="subheader">
<div id="breadcrumbs">
<?php cal_breadcrumbs(); ?>
</div>

<div id="search">
<?php searchform(); ?>
</div>
</div>

<div id="left">
<h3>Categories:</h3>
<ul>
<?php categories(); ?>
</ul>

<h3>New Articles:</h3>
<ul>
<?php menu_articles(0,3); ?>
</ul>

<h3>New comments:</h3>
<ul>
<?php new_comments(530); ?>
</ul>

<?php extra(); ?>
</div>

<div id="right">
            <table cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td>
<?php echo $scrollarrows ?>
<span class="date_header">
&nbsp;<?php echo $lang['months'][$m-1?>&nbsp;<?php echo $y ?></span>
</td>

<!-- form tags must be outside of <td> tags -->
<form name="monthYear">
<td align="right">
<?php monthPullDown($m$lang['months']); yearPullDown($y); ?>
<input type="button" value="GO" onClick="submitMonthYear()">
</td>
</form>

</tr>

<tr>
<td colspan="2" bgcolor="#000000">
<?php echo writeCalendar($m$y); ?></td>
</tr>

</table>
</div>

<div id="footer">
<ul id="rss">
<?php rss_links(); ?>
</ul>
<p>Barbecued by <a href="http://snews.solucija.com/" title="Single file CMS">sNews</a> &middot; <?php login_link(); ?></p>
</div>
</div>
</body>
</html>

The changes to core.php is not made in snewsMEMU, it's called snewsMU.php, atleast that I can see. And as you can see I have made the changes in index.php to snewsMU.php.

Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 24, 2007, 01:20:27 am
did you also make the change in the other files I specified?
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 24, 2007, 01:30:29 am
did you also make the change in the other files I specified?

Yes..
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 24, 2007, 01:35:26 am
in default.php, change
Code: [Select]
<?php cal_title(); javaScript() ?>to
Code: [Select]
<?php cal_title(); javaScript(); ?>
That is an error in the package on my part.  My apologies
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 24, 2007, 01:43:45 am
Sorry mike1.. Does not seems to be the problem here.. I stil have a white page..
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 24, 2007, 01:50:39 am
replace functions.php with this

Code: [Select]
<?php

/*******************************************************
* functions.php -
* phpEventCalendar global include file
*******************************************************/

# ###################################################################

function monthPullDown($month$montharray)
{
echo "<select name=\"month\">\n";

$selected[$month 1] = ' selected="selected"';

for($i=0;$i 12$i++) {
$val $i 1;
$sel = (isset($selected[$i])) ? $selected[$i] : "";
echo " <option value=\"$val\"$sel>$montharray[$i]</option>\n";
}
echo "</select>\n\n";
}

# ###################################################################

function yearPullDown($year)
{
echo "<select name=\"year\">\n";

$selected[$year] = ' selected="selected"';
$years_before_and_after 3;
$start_year $year $years_before_and_after;
$end_year   $year $years_before_and_after;

for($i=$start_year;$i <= $end_year$i++) {
$sel = (isset($selected[$i])) ? $selected[$i] : "";
echo " <option value=\"$i\"$sel>$i</option>\n";
}
echo "</select>\n\n";
}

# ###################################################################

function dayPullDown($day)
{
echo "<select name=\"day\">\n";

$selected[$day] = ' selected="selected"';

for($i=1;$i <= 31$i++) {
$sel = (isset($selected[$i])) ? $selected[$i] : "";
echo " <option value=\"$i\"$sel>$i</option>\n";
}
echo "</select>\n\n";
}

# ###################################################################

function hourPullDown($hour$namepre)
{
echo "\n<select name=\"" $namepre "_hour\">\n";

$selected[$hour] = ' selected="selected"';

for($i=0;$i <= 12$i++) {
$sel = (isset($selected[$i])) ? $selected[$i] : "";
echo " <option value=\"$i\"$sel>$i</option>\n";
}
echo "</select>\n\n";
}

# ###################################################################

function minPullDown($min$namepre)
{
echo "\n<select name=\"" $namepre "_min\">\n";

$selected[$min] = ' selected="selected"';

for($i=0;$i 60$i+=5) {
$disp_min sprintf("%02d"$i);
$sel = (isset($selected[$i])) ? $selected[$i] : "";
echo "\t<option value=\"$i\"$sel>$disp_min</option>\n";
}

echo "</select>\n\n";
}

# ###################################################################

function amPmPullDown($pm$namepre)
{
$sel ' selected="selected"';
$am  null;
if ($pm) { $pm $sel; } else { $am $sel; }

echo "\n<select name=\"" $namepre "_am_pm\">\n";
echo " <option value=\"0\"$am>am</option>\n";
echo " <option value=\"1\"$pm>pm</option>\n";
echo "</select>\n\n";
}

# ###################################################################

function javaScript()
{
?>

<script language="javascript">
function submitMonthYear() {
document.monthYear.method = "post";
document.monthYear.action =
"index.php?month=" + document.monthYear.month.value +
"&year=" + document.monthYear.year.value;
document.monthYear.submit();
}

function postMessage(day, month, year) {
eval(
"page" + day + " = window.open('eventform.php?d=" + day + "&m=" +
month + "&y=" + year + "', 'postScreen', 'toolbar=0,scrollbars=1," +
"location=0,statusbar=0,menubar=0,resizable=1,width=340,height=400');"
);
}

function openPosting(pId) {
eval(
"page" + pId + " = window.open('eventdisplay.php?id=" + pId +
"', 'mssgDisplay', 'toolbar=0,scrollbars=1,location=0,statusbar=0," +
"menubar=0,resizable=1,width=340,height=400');"
);
}

</script>
<?php
}

function 
search_javaScript()
{
?>

<script language="javascript">

function openPosting(pId) {
eval(
"page" + pId + " = window.open('cal/eventdisplay.php?id=" + pId +
"', 'mssgDisplay', 'toolbar=0,scrollbars=1,location=0,statusbar=0," +
"menubar=0,resizable=1,width=340,height=400');"
);
}
</script>
<?php
}
# ###################################################################

function scrollArrows($m$y)
{
// set variables for month scrolling
$nextyear  = ($m != 12) ? $y $y 1;
$prevyear  = ($m != 1)  ? $y $y 1;
$prevmonth = ($m == 1)  ? 12 $m 1;
$nextmonth = ($m == 12) ? 1  $m 1;

return "
<a href=\"index.php?month=" 
$prevmonth "&year=" $prevyear "\">
<img src=\"images/leftArrow.gif\" border=\"0\"></a>
<a href=\"index.php?month=" 
$nextmonth "&year=" $nextyear "\">
<img src=\"images/rightArrow.gif\" border=\"0\"></a>
"
;
}

# ###################################################################

function writeCalendar($month$year)
{
$str getDayNameHeader();
$eventdata getEventDataArray($month$year);

# get first row position of first day of month.
$weekpos getFirstDayOfMonthPosition($month$year);

# get number of days in month
$days date("t"mktime(0,0,0,$month,1,$year));

# initialize day variable to zero, unless $weekpos is zero
if ($weekpos == 0$day 1; else $day 0;

# initialize today's date variables for color change
$timestamp mktime() + CURR_TIME_OFFSET 3600;
$d date('j'$timestamp); 
$m date('n'$timestamp); 
$y date('Y'$timestamp);

# lookup for testing whether day is today
$today["$y-$m-$d"] = 1;

# loop writes empty cells until it reaches position of 1st day of 
# month ($wPos).  It writes the days, then fills the last row with empty 
# cells after last day
while($day <= $days) {
$str .="<tr>\n";

# write row
for($i=0;$i 7$i++) {
# if cell is a day of month
if($day && $day <= $days) {
# set css class today if cell represents current date
$class = (isset($today["$year-$month-$day"])) ? 'today' 'day';

$str .= "
<td class=\"
{$class}_cell\" valign=\"top\">
<span class=\"day_number\">\n"
;

if ($_SESSION[db('website').'Logged_In'] == token()) {
$str .= "
<a href=\"javascript: postMessage(
$day$month$year)\">
$day</a>";
} else {
$str .= "$day";
}
$str .= "</span><br>";

if (isset($eventdata[$day]["title"])) {
// enforce title limit
$eventcount count($eventdata[$day]["title"]);

if (MAX_TITLES_DISPLAYED $eventcount) {
$eventcount MAX_TITLES_DISPLAYED;
}

// write title link if day's postings 
for($j=0;$j $eventcount;$j++) {
$str .= "
<span class=\"title_txt\">
-<a href=\"javascript:openPosting("
$eventdata[$day]["id"][$j] . ")\">"
$eventdata[$day]["title"][$j] . "</a></span>"
$eventdata[$day]["timestr"][$j];
}
}

$str .= "</td>\n";
$day++;
} elseif($day == 0)  {
     
$str .= "
<td class=\"empty_day_cell\" valign=\"top\">&nbsp;</td>\n"
;
$weekpos--;
if ($weekpos == 0$day++;
     
} else {
$str .= "
<td class=\"empty_day_cell\" valign=\"top\">&nbsp;</td>\n"
;
}
     
}
$str .= "</tr>\n\n";
}
$str .= "</table>\n\n";
return $str;
}

# ###################################################################

function getDayNameHeader()
{
global $lang;

// adjust day name order if weekstart not Sunday
if (WEEK_START != 0) {
for($i=0$i WEEK_START$i++) {
$tempday array_shift($lang['abrvdays']);
array_push($lang['abrvdays'], $tempday);
}
}

$s "<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\">\n<tr>\n";

foreach($lang['abrvdays'] as $day) {
$s .= "\t<td class=\"column_header\">&nbsp;$day</td>\n";
}

$s .= "</tr>\n\n";
return $s;
}

# ###################################################################

function getEventDataArray($month$year)
{
$eventdata null;
mysql_connect(DB_HOSTDB_USERDB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());

$sql "SELECT id, d, title, start_time, end_time, ";

if (TIME_DISPLAY_FORMAT == "12hr") {
$sql .= "TIME_FORMAT(start_time, '%l:%i%p') AS stime, ";
$sql .= "TIME_FORMAT(end_time, '%l:%i%p') AS etime ";
} elseif (TIME_DISPLAY_FORMAT == "24hr") {
$sql .= "TIME_FORMAT(start_time, '%H:%i') AS stime, ";
$sql .= "TIME_FORMAT(end_time, '%H:%i') AS etime ";
} else {
echo "Bad time display format, check your configuration file.";
}

$sql .= "
FROM " 
DB_TABLE_PREFIX "mssgs WHERE m = $month AND y = $year
ORDER BY start_time"
;

$result mysql_query($sql) or die(mysql_error());

while($row mysql_fetch_assoc($result)) {
$day $row["d"];
$eventdata[$day]["id"][] = $row["id"];

# set title string; limit char length and append ellipsis if necessary
$title stripslashes($row["title"]);
$eventdata[$day]["title"][] = (strlen($title) > TITLE_CHAR_LIMIT)
substr($title0TITLE_CHAR_LIMIT) . '...'
$title

# set time string
if (!($row["start_time"] == "55:55:55" 
&& $row["end_time"] == "55:55:55")) {
$starttime 
= ($row["start_time"] == "55:55:55") ? "- -" $row["stime"];
$endtime 
= ($row["end_time"] == "55:55:55") ? "- -" $row["etime"];

$timestr "
<div align=\"right\" class=\"time_str\">
(
$starttime - $endtime)&nbsp;</div>\n";
} else {
$timestr "<br />";
}
$eventdata[$day]["timestr"][] = $timestr;
}
return $eventdata;
}

# ###################################################################

function getFirstDayOfMonthPosition($month$year)
{
$weekpos date("w"mktime(0,0,0,$month,1,$year));

// adjust position if weekstart not Sunday
if (WEEK_START != 0) {
if ($weekpos WEEK_START) {
$weekpos $weekpos WEEK_START;
} else {
$weekpos $weekpos WEEK_START;
}
}
return $weekpos;
}

# ###################################################################

?>

Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 24, 2007, 01:55:30 am
change include strings from snewsMU.php to config.php (MEMU config, not calendar config)
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 24, 2007, 02:08:18 am
seems like we are going somwhere.. We have finaly got the cal up and running, a bit hard to start the css.. so ass you can see in the page, it looks a litle different from what I am hoping for.

http://www.xclusive.name/kaff/cal/
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 24, 2007, 02:12:39 am
nice to see you have it working  :)
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 24, 2007, 02:39:26 pm
I removed the cal_pages and included the important line into the original default_pages function. Remember to edit the defuault.php to use defualt_pages instead of cal_pages.

Code: [Select]
function default_pages() {
$categorySEF = get_id('category'); $pageSEF = get_id('article'); $home = l('home_sef');
$class = (empty($categorySEF) || $categorySEF == $home && empty($pageSEF)) ? ' class="current"' : '';
if (s('disable_home') != 'on') {
echo '<li><a'.$class.' href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></li>';
$class = ($categorySEF == 'archive') ? ' class="current"' : '';
} # closes "if"
          if (s('disable_archive') != 'on') {
$class = ($categorySEF == 'archive') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'archive/" title="'.l('archive').'">'.l('archive').'</a></li>';
} # closes "if"

------------------
          if (s('disable_cal') != 'on') {
$class = ($categorySEF == 'cal') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'cal/" title="'.l('events').'">'.l('events').'</a></li>';
} # closes "if"
------------------

      if (s('disable_contact') != 'on') {
$class = ($categorySEF == 'contact') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'contact/" title="'.l('contact').'">'.l('contact').'</a></li>';
} # closes "if"
      if (s('disable_sitemap') != 'on') {
$class = ($categorySEF == 'sitemap') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'sitemap/" title="'.l('sitemap').'">'.l('sitemap').'</a></li>';
} # closes "if"
## MULTI_USER - Displays the public "Register" link in pages menu
if (s('registration_off') != 'on') {
if ($_SESSION[db('website').'Logged_In'] != token()) {
$class = ($categorySEF == 'register') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'register/" title="'.l('register').'">'.l('register').'</a></li>';
} // closes 2nd "if"
} // closes 1st "if"
## END MULTI_USER
}

As you can see this defalt_pages function is already altered, made by keyrocks in the snewsMEMU. Because I wanted to have the calendar into the menu in the original text, I made these changes to leave out the cal_pages function and make the paged function more smooth. This works fine for me, and should do so in the package if you chose to make  changes to your mod.

I'm also looking for a solution to include the cal_breadcrumbs and cal_title into the original functions aswell.

Some other questions: I am struggling with the calender css, is there any default css calss made in the function.php that I dont see?

It seems to be 2 problems with the way I'm puting the calendar into the default_pages function. The first one si If you look at the calendar in the browser http://www.xclusive.name/kaff/cal/ you vil notise that link:active tag markes the wrong link. It say that its at home instead of calendar. Is there an explenation? If I should gues, the problem is related to this line    $class = ($categorySEF == 'cal') ? ' class="current"': '';       but why, I don't know.

The second is that you cant use the catergories links on the left side, it would not expand so that you can se the articles under each categori. The strange thing is that I can use everything else.

I have also experienced that the User Status box sometime will be empty. Is this a bug in you package Keyrocks?
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 24, 2007, 03:46:30 pm
After looking at the cal_title and cal_breadcrumbs, it seems that you have to make a big change to the PEC to get it to work and include it into the snewsMEMU, atleast more than I can manage to do, since I dont know the script to well, and I don't do programing.

If Keyrocks could be so kind to do a thing like that, he would be one of the greatest men on the earth. :D

I realy would like this to work 100% and to be included as an option in to admin so you can chose to use the "cal" or not.

What do you say Keyrock, is this a task you would manage to do?
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 24, 2007, 04:20:24 pm
Quote from: Anders Hansen
I have also experienced that the User Status box sometime will be empty. Is this a bug in you package Keyrocks?

Not that I am aware of... I have never had this experience with my installations.

Quote from: Anders Hansen
If Keyrocks could be so kind to do a thing like that, he would be one of the greatest men on the earth.
What do you say Keyrock, is this a task you would manage to do?

Thank you for the kind comment. I would... if I had the time... but I am far behind on several other projects that must be completed first. Please remember that we sNews Dudes volunteer our time to help members get their sNews packages installed and running... and anything more that we might provide beyond that is done if and when we have the time to do so. We encourage all members to modify and add more functionality to sNews the same way we did... by doing and learning by trial and error along the way. :)
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 24, 2007, 08:12:30 pm
I removed the cal_pages and included the important line into the original default_pages function. Remember to edit the defuault.php to use defualt_pages instead of cal_pages.

Code: [Select]
function default_pages() {
$categorySEF = get_id('category'); $pageSEF = get_id('article'); $home = l('home_sef');
$class = (empty($categorySEF) || $categorySEF == $home && empty($pageSEF)) ? ' class="current"' : '';
if (s('disable_home') != 'on') {
echo '<li><a'.$class.' href="'.db('website').'" title="'.l('home').'">'.l('home').'</a></li>';
$class = ($categorySEF == 'archive') ? ' class="current"' : '';
} # closes "if"
          if (s('disable_archive') != 'on') {
$class = ($categorySEF == 'archive') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'archive/" title="'.l('archive').'">'.l('archive').'</a></li>';
} # closes "if"

------------------
          if (s('disable_cal') != 'on') {
$class = ($categorySEF == 'cal') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'cal/" title="'.l('events').'">'.l('events').'</a></li>';
} # closes "if"
------------------

      if (s('disable_contact') != 'on') {
$class = ($categorySEF == 'contact') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'contact/" title="'.l('contact').'">'.l('contact').'</a></li>';
} # closes "if"
      if (s('disable_sitemap') != 'on') {
$class = ($categorySEF == 'sitemap') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'sitemap/" title="'.l('sitemap').'">'.l('sitemap').'</a></li>';
} # closes "if"
## MULTI_USER - Displays the public "Register" link in pages menu
if (s('registration_off') != 'on') {
if ($_SESSION[db('website').'Logged_In'] != token()) {
$class = ($categorySEF == 'register') ? ' class="current"': '';
echo '<li><a'.$class.' href="'.db('website').'register/" title="'.l('register').'">'.l('register').'</a></li>';
} // closes 2nd "if"
} // closes 1st "if"
## END MULTI_USER
}

As you can see this defalt_pages function is already altered, made by keyrocks in the snewsMEMU. Because I wanted to have the calendar into the menu in the original text, I made these changes to leave out the cal_pages function and make the paged function more smooth. This works fine for me, and should do so in the package if you chose to make  changes to your mod.

I'm also looking for a solution to include the cal_breadcrumbs and cal_title into the original functions aswell.

Some other questions: I am struggling with the calender css, is there any default css calss made in the function.php that I dont see?

It seems to be 2 problems with the way I'm puting the calendar into the default_pages function. The first one si If you look at the calendar in the browser http://www.xclusive.name/kaff/cal/ you vil notise that link:active tag markes the wrong link. It say that its at home instead of calendar. Is there an explenation? If I should gues, the problem is related to this line    $class = ($categorySEF == 'cal') ? ' class="current"': '';       but why, I don't know.

The second is that you cant use the catergories links on the left side, it would not expand so that you can se the articles under each categori. The strange thing is that I can use everything else.

I have also experienced that the User Status box sometime will be empty. Is this a bug in you package Keyrocks?

The default installation instructions and package rectifies some of these problems.  For example, leaving the doctype unchanged rectifies the css problem, and using the  cal_pages function rectifies the class="current" issue.  Then, add the calendar link to the default_pages for the rest of the site.

Everything in the default calendar package and instructions is there for a reason.  Edit at your own risk  ;)
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 26, 2007, 06:48:31 am
Ok. So fare I have redone to the default instructions, but I still have det problem that I described when you press any category while viewing the callendar.. Some Ideas?

So fare thanx for all you help..  both of you..

And keyrocks: It seems like there is a conflict with the user status box with this addon.. The text inside disapers some times..
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 27, 2007, 10:41:57 pm
@ Anders... how are you making out with the phpEvent Calendar project?
I am caught up with my other projects... and have installed this in my MEMU package today... it was a little tricky following through all the notes in this topic though. I now have NO css applied from the default sNews template. How did you manage to get the CSS display problem solved?
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 28, 2007, 12:59:43 am
screenshot and/or link?

if you added a base href in the title() function, you'll have issues.
If you change the doctype, you'll have issues (although if you look at Anders' source code on his website, you'll see that hes thought of a creative solution)

I ran into a little issue with the package today.  I found that relative links in the extra(); function have issues.  For example, if you have "Contact us" in the extra box with an href of "contact/", it wont work because it goes to cal/contact/.  A workaround for this is absolute URLs.  A real fix would be to adda  base href in the title function, although a significant portion of the calendar would need to be rewritten to add cal/ to the links.

And now for the bonus :)
Is there interest in a recurring events within the month feature?  If so, I'll post the code up here.  The method is crude (looping through checkboxes), but it works. 
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 28, 2007, 03:11:16 am
1 - screenshot and/or link?

2 - I ran into a little issue with the package today.  I found that relative links in the extra(); function have issues.  For example, if you have "Contact us" in the extra box with an href of "contact/", it wont work because it goes to cal/contact/.  A workaround for this is absolute URLs.  A real fix would be to adda  base href in the title function, although a significant portion of the calendar would need to be rewritten to add cal/ to the links.

3 - And now for the bonus :) Is there interest in a recurring events within the month feature?  If so, I'll post the code up here.  The method is crude (looping through checkboxes), but it works. 
1 - My project is on localhost... nothing to see really... the calendar's template has no css applied... was out for most of the evening... just had a look in the templates/default.php file and I see the problem. The stylesheet link string is not accessing my style.css file... because it is located in sNews/templates/default/css/style.css... a long ways off. We'll have to figure a way to make this switchable so that when we change templates from the Admin panel... (using Bakercad's Template Switch Mod) the right stylesheet will always apply to the calendar's template file.

2 & 3 - If its worthing anything to you Mike... I believe this calendar can be an excellent addon to sNews. I have several clients that want a full-sized calendar... and one with recurring events... which is particularly useful for scheduling meetings and events that happen on the same day every month all year long. It's good for clubs... non-profit organizations... and community portals. It appears you have come to know the calendar script very well... so you I suggest you should continue as the "Project Leader" on improving it... if you are up to it that is. For instance... you've noted that URL issue... and that could likely be solved by using variables to replace stuff throughout the files. And since you know your way around it better than the rest of us... you have the credentials to do it. So... You are nominated to continue refining this calendar script as an sNews Addon.  ;)
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 28, 2007, 05:29:04 am
Hello Keyrocks and Mike1.

Keyrocks: You had the same problem as myself at the start. I did not understand why the css file did not load. But I got the hang of it, and I hope you have an idé of how to make it work with the MEMU. I have to give you a big thanks for making the package. I actually got my university to open there eyes for the site I am building.

It seems like I good idé to add the calendar to the MEMU, I should realy be thankfull if you manage to include the calender into the site.
 
I get another fontsize than the snews template because of a different doctype in the cal default.php. If you have a solution with that problem, I am thankfull if you could tel me. If it is possible to change it to xhtml like in the MEMU it would be great. I'm not good with codes, so I would like to have some help there if it's possible. Somthing else that i have noticed is that it either looks like there is a tag or a class/id in the css that is not ass it should be. When I press the Your Profile in the status box it looks like the adminpanel is bleeding or something. One of the things is that the "save button is at the top left side of the extrabox on the top. It seems like it it is just when you are logged in as an siteadmin. I dont know if you have seen it, but since i have a black background, it is much easyer to spot.. 

And mike1: Nice that you found the issue with relative liks in extras. Thats the same thing I tried to explain, but my english is not the greatest, so It would be some difficulties understanding what I was trying to explain.

The addon to the cal to sound great. To make recurring events would be nice to have..

Karma from me to both of you..
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 28, 2007, 07:16:45 am
Adds recurring events for the month

New eventform.php
Code: [Select]
<?php
session_start
();
require(
"config.php");
require(
"./lang/lang.admin." LANGUAGE_CODE ".php");
require(
"functions.php");
include(
"../snews.php");

$id   = (isset($_GET['id'])) ? $_GET['id'] : null;

if (
$_SESSION[db('website').'Logged_In'] == token()) {
if (empty($id)) {
displayEditForm('Add');
} else {
if ($_SESSION[db('website').'Logged_In'] == token()) {
displayEditForm('Edit'$id);
} else {
echo $lang['accessdenied'];
}
}
} else {
echo $lang['accessdenied'];
}

# ###########################################################

function 
displayEditForm($mode$id="")
{
global $lang;

if ($mode == "Add") {
$d  $_GET['d'];
$m  $_GET['m'];
$y  $_GET['y'];
$text  $title "";
$headerstr  $lang['addheader'];
$buttonstr  $lang['addbutton'];
$pgtitle  $lang['addeventtitle'];
$qstr  "?flag=add";
$stime_vals null;
$etime_vals null;
} elseif ($mode == "Edit") {

mysql_connect(DB_HOSTDB_USERDB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());

$sql "SELECT y, m, d, start_time, end_time, title, text ";
$sql .= "FROM " DB_TABLE_PREFIX "mssgs WHERE id = $id";

$result mysql_query($sql) or die(mysql_error());
$row mysql_fetch_assoc($result);

if (!empty($row)) {
$qstr  "?flag=edit&id=$id";
$headerstr  $lang['editheader'];
$buttonstr $lang['editbutton'];
$pgtitle  $lang['editeventtitle'];
$title  stripslashes($row["title"]);
$text  stripslashes($row["text"]);
$m  $row["m"];
$d  $row["d"];
$y  $row["y"];
}

$stime_vals getPullDownTimeValues($row["start_time"]);
$etime_vals getPullDownTimeValues($row["end_time"]);
#, $ehour, $eminute, $epm);
} else {
$lang['accesswarning'];
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php echo $pgtitle ?></title>
<link rel="stylesheet" type="text/css" href="css/popwin.css">

<script language="JavaScript">
function formSubmit() {
if (document.eventForm.title.value != "") {
document.eventForm.method = "post";
document.eventForm.action = "eventsubmit.php<?php echo $qstr ?>";
document.eventForm.submit();
} else {
alert("<?php echo $lang['titlemissing'?>");
}
}
</script>

</head>
<body>
<span class="add_new_header"><?php echo $headerstr ?></span>
<br><img src="images/clear.gif" width="1" height="5"><br>
<table border=0 cellspacing=7 cellpadding=0>
<form name="eventForm">
<tr>
<td nowrap valign="top" align="right" nowrap><span class="form_labels"></span></td>
<td><?php monthPullDown($m$lang['months']); dayPullDown($d); yearPullDown($y); ?></td>
</tr>
<tr>
<td nowrap valign="top" align="right" nowrap>
<span class="form_labels"><?php echo $lang['title']?></span></td>
<td><input type="text" name="title" size="29" value="<?php echo $title ?>" maxlength="50"></td>
</tr>
<tr>
<td nowrap valign="top" align="right" nowrap>
<span class="form_labels"><?php echo $lang['text']?></span></td>
<td><textarea cols=22 rows=6 name="text"><?php echo $text ?></textarea></td>
</tr>
<tr>
<td valign="top" align="right" nowrap><span class="form_labels"><?php echo $lang['starttime'?></span></td>
<td><?php hourPullDown($stime_vals['hour'], "start"); ?><b>:</b><?php minPullDown($stime_vals['minute'], "start"); amPmPullDown($stime_vals['pm'], "start"); ?></td>
</tr>
<tr>
<td valign="top" align="right" nowrap><span class="form_labels"><?php echo $lang['endtime'?></span></td>
<td><?php hourPullDown($etime_vals['hour'], "end"); ?><b>:</b><?php minPullDown($etime_vals['minute'], "end"); amPmPullDown($etime_vals['pm'], "end"); ?></td>
</tr>
            <tr>
<? if ($mode == "Add") { ?>
<td nowrap valign="top" align="right">Or</td>
<td width="208"></td>
</tr>
<tr>
<td nowrap valign="top" align="right"><span class="form_labels">Reoccuring Event:<br>
</span><span class="form_labels">Days of this month:</span></td>
<td width="208">
<table border="0" cellspacing="2" cellpadding="0">
<tr height="19">
<td align="right" width="41" height="19">1<input type="checkbox" name="1" value="1" border="0"></td>
<td align="right" width="38" height="19">2<input type="checkbox" name="2" value="1" border="0"></td>
<td align="right" width="38" height="19">3<input type="checkbox" name="3" value="1" border="0"></td>
<td align="right" width="40" height="19">4<input type="checkbox" name="4" value="1" border="0"></td>
<td align="right" width="39" height="19">5<input type="checkbox" name="5" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">6<input type="checkbox" name="6" value="1" border="0"></td>
<td align="right" width="38" height="19">7<input type="checkbox" name="7" value="1" border="0"></td>
<td align="right" width="38" height="19">8<input type="checkbox" name="8" value="1" border="0"></td>
<td align="right" width="40" height="19">9<input type="checkbox" name="9" value="1" border="0"></td>
<td align="right" width="39" height="19">10<input type="checkbox" name="10" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">11<input type="checkbox" name="11" value="1" border="0"></td>
<td align="right" width="38" height="19">12<input type="checkbox" name="12" value="1" border="0"></td>
<td align="right" width="38" height="19">13<input type="checkbox" name="13" value="1" border="0"></td>
<td align="right" width="40" height="19">14<input type="checkbox" name="14" value="1" border="0"></td>
<td align="right" width="39" height="19">15<input type="checkbox" name="15" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">16<input type="checkbox" name="16" value="1" border="0"></td>
<td align="right" width="38" height="19">17<input type="checkbox" name="17" value="1" border="0"></td>
<td align="right" width="38" height="19">18<input type="checkbox" name="18" value="1" border="0"></td>
<td align="right" width="40" height="19">19<input type="checkbox" name="19" value="1" border="0"></td>
<td align="right" width="39" height="19">20<input type="checkbox" name="20" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">21<input type="checkbox" name="21" value="1" border="0"></td>
<td align="right" width="38" height="19">22<input type="checkbox" name="22" value="1" border="0"></td>
<td align="right" width="38" height="19">23<input type="checkbox" name="23" value="1" border="0"></td>
<td align="right" width="40" height="19">24<input type="checkbox" name="24" value="1" border="0"></td>
<td align="right" width="39" height="19">25<input type="checkbox" name="25" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">26<input type="checkbox" name="26" value="1" border="0"></td>
<td align="right" width="38" height="19">27<input type="checkbox" name="27" value="1" border="0"></td>
<td align="right" width="38" height="19">28<input type="checkbox" name="28" value="1" border="0"></td>
<td align="right" width="40" height="19">29<input type="checkbox" name="29" value="1" border="0"></td>
<td align="right" width="39" height="19">30<input type="checkbox" name="30" value="1" border="0"></td>
</tr>
<tr height="19">
<td align="right" width="41" height="19">31<input type="checkbox" name="31" value="1" border="0"></td>
<td align="right" width="38" height="19"></td>
<td align="right" width="38" height="19"></td>
<td align="right" width="40" height="19"></td>
<td align="right" width="39" height="19"></td>
</tr>
</table>
</td><? } ?>
</tr>
            <tr><td></td><td><br><input type="button" value="<?php echo $buttonstr ?>" onClick="formSubmit()">&nbsp;<input type="button" value="<?php echo $lang['cancel'?>" onClick="window.close();"></td></tr>
</form>
</table>
</body>
</html>
<?php
}

# ###########################################################

function getPullDownTimeValues($time
{
$hour = (int) substr($time02);
$minute = (int) substr($time32);
$pm     false;

if ($hour == 55) {
$hour 0;
$minute 0;
} elseif ($hour 12) {
$hour $hour 12;
$pm true;
} elseif ($hour == 12) {
$pm true;
} elseif ($hour == 0) {
$hour 12;
$pm false;
}
return Array('hour' => $hour'minute' => $minute'pm' => $pm);
}

# ###########################################################
?>


New eventsubmit.php
Code: [Select]
<?php
session_start
();
require(
"config.php");
require(
"./lang/lang.admin." LANGUAGE_CODE ".php");
require(
"functions.php");
include(
"../snews.php");

if (
$_SESSION[db('website').'Logged_In'] == token()) {
switch ($_GET['flag']) {
case "add" :
submitEventData();
break;
case "edit":
$id = (int) $_GET['id'];

if (!empty($id))
submitEventData($id);
else
$lang['accesswarning'];
break;
case "delete":
$month  = (int) $_GET['month'];
$year = (int) $_GET['year'];
$id  = (int) $_GET['id'];

if (!(empty($id) && empty($month) && empty($year)))
deleteEvent($id$month$year);
else
$lang['accesswarning'];
break;
default:
$lang['accesswarning'];
}
} else {
echo $lang['accessdenied'];
}


function 
submitEventData ($id="")
{
global $lang;

$title  addslashes($_POST['title']);
$title strip_tags($title);
$text  addslashes($_POST['text']);
$text strip_tags($text);
$month  $_POST['month'];
$day  $_POST['day'];
$year  $_POST['year'];
$shour  $_POST['start_hour'];
$sminute  $_POST['start_min'];
$s_ampm  $_POST['start_am_pm'];
$ehour  $_POST['end_hour'];
$eminute  $_POST['end_min'];
$e_ampm  $_POST['end_am_pm'];
$a1 $_POST['1'];
$a2 $_POST['2'];
$a3 $_POST['3'];
$a4 $_POST['4'];
$a5 $_POST['5'];
$a6 $_POST['6'];
$a7 $_POST['7'];
$a8 $_POST['8'];
$a9 $_POST['9'];
$a10 $_POST['10'];
$a11 $_POST['11'];
$a12 $_POST['12'];
$a13 $_POST['13'];
$a14 $_POST['14'];
$a15 $_POST['15'];
$a16 $_POST['16'];
$a17 $_POST['17'];
$a18 $_POST['18'];
$a19 $_POST['19'];
$a20 $_POST['20'];
$a21 $_POST['21'];
$a22 $_POST['22'];
$a23 $_POST['23'];
$a24 $_POST['24'];
$a25 $_POST['25'];
$a26 $_POST['26'];
$a27 $_POST['27'];
$a28 $_POST['28'];
$a29 $_POST['29'];
$a30 $_POST['30'];
$a31 $_POST['31'];
//$reoccurevent = $HTTP_POST_VARS['reoccurevent'];

if ($shour == && $sminute == && $s_ampm == 0) {
$starttime "55:55:55";
} else {
if (
$s_ampm == && $shour != 12$shour $shour 12;
if (
$s_ampm == && $shour == 12$shour 0;
$starttime "$shour:$sminute:00";
}

if (
$ehour == && $eminute == && $e_ampm == 0) {
$endtime "55:55:55";
} else {
if (
$e_ampm == && $ehour != 12$ehour $ehour 12;
if (
$e_ampm == && $ehour == 12$ehour 0;
$endtime "$ehour:$eminute:00";
}

mysql_connect(DB_HOSTDB_USERDB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());

if (
$id) {
$sql "UPDATE " DB_TABLE_PREFIX "mssgs SET m='$month', d='$day', y='$year', ";
$sql .= "start_time='$starttime', end_time='$endtime', title='$title', text='$text' ";
$sql .= "WHERE id=$id";
$result $lang['updated'];
mysql_query($sql) or die(mysql_error());
} else {
// If any of the reoccuring check boxes are checked then add all of them
// or else just add a one day event
$reoccur = array($a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,$a10,$a11,$a12,$a13,$a14,$a15,$a16,$a17,$a18,$a19,$a20,$a21,$a22,$a23,$a24,$a25,$a26,$a27,$a28,$a29,$a30,$a31);
for(
$count 0$count <= count($reoccur); $count++)
{
if (
$reoccur[$count] == '1') {$reoccurevent 1;}
}

// Add Reoccuring event
if ($reoccurevent == '1')
{
for(
$count 0$count <= count($reoccur); $count++)
{
if (
$reoccur[$count] == '1')
{
$count++;
$sql "INSERT INTO " DB_TABLE_PREFIX "mssgs SET m=$month, d=$count, y=$year, ";
$sql .= "start_time='$starttime', end_time='$endtime', title='$title', text='$text'";
$count--;
mysql_query($sql) or die(mysql_error());
}
}

}
// Add one day event
else
{
$sql "INSERT INTO " DB_TABLE_PREFIX "mssgs SET m=$month, d=$day, y=$year, ";
$sql .= "start_time='$starttime', end_time='$endtime', title='$title', text='$text'";
mysql_query($sql) or die(mysql_error());
}
$result $lang['added'];
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/popwin.css">
<script language="JavaScript">
opener.location =
"index.php?month=<?php echo $month ?>&year=<?php echo $year ?>";
window.setTimeout('window.close()', 1000);
</script>
</head>
<body>

<div align=\"center\" class=\"display_txt\">
<?php echo stripslashes($title?> <?php echo $result ?></div>

</body>
</html>
<?php
}

function deleteEvent($id, $m, $y)
{
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());

$sql = "DELETE FROM " . DB_TABLE_PREFIX . "mssgs WHERE id = $id";
$result = mysql_query($sql) or die(mysql_error());

header("Location: index.php?month=$m&year=$y");
}
?>


Make a small change to functions.php (window sizing issue)
In functions.php, find
Code: [Select]
function postMessage(day, month, year) {and you will see about 4 lines down
Code: [Select]
width=340,height=400(or some other numbers)
change it to
Code: [Select]
width=540,height=600'
Remember to change the include file paths for integration in MESU/MEMU package'
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 28, 2007, 07:38:54 am
Mike: I have done the things you said, but that did not do the trick.. I get a white eventpostingpage..

www.xclusive.name/kaff/cal/
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 28, 2007, 08:06:02 am
that sounds like an include error because i dont get an access denied error when trying to access it.

make sure to change
Code: [Select]
include ('../snews.php') to
Code: [Select]
include('../config.php');
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 28, 2007, 08:28:18 am
thanx mike1.. that was just a dumb thing from my side. I did not remember what to change to. i wrote snewsMU and not config
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 28, 2007, 07:28:21 pm
TEST RESULTS WITH MEMU Package:
OK... I spent a few hours working with this mod in my MEMU project and there are a few problems I have not been able to solve... so I will put this aside for now to get on to other priorities for a while. I had experienced most of the same problems with it before in early 1.5.31 SU projects well, so they are calendar-script related. I thought it would be a good idea to list them here as a reference for anyone trying to make this work with the MEMU package. Some of these were already reported by Anders.

DOC TYPE BUG
Using the existing DOCTYPE string in cal/templates/default.php causes the template to lose its left-margin, shifting everything to the very edge of the screen. Replacing it with the DOCTYPE strings from the sNews index.php file restores the left-margin... but the calendar itself shrinks... distorted and quite small with the black background mostly exposed.

ADD EVENT LINK BUG
 ... <a href="javascript: postMessage()" title="Add Event">Add Event</a> ... - added under the "Files" panel link in function administration() throws a "404" error and... though the prompt panel for creating adding an event pops up... it contains the template instead of the add event panel.

CALENDAR LINK NOT CURRENT
The Calendar link shows as current when using the cal_pages function... but "Home" shows as the current page-link when using the default_pages function (with Bram's switchable default pages mod). There should be a way to adjust that somehow.

CATEGORY LISTS
My MEMU package uses Philmoz's expandable category links mod... an absolute necessity for listing lots of article-links and page-links by category. There is a javascript conflict going on here.

CSS LINKING ISSUE
The MEMU package... as well as the MESU package... both use Bakercad's Template Switch mod, which keeps template folders (by name) in a root/templates directory. Each template folder contains its own files in more folders... css, images, and other template-specific scripts... as well as its own index.php (template) file. The calendar's template file - cal/templates/default.php (or other name) have the stylesheet link hard-coded... and it can only apply to one sNews template's stylesheet file. We can create more template files in the calendar's templates folder by name... but the only way to switch them is by changing a string in the cal/config.php file. To work with Bakercad's Template Switch mod... we'll need to devise a way of switching the calendar template file when the sNews template is switched from the Admin >> Settings >> Templates panel.

In general... I still like the phpEvent Calendar script. Mike1 has made some significant, positive changes to this version. It has great potential... and we should thank Mike1 for providing the "Recurring Events" mod as well. However... it still needs some work to get it functioning well enough (without bugs) for use in an actual online site. Keep refining this one Mike.  :)

Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 28, 2007, 10:01:15 pm
Rocks: This is how I solved the edd event link. If it givs any help, just tell me.

      ## MULTI_USER - files manager panel
      $permit_upload = retrieve('permit_upload', 'users', 'id', $_SESSION['id']);
      if ($permit_upload == 'YES' || get_identity($_SESSION['id'], 'level') == '1') {
      # admin panel mod
      echo '<div class="admpanel"><center><span class="admintitle">'.l('mu_upload files').'</span><br />'.l('admintips2a').'<br />';
      echo '<a href="files/" title="'.l('files').'">'.l('files').'</a>';
      echo '<p><a href="javascript: postMessage()" title="Add Event">Add Event</a></fieldset></p>';
      echo '</center></div>';
                ## END MULTI_USER files manager panel

Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 28, 2007, 11:15:16 pm
Actually... echo '<br /><a href="javascript: postMessage()" title="Add Event">Add Event</a>'; will do the job a bit better. There is no need to close </fieldset> since the opening tag is removed... and if we replace the opening <p>-tag... there is no need to close it either. The problem I am having though is that the javascript action - postMessage() is not opening the add message panel... it's throwing "404"... so maybe I have to check out the function that generates that "add event" panel.
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 29, 2007, 12:30:55 am
Actually... echo '<br /><a href="javascript: postMessage()" title="Add Event">Add Event</a>'; will do the job a bit better. There is no need to close </fieldset> since the opening tag is removed... and if we replace the opening <p>-tag... there is no need to close it either. The problem I am having though is that the javascript action - postMessage() is not opening the add message panel... it's throwing "404"... so maybe I have to check out the function that generates that "add event" panel.


check step 7
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 29, 2007, 02:22:54 am
Yepp... I've done Step 7. So what would keep the link from functioning properly?
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 29, 2007, 03:10:33 am
step 7 adds another javascript function to the js() function that is activated if you are logged into the snews admin.  The javascript postmessage() in the add event link calls that function.  There would be 2 reasons that it isnt working.

1.  check the path to eventform.php in step 7.  Because youre calling it from snews.php, it should read <calendar directory>/eventform.php
2.  postmessage() is being declared twice in your snews index.php.  One of the declarations says the path to eventform.php is just plain eventform.php, while the second declaration is correct (cal/eventform.php).  You can only have one declaration, so I would check your source.

In all likelihood, its the second issue

Even if that doesn't work, you can add events through the calendar page by logging in and clicking on the date (which I find more convenient since the date is automatically filled in)
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 29, 2007, 05:22:19 pm

2.  postmessage() is being declared twice in your snews index.php.  One of the declarations says the path to eventform.php is just plain eventform.php, while the second declaration is correct (cal/eventform.php).  You can only have one declaration, so I would check your source.

Even if that doesn't work, you can add events through the calendar page by logging in and clicking on the date (which I find more convenient since the date is automatically filled in)
Thanks Mike. The path in the js function is correct... there by default... and the file is located (with all others) in root/cal. As you note... the link in the "Files" panel isn't required since all events can be added/edited/deleted by the Admin by date-clicking when logged in.
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 29, 2007, 06:46:12 pm
are there 2 declarations of postmessage() when you view source?
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 30, 2007, 02:41:20 am
are there 2 declarations of postmessage() when you view source?
No... only one. Interesting discovery though... I re-activated the "Add Event" link under the "Files" link in function administration. Clicking it in Firefox renders the "Add Event" pop-up OK... yet in IE7 the pop-up continues to throw the sNews "404" error message... within a full template... "Requested contents could not be found. Please go back or use the search feature." Now... why would it work OK in FF and not in IE7  ???
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 30, 2007, 02:48:40 am
are there 2 declarations of postmessage() when you view source?
No... only one. Interesting discovery though... I re-activated the "Add Event" link under the "Files" link in function administration. Clicking it in Firefox renders the "Add Event" pop-up OK... yet in IE7 the pop-up continues to throw the sNews "404" error message... within a full template... "Requested contents could not be found. Please go back or use the search feature." Now... why would it work OK in FF and not in IE7  ???

Do you have the same problem when you log in to my site key? Coz i dont have the same problem as you when I use safari.
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 30, 2007, 03:02:12 am
Do you have the same problem when you log in to my site key? Coz i dont have the same problem as you when I use safari.
Yes... as a matter of fact... I do... the "404" page displays in IE7... in the Add Event Panel on your site too... it IS a friggin' IE7 issue  :(
I know... the quick answer is stop using IE7... but in reality... we will have to make things work with it even it is a pain in the **s because most average, everyday computer users have it on their Windows-powered machines. Dissappointing... eh?
Title: Re: [ADDON] phpEventCalendar
Post by: Joost on November 30, 2007, 03:17:52 am
This means that the request, send by IE7 is malformed and is not recognized by sNews/Calendar. Find out what should have been send and what has been received by sNews.
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on November 30, 2007, 03:28:04 am
This means that the request, send by IE7 is malformed and is not recognized by sNews/Calendar. Find out what should have been send and what has been received by sNews.
Sounds like a heck of a good idea Joost... but it's beyond my comprehension... remember I'm just an old, retired geezer who dabbles with this webbie stuff in a learn-as-I-go sorta way.  :P
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 30, 2007, 03:56:50 am
I have found more problems with the Calendar: When you press the green arrow while looking at the calendar, it gots back to the top of the root og sNews.  And the your profile/Site Admin/Logout disapares allong with the  Site settings and the Filemanager in the Admin panel in MEMU. This is a error that i found both in FF and Safari.

I have manage to find the error with the admin logout you profile and the settings menu disapearing. When you go to the calendarview and pres a date to add a event, not from the add event under the filemanager.  And you quit the add event window without adding. And the go bak to home, the errer is making problems.
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 30, 2007, 06:06:53 am
I have found more problems with the Calendar: When you press the green arrow while looking at the calendar, it gots back to the top of the root og sNews.  And the your profile/Site Admin/Logout disapares allong with the  Site settings and the Filemanager in the Admin panel in MEMU. This is a error that i found both in FF and Safari.

I have manage to find the error with the admin logout you profile and the settings menu disapearing. When you go to the calendarview and pres a date to add a event, not from the add event under the filemanager.  And you quit the add event window without adding. And the go bak to home, the errer is making problems.

one again, this sounds like a base href problem.  I think i have to modify a good chunk of the calendar to rectify it.  As I look at the calendar now, a lot of what I did was to make the calendar template and snews template play nice with each other.  In the environment of snews (being as flexible as it is), I dont believe this is a viable option.  I have some ideas on how to rectify this, but it will require me to start over on everything I've done and take a completely different route.

Personally, the instructions posted above will work for a default SU implementation.  Other than that, I think that the calendar in its current state is quite a hassle to implement, and creates a lot of redundant code.  For now, I'm going to cap development of the calendar at its current state and take a completely different approach (which may take a few months to create).
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on November 30, 2007, 09:56:41 am
Thanx for a good answer Mike, I appreciate the effort you have given the phpEventCalendar. I think the Calender have a lot of good potentials as an implementation to sNews because it's so smal. I myself is  looking for a good CV database to implement, and that is not a small job to implement.

I will be happy to help you with the testing of the your work along the way to implement phpEventCalendar to a fully functional part of sNews.

What can I do to help you minimise the time you use?
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on November 30, 2007, 03:29:53 pm
What can I do to help you minimise the time you use?

take my classes/work my jobs?  ;D ;D
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on December 08, 2007, 11:03:38 am
Hi guys.

I manage til fix the screwup with the writing of the calendar when you change det doctype to xhtml. change the default.css to this.

Code: [Select]
/**** color and size of calendar cells.  ****/
.day_cell { background-color:#EDECD8; height:80px; width: 95px; }
.empty_day_cell     { background-color:#EEEEEE; height:80px; width: 95px; }
.today_cell { background-color:#F5F4ED; height:80px; width: 95px; }

Mike: Started working on the rewriting? If so I have an idè for you. How about adding the posibillity to add an event when you writing a article, and relate the article and event in some way..? This meens that when someone is using the calendar, he/she would also get a link to the article in the calender in the bottom of the eventtext, and vice versa for the article. After mine opinion, the searh_function sould have some alt to narrow the search to articles and/or events. I dont know if that is possible.
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on December 20, 2007, 03:49:04 am
Hi guys.

I manage til fix the screwup with the writing of the calendar when you change det doctype to xhtml. change the default.css to this.

Code: [Select]
/**** color and size of calendar cells.  ****/
.day_cell { background-color:#EDECD8; height:80px; width: 95px; }
.empty_day_cell     { background-color:#EEEEEE; height:80px; width: 95px; }
.today_cell { background-color:#F5F4ED; height:80px; width: 95px; }
Just tried this patch... still doesn't allow the use of - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" in either the sNews or calendar index.php files.  ???
Title: Re: [ADDON] phpEventCalendar
Post by: Anders Hansen on December 20, 2007, 04:30:55 am
After feedback from Keyrocks that by using this css file everything works. I relase it for all you who want the styling to match the xhtml doctype.  If you have problems try to look me up. This is the default.css file... placed under css in the phpEventCalendar folder.

Code: [Select]
<STYLE TYPE="text/css">
<!--
/**************************************************************
********* Formatting For Month Table and Text *****************
**************************************************************/

A { font-family:arial, helvetica; color:#00F; text-decoration:underline }
SPAN { font-family:arial, helvetica }
TD      { font-family:arial, helvetica }
BODY { background-color:#FFF }

/**** month and year header at top of calendar ****/
.date_header { font-size:16px; font-family:arial, helvetica; font-weight:bold }

/**** color and size of calendar cells.  ****/
.day_cell { background-color:#444444; height:80px; width: 95px; }
.empty_day_cell { background-color:#555555; height:80px; width: 95px; }
.today_cell { background-color:#777777; height:80px; width: 95px; }

/**** day number in upper left corner of each cell ****/
.day_number { font-size:10px; font-family:verdana, arial, helvetica; color:#eee }

/**** title_txt is the text for each post on main page ****/
.title_txt { font-size:10px; font-family:verdana, arial, helvetica; color:#eee }
.title_txt A:hover { color:#aaaaaa; text-decoration:underline }

/**** time line under title text when event time given ****/
.time_str { font-size:9px; font-family:arial, helvetica }

/**** column headers or days of the week ****/
.column_header { background-color:#111; font-size:12px; font-family:arial, helvetica; color:#FFFFFF; font-weight:bold;}

/**** footprint text ****/
.footprint { font-size:10px; font-family:verdana, arial, helvetica; color:#000; font-weight:bold; }
.footprint A { font-size:10px; font-family:verdana, arial, helvetica; color:#00F; font-weight:bold; }
// end hiding -->
</STYLE>
Title: Re: [ADDON] phpEventCalendar
Post by: Keyrocks on December 20, 2007, 05:09:12 am
Just tried this patch... still doesn't allow the use of - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" in either the sNews or calendar index.php files.  ???
And... my apologies... the patch above did work... once I realized I was applying it to a file that wasn't active. Turns out the issue with the doctype string is a very simple one that I hadn't really notice before... that the height and width of the table cells was defined without the unit. Adding px to the height and width numbers is necessary to work with the strict doctype string.
Title: Re: [ADDON] phpEventCalendar
Post by: mantra on March 13, 2009, 08:28:50 am
Is this add on work .......... in new version of snews ??
Title: Re: [ADDON] phpEventCalendar
Post by: mike1 on March 16, 2009, 04:27:24 am
nope