Exemple #1
0
 /**
  * Delete attachment
  *
  * @return true on sucess
  * @access private
  *
  * Views:
  * event, venue
  *
  * Reference to the task is located in the attachments.js
  *
  */
 function ajaxattachremove()
 {
     $id = JFactory::getApplication()->input->request->getInt('id', 0);
     $res = JEMAttachment::remove($id);
     if (!$res) {
         echo 0;
         jexit();
     }
     $cache = JFactory::getCache('com_jem');
     $cache->clean();
     echo 1;
     jexit();
 }
Exemple #2
0
 /**
  * Method to get a specific Venue
  *
  * @access public
  * @return array
  */
 function getVenue()
 {
     $user = JFactory::getUser();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $_venue = array();
     $query->select('id, venue, published, city, state, url, street, custom1, custom2, custom3, custom4, custom5, ' . ' custom6, custom7, custom8, custom9, custom10, phone, fax, email, locimage, meta_keywords, meta_description, ' . ' created, locdescription, country, map, latitude, longitude, postalCode, checked_out AS vChecked_out, checked_out_time AS vChecked_out_time, ' . ' CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(\':\', id, alias) ELSE id END as slug');
     $query->from($db->quoteName('#__jem_venues'));
     $query->where('id = ' . $this->_id);
     $db->setQuery($query);
     $_venue = $db->loadObject();
     if (empty($_venue)) {
         return JError::raiseError(404, JText::_('COM_JEM_VENUE_NOTFOUND'));
     }
     $_venue->attachments = JEMAttachment::getAttachments('venue' . $_venue->id);
     return $_venue;
 }
Exemple #3
0
	/**
	 * Delete attachment
	 *
	 * @return true on sucess
	 * @access private
	 *
	 */
	function ajaxattachremove()
	{
		$id	 = JFactory::getApplication()->input->getInt('id', 0);

		$res = JEMAttachment::remove($id);
		if (!$res) {
			echo 0; // The caller expects an answer!
			jexit();
		}

		$cache = JFactory::getCache('com_jem');
		$cache->clean();

		echo 1; // The caller expects an answer!
		jexit();
	}
 /**
  * Method to get event data.
  *
  * @param integer	The id of the event.
  *
  * @return mixed item data object on success, false on failure.
  */
 public function getItem($itemId = null)
 {
     $jemsettings = JemHelper::config();
     // Initialise variables.
     $itemId = (int) (!empty($itemId)) ? $itemId : $this->getState('event.id');
     // Get a row instance.
     $table = $this->getTable();
     // Attempt to load the row.
     $return = $table->load($itemId);
     // Check for a table object error.
     if ($return === false && $table->getError()) {
         $this->setError($table->getError());
         return false;
     }
     $properties = $table->getProperties(1);
     $value = JArrayHelper::toObject($properties, 'JObject');
     // Backup current recurrence values
     if ($value->id) {
         $value->recurr_bak = new stdClass();
         foreach (get_object_vars($value) as $k => $v) {
             if (strncmp('recurrence_', $k, 11) === 0) {
                 $value->recurr_bak->{$k} = $v;
             }
         }
     }
     // Convert attrib field to Registry.
     $registry = new JRegistry();
     $registry->loadString($value->attribs);
     $globalregistry = JEMHelper::globalattribs();
     $value->params = clone $globalregistry;
     $value->params->merge($registry);
     // Compute selected asset permissions.
     $user = JFactory::getUser();
     $userId = $user->get('id');
     //$asset = 'com_jem.event.' . $value->id;
     $asset = 'com_jem';
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select(array('count(id)'));
     $query->from('#__jem_register');
     $query->where(array('event= ' . $db->quote($itemId), 'waiting= 0'));
     $db->setQuery($query);
     $res = $db->loadResult();
     $value->booked = $res;
     $files = JEMAttachment::getAttachments('event' . $itemId);
     $value->attachments = $files;
     // Check general edit permission first.
     if ($user->authorise('core.edit', $asset)) {
         $value->params->set('access-edit', true);
     } elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) {
         // Check for a valid user and that they are the owner.
         if ($userId == $value->created_by) {
             $value->params->set('access-edit', true);
         }
     }
     // Check edit state permission.
     if ($itemId) {
         // Existing item
         $value->params->set('access-change', $user->authorise('core.edit.state', $asset));
     } else {
         // New item.
         $catId = (int) $this->getState('event.catid');
         if ($catId) {
             $value->params->set('access-change', $user->authorise('core.edit.state', 'com_jem.category.' . $catId));
             $value->catid = $catId;
         } else {
             $value->params->set('access-change', $user->authorise('core.edit.state', 'com_jem'));
         }
     }
     ////////////////
     $venueQuery = $db->getQuery(true);
     $venueQuery->select(array('alias'));
     $venueQuery->from('#__jem_venues');
     $venueQuery->where(array('id= ' . $db->quote($value->locid)));
     $db->setQuery($venueQuery);
     $venueResult = $db->loadResult();
     $value->localias = $venueResult;
     ////////////////
     $value->author_ip = $jemsettings->storeip ? JemHelper::retrieveIP() : false;
     $value->articletext = $value->introtext;
     if (!empty($value->fulltext)) {
         $value->articletext .= '<hr id="system-readmore" />' . $value->fulltext;
     }
     return $value;
 }
Exemple #5
0
 /**
  * Method to get event data.
  *
  * @param integer	The id of the event.
  * @return mixed item data object on success, false on failure.
  */
 public function &getItem($pk = null)
 {
     // Initialise variables.
     $pk = !empty($pk) ? $pk : (int) $this->getState('event.id');
     if ($this->_item === null) {
         $this->_item = array();
     }
     if (!isset($this->_item[$pk])) {
         try {
             $settings = JEMHelper::globalattribs();
             $db = $this->getDbo();
             $query = $db->getQuery(true);
             $query->select($this->getState('item.select', 'a.id, a.access, a.attribs, a.metadata, a.registra, a.custom1, a.custom2, a.custom3, a.custom4, a.custom5, a.custom6, a.custom7, a.custom8, a.custom9, a.custom10, a.times, a.endtimes, a.dates, a.enddates, a.id AS did, a.title, a.alias, ' . 'a.created, a.unregistra, a.published, a.created_by, ' . 'CASE WHEN a.modified = 0 THEN a.created ELSE a.modified END as modified, ' . 'a.modified_by, a.checked_out, a.checked_out_time, ' . 'a.datimage,  a.version, ' . 'a.meta_keywords, a.created_by_alias, a.introtext, a.fulltext, a.maxplaces, a.waitinglist, a.meta_description, a.hits, a.language, a.recurrence_group,' . 'a.recurrence_type, a.recurrence_first_id'));
             $query->from('#__jem_events AS a');
             // Join on user table.
             $name = $settings->get('global_regname', '1') ? 'u.name' : 'u.username';
             $query->select(array($name . ' AS author', 'u.name', 'u.username'));
             $query->join('LEFT', '#__users AS u on u.id = a.created_by');
             // Join on contact-user table.
             $query->select('con.id AS conid, con.name AS conname, con.telephone AS contelephone, con.email_to AS conemail');
             $query->join('LEFT', '#__contact_details AS con ON con.id = a.contactid');
             // Join on venue table.
             $query->select('l.custom1 AS venue1, l.custom2 AS venue2, l.custom3 AS venue3, l.custom4 AS venue4, l.custom5 AS venue5, l.custom6 AS venue6, l.custom7 AS venue7, l.custom8 AS venue8, l.custom9 AS venue9, l.custom10 AS venue10, ' . 'l.id AS locid, l.alias AS localias, l.venue, l.city, l.state, l.url, l.locdescription, l.locimage, l.city, l.postalCode, l.street, l.country,l.phone,l.fax,l.email,l.map, l.created_by AS venueowner, l.latitude, l.longitude, l.timezone, l.checked_out AS vChecked_out, l.checked_out_time AS vChecked_out_time');
             $query->join('LEFT', '#__jem_venues AS l ON a.locid = l.id');
             # join over the category-tables
             $query->join('LEFT', '#__jem_cats_event_relations AS rel ON rel.itemid = a.id');
             $query->join('LEFT', '#__jem_categories AS c ON c.id = rel.catid');
             // Filter by language
             /* commented out yet because it's incomplete
             			if ($this->getState('filter.language')) {
             				$query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
             			}
             			*/
             $query->where('a.id = ' . (int) $pk);
             // Filter by start and end dates.
             $nullDate = $db->Quote($db->getNullDate());
             $date = JFactory::getDate();
             $nowDate = $db->Quote($date->toSql());
             // Filter by published state.
             $published = $this->getState('filter.published');
             $archived = $this->getState('filter.archived');
             if (is_numeric($published)) {
                 $query->where('(a.published = ' . (int) $published . ' OR a.published =' . (int) $archived . ')');
             }
             #####################
             ### FILTER - BYCAT ##
             #####################
             $cats = $this->getCategories('all');
             $query->where('c.id  IN (' . implode(',', $cats) . ')');
             //$query->group('a.id');
             $db->setQuery($query);
             $data = $db->loadObject();
             if ($error = $db->getErrorMsg()) {
                 throw new Exception($error);
             }
             if (empty($data)) {
                 throw new Exception(JText::_('COM_JEM_EVENT_ERROR_EVENT_NOT_FOUND'), 404);
             }
             // Convert parameter fields to objects.
             $registry = new JRegistry();
             $registry->loadString($data->attribs);
             $globalattribs = JEMHelper::globalattribs();
             $globalregistry = new JRegistry();
             $globalregistry->loadString($globalattribs);
             $data->params = clone $globalregistry;
             $data->params->merge($registry);
             $registry = new JRegistry();
             $registry->loadString($data->metadata);
             $data->metadata = $registry;
             // Compute selected asset permissions.
             $user = JFactory::getUser();
             // Technically guest could edit an event, but lets not check
             // that to improve performance a little.
             if (!$user->get('guest')) {
                 $userId = $user->get('id');
                 $asset = 'com_jem.event.' . $data->id;
                 // Check general edit permission first.
                 if ($user->authorise('core.edit', $asset)) {
                     $data->params->set('access-edit', true);
                 } elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) {
                     // Check for a valid user and that they are the owner.
                     if ($userId == $data->created_by) {
                         $data->params->set('access-edit', true);
                     }
                 }
             }
             // Compute view access permissions.
             if ($access = $this->getState('filter.access')) {
                 // If the access filter has been set, we already know this
                 // user can view.
                 $data->params->set('access-view', true);
             } else {
                 # retrieve category's that the user is able to see
                 # if there is no category the event should not be displayed
                 $user = JFactory::getUser();
                 $groups = $user->getAuthorisedViewLevels();
                 $category_viewable = $this->getCategories($pk);
                 if ($category_viewable) {
                     $data->params->set('access-view', true);
                 }
             }
             $this->_item[$pk] = $data;
         } catch (JException $e) {
             if ($e->getCode() == 404) {
                 // Need to go thru the error handler to allow Redirect to work.
                 JError::raiseError(404, $e->getMessage());
                 return false;
             } else {
                 $this->setError($e);
                 $this->_item[$pk] = false;
                 return false;
             }
         }
     }
     // Define Attachments
     $user = JFactory::getUser();
     $this->_item[$pk]->attachments = JEMAttachment::getAttachments('event' . $this->_item[$pk]->did);
     // Define Venue-Attachments
     $this->_item[$pk]->vattachments = JEMAttachment::getAttachments('venue' . $this->_item[$pk]->locid);
     // Define Booked
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $query->select(array('COUNT(*)'));
     $query->from('#__jem_register');
     $query->where(array('event= ' . $db->quote($this->_item[$pk]->did), 'waiting= 0'));
     $db->setQuery($query);
     $res = $db->loadResult();
     $this->_item[$pk]->booked = $res;
     // Define Waiters
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $query->select(array('COUNT(*)'));
     $query->from('#__jem_register');
     $query->where(array('event= ' . $db->quote($this->_item[$pk]->did), 'waiting= 1'));
     $db->setQuery($query);
     $res2 = $db->loadResult();
     $this->_item[$pk]->waiters = $res2;
     return $this->_item[$pk];
 }
Exemple #6
0
	/**
	 * Method to save the form data.
	 *
	 * @param $data array
	 */
	public function save($data)
	{
		// Variables
		$date        = JFactory::getDate();
		$app         = JFactory::getApplication();
		$jinput      = $app->input;
		$user        = JemFactory::getUser();
		$jemsettings = JEMHelper::config();
		$fileFilter  = new JInput($_FILES);
		$table       = $this->getTable();
		$task        = $jinput->get('task', '', 'cmd');

		// Check if we're in the front or back
		if ($app->isAdmin())
			$backend = true;
		else
			$backend = false;

		// Store IP of author only.
		if (!$data['id']) {
			$author_ip = $jinput->get('author_ip', '', 'string');
			$data['author_ip'] = $author_ip;
		}

		// Store as copy - reset creation date, modification fields, hit counter, version
		if ($task == 'save2copy') {
			unset($data['created']);
			unset($data['modified']);
			unset($data['modified_by']);
			unset($data['version']);
		//	unset($data['hits']);
		}

		//uppercase needed by mapservices
		if ($data['country']) {
			$data['country'] = JString::strtoupper($data['country']);
		}

		if (parent::save($data)){
			// At this point we do have an id.
			$pk = $this->getState($this->getName() . '.id');

			// attachments, new ones first
			$attachments 				= array();
			$attachments 				= $fileFilter->get('attach', array(), 'array');
			$attachments['customname']	= $jinput->post->get('attach-name', array(), 'array');
			$attachments['description'] = $jinput->post->get('attach-desc', array(), 'array');
			$attachments['access'] 		= $jinput->post->get('attach-access', array(), 'array');
			JEMAttachment::postUpload($attachments, 'venue' . $pk);

			// and update old ones
			$old				= array();
			$old['id'] 			= $jinput->post->get('attached-id', array(), 'array');
			$old['name'] 		= $jinput->post->get('attached-name', array(), 'array');
			$old['description'] = $jinput->post->get('attached-desc', array(), 'array');
			$old['access'] 		= $jinput->post->get('attached-access', array(), 'array');

			foreach ($old['id'] as $k => $id){
				$attach 				= array();
				$attach['id'] 			= $id;
				$attach['name'] 		= $old['name'][$k];
				$attach['description'] 	= $old['description'][$k];
				$attach['access'] 		= $old['access'][$k];
				JEMAttachment::update($attach);
			}

			return true;
		}

		return false;
	}
Exemple #7
0
 /**
  * Method to get event data.
  *
  * @param integer	The id of the event.
  *
  * @return mixed item data object on success, false on failure.
  */
 public function getItem($itemId = null)
 {
     $jemsettings = JemHelper::config();
     // Initialise variables.
     $itemId = (int) (!empty($itemId)) ? $itemId : $this->getState('event.id');
     // Get a row instance.
     $table = $this->getTable();
     // Attempt to load the row.
     $return = $table->load($itemId);
     // Check for a table object error.
     if ($return === false && $table->getError()) {
         $this->setError($table->getError());
         return false;
     }
     $properties = $table->getProperties(1);
     $value = JArrayHelper::toObject($properties, 'JObject');
     // Convert attrib field to Registry.
     $registry = new JRegistry();
     $registry->loadString($value->attribs);
     $globalsettings = JEMHelper::globalattribs();
     $globalregistry = new JRegistry();
     $globalregistry->loadString($globalsettings);
     $value->params = clone $globalregistry;
     $value->params->merge($registry);
     // Compute selected asset permissions.
     $user = JFactory::getUser();
     $userId = $user->get('id');
     //$asset = 'com_jem.event.' . $value->id;
     $asset = 'com_jem';
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select(array('count(id)'));
     $query->from('#__jem_register');
     $query->where(array('event= ' . $db->quote($itemId), 'waiting= 0'));
     $db->setQuery($query);
     $res = $db->loadResult();
     $value->booked = $res;
     $files = JEMAttachment::getAttachments('event' . $itemId);
     $value->attachments = $files;
     ################
     ## RECURRENCE ##
     ################
     # check recurrence
     if ($value->recurrence_group) {
         # this event is part of a recurrence-group
         #
         # check for groupid & groupid_ref (recurrence_table)
         # - groupid		= $item->recurrence_group
         # - groupid_ref	= $item->recurrence_group
         # - Itemid		= $item->id
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select(array('count(id)'));
         $query->from('#__jem_recurrence');
         $query->where(array('groupid= ' . $value->recurrence_group, 'itemid= ' . $value->id, 'groupid = groupid_ref'));
         $db->setQuery($query);
         $rec_groupset_check = $db->loadResult();
         if ($rec_groupset_check == '1') {
             $value->recurrence_groupcheck = true;
         } else {
             $value->recurrence_groupcheck = false;
         }
     } else {
         $value->recurrence_groupcheck = false;
     }
     ##############
     ## HOLIDAYS ##
     ##############
     # Retrieve dates that are holidays and enabled.
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('holiday');
     $query->from('#__jem_dates');
     $query->where(array('enabled = 1', 'holiday = 1'));
     $db->setQuery($query);
     $holidays = $db->loadColumn();
     if ($holidays) {
         $value->recurrence_country_holidays = true;
     } else {
         $value->recurrence_country_holidays = false;
     }
     // Check general edit permission first.
     if ($user->authorise('core.edit', $asset)) {
         $value->params->set('access-edit', true);
     } elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) {
         // Check for a valid user and that they are the owner.
         if ($userId == $value->created_by) {
             $value->params->set('access-edit', true);
         }
     }
     // Check edit state permission.
     if ($itemId) {
         // Existing item
         $value->params->set('access-change', $user->authorise('core.edit.state', $asset));
     } else {
         // New item.
         $catId = (int) $this->getState('event.catid');
         if ($catId) {
             $value->params->set('access-change', $user->authorise('core.edit.state', 'com_jem.category.' . $catId));
             $value->catid = $catId;
         } else {
             $access_change = $user->authorise('core.edit.state', 'com_jem');
             $value->params->set('access-change', $access_change);
         }
     }
     $value->author_ip = $jemsettings->storeip ? JemHelper::retrieveIP() : false;
     $value->articletext = $value->introtext;
     if (!empty($value->fulltext)) {
         $value->articletext .= '<hr id="system-readmore" />' . $value->fulltext;
     }
     if (!empty($value->datimage)) {
         if (strpos($value->datimage, 'images/') !== false) {
             # the image selected contains the images path
         } else {
             # the image selected doesn't have the /images/ path
             # we're looking at the locimage so we'll append the venues folder
             $value->datimage = 'images/jem/events/' . $value->datimage;
         }
     }
     $admin = JFactory::getUser()->authorise('core.manage', 'com_jem');
     if ($admin) {
         $value->admin = true;
     } else {
         $value->admin = false;
     }
     return $value;
 }
Exemple #8
0
	/**
	 * Method to get a specific Venue
	 *
	 * @access public
	 * @return array
	 */
	function getVenue()
	{
		$user  = JemFactory::getUser();

		$db    = JFactory::getDbo();
		$query = $db->getQuery(true);
		$_venue = array();

		$query->select('id, venue, published, city, state, url, street, custom1, custom2, custom3, custom4, custom5, '.
				' custom6, custom7, custom8, custom9, custom10, locimage, meta_keywords, meta_description, '.
				' created, created_by, locdescription, country, map, latitude, longitude, postalCode, checked_out AS vChecked_out, checked_out_time AS vChecked_out_time, '.
				' CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(\':\', id, alias) ELSE id END as slug');
		$query->from($db->quoteName('#__jem_venues'));
		$query->where('id = '.(int)$this->_id);

		// all together: if published or the user is creator of the venue or allowed to edit or publish venues
		if (empty($user->id)) {
			$query->where('published = 1');
		}
		// no limit if user can publish or edit foreign venues
		elseif ($user->can(array('edit', 'publish'), 'venue')) {
			$query->where('published IN (0,1)');
		}
		// user maybe creator
		else {
			$query->where('(published = 1 OR (published = 0 AND created_by = ' . $this->_db->Quote($user->id) . '))');
		}

		$db->setQuery($query);
		$_venue = $db->loadObject();

		if (empty($_venue)) {
			//return JError::raiseError(404, JText::_('COM_JEM_VENUE_NOTFOUND'));
			$this->setError(JText::_('COM_JEM_VENUE_ERROR_VENUE_NOT_FOUND'));
			return false;
		}

		$_venue->attachments = JEMAttachment::getAttachments('venue'.$_venue->id);

		return $_venue;
	}
Exemple #9
0
	/**
	 * Method to get event data.
	 *
	 * @param integer	The id of the event.
	 * @return mixed item data object on success, false on failure.
	 */
	public function &getItem($pk = null)
	{
		// Initialise variables.
		$pk = (!empty($pk)) ? $pk : (int) $this->getState('event.id');
		$user = JemFactory::getUser();

		if ($this->_item === null) {
			$this->_item = array();
		}

		if (!isset($this->_item[$pk])) {

			try {
				$settings = JEMHelper::globalattribs();

				$db = $this->getDbo();
				$query = $db->getQuery(true);

				$query->select(
						$this->getState('item.select',
								'a.id, a.access, a.attribs, a.metadata, a.registra, a.custom1, a.custom2, a.custom3, a.custom4, a.custom5, a.custom6, a.custom7, a.custom8, a.custom9, a.custom10, a.times, a.endtimes, a.dates, a.enddates, a.id AS did, a.title, a.alias, ' .
										'a.created, a.unregistra, a.published, a.created_by, ' .
										'CASE WHEN a.modified = 0 THEN a.created ELSE a.modified END as modified, ' . 'a.modified_by, a.checked_out, a.checked_out_time, ' . 'a.datimage,  a.version, ' .
										'a.meta_keywords, a.created_by_alias, a.introtext, a.fulltext, a.maxplaces, a.waitinglist, a.meta_description, a.hits, a.language, ' .
										'a.recurrence_type, a.recurrence_first_id'));
				$query->from('#__jem_events AS a');

				// Join on user table.
				$name = $settings->get('global_regname','1') ? 'u.name' : 'u.username';
				$query->select($name.' AS author');
				$query->join('LEFT', '#__users AS u on u.id = a.created_by');

				// Join on contact-user table.
				$query->select('con.id AS conid, con.name AS conname, con.telephone AS contelephone, con.email_to AS conemail');
				$query->join('LEFT', '#__contact_details AS con ON con.id = a.contactid');

				// Join on venue table.
				$query->select('l.custom1 AS venue1, l.custom2 AS venue2, l.custom3 AS venue3, l.custom4 AS venue4, l.custom5 AS venue5, l.custom6 AS venue6, l.custom7 AS venue7, l.custom8 AS venue8, l.custom9 AS venue9, l.custom10 AS venue10, ' .
				               'l.id AS locid, l.alias AS localias, l.venue, l.city, l.state, l.url, l.locdescription, l.locimage, l.city, l.postalCode, l.street, l.country, l.map, l.created_by AS venueowner, l.latitude, l.longitude, l.checked_out AS vChecked_out, l.checked_out_time AS vChecked_out_time');
				$query->join('LEFT', '#__jem_venues AS l ON a.locid = l.id');

				# join over the category-tables
				$query->join('LEFT', '#__jem_cats_event_relations AS rel ON rel.itemid = a.id');
				$query->join('LEFT', '#__jem_categories AS c ON c.id = rel.catid');

				// Get contact id
				$subQuery = $db->getQuery(true);
				$subQuery->select('MAX(contact.id) AS id');
				$subQuery->from('#__contact_details AS contact');
				$subQuery->where('contact.published = 1');
				$subQuery->where('contact.user_id = a.created_by');

				// Filter by language
				if ($this->getState('filter.language')) {
					$subQuery->where('(contact.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ') OR contact.language IS NULL)');
				}

				$query->select('(' . $subQuery . ') as contactid2');

				// Filter by language
				/* commented out yet because it's incomplete
				if ($this->getState('filter.language')) {
					$query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
				}
				*/

				$query->where('a.id = ' . (int) $pk);

				// Filter by start and end dates.
				$nullDate = $db->Quote($db->getNullDate());
				$date = JFactory::getDate();

				$nowDate = $db->Quote($date->toSql());


				// Filter by published state ==> later.
				//  It would result in too complicated query.
				//  It's easier to get data and check then e.g. for event owner etc.


				#####################
				### FILTER - BYCAT ##
				#####################

				$cats = $this->getCategories('all');
				if (!empty($cats)) {
					$query->where('c.id  IN (' . implode(',', $cats) . ')');
				}

				//$query->group('a.id');
				$db->setQuery($query);
				$data = $db->loadObject();

				if ($error = $db->getErrorMsg()) {
					throw new Exception($error);
				}

				if (empty($data)) {
					throw new Exception(JText::_('COM_JEM_EVENT_ERROR_EVENT_NOT_FOUND'), 404);
				}

				// Convert parameter fields to objects.
				$registry = new JRegistry;
				$registry->loadString($data->attribs);

				$data->params = JEMHelper::globalattribs(); // returns JRegistry object
				$data->params->merge($registry);

				$registry = new JRegistry;
				$registry->loadString($data->metadata);
				$data->metadata = $registry;

				$data->categories = $this->getCategories($pk);

				// Compute selected asset permissions.
				$viewLevels  = $user->getAuthorisedViewLevels();

				$access_edit = $user->can('edit', 'event', $data->id, $data->created_by);
				$access_view = (($data->published == 1) || ($data->published == 2) ||          // published and archived event
				                (($data->published == 0) && $access_edit) ||                   // unpublished for editors,
				                $user->can('publish', 'event', $data->id, $data->created_by)); // all for publishers

				$data->params->set('access-edit', $access_edit);

				// Compute view access permissions.

				# event can be shown if
				#  - user has matching view access level and
				#  - there is at least one category attached user can see and
				#  - publishing state and user permissions allow that (e.g. unpublished event but user is editor, owner, or publisher)
				$data->params->set('access-view', $access_view && !empty($data->categories) && in_array($data->access, $viewLevels));

				$this->_item[$pk] = $data;
			}
			catch (JException $e) {
				if ($e->getCode() == 404) {
					// Need to go thru the error handler to allow Redirect to
					// work.
					JError::raiseError(404, $e->getMessage());
					return false;
				}
				else {
					$this->setError($e);
					$this->_item[$pk] = false;
					return false;
				}
			}
		}

		// Define Attachments
		$this->_item[$pk]->attachments = JEMAttachment::getAttachments('event' . $this->_item[$pk]->did);

		// Define Venue-Attachments
		$this->_item[$pk]->vattachments = JEMAttachment::getAttachments('venue' . $this->_item[$pk]->locid);

		// Define Booked
		$db = $this->getDbo();
		$query = $db->getQuery(true);
		$query->select(array('COUNT(*)'));
		$query->from('#__jem_register');
		$query->where(array(
				'event= ' . $db->quote($this->_item[$pk]->did),
				'waiting= 0'
		));
		$db->setQuery($query);
		$res = $db->loadResult();
		$this->_item[$pk]->booked = $res;


		return $this->_item[$pk];
	}
Exemple #10
0
 /**
  * Method to save the form data.
  *
  * @param $data array
  */
 public function save($data)
 {
     $date = JFactory::getDate();
     $app = JFactory::getApplication();
     $jinput = $app->input;
     $user = JFactory::getUser();
     $jemsettings = JEMHelper::config();
     $settings = JemHelper::globalattribs();
     $veditevent = JemHelper::viewSettings('veditevent');
     $fileFilter = new JInput($_FILES);
     $table = $this->getTable();
     # Check if we're in the front or back
     if ($app->isAdmin()) {
         $backend = true;
     } else {
         $backend = false;
     }
     $cats = $data['cats'];
     $data['author_ip'] = $jinput->getString('author_ip');
     ## Recurrence - check option ##
     # if the option to hide the recurrence/other tab has been set (front) then
     # we should ignore the recurrence variables.
     $option_othertab = $veditevent->get('editevent_show_othertab');
     if ($option_othertab) {
         $hide_othertab = false;
     } else {
         $hide_othertab = true;
     }
     if ($backend || $hide_othertab == false) {
         ##############
         ## HOLIDAYS ##
         ##############
         if (isset($data['activated'])) {
             if ($data['activated'] == null) {
                 $holidays = array();
             } else {
                 $holidays = $data['activated'];
             }
         } else {
             $holidays = array();
         }
         $countryholiday = $jinput->getInt('recurrence_country_holidays', '');
         ################
         ## RECURRENCE ##
         ################
         # check if a startdate has been set
         if (isset($data['dates'])) {
             if ($data['dates'] == null) {
                 $dateSet = false;
             } else {
                 $dateSet = true;
             }
         } else {
             $dateSet = false;
         }
         if (!isset($data['recurrence_freq'])) {
             $data['recurrence_freq'] = 0;
         }
         # implode weekday values
         # @todo implement check to see if days have been selected in case of freq week
         if (isset($data['recurrence_weekday'])) {
             $data['recurrence_weekday'] = implode(',', $data['recurrence_weekday']);
         }
         # blank recurrence-fields
         #
         # if we don't have a startdate or a recurrence-type then
         # the recurrence-fields within the event-table will be blanked.
         #
         # but the recurrence_group field will stay filled as it's not removed by the user.
         if (empty($data['dates']) || $data['recurrence_freq'] == '0') {
             $data['recurrence_count'] = '';
             $data['recurrence_freq'] = '';
             $data['recurrence_interval'] = '';
             $data['recurrence_until'] = '';
             $data['recurrence_weekday'] = '';
             $data['recurrence_exdates'] = '';
         }
         # the exdates are not stored in the event-table but they are trown in an variable
         if (isset($data['recurrence_exdates'])) {
             $exdates = $data['recurrence_exdates'];
         } else {
             $exdates = false;
         }
     }
     # parent-Save
     if (parent::save($data)) {
         // At this point we do have an id.
         $pk = $this->getState($this->getName() . '.id');
         if (isset($data['featured'])) {
             $this->featured($pk, $data['featured']);
         }
         $checkAttachName = $jinput->post->get('attach-name', '', 'array');
         if ($checkAttachName) {
             # attachments, new ones first
             $attachments = array();
             $attachments = $fileFilter->get('attach', array(), 'array');
             $attachments['customname'] = $jinput->post->get('attach-name', array(), 'array');
             $attachments['description'] = $jinput->post->get('attach-desc', array(), 'array');
             $attachments['access'] = $jinput->post->get('attach-access', array(), 'array');
             JEMAttachment::postUpload($attachments, 'event' . $pk);
             # and update old ones
             $old = array();
             $old['id'] = $jinput->post->get('attached-id', array(), 'array');
             $old['name'] = $jinput->post->get('attached-name', array(), 'array');
             $old['description'] = $jinput->post->get('attached-desc', array(), 'array');
             $old['access'] = $jinput->post->get('attached-access', array(), 'array');
             foreach ($old['id'] as $k => $id) {
                 $attach = array();
                 $attach['id'] = $id;
                 $attach['name'] = $old['name'][$k];
                 $attach['description'] = $old['description'][$k];
                 $attach['access'] = $old['access'][$k];
                 JEMAttachment::update($attach);
             }
         }
         # Store categories
         $cats = $data['cats'];
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->delete($db->quoteName('#__jem_cats_event_relations'));
         $query->where('itemid = ' . $pk);
         $db->setQuery($query);
         $db->execute();
         foreach ($cats as $cat) {
             $db = $this->getDbo();
             $query = $db->getQuery(true);
             // Insert columns.
             $columns = array('catid', 'itemid');
             // Insert values.
             $values = array($cat, $pk);
             // Prepare the insert query.
             $query->insert($db->quoteName('#__jem_cats_event_relations'))->columns($db->quoteName($columns))->values(implode(',', $values));
             // Reset the query using our newly populated query object.
             $db->setQuery($query);
             $db->execute();
         }
         if ($backend || $hide_othertab == false) {
             # check for recurrence
             # when part of a recurrence_set it will not perform the generating function
             /*
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('id');
             $query->from($db->quoteName('#__jem_recurrence'));
             $query->where(array('exdate IS NULL','itemid ='.$pk));
             $db->setQuery($query);
             $recurrence_set = $db->loadResult();
             */
             $table->load($pk);
             # check recurrence
             if ($table->recurrence_group) {
                 # this event is part of a recurrence-group
                 #
                 # check for groupid & groupid_ref (recurrence_table)
                 # - groupid		= $item->recurrence_group
                 # - groupid_ref	= $item->recurrence_group
                 # - Itemid		= $item->id
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->select(array('count(id)'));
                 $query->from('#__jem_recurrence');
                 $query->where(array('groupid= ' . $table->recurrence_group, 'itemid= ' . $pk, 'groupid = groupid_ref'));
                 $db->setQuery($query);
                 $rec_groupset_check = $db->loadResult();
                 if ($rec_groupset_check == '1') {
                     $recurrence_set = true;
                 } else {
                     $recurrence_set = false;
                 }
             } else {
                 $recurrence_set = false;
             }
             ## check values, pass check before we continue to generate additional events ##
             # - do we have an interval?
             # - does the event has a date?
             # - is the event part of a recurrenceset?
             if ($table->recurrence_interval > 0 && !$table->dates == null && $recurrence_set == null) {
                 # recurrence_interval is bigger then 0
                 # we do have a startdate
                 # the event is not part of a recurrence-set
                 # we passed the check but now we'll pass some variables to the generating functions
                 # exdates: the dates filled
                 # table: the row info
                 if ($this->state->task == 'apply' || $this->state->task == 'save') {
                     JemHelper::generate_events($table, $exdates, $holidays);
                 }
             }
         }
         return true;
     }
     return false;
 }
Exemple #11
0
	/**
	 * Method to save the form data.
	 *
	 * @param $data array
	 */
	public function save($data)
	{
		// Variables
		$date        = JFactory::getDate();
		$app         = JFactory::getApplication();
		$jinput      = $app->input;
		$jemsettings = JEMHelper::config();
		$fileFilter  = new JInput($_FILES);
		$table       = $this->getTable();

		// Check if we're in the front or back
		$backend = (bool)$app->isAdmin();
		$new     = (bool)empty($data['id']);

		// Variables
		$cats             = $jinput->get('cid', array(), 'array');
		$recurrencenumber = $jinput->get('recurrence_number', '', 'int');
		$recurrencebyday  = $jinput->get('recurrence_byday', '', 'string');
		$metakeywords     = $jinput->get('meta_keywords', '', '');
		$metadescription  = $jinput->get('meta_description', '', '');
		$task             = $jinput->get('task', '', 'cmd');

		// event maybe first of recurrence set -> dissolve complete set
		if (JemHelper::dissolve_recurrence($data['id'])) {
			$this->cleanCache();
		}

		if ($data['dates'] == null || $data['recurrence_type'] == '0')
		{
			$data['recurrence_number']		= '';
			$data['recurrence_byday']		= '';
			$data['recurrence_counter'] 	= '';
			$data['recurrence_type']		= '';
			$data['recurrence_limit']		= '';
			$data['recurrence_limit_date']	= '';
			$data['recurrence_first_id']	= '';
		} else {
			if (!$new) {
				// edited event maybe part of a recurrence set
				// -> drop event from set
				$data['recurrence_first_id']	= '';
				$data['recurrence_counter'] 	= '';
			}

			$data['recurrence_number']		= $recurrencenumber;
			$data['recurrence_byday']		= $recurrencebyday;
		}

		$data['meta_keywords'] 		= $metakeywords;
		$data['meta_description']	= $metadescription;

		// Store IP of author only.
		if ($new) {
			$author_ip = $jinput->get('author_ip', '', 'string');
			$data['author_ip'] = $author_ip;
		}

		// Store as copy - reset creation date, modification fields, hit counter, version
		if ($task == 'save2copy') {
			unset($data['created']);
			unset($data['modified']);
			unset($data['modified_by']);
			unset($data['version']);
			unset($data['hits']);
		}

		// Save the event
		$saved = parent::save($data);

		if ($saved) {
			// At this point we do have an id.
			$pk = $this->getState($this->getName() . '.id');

			if (isset($data['featured'])) {
				$this->featured($pk, $data['featured']);
			}

			// attachments, new ones first
			$attachments 				= array();
			$attachments 				= $fileFilter->get('attach', array(), 'array');
			$attachments['customname']	= $jinput->post->get('attach-name', array(), 'array');
			$attachments['description'] = $jinput->post->get('attach-desc', array(), 'array');
			$attachments['access'] 		= $jinput->post->get('attach-access', array(), 'array');
			JEMAttachment::postUpload($attachments, 'event' . $pk);

			// and update old ones
			$old				= array();
			$old['id'] 			= $jinput->post->get('attached-id', array(), 'array');
			$old['name'] 		= $jinput->post->get('attached-name', array(), 'array');
			$old['description'] = $jinput->post->get('attached-desc', array(), 'array');
			$old['access'] 		= $jinput->post->get('attached-access', array(), 'array');

			foreach ($old['id'] as $k => $id) {
				$attach 				= array();
				$attach['id'] 			= $id;
				$attach['name'] 		= $old['name'][$k];
				$attach['description'] 	= $old['description'][$k];
				$attach['access'] 		= $old['access'][$k];
				JEMAttachment::update($attach);
			}

			// Store cats
			$saved |= $this->_storeCategoriesSelected($pk, $cats, !$backend, $new);

			// check for recurrence
			// when filled it will perform the cleanup function
			$table->load($pk);
			if (($table->recurrence_number > 0) && ($table->dates != null)) {
				JEMHelper::cleanup(2); // 2 = force on save, needs special attention
			}
		}

		return $saved;
	}
Exemple #12
0
 /**
  * Method to save the form data.
  *
  * @param $data array
  */
 public function save($data)
 {
     // Variables
     $app = JFactory::getApplication();
     $date = JFactory::getDate();
     $jinput = $app->input;
     $user = JFactory::getUser();
     $fileFilter = new JInput($_FILES);
     $table = $this->getTable();
     // Check if we're in the front or back
     if ($app->isAdmin()) {
         $backend = true;
     } else {
         $backend = false;
     }
     // uppercase needed by mapservices
     if ($data['country']) {
         $data['country'] = JString::strtoupper($data['country']);
     }
     $data['author_ip'] = $jinput->getString('author_ip');
     if (parent::save($data)) {
         // At this point we do have an id.
         $pk = $this->getState($this->getName() . '.id');
         // attachments, new ones first
         $attachments = array();
         $attachments = $fileFilter->get('attach', array(), 'array');
         $attachments['customname'] = $jinput->post->get('attach-name', array(), 'array');
         $attachments['description'] = $jinput->post->get('attach-desc', array(), 'array');
         $attachments['access'] = $jinput->post->get('attach-access', array(), 'array');
         JEMAttachment::postUpload($attachments, 'venue' . $pk);
         // and update old ones
         $old = array();
         $old['id'] = $jinput->post->get('attached-id', array(), 'array');
         $old['name'] = $jinput->post->get('attached-name', array(), 'array');
         $old['description'] = $jinput->post->get('attached-desc', array(), 'array');
         $old['access'] = $jinput->post->get('attached-access', array(), 'array');
         foreach ($old['id'] as $k => $id) {
             $attach = array();
             $attach['id'] = $id;
             $attach['name'] = $old['name'][$k];
             $attach['description'] = $old['description'][$k];
             $attach['access'] = $old['access'][$k];
             JEMAttachment::update($attach);
         }
         return true;
     }
     return false;
 }