I saw some request in JCow forum about user add from admin panel.
So i gave sometimes and it works.
Here is the code:
1. First you have to edit modules/admin/admin.php
and put these two function.
function useradd(){
nav(t(‘Users/Add User’));
section_content(‘
<fieldset>
<form action=”‘.url(‘admin/useraddpost’).’” method=”post”>
‘);
section_content(‘
<p>
‘.label(‘Full Name’).’
<input type=”text” name=”fullname” size=30 />
</p>
<p>
‘.label(‘Username’).’
<input type=”text” name=”username” size=30 />
</p>
<p>
‘.label(‘Password’).’
<input type=”text” name=”password” size=30 />
</p>
<p>
‘.label(‘E-mail’).’
<input type=”text” name=”email” size=30 />
</p>
<p>
‘.label(t(‘Gender’)).’
<input type=”radio” name=”gender” value=1 checked/> Male
<input type=”radio” name=”gender” value=0 /> Female
<input type=”radio” name=”gender” value=2 /> Hide<br />
</p>
<p>
‘.label(t(‘Status’)).’
<input type=”radio” name=”disabled” value=0 checked/> Active
<input type=”radio” name=”disabled” value=1 /> Pending
<input type=”radio” name=”disabled” value=2 /> Suspended<br />
</p>
<p>
<input type=”submit” value=”‘.t(‘Add User’).’” />
</p>
</form>
</fieldset>’);
}
the above function will show form to add user.
function useraddpost(){
$_POST['username'] = strtolower($_POST['username']);
if (strlen($_POST['username']) < 4 || strlen($_POST['username']) > 18 || !ereg(“^[0-9a-z]+$”,$_POST['username'])) {
$errors[] = t(‘Username’).’: ‘.t(‘from 4 to 18 characters, only 0-9,a-z’);
}
if (!$_POST['email'] || !$_POST['fullname'] || !$_POST['username'] || !$_POST['password']) {
$errors[] = t(‘Please fill in all the required blanks’);
}
if(!eregi(“^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$”, $_POST['email'])) {
$errors[] = t(‘Unavailable email address’);
}
$password = md5($_POST['password'].’jcow’);
$timeline = time();
$res = sql_query(“select * from `”.tb().”accounts` where email=’{$_POST['email']}’”);
if (sql_counts($res)) {
$errors[] = t(‘You have registered with this email address before.’);
}
$res = sql_query(“select * from `”.tb().”accounts` where username=’{$_POST['username']}’”);
if (sql_counts($res)) {
$errors[] = t(‘The Username has already been used’);
}
if(!is_array($errors)){
sql_query(“insert into `”.tb().”accounts` (hide_age,gender,disabled,password,email,username,fullname,created) values
(’1′,”.$_POST['gender'].”,”.$_POST['disabled'].”,’$password’,'”.$_POST['email'].”‘,’”.$_POST['username'].”‘,’”.$_POST['fullname'].”‘,’”.$timeline.”‘)”);
$uid = insert_id();
sql_query(“insert into `”.tb().”profiles` (id,style_ids) values($uid,’3|3|3′)”);
stream_publish(t(‘Signed Up’),”,”,$uid);
t(‘Congratulations! You have successfully created user.’);
redirect(“admin/users”);
}else {
foreach ($errors as $error) {
$error_msg .= ‘<li>’.$error.’</li>’;
}
sys_notice(t(‘Errors’).’:<ul>’.$error_msg.’</ul>’);
}
}
The above function will add user after submitting.
2. Now add this line to users() function of admin.php files.
c(“<p><a href=”.url(“admin/useradd”).”>Add User</a></p>”);

Jcow Admin Add user Link
3. That’s all. Go to admin panel->members->add user. i hope rest of work you can do:P..
Download the source code.
Jcow Admin Add user Source
Recent Comments