diff --git a/lib/unitmanagement/Unit.inc b/lib/unitmanagement/Unit.inc index 64966ba..77a75fd 100644 --- a/lib/unitmanagement/Unit.inc +++ b/lib/unitmanagement/Unit.inc @@ -132,16 +132,31 @@ class Unit { { global $default, $lang_err_database, $lang_err_object_key; //only delete the object if it exists in the database - if ($this->iId >= 0) - { + + if ($this->iId >= 0) { + //check to see if group is linked to a unit $sql = $default->db; - $result = $sql->query("DELETE FROM $default->owl_units_table WHERE id = $this->iId"); - if ($result) - { - return true; + $query = "SELECT unit_id FROM ". $default->owl_groups_units_table ." WHERE unit_id = '" . $this->iId . "'"; + $sql->query($query); + $rows = $sql->num_rows($sql); + + + + if ($rows > 0){ + // duplicate link exists + $_SESSION["errorMessage"] = "Group::The Group " . $this->sName . " exits!"; + return false; + + }else{ + $sql = $default->db; + $result = $sql->query("DELETE FROM $default->owl_units_table WHERE id = $this->iId"); + if ($result) + { + return true; + } + $_SESSION["errorMessage"] = $lang_err_database; + return false; } - $_SESSION["errorMessage"] = $lang_err_database; - return false; } $_SESSION["errorMessage"] = $lang_err_object_key; return false; @@ -245,5 +260,17 @@ class Unit { } } - +/** +* Static function +* +* Creates a unit object from an array +* +* @param Array Array of parameters. Must match order of parameters in constructor +* +* @return User user object +*/ +function & unitCreateFromArray($aParameters) { + $oUnit = & new Unit($aParameters[0], $aParameters[1], $aParameters[2], $aParameters[3], $aParameters[4], $aParameters[5], $aParameters[6], $aParameters[7], $aParameters[8], $aParameters[9], $aParameters[10]); + return $oUnit; +} ?> diff --git a/lib/unitmanagement/UnitOrganisationLink.inc b/lib/unitmanagement/UnitOrganisationLink.inc index 55b563c..109b95e 100644 --- a/lib/unitmanagement/UnitOrganisationLink.inc +++ b/lib/unitmanagement/UnitOrganisationLink.inc @@ -77,6 +77,8 @@ class UnitOrganisationLink { $this->iUnitID = $iNewValue; } + + /** * Create the current object in the database * @@ -90,7 +92,7 @@ class UnitOrganisationLink { { $sql = $default->db; - $query = "SELECT unit_id and organisation_ID FROM ". $default->owl_units_organisations_link_table ." WHERE unit_id = '" . $this->iUnitID . "' and organisation_id = '". $this->iOrgID ."'"; + $query = "SELECT unit_id and organisation_id FROM ". $default->owl_units_organisations_table ." WHERE unit_id = '" . $this->iUnitID . "' and organisation_id = '". $this->iOrgID ."'"; $sql->query($query); $rows = $sql->num_rows($sql); @@ -102,7 +104,7 @@ class UnitOrganisationLink { } else { - $result = $sql->query("INSERT INTO " . $default->owl_units_organisations_link_table . " (unit_id,organisation_id) VALUES ($this->iUnitID,$this->iOrgID,)"); + $result = $sql->query("INSERT INTO " . $default->owl_units_organisations_table . " (unit_id,organisation_id) VALUES ($this->iUnitID,$this->iOrgID)"); if ($result) { $this->iId = $sql->insert_id(); @@ -127,7 +129,7 @@ class UnitOrganisationLink { //only update if the object has been stored if ($this->iId > 0) { $sql = $default->db; - $result = $sql->query("UPDATE " . $default->owl_units_organisations_link_table . " SET organisation_id = $this->iOrgID, unit_id = $this->iUnitID WHERE id = $this->iId"); + $result = $sql->query("UPDATE " . $default->owl_units_organisations_table . " SET organisation_id = $this->iOrgID, unit_id = $this->iUnitID WHERE id = $this->iId"); if ($result) { return true; } @@ -149,7 +151,7 @@ class UnitOrganisationLink { //only delete the object if it exists in the database if ($this->iId >= 0) { $sql = $default->db; - $result = $sql->query("DELETE FROM $default->owl_units_organisations_link_table WHERE id = $this->iId"); + $result = $sql->query("DELETE FROM $default->owl_units_organisations_table WHERE id = $this->iId"); if ($result) { return true; } @@ -212,5 +214,44 @@ class UnitOrganisationLink { return false; } + /* + * static function + * + * test to see if unit belongs to org + * + * @param false or a value + * + */ + + function unitBelongsToOrg($unitId) + { + global $default; + + $value = lookupField("$default->owl_units_organisations_table", "organisation_id", "unit_id", $unitId ); + + return $value; + + } + + /* + * static function + * + * sets the id of the unitorg using their unit id + * + * @param String + * The unit_ID + * + */ + + function setUnitOrgID($unitId) + { + global $default; + + $id = lookupID($default->owl_units_organisations_table, "unit_id", $unitId); + + $this->iId= $id; + } + + } ?>