|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
/**
|
|
Alain Reguera Delgado |
8f60cb |
* User related functions
|
|
Alain Reguera Delgado |
8f60cb |
*
|
|
Alain Reguera Delgado |
8f60cb |
*/
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
//---------------------/* Define user's roles */
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function get_user_roles()
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
// First array value ("writer" in this case) define the default value.
|
|
Alain Reguera Delgado |
8f60cb |
$employeetype = array('writer', 'administrator');
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
return $employeetype;
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
//---------------------/* Define user's attributes */
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function get_user_attributes()
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$attributes = array('dn', 'objectclass', 'uid', 'employeetype',
|
|
Alain Reguera Delgado |
8f60cb |
'sn', 'preferredlanguage', 'userpassword',
|
|
Alain Reguera Delgado |
8f60cb |
'displayname', 'mail', 'cn');
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
return $attributes;
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
//---------------------/* Define user's languages */
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function get_user_languages()
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$languages = array('en' => 'English',
|
|
Alain Reguera Delgado |
8f60cb |
'es' => 'Español',
|
|
Alain Reguera Delgado |
8f60cb |
'fr' => 'Français');
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
return $languages;
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
//---------------------/* Determine user's role */
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function is_user( $role )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
if ( $_SESSION['employeetype'] == $role )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
return true;
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
else
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
return false;
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
//---------------------/* User Role-Selector */
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function get_user_roleSelector( $id = '', $entry_value = '' )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$employeetypes = get_user_roles();
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
if ( ! is_int($id) )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html = '<select name="employeetype">';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
else
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html = '<select name="employeetype['. $id . ']">';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
foreach ($employeetypes as $value )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
if ( $entry_value <> '' && $value == $entry_value )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<option selected value="'.$value.'">'.ucfirst(translate($value)).'</option>';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
else
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<option value="'.$value.'">'.ucfirst(translate($value)).'</option>';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '</select>';
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
return $html;
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
//---------------------/* User Attribute-Selector */
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function get_user_attrSelector( $attr = '/(uid|cn|preferredlanguage|employeetype)/' )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
global $ldap;
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
$clean['attrb'] = $ldap->sanitize_filter_attribute();
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
$attributes = get_user_attributes();
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
$html = '<select name="attribute">';
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
foreach ( $attributes as $value )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
if ( preg_match ( $attr, $value ) )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
if ( $clean['attrb'] == $value )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<option selected value="'.$value.'">' . ucfirst(translate($value)) . '</option>';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
else
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<option value="'.$value.'">' . ucfirst(translate($value)) . '</option>';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '</select>';
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
return $html;
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
//---------------------/* User Language-Selector */
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function get_user_langSelector( $id = '', $entry_value = '' )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$languages = get_user_languages();
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
if ( isset($id) && is_int($id) )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html = '<select name="preferredlanguage['. $id . ']">';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
else
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html = '<select name="preferredlanguage">';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
foreach ($languages as $key => $value )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
if ( ( $entry_value <> '' && $key == $entry_value ) || ( $id == '' && $entry_value == '' && $key == LANGUAGE ) )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<option selected value="'.$key.'">'.ucfirst(translate($value)).'</option>';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
else
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<option value="'.$key.'">'.ucfirst(translate($value)).'</option>';
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '</select>';
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
return $html;
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
//-------/* Build useradd's form */
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function show_useradd_form( $entry )
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
$html = '';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<form name="useradd" action="" method="post">';
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '' . ucfirst(translate('uid')) .':';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<input type="text" name="uid" value="' . $entry['uid'] . '" size="30" /> ' . ucfirst(translate('ex')) . '. john@example.com';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '' . ucfirst(translate('password')) . ':';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<input type="password" name="userpassword" value="" size="30" />';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= ''. ucfirst(translate('cn')) . ':';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<input type="text" name="cn" value="' . $entry['cn'] . '" size="30" />';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= ''. ucfirst(translate('displayname')) . ':';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<input type="text" name="displayname" value="' . $entry['displayname'] . '" size="30" />';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= ''. ucfirst(translate('preferredlanguage')) . ':';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '' . get_user_langSelector() . '';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '' . ucfirst(translate('employeetype')) . ':';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= ''. get_user_roleSelector() . '';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '<input type="submit" name="useradd" value="' . ucfirst(translate('add')) . '" />';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '';
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '</form>';
|
|
Alain Reguera Delgado |
8f60cb |
$html .= '';
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
return $html;
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
//-------/* Show useradmin form
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
function show_useradmin_form()
|
|
Alain Reguera Delgado |
8f60cb |
{
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
?>
|