generateAccounts.php 4.27 KB
<?
$_LOSP_DUMP_ACCOUNTS = '500';



require_once("../include/config.php");
$_LOSPDIR = $_LOSP_PATH_TO_ROOT = '../';
$_LOSP_DEV = false;
require_once("../include/System/php/RequireClass.inc.php");
require_once("generateAccounts_AccountData.php");
$var_filedir = 'Userfiles';
$var_http_filedir = $_SERVER['HTTP_HOST'];
$obj_ManipulateFiles = new ManipulateFiles($var_filedir);
$DB = StorableFactory::create($_LOSP_STORABLE_KINDOF, $_LOSP_STORABLE_DATA);


function count_mysqlrows($DB,$param_table='losp_BE_profile', $param_tag='start') {
	$query = "SELECT COUNT(*) FROM ".$param_table." ;";
	$stmt = $DB->PDO_query($query);
	$i=0;
	foreach($DB->PDO_fetchAll($stmt) as $spalten) {
		$ary_keys= array_keys($spalten);
		$out[$param_tag] = $spalten[$ary_keys[$i]];
		$i++;
	}
	return $out[$param_tag];
}
$numOfNicks = count_mysqlrows($DB);
echo " numOfNicks: ".$numOfNicks;

if($_LOSP_DUMP_ACCOUNTS) {
	$var_query = 'select max(ID) from losp_be_account';
	$INPUT_Accounts = array ();
	for($i=0; $i<$_LOSP_DUMP_ACCOUNTS;$i++) {
		$var_passwd = Dump::genPassword(6);
		$var_nick = 'nick' . $i;
		$INPUT_Accounts[] = array(

				'Account' => array(
					'Password' => $var_passwd,
					'EMail' => '@',
					'FirstName' => ' '.$i,	'SurName' => ' '.$i,
					'Street' => '',	'Streetnumber' => '',	'City' => '',	'ZipCode' => '',
		),
				'Profile' => array(
					'NickName' =>$var_nick,
					'EMail' => '@',
					'Name' => 'Name','Avatar' => '','Signature' => '',
					'Fingerprint' => '',	'Jabber' => '','Url' => '','Subject' => 'Subject','Text' => 'Text',
		),
		//				'BasisClipboards' => array(	'LocationBC' => array (	'Name' => 'Osnabrück'	)	),
		) ;

	}
}

$count_createted = 0;
foreach($INPUT_Accounts as $var_data)	 {
	if($var_data['Profile']['NickName'] && Profile::NickNameToID($DB, $var_data['Profile']['NickName'])==$var_data['Profile']['NickName']) {
		$count_createted++;
		{
			$var_Profile = BasisElement::createNewInstance($DB, 'Profile', '');
			$var_Profile->setData($HostAccount, $DB,$var_data['Profile']);
			$var_Profile->saveObject($HostAccount, $DB);

		}

		if($var_Profile->getObjVar('ID')){
			echo $count_createted.": $var_Profile Nickname: ".$var_data['Profile']['NickName']." -- ";
			$var_Account = BasisElement::createNewInstance($DB, 'Account', '');
			$var_data['Account']['ProfileID']=$var_Profile->getObjVar('ID');
			$var_Account->setData($HostAccount, $DB, $var_data['Account']);
			$var_Account->setPassword($var_data['Account']['Password']);
			$var_Account->saveObject($var_Account, $DB);
			echo "$var_Account \n";

			if(array_key_exists('BasisClipboards', $var_data) && is_array($var_data['BasisClipboards'])) {
				foreach($var_data['BasisClipboards'] as $var_BCName => $var_KeyValueArray) {
					$var_BEName = CONFIG::getBC_MultimediaText($var_BCName);
					$var_table = CONFIG::getSQL_Data($var_BEName, 'Tablename');
					if($var_table && is_array($var_KeyValueArray)) {
						$var_query = 'select MTextID from '.$var_table.' where ';
						$var_tmp=false;
						foreach($var_KeyValueArray as $var_Key => $var_Value) {
							if($var_tmp) {
								$var_query .= ' and ';
							}
							$var_query .= ' '.$var_Key.'=\''.$var_Value.'\' ';
							$var_tmp =true;
						}
						$Resource = $DB->PDO_query($var_query);
						if($Resource) {
							foreach($DB->PDO_fetchAll($Resource) as $row) {
								$var_query_BCinsert='select insertMTextIntoClipboard('.$var_Profile->getObjVar('ID').', '.$var_Profile->getObjVar('ID').', '.$row['MTextID'].', \''.$var_BCName.'\', \'\', \'unreaded\')';
								echo "\t ".$var_query_BCinsert." \n";
								$Resource1 = $DB->PDO_query($var_query_BCinsert);
							}
						}
					}
				}
			}
			$string = ' nick: '.$var_data['Profile']['NickName']. " pw: ".$var_data['Account']['Password'] .'
' ;
			$var_filename = 'GenUsers.txt';
			$obj_ManipulateFiles->fileputs($var_filename,$string);
		} else {
			echo "0: $var_Profile Nickname: ".$var_data['Profile']['NickName']." \n";
		}
	} else if(!$var_data['Profile']['NickName']) {
		echo " Profile Nickname ".$var_data['Profile']['NickName']." ist leer!! \n";
	} else {
		echo " Profile Nickname ".$var_data['Profile']['NickName']." existiert schon!! ID(".Profile::NickNameToID($DB, $var_data['Profile']['NickName']).") \n";
	}

}
echo "\n".$count_createted." Account/Profile wurden erstellt   [$count_createted/".count($INPUT_Accounts)."]  \n";

?>