00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00036
00037
00038 require_once "class.ilContainer.php";
00039
00040 define('GRP_REGISTRATION_DIRECT',0);
00041 define('GRP_REGISTRATION_REQUEST',1);
00042 define('GRP_REGISTRATION_PASSWORD',2);
00043
00044
00045 class ilObjGroup extends ilContainer
00046 {
00050 var $file_obj = null;
00051
00052 var $m_grpStatus;
00053
00054 var $m_roleMemberId;
00055
00056 var $m_roleAdminId;
00057
00064 function ilObjGroup($a_id = 0,$a_call_by_reference = true)
00065 {
00066 global $tree;
00067
00068 $this->tree =& $tree;
00069
00070 $this->type = "grp";
00071 $this->ilObject($a_id,$a_call_by_reference);
00072 $this->setRegisterMode(true);
00073 }
00074
00080 function join($a_user_id, $a_mem_role="")
00081 {
00082 global $rbacadmin;
00083
00084 if (is_array($a_mem_role))
00085 {
00086 foreach ($a_mem_role as $role)
00087 {
00088 $rbacadmin->assignUser($role,$a_user_id, false);
00089 }
00090 }
00091 else
00092 {
00093 $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
00094 }
00095
00096 ilObjUser::updateActiveRoles($a_user_id);
00097 return true;
00098 }
00099
00104 function getDefaultMemberRole()
00105 {
00106 $local_group_Roles = $this->getLocalGroupRoles();
00107
00108 return $local_group_Roles["il_grp_member_".$this->getRefId()];
00109 }
00110
00115 function getDefaultAdminRole()
00116 {
00117 $local_group_Roles = $this->getLocalGroupRoles();
00118
00119 return $local_group_Roles["il_grp_admin_".$this->getRefId()];
00120 }
00121
00128 function addMember($a_user_id, $a_mem_role)
00129 {
00130 global $rbacadmin;
00131
00132 if (isset($a_user_id) && isset($a_mem_role) )
00133 {
00134 $this->join($a_user_id,$a_mem_role);
00135 return true;
00136 }
00137 else
00138 {
00139 $this->ilias->raiseError(get_class($this)."::addMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
00140 return false;
00141 }
00142 }
00143
00148 function getNewRegistrations()
00149 {
00150 global $ilDB;
00151
00152 $appList = array();
00153 $q = "SELECT * FROM grp_registration WHERE grp_id=".$ilDB->quote($this->getId());
00154 $res = $this->ilias->db->query($q);
00155 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00156 {
00157 if (ilObject::_exists($row->user_id) &&
00158 ilObject::_lookupType($row->user_id) == "usr")
00159 {
00160 array_push($appList,$row);
00161 }
00162 }
00163
00164 return ($appList) ? $appList : false;
00165 }
00166
00171 function deleteApplicationListEntry($a_userId)
00172 {
00173 global $ilDB;
00174
00175 $q = "DELETE FROM grp_registration WHERE user_id=".
00176 $ilDB->quote($a_userId)." AND grp_id=".$ilDB->quote($this->getId());
00177 $res = $this->ilias->db->query($q);
00178 }
00179
00186 function leaveGroup()
00187 {
00188 global $rbacadmin, $rbacreview;
00189
00190 $member_ids = $this->getGroupMemberIds();
00191
00192 if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids))
00193 {
00194 return 2;
00195 }
00196 else
00197 {
00198 if (!$this->isAdmin($this->ilias->account->getId()))
00199 {
00200 $this->leave($this->ilias->account->getId());
00201 $member = new ilObjUser($this->ilias->account->getId());
00202 $member->dropDesktopItem($this->getRefId(), "grp");
00203
00204 return 0;
00205 }
00206 else if (count($this->getGroupAdminIds()) == 1)
00207 {
00208 return 1;
00209 }
00210 }
00211 }
00212
00217 function leave($a_user_id)
00218 {
00219 global $rbacadmin;
00220
00221 $arr_groupRoles = $this->getMemberRoles($a_user_id);
00222
00223 if (is_array($arr_groupRoles))
00224 {
00225 foreach ($arr_groupRoles as $groupRole)
00226 {
00227 $rbacadmin->deassignUser($groupRole, $a_user_id);
00228 }
00229 }
00230 else
00231 {
00232 $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
00233 }
00234
00235 ilObjUser::updateActiveRoles($a_user_id);
00236
00237 return true;
00238 }
00239
00244 function removeMember($a_user_id, $a_grp_id="")
00245 {
00246 if (isset($a_user_id) && isset($a_grp_id) && $this->isMember($a_user_id))
00247 {
00248 if (count($this->getGroupMemberIds()) > 1)
00249 {
00250 if ($this->isAdmin($a_user_id) && count($this->getGroupAdminIds()) < 2)
00251 {
00252 return "grp_err_administrator_required";
00253 }
00254 else
00255 {
00256 $this->leave($a_user_id);
00257 $member = new ilObjUser($a_user_id);
00258 $member->dropDesktopItem($this->getRefId(), "grp");
00259
00260 return "";
00261 }
00262 }
00263 else
00264 {
00265 return "grp_err_last_member";
00266 }
00267 }
00268 else
00269 {
00270 $this->ilias->raiseError(get_class($this)."::removeMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
00271 }
00272 }
00273
00280 function getGroupMemberIds()
00281 {
00282 global $rbacadmin, $rbacreview;
00283
00284 $usr_arr= array();
00285
00286 $rol = $this->getLocalGroupRoles();
00287
00288 foreach ($rol as $value)
00289 {
00290 foreach ($rbacreview->assignedUsers($value) as $member_id)
00291 {
00292 array_push($usr_arr,$member_id);
00293 }
00294 }
00295
00296 $mem_arr = array_unique($usr_arr);
00297
00298 return $mem_arr ? $mem_arr : array();
00299 }
00300
00308 function getGroupMemberData($a_mem_ids, $active = 1)
00309 {
00310 global $rbacadmin, $rbacreview, $ilBench, $ilDB;
00311
00312 $usr_arr= array();
00313
00314 if (count ($a_mem_ids) == 0)
00315 $a_mem_ids = array ("-1");
00316
00317 $q = "SELECT login,firstname,lastname,title,usr_id,last_login ".
00318 "FROM usr_data ".
00319 "WHERE usr_id IN (".implode(',',$a_mem_ids).")";
00320
00321 if (is_numeric($active) && $active > -1)
00322 $q .= " AND active = '$active'";
00323
00324 $r = $ilDB->query($q);
00325
00326 while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00327 {
00328 $mem_arr[] = array("id" => $row->usr_id,
00329 "login" => $row->login,
00330 "firstname" => $row->firstname,
00331 "lastname" => $row->lastname,
00332 "last_login" => $row->last_login
00333 );
00334 }
00335
00336 return $mem_arr ? $mem_arr : array();
00337 }
00338
00339 function getCountMembers()
00340 {
00341 return count($this->getGroupMemberIds());
00342 }
00343
00350 function getGroupAdminIds($a_grpId="")
00351 {
00352 global $rbacreview;
00353
00354 if (!empty($a_grpId))
00355 {
00356 $grp_id = $a_grpId;
00357 }
00358 else
00359 {
00360 $grp_id = $this->getRefId();
00361 }
00362
00363 $usr_arr = array();
00364 $roles = $this->getDefaultGroupRoles($this->getRefId());
00365
00366 foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
00367 {
00368 array_push($usr_arr,$member_id);
00369 }
00370
00371 return $usr_arr;
00372 }
00373
00379 function getDefaultGroupRoles($a_grp_id="")
00380 {
00381 global $rbacadmin, $rbacreview;
00382
00383 if (strlen($a_grp_id) > 0)
00384 {
00385 $grp_id = $a_grp_id;
00386 }
00387 else
00388 {
00389 $grp_id = $this->getRefId();
00390 }
00391
00392 $rolf = $rbacreview->getRoleFolderOfObject($grp_id);
00393 $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
00394
00395 foreach ($role_arr as $role_id)
00396 {
00397 $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
00398
00399 $grp_Member ="il_grp_member_".$grp_id;
00400 $grp_Admin ="il_grp_admin_".$grp_id;
00401
00402 if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
00403 {
00404 $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
00405 }
00406
00407 if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
00408 {
00409 $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
00410 }
00411 }
00412
00413 return $arr_grpDefaultRoles;
00414 }
00415
00422 function getLocalGroupRoles($a_translate = false)
00423 {
00424 global $rbacadmin,$rbacreview;
00425
00426 if (empty($this->local_roles))
00427 {
00428 $this->local_roles = array();
00429 $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
00430 $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
00431
00432 foreach ($role_arr as $role_id)
00433 {
00434 if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
00435 {
00436 $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
00437
00438 if ($a_translate)
00439 {
00440 $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
00441 }
00442 else
00443 {
00444 $role_name = $role_Obj->getTitle();
00445 }
00446
00447 $this->local_roles[$role_name] = $role_Obj->getId();
00448 }
00449 }
00450 }
00451
00452 return $this->local_roles;
00453 }
00454
00460 function getGrpStatusClosedTemplateId()
00461 {
00462 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
00463 $res = $this->ilias->db->query($q);
00464 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00465
00466 return $row["obj_id"];
00467 }
00468
00474 function getGrpStatusOpenTemplateId()
00475 {
00476 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
00477 $res = $this->ilias->db->query($q);
00478 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00479
00480 return $row["obj_id"];
00481 }
00482
00488 function setRegistrationFlag($a_regFlag="")
00489 {
00490 global $ilDB;
00491
00492 $q = "SELECT * FROM grp_data WHERE grp_id=".$ilDB->quote($this->getId());
00493 $res = $this->ilias->db->query($q);
00494
00495 if (!isset($a_regFlag))
00496 {
00497 $a_regFlag = 0;
00498 }
00499
00500 if ($res->numRows() == 0)
00501 {
00502 $q = "INSERT INTO grp_data (grp_id, register) VALUES(".
00503 $ilDB->quote($this->getId()).",".$ilDB->quote($a_regFlag).")";
00504 $res = $this->ilias->db->query($q);
00505 }
00506 else
00507 {
00508 $q = "UPDATE grp_data SET register=".$ilDB->quote($a_regFlag)." WHERE grp_id=".
00509 $ilDB->quote($this->getId())."";
00510 $res = $this->ilias->db->query($q);
00511 }
00512 }
00513
00519 function getRegistrationFlag()
00520 {
00521 global $ilDB;
00522
00523 $q = "SELECT * FROM grp_data WHERE grp_id=".
00524 $ilDB->quote($this->getId());
00525 $res = $this->ilias->db->query($q);
00526 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00527
00528 return $row["register"];
00529 }
00530
00536 function getPassword()
00537 {
00538 global $ilDB;
00539
00540 $q = "SELECT * FROM grp_data WHERE grp_id=".
00541 $ilDB->quote($this->getId());
00542 $res = $this->ilias->db->query($q);
00543 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00544
00545 return $row["password"];
00546 }
00547
00553 function setPassword($a_password="")
00554 {
00555 global $ilDB;
00556
00557 $q = "SELECT * FROM grp_data WHERE grp_id=".$ilDB->quote($this->getId());
00558 $res = $this->ilias->db->query($q);
00559
00560 if ($res->numRows() == 0)
00561 {
00562 $q = "INSERT INTO grp_data (grp_id, password) VALUES(".$ilDB->quote($this->getId()).",".
00563 $ilDB->quote($a_password).")";
00564 $res = $this->ilias->db->query($q);
00565 }
00566 else
00567 {
00568 $q = "UPDATE grp_data SET password=".$ilDB->quote($a_password)." WHERE grp_id=".
00569 $ilDB->quote($this->getId())."";
00570 $res = $this->ilias->db->query($q);
00571 }
00572 }
00573
00579 function setExpirationDateTime($a_date)
00580 {
00581 global $ilDB;
00582
00583 $q = "SELECT * FROM grp_data WHERE grp_id=".$ilDB->quote($this->getId());
00584 $res = $this->ilias->db->query($q);
00585 $date = ilFormat::input2date($a_date);
00586
00587 if ($res->numRows() == 0)
00588 {
00589 $q = "INSERT INTO grp_data (grp_id, expiration) VALUES(".$ilDB->quote($this->getId()).",".
00590 $ilDB->quote($date).")";
00591 $res = $this->ilias->db->query($q);
00592 }
00593 else
00594 {
00595 $q = "UPDATE grp_data SET expiration=".$ilDB->quote($date)." WHERE grp_id=".
00596 $ilDB->quote($this->getId())."";
00597 $res = $this->ilias->db->query($q);
00598 }
00599 }
00600
00606 function getExpirationDateTime()
00607 {
00608 global $ilDB;
00609
00610 $q = "SELECT * FROM grp_data WHERE grp_id=".
00611 $ilDB->quote($this->getId());
00612 $res = $this->ilias->db->query($q);
00613 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00614 $datetime = $row["expiration"];
00615 $date = ilFormat::fdateDB2dateDE($datetime);
00616 $time = substr($row["expiration"], -8);
00617 $datetime = array(0=>$date, 1=>$time);
00618
00619 return $datetime;
00620 }
00621
00622 function getExpirationTimestamp()
00623 {
00624 global $ilDB;
00625
00626 $query = "SELECT * FROM grp_data WHERE grp_id = ".
00627 $ilDB->quote($this->getId());
00628
00629 $res = $this->ilias->db->query($query);
00630 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00631 $datetime = $row["expiration"];
00632
00633 return ($timest = ilFormat::datetime2unixTS($datetime)) ? $timest : 0;
00634 }
00635
00636
00637 function registrationPossible()
00638 {
00639 $datetime = $this->getExpirationDateTime();
00640 $today_date = ilFormat::getDateDE();
00641 $today_time = date("H:i:s");
00642
00643 $ts_exp_date = ilFormat::dateDE2timestamp($datetime[0]);
00644 $ts_today_date = ilFormat::dateDE2timestamp($today_date);
00645
00646 $ts_exp_time = substr($datetime[1], 0, 2).
00647 substr($datetime[1], 3, 2).
00648 substr($datetime[1], 6, 2);
00649
00650 $ts_today_time = substr($today_time, 0, 2).
00651 substr($today_time, 3, 2).
00652 substr($today_time, 6, 2);
00653
00654
00655 if ($ts_exp_date == 0)
00656 {
00657 return true;
00658 }
00659
00660 if ($ts_today_date < $ts_exp_date)
00661 {
00662 return true;
00663 }
00664 elseif (($ts_today_date == $ts_exp_date) and (strcmp($ts_exp_time,$ts_today_time) >= 0))
00665 {
00666 return true;
00667 }
00668 else
00669 {
00670 return false;
00671 }
00672 }
00673
00692 function __setGroupStatus($a_grpStatus)
00693 {
00694 global $rbacadmin, $rbacreview, $rbacsystem;
00695
00696
00697 $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
00698
00699
00700 $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
00701 $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$this->getDefaultGroupRoles());
00702
00703
00704 if ($a_grpStatus == 0 || $a_grpStatus == 1)
00705 {
00706 if ($a_grpStatus == 0)
00707 {
00708 $template_id = $this->getGrpStatusOpenTemplateId();
00709 } else {
00710 $template_id = $this->getGrpStatusClosedTemplateId();
00711 }
00712
00713 $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
00714
00715 foreach ($arr_relevantParentRoleIds as $parentRole)
00716 {
00717 if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
00718 {
00719 continue;
00720 }
00721
00722 $granted_permissions = array();
00723
00724
00725
00726 $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
00727
00728
00729
00730
00731
00732
00733 $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
00734 $rbacadmin->revokePermission($this->getRefId(), $parentRole);
00735 foreach ($template_ops as $template_op)
00736 {
00737 if (in_array($template_op,$current_ops))
00738 {
00739 array_push($granted_permissions,$template_op);
00740 }
00741 }
00742 if (!empty($granted_permissions))
00743 {
00744 $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
00745 }
00746
00747
00748
00749
00750
00751 $rbacadmin->copyRolePermissionIntersection(
00752 $template_id, ROLE_FOLDER_ID,
00753 $parentRole, $arr_parentRoles[$parentRole]['parent'],
00754 $rolf_data["child"], $parentRole
00755 );
00756 $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
00757 }
00758 }
00759 }
00760
00766 function getGroupStatus()
00767 {
00768 global $rbacsystem,$rbacreview;
00769
00770 $role_folder = $rbacreview->getRoleFolderOfObject($this->getRefId());
00771 $local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
00772
00773
00774 $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
00775
00776 $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
00777
00778
00779 foreach ($arr_globalRoles as $globalRole)
00780 {
00781 $ops_of_role = $rbacreview->getOperationsOfRole($globalRole,"grp", ROLE_FOLDER_ID);
00782
00783 if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
00784 {
00785 return 0;
00786 }
00787 }
00788
00789 return 1;
00790 }
00791
00798 function getMemberRoles($a_user_id)
00799 {
00800 global $rbacadmin, $rbacreview,$ilBench;
00801
00802 $ilBench->start("Group", "getMemberRoles");
00803
00804 $arr_assignedRoles = array();
00805
00806 $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
00807
00808 $ilBench->stop("Group", "getMemberRoles");
00809
00810 return $arr_assignedRoles;
00811 }
00812
00819 function getMemberRolesTitle($a_user_id)
00820 {
00821 global $ilDB,$ilBench;
00822
00823 include_once ('class.ilObjRole.php');
00824
00825 $ilBench->start("Group", "getMemberRolesTitle");
00826
00827 $str_member_roles ="";
00828
00829 $q = "SELECT title ".
00830 "FROM object_data ".
00831 "LEFT JOIN rbac_ua ON object_data.obj_id=rbac_ua.rol_id ".
00832 "WHERE object_data.type = 'role' ".
00833 "AND rbac_ua.usr_id = ".$ilDB->quote($a_user_id)." ".
00834 "AND rbac_ua.rol_id IN (".implode(',',$this->getLocalGroupRoles()).")";
00835
00836 $r = $ilDB->query($q);
00837
00838 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
00839 {
00840
00841 $str_member_roles .= ilObjRole::_getTranslation($row["title"]).", ";
00842 }
00843
00844 $ilBench->stop("Group", "getMemberRolesTitle");
00845
00846 return substr($str_member_roles,0,-2);
00847 }
00848
00855 function setMemberStatus($a_user_id, $a_member_role)
00856 {
00857 if (isset($a_user_id) && isset($a_member_role))
00858 {
00859 $this->removeMember($a_user_id);
00860 $this->addMember($a_user_id, $a_member_role);
00861 }
00862 }
00863
00870 function isMember($a_userId = "")
00871 {
00872 if (strlen($a_userId) == 0)
00873 {
00874 $user_id = $this->ilias->account->getId();
00875 }
00876 else
00877 {
00878 $user_id = $a_userId;
00879 }
00880
00881 if ($this->getType() == "grp")
00882 {
00883 $arr_members = $this->getGroupMemberIds();
00884
00885 if (in_array($user_id, $arr_members))
00886 {
00887 return true;
00888 }
00889 else
00890 {
00891 return false;
00892 }
00893 }
00894 }
00895
00902 function isAdmin($a_userId)
00903 {
00904 global $rbacreview;
00905
00906 $grp_Roles = $this->getDefaultGroupRoles();
00907
00908 if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
00909 {
00910 return true;
00911 }
00912 else
00913 {
00914 return false;
00915 }
00916 }
00917
00926 function ilClone($a_parent_ref)
00927 {
00928 global $rbacadmin;
00929
00930
00931 $new_ref_id = parent::ilClone($a_parent_ref);
00932
00933
00934 $groupObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00935
00936
00937 for ($n = 1;$n < 99;$n++)
00938 {
00939 $groupname_copy = $groupObj->getTitle()."_(copy_".$n.")";
00940
00941 if (!ilUtil::groupNameExists($groupname_copy))
00942 {
00943 $groupObj->setTitle($groupname_copy);
00944 $groupObj->update();
00945 break;
00946 }
00947 }
00948
00949
00950 $roles = $groupObj->initDefaultRoles();
00951
00952
00953 $rbacadmin->assignUser($roles[0], $groupObj->getOwner(), "n");
00954 ilObjUser::updateActiveRoles($groupObj->getOwner());
00955
00956
00957 unset($groupObj);
00958 unset($rfoldObj);
00959 unset($roleObj);
00960
00961
00962 return $new_ref_id;
00963 }
00964
00973 function delete()
00974 {
00975 global $ilDB;
00976
00977
00978 if (!parent::delete())
00979 {
00980 return false;
00981 }
00982
00983 $query = "DELETE FROM grp_data WHERE grp_id=".$ilDB->quote($this->getId());
00984 $this->ilias->db->query($query);
00985
00986 return true;
00987 }
00988
00994 function initDefaultRoles()
00995 {
00996 global $rbacadmin, $rbacreview;
00997
00998
00999 $rfoldObj =& $this->createRoleFolder();
01000
01001
01002
01003 $roleObj = $rfoldObj->createRole("il_grp_admin_".$this->getRefId(),"Groupadmin of group obj_no.".$this->getId());
01004 $this->m_roleAdminId = $roleObj->getId();
01005
01006
01007 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_admin'";
01008 $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
01009 $rbacadmin->copyRolePermission($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
01010
01011
01012 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
01013 $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
01014
01015
01016
01017
01018
01019
01020
01021 $roleObj = $rfoldObj->createRole("il_grp_member_".$this->getRefId(),"Groupmember of group obj_no.".$this->getId());
01022 $this->m_roleMemberId = $roleObj->getId();
01023
01024
01025 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_member'";
01026 $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
01027 $rbacadmin->copyRolePermission($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
01028
01029
01030 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
01031 $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
01032
01033
01034
01035
01036
01037 unset($rfoldObj);
01038 unset($roleObj);
01039
01040 $roles[] = $this->m_roleAdminId;
01041 $roles[] = $this->m_roleMemberId;
01042
01043
01044
01045
01046 $this->__setGroupStatus($_POST["group_status"]);
01047
01048 return $roles ? $roles : array();
01049 }
01050
01061 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
01062 {
01063 global $tree;
01064
01065 $parent_id = (int) $tree->getParentId($a_node_id);
01066
01067 if ($parent_id != 0)
01068 {
01069 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01070 $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
01071 }
01072
01073 return true;
01074 }
01075
01076
01077 function exportXML()
01078 {
01079 include_once 'classes/class.ilGroupXMLWriter.php';
01080
01081 $xml_writer = new ilGroupXMLWriter($this);
01082 $xml_writer->start();
01083
01084 $xml = $xml_writer->getXML();
01085
01086 $name = time().'__'.$this->ilias->getSetting('inst_id').'__grp_'.$this->getId();
01087
01088 $this->__initFileObject();
01089
01090 $this->file_obj->addGroupDirectory();
01091 $this->file_obj->addDirectory($name);
01092 $this->file_obj->writeToFile($xml,$name.'/'.$name.'.xml');
01093 $this->file_obj->zipFile($name,$name.'.zip');
01094 $this->file_obj->deleteDirectory($name);
01095
01096 return true;
01097 }
01098
01099 function deleteExportFiles($a_files)
01100 {
01101 $this->__initFileObject();
01102
01103 foreach($a_files as $file)
01104 {
01105 $this->file_obj->deleteFile($file);
01106 }
01107 return true;
01108 }
01109
01110 function downloadExportFile($file)
01111 {
01112 $this->__initFileObject();
01113
01114 if($abs_name = $this->file_obj->getExportFile($file))
01115 {
01116 ilUtil::deliverFile($abs_name,$file);
01117
01118 }
01119 return false;
01120 }
01121
01130 function _importFromXMLString($xml,$parent_id)
01131 {
01132 include_once 'classes/class.ilGroupImportParser.php';
01133
01134 $import_parser = new ilGroupImportParser($xml,$parent_id);
01135
01136 return $import_parser->startParsing();
01137 }
01138
01146 function _importFromFile($file,$parent_id)
01147 {
01148 global $lng;
01149
01150 include_once 'classes/class.ilFileDataGroup.php';
01151
01152 $file_obj = new ilFileDataGroup(null);
01153 $file_obj->addImportDirectory();
01154 $file_obj->createImportFile($_FILES["xmldoc"]["tmp_name"],$_FILES['xmldoc']['name']);
01155 $file_obj->unpackImportFile();
01156
01157 if(!$file_obj->validateImportFile())
01158 {
01159 return false;
01160 }
01161 return ilObjGroup::_importFromXMLString(file_get_contents($file_obj->getImportFile()),$parent_id);
01162 }
01163
01172 function _search(&$a_search_obj)
01173 {
01174 global $ilBench;
01175
01176
01177
01178 $where_condition = $a_search_obj->getWhereCondition("like",array("title","description"));
01179 $in = $a_search_obj->getInStatement("ore.ref_id");
01180
01181 $query = "SELECT ore.ref_id AS ref_id FROM object_data AS od, object_reference AS ore ".
01182 $where_condition." ".
01183 $in." ".
01184 "AND od.obj_id = ore.obj_id ".
01185 "AND od.type = 'grp' ";
01186
01187 $ilBench->start("Search", "ilObjGroup_search");
01188 $res = $a_search_obj->ilias->db->query($query);
01189 $ilBench->stop("Search", "ilObjGroup_search");
01190
01191 $counter = 0;
01192
01193 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01194 {
01195 $result_data[$counter++]["id"] = $row->ref_id;
01196 #$result_data[$counter]["link"] = "group.php?cmd=view&ref_id=".$row->ref_id;
01197 #$result_data[$counter++]["target"] = "";
01198 }
01199
01200 return $result_data ? $result_data : array();
01201 }
01202
01211 function _getLinkToObject($a_id)
01212 {
01213 return array("repository.php?ref_id=".$a_id."&set_mode=flat&cmdClass=ilobjgroupgui","");
01214 }
01215
01216 function _lookupIdByTitle($a_title)
01217 {
01218 global $ilDB;
01219
01220 $query = "SELECT * FROM object_data WHERE title = ".$ilDB->quote($a_title)." AND type = 'grp'";
01221 $res = $ilDB->query($query);
01222 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01223 {
01224 return $row->obj_id;
01225 }
01226 return 0;
01227 }
01228
01229
01230 function isUserRegistered($a_user_id = 0)
01231 {
01232 global $rbacsystem;
01233
01234
01235
01236
01237
01238
01239
01240 if (!$this->isMember() or !$rbacsystem->checkAccess("join", $this->ref_id))
01241 {
01242 return false;
01243 }
01244
01245 return true;
01246 }
01247
01248 function _isMember($a_user_id,$a_ref_id,$a_field = '')
01249 {
01250 global $rbacreview,$ilObjDataCache,$ilDB;
01251
01252 $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
01253 $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
01254 $user_roles = $rbacreview->assignedRoles($a_user_id);
01255
01256
01257 if($a_field)
01258 {
01259 include_once 'classes/class.ilObjUser.php';
01260
01261 $tmp_user =& ilObjectFactory::getInstanceByObjId($a_user_id);
01262 switch($a_field)
01263 {
01264 case 'login':
01265 $and = "AND login = '".$tmp_user->getLogin()."' ";
01266 break;
01267 case 'email':
01268 $and = "AND email = '".$tmp_user->getEmail()."' ";
01269 break;
01270 case 'matriculation':
01271 $and = "AND matriculation = '".$tmp_user->getMatriculation()."' ";
01272 break;
01273
01274 default:
01275 $and = "AND usr_id = '".$a_usr_id."'";
01276 break;
01277 }
01278 if(!$members = ilObjGroup::_getMembers($ilObjDataCache->lookupObjId($a_ref_id)))
01279 {
01280 return false;
01281 }
01282 $query = "SELECT * FROM usr_data as ud ".
01283 "WHERE usr_id IN ('".implode("','",$members)."') ".
01284 $and;
01285 $res = $ilDB->query($query);
01286
01287 return $res->numRows() ? true : false;
01288 }
01289
01290
01291
01292
01293
01294 if (!array_intersect($local_roles,$user_roles))
01295 {
01296 return false;
01297 }
01298
01299 return true;
01300 }
01301
01302 function _getMembers($a_obj_id)
01303 {
01304 global $rbacreview;
01305
01306
01307 $ref_ids = ilObject::_getAllReferences($a_obj_id);
01308 $ref_id = current($ref_ids);
01309
01310 $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
01311 $local_roles = $rbacreview->getRolesOfRoleFolder($rolf['ref_id'],false);
01312
01313 $users = array();
01314 foreach($local_roles as $role_id)
01315 {
01316 $users = array_merge($users,$rbacreview->assignedUsers($role_id));
01317 }
01318
01319 return array_unique($users);
01320 }
01321
01322
01323
01324
01325 function __initFileObject()
01326 {
01327 if($this->file_obj)
01328 {
01329 return $this->file_obj;
01330 }
01331 else
01332 {
01333 include_once 'classes/class.ilFileDataGroup.php';
01334
01335 return $this->file_obj = new ilFileDataGroup($this);
01336 }
01337 }
01338
01339 function getMessage()
01340 {
01341 return $this->message;
01342 }
01343 function setMessage($a_message)
01344 {
01345 $this->message = $a_message;
01346 }
01347 function appendMessage($a_message)
01348 {
01349 if($this->getMessage())
01350 {
01351 $this->message .= "<br /> ";
01352 }
01353 $this->message .= $a_message;
01354 }
01355
01356
01357 }
01358 ?>