Blame Scripts/centos-web/admin/includes/functions/users.php

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