<?php

/**
 * @Copyright Copyright (C) 2009-2010 Ahmad Bilal
 * @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
 * Company:     Buruj Solutions
 + Contact:     https://www.burujsolutions.com , info@burujsolutions.com
 * Created on:  Nov 22, 2010
 ^
 + Project:     JS Jobs
 ^ 
 */
 
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');

class JSJobsControllerCompany extends JSController {

    function __construct() {
        $app = JFactory::getApplication();
        $user = JFactory::getUser();
        if ($user->guest) { // redirect user if not login
            $link = 'index.php?option=com_user';
            $this->setRedirect($link);
        }
        parent::__construct();
    }

    function savecompany() { //save company
        $jobsharing = $this->getModel('jobsharingsite', 'JSJobsModel');
        $uid = JFactory::getApplication()->input->get('uid', 'none', 'string');
        $Itemid = JFactory::getApplication()->input->get('Itemid');
        $company = $this->getmodel('Company', 'JSJobsModel');
        $return_value = $company->storeCompany();
        $link = 'index.php?option=com_jsjobs&c=company&view=company&layout=mycompanies&Itemid=' . $Itemid;

        if ($return_value == 1) {
            JSJOBSActionMessages::setMessage(SAVED, 'company','message');
        } else if ($return_value == 2) {
            JSJOBSActionMessages::setMessage(REQUIRED_FIELDS, 'company','error');
            $link = 'index.php?option=com_jsjobs&c=company&view=company&layout=formcompany&Itemid=' . $Itemid;
        } else if ($return_value == 6) {
            JSJOBSActionMessages::setMessage(FILE_TYPE_ERROR, 'company','warning');
        } else if ($return_value == 5) {
            JSJOBSActionMessages::setMessage(FILE_SIZE_ERROR, 'company','warning');
            $link = 'index.php?option=com_jsjobs&c=company&view=company&layout=formcompany&Itemid=' . $Itemid;
        } else {
            JSJOBSActionMessages::setMessage(SAVE_ERROR, 'company','error');
            $link = 'index.php?option=com_jsjobs&c=company&view=company&layout=formcompany&Itemid=' . $Itemid;
        }
        $this->setRedirect(JRoute::_($link , false));
    }

    function deletecompany() { //delete company
        JSession::checkToken('get') or die( 'Invalid Token' );
        $jobsharing = $this->getModel('jobsharingsite', 'JSJobsModel');
        $user = JFactory::getUser();
        $uid = $user->id;
        $Itemid = JFactory::getApplication()->input->get('Itemid');
        $common = $this->getmodel('Common', 'JSJobsModel');
        $companyid = $common->parseId(JFactory::getApplication()->input->get('cd', ''));
        $company = $this->getmodel('Company', 'JSJobsModel');
        $return_value = $company->deleteCompany($companyid, $uid);
        if ($return_value == 1) {
            JSJOBSActionMessages::setMessage(DELETED, 'company','message');
        } elseif ($return_value == 2) {
            JSJOBSActionMessages::setMessage(DELETE_ERROR, 'company','error');
        } elseif ($return_value == 3) {
            JSJOBSActionMessages::setMessage(NOT_YOUR, 'company','error');
        } else {
            JSJOBSActionMessages::setMessage(DELETE_ERROR, 'company','error');
        }
        $link = 'index.php?option=com_jsjobs&c=company&view=company&layout=mycompanies&Itemid=' . $Itemid;
        $this->setRedirect(JRoute::_($link , false));
    }

    function postcompanyonjomsocial(){
        JSession::checkToken() or die( 'Invalid Token' );
        $isallowed = JSModel::getJSModel('configurations')->getConfigValue('jomsocial_allowpostcompany');
        if($isallowed){            
            $companyid = JFactory::getApplication()->input->get('id',0);
            $res = JSModel::getJSModel('company')->postCompanyOnJomSocial($companyid);
            if($res){
                JSJOBSActionMessages::setMessage("Company has been successfully posted on JomSocial", 'company','message');
            }else{
                JSJOBSActionMessages::setMessage("Company has not been posted on JomSocial", 'company','error');
            }
        }
        $link = 'index.php?option=com_jsjobs&c=company&view=company&layout=mycompanies&Itemid=' . $Itemid;
        $this->setRedirect($link);
    }

    function display($cachable = false, $urlparams = false) { // correct employer controller display function manually.
        $document = JFactory::getDocument();
        $viewName = JFactory::getApplication()->input->get('view', 'default');
        $layoutName = JFactory::getApplication()->input->get('layout', 'default');
        $viewType = $document->getType();
        $view = $this->getView($viewName, $viewType);
        $view->setLayout($layoutName);
        $view->display();
    }

}

?>
    
