File Manager

Current Path : /webspace/www.promiel.be/html/modules/CGCalendar/
Upload File :
Current File : //webspace/www.promiel.be/html/modules/CGCalendar/CGCalendar.module.php

<?php  /* -*- Mode: PHP; tab-width: 4; c-basic-offset: 2 -*- */
#BEGIN_LICENSE
#-------------------------------------------------------------------------
# Module: Skeleton (c) 2008
#      by Robert Allen (akrabat) and
#         Robert Campbell (calguy1000@cmsmadesimple.org)
#  An addon module for CMS Made Simple to allow displaying calendars,
#  and management and display of time based events.
#
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2005 by Ted Kulp (wishy@cmsmadesimple.org)
# This projects homepage is: http://www.cmsmadesimple.org
#
#-------------------------------------------------------------------------
#
# 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.
#
# However, as a special exception to the GPL, this software is distributed
# as an addon module to CMS Made Simple.  You may not use this software
# in any Non GPL version of CMS Made simple, or in any version of CMS
# Made simple that does not indicate clearly and obviously in its admin
# section that the site was built with CMS Made simple.
#
# 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
#
#-------------------------------------------------------------------------
#END_LICENSE

$cgextensions = cms_join_path($gCms->config['root_path'],'modules','CGExtensions','CGExtensions.module.php');
if( !is_readable( $cgextensions ) ) {
  echo '<h1><font color="red">ERROR: The CGExtensions module could not be found.</font></h1>';
  return;
}
require_once($cgextensions);

define('CGCALENDAR_PREF_NEWCALENDAR_TEMPLATE','cgcalendar_pref_newcalendar_template');
define('CGCALENDAR_PREF_DFLTCALENDAR_TEMPLATE','cgcalendar_pref_dfltcalendar_template');
define('CGCALENDAR_PREF_NEWLIST_TEMPLATE','cgcalendar_pref_newlist_template');
define('CGCALENDAR_PREF_DFLTLIST_TEMPLATE','cgcalendar_pref_dfltlist_template');
define('CGCALENDAR_PREF_NEWUPCOMINGLIST_TEMPLATE','cgcalendar_pref_newupcominglist_template');
define('CGCALENDAR_PREF_DFLTUPCOMINGLIST_TEMPLATE','cgcalendar_pref_dfltupcominglist_template');
define('CGCALENDAR_PREF_NEWEVENT_TEMPLATE','cgcalendar_pref_newevent_template');
define('CGCALENDAR_PREF_DFLTEVENT_TEMPLATE','cgcalendar_pref_dfltevent_template');
define('CGCALENDAR_PREF_NEWSEARCH_TEMPLATE','cgcalendar_pref_newsearch_template');
define('CGCALENDAR_PREF_DFLTSEARCH_TEMPLATE','cgcalendar_pref_dfltsearch_template');
define('CGCALENDAR_PREF_NEWSEARCHRESULT_TEMPLATE','cgcalendar_pref_newsearchresult_template');
define('CGCALENDAR_PREF_DFLTSEARCHRESULT_TEMPLATE','cgcalendar_pref_dfltsearchresult_template');
define('CGCALENDAR_PREF_NEWMYEVENTS_TEMPLATE','cgcalendar_pref_newmyevents_template');
define('CGCALENDAR_PREF_DFLTMYEVENTS_TEMPLATE','cgcalendar_pref_dfltmyevents_template');
define('CGCALENDAR_PREF_NEWEDITEVENT_TEMPLATE','cgcalendar_pref_neweditevent_template');
define('CGCALENDAR_PREF_DFLTEDITEVENT_TEMPLATE','cgcalendar_pref_dflteditevent_template');

final class CGCalendar extends CGExtensions
{
  var $categories_table_name;
  var $events_to_categories_table_name;
  var $events_table_name;
  var $fields_table_name;
  var $event_field_values_table_name;
  var $admin_tools_loaded;
  static $_cached_fields;

  function __construct()
  {
	parent::__construct();
	$this->AddImageDir('images');

	$this->categories_table_name = cms_db_prefix() . 'module_cgcalendar_categories';
	$this->events_to_categories_table_name = cms_db_prefix().'module_cgcalendar_events_to_categories';
	$this->events_table_name = cms_db_prefix().'module_cgcalendar_events';
	$this->event_field_values_table_name = cms_db_prefix() . 'module_cgcalendar_event_field_values';
	$this->fields_table_name = cms_db_prefix() . 'module_cgcalendar_fields';
	$this->admin_tools_loaded = false;
  }

  function SetParameters()
  {
	$this->RegisterModulePlugin();
	$this->RestrictUnknownParams();

	$this->SetParameterType('day',CLEAN_INT);

	$this->SetParameterType('display',CLEAN_STRING);
	$this->SetParameterType('category',CLEAN_STRING);
	$this->SetParameterType('week',CLEAN_INT);
	$this->SetParameterType('month',CLEAN_INT);
	$this->SetParameterType('year',CLEAN_INT);
	$this->SetParameterType('date',CLEAN_STRING);
	$this->SetParameterType('use_session',CLEAN_STRING);
	$this->SetParameterType('inline',CLEAN_INT);
	$this->SetParameterType('reverse',CLEAN_STRING);
	$this->SetParameterType('pastitems',CLEAN_INT);
	$this->SetParameterType('detailpage',CLEAN_STRING);

	$this->SetParameterType('page',CLEAN_INT);
	$this->SetParameterType('event_id',CLEAN_INT);
	$this->SetParameterType('limit',CLEAN_INT);
	$this->SetParameterType('calendartemplate',CLEAN_STRING);
	$this->SetParameterType('eventtemplate',CLEAN_STRING);
	$this->SetParameterType('listtemplate',CLEAN_STRING);
	$this->SetParameterType('upcominglisttemplate',CLEAN_STRING);
	$this->SetParameterType('searchtemplate',CLEAN_STRING); // todo, doc this.
	$this->SetParameterType('searchresulttemplate',CLEAN_STRING); // todo, doc this.
	$this->SetParameterType('searchresultpage',CLEAN_STRING); // todo, doc this
	$this->SetParameterType('displayforday',CLEAN_INT);

	$this->SetParameterType('myeventstemplate',CLEAN_STRING);
	$this->SetParameterType('editeventtemplate',CLEAN_STRING);
	$this->SetParameterType('editpage',CLEAN_INT);

	$this->SetParameterType('unique_only',CLEAN_INT);
	$this->SetParameterType('return_id',CLEAN_INT);
	$this->SetParameterType('show_ical',CLEAN_STRING);

	$this->SetParameterType(CLEAN_REGEXP.'/cal_.*/',CLEAN_STRING);

	$prefix = $this->GetPreference('url_prefix');
	if( !$prefix ) $prefix = 'calendar';
	$this->RegisterRoute('/'.$prefix.'\/(?P<returnid>[0-9]+)\/(?P<event_id>[0-9]+)-.*$/',
						 array('action'=>'default','display'=>'event'));
  }

  function InitializeAdmin()
  {
	$this->CreateParameter('myeventstemplate','',$this->Lang('help_param_myeventstemplate'));
	$this->CreateParameter('editeventtemplate','',$this->Lang('help_param_editeventtemplate'));
	$this->CreateParameter('editpage','',$this->Lang('help_param_editpage'));
  }

  function InitializeFrontend() { $this->SetParameters(); }
  function GetName() { return 'CGCalendar'; }
  function GetAuthor() { return 'Robert Campbell'; }
  function GetAuthorEmail() { return 'calguy1000@gmail.com'; }
  function IsPluginModule() { return true; }
  function HasAdmin() { return true; }
  function GetEventDescription( $eventname ) { return $this->lang('eventdesc-' . $eventname); }
  function GetEventHelp( $eventname ) {	return $this->lang('eventhelp-' . $eventname); }
  function GetVersion() { return '1.14.3'; }
  function GetDependencies() { return array('CGExtensions'=>'1.38.10','CGSimpleSmarty'=>'1.7.3'); }
  function GetDescription($lang = 'en_US') { return $this->Lang("description"); }
  function GetAdminDescription() { return $this->Lang('cal_description'); }
  function GetAdminSection() { return 'content'; }
  function GetHelp () { return file_get_contents(__DIR__.'/help.inc'); }
  function MinimumCMSVersion() { return '1.11.9'; }
  function GetChangeLog() { return file_get_contents(__DIR__.'/changelog.inc'); }
  function InstallPostMessage() { return $this->Lang('install_postmessage'); }
  function UninstallPreMessage() { return $this->Lang('areyousure_uninstall'); }
  function AllowAutoInstall() { return FALSE; }
  function AllowAutoUpgrade() { return FALSE; }
  function UninstallPostMessage() {	return $this->Lang('post_uninstall'); }
  public function LazyLoadFrontend() { return FALSE; }
  public function LazyLoadAdmin() { return TRUE; }

  function GetFriendlyName()
  {
	$tmp = $this->GetPreference('friendlyname');
	if( !$tmp ) $tmp = $this->Lang('cal_calendar');
	return $tmp;
  }

  function VisibleToAdminUser()
  {
	return $this->CheckPermission('Modify Calendar') ||
	  $this->CheckPermission('Add Calendar Events') ||
	  $this->CheckPermission('Edit My Calendar Events') ||
	  $this->CheckPermission('Manage Calendar Attributes') ||
	  $this->CheckPermission('Modify Site Preferences') ||
	  $this->CheckPermission('Modify Templates');
  }

  public function GetHeaderHTML()
  {
    // would be nice to put stuff in here per action.
    $urlbase = $this->GetModuleURLPath();
    $jsfmt = '<script type="text/javascript" src="%s"></script>'."\n";
    $cssfmt = '<link rel="stylesheet" href="%s"/>'."\n";
    $out = null;
    $out .= sprintf($cssfmt,$urlbase."/lib/fullcalendar/fullcalendar.css");
    $out .= sprintf($cssfmt,$urlbase."/lib/colorPicker/colorPicker.css");
    $out .= sprintf($jsfmt,$urlbase."/lib/fullcalendar/fullcalendar.min.js");
    $out .= sprintf($jsfmt,$urlbase."/lib/colorPicker/jquery.colorPicker.min.js");
    return $out;
  }

  protected function GetEvent($event_id,$uid = -1)
  {
	$rs = null;

	if( $event_id > 0 ) {
	  $db = $this->GetDb(); /* @var $db ADOConnection */
	  $sql = 'SELECT * FROM ' . $this->events_table_name .' WHERE event_id = ?';
	  $parms = array($event_id);
	  if( $uid != -1 && $uid != 0 ) {
		$sql .= ' AND event_created_by = ?';
		$parms[] = $uid;
	  }
	  $rs = $db->Execute($sql,$parms);
	}

	if($rs && $rs->RecordCount() > 0) {
	  $result = $rs->FetchRow();
	  $result['event_date_start_ut'] = $db->UnixTimeStamp($result['event_date_start']);
	  if( is_null($result['event_date_end']) || $result['event_date_end'] == '0000-00-00 00:00:00') $result['event_date_end'] = NULL;
	  $result['event_date_end_ut'] = $db->UnixTimeStamp($result['event_date_end']);
	  if( is_null($result['event_date_recur_end']) || $result['event_date_recur_end'] == '0000-00-00 00:00:00' ) {
		$result['event_date_recur_end'] = NULL;
	  }
	  $result['event_date_recur_end_ut'] = $db->UnixTimeStamp($result['event_date_recur_end']);
	  $result['event_recur_count'] = $result['event_recur_nevents'];
	  $result['event_recur_weekdays'] = explode(',',$result['event_recur_weekdays']);
	  $result['event_recur_monthdays'] = explode(',',$result['event_recur_monthdays']);
	  $result['categories'] = array();

	  // now pick up categories
	  $sql = 'SELECT category_id FROM ' . $this->events_to_categories_table_name . ' WHERE event_id = ?';
	  $rs = $db->Execute($sql,array($event_id));
	  if($rs) {
		while($row = $rs->FetchRow()) {
		  $result['categories'][] = $row['category_id'];
		}
	  }

	  // now pick up the custom fields
	  $result['fields'] = array();
	  $sql = 'SELECT field_name, field_value FROM ' . $this->event_field_values_table_name . ' WHERE event_id = ?';
	  $rs = $db->Execute($sql,array($event_id));
	  if($rs) {
		while($row = $rs->FetchRow()) {
		  $result['fields'][$row['field_name']] = $row['field_value'];
		}
	  }

	  // test if this is an all day event.
	  // cuz we don't store that info in the database.
	  $sd = date('z',$result['event_date_start_ut']);
	  $sh = date('G',$result['event_date_start_ut']);
	  $sm = date('i',$result['event_date_start_ut']);
	  $ed = date('z',$result['event_date_end_ut']);
	  $eh = date('G',$result['event_date_end_ut']);
	  $em = date('i',$result['event_date_end_ut']);
	  $result['all_day_event'] = $result['event_all_day'];
	  $result['alt_end_date'] = 0;
	  if( $sd != $ed ) $result['alt_end_date'] = 1;
	}
	else {
	  // create an empty record
	  $result = array();
	  $result['event_id'] = -1;
	  $result['event_title'] = '';
	  $result['event_summary'] = '';
	  $result['event_details'] = '';
	  $result['event_date_start'] = NULL;
	  $result['event_date_end'] = NULL;
	  $result['event_date_start_ut'] = strtotime($this->GetPreference('dflt_starttime'));
	  $result['event_date_end_ut'] = NULL;
	  $result['event_created_by'] = -1;
	  $result['event_create_date'] = NULL;
	  $result['event_modified_date'] = NULL;
	  $result['event_recur_period'] = 'none';
	  $result['event_date_recur_end_ut'] = NULL;
	  $result['event_date_recur_end'] = NULL;
	  $result['event_recur_interval'] = -1;
	  $result['event_parent_id'] = -1;
	  $result['event_recur_count'] = -1;
	  $result['event_recur_weekdays'] = array();
	  $result['event_recur_monthdays'] = array();
	  $result['event_allows_overlap'] = 1; // default to yes.
	  $result['categories'] = array();
	  $result['fields'] = array();
	  $result['all_day_event'] = $this->GetPreference('dflt_alldayevent');
	  $result['alt_end_date'] = 0;
	}

	return $result;
  }

  protected function GetEventFromParams(&$event,$params,$is_edit = false)
  {
	  $db = $this->GetDb();
	  if( isset($params['event_id']) )  $event['event_id'] =  (int)$params['event_id'];
	  if( isset($params['event_parent_id']) )  $event['event_parent_id'] = (int)$params['event_parent_id'];
      if( isset($params['removefromparent']) && $params['removefromparent'] ) $event['event_parent_id'] = -1;
	  if( isset($params['event_title']) )  $event['event_title'] = trim($params['event_title']);
	  if( isset($params['event_summary']) )  $event['event_summary'] = trim($params['event_summary']);
	  if( isset($params['event_details']) )  $event['event_details'] = trim($params['event_details']);
	  if( isset($params['event_allows_overlap']) ) {
		$event['event_allows_overlap'] = (int)$params['event_allows_overlap'];
	  }
	  else {
		$tmp = $this->GetPreference('overlap_policy','all');
		$event['event_allows_overlap'] = ($tmp == 'all')?1:0;
	  }

	  $all_day_event = 0;
	  if( isset($params['all_day_event']) )  $all_day_event = (int)$params['all_day_event'];
	  $event['event_all_day'] = $all_day_event;

	  $start_hour = 0;
	  $start_minute = 0;
	  if( isset($params['startdate_Month']) ) {
        $start_hour = $params['startdate_Hour'];
	    $start_minute = $params['startdate_Minute'];
	    if( isset($params['startdate_Meridian']) ) {
	   	  if( $params['startdate_Meridian'] == 'am' && $start_hour >= 12 ) {
		    $start_hour -= 12;
          }
		  else if( $params['startdate_Meridian'] == 'pm' && $start_hour < 12 ) {
		    $start_hour += 12;
		  }
		}
		$event['event_date_start_ut'] = mktime($start_hour,$start_minute,0,$params['startdate_Month'],$params['startdate_Day'],
											   $params['startdate_Year']);
		$event['event_date_start'] = $db->DbTimeStamp($event['event_date_start_ut']);
	  }

	  $event['event_date_end'] = NULL;
	  $event['event_date_end_ut'] = NULL;
	  if( isset($params['enddate_valid']) && $params['enddate_valid'] && isset($params['enddate_Day']) ) {
		$end_month = $params['enddate_Month'];
		$end_day = $params['enddate_Day'];
		$end_year = $params['enddate_Year'];
  	    $end_hour = $params['enddate_Hour'];
		$end_minute = $params['enddate_Minute'];
	    if( isset($params['enddate_Meridian']) && $params['enddate_Meridian'] == 'am' && $end_hour >= 12 ) {
		  $end_hour -= 12;
		}
		else if( isset($params['enddate_Meridian']) && $params['enddate_Meridian'] == 'pm' && $end_hour < 12 ) {
		  $end_hour += 12;
		}
		$event['event_date_end_ut'] = mktime($end_hour,$end_minute,0,$end_month,$end_day,$end_year);
		$event['event_date_end'] = $db->DbTimeStamp($event['event_date_end_ut']);
	  }

	  if( isset($params['event_recur_period']) ) $event['event_recur_period'] = trim($params['event_recur_period']);
	  if( isset($params['event_recur_interval']) ) $event['event_recur_interval'] = (int)$params['event_recur_interval'];
	  if( isset($params['event_recur_weekdays']) ) {
		if( is_array($params['event_recur_weekdays']) ) {
		  $event['event_recur_weekdays'] = $params['event_recur_weekdays'];
		}
		else {
		  $event['event_recur_weekdays'] = explode(',',$params['event_recur_weekdays']);
		}
	  }
	  if( isset($params['event_recur_monthdays']) ) {
		if( is_array($params['event_recur_monthdays']) ) {
		  $event['event_recur_monthdays'] = $params['event_recur_monthdays'];
		}
		else {
		  $event['event_recur_monthdays'] = explode(',',$params['event_recur_monthdays']);
		}
	  }
	  if( isset($params['event_recur_count']) )  $event['event_recur_count'] = (int)$params['event_recur_count'];
	  if( isset($params['event_recur_date_Month']) && $params['event_recur_period'] != 'none' ) {
		$event['event_date_recur_end_ut'] = mktime(0,0,0,
												   $params['event_recur_date_Month'],$params['event_recur_date_Day'],
												   $params['event_recur_date_Year']);
		$event['event_date_recur_end'] = $db->DbTimeStamp($event['event_date_recur_end_ut']);
	  }
	  else {
		$event['event_date_recur_end'] = NULL;
		$event['event_date_recur_end_ut'] = NULL;
	  }

      if( isset($params['event_categories']) ) {
        if( is_string($params['event_categories']) ) $params['event_categories'] = unserialize($params['event_categories']);
      }
  }

  // deprecated
  function GetCategories()
  {
    return \CGCalendar\category::get_categories();
  }

  private function _LoadAdmin()
  {
	if( $this->admin_tools_loaded === false ) require_once('functions.admin_tools.php');
  }

  function GetFields()
  {
	if( !is_array(self::$_cached_fields) ) {
	  self::$_cached_fields = array();

	  $db = $this->GetDb(); /* @var $db ADOConnection */
	  $fields_table_name = $this->fields_table_name;
	  $sql = "SELECT * FROM $fields_table_name ORDER BY field_order,field_name";

	  $result = array();
	  $rs = $db->Execute($sql);
	  if($rs && $rs->RecordCount() > 0) {
		$result = $rs->GetArray();
		if( is_array($result) && count($result) ) {
		  foreach( $result as &$one ) {
			if( $one['field_extra'] != '' ) $one['field_extra'] = unserialize($one['field_extra']);
		  }
		}
		self::$_cached_fields = $result;
	  }
	}
	return self::$_cached_fields;
  }

  function GetDayNames()
  {
    $tmp = cgcalendar_utils::get_locale_dates();
    $day_names = $tmp['dayNames'];

	if($this->GetPreference('firstdayofweek',1)) {
	  $first = array_shift($day_names);
	  $day_names[] = $first;
	}
	return $day_names;
  }

  function GetDayShortNames()
  {
    $tmp = cgcalendar_utils::get_locale_dates();
    $day_short_names = $tmp['dayNamesShort'];

    if($this->GetPreference('firstdayofweek',1)) {
      $first = array_shift($day_short_names);
      $day_short_names[] = $first;
    }
    return $day_short_names;
  }

  function GetMonthNames()
  {
    $tmp = cgcalendar_utils::get_locale_dates();
    $month_names = $tmp['monthNames'];
    return $month_names;
  }

  function GetLabels()
  {
      $lang['date'] = $this->Lang('cal_date');
      $lang['summary'] = $this->Lang('cal_summary');

      $lang['details'] = $this->Lang('cal_details');
      $lang['return'] = $this->Lang('cal_return');
	  $lang['current'] = $this->Lang('cal_current');
	  $lang['from'] = $this->Lang('cal_from');
      $lang['to'] = $this->Lang('cal_to');
      $lang['next'] = $this->Lang('cal_next');
      $lang['prev'] = $this->Lang('cal_prev');
      $lang['past_events'] = $this->Lang('cal_past_events');
      $lang['upcoming_events'] = $this->Lang('cal_upcoming_events');
      return $lang;
  }


  function isValidFilename($filename)
  {
      $this->_LoadAdmin();
      return calendar_isValidFilename($this,$filename);
  }


  function HandleUpload($fldname,&$error)
  {
      $this->_LoadAdmin();
      return calendar_HandleUpload($this,$fldname,$error);
  }

  function GetDefaultTemplate($template)
  {
      $fn = sprintf('orig_%s_template.tpl',$template);
      $fn = cms_join_path(__DIR__,'templates',$fn);
      $data = @file_get_contents($fn);
      return $data;
  }

  function NoBreak($string) {
    return str_replace(" ","&nbsp;",$string);
  }

  function SearchResult($returnid, $event_id, $attr = '')
  {
      $result = array();
      if( $attr != 'event') return $result;

      $db = $this->GetDb();
      $query = 'SELECT event_title FROM '.$this->events_table_name.' WHERE event_id = ?';
      $title = $db->GetOne( $query, array($event_id) );

      $result[0] = $this->GetFriendlyName();
      $result[1] = $title;

      $titleSEO = munge_string_to_url($title);
      $destpage = $this->GetPreference('defaultcalendarpage',-1);
      $destpage=$destpage!=-1?$destpage:$returnid;
      $destpage=$detailpage!=''?$detailpage:$destpage;
	  $prefix = $this->GetPreference('url_prefix');
	  if( !$prefix ) $prefix = 'calendar';
      $prettyurl = sprintf($prefix."/%d/%d-%s", $destpage,$event_id,$titleSEO);
      $result[2] = $this->CreateLink($id,'default',$destpage,'',
									 array('event_id'=>$event_id,'display'=>'event','detailpage'=>$destpage,'return_id'=>$returnid),
									 '', true, '', '', $prettyurl);
      return $result;
  }

  function SearchReindex(&$module)
  {
      $db = $this->GetDb();

      $query = 'SELECT * FROM '.$this->events_table_name.' ORDER BY event_date_start';
      $dbr = $db->Execute($query);

	  $fquery = 'SELECT fv.field_value FROM '.$this->fields_table_name.' fd
                   LEFT JOIN '.$this->event_field_values_table_name.' fv
                     ON fd.field_name = fv.field_name AND fd.field_searchable = 1
                  WHERE fv.event_id = ?';

      while ($dbr && !$dbr->EOF) {
		$text = $dbr->fields['event_title'].' '.$dbr->fields['event_summary'].' '.$dbr->fields['event_details'];

		$morewords = $db->GetCol($fquery,array($dbr->fields['event_id']));
		if( $morewords ) $text .= ' '.implode(' ',$morewords);
		$module->AddWords($this->GetName(), $dbr->fields['event_id'], 'event', $text, NULL);
		$dbr->MoveNext();
	  }
  }

  function ToAbbreviatedWeekdays($data)
  {
	if( !is_array($data) ) $data = explode(',',$data);

	$weekdays = array(0=>'sunday',
					  1=>'monday',
					  2=>'tuesday',
					  3=>'wednesday',
					  4=>'thursday',
					  5=>'friday',
					  6=>'saturday');
	$result = array();
	foreach( $data as $one ) {
	  $result[] = $this->Lang('abbr_'.$weekdays[$one]);
	}
    if( !count($result) ) return '';
	$tmp = implode(',',$result);
	return $tmp;
  }

  // timestamp is a Unix timestamp (seconds since epoch)
  // tzone is an time-zone offset from GMT
  function UnixTimestampToiCal($timestamp, $tzone = 0)
  {
	$zulu = $timestamp + ($tzone * 3600);
	$iCal  = date("Ymd\THis\Z", $zulu);
	return $iCal;
  }

  function GetCategoryNames($category_ids)
  {
	if( !is_array($category_ids) && (int)$category_ids > 0 ) {
	  $category_ids = array($catetegory_ids);
	}

	$allcats = $this->GetCategories();
	if( !is_array($allcats) || count($allcats) == 0 ) return;

	$tmp = array();
	foreach( $category_ids as $one ) {
	  for( $i = 0; $i < count($allcats); $i++ ) {
		if( $one == $allcats[$i]['category_id'] ) {
		  $tmp[] = $allcats[$i]['category_name'];
		  break;
		}
	  }
	}
	if( count($tmp) > 0 ) return implode(', ',$tmp);
  }

  function ConvertCategoriesToString($categories)
  {
	$ary = array();
	foreach ($categories as $one) {
	  $ary[] = $one['category_name'];
	}
	return implode(',', $ary);
  }

}; // class
?>

File Manager Version 1.0, Coded By Lucas
Email: hehe@yahoo.com