Your IP : 216.73.216.54


Current Path : /var/www/html/components/com_jvld/models/
Upload File :
Current File : /var/www/html/components/com_jvld/models/editprofile.php

<?php
/**
 * @version		$Id$
 * @package		JV-LinkDirectory
 * @subpackage	com_jvld
 * @copyright	Copyright 2008-2013 JV-Extensions. All rights reserved
 * @license		GNU General Public License version 3 or later
 * @author		JV-Extensions
 * @link		http://www.jv-extensions.com
 */

// No direct access
defined('_JEXEC') or die('Restricted access');

class JvldModelEditprofile extends JvldFendModel
{
	public function getForm($data = array(), $loadData = true)
	{
		$form = $this->loadForm('com_jvld.editprofile', 'editprofile', array('control' => 'jform', 'load_data' => $loadData), true);
		if (empty($form))
			return false;

		return $form;
	}

	public function getItem()
	{
		$lid = JFactory::getApplication()->input->getInt('lid', 0);
		$id = JFactory::getApplication()->input->getInt('id', 0);

		if ($id)
			return JvldDb::getRow("select * from #__jvld_linkprof where id = ".(int)$id." and lid = ".(int)$lid);
		else
			return null;
	}

	protected function loadFormData()
	{
		$item = $this->getItem();
		if ($item)
		{
		}

		return $item;
	}

	public function process()
	{
		try
		{
			parent::preProcess();

			if (!$this->lid)
				throw new Exception(JText::_('COM_JVLD_ERR_INVALID_REQ'));

			$this->title = \Joomla\String\StringHelper::trim($this->title);

			if ($this->title == '')
				throw new Exception(JText::_("COM_JVLD_LINKS_ADD_TP_TITLE_MISSING"));

			if (\Joomla\String\StringHelper::strlen($this->title) > $this->cfg->get('prof_title_maxchar'))
				throw new Exception(JText::sprintf("COM_JVLD_LINKS_ADD_TP_TITLELEN_EXCEEDS", $this->cfg->get('prof_title_maxchar')));

			if (in_array($this->cfg->get('prof_desc_require'), array(_JVLD_LISTING_PROF_REQUIRED, _JVLD_LISTING_PROF_OPTIONAL)))
			{
				if (($this->cfg->get('prof_desc_require') == _JVLD_LISTING_PROF_REQUIRED) && ($this->description == ''))
					throw new Exception(JText::_("COM_JVLD_LINKS_ADD_TP_DESC_MISSING"));
			}
			else
			{
				$this->description = '';
			}

			if ($this->id)
			{
				$erec = JvldDb::getRow("select * from #__jvld_linkprof where id = ".(int)$this->id);
			}
			else
			{
				// check profile cnt
				$profcntarr = JvldPostinit::getProfileCounts($this->lid);
				if ($profcntarr['cnt'] >= $profcntarr['maxcnt'])
					throw new Exception(JText::_('COM_JVLD_LINKS_ADDPROFILE_EXHAUSTED'));
			}

			$this->banner = '';
			if (in_array($this->cfg->get('prof_banner_require'), array(_JVLD_LISTING_PROF_REQUIRED, _JVLD_LISTING_PROF_OPTIONAL)))
			{
				$banner_del = JvldUtil::getJFormVariableValue('banner_del', 0, 'int');
				$up_banner  = JvldFileManager::upload("banner", _JVLD_PROFBANNERS_ABSPATH, array('allowed_extns' => $this->cfg->get('prof_banner_allowextns'), 'width' => $this->cfg->get('prof_banner_maxwpix'), 'height' => $this->cfg->get('prof_banner_maxhpix'), 'maxsize' => $this->cfg->get('prof_banner_maxsize'), 'genprefix' => 1, 'err_on_nofileupload' => 0));
				if ($up_banner != '')
				{
					$this->banner = $up_banner;
				}
				else
				{
					if ($banner_del)
					{
						$this->banner = '';
					}
					else
					{
						$this->banner = ($this->id) ? $erec->banner : '';
					}
				}

				if (($this->cfg->get('prof_banner_require') == _JVLD_LISTING_PROF_REQUIRED) && ($this->banner == ''))
					throw new Exception(JText::_("COM_JVLD_LINKS_PROFILE_BANNER_MISSING"));
			}

			if (!$this->id) // new profile
			{
				// create profile
				$prof_id = JvldDb::update("insert into #__jvld_linkprof (lid, title, description, banner) values('".(int)$this->lid."', '".JvldSecure::defendSQL($this->title)."', '".JvldSecure::defendSQL($this->description)."', '".JvldSecure::defendSQL($this->banner)."')");

				JvldInit::triggerPlugins('OnNewLinkProfile', array($this->lid, $prof_id));
			}
			else
			{
				// update profile
				JvldDb::update("update #__jvld_linkprof set title = '".JvldSecure::defendSQL($this->title)."', description = '".JvldSecure::defendSQL($this->description)."', banner = '".JvldSecure::defendSQL($this->banner)."' where id = ".(int)$this->id);
			}

			// update title in links
			JvldDb::update("update #__jvld_links set partner_title = '".JvldSecure::defendSQL($this->title)."', link_updated_on = '".JvldDate::getDateTimeInUTCInMySqlFormat()."' where id = ".(int)$this->lid);

			$msg = ($this->id) ? JText::_('COM_JVLD_PROFILE_OK_EDIT') : JText::_('COM_JVLD_PROFILE_OK_ADD');

			JvldMsg::display($msg, _JVLD_NEXT_PAGE_GO_TO_RETURN_URL);
			return;
		}
		catch (Exception $ex)
		{
			JvldMsg::display($ex->getMessage(), _JVLD_NEXT_PAGE_GO_BACK);
			return;
		}
	}
}