<?php
// $Id: gen10000.php,v 1.3 2005/10/28 11:56:02 ohwada Exp $

//================================================================
// genarete 10000 link data
// for debug
// 2004/08/10 K.OHWADA
//================================================================

include '../../../mainfile.php';
include '../../../include/cp_header.php';

global $xoopsDB, $xoopsUser, $xoopsModule;
xoops_cp_header();

// check permission
$flag = false;
if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) 
{	$flag = true;	}

if (!$flag)
{
	echo "<font color=red>you are not admin</font><br>";
	xoops_cp_footer();
	exit();
}

// table name
$MODULE_DIRNAME = $xoopsModule->dirname();
$table_link     = $MODULE_DIRNAME."_link";
$table_link     = $xoopsDB->prefix($table_link);
$table_catlink  = $MODULE_DIRNAME."_catlink";
$table_catlink  = $xoopsDB->prefix($table_catlink);

echo "<h3>start</h3>";

srand( (double)microtime()*1000000 );

for ($i=0; $i<10000; $i++)
{

// randum data
	$title = chr( rand(97,122) ).sprintf( "%06d", rand(0,999999) );
	$url   = "http://$title/";
	$time  = time();
	$desc  = "$title $time ";

	$cids = '&';
	$arr  = array();

	for ($j=0; $j<4; $j++)
	{
		$cid = rand(1,120);

		$cids .= "$cid&";
		$arr[] = $cid;
	}

// link table
	$sql  = "INSERT INTO $table_link ";
	$sql .= "(cids,title,url,description,time_create,time_update) ";
	$sql .= "VALUES ('$cids','$title','$url','$desc',$time,$time) ";

	echo "$sql <br>";
	sql_exec($sql);

	$newid = $xoopsDB->getInsertId();

// catlink table
	foreach ($arr as $cid)
	{
		$sql  = "INSERT INTO $table_catlink ";
		$sql .= " (cid, lid) ";
		$sql .= " VALUES ($cid, $newid) ";

		echo "$sql <br>";
		sql_exec($sql);
	}

}

echo "<h3>end</h3>";
xoops_cp_footer();
exit();


function sql_exec($sql)
{ 
	global $xoopsDB;

	$ret = $xoopsDB->queryF($sql);
	if ($ret != false ) { return $ret; }

	$error = $xoopsDB->error();
	echo "<font color=red>$sql<br>$error</font><br>";

	return false;
}


?>