Esempio n. 1
0
/**
 * Smarty {scaffold} function plugin
 *
 * Type:     function<br>
 * Name:     scaffold<br>
 * Purpose:  scaffold
 *
 * @param         $params
 * @param \Smarty $smarty
 * @return bool
 */
function smarty_function_scaffold($params, &$smarty)
{
    if (isset($params['model'])) {
        global $db;
        require_once $smarty->_get_plugin_filepath('function', 'control');
        $table = $db->getDataDefinition($params['model']);
        foreach ($table as $key => $col) {
            if ($key != 'created_at' && $key != 'edited_at' && $key != 'poster' && $key != 'editor' && $key != 'location_data') {
                $ctl = array();
                //Get the default value
                if (isset($params['item'])) {
                    $ctl['value'] = isset($params['item']->{$key}) ? $params['item']->{$key} : "";
                }
                //Get the base control
                if ($key == 'id') {
                    $ctl['type'] = 'hidden';
                } else {
                    $ctl['type'] = expTemplate::guessControlType($col, $default_value, $key);
                }
                //format the values if needed
                if (isset($col[FORM_FIELD_FILTER])) {
                    switch ($col[FORM_FIELD_FILTER]) {
                        case MONEY:
                        case DECIMAL_MONEY:
                            $ctl['value'] = expCore::getCurrencySymbol('USD') . number_format($ctl['value'], 2, '.', ',');
                            $ctl['filter'] = 'money';
                            break;
                    }
                }
                //write out the control itself...and then we're done.
                if (isset($col[FORM_FIELD_ONCLICK])) {
                    $ctl['onclick'] = $col[FORM_FIELD_ONCLICK];
                }
                $ctl['label'] = isset($col[FORM_FIELD_LABEL]) ? $col[FORM_FIELD_LABEL] : $key;
                $ctl['name'] = isset($col[FORM_FIELD_NAME]) ? $col[FORM_FIELD_NAME] : $key;
                echo smarty_function_control($ctl, $smarty);
                //echo $control->controlToHTML($control_label, $control_name);
            }
        }
    }
    $submit = new buttongroupcontrol(gt('Submit'), gt('Reset'), gt('Cancel'));
    echo $submit->controlToHTML('submit');
}
Esempio n. 2
0
 function __construct($item_type, $item_dir, $view = "Default")
 {
     include_once SMARTY_PATH . 'Smarty.class.php';
     // Set up the Smarty template variable we wrap around.
     $this->tpl = new Smarty();
     $this->tpl->error_reporting = error_reporting() & ~E_NOTICE & ~E_WARNING;
     //FIXME this disables bad template code reporting 3.x
     $this->tpl->error_unassigned = true;
     // display notice when accessing unassigned variable, if warnings turned on
     //		$this->tpl->debugging = DEVELOPMENT;  // Opens up the debug console
     //Some (crappy) wysiwyg editors use php as their default initializer
     //FJD - this might break some editors...we'll see.
     $this->tpl->php_handling = SMARTY::PHP_REMOVE;
     $this->tpl->caching = false;
     $this->tpl->cache_dir = BASE . 'tmp/cache';
     $this->tpl->setPluginsDir(array(SMARTY_PATH . 'plugins', BASE . 'framework/plugins'));
     //autoload filters
     $this->tpl->autoload_filters = array('post' => array('includemiscfiles'));
     $this->viewfile = expTemplate::getViewFile($item_type, $item_dir, $view);
     $this->viewdir = realpath(dirname($this->viewfile));
     $this->module = $item_dir;
     $this->view = substr(basename($this->viewfile), 0, -4);
     //fix for the wamp/lamp issue
     //checks necessary in case a file from /views/ is used
     //should go away, the stuff should be put into a CoreModule
     //then this can be simplified
     //TODO: generate this through $this->viewfile using find BASE/THEME_ABSOLUTE and replace with ""
     //		if($item_type != "") {
     //			$this->langdir .= $item_type . "/";
     //		}
     //		if($item_dir != "") {
     //			$this->langdir .= $item_dir . "/";
     //		}
     //		$this->langdir .= "views/";
     $this->tpl->template_dir = $this->viewdir;
     $this->tpl->compile_dir = BASE . 'tmp/views_c';
     $this->tpl->compile_id = md5($this->viewfile);
     $this->tpl->assign("__view", $this->view);
     $this->tpl->assign("__redirect", expHistory::getLastNotEditable());
 }
Esempio n. 3
0
 function __construct($module, $view = null, $loc = null, $caching = false, $type = null)
 {
     $type = !isset($type) ? 'modules' : $type;
     //parent::__construct("modules", $module, $view);
     parent::__construct($type, $module, $view);
     $this->viewparams = expTemplate::getViewParams($this->viewfile);
     if ($loc == null) {
         $loc = expCore::makeLocation($module);
     }
     $this->tpl->assign("__loc", $loc);
     $this->tpl->assign("__name", $module);
     // View Config
     global $db;
     $container_key = serialize($loc);
     $cache = expSession::getCacheValue('containermodule');
     if (isset($cache[$container_key])) {
         $container = $cache[$container_key];
     } else {
         $container = $db->selectObject("container", "internal='" . $container_key . "'");
         $cache[$container_key] = $container;
     }
     $this->viewconfig = $container && isset($container->view_data) && $container->view_data != "" ? unserialize($container->view_data) : array();
     $this->tpl->assign("__viewconfig", $this->viewconfig);
 }
Esempio n. 4
0
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
/** @define "BASE" "../../../.." */
if (!defined('EXPONENT')) {
    exit('');
}
//if (expPermissions::check('administrate',$loc)) {
if ($user->isAdmin()) {
    global $router;
    if (expTemplate::getModuleViewFile($loc->mod, '_userpermissions', false) == TEMPLATE_FALLBACK_VIEW) {
        $template = new template('common', '_userpermissions', $loc);
    } else {
        //TODO
        //ADK - I hard coded the common module name into the new template declaration since the path resolver
        // can't seem to figure out that we are in the common module and not the module that call this action.
        //$template = new template($loc->mod,'_userpermissions',$loc);
        $template = new template('common', '_userpermissions', $loc);
    }
    $template->assign('user_form', 1);
    $users = array();
    $modulename = expModules::controllerExists($loc->mod) ? expModules::getControllerClassName($loc->mod) : $loc->mod;
    $modclass = $modulename;
    $mod = new $modclass();
    $perms = $mod->permissions($loc->int);
    $have_users = 0;
Esempio n. 5
0
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
if (!defined('EXPONENT')) {
    exit('');
}
if (expPermissions::check('configure', $loc)) {
    $config = $db->selectObject($_POST['module'] . '_config', "location_data='" . serialize($loc) . "'");
    $config = call_user_func(array($_POST['module'] . '_config', 'update'), $_POST, $config);
    $config->location_data = serialize($loc);
    if (isset($config->id)) {
        $db->updateObject($config, $_POST['module'] . '_config');
    } else {
        $db->insertObject($config, $_POST['module'] . '_config');
    }
    $container = $db->selectObject('container', "internal='" . serialize($loc) . "'");
    $vconfig = array();
    if (isset($_POST['_viewconfig'])) {
        $opts = expTemplate::getViewConfigOptions($loc->mod, $container->view);
        foreach (array_keys($opts) as $o) {
            $vconfig[$o] = isset($_POST['_viewconfig'][$o]) ? $_POST['_viewconfig'][$o] : 0;
        }
    }
    $container->view_data = serialize($vconfig);
    $db->updateObject($container, 'container');
    expHistory::back();
} else {
    echo SITE_403_HTML;
}
Esempio n. 6
0
/**
 * Smarty {viewfile} function plugin
 *
 * Type:     function<br>
 * Name:     viewfile<br>
 * Purpose:  get and assign a view file
 *
 * @param         $params
 * @param \Smarty $smarty
 * @return bool
 */
function smarty_function_viewfile($params, &$smarty)
{
    $view = expTemplate::getModuleViewFile($params['module'], $params['view']);
    $smarty->assign($params['var'], $view);
}
Esempio n. 7
0
     $module = new $moduleclass();
     $mod = null;
     // Get basic module meta info
     $mod->name = $module->name();
     $mod->author = $module->author();
     $mod->description = $module->description();
     if (isset($container->view) && $container->internal->mod == $moduleclass) {
         $mod->defaultView = $container->view;
     } else {
         $mod->defaultView = DEFAULT_VIEW;
     }
     // Get support flags
     $mod->supportsSources = $module->hasSources() ? 1 : 0;
     $mod->supportsViews = $module->hasViews() ? 1 : 0;
     // Get a list of views
     $mod->views = expTemplate::listModuleViews($moduleclass);
     natsort($mod->views);
     // if (!$haveclass) {
     //  $js_init .=  exponent_javascript_class($mod,'Module');
     //  $js_init .=  "var modules = new Array();\r\n";
     //  $js_init .=  "var modnames = new Array();\r\n\r\n";
     //  $haveclass = true;
     // }
     // $js_init .=  "modules.push(" . exponent_javascript_object($mod,"Module") . ");\r\n";
     // $js_init .=  "modnames.push('" . $moduleclass . "');\r\n";
     $modules[$moduleclass] = $mod;
     $mods[$moduleclass] = $module->name();
 }
 //$js_init .= "\r\n</script>";
 array_multisort(array_map('strtolower', $mods), $mods);
 if (!key_exists($container->internal->mod, $mods) && !empty($container->id)) {
Esempio n. 8
0
     $config = $db->selectObject($_GET['module'] . '_config', "location_data='" . serialize($loc) . "'");
     if (empty($config->location_data)) {
         $config->location_data = serialize($loc);
     }
     $form = call_user_func(array($_GET['module'] . '_config', 'form'), $config);
     if (isset($form->controls['submit'])) {
         $submit = $form->controls['submit'];
         $form->unregister('submit');
     }
     $hasConfig = 1;
     //We have a configuration stored in its own table
 }
 $container = $db->selectObject('container', "internal='" . serialize($loc) . "'");
 if ($container) {
     $values = $container->view_data != '' ? unserialize($container->view_data) : array();
     $form = expTemplate::getViewConfigForm($loc->mod, $container->view, $form, $values);
     if (isset($form->controls['submit'])) {
         // Still have a submit button.
         $submit = $form->controls['submit'];
         $form->unregister('submit');
     }
     $hasConfig = 1;
     //We have a per-view, per-container configuration stored in the container data
 }
 //FIXME PLEASE EVALUATE: since expTemplate::getViewConfigForm is called only here, is it necessary to make it add
 //the submit button to the config form just to unregister and re-register it down here?
 if ($hasConfig) {
     $form->location($loc);
     $form->meta('action', 'saveconfig');
     $form->meta('_common', '1');
 }
Esempio n. 9
0
                    $ctl->id = $control->id;
                    $control_type = get_class($ctl);
                    $f->id = $control->form_id;
                }
            }
            if ($control_type == "") {
                $control_type = $_POST['control_type'];
            }
            $form = call_user_func(array($control_type, "form"), $ctl);
            $form->location($loc);
            if ($ctl) {
                $form->controls['identifier']->disabled = true;
                $form->meta("id", $ctl->id);
                $form->meta("identifier", $ctl->identifier);
            }
            $form->meta("action", "save_control");
            $form->meta('control_type', $control_type);
            $form->meta('form_id', $f->id);
            $types = expTemplate::listControlTypes();
            $template = new template('formbuilder', '_edit_control');
            $template->assign('form_html', $form->toHTML($f->id));
            $template->assign('type', $types[$control_type]);
            $template->assign('is_edit', $ctl == null ? 0 : 1);
            $template->output();
        }
    } else {
        echo SITE_403_HTML;
    }
} else {
    echo SITE_404_HTML;
}