Esempio n. 1
0
/**
 * Displays backend navigation menu
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 *
 * @package application.helper.smarty
 * @author Integry Systems
 */
function smarty_function_backendMenu($params, Smarty_Internal_Template $smarty)
{
    $smarty = $smarty->smarty;
    $locale = $smarty->getApplication()->getLocale();
    $request = $smarty->getApplication()->getRequest();
    $controller = $request->get('controller');
    $action = $request->get('action');
    // load language file for menu
    $locale->translationManager()->loadFile('backend/menu');
    $menuLoader = new MenuLoader($smarty->getApplication(), $params['menu']);
    $structure = $menuLoader->getCurrentHierarchy($controller, $action);
    $router = $smarty->getApplication()->getRouter();
    // get translations and generate URL's
    $items = array();
    foreach ($structure['items'] as $topValue) {
        if (!empty($topValue['role']) && !AccessStringParser::run($topValue['role'])) {
            continue;
        }
        $filteredValue = array();
        foreach (array('title', 'descr') as $field) {
            $filteredValue[$field] = $smarty->branding($locale->translator()->translate($topValue[$field]));
        }
        $filteredValue['controller'] = isset($topValue['controller']) ? $topValue['controller'] : '';
        $filteredValue['action'] = isset($topValue['action']) ? $topValue['action'] : '';
        $filteredValue['icon'] = isset($topValue['icon']) ? $topValue['icon'] : '';
        if (!empty($topValue['controller'])) {
            $filteredValue['url'] = $router->createUrl(array('controller' => $topValue['controller'], 'action' => isset($topValue['action']) ? $topValue['action'] : null), true);
        }
        if (isset($topValue['items']) && is_array($topValue['items'])) {
            $subItems = array();
            foreach ($topValue['items'] as &$subValue) {
                if (!empty($subValue['role']) && !AccessStringParser::run($subValue['role'])) {
                    continue;
                }
                $filteredSubValue = array();
                foreach (array('title', 'descr') as $field) {
                    $filteredSubValue[$field] = $smarty->branding($locale->translator()->translate($subValue[$field]));
                }
                $filteredSubValue['url'] = $router->createUrl(array('controller' => $subValue['controller'], 'action' => isset($subValue['action']) ? $subValue['action'] : null), true);
                if (!empty($subValue['query'])) {
                    $filteredSubValue['url'] .= '?' . $subValue['query'];
                }
                $filteredSubValue['controller'] = $subValue['controller'];
                $filteredSubValue['action'] = isset($subValue['action']) ? $subValue['action'] : '';
                $filteredSubValue['icon'] = isset($subValue['icon']) ? $subValue['icon'] : '';
                $subItems[] = $filteredSubValue;
            }
            if (count($subItems) > 0) {
                $filteredValue['items'] = $subItems;
            }
        }
        $items[] = $filteredValue;
    }
    $smarty->assign('menuArray', json_encode($items));
    $smarty->assign('controller', $controller);
    $smarty->assign('action', $action);
    return $smarty->display('block/backend/backendMenu.tpl');
}
Esempio n. 2
0
/**
 * Display a tip block
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_denied($params, $content, LiveCartSmarty $smarty, &$repeat)
{
    if (!$repeat) {
        ClassLoader::import('application.helper.AccessStringParser');
        if (!AccessStringParser::run($params['role'])) {
            return $content;
        }
    }
}
Esempio n. 3
0
/**
 * Display a tip block
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_allowed($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if (!$repeat) {
        ClassLoader::import('application.helper.AccessStringParser');
        if (AccessStringParser::run($params['role'])) {
            return $content;
        }
    }
}
Esempio n. 4
0
/**
 * Tab
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_tab($params, $content, Smarty_Internal_Template $smarty, &$repeat)
{
    if (!$repeat) {
        ClassLoader::import('application.helper.AccessStringParser');
        if (!empty($params['role']) && !AccessStringParser::run($params['role'])) {
            return false;
        }
        $user = SessionUser::getUser();
        $userPref = $user->getPreference('tab_' . $params['id']);
        $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false';
        $content = '
<li id="' . $params['id'] . '" rel="' . $params['help'] . '" class="tab ui-state-default ui-corner-top inactive' . ($isHidden ? ' hidden' : '') . '">' . $content . '</li>';
        return $content;
    }
}
Esempio n. 5
0
/**
 * Tab
 *
 * @package application.helper.smarty
 * @author Integry Systems
 *
 * @package application.helper.smarty
 */
function smarty_block_tab($params, $content, LiveCartSmarty $smarty, &$repeat)
{
    if (!$repeat) {
        ClassLoader::import('application.helper.AccessStringParser');
        if (!empty($params['role']) && !AccessStringParser::run($params['role'])) {
            return false;
        }
        $user = SessionUser::getUser();
        $userPref = $user->getPreference('tab_' . $params['id']);
        $isHidden = is_null($userPref) ? !empty($params['hidden']) : $userPref == 'false';
        $content = '
<li id="' . $params['id'] . '" class="tab inactive' . ($isHidden ? ' hidden' : '') . '">' . $content . '
	<span> </span>
	<span class="tabHelp">' . $params['help'] . '</span>
</li>';
        return $content;
    }
}
Esempio n. 6
0
/**
 * Smarty form helper
 *
 * <code>
 * </code>
 *
 * @package application.helper.smarty.form
 * @author Integry Systems
 *
 * @todo Include javascript validator source
 */
function smarty_block_form(&$params, $content, $smarty, &$repeat)
{
    if ($repeat) {
        // Check permissions
        $params['readonly'] = false;
        if (isset($params['readonly']) && $params['readonly']) {
            $params['class'] .= ' formReadonly';
            $params['readonly'] = true;
        } else {
            if (isset($params['role'])) {
                ClassLoader::import('application.helper.AccessStringParser');
                if (!AccessStringParser::run($params['role'])) {
                    if (!isset($params['class'])) {
                        $params['class'] = '';
                    }
                    $params['class'] .= ' formReadonly';
                    $params['readonly'] = true;
                }
            }
        }
    } else {
        $formHandler = $params['handle'];
        $formAction = $params['action'];
        $role = isset($params['role']) ? $params['role'] : false;
        unset($params['handle']);
        unset($params['role']);
        unset($params['action']);
        $params = array_merge($params, $formHandler->getParams());
        if (!empty($params['url'])) {
            $actionURL = $params['url'];
            unset($params['url']);
        } else {
            if ($formAction && 'self' != $formAction) {
                $vars = explode(" ", $formAction);
                $URLVars = array();
                foreach ($vars as $var) {
                    $parts = explode("=", $var, 2);
                    $URLVars[$parts[0]] = $parts[1];
                }
                try {
                    $actionURL = $smarty->getApplication()->getRouter()->createURL($URLVars, true);
                } catch (RouterException $e) {
                    $actionURL = "INVALID_FORM_ACTION_URL";
                }
            } else {
                if ('self' == $formAction || !$formAction) {
                    $actionURL = urldecode($_SERVER['REQUEST_URI']);
                }
            }
        }
        if (!empty($params['onsubmit'])) {
            $customOnSubmit = $params['onsubmit'];
            unset($params['onsubmit']);
        }
        $onSubmit = "";
        $validatorField = "";
        $preValidate = "";
        if (isset($params['prevalidate'])) {
            $preValidate = $params['prevalidate'] . '; ';
            unset($params['prevalidate']);
        }
        if ($formHandler->isClientSideValidationEnabled()) {
            if (!empty($customOnSubmit)) {
                $onSubmit = $preValidate . 'if (!validateForm(this)) { return false; } ' . $customOnSubmit;
            } else {
                $onSubmit = 'return validateForm(this);';
            }
            $validatorField = '<input type="hidden" disabled="disabled" name="_validator" value="' . $formHandler->getValidator()->getJSValidatorParams() . '"/>';
            $filterField = '<input type="hidden" disabled="disabled" name="_filter" value="' . $formHandler->getValidator()->getJSFilterParams() . '"/>';
            $params['onkeyup'] = 'applyFilters(this, event);';
        } else {
            $onSubmit = $customOnSubmit;
        }
        if ($onSubmit) {
            $params['onsubmit'] = $onSubmit;
        }
        // pass URL query parameters with hidden fields for GET forms
        if (empty($params['method']) || strtolower($params['method']) == 'get') {
            if (strpos($actionURL, '?')) {
                $q = substr($actionURL, strpos($actionURL, '?') + 1);
                $actionURL = substr($actionURL, 0, strpos($actionURL, '?'));
            }
            if (!empty($q)) {
                $pairs = explode('&', $q);
                $values = array();
                foreach ($pairs as $pair) {
                    list($key, $value) = explode('=', $pair, 2);
                    $values[$key] = $value;
                }
                $hidden = array();
                foreach ($values as $key => $value) {
                    $hidden[] = '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
                }
                $content = implode("\n", $hidden) . $content;
            }
        }
        if (empty($params['method'])) {
            $params['method'] = 'get';
        } else {
            $params['method'] = strtolower($params['method']);
        }
        $formAttributes = "";
        unset($params['readonly']);
        foreach ($params as $param => $value) {
            $formAttributes .= $param . '="' . $value . '" ';
        }
        $form = '<form action="' . $actionURL . '" ' . $formAttributes . '>' . "\n";
        $form .= $validatorField;
        $form .= $filterField;
        $form .= $content;
        $form .= "</form>";
        return $form;
    }
}