<?php

	#$this; // object reference 
	#$this->dbh; // initialized MySQL database handle 
	#$this->key; // primary key name 
	#$this->key_type; // primary key type 
	#$this->key_delim; // primary key deliminator 
	#$this->rec; // primary key value (update and delete only) 
	#$newvals; // associative array of new values (update and insert only) 
	#$oldvals; // associative array of old values (update and delete only) 
	#$changed; // array of keys with changed values

	require_once 'auth.php';
	global $adodb;
	#$adodb->debug = 1;
	#var_dump($newvals);

	$copyid = $_REQUEST['copyid'];
	if ($copyid) {
		$insertID = $this->insert_id;
		$rs = $adodb->Execute("SELECT * FROM qb_report".
		" WHERE id = ? ", array($copyid));
		$record = $rs->fields;

		$rs = $adodb->Execute("SELECT * FROM qb_user_report".
		" WHERE name = ? ", array($record['name']));
		while (!$rs->EOF) {
			$record = $rs->fields;
			unset($record['id']);
			$record['name'] = $newvals['name'];
			$adodb->Execute($adodb->GetInsertSQL($rs, $record));
			$rs->MoveNext();
		}

		$rs = $adodb->Execute("SELECT * FROM qb_dictionary".
		" WHERE module = ? ", array('qb_report_'.$copyid));
		while (!$rs->EOF) {
			$record = $rs->fields;
			unset($record['id']);
			$record['module'] = 'qb_report_'.$insertID;
			$adodb->Execute($adodb->GetInsertSQL($rs, $record));
			$rs->MoveNext();
		}
	}

?>
