4 * Event Calendar for Elxis CMS 2008.x and 2009.x
6 * Backend Event Handler
9 * @package eventCalendar
10 * @author Apostolos Koutsoulelos <akoutsoulelos@yahoo.gr>
11 * @copyright Copyright (C) 2009-2010 Apostolos Koutsoulelos. All rights reserved.
12 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
16 // Prevent direct inclusion of this file
17 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
19 // Check if the user is allowed to access this component. If not then re-direct him to the administration's front-page.
20 if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype
, 'components', 'all' )
21 |
$acl->acl_check( 'administration', 'edit', 'users', $my->usertype
, 'components', 'com_eventcalendar' ))) {
22 mosRedirect( 'index2.php', $adminLanguage->A_NOT_AUTH
);
26 require_once($mainframe->getCfg('absolute_path' ).'/components/com_eventcalendar/eventcalendar.class.php'); // Component's general classes
27 require_once($mainframe->getCfg('absolute_path' ).'/administrator/components/com_eventcalendar/admin.eventcalendar.html.php'); // Component's html file for the administration area
28 require_once($mainframe->getCfg('absolute_path' ).'/administrator/includes/pageNavigation.php'); // Elxis core pageNavigation component
30 /*************************************************************************/
31 /* THE CLASS THAT WILL CONTAIN THE COMPONENT'S BACK-END FUNCTIONALITY */
32 /*************************************************************************/
33 class clsEventCalendarAdmin
{
35 // Initialize variables
36 public $task = ''; // component's current task
37 public $apath = ''; // component's back-end absolute path
38 public $hpath = ''; // component's front-end absolute path
39 public $live_apath = ''; // component's back-end absolute path
40 public $live_hpath = ''; // component's front-end absolute path
41 public $lng = null; // component's language
42 public $event_id = '';
48 /****************************/
49 /* The class' constructor */
50 /****************************/
51 public function __construct() {
52 global $alang, $mainframe; $mosConfig_live_site; // Pass global variables or objects
55 $this->task
= htmlspecialchars(mosGetParam($_REQUEST, 'task', 'events'));
56 $this->apath
= $mainframe->getCfg('absolute_path').'/administrator/components/com_eventcalendar';
57 $this->hpath
= $mainframe->getCfg('absolute_path').'/components/com_eventcalendar';
58 $this->live_apath
= $mainframe->getCfg('live_site').'/administrator/components/com_eventcalendar';
59 $this->live_hpath
= $mainframe->getCfg('live_site').'/components/com_eventcalendar';
60 $this->event_id
= mosGetParam( $_REQUEST, 'cid', array(0) );
61 $this->cat_id
= mosGetParam( $_REQUEST, 'catid', '0' );
62 $this->cid
= $event_id;
63 $this->field
= mosGetParam($_REQUEST, 'field', false);
64 $this->order
= mosGetParam($_REQUEST, 'order', 'none');
66 // Load component's language
67 if (file_exists($this->hpath
.'/language/'.$alang.'.php')) {
68 require_once($this->hpath
.'/language/'.$alang.'.php');
69 } else if (file_exists($this->hpath
.'/language/'.$mainframe->getCfg('alang').'.php')) {
70 require_once($this->hpath
.'/language/'.$mainframe->getCfg('alang').'.php');
72 require_once($this->hpath
.'/language/english.php');
74 $this->lng
= new clsEventCalendarLanguage();
77 /******************************/
78 /* The class' main function */
79 /******************************/
80 public function main() {
82 switch ($this->task
) {
85 $this->showControlPanel();
89 $this->saveConfiguration();
92 mosRedirect( 'index2.php?option=com_eventcalendar' );
100 $this->removeTemplate();
105 $this->event_id
= (is_array($this->event_id
))?
$this->event_id
[0]:$this->event_id
;
106 $this->editEvent($this->event_id
);
113 $this->saveEvent(); //
116 $this->cancelEvent(); //
119 $this->publishEvent($this->event_id
, 1); //
122 $this->publishEvent($this->event_id
, 0); //
125 $this->deleteEvent($this->event_id
); //
130 $this->validateSEO();
136 $this->ajaxchangeContent();
147 /**********************/
148 /* Template handler */
149 /**********************/
150 protected function addTemplate() {
151 global $fmanager, $mosConfig_absolute_path, $adminLanguage;
153 require_once($mosConfig_absolute_path.'/administrator/includes/pcl/pclzip.lib.php');
155 $size_str = @ini_get
('upload_max_filesize');
158 while(ctype_digit($size_str[$i])) {
159 $size .= $size_str[$i];
162 if ($size_str[$i]=="M"||
$size_str[$i]=="m") {
163 $size = $size*1024*1024;
164 } else if ($size_str[$i]=="K"||
$size_str[$i]=="k") {
167 $size = 1024*1024*1024;
170 $size = 2048*1024*1024;
173 $validFileTypes = array('zip');
174 $userfile = $_FILES['userfile'];
175 if ( ($userfile['name'] <> '') ||
($userfile['size'] <= $size) ) {
176 $source = $userfile['tmp_name'];
177 if (in_array($fmanager->fileExt($userfile['name']), $validFileTypes)) {
178 $dest = $mosConfig_absolute_path.'/tmpr/'.$userfile['name'];
179 $fmanager->upload($source, $dest);
181 mosRedirect( 'index2.php?option=com_eventcalendar&task=cp', $this->lng
->CP_MSG_TEMPLATE_ADD_ERROR
);
184 mosRedirect( 'index2.php?option=com_eventcalendar&task=cp', $this->lng
->CP_MSG_TEMPLATE_ADD_ERROR
);
189 @chdir
($this->hpath
.'/templates');
190 if (is_file($zipfile)) {
191 $path_parts = pathinfo($zipfile);
192 if (strtolower($path_parts['extension']) == 'zip') {
193 $zip = new PclZip($zipfile);
194 $list = $zip->extract(".");
196 mosRedirect( 'index2.php?option=com_eventcalendar&task=cp', $adminLanguage->A_CMP_ME_FINOZIP
);
199 mosRedirect( 'index2.php?option=com_eventcalendar&task=cp', $adminLanguage->A_CMP_ME_FILNEX
);
201 mosRedirect( 'index2.php?option=com_eventcalendar&task=cp', $this->lng
->CP_MSG_TEMPLATE_ADD_OK
);
204 protected function removeTemplate() {
207 $css_filename = mosGetParam( $_REQUEST, 'css_filename', '' );
210 if ( ($fmanager->deleteFile($this->hpath
."/templates/".$css_filename)) && ($fmanager->deleteFolder($this->hpath
."/templates/f_".$css_filename."/")) ) {
211 mosRedirect( 'index2.php?option=com_eventcalendar&task=cp', $this->lng
->CP_MSG_TEMPLATE_REM_OK
);
214 mosRedirect( 'index2.php?option=com_eventcalendar&task=cp', $this->lng
->CP_MSG_TEMPLATE_REM_ERROR
);
218 /***********************************/
219 /* Prepare to show control panel */
220 /***********************************/
221 protected function showControlPanel() {
222 global $mainframe, $database; // Pass global variables or objects
224 // Initialize variables
225 $borders = null; // store the borders of Public Backend user group
226 $groups = null; // store Public Backend groups
227 $text = ''; // get params from database
228 $config_values = null; // store params
230 // Get Public Backend user groups
231 $groups = $mainframe->backGroups();
233 // Load params values
234 $database->setQuery( "SELECT params FROM #__components WHERE link = 'option=com_eventcalendar'" );
235 $text = $database->loadResult();
236 $config_values = new mosParameters( $text );
239 clsEventCalendarAdminHTML
::showControlPanelHTML( $config_values, $groups );
242 /************************/
243 /* Save configuration */
244 /************************/
245 protected function saveConfiguration() {
246 global $database, $mainframe, $fmanager; // Pass global variables or objects
248 // Initialize variables
249 $params = new mosParameters('');
251 // Get group_role_permissions from Post-Data
252 $group_roles_new_auto = mosGetParam( $_REQUEST, 'newauto', array('') );
253 $group_roles_new_all = mosGetParam( $_REQUEST, 'newall', array('') );
254 $group_roles_changes_auto = mosGetParam( $_REQUEST, 'changesauto', array('') );
255 $group_roles_changes_all = mosGetParam( $_REQUEST, 'changesall', array('') );
256 $params->set( 'newauto', implode( ',', $group_roles_new_auto ) );
257 $params->set( 'newall', implode( ',', $group_roles_new_all ) );
258 $params->set( 'changesauto', implode( ',', $group_roles_changes_auto ) );
259 $params->set( 'changesall', implode( ',', $group_roles_changes_all ) );
261 // Get timetable from Post Data and implode it to an array
262 $timetable = mosGetParam( $_REQUEST, 'timetable', array() );
263 $timetable = serialize( $timetable );
264 $params->set( 'timetable', $timetable);
265 $timetable_selected = mosGetParam( $_REQUEST, 'timetable_selected', 0 );
266 $params->set( 'timetable_selected', $timetable_selected);
268 // Get the rest settings
269 $who_can_post_events = intval(mosGetParam( $_REQUEST, 'who_can_post_events', 2 ));
270 $who_can_edit_events = intval(mosGetParam( $_REQUEST, 'who_can_edit_events', 2 ));
271 $week_startingday = intval(mosGetParam( $_REQUEST, 'week_startingday', 0 ));
272 $show_weeknumber = intval(mosGetParam( $_REQUEST, 'show_weeknumber', 1 ));
273 $week_number_links = intval(mosGetParam( $_REQUEST, 'week_number_links', 0 ));
274 $default_view = mosGetParam( $_REQUEST, 'default_view', 'monthview' );
275 $view_nav = mosGetParam( $_REQUEST, 'view_nav', true );
276 $view_print = mosGetParam( $_REQUEST, 'view_print', true );
277 $view_rss = mosGetParam( $_REQUEST, 'view_rss', true );
278 $view_catlist = mosGetParam( $_REQUEST, 'view_catlist', true );
279 $view_periodicity = mosGetParam( $_REQUEST, 'view_periodicity', true );
280 $view_reservation = mosGetParam( $_REQUEST, 'view_reservation', false );
281 $col_catlist = mosGetParam( $_REQUEST, 'col_catlist', 2 );
282 $rss_cache = mosGetParam( $_REQUEST, 'rss_cache', '0' );
283 $rss_cachetime = mosGetParam( $_REQUEST, 'rss_cachetime', '3600' );
284 $rss_num = mosGetParam( $_REQUEST, 'rss_num', '5' );
285 $rss_title = mosGetParam( $_REQUEST, 'rss_title', 'EventCalendar RSS feeds' );
286 $rss_description = mosGetParam( $_REQUEST, 'rss_description', 'EventCalendar web syndication.' );
287 $rss_img = mosGetParam( $_REQUEST, 'rss_img', 'elxis_rss.png' );
288 $rss_imgalt = mosGetParam( $_REQUEST, 'rss_imgalt', 'EventCalendar RSS feeds' );
289 $rss_limittext = mosGetParam( $_REQUEST, 'rss_limittext', '0' );
290 $rss_textlength = mosGetParam( $_REQUEST, 'rss_textlength', '20' );
291 $rss_multilang = mosGetParam( $_REQUEST, 'rss_multilang', '0' );
292 $rss_live = mosGetParam( $_REQUEST, 'rss_live', '0' );
293 $pp_mail = mosGetParam( $_REQUEST, 'pp_mail', 'mypaypal@email.com' );
294 $pp_curlist = mosGetParam( $_REQUEST, 'pp_curlist', 'EUR' );
295 $css_filename = mosGetParam( $_REQUEST, 'css_filename', '' );
296 $date_format = mosGetParam( $_REQUEST, 'date_format', 'd-m-Y' );
297 $params->set( 'who_can_post_events', $who_can_post_events );
298 $params->set( 'who_can_edit_events', $who_can_edit_events );
299 $params->set( 'week_startingday', $week_startingday );
300 $params->set( 'show_weeknumber', $show_weeknumber );
301 $params->set( 'week_number_links', $week_number_links );
302 $params->set( 'default_view', $default_view );
303 $params->set( 'view_nav', $view_nav );
304 $params->set( 'view_print', $view_print );
305 $params->set( 'view_rss', $view_rss );
306 $params->set( 'view_catlist', $view_catlist );
307 $params->set( 'view_periodicity', $view_periodicity );
308 $params->set( 'view_reservation', $view_reservation );
309 $params->set( 'col_catlist', $col_catlist );
310 $params->set( 'rss_cache', $rss_cache );
311 $params->set( 'rss_cachetime', $rss_cachetime );
312 $params->set( 'rss_num', $rss_num );
313 $params->set( 'rss_title', $rss_title );
314 $params->set( 'rss_description', $rss_description );
315 $params->set( 'rss_img', $rss_img );
316 $params->set( 'rss_imgalt', $rss_imgalt );
317 $params->set( 'rss_multilang', $rss_multilang );
318 $params->set( 'rss_limittext', $rss_limittext );
319 $params->set( 'rss_textlength', $rss_textlength );
320 $params->set( 'rss_live', $rss_live );
321 $params->set( 'pp_mail', $pp_mail );
322 $params->set( 'pp_curlist', $pp_curlist );
323 $params->set( 'css_filename', $css_filename );
324 $params->set( 'date_format', $date_format );
326 // Store params to database
327 $params_as_text = array();
328 foreach ($params->_params
as $k=>$v) {
329 $params_as_text[] = "$k=$v";
331 $database->setQuery( "UPDATE #__components SET params = \n'" . mosParameters
::textareaHandling( $params_as_text ) . "'\n WHERE link = 'option=com_eventcalendar'" );
332 if ($database->query()) {
333 $msg = $this->lng
->CP_MSG_CONFIGURATION_STORED
;
335 $msg = $this->lng
->CP_MSG_CONFIGURATION_ERROR
;
338 // Activate IOS Sitemap extension
339 if (mosGetParam( $_REQUEST, 'sitemap_ext') == 'on') {
340 $source = $mainframe->getCfg('absolute_path').'/administrator/components/com_eventcalendar/eventcalendar.sitemap.php';
341 $destination = $mainframe->getCfg('absolute_path').'/administrator/components/com_sitemap/extensions/eventcalendar.sitemap.php';
342 $success = $fmanager->copyFile($source, $destination);
345 // Check if task is apply or save and redirect respectively
346 switch ( $this->task
) {
348 mosRedirect( 'index2.php?option=com_eventcalendar&task=cp', $msg );
352 mosRedirect( 'index2.php?option=com_eventcalendar', $msg );
357 /*********************************/
358 /* Prepare to show events list */
359 /*********************************/
360 protected function listEvents () {
361 global $mainframe, $database, $mosConfig_list_limit; // Pass global variables or objects
363 if ( $this->field
&& $this->order
<> "none" ) {
364 $ordering = "\n ORDER BY e.$this->field " . $this->order
;
366 $ordering = "\n ORDER BY e.start_date DESC, e.recur_week";
369 if (isset($searchstring)) $searcharray[] = $searchstring;
371 if(($this->cat_id
<> 0) && is_numeric($this->cat_id
) ) {
372 $searcharray[] = " e.catid=" . $this->cat_id
;
373 } else if ($this->cat_id
=== "old") {
375 $searcharray[] = "e.end_date < $today[0]";
378 if ($this->task
== "unpublished") {$searcharray[] = "e.published = '0'";}
381 $search = mosGetParam($_REQUEST, "search", false);
382 if ($search) $searcharray[] = "(e.title LIKE '%$search%' OR e.description LIKE '%$search%')";
383 $searchstring = (@$searcharray)?
implode(" AND ", $searcharray):"1";
384 $database->setQuery( "SELECT COUNT(*) FROM #__eventcalendar e WHERE $searchstring");
387 $total = $database->loadResult();
388 $limitstart = $mainframe->getUserStateFromRequest( "view{eventcalendar}", 'limitstart', 0 );
389 $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit );
390 $pageNav = new mosPageNav( $total, $limitstart, $limit );
393 "SELECT e.*, u.name AS editor, c.title AS cat_name, c.params AS cat_params FROM #__eventcalendar e" .
394 "\n LEFT JOIN #__users u ON u.id = e.checked_out" .
395 "\n LEFT JOIN #__categories c ON c.id = e.catid" .
396 "\n WHERE " . $searchstring .
397 $ordering, '#__', $pageNav->limit
, $pageNav->limitstart
399 $results = $database->loadObjectList();
400 $categories[] = mosHTML
::makeOption( "0", $this->lng
->LST_ALL_EVENTS
);
401 $categories[] = mosHTML
::makeOption( "old", $this->lng
->LST_OLD_EVENTS
);
403 $query = "SELECT id AS value, name AS text"
404 . "\n FROM #__categories"
405 . "\n WHERE section = 'com_eventcalendar'"
406 . "\n AND published = '1'";
407 $database->setQuery( $query );
408 $categories = array_merge( $categories, $database->loadObjectList() );
410 $catlist = mosHTML
::selectList( $categories, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $this->cat_id
);
412 clsEventCalendarAdminHTML
::listEventsHTML($results, $pageNav, $catlist );
415 /*******************************/
416 /* Prepare to edit/add event */
417 /*******************************/
418 protected function editEvent($existing = NULL) {
419 global $my, $database;
421 if (is_numeric($existing)) {
422 $event = new mosEventCalendar_Event($database);
423 $event->load($existing);
425 $existing->checkout( $my->id
);
427 clsEventCalendarAdminHTML
::editEventHTML($existing);
433 protected function saveEvent() {
434 global $objEventCalendar, $database, $adminLanguage, $my;
437 $tokname = 'token'.$my->id
;
438 if ( !isset($_POST[$tokname]) ||
!isset($_SESSION[$tokname]) ||
($_POST[$tokname] != $_SESSION[$tokname]) ) {
439 die( 'Detected CSRF attack! Someone is forging your requests.' );
442 foreach ($_POST['languages'] as $xlang) {
443 if (trim($xlang) == '') { $newlangs = ''; }
445 if (!isset($newlangs)) {
446 $newlangs = implode(',', $_POST['languages']);
448 $_POST['language'] = $newlangs;
450 $event = new mosEventCalendar_Event($database);
451 $event->bind( $_POST );
452 if ($event->check($error)) {
453 if ($event->store()) {
454 // Update category color
455 $cat_col = new mosCategory( $database );
456 $cat_col->load($_POST['catid']);
457 $cat_col_par = new mosParameters( $cat_col->params
);
459 if($_POST['color'.$_POST['id'].'display'] != "")
460 $cat_col_par->set("color", $_POST['color'.$_POST['id'].'display']);
462 $cat_col_par_txt = array();
463 foreach ($cat_col_par->_params
as $k=>$v) {
464 $cat_col_par_txt[] = "$k=$v";
466 $cat_col->params
= mosParameters
::textareaHandling( $cat_col_par_txt );
467 if ($cat_col->store()) {
468 $msg = $objEventCalendar->lng
->EDT_MSG_STORED
;
470 echo "<script type=\"text/javascript\">alert('".$objEventCalendar->lng
->GEN_COMPONENT_TITLE
.": ".$objEventCalendar->lng
->EDT_MSG_ERROR
."'); window.history.go(-1);</script>"._LEND
;
474 echo "<script type=\"text/javascript\">alert('".$objEventCalendar->lng
->GEN_COMPONENT_TITLE
.": ".$objEventCalendar->lng
->EDT_MSG_ERROR
."'); window.history.go(-1);</script>"._LEND
;
478 echo "<script type=\"text/javascript\">alert('".$objEventCalendar->lng
->GEN_COMPONENT_TITLE
.": ".$error."'); window.history.go(-1);</script>"._LEND
;
483 require_once($this->apath
.'/eventcalendar.seovs.class.php');
484 $seo = new seovsEventCalendar('com_eventcalendar', '', $event->seotitle
);
485 $seo->id
= intval($event->id
);
486 $seo->catid
= intval($event->catid
);
487 $seoval = $seo->validate();
489 echo "<script type=\"text/javascript\">alert('".$adminLanguage->A_SEOTITLE
.": ".$seo->message
."'); window.history.go(-1);</script>"._LEND
;
493 // Check if task is apply or save and redirect respectively
494 switch ( $this->task
) {
496 mosRedirect( 'index2.php?option=com_eventcalendar&task=edit&hidemainmenu=1&cid='.$event->id
, $msg );
500 mosRedirect( 'index2.php?option=com_eventcalendar', $msg );
505 /*********************/
506 /* Cancel add/edit */
507 /*********************/
508 protected function cancelEvent() {
511 $event = new mosEventCalendar_Event($database);
512 $event->checkin($_POST['id']); //the id is defined globally
521 protected function deleteEvent($itemids) {
524 $event = new mosEventCalendar_Event($database);
525 foreach($itemids AS $itemid) {
526 $event->delete($itemid);
532 /***********************/
533 /* Un-/Publish event */
534 /***********************/
535 protected function publishEvent($event_id, $value) {
538 $event = new mosEventCalendar_Event($database);
539 foreach($event_id AS $id) {
541 $event->published
= ''.intval($value).'';
547 /*****************************/
548 /* Validate SEO Title (AJAX) */
549 /*****************************/
550 protected function validateSEO() {
553 $coid = intval(mosGetParam($_POST, 'coid', 0));
554 $cocatid = intval(mosGetParam($_POST, 'cocatid', 0));
555 $seotitle = eUTF
::utf8_trim(mosGetParam($_POST, 'seotitle', ''));
557 require_once($this->apath
.'/eventcalendar.seovs.class.php');
558 $seo = new seovsEventCalendar('com_eventcalendar', '', $seotitle);
560 $seo->catid
= $cocatid;
567 /****************************/
568 /* Suggest SEO Title (AJAX) */
569 /****************************/
570 protected function suggestSEO() {
573 $coid = intval(mosGetParam($_POST, 'coid', 0));
574 $cocatid = intval(mosGetParam($_POST, 'cocatid', 0));
575 $cotitle = mosGetParam($_POST, 'cotitle', '');
577 require_once($this->apath
.'/eventcalendar.seovs.class.php');
578 $seo = new seovsEventCalendar('com_eventcalendar', $cotitle);
580 $seo->catid
= $cocatid;
581 $sname = $seo->suggest();
584 @header
('Content-Type: text/plain; Charset: utf-8');
588 echo '|0|'.$seo->message
;
593 /*******************************/
594 /* Change publish state (AJAX) */
595 /*******************************/
596 function ajaxchangeContent() {
597 global $database, $my, $adminLanguage;
599 $elem = intval(mosGetParam($_REQUEST, 'elem', 0));
600 $id = intval(mosGetParam($_REQUEST, 'id', 0));
601 $state = intval(mosGetParam($_REQUEST, 'state', 0));
604 echo '<img src="../includes/js/ThemeOffice/warning.png" width="16" height="16" border="0" title="'.$adminLanguage->A_ERROR
.': Invalid Item id" />'._LEND
;
609 $database->setQuery( "UPDATE #__eventcalendar SET published='$state' WHERE id='$id' AND (checked_out=0 OR (checked_out='".$my->id
."'))");
610 if (!$database->query()) { $error = 1; }
612 if ($error) { $state = $state ?
0 : 1; }
613 $img = $state ?
'publish_g.png' : 'publish_x.png';
614 $alt = $state ?
$adminLanguage->A_PUBLISHED
: $adminLanguage->A_UNPUBLISHED
; ?
>
615 <a href
="javascript: void(0);"
616 onclick
="changeContentState('<?php echo $elem; ?>', '<?php echo $id; ?>', '<?php echo ($state) ? 0 : 1; ?>');" title
="<?php echo $alt; ?>">
617 <img src
="images/<?php echo $img; ?>" width
="12" height
="12" border
="0" alt
="<?php echo $alt; ?>" /></a
>
623 // Initiate the class/ and execute it, then unset the
624 // object in order to free the allocated PHP memory.
625 $objEventCalendar = new clsEventCalendarAdmin();
626 $objEventCalendar->main();
627 unset($objEventCalendar);