Commit 7e37152fd9c6794216c945052f70cdcce209280f
1 parent
15ffa551
changed a number of functions for unitmanagement
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1005 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
81 additions
and
13 deletions
lib/unitmanagement/Unit.inc
| @@ -132,16 +132,31 @@ class Unit { | @@ -132,16 +132,31 @@ class Unit { | ||
| 132 | { | 132 | { |
| 133 | global $default, $lang_err_database, $lang_err_object_key; | 133 | global $default, $lang_err_database, $lang_err_object_key; |
| 134 | //only delete the object if it exists in the database | 134 | //only delete the object if it exists in the database |
| 135 | - if ($this->iId >= 0) | ||
| 136 | - { | 135 | + |
| 136 | + if ($this->iId >= 0) { | ||
| 137 | + //check to see if group is linked to a unit | ||
| 137 | $sql = $default->db; | 138 | $sql = $default->db; |
| 138 | - $result = $sql->query("DELETE FROM $default->owl_units_table WHERE id = $this->iId"); | ||
| 139 | - if ($result) | ||
| 140 | - { | ||
| 141 | - return true; | 139 | + $query = "SELECT unit_id FROM ". $default->owl_groups_units_table ." WHERE unit_id = '" . $this->iId . "'"; |
| 140 | + $sql->query($query); | ||
| 141 | + $rows = $sql->num_rows($sql); | ||
| 142 | + | ||
| 143 | + | ||
| 144 | + | ||
| 145 | + if ($rows > 0){ | ||
| 146 | + // duplicate link exists | ||
| 147 | + $_SESSION["errorMessage"] = "Group::The Group " . $this->sName . " exits!"; | ||
| 148 | + return false; | ||
| 149 | + | ||
| 150 | + }else{ | ||
| 151 | + $sql = $default->db; | ||
| 152 | + $result = $sql->query("DELETE FROM $default->owl_units_table WHERE id = $this->iId"); | ||
| 153 | + if ($result) | ||
| 154 | + { | ||
| 155 | + return true; | ||
| 156 | + } | ||
| 157 | + $_SESSION["errorMessage"] = $lang_err_database; | ||
| 158 | + return false; | ||
| 142 | } | 159 | } |
| 143 | - $_SESSION["errorMessage"] = $lang_err_database; | ||
| 144 | - return false; | ||
| 145 | } | 160 | } |
| 146 | $_SESSION["errorMessage"] = $lang_err_object_key; | 161 | $_SESSION["errorMessage"] = $lang_err_object_key; |
| 147 | return false; | 162 | return false; |
| @@ -245,5 +260,17 @@ class Unit { | @@ -245,5 +260,17 @@ class Unit { | ||
| 245 | } | 260 | } |
| 246 | 261 | ||
| 247 | } | 262 | } |
| 248 | - | 263 | +/** |
| 264 | +* Static function | ||
| 265 | +* | ||
| 266 | +* Creates a unit object from an array | ||
| 267 | +* | ||
| 268 | +* @param Array Array of parameters. Must match order of parameters in constructor | ||
| 269 | +* | ||
| 270 | +* @return User user object | ||
| 271 | +*/ | ||
| 272 | +function & unitCreateFromArray($aParameters) { | ||
| 273 | + $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]); | ||
| 274 | + return $oUnit; | ||
| 275 | +} | ||
| 249 | ?> | 276 | ?> |
lib/unitmanagement/UnitOrganisationLink.inc
| @@ -77,6 +77,8 @@ class UnitOrganisationLink { | @@ -77,6 +77,8 @@ class UnitOrganisationLink { | ||
| 77 | $this->iUnitID = $iNewValue; | 77 | $this->iUnitID = $iNewValue; |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | + | ||
| 81 | + | ||
| 80 | /** | 82 | /** |
| 81 | * Create the current object in the database | 83 | * Create the current object in the database |
| 82 | * | 84 | * |
| @@ -90,7 +92,7 @@ class UnitOrganisationLink { | @@ -90,7 +92,7 @@ class UnitOrganisationLink { | ||
| 90 | { | 92 | { |
| 91 | 93 | ||
| 92 | $sql = $default->db; | 94 | $sql = $default->db; |
| 93 | - $query = "SELECT unit_id and organisation_ID FROM ". $default->owl_units_organisations_link_table ." WHERE unit_id = '" . $this->iUnitID . "' and organisation_id = '". $this->iOrgID ."'"; | 95 | + $query = "SELECT unit_id and organisation_id FROM ". $default->owl_units_organisations_table ." WHERE unit_id = '" . $this->iUnitID . "' and organisation_id = '". $this->iOrgID ."'"; |
| 94 | $sql->query($query); | 96 | $sql->query($query); |
| 95 | $rows = $sql->num_rows($sql); | 97 | $rows = $sql->num_rows($sql); |
| 96 | 98 | ||
| @@ -102,7 +104,7 @@ class UnitOrganisationLink { | @@ -102,7 +104,7 @@ class UnitOrganisationLink { | ||
| 102 | } | 104 | } |
| 103 | else | 105 | else |
| 104 | { | 106 | { |
| 105 | - $result = $sql->query("INSERT INTO " . $default->owl_units_organisations_link_table . " (unit_id,organisation_id) VALUES ($this->iUnitID,$this->iOrgID,)"); | 107 | + $result = $sql->query("INSERT INTO " . $default->owl_units_organisations_table . " (unit_id,organisation_id) VALUES ($this->iUnitID,$this->iOrgID)"); |
| 106 | if ($result) | 108 | if ($result) |
| 107 | { | 109 | { |
| 108 | $this->iId = $sql->insert_id(); | 110 | $this->iId = $sql->insert_id(); |
| @@ -127,7 +129,7 @@ class UnitOrganisationLink { | @@ -127,7 +129,7 @@ class UnitOrganisationLink { | ||
| 127 | //only update if the object has been stored | 129 | //only update if the object has been stored |
| 128 | if ($this->iId > 0) { | 130 | if ($this->iId > 0) { |
| 129 | $sql = $default->db; | 131 | $sql = $default->db; |
| 130 | - $result = $sql->query("UPDATE " . $default->owl_units_organisations_link_table . " SET organisation_id = $this->iOrgID, unit_id = $this->iUnitID WHERE id = $this->iId"); | 132 | + $result = $sql->query("UPDATE " . $default->owl_units_organisations_table . " SET organisation_id = $this->iOrgID, unit_id = $this->iUnitID WHERE id = $this->iId"); |
| 131 | if ($result) { | 133 | if ($result) { |
| 132 | return true; | 134 | return true; |
| 133 | } | 135 | } |
| @@ -149,7 +151,7 @@ class UnitOrganisationLink { | @@ -149,7 +151,7 @@ class UnitOrganisationLink { | ||
| 149 | //only delete the object if it exists in the database | 151 | //only delete the object if it exists in the database |
| 150 | if ($this->iId >= 0) { | 152 | if ($this->iId >= 0) { |
| 151 | $sql = $default->db; | 153 | $sql = $default->db; |
| 152 | - $result = $sql->query("DELETE FROM $default->owl_units_organisations_link_table WHERE id = $this->iId"); | 154 | + $result = $sql->query("DELETE FROM $default->owl_units_organisations_table WHERE id = $this->iId"); |
| 153 | if ($result) { | 155 | if ($result) { |
| 154 | return true; | 156 | return true; |
| 155 | } | 157 | } |
| @@ -212,5 +214,44 @@ class UnitOrganisationLink { | @@ -212,5 +214,44 @@ class UnitOrganisationLink { | ||
| 212 | return false; | 214 | return false; |
| 213 | } | 215 | } |
| 214 | 216 | ||
| 217 | + /* | ||
| 218 | + * static function | ||
| 219 | + * | ||
| 220 | + * test to see if unit belongs to org | ||
| 221 | + * | ||
| 222 | + * @param false or a value | ||
| 223 | + * | ||
| 224 | + */ | ||
| 225 | + | ||
| 226 | + function unitBelongsToOrg($unitId) | ||
| 227 | + { | ||
| 228 | + global $default; | ||
| 229 | + | ||
| 230 | + $value = lookupField("$default->owl_units_organisations_table", "organisation_id", "unit_id", $unitId ); | ||
| 231 | + | ||
| 232 | + return $value; | ||
| 233 | + | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + /* | ||
| 237 | + * static function | ||
| 238 | + * | ||
| 239 | + * sets the id of the unitorg using their unit id | ||
| 240 | + * | ||
| 241 | + * @param String | ||
| 242 | + * The unit_ID | ||
| 243 | + * | ||
| 244 | + */ | ||
| 245 | + | ||
| 246 | + function setUnitOrgID($unitId) | ||
| 247 | + { | ||
| 248 | + global $default; | ||
| 249 | + | ||
| 250 | + $id = lookupID($default->owl_units_organisations_table, "unit_id", $unitId); | ||
| 251 | + | ||
| 252 | + $this->iId= $id; | ||
| 253 | + } | ||
| 254 | + | ||
| 255 | + | ||
| 215 | } | 256 | } |
| 216 | ?> | 257 | ?> |