Файл: source/app/objects/admin/table/add.tpl.php
Строк: 561
<?php
$lang = Lang::singleton();
$editFlag = false;
if (isset($_GET['table']) && trim($_GET['table']) != '') {
if (!in_array($_GET['table'], $this->tables)) {
redirect('admin/table/index.php');
}
$editFlag = true;
}
?>
<div class="container" >
<h2><?php echo $lang->line('tools_table_builder'); ?> </h2>
<ul class="nav nav-tabs" id="auth_tab" style="margin-bottom: 10px;">
<li><a href="<?php echo strUrl('admin/component/builder.php'); ?>"> <?php echo $lang->line('components'); ?> </a></li>
<li><a href="<?php echo strUrl('admin/component/groups.php'); ?>"> <?php echo $lang->line('group_component'); ?> </a></li>
<li class="active"><a href="<?php echo strUrl('admin/table/index.php'); ?>"><?php echo $lang->line('table_builder'); ?></a></li>
<li><a href="<?php echo strUrl('admin/language/index.php'); ?>"> <?php echo $lang->line('language_manager'); ?> </a></li>
</ul>
<h3 style="margin-top: 7px;"><?php if ($editFlag == true) { ?><?php echo $lang->line('edit'); ?><?php } else { ?><?php echo $lang->line('create'); ?><?php } ?> <?php echo $lang->line('table'); ?></h3>
<div id="errors" style="display:none;"></div>
<form class="form-horizontal" id="frm_new_table">
<?php if ($editFlag == true) { ?>
<input type="hidden" id="table_name_id" value="<?php echo $_GET['table']; ?>" />
<?php } ?>
<div class="control-group" style="margin-bottom: 8px !important;">
<label class="control-label" for="table_name"><?php echo $lang->line('table_name'); ?></label>
<div class="controls">
<input type="text" id="table_name" name="table_name" placeholder="Table Name">
</div>
</div>
<div class="control-group" style="margin-bottom: 8px !important;">
<label class="control-label" for="storage_engine"><?php echo $lang->line('storage_engine'); ?></label>
<div class="controls">
<select id="storage_engine" name="storage_engine">
<?php foreach ($this->engines as $k => $v) { ?>
<option value="<?php echo $k; ?>"><?php echo $v; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="control-group" style="margin-bottom: 8px !important;">
<label class="control-label" for="collation"><?php echo $lang->line('collation'); ?></label>
<div class="controls">
<select name="collation" id="collation">
<option value=""></option>
<?php foreach ($this->collations as $k => $v) { ?>
<optgroup label="<?php echo $k; ?>">
<?php foreach ($v as $k1 => $v1) { ?>
<option value="<?php echo $k1; ?>"><?php echo $v1; ?></option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
</div>
</div>
<div class="control-group" style="margin-bottom: 8px !important;">
<label class="control-label" for="table_comment"><?php echo $lang->line('table_comments'); ?></label>
<div class="controls">
<input type="text" id="table_comment" name="table_comment" placeholder="Comments" class="input-xxlarge">
</div>
</div>
<table class="table table-bordered list table-condensed" id="crud_table">
<thead>
<tr>
<th style=" cursor:default; color:#333333;text-shadow: 0 1px 0 #FFFFFF;background-color: #e6e6e6;">Name</th>
<th style=" cursor:default; color:#333333;text-shadow: 0 1px 0 #FFFFFF;background-color: #e6e6e6;">Type</th>
<th style=" cursor:default; color:#333333;text-shadow: 0 1px 0 #FFFFFF;background-color: #e6e6e6;">Length/Values</th>
<th style=" cursor:default; color:#333333;text-shadow: 0 1px 0 #FFFFFF;background-color: #e6e6e6;">Default</th>
<th style=" cursor:default; color:#333333;text-shadow: 0 1px 0 #FFFFFF;background-color: #e6e6e6;">Collation</th>
<th style=" cursor:default; color:#333333;text-shadow: 0 1px 0 #FFFFFF;background-color: #e6e6e6;">Null</th>
<th style=" cursor:default; color:#333333;text-shadow: 0 1px 0 #FFFFFF;background-color: #e6e6e6;">Key</th>
<th style=" cursor:default; color:#333333;text-shadow: 0 1px 0 #FFFFFF;background-color: #e6e6e6;">A_I</th>
<th style=" cursor:default; color:#333333;text-shadow: 0 1px 0 #FFFFFF;background-color: #e6e6e6;">Action</th>
</tr>
</thead>
<tr style="display:none;" id="template">
<td style="width: 260px;">
<input type="text" style="width:95%;" name="field_name[]" placeholder="Field Name"/>
</td>
<td style="width: 130px;">
<select name="field_type[]" style="width: auto;" onchange="resetCollation(this);">
<option selected="selected" value="INT">INT</option>
<option value="VARCHAR">VARCHAR</option>
<option value="TEXT">TEXT</option>
<option value="DATE">DATE</option>
<optgroup label="NUMERIC">
<option value="TINYINT">TINYINT</option>
<option value="SMALLINT">SMALLINT</option>
<option value="MEDIUMINT">MEDIUMINT</option>
<option value="INT">INT</option>
<option value="BIGINT">BIGINT</option>
<option value="-">-</option>
<option value="DECIMAL">DECIMAL</option>
<option value="FLOAT">FLOAT</option>
<option value="DOUBLE">DOUBLE</option>
<option value="REAL">REAL</option>
<option value="-">-</option>
<option value="BIT">BIT</option>
<option value="BOOL">BOOL</option>
<option value="SERIAL">SERIAL</option>
</optgroup>
<optgroup label="DATE and TIME">
<option value="DATE">DATE</option>
<option value="DATETIME">DATETIME</option>
<option value="TIMESTAMP">TIMESTAMP</option>
<option value="TIME">TIME</option>
<option value="YEAR">YEAR</option>
</optgroup>
<optgroup label="STRING">
<option value="CHAR">CHAR</option>
<option value="VARCHAR">VARCHAR</option>
<option value="-">-</option>
<option value="TINYTEXT">TINYTEXT</option>
<option value="TEXT">TEXT</option>
<option value="MEDIUMTEXT">MEDIUMTEXT</option>
<option value="LONGTEXT">LONGTEXT</option>
<option value="-">-</option>
<option value="BINARY">BINARY</option>
<option value="VARBINARY">VARBINARY</option>
<option value="-">-</option>
<option value="TINYBLOB">TINYBLOB</option>
<option value="MEDIUMBLOB">MEDIUMBLOB</option>
<option value="BLOB">BLOB</option>
<option value="LONGBLOB">LONGBLOB</option>
<option value="-">-</option>
<option value="ENUM">ENUM</option>
<option value="SET">SET</option>
</optgroup>
</select>
</td>
<td style="width: 90px;">
<input type="text" name="field_length_value[]" style="width: 89%;" placeholder="Length"/>
</td>
<td style="width: 175px;">
<select name="field_default[]" style="width: auto;" onchange="default_field(this);">
<option value=""></option>
<option value="NULL">NULL</option>
<option value="USER_DEFINED">As defined:</option>
<option value="CURRENT_TIMESTAMP">CURRENT_TIMESTAMP</option>
</select>
<br>
<input type="text" name="field_user_defined[]" style=" margin-top: 3px; width: 93%; display: none;" />
</td>
<td style="width: 185px;">
<select name="field_collation[]" style="width: auto;">
<option value=""></option>
<?php foreach ($this->collations as $k => $v) { ?>
<optgroup label="<?php echo $k; ?>">
<?php foreach ($v as $k1 => $v1) { ?>
<option value="<?php echo $k1; ?>"><?php echo $v1; ?></option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
</td>
<td style="width: 30px; text-align: center;">
<input type="checkbox" value="1" checked="checked" name="field_null[]">
</td>
<td style="width: 30px; text-align: center;">
<input type="checkbox" value="1" name="field_key[]"/>
</td>
<td style="width: 30px; text-align: center;">
<input type="checkbox" value="1" name="field_ai[]"/>
</td>
<td style="text-align: center;">
<a class="btn btn-info btn-mini" onclick="add_field(this);"><?php echo $lang->line('add'); ?></a>
<a class="btn btn-danger btn-mini" onclick="delete_field(this);"><?php echo $lang->line('delete'); ?></a>
</td>
</tr>
</table>
<?php if ($editFlag == true){ ?>
<p>A_I: AUTO_INCREMENT<br />
<?php echo $lang->line('config_of_this_table_will_be_removed'); ?>
</p>
<?php } ?>
<div style="text-align: center;">
<input type="button" class="btn" value="<?php echo $lang->line('cancel'); ?>" onclick="cancel();"/>
<?php if ($editFlag == true) { ?>
<input type="button" class="btn btn-info" value=" <?php echo $lang->line('save'); ?> " onclick="updateTable();" />
<?php } else { ?>
<input type="button" class="btn btn-info" value=" <?php echo $lang->line('save'); ?> " onclick="createNewTable();" />
<?php } ?>
</div>
</form>
</div>
<script>
function add_field(obj){
var _field = $('#template').clone();
_field.attr('id', '');
_field.addClass('crud_field');
_field.show();
$(obj).parent().parent().after(_field);
}
function delete_field(obj){
if ($('.crud_field').length > 1){
$(obj).parent().parent().remove();
}
}
function default_field(obj){
var target = $(obj).parent().children('input[name="field_user_defined[]"]');
if ($(obj).val() == 'USER_DEFINED'){
target.show();
}else{
target.hide();
}
}
function cancel(){
window.location = '<?php echo strUrl('admin/table/index.php'); ?>';
}
function resetCollation(obj){
var _field = $(obj).parent().parent();
_field.find('select[name="field_collation[]"]').val('');
}
function createNewTable(){
var obj = {};
obj.table_name = $('#table_name').val();
obj.storage_engine = $('#storage_engine').val();
obj.collation = $('#collation').val();
obj.table_comment = $('#table_comment').val();
obj.fields = [];
$('.crud_field').each(function(){
var o = {};
o.name = $(this).find('input[name="field_name[]"]').val();
o.type = $(this).find('select[name="field_type[]"]').val();
o.length_value = $(this).find('input[name="field_length_value[]"]').val();
o.def = $(this).find('select[name="field_default[]"]').val();
o.user_def = $(this).find('input[name="field_user_defined[]"]').val();
o.collation = $(this).find('select[name="field_collation[]"]').val();
o.is_null = $(this).find('input[name="field_null[]"]:checked').val();
o.key = $(this).find('input[name="field_key[]"]:checked').val();
o.ai = $(this).find('input[name="field_ai[]"]:checked').val();
obj.fields[obj.fields.length] = o;
});
$.post('<?php echo strUrl('admin/table/insert.php'); ?>', obj, function(o){
if (o.error == 1){
var objError = $('<div class="alert alert-error"></div>');
objError.append('<button data-dismiss="alert" class="close" type="button">×</button>');
if (o.messages.length >0){
for(var i in o.messages){
objError.append('<strong>Error!</strong> '+o.messages[i]+'. <br/>');
}
}
$('#errors').html(objError);
$('#errors').show();
}else{
window.location = '<?php echo strUrl('admin/table/index.php'); ?>';
}
}, 'json');
}
function updateTable(){
var obj = {};
obj.table_name = $('#table_name').val();
obj.table_name_id = $('#table_name_id').val();
obj.storage_engine = $('#storage_engine').val();
obj.collation = $('#collation').val();
obj.table_comment = $('#table_comment').val();
obj.fields = [];
$('.crud_field').each(function(){
var o = {};
o.id = $(this).attr('id');
o.name = $(this).find('input[name="field_name[]"]').val();
o.type = $(this).find('select[name="field_type[]"]').val();
o.length_value = $(this).find('input[name="field_length_value[]"]').val();
o.def = $(this).find('select[name="field_default[]"]').val();
o.user_def = $(this).find('input[name="field_user_defined[]"]').val();
o.collation = $(this).find('select[name="field_collation[]"]').val();
o.is_null = $(this).find('input[name="field_null[]"]:checked').val();
o.key = $(this).find('input[name="field_key[]"]:checked').val();
o.ai = $(this).find('input[name="field_ai[]"]:checked').val();
obj.fields[obj.fields.length] = o;
});
$.post('<?php echo strUrl('admin/table/update.php'); ?>', obj, function(o){
if (o.error == 1){
var objError = $('<div class="alert alert-error"></div>');
objError.append('<button data-dismiss="alert" class="close" type="button">×</button>');
if (o.messages.length >0){
for(var i in o.messages){
objError.append('<strong>Error!</strong> '+o.messages[i]+'. <br/>');
}
}
$('#errors').html(objError);
$('#errors').show();
}else{
window.location = '<?php echo strUrl('admin/table/index.php'); ?>';
}
}, 'json');
}
$(document).ready(function(){
$('title').html($('h3').text());
<?php if ($editFlag == true) { ?>
$('#table_name').val('<?php echo $this->table_info['Name']; ?>');
$('#storage_engine').val('<?php echo $this->table_info['Engine']; ?>');
$('#collation').val('<?php echo $this->table_info['Collation']; ?>');
$('#table_comment').val('<?php echo $this->table_info['Comment']; ?>');
<?php if (is_array($this->columns_info) && count($this->columns_info) > 0) { ?>
<?php foreach ($this->columns_info as $k => $v) { ?>
<?php
$aryType = explode('(', $v['Type']);
preg_match("/((.*))/i", $v['Type'],$aryTmp);
$valType = (isset($aryTmp[1]))?$aryTmp[1]:'';
?>
var _field = $('#template').clone();
_field.attr('id', '<?php echo $v['Field'] ?>');
_field.addClass('crud_field');
_field.find('input[name="field_name[]"]').val('<?php echo $v['Field'] ?>');
_field.find('select[name="field_type[]"]').val('<?php echo strtoupper($aryType[0]); ?>');
<?php if (isset($aryType[1])) { ?>
_field.find('input[name="field_length_value[]"]').val("<?php echo $valType; ?>");
<?php } ?>
<?php if ($v['Default'] === NULL) { ?>
<?php if ($v['Null'] == 'YES') { ?>
_field.find('select[name="field_default[]"]').val('NULL');
<?php } ?>
<?php } else if ($v['Default'] == 'CURRENT_TIMESTAMP') { ?>
_field.find('select[name="field_default[]"]').val('<?php echo $v['Default'] ?>');
<?php } else { ?>
_field.find('select[name="field_default[]"]').val('USER_DEFINED');
_field.find('input[name="field_user_defined[]"]').val('<?php echo $v['Default'] ?>');
_field.find('input[name="field_user_defined[]"]').show();
<?php } ?>
_field.find('select[name="field_collation[]"]').val('<?php echo $v['Collation'] ?>');
<?php if ($v['Null'] == 'NO') { ?>
_field.find('input[name="field_null[]"]').attr({checked:false});
<?php } ?>
<?php if ($v['Key'] == 'PRI') { ?>
_field.find('input[name="field_key[]"]').attr({checked:true});
<?php } ?>
<?php if ($v['Extra'] == 'auto_increment') { ?>
_field.find('input[name="field_ai[]"]').attr({checked:true});
<?php } ?>
_field.show();
$('#crud_table').append(_field);
<?php } ?>
<?php } ?>
<?php } ?>
if ($('.crud_field').length <= 0){
var _field = $('#template').clone();
_field.attr('id', '');
_field.addClass('crud_field');
_field.find('input[name="field_name[]"]').val('id');
_field.find('input[name="field_null[]"]').attr({checked:false});
_field.find('input[name="field_key[]"]').attr({checked:true});
_field.find('input[name="field_ai[]"]').attr({checked:true});
_field.show();
$('#crud_table').append(_field);
}
});
</script>