function comic_table($order, $sort, $filter, $start, $query, $qfield, &$table_c)
{
    $edit_label = lang('Edit');
    $delete_label = lang('Delete');
    $searchobj = array(array('data_title', 'Title'), array('data_class', 'Genre'), array('data_censorlvl', 'Rated'), array('data_parser', 'Parser'), array('data_resolve', 'Resolve'));
    if (!$sort) {
        $sort = 'desc';
    }
    if ($order) {
        $ordermethod = "order by {$order} {$sort} ";
    } else {
        $ordermethod = "order by data_title asc ";
    }
    if (!$start) {
        $start = 0;
    }
    if (!$filter) {
        $filter = 'none';
    }
    $likeness = 'like';
    $myquery = '%' . $query . '%';
    $myqfield = $qfield;
    if ($qfield == 'data_censorlvl') {
        while (list($key, $value) = each($GLOBALS['g_censor_level'])) {
            if (ucwords($query) == $value) {
                $myquery = $key;
                $likeness = '=';
                break;
            }
        }
    } elseif ($qfield == "data_title") {
        $myqfield = "lower({$qfield})";
        $myquery = "%" . strtolower($query) . "%";
    }
    if (!$query) {
        $sql_clause = '';
    } else {
        $sql_clause = 'WHERE ' . $myqfield . ' ' . $likeness . " '{$myquery}' ";
    }
    $sql_query = 'select * from phpgw_comic_data ' . $sql_clause . $ordermethod;
    $sql_query_count = 'select count(*) from phpgw_comic_data ' . $sql_clause;
    $GLOBALS['phpgw']->db->query($sql_query_count, __LINE__, __FILE__);
    $GLOBALS['phpgw']->db->next_record();
    $total_records = $GLOBALS['phpgw']->db->f(0);
    if ($total_records > $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']) {
        if ($start + $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > $total_records) {
            $max_turn = $total_records;
        } else {
            $max_turn = $start + $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
        }
        $match_comment = lang('showing %1 - %2 of %3', $start + 1, $max_turn, $total_records);
    } else {
        $match_comment = lang('showing %1', $total_records);
    }
    $GLOBALS['phpgw']->db->limit_query($sql_query, intval($start), __LINE__, __FILE__);
    $table_tpl = CreateObject('phpgwapi.Template', $GLOBALS['phpgw']->common->get_tpl_dir('comic'));
    $table_tpl->set_unknowns('remove');
    $table_tpl->set_file(array('table' => 'table.comics.tpl', 'row' => 'row.comics.tpl'));
    while ($GLOBALS['phpgw']->db->next_record()) {
        $tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color);
        $data_id = $GLOBALS['phpgw']->db->f('data_id');
        $comic_encoded = urlencode($data_id);
        $comic_censor = $GLOBALS['g_censor_level'][$GLOBALS['phpgw']->db->f('data_censorlvl')];
        $table_tpl->set_var(array('row_color' => $tr_color, 'data_title' => get_db_var('data_title'), 'comic_parser' => get_db_var('data_parser'), 'comic_resolve' => get_db_var('data_resolve'), 'comic_class' => get_db_var('data_class'), 'comic_censor' => $comic_censor, 'edit_url' => $GLOBALS['phpgw']->link('/comic/admin_comics.php', array('data_id' => $comic_encoded, 'act' => 'edit', 'start' => $start, 'order' => $order, 'filter' => $filter, 'sort' => $sort, 'query' => urlencode($query), 'qfield' => $qfield)), 'edit_label' => $edit_label, 'delete_url' => $GLOBALS['phpgw']->link('/comic/admin_comics.php', array('data_id' => $comic_encoded, 'act' => 'delete', 'start' => $start, 'order' => $order, 'filter' => $filter, 'sort' => $sort, 'query' => urlencode($query), 'qfield' => $qfield)), 'delete_label' => $delete_label));
        $table_tpl->parse(comic_rows, 'row', True);
    }
    $table_tpl->set_var(array('th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'], 'total_matchs' => $match_comment, 'next_matchs' => $GLOBALS['phpgw']->nextmatchs->show_tpl('/comic/admin_comics.php', $start, $total_records, '', '85%', $GLOBALS['phpgw_info']['theme']['th_bg'], $searchobj, 0), 'comic_label' => $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'data_title', $order, '/comic/admin_comics.php', lang('Title')), 'comic_parser_label' => $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'data_parser', $order, '/comic/admin_comics.php', lang('Parser')), 'comic_resolve_label' => $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'data_resolve', $order, '/comic/admin_comics.php', lang('Resolve')), 'comic_class_label' => $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'data_class', $order, '/comic/admin_comics.php', lang('Genre')), 'comic_censor_label' => $GLOBALS['phpgw']->nextmatchs->show_sort_order($sort, 'data_censorlvl', $order, '/comic/admin_comics.php', lang('Rated')), 'edit_label' => $edit_label, 'delete_label' => $delete_label, 'action_url' => $action_url, 'action_label' => lang($act), 'reset_label' => lang('Reset')));
    $table_tpl->parse(table_part, 'table');
    $table_c = $table_tpl->get('table_part');
}
Example #2
0
function render_global($game_id)
{
    global $UNI, $systems, $preview, $loc, $exp_sys, $random_filename, $gen_new_maps, $directories;
    $size_x = $UNI['size_x'] + $UNI['map_border'] * 2;
    $size_y = $UNI['size_y'] + $UNI['map_border'] * 2;
    $offset_x = $UNI['map_border'];
    $offset_y = $UNI['map_border'];
    $central_star = 1;
    //this star is the hub of the universe.
    $uv_show_warp_numbers = get_db_var('uv_show_warp_numbers');
    $numsize = $UNI['num_size'];
    $im = imagecreatetruecolor($size_x, $size_y);
    $earthIm = imagecreatefrompng($directories['images'] . '/map/earth.png');
    $earthDim = array(imagesx($earthIm), imagesy($earthIm));
    $earthPos = array(-$earthDim[0] / 2, -$earthDim[1] / 2);
    $starIm = imagecreatefrompng($directories['images'] . '/map/star.png');
    $starDim = array(imagesx($starIm), imagesy($starIm));
    $starPos = array(-$starDim[0] / 2, -$starDim[1] / 2);
    //allocate the colours
    $color_bg = ImageColorAllocate($im, $UNI['bg_color'][0], $UNI['bg_color'][1], $UNI['bg_color'][2]);
    $color_st = ImageColorAllocate($im, $UNI['num_color'][0], $UNI['num_color'][1], $UNI['num_color'][2]);
    $color_sd = ImageColorAllocate($im, $UNI['star_color'][0], $UNI['star_color'][1], $UNI['star_color'][2]);
    $color_sl = ImageColorAllocate($im, $UNI['link_color'][0], $UNI['link_color'][1], $UNI['link_color'][2]);
    $color_sh = ImageColorAllocate($im, $UNI['num_color3'][0], $UNI['num_color3'][1], $UNI['num_color3'][2]);
    $color_l = ImageColorAllocate($im, $UNI['label_color'][0], $UNI['label_color'][1], $UNI['label_color'][2]);
    $worm_1way_color = ImageColorAllocate($im, $UNI['worm_one_way_color'][0], $UNI['worm_one_way_color'][1], $UNI['worm_one_way_color'][2]);
    $worm_2way_color = ImageColorAllocate($im, $UNI['worm_two_way_color'][0], $UNI['worm_two_way_color'][1], $UNI['worm_two_way_color'][2]);
    //get the star systems from the Db if using pre-genned map.
    if (isset($gen_new_maps)) {
        db("select (star_id -1) as num, x_loc, y_loc, wormhole, CONCAT(link_1 -1, ',', link_2 -1, ',', link_3 -1, ',', link_4 -1, ',', link_5 -1, ',', link_6 -1) as links from {$game_id}_stars order by star_id asc");
        while ($systems[] = dbr(1)) {
        }
        //dump all entries into $systems.
        unset($systems[count($systems) - 1]);
        //remove a surplus entry
    }
    //process stars
    foreach ($systems as $star) {
        if (!empty($star['links'])) {
            //don't link all systems to 1 automatically.
            $star_links = array_map("plus_one", explode(',', $star['links']));
            $star_id = $star['num'] + 1;
            foreach ($star_links as $link) {
                //make star links
                if ($link < 1) {
                    continue 1;
                }
                $other_star = $systems[$link - 1];
                //set other_star to the link destination.
                imageline($im, $star['x_loc'] + $offset_x, $star['y_loc'] + $offset_y, $other_star['x_loc'] + $offset_x, $other_star['y_loc'] + $offset_y, $color_sl);
            }
        }
        if (!empty($star['wormhole'])) {
            //Wormhole Manipulation
            $other_star = $systems[$star['wormhole'] - 1];
            if ($other_star['wormhole'] == $star_id) {
                //two way
                imageline($im, $star['x_loc'] + $offset_x, $star['y_loc'] + $offset_y, $other_star['x_loc'] + $offset_x, $other_star['y_loc'] + $offset_y, $worm_2way_color);
            } else {
                //one way
                imageline($im, $star['x_loc'] + $offset_x, $star['y_loc'] + $offset_y, $other_star['x_loc'] + $offset_x, $other_star['y_loc'] + $offset_y, $worm_1way_color);
            }
        }
    }
    $central_star = 0;
    //hack to take into account arrays start with 0.
    foreach ($systems as $star) {
        //place the star itself. This is done after the lines, so the text comes on top.
        $off = array(-5, 4);
        //offset of text from star location
        if ($star['num'] == $central_star) {
            imagecopy($im, $earthIm, $star['x_loc'] + $offset_x + $earthPos[0], $star['y_loc'] + $offset_y + $earthPos[1], 0, 0, $earthDim[0], $earthDim[1]);
        } else {
            imagecopy($im, $starIm, $star['x_loc'] + $offset_x + $starPos[0], $star['y_loc'] + $offset_y + $starPos[1], 0, 0, $starDim[0], $starDim[1]);
        }
        //only show warp numbers if admin wants them.
        if ($uv_show_warp_numbers == 1) {
            if ($central_star === $star['num']) {
                $off = array(-5, 9);
                //write the star number under the star
                imagestring($im, $UNI['num_size'] + 2, $star['x_loc'] + $offset_x + $off[0], $star['y_loc'] + $offset_y + $off[1], $star['num'] + 1, $color_st);
            } else {
                imagestring($im, $UNI['num_size'], $star['x_loc'] + $offset_x + $off[0], $star['y_loc'] + $offset_y + $off[1], $star['num'] + 1, $color_st);
            }
        }
    }
    //for just a preview we can quit while we're ahead.
    if (isset($preview)) {
        Header("Content-type: image/png");
        ImagePng($im);
        ImageDestroy($im);
        exit;
    }
    //Draw title centered on the horizontal
    imagestring($im, 5, $size_x / 2 - 80, 5, "Universal Star Map", $color_l);
    //Create buffer image
    $bb_im = imagecreatetruecolor($UNI['size_x'] + $UNI['localmapwidth'], $UNI['size_y'] + $UNI['localmapheight']);
    ImageColorAllocate($im, $UNI['bg_color'][0], $UNI['bg_color'][1], $UNI['bg_color'][2]);
    ImageCopy($bb_im, $im, $UNI['localmapwidth'] / 2, $UNI['localmapheight'] / 2, $offset_x, $offset_y, $size_x, $size_y);
    //Create printable map
    $p_im = imagecreatetruecolor($size_x, $size_y);
    ImageColorAllocate($p_im, $UNI['print_bg_color'][0], $UNI['print_bg_color'][1], $UNI['print_bg_color'][2]);
    ImageCopy($p_im, $im, 0, 0, 0, 0, $size_x, $size_y);
    //Replace colors
    $index = ImageColorExact($p_im, $UNI['bg_color'][0], $UNI['bg_color'][1], $UNI['bg_color'][2]);
    ImageColorSet($p_im, $index, $UNI['print_bg_color'][0], $UNI['print_bg_color'][1], $UNI['print_bg_color'][2]);
    $index = ImageColorExact($p_im, $UNI['link_color'][0], $UNI['link_color'][1], $UNI['link_color'][2]);
    ImageColorSet($p_im, $index, $UNI['print_link_color'][0], $UNI['print_link_color'][1], $UNI['print_link_color'][2]);
    $index = ImageColorExact($p_im, $UNI['num_color'][0], $UNI['num_color'][1], $UNI['num_color'][2]);
    ImageColorSet($p_im, $index, $UNI['print_num_color'][0], $UNI['print_num_color'][1], $UNI['print_num_color'][2]);
    $index = ImageColorExact($p_im, $UNI['num_color3'][0], $UNI['num_color3'][1], $UNI['num_color3'][2]);
    ImageColorSet($p_im, $index, $UNI['print_num_color'][0], $UNI['print_num_color'][1], $UNI['print_num_color'][2]);
    $index = ImageColorExact($p_im, $UNI['star_color'][0], $UNI['star_color'][1], $UNI['star_color'][2]);
    ImageColorSet($p_im, $index, $UNI['print_star_color'][0], $UNI['print_star_color'][1], $UNI['print_star_color'][2]);
    //Draw new label
    ImageFilledRectangle($p_im, 0, 0, $size_x, $UNI['map_border'], ImageColorExact($p_im, $UNI['print_bg_color'][0], $UNI['print_bg_color'][1], $UNI['print_bg_color'][2]));
    imagestring($p_im, 5, $size_x / 2 - 80, 5, "Printable Star Map", ImageColorExact($p_im, $UNI['print_label_color'][0], $UNI['print_label_color'][1], $UNI['print_label_color'][2]));
    //get random filename. primarily for it re-genning maps.
    if (empty($random_filename)) {
        db("select random_filename from se_games where db_name = '{$game_id}'");
        $temp_filename = dbr(1);
        $random_filename = $temp_filename['random_filename'];
    }
    //Save map and finish
    ImagePng($im, "{$directories['images']}/{$game_id}_maps/sm_full_{$random_filename}.png");
    ImageDestroy($im);
    ImagePng($bb_im, "{$directories['images']}/{$game_id}_maps/bb_full_{$random_filename}.png");
    ImageDestroy($bb_im);
    ImagePng($p_im, "{$directories['images']}/{$game_id}_maps/psm_full_{$random_filename}.png");
    ImageDestroy($p_im);
}