<?php

/**
 * @name          : Joomla Social Pinboard
 ** @version	  : 2.0
 * @package       : apptha
 * @since         : Joomla 1.5
 * @author        : Apptha - http://www.apptha.com
 * @copyright     : Copyright (C) 2011 Powered by Apptha
 * @license       : http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
 * @abstract      : Social Pinboard Component ajaxcontroller file
 * @Creation Date : March 2013
 * @Modified Date : March 2013
 * */
// No direct Access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller');

class wishlogueControllerajaxcontrol extends WishlogueController {

    /**
     * Method to display the view
     */
    function display($cachable = false, $urlparams = false) {
        //get user id for logincheck
        parent::display();
    }

	///rgs.

	function subcatalogueList() {
		$model = $this->getModel('wishitdisplay');
        $catId = JRequest::getVar('catId');
		$result = $model->subcatalogueList($catId);
        echo json_encode($result);
        die;
	}

	function getPageTitle() {
		$model = $this->getModel('wishitdisplay');
        $Url = JRequest::getVar('url');
		$result = $model->getPageTitle($Url);
        echo $result;
        die;
	}

	function checkCatalogueExistance() {
		$model = $this->getModel('cataloguedisplay');
        $catId = JRequest::getVar('catId');
        $subCat = JRequest::getVar('subCat');
		$result = $model->checkCatalogueExistance($catId, $subCat);
        echo $result;
        die;
	}

    function getArticlesRSS() {
		$model = $this->getModel('home');
        $result = $model->getArticlesRSS();
        echo $result;
        die;
    }

	function getWishesRSS() {
		$model = $this->getModel('home');
        $result = $model->getWishesRSS();
        echo $result;
        die;
    }

	function removeFromNotifications() {
		$notifyID = JRequest::getVar('notifyID');

		$model = $this->getModel('notifications');
        $result = $model->removeFromNotifications($notifyID);
        echo $result;
        die;
    }

	function acceptGrantedWish() {
        $pinId = JRequest::getVar('wishID');
		$memberId = JRequest::getVar('memberID');

		$model = $this->getModel('wish');
        $result = $model->acceptGrantedWish($pinId, $memberId);
        echo $result;
        die;
    }

	function declineGrantedWish() {
        $pinId = JRequest::getVar('wishID');
		$memberId = JRequest::getVar('memberID');

		$model = $this->getModel('wish');
        $result = $model->declineGrantedWish($pinId, $memberId);
        echo $result;
        die;
    }

	function anonymouslyGrantedWish() {
        $pinId = JRequest::getVar('wishID');

		$model = $this->getModel('wish');
        $result = $model->anonymouslyGrantedWish($pinId);
        echo $result;
        die;
    }

	function removefromFamily() {
        $field = JRequest::getVar('field');
		$member = JRequest::getVar('member');

		$model = $this->getModel('family');
        $result = $model->removefromFamily($member, $field);
        echo $result;
        die;
    }

	function addtoFamily() {
        $field = JRequest::getVar('field');
		$member = JRequest::getVar('member');

		$model = $this->getModel('family');
        $result = $model->addtoFamily($member, $field);
        echo $result;
        die;
    }

	function declineRequest()
	{
        $field = JRequest::getVar('field');
		$member = JRequest::getVar('member');

		$model = $this->getModel('family');
        $result = $model->declineRequest($member, $field);
        echo $result;
        die;
    }

	function acceptRequest()
	{
        $field = JRequest::getVar('field');
		$member = JRequest::getVar('member');

		$model = $this->getModel('family');
        $result = $model->acceptRequest($member, $field);
        echo $result;
        die;
	}

	function addfamilysearch() {
        $field = JRequest::getVar('field');
		$member = JRequest::getVar('member');

		$model = $this->getModel('family');
        $result = $model->addfamilysearch($member, $field);
        echo $result;
        die;
    }
	
	function FamilySearchBox() {
		$SearchTerm = JRequest::getVar('term');
		$field = JRequest::getVar('field');

		$model = $this->getModel('family');
		$data = $model->FamilySearchBox($SearchTerm, $field);
		echo json_encode($data);
		exit();
    }

	///rgs..
	
    function getrepin() {
        $res['board_id'] = JRequest::getVar('board_id');
        $res['description'] = JRequest::getVar('description');
        $res['repin_id'] = JRequest::getVar('repin_id');
        $res['pin_real_pin_id'] = JRequest::getVar('pin_real_pin_id');
        $res['pin_user_id'] = JRequest::getVar('pin_user_id');
        $model = $this->getModel('home');
        $result = $model->setPins($res);
        echo $result;
        die;
    }

    function getpininfo() {
        $mainframe = JFactory::getApplication();
        $pin_id = JRequest::getVar('pin_id');
        $model = $this->getModel('home');
        $res = $model->getPin($pin_id);		

        $pin['pin_type_id'] = $res[0]->pin_type_id;
        $pin['pin_repin_id'] = $pin_id;
        $pin['pin_real_pin_id'] = $res[0]->pin_real_pin_id;
        $pin['pin_url'] = $res[0]->pin_url;
        if ($res[0]->link_type == 'youtube' || $res[0]->link_type == 'vimeo') {
            $pin['image'] = $res[0]->pin_image;
        } else {
            $pin['image'] = JURI::base() . 'images/wishlogue/wish_medium/' . $res[0]->pin_image;
        }
        $pin['description'] = $res[0]->pin_description;
        $pin['board_id'] = $res[0]->pin_board_id;

		//rgs.
		$pin['price'] = $res[0]->price;
		$pin['wish_item'] = $res[0]->wish_item;
		$pin['wish_retailer'] = $res[0]->wish_retailer;
		$pin['wish_product_url'] = $res[0]->wish_product_url;
		$pin['wish_currency'] = $res[0]->wish_currency;
		$pin['wish_quantity'] = $res[0]->wish_quantity;
		$pin['wish_size'] = $res[0]->wish_size;
		$pin['wish_style'] = $res[0]->wish_style;
		$pin['wish_color'] = $res[0]->wish_color;
		//rgs..

        echo $result = implode("*&@#@%asdfbk", $pin);
        die;
    }

    function getlikeinfo() {

        $mainframe = JFactory::getApplication();
        $pin['pin_id'] = JRequest::getVar('pin_id');
        $pin['user_id'] = JRequest::getVar('user_id');
        $pin['pin_flag'] = JRequest::getVar('pin_flag');
        $model = $this->getModel('home');
        $res = $model->getLike($pin);
        echo $res;
        die;
    }

    function getcommentinfo() {

        $mainframe = JFactory::getApplication();
        $pin['pin_id'] = JRequest::getVar('pin_id');
        $pin['comment'] = JRequest::getVar('comment');
        $model = $this->getModel('home');
        $res = $model->getComment($pin);
        echo json_encode($res);
        die;
    }

    function get_newpin_notification() {

        $model = $this->getModel('home');
        $res = $model->getPinscount();
        echo $res;
        die;
    }

    function addnewboard() {

        $pin['user_id'] = JRequest::getVar('user_id');
        $pin['board_name'] = JRequest::getVar('board_name');
		$pin['board_category'] = JRequest::getVar('board_category');

        $model = $this->getModel('home');
        $res = $model->addnewboard($pin);
        echo $res;
        die;
    }

    function followall() {
        $mainframe = JFactory::getApplication();
        $follow['user_id'] = JRequest::getVar('user_id');
        $follow['fuser_id'] = JRequest::getVar('fuser_id');
        $model = $this->getModel('home');
        $result = $model->getFollow($follow);
        echo $result;
        die;
    }

    function unfollowall() {
        $mainframe = JFactory::getApplication();
        $unFollow['user_id'] = JRequest::getVar('user_id');
        $unFollow['fuser_id'] = JRequest::getVar('fuser_id');
        $model = $this->getModel('home');
        $result = $model->getUnFollow($unFollow);
        echo $result;
        die;
    }

    function followboard() {
        $mainframe = JFactory::getApplication();
        $unFollowBoard['user_id'] = JRequest::getVar('user_id');
        $unFollowBoard['fuser_id'] = JRequest::getVar('fuser_id');
        $unFollowBoard['board_id'] = JRequest::getVar('boardid');
        $model = $this->getModel('home');
        $result = $model->getFollowBoard($unFollowBoard);
        echo $result;
        die;
    }

    function unfollowboard() {
        $mainframe = JFactory::getApplication();
        $unFollowBoard['user_id'] = JRequest::getVar('user_id');
        $unFollowBoard['fuser_id'] = JRequest::getVar('fuser_id');
        $unFollowBoard['board_id'] = JRequest::getVar('boardid');

        $model = $this->getModel('home');
        $result = $model->getUnFollowBoard($unFollowBoard);
        echo $result;
        die;
    }

    function getcategoryimage() {
        $mainframe = JFactory::getApplication();
        $category['userId'] = JRequest::getVar('userId');
        $category['category_id'] = JRequest::getVar('cid');

        $model = $this->getModel('userfollow');
        $result = $model->getFollowersCategory($category);
        echo $result;
        die;
    }

    function getuncategoryimage() {
        $mainframe = JFactory::getApplication();
        $category['userId'] = JRequest::getVar('userId');
        $category['category_id'] = JRequest::getVar('cid');
        $model = $this->getModel('userfollow');
        $result = $model->getFollowersUnCategory($category);
        echo $result;
        die;
    }

    function checkUserName() {

        $mainframe = JFactory::getApplication();
        $user_name = JRequest::getVar('username');
        $model = $this->getModel('mailfriends');
        $results = $model->checkUserName($user_name);
        echo $results;
        die();
    }

    function checkEmail() {

        $mainframe = JFactory::getApplication();
        $email = JRequest::getVar('email');
        $model = $this->getModel('mailfriends');
        $results = $model->checkEmail($email);
        echo $results;
        die();
    }

    function addcontributers() {
        $mainframe = JFactory::getApplication();
        $contributors = JRequest::getVar('name_contributers');
        $model = $this->getModel('home');
        $result = $model->contributers($contributors);
        echo $result;
        die;
    }

    function getcontributers() {
        $mainframe = JFactory::getApplication();

        $user_contributers['user'] = JRequest::getVar('user');
        $user_contributers['bidd'] = JRequest::getVar('bidd');

        $model = $this->getModel('catalogueedit');
        $results = $model->getContributers($user_contributers);

        $inc = 0;
        $username = '';
        if ($results != '') {
            foreach ($results as $result) {

                if ((count($results) - 1) == $inc) {
                    $username['username'][] = $result->username;
                    $username['userid'][] = $result->user_id;
                } else {

                    $username['username'][] = $result->username;
                    $username['userid'][] = $result->user_id;
                }
                $inc++;
            }
        } else {
            $username = "no user";
        }
        echo json_encode($username);
        die;
    }

    function removeContributers() {
        $mainframe = JFactory::getApplication();
        $user_contributers['user_id'] = JRequest::getVar('user_id');
        $user_contributers['bidd'] = JRequest::getVar('bidd');
        $model = $this->getModel('catalogueedit');
        $results = $model->removeContributers($user_contributers);
        echo $results;
        die;
    }

    function addBoardContributers() {
        $mainframe = JFactory::getApplication();

        $user_contributers['name_contributer'] = JRequest::getVar('name_contributer');
        $user_contributers['user_id_contributors'] = JRequest::getVar('user_id_contributors');
        $user_contributers['bidd'] = JRequest::getVar('bidd');

        $model = $this->getModel('catalogueedit');
        $results = $model->addBoardContributers($user_contributers);


        echo $results;
        die;
    }

    function justMeContributors() {
        $mainframe = JFactory::getApplication();
        $user_contributers_bidd = JRequest::getVar('bidd');
        $model = $this->getModel('catalogueedit');
        $results = $model->justMeContributors($user_contributers_bidd);
        echo $results;
        die;
    }

    function deleteComment() {
        $user_comment_id = JRequest::getVar('comment_id');
        $comment_pin_id = JRequest::getVar('comment_pin_id');
        $model = $this->getModel('home');
        $results = $model->deleteComment($user_comment_id, $comment_pin_id);
        echo $results;
        die;
    }

    function checkPassword() {
        $user_email = JRequest::getVar('email');
        $user_password = JRequest::getVar('password');
        $twitter_id = JRequest::getVar('twitter_id');
        $model = $this->getModel('userlogin');
        $username = JRequest::getVar('username');
        $results = $model->checkPassword($user_email, $user_password, $twitter_id, $username);
        echo $results;
        die;
    }

    function block() {
        $mainframe = JFactory::getApplication();
        $follow['user_id'] = JRequest::getVar('user_id');
        $follow['fuser_id'] = JRequest::getVar('fuser_id');
        $model = $this->getModel('home');
        $result = $model->getUnFollow($follow);
        $result = $model->getBlock($follow);
        echo $result;
        die;
    }

    function unblock() {
        $mainframe = JFactory::getApplication();
        $unFollow['user_id'] = JRequest::getVar('user_id');
        $unFollow['fuser_id'] = JRequest::getVar('fuser_id');
        $model = $this->getModel('home');
        $result = $model->getUnblock($unFollow);
        echo $result;
        die;
    }

}

?>