| Current Path : /var/www/html/components/com_jvld/models/ |
| Current File : /var/www/html/components/com_jvld/models/profiles.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');
jimport('joomla.application.component.modellist');
class JvldModelProfiles extends JModelList
{
protected function getListQuery()
{
$lid = JFactory::getApplication()->input->getInt('lid', 0);
return "select * from #__jvld_linkprof where lid = ".(int)$lid;
}
public function getCurrentPageNumber()
{
if ($this->getLimit() == 0)
return 0;
return ($this->getStart()/$this->getLimit()) + 1;
}
public function getStart()
{
return $this->getState('list.start');
}
public function getLimit()
{
return $this->getState('list.limit');
}
protected function getStoreId($id = '')
{
return parent::getStoreId($id);
}
protected function populateState($ordering = null, $direction = null)
{
$app = JFactory::getApplication();
$start_value = $app->input->get('limitstart', 0, 'int');
$this->setState('list.start', $start_value);
$limit_value = $app->input->get('limit', intval($app->get('list_limit', 0)), 'uint');
$this->setState('list.limit', $limit_value);
}
public function deleteProfile()
{
try
{
$id = JFactory::getApplication()->input->getInt('id', 0);
if (!$id)
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
// Get link info
$prof = JvldDb::getRow("select * from #__jvld_linkprof where id = '".(int)$id."'");
if (!$prof)
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
// Get link ID
$lid = $prof->lid;
// Get link info
$link = new JvldLinkinfo($lid);
if (!$link->isValid())
throw new Exception(JText::_("COM_JVLD_ERR_INVALID_REQ"));
// Am i the owner?
if ($link->getInfo('uid') != JFactory::getUser()->get('id'))
throw new Exception(JText::_("COM_JVLD_UNAUTHORIZED"));
// Is this the only profile for this link?
$cnt = JvldDb::getCount("select count(id) as CNT from #__jvld_linkprof where lid = '".(int)$lid."'");
if ($cnt == 1)
throw new Exception(JText::_("COM_JVLD_PROFILE_ONLY_ONE"));
// Update
JvldDb::update("delete from #__jvld_linkprof where id = '".(int)$id."'");
JvldDb::update("update #__jvld_links set partner_title = (select title from #__jvld_linkprof where lid = '".(int)$lid."' limit 0, 1) where id = '".(int)$lid."'");
JvldMsg::display(JText::_("COM_JVLD_DELPROFILE_DONE"), _JVLD_NEXT_PAGE_GO_TO_URL, JvldPostinit::getRoute('profiles', $lid));
return;
}
catch (Exception $ex)
{
JvldMsg::display($ex->getMessage(), _JVLD_NEXT_PAGE_GO_BACK);
return;
}
}
}