Commit 2970590761b8b68ec088f4b7b1a12bfb311702eb
1 parent
b17af6c6
added
- remove - update - listall - getuserdetails functions git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@149 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
316 additions
and
38 deletions
lib/administration/UnitManager.inc
| @@ -8,9 +8,19 @@ require_once("$default->owl_fs_root/lib/class.AuthLdap.php"); | @@ -8,9 +8,19 @@ require_once("$default->owl_fs_root/lib/class.AuthLdap.php"); | ||
| 8 | * Performs unit administration tasks- this includes user, group and category management, | 8 | * Performs unit administration tasks- this includes user, group and category management, |
| 9 | * | 9 | * |
| 10 | * @version $Revision$ | 10 | * @version $Revision$ |
| 11 | - * @author <a href="mailto:michael@jamwarehouse.com>Michael Joseph</a>, Jam Warehouse (Pty) Ltd, South Africa | 11 | + * @author Mukhtar Dharsey |
| 12 | * @package dmslib | 12 | * @package dmslib |
| 13 | */ | 13 | */ |
| 14 | +/*-----------------------------------------------------------------*/ | ||
| 15 | +/** | ||
| 16 | + * Class Unit Manager | ||
| 17 | + * | ||
| 18 | + * Performs unit administration tasks- this includes user, group and category management, | ||
| 19 | + * | ||
| 20 | + * | ||
| 21 | + */ | ||
| 22 | +/*-----------------------------------------------------------------*/ | ||
| 23 | + | ||
| 14 | class UnitManager { | 24 | class UnitManager { |
| 15 | 25 | ||
| 16 | /** | 26 | /** |
| @@ -20,7 +30,10 @@ class UnitManager { | @@ -20,7 +30,10 @@ class UnitManager { | ||
| 20 | 30 | ||
| 21 | // user management | 31 | // user management |
| 22 | 32 | ||
| 23 | - /** | 33 | + /*-----------------------------------------------------------------*/ |
| 34 | + /* | ||
| 35 | + * Function ListLdapUsers($userNameSearch) | ||
| 36 | + * | ||
| 24 | * Searches the LDAP directory for users matching the supplied search string. | 37 | * Searches the LDAP directory for users matching the supplied search string. |
| 25 | * | 38 | * |
| 26 | * @param $userNameSearch | 39 | * @param $userNameSearch |
| @@ -28,6 +41,7 @@ class UnitManager { | @@ -28,6 +41,7 @@ class UnitManager { | ||
| 28 | * @return | 41 | * @return |
| 29 | * returns an array containing the users found | 42 | * returns an array containing the users found |
| 30 | */ | 43 | */ |
| 44 | + /*-----------------------------------------------------------------*/ | ||
| 31 | function listLdapUsers($userNameSearch) { | 45 | function listLdapUsers($userNameSearch) { |
| 32 | global $default; | 46 | global $default; |
| 33 | 47 | ||
| @@ -62,16 +76,21 @@ class UnitManager { | @@ -62,16 +76,21 @@ class UnitManager { | ||
| 62 | } | 76 | } |
| 63 | } | 77 | } |
| 64 | 78 | ||
| 65 | - /** | 79 | + |
| 80 | + //----------------------------------------------------------------- | ||
| 81 | + /* | ||
| 82 | + * Function addUser($unitID, $userDetails) | ||
| 83 | + * | ||
| 66 | * Adds a user to the unit. | 84 | * Adds a user to the unit. |
| 67 | * | 85 | * |
| 68 | - * @param unitID | 86 | + * @param unitID |
| 69 | * the ID of the unit to add the user to | 87 | * the ID of the unit to add the user to |
| 70 | - * @param userDetails | 88 | + * @param userDetails |
| 71 | * an array containing the details of the user | 89 | * an array containing the details of the user |
| 72 | * @return | 90 | * @return |
| 73 | * true if the addition was successful, else false. | 91 | * true if the addition was successful, else false. |
| 74 | - */ | 92 | + */ |
| 93 | + //----------------------------------------------------------------- | ||
| 75 | function addUser($unitID, $userDetails) { | 94 | function addUser($unitID, $userDetails) { |
| 76 | global $default; | 95 | global $default; |
| 77 | 96 | ||
| @@ -138,54 +157,248 @@ class UnitManager { | @@ -138,54 +157,248 @@ class UnitManager { | ||
| 138 | return true; | 157 | return true; |
| 139 | } | 158 | } |
| 140 | 159 | ||
| 141 | - /** | ||
| 142 | - * @param unitID | ||
| 143 | - * @param userID | ||
| 144 | - */ | ||
| 145 | - function removeUser($unitID, $userID){ | ||
| 146 | - return false; | ||
| 147 | - } | 160 | + //----------------------------------------------------------------- |
| 161 | + /* | ||
| 162 | + * Function RemoveUser($unitID, $userID) | ||
| 163 | + * | ||
| 164 | + * Adds a user to the unit. | ||
| 165 | + * | ||
| 166 | + * @param unitID | ||
| 167 | + * The ID of the unit to add the user to | ||
| 168 | + * @param userID | ||
| 169 | + * The Id of the User that must be deleted | ||
| 170 | + * @return | ||
| 171 | + * True if the deletion was successful, else false if not or nonexistant. | ||
| 172 | + */ | ||
| 173 | + //----------------------------------------------------------------- | ||
| 174 | + function removeUser($unitID, $userID) | ||
| 175 | + { | ||
| 176 | + global $default; | ||
| 177 | + // create a connection | ||
| 178 | + $db = new Owl_DB; | ||
| 179 | + | ||
| 180 | + //do validation that userid exists | ||
| 181 | + $sql = "SELECT * FROM $default->owl_users_table WHERE $id = $userID"; | ||
| 182 | + $result = $db->query($sql) | ||
| 183 | + if(!'result') | ||
| 184 | + { | ||
| 185 | + printf"User does not exist in the database") | ||
| 186 | + return false | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + //if user id exists delete it from the users table | ||
| 190 | + $sql = "DELETE FROM $default->owl_users_table WHERE id = $userID"; | ||
| 191 | + $result = $db->query($sql) | ||
| 192 | + if(!'result') | ||
| 193 | + { | ||
| 194 | + return false; | ||
| 195 | + } | ||
| 196 | + else | ||
| 197 | + { | ||
| 198 | + echo "Deletion from user table Successful<br>"; | ||
| 199 | + return true; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + } | ||
| 148 | 203 | ||
| 149 | - /** | ||
| 150 | - * @param userID | ||
| 151 | - * @param userDetails | ||
| 152 | - */ | ||
| 153 | - function updateUser($userID, $userDetails){ | ||
| 154 | - return false; | 204 | + //----------------------------------------------------------------- |
| 205 | + /* | ||
| 206 | + * Function updateUser($userID, $userDetails) | ||
| 207 | + * | ||
| 208 | + * Adds a user to the unit. | ||
| 209 | + * | ||
| 210 | + * @param userID | ||
| 211 | + * the ID of the unit to add the user to | ||
| 212 | + * @param userDetails | ||
| 213 | + * an array containing the details of the user | ||
| 214 | + * @return | ||
| 215 | + * true if the addition was successful, else false. | ||
| 216 | + */ | ||
| 217 | + //----------------------------------------------------------------- | ||
| 218 | + function updateUser($userID, $userDetails) | ||
| 219 | + { | ||
| 220 | + global $default; | ||
| 221 | + // create a connection | ||
| 222 | + $db = new Owl_DB; | ||
| 223 | + | ||
| 224 | + //do validation that userid exists | ||
| 225 | + $sql = "SELECT * FROM $default->owl_users_table WHERE $id = $userID"; | ||
| 226 | + $result = $db->query($sql) | ||
| 227 | + if(!'result') | ||
| 228 | + { | ||
| 229 | + printf"User does not exist in the database") | ||
| 230 | + return false | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + //if user id exists update all info into the users table | ||
| 234 | + //TODO group id change?????? | ||
| 235 | + $sql = "UPDATE $default->owl_users_table SET " . | ||
| 236 | + " username = " . $userDetails['username'] . "," . | ||
| 237 | + " name = " . $userDetails['name'] . "," . | ||
| 238 | + " password = " . $userDetails['password'] . "," . | ||
| 239 | + " quota_max = " . $userDetails['quota_max'] ."," . | ||
| 240 | + " quota_current = " . $userDetails['quota_current'] ."," . | ||
| 241 | + " name = " . $userDetails['name'] . "," . | ||
| 242 | + " email = " . $userDetails['email'] . "," . | ||
| 243 | + " mobile = " . $userDetails['mobile'] . "," . | ||
| 244 | + " email_notification = " . $userDetails['email_notification'] ."," . | ||
| 245 | + " sms_notification = " . $userDetails['sms_notification'] . " | ||
| 246 | + " WHERE id = ". $userID ."" ; | ||
| 247 | + | ||
| 248 | + | ||
| 249 | + $result = $db->query($sql) | ||
| 250 | + if(!'result') | ||
| 251 | + { | ||
| 252 | + printf("Not Updated) | ||
| 253 | + return false; | ||
| 254 | + } | ||
| 255 | + else | ||
| 256 | + { | ||
| 257 | + echo "Deletion from user table Successful<br>"; | ||
| 258 | + return true; | ||
| 259 | + } | ||
| 155 | } | 260 | } |
| 156 | - | 261 | + //----------------------------------------------------------------- |
| 262 | + /* | ||
| 263 | + * Function listUser() | ||
| 264 | + * | ||
| 265 | + * returns an array of all the usernames | ||
| 266 | + * | ||
| 267 | + * @Return | ||
| 268 | + * an array of usernames | ||
| 269 | + */ | ||
| 270 | + //----------------------------------------------------------------- | ||
| 157 | function listUser(){ | 271 | function listUser(){ |
| 158 | - //return null; | 272 | + |
| 273 | + global $default; | ||
| 274 | + // create a connection | ||
| 275 | + $db = new Owl_DB; | ||
| 276 | + | ||
| 277 | + //Get list of all the usernames | ||
| 278 | + $sql = "SELECT username FROM $default->owl_users_table"; | ||
| 279 | + $result = $db->query($sql) | ||
| 280 | + | ||
| 281 | + //return an array of the usernames | ||
| 282 | + return $result; | ||
| 283 | + | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + //----------------------------------------------------------------- | ||
| 287 | + /* | ||
| 288 | + * Function GetUserDetails($userID) | ||
| 289 | + * | ||
| 290 | + * Returns an array of all the details for a specified user. | ||
| 291 | + * | ||
| 292 | + * @Return | ||
| 293 | + * an array of usernames | ||
| 294 | + */ | ||
| 295 | + //----------------------------------------------------------------- | ||
| 296 | + function GetUserDetails($userID){ | ||
| 297 | + | ||
| 298 | + global $default; | ||
| 299 | + // create a connection | ||
| 300 | + $db = new Owl_DB; | ||
| 301 | + | ||
| 302 | + //do validation that userid exists | ||
| 303 | + $sql = "SELECT * FROM $default->owl_users_table WHERE $id = $userID"; | ||
| 304 | + $result = $db->query($sql) | ||
| 305 | + if(!'result') | ||
| 306 | + { | ||
| 307 | + printf"User does not exist in the database") | ||
| 308 | + return false | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + //return an array of the usernames | ||
| 312 | + return $result; | ||
| 313 | + | ||
| 159 | } | 314 | } |
| 160 | 315 | ||
| 161 | // group management | 316 | // group management |
| 162 | 317 | ||
| 163 | - /** | ||
| 164 | - * @param name | ||
| 165 | - */ | 318 | + //----------------------------------------------------------------- |
| 319 | + /* | ||
| 320 | + * Function addUser($unitID, $userDetails) | ||
| 321 | + * | ||
| 322 | + * Adds a user to the unit. | ||
| 323 | + * | ||
| 324 | + * @param unitID | ||
| 325 | + * the ID of the unit to add the user to | ||
| 326 | + * @param userDetails | ||
| 327 | + * an array containing the details of the user | ||
| 328 | + * @return | ||
| 329 | + * true if the addition was successful, else false. | ||
| 330 | + */ | ||
| 331 | + //----------------------------------------------------------------- | ||
| 166 | function createGroup($name){ | 332 | function createGroup($name){ |
| 167 | return false; | 333 | return false; |
| 168 | } | 334 | } |
| 169 | 335 | ||
| 170 | - /** | ||
| 171 | - * @param groupID | ||
| 172 | - */ | 336 | + //----------------------------------------------------------------- |
| 337 | + /* | ||
| 338 | + * Function addUser($unitID, $userDetails) | ||
| 339 | + * | ||
| 340 | + * Adds a user to the unit. | ||
| 341 | + * | ||
| 342 | + * @param unitID | ||
| 343 | + * the ID of the unit to add the user to | ||
| 344 | + * @param userDetails | ||
| 345 | + * an array containing the details of the user | ||
| 346 | + * @return | ||
| 347 | + * true if the addition was successful, else false. | ||
| 348 | + */ | ||
| 349 | + //----------------------------------------------------------------- | ||
| 173 | function removeGroup($groupID){ | 350 | function removeGroup($groupID){ |
| 174 | return false; | 351 | return false; |
| 175 | } | 352 | } |
| 176 | 353 | ||
| 177 | - /** | ||
| 178 | - * @param groupID | ||
| 179 | - * @param name | ||
| 180 | - */ | 354 | + //----------------------------------------------------------------- |
| 355 | + /* | ||
| 356 | + * Function addUser($unitID, $userDetails) | ||
| 357 | + * | ||
| 358 | + * Adds a user to the unit. | ||
| 359 | + * | ||
| 360 | + * @param unitID | ||
| 361 | + * the ID of the unit to add the user to | ||
| 362 | + * @param userDetails | ||
| 363 | + * an array containing the details of the user | ||
| 364 | + * @return | ||
| 365 | + * true if the addition was successful, else false. | ||
| 366 | + */ | ||
| 367 | + //----------------------------------------------------------------- | ||
| 181 | function updateGroup($groupID, $name){ | 368 | function updateGroup($groupID, $name){ |
| 182 | return false; | 369 | return false; |
| 183 | } | 370 | } |
| 184 | - | 371 | +//----------------------------------------------------------------- |
| 372 | + /* | ||
| 373 | + * Function addUser($unitID, $userDetails) | ||
| 374 | + * | ||
| 375 | + * Adds a user to the unit. | ||
| 376 | + * | ||
| 377 | + * @param unitID | ||
| 378 | + * the ID of the unit to add the user to | ||
| 379 | + * @param userDetails | ||
| 380 | + * an array containing the details of the user | ||
| 381 | + * @return | ||
| 382 | + * true if the addition was successful, else false. | ||
| 383 | + */ | ||
| 384 | + //----------------------------------------------------------------- | ||
| 185 | function listGroup(){ | 385 | function listGroup(){ |
| 186 | //return null; | 386 | //return null; |
| 187 | } | 387 | } |
| 188 | - | 388 | + //----------------------------------------------------------------- |
| 389 | + /* | ||
| 390 | + * Function addUser($unitID, $userDetails) | ||
| 391 | + * | ||
| 392 | + * Adds a user to the unit. | ||
| 393 | + * | ||
| 394 | + * @param unitID | ||
| 395 | + * the ID of the unit to add the user to | ||
| 396 | + * @param userDetails | ||
| 397 | + * an array containing the details of the user | ||
| 398 | + * @return | ||
| 399 | + * true if the addition was successful, else false. | ||
| 400 | + */ | ||
| 401 | + //----------------------------------------------------------------- | ||
| 189 | /** | 402 | /** |
| 190 | * @param groupID | 403 | * @param groupID |
| 191 | * @param userID | 404 | * @param userID |
| @@ -193,7 +406,20 @@ class UnitManager { | @@ -193,7 +406,20 @@ class UnitManager { | ||
| 193 | function addUserToGroup($groupID, $userID){ | 406 | function addUserToGroup($groupID, $userID){ |
| 194 | return false; | 407 | return false; |
| 195 | } | 408 | } |
| 196 | - | 409 | +//----------------------------------------------------------------- |
| 410 | + /* | ||
| 411 | + * Function addUser($unitID, $userDetails) | ||
| 412 | + * | ||
| 413 | + * Adds a user to the unit. | ||
| 414 | + * | ||
| 415 | + * @param unitID | ||
| 416 | + * the ID of the unit to add the user to | ||
| 417 | + * @param userDetails | ||
| 418 | + * an array containing the details of the user | ||
| 419 | + * @return | ||
| 420 | + * true if the addition was successful, else false. | ||
| 421 | + */ | ||
| 422 | + //----------------------------------------------------------------- | ||
| 197 | /** | 423 | /** |
| 198 | * @param groupID | 424 | * @param groupID |
| 199 | * @param userID | 425 | * @param userID |
| @@ -201,7 +427,20 @@ class UnitManager { | @@ -201,7 +427,20 @@ class UnitManager { | ||
| 201 | function removeUserFromGroup($groupID, $userID){ | 427 | function removeUserFromGroup($groupID, $userID){ |
| 202 | return false; | 428 | return false; |
| 203 | } | 429 | } |
| 204 | - | 430 | + //----------------------------------------------------------------- |
| 431 | + /* | ||
| 432 | + * Function addUser($unitID, $userDetails) | ||
| 433 | + * | ||
| 434 | + * Adds a user to the unit. | ||
| 435 | + * | ||
| 436 | + * @param unitID | ||
| 437 | + * the ID of the unit to add the user to | ||
| 438 | + * @param userDetails | ||
| 439 | + * an array containing the details of the user | ||
| 440 | + * @return | ||
| 441 | + * true if the addition was successful, else false. | ||
| 442 | + */ | ||
| 443 | + //----------------------------------------------------------------- | ||
| 205 | // category management | 444 | // category management |
| 206 | 445 | ||
| 207 | /** | 446 | /** |
| @@ -210,14 +449,40 @@ class UnitManager { | @@ -210,14 +449,40 @@ class UnitManager { | ||
| 210 | function createCategory($name){ | 449 | function createCategory($name){ |
| 211 | return false; | 450 | return false; |
| 212 | } | 451 | } |
| 213 | - | 452 | +//----------------------------------------------------------------- |
| 453 | + /* | ||
| 454 | + * Function addUser($unitID, $userDetails) | ||
| 455 | + * | ||
| 456 | + * Adds a user to the unit. | ||
| 457 | + * | ||
| 458 | + * @param unitID | ||
| 459 | + * the ID of the unit to add the user to | ||
| 460 | + * @param userDetails | ||
| 461 | + * an array containing the details of the user | ||
| 462 | + * @return | ||
| 463 | + * true if the addition was successful, else false. | ||
| 464 | + */ | ||
| 465 | + //----------------------------------------------------------------- | ||
| 214 | /** | 466 | /** |
| 215 | * @param categoryID | 467 | * @param categoryID |
| 216 | */ | 468 | */ |
| 217 | function removeCategory($categoryID){ | 469 | function removeCategory($categoryID){ |
| 218 | return false; | 470 | return false; |
| 219 | } | 471 | } |
| 220 | - | 472 | +//----------------------------------------------------------------- |
| 473 | + /* | ||
| 474 | + * Function addUser($unitID, $userDetails) | ||
| 475 | + * | ||
| 476 | + * Adds a user to the unit. | ||
| 477 | + * | ||
| 478 | + * @param unitID | ||
| 479 | + * the ID of the unit to add the user to | ||
| 480 | + * @param userDetails | ||
| 481 | + * an array containing the details of the user | ||
| 482 | + * @return | ||
| 483 | + * true if the addition was successful, else false. | ||
| 484 | + */ | ||
| 485 | + //----------------------------------------------------------------- | ||
| 221 | /** | 486 | /** |
| 222 | * @param name | 487 | * @param name |
| 223 | * @param categoryID | 488 | * @param categoryID |
| @@ -225,7 +490,20 @@ class UnitManager { | @@ -225,7 +490,20 @@ class UnitManager { | ||
| 225 | function updateCategory($name, $categoryID){ | 490 | function updateCategory($name, $categoryID){ |
| 226 | return false; | 491 | return false; |
| 227 | } | 492 | } |
| 228 | - | 493 | +//----------------------------------------------------------------- |
| 494 | + /* | ||
| 495 | + * Function addUser($unitID, $userDetails) | ||
| 496 | + * | ||
| 497 | + * Adds a user to the unit. | ||
| 498 | + * | ||
| 499 | + * @param unitID | ||
| 500 | + * the ID of the unit to add the user to | ||
| 501 | + * @param userDetails | ||
| 502 | + * an array containing the details of the user | ||
| 503 | + * @return | ||
| 504 | + * true if the addition was successful, else false. | ||
| 505 | + */ | ||
| 506 | + //----------------------------------------------------------------- | ||
| 229 | function listCategories(){ | 507 | function listCategories(){ |
| 230 | //return null; | 508 | //return null; |
| 231 | } | 509 | } |