<?php

require("db.inc.php");
require("functions.php");


if ($round == 1) {

	$title="list creator";

	include('header.inc.php');

    $stmt = "SELECT szuro FROM kk_szuro WHERE id='" . $id ."'";
	$mydb = new db();
	$result=$mydb->query($stmt);
    $row = mysql_fetch_object($result);

    $stmt = $row->szuro;
	$result=$mydb->query($stmt);


    printf("
    <B>Az új lista elemei</B>
    <TABLE border='1' style='border-collapse: collapse' bordercolor='#CCCCCC' CELLPADDING='5' STYLE='background: #FFFFFF;'>
    <TR>");
	printf("<TH style='font-size: 11px'>Az.</TH>\n");
	printf("<TH style='font-size: 11px'>Adatok</TH>\n");
	printf("<TH style='font-size: 11px'>Admin</TH>\n");

    while($row = mysql_fetch_row($result)){

        $s_data = "";
        for ($i=1;$i<sizeof($row);$i++) {
            $s_data .= $row[$i] . " | ";
            }

        $a_ids[] = $row[0];

        $s_data = substr($s_data, 0, strlen($s_data)-3);

        printf("<tr><td>%s</td><td>%s</td><td>Töröl</td></tr>", $row[0], $s_data);
        }

    printf("</TABLE>");


	$title="uj lista";

	printf("<B>Az új lista adatai</B>");

	$mydb = new db();

	$link=$mydb->get_link();

	$result=mysql_list_fields("fordit", "kk_lista", $link );

	for($field_index=0; $field_index<mysql_num_fields($result); $field_index++){
		$field_name=mysql_field_name($result, $field_index);
		$data[$field_name]="";
	}


    $s_ids = serialize($a_ids);
    $data['ids'] = base64_encode($s_ids);
    $data['datum'] = date('Y-m-d');
    
    generate_html_form('lista', $data, $PHP_SELF, 2);


	include('footer.inc.php');




} elseif($round==2){


    // insert
	while (list($key, $val) = each($_POST)) {
		if ($key<>"id" && $key<>"Submit" && $key<>"round"){
			$insert_fields.=$key .", ";
			$insert_values.= "'". addslashes($val) . "', ";
		}
	}

	$insert_fields=substr($insert_fields,0, strlen($insert_fields)-2);
	$insert_values=substr($insert_values,0, strlen($insert_values)-2);

	$stmt="INSERT INTO kk_lista($insert_fields) VALUES($insert_values)";

	$mydb = new db();
	$result=$mydb->query($stmt);
	header("Location:a_lista.php");


} else {

	$title="list creator";

	include('header.inc.php');

	$mydb = new db();

	printf("<B>Új lista gyártása</B>");

	printf("<FORM METHOD=post ACTION=\"%s\">\n", $PHP_SELF);
    printf("<table cellspacing=\"1\" style='background: #BBBBBB;'>");

    PrintSelect('kk_szuro', 'id', 'Szűrő', 1, 'id', 'nev');

    printf("<tr><td>&nbsp;</td><td><input type=\"submit\" name=\"Submit\" value=\"Mehet\"></td></tr>");
    printf("</table>");
    printf("<input type=\"hidden\" name=\"round\" value=\"1\">");
	printf("</FORM>");
	include('footer.inc.php');
}





?>
