Intranet Software, Extranet Software, Corporate Intranets & Extranets
Translations of this page:

Create user account and send an email notification with newly created account details

For basic information on plugins, please refer: Infocapture plugins

In this section we would see the following things:

1. How to create a new user account

2. Assign newly created user to the selected Extranet area, Group and Role

3. Send an email notification with the newly created account details to the user

You can find the xml file of the test project here:

Lets suppose we have this test project with ID = 47

We require three plugins to achive above said things:

1. plugin_47_pre_add_issue.php

<?php
function hd_plugin_47_pre_add_issue($params)
{
	$project_info = $params["project"];
	$issue_info = $params["issue"];
	$issue_fields = $params["issue"]["fields_values"];
 
	$username = $issue_fields["username"];
	$password = $issue_fields["password"];
	$confirm_pass = $issue_fields["confirm_password"];
	
	$pass = strcmp($password, $confirm_pass);
	if($pass != 0)
		return array("error_message" => "Password and Confirm password must be same!!");
 
	$user_list = User::GetAll();
	foreach($user_list as $id)
	{
		$usern = $id->GetUsername();
		if($username == $usern)
			return array("error_message" => "Username already exits. Kindly enter another username");
	}
}
?>

2. plugin_47_add_issue.php

<?php
function hd_plugin_47_add_issue($params)
{
	//This function is used to send an Email Notification Template
	//$email_address: The email id to send an Email Notification
	//$id: id of the Notification Template
	//$templates: An array which consists the template
	function sendMessage($email_address, $id, $templates)
	{
		$msg = new ClaMailMessage('utf-8');
		$msg->SetFrom("noreply@claromentis.com");
		$msg->SetTo($email_address);
		$msg->SetSubject($templates["subj"]["$id"]);
 
		if($templates["html"]["$id"])
		{
			$msg->SetTxtBody(Html2Plain($templates["body"]["$id"]));
			$msg->SetHtmlBody($templates["body"]["$id"]);
		}
		else
		{
			$msg->SetTxtBody($templates["body"]["$id"]);
		}
		$msg->Send();
	}
 
	//Creating neccessary objects while used in parsing
	$issue = new HDIssue();
	$issue->Load($params["issue"]["id"]);
	$issue->GetFormData();
 
	//Getting all Notifications from the project
	$project = new HDProject();
	$project->Load($params["project"]["id"]);
	list($notif_templates, $notif_settings) = $project->GetNotifSettings();
		
	$project_info = $params["project"];
	$issue_info = $params["issue"];
	$issue_fields = $params["issue"]["fields_values"];
	
	$fbform = new FBForm();
	$pid = 47;
 
	if (!$project->Load($pid))
	{
		$errno = "Cannot load current project";
		vard2($errno);
		exit;
	}
	$fbform = $project->getForm();
	$fbform->loadFields();
	$fd = $issue->GetFormData();
	
	if ($fd)
	{
		$fd->loadAllData();
	}
	$fd->LoadFormPrototype($form);
	$fd->loadAllData();
	$fd->GetFieldsData();
	
	//Fetch groups
	$groups = "Please Select,#0\n";
	$group_list = UserGroup::GetGroupsList();
	foreach($group_list as $group_id => $group_name)
	{
		$groups = "$groups" . $group_name . ",#" . $group_id . "\n";
	}
	$group = $fbform->getFieldBySymname("group");
	$group->setFBValue("items","$groups");
 
	//Fetch roles
	$roles = "Please Select,#0\n";
	$role_list = UserRole::GetRolesList();
	foreach($role_list as $role_id => $role_name)
	{
		$roles = "$roles" . $role_name . ",#" . $role_id . "\n";
	}
	$role = $fbform->getFieldBySymname("role");
	$role->setFBValue("items","$roles");
		
	$group_assign = $issue_fields["group"];
	$role_assign = $issue_fields["role"];
	$create_account = $issue_fields["create_account"];
		
	//create user account if checkbox is checked
	if($create_account == 1)
	{
		$user = new User($uid = 0);
		$user->SetSurname($issue_fields["surname"]);
		$user->SetFirstname($issue_fields["first_name"]);
		$user->SetEmailad($issue_fields["email"]);
		$user->SetCompany($issue_fields["company"]);
		$user->SetCity($issue_fields["city"]);
		$user->SetLandline($issue_fields["landline"]);
		$user->SetUsername($issue_fields["username"]);
		$user->SetPassword($issue_fields["password"]);
		$user->SetExAreaId($issue_fields["extranet"]);
		$user->SetGroup($group_assign);
		$user->SetRole($role_assign);
		$user->SetPpChangeNextTime(1);
		$user->Save();
		$user->Unblock();
		$id = $user->GetId();
		
		
		foreach($group_list as $group_id1 => $group_name1)
		{
			if($group_id1 == $group_assign)
				$value = array($group_id1 => $group_name1);
		}
		UserGroup::AssignNewGroups($id, $value);
		
		foreach($role_list as $role_id1 => $role_name1)
		{
			if($role_id1 == $role_assign)
				$value1 = array($role_id1 => $role_name1);
		}
		UserRole::AssignNewRoles($id, $value1);
		
		$templates = array();
		$templates["body"][0] = "";
		$templates["subj"][0] = "";
		$templates["html"][0] = "";
 
		$tmpl = parse_ic_templates($params);
		
		sendMessage($issue_fields["email"], "1", $tmpl);
	}
}
?>

3. plugin_47_view_form.php

<?php
function hd_plugin_47_view_form($params)
{
	//Fetch groups
	$groups = "Please Select,#0\n";
	$group_list = UserGroup::GetGroupsList();
	foreach($group_list as $group_id => $group_name)
	{
		$groups = "$groups" . $group_name . ",#" . $group_id . "\n";
	}
	
	//Fetch roles
	$roles = "Please Select,#0\n";
	$role_list = UserRole::GetRolesList();
	foreach($role_list as $role_id => $role_name)
	{
		$roles = "$roles" . $role_name . ",#" . $role_id . "\n";
	}
	
	$ret = array();
	$ret["form_fields"]["group"]["items"] = $groups;
	$ret["form_fields"]["role"]["items"] = $roles;
	return ($ret);
}
?>

If you fill the above form, check the checkbox for “Create user account” and report the form, a new user account would be created with the specified details in the form and an email notification would be send to the email address entered in the form

 
help/infocapture/plugins/create_user_account.txt · Last modified: 07/06/2011 04:49 by sweta
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki