#!/usr/local/php/bin/php
<?php
/**
 *	Project:	Quicty: Quick application build environment for PHP depends on PEAR and Smarty
 *	File:		Quicty/modules/template/userauth/bin/set_user_pass.php
 *	Usage:		$ bin/set_user_pass.php login_id=foo
 *
 *	@copyright	Tomoyuki Negishi and ZubaPitaTech, Inc.
 *	@author		Tomoyuki Negishi <tomoyu-n@zubapita.jp>
 *	@license	http://www.opensource.org/licenses/bsd-license.php The BSD License
 *	@package	Quicty
 *	@version	$Id:$
 */
$dir_path = explode('/',dirname(__FILE__));
$dummy = array_pop($dir_path);
$home_dir = implode('/',$dir_path);
require_once $home_dir.'/lib/myQuicty.php';

class set_user_pass extends myQuicty {

function dispatch_index() {
	global $home_dir;
	$argv = get_argv();
	$login_id = $argv['login_id'];
	if(!$login_id) {
		echo "usage: set_user_pass.php login_id=xxxxxxxx\n";
		exit;
	}
	$_FORM = $this->new_data_set('userauth');
	$user = $_FORM->select_table("where login_id='$login_id'");
	if(count($user)<1) {
		echo "error!. login_id:$login_id is not found.\n";
		exit;
	}
	$new_pass = substr(uniqid(),0,8);
	$md5_pass = md5($new_pass);
	$update_set['password'] = $new_pass;
	$result = $_FORM->update_table($update_set,"where login_id='$login_id'");
	$user = $_FORM->select_table("where login_id='$login_id'");
	$handle = $user[0]['handle'];
	$realname = $user[0]['family_name'].' '.$user[0]['given_name'];
	echo "IDとパスワード\n";
	echo "\n";
	echo "$handle さん（$realname さん）のログインIDとパスワードをお知らせします。\n";
	echo "-----------------------------------\n";
	echo "login ID             :$login_id\n";
	echo "login password       :$new_pass\n";
	echo "----------------------------------\n";
	echo "上記のIDとパスワードでログインしたあと、「ユーザー登録情報」で覚えやすいパスワードに変更してください。\n";
	echo "----------------------------------\n";
	echo "md5 password:$md5_pass\n";
	exit;
}

	
} // end of set_user_pass
// }}}
$quicty = new set_user_pass($home_dir);
$quicty->dispatch_index();

?>
