Esempio n. 1
0
 /**
  * Check if to use a mobile theme
  *
  * @return boolean
  */
 public function isMobileTheme()
 {
     if (is_bool($this->isMobileTheme)) {
         return $this->isMobileTheme;
     }
     if (!env('APP_MOBILE_THEME', false)) {
         return false;
     }
     /**
      * check if really a mobile
      * check cookie
      * check session
      * check user theme to use
      */
     if (env('APP_ENV_MOBILE', false)) {
         return true;
     }
     if ($this->detector()->isMobile()) {
         $this->isMobileTheme = true;
         return true;
     }
     if ($this->detector()->isTablet()) {
         $this->isMobileTheme = true;
         return true;
     }
     if (!empty(zbase_cookie($this->mobileVarName))) {
         $this->isMobileTheme = true;
         return true;
     }
     if (!empty(zbase_session_has($this->mobileVarName)) && !empty(zbase_session_get($this->mobileVarName))) {
         $this->isMobileTheme = true;
         return true;
     }
     if (!empty(zbase_request_query_input($this->mobileVarName))) {
         if (!empty(zbase_request_query_input($this->mobileVarName . 'Cookie'))) {
             zbase_cookie_forever($this->mobileVarName, 1);
         }
         $this->isMobileTheme = true;
         return true;
     }
     $this->isMobileTheme = false;
     return false;
 }
Esempio n. 2
0
 /**
  * Check if was posted
  * @return boolean
  */
 public function wasPosted()
 {
     $currentTab = zbase_session_get('sessiontab', false);
     if (!empty($currentTab)) {
         if ($this->getTab() != $currentTab) {
             return false;
         }
     }
     if ($this->form() instanceof \Zbase\Widgets\Type\FormInterface) {
         return $this->form()->wasPosted();
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Create an element
  * @param array $element Element configuration
  * @param string $tabName The tabName the element belongs
  * @return Zbase\Ui\Form\ElementInterface
  */
 protected function _createElement($element, $tabName = null)
 {
     $e = \Zbase\Ui\Form\Element::factory($element);
     if (is_null($e)) {
         return;
     }
     $e->setAttribute('widgetEntity', $this->entity());
     if ($e instanceof \Zbase\Widgets\Type\FormInterface) {
         $e->form($this);
         if (empty($this->_entityIsDefault)) {
             $e->entity($this->_entity);
         }
     }
     if ($e instanceof \Zbase\Ui\Form\ElementInterface) {
         if (!empty($tabName)) {
             $e->setTab($tabName);
         }
         if ($this->isValueToSession()) {
             $e->setValue(zbase_session_get($e->id()));
         }
     }
     if ($e instanceof \Zbase\Widgets\EntityInterface) {
         $e->entity($this->_entity);
     }
     if ($e instanceof \Zbase\Widgets\Type\FormInterface) {
         $widgetElements = $e->elements();
         if (!empty($widgetElements)) {
             foreach ($widgetElements as $widgetElement) {
                 if (!empty($element['widget']) && !empty($element['prefix'])) {
                     $widgetElement->setIdPrefix($element['prefix']);
                     if ($this->isValueToSession()) {
                         $widgetElement->setValue(zbase_session_get($widgetElement->id()));
                     }
                 }
                 if (!empty($tabName)) {
                     if ($widgetElement instanceof \Zbase\Ui\Form\ElementInterface) {
                         $widgetElement->setTab($tabName);
                     }
                     if ($widgetElement instanceof \Zbase\Interfaces\ValidationInterface) {
                         if ($widgetElement->hasValidations()) {
                             //$currentTab = zbase_request_input('tab', false);
                             //if(zbase_request_method() == 'post' && !empty($currentTab))
                             //{
                             $widgetValidationRules = $widgetElement->getValidationRules($this->getAction());
                             if (!is_array($widgetValidationRules)) {
                                 $widgetValidationRules = [$widgetElement->getId() => $widgetValidationRules];
                             }
                             $this->_validationRules = array_replace_recursive($this->_validationRules, $widgetValidationRules);
                             $this->_validationMessages = array_replace_recursive($this->_validationMessages, $widgetElement->getValidationMessages($this->getAction()));
                             //}
                         }
                     }
                 }
             }
         } else {
             if ($e instanceof \Zbase\Ui\Form\ElementInterface) {
                 if ($e instanceof \Zbase\Interfaces\ValidationInterface) {
                     if ($e->hasValidations()) {
                         $widgetValidationRules = $e->getValidationRules($this->getAction());
                         if (!is_array($widgetValidationRules)) {
                             $widgetValidationRules = [$e->getId() => $widgetValidationRules];
                         }
                         $this->_validationRules = array_replace_recursive($this->_validationRules, $widgetValidationRules);
                         $this->_validationMessages = array_replace_recursive($this->_validationMessages, $e->getValidationMessages($this->getAction()));
                     }
                 }
             }
         }
     }
     $currentTab = zbase_request_input('tab', false);
     if ($e instanceof \Zbase\Interfaces\ValidationInterface) {
         if ($e->hasValidations()) {
             $formTag = $this->_v('form_tab', true);
             if (zbase_request_method() == 'post' && empty($formTag) && !empty($currentTab)) {
                 if ($tabName == $currentTab) {
                     if (!isset($this->_validationRules['_tab' . $tabName])) {
                         $this->_validationRules['_tab' . $tabName] = [];
                     }
                     $this->_validationRules['_tab' . $tabName][$e->name()] = $e->getValidationRules($this->getAction());
                     $this->_validationMessages = array_replace_recursive($this->_validationMessages, $e->getValidationMessages($this->getAction()));
                 }
             }
             //				if(zbase_request_method() == 'post' && empty($formTag) && !empty($currentTab))
             //				{
             //					if($tabName == $currentTab)
             //					{
             //						$this->_validationRules[$e->name()] = $e->getValidationRules($this->getAction());
             //						$this->_validationMessages = array_replace_recursive($this->_validationMessages, $e->getValidationMessages($this->getAction()));
             //					}
             //				}
             //				else
             //				{
             //					$this->_validationRules[$e->name()] = $e->getValidationRules($this->getAction());
             //					$this->_validationMessages = array_replace_recursive($this->_validationMessages, $e->getValidationMessages($this->getAction()));
             //				}
         }
         //			if(zbase_request_method() == 'post')
         //			{
         //				var_dump(zbase_request_inputs());
         //				var_dump($currentTab . '-' . $tabName);
         //			}
     }
     return $e;
 }
Esempio n. 4
0
 /**
  * Add a Tab
  * @param \Zbase\UIs\Tab $tab
  * @return \Zbase\UIs\Tabs
  */
 public function add(UIs\Tab $tab)
 {
     if ($tab->enabled() && $tab->hasAccess()) {
         $activeTab = zbase_request_input('tab', false);
         if (empty($activeTab)) {
             $activeTab = zbase_session_get('sessiontab', false);
         }
         if (!empty($activeTab)) {
             $tab->setActive(false);
             if ($tab->tabId() == $activeTab) {
                 $tab->setActive(true);
             }
         }
         if ($tab->isActive()) {
             $this->_hasActiveTab = true;
         }
         $this->_tabs[] = $tab;
     }
     return $this;
 }
Esempio n. 5
0
 /**
  * Process initial authentication
  * Checking if user can Auth
  */
 public function authenticated(Request $request, $user)
 {
     if (!$user->canAuth()) {
         \Auth::logout();
     }
     $user->log('user::authenticated');
     $user->authenticated();
     if (zbase_route_username()) {
         $usernameRoutePrefix = zbase_route_username_prefix();
         $redirect = zbase_request_input('redirect', zbase_session_get('__loginRedirect', zbase_url_from_route('home', [$usernameRoutePrefix => $user->username()])));
     } else {
         $redirect = !empty($this->redirectTo) ? $this->redirectTo : zbase_request_input('redirect', zbase_session_get('__loginRedirect', zbase_url_from_route('home')));
     }
     zbase()->json()->setVariable('_redirect', $redirect);
     zbase()->json()->setVariable('login_success', 1);
     return redirect()->intended($redirect);
 }
Esempio n. 6
0
/**
 * Return the Current Authed User
 * @return \
 */
function zbase_auth_user()
{
    if (!zbase_auth_has()) {
        return false;
    }
    if (\Auth::user()->isAdmin() && !empty(zbase_session_has('_duplexSession'))) {
        return zbase_user_byId(zbase_session_get('_duplexSession'));
    }
    if (!empty(\Auth::user())) {
        return zbase_user_byid(\Auth::user()->id());
    }
    return false;
}
Esempio n. 7
0
/**
 * GEt form input has error
 *
 * @param string $key
 * @return boolean
 */
function zbase_form_input_get_error($key)
{
    return zbase_session_get('_form_error_' . $key);
}