Example #1
0
function table_array($table)
{
    $fields = array();
    $cols = query("SHOW columns FROM `{$table}`", '2d');
    foreach ($cols as $col) {
        $field = array();
        $bracket = strpos($col['Type'], '(');
        if ($bracket > 0) {
            $bracket++;
            $field['length'] = substr($col['Type'], $bracket, strpos($col['Type'], ')') - $bracket);
            $field['type'] = substr($col['Type'], 0, $bracket - 1);
        } else {
            $field['type'] = $col['Type'];
        }
        field_type($field['type'], $field['length']);
        if (empty($field['length'])) {
            unset($field['length']);
        }
        if (strlen($col['Default']) > 0) {
            $field['default'] = $col['Default'];
        }
        if ($col['Extra'] == 'auto_increment') {
            $field['auto'] = 1;
        }
        if ($col['Key'] == 'PRI') {
            $arr['primary'] = $col['Field'];
        }
        $fields[$col['Field']] = $field;
    }
    $arr['fields'] = $fields;
    $indexes = query("SHOW INDEX FROM `{$table}` WHERE Key_name<>'PRIMARY'", '2d');
    foreach ($indexes as $index) {
        $arr['index'][] = $index['Key_name'];
    }
    return $arr;
}
Example #2
0
function show($sql, $header, $top_raw, $tname, $target, $all_readonly, $display_heads, $equipment_name)
{
    $link = start_nchsls();
    $pri = find_primary($tname);
    $ft = field_type($tname);
    if (!($result = mysql_query($sql, $link))) {
        echo 'show() error:' . mysql_error();
    } else {
        echo '<table>';
        if ($display_heads == 'yes') {
            echo '<tr><th colspan=20>' . $header . '</th></tr>';
            echo '<tr  class="top">';
            echo '<td></td>';
            foreach ($top_raw as $key => $value) {
                echo '<td>';
                echo $value;
                echo '</td>';
            }
            echo '</tr>';
        }
        while ($result_array = mysql_fetch_assoc($result)) {
            if ($result_array['equipment_name'] == $equipment_name) {
                echo '<tr class="equipment">';
            } else {
                echo '<tr>';
            }
            echo '<form method=post action=\'' . $target . '\'   enctype=\'multipart/form-data\'>';
            echo '<input type=hidden name=tname value=\'' . $tname . '\'>';
            if ($all_readonly == 'readonly') {
                $disabled = 'disabled';
            } else {
                $disabled = '';
            }
            echo '<td>	<button ' . $disabled . ' type=submit name=action  value=delete >Delete</button>
						<button ' . $disabled . ' type=submit name=action  value=save_edit >Save</button>
						<button ' . $disabled . ' type=submit name=action  value=download >Download</button>
					</td>';
            foreach ($result_array as $key => $value) {
                if (in_array($key, $pri)) {
                    $readonly = 'readonly';
                } else {
                    $readonly = '';
                }
                if ($all_readonly == 'readonly') {
                    $readonly = 'readonly';
                }
                echo '<td>';
                $dt_id = '';
                foreach ($pri as $keyy => $valuee) {
                    $dt_id = $dt_id . '_' . $result_array[$valuee];
                }
                $dt_id = $dt_id . '_' . $key;
                if ($ft[$key] == 'date') {
                    echo '<input ' . $readonly . ' value=\'' . $value . '\' id=\'' . $dt_id . '\' class="datepicker" size="10" name=\'' . $key . '\' />';
                } elseif ($ft[$key] == 'longblob') {
                    show_blob($key);
                } else {
                    //echo '<h5>'.$value.'</h5>';
                    if (!mk_select_grand($key, $readonly, $value)) {
                        $exp = explode('(', $ft[$key]);
                        //print_r($exp);
                        if ($exp[0] == 'varchar' && $exp[1] > 100) {
                            echo '<textarea rows=3 ' . $readonly . ' name=\'' . $key . '\' >' . $value . '</textarea>';
                        } else {
                            echo '<input  size=10 ' . $readonly . ' value=\'' . $value . '\' type=text name=\'' . $key . '\' >';
                        }
                    }
                }
                /////////////////////gooood
                echo '</td>';
            }
            echo '</form>';
            echo '</tr>';
        }
        echo '</table>';
    }
}