Made some quick changes to the FeuCalendar module to make it work with Calendar-0.8.2 and add file inputs for any custom upload fields. See also attached module XML file (extension changed to .txt)
Code: Select all
<?php
#-------------------------------------------------------------------------
# FeuCalendar - Front End Users to Calendar bridge
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org)
# This project's homepage is: http://www.cmsmadesimple.org
# The module's homepage is: http://dev.cmsmadesimple.org/projects/feucalendar/
#-------------------------------------------------------------------------
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
#-------------------------------------------------------------------------
class FeuCalendar extends CMSModule
{
function GetName()
{
return get_class($this);
}
function GetFriendlyName()
{
return $this->Lang('friendlyname');
}
function GetVersion()
{
return '0.1';
}
function GetHelp()
{
return $this->Lang('help');
}
function GetAuthor()
{
return 'tamlyn';
}
function GetAuthorEmail()
{
return 'tam@zenology.co.uk';
}
function GetChangeLog()
{
return $this->Lang('changelog');
}
function IsPluginModule()
{
return true;
}
function HasAdmin()
{
return true;
}
function GetAdminSection()
{
return 'extensions';
}
function GetAdminDescription()
{
return $this->Lang('moddescription');
}
function VisibleToAdminUser()
{
return $this->CheckPermission('Modify Calendar');
}
function GetDependencies()
{
return array('FrontEndUsers' => '1.1.1', 'Calendar' => '0.7.3');
}
function MinimumCMSVersion()
{
return "1.0";
}
function InstallPostMessage()
{
return $this->Lang('postinstall');
}
function UninstallPostMessage()
{
return $this->Lang('postuninstall');
}
function UninstallPreMessage()
{
return false;//$this->Lang('really_uninstall');
}
function DoAction($action, $id, $params, $returnid=-1)
{
switch ($action)
{
case 'default' :
case 'showform' :
//show the form for adding new events
if($this->CheckUser())
$this->AddEventForm($id, $params, $returnid);
else
$this->DisplayMessage($id, $params, $returnid, $this->Lang('denied_title'), $this->Lang('denied_message'));
break;
case 'add_event' :
//add the event submitted from the event form
if($this->CheckUser())
$this->AddEvent($id, $params, $returnid);
else
$this->DisplayMessage($id, $params, $returnid, $this->Lang('access_denied'));
break;
case 'defaultadmin' :
case 'admin_prefs' :
// only let people access module preferences if they have permission
if ($this->CheckPermission('Modify Calendar'))
$this->DisplayAdminPrefs($id, $params, $returnid);
else
$this->DisplayErrorPage($id, $params, $returnid,
$this->Lang('accessdenied'));
break;
case 'save_admin_prefs':
// only let people save module preferences if they have permission
if ($this->CheckPermission('Modify Calendar'))
$this->SaveAdminPrefs($id, $params, $returnid);
break;
}
}
function AddEventForm($id, $params, $returnid)
{
$calendar = $this->GetModuleInstance('Calendar');
$event_id = -1;
$this->smarty->assign('form_start', $this->CreateFormStart($id, 'add_event', $returnid, $method='post', $enctype='multipart/form-data',false,"",array()) . $this->CreateInputHidden($id, 'event_id', $event_id));
$this->smarty->assign('form_end', $this->CreateFormEnd());
$this->smarty->assign('form_submit', $this->CreateInputSubmit($id, '', $calendar->Lang('cal_add_event')));
$this->smarty->assign('form_cancel', '<input type="button" value="'.$this->Lang('form_cancel').'" onclick="javascript:window.history.go(-1)" />');
$this->smarty->assign('start_label', $calendar->Lang('cal_fromdate'));
$this->smarty->assign('end_label', $calendar->Lang('cal_todate'));
$this->smarty->assign('title_label', $calendar->Lang('cal_title'));
$this->smarty->assign('summary_label', $calendar->Lang('cal_summary'));
$this->smarty->assign('details_label', $calendar->Lang('cal_details'));
$this->smarty->assign('categories_label', $calendar->Lang('cal_categories'));
$current_year = date('Y');
$start = $current_year - 2;
$end = $current_year + 10;
$year_array = array();
for($i = $start; $i < $end; $i++) {
$year_array[$i] = $i;
}
$month_array = array();
for($i = 0; $i < 12; $i++) {
$month_name = strftime('%b', mktime(12,0,0,$i+1,1));
$month_number = sprintf('%02d', $i+1);
$month_array[$month_name] = $month_number;
}
$day_array = array();
for($i=1; $i < 32; $i++) {
$day = sprintf('%02d', $i);
$day_array[$i] = $day;
}
$hour_array = array();
for($i=0; $i < 24; $i++) {
$hour = sprintf('%02d', $i);
if (1 == $calendar->GetPreference('use_twelve_hour_clock')) {
if ($i >= 12) {
if ($i == 12) {
$hour_array[$i.' noon'] = $hour;
} else {
$pm_hour = $i - 12;
$hour_array[$pm_hour.' p.m.'] = $hour;
}
} else {
if ($i == 0)
$hour_array['12 midnight'] = $hour;
else
$hour_array[$i.' a.m.'] = $hour;
}
} else {
$hour_array[$hour] = $hour;
}
}
$minute_array = array();
for($i=0; $i < 60; $i++) {
$minute = sprintf('%02d', $i);
$minute_array[$minute] = $minute;
}
/*if(isset($event['event_date_start'])) {
$event_date_start_time = strtotime($event['event_date_start']);
$event_date_start_minute = date('i', $event_date_start_time);
$event_date_start_hour = date('H', $event_date_start_time);
$event_date_start_day = date('d', $event_date_start_time);
$event_date_start_month = date('m', $event_date_start_time);
$event_date_start_year = date('Y', $event_date_start_time);
} else {
*/
$event_date_start_minute = 0; //date('i');
$event_date_start_hour = 0; //date('H');
$event_date_start_day = date('d');
$event_date_start_month = date('n');
$event_date_start_year = $current_year;
//}
$this->smarty->assign('start_input',
$this->CreateInputDropdown($id, 'event_date_start_day', $day_array, -1, $event_date_start_day) .
$this->CreateInputDropdown($id, 'event_date_start_month', $month_array, -1, $event_date_start_month) .
$this->CreateInputDropdown($id, 'event_date_start_year', $year_array, -1, $event_date_start_year) .
$this->Lang('date_time_separator') .
$this->CreateInputDropdown($id, 'event_date_start_hour', $hour_array, -1, $event_date_start_hour) .
$this->Lang('hour_minute_separator') .
$this->CreateInputDropdown($id, 'event_date_start_minute', $minute_array, -1, $event_date_start_minute)
);
/*if(isset($event['event_date_end'])) {
$event_date_end_time = strtotime($event['event_date_end']);
$event_date_end_minute = date('i', $event_date_end_time);
$event_date_end_hour = date('H', $event_date_end_time);
$event_date_end_day = date('d', $event_date_end_time);
$event_date_end_month = date('m', $event_date_end_time);
$event_date_end_year = date('Y', $event_date_end_time);
} else {
*/
$event_date_end_minute = 0;
$event_date_end_hour = 0;
$event_date_end_day = 0;
$event_date_end_month = 0;
$event_date_end_year = 0;
//}
$day_array[''] = 0;
$month_array[''] = 0;
$year_array[''] = 0;
asort($day_array);
asort($month_array);
asort($year_array);
$this->smarty->assign('end_input',
$this->CreateInputDropdown($id, 'event_date_end_day', $day_array, -1, $event_date_end_day) .
$this->CreateInputDropdown($id, 'event_date_end_month', $month_array, -1, $event_date_end_month) .
$this->CreateInputDropdown($id, 'event_date_end_year', $year_array, -1, $event_date_end_year) .
$this->Lang('date_time_separator') .
$this->CreateInputDropdown($id, 'event_date_end_hour', $hour_array, -1, $event_date_end_hour) .
$this->Lang('hour_minute_separator') .
$this->CreateInputDropdown($id, 'event_date_end_minute', $minute_array, -1, $event_date_end_minute)
);
$custom_field_inputs = array();
foreach($calendar->GetFields() as $field) {
switch ($field['field_type'])
{
case '0': // text field
break;
case '1': // file upload field
$safefieldname = str_replace (" ", "_", $field['field_name']);
$custom_field_inputs[]['label'] = $this->CreateLabelForInput($id, 'field_' . $safefieldname, $field['field_name']);
$custom_field_inputs[]['input'] = $this->CreateFileUploadInput($id, 'field_' . $safefieldname)
. $this->CreateInputHidden($id, 'upload_field_' . $safefieldname, $field['field_name']);
break;
}
}
$this->smarty->assign('custom_field_inputs', $custom_field_inputs);
$this->smarty->assign('title_input', $this->CreateInputText($id, 'event_title', $event['event_title'], 50, 50));
$this->smarty->assign('summary_input', $this->CreateInputText($id, 'event_summary', $event['event_summary'], 50, 100));
$this->smarty->assign('details_input', $this->CreateTextArea(true, $id, $event['event_details'], 'event_details', 'content', $id, '', '', 40, 10));
$categories = $calendar->GetCategories();
$num_cats = count($categories);
$num_cols = 2;
$rows_per_col = intval($num_cats / $num_cols);
$count = 0;
$cat_code = "";
for($i = 0; $i < $num_cats; $i++,$count ++) {
if($count >= $rows_per_col && $rows_per_col != 0) {
$count = 0;
$cat_code .= "</td><td valign='top' style='padding-left: 40px;' >\n";
$padding = 0;
}
if($i < $num_cats) {
$category = $categories[$i];
$cat_id = $category['category_id'];
$cat_name = $category['category_name'];
$checked = '';
//if(in_array($cat_id, $event['categories']))
// $checked = $cat_id;
$cat_code .= "<div><label>";
$cat_code .= $this->CreateInputCheckbox($id, 'event_categories[]', $cat_id, $checked);
$cat_code .= $cat_name;
$cat_code .= "</label></div>\n";
}
}
$this->smarty->assign('categories_input', $cat_code);
echo $this->ProcessTemplate("add_event.tpl");
}
function CreateTextArea($enablewysiwyg, $id, $text, $name, $classname='', $htmlid='', $encoding='', $stylesheet='', $width='80', $cols='15',$forcewysiwyg="")
{
return create_textarea($enablewysiwyg, $text, $id.$name, $classname, $htmlid, $encoding, $stylesheet, $width, $cols,$forcewysiwyg);
}
/**
* Save the submitted event info by passing it to the calendar module
*/
function AddEvent($id, &$params, $returnid)
{
$calendar = $this->GetModuleInstance('Calendar');
//set user_id to 0 since not an admin user
$tmp = $this->cms->variables['user_id'];
$this->cms->variables['user_id'] = 0;
//add the event through the calendar module
$calendar->DoAction('admin_event_update', $id, $params, $returnid);
//set user_id back to whatever it was
$this->cms->variables['user_id'] = $tmp;
$this->DisplayMessage($id, $params, $returnid, $this->Lang('success_title'), $this->Lang('success_message'));
}
function DisplayAdminPrefs($id, &$params, $returnid, $message='')
{
$this->smarty->assign('mod_prefs_title', $this->Lang('mod_prefs_title'));
$this->smarty->assign('form_start', $this->CreateFormStart($id, 'save_admin_prefs', $returnid, $method='post', $enctype='multipart/form-data'));
$this->smarty->assign('form_end', $this->CreateFormEnd());
$this->smarty->assign('form_submit', $this->CreateInputSubmit($id, 'form_submit', $this->Lang('form_submit')));
// you'll often want to do things like this to provide feedback:
$this->smarty->assign('message', (isset($params['message'])?$params['message']:''));
//$wysiwygs = $this->GetWYSIWYGs();
$feu = $this->GetModuleInstance('FrontEndUsers');
$groups = $feu->GetGroupList();
$this->smarty->assign('allow_guest_label', $this->Lang('allow_guest_label'));
$this->smarty->assign('allow_guest_input', $this->CreateInputCheckbox($id, 'allow_guest', 1, $this->GetPreference('allow_guest', '0')));
$this->smarty->assign('group_label', $this->Lang('group_label'));
$this->smarty->assign('group_input', $this->CreateInputDropdown($id, 'group', $groups, -1, $this->GetPreference('group', '')));
$this->smarty->assign('wysiwyg_label', $this->Lang('wysiwyg_label'));
$this->smarty->assign('wysiwyg_input', 'None');//$this->CreateInputDropdown($id, 'wysiwyg_input', $day_array, -1, $event_date_end_day));
echo $this->ProcessTemplate('admin.tpl');
}
/**
* Get an array of all active wysiwyg modules
*/
function GetWYSIWYGArray()
{
global $gCms;
$module_list = array();
foreach($gCms->modules as $key => $module)
if($module['installed'] && $module['active'] && $module['object']->IsWYSIWYG())
$module_list[] =& $gCms->modules[$key]['object']; //set reference to module object
return $module_list;
}
function SaveAdminPrefs($id, &$params, $returnid)
{
$this->SetPreference('group', $params['group']);
//$this->SetPreference('wysiwyg', $params['wysiwyg']);
$this->SetPreference('allow_guest', isset($params['allow_guest'])?$params['allow_guest']:'0');
// to call another method of the module, you have to be careful now that
// methods can be split into other files. Here's the prefered approach:
$params['message'] = $this->Lang('prefsupdated');
$this->Redirect($id, 'defaultadmin', $returnid);
}
/**
* Display a simple message
*/
function DisplayMessage($id, &$params, $returnid, $title, $message)
{
$this->smarty->assign('title', $title);
$this->smarty->assign('message', $message);
echo $this->ProcessTemplate('message.tpl');
}
/**
* Check if current user is allowed to post
*/
function CheckUser()
{
$feu =& $this->GetModuleInstance('FrontEndUsers');
if( $this->GetPreference('allow_guest') ||
$feu->LoggedIn() &&
$feu->MemberOfGroup($feu->LoggedInId(), $this->GetPreference('group')))
return true;
else {
return false;
}
}
}
?>
The Calendar module redirects to the admin after event update, so the last line of Calendar/action.admin_event_update.php has to be changed from