diff options
| author | MW <joasch@users.sourceforge.net> | 2007-11-15 19:27:20 +0000 |
|---|---|---|
| committer | MW <joasch@users.sourceforge.net> | 2007-11-15 19:27:20 +0000 |
| commit | 80e67adc95367049a2dabc0091f721749bad230f (patch) | |
| tree | e77d9ead7ded8eaf33f847812817b2959de1be21 | |
| parent | 6f65e95f0f4a4c2712814af65994ca3b0379688c (diff) | |
| download | users-80e67adc95367049a2dabc0091f721749bad230f.tar.gz users-80e67adc95367049a2dabc0091f721749bad230f.tar.bz2 users-80e67adc95367049a2dabc0091f721749bad230f.zip | |
moving user import to an admin page of its own. 2 new files for this, and 1 new users_lib.php file for common functions. Just 1 so far.
| -rw-r--r-- | admin/index.php | 112 | ||||
| -rw-r--r-- | admin/users_import.php | 97 | ||||
| -rw-r--r-- | templates/menu_users_admin.tpl | 1 | ||||
| -rw-r--r-- | templates/users_admin.tpl | 76 | ||||
| -rw-r--r-- | templates/users_import.tpl | 89 | ||||
| -rw-r--r-- | users_lib.php | 34 |
6 files changed, 225 insertions, 184 deletions
diff --git a/admin/index.php b/admin/index.php index dd2a1ca..cce1b75 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,127 +1,26 @@ <?php -// $Header: /cvsroot/bitweaver/_bit_users/admin/index.php,v 1.22 2007/11/14 15:30:34 joasch Exp $ +// $Header: /cvsroot/bitweaver/_bit_users/admin/index.php,v 1.23 2007/11/15 19:27:20 joasch Exp $ // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. // All Rights Reserved. See copyright.txt for details and a complete list of authors. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. // Initialization require_once( '../../bit_setup_inc.php' ); -function batchImportUsers() { - global $gBitSmarty, $gBitUser, $gBitSystem; - // get the delimiter if it's set - use comma if it not - $delimiter = !empty( $_REQUEST['delimiter'] ) ? $_REQUEST['delimiter'] : ","; - $fname = $_FILES['csvlist']['tmp_name']; - $fhandle = fopen( $fname, "r" ); - - //Get the field names - $fields = fgetcsv( $fhandle, 1000, $delimiter ); - - // is the file a valid CSV file? - if( empty( $fields[0] ) ) { - $gBitSystem->fatalError( tra( "The file is not a CSV file or has not a correct syntax" )); - } - - //now load the users in a table - while( !feof( $fhandle ) ) { - if( $data = fgetcsv( $fhandle, 1000, $delimiter ) ) { - for( $i = 0; $i < count( $fields ); $i++ ) { - @$ar[$fields[$i]] = $data[$i]; - } - $userRecords[] = $ar; - } - } - fclose( $fhandle ); - - // were there any users in the list? - if( !is_array( $userRecords ) ) { - $gBitSystem->fatalError( tra( "No records were found. Check the file please!" )); - } - // Process user array - $added = 0; - $i = 1; - foreach( $userRecords as $userRecord ) { - $newUser = new BitPermUser(); - if( $newUser->importUser( $userRecord ) ) { - if( !empty( $userRecord['groups'] ) ) { - // groups need to be separated by spaces since this is a csv file - $groups = explode( " ", $userRecord['groups'] ); - foreach( $groups as $group ) { - if( $groupId = $gBitUser->groupExists( $group, ROOT_USER_ID ) ) { - $newUser->addUserToGroup( $newUser->mUserId, $groupId ); - } - } - } - if( empty( $_REQUEST['admin_noemail_user'] ) ) { - $ret = adminEmailUser( $userRecord ); - if( is_array( $ret ) ) { - list($key, $val) = each($ret); - $newUser->mLogs[$key] = $val; - } - $logHash['action_log']['title'] = $userRecord['login']; - $newUser->storeActionLog( $logHash ); - } - - $added++; - } else { - $discarded[$i] = implode( ',', $newUser->mErrors ); - } - unset( $newUser ); - $i++; - } - - $gBitSmarty->assign( 'added', $added ); - if( @is_array( $discarded ) ) { - $gBitSmarty->assign( 'discarded', count( $discarded ) ); - $gBitSmarty->assign_by_ref( 'discardlist', $discarded ); - } -} - -function adminEmailUser( &$pParamHash ) { - global $gBitSmarty, $gBitSystem; - - $ret = FALSE; - $siteName = $gBitSystem->getConfig('site_title', $_SERVER['HTTP_HOST'] ); - $gBitSmarty->assign('siteName',$_SERVER["SERVER_NAME"]); - $gBitSmarty->assign('mail_site',$_SERVER["SERVER_NAME"]); - $gBitSmarty->assign('mail_user',$pParamHash['login']); - if( !empty( $_REQUEST['admin_verify_user'] ) && !empty($pParamHash['user_store']['provpass']) ) { - $apass = addslashes(substr(md5($gBitSystem->genPass()),0,25)); - $apass = $pParamHash['user_store']['provpass']; - $machine = httpPrefix().USERS_PKG_URL.'confirm.php'; - // Send the mail - $gBitSmarty->assign('mail_machine',$machine); - $gBitSmarty->assign('mailUserId',$pParamHash['user_store']['user_id']); - $gBitSmarty->assign('mailProvPass',$apass); - $mail_data = $gBitSmarty->fetch('bitpackage:users/admin_validation_mail.tpl'); - mail($pParamHash['email'], $siteName.' - '.tra('Your registration information'),$mail_data,"From: ".$gBitSystem->getConfig('site_sender_email')."\r\nContent-type: text/plain;charset=utf-8\r\n"); - $gBitSmarty->assign('showmsg','n'); - - $ret = array('confirm' => 'Validation email sent to ' . $pParamHash['email'] . '.'); - } elseif( !empty( $pParamHash['password'] ) ) { - // Send the welcome mail - $gBitSmarty->assign( 'mailPassword',$pParamHash['password'] ); - $gBitSmarty->assign( 'mailEmail',$pParamHash['email'] ); - $mail_data = $gBitSmarty->fetch('bitpackage:users/admin_welcome_mail.tpl'); - mail($pParamHash["email"], tra( 'Welcome to' ).' '.$siteName,$mail_data,"From: ".$gBitSystem->getConfig('site_sender_email')."\r\nContent-type: text/plain;charset=utf-8\r\n"); - $ret = array('welcome'=>'Welcome email sent to ' . $pParamHash['email'] . '.'); - } - return $ret; -} $gBitSystem->verifyPermission( 'p_users_admin' ); $feedback = array(); -// Process the form to add a user here if( isset($_REQUEST["newuser"] ) ) { + require_once( USERS_PKG_PATH.'users_lib.php' ); $userRecord = $_REQUEST; $newUser = new BitPermUser(); if( $newUser->importUser( $userRecord ) ) { $gBitSmarty->assign( 'addSuccess', "User Added Successfully" ); if( empty( $_REQUEST['admin_noemail_user'] ) ) { - $ret = adminEmailUser( $userRecord ); + $ret = users_admin_email_user( $userRecord ); if( is_array( $ret ) ) { list($key, $val) = each($ret); $newUser->mLogs[$key] = $val; @@ -133,11 +32,6 @@ if( isset($_REQUEST["newuser"] ) ) { $gBitSmarty->assign_by_ref( 'newUser', $_REQUEST ); $gBitSmarty->assign( 'errors', $newUser->mErrors ); } - // if no user data entered, check if it's a batch upload -} elseif( isset( $_REQUEST["batchimport"]) ) { - if( $_FILES['csvlist']['size'] && is_uploaded_file($_FILES['csvlist']['tmp_name'] ) ) { - batchImportUsers(); - } } elseif( isset( $_REQUEST["assume_user"]) && $gBitUser->hasPermission( 'p_users_admin' ) ) { $assume_user = (is_numeric( $_REQUEST["assume_user"] )) ? array( 'user_id' => $_REQUEST["assume_user"] ) : array('login' => $_REQUEST["assume_user"]) ; $userInfo = $gBitUser->getUserInfo( $assume_user ); diff --git a/admin/users_import.php b/admin/users_import.php new file mode 100644 index 0000000..971bd33 --- /dev/null +++ b/admin/users_import.php @@ -0,0 +1,97 @@ +<?php +// $Header: /cvsroot/bitweaver/_bit_users/admin/users_import.php,v 1.1 2007/11/15 19:27:20 joasch Exp $ +// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. +// All Rights Reserved. See copyright.txt for details and a complete list of authors. +// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. +// Initialization +require_once( '../../bit_setup_inc.php' ); + +$gBitSystem->verifyPermission( 'p_users_admin' ); + +$feedback = array(); + +if( isset( $_REQUEST["batchimport"])) { + require_once( USERS_PKG_PATH.'users_lib.php' ); + // check if it's a batch upload + + if( $_FILES['csvlist']['size'] && is_uploaded_file($_FILES['csvlist']['tmp_name'] ) ) { + global $gBitSmarty, $gBitUser, $gBitSystem; + + // get the delimiter if it's set - use comma if it not + $delimiter = !empty( $_REQUEST['delimiter'] ) ? $_REQUEST['delimiter'] : ","; + $fname = $_FILES['csvlist']['tmp_name']; + $fhandle = fopen( $fname, "r" ); + + //Get the field names + $fields = fgetcsv( $fhandle, 1000, $delimiter ); + + // is the file a valid CSV file? + if( empty( $fields[0] ) ) { + $gBitSystem->fatalError( tra( "The file is not a CSV file or has not a correct syntax" )); + } + + //now load the users in a table + while( !feof( $fhandle ) ) { + if( $data = fgetcsv( $fhandle, 1000, $delimiter ) ) { + for( $i = 0; $i < count( $fields ); $i++ ) { + @$ar[$fields[$i]] = $data[$i]; + } + $userRecords[] = $ar; + } + } + fclose( $fhandle ); + + // were there any users in the list? + if( !is_array( $userRecords ) ) { + $gBitSystem->fatalError( tra( "No records were found. Check the file please!" )); + } + // Process user array + $added = 0; + $i = 1; + foreach( $userRecords as $userRecord ) { + $newUser = new BitPermUser(); + if( $newUser->importUser( $userRecord ) ) { + if( !empty( $userRecord['groups'] ) ) { + // groups need to be separated by spaces since this is a csv file + $groups = explode( " ", $userRecord['groups'] ); + foreach( $groups as $group ) { + if( $groupId = $gBitUser->groupExists( $group, ROOT_USER_ID ) ) { + $newUser->addUserToGroup( $newUser->mUserId, $groupId ); + } + } + } + if( empty( $_REQUEST['admin_noemail_user'] ) ) { + $ret = users_admin_email_user( $userRecord ); + if( is_array( $ret ) ) { + list($key, $val) = each($ret); + $newUser->mLogs[$key] = $val; + } + $logHash['action_log']['title'] = $userRecord['login']; + $newUser->storeActionLog( $logHash ); + } + + $added++; + } else { + $discarded[$i] = implode( ',', $newUser->mErrors ); + } + unset( $newUser ); + $i++; + } + + $gBitSmarty->assign( 'added', $added ); + if( @is_array( $discarded ) ) { + $gBitSmarty->assign( 'discarded', count( $discarded ) ); + $gBitSmarty->assign_by_ref( 'discardlist', $discarded ); + } + } +} + +// get default group and pass it to tpl +foreach( $gBitUser->getDefaultGroup() as $defaultGroupId => $defaultGroupName ) { + $gBitSmarty->assign('defaultGroupId', $defaultGroupId ); + $gBitSmarty->assign('defaultGroupName', $defaultGroupName ); +} + +// Display the template +$gBitSystem->display( 'bitpackage:users/users_import.tpl', (!empty( $title ) ? $title : 'Import Users' ) ); +?> diff --git a/templates/menu_users_admin.tpl b/templates/menu_users_admin.tpl index ba167bb..38170c2 100644 --- a/templates/menu_users_admin.tpl +++ b/templates/menu_users_admin.tpl @@ -6,6 +6,7 @@ {/if} <li><a class="item" href="{$smarty.const.KERNEL_PKG_URL}admin/index.php?page=login">{tr}Login Settings{/tr}</a></li> <li><a class="item" href="{$smarty.const.USERS_PKG_URL}admin/index.php">{tr}Edit Users{/tr}</a></li> + <li><a class="item" href="{$smarty.const.USERS_PKG_URL}admin/users_import.php">{tr}Import Users{/tr}</a></li> <li><a class="item" href="{$smarty.const.USERS_PKG_URL}admin/edit_group.php">{tr}Groups & Permissions{/tr}</a></li> <li><a class="item" href="{$smarty.const.USERS_PKG_URL}admin/permissions.php">{tr}Permission Maintenance{/tr}</a></li> </ul> diff --git a/templates/users_admin.tpl b/templates/users_admin.tpl index 5d7a844..6ed8e98 100644 --- a/templates/users_admin.tpl +++ b/templates/users_admin.tpl @@ -1,4 +1,4 @@ -{* $Header: /cvsroot/bitweaver/_bit_users/templates/users_admin.tpl,v 1.9 2007/11/14 15:30:34 joasch Exp $ *} +{* $Header: /cvsroot/bitweaver/_bit_users/templates/users_admin.tpl,v 1.10 2007/11/15 19:27:18 joasch Exp $ *} {strip} <div class="floaticon">{bithelp}</div> @@ -8,24 +8,6 @@ </div> <div class="body"> - {if (($added ne "") || ($discarded ne "")) } - <h2>{tr}Batch Upload Results{/tr}</h2> - {if $added} - {formfeedback success="`$added` Users Added"} - {/if} - - {if $discarded ne '' } - {formfeedback error="`$discarded` Users Rejected"} - <table class="data" style="width:400px"> - <tr class="error"><th>{tr}Row{/tr}</th><th>{tr}Reason{/tr}</th></tr> - {foreach key=row from=$discardlist item=reason} - <tr class="{cycle values="odd,even"}"><td>{$row}</td><td>{$reason}</td></tr> - {/foreach} - </table> - <br /> - {/if} - {/if} - {jstabs} {jstab title="List of Users"} {include file="bitpackage:users/users_list.tpl"} @@ -123,62 +105,6 @@ </div> {/form} {/jstab} - - {jstab title="Advanced"} - {form legend="Batch user addition" enctype="multipart/form-data"} - <div class="row"> - {formlabel label="Batch upload (CSV file)" for="csvlist"} - {forminput} - <input type="file" name="csvlist" id="csvlist" /> - {formhelp note="You can batch import users by uploading a CSV (comma-separated values) file. The file needs to have the column names in the first line. The column titles need to match with fields in 'users_users' table. Login, password and email are required fields, however if you leave the password field empty a new password will be auto generated. You can also import a MD5 hash as password, like from phpBB2, it need to be put in the 'hash' column. In such case it override other options and it's assumed the user or at least admin knows the password. Currently you can't import custom fields and if a non-existent field is specified, it's ignored."} - {/forminput} - </div> - - <div class="row"> - {formlabel label="Delimiter" for="delimiter"} - {forminput} - <input type="text" size="3" name="delimiter" id="delimiter" value="," /> - {formhelp note="Set the delimiter of the file. You can not use tab as delimiter."} - {/forminput} - </div> - - <div class="row"> - {formlabel label="Overwrite existing users" for="overwrite"} - {forminput} - <input type="checkbox" name="overwrite" id="overwrite" /> - {formhelp note=""} - {/forminput} - </div> - - <div class="row"> - {formlabel label="Validate users by email" for="admin_verify_user"} - {forminput} - <input type="checkbox" name="admin_verify_user" id="admin_verify_user" /> - {formhelp note="This will email the user a validation url with a temporary one time password. On validation the user is forced to choose a new password."} - {/forminput} - </div> - - <div class="row"> - {formlabel label="Validate email address" for="admin_verify_email"} - {forminput} - <input type="checkbox" name="admin_verify_email" id="admin_verify_email" /> - {formhelp note="This feature should be used only when you need the maximum security and should be used with discretion. If a visitor's email server is not responding, they will not be able to register. You also must have a valid sender email to use this feature."} - {/forminput} - </div> - - <div class="row"> - {formlabel label="Don't email imported users" for="admin_noemail_user"} - {forminput} - <input type="checkbox" name="admin_noemail_user" id="admin_noemail_user" /> - {formhelp note="If you for some reason don't want to email imported users the login and password, or validation url."} - {/forminput} - </div> - - <div class="row submit"> - <input type="submit" name="batchimport" value="{tr}Import{/tr}" /> - </div> - {/form} - {/jstab} {/jstabs} </div><!-- end .body --> </div><!-- end .users --> diff --git a/templates/users_import.tpl b/templates/users_import.tpl new file mode 100644 index 0000000..9eee28b --- /dev/null +++ b/templates/users_import.tpl @@ -0,0 +1,89 @@ +{* $Header: /cvsroot/bitweaver/_bit_users/templates/users_import.tpl,v 1.1 2007/11/15 19:27:18 joasch Exp $ *} +{strip} +<div class="floaticon">{bithelp}</div> + +<div class="admin users"> + <div class="header"> + <h1>{tr}Admin users{/tr}</h1> + </div> + + <div class="body"> + {if (($added ne "") || ($discarded ne "")) } + <h2>{tr}Batch Upload Results{/tr}</h2> + {if $added} + {formfeedback success="`$added` Users Added"} + {/if} + + {if $discarded ne '' } + {formfeedback error="`$discarded` Users Rejected"} + <table class="data" style="width:400px"> + <tr class="error"><th>{tr}Row{/tr}</th><th>{tr}Reason{/tr}</th></tr> + {foreach key=row from=$discardlist item=reason} + <tr class="{cycle values="odd,even"}"><td>{$row}</td><td>{$reason}</td></tr> + {/foreach} + </table> + <br /> + {/if} + {/if} + + {jstabs} + {jstab title="Advanced"} + {form legend="Batch user addition" enctype="multipart/form-data"} + <div class="row"> + {formlabel label="Batch upload (CSV file)" for="csvlist"} + {forminput} + <input type="file" name="csvlist" id="csvlist" /> + {formhelp note="You can batch import users by uploading a CSV (comma-separated values) file. The file needs to have the column names in the first line. The column titles need to match with fields in 'users_users' table. Login, password and email are required fields, however if you leave the password field empty a new password will be auto generated. You can also import a MD5 hash as password, like from phpBB2, it need to be put in the 'hash' column. In such case it override other options and it's assumed the user or at least admin knows the password. Currently you can't import custom fields and if a non-existent field is specified, it's ignored."} + {/forminput} + </div> + + <div class="row"> + {formlabel label="Delimiter" for="delimiter"} + {forminput} + <input type="text" size="3" name="delimiter" id="delimiter" value="," /> + {formhelp note="Set the delimiter of the file. You can not use tab as delimiter."} + {/forminput} + </div> + + <div class="row"> + {formlabel label="Overwrite existing users" for="overwrite"} + {forminput} + <input type="checkbox" name="overwrite" id="overwrite" /> + {formhelp note=""} + {/forminput} + </div> + + <div class="row"> + {formlabel label="Validate users by email" for="admin_verify_user"} + {forminput} + <input type="checkbox" name="admin_verify_user" id="admin_verify_user" /> + {formhelp note="This will email the user a validation url with a temporary one time password. On validation the user is forced to choose a new password."} + {/forminput} + </div> + + <div class="row"> + {formlabel label="Validate email address" for="admin_verify_email"} + {forminput} + <input type="checkbox" name="admin_verify_email" id="admin_verify_email" /> + {formhelp note="This feature should be used only when you need the maximum security and should be used with discretion. If a visitor's email server is not responding, they will not be able to register. You also must have a valid sender email to use this feature."} + {/forminput} + </div> + + <div class="row"> + {formlabel label="Don't email imported users" for="admin_noemail_user"} + {forminput} + <input type="checkbox" name="admin_noemail_user" id="admin_noemail_user" /> + {formhelp note="If you for some reason don't want to email imported users the login and password, or validation url."} + {/forminput} + </div> + + <div class="row submit"> + <input type="submit" name="batchimport" value="{tr}Import{/tr}" /> + </div> + {/form} + {/jstab} + {/jstabs} + </div><!-- end .body --> +</div><!-- end .users --> + +{/strip} diff --git a/users_lib.php b/users_lib.php new file mode 100644 index 0000000..533cfef --- /dev/null +++ b/users_lib.php @@ -0,0 +1,34 @@ +<?php + +function users_admin_email_user( &$pParamHash ) { + global $gBitSmarty, $gBitSystem; + + $ret = FALSE; + $siteName = $gBitSystem->getConfig('site_title', $_SERVER['HTTP_HOST'] ); + $gBitSmarty->assign('siteName',$_SERVER["SERVER_NAME"]); + $gBitSmarty->assign('mail_site',$_SERVER["SERVER_NAME"]); + $gBitSmarty->assign('mail_user',$pParamHash['login']); + if( !empty( $_REQUEST['admin_verify_user'] ) && !empty($pParamHash['user_store']['provpass']) ) { + $apass = addslashes(substr(md5($gBitSystem->genPass()),0,25)); + $apass = $pParamHash['user_store']['provpass']; + $machine = httpPrefix().USERS_PKG_URL.'confirm.php'; + // Send the mail + $gBitSmarty->assign('mail_machine',$machine); + $gBitSmarty->assign('mailUserId',$pParamHash['user_store']['user_id']); + $gBitSmarty->assign('mailProvPass',$apass); + $mail_data = $gBitSmarty->fetch('bitpackage:users/admin_validation_mail.tpl'); + mail($pParamHash['email'], $siteName.' - '.tra('Your registration information'),$mail_data,"From: ".$gBitSystem->getConfig('site_sender_email')."\r\nContent-type: text/plain;charset=utf-8\r\n"); + $gBitSmarty->assign('showmsg','n'); + + $ret = array('confirm' => 'Validation email sent to ' . $pParamHash['email'] . '.'); + } elseif( !empty( $pParamHash['password'] ) ) { + // Send the welcome mail + $gBitSmarty->assign( 'mailPassword',$pParamHash['password'] ); + $gBitSmarty->assign( 'mailEmail',$pParamHash['email'] ); + $mail_data = $gBitSmarty->fetch('bitpackage:users/admin_welcome_mail.tpl'); + mail($pParamHash["email"], tra( 'Welcome to' ).' '.$siteName,$mail_data,"From: ".$gBitSystem->getConfig('site_sender_email')."\r\nContent-type: text/plain;charset=utf-8\r\n"); + $ret = array('welcome'=>'Welcome email sent to ' . $pParamHash['email'] . '.'); + } + return $ret; +} +?>
\ No newline at end of file |
