<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/

class  Inspira_Widget_LandingPageMainController extends Engine_Content_Widget_Abstract {

  public function indexAction() {
    $this->view->title = $this->_getParam("title",'');
    $this->view->description = $this->_getParam("description",'');
    $this->view->Wimage = $this->_getParam("image",'');
     // Do not show if logged in
    if( Engine_Api::_()->user()->getViewer()->getIdentity() ) {
      $this->setNoRender();
      return;
    }
    $this->view->image = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.general.landingimage', '');

    // Display form
    $form = $this->view->form = new User_Form_Login(array(
      'mode' => 'column',
    ));;
    $form->setTitle(null)->setDescription(null);

    // Facebook login
    if( 'none' == Engine_Api::_()->getApi('settings', 'core')->core_facebook_enable ) {
      $form->removeElement('facebook');
    }
    
    // Check for recaptcha - it's too fat
    $this->view->noForm = false;
    if( ($captcha = $form->getElement('captcha')) instanceof Zend_Form_Element_Captcha && 
        $captcha->getCaptcha() instanceof Zend_Captcha_ReCaptcha ) {
      $this->view->noForm = true;
      $emailFieldName = $form->getEmailElementFieldName();
      $form->removeElement($emailFieldName);
      $form->removeElement('password');
      $form->removeElement('captcha');
      $form->removeElement('submit');
      $form->removeElement('remember');
//      $form->removeElement('facebook');
//      $form->removeElement('twitter');
      $form->removeDisplayGroup('buttons');
    }

    $languagePath = APPLICATION_PATH . '/application/languages';
        $this->view->navigation = $navigation = Engine_Api::_()
            ->getApi('menus', 'core')
            ->getNavigation('core_footer');

        // Languages
        $translate    = Zend_Registry::get('Zend_Translate');
        $languageList = $translate->getList();

        //$currentLocale = Zend_Registry::get('Locale')->__toString();

        // Prepare default langauge
        $defaultLanguage = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.locale.locale', 'en');
        if ($defaultLanguage == 'auto') {
            $defaultLanguage = 'en';
        }

        // Init default locale
        $localeObject = Zend_Registry::get('Locale');
        $languages = Zend_Locale::getTranslationList('language', $localeObject);
        $territories = Zend_Locale::getTranslationList('territory', $localeObject);

        $localeMultiOptions = array();
        foreach ($languageList as $key) {
            $dir = $languagePath . '/' . $key;
            if (!is_dir($dir)) {
                continue;
            }

            $languageName = null;
            if (!empty($languages[$key])) {
                $languageName = $languages[$key];
            } else {
                $tmpLocale = new Zend_Locale($key);
                $region = $tmpLocale->getRegion();
                $language = $tmpLocale->getLanguage();
                if (!empty($languages[$language]) && !empty($territories[$region])) {
                    $languageName =  $languages[$language] . ' (' . $territories[$region] . ')';
                }
            }

            if ($languageName) {
                $localeMultiOptions[$key] = $languageName . '';
            }
        }

        if (!isset($localeMultiOptions[$this->view->defaultLanguage])) {
            $defaultLanguage = 'en';
        }

        $this->view->defaultLanguage = $defaultLanguage;
        $this->view->languageNameList = $localeMultiOptions;
        
        $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
        $this->view->viewer_id = $viewer->getIdentity();

        //**
             $setting = Engine_Api::_()->getApi('settings', 'core');
      $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
      //widget options
      if($viewer->getIdentity())
      $options = $this->view->options = unserialize($setting->getSetting("inspira_headerloggedinoptions",'a:4:{i:0;s:6:"search";i:1;s:8:"miniMenu";i:2;s:8:"mainMenu";i:3;s:4:"logo";}'));
      else
      $options = $this->view->options = unserialize($setting->getSetting("inspira_headernonloggedinoptions",'a:4:{i:0;s:6:"search";i:1;s:8:"miniMenu";i:2;s:8:"mainMenu";i:3;s:4:"logo";}'));

      $this->view->accessibility_option = $setting->getSetting("accessibility_options");
      $this->view->logo = $setting->getSetting("landingpageinspira_logo") ? $setting->getSetting("landingpageinspira_logo") : $setting->getSetting("inspira_logo");

  }





}
