コード例 #1
0
ファイル: ZoneDefault.php プロジェクト: laiello/zoop
 public function pageList($p, $z)
 {
     $filterId = isset($p[1]) ? $p[1] : '';
     $filter = $filterId ? new Filter($filterId) : null;
     // if($filterId)
     // 	echo_r(json_decode($filter->content));
     $this->assign('requests', $this->loggedInUser->getPermittedRequests());
     $this->assign('config', Config::get('app.filter'));
     //	do any database lookups that need to be done to fill out the config data
     $config = Config::get('app.filter');
     foreach ($config['fields'] as $fieldName => $fieldInfo) {
         if ($fieldInfo['type'] == 'discreet' && !isset($fieldInfo['list'])) {
             $config['fields'][$fieldName]['list'] = SqlFetchSimpleMap("SELECT id, :nameField:identifier FROM :tableName:identifier", 'id', $fieldInfo['display_field'], array('nameField' => $fieldInfo['display_field'], 'tableName' => $fieldInfo['references']));
         }
     }
     $this->assign('config', $config);
     $filterList = array('' => '');
     $options = SqlFetchSimpleMap("SELECT id, name from filter order by name", 'id', 'name', array());
     foreach ($options as $key => $val) {
         $filterList[$key] = $val;
     }
     // echo_r(json_decode($filter->content));
     $this->assign('filter', $filter);
     $this->assign('filterId', $filterId);
     $this->assign('filterList', $filterList);
 }
コード例 #2
0
 public function getOptions()
 {
     if ($this->options) {
         return $this->options;
     } else {
         return SqlFetchSimpleMap("select {$this->remoteKeyField}, {$this->remoteValueField} from {$this->remoteTable}", $this->remoteKeyField, $this->remoteValueField, array());
     }
 }
コード例 #3
0
ファイル: ZoneFilter.php プロジェクト: laiello/zoop
 public function pageEdit($p, $z)
 {
     $config = Config::get('app.filter');
     //	do any database lookups that need to be done to fill out the config data
     foreach ($config['fields'] as $fieldName => $fieldInfo) {
         if ($fieldInfo['type'] == 'discreet' && !isset($fieldInfo['list'])) {
             $config['fields'][$fieldName]['list'] = SqlFetchSimpleMap("SELECT id, :nameField:identifier FROM :tableName:identifier", 'id', $fieldInfo['display_field'], array('nameField' => $fieldInfo['display_field'], 'tableName' => $fieldInfo['references']));
         }
     }
     $this->assign('config', $config);
 }
コード例 #4
0
/**
 * Smarty {html_dboptions} function plugin
 *
 * Type:     function<br>
 * Name:     html_dboptions<br>
 * Input:<br>
 *           - name       (optional) - string default "select"
 *			 - tablename  (required 
 *           - selected   (optional) - string default not set
 * Purpose:  Pulls a list of options from the database and prints the list of <option> tags generated from
 *           the passed parameters
 * @param array
 * @param Smarty
 * @return string
 * @uses smarty_function_html_options()
 */
function smarty_function_html_dboptions($params, &$smarty)
{
    require_once $smarty->_get_plugin_filepath('function', 'html_options');
    $tableName = $params['tablename'];
    if (isset($params['namefield'])) {
        $nameField = $params['namefield'];
    } else {
        $nameField = 'name';
    }
    $params['options'] = SqlFetchSimpleMap("SELECT id, :nameField AS name FROM :tableName:identifier order by id", 'id', 'name', array('nameField:identifier' => $nameField, 'tableName' => $tableName));
    return smarty_function_html_options($params, $smarty);
}
コード例 #5
0
ファイル: ZoneFilter.php プロジェクト: rgigger/zoopframework
 public function pageEdit($p, $z)
 {
     // +1. get the config from the yaml file
     // +2. Update the real table with the row from the template table
     // +3. populate the list of fields
     // +4. populate the initial list of operators for the default field
     // +5. update the operators menu when they change the field type
     // +6. update the operand paramater fields to match the operator and field
     // -7. make the .. button work
     // -7. save the output somehow
     // -8. reload the output
     // -9. converit it to sql
     // echo_r(Config::get('app.filter'));
     $config = Config::get('app.filter');
     //	do any database lookups that need to be done to fill out the config data
     foreach ($config['fields'] as $fieldName => $fieldInfo) {
         if ($fieldInfo['type'] == 'discreet' && !isset($fieldInfo['list'])) {
             $config['fields'][$fieldName]['list'] = SqlFetchSimpleMap("SELECT id, :nameField:identifier FROM :tableName:identifier", 'id', $fieldInfo['display_field'], array('nameField' => $fieldInfo['display_field'], 'tableName' => $fieldInfo['references']));
         }
     }
     $this->assign('config', $config);
 }
コード例 #6
0
ファイル: index.php プロジェクト: laiello/zoop
<?php

include 'config.php';
include zoop_dir . '/Zoop.php';
Zoop::loadLib('db');
$map = SqlFetchSimpleMap('select * from test', 'name', 'value', array());
echo_r($map);
$rows = SqlFetchRows('select * from test', array());
echo_r($rows);
$rows = SqlFetchRows('select * from test where name = :name', array('name' => 'one'));
echo_r($rows);
コード例 #7
0
ファイル: function.input.php プロジェクト: rgigger/zinc
function smarty_function_input($params, &$smarty)
{
    $type = isset($params['type']) ? $params['type'] : 'text';
    $valueAtt = isset($params['value']) ? $params['value'] : '';
    // handle the data bindings
    if (isset($params['data_object'])) {
        if (!isset($params['data_field'])) {
            trigger_error("gui:input: if you specifiy a data object you must also specify a data field");
        }
        $object = $params['data_object'];
        $field = $params['data_field'];
        if (!isset($params['append']) || $params['append'] == false) {
            $form = $smarty->getTemplateVars('__zinc');
            if (!$form) {
                trigger_error("gui:input: if you specifiy a data object you must first use the 'openform' tag");
            }
            $name = $form->addBinding($object, $field);
        } else {
            $binding = new FormBinding($object, $field);
            Form::appendBindings(array($binding));
            $name = $binding->getName();
        }
        if (isset($params['default']) && ($object->{$field} === '' || $object->{$field} === NULL)) {
            $value = $params['default'];
        } else {
            $value = isset($params['value']) ? $params['value'] : $object->{$field};
        }
        $namePart = ' name="' . $name . '"';
        if ($type == 'radio') {
            $valuePart = ' value="' . $valueAtt . '"';
        } else {
            $valuePart = ' value="' . $value . '"';
        }
    } else {
        $value = $valueAtt;
        $name = isset($params['name']) ? $params['name'] : '';
        $namePart = isset($params['name']) ? ' name="' . $params['name'] . '"' : '';
        $valuePart = isset($params['value']) ? ' value="' . $params['value'] . '"' : '';
    }
    // pass on anything else they put in
    $extraFields = '';
    $extraMap = array();
    foreach ($params as $paramName => $paramValue) {
        // if($paramName == 'name' && !isset($params['id']))
        // 	$params['id'] = $paramValue;
        if (in_array($paramName, array('type', 'name', 'type', 'value', 'default', 'data_object', 'data_field', 'append', 'minlen', 'sameas', 'required', 'requireOther', 'otherValue', 'otherField', 'message', 'intrange'))) {
            continue;
        }
        if (substr($paramName, 0, 5) == 'data_') {
            $paramName[4] = '-';
        }
        $extraMap[$paramName] = $paramValue;
        $extraFields .= ' ' . $paramName . '="' . $paramValue . '"';
    }
    if (isset($params['class'])) {
        $classes = array_flip(explode(' ', trim($params['class'])));
    } else {
        $classes = array();
    }
    $required = isset($params['required']) && $params['required'];
    if ($required) {
        $extraFields .= ' data-constraint="required"';
        $classes['constraint'] = 1;
    }
    if (isset($params['sameas'])) {
        $extraFields .= ' data-constraint="sameas" data-sameas="' . $params['sameas'] . '"';
        $classes['constraint'] = 1;
    }
    if (isset($params['message'])) {
        $messageClause = '" data-message="' . $params['message'] . '"';
    } else {
        $messageClause = '';
    }
    if (isset($params['minlen'])) {
        $extraFields .= ' data-constraint="minlen" data-minlen="' . $params['minlen'] . $messageClause;
        $classes['constraint'] = 1;
    }
    if (isset($params['required'])) {
        $extraFields .= ' data-constraint="required" data-required="true" ' . $messageClause;
        $classes['constraint'] = 1;
    }
    // if(isset($params['requireOther']))
    // {
    // 	$extraSelectFields = array(
    // 		'data-constraint' => 'requireOther',
    // 		'data-other-value' => $params['otherValue'],
    // 		'data-other-field' => $params['otherField']
    // 	);
    // 	$classes['constraint'] = 1;
    // }
    if (isset($params['requireOther'])) {
        $extraFields .= ' data-constraint="requireOther" data-other-value="' . $params['otherValue'] . '" data-other-field="' . $params['otherField'] . '"' . $messageClause;
        $classes['constraint'] = 1;
    }
    if (isset($params['intrange'])) {
        $parts = explode(',', $params['intrange']);
        assert(count($parts) == 2);
        $extraFields .= ' data-constraint="intrange" data-range-min="' . $parts[0] . '" data-range-max="' . $parts[1] . '"' . $messageClause;
        $classes['constraint'] = 1;
    }
    $classClause = 'class="' . implode(' ', array_keys($classes)) . '"';
    $extraFields .= " {$classClause}";
    switch ($type) {
        case 'text':
        case 'submit':
        case 'hidden':
            return '<input type="' . $type . '"' . " {$namePart} {$valuePart} {$extraFields}>";
            break;
        case 'button':
            if (isset($params['href'])) {
                return '<a href="' . $params['href'] . "\" {$extraFields}>" . (isset($params['text']) ? $params['text'] : '') . "</a>";
            } else {
                return "<button {$namePart} {$valuePart} {$extraFields}>" . (isset($params['text']) ? $params['text'] : '') . "</button>";
            }
            break;
        case 'checkbox':
            $checked = $value == 't' ? ' checked' : '';
            $return = '<input value="f" type="hidden"' . " {$namePart} {$extraFields} {$checked}>";
            $return .= '<input value="t" type="' . $type . '"' . " {$namePart} {$extraFields} {$checked}>";
            return $return;
            break;
        case 'password':
            return '<input type="' . $type . '"' . " {$namePart} {$extraFields}>";
            break;
        case 'radio':
            $checked = $valueAtt == $value ? ' checked' : '';
            return '<input type="' . $type . '"' . " {$namePart} {$valuePart} {$extraFields} {$checked}>";
            break;
        case 'textarea':
            $return = '<textarea ' . $namePart . ' ' . $extraFields . '>';
            $return .= $value;
            $return .= '</textarea>';
            return $return;
            break;
        case 'select':
            require_once SMARTY_PLUGINS_DIR . 'function.html_options.php';
            $selectParams['selected'] = $value;
            if (isset($extraMap['option_table']) && $extraMap['option_table']) {
                $nameField = isset($selectParams['name_field']) ? $selectParams['name_field'] : 'name';
                $tableName = $extraMap['option_table'];
                $selectParams['options'] = SqlFetchSimpleMap("SELECT id, :nameField AS name FROM :tableName:identifier order by id", 'id', 'name', array('nameField:identifier' => $nameField, 'tableName' => $tableName));
            } else {
                if ($extraMap['options']) {
                    $selectParams['options'] = $extraMap['options'];
                }
            }
            $markup = '<select' . " {$namePart} {$valuePart} {$extraFields}>";
            $markup .= smarty_function_html_options($selectParams, $smarty);
            $markup .= '</select>';
            return $markup;
            break;
        default:
            trigger_error("unknown input type: {$type}");
            break;
    }
}
コード例 #8
0
ファイル: function.input.php プロジェクト: rgigger/zinc
function smarty_function_input($params, &$smarty)
{
    $type = isset($params['type']) ? $params['type'] : 'text';
    $valueAtt = isset($params['value']) ? $params['value'] : '';
    // handle the data bindings
    if (isset($params['data_object'])) {
        if (!isset($params['data_field'])) {
            trigger_error("gui:input: if you specifiy a data object you must also specify a data field");
        }
        $object = $params['data_object'];
        $field = $params['data_field'];
        if (!isset($params['append']) || $params['append'] == false) {
            if (!isset($smarty->zoop->form)) {
                trigger_error("gui:input: if you specifiy a data object you must first use the 'openform' tag");
            }
            $name = $smarty->zoop->form->addBinding($object, $field);
        } else {
            $binding = new FormBinding($object, $field);
            Form::appendBindings(array($binding));
            $name = $binding->getName();
        }
        $namePart = ' name="' . $name . '"';
        if ($type == 'radio') {
            if (isset($params['default']) && ($object->{$field} === '' || $object->{$field} === NULL)) {
                $value = $params['default'];
            } else {
                $value = $object->{$field};
            }
            $valuePart = ' value="' . $valueAtt . '"';
        } else {
            if (isset($params['default']) && ($object->{$field} === '' || $object->{$field} === NULL)) {
                $value = $params['default'];
            } else {
                $value = isset($params['value']) ? $params['value'] : $object->{$field};
            }
            $valuePart = ' value="' . $value . '"';
        }
    } else {
        $value = $valueAtt;
        $name = isset($params['name']) ? $params['name'] : '';
        $namePart = isset($params['name']) ? ' name="' . $params['name'] . '"' : '';
        $valuePart = isset($params['value']) ? ' value="' . $params['value'] . '"' : '';
    }
    // pass on anything else they put in
    $extraFields = '';
    $extraMap = array();
    foreach ($params as $paramName => $paramValue) {
        // if($paramName == 'name' && !isset($params['id']))
        // 	$params['id'] = $paramValue;
        if (in_array($paramName, array('type', 'name', 'type', 'value', 'default', 'data_object', 'data_field', 'append', 'required'))) {
            continue;
        }
        $extraMap[$paramName] = $paramValue;
        $extraFields .= ' ' . $paramName . '="' . $paramValue . '"';
    }
    $required = isset($params['required']) && $params['required'];
    if ($required && $type != 'checkbox') {
        $extraFields .= ' data-constraint="required" required="required"';
    }
    if (isset($params['sameas'])) {
        $extraFields .= ' data-constraint="sameas" data-sameas="' . $params['sameas'] . '"';
    }
    switch ($type) {
        case 'text':
        case 'submit':
        case 'hidden':
            return '<input type="' . $type . '"' . " {$namePart} {$valuePart} {$extraFields}>";
            break;
        case 'button':
            if (isset($params['href'])) {
                return '<a href="' . $params['href'] . " {$extraFields}>";
            } else {
                return "<button {$namePart} {$valuePart} {$extraFields}>";
            }
            break;
        case 'checkbox':
            $checked = $value == 't' ? ' checked' : '';
            $return = '<input value="f" type="hidden"' . " {$namePart} {$extraFields} {$checked}>";
            $return .= '<input value="t" type="' . $type . '"' . " {$namePart} {$extraFields} {$checked}>";
            return $return;
            break;
        case 'password':
            return '<input type="' . $type . '"' . " {$namePart} {$extraFields}>";
            break;
        case 'radio':
            if (isset($params['data_object'])) {
                $checked = $valueAtt == $value ? ' checked' : '';
            } else {
                $checked = isset($params['checked']) && $params['checked'] ? ' checked' : '';
            }
            return '<input type="' . $type . '"' . " {$namePart} {$valuePart} {$extraFields} {$checked}>";
            break;
        case 'textarea':
            $return = '<textarea ' . $namePart . ' ' . $extraFields . '>';
            $return .= $value;
            $return .= '</textarea>';
            return $return;
            break;
        case 'select':
            require_once $smarty->_get_plugin_filepath('function', 'html_options');
            $selectParams = $extraMap;
            $selectParams['name'] = $name;
            $selectParams['selected'] = $value;
            $nameField = 'name';
            if (isset($extraMap['option_table']) && $extraMap['option_table']) {
                $tableName = $extraMap['option_table'];
                $selectParams['options'] = SqlFetchSimpleMap("SELECT id, :nameField AS name FROM :tableName:identifier order by id", 'id', 'name', array('nameField:identifier' => $nameField, 'tableName' => $tableName));
            } else {
                if ($extraMap['options']) {
                    $selectParams['options'] = $extraMap['options'];
                }
            }
            return smarty_function_html_options($selectParams, $smarty);
            break;
        default:
            trigger_error("unknown input type: {$type}");
            break;
    }
}
コード例 #9
0
ファイル: index.php プロジェクト: rgigger/zinc
<?php

// include('config.php');
define('app_dir', __DIR__);
include dirname(dirname(__DIR__)) . '/framework/Zinc.php';
Zinc::loadLib('app');
Zinc::loadLib('db');
$map = SqlFetchSimpleMap('select * from test', 'one', 'two', array());
echo_r($map);
$rows = SqlFetchRows('select * from test', array());
echo_r($rows);