Ejemplo n.º 1
0
 /**
  * Saves the recurring date
  *
  * @param   bool  $frontend  - Are we in the frontend?
  *
  * @throws  Exception on db error
  * @return  string    - (id of the recurring date)
  */
 public static function saveRecurring($frontend = false)
 {
     $database = JFactory::getDBO();
     $input = JFactory::getApplication()->input;
     // 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');
     $id = $input->getInt('id', 0);
     $post = JRequest::get('post');
     $row = JTable::getInstance('Recurring', 'MatukioTable');
     $row->load($id);
     if (!$row->bind($post)) {
         throw new Exception($row->getError(), 42);
     }
     // 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);
     if (!$row->check()) {
         throw new Exception($database->stderr(), 42);
     }
     if (!$row->store()) {
         throw new Exception($database->stderr(), 42);
     }
     $row->checkin();
     // Return id
     return $row->id;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /**
  * $cattable->id = null;
  * $cattable->asset_id = 0;
  * $cattable->parent_id = 0;
  * $cattable->lft = 0;
  * $cattable->rgt = 0;
  * $cattable->level = 1;
  * $cattable->path = "test";
  * $cattable->extension = "com_matukio";
  * $cattable->title = "";
  * $cattable->alias = "";
  * $cattable->note = "";
  * $cattable->description = "";
  * $cattable->published = "";
  * $cattable->checked_out = 0;
  * $cattable->checked_out_time = "0000-00-00 00:00:00";
  * $cattable->access = "";
  * $cattable->params = "";
  *
  * $cattable->metadesc = "";
  * $cattable->metakey = "";
  * $cattable->metadata = "";
  * $cattable->created_user_id = "";
  * $cattable->created_time = "";
  * $cattable->modified_user_id = "";
  * $cattable->hits = "";
  * $cattable->language = "";
  */
 public function importseminar()
 {
     $input = JFactory::getApplication()->input;
     $db = JFactory::getDbo();
     $seminar_table = $input->get('seminar_table', '');
     $seminar_category_table = $input->get('seminar_category_table', '');
     $seminar_booking_table = $input->get('seminar_booking_table', '');
     $seminar_number_table = $input->get('seminar_number_table', '');
     // Load old categories
     $query = $db->getQuery(true);
     $query->select("*")->from($seminar_category_table)->where("section = " . $db->quote("com_seminar"));
     $db->setQuery($query);
     $cats = $db->loadObjectList();
     $insert_id = null;
     $relationsDb = array();
     $user = JFactory::getUser();
     $i = 0;
     $table = JTable::getInstance('Category', 'JTable');
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     foreach ($cats as $cat) {
         // Import category into Joomla 2.5 #__categories table
         $old_id = $cat->id;
         $cat->name = html_entity_decode($cat->title);
         $cat->path = $cat->name;
         $cat->alias = $cat->alias;
         $cat->parent = 1;
         $cat->author = $user->id;
         $new_id = $this->insertCategory($cat);
         if ($new_id == -1) {
             break;
         }
         $dispatcher->trigger('onContentAfterSave', array('com_content.category.' . $insert_id, &$table, true));
         $relationsDb[] = $db->quote($new_id) . ',' . $i . ',' . $old_id;
         // Get the events for the category
         $query = $db->getQuery(true);
         $query->select("*")->from($seminar_table)->where("catid = " . $old_id);
         $db->setQuery($query);
         $events = $db->loadObjectList();
         foreach ($events as $event) {
             $mattab = JTable::getInstance('Matukio', 'Table');
             $old_event_id = $event->id;
             // Reset event id
             $event->id = null;
             $event->created_by = $user->id;
             $event->catid = $new_id;
             if (!$mattab->bind($event)) {
                 JError::raiseError(500, $mattab->getError());
             }
             // Zuweisung der Startzeit
             $mattab->begin = JFactory::getDate($event->begin, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false);
             // Zuweisung der Endzeit
             $mattab->end = JFactory::getDate($event->end, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false);
             // Zuweisung der Buchungszeit
             $mattab->booked = JFactory::getDate($event->booked, MatukioHelperUtilsBasic::getTimeZone())->format('Y-m-d H:i:s', false, false);
             if (!$mattab->check()) {
                 JError::raiseError(500, $db->stderr());
             }
             if (!$mattab->store()) {
                 JError::raiseError(500, $db->stderr());
             }
             $mattab->checkin();
             // Add recurring event date
             $rid = MatukioHelperRecurring::saveRecurringDateForEvent($mattab);
             // Get the event bookings for this event
             $query = $db->getQuery(true);
             $query->select("*")->from($seminar_booking_table)->where("semid = " . $old_event_id);
             $db->setQuery($query);
             $bookings = $db->loadObjectList();
             foreach ($bookings as $booking) {
                 // Reset
                 $booking->id = null;
                 // Update 3.1 - we need the recurring id not the event id
                 $booking->semid = $rid;
                 $booking->uuid = MatukioHelperPayment::getUuid(true);
                 // Calculating payment
                 $booking->payment_brutto = $mattab->fees * $booking->nrbooked;
                 // No taxes here -> user is goign to add them later
                 $booking->payment_netto = $booking->payment_brutto;
                 $booking->payment_tax = 0.0;
                 $booktable = JTable::getInstance('Bookings', 'Table');
                 if (!$booktable->bind($booking)) {
                     JError::raiseError(500, $booktable->getError());
                 }
                 if (!$booktable->check()) {
                     JError::raiseError(500, $db->stderr());
                 }
                 if (!$booktable->store()) {
                     JError::raiseError(500, $db->stderr());
                 }
             }
         }
         $i++;
     }
     // Import Numbers
     $query = $db->getQuery(true);
     $query->select("*")->from($seminar_number_table);
     $db->setQuery($query);
     $numbers = $db->loadObjectList();
     foreach ($numbers as $number) {
         $numtable = JTable::getInstance("Number", "Table");
         if (!$numtable->bind($number)) {
             JError::raiseError(500, $numtable->getError());
         }
         if (!$numtable->check()) {
             JError::raiseError(500, $db->stderr());
         }
         if (!$numtable->store()) {
             JError::raiseError(500, $db->stderr());
         }
     }
     $msg = JText::_("COM_MATUKIO_IMPORT_SUCCESSFULLY");
     $link = 'index.php?option=com_matukio&view=import';
     $this->setRedirect($link, $msg);
 }