Location: PHPKode > projects > phpMyOrdering > phpMyOrdering-0.1.7-alpha/phpMyPurchasing-0.1.2-alpha/scripts/classes/class.users.php
<?PHP
/*
 * phpMyPurchasing - All rights reserved.
 * Jason Gerfen [hide@address.com]
 *
 * class.users.php - User management libs
 *
 */

class users
{

 function process($token,$get,$post,$server)
 {
  global $errors, $handles, $defined;

  $user_details = $handles['encrypt']->DecodeAuthTokenHeavy($token);
		$user = $user_details[0]; $formData['addAppAdmin'] = $username;
  $group = $user_details[3];

  $post = array_merge($post,$this->GenAllErrors($post));

  $post['importUsers'] = $this->createImportForm($post);
  if(count($post['ldap_users'])>0) {
   $post['lerror'] = '<div class="error">' . $this->import($post,$user,$group) . '</div>';
  }

		if(!empty($post['cmd'])) {
			if((!empty($post['txtUserName']))&&(!empty($post['txtUserLevel']))||($post['txtUserLevel']!=="---------------")&&(!empty($post['txtUserGroup']))||($post['txtUserGroup']!=="---------------")&&(!empty($post['txtUserFname']))&&(!empty($post['txtUserLname']))&&(!empty($post['txtUserEmail']))) {
				if(($handles['val']->ValidateParagraph($post['txtUserName'])!==-1)&&($handles['val']->ValidateParagraph($post['txtUserLevel'])!==-1)&&($handles['val']->ValidateParagraph($post['txtUserGroup'])!==-1)&&($handles['val']->ValidateParagraph($post['txtUserFname'])!==-1)&&($handles['val']->ValidateParagraph($post['txtUserLname'])!==-1)&&($handles['val']->ValidateParagraph($post['txtUserDepartment'])!==-1)&&($handles['val']->ValidatePhone($post['txtUserPhone'])!==-1)&&($handles['val']->ValidateEmail($post['txtUserEmail'])!==-1)) {

 				if($post['cmd']==="addUser") {
      $flag = 'add';
      $sql['main'] = $this->add($token,$order,$post,$user);
					}
 				if($post['cmd']==="editUser") {
      $flag = 'edit';
				  $sql['main'] = $this->edit($post,$user);
 				}
 				if($post['cmd']==="delUser") {
      $flag = 'del';
				  $sql['main'] = $this->delete($post);
      $sql['resource'] = $this->dresource($post);
      $sql['uresource'] = $this->duresource($post);
      //$sql['udelete'] = $this->udelete($post);
      //$sql['uresourced'] = $this->udelete($post);
 				}

     if($post['cmd']!=="delUser") {
      $sql['resource'] = $this->resource($user,$post);
      $sql['gresource'] = $this->gresource($group,$post);
      $sql['uresource'] = $this->uresource($user,$post);
     }

     $result = $this->execute($sql);
     if($result==='-1'){
      $x = $defined['error']; $class = "error";
      $message = "A database error occured when saving changes to '$post[txtUserName]'";
     } else {
      $x = $defined['good']; $class = "good";
      $message = "Changes to '$post[txtUserName]' were successful. $result changes were made.";
     }

     $post['error'] = '<div class="' . $class . '">' . $handles['err']->GenerateErrorImg( $x, "help/help.html", NULL, '800', '800' ) . '&nbsp;' . $message . '</div>';

				} else {
					$erlink = $handles['err']->GenerateErrorImg( $defined['error'], "help/help.html", "", '800', '800' );
     $list = "<ul>";
     if($handles['val']->ValidateParagraph($post['txtUserName'])===-1){ $list .= "<li>User name is invalid. Allowed: [ -?!#$&+0-9=?A-Z^_.,]</li>"; $post['txtUserNameErr'] = $erlink; }
					if($handles['val']->ValidateParagraph($post['txtUserLevel'])===-1){ $list .= "<li>Access level is invalid. Allowed: [ -?!#$&+0-9=?A-Z^_.,]</li>"; $post['txtUserLevelErr'] = $erlink; }
     if($handles['val']->ValidateParagraph($post['txtUserGroup'])===-1){ $list .= "<li>Group assignment is invalid. Allowed: [ -?!#$&+0-9=?A-Z^_.,]</li>"; $post['txtUserGroupErr'] = $erlink; }
     if($handles['val']->ValidateParagraph($post['txtUserFname'])===-1){ $list .= "<li>First name is invalid. Allowed: [ -?!#$&+0-9=?A-Z^_.,]</li>"; $post['txtUserFnameErr'] = $erlink; }
     if($handles['val']->ValidateParagraph($post['txtUserLname'])===-1){ $list .= "<li>Last name is invalid. Allowed: [ -?!#$&+0-9=?A-Z^_.,]</li>"; $post['txtUserLnameErr'] = $erlink; }
     if($handles['val']->ValidateParagraph($post['txtUserDepartment'])===-1){ $list .= "<li>Department is invalid. Allowed: [ -?!#$&+0-9=?A-Z^_.,]</li>"; $post['txtUserDepartmentErr'] = $erlink; }
					if($handles['val']->ValidatePhone($post['txtUserPhone'])===-1){ $list .= "<li>User phone is invalid. Allowed: [xxx-xxx-xxxx]</li>"; $post['txtUserPhoneErr'] = $erlink; }
					if($handles['val']->ValidateEmail($post['txtUserEmail'])===-1){ $list .= "<li>Email address is invalid. Allowed: [_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,5})</li>"; $post['txtUserEmailErr'] = $erlink; }
					$list .= "</ul>";
					$post['error'] = '<div class="error">' . $list . '</div>';
				}
			} else {
				$erlink = $handles['err']->GenerateErrorImg( $defined['error'], "help/help.html", "", '800', '800' );
    $list = "<ul>";
				if(empty($post['txtUserName'])){ $list .= "<li>User name is missing</li>"; $post['txtUserNameErr'] = $erlink; }
				if((empty($post['txtUserLevel']))||($post['txtUserLevel']==="---------------")){ $list .= "<li>Access level is missing</li>"; $post['txtUserLevelErr'] = $erlink; }
				if((empty($post['txtUserGroup']))||($post['txtUserGroup']==="---------------")){ $list .= "<li>Group assignment is missing</li>"; $post['txtUserGroupErr'] = $erlink; }
    if(empty($post['txtUserFname'])){ $list .= "<li>First name is missing</li>"; $post['txtUserFnameErr'] = $erlink; }
    if(empty($post['txtUserLname'])){ $list .= "<li>Last name is missing</li>"; $post['txtUserLnameErr'] = $erlink; }
    if(empty($post['txtUserEmail'])){ $list .= "<li>Email is missing</li>"; $post['txtUserEmailErr'] = $erlink; }
				$list .= "</ul>";
				$post['error'] = '<div class="error">' . $list . '</div>';
			}
		} else {
   $post = array_merge($post, $this->GenAllValues());
  }

  if(function_exists("json_encode")) {
   $jsonUsers = json_encode(array_map($handles['val']->ValidateXSS,$this->getUserInfo($token)));
  } else {
   $jsonUsers = $handles['misc']->arr2json(array_map($handles['val']->ValidateXSS,$this->getUserInfo($token)));
  }
  $post['jsonUsers'] = 'var users = ' . $jsonUsers . ';';

  $post['txtUserLevel'] = $handles['level']->GenDropMenuWSelectedLevels($this->getLevels(),$post['txtUserLevel'],'txtUserLevel');
  $post['txtUserGroup'] = $handles['groups']->GenDropMenuWSelectedGroups($handles['groups']->getGroupInfo($token),$post['txtUserGroup'],'txtUserGroup');
  $post['txtUserDepartment'] = $this->GenDropMenuWSelectedDepartments($this->getDepartments(),$post['txtUserDepartment'],'txtUserDepartment');

  return $post;
 }

 function genAllValues()
 {
  $post['txtUserName'] = '';
  $post['txtUserLevel'] = '';
  $post['txtUserGroup'] = '';
  $post['txtUserFname'] = '';
  $post['txtUserLname'] = '';
  $post['txtUserDepartment'] = '';
  $post['txtUserPhone'] = '';
  $post['txtUserEmail'] = '';
  return $post;
 }

 function genAllErrors($post)
 {
  $post['error'] = '';
  $post['lerror'] = '';
  $post['txtUserNameErr'] = '*';
  $post['txtUserLevelErr'] = '*';
  $post['txtUserGroupErr'] = '*';
  $post['txtUserFnameErr'] = '*';
  $post['txtUserLnameErr'] = '*';
  $post['txtUserDepartmentErr'] = '';
  $post['txtUserPhoneErr'] = '';
  $post['txtUserEmailErr'] = '*';
  return $post;
 }

 function getUserInfo($token)
	{
		global $defined, $handles;

  $details = $handles['encrypt']->DecodeAuthTokenHeavy($token);
  $dbconn = $handles['db']->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
  $sql = "SELECT `txtUserName`,`txtUserLevel`,`txtUserGroup`,`txtUserDepartment`,`txtUserFname`,`txtUserLname`,`txtUserPhone`,`txtUserEmail` FROM `users`";
		if(($value = $handles['db']->dbQuery($handles['val']->ValidateSQL($sql, $dbconn), $dbconn))!==-1) {
   if($handles['db']->dbNumRows($value)>0) {
				$data = $handles['db']->dbArrayResultsAssoc($value);
			}
		}
		$handles['misc']->CleanUpVars($details, NULL);
  $handles['db']->dbFixTable("groups", $dbconn);
  $handles['db']->dbFreeData($dbconn);
  $handles['db']->dbCloseConn($dbconn);
  return $data;
	}

 function getGroupUsers($group)
	{
		global $defined,$handles;

  $dbconn = $handles['db']->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
  $sql = "SELECT * FROM `users` WHERE `group` = \"" . $group . "\"";
		if(($value = $handles['db']->dbQuery($handles['val']->ValidateSQL($sql, $dbconn), $dbconn))!==-1) {
   if($handles['db']->dbNumRows($value)>0) {
				$data = $handles['db']->dbArrayResultsAssoc($value);
			}
		}
		$handles['misc']->CleanUpVars($details, NULL);
  $handles['db']->dbFixTable("groups", $dbconn);
  $handles['db']->dbFreeData($dbconn);
  $handles['db']->dbCloseConn($dbconn);
  return $data;
	}

 function getLevels()
 {
  global $defined,$handles;
  $dbconn = $handles['db']->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
  $lvl = "SELECT `level` FROM `levels` ORDER BY `level` ASC";
		if(($return = $handles['db']->dbQuery($handles['val']->ValidateSQL($lvl,$dbconn),$dbconn))!==-1) {
   if($handles['db']->dbNumRows($return)>0) {
  	 $data = $handles['db']->dbArrayResultsAssoc($return);
   }
		}
  $handles['db']->dbFixTable("levels", $dbconn);
  $handles['db']->dbFreeData($dbconn);
  $handles['db']->dbCloseConn($dbconn);
  return $data;
 }

 function getDepartments()
 {
  global $defined,$handles;
  $dbconn = $handles['db']->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
  $lvl = "SELECT * FROM `departments` ORDER BY `level` ASC";
		if(($return = $handles['db']->dbQuery($handles['val']->ValidateSQL($lvl,$dbconn),$dbconn))!==-1) {
   if($handles['db']->dbNumRows($return)>0) {
  	 $data = $handles['db']->dbArrayResultsAssoc($return);
   }
		}
  $handles['db']->dbFixTable("levels", $dbconn);
  $handles['db']->dbFreeData($dbconn);
  $handles['db']->dbCloseConn($dbconn);
  return $data;
 }

 function add($token,$order,$post,$user)
 {
  return "INSERT INTO `users` (`txtUserName`,`txtUserLevel`,`txtUserGroup`,`txtUserFname`,`txtUserLname`,`txtUserDepartment`,`txtUserPhone`,`txtUserEmail`,`create_date`,`create_time`,`reset`,`owner`) VALUES (\"" . $post['txtUserName'] . "\",\"" . $post['txtUserLevel'] . "\",\"" . $post['txtUserGroup'] . "\",\"" . $post['txtUserFname'] . "\",\"" . $post['txtUserLname'] . "\",\"" . $post['txtUserDepartment'] . "\",\"" . $post['txtUserPhone'] . "\",\"" . $post['txtUserEmail'] . "\",\"" . $create_date . "\",\"" . $create_time . "\",\"TRUE\",\"" . $user . "\") ON DUPLICATE KEY UPDATE `txtUserName` = \"" . $post['txtUserName'] . "\",`txtUserLevel` = \"" . $post['txtUserLevel'] . "\",`txtUserGroup` = \"" . $post['txtUserGroup'] . "\",`txtUserFname` = \"" . $post['txtUserFname'] . "\",`txtUserLname` = \"" . $post['txtUserLname'] . "\",`txtUserDepartment` = \"" . $post['txtUserDepartment'] . "\",`txtUserPhone` = \"" . $post['txtUserPhone'] . "\",`txtUserEmail` = \"" . $post['txtUserEmail'] . "\"";
 }

 function edit($post,$user)
 {
  return "UPDATE `users` SET `txtUserName` = \"" . $post['txtUserName'] . "\",`txtUserLevel` = \"" . $post['txtUserLevel'] . "\",`txtUserGroup` = \"" . $post['txtUserGroup'] . "\",`txtUserFname` = \"" . $post['txtUserFname'] . "\",`txtUserLname` = \"" . $post['txtUserLname'] . "\",`txtUserDepartment` = \"" . $post['txtUserDepartment'] . "\",`txtUserPhone` = \"" . $post['txtUserPhone'] . "\",`txtUserEmail` = \"" . $post['txtUserEmail'] . "\" WHERE `txtUserName` = \"" . $post['txtUserName'] . "\" LIMIT 1";
 }
 
 function delete($post)
 {
  return "DELETE FROM `users` WHERE `txtUserName` = \"" . $post['txtUserName'] . "\" LIMIT 1";
 }

 function uresourced($post)
 {
  return "DELETE FROM `uresources` WHERE `user` = \"" . $post['txtUserName'] . "\" LIMIT 1";
 }

 function resource($user,$post)
 {
  return "INSERT INTO `resources` (`resource`,`common-name`,`owner`) VALUES (\"" . md5($post['txtUserName']) . "\", \"" . $post['txtUserName'] . "\", \"" . $user . "\") ON DUPLICATE KEY UPDATE `resource` = \"" . md5($post['txtUserName']) . "\",`common-name` = \"" . $post['txtUserName'] . "\"";
 }
 
 function gresource($group,$post)
 {
  return "INSERT INTO `gresources` (`resource`,`group`,`read`,`write`) VALUES (\"" . md5($post['txtUserName']) . "\", \"" . $group . "\", \"1\", \"1\") ON DUPLICATE KEY UPDATE `resource` = \"" . md5($post['txtUserName']) . "\",`group` = \"" . $group . "\",`read` = \"1\", `write` = \"1\"";
 }

 function uresource($user,$post)
 {
  return "INSERT INTO `uresources` (`resource`,`user`,`read`,`write`) VALUES (\"" . md5($post['txtUserName']) . "\", \"" . $user . "\", \"1\", \"1\") ON DUPLICATE KEY UPDATE `resource` = \"" . md5($post['txtUserName']) . "\",`user` = \"" . $user . "\",`read` = \"1\", `write` = \"1\"";
 }

 function dresource($post)
 {
  return "DELETE FROM `resources` WHERE `resource` = \"" . md5($post['txtUserName']) . "\" LIMIT 1";
 }
 
 function duresource($user)
 {
  return "DELETE FROM `uresources` WHERE `resource` = \"" . md5($post['txtUserName']) . "\"";
 }

 function dresourcebyname($user)
 {
  return "DELETE FROM `resources` WHERE `common-name` = \"" . $post['txtUserName'] . "\"";
 }

 function execute($sql)
 {
  global $defined, $handles;
  if(count($sql)>0) {
   $dbconn = $handles['db']->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
   foreach($sql as $key => $value) {
    if(($res = $handles['db']->dbQuery($handles['val']->ValidateSQL($value, $dbconn), $dbconn))!==-1) {
     if(($a=$handles['db']->dbNumRowsAffected($dbconn))>0) {
      $a++;
      $return = $a;
			  }
		  } else {
     $return = '-1';
    }
   }
   $handles['db']->dbFixTable("users", $dbconn);
   $handles['db']->dbFixTable("resources", $dbconn);
   $handles['db']->dbFixTable("gresources", $dbconn);
   $handles['db']->dbFixTable("uresources", $dbconn);
   $handles['db']->dbFreeData($dbconn);
   $handles['db']->dbCloseConn($dbconn);
  }
  return $return;
 }

 function createImportForm($post)
 {
  global $defined, $handles;
		if( ( !empty( $defined['ldapuser'] ) ) && ( !empty( $defined['ldappass'] ) ) && ( !empty( $defined['ldapdomain'] ) ) && ( !empty( $defined['ldapserv'] ) ) && ( !empty( $defined['ldapport'] ) ) && ( !empty( $defined['binddn'] ) ) && ( !empty( $defined['basedn'] ) ) ) {
			if( ( $ldapConn = $handles['ldap']->connect( $defined['ldapserv'], $defined['ldapport'] ) ) === -1 ) {
				$importLDAPUsers = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_connect", $defined['error'], $errors['ldap_connect_err'], '800', '800' );
			} else {
				if( ( $ldapBind = $handles['ldap']->bind( $ldapConn, $defined['ldapuser'] . "@" . $defined['ldapdomain'], $defined['ldappass'] ) ) === 0 ) {
					$ldap_data = $handles['ldap']->queryUsers( $ldapConn, $defined['basedn'] );
 				$ldap_data = $handles['ldap']->getEntries( $ldapConn, $ldap_data );
 				$ldap_data = $handles['ldap']->filterGroupsResults( $ldap_data );
					if( count( $ldap_data ) > 0 ) {
						$importLDAPUsers = $handles['users']->CreateSelectBoxUsers( $ldap_data );
					} else {
						$importLDAPUsers = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_connect", $defined['error'], $errors['ldap_connect_err'], '800', '800' );
					}
				} else {
					$importLDAPUsers = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_connect", $defined['error'], $errors['ldap_connect_err'], '800', '800' );
				}
			}
  } else {
   $importLDAPUsers = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_options", $defined['error'], $errors['ldap_options_err'] . " I am not configured to utilize OpenLDAP/Active Directory functionality. Please configure an optional authentication source under the configuration menu.", '600', '600' );
  }
  return $importLDAPUsers;
 }

 function import($post,$user,$group)
 {
  global $defined, $handles;
  if( !empty( $post['ldap_users'] ) ) {
			if( count( $post['ldap_users'] ) > 0 ) {
    $dbconn = $handles['db']->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
				foreach( $post['ldap_users'] as $key => $value ) {
	    if( ( !empty( $defined['ldapuser'] ) ) && ( !empty( $defined['ldappass'] ) ) && ( !empty( $defined['ldapdomain'] ) ) && ( !empty( $defined['ldapserv'] ) ) && ( !empty( $defined['ldapport'] ) ) && ( !empty( $defined['binddn'] ) ) && ( !empty( $defined['basedn'] ) ) ) {
		    if( ( $ldapConn = $handles['ldap']->connect( $defined['ldapserv'], $defined['ldapport'] ) ) === -1 ) {
			    $message = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_connect", $defined['error'], $errors['ldap_connect_err'] . $list, '600', '600' );
		    } else {
			    if( ( $ldapBind = $handles['ldap']->bind( $ldapConn, $defined['ldapuser'] . "@" . $defined['ldapdomain'], $defined['ldappass'] ) ) === 0 ) {
				    $ldap_data = $handles['ldap']->queryObject( $ldapConn, $defined['basedn'], $value );
				    $ldap_data = $handles['ldap']->getEntries( $ldapConn, $ldap_data );
				    $ldap_data = $handles['ldap']->filterUserResults( $ldap_data );
				    if( count( $ldap_data ) > 0 ) {
					    $list = "<ol>";
									foreach( $ldap_data as $obj => $data ) {
          foreach($ldap_data[$obj]['groups'] as $i => $v) {
           $lgroups = preg_split('/,/i',$v);
           $lgroups = preg_split('/=/',$lgroups[0]);
           foreach($handles['groups']->getGroupInfo($_SESSION['token']) as $x => $y) {
            if(in_array($lgroups[1],$y)) {
             $lgroup = $lgroups[1];
            }
           }
          }
										if( !empty( $data['username'] ) ) {
											$sql_usr = "INSERT INTO `users` ( `txtUserName`, `txtUserLevel`, `txtUserGroup`, `create_date`, `create_time`, `reset`, `owner` ) VALUES ( \"" . $data['username'] . "\", \"user\", \"" . $lgroup . "\", \"" . $data['create_date'] . "\", \"" . $data['create_time'] . "\", \"FALSE\", \"" . $user . "\" ) ON DUPLICATE KEY UPDATE `txtUserName` = \"" . $data['username'] . "\", `txtUserLevel` = \"user\", `txtUserGroup` = \"" . $lgroup . "\"";
           $count = $count + $handles['db']->dbNumRowsAffected( $dbconn );
           if( ( $sql_res = $handles['db']->dbQuery( $handles['val']->ValidateSQL( $sql_usr, $dbconn ), $dbconn ) ) === -1 ) {
												$err_chk = 1;
												$list .= "<li>Error importing '" . $data['username'] . "'</li>";
											} else {
            $err_chk = 0;
            $res_usr['resource'] = "INSERT INTO `resources` (`resource`,`common-name`,`owner`) VALUES (\"" . md5($data['username']) . "\", \"" . $data['username'] . "\", \"" . $user . "\") ON DUPLICATE KEY UPDATE `resource` = \"" . md5($data['username']) . "\",`common-name` = \"" . $data['username'] . "\"";
            $res_usr['gresource'] = "INSERT INTO `gresources` (`resource`,`group`,`read`,`write`) VALUES (\"" . md5($data['username']) . "\", \"" . $group . "\", \"1\", \"1\") ON DUPLICATE KEY UPDATE `resource` = \"" . md5($data['username']) . "\",`group` = \"" . $group . "\",`read` = \"1\", `write` = \"1\"";
            $res_usr['uresource'] = "INSERT INTO `uresources` (`resource`,`user`,`read`,`write`) VALUES (\"" . md5($data['username']) . "\", \"" . $user . "\", \"1\", \"1\") ON DUPLICATE KEY UPDATE `resource` = \"" . md5($data['username']) . "\",`user` = \"" . $user . "\",`read` = \"1\", `write` = \"1\"";
            foreach($res_usr as $k => $v){
             if( ( $sql_res = $handles['db']->dbQuery( $handles['val']->ValidateSQL( $v, $dbconn ), $dbconn ) ) === -1 ) {
												  $err_chk = 1;
												  $list .= "<li>Error while setting permission objects for '" . $data[$val]['username'] . "'</li>";
											  } else {
              $err_chk = 0;
              $perm_count = $perm_count + $handles['db']->dbNumRowsAffected( $dbconn );
             }
            }
            $count = $count + $handles['db']->dbNumRowsAffected( $dbconn );
           }
										}
									}
									$list .= "</ol>";
         if( $err_chk === 1 ) {
										$message = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_groups", $defined['error'], "There was an error during importing of Active Directory/OpenLDAP groups" . $list, '600', '600' );
									} else {
          $message = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_groups", $defined['good'], "The importing of " . $count . " user(s) was completed and " . $perm_count . " corresponding permission objects were created", '600', '600' );
         }
				    } else {
					    $message = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_connect", $defined['error'], $errors['ldap_connect_err'], '600', '600' );
				    }
			    } else {
 			    $message = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_connect", $defined['error'], $errors['ldap_connect_err'], '600', '600' );
			    }
		    }
	    } else {
		    $message = $handles['err']->GenerateErrorLink( "help/help.php", "#ldap_options", $defined['error'], $errors['ldap_options_err'], '600', '600' );
	    }
				}
   }
		}
  $handles['db']->dbFixTable("users", $dbconn);
  $handles['db']->dbFixTable("resources", $dbconn);
  $handles['db']->dbFixTable("gresources", $dbconn);
  $handles['db']->dbFixTable("uresources", $dbconn);
  $handles['db']->dbFreeData($dbconn);
  $handles['db']->dbCloseConn($dbconn);
  return $message;
 }

 function CreateSelectBoxUsers( $users )
 {
  global $handles;

  if( count( $users ) > 0 ) {
   sort($users);
   $html = "<table>";
   $html .= "<tr><td>";
   $html .= "<SELECT name=\"ldap_users[]\" size=\"15\" style=\"width: 600px;\" multiple>";
   foreach( $users as $key => $value ) {
    $value['description'] = $handles['misc']->TrimString( $value['description'], 50 );
    $html .= "<option value=\"" . $value['username'] . "\">" . $handles['misc']->TrimString( $value['username'], 30 ) . " :: " . $value['description'] . "</option>";
   }
   $html .= "</SELECT></td></tr><tr><td align=center><input type=\"submit\" name=\"addLdapUsers\" value=\"Import Users?\"></td></tr></table>";
  }
  return $html;
 }

 function CreateSelectBoxGroups( $groups )
 {
  if( count( $groups ) > 0 ) {
   asort($groups);
   $html .= "<table>";
   $html .= "<tr><td colspan=2><SELECT name=\"ldap_groups[]\" size=\"15\" style=\"width: 600px;\" multiple>";
   foreach( $groups as $key => $value ) {
    $html .= "<option value=\"" . $value['username'] . "\">" . $value['username'] . "</option>";
   }
   $html .= "</SELECT></td></tr>";
   $html .= "<tr><td width=150><b>Add group members?</b></td><td><input type=\"checkbox\" name=\"add_ldap_users\" value=\"1\"></td></tr>";
  }
  return $html;
 }

 function GenDropMenuWSelectedDepartments( $array, $selected, $name )
 {
  global $handles;

  if( count( $array[0] ) > 0 ) {
   $list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
   if( !empty( $selected ) ) {
    $list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
   }
   $list .= "<option>---------------</option>";
   foreach( $array as $key => $value ) {
    $value['group'] = $handles['misc']->TrimString( $value['group'], 60 );
    $list .= "<option value=\"" . $value['group'] . "\">" . $value['group'] . "</option>";
   }
   $list .= "</select>";
  } else {
   $list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
   $list .= "<option value=\"---------------\">No departments defined (Please add a department first)</option>";
   $list .= "</select>";
  }
  return $list;
 }

 function GenDropMenuWSelectedGroups( $array, $selected, $name )
 {
  global $handles;

  if( count( $array[0] ) !== 0 ) {
   $list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
   if( !empty( $selected ) ) {
    $list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
   }
   $list .= "<option>---------------</option>";
   foreach( $array as $key => $value ) {
    $value['group'] = $handles['misc']->TrimString( $value['group'], 60 );
    $list .= "<option value=\"" . $value['group'] . "\">" . $value['group'] . "</option>";
   }
   $list .= "</select>";
  } else {
   $list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
   $list .= "<option value=\"---------------\">No groups defined (Please add a group first)</option>";
   $list .= "</select>";
  }
  return $list;
 }

	function GenJumpMenuBoxGROUPS( $array, $name, $skin )
 {
  global $handles;
  $frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\" style=\"width: 100%\">";
  if( count( $array ) < 1 ) {
   $frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No Groups Defined</option>";
  } else {
   foreach( $array as $key => $value ) {
    $value['group'] = $handles['misc']->TrimString( $value['group'], 60 );
    $value['description'] = $handles['misc']->TrimString( $value['description'], 35 );
    $frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['group'] . " :: " . $value['description'] . "</option>";
   }
  }
  $frm .= "</select>";
  $data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
            <tr>
             <td valign=\"top\">$frm</td>
            <tr>
           </table>";
  return $data;
 }

}

?>
Return current item: phpMyOrdering