<?php

defined( '_JEXEC' ) or die( 'Restricted access' );
require_once(JPATH_ADMINISTRATOR.'/components/com_jxplorer'.DS.'xajax'.DS.'xajax_core'.DS.'xajax.inc.php' );
function jxShowUploadForm()
{
    $objResponse = new xajaxResponse();
    ob_start();
    include "components/com_jxplorer/tmpl/uploadform.html.php";
    $form = ob_get_clean();
    
    
    
    $objResponse->assign('prop_form', "innerHTML", $form);
    $objResponse->script("jxShowForm();");
    return $objResponse;
}
function jxProcessFavorit($id)
{
    global $mainframe;
    $objResponse = new xajaxResponse();
    $db = & JFactory::getDBO();
    $user = & JFactory::getUser();
    if(!$user->get('id'))
    {
        $objResponse->alert(jcText::_('You need to be loged in to use Favorite feature.'));
        return $objResponse;
    }
    $sql = "SELECT id FROM #__jx_favorites WHERE file_id = $id AND user_id = ".$user->get('id');
    $db->setQuery($sql);
    $res = $db->loadResult();
    
    if($res)
    {
        $pic = 'favor0.png';
        $sql = "DELETE FROM #__jx_favorites WHERE id = $res";
        $db->setQuery($sql);
        $db->query();
    }
    else
    {
        $pic = 'favor.png';
        $sql = "INSERT INTO #__jx_favorites VALUES(NULL, '".$user->get('id')."', '$id', NOW())";
        $db->setQuery($sql);
        $db->query();
    }
    $img = JURI::root(true).'/components/com_jxplorer/tmpl/images/'.$pic;
    $objResponse->assign('favor_'.$id, "src", $img);
    return $objResponse;
}

$xajax = new xajax(JURI::root(true).'/index.php?option=com_jxplorer&no_html=1'); 

$xajax->registerFunction("jxShowUploadForm");
$xajax->registerFunction("jxProcessFavorit");

$xajax->processRequest();
$xajax->printJavascript('administrator/components/com_jxplorer/js/');
?>