Blame Scripts/Php/Webenv/admin/includes/functions/users.php

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