コード例 #1
0
 function generateAll($f = array())
 {
     global $REX;
     $types = rex_xform::getTypeArray();
     foreach ($this->getTables() as $table) {
         // ********** Table schon vorhanden ?, wenn nein, dann anlegen
         $c = rex_sql::factory();
         // $c->debugsql = 1;
         $c->setQuery('CREATE TABLE IF NOT EXISTS `' . $table["table_name"] . '` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY )');
         // Felder merken, erstellen und eventuell loeschen
         $c->setQuery('SHOW COLUMNS FROM `' . $table["table_name"] . '`');
         $saved_columns = $c->getArray();
         foreach ($this->getTableFields($table["table_name"]) as $field) {
             $type_name = $field["type_name"];
             $type_id = $field["type_id"];
             if ($type_id == "value") {
                 $type_label = $field["f1"];
                 $dbtype = $types[$type_id][$type_name]['dbtype'];
                 if ($dbtype != "none" && $dbtype != "") {
                     // Column schon vorhanden ?
                     $add_column = TRUE;
                     foreach ($saved_columns as $uu => $vv) {
                         if ($vv["Field"] == $type_label) {
                             $add_column = FALSE;
                             unset($saved_columns[$uu]);
                             break;
                         }
                     }
                     // Column erstellen
                     if ($add_column) {
                         $c->setQuery('ALTER TABLE `' . $table["table_name"] . '` ADD `' . $type_label . '` ' . $dbtype);
                     }
                 }
             }
         }
         if (isset($f["delete_fields"]) && $f["delete_fields"] === TRUE) {
             foreach ($saved_columns as $uu => $vv) {
                 if ($vv["Field"] != "id") {
                     $c->setQuery('ALTER TABLE `' . $table["table_name"] . '` DROP `' . $vv["Field"] . '` ');
                 }
             }
         }
     }
 }
コード例 #2
0
<?php

// ********************************************* TABLE ADD/EDIT/LIST
$table = $REX['TABLE_PREFIX'] . 'em_table';
$table_field = $REX['TABLE_PREFIX'] . 'em_field';
$bezeichner = "Tabelle";
$func = rex_request("func", "string", "");
$page = rex_request("page", "string", "");
$subpage = rex_request("subpage", "string", "");
$table_id = rex_request("table_id", "int");
$show_list = TRUE;
// ********************************************* FORMULAR
if ($func == "add" || $func == "edit") {
    $xform = new rex_xform();
    // $xform->setDebug(TRUE);
    $xform->setHiddenField("page", $page);
    $xform->setHiddenField("subpage", $subpage);
    $xform->setHiddenField("func", $func);
    $xform->setActionField("showtext", array("", "Vielen Dank fuer die Eintragung"));
    $xform->setObjectparams("main_table", $table);
    // für db speicherungen und unique abfragen
    $xform->setValueField("text", array("prio", "Priorit&auml;t"));
    if ($func == "edit") {
        $xform->setValueField("showvalue", array("table_name", "Name"));
        $xform->setHiddenField("table_id", $table_id);
        $xform->setActionField("db", array($table, "id={$table_id}"));
        $xform->setObjectparams("main_id", $table_id);
        $xform->setObjectparams("main_where", "id={$table_id}");
        $xform->setObjectparams('getdata', true);
        // Datein vorher auslesen
    } elseif ($func == "add") {
コード例 #3
0
    if (isset($types['action'])) {
        ksort($types['action']);
        foreach ($types['action'] as $k => $v) {
            echo '<p class="rex-button">"<a href="' . $link . 'type_id=action&type_name=' . $k . '">' . $k . '</a>" - ' . $v['description'] . '</p>';
        }
    }
    ?>
</p>
</div>
</div>

<?php 
}
// ********************************************* FORMULAR
if (($func == "add" || $func == "edit") && isset($types[$type_id][$type_name])) {
    $xform = new rex_xform();
    // $xform->setDebug(TRUE);
    foreach ($this->getLinkVars() as $k => $v) {
        $xform->setHiddenField($k, $v);
    }
    $xform->setHiddenField("func", $func);
    $xform->setHiddenField("table_name", $table["table_name"]);
    $xform->setValueField("hidden", array("table_name", $table["table_name"]));
    $xform->setValueField("hidden", array("type_name", $type_name, "REQUEST"));
    $xform->setValueField("hidden", array("type_id", $type_id, "REQUEST"));
    $xform->setValueField("text", array("prio", "Prioritaet"));
    $i = 0;
    foreach ($types[$type_id][$type_name]['values'] as $v) {
        $i++;
        switch ($v['type']) {
            case "name":
コード例 #4
0
    function getFieldPage()
    {
        global $REX, $I18N;
        // ********************************************* FIELD ADD/EDIT/LIST
        $func = rex_request('func', 'string', 'list');
        $page = rex_request('page', 'string', '');
        $subpage = rex_request('subpage', 'string', '');
        $tripage = rex_request('tripage', 'string', '');
        $type_id = rex_request('type_id', 'string');
        $type_name = rex_request('type_name', 'string');
        $field_id = rex_request('field_id', 'int');
        $show_list = true;
        $link_vars = '';
        foreach ($this->getLinkVars() as $k => $v) {
            $link_vars .= '&' . urlencode($k) . '=' . urlencode($v);
        }
        $TYPE = array('value' => $I18N->msg('xform_values'), 'validate' => $I18N->msg('xform_validates'), 'action' => $I18N->msg('xform_action'));
        // ********************************** TABELLE HOLEN
        $table = $this->table;
        $table_info = '<b>' . rex_translate($table->getName()) . ' [' . $table->getTableName() . ']</b> ';
        echo rex_content_block($table_info);
        // ********************************************* Missing Fields
        $mfields = $table->getMissingFields();
        // ksort($mfields);
        $type_real_field = rex_request('type_real_field', 'string');
        if ($type_real_field != '' && !array_key_exists($type_real_field, $mfields)) {
            $type_real_field = '';
        }
        if ($type_real_field != '') {
            ?>
            <div class="rex-addon-output"><h2 class="rex-hl2">Folgendes Feld wird verwendet: <?php 
            echo $type_real_field;
            ?>
</h2><div class="rex-addon-content"><p class="rex-tx1"><?php 
            $rfields = $this->table->getColumns();
            foreach ($rfields[$type_real_field] as $k => $v) {
                echo '<b>' . $k . ':</b> ' . $v . '<br />';
            }
            ?>
</p></div></div><?php 
        }
        // ********************************************* CHOOSE FIELD
        $types = rex_xform::getTypeArray();
        if ($func == 'choosenadd') {
            // type and choose !!
            $link = 'index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=add&';
            if (!$table->hasId()) {
                ?>
                <div class="rex-addon-output" id="xform-choosenadd"><h2 class="rex-hl2"><?php 
                echo $I18N->msg('xform_id_is_missing');
                ?>
</h2><div class="rex-addon-content">
                        <p class="rex-tx1"><?php 
                echo $I18N->msg('xform_id_missing_info');
                ?>
</p>
                    </div></div>
            <?php 
            } else {
                ?>
                <div class="rex-addon-output" id="xform-choosenadd"><h2 class="rex-hl2"><?php 
                echo $I18N->msg('xform_choosenadd');
                ?>
</h2><div class="rex-addon-content">
                        <p class="rex-tx1"><?php 
                echo $I18N->msg('xform_choosenadd_description');
                ?>
</p>
                    </div></div>
                <?php 
                if ($type_real_field == '' && count($mfields) > 0) {
                    ?>
                    <div class="rex-addon-output"><h2 class="rex-hl2">Es gibt noch Felder in der Tabelle welche nicht zugewiesen sind.</h2><div class="rex-addon-content">
                            <?php 
                    $d = 0;
                    foreach ($mfields as $k => $v) {
                        $d++;
                        $l = 'index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=choosenadd&type_real_field=' . $k . '&type_layout=t';
                        echo '<a href="' . $l . '">' . $k . '</a>, ';
                    }
                    ?>
</div></div>

                <?php 
                }
                ?>


                <div class="rex-addon-output xform-table_field">
                    <div class="rex-area-col-2">

                        <div class="rex-area-col-a">
                            <h3 class="rex-hl2">beliebte <?php 
                echo $TYPE['value'];
                ?>
</h3>
                            <div class="rex-area-content"><p class="rex-tx1"><?php 
                if (isset($types['value'])) {
                    ksort($types['value']);
                    foreach ($types['value'] as $k => $v) {
                        if (isset($v['famous']) && $v['famous']) {
                            echo '<p class="rex-button"><a class="rex-button" href="' . $link . 'type_id=value&type_name=' . $k . '&type_real_field=' . $type_real_field . '">' . $k . '</a> <span>' . $v['description'] . '</span></p>';
                        }
                    }
                }
                ?>
</p></div></div>

                        <div class="rex-area-col-b"><h3 class="rex-hl2">beliebte <?php 
                echo $TYPE['validate'];
                ?>
</h3><div class="rex-area-content"><p class="rex-tx1"><?php 
                if (isset($types['validate'])) {
                    ksort($types['validate']);
                    foreach ($types['validate'] as $k => $v) {
                        if (isset($v['famous']) && $v['famous']) {
                            echo '<p class="rex-button"><a class="rex-button" href="' . $link . 'type_id=validate&type_name=' . $k . '">' . $k . '</a> <span>' . $v['description'] . '</span></p>';
                        }
                    }
                }
                ?>
</p></div></div>

                    </div></div>

                <div class="rex-addon-output xform-table_field">
                    <div class="rex-area-col-2">

                        <div class="rex-area-col-a"><h3 class="rex-hl2"><?php 
                echo $TYPE['value'];
                ?>
</h3><div class="rex-area-content"><p class="rex-tx1"><?php 
                if (isset($types['value'])) {
                    ksort($types['value']);
                    foreach ($types['value'] as $k => $v) {
                        if (!isset($v['famous']) || $v['famous'] !== true) {
                            echo '<p class="rex-button"><a class="rex-button" href="' . $link . 'type_id=value&type_name=' . $k . '&type_real_field=' . $type_real_field . '">' . $k . '</a> <span>' . $v['description'] . '</span></p>';
                        }
                    }
                }
                ?>
</p></div></div>

                        <div class="rex-area-col-b"><h3 class="rex-hl2"><?php 
                echo $TYPE['validate'];
                ?>
</h3><div class="rex-area-content"><p class="rex-tx1"><?php 
                if (isset($types['validate'])) {
                    ksort($types['validate']);
                    foreach ($types['validate'] as $k => $v) {
                        if (!isset($v['famous']) || $v['famous'] !== true) {
                            echo '<p class="rex-button"><a class="rex-button" href="' . $link . 'type_id=validate&type_name=' . $k . '">' . $k . '</a> <span>' . $v['description'] . '</span></p>';
                        }
                    }
                }
                ?>
</p></div></div>

                    </div></div>

                <!--
             <div class="rex-addon-output">
             <h2 class="rex-hl2"><?php 
                echo $TYPE['action'];
                ?>
</h2>
             <div class="rex-addon-content">
             <p class="rex-tx1"><?php 
                if (isset($types['action'])) {
                    ksort($types['action']);
                    foreach ($types['action'] as $k => $v) {
                        echo '<p class="rex-button">"<a href="' . $link . 'type_id=action&type_name=' . $k . '">' . $k . '</a>" - ' . $v['description'] . '</p>';
                    }
                }
                ?>
</p>
             </div>
             </div>
             -->

            <?php 
            }
            $table_echo = '<a href="index.php?' . $link_vars . '&amp;table_name=' . $table->getTableName() . '"><b>&laquo; ' . $I18N->msg('xform_back_to_overview') . '</b></a>';
            echo rex_content_block($table_echo);
        }
        // ********************************************* FORMULAR
        if (($func == 'add' || $func == 'edit') && isset($types[$type_id][$type_name])) {
            $xform = new rex_xform();
            $xform->setDebug(false);
            foreach ($this->getLinkVars() as $k => $v) {
                $xform->setHiddenField($k, $v);
            }
            $xform->setHiddenField('func', $func);
            $xform->setHiddenField('table_name', $table->getTableName());
            $xform->setHiddenField('type_real_field', $type_real_field);
            $xform->setHiddenField('list', rex_request('list', 'string'));
            $xform->setHiddenField('sort', rex_request('sort', 'string'));
            $xform->setHiddenField('sorttype', rex_request('sorttype', 'string'));
            $xform->setHiddenField('start', rex_request('start', 'string'));
            $xform->setValueField('hidden', array('table_name', $table->getTableName()));
            $xform->setValueField('hidden', array('type_name', $type_name, 'REQUEST'));
            $xform->setValueField('hidden', array('type_id', $type_id, 'REQUEST'));
            $xform->setValueField('prio', array('prio', 'Prioritaet', array('name', 'type_id', 'type_name'), array('table_name')));
            $selectFields = array();
            $i = 1;
            foreach ($types[$type_id][$type_name]['values'] as $k => $v) {
                $field = $this->getFieldName($k, $type_id);
                $selectFields['f' . $i] = $field;
                $i++;
                switch ($v['type']) {
                    case 'name':
                        if ($func == 'edit') {
                            $xform->setValueField('showvalue', array($field, 'Name'));
                        } else {
                            if (!isset($v['value']) && $type_real_field != '') {
                                $v['value'] = $type_real_field;
                            } elseif (!isset($v['value'])) {
                                $v['value'] = '';
                            }
                            $xform->setValueField('text', array($field, 'Name', $v['value']));
                            $xform->setValidateField('notEmpty', array($field, $I18N->msg('xform_validatenamenotempty')));
                            $xform->setValidateField('preg_match', array($field, "/(([a-zA-Z])+([a-zA-Z0-9\\_])*)/", $I18N->msg('xform_validatenamepregmatch')));
                            $xform->setValidateField('customfunction', array($field, 'rex_xform_manager_checkField', array('table_name' => $table->getTableName()), $I18N->msg('xform_validatenamecheck')));
                        }
                        break;
                    case 'no_db':
                        if (!isset($v['default']) || $v['default'] != 1) {
                            $v['default'] = 0;
                        }
                        $xform->setValueField('checkbox', array($field, $I18N->msg('xform_donotsaveindb'), 'no_db', $v['default']));
                        break;
                    case 'boolean':
                        // checkbox|check_design|Bezeichnung|Value|1/0|[no_db]
                        if (!isset($v['default'])) {
                            $v['default'] = '';
                        }
                        $xform->setValueField('checkbox', array($field, $v['label'], '', $v['default']));
                        break;
                    case 'select':
                        // select|gender|Geschlecht *|Frau=w;Herr=m|[no_db]|defaultwert|multiple=1
                        $xform->setValueField('select', array($field, $v['label'], $v['options'], '', $v['default'], 0));
                        break;
                    case 'table':
                        // ist fest eingetragen, damit keine Dinge durcheinandergehen
                        if ($func == 'edit') {
                            $xform->setValueField('showvalue', array($field, $v['label']));
                        } else {
                            $_tables = rex_xform_manager_table::getAll();
                            $_options = array();
                            if (isset($v['empty_option']) && $v['empty_option']) {
                                $_options[0] = '–=';
                            }
                            foreach ($_tables as $_table) {
                                $_options[$_table['table_name']] = str_replace('=', '-', rex_translate($_table['name']) . ' [' . $_table['table_name'] . ']') . '=' . $_table['table_name'];
                                $_options[$_table['table_name']] = str_replace(',', '.', $_options[$_table['table_name']]);
                            }
                            if (!isset($v['default'])) {
                                $v['default'] = '';
                            }
                            $xform->setValueField('select', array($field, $v['label'], implode(',', $_options), '', $v['default'], 0));
                        }
                        break;
                    case 'textarea':
                        $xform->setValueField('textarea', array($field, $v['label']));
                        break;
                    case 'table.field':
                        // Todo:
                    // Todo:
                    case 'select_name':
                        $_fields = array();
                        foreach ($table->getValueFields() as $_k => $_v) {
                            $_fields[] = $_k;
                        }
                        $xform->setValueField('select', array($field, $v['label'], implode(',', $_fields), '', '', 0));
                        break;
                    case 'select_names':
                        $_fields = array();
                        foreach ($table->getValueFields() as $_k => $_v) {
                            $_fields[] = $_k;
                        }
                        $xform->setValueField('select', array($field, $v['label'], implode(',', $_fields), '', '', 1, 5));
                        break;
                    default:
                        // nur beim "Bezeichnungsfeld"
                        if ($field == 'label' && $type_real_field != '' && !isset($v['value'])) {
                            $v['value'] = $type_real_field;
                        } elseif (!isset($v['value'])) {
                            $v['value'] = '';
                        }
                        $xform->setValueField('text', array($field, $v['label'], $v['value']));
                }
            }
            $xform->setActionField('showtext', array('', '<p>' . $I18N->msg('xform_thankyouforentry') . '</p>'));
            $xform->setObjectparams('main_table', rex_xform_manager_field::table());
            if ($func == 'edit') {
                $xform->setObjectparams('submit_btn_label', $I18N->msg('xform_save'));
                $xform->setHiddenField('field_id', $field_id);
                $xform->setActionField('manage_db', array(rex_xform_manager_field::table(), "id={$field_id}"));
                $xform->setObjectparams('main_id', $field_id);
                $xform->setObjectparams('main_where', "id={$field_id}");
                $sql = rex_sql::factory();
                $sql->setQuery('SELECT * FROM ' . rex_xform_manager_field::table() . " WHERE id={$field_id}");
                foreach ($selectFields as $alias => $field) {
                    if ($alias != $field) {
                        if ((!$sql->hasValue($field) || null === $sql->getValue($field) || '' === $sql->getValue($field)) && $sql->hasValue($alias)) {
                            $sql->setValue($field, $sql->getValue($alias));
                        }
                        $xform->setValueField('hidden', array($alias, ''));
                    }
                }
                $xform->setObjectparams('sql_object', $sql);
                $xform->setObjectparams('getdata', true);
            } elseif ($func == 'add') {
                $xform->setObjectparams('submit_btn_label', $I18N->msg('xform_add'));
                $xform->setActionField('manage_db', array(rex_xform_manager_field::table()));
            }
            if ($type_id == 'value') {
                $xform->setValueField('checkbox', array('list_hidden', $I18N->msg('xform_hideinlist'), 1, '1'));
                $xform->setValueField('checkbox', array('search', $I18N->msg('xform_useassearchfieldalidatenamenotempty'), 1, '1'));
            } elseif ($type_id == 'validate') {
                $xform->setValueField('hidden', array('list_hidden', 1));
            }
            $form = $xform->getForm();
            if ($xform->objparams['form_show']) {
                if ($func == 'add') {
                    echo '<div class="rex-addon-output"><h3 class="rex-hl2">' . $I18N->msg('xform_addfield') . ' "' . $type_name . '"</h3><div class="rex-addon-content">';
                } else {
                    echo '<div class="rex-addon-output"><h3 class="rex-hl2">' . $I18N->msg('xform_editfield') . ' "' . $type_name . '"</h3><div class="rex-addon-content">';
                }
                echo $form;
                echo '</div></div>';
                $table_echo = '<a href="index.php?' . $link_vars . '&amp;table_name=' . $table->getTableName() . '"><b>&laquo; ' . $I18N->msg('xform_back_to_overview') . '</b></a>';
                echo rex_content_block($table_echo);
                $func = '';
            } else {
                if ($func == 'edit') {
                    $this->generateAll();
                    echo rex_info($I18N->msg('xform_thankyouforupdate'));
                } elseif ($func == 'add') {
                    $this->generateAll();
                    echo rex_info($I18N->msg('xform_thankyouforentry'));
                }
                $func = 'list';
            }
        }
        // ********************************************* LOESCHEN
        if ($func == 'delete') {
            $sf = new rex_sql();
            $sf->debugsql = self::$debug;
            $sf->setQuery('select * from ' . rex_xform_manager_field::table() . ' where table_name="' . $table->getTableName() . '" and id=' . $field_id);
            $sfa = $sf->getArray();
            if (count($sfa) == 1) {
                $query = 'delete from ' . rex_xform_manager_field::table() . ' where table_name="' . $table->getTableName() . '" and id=' . $field_id;
                $delsql = new rex_sql();
                $delsql->debugsql = self::$debug;
                $delsql->setQuery($query);
                echo rex_info($I18N->msg('xform_tablefielddeleted'));
                $this->generateAll();
            } else {
                echo rex_warning($I18N->msg('xform_tablefieldnotfound'));
            }
            $func = 'list';
        }
        // ********************************************* CREATE/UPDATE FIELDS
        if ($func == 'updatetable') {
            $this->generateAll();
            echo rex_info($I18N->msg('xform_tablesupdated'));
            $func = 'list';
        }
        if ($func == 'updatetablewithdelete') {
            $this->generateAll(array('delete_fields' => true));
            echo rex_info($I18N->msg('xform_tablesupdated'));
            $func = 'list';
        }
        if ($func == 'show_form_notation') {
            $formbuilder_fields = $table->getFields();
            $notation_php = '';
            $notation_pipe = '';
            $notation_email = '';
            $notation_php_pre = array('$xform = new rex_xform();', '$xform->setObjectparams(\'form_skin\', \'default\');', '$xform->setObjectparams(\'form_showformafterupdate\', 0);', '$xform->setObjectparams(\'real_field_names\', true);');
            $notation_php .= implode("\n", $notation_php_pre) . "\n";
            $notation_pipe_pre = array('objparams|form_skin|default', 'objparams|form_showformafterupdate|0', 'objparams|real_field_names|true');
            $notation_pipe .= implode("\n", $notation_pipe_pre) . "\n";
            foreach ($formbuilder_fields as $field) {
                $classname = rex_xform::includeClass($field['type_id'], $field['type_name']);
                $cl = new $classname();
                $definitions = $cl->getDefinitions();
                $values = array();
                $i = 1;
                foreach ($definitions['values'] as $key => $_) {
                    $key = $this->getFieldName($key, $field['type_id']);
                    if (isset($field[$key])) {
                        $values[] = $field[$key];
                    } elseif (isset($field['f' . $i])) {
                        $values[] = $field['f' . $i];
                    } else {
                        $values[] = '';
                    }
                    $i++;
                }
                if ($field['type_id'] == 'value') {
                    $notation_php .= "\n" . '$xform->setValueField(\'' . $field['type_name'] . '\', array("' . rtrim(implode('","', $values), '","') . '"));';
                    $notation_pipe .= "\n" . $field['type_name'] . '|' . rtrim(implode('|', $values), '|') . '|';
                    $notation_email .= "\n" . $field['label'] . ': ###' . $field['name'] . '###';
                } elseif ($field['type_id'] == 'validate') {
                    $notation_php .= "\n" . '$xform->setValidateField(\'' . $field['type_name'] . '\', array("' . rtrim(implode('","', $values), '","') . '"));';
                    $notation_pipe .= "\n" . $field['type_id'] . '|' . $field['type_name'] . '|' . rtrim(implode('|', $values), '|') . '|';
                } elseif ($field['type_id'] == 'action') {
                    $notation_php .= "\n" . '$xform->setActionField(\'' . $field['type_name'] . '\', array("' . rtrim(implode('","', $values), '","') . '"));';
                    $notation_pipe .= "\n" . $field['type_id'] . '|' . $field['type_name'] . '|' . rtrim(implode('|', $values), '|') . '|';
                }
            }
            $notation_php .= "\n\n" . '$xform->setActionField(\'db2email\', array(\'emailtemplate\', \'emaillabel\', \'email@domain.de\'));';
            $notation_php .= "\n" . 'echo $xform->getForm();';
            $notation_pipe .= "\n\n" . 'action|db2email|emailtemplate|emaillabel|email@domain.de';
            echo '<div class="rex-addon-output">';
            echo '<h2 class="rex-hl2">PHP</h2>';
            echo '<div class="rex-addon-content">';
            echo '<pre class="rex-code"><code>' . $notation_php . '</code></pre>';
            echo '</div></div>';
            echo '<div class="rex-addon-output">';
            echo '<h2 class="rex-hl2">Pipe</h2>';
            echo '<div class="rex-addon-content">';
            echo '<pre class="rex-code"><code>' . $notation_pipe . '</code></pre>';
            echo '</div></div>';
            echo '<div class="rex-addon-output">';
            echo '<h2 class="rex-hl2">E-Mail</h2>';
            echo '<div class="rex-addon-content">';
            echo '<pre class="rex-code"><code>' . $notation_email . '</code></pre>';
            echo '</div></div>';
            $func = 'list';
        }
        // ********************************************* LIST
        if ($func == 'list') {
            // ****** EP XFORM_MANAGER_TABLE_FIELD_FUNC
            $show_list = true;
            $show_list = rex_register_extension_point('XFORM_MANAGER_TABLE_FIELD_FUNC', $show_list, array('table' => $table, 'link_vars' => $this->getLinkVars()));
            if ($show_list) {
                function rex_xform_list_format($p, $value = '')
                {
                    if ($value != '') {
                        $p['value'] = $value;
                    }
                    switch ($p['list']->getValue('type_id')) {
                        case 'validate':
                            $style = 'color:#aaa;';
                            // background-color:#cfd9d9;
                            break;
                        case 'action':
                            $style = 'background-color:#cfd9d9;';
                            break;
                        default:
                            $style = 'background-color:#eff9f9;';
                            break;
                    }
                    return '<td style="' . $style . '">' . $p['value'] . '</td>';
                }
                function rex_xform_list_edit_format($p)
                {
                    global $REX, $I18N;
                    return rex_xform_list_format($p, $p['list']->getColumnLink($I18N->msg('xform_edit'), $I18N->msg('xform_edit')));
                }
                function rex_xform_list_delete_format($p)
                {
                    global $REX, $I18N;
                    return rex_xform_list_format($p, $p['list']->getColumnLink($I18N->msg('xform_delete'), $I18N->msg('xform_delete')));
                }
                $table_echo = '
                     <div class="rex-area-col-2">
                             <div class="rex-area-col-a">
                                     <a href="index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=choosenadd"><b>+ ' . $I18N->msg('xform_addtablefield') . '</b></a>
                             </div>
                             <div class="rex-area-col-b rex-algn-rght">
                                <ul class="rex-navi-piped">
                                    <li><a href="index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=show_form_notation">' . $I18N->msg('xform_manager_show_form_notation') . '</a></li><li><a href="index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=updatetable">' . $I18N->msg('xform_updatetable') . '</a></li><li><a href="index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=updatetablewithdelete" onclick="return confirm(\'' . $I18N->msg('xform_updatetable_with_delete_confirm') . '\')">' . $I18N->msg('xform_updatetable_with_delete') . '</a></li>
                                </ul>
                             </div>
                     </div>
                     <div class="rex-clearer"></div>
                     ';
                echo rex_content_block($table_echo);
                $sql = 'select id, prio, type_id, type_name, name from ' . rex_xform_manager_field::table() . ' where table_name="' . $table->getTableName() . '" order by prio';
                $list = rex_list::factory($sql, 30);
                // $list->debug = 1;
                $list->setColumnFormat('id', 'Id');
                foreach ($this->getLinkVars() as $k => $v) {
                    $list->addParam($k, $v);
                }
                $list->addParam('start', rex_request('start', 'int'));
                $list->addParam('table_name', $table->getTableName());
                $list->removeColumn('id');
                $list->setColumnLabel('prio', $I18N->msg('xform_manager_table_prio_short'));
                $list->setColumnLabel('type_id', $I18N->msg('xform_manager_type_id'));
                $list->setColumnLabel('type_name', $I18N->msg('xform_manager_type_name'));
                $list->setColumnLabel('name', $I18N->msg('xform_manager_name'));
                $list->setColumnLayout('prio', array('<th>###VALUE###</th>', '###VALUE###'));
                $list->setColumnFormat('prio', 'custom', 'rex_xform_list_format');
                $list->setColumnLayout('type_id', array('<th>###VALUE###</th>', '###VALUE###'));
                $list->setColumnFormat('type_id', 'custom', 'rex_xform_list_format');
                $list->setColumnLayout('type_name', array('<th>###VALUE###</th>', '###VALUE###'));
                $list->setColumnFormat('type_name', 'custom', 'rex_xform_list_format');
                $list->setColumnLayout('name', array('<th>###VALUE###</th>', '###VALUE###'));
                // ###VALUE###
                $list->setColumnFormat('name', 'custom', 'rex_xform_list_format');
                $list->addColumn($I18N->msg('xform_edit'), $I18N->msg('xform_edit'));
                $list->setColumnParams($I18N->msg('xform_edit'), array('field_id' => '###id###', 'func' => 'edit', 'type_name' => '###type_name###', 'type_id' => '###type_id###'));
                $list->setColumnLayout($I18N->msg('xform_edit'), array('<th>###VALUE###</th>', '###VALUE###'));
                $list->setColumnFormat($I18N->msg('xform_edit'), 'custom', 'rex_xform_list_edit_format');
                $list->addColumn($I18N->msg('xform_delete'), $I18N->msg('xform_delete'));
                $list->setColumnParams($I18N->msg('xform_delete'), array('field_id' => '###id###', 'func' => 'delete'));
                $list->setColumnLayout($I18N->msg('xform_delete'), array('<th>###VALUE###</th>', '###VALUE###'));
                $list->setColumnFormat($I18N->msg('xform_delete'), 'custom', 'rex_xform_list_delete_format');
                $list->addLinkAttribute($I18N->msg('xform_delete'), 'onclick', 'return confirm(\' [###type_id###, ###type_name###, ###name###] ' . $I18N->msg('xform_delete') . ' ?\')');
                echo $list->get();
            }
        }
    }
コード例 #5
0
/**
 * XForm
 * @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
 * @author <a href="http://www.yakamara.de">www.yakamara.de</a>
 */
// ********************************************* TABLE ADD/EDIT/LIST
$table = $REX['TABLE_PREFIX'] . 'xform_table';
$table_field = $REX['TABLE_PREFIX'] . 'xform_field';
$func = rex_request('func', 'string', '');
$page = rex_request('page', 'string', '');
$subpage = rex_request('subpage', 'string', '');
$table_id = rex_request('table_id', 'int');
$show_list = true;
// ********************************************* FORMULAR
if (($func == 'add' || $func == 'edit') && $REX['USER']->isAdmin()) {
    $xform = new rex_xform();
    // $xform->setDebug(TRUE);
    $xform->setHiddenField('page', $page);
    $xform->setHiddenField('subpage', $subpage);
    $xform->setHiddenField('func', $func);
    $xform->setActionField('showtext', array('', $I18N->msg('xform_manager_table_entry_saved')));
    $xform->setObjectparams('main_table', $table);
    $xform->setValueField('text', array('prio', $I18N->msg('xform_manager_table_prio')));
    if ($func == 'edit') {
        $xform->setObjectparams('submit_btn_label', $I18N->msg('save'));
        $xform->setValueField('showvalue', array('table_name', $I18N->msg('xform_manager_table_name')));
        $xform->setHiddenField('table_id', $table_id);
        $xform->setActionField('db', array($table, "id={$table_id}"));
        $xform->setObjectparams('main_id', $table_id);
        $xform->setObjectparams('main_where', "id={$table_id}");
        $xform->setObjectparams('getdata', true);
 static function generateTablesAndFields($delete_old = false)
 {
     rex_xform_manager_table::reload();
     $types = rex_xform::getTypeArray();
     foreach (rex_xform_manager_table::getAll() as $table) {
         $c = rex_sql::factory();
         $c->debugsql = self::$debug;
         $c->setQuery('CREATE TABLE IF NOT EXISTS `' . $table['table_name'] . '` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY )');
         // remember fields, create and in case delete
         $c->setQuery('SHOW COLUMNS FROM `' . $table['table_name'] . '`');
         $saved_columns = $c->getArray();
         foreach ($table->getFields() as $field) {
             $type_name = $field['type_name'];
             $type_id = $field['type_id'];
             if ($type_id == 'value') {
                 $type_label = $field['name'];
                 $dbtype = $types[$type_id][$type_name]['dbtype'];
                 if ($dbtype != 'none' && $dbtype != '') {
                     if (isset($types[$type_id][$type_name]['hooks']['preCreate'])) {
                         $result = call_user_func($types[$type_id][$type_name]['hooks']['preCreate'], $field);
                         if (false === $result) {
                             continue;
                         } elseif (is_string($result)) {
                             $dbtype = $result;
                         }
                     }
                     $add_column = true;
                     foreach ($saved_columns as $uu => $vv) {
                         if ($vv['Field'] == $type_label) {
                             $add_column = false;
                             unset($saved_columns[$uu]);
                             break;
                         }
                     }
                     if ($add_column) {
                         $null = isset($types[$type_id][$type_name]['null']) && $types[$type_id][$type_name]['null'];
                         $null = $null ? '' : ' NOT NULL';
                         $c->setQuery('ALTER TABLE `' . $table['table_name'] . '` ADD `' . $type_label . '` ' . $dbtype . $null);
                     }
                 }
             }
         }
         if ($delete_old === true) {
             foreach ($saved_columns as $uu => $vv) {
                 if ($vv['Field'] != 'id') {
                     $c->setQuery('ALTER TABLE `' . $table['table_name'] . '` DROP `' . $vv['Field'] . '` ');
                 }
             }
         }
     }
 }
コード例 #7
0
         echo rex_content_block('<a href="index.php?page=' . $page . '&amp;subpage=' . $subpage . '"><b>&laquo; ' . $I18N->msg('xform_back_to_overview') . '</b></a>');
         $show_list = false;
     } else {
         $table_name = $xform->objparams['value_pool']['sql']['table_name'];
         $convert_id = $xform->objparams['value_pool']['sql']['convert_id'];
         try {
             rex_xform_manager_table_api::migrateTable($table_name, $convert_id);
             // with convert id / auto_increment finder
             echo rex_info($I18N->msg('xform_manager_table_migrated_success'));
         } catch (Exception $e) {
             echo rex_warning($I18N->msg('xform_manager_table_migrated_failed', $table_name, $e->getMessage()));
         }
     }
 } else {
     if (($func == 'add' || $func == 'edit') && $REX['USER']->isAdmin()) {
         $xform = new rex_xform();
         // $xform->setDebug(TRUE);
         $xform->setHiddenField('page', $page);
         $xform->setHiddenField('subpage', $subpage);
         $xform->setHiddenField('func', $func);
         $xform->setHiddenField('list', rex_request('list', 'string'));
         $xform->setHiddenField('sort', rex_request('sort', 'string'));
         $xform->setHiddenField('sorttype', rex_request('sorttype', 'string'));
         $xform->setHiddenField('start', rex_request('start', 'string'));
         $xform->setActionField('showtext', array('', $I18N->msg('xform_manager_table_entry_saved')));
         $xform->setObjectparams('main_table', rex_xform_manager_table::table());
         $xform->setValueField('prio', array('prio', $I18N->msg('xform_manager_table_prio'), 'name'));
         if ($func == 'edit') {
             $xform->setObjectparams('submit_btn_label', $I18N->msg('xform_save'));
             $xform->setValueField('showvalue', array('table_name', $I18N->msg('xform_manager_table_name')));
             $xform->setHiddenField('table_id', $table_id);
コード例 #8
0
	<h2 class="rex-hl2">Beschreibung</h2>
	<div class="rex-addon-content">
	<p>
	
	Im Modul sind vor allem die Felddefinitionen wichtig, die sich in 3 Bereiche
	aufteilen.
	
	<br /><br /><b>Value Felder</b> - Das sind die Felder die im Formular normalerweise
	direkt auftauchen. Das können einerseits einfache Textfelder, Selectfelder,
	Checkboxen etc. sein, aber genauso auch Versteckte Felder, Geburtsdatum, 
	Datenbankselectfelder etc. sein.
	
	<br /><br /><b>Validate Felder</b> - sind Felder zum überprüfen der Werte in den Value
	Felder. D.h. damit kann man z.B. überprüfen ob ein Wert eingetragen worden 
	ist (notEmpty) oder ob es ein String, Integer oder sonstiges Feld ist. Genauso
	kann aber auch überprüft werden ob ein Datenbankfeld mit diesem Wert schon
	existiert etc.
	
	<br /><br /><b>Action Felder</b> - sind für die späteren Verwendungen wichtig. Soll
	eine E-Mail verschickt werden und/oder ein Eintrag in die Datenbank geschehen...

	<br /><br />

	</p>
	<hr />
<?php 
rex_xform::showHelp();
?>
	</div>
</div>
コード例 #9
0
$table = 'rex_xform_table';
$table_field = 'rex_xform_field';
$func = rex_request("func", "string", "");
$page = rex_request("page", "string", "");
$subpage = rex_request("subpage", "string", "");
$table_id = rex_request("table_id", "int");
$show_list = TRUE;
if ($func == "update" && $REX['USER']->isAdmin()) {
    $t = new rex_xform_manager();
    $t->generateAll();
    echo rex_info($I18N->msg("xform_manager_table_updated"));
    $func = "";
}
// ********************************************* FORMULAR
if (($func == "add" || $func == "edit") && $REX['USER']->isAdmin()) {
    $xform = new rex_xform();
    // $xform->setDebug(TRUE);
    $xform->setHiddenField("page", $page);
    $xform->setHiddenField("subpage", $subpage);
    $xform->setHiddenField("func", $func);
    $xform->setActionField("showtext", array("", $I18N->msg("xform_manager_table_entry_saved")));
    $xform->setObjectparams("main_table", $table);
    // fŸr db speicherungen und unique abfragen
    $xform->setValueField("text", array("prio", $I18N->msg("xform_manager_table_prio")));
    if ($func == "edit") {
        $xform->setValueField("showvalue", array("table_name", "Name"));
        $xform->setHiddenField("table_id", $table_id);
        $xform->setActionField("db", array($table, "id={$table_id}"));
        $xform->setObjectparams("main_id", $table_id);
        $xform->setObjectparams("main_where", "id={$table_id}");
        $xform->setObjectparams('getdata', true);
コード例 #10
0
<?php

rex_title("XForm", $REX['ADDON'][$page]['SUBPAGES']);
echo '<div class="rex-addon-output">
	<h2 class="rex-hl2">Beschreibung</h2>
	<div class="rex-addon-content">
	<div class="xform-description">' . $I18N->msg('xform_description_all') . '</div>';
echo rex_xform::showHelp(true, true);
echo '
	</div>
</div>';
コード例 #11
0
 function getQueryFilterArray()
 {
     if (!$this->table->isSearchable()) {
         return array();
     }
     $queryFilter = array();
     $vars = $this->getSearchVars();
     foreach ($this->table->getFields() as $field) {
         if (array_key_exists($field->getName(), $vars['rex_xform_searchvars']) && $field->getType() == 'value' && $field->isSearchable()) {
             rex_xform::includeClass($field->getType(), $field->getTypeName());
             if (method_exists('rex_xform_' . $field->getTypeName(), 'getSearchFilter')) {
                 $qf = call_user_func('rex_xform_' . $field->getTypeName() . '::getSearchFilter', array('field' => $field, 'fields' => $this->table->getFields(), 'value' => $vars['rex_xform_searchvars'][$field->getName()]));
                 if ($qf != '') {
                     $queryFilter[] = $qf;
                 }
             }
         }
     }
     return $queryFilter;
 }
コード例 #12
0
ファイル: data_edit.inc.php プロジェクト: rotzek/redaxo_xform
 // -------------- truncate table
 if ($func == "truncate_table" && $this->hasDataPageFunction("truncate_table")) {
     $truncate = TRUE;
     if (rex_register_extension_point('XFORM_DATA_TABLE_TRUNCATE', $truncate, array())) {
         $query = 'truncate table ' . $table["table_name"];
         $trunsql = new rex_sql();
         $trunsql->setQuery($query);
         echo rex_info($I18N->msg("table_truncated"));
         $func = "";
         rex_register_extension_point('XFORM_DATA_TABLE_TRUNCATED', "", array());
     }
 }
 // -------------- form
 if ($func == "add" && $this->hasDataPageFunction("add") || $func == "edit") {
     $back = '<table cellpadding="5" class="rex-table"><tr><td><a href="index.php?' . $link_vars . $em_url . $em_rex_list . '"><b>&laquo; ' . $I18N->msg('back_to_overview') . '</b></a></td></tr></table>';
     $xform = new rex_xform();
     // $xform->setDebug(TRUE);
     foreach ($this->getLinkVars() as $k => $v) {
         $xform->setHiddenField($k, $v);
     }
     $xform->setHiddenField("func", $func);
     if (count($rex_xform_manager_opener) > 0) {
         foreach ($rex_xform_manager_opener as $k => $v) {
             $xform->setHiddenField('rex_xform_manager_opener[' . $k . ']', $v);
         }
     }
     // TODO
     if (count($rex_xform_filter) > 0) {
         foreach ($rex_xform_filter as $k => $v) {
             $xform->setHiddenField('rex_xform_filter[' . $k . ']', $v);
         }
コード例 #13
0
 function generateAll()
 {
     global $REX;
     $types = rex_xform::getTypeArray();
     foreach ($this->getTables() as $table) {
         $c = rex_sql::factory();
         $c->setQuery('CREATE TABLE IF NOT EXISTS `' . $table["table_name"] . '` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY )');
         $c->setQuery('SHOW COLUMNS FROM `' . $table["table_name"] . '`');
         $current_columns = array();
         foreach ($c->getArray() as $field) {
             if ($field["Field"] != "id") {
                 $current_columns[$field["Field"]] = $field["Type"];
             }
         }
         $new_columns = array();
         foreach ($this->getTableFields($table["table_name"]) as $field) {
             $type_id = $field["type_id"];
             $type_name = $field["type_name"];
             $f1 = $field["f1"];
             $f2 = $field["f2"];
             $f3 = $field["f3"];
             if ($type_id == "validate" && $type_name == "type") {
                 $new_columns[$f1] = $f2;
                 rex_xform::includeClass("validate", "type");
                 if ($f3 != "" || ($f3 = rex_xform_validate_type::getDefaultTypeValue($f2))) {
                     $new_columns[$f1] .= '(' . $f3 . ')';
                 }
             } elseif ($type_id == "value" && !isset($new_columns[$f1])) {
                 $new_columns[$f1] = $types[$type_id][$type_name]['dbtype'];
             }
         }
         $c = rex_sql::factory();
         foreach ($new_columns as $field => $type) {
             if (!array_key_exists($field, $current_columns)) {
                 $c->setQuery('ALTER TABLE `' . $table["table_name"] . '` ADD `' . $field . '` ' . $type . '  NOT NULL ;');
                 unset($current_columns[$field]);
             } elseif ($current_columns[$field] == $type) {
                 unset($current_columns[$field]);
             } else {
                 $c->setQuery('ALTER TABLE `' . $table["table_name"] . '` CHANGE `' . $field . '` `' . $field . '` ' . $type . ' NOT NULL;');
                 unset($current_columns[$field]);
             }
         }
         foreach ($current_columns as $field => $type) {
             $c->setQuery('ALTER TABLE `' . $table["table_name"] . '` DROP `' . $field . '` ');
         }
     }
     return;
 }