Commit 0e9daf363f5936c7e78c995e37d2c0f9d921de4d

Authored by mukhtar
1 parent a5b4e0ba

changed several functions to use the lookups.inc library


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@305 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/administration/GroupManager.inc
... ... @@ -300,31 +300,10 @@
300 300 {
301 301 global $default;
302 302  
303   - $sql = new Owl_DB;
304   -
305   - // check that group exists if it does'nt return false
306   - $query = "SELECT id FROM $default->owl_groups_table WHERE name = '" . $groupName . "'";
307   - $sql->query($query);
308   - $rows = $sql->num_rows($sql);
309   - // go into record set
310   - $sql->next_record();
  303 + $id = lookupID($default->owl_groups_table, "name", $groupName);
311 304  
312   - // store the id in a variable
313   - $id = $sql->f("id");
314   -
315   - // if no entry..username does not exist
316   - if ($rows == 0)
317   - {
318   - // duplicate username
319   - $default->errorMessage = "GroupManager::The Group " . $groupName . " does not exist<br>";
320   - $default->log->debug($default->errorMessage);
321   - return false;
322   - }
323   - else
324   - {
325   - return $id;
326   - }
327   - }
  305 + return $id;
  306 + }
328 307  
329 308 /*
330 309 * Function getGroupName($groupID)
... ... @@ -341,31 +320,10 @@
341 320 {
342 321 global $default;
343 322  
344   - $sql = new Owl_DB;
345   -
346   -
347   - // check that username exists if it does'nt return false
348   - $query = "SELECT name FROM $default->owl_groups_table WHERE id = '" . $groupID . "'";
349   - $sql->query($query);
350   - $rows = $sql->num_rows($sql);
351   - // go into record set
352   - $sql->next_record();
353   -
354   - // store the id in a variable
355   - $name = $sql->f("name");
  323 + //call lookup function
  324 + $name = lookupField($default->owl_groups_table, "name" , "id", $groupID);
356 325  
357   - // if no entry..group name does'nt exist
358   - if ($rows == 0)
359   - {
360   - // duplicate username
361   - $default->errorMessage = "GroupManager::The group does not exist<br>";
362   - $default->log->debug($default->errorMessage);
363   - return false;
364   - }
365   - else
366   - {
367   - return $name;
368   - }
  326 + return $name;
369 327 }
370 328  
371 329 /*
... ... @@ -381,77 +339,46 @@
381 339 {
382 340 global $default;
383 341 $unitinfo = array();
384   - $sql = new Owl_DB;
385   - //$groupName = new GroupManager;
386 342  
387   -
388   - // check that group exists if it does'nt return false
389   - $query = "SELECT unit_id FROM $default->owl_groups_units_table WHERE group_id = '" . $groupID . "'";
390   - $sql->query($query);
391   - $rows = $sql->num_rows($sql);
  343 + // call lookup functions
  344 + $unitID = lookupField($default->owl_groups_units_table, "unit_id" , "group_id", $groupID);
  345 + $unitName = lookupField($default->owl_units_table, "name" , "id", $unitID);
392 346  
393   - // if no entry..group does not belong to a unit
394   - if ($rows == 0)
395   - {
396   - // duplicate username
397   - $default->errorMessage = "GroupManager::The group does not belong to a unit<br>";
398   - $default->log->debug($default->errorMessage);
399   - return false;
400   - }
401   -
402   -
403   - while($sql->next_record())
404   - {
405   - $unitinfo[1] = array("id" => $sql->f("unit_id"),
406   - "name" => $this->getUnitName($sql->f("unit_id")) // TODO change this to unit obj
407   - );
  347 + $unitinfo[1] = array("id" => $unitID, "name" => $unitName);
408 348  
409   - }
410   -
  349 + // return an array
411 350 return $unitinfo;
  351 +
412 352 }
413 353  
414 354  
415   -
  355 +
416 356 /*
417 357 *
418   - * gets the name of a unit using their username
  358 + * gets the org details of the org a unit belongs to TODO: move into System/Or Management
419 359 *
420   - * @param unitID
421   - * The id of the unit who's name we want
422   - * @return char
423   - * name of unit
  360 + * @param orgID
  361 + * The id of the org who's name we want based on the unit who belongs to it
  362 + * @return array
  363 + * if and name of org
424 364 */
425 365  
426   - function getUnitName($unitID)
  366 + function getOrg($unitID)
427 367 {
428   - global $default;
429   -
430   - $sql = new Owl_DB;
  368 +
  369 + global $default;
  370 + $orginfo = array();
431 371  
432   -
433   - // check that username exists if it does'nt return false
434   - $query = "SELECT name FROM $default->owl_units_table WHERE id = '" . $unitID . "'";
435   - $sql->query($query);
436   - $rows = $sql->num_rows($sql);
437   - // go into record set
438   - $sql->next_record();
  372 + // call lookup functions
  373 + $orgID = lookupField($default->owl_units_table, "organisation_id" , "id", $unitID);
  374 + $orgName = lookupField($default->owl_organisations_table, "name" , "id", $orgID);
439 375  
440   - // store the id in a variable
441   - $name = $sql->f("name");
  376 + $orginfo[1] = array("id" => $orgID, "name" => $orgName);
  377 +
  378 + // return an array
  379 + return $orginfo;
442 380  
443   - // if no entry..unit name does'nt exist
444   - if ($rows == 0)
445   - {
446   - // duplicate username
447   - $default->errorMessage = "GroupManager::The unit does not exist<br>";
448   - $default->log->debug($default->errorMessage);
449   - return false;
450   - }
451   - else
452   - {
453   - return $name;
454   - }
  381 +
455 382 }
456 383  
457 384 }
... ...