Запись [z:visual] < dev.sky.1.001
Версия 1.001
• N1: WRITE FILE: _dev/util/visual.php
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | <?php defined('START') and AUTH_OK or die; eval(get()); $funcs = ['as_is', 'html()', 'as_link', 'date()']; $inputs = ['now()', 'textarea', 'select', 'text', 'checkbox', 'radio', 'file', 'datetime-local', 'email', 'tel', 'range', 'url']; $objects = ['list', 'show', 'edit', 'new']; $standard = [ 'index.php' => '..Main entry point + main layout', '.htaccess, robots.txt, pub/favicon.ico' => '..Use mod_rewrite(apache) and more..', 'admin/_main.php, main/etc.php, pub/img/ok.gif' => '1..Default admin page for ROOT profile users', 'admin/_settings.php' => '..App settings file', 'admin/_users.php' => '..File to view and manage users in admin section', 'admin/_visitors.php' => '..File to view and manage anonymous visitors', 'admin/index.php' => '1..Admin main route file', 'main/ajax.php' => '..Main entry point for ajax requests', 'main/body.php' => '..Main controller for page processing', 'main/c_summer.php' => '1..Cron script to auto-set summer/winter time in MySQL', 'main/conf.php' => '..Main PRIMARY config file', 'main/cron.php' => '..Main cron layer', 'main/debug.php' => '1..Debug funcs, used in debug mode only', 'main/front.php' => '1..Front class and util, coresky', 'main/mvc.php' => '1..MVC base classes', 'main/sky.php' => '1..Primary coresky file, used always', 'main/wing.php' => '1..Secondary coresky file, used always, except console', 'main/mvc/c_main.php' => '..MVC controller of a main page', 'main/mvc/common_c.php' => '..MVC common controller. Participate in all requests', 'main/mvc/default_c.php' => '..This controller used when some controller not exists', 'pub/admin.css' => '..CSS for admin section', 'pub/admin.js' => '..js for admin section', 'pub/front.css' => '..CSS for front section (used on all pages)', 'pub/front.js' => '..js for front section (used on all pages)', 'pub/wing.css' => '1..The reusable CSS', 'pub/wing.js' => '1..The reusable js code', 'view/_login.php' => '..User login page (as a sample, adjust for your custom app)', 'view/_main.php' => '..Main page placeholder', 'view/head.php, view/foot.php' => '..Included from layout, just to simplify it', ]; $ovwr = $wrs = $notf = []; $size = 0; function wr_file($fn, $data) { global $overwrite, $size, $ovwr, $wrs; $name = basename($fn); $ov = '_dev/' != substr($fn, 0, 5); $path = ''; foreach (explode('/', $fn) as $one) { if ($name == $one) { if ($ov && is_file($fn)) { $ovwr[] = $fn; if (!$overwrite) return 0; wr_file("_dev/temp/visual/$fn", file_get_contents($fn)); } $size = file_put_contents($fn, $data); if ($size && $ov) $wrs[] = $fn; return $size; } elseif (!is_dir($path .= $path ? "/$one" : $one)) mkdir($path) && trace($path); } } if ('ajax' == START): switch ($ival): case 1: require 'v_database.php'; break; case 2: require 'v_design.php'; break; case 3: require 'v_admin.php'; break; case 4: require 'v_front.php'; break; case 5: switch (PAGE) { case 'opt': set($_POST); if (isset($_POST['aname'])) set('u_my_app', $_POST['aname'], 3); echo 'Configutation options saved!'; break; } endswitch; else: # HTML PAGE $menu = ['Options', 'Database', 'Design', 'Files']; $TOP = sprintf('> <span id="links">%s (Esc)</span> <span></span>', menu(0, $menu, 'javascript:sheet(%d)', ' > ')); $chs_list = sql("@select CHARACTER_SET_NAME,CHARACTER_SET_NAME from information_schema.CHARACTER_SETS"); echo tag(form($GLOBALS, [ 'aname' => ['', 'Application name: '], sprintf(' Characters: <select name="charset">%s</select><p>', option($charset, $chs_list)), '<fieldset><legend>Select front application sheme:</legend>', 'scheme' => ['radio', '', $schemes = ['Main SKY scheme', 'NICE layout', 'MVC Layer']], '<br>', 'nob' => ['checkbox', 'NOB - no output buffering'], '</fieldset><p>', '<fieldset><legend>Select lang settings:</legend>', 'lang' => ['radio', '', [1 => 'one only language', 'two languages', 'more then two languages'], 1, 'onclick="fc(this.value)"'], sprintf('<div id="intfc"%s>', 1 == $lang ? ' style="display:none"' : ''), 'intfc' => ['checkbox', 'Interface only but not content', '', 1], '</div>', '</fieldset><p>', '<fieldset><legend>Select front URL\'s sheme:</legend>', 'url' => ['radio', '', ['coresky.net scheme', 'Clean query string', 'Clean URL (not recommended)'], 0, 'onclick="sa(this.value)"'], '<br>Sample: <a href="#"></a>', '</fieldset><p>', 'overwrite' => ['checkbox', 'Overwrite files if exists'], '<p><br>', ['button', 'Save - F2', 'onclick="key_F2()"'], '<p><br>', '<p style="text-align:right; width:90%"><b>Project summary</b></p>', ]), 'id="res"'); ?><script type="text/javascript"> var str = "This utility designed for quick start of custom SKY. application: create database's tables, php-files with standartized "; mtop(str + 'code, create initial design scheme of front app section and more..<br>Status: initial functionality, 2do'); var schemes = ['<?=implode("','", $schemes)?>'], xpage = <?=$xpage?>, is_front = <?=@$is_front ? 'true' : 'false'?>, scheme = <?=$scheme?>, scheme_ini = 7, lang = <?=$lang?>, url = <?=$url?>, intfc = <?=$intfc?>, lock_esc = false; function key_Esc() { if (lock_esc) return lock_esc = false; var i = sheet() + 1; sheet(4 == i ? 0 : i); } function key_F2() { var i = sheet(), hash = qs$('res', true); ajax('5&opt=&xpage=' + xpage, function(){}); if (i) eval('f2_' + i + 'sheet()'); else ajax('5&opt=&' + qs$('res'), function (r, err) { scheme = parseInt(hash['scheme']), lang = hash['lang'], url = hash['url'], intfc = parseInt(hash['intfc']); var str = $('mtop').html(); mtop(r, green); setTimeout(function() { hide$('mtop', function() { mtop(str); if (xpage) $('mtop', false); }); }, 2000); }); } function key_F9() { try { eval('f9_' + sheet() + 'sheet()') } catch(e){} } function fc(val) { $('intfc', val > 1); } function sa(val) { var ary = ['http://site.uk/news?edit=3', 'http://site.uk/?news=edit&id=3', 'http://site.uk/news/edit/id/3']; $$('a', 'res', 0).html(ary[val]); } sa(<?=$url?>); </script> <style type="text/css"> fieldset { background:#eee; width:90%; } #sel-0 span, #sel-1 span, #sel-2 span { color:green;font:normal 14px courier; } </style> <?php # text-decoration:underline; require 'v_admin.php'; # sheet 3 require 'v_database.php'; # sheet 1 require 'v_design.php'; # sheet 2 endif; # Options (this file) sheet 0 ajax as 5 # v_front.php sheet 4 (ajax only) |
• N2: WRITE FILE: _dev/util/v_admin.php
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | <?php defined('START') and AUTH_OK or die; if (START == 'ajax'): switch (PAGE): case 'save': # generate admin files set('is_front', 0); $out = "<?php eval(\$me) or die;\n\n"; if ($p_oname != $PVAL) $out .= "\$me = '$PVAL';\n\n"; if ($tab = @$p_xa) $out .= "if (AJAX):\n\tswitch (AJAX):\n\tcase '':\n\t\tbreak;\n\tendswitch;\n\nelse"; $set = array_combine($objects, [(int)(bool)@$p_list, (int)(bool)@$p_show, (int)(bool)@$p_edit, (int)(bool)@$p_new]); if ('new' == $p_default && @$p_edit) $p_default = 'edit'; unset($set[$p_default]); $cnt = array_sum($set += [$p_default => 1]); $tab or $tab = $cnt > 1 or $tab = ''; $funcs = array_flip($funcs); if ($p_sd && @$p_show || @$p_list && $p_ld && !$p_lr) { $out .= "if ('delete' == \$PVAL)" . ($tab ? ":\n" : " {\n"); $out .= "\tsql(\"delete from \$me where id=\$WVAL\");\n"; $out .= "\tjump(me);\n" . ($tab ? "\nelse" : "}\n\n"); } foreach ($set as $k => $v) if ($v) { if ($tab) { $tab = "\t"; if ($def = $k == $p_default || 'new' == $p_default && 'edit' == $k) $out .= ":\n"; else { if ('list' == $k) $rule = "'list' == \$PVAL"; elseif ('new' == $k) $rule = "'new' == \$PVAL"; elseif ('show' == $k || !isset($set['show']) && 'edit' == $k) $rule = "is_numeric(\$PVAL)"; else $rule = '' === @$p_new ? "'new' == \$PVAL || 'edit' == \$PVAL" : "'edit' == \$PVAL"; $out .= "if ($rule):\n"; } } else $def = true; $ary = explode(' ', $_POST[$k]); if ('list' == $k) { if ($p_ld && $p_lr) $out .= "{$tab}if (\$_POST) sqlf(\"delete from \$me where id in (%s)\", \$_POST['id']);\n"; if ($p_lp) $out .= "{$tab}list(\$TOP, \$start) = pagination(sql(\"+select count(1) from \$me\"), \$ipp = 20);\n"; if ($p_em && isset($p_new)) $out .= "{$tab}\$TOP .= ' > add ' . a('new', me . '=new');\n"; if ($p_ld && $p_lr) $out .= "{$tab}echo '<form method=\"post\">';\n"; $out .= $p_lp ? "{$tab}echo th([\n" : "{$tab}echo th([\n"; $td = ''; foreach ($ary as $one) { list ($name, $type) = explode(':', $one); $out .= sprintf("$tab\t'%s',\n", ucfirst($name)); if ('as_is' == $type) $td .= sprintf("$tab\t%s,\n", "\$r_$name"); elseif ('html()' == $type) $td .= sprintf("$tab\t%s,\n", "html(\$r_$name)"); elseif ('as_link' == $type) $td .= sprintf("$tab\ta(\$r_$name, me . \"%s=\$r_id\"),\n", @$p_show ? '' : '=edit&id'); elseif ('date()' == $type) $td .= sprintf("$tab\t%s,\n", "\$sky->date(\$r_$name)"); } if ($p_ld) { $out .= $p_lr ? "$tab\t'[x]' => 'width=\"50\"',\n" : "$tab\t'' => 'width=\"100\"',\n"; $td .= $p_lr ? "$tab\t[sprintf(TPL_CHECKBOX, \$r_id, ''), 'style=\"text-align:center\"'],\n" : "$tab\tsprintf('<a href=\"javascript:if (confirm(\\'Realy delete?\\')) location.href=\\'adm' . me . '=delete&id=%d\\'\">delete</a>', \$r_id),\n"; } $out .= "$tab], 'cellspacing=\"0\" width=\"100%\"');\n"; $out .= "{$tab}for (\$q = sql(\"select * from \$me" . ($p_lp ? ' limit $start, $ipp"' : '"'); $out .= "); eval(fetch); ) echo td([\n$td$tab], eval(zebra));\n{$tab}echo '</table>';\n"; if ($p_ld && $p_lr) $out .= "{$tab}echo tag('<input type=\"submit\" value=\"delete checked\" />') . '</form>';\n"; } elseif ('show' == $k) { $rule = $def ? 'order by id desc limit 1' : 'where id=$PVAL'; $out .= "$tab\$q = sql(\"select * from \$me $rule\");\n"; $out .= "{$tab}if (!eval(fetch)) jump();\n"; if ($sl = $p_se && @$p_edit) $out .= "{$tab}\$TOP = a('edit', me . \"=edit&id=\$r_id\")"; if ($p_sd) $out .= sprintf("%s a('delete', 'adm' . me . \"=delete&id=\$r_id\")", $sl ? " . ' | ' . " : "{$tab}\$TOP ="); if ($sl || $p_sd) $out .= ";\n"; $out .= "{$tab}echo '<table>';\n{$tab}\$ary = [\n"; foreach ($ary as $one) { list ($name, $type) = explode(':', $one); if ('as_is' == $type) $out .= sprintf("$tab\t['%s', \$r_$name],\n", ucfirst($name)); elseif ('html()' == $type) $out .= sprintf("$tab\t['%s', html(\$r_$name)],\n", ucfirst($name)); elseif ('as_link' == $type) $out .= sprintf("$tab\t['%s', a(\$r_$name, me . \"%s=\$r_id\")],\n", ucfirst($name), @$p_show ? '' : '=edit&id'); elseif ('date()' == $type) $out .= sprintf("$tab\t['%s', \$sky->date(\$r_$name)],\n", ucfirst($name)); } $out .= "{$tab}];\n{$tab}foreach (\$ary as \$td) echo td(\$td);\n{$tab}echo '</table>';\n"; } else { # edit, new if ($both = '' === @$p_new) $out .= "{$tab}\$new = !\$WVAL or is_numeric(\$WVAL) or die;\n"; $rule = ($se = $def && @$p_edit && !$both) ? 'order by id desc limit 1' : 'where id=$WVAL'; $out .= sprintf("{$tab}\$TOP .= %s;\n", $both ? "\$new ? ' new' : ' edit'" : (@$p_new ? "' new'" : "' edit'")); $out .= "{$tab}if (\$_POST) {\n$tab\t\$ary = [\n"; $form = ''; foreach ($ary as $one) { list ($name, $type) = explode(':', $one); if ('now()' == $type) $out .= "$tab\t\t'$name' => 'now()',\n"; else { $ucname = ucfirst($name); $out .= "$tab\t\t'$name' => ['.+', 'Field `$name` cannot be empty'],\n"; if ('textarea' == $type) $form .= "$tab\t'$name' => ['$type', '', 'rows=\"12\" style=\"width:50%\"'],\n"; elseif (in_array($type, ['select', 'radio'])) $form .= "$tab\t'$name' => ['$type', '$ucname', ['--', '++']],\n"; elseif ('checkbox' == $type) $form .= "$tab\t'$name' => ['$type', '$ucname'], '<br />',\n"; else $form .= "$tab\t'$name' => ['$type', '$ucname'],\n"; } } $out .= "$tab\t];\n$tab\t\$ret = \$sky->"; if ($both) $out .= "replace(\$me, \$new ? 0 : \$WVAL, \$ary);\n"; else $out .= @$p_new ? "insert(\$me, \$ary);\n" : sprintf("update(\$me, %s, \$ary);\n", $def && !@$p_new ? '$p_post_id' : '$WVAL'); $out .= "$tab\tif (false === \$ret) {\n"; $out .= "$tab\t\t\$MESS = \$sky->get_errors();\n$tab\t} else {\n$tab\t\t\$JUMP = [2, me];\n"; if ($both) $mes = "\$new ? 'Record inserted!' : 'Record updated!'"; else $mes = @$p_new ? "'Record inserted!'" : "'Record updated!'"; $out .= "$tab\t\t\$TOP .= ' : ' . tag($mes, 'class=\"active\"', 'span');\n"; $out .= "$tab\t}\n$tab}\n\n$tab"; if (!@$p_new) $out .= sprintf('$row = %ssql("~select * from $me %s");', $both ? '$new ? $_POST : ' : '', $rule) . "\n{$tab}"; $row = @$p_new ? '$_POST' : '$row'; $out .= "echo form($row, [\n$form"; if ($se) $out .= "$tab\t'post_id' => ['hidden', \$row['id']],\n"; $out .= "$tab\t['submit', 'Save'],\n"; $out .= "$tab]);\n"; } if ($tab) $out .= $def ? "\nendif;\n" : "\nelse"; } wr_file($fn = "admin/_$p_oname.php", $out); if (!$size && $overwrite) echo "-Cannot create file `$fn`"; if ($ovwr) $overwrite ? printf("Files `$fn` overwritten, find old version in the dir: `_dev/temp/visual`<br>") : printf("-Files `$fn` exists, cannot overwrite<br>"); if ($wrs && $wrs != $ovwr) echo "+File `$fn` generated!"; break; case 'page0': # List of tables echo th(['##' => 'width="5%"', 'Table name', 'Files count (2do)', 'list' => $width = 'width="10%"', 'show' => $width, 'edit' => $width, 'new' => $width ], 'id="table" style="width:90%"'); trace($tables = fetch(sql("show table status where left(name,5)<>'_dev_'"), 0)); for ($i = 0; list($table, $d) = each($tables); ) echo td([ sprintf('<label><nobr><input type="checkbox" name="name[]" value="%1$d"> %1$02d</nobr></label>', $i), sprintf('<a href="javascript:subsheet(3,\'%1$s\')">%1$s</a>', $table), 0, '-', '-', '-', '-', ], eval(zebra)); echo '</table>'; break; case 'page1': # table XXX for ($q = sql("explain `$PVAL`"), $i = 0; $r = fetch($q); ) { $i or $one_table = th(['##' => 'width="5%"'] + array_keys($r), 'id="table" style="width:75%"'); $row = array_values($r); $one_table .= td([-1 => $i] + $row, eval(zebra)); } echo "$one_table</table>"; set('xpage', 3); break; case 'page2': # Finalize show $html = th([ '##' => 'width="5%"', 'Files', 'Exist' => 'width="5%"', 'Comment' => 'width="50%"' ], 'id="table" style="width:90%"'); for ($i = 0; list($files, $v) = each($standard); ) { list($is, $meth, $desc) = explode('.', $v, 3); $list = explode(', ', $files); $file = $list[0]; if (1 == count($list)) { $ch = is_file($file) ? '' : ' checked'; $ex = !$ch ? '<big>YES</big>' : sprintf(span_r, 'NO'); } else for ($ch = $ex = ''; list(,$_) = each($list);) { if (!is_file($_)) $ch = ' checked'; $ex .= is_file($_) ? '<big>Y</big>' : sprintf(span_r, 'N'); } $com = ''; if (2 != $scheme && strstr($file, 'mvc')) { $ch = ''; $desc .= '<br>' . sprintf(span_r, '.. for MVC only'); } if (0 != $scheme && $file != str_replace(['ajax.', 'body.'], '', $file)) { $ch = ''; $desc .= '<br>' . sprintf(span_r, '.. for Main SKY scheme only'); } $desc .= tag($is ? sprintf(span_g, 'reusable code') : sprintf(span_b, 'app code')); $html .= td([ pad00(1 + $i), sprintf('<label>' . TPL_CHECKBOX . ' %s</label>', $files, $ch, $files), $ex, $desc ], eval(zebra)); } echo "$html</table>"; break; endswitch; else: # HTML PAGE $tmp = $funcs; array_walk($tmp, function(&$v) { $v = "set % to $v"; }); $cm1 = sprintf("{'%s':proc}", implode("':proc,'", $tmp)); $tmp = $inputs; array_walk($tmp, function(&$v) { $v = "set % to $v"; }); $cm2 = sprintf("{'%s':proc}", implode("':proc,'", $tmp)); ?> <div id="three" style="display:none"> <div style="display:none"> <p style="text-align:right; width:90%"><b>Table's list in Database</b></p> <div></div> </div> <div style="display:none"> Table name: `<b class="one"></b>`<?=pad(15)?><b><u>CREATE:</u></b><br> Type: <select id="type" onchange="e.typ(this)"><?=option(0, $objects)?></select>, add also: <label><input type="checkbox" onclick="e.tp2(this)"><span>show</span></label> <label><input type="checkbox" onclick="e.tp2(this)"><span>edit</span></label> <label><input type="checkbox" onclick="e.tp2(this)"><span>new</span></label><?=pad()?> in <?=form($GLOBALS,['is_front' => ['radio','',['admin section', '<span></span>'], 0,'class="front_sec"']],false)?> <br> Object name: <input class="one">, GENERATE FILES:<br> <div id="opt_admin"> <label><b>admin/_<span class="oname"></span>.php</b></label> - HTML+BODY<br> <?=pad()?><label><input type="checkbox">add ajax layout</label> </div><div id="qq0"> <label><input type="checkbox" checked><b>view/_<span class="oname"></span>.php</b></label> - HTML<br> <label><input type="checkbox" checked><b>main/b_<span class="oname"></span>.php</b></label> - BODY, else code can be written to <b>main/body.php</b><br> <label><input type="checkbox" checked><b>main/a_<span class="oname"></span>.php</b></label> - AJAX, else code can be written to <b>main/ajax.php</b> </div><div id="qq1"> <label><input type="checkbox" checked><b>view/_<span class="oname"></span>.php</b></label> - HTML<br> <label><input type="checkbox" checked><b><span class="oname"></span>.php</b></label> - BODY CODE,<br> <?=pad()?><label><input type="checkbox">add ajax layout</label> </div><div id="qq2"> <label><input type="checkbox" checked onclick="this.$(-1,2,this.checked)"><b>view/_<span class="oname"></span><span></span><span></span>.php</b></label> <?=pad()?><label><input type="checkbox" onclick="e.pfix(this)">add postfix `<b>_new</b>`</label> - HTML (VIEW)<br> <label><input type="checkbox" checked><b>main/mvc/c_<span class="oname"></span>.php</b></label> - CONTROLLER<br> <label><input type="checkbox" checked><b>main/mvc/t_<span class="oname"></span>.php</b></label> - MODEL T (for table)<br> <label><input type="checkbox"><b>main/mvc/m_<span class="oname"></span>.php</b></label> - MODEL M (general) </div> <p style="text-align:right; width:75%"><b>Table's definition, columns</b></p> <div id="one-table" style="display:none"></div> <br> <table width="100%" id="id-res"> <tr><td class="w33"> For <b>LIST</b>:<br> <a href="javascript:;" onclick="e.a(this,0)">deselect</a> ALL <a href="javascript:;" onclick="e.a(this,1)">select</a><br> <div class="tpl"></div><div class="tpl-h" style="display:none"></div><br> <label><input type="checkbox" checked name="lm">add to menu</label><br> <label><input type="checkbox" checked name="ld">add delete code</label><br> <?=pad()?><label><input type="checkbox" checked name="lr">via checkbox's array</label><br> <label><input type="checkbox" checked name="lp">add pagination</label> </td><td class="w33 leb"> For <b>SHOW</b>:<br> <a href="javascript:;" onclick="e.a(this,0)">deselect</a> ALL <a href="javascript:;" onclick="e.a(this,1)">select</a><br> <div class="tpl"></div><div class="tpl-h" style="display:none"></div><br> <label><input type="checkbox" checked name="sd">add delete code</label><br> <label><input type="checkbox" checked name="se">add edit link</label><br> </td><td class="w33 leb"> For <b>EDIT</b>:<br> <a href="javascript:;" onclick="e.a(this,0)">deselect</a> ALL <a href="javascript:;" onclick="e.a(this,1)">select</a><br> <div class="tpl"></div><div class="tpl-h" style="display:none"></div><br> <label><input type="checkbox" checked name="em">add to menu</label><br> </td></tr> </table><br> <input type="button" value="Generate (F2)" onclick="key_F2()" /><?=pad()?> </div> <div style="display:none"><!-- FINALIZE --></div> </div> <script type="text/javascript"> var selected = [1, 0, 0, 0], types = ['<?=implode("','", $objects)?>'], inputs = ['<?=implode("','", $inputs)?>'], custom = 1, one = '', apage = 0, postfix = 0, subload = [0, 0, 0]; function fint($x) { return $x ? 1 : 0; } function re_false() { return false; } function f9_3sheet() { subsheet(3, 2 == apage ? 0 : (one ? apage + 1 : apage + 2)); } function f2_3sheet() { switch (apage) { case 0: // gen list of controllers and models ajax('4&nice=&' + qs$($$('div', 'three', 0)), function(r, err) { mtop('2DO: ' +r); }); break; case 1: // gen 1 file var ary = [], sn = ['main=', 'sliced=', 'mvc='], oname = $$('span', 'three', 'oname', 0).text(), data = (is_front ? '4&' + sn[scheme] : '3&save=') + one + '&oname=' + oname + '&default=' + types[$('type').value], get_res = function(i) { var tpl = $('id-res').$$('div', 'tpl', i), s = ''; tpl.$$('div', 'bb', function(el, i) { if ('bb yy' == el.className) return; if (s) s += ' '; s += el.$$('span', 1).text() + ':' + el.$$('span', 2).text(); }); return s; }; for (var i = 0; i < 4; i++) if (selected[i]) { var s = get_res(3 == i ? 2 : i); if (!s) return mtop('Select fields first!', red); if (3 == i && selected[2]) data += '&new='; else data += '&' + types[i] + '=' + e$(s); } data += '&' + qs$('id-res'); if (!is_front) data += '&xa=' + fint($$('input', 'opt_admin', 0).checked); else if (2 == scheme) { // mvc ary = $('opt_admin', 3).$$('input'); data += '&xv=' + fint(ary[0].checked) + '&xc=' + fint(ary[2].checked) + '&xt=' + fint(ary[3].checked) + '&xm=' + fint(ary[4].checked); if (ary[0].checked) data += '&xx=' + (ary[1].checked ? types[$('type').value] : ''); } else { ary = $('opt_admin', scheme ? 2 : 1).$$('input'); data += '&xv=' + fint(ary[0].checked) + '&xb=' + fint(ary[1].checked) + '&xa=' + fint(ary[2].checked); } mtop(); ajax(data + '&front=' + is_front, function(r, err) { var c = green; if (err) r = err + r, c = red; if ('-' == r.charAt(0)) r = r.substr(1), c = red; mtop(r, c); }); break; case 2: // gen "finalize" ajax('4&files=&' + qs$($$('div', 'three', 0).$(4)), function(r, err) { mtop(r); }); break; } } var e = { anim: function(event) { var act = '+' == event.currentTarget.text(), bb = event.currentTarget.$(-1), ary = [], i, j, last, height, set_el = function(el) { if (act) { $$('td', 'w33', 'id-res', function(td, i) { if (td == el.$(-2)) j = i; }); e.was[j] = false; e.tbl(el.$(-1), j, true); } else { el.firstChild.onclick = e.anim; el.onmousedown = el.oncontextmenu = re_false; } }; event.currentTarget.text(act ? 'X' : '+'); bb.className = 'bb y' + (act ? '' : 'y'); bb.$(-1).$$('div', 'bb', function(row, i) { ary[i] = row; if (bb == row) j = i, height = row.h$(); }); if ((i = j) == (last = ary.length - 1) && act || !act && !j) return set_el(ary[j]); var end_fly, mem = ary[i].outerHTML, mutex = 0, k = act ? ary.length - i : i + 1, end_anim = function(el) { mutex++; if (el == ary[j]) setTimeout(end_fly = function() { // end if (mutex < k) return setTimeout(end_fly, 30); ary[act ? j++ : j--].$(''); el = act ? html(ary[last], 'ae', mem) : html(ary[0], 'bb', mem); for (; act ? j <= last : j > -1; act ? j++ : j--) ary[j].$({top:0, position:'static'}); set_el(el); }, 30); }, anim = function () { var el = ary[act ? ++i : --i]; el.style.position = 'relative'; anim$(el, {top: act ? -height : height}, 1, end_anim); if (i && i < last) setTimeout(anim, 20); }; ary[i].style.position = 'relative'; anim$(ary[i], {top: act ? height * (last - i) : -height * i}, end_anim); anim(); }, was: [0, 0, 0], tbl: function(tpl, i, act) { if (e.was[i] !== 0 && act == e.was[i]) return; e.was[i] = act; var func_menu = function() { tpl.$$('div', 'bb', function(el) { var proc = function(s) { var p = s.split(' '); el.$$('span', 2).html(p[p.length - 1]); } if ('bb y' == el.className) cmenu$(el, el.$$('span', 1).text(), 2 == i ? <?=$cm2?> : <?=$cm1?>); el.firstChild.onclick = e.anim; }); }, func_recurs = function() { func_menu(); sort$(tpl, 'y', func_recurs); }; tpl.$({borderTop: act ? '3px solid #0f0' : '3px solid red'}); if (act) { func_menu(); sort$(tpl, 'y', func_recurs); tpl.$(1, act = false); } else { var box = tpl.getBoundingClientRect(); tpl.$(1, {left:-box.right + box.left, top:7, width:box.right - box.left, height:box.bottom - box.top, display:'inline-block'}); } }, a: function(a, act) { var j, td = a.$(-1), tpl = td.$$('div', 'tpl', 0); $$('td', 'w33', 'id-res', function(el, i) { if (td == el) j = i; }); e.was[j] = false; tpl.$$('div', 'bb', function(el) { el.className = act ? 'bb y' : 'bb yy'; el.firstChild.text(act ? 'X' : '+').onclick = e.anim; if (!act) el.onmousedown = el.oncontextmenu = re_false; }); if (act) e.tbl(tpl, j, true); return; }, ini: function(tbl_html) { $$('td', 'w33', 'id-res', function(td, i) { tpl = td.$$('div', 'tpl', 0); if (tbl_html) { e.was = [0, 0, 0]; tpl.html(tbl_html).$$('div', 'bb', function(el) { var span = el.$$('span', 2); switch (span.text()) { case 'int': span.text(2 == i ? 'text' : 'as_is'); break; case 'text': span.text(2 == i ? 'textarea' : 'html()'); break; case 'char': span.text(2 == i ? 'text' : 'html()'); break; case 'dt': span.text(2 == i ? 'text' : 'date()'); break; } }); } if (tbl_html) tpl.$({position:'relative', display:'inline-block'}); if (i == 2) td.$$('b', 0).html(selected[2] && selected[3] ? 'NEW+EDIT' : (selected[3] ? 'NEW' : 'EDIT')); e.tbl(tpl, i, 2 == i ? selected[2] || selected[3] : selected[i]); }); adjust(); }, typ: function(el) { var i, v = el.value, v1 = types[v]; selected[v] = 1; for (i in types) if (i != v && i != '$$') { el = el.$(2); selected[i] = el.$$('span', 0).html(types[i]).previousSibling.checked; if (selected[i] && 'list' == types[i]) v1 = 'list'; } e.ini(); el = $('opt_admin', 3).$$('b', 1).html('_' + v1).$(-2); el.$$('span', 2).html(el.$$('input', 1).checked ? '_' + v1 : ''); }, tp2: function(el) { var i, v = el.$(1).html(); for (i in types) if (types[i] == v) selected[i] = el.checked; e.ini(); }, pfix: function(el) { el.$(-2).$$('span', 2).html(el.checked ? el.$(2).html() : ''); } }; function subsheet(q, n) { $('mtop', !q); $('three', 3 == (xpage = q)); var str = '', div = $$('div', 'three', 0), oname, set_divs; if (3 == q) { if (!t$(n)) n = apage; if (t$(n, 'string')) { one = n, n = 1; } if (scheme_ini != scheme) { $$('input', 'three', 'front_sec', function(el, i) { el.onclick = set_divs = function(e) { if (e) is_front = '1' == this.value; $('opt_admin', !is_front).$(1, 0 == scheme && is_front).$(1, 1 == scheme && is_front).$(1, 2 == scheme && is_front); } if (i) el.$(2).html('front (' + schemes[scheme_ini = scheme] + ')'); }); set_divs(); } div.$(0 == n).$(2, 1 == n).$(2, 2 == n); switch (apage = n) { case 0: if (!subload[0]) ajax('3&page0=', function(r, err) { if (2 == scheme) r += '<p><br>' + '<label><input type="checkbox" name="g_"> Use table with "dummy rows generator" for checked</label><br>' + '<label><input type="checkbox" name="m_"> Create MVC model files for checked</label><br>' + '<label><input type="checkbox" name="c_"> Create MVC controller files for checked</label>' + '<p><input type="button" value="Generate (F2)" onclick="key_F2()" />'; div.$$('div', 0).html(r); }); subload[0] = true; break; case 1: if (one == subload[1]) break; $$('*', 'three', 'one', function (el) { if ('input' != el.tagName.toLowerCase()) el.html(one); else { el.value = one; el.onkeyup = oname = function (e) { var v = e ? this.value : one; $$('span', 'three', 'oname', function(el) { el.html(v); }); } } }); oname(); ajax('3&page1=' + one, function(r, err) { $('one-table', true).html(r); ajax('1&gen=' + one, function(r, err) { var json = callback(r, err, '(visual) '); e.ini(json.html); }); }); subload[1] = one; break; case 2: if (!subload[2]) ajax('3&page2=', function(r, err) { div.$(4).html( '<p style="text-align:right; width:90%"><b>Common files to write (' + schemes[scheme] + '):</b></p>' + r + '<p><br><input type="button" value="Generate (F2)" onclick="key_F2()" /><?=pad()?>' ); }); subload[2] = true; break; } var menu = ['List of tables', one, 'Finalize']; for (var i = 0; i < 3; i++) if (menu[i]) { str += (i ? ' | ' : '') + '<a href="javascript:subsheet(3,'+ i + ')"' + (i == apage ? ' class="selected"' : '') + '>' + (1 == i ? 'Table: ' : '') + menu[i] + '</a>'; } str += ' (F9)'; } $('links', 2).html(str); if (1 == q) _loaded(ini_nd); } </script><? endif; |
• N3: WRITE FILE: _dev/util/v_database.php
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | <?php defined('START') and AUTH_OK or die; $div = '<div class="bb %s"><div class="nu">%s</div><span class="mv">%s</span> <span>%s</span> <span>%s</span></div>'; $tpl = "CREATE TABLE `table` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) DEFAULT NULL, `dt` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8"; if (START == 'ajax'): switch (PAGE): case 'pos': set([ 'tbls' => serialize(json_decode($PVAL, true)), 'xpage' => 1, ]); return print '{}'; case 'std': $a1 = Record::ary(10); $a2 = Record::ary(9); return print implode("\n", $a1[1][2]) . "\n" . implode("\n", $a2[2][2]) . "\n" . sprintf("update memory set tmemo=%s where id=3", escape(implode("\n", $a2[3][2]))); case 'dum': case 'gen': # show for file generator if ('dum' == PAGE) dummy_gen($PVAL); $dst = $PVAL; $PAGE = $alt = 'alt'; break; case 'ren': # rename column, change type list($dst, $i, $new) = explode('.', $PVAL, 3); $row = sql("@show create table `$dst`"); $create = explode("\n", unl($row[$dst])); list($cname, $def) = explode(' ', trim($create[$i], " \t,"), 2); sql($alt = "alter table `$dst` change $cname " . (isset($p_rc) ? "`$new` $def" : "$cname $new")); $PAGE = 'alt'; break; case 'mov': # move column list($dst, $fr, $to) = explode('.', $PVAL, 3); $row = sql("@show create table `$dst`"); $row = explode("\n", unl($row[$dst])); if ($to > $fr) $to++; $fr = preg_match("|^(`\w+`.*?),?$|", trim($row[$fr + 1]), $n) ? $n[1] : 0; $to = $to ? (preg_match("|^(`\w+`).*?,?$|", trim($row[$to]), $n) ? "after $n[1]" : 0) : 'first'; sql($alt = "alter table `$dst` modify $fr $to"); $PAGE = 'alt'; break; case 'alt': # add column list($dst, $src, $i) = explode('.', $PVAL, 3); $row = $src ? sql("@show create table `$src`") : [$src = $i = 2 => $tpl]; $cex = array_keys(sql("@explain `$dst`")); $create = explode("\n", unl($row[$src])); list($cname, $def) = explode(' ', trim($create[$i], " \t,"), 2); for ($cname = substr($cname, 1, -1); in_array($cname, $cex);) $cname .= 1; sql($alt = "alter table `$dst` add `$cname` $def"); break; case 'add': # add table $row = $PVAL ? sql("@show create table `$PVAL`") : [$PVAL = 'table' => $tpl]; $tbls = sql("@show tables"); for ($i = 1; 1; $i++) if (!in_array($dst = $PVAL . $i, $tbls)) break; $alt = str_replace("`$PVAL`", "`$dst`", unl($row[$PVAL])); sql($alt); $PAGE = 'alt'; break; endswitch; #'get': 'ini': 'flt': $PVAL or $PVAL = '!_dev_'; if ('flt' == PAGE) set('filter', $PVAL); if ('alt' == $PAGE) $where = "name='$dst'"; elseif (1 == $PVAL) $where = "name in ('visitors','users','memory')"; else { $not = '!' == $PVAL[0] ? '!' : ''; $where = sprintf("'%s'$not=left(name,%d)", $PVAL = ($not ? substr($PVAL, 1) : $PVAL), strlen($PVAL)); } $tables = sql("@show table status where $where"); for ($out = $table_ = ''; list($table, $d) = each($tables); $out .= '</div>') { 'alt' == $PAGE or $out .= '<div class="tpl">'; if ($ng = 'gen' != PAGE) $out .= sprintf($div, 'blue', '+', "$d[3]rows", "<b>$table</b>", "$d[0]"); $q = sql("explain `$table`"); for ($i = 0; $r = fetch($q, true); $i++) { if ($r[3] && $ng) $r[0] = "<b>$r[0]</b>"; if ($ng) $type = $r[1] . ('NO'==$r[2]?' !N ':' ') . ($r[5] ? ' AI' : ($r[4] === null ? '' : "'$r[4]'")); elseif (preg_match("/^[a-z]*text$/i", $r[1])) $type = 'text'; elseif (preg_match("/^[a-z]*char/i", $r[1])) $type = 'char'; elseif ('datetime' == $r[1]) $type = 'dt'; else $type = 'int'; $out .= sprintf($div, 'y', 'X', pad00($i), $r[0], $type); } 'alt' == $PAGE or $out .= '</div>'; $table_ = $table; } $ary = ['html' => $out, 'name' => $table_]; if ('alt' == $PAGE) $ary += ['log' => $alt]; if ('ini' == PAGE) $ary += [ 'pos' => unserialize($tbls), 'tpl' => '<div class="tpl">' . sprintf($div, 'blue', '+', '0rows', '', 'MyISAM') . sprintf($div, 'y', 'X', '00', 'id', 'int(11) unsigned !N AI') . sprintf($div, 'y', 'X', '01', 'name', 'varchar(100)') . sprintf($div, 'y', 'X', '02', 'dt', 'datetime !N') . '</div>', ]; trace($ary); echo json_encode($ary); else: # HTML PAGE ?> <form id="f1" style="width:1px;height:1px;"> <div id="inner"> <div id="hold"> <div id="bh" title="drag to/from from here to create/drop mysql tables">table's hole</div> <div id="store"></div> </div> </div> <pre id="log"></pre> <div id="tpl"><div class="tpl"></div></div> </form> <script type="text/javascript"> var mtv, showlog = 0, create = 0, tbl_cnt = 0, _filter = '<?=$filter?>', tbl_sel1 = 0, tbl_sel2 = '.', ini_nd = []; function _dev(tbl, op) { var ary = ['_dev_codebase', '_dev_help', '_dev_memory', '_dev_packages', '_dev_recycled']; for (i in ary) if (ary[i] == tbl) { alert('Cannot ' + op + ' DEV.SKY. tables'); return false; } return true; } function walk(func) { var name, ary = []; $$('div', 'store', 'tpl', function(el, i) { ary[i] = [name = el.$$('span', 1).text(), el]; if (func) func(el, i, name); }); return ary; } function runsql(sql, func) { ajax('sql_query&sql=' + e$(sql = trim(sql)) + '&pos=-1', function(r, err) { if (!html('log')) html('log', '<div onclick="f2_1sheet();this.html(-1,\'\')">clear log</div>').onscroll = function(e) { this.$$('div', 0).$({top:this.scrollTop}); }; var pos = r.indexOf('<hr>'); if (-1 != pos) r = r.substr(pos + 4); html('log', 'ab', sql + '<span style=color:yellow> | ' + trim(r) + '</span>' + "\n\n"); if (-1 == r.indexOf('Query OK')) showlog = 0, f2_1sheet(); if (func) func(); }); } function f9_1sheet() { // create standard tables if (!confirm('Create standard tables?')) return; ajax('1&std=', function(r, err) { runsql(r, function() { add_tbl('1'); }); }); } function f2_1sheet() { // show log showlog = !showlog; adjust(); } function add_tbl(s, func) { var mode = tbl_cnt ? 'get' : 'ini'; if ('+' == s.substr(0, 1)) mode = 'flt', s = s.substr(1); ajax('1&' + mode + '=' + s, function(r, err) { var j = 0, json = callback(r, err, '(visual) '); html('store', 'be', json.html); walk(function(div, i, name) { if (!func && i < tbl_cnt) return; tbl_cnt++; div.$({left:j * 16, top:32 + 16 * j++, zIndex:i}); set_tbl(div, name); }); if (func) { html('tpl', json.tpl); func(json.pos); } }); } function flt_tbl() { html('store', ''); tbl_cnt = 0; _loaded(true); } function _loaded(is) { if (is !== true) $('links', 2).html( 'filter tables: <input id="ftbls" value="' + _filter + '" /><a href="javascript:flt_tbl()">-------->></a> ' + '<a href="javascript:f2_1sheet()">Show log (F2)</a> ' + '<a href="javascript:f9_1sheet()" title="Create standard tables">CST (F9)</a>' ); if (is === false) return; var val = $('ftbls').value; if (is === true) { _filter = val; val = '+' + val; } ini_nd = false; add_tbl(val, function(pos) { setTimeout(function () { walk(function(div, i, name) { if ('object' == typeof pos[name]) anim$(div, {left:pos[name].x, top:pos[name].y}); }); }, 300); }); } $('bh').onmouseout = function(e) { this.$({background:'#000'}); if (create) create++; } $('bh').onmousedown = function(e) { var tpl = 0, box = this.getBoundingClientRect(), inn = $('inner'); create = 1; this.$({background:'red'}); walk(function(div, i, name) { if (name == tbl_sel1) tpl = div.html(); }); tpl = tpl ? '<div class="tpl">' + tpl + '</div>' : html('tpl'); var div = html('store', 'ab', tpl).$({left:e.clientX - box.left - 30 + inn.scrollLeft, top:e.clientY - box.top - 5 + inn.scrollTop, zIndex:tbl_cnt}); div.$$('span', 0).html('0rows'); div.$$('span', 1).html('???'); set_tbl(div, '???', e); } function set_tbl(tbl, tbl_name, event) { var under_hole = false, xy, result = function(r, err) { var json = callback(r, err, '(visual) '); tbl.html(json.html); html('log', 'ab', json.log + '<span style=color:yellow> | ??</span>' + "\n\n"); if ('???' == tbl_name) tbl_name = json.name, tbl_cnt++; set_tbl(tbl, tbl_name); }; tbl.onmousedown = function() { var z = parseInt(tbl.style.zIndex); if (z >= tbl_cnt - 1) return; walk(function(div, i, name) { if (tbl_name == name) tbl.style.zIndex = tbl_cnt - 1; else if (div.style.zIndex < z) return; else div.style.zIndex--; }); } sort$(tbl, 'y', function(from, to) { ajax('1&mov=' + tbl_name + '.' + from + '.' + to, result); }); tbl.$$('div', 'bb', function(div, i) { var s1 = div.$$('span', 1), rename = function() { var el = t$(this, 'node') ? this : s1; var val = el.text(), key = '<' == el.html().substr(0, 1), selection = window.getSelection(), range = document.createRange(); el.onmousedown = null; el.contentEditable = true; el.$({background:'#d4e9f7'}); range.selectNodeContents(el); selection.removeAllRanges(); selection.addRange(range); el.onkeydown = function(e) { if (e.keyCode == 13) { // ENTER el.contentEditable = false; el.$({background:'transparent'}); el.onmousedown = re_false; el.html(key ? '<b>' + el.text() + '</b>' : el.text()); if (i) ajax('1&ren=' + tbl_name + '.' + i + '.' + el.text() + (el === s1 ? '&rc=' : ''), result); else { runsql('rename table `' + val + '` to `' + (tbl_name = el.text()) + '`'); if (tbl_sel1 == el.text()) tbl_sel1 = tbl_name; if (tbl_sel2.substr(0, tbl_sel2.indexOf('.')) == el.text()) tbl_sel2 = tbl_name + '.' + tbl_sel2.substr(1 + tbl_sel2.indexOf('.')); } } else if (e.keyCode == 27) { el.contentEditable = false; el.$({background:'transparent'}); el.onmousedown = re_false; el.html(key ? '<b>' + val + '</b>' : val); lock_esc = true; } } return false; } if (i) { // columns div.firstChild.onclick = function() { // drop column if (_dev(tbl_name, 'alter')) runsql('alter table `' + tbl_name + '` drop `' + div.$$('span', 1).text() + '`'), div.$(''); } div.onclick = function() { $$('div', 'store', 'y', function(bb) { bb.className = bb == div ? 'bb y act2' : 'bb y' if (bb == div) tbl_sel2 = tbl_name + '.' + i; }) } s1.ondblclick = function() { // add / drop a key var ast = s1.text(), noi = ast == s1.html(); s1.html(noi ? '<b>' + ast + '</b>' : ast); runsql((noi ? 'create' : 'drop') + ' index `' + ast + '` on `' + tbl_name + (noi ? '` (`' + ast + '`)' : '`')); } s1.oncontextmenu = rename; div.$$('span', 2).oncontextmenu = rename; } else { // head div.firstChild.onclick = function() { // add column ajax('1&alt=' + tbl_name + '.' + tbl_sel2, result); } var engine = function (str) { runsql(str), div.$$('span', 2).text('M' == str.substr(-1) ? 'MyISAM' : 'InnoDB'); }, util = function (sql) { location = '?utility=sql_query&sql=' + e$(sql); }; var eng = div.$$('span', 2).text(), menu = { 'rename table %': rename, 'truncate table `%`': runsql, 'alter table `%` auto_increment=1': runsql, 'select * from `%` limit 100 -- (util)': util, 'explain extended select * from `%` -- (util)': util, 'use "dummy-rows gen" for `%`': function (str) { ajax('1&dum=' + tbl_name, result); } }; if ('MyISAM' != eng) menu['alter table `%` engine=MyISAM'] = engine; if ('InnoDB' != eng) menu['alter table `%` engine=InnoDB'] = engine; cmenu$(div, tbl_name, menu); } }); drag$(tbl, tbl.firstChild, function() { // DOWN xy = {left:parseInt(tbl.style.left), top:parseInt(tbl.style.top)}; if (!create) walk(function(div, i, name) { div.className = 'tpl' + ((i = tbl == div) ? ' act1' : ''); if (i) tbl_sel1 = name; }); }, function() { // UP if (under_hole) { if (create) tbl.$(''); else { var sql = 'drop table ' + tbl_name; if (!_dev(tbl_name, 'delete') || !confirm(sql + '?')) anim$(tbl, xy); else { tbl.$(''); runsql(sql); tbl_cnt--; if (tbl_sel1 == tbl_name) tbl_sel1 = 0; if (tbl_sel2.substr(0, tbl_sel2.indexOf('.')) == tbl_name) tbl_sel2 = '.'; } } } else if (create > 1) ajax('1&add=' + tbl_sel1, result); tbl.$({left:16 * Math.floor(tbl.offsetLeft / 16), top:16 * Math.floor(tbl.offsetTop / 16)}); create = 0; $('bh', {background: '#000'}); }, function() { // MOVE under_hole = parseInt(tbl.style.left) < 96 + $('inner').scrollLeft && parseInt(tbl.style.top) < 32 + $('inner').scrollTop; $('bh', {background: under_hole ? 'red' : '#000'}); if (mtv) clearTimeout(mtv); mtv = setTimeout(function() { // store position var s = {}; walk(function(div, i, name) { s[name] = {x: parseInt(div.style.left), y: parseInt(div.style.top)} }); ajax('1&pos=' + e$(JSON.stringify(s))); }, 3000); }, event); } function adjust(x, y) { var box = f1.parentNode.getBoundingClientRect(), yy = Math.round(box.bottom - box.top), i = sheet(); y = Math.round(yy / 2); switch (i) { case 1: $('inner', {width:x = 16* Math.round((x - 185) / 16), height:showlog ? y : y*2}); $('log', {width: x, height:showlog ? y : 0}); break; case 2: $('no-index', {height:yy - 140}); break; case 3: $$('div', 'id-res', 'tpl-h', function(el) { box = el.$(-1).getBoundingClientRect(); el.$({left:box.left + $().body.scrollLeft, top:box.top + $().body.scrollTop, width:el.$(-1).w$(), height:el.$(-1).h$()}); }); break; } } </script> <style type="text/css"> #inner { overflow:auto; position:relative; } #hold {background:url(dev.php?img=13.box.png); z-index:-1; width:2000px;height:2000px; } #log {font:normal 12px courier; overflow-y:auto; line-height:14px; background:#005; color:#0f0; margin-top:0; position:relative;} #log div {width:90px; position:absolute;right:0px;top:0; background:yellow;color:red; padding:1px 3px; cursor:pointer } #log div:hover {background:red;color:#fff; } #allow {padding: 5px 3px;} #bh {width:96px; background:#222; color:#fff; padding:8px 0; cursor:move; text-align:center; position:fixed; } #tpl {display: none} .tpl {background:#fff; position:absolute; border-left:1px solid #77f; border-right:1px solid #77f } .bb {border-bottom:1px solid #aaa; height:15px !important; font:normal 12px courier; white-space:nowrap; padding:0 3px} .bb span {cursor: default } .blue {background: #b9d8f7} .y {background: #c2f292} .yy {background: #ddd} span.mv {cursor:move} .nu {height: 15px; font:normal 11px courier; line-height:15px; padding:0 2px; cursor:pointer; float:right; } .nu:hover {background:#33f; color:#fff; } .bd a {color:red;} .act1 {border-left:1px solid red; } .act2 {border-bottom:1px solid red; } #ftbls { font-size:10px; padding: 0 2px; position:absolute; width:55px;} .w33 {width: 33%; vertical-align:top; overflow:hide; padding-left:20px;} .leb {border-left: 2px solid silver} .tpl-h {position:absolute;background:#fff;opacity:0.6;z-index:100; display:none;} </style><? endif; |
• N4: WRITE FILE: _dev/util/v_design.php
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 | <?php defined('START') and AUTH_OK or die; if (START == 'ajax'): switch (PAGE): case 'file': ; break; case 'html': $dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadHTML("<html>$PVAL</html>"); file_put_contents('index.visual', "<html>$PVAL</html>"); # $dom->saveHTML() break; endswitch; else: # HTML PAGE ?> <div id="tbl" style="display:none"> <table><tr><td> <table border="1" id="mockup"> <tr><td colspan="3"> </td></tr> <tr><td id="middle"> </td><td> </td><td> </td></tr> <tr><td colspan="3"> </td></tr> </table> </td><td> <table height="100"> <tr><td> <label><input type="checkbox" checked /> head</label><br> </td></tr><tr><td> <label><input type="radio" name="cs" /> 1 column</label> <label><input type="radio" name="cs" /> 2 column</label> <label><input type="radio" name="cs" checked /> 3 column</label><br> </td></tr><tr><td> <label><input type="checkbox" checked /> footer</label> </td></tr> </table> </td></tr></table> <p>design showed in frame:<br> <?if(is_file('index.php')):?><iframe id="frame" src="index.php"></iframe><?else:?> <div id="no-index">index.php not found</div> <?endif?> </div> <script type="text/javascript"> function f2_2sheet() {} function drt() { alert(); } $$('input', 'tbl', function(el, i) { el.onclick = function(e) { switch (i) { case 0: drt(); break; case 1: drt(); break; case 2: drt(); break; case 3: drt(); break; case 4: drt(); break; } } }); sheet(xpage); </script> <style type="text/css"> #mockup td { min-width: 50px; } #middle { height: 50px; } #frame, #no-index { width: 100%; border: 1px solid #f00; background: #D4C3F7; } #no-index { font: bold 46px Arial; color: purple; } #table td {padding: 0 2px;} </style><? endif; |
• N5: WRITE FILE: _dev/util/v_front.php
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | <?php defined('START') and AUTH_OK and START == 'ajax' or die; set('is_front', 1); $set = array_combine($objects, [@$p_list, @$p_show, @$p_edit, @$p_new]); $php = "<?php defined('START') or die;\n"; $app_menu = @unserialize($app_menu) or $app_menu = []; switch (PAGE): case 'main': ; print_r($_POST); echo ' ' . PAGE; break; case 'nice': ; print_r($_POST); echo ' ' . PAGE; break; case 'mvc': ; $crud = (int)(bool)@$p_list + (int)(bool)@$p_show + (int)((bool)@$p_edit || (bool)@$p_new); $tab = $crud > 1 ? "\t" : ''; if ($p_xv): # view file $out = "<?php eval(\$me) or die ?>\n\n<h1><?=html(\$v_h1)?></h1>\n\n"; if (@$p_list) { if ($tab) $out .= "<?if('list' == \$k_->type):?>\n"; if ($p_lp) $out .= "$tab<?=\$e_{$p_oname}->pagination?>\n"; if ($frm = $p_ld && $p_lr) $out .= "$tab<form method=\"post\">\n"; $out .= "$tab<table width=\"100%\">\n"; $out .= "$tab<?for(;eval(\$e_{$p_oname}->row);):?>\n$tab<tr>\n"; $ary = explode(' ', $p_list); foreach ($ary as $one) { list ($name, $type) = explode(':', $one); $out .= "$tab\t<td><?=\$row->$name?></td>\n"; } if ($p_ld) $out .= "$tab\t<?if(1==\$user->pid):?><td><?=\$row->_del?></td><?endif?>\n"; $out .= "$tab</tr>\n$tab<?endfor?>\n"; $out .= "$tab</table>\n"; if ($frm) $out .= "$tab<?if(1==\$user->pid):?><div class=\"fr\"><input type=\"submit\" value=\"delete checked\"></div><?endif?>\n"; if ($frm) $out .= "$tab</form>\n"; if ($p_lp) $out .= "$tab<?=\$e_{$p_oname}->pagination?>\n"; if ($p_lm) $app_menu += [$p_oname => "List $p_oname"]; } if (@$p_show) { if ($tab) $out .= @$p_list ? "\n<?else" . (3 == $crud ? "if('show' == \$k_->type):?>\n" : ":?>\n") : "<?if('show' == \$k_->type):?>\n"; $out .= "$tab<table width=\"100%\">\n"; $ary = explode(' ', $p_show); foreach ($ary as $one) { list ($name, $type) = explode(':', $one); $out .= "$tab\t<tr><td>$name</td><td><?=\$row->$name?></td></tr>\n"; } $out .= "$tab</table>\n"; if ($p_se) $out .= "$tab<br><a href=\"?edit=<?=\$row->id?>\">edit</a>\n"; if ($p_ld) $out .= "$tab<?if(1==\$user->pid):?><br><a href=\"?delete=<?=\$row->id?>\">delete</a><?endif?>\n"; if (2 == $crud && @$p_list) $out .= "<?endif?>\n"; } if (@$p_edit || @$p_new) { if ($tab) $out .= sprintf("\n<?else: #%s?>\n", (@$p_edit ? 'edit ' : '') . (isset($p_new) ? 'new ' : '')); $out .= "$tab<?if(\$v_mess):?><div class=\"message\"><?=\$v_mess?></div><?endif?>\n"; $out .= "$tab<form method=\"post\">\n"; $out .= "$tab<table width=\"100%\">\n"; $ary = explode(' ', @$p_edit ? $p_edit : $p_new); foreach ($ary as $one) { list ($name, $type) = explode(':', $one); if ('now()' == $type) continue; elseif ('textarea' == $type) $in = "<textarea name=\"$name\"><?=\$row->$name?></textarea>"; elseif ('select' == $type) $in = "<select name=\"$name\">\n<option value=\"1\">1</option>\n</select>"; else $in = "<input type=\"$type\" name=\"$name\" value=\"<?=\$row->$name?>\" />"; $out .= "$tab\t<tr><td>$name</td><td>$in</td></tr>\n"; } $out .= "$tab</table>\n"; $out .= "$tab<input type=\"submit\" value=\"do post\" />\n"; $out .= "$tab</form>\n"; if ($tab) $out .= "<?endif?>\n"; if ($p_em) $app_menu += ["$p_oname?new" => "New $p_oname"]; } if ($p_xx) $p_oname .= "_$p_xx"; wr_file("view/_$p_oname.php", $out); endif; if ($p_xc): # controller $out = "$php\nclass c_$p_oname extends SKY_CONTROLLER\n{"; if (@$p_list) { $out .= "\n\tfunction empty_c() { #list\n"; if ($p_ld && $p_lr) { $out .= "\t\tif (\$_POST) {\n"; $out .= "\t\t\t1 == self::\$user->pid or die;\n"; $out .= "\t\t\t\$this->t_{$p_oname}->delete(\$_POST['id']);\n"; $out .= "\t\t}\n"; } $out .= "\t\t\$this->_v = [\n"; $out .= "\t\t\t'h1' => 'List $p_oname',\n"; $out .= "\t\t\t'k_type' => 'list',\n"; $ipp = $p_lp ? 45 : ''; $out .= "\t\t\t'e_$p_oname' => \$this->t_{$p_oname}->listing($ipp),\n\t\t];\n"; $out .= "\t}\n"; } if ($p_ld && !$p_lr || $p_sd) { $out .= "\n\tfunction c_delete(\$id) {\n"; $out .= "\t\t1 == self::\$user->pid or die;\n"; $out .= "\t\t\$this->t_{$p_oname}->delete(\"id=\$id\");\n"; $out .= "\t\tjump('$p_oname');\n"; $out .= "\t}\n"; } if (@$p_edit || @$p_new) { # edit new if (@$p_edit && isset($p_new)) { $out .= "\n\tfunction c_new() {\n"; $out .= "\t\treturn \$this->c_edit();\n"; $out .= "\t}\n"; $is = 'is_numeric($id) or die;'; $xs = "\$id ? 'Edit $p_oname' : 'New $p_oname'"; } else { $is = @$p_new ? false : 'is_numeric($id) && $id > 0 or die;'; $xs = @$p_new ? "'New $p_oname'" : "'Edit $p_oname'"; } $ary = explode(' ', @$p_edit ? $p_edit : $p_new); $out .= sprintf("\n\tfunction c_%s(%s) {\n", @$p_edit ? 'edit' : 'new', $ys = @$p_new ? '' : '$id = 0'); if ($is) $out .= "\t\t$is\n"; $ys = $ys ? '$id' : 0; $out .= "\t\tif (\$_POST) {\n"; if (!$ys) $out .= "\t\t\t\$id = 0;\n"; $out .= "\t\t\tif (!\$mess = \$this->t_{$p_oname}->replace(\$id)) jump(\"{$p_oname}?id\$id\");\n"; $out .= "\t\t\t\$row = (object)\$_POST;\n"; $out .= "\t\t} else {\n"; $out .= "\t\t\tif (!\$row = \$this->t_{$p_oname}->one($ys)) return 404;\n"; $out .= "\t\t}\n"; $out .= "\t\t\$this->t_{$p_oname}->_html(\$row);\n"; $out .= "\t\t\$this->_v = [\n"; $out .= "\t\t\t'h1' => $xs,\n"; $out .= "\t\t\t'd_row' => \$row,\n"; $out .= "\t\t\t'mess' => \$_POST ? \$mess : false,\n"; $out .= "\t\t];\n\t}\n"; } if (@$p_show) { $ary = explode(' ', $p_show); $out .= "\n\tfunction __call(\$name, \$args) { #show\n\t\tpreg_match(\"/^c_id(\d+)$/\", \$name, \$m) or die;\n"; $out .= "\t\tif (!\$row = \$this->t_{$p_oname}->one(\$id = \$m[1])) return 404;\n"; $out .= "\t\t\$this->t_{$p_oname}->fix_show(\$row);\n"; $out .= "\t\t\$this->_v = [\n"; $out .= "\t\t\t'h1' => 'Show $p_oname',\n"; $out .= "\t\t\t'd_row' => \$row,\n"; $out .= "\t\t];\n\t}\n"; } wr_file("main/mvc/c_$p_oname.php", "$out}\n"); endif; if ($p_xt): # model t $out = "$php\nclass t_$p_oname extends SKY_MODEL_T\n{"; if (@$p_edit || @$p_new) { # edit new $out .= "\n\tfunction replace(&\$id, \$validate = true) {\n"; $out .= "\t\treturn parent::replace(\$id, [\n"; $ary = explode(' ', @$p_edit ? $p_edit : $p_new); foreach ($ary as $one) { list ($name, $type) = explode(':', $one); if ('now()' == $type) $out .= "\t\t\t'$name' => 'now()',\n"; else $out .= sprintf("\t\t\t'$name' => ['.+', '%s can\'t be empty'],\n", ucfirst($name)); } $out .= "\t\t]);\n"; $out .= "\t}\n"; } if (@$p_show) { $out .= "\n\tfunction fix_show(\$row) {\n"; $ary = explode(' ', $p_show); foreach ($ary as $one) { list ($name, $type) = explode(':', $one); if ('html()' == $type) $out .= "\t\t\$row->{$name} = html(\$row->{$name});\n"; if ('date()' == $type) $out .= "\t\t\$row->{$name} = self::\$sky->date(\$row->{$name});\n"; } $out .= "\t}\n"; } if (@$p_list) { $out .= "\n\tfunction fix_list(\$row) {\n"; $ary = explode(' ', $p_list); foreach ($ary as $one) { list ($name, $type) = explode(':', $one); if ('html()' == $type) $out .= "\t\t\$row->{$name} = html(\$row->{$name});\n"; if ('date()' == $type) $out .= "\t\t\$row->{$name} = self::\$sky->date(\$row->{$name});\n"; if ('as_link' == $type) $out .= sprintf("\t\t\$row->{$name} = a(\$row->{$name}, \"%s\$row->id\");\n", @$p_show ? '?id' : '?edit='); } if ($p_ld && $p_lr) $out .= "\t\t\$row->_del = sprintf(TPL_CHECKBOX, \$row->id, '');\n"; elseif ($p_ld) $out .= "\t\t\$row->_del = a('delete', \"?delete=\$row->id\");\n"; $out .= "\t}\n"; $ipp = $p_lp ? '$ipp' : ''; $out .= "\n\tfunction listing($ipp) {\n"; $out .= "\t\treturn parent::_list($ipp) + ['callback' => [\$this, 'fix_list']];\n"; $out .= "\t}\n"; } wr_file("main/mvc/t_$p_oname.php", "$out}\n"); endif; if ($p_xm): # model m $out = "$php\nclass m_$p_oname extends SKY_MODEL_M\n{"; wr_file("main/mvc/m_$p_oname.php", "$out}\n"); endif; if ($app_menu) { set('app_menu', serialize($app_menu)); $common_c = 'main/mvc/common_c.php'; file_exists($common_c) or $_POST['id'][0] = $common_c; } else break; case 'files': is_dir('var') or mkdir('var'); is_dir('var/hard') or mkdir('var/hard'); if ($_POST) { $cache = []; eval(sql("+select tmemo from _dev_memory where id=10")); if (isset($_POST['id'])) foreach ($_POST['id'] as $files) foreach (explode(', ', $files) as $fn) { $where = "id < 100 and (name='f:$fn' or `code` like '%WRITE FILE: {$fn}%')"; if (!$id = sql("+select id from _dev_codebase where $where order by id limit 1")) continue; $ary = isset($cache[$id]) ? $cache[$id] : ($cache[$id] = Record::ary($id)); $file = false; foreach ($ary as $one) if ('WRITE FILE' == $one[0] && $fn == $one[1]) { $file = implode($u_system_eol, $one[2]); if (1 != rectype($fn)) $file = base64_decode($file); // decode if not a text break; } if (false === $file) $notf[] = $fn; else { if ('index.php' == $fn) $file = str_replace( '<? require \'view/right.php\' ?>', '<h3>Menu</h3><?=$y_menu?>', $file ); wr_file($fn, preg_replace_callback('|(\{\$a_\w+\})|sm', 'replace_a_vars', $file)); } } } elseif ('files' == PAGE) echo "No files selected<br>"; if ('files' != PAGE && $app_menu) { $lines = file($common_c); foreach ($lines as &$line) if (preg_match('/^\s*\$menu =/s', $line)) $line = "\t\t\$menu = " . strtr(var_export($app_menu, true), ["\n" => '', "\r" => '', "\t" => '']) . ";\n"; file_put_contents($common_c, implode('', $lines)); } endswitch; $mess = ', find old version in the dir: `_dev/temp/visual`'; if (!$size && $overwrite) echo "Cannot write files<br>"; if ($notf) printf("Not found: %s<br>", count($notf) > 3 ? count($notf) . 'files' : implode(', ', $notf)); if ($ovwr) $overwrite ? printf("Files overwritten: %s$mess<br>", count($ovwr) > 3 ? count($ovwr) . 'pcs' : implode(', ', $ovwr)) : printf("-Files exists: %s, cannot overwrite<br>", count($ovwr) > 3 ? count($ovwr) . 'pcs' : implode(', ', $ovwr)); if ($wrs && $wrs != $ovwr) printf("New files written: %s<br>", count($wrs) > 3 ? count($wrs) . 'pcs' : implode(', ', $wrs)); |
Записи Codebase (89)
Статус SKY.
Current version: 1.001
Coresky records: 22
Local (DEV) records: 89
Web (all) records: 105
Download: dev.php
Coresky records: 22
Local (DEV) records: 89
Web (all) records: 105
Download: dev.php