inc/users.inc.php
changeset 190 7a683326ccec
parent 188 4066e4c0de01
child 192 3d18290ac993
equal deleted inserted replaced
189:b918c891f81d 190:7a683326ccec
    52         // Does this user have ueberuser rights?
    52         // Does this user have ueberuser rights?
    53         $query = "SELECT id 
    53         $query = "SELECT id 
    54 			FROM perm_templ_items 
    54 			FROM perm_templ_items 
    55 			WHERE templ_id = " . $db->quote($templ_id) . " 
    55 			WHERE templ_id = " . $db->quote($templ_id) . " 
    56 			AND perm_id = ".$ueberUserId;
    56 			AND perm_id = ".$ueberUserId;
    57         $result = $db->query($query);
    57         $response = $db->query($query);
    58         if ( $result->numRows() > 0 ) {
    58 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
       
    59         if ( $response->numRows() > 0 ) {
    59                 return 1;
    60                 return 1;
    60         }
    61         }
    61 
    62 
    62         // Find the permission ID for the requested permission.
    63         // Find the permission ID for the requested permission.
    63         $query = "SELECT id 
    64         $query = "SELECT id 
    68         // Check if the permission ID is assigned to the template ID. 
    69         // Check if the permission ID is assigned to the template ID. 
    69         $query = "SELECT id 
    70         $query = "SELECT id 
    70 			FROM perm_templ_items 
    71 			FROM perm_templ_items 
    71 			WHERE templ_id = " . $db->quote($templ_id) . " 
    72 			WHERE templ_id = " . $db->quote($templ_id) . " 
    72 			AND perm_id = " . $db->quote($perm_id) ;
    73 			AND perm_id = " . $db->quote($perm_id) ;
    73         $result = $db->query($query);
    74 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
    74         if ( $result->numRows() > 0 ) {
    75         $response = $db->query($query);
       
    76         if ( $response->numRows() > 0 ) {
    75                 return 1;
    77                 return 1;
    76         } else {
    78         } else {
    77                 return 0;
    79                 return 0;
    78         }
    80         }
    79 }
    81 }
   102  */
   104  */
   103 function show_users($id='',$rowstart=0,$rowamount=9999999)
   105 function show_users($id='',$rowstart=0,$rowamount=9999999)
   104 {
   106 {
   105  	global $db;
   107  	global $db;
   106 	$add = '';
   108 	$add = '';
   107  	if(is_numeric($id))
   109  	if(is_numeric($id)) {
   108  	{
       
   109                  //When a user id is given, it is excluded from the userlist returned.
   110                  //When a user id is given, it is excluded from the userlist returned.
   110                  $add = " WHERE users.id!=".$db->quote($id);
   111                  $add = " WHERE users.id!=".$db->quote($id);
   111 	}
   112 	}
   112 
   113 
   113 	// Make a huge query.
   114 	// Make a huge query.
   114 	$sqlq = "SELECT users.id AS id,
   115 	$query = "SELECT users.id AS id,
   115 		users.username AS username,
   116 		users.username AS username,
   116 		users.fullname AS fullname,
   117 		users.fullname AS fullname,
   117 		users.email AS email,
   118 		users.email AS email,
   118 		users.description AS description,
   119 		users.description AS description,
   119 		users.active AS active,
   120 		users.active AS active,
   131 		ORDER BY
   132 		ORDER BY
   132 			users.fullname";
   133 			users.fullname";
   133 
   134 
   134 	// Execute the huge query.
   135 	// Execute the huge query.
   135 	$db->setLimit($rowamount, $rowstart);
   136 	$db->setLimit($rowamount, $rowstart);
   136 	$result = $db->query($sqlq);
   137 	$response = $db->query($query);
       
   138 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   137 	$ret = array();
   139 	$ret = array();
   138 	$retcount = 0;
   140 	$retcount = 0;
   139 	while ($r = $result->fetchRow())
   141 	while ($r = $response->fetchRow()) {
   140 	{
       
   141 		$ret[] = array(
   142 		$ret[] = array(
   142 		 "id"                    =>              $r["id"],
   143 		 "id"                    =>              $r["id"],
   143 		 "username"              =>              $r["username"],
   144 		 "username"              =>              $r["username"],
   144 		 "fullname"              =>              $r["fullname"],
   145 		 "fullname"              =>              $r["fullname"],
   145 		 "email"                 =>              $r["email"],
   146 		 "email"                 =>              $r["email"],
   146 		 "description"           =>              $r["description"],
   147 		 "description"           =>              $r["description"],
   147 //		 "level"                 =>              $r["level"],
       
   148 		 "active"                =>              $r["active"],
   148 		 "active"                =>              $r["active"],
   149 		 "numdomains"            =>              $r["aantal"]
   149 		 "numdomains"            =>              $r["aantal"]
   150 		);
   150 		);
   151 	}
   151 	}
   152 	return $ret;
   152 	return $ret;
   158  * return values: true if user exists, false if users doesnt exist.
   158  * return values: true if user exists, false if users doesnt exist.
   159  */
   159  */
   160  function is_valid_user($id)
   160  function is_valid_user($id)
   161 {
   161 {
   162 	global $db;
   162 	global $db;
   163 	if(is_numeric($id))
   163 	if(is_numeric($id)) {
   164 	{
   164 		$response = $db->query("SELECT id FROM users WHERE id=".$db->quote($id));
   165 		$result = $db->query("SELECT id FROM users WHERE id=".$db->quote($id));
   165 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   166 		if ($result->numRows() == 1)
   166 		if ($response->numRows() == 1) {
   167 		{
       
   168 			return true;
   167 			return true;
   169 		}
   168 		} else {
   170 		else
       
   171 		{
       
   172 			return false;
   169 			return false;
   173 		}
   170 		}
   174 	}
   171 	}
   175 }
   172 }
   176 
   173 
   180  * return values: true if exists, false if not.
   177  * return values: true if exists, false if not.
   181  */
   178  */
   182 function user_exists($user)
   179 function user_exists($user)
   183 {
   180 {
   184 	global $db;
   181 	global $db;
   185 	$result = $db->query("SELECT id FROM users WHERE username=".$db->quote($user));
   182 	$response = $db->query("SELECT id FROM users WHERE username=".$db->quote($user));
   186 	if ($result->numRows() == 0)
   183 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   187 	{
   184 	if ($response->numRows() == 0) {
   188                  return false;
   185                  return false;
   189 	}
   186 	} elseif ($response->numRows() == 1) {
   190 	elseif($result->numRows() == 1)
       
   191 	{
       
   192         	return true;
   187         	return true;
   193 	}
   188 	} else {
   194         else
       
   195         {
       
   196         	error(ERR_UNKNOWN);
   189         	error(ERR_UNKNOWN);
   197 	}
   190 	}
   198 }
   191 }
   199 
   192 
   200 
   193 
   221 				}
   214 				}
   222 			}
   215 			}
   223 		}
   216 		}
   224 
   217 
   225 		$query = "DELETE FROM zones WHERE owner = " . $db->quote($uid) ;
   218 		$query = "DELETE FROM zones WHERE owner = " . $db->quote($uid) ;
   226 		$result = $db->query($query);
   219 		$response = $db->query($query);
   227 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   220 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   228 
   221 
   229 		$query = "DELETE FROM users WHERE id = " . $db->quote($uid) ;
   222 		$query = "DELETE FROM users WHERE id = " . $db->quote($uid) ;
   230 		$result = $db->query($query);
   223 		$response = $db->query($query);
   231 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   224 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   232 	}
   225 	}
   233 	return true;
   226 	return true;
   234 }
   227 }
   235 
   228 
   238 	global $db;
   231 	global $db;
   239 	if (!(verify_permission('user_edit_templ_perm'))) {
   232 	if (!(verify_permission('user_edit_templ_perm'))) {
   240 		error(ERR_PERM_DEL_PERM_TEMPL);
   233 		error(ERR_PERM_DEL_PERM_TEMPL);
   241 	} else {
   234 	} else {
   242 		$query = "SELECT id FROM users WHERE perm_templ = " . $ptid;
   235 		$query = "SELECT id FROM users WHERE perm_templ = " . $ptid;
   243 		$result = $db->query($query);
   236 		$response = $db->query($query);
   244 		if (PEAR::isError($result)) { error($response->getMessage()); return false; }
   237 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   245 
   238 
   246 		if($result->numRows() > 0) {
   239 		if($response->numRows() > 0) {
   247 			error(ERR_PERM_TEMPL_ASSIGNED);
   240 			error(ERR_PERM_TEMPL_ASSIGNED);
   248 			return false;
   241 			return false;
   249 		} else {
   242 		} else {
   250 			$query = "DELETE FROM perm_templ_items WHERE templ_id = " . $ptid;
   243 			$query = "DELETE FROM perm_templ_items WHERE templ_id = " . $ptid;
   251 			$result = $db->query($query);
   244 			$response = $db->query($query);
   252 			if (PEAR::isError($result)) { error($response->getMessage()); return false; }
   245 			if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   253 
   246 
   254 			$query = "DELETE FROM perm_templ WHERE id = " . $ptid;
   247 			$query = "DELETE FROM perm_templ WHERE id = " . $ptid;
   255 			$result = $db->query($query);
   248 			$response = $db->query($query);
   256 			if (PEAR::isError($result)) { error($response->getMessage()); return false; }
   249 			if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   257 
   250 
   258 			return true;
   251 			return true;
   259 		}
   252 		}
   260 	}
   253 	}
   261 }
   254 }
   303 			// Username of user ID in the database is different from the name
   296 			// Username of user ID in the database is different from the name
   304 			// we have been given. User wants a change of username. Now, make
   297 			// we have been given. User wants a change of username. Now, make
   305 			// sure it doesn't already exist.
   298 			// sure it doesn't already exist.
   306 			
   299 			
   307 			$query = "SELECT id FROM users WHERE username = " . $db->quote($user);
   300 			$query = "SELECT id FROM users WHERE username = " . $db->quote($user);
   308 			$result = $db->query($query);
   301 			$response = $db->query($query);
   309 			if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   302 			if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   310 
   303 
   311 			if($result->numRows() > 0) {
   304 			if($response->numRows() > 0) {
   312 				error(ERR_USER_EXIST);
   305 				error(ERR_USER_EXIST);
   313 				return false;
   306 				return false;
   314 			}
   307 			}
   315 		}
   308 		}
   316 
   309 
   353 		error(ERR_USER_MATCH_NEW_PASS);
   346 		error(ERR_USER_MATCH_NEW_PASS);
   354 		return false;
   347 		return false;
   355 	}
   348 	}
   356 
   349 
   357 	$query = "SELECT id, password FROM users WHERE username = " . $db->quote($_SESSION["userlogin"]);
   350 	$query = "SELECT id, password FROM users WHERE username = " . $db->quote($_SESSION["userlogin"]);
   358 	$result = $db->query($query);
   351 	$response = $db->query($query);
   359 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   352 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   360 
   353 
   361 	$rinfo = $result->fetchRow();
   354 	$rinfo = $response->fetchRow();
   362 
   355 
   363 	if(md5($details['currentpass']) == $rinfo['password']) {
   356 	if(md5($details['currentpass']) == $rinfo['password']) {
   364 		$query = "UPDATE users SET password = " . $db->quote(md5($details['newpass'])) . " WHERE id = " . $db->quote($rinfo['id']) ;
   357 		$query = "UPDATE users SET password = " . $db->quote(md5($details['newpass'])) . " WHERE id = " . $db->quote($rinfo['id']) ;
   365 		$result = $db->query($query);
   358 		$response = $db->query($query);
   366 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   359 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   367 
   360 
   368 		logout( _('Password has been changed, please login.')); 
   361 		logout( _('Password has been changed, please login.')); 
   369 	} else {
   362 	} else {
   370 		error(ERR_USER_WRONG_CURRENT_PASS);
   363 		error(ERR_USER_WRONG_CURRENT_PASS);
   378  * return values: gives the fullname from a userid.
   371  * return values: gives the fullname from a userid.
   379  */
   372  */
   380 function get_fullname_from_userid($id) {
   373 function get_fullname_from_userid($id) {
   381 	global $db;
   374 	global $db;
   382 	if (is_numeric($id)) {
   375 	if (is_numeric($id)) {
   383 		$result = $db->query("SELECT fullname FROM users WHERE id=".$db->quote($id));
   376 		$response = $db->query("SELECT fullname FROM users WHERE id=".$db->quote($id));
   384 		$r = $result->fetchRow();
   377 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
       
   378 		$r = $response->fetchRow();
   385 		return $r["fullname"];
   379 		return $r["fullname"];
   386 	} else {
   380 	} else {
   387 		error(ERR_INV_ARG);
   381 		error(ERR_INV_ARG);
   388 		return false;
   382 		return false;
   389 	}
   383 	}
   397 function get_owner_from_id($id)
   391 function get_owner_from_id($id)
   398 {
   392 {
   399 	global $db;
   393 	global $db;
   400 	if (is_numeric($id))
   394 	if (is_numeric($id))
   401 	{
   395 	{
   402 		$result = $db->query("SELECT fullname FROM users WHERE id=".$db->quote($id));
   396 		$response = $db->query("SELECT fullname FROM users WHERE id=".$db->quote($id));
   403 		if ($result->numRows() == 1)
   397 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
       
   398 		if ($response->numRows() == 1)
   404 		{
   399 		{
   405 			$r = $result->fetchRow();
   400 			$r = $response->fetchRow();
   406 			return $r["fullname"];
   401 			return $r["fullname"];
   407 		}
   402 		}
   408 		else
   403 		else
   409 		{
   404 		{
   410 			error(ERR_USER_NOT_EXIST);
   405 			error(ERR_USER_NOT_EXIST);
   419  * @todo also fetch the subowners
   414  * @todo also fetch the subowners
   420  * @param $id integer the id of the domain
   415  * @param $id integer the id of the domain
   421  * @return String the list of owners for this domain
   416  * @return String the list of owners for this domain
   422  */
   417  */
   423 function get_fullnames_owners_from_domainid($id) {
   418 function get_fullnames_owners_from_domainid($id) {
   424       
   419 
   425       global $db;
   420 	global $db;
   426       if (is_numeric($id))
   421 	if (is_numeric($id)) {
   427       {
   422 		$response = $db->query("SELECT users.id, users.fullname FROM users, zones WHERE zones.domain_id=".$db->quote($id)." AND zones.owner=users.id ORDER by fullname");
   428               $result = $db->query("SELECT users.id, users.fullname FROM users, zones WHERE zones.domain_id=".$db->quote($id)." AND zones.owner=users.id ORDER by fullname");
   423 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   429               if ($result->numRows() == 0)
   424 		if ($response->numRows() == 0) {
   430               {
   425 			return "";
   431 		      return "";
   426 		} else {
   432               } 
   427 			$names = array();
   433 	      else 
   428 			while ($r = $response->fetchRow()) {
   434 	      {
   429 				$names[] = $r['fullname'];
   435                       $names = array();
   430 			}
   436                       while ($r = $result->fetchRow()) 
   431 			return implode(', ', $names);
   437 		      {
   432 		}
   438                               $names[] = $r['fullname'];
   433 	}
   439                       }
   434 	error(ERR_INV_ARG);
   440                       return implode(', ', $names);
       
   441               }
       
   442       }
       
   443       error(ERR_INV_ARG);
       
   444 }
   435 }
   445 
   436 
   446 
   437 
   447 
   438 
   448 function verify_user_is_owner_zoneid($zoneid) {
   439 function verify_user_is_owner_zoneid($zoneid) {
   449 	global $db;
   440 	global $db;
   450 
   441 
   451 	$userid=$_SESSION["userid"];
   442 	$userid=$_SESSION["userid"];
   452 
   443 
   453 	if (is_numeric($zoneid)) {
   444 	if (is_numeric($zoneid)) {
   454 		$result = $db->query("SELECT zones.id 
   445 		$response = $db->query("SELECT zones.id 
   455 				FROM zones 
   446 				FROM zones 
   456 				WHERE zones.owner = " . $db->quote($userid) . "
   447 				WHERE zones.owner = " . $db->quote($userid) . "
   457 				AND zones.domain_id = ". $db->quote($zoneid)) ;
   448 				AND zones.domain_id = ". $db->quote($zoneid)) ;
   458 		if ($result->numRows() == 0) {
   449 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
       
   450 		if ($response->numRows() == 0) {
   459 			return "0";
   451 			return "0";
   460 		} else {
   452 		} else {
   461 			return "1";
   453 			return "1";
   462 		}
   454 		}
   463 	}
   455 	}
   561 
   553 
   562 	$query = "SELECT *
   554 	$query = "SELECT *
   563 			FROM perm_templ
   555 			FROM perm_templ
   564 			WHERE perm_templ.id = " . $db->quote($templ_id);
   556 			WHERE perm_templ.id = " . $db->quote($templ_id);
   565 
   557 
   566 	$result = $db->query($query);
   558 	$response = $db->query($query);
   567 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   559 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   568 
   560 
   569 	$details = $result->fetchRow(); 
   561 	$details = $response->fetchRow(); 
   570 	return $details;
   562 	return $details;
   571 }	
   563 }	
   572 
   564 
   573 
   565 
   574 // Get a list of all available permission templates.
   566 // Get a list of all available permission templates.
   575 
   567 
   576 function get_list_permission_templates() {
   568 function get_list_permission_templates() {
   577 	global $db;
   569 	global $db;
   578 
   570 
   579 	$query = "SELECT * FROM perm_templ";
   571 	$query = "SELECT * FROM perm_templ";
   580 	$result = $db->query($query);
   572 	$response = $db->query($query);
   581 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   573 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   582 
   574 
   583 	$perm_templ_list = array();
   575 	$perm_templ_list = array();
   584 	while ($perm_templ = $result->fetchRow()) {
   576 	while ($perm_templ = $response->fetchRow()) {
   585 		$perm_templ_list[] = array(
   577 		$perm_templ_list[] = array(
   586 			"id"	=>	$perm_templ['id'],
   578 			"id"	=>	$perm_templ['id'],
   587 			"name"	=>	$perm_templ['name'],
   579 			"name"	=>	$perm_templ['name'],
   588 			"descr"	=>	$perm_templ['descr']
   580 			"descr"	=>	$perm_templ['descr']
   589 			);
   581 			);
   602 	$query = "INSERT INTO perm_templ (name, descr)
   594 	$query = "INSERT INTO perm_templ (name, descr)
   603 			VALUES (" 
   595 			VALUES (" 
   604 				. $db->quote($details['templ_name']) . ", " 
   596 				. $db->quote($details['templ_name']) . ", " 
   605 				. $db->quote($details['templ_descr']) . ")";
   597 				. $db->quote($details['templ_descr']) . ")";
   606 
   598 
   607 	$result = $db->query($query);
   599 	$response = $db->query($query);
   608 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   600 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   609 
   601 
   610 	$perm_templ_id = $db->lastInsertId('perm_templ', 'id');
   602 	$perm_templ_id = $db->lastInsertId('perm_templ', 'id');
   611 
   603 
   612 	foreach ($details['perm_id'] AS $perm_id) {
   604 	foreach ($details['perm_id'] AS $perm_id) {
   613 		$query = "INSERT INTO perm_templ_items (templ_id, perm_id) VALUES (" . $db->quote($perm_templ_id) . "," . $db->quote($perm_id) . ")";
   605 		$query = "INSERT INTO perm_templ_items (templ_id, perm_id) VALUES (" . $db->quote($perm_templ_id) . "," . $db->quote($perm_id) . ")";
   614 		$result = $db->query($query);
   606 		$response = $db->query($query);
   615 		if (pear::iserror($response)) { error($response->getmessage()); return false; }
   607 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   616 	}
   608 	}
   617 
   609 
   618 	return true;
   610 	return true;
   619 }
   611 }
   620 
   612 
   627 
   619 
   628 	$query = "UPDATE perm_templ 
   620 	$query = "UPDATE perm_templ 
   629 			SET name = " . $db->quote($details['templ_name']) . ",
   621 			SET name = " . $db->quote($details['templ_name']) . ",
   630 			descr = " . $db->quote($details['templ_descr']) . "
   622 			descr = " . $db->quote($details['templ_descr']) . "
   631 			WHERE id = " . $db->quote($details['templ_id']) ;
   623 			WHERE id = " . $db->quote($details['templ_id']) ;
   632 	
   624 	$response = $db->query($query);
   633 	$result = $db->query($query);
       
   634 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   625 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   635 
   626 
   636 	// Now, update list of permissions assigned to this template. We could do 
   627 	// Now, update list of permissions assigned to this template. We could do 
   637 	// this The Correct Way [tm] by comparing the list of permissions that are
   628 	// this The Correct Way [tm] by comparing the list of permissions that are
   638 	// currently assigned with a list of permissions that should be assigned and
   629 	// currently assigned with a list of permissions that should be assigned and
   639 	// apply the difference between these two lists to the database. That sounds 
   630 	// apply the difference between these two lists to the database. That sounds 
   640 	// like to much work. Just delete all the permissions currently assigned to 
   631 	// like too much work. Just delete all the permissions currently assigned to 
   641 	// the template, than assign all the permessions the template should have.
   632 	// the template, than assign all the permessions the template should have.
   642 
   633 
   643 	$query = "DELETE FROM perm_templ_items WHERE templ_id = " . $details['templ_id'] ;
   634 	$query = "DELETE FROM perm_templ_items WHERE templ_id = " . $details['templ_id'] ;
   644 	$result = $db->query($query);
   635 	$response = $db->query($query);
   645 	if (pear::iserror($response)) { error($response->getmessage()); return false; }
   636 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   646 
   637 
   647 	foreach ($details['perm_id'] AS $perm_id) {
   638 	foreach ($details['perm_id'] AS $perm_id) {
   648 		$query = "INSERT INTO perm_templ_items (templ_id, perm_id) VALUES (" . $db->quote($details['templ_id']) . "," . $db->quote($perm_id) . ")";
   639 		$query = "INSERT INTO perm_templ_items (templ_id, perm_id) VALUES (" . $db->quote($details['templ_id']) . "," . $db->quote($perm_id) . ")";
   649 		$result = $db->query($query);
   640 		$response = $db->query($query);
   650 		if (pear::iserror($response)) { error($response->getmessage()); return false; }
   641 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   651 	}
   642 	}
   652 
   643 
   653 	return true;
   644 	return true;
   654 }
   645 }
   655 
   646 
   682 		// First find the current username of the user ID we want to change. If the 
   673 		// First find the current username of the user ID we want to change. If the 
   683 		// current username is not the same as the username that was given by the 
   674 		// current username is not the same as the username that was given by the 
   684 		// user, the username should apparantly changed. If so, check if the "new" 
   675 		// user, the username should apparantly changed. If so, check if the "new" 
   685 		// username already exists.
   676 		// username already exists.
   686 		$query = "SELECT username FROM users WHERE id = " . $db->quote($details['uid']);
   677 		$query = "SELECT username FROM users WHERE id = " . $db->quote($details['uid']);
   687 		$result = $db->query($query);
   678 		$response = $db->query($query);
   688 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   679 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   689 
   680 
   690 		$usercheck = array();
   681 		$usercheck = array();
   691 		$usercheck = $result->fetchRow();
   682 		$usercheck = $response->fetchRow();
   692 
   683 
   693 		if ($usercheck['username'] != $details['username']) {
   684 		if ($usercheck['username'] != $details['username']) {
   694 			// Username of user ID in the database is different from the name
   685 			// Username of user ID in the database is different from the name
   695 			// we have been given. User wants a change of username. Now, make
   686 			// we have been given. User wants a change of username. Now, make
   696 			// sure it doesn't already exist.
   687 			// sure it doesn't already exist.
   697 			$query = "SELECT id FROM users WHERE username = " . $db->quote($details['username']);
   688 			$query = "SELECT id FROM users WHERE username = " . $db->quote($details['username']);
   698 			$result = $db->query($query);
   689 			$response = $db->query($query);
   699 			if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   690 			if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   700 
   691 
   701 			if($result->numRows() > 0) {
   692 			if($response->numRows() > 0) {
   702 				error(ERR_USER_EXIST);
   693 				error(ERR_USER_EXIST);
   703 				return false;
   694 				return false;
   704 			}
   695 			}
   705 		}
   696 		}
   706 
   697 
   724 			$query .= ", password = '" . md5($db->quote($details['password'])) . "' ";
   715 			$query .= ", password = '" . md5($db->quote($details['password'])) . "' ";
   725 		}
   716 		}
   726 
   717 
   727 		$query .= " WHERE id = " . $db->quote($details['uid']) ;
   718 		$query .= " WHERE id = " . $db->quote($details['uid']) ;
   728 
   719 
   729 		$result = $db->query($query);
   720 		$response = $db->query($query);
   730 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   721 		if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   731 
   722 
   732 	} else {
   723 	} else {
   733 		error(ERR_PERM_EDIT_USER);
   724 		error(ERR_PERM_EDIT_USER);
   734 		return false;
   725 		return false;
   764 			. $db->quote($details['descr']) . ", "
   755 			. $db->quote($details['descr']) . ", "
   765 			. $db->quote($details['perm_templ']) . ", "
   756 			. $db->quote($details['perm_templ']) . ", "
   766 			. $db->quote($active) 
   757 			. $db->quote($active) 
   767 			. ")";
   758 			. ")";
   768 
   759 
   769 	$result = $db->query($query);
   760 	$response = $db->query($query);
   770 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   761 	if (PEAR::isError($response)) { error($response->getMessage()); return false; }
   771 	
   762 	
   772 	return true;
   763 	return true;
   773 }
   764 }
   774 
   765