예제 #1
0
 function create_tree(&$list, $parent, $i, $c)
 {
     $tree = array();
     foreach ($parent as $k => $l) {
         if (isset($list[$l[$i]])) {
             $l[$c] = create_tree($list, $list[$l[$i]], $i, $c);
         }
         $tree[] = $l;
     }
     return $tree;
 }
예제 #2
0
function create_tree($id, &$tree, $indent = false)
{
    $content = $indent ? '<div style="margin-left: 8px;">' : '';
    while ($page = array_shift($tree)) {
        if ($page['id'] == $id) {
            $content .= '<b>&#8226; ' . $page['title'] . '</b><br />';
        } else {
            $content .= '&#8226; <a href="' . URL::index('&amp;id=' . $page['id']) . '">' . $page['title'] . '</a><br />';
        }
        if (isset($page['sub'])) {
            $content .= create_tree($id, $page['sub'], true);
        }
    }
    if ($indent) {
        $content .= '</div>';
    }
    return $content;
}
예제 #3
0
파일: api.php 프로젝트: muqidi/PHP
/**
 *  循环生成xml节点
 *
 *  @param  handle      $doc            xml实例句柄
 *  @param  handle      $top            当前父节点
 *  @param  array       $info_arr       需要解析的数组
 *  @param  boolean     $have_item      是否是数据数组,是则需要在每条数据上加item父节点
 *
 */
function create_tree($doc, $top, $info_arr, $have_item = false)
{
    if (is_array($info_arr)) {
        foreach ($info_arr as $key => $val) {
            if (is_array($val)) {
                if ($have_item == false) {
                    $data_info = $doc->createElement('data_info');
                    $top->appendChild($data_info);
                    create_tree($doc, $data_info, $val, true);
                } else {
                    $item = $doc->createElement('item');
                    $top->appendChild($item);
                    $key_code = $doc->createAttribute('key');
                    $item->appendChild($key_code);
                    $key_code->appendChild($doc->createTextNode($key));
                    create_tree($doc, $item, $val);
                }
            } else {
                $text_code = $doc->createElement($key);
                $top->appendChild($text_code);
                if (is_string($val)) {
                    $text_code->appendChild($doc->createCDATASection($val));
                } else {
                    $text_code->appendChild($doc->createTextNode($val));
                }
            }
        }
    } else {
        $top->appendChild($doc->createCDATASection($info_arr));
    }
}
예제 #4
0
function create_tree(ArrayIterator &$it)
{
    global $operators_dictionary;
    global $has_quotes;
    if (!in_array($it->current()["term"], $operators_dictionary) || $has_quotes) {
        $leaf = new leaf($it->current());
        $it->next();
        return $leaf;
    } else {
        if ($it->current()["term"] == "not") {
            $it->next();
            $op = create_tree($it);
            return new notEx($op);
        } else {
            if ($it->current()["term"] == "and") {
                $it->next();
                $left = create_tree($it);
                $right = create_tree($it);
                return new andEx($left, $right);
            } else {
                if ($it->current()["term"] == "or") {
                    $it->next();
                    $left = create_tree($it);
                    $right = create_tree($it);
                    return new orEx($left, $right);
                }
            }
        }
    }
    return null;
}
예제 #5
0
function tbody($params)
{
    global $conn, $modul, $sub_page, $pages;
    if (!isset($sub_page) or $sub_page == 0) {
        $sub_page = 1;
    }
    if ($modul == 'content_tree') {
        if (isset($params['FILTER'])) {
            $arr_tmp = create_tree('content_tree', 0, $params['FILTER']);
        } else {
            $arr_tmp = create_tree('content_tree', 0);
        }
        if ($arr_tmp) {
            $tbody = "<div class='table-body tree'>";
            $tbody .= tree_nav_table($params, 'content', $arr_tmp, tree_get_parents('content_tree', NULL));
            $tbody .= "</div><!-- /.table-body -->";
        }
    } else {
        if (!isset($params['FILTER'])) {
            $params['FILTER'] = NULL;
        } elseif (!isset($params['SORT'])) {
            $params['SORT'] = NULL;
        }
        if (!isset($params['GROUP'])) {
            $params['GROUP'] = NULL;
        }
        if (!isset($params['ADD'])) {
            $params['ADD'] = NULL;
        }
        $result = db_mysql_query(select_tbody($params['TABLE'], $params['SORT'], $params['FILTER'], $params['GROUP'], $params['ADD'], 100), $conn);
        if ($sub_page <= 1) {
            $sql_sub = "SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = '" . $_SESSION['TABLE_PREFIX'] . $modul . "' AND COLUMN_NAME = 'sort_order' ";
            $result_sub = db_mysql_query($sql_sub, $conn);
            if ($modul == 'content_tree') {
                $tbody = "<div class='table-body tree'>";
            } else {
                if (db_mysql_num_rows($result_sub)) {
                    $tbody = "<div class='table-body sortable'>";
                } else {
                    $tbody = "<div class='table-body " . $modul . "'>";
                }
            }
        }
        while ($arr = db_mysql_fetch_array($result)) {
            $tbody .= "<div class='table-row' id='" . $arr['id'] . "' >";
            foreach ($params['TABLE'] as $key => $value) {
                $data = init($arr[$key], $value, $key);
                if ($value == 'activate') {
                    $tbody .= "<div class='table-cell icon-only " . $key . "'>";
                    if ($arr[$key]) {
                        $tbody .= "<a href='#' class='icon-cell " . $key . "_de" . $value . "' data-content='" . $modul . "' id='" . $arr['id'] . "' ><i class='icon-" . $value . "-active'></i>";
                    } else {
                        $tbody .= "<a href='#' class='icon-cell " . $key . "_" . $value . "' data-content='" . $modul . "' id='" . $arr['id'] . "' ><i class='icon-" . $value . "'></i>";
                    }
                    $tbody .= "</div><!-- /.table-cell -->";
                } else {
                    $tbody .= "<div class='table-cell " . $key . "'>" . $data . "</div><!-- /.table-cell -->";
                }
            }
            if (count(array_filter($params['CONSTRUCT']))) {
                $width = 40 + 26 * count(array_filter($params['CONSTRUCT']));
                $tbody .= "<div class='table-cell tools' style='width: " . $width . "px;'>";
                foreach ($params['CONSTRUCT'] as $key => $value) {
                    if ($value === true) {
                        if ($key == 'activate') {
                            if (!isset($arr['c_default']) or $arr['c_default'] == 0) {
                                if ($arr['c_active']) {
                                    $tbody .= "<a href='#' class='icon-cell de" . $key . "' data-content='" . $modul . "' id='" . $arr['id'] . "' ><i class='icon-" . $key . "-active'></i>";
                                } else {
                                    $tbody .= "<a href='#' class='icon-cell " . $key . "' data-content='" . $modul . "' id='" . $arr['id'] . "' ><i class='icon-" . $key . "'></i>";
                                }
                                $tbody .= "</a>";
                            }
                        } elseif ($key == 'delete') {
                            if (!isset($arr['c_default']) or $arr['c_default'] == 0) {
                                $tbody .= "<a href='#' class='icon-cell " . $key . "' data-content='" . $modul . "' id='" . $arr['id'] . "' ><i class='icon-" . $key . "'></i></a>";
                            }
                        } else {
                            $tbody .= "<a href='#' class='icon-cell " . $key . "' data-content='" . $modul . "' id='" . $arr['id'] . "' ><i class='icon-" . $key . "'></i></a>";
                        }
                    }
                }
                $tbody .= "</div><!-- /.table-cell -->";
            }
            $tbody .= "</div><!-- /.table-row -->";
        }
        if (ceil($pages) != $sub_page) {
            $next_page = $sub_page + 1;
            $tbody .= "<form id='next_rows' method='POST'>";
            $tbody .= "<input type='hidden' name='modul' value='" . $modul . "'>";
            $tbody .= "<input type='hidden' name='params' value='" . serialize($params) . "'>";
            $tbody .= "<input type='hidden' name='sub_page' value='" . $next_page . "'>";
            $tbody .= "</form>";
        }
        $tbody .= "</div><!-- /.table-body -->";
    }
    if (isset($tbody)) {
        print $tbody;
    }
}
예제 #6
0
function reorder_tree()
{
    global $tree, $db;
    // read the tree
    read_tree(true);
    // update with new order
    $order = 0;
    for ($i = 0; $i < count($tree['data']); $i++) {
        if (!empty($tree['id'][$i])) {
            $order += 10;
            if ($tree['type'][$i] == POST_FORUM_URL) {
                $sql = "UPDATE " . FORUMS_TABLE . "\n                            SET forum_order = {$order}\n                            WHERE forum_id = " . intval($tree['id'][$i]);
            } else {
                $sql = "UPDATE " . CATEGORIES_TABLE . "\n                            SET cat_order = {$order}\n                            WHERE cat_id = " . intval($tree['id'][$i]);
            }
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Couldn\'t reorder forums/categories table', '', __LINE__, __FILE__, $sql);
            }
        }
    }
    // re-read the tree
    create_tree();
}
예제 #7
0
preg_match("/(.*)_(.*)/i", $modul, $next_modul);
if ($next_modul) {
    $next_modul = $next_modul[1];
} else {
    $next_modul = $modul;
}
$sql_sb = "SELECT modul, modul_string FROM cmt_modul WHERE c_active = '1' ORDER BY sort_order";
$result_sb = db_mysql_query($sql_sb, $conn);
if (db_mysql_num_rows($result_sb)) {
    while ($arr_sb = db_mysql_fetch_array($result_sb)) {
        if ($arr_sb['modul'] == 'content') {
            $sql = "SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = '" . $_SESSION['TABLE_PREFIX'] . "content_tree' AND COLUMN_NAME = 'id_parent' ";
            $result = db_mysql_query($sql, $conn);
            $id_parent = db_mysql_num_rows($result);
            if ($id_parent) {
                $arr_tmp = create_tree('content_tree');
                if ($arr_tmp) {
                    print "\n\t\t\t\t\t\t<li class='has-dropdown'>\n\t\t\t\t\t\t\t<a href='?modul=content'>\n\t\t\t\t\t\t\t\t<i class='icon-content'></i><span class='toggle ";
                    if ($next_modul == 'content') {
                        print 'active';
                    }
                    print "'>" . v('CMT_MODUL_CONTENT') . "</span>\n\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t<ul class='dropdown sub-tree ";
                    if ($next_modul == 'content') {
                        print 'active';
                    }
                    print "'>";
                    if (isset($id_tree)) {
                        tree_sidebar('content', $arr_tmp, tree_get_parents('content_tree', $id_tree));
                    } else {
                        tree_sidebar('content', $arr_tmp, tree_get_parents('content_tree', NULL));
                    }
예제 #8
0
파일: index.php 프로젝트: cbsistem/nexos
    if ($page['parent_id'] > 0) {
        $parents = array();
        get_parents($page['parent_id'], $parents);
        foreach ($parents as $parent) {
            $page_no .= "{$parent['pos']}.";
            $crumbs[] = '<a href="' . URL::index('&amp;id=' . $parent['id']) . '">' . $parent['title'] . '</a>';
        }
    }
    $crumbs[] = $page['title'];
    $crumbs = implode(' ' . _BC_DELIM . ' ', $crumbs);
    $pagetitle = strip_tags($crumbs);
    $tree = $page;
    $tree['sub'] = list_all($page['id'], false);
    $tree = go_up($tree);
    require_once 'header.php';
    $cpgtpl->assign_vars(array('G_ID' => '1', 'U_CRUMBS' => '<span style="float: left;">' . $crumbs . '</span>', 'U_ADDPAGE' => is_user() ? '<a href="' . URL::index('&amp;file=manage') . '">Add new page</a>' : '', 'U_EDITPAGE' => isset($_GET['id']) ? '&nbsp;|&nbsp;<a href="' . URL::index('&amp;file=manage&amp;id=' . intval($_GET['id'])) . '">Edit this page</a>' : '', 'U_TREE' => create_tree($page_id, $tree), 'S_PAGE' => $page_no, 'S_SUBPAGE' => $page['pos'], 'S_TITLE' => $page['title'], 'S_COMMENT' => $page['comment'], 'S_BODY' => $page['body'], 'S_AUTHOR' => 'Author:&nbsp;<a href="' . URL::index('Your_Account&amp;profile=' . $page['user_id']) . '">' . $page['author'] . '</a>', 'S_CREATED' => 'Created:&nbsp;' . formatDateTime($page['time'], _DATESTRING), 'S_UPDATED' => $page['supercede'] ? 'Last update: ' . formatDateTime($page['supercede'], _DATESTRING) . ' by <a href="' . URL::index('Your_Account&amp;profile=' . $page['upd_user_id']) . '">' . $page['upd_author'] . '</a>' : ''));
    $cpgtpl->set_filenames(array('body' => 'wiki/index.html'));
    $cpgtpl->display('body');
} else {
    $pagetitle = $module_name;
    require_once 'header.php';
    $cpgtpl->assign_vars(array('G_ID' => '', 'S_TITLE' => $sitename . ' Wiki', 'U_ADDPAGE' => is_user() ? '<a href="' . URL::index('&amp;file=manage') . '">Add new page</a>' : ''));
    $result = $db->sql_query("SELECT * FROM " . $module_prefix . "_pages WHERE parent_id=0 ORDER BY pos");
    if ($db->sql_numrows($result) > 0) {
        while ($row = $db->sql_fetchrow($result)) {
            $cpgtpl->assign_block_vars('pages', array('U_PAGE' => '<li><b><a href="' . URL::index("&amp;id=" . $row['id']) . '">' . $row['title'] . '</a></b><br />' . $row['comment'] . '</li>'));
        }
    }
    $cpgtpl->set_filenames(array('body' => 'wiki/index.html'));
    $cpgtpl->display('body');
}
function read_tree($force = false)
{
    global $db, $userdata, $board_config, $HTTP_COOKIE_VARS;
    global $tree;
    global $phpbb_root_path, $phpEx;
    // get censored words
    $orig_word = array();
    $replacement_word = array();
    obtain_word_list($orig_word, $replacement_word);
    //-- mod : keep unread -----------------------------------------------------------------------------
    //-- delete
    //	// read the user cookie
    //	$tracking_topics	= ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_t"]) : array();
    //	$tracking_forums	= ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . "_f"]) : array();
    //	$tracking_all		= ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) ) ? intval($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) : -1;
    //-- fin mod : keep unread -------------------------------------------------------------------------
    // extended auth compliancy
    $sql_extend_auth = '';
    if (defined('EXTEND_AUTH_INSTALLED')) {
        $sql_extend_auth = ' AND aa.auth_type = ' . POST_FORUM_URL;
    }
    // try the cache
    $use_cache_file = false;
    create_tree();
    // read the user auth and the last post of each forums
    if ($userdata['session_logged_in']) {
        $sql_select = ', a.*, ug.user_id';
        $sql_from = "LEFT JOIN " . AUTH_ACCESS_TABLE . " a ON a.forum_id = f.forum_id )\n\t\t\t\t\tLEFT JOIN " . USER_GROUP_TABLE . " ug ON ug.group_id = a.group_id AND ug.user_id = " . intval($userdata['user_id']) . " AND ug.user_pending=0 )";
    } else {
        $sql_select = '';
        $sql_from = '))';
    }
    $sql = "SELECT f.forum_id AS forum_id_main, f.forum_last_post_id {$sql_select}\n\t\t\t\tFROM ((" . FORUMS_TABLE . " f {$sql_from}";
    if (!($result = $db->sql_query($sql))) {
        message_die(GENERAL_ERROR, 'Couldn\'t access list of last posts from forums', '', __LINE__, __FILE__, $sql);
    }
    $u_access = array();
    $s_last_posts = '';
    $last_posts = array();
    while ($row = $db->sql_fetchrow($result)) {
        // get the last post
        if (!empty($row['forum_last_post_id']) && !isset($last_posts[$row['forum_last_post_id']])) {
            $last_posts[$row['forum_last_post_id']] = $row['forum_id_main'];
            $s_last_posts .= (empty($s_last_posts) ? '' : ', ') . $row['forum_last_post_id'];
        }
        // get the access auth
        if ($userdata['session_logged_in'] && $row['user_id'] == $userdata['user_id']) {
            $u_access[$row['forum_id_main']][] = $row;
        }
    }
    $userdata['user_forums_auth'] = $u_access;
    $sql_last_posts = empty($s_last_posts) ? '' : " OR p.post_id IN ({$s_last_posts})";
    // read the last or unread posts
    //-- mod : keep unread -----------------------------------------------------------------------------
    //-- delete
    //	$user_lastvisit = $userdata['session_logged_in'] ? $userdata['user_lastvisit'] : 99999999999;
    //-- add
    // get last visit for guest
    if (!$userdata['session_logged_in']) {
        $userdata['user_lastvisit'] = $board_config['guest_lastvisit'];
    }
    $user_lastvisit = $userdata['user_lastvisit'];
    // unreads
    $sql_unreads = '';
    if (!empty($board_config['tracking_unreads'])) {
        // get the unreads topic id
        @reset($board_config['tracking_unreads']);
        while (list($id, $time) = @each($board_config['tracking_unreads'])) {
            // don't add obsolete cookies
            if ($time > intval($board_config['tracking_all']) && $time > intval($board_config['tracking_topics'][$id])) {
                $sql_unreads .= (empty($sql_unreads) ? '' : ', ') . $id;
            }
        }
        if (!empty($sql_unreads)) {
            $sql_unreads = " OR p.topic_id IN ({$sql_unreads})";
        }
    }
    // prepare the result
    $new_unreads = array();
    //-- fin mod : keep unread -------------------------------------------------------------------------
    //-- mod : keep unread -----------------------------------------------------------------------------
    // here we added
    //	 $sql_unreads
    //-- modify
    $sql = "SELECT p.forum_id, p.topic_id, p.post_time, p.post_username, u.username, u.user_id, t.topic_last_post_id, t.topic_title\n\t\t\t\tFROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u\n\t\t\t\tWHERE ( p.post_time > {$user_lastvisit} {$sql_last_posts} {$sql_unreads} )\n\t\t\t\t\t\tAND p.post_id = t.topic_last_post_id\n\t\t\t\t\t\tAND t.topic_id = p.topic_id AND t.forum_id = p.forum_id AND t.topic_moved_id = 0\n\t\t\t\t\t\tAND u.user_id = p.poster_id";
    //-- fin mod : keep unread -------------------------------------------------------------------------
    if (!($result = $db->sql_query($sql))) {
        message_die(GENERAL_ERROR, 'Couldn\'t access list of unread posts from forums', '', __LINE__, __FILE__, $sql);
    }
    $new_topic_data = array();
    while ($row = $db->sql_fetchrow($result)) {
        //-- mod : keep unread -----------------------------------------------------------------------------
        //-- delete
        //		if ( $row['post_time'] > $user_lastvisit )
        //		{
        //-- add
        // get some ids
        $topic_id = $row['topic_id'];
        $forum_id = $row['forum_id'];
        // check the validity of the cookies : forum
        if (isset($board_config['tracking_forums'][$forum_id])) {
            if (!empty($board_config['tracking_all']) && $board_config['tracking_all'] >= $board_config['tracking_forums'][$forum_id]) {
                unset($board_config['tracking_forums'][$forum_id]);
            }
        }
        // topic cookie still valid ?
        if (isset($board_config['tracking_topics'][$topic_id])) {
            if (!empty($board_config['tracking_all']) && $board_config['tracking_all'] >= $board_config['tracking_topics'][$topic_id] || isset($board_config['tracking_forums'][$forum_id]) && $board_config['tracking_forums'][$forum_id] >= $board_config['tracking_topics'][$topic_id]) {
                unset($board_config['tracking_topics'][$topic_id]);
            }
        }
        // unread cookie still valid ?
        if (isset($board_config['tracking_unreads'][$topic_id])) {
            if (!empty($board_config['tracking_all']) && $board_config['tracking_all'] >= $board_config['tracking_unreads'][$topic_id] || isset($board_config['tracking_forums'][$forum_id]) && $board_config['tracking_forums'][$forum_id] >= $board_config['tracking_unreads'][$topic_id] || isset($board_config['tracking_topics'][$topic_id]) && $board_config['tracking_topics'][$topic_id] >= $board_config['tracking_unreads'][$topic_id]) {
                unset($board_config['tracking_unreads'][$topic_id]);
            }
        }
        // have we got a last visit time for this topic
        $topic_last_read = intval($board_config['tracking_unreads'][$topic_id]);
        if (!empty($board_config['tracking_all']) && $board_config['tracking_all'] > $topic_last_read) {
            $topic_last_read = $board_config['tracking_all'];
        }
        if (isset($board_config['tracking_forums'][$forum_id]) && $board_config['tracking_forums'][$forum_id] > $topic_last_read) {
            $topic_last_read = $board_config['tracking_forums'][$forum_id];
        }
        if (isset($board_config['tracking_topics'][$topic_id]) && $board_config['tracking_topics'][$topic_id] > $topic_last_read) {
            $topic_last_read = $board_config['tracking_topics'][$topic_id];
        }
        if (empty($topic_last_read)) {
            $topic_last_read = $userdata['user_lastvisit'];
        }
        // check the topic last visit time
        if ($row['post_time'] > $topic_last_read) {
            $new_unreads[$topic_id] = $topic_last_read;
            //-- fin mod : keep unread -------------------------------------------------------------------------
            $new_topic_data[$row['forum_id']][$row['topic_id']] = $row['post_time'];
        }
        if (isset($last_posts[$row['topic_last_post_id']])) {
            // topic title censor
            if (count($orig_word)) {
                $row['topic_title'] = preg_replace($orig_word, $replacement_word, $row['topic_title']);
            }
            // store the added columns
            $idx = $tree['keys'][POST_FORUM_URL . $row['forum_id']];
            @reset($row);
            while (list($key, $value) = @each($row)) {
                $nkey = intval($key);
                if ($key != "{$nkey}") {
                    $tree['data'][$idx][$key] = $row[$key];
                }
            }
        }
    }
    //-- mod : keep unread -----------------------------------------------------------------------------
    //-- add
    // update the unread topics from the list readed
    $board_config['tracking_unreads'] = $new_unreads;
    // except the cookies
    write_cookies($userdata);
    //-- fin mod : keep unread -------------------------------------------------------------------------
    // set the unread flag
    $tree['unread_topics'] = array();
    for ($i = 0; $i < count($tree['data']); $i++) {
        if ($tree['type'][$i] == POST_FORUM_URL) {
            // get the last post time per forums
            $forum_id = $tree['id'][$i];
            $unread_topics = false;
            if (!empty($new_topic_data[$forum_id])) {
                $forum_last_post_time = 0;
                @reset($new_topic_data[$forum_id]);
                while (list($check_topic_id, $check_post_time) = @each($new_topic_data[$forum_id])) {
                    //-- mod : keep unread -----------------------------------------------------------------------------
                    //-- delete
                    //					if ( empty($tracking_topics[$check_topic_id]) )
                    //					{
                    //-- fin mod : keep unread -------------------------------------------------------------------------
                    $unread_topics = true;
                    $forum_last_post_time = max($check_post_time, $forum_last_post_time);
                    //-- mod : keep unread -----------------------------------------------------------------------------
                    //-- delete
                    //					}
                    //					else
                    //					{
                    //						if ( $tracking_topics[$check_topic_id] < $check_post_time )
                    //						{
                    //							$unread_topics = true;
                    //							$forum_last_post_time = max($check_post_time, $forum_last_post_time);
                    //						}
                    //					}
                    //				}
                    //
                    //				// is there a cookie for this forum ?
                    //				if ( !empty($tracking_forums[$forum_id]) )
                    //				{
                    //					if ( $tracking_forums[$forum_id] > $forum_last_post_time )
                    //					{
                    //						$unread_topics = false;
                    //					}
                    //				}
                    //
                    //				// is there a cookie for all forums ?
                    //				if ( $tracking_all > $forum_last_post_time )
                    //				{
                    //					$unread_topics = false;
                    //-- fin mod : keep unread -------------------------------------------------------------------------
                }
            }
            // store the result
            $tree['unread_topics'][$i] = $unread_topics;
        }
    }
    return;
}
예제 #10
0
function cross_table($title, $value = 0, $value_name = NULL, $value_label = NULL)
{
    global $conn, $formdata, $modul;
    preg_match("/(.*)_(.*)/i", $modul, $next_modul);
    if ($next_modul) {
        $next_modul = $next_modul[1];
    } else {
        $next_modul = $modul;
    }
    $sql = "SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = '" . $_SESSION['TABLE_PREFIX'] . $formdata[$title]['settings']['data'] . "' AND COLUMN_NAME = 'id_parent' ";
    $result = db_mysql_query($sql, $conn);
    $id_parent = db_mysql_num_rows($result);
    if ($id_parent) {
        $arr_tmp = create_tree($formdata[$title]['settings']['data']);
        generate_tree_select($title, $arr_tmp, tree_get_parents($formdata[$title]['settings']['data'], $value));
        $formdata['levels'] = array('type' => 'hidden', 'value' => 1);
        unset($formdata[$title]);
    } else {
        if ($title == 'language') {
            $next_modul = 'content';
        }
        $sql = "SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = '" . $_SESSION['TABLE_PREFIX'] . $next_modul . "_fields' AND COLUMN_NAME = 'id' ";
        $result = db_mysql_query($sql, $conn);
        if (db_mysql_num_rows($result)) {
            $sql = "SELECT value, label FROM " . $_SESSION['TABLE_PREFIX'] . $next_modul . "_fields WHERE source_table = '" . $formdata[$title]['settings']['data'] . "' ";
            $result = db_mysql_query($sql, $conn);
            if (db_mysql_num_rows($result)) {
                $arr = db_mysql_fetch_array($result);
            }
        }
        if (!isset($arr['value']) or !$arr['value']) {
            $arr['value'] = 'id';
        }
        if (!isset($arr['label']) or !$arr['label']) {
            $arr['label'] = 'title';
        }
        if (isset($value_name) && $value_name) {
            $arr['value'] = $value_name;
        }
        if (isset($value_label) && $value_label) {
            $arr['value'] = $value_label;
        }
        $sql_tmp = "SELECT " . $arr['value'] . ", " . $arr['label'] . ", sort_order FROM " . $formdata[$title]['settings']['data'] . " WHERE c_active = '1' ";
        if ($formdata[$title]['settings']['data'] == 'content_templates') {
            $sql_tmp .= "GROUP BY id_template ";
        }
        $sql_tmp .= "ORDER BY sort_order ASC ";
        $result_tmp = db_mysql_query($sql_tmp, $conn);
        if ($formdata[$title]['settings']['data'] == 'cmt_accounts') {
            $formdata[$title]['value'] = CMT_USER_ID;
        }
        unset($formdata[$title]['settings']['data']);
        if ($formdata[$title]['type'] != 'radio') {
            $formdata[$title]['settings']['data'][0] = "...";
        }
        while ($arr_tmp = db_mysql_fetch_array($result_tmp)) {
            if ($arr['label'] == 'label') {
                $formdata[$title]['settings']['data'][$arr_tmp[$arr['value']]] = v("CMT_" . $arr_tmp[$arr['label']]);
            } else {
                $formdata[$title]['settings']['data'][$arr_tmp[$arr['value']]] = $arr_tmp[$arr['label']];
            }
        }
    }
}