예제 #1
0
파일: msqedit.php 프로젝트: philum/cms
function msqdt_build($p, $o)
{
    req('msql');
    $ra['_menus_'] = explode(',', $o);
    $r = msql_read_b('', ses('msqdt'), '', '', $ra);
    $murl = sesm('murl', murl('users', '', ses('qb'), $p, ''));
    if ($r) {
        return draw_table($r, $murl, '');
    }
}
예제 #2
0
파일: msql.php 프로젝트: philum/cms
function msql_adm($msql = '')
{
    //echo br();
    $root = sesm('root', 'msql/');
    $auth = $_SESSION['auth'];
    $ath = 6;
    //auth_level_mini
    $wsz = define_s('wsz', 700);
    $msql = $msql ? $msql : $_GET['msql'];
    $_SESSION['page'] = $_GET['page'] ? $_GET['page'] : 1;
    #boot
    if ($msql && $msql != '=') {
        $url = sesm('url', '/msql/');
        $ra = msql_boot($msql);
        $_SESSION['msql_boot'] = $ra;
        list($bases, $base, $dirs, $dir, $prefixes, $prefix, $files, $table, $version, $folder, $node) = $ra;
        //build url
        $murl = sesm('murl', murl($base, $dir, $prefix, $table, $version));
        //b/d/p_t_v
        $basename = $root . $folder . $node;
        $is_file = is_file($basename . '.php');
        $lk = sesm('lk', $url . $folder . $node . gpage());
        $folder = $root . $folder;
        //conformity
        msql_adm_head($lk, $base, $prefix, $table, $version);
    }
    $def = ajx($_POST['def'] ? $_POST['def'] : $_GET['def'], 1);
    if ($_GET['see']) {
        $ret[] = verbose($ra, 'dirs');
    }
    //auth
    if ($base == 'users' && $prefix == $_SESSION['USE']) {
        $_SESSION['ex_atz'] = 1;
    }
    if ($auth >= $ath && $_SESSION['ex_atz'] or $auth >= 6) {
        $authorized = true;
    }
    $lkb = $lk . '&';
    #load
    //reqp('msql'); $msq=new msql($base,$node); if($is_file)$defs=$msq->load();
    if (get('repair')) {
        msql_repair($folder, $node);
    }
    //old
    if ($is_file) {
        $defs = read_vars($folder, $node, $defsb);
    }
    //if(!$defs)$ret[]=verbose($ra,'');
    if ($defs['_menus_']) {
        $defsb['_menus_'] = $defs['_menus_'];
    }
    //save
    if ($def && !$defs[$def]) {
        $_POST['add'] = $def;
    }
    if (($_POST['def'] or $_POST['add']) && $authorized) {
        list($defs, $def) = save_defs($folder, $node, $defs, $def, $base);
    }
    //savb
    if ($_GET['sav']) {
        save_vars($folder, $node . '_sav', $defs, 1);
    }
    //create
    if ($_GET['create'] && $authorized) {
        $prefix = normaliz_c($_POST['prfx']);
        $table = normaliz_c($_POST['hbname']);
        if ($_POST['hbnb'] && $_POST['hbnb'] != 'version') {
            $version = $_POST['hbnb'];
        }
        if (!$_POST['hbnb']) {
            $version = '';
        }
        if (is_numeric($_POST['nbc'])) {
            $defsb['_menus_'] = '';
            $nbc = $_POST['nbc'];
            $nbc = $nbc > 1 ? $nbc : 1;
            for ($i = 1; $i <= $nbc; $i++) {
                $defsb['_menus_'][] = 'col_' . $i;
            }
        } elseif ($defs['_menus_']) {
            $defsb['_menus_'] = $defs['_menus_'];
        } else {
            $defsb['_menus_'] = array('');
        }
        $node = mnod($prefix, $table, $version);
        if ($folder && $prefix) {
            read_vars($folder, $node, $defsb);
        }
        relod(sesm('url') . murl_build('', '', $prefix, $table, $version));
    }
    #modifs
    //save_modif
    $do = find_command();
    if ($do && $auth >= $ath) {
        $defs = msql_modifs($defs, $defsb, $folder, $prefix . '_' . $table, $node, $basename, $do);
    }
    #render
    $lh = sesmk('msqlang');
    #-menus
    if (!$_GET['def']) {
        $ret['menus'] = msql_menus($ra);
    }
    //auth(3) &&
    if (!$_GET['def']) {
        //called
        #-files
        //add
        if (auth(4)) {
            $ret['fls'] = lkc('txtblc', $lkb . 'new==', pictxt('add', $lh[9][0])) . ' ';
        }
        if ($table && $authorized && $prefix && $is_file) {
            //$defs &&
            $ret['fls'] .= lkc('txtx', $lkb . 'sav==', $lh[2][0]) . ' ';
            if (is_file($basename . '_sav.php')) {
                $ret['fls'] .= lkc('txtx', $lkb . 'restore==', $lh[3][0]) . ' ';
            }
            $ret['fls'] .= lj_goto('import_defs', 5);
            //$ret['fls'].=lj_goto('import_old','');
            $ret['fls'] .= lj_goto('import_keys', 17);
            $ret['fls'] .= lj_goto('merge_defs', 6);
            $ret['fls'] .= lj_goto('append_update', 7);
            $ret['fls'] .= lj_goto('append_values', 8);
        } else {
            $ret['fls'] .= $bckp;
        }
        if ($files[$prefix] && ($auth > $ath or $prefix == $_SESSION['USE'])) {
            if ($auth >= $ath && $table && $prefix && $is_file) {
                $ret['fls'] .= lkc('txtx', $lkb . 'del_table==', $lh[10][0]) . ' ';
                $ret['fls'] .= ljb('txtblc', 'delfile', $lkb . 'del_file==', $lh[11][0]) . ' ';
                //$ret['fls'].=lkc('txtyl',$lkb.'del_file==',$lh[11][0]).' ';
                if (!$defs or isset($defs[0])) {
                    $ret['fls'] .= lkc('txtyl', $lkb . 'repair==', $lh[12][0]) . ' ';
                }
            }
        }
        if ($ret['fls']) {
            $ret['fls'] .= br();
        }
        //$ret['fls']=divc('menu',$ret['fls']);
        //new
        if ($_GET['new']) {
            $ret['fls'] .= newbase($base, $prefix, $table, $version);
        }
        #-util
        if ($table && $authorized && $prefix && $is_file) {
            $ret['utl'] .= lkc('txtblc', $lkb . 'def=_menus_', $lh[1][0]) . ' ';
            $ret['utl'] .= lkc('txtx', $lkb . 'reset_menus==', $lh[22][0]) . ' ';
            $ret['utl'] .= lkc('txtx', $lkb . 'del_menus==', $lh[23][0]) . ' ';
            $ret['utl'] .= lkc('txtx', $lkb . 'add_keys==', $lh[24][0]) . ' ';
            $ret['utl'] .= lkc('txtx', $lkb . 'del_keys==', $lh[25][0]) . ' ';
            $ret['utl'] .= lkc('txtx', $lkb . 'def=_menus_&add_col==', $lh[14][0]) . ' ';
            $ret['utl'] .= lj_goto('del_col', 15);
            if ($is_file) {
                $ret['utl'] .= lkc('txtx" title="' . $lh[13][1], $lkb . 'repair_cols==', $lh[13][0]) . br();
            }
            if ($base != 'system' && is_file(sesm('root') . 'system/' . $node . '.php')) {
                $ret['utl'] .= lkc('txtblc', $lkb . 'update==', $lh[26][0]) . ' ';
            }
            $ret['utl'] .= lj_goto('sort_table', 19);
            if ($table != 'restrictions' && $table != 'params') {
                $ret['utl'] .= lkc('txtx', $lkb . 'reorder==', $lh[20][0]) . ' ';
            }
            $ret['utl'] .= lj_goto('permut', 21);
            $ret['utl'] .= lkc('txtx', $lkb . 'edit_conn==', $lh[16][0]) . ' ';
            $ret['utl'] .= lkc('txtx" title="' . $lh[6][1], $lkb . 'inject_defs==', $lh[18][0]) . ' ';
            $ret['utl'] .= lkc('txtx', $lkb . 'edit_csv==', 'csv') . ' ';
            $ret['utl'] .= lkc('txtx', $lkb . 'json==', 'json') . ' ';
            if (auth(6)) {
                $ret['utl'] .= lkc('txtx', $lkb . 'export_mysql==', 'sql') . ' ';
            }
            if (auth(6)) {
                $ret['utl'] .= lkc('txtx', $lkb . 'create_mysql==', 'create mysql') . ' ';
            }
            $ret['utl'] .= lj('txtx', 'popup_msql___lang_helps_msql', '?');
        }
        #-fieldset
        if ($ret['fls'] . $ret['utl']) {
            $ret['utils'] = divc('menu', $ret['fls'] . $ret['utl']);
        }
        $ret['fls'] = $ret['utl'] = '';
        //if($ret['nfo'])$ret['nfo'].=br();
    }
    //called
    #-infos
    if ($table && $is_file) {
        $ret['nfo'] = lkc('popsav', $lk, $murl) . ' ';
        $wurl = $_SERVER['HTTP_HOST'] . '/msql/' . $murl;
        $ret['nfo'] .= lj('popbt', 'popup_text___' . ajx($wurl) . '_weburl_console', pictit('link', 'web url'));
        $wcon = '[' . $murl . $kdef . ($def ? ':' . $def : '') . ':microsql]';
        $ret['nfo'] .= lj('popbt', 'popup_text___' . ajx($wcon) . '_connector_console', pictit('conn', 'connector'));
        $ret['nfo'] .= lkt('popbt', '/plug/microxml.php?table=' . $murl, pictit('rss', 'xml')) . ' - ';
        $ret['nfo'] .= btn('txtsmall2', count($defs) . ' ' . plurial(count($defs), 116)) . ' - ';
        if ($is_file) {
            $ret['nfo'] .= btn('txtsmall2', fsize($basename . '.php')) . ' - ';
        }
        $ret['nfo'] .= btn('txtsmall2', ftime($basename . '.php')) . ' ';
        $ret['nfo'] .= msq_search($murl);
    }
    if ($ret['nfo']) {
        $ret['nfo'] = divc('menu', $ret['nfo']);
    }
    //entries
    //if($defs)$ret['edt'].=slctmenuder($defs,$def?$def:'_menus_');
    //add
    if ($is_file && $authorized && !$_GET['called'] && $defs && !$_GET['def']) {
        $ret['edt'] .= divc('menu', f_inp_add($defs, $defsb, $def)) . br();
    }
    //edit
    //echo verbose($ra,'');
    if ($def && $defs[$def]) {
        $ret['edt'] .= f_inp_m($defs, $defsb['_menus_'], $def);
    }
    //edit_conn
    if ($_GET['edit_conn'] == '=') {
        if ($defs) {
            foreach ($defs as $k => $v) {
                $v = str_replace(array('|', '¬'), array(':BAR:', ':LINE:'), $v);
                $edittable .= implode('|', $v) . '¬' . "\n";
            }
        }
        //(!is_numeric($k)?$k.'|':'')
        $ret[] = divc('', 'paste a table as created by transductor from html table :: use "|" for cells and "¬" for lines of cells') . form($lkb . 'def=' . $def, txarea('import_conn', $edittable, 60, 14) . br() . checkbox('aid', 'ok', 'auto_increment', '1') . input2('submit', 'save', 'import', 'txtbox')) . hr() . br();
    }
    //array
    if ($_GET['inject_defs'] == '=') {
        $datas = str_replace(array('<' . '?php', '?' . '>'), '', read_file($basename . '.php'));
        $ret[] = divc('', 'paste $r[1]=array(1,2,3)') . form($lkb, txarea('inject_defs', $datas, 60, 14) . br() . input2('submit', 'replace', 'replace', 'txtbox') . input2('submit', 'inject', 'inject', 'txtbox') . checkbox('mono', '1', 'key=>value', '') . checkbox('sql', '1', 'mysql', '')) . hr() . br();
    }
    //export_mysql
    if ($_GET['create_mysql'] == '=' && auth(6)) {
        $ok = plugin_func('mysql', 'import_msql', $defs, $node);
        $ret[] = divc('txtalert', 'create table ' . $node . ': ' . $ok);
    }
    if ($_GET['export_mysql'] == '=' && auth(6)) {
        $ret[] = txarea('', mysqlrb($defs), 60, 40);
    }
    //csv
    if ($_GET['edit_csv'] == '=') {
        foreach ($defs as $k => $v) {
            if ($v) {
                $edittable .= $k . ':' . (is_array($v) ? implode(',', $v) : htmlentities($v)) . "\n";
            }
        }
        $ret[] = divc('', 'paste csv using "," for cells and lines for rows') . form($lkb . 'def=' . $def, txarea('edit_csv', $edittable, 60, 14) . br() . checkbox('aid', 'ok', 'auto_increment', '1') . input2('submit', 'save', 'import', 'txtbox')) . hr() . br();
    }
    //csv
    if ($_GET['json'] == '=') {
        foreach ($defs as $k => $v) {
            if ($v) {
                $edittable .= '"' . $k . '":' . (is_array($v) ? '["' . implode('","', $v) . '"]' : '"' . htmlentities($v[0])) . '",';
            }
        }
        $ret[] = txarea('edit_csv', '{' . $edittable, 60, 14) . '}' . br();
    }
    //see_table
    if ($defs && !$_GET['def']) {
        // && (!$def or $_POST['save'])//called
        $out = divd('editmsql', draw_table($defs, $murl, ''));
        $ret[] = $out . br();
    } else {
        $ret[] = divd('editmsql', '');
    }
    if ($auth > 6) {
        $ret[] = lkc('txtx', $lkb . 'backup_msql==', 'backup') . ' ';
    }
    if ($_GET['backup_msql']) {
        $ret[] = backup_msql();
    }
    return divd('content', implode('', $ret));
}