Пример #1
0
<?php

/**
 * @package    Matukio
 * @author     Yves Hoppe <*****@*****.**>
 * @date       10.11.13
 *
 * @copyright  Copyright (C) 2008 - 2013 Yves Hoppe - compojoom.com . All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE
 */
defined('_JEXEC') or die('Restricted access');
$input = JFactory::getApplication()->input;
$task = $input->get('task', null);
// Checking if task is set
if (!$task) {
    echo "No task specified";
    return;
}
// URL index.php?option=com_matukio&format=raw&view=requests&task=get_override_fee_edit_row
if ($task == 'get_override_fee_edit_row') {
    MatukioHelperFees::printDifferentFeesRow();
} elseif ($task == 'generate_recurring') {
    MatukioHelperRecurring::printGenerateRecurring();
}
jexit();
 public static function saveEvent($frontend = false)
 {
     $database = JFactory::getDBO();
     $input = JFactory::getApplication()->input;
     $caid = $input->getInt('caid', 0);
     $cancel = $input->getInt('cancel', 0);
     $deldatei1 = $input->get('deldatei1', 0);
     $deldatei2 = $input->get('deldatei2', 0);
     $deldatei3 = $input->get('deldatei3', 0);
     $deldatei4 = $input->get('deldatei4', 0);
     $deldatei5 = $input->get('deldatei5', 0);
     $vorlage = $input->getInt('vorlage', 0, 'string');
     $id = $input->getInt('id', 0);
     $art = $input->getInt('art', 2);
     $neudatum = MatukioHelperUtilsDate::getCurrentDate();
     $recurring = $input->getInt("recurring", 0);
     $isNew = true;
     JPluginHelper::importPlugin('content');
     $dispatcher = JDispatcher::getInstance();
     // Zeit formatieren
     $_begin_date = $input->get('_begin_date', '0000-00-00', 'string');
     $_end_date = $input->get('_end_date', '0000-00-00', 'string');
     $_booked_date = $input->get('_booked_date', '0000-00-00', 'string');
     if ($id > 0) {
         $kurs = JTable::getInstance('Matukio', 'Table');
         $kurs->load($id);
         $isNew = false;
     }
     if ($vorlage > 0) {
         $kurs = JTable::getInstance('Matukio', 'Table');
         $kurs->load($vorlage);
     }
     $post = JRequest::get('post');
     // Allow HTML for certain fields
     $post['description'] = JRequest::getVar('description', '', 'post', 'html', JREQUEST_ALLOWHTML);
     $post['booking_mail'] = JRequest::getVar('booking_mail', '', 'post', 'html', JREQUEST_ALLOWHTML);
     $post['certificate_code'] = JRequest::getVar('certificate_code', '', 'post', 'html', JREQUEST_ALLOWHTML);
     $post['shortdesc'] = JRequest::getVar('shortdesc', '', 'post', 'html', JREQUEST_ALLOWHTML);
     $post['place'] = JRequest::getVar('place', '', 'post', 'html', JREQUEST_ALLOWHTML);
     $row = JTable::getInstance('Matukio', 'Table');
     $row->load($id);
     if (!$row->bind($post)) {
         throw new Exception($row->getError(), 42);
     }
     // Zuweisung der aktuellen Zeit
     if ($id == 0) {
         $row->publishdate = $neudatum;
     }
     $row->updated = $neudatum;
     if ($cancel != $row->cancelled && MatukioHelperSettings::_("notify_participants_cancel", 1)) {
         $tempmail = 9 + $cancel;
         $events = MatukioHelperUtilsEvents::getEventsRecurringOnEventId($row->id);
         foreach ($events as $e) {
             $database->setQuery("SELECT * FROM #__matukio_bookings WHERE semid='{$e->id}'");
             $rows = $database->loadObjectList();
             for ($i = 0, $n = count($rows); $i < $n; $i++) {
                 MatukioHelperUtilsEvents::sendBookingConfirmationMail($e, $rows[$i]->id, $tempmail);
             }
         }
     }
     $row->cancelled = $cancel;
     $row->catid = $caid;
     // Zuweisung der Startzeit
     $row->begin = JFactory::getDate($_begin_date, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false);
     // Zuweisung der Endzeit
     $row->end = JFactory::getDate($_end_date, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false);
     // Zuweisung der Buchungszeit
     $row->booked = JFactory::getDate($_booked_date, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false);
     // Neue Daten eintragen
     $row->description = str_replace('<br>', '<br />', $row->description);
     $row->description = str_replace('\\"', '"', $row->description);
     $row->description = str_replace("'", "'", $row->description);
     $row->fees = str_replace(",", ".", $row->fees);
     $row->different_fees_override = "";
     $different_fees_override = $input->get("different_fees_override", array(), 'Array');
     if (count($different_fees_override)) {
         // Check if element 0 is not empty
         if (!empty($different_fees_override[0]["title"])) {
             $row->different_fees_override = json_encode($different_fees_override);
         }
     }
     if ($row->id > 0 or $vorlage > 0) {
         if ($deldatei1 != 1) {
             $row->file1 = $kurs->file1;
             $row->file1code = $kurs->file1code;
         }
         if ($deldatei2 != 1) {
             $row->file2 = $kurs->file2;
             $row->file2code = $kurs->file2code;
         }
         if ($deldatei3 != 1) {
             $row->file3 = $kurs->file3;
             $row->file3code = $kurs->file3code;
         }
         if ($deldatei4 != 1) {
             $row->file4 = $kurs->file4;
             $row->file4code = $kurs->file4code;
         }
         if ($deldatei5 != 1) {
             $row->file5 = $kurs->file5;
             $row->file5code = $kurs->file5code;
         }
     }
     if ($row->id > 0) {
         $row->hits = $kurs->hits;
     }
     $fileext = explode(' ', strtolower(MatukioHelperSettings::getSettings('file_endings', 'txt zip pdf')));
     $filesize = MatukioHelperSettings::getSettings('file_maxsize', 500) * 1024;
     $fehler = array('', '', '', '', '', '', '', '', '', '');
     if (!empty($_FILES['datei1'])) {
         if (is_file($_FILES['datei1']['tmp_name']) and $_FILES['datei1']['size'] > 0) {
             if ($_FILES['datei1']['size'] > $filesize) {
                 $fehler[0] = str_replace("SEM_FILE", $_FILES['datei1']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE'));
             }
             $datei1ext = array_pop(explode(".", strtolower($_FILES['datei1']['name'])));
             if (!in_array($datei1ext, $fileext)) {
                 $fehler[1] = str_replace("SEM_FILE", $_FILES['datei1']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE'));
             }
             if ($fehler[0] == "" and $fehler[1] == "") {
                 if ($deldatei1 != 1) {
                     $row->file1 = $_FILES['datei1']['name'];
                     $row->file1code = base64_encode(file_get_contents($_FILES['datei1']['tmp_name']));
                 } else {
                     $row->file1 = "";
                     $row->file1code = "";
                 }
             }
         }
     } else {
         // Delete file
         if ($deldatei1 == 1) {
             $row->file1 = "";
             $row->file1code = "";
         }
     }
     if (!empty($_FILES['datei2'])) {
         if (is_file($_FILES['datei2']['tmp_name']) and $_FILES['datei2']['size'] > 0) {
             if ($_FILES['datei2']['size'] > $filesize) {
                 $fehler[2] = str_replace("SEM_FILE", $_FILES['datei2']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE'));
             }
             $datei2ext = array_pop(explode(".", strtolower($_FILES['datei2']['name'])));
             if (!in_array($datei2ext, $fileext)) {
                 $fehler[3] = str_replace("SEM_FILE", $_FILES['datei2']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE'));
             }
             if ($fehler[2] == "" and $fehler[3] == "") {
                 $row->file2 = $_FILES['datei2']['name'];
                 $row->file2code = base64_encode(file_get_contents($_FILES['datei2']['tmp_name']));
             }
         }
     } else {
         // Delete file
         if ($deldatei2 == 1) {
             $row->file2 = "";
             $row->file2code = "";
         }
     }
     if (!empty($_FILES['datei3'])) {
         if (is_file($_FILES['datei3']['tmp_name']) and $_FILES['datei3']['size'] > 0) {
             if ($_FILES['datei3']['size'] > $filesize) {
                 $fehler[4] = str_replace("SEM_FILE", $_FILES['datei3']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE'));
             }
             $datei3ext = array_pop(explode(".", strtolower($_FILES['datei3']['name'])));
             if (!in_array($datei3ext, $fileext)) {
                 $fehler[5] = str_replace("SEM_FILE", $_FILES['datei3']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE'));
             }
             if ($fehler[4] == "" and $fehler[5] == "") {
                 $row->file3 = $_FILES['datei3']['name'];
                 $row->file3code = base64_encode(file_get_contents($_FILES['datei3']['tmp_name']));
             }
         }
     } else {
         // Delete file
         if ($deldatei3 == 1) {
             $row->file3 = "";
             $row->file3code = "";
         }
     }
     if (!empty($_FILES['datei4'])) {
         if (is_file($_FILES['datei4']['tmp_name']) and $_FILES['datei4']['size'] > 0) {
             if ($_FILES['datei4']['size'] > $filesize) {
                 $fehler[6] = str_replace("SEM_FILE", $_FILES['datei4']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE'));
             }
             $datei4ext = array_pop(explode(".", strtolower($_FILES['datei4']['name'])));
             if (!in_array($datei4ext, $fileext)) {
                 $fehler[7] = str_replace("SEM_FILE", $_FILES['datei4']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE'));
             }
             if ($fehler[6] == "" and $fehler[7] == "") {
                 $row->file4 = $_FILES['datei4']['name'];
                 $row->file4code = base64_encode(file_get_contents($_FILES['datei4']['tmp_name']));
             }
         }
     } else {
         // Delete file
         if ($deldatei4 == 1) {
             $row->file4 = "";
             $row->file4code = "";
         }
     }
     if (!empty($_FILES['datei5'])) {
         if (is_file($_FILES['datei5']['tmp_name']) and $_FILES['datei5']['size'] > 0) {
             if ($_FILES['datei5']['size'] > $filesize) {
                 $fehler[8] = str_replace("SEM_FILE", $_FILES['datei5']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_MAX_SIZE'));
             }
             $datei5ext = array_pop(explode(".", strtolower($_FILES['datei5']['name'])));
             if (!in_array($datei5ext, $fileext)) {
                 $fehler[9] = str_replace("SEM_FILE", $_FILES['datei5']['name'], JTEXT::_('COM_MATUKIO_UPLOAD_FAILED_FILE_TYPE'));
             }
             if ($fehler[8] == "" and $fehler[9] == "") {
                 $row->file5 = $_FILES['datei5']['name'];
                 $row->file5code = base64_encode(file_get_contents($_FILES['datei5']['tmp_name']));
             }
         }
     } else {
         // Delete file
         if ($deldatei5 == 1) {
             $row->file5 = "";
             $row->file5code = "";
         }
     }
     // Eingaben ueberpruefen
     $speichern = true;
     // Template?? Deprecated
     if ($art == 3) {
         if (!MatukioHelperUtilsEvents::checkRequiredFieldValues($row->pattern, 'leer')) {
             $speichern = false;
             $fehler[] = JTEXT::_('COM_MATUKIO_YOU_HAVENT_FILLED_OUT_ALL_REQUIRED_FIELDS');
         }
     } else {
         if (!MatukioHelperUtilsEvents::checkRequiredFieldValues($row->semnum, 'leer') or !MatukioHelperUtilsEvents::checkRequiredFieldValues($row->title, 'leer') or $row->catid == 0 or !MatukioHelperUtilsEvents::checkRequiredFieldValues($row->shortdesc, 'leer')) {
             $speichern = false;
             $fehler[] = JTEXT::_('COM_MATUKIO_YOU_HAVENT_FILLED_OUT_ALL_REQUIRED_FIELDS');
         } elseif (!MatukioHelperUtilsEvents::checkRequiredFieldValues($row->maxpupil, 'nummer') or !MatukioHelperUtilsEvents::checkRequiredFieldValues($row->nrbooked, 'nummer')) {
             $speichern = false;
             $fehler[] = JTEXT::_('COM_MATUKIO_YOU_HAVENT_TYPED_A_NUMBER');
         } else {
             $database->setQuery("SELECT id FROM #__matukio WHERE semnum='{$row->semnum}' AND id!='{$row->id}'");
             $rows = $database->loadObjectList();
             if (count($rows) > 0) {
                 $speichern = false;
                 $htxt = JTEXT::_('COM_MATUKIO_NOT_UNIQUE_NUMBERS');
                 if ($id < 1) {
                     $htxt .= " " . JTEXT::_('COM_MATUKIO_EVENT_NOT_STORED');
                 }
                 $fehler[] = $htxt;
             }
         }
     }
     // Kurs speichern
     if ($speichern == true) {
         // Trigger plugin event
         $results = $dispatcher->trigger('onBeforeSaveEvent', $row);
         // Check if we already created recurring events
         if ($recurring == 1) {
             $edited = $input->getInt("recurring_edited", 0);
             if ($row->recurring_created && $edited && $row->id > 0) {
                 // Delete old recurring events
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->delete("#__matukio_recurring")->where("event_id = " . $row->id);
                 $db->setQuery($query);
                 $db->execute();
                 // Maybe set booking status to deleted too?
             } else {
                 // Set it to 1
                 $row->recurring_created = 1;
             }
         }
         if (!$row->check()) {
             throw new Exception($database->stderr(), 42);
         }
         if (!$row->store()) {
             throw new Exception($database->stderr(), 42);
         }
         $row->checkin();
         // Trigger plugin event
         $results = $dispatcher->trigger('onAfterSaveEvent', array('com_matukio.event', &$row, $isNew));
         // Create recurring events
         if ($recurring == 1) {
             $dates_string = $input->get("recurring_dates", '', 'string');
             if (!empty($dates_string)) {
                 $bdate = explode(" ", $row->begin);
                 $bdate = $bdate[0];
                 // Add begin date (if not already in there)
                 if (strpos($dates_string, $bdate) === false) {
                     $dates_string = $bdate . "," . "{$dates_string}";
                 }
                 $dates = explode(",", $dates_string);
                 $begin_date = new DateTime($row->begin);
                 $end_date = new DateTime($row->end);
                 $closing_date = new DateTime($row->booked);
                 $diff = $begin_date->diff($end_date);
                 $diff2 = $begin_date->diff($closing_date);
                 $start_time = $begin_date->format("H:i:s");
                 $year = date('Y');
                 foreach ($dates as $d) {
                     $rec_start = new DateTime($d . " " . $start_time);
                     $rec_end = clone $rec_start;
                     $rec_end->add($diff);
                     $rec_close = clone $rec_start;
                     $rec_close->add($diff2);
                     $robj = new stdClass();
                     $robj->event_id = $row->id;
                     $robj->semnum = MatukioHelperUtilsEvents::createNewEventNumber($year);
                     $robj->begin = $rec_start->format("Y-m-d H:i:s");
                     $robj->end = $rec_end->format("Y-m-d H:i:s");
                     $robj->booked = $rec_close->format("Y-m-d H:i:s");
                     $robj->published = 1;
                     $rect = JTable::getInstance('Recurring', 'MatukioTable');
                     if (!$rect->bind($robj)) {
                         throw new Exception($rect->getError(), 42);
                     }
                     if (!$rect->check()) {
                         throw new Exception($rect->getError(), 42);
                     }
                     if (!$rect->store()) {
                         throw new Exception($rect->getError(), 42);
                     }
                 }
             }
         } else {
             // Delete the current date from recurring table and insert the new one
             // Delete old recurring events
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select("*")->from("#__matukio_recurring")->where("event_id = " . $row->id);
             $db->setQuery($query);
             $recd = $db->loadObjectList();
             // Switch from recurring events to none recurring
             if (count($recd) > 1) {
                 $query = $db->getQuery(true);
                 $query->delete("#__matukio_recurring")->where("event_id = " . $row->id);
                 $db->setQuery($query);
                 $db->execute();
                 // Insert it ones
                 MatukioHelperRecurring::saveRecurringDateForEvent($row);
             } elseif (count($recd) == 1) {
                 // Ugly hack
                 $recd = $recd[0];
                 $rect = JTable::getInstance('Recurring', 'MatukioTable');
                 $recd->semnum = $row->semnum;
                 $recd->begin = $row->begin;
                 $recd->end = $row->end;
                 $recd->booked = $row->booked;
                 $recd->published = $row->published;
                 // We just update the date
                 if (!$rect->bind($recd)) {
                     throw new Exception($rect->getError(), 42);
                 }
                 if (!$rect->check()) {
                     throw new Exception($rect->getError(), 42);
                 }
                 if (!$rect->store()) {
                     throw new Exception($rect->getError(), 42);
                 }
             } else {
                 // Insert date into recurring table
                 // Add recurring date
                 MatukioHelperRecurring::saveRecurringDateForEvent($row);
             }
         }
         // Trigger plugin event
         $results = $dispatcher->trigger('onAfterSaveRecurring', $row);
     }
     // Ausgabe der Kurse
     $fehlerzahl = array_unique($fehler);
     if (count($fehlerzahl) > 1) {
         $fehler = array_unique($fehler);
         if ($fehler[0] == "") {
             $fehler = array_slice($fehler, 1);
         }
         $fehler = implode("<br />", $fehler);
         JFactory::getApplication()->enqueueMessage($fehler, 'Warning');
     }
     // Notify Admin BCC of event creation
     if (MatukioHelperSettings::getSettings('sendmail_operator', '') != '' && $isNew && $speichern) {
         $mailer = JFactory::getMailer();
         $mainframe = JFactory::getApplication();
         $sender = $mainframe->getCfg('fromname');
         $from = $mainframe->getCfg('mailfrom');
         $user = JFactory::getUser($row->publisher);
         $replyname = $user->name;
         $replyto = $user->email;
         $subject = JText::_("COM_MATUKIO_NEW_EVENT_CREATED");
         $body = JText::_("COM_MATUKIO_NEW_EVENT_CREATED") . "\n\n";
         $body .= JText::_("COM_MATUKIO_EVENT_DETAILS") . ":\n\n";
         $body .= JText::_("COM_MATUKIO_TITLE") . ":\t\t" . $row->title . "\n";
         $body .= JText::_("COM_MATUKIO_RECURRING_SEMNUM") . ":\t\t" . $row->semnum . "\n";
         $body .= JText::_("COM_MATUKIO_BEGIN") . ":\t\t" . $row->begin . "\n";
         $body .= JText::_("COM_MATUKIO_END") . ":\t\t" . $row->end . "\n";
         $body .= JText::_("COM_MATUKIO_EVENT_DEFAULT_PLACE") . ":\t\t" . $row->place . "\n";
         $body .= JText::_("COM_MATUKIO_EVENT_DEFAULT_SHORT_DESCRIPTION") . ":\t\t" . $row->shortdesc . "\n";
         $body .= JText::_("COM_MATUKIO_PUBLISHER") . ":\t\t" . $user->name . "\n";
         $success = $mailer->sendMail($from, $sender, explode(",", MatukioHelperSettings::getSettings('sendmail_operator', '')), $subject, $body, MatukioHelperSettings::getSettings('email_html', 1), null, null, null, $replyto, $replyname);
     }
     // Send an notification email to all users with new event details @since 4.3.0
     if (MatukioHelperSettings::getSettings('sendmail_newevent', 1) && $isNew && $speichern) {
         // We send an notification of the new event to all users / user group
         if (MatukioHelperSettings::_("sendmail_newevent_group", 0)) {
             // Filter users to the given group if not 0 (all) given
             jimport('joomla.access.access');
             $ids = JAccess::getUsersByGroup(MatukioHelperSettings::_("sendmail_newevent_group", 0));
             $query = "SELECT * FROM #__users WHERE block = 0 AND id IN (" . implode(",", $ids) . ")";
             $db->setQuery($query);
             $users = $db->loadObjectList();
         } else {
             // Get all users
             $query = "SELECT * FROM #__users WHERE block = 0";
             $db->setQuery($query);
             $users = $db->loadObjectList();
         }
         $mailer = JFactory::getMailer();
         // Set an empty category here - TODO query it from #__category table
         $row->category = "";
         $tmpl = MatukioHelperTemplates::getEmailBody("mail_newevent", $row, null);
         // Use HTML or text E-Mail
         if (MatukioHelperSettings::getSettings('email_html', 1)) {
             // Start html output
             $body = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n";
             $body .= '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n";
             $body .= "<head>\n";
             $body .= "</head>\n";
             $body .= "<body>\n";
             $body .= $tmpl->value;
             $body .= "</body>\n</html>";
         } else {
             $body = $tmpl->value_text;
         }
         $subject = $tmpl->subject;
         $mainframe = JFactory::getApplication();
         $sender = $mainframe->getCfg('fromname');
         $from = $mainframe->getCfg('mailfrom');
         // Loop and sent mail
         foreach ($users as $u) {
             $success = $mailer->sendMail($from, $sender, $u->email, $subject, $body, MatukioHelperSettings::getSettings('email_html', 1), null, null, null);
             $mailer->ClearAllRecipients();
         }
         // E-Mail to Admin / Operator etc.
         if (MatukioHelperSettings::getSettings('sendmail_operator', '') != "") {
             $success = $mailer->sendMail($from, $sender, explode(",", MatukioHelperSettings::getSettings('sendmail_operator', '')), $subject, $body, MatukioHelperSettings::getSettings('email_html', 1), null, null, null);
             $mailer->ClearAllRecipients();
         }
     }
     $obj = new StdClass();
     $obj->id = $row->id;
     $obj->error = $row->fehler;
     $obj->error_count = count($fehlerzahl);
     $obj->saved = $speichern;
     $obj->event = $row;
     return $obj;
 }
Пример #3
0
 /**
  * Imports events from a ics file
  *
  * @throws  Exception
  *
  * @return  void
  */
 public function importics()
 {
     $input = JFactory::getApplication()->input;
     // Let's start uploading the file
     $file = JRequest::getVar('ics_file', null, 'files', 'array');
     $catid = $input->getInt("caid", 0);
     if (empty($file)) {
         throw new Exception("COM_MATUKIO_NO_FILE");
     }
     if (empty($catid)) {
         throw new Exception("COM_MATUKIO_PLEASE_SELECT_A_CATEGORY");
     }
     jimport('joomla.filesystem.file');
     $count = 0;
     if (!strtolower(JFile::getExt($file['name'])) == 'ics') {
         throw new Exception("COM_MATUKIO_NO_ICS_FILE");
     }
     $ar = $this->icsToArray($file['tmp_name']);
     var_dump($ar);
     $user_id = JFactory::getUser()->id;
     // Go through the events saved in the file
     foreach ($ar as $e) {
         if ($e['BEGIN'] == 'VEVENT') {
             $new = MatukioHelperUtilsEvents::getEventEditTemplate();
             // Our real events
             $new->publisher = $user_id;
             $new->title = $e['SUMMARY'];
             $new->shortdesc = $e['SUMMARY'];
             $new->place = $e['LOCATION'];
             $new->description = $e['DESCRIPTION'];
             $new->begin = date("Y-m-d H:i:s", strtotime($e['DTSTART']));
             $new->end = date("Y-m-d H:i:s", strtotime($e['DTEND']));
             $new->booked = $new->begin;
             $new->catid = $catid;
             $new->updated = date("Y-m-d H:i:s");
             $new->publishdate = date("Y-m-d H:i:s");
             // Save new event
             $tab = JTable::getInstance('Matukio', 'Table');
             if (!$tab->bind($new)) {
                 throw new Exception($tab->getError(), 42);
             }
             if (!$tab->check()) {
                 throw new Exception($tab->getError(), 42);
             }
             if (!$tab->store()) {
                 throw new Exception($tab->getError(), 42);
             }
             $tab->checkin();
             // Save date in rec dates
             MatukioHelperRecurring::saveRecurringDateForEvent($tab);
             $count++;
         }
     }
     $msg = JText::_("COM_MATUKIO_ICS_IMPORT_SUCCESSFULLY") . " " . $count;
     $link = 'index.php?option=com_matukio&view=import';
     $this->setRedirect($link, $msg);
 }
Пример #4
0
 /**
  * Saves the recurring date
  *
  * @throws  exception - if query fails
  * @return  void
  */
 public function save()
 {
     $id = MatukioHelperRecurring::saveRecurring();
     switch ($this->task) {
         case 'apply':
             $msg = JText::_('COM_MATUKIO_RECURRING_APPLY');
             $link = 'index.php?option=com_matukio&controller=recurring&task=edit&id=' . $id;
             break;
         case 'save':
         default:
             $msg = JText::_('COM_MATUKIO_RECURRING_SAVE');
             $link = 'index.php?option=com_matukio&view=recurring';
             break;
     }
     $this->setRedirect($link, $msg);
 }
 /**
  * Duplicate an event
  *
  * @return  object
  */
 public function duplicateEvent()
 {
     $msg = JText::_("COM_MATUKIO_EVENT_DUPLICATE_SUCCESS");
     $database = JFactory::getDBO();
     $cid = JFactory::getApplication()->input->getInt('cid', 0);
     // Check authorization
     if (!JFactory::getUser()->authorise('core.edit', 'com_matukio', $cid)) {
         return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
     }
     $database->setQuery("SELECT * FROM #__matukio WHERE id='{$cid}'");
     $item = $database->loadObject();
     if ($database->getErrorNum()) {
         JError::raiseError(500, $database->getError());
         $msg = "COM_MATUKIO_EVENT_DUPLICATE_FAILURE_" . $database->getError();
     }
     $item->id = null;
     $row = JTable::getInstance('matukio', 'Table');
     if (!$row->bind($item)) {
         JError::raiseError(500, $row->getError());
         $msg = "COM_MATUKIO_EVENT_DUPLICATE_FAILURE_" . $row->getError();
     }
     $row->id = null;
     $row->hits = 0;
     $row->grade = 0;
     $row->certificated = 0;
     $row->sid = $item->id;
     $row->publishdate = MatukioHelperUtilsDate::getCurrentDate();
     $row->semnum = MatukioHelperUtilsEvents::createNewEventNumber(date('Y'));
     if (!$row->check()) {
         JError::raiseError(500, $row->getError());
         $msg = "COM_MATUKIO_EVENT_DUPLICATE_FAILURE_" . $row->getError();
     }
     if (!$row->store()) {
         JError::raiseError(500, $row->getError());
         $msg = "COM_MATUKIO_EVENT_DUPLICATE_FAILURE_" . $row->getError();
     }
     $row->checkin();
     // Add recurring date
     MatukioHelperRecurring::saveRecurringDateForEvent($row);
     $link = JRoute::_("index.php?option=com_matukio&view=eventlist&art=2");
     $this->setRedirect($link, $msg);
 }
Пример #6
0
 /**
  * Removes an or multiple events
  *
  * @throws  Exception - If db queries fail
  * @return void
  */
 public function remove()
 {
     $cid = JFactory::getApplication()->input->get('cid', array(), 'array');
     JPluginHelper::importPlugin('content');
     $dispatcher = JDispatcher::getInstance();
     $db = JFactory::getDBO();
     if (count($cid)) {
         // Notify users
         if (MatukioHelperSettings::_("notify_participants_delete", 1)) {
             foreach ($cid as $id) {
                 $events = MatukioHelperUtilsEvents::getEventsRecurringOnEventId($id);
                 foreach ($events as $e) {
                     $db->setQuery("SELECT * FROM #__matukio_bookings WHERE semid = " . $db->quote($e->id) . " AND status = 1");
                     $bookings = $db->loadObjectList();
                     if ($db->getErrorNum()) {
                         throw new Exception($db->getErrorMsg(), 500);
                     }
                     foreach ($bookings as $b) {
                         MatukioHelperUtilsEvents::sendBookingConfirmationMail($e, $b->id, 4);
                     }
                     // Delete old bookings
                     $db->setQuery("UPDATE #__matukio_bookings SET status = 4 WHERE semid = " . $db->quote($e->id));
                     if (!$db->execute()) {
                         throw new Exception($db->getErrorMsg(), 42);
                     }
                 }
             }
         }
         foreach ($cid as $c) {
             // Delete recurring events
             MatukioHelperRecurring::deleteRecurringEvents($c);
         }
         // Delete events
         $cids = implode(',', $cid);
         $query = "DELETE FROM #__matukio where id IN (" . $cids . ")";
         $db->setQuery($query);
         if (!$db->execute()) {
             throw new Exception($db->getErrorMsg(), 500);
         }
     }
     // Trigger the onContentChangeState event.
     $result = $dispatcher->trigger('onEventAfterDelete', array('com_matukio.event', $cid));
     $msg = JText::_("COM_MATUKIO_DELETE_SUCCESS");
     $this->setRedirect('index.php?option=com_matukio&view=eventlist', $msg);
 }