00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00035
00036
00037 require_once "class.ilContainer.php";
00038
00039 class ilObjGroup extends ilContainer
00040 {
00044 var $file_obj = null;
00045
00046 var $m_grpStatus;
00047
00048 var $m_roleMemberId;
00049
00050 var $m_roleAdminId;
00051
00058 function ilObjGroup($a_id = 0,$a_call_by_reference = true)
00059 {
00060 global $tree;
00061
00062 $this->tree =& $tree;
00063
00064 $this->type = "grp";
00065 $this->ilObject($a_id,$a_call_by_reference);
00066 $this->setRegisterMode(true);
00067 }
00068
00074 function join($a_user_id, $a_mem_role="")
00075 {
00076 global $rbacadmin;
00077
00078 if (is_array($a_mem_role))
00079 {
00080 foreach ($a_mem_role as $role)
00081 {
00082 $rbacadmin->assignUser($role,$a_user_id, false);
00083 }
00084 }
00085 else
00086 {
00087 $rbacadmin->assignUser($a_mem_role,$a_user_id, false);
00088 }
00089
00090 ilObjUser::updateActiveRoles($a_user_id);
00091 return true;
00092 }
00093
00098 function getDefaultMemberRole()
00099 {
00100 $local_group_Roles = $this->getLocalGroupRoles();
00101
00102 return $local_group_Roles["il_grp_member_".$this->getRefId()];
00103 }
00104
00109 function getDefaultAdminRole()
00110 {
00111 $local_group_Roles = $this->getLocalGroupRoles();
00112
00113 return $local_group_Roles["il_grp_admin_".$this->getRefId()];
00114 }
00115
00122 function addMember($a_user_id, $a_mem_role)
00123 {
00124 global $rbacadmin;
00125
00126 if (isset($a_user_id) && isset($a_mem_role) )
00127 {
00128 $this->join($a_user_id,$a_mem_role);
00129 return true;
00130 }
00131 else
00132 {
00133 $this->ilias->raiseError(get_class($this)."::addMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
00134 return false;
00135 }
00136 }
00137
00142 function getNewRegistrations()
00143 {
00144 $appList = array();
00145 $q = "SELECT * FROM grp_registration WHERE grp_id=".$this->getId();
00146 $res = $this->ilias->db->query($q);
00147 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00148 {
00149 if (ilObject::_exists($row->user_id) &&
00150 ilObject::_lookupType($row->user_id) == "usr")
00151 {
00152 array_push($appList,$row);
00153 }
00154 }
00155
00156 return ($appList) ? $appList : false;
00157 }
00158
00163 function deleteApplicationListEntry($a_userId)
00164 {
00165 $q = "DELETE FROM grp_registration WHERE user_id=".$a_userId." AND grp_id=".$this->getId();
00166 $res = $this->ilias->db->query($q);
00167 }
00168
00175 function leaveGroup()
00176 {
00177 global $rbacadmin, $rbacreview;
00178
00179 $member_ids = $this->getGroupMemberIds();
00180
00181 if (count($member_ids) <= 1 || !in_array($this->ilias->account->getId(), $member_ids))
00182 {
00183 return 2;
00184 }
00185 else
00186 {
00187 if (!$this->isAdmin($this->ilias->account->getId()))
00188 {
00189 $this->leave($this->ilias->account->getId());
00190 $member = new ilObjUser($this->ilias->account->getId());
00191 $member->dropDesktopItem($this->getRefId(), "grp");
00192
00193 return 0;
00194 }
00195 else if (count($this->getGroupAdminIds()) == 1)
00196 {
00197 return 1;
00198 }
00199 }
00200 }
00201
00206 function leave($a_user_id)
00207 {
00208 global $rbacadmin;
00209
00210 $arr_groupRoles = $this->getMemberRoles($a_user_id);
00211
00212 if (is_array($arr_groupRoles))
00213 {
00214 foreach ($arr_groupRoles as $groupRole)
00215 {
00216 $rbacadmin->deassignUser($groupRole, $a_user_id);
00217 }
00218 }
00219 else
00220 {
00221 $rbacadmin->deassignUser($arr_groupRoles, $a_user_id);
00222 }
00223
00224 ilObjUser::updateActiveRoles($a_user_id);
00225
00226 return true;
00227 }
00228
00233 function removeMember($a_user_id, $a_grp_id="")
00234 {
00235 if (isset($a_user_id) && isset($a_grp_id) && $this->isMember($a_user_id))
00236 {
00237 if (count($this->getGroupMemberIds()) > 1)
00238 {
00239 if ($this->isAdmin($a_user_id) && count($this->getGroupAdminIds()) < 2)
00240 {
00241 return "grp_err_administrator_required";
00242 }
00243 else
00244 {
00245 $this->leave($a_user_id);
00246 $member = new ilObjUser($a_user_id);
00247 $member->dropDesktopItem($this->getRefId(), "grp");
00248
00249 return "";
00250 }
00251 }
00252 else
00253 {
00254 return "grp_err_last_member";
00255 }
00256 }
00257 else
00258 {
00259 $this->ilias->raiseError(get_class($this)."::removeMember(): Missing parameters !",$this->ilias->error_obj->WARNING);
00260 }
00261 }
00262
00269 function getGroupMemberIds()
00270 {
00271 global $rbacadmin, $rbacreview;
00272
00273 $usr_arr= array();
00274
00275 $rol = $this->getLocalGroupRoles();
00276
00277 foreach ($rol as $value)
00278 {
00279 foreach ($rbacreview->assignedUsers($value) as $member_id)
00280 {
00281 array_push($usr_arr,$member_id);
00282 }
00283 }
00284
00285 $mem_arr = array_unique($usr_arr);
00286
00287 return $mem_arr ? $mem_arr : array();
00288 }
00289
00297 function getGroupMemberData($a_mem_ids, $active = 1)
00298 {
00299 global $rbacadmin, $rbacreview, $ilBench, $ilDB;
00300
00301 $usr_arr= array();
00302
00303 $q = "SELECT login,firstname,lastname,title,usr_id,last_login ".
00304 "FROM usr_data ".
00305 "WHERE usr_id IN (".implode(',',$a_mem_ids).")";
00306
00307 if (is_numeric($active) && $active > -1)
00308 $q .= "AND active = '$active'";
00309
00310 $r = $ilDB->query($q);
00311
00312 while($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00313 {
00314 $mem_arr[] = array("id" => $row->usr_id,
00315 "login" => $row->login,
00316 "firstname" => $row->firstname,
00317 "lastname" => $row->lastname,
00318 "last_login" => $row->last_login
00319 );
00320 }
00321
00322 return $mem_arr ? $mem_arr : array();
00323 }
00324
00325 function getCountMembers()
00326 {
00327 return count($this->getGroupMemberIds());
00328 }
00329
00336 function getGroupAdminIds($a_grpId="")
00337 {
00338 global $rbacreview;
00339
00340 if (!empty($a_grpId))
00341 {
00342 $grp_id = $a_grpId;
00343 }
00344 else
00345 {
00346 $grp_id = $this->getRefId();
00347 }
00348
00349 $usr_arr = array();
00350 $roles = $this->getDefaultGroupRoles($this->getRefId());
00351
00352 foreach ($rbacreview->assignedUsers($this->getDefaultAdminRole()) as $member_id)
00353 {
00354 array_push($usr_arr,$member_id);
00355 }
00356
00357 return $usr_arr;
00358 }
00359
00365 function getDefaultGroupRoles($a_grp_id="")
00366 {
00367 global $rbacadmin, $rbacreview;
00368
00369 if (strlen($a_grp_id) > 0)
00370 {
00371 $grp_id = $a_grp_id;
00372 }
00373 else
00374 {
00375 $grp_id = $this->getRefId();
00376 }
00377
00378 $rolf = $rbacreview->getRoleFolderOfObject($grp_id);
00379 $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
00380
00381 foreach ($role_arr as $role_id)
00382 {
00383 $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
00384
00385 $grp_Member ="il_grp_member_".$grp_id;
00386 $grp_Admin ="il_grp_admin_".$grp_id;
00387
00388 if (strcmp($role_Obj->getTitle(), $grp_Member) == 0 )
00389 {
00390 $arr_grpDefaultRoles["grp_member_role"] = $role_Obj->getId();
00391 }
00392
00393 if (strcmp($role_Obj->getTitle(), $grp_Admin) == 0)
00394 {
00395 $arr_grpDefaultRoles["grp_admin_role"] = $role_Obj->getId();
00396 }
00397 }
00398
00399 return $arr_grpDefaultRoles;
00400 }
00401
00408 function getLocalGroupRoles($a_translate = false)
00409 {
00410 global $rbacadmin,$rbacreview;
00411
00412 if (empty($this->local_roles))
00413 {
00414 $this->local_roles = array();
00415 $rolf = $rbacreview->getRoleFolderOfObject($this->getRefId());
00416 $role_arr = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"]);
00417
00418 foreach ($role_arr as $role_id)
00419 {
00420 if ($rbacreview->isAssignable($role_id,$rolf["ref_id"]) == true)
00421 {
00422 $role_Obj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
00423
00424 if ($a_translate)
00425 {
00426 $role_name = ilObjRole::_getTranslation($role_Obj->getTitle());
00427 }
00428 else
00429 {
00430 $role_name = $role_Obj->getTitle();
00431 }
00432
00433 $this->local_roles[$role_name] = $role_Obj->getId();
00434 }
00435 }
00436 }
00437
00438 return $this->local_roles;
00439 }
00440
00446 function getGrpStatusClosedTemplateId()
00447 {
00448 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_closed'";
00449 $res = $this->ilias->db->query($q);
00450 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00451
00452 return $row["obj_id"];
00453 }
00454
00460 function getGrpStatusOpenTemplateId()
00461 {
00462 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_status_open'";
00463 $res = $this->ilias->db->query($q);
00464 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00465
00466 return $row["obj_id"];
00467 }
00468
00474 function setRegistrationFlag($a_regFlag="")
00475 {
00476 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00477 $res = $this->ilias->db->query($q);
00478
00479 if (!isset($a_regFlag))
00480 {
00481 $a_regFlag = 0;
00482 }
00483
00484 if ($res->numRows() == 0)
00485 {
00486 $q = "INSERT INTO grp_data (grp_id, register) VALUES(".$this->getId().",".$a_regFlag.")";
00487 $res = $this->ilias->db->query($q);
00488 }
00489 else
00490 {
00491 $q = "UPDATE grp_data SET register=".$a_regFlag." WHERE grp_id=".$this->getId()."";
00492 $res = $this->ilias->db->query($q);
00493 }
00494 }
00495
00501 function getRegistrationFlag()
00502 {
00503 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00504 $res = $this->ilias->db->query($q);
00505 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00506
00507 return $row["register"];
00508 }
00509
00515 function getPassword()
00516 {
00517 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00518 $res = $this->ilias->db->query($q);
00519 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00520
00521 return $row["password"];
00522 }
00523
00529 function setPassword($a_password="")
00530 {
00531 global $ilDB;
00532
00533 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00534 $res = $this->ilias->db->query($q);
00535
00536 if ($res->numRows() == 0)
00537 {
00538 $q = "INSERT INTO grp_data (grp_id, password) VALUES(".$this->getId().",".$ilDB->quote($a_password).")";
00539 $res = $this->ilias->db->query($q);
00540 }
00541 else
00542 {
00543 $q = "UPDATE grp_data SET password=".$ilDB->quote($a_password)." WHERE grp_id=".$this->getId()."";
00544 $res = $this->ilias->db->query($q);
00545 }
00546 }
00547
00553 function setExpirationDateTime($a_date)
00554 {
00555 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00556 $res = $this->ilias->db->query($q);
00557 $date = ilFormat::input2date($a_date);
00558
00559 if ($res->numRows() == 0)
00560 {
00561 $q = "INSERT INTO grp_data (grp_id, expiration) VALUES(".$this->getId().",'".$date."')";
00562 $res = $this->ilias->db->query($q);
00563 }
00564 else
00565 {
00566 $q = "UPDATE grp_data SET expiration='".$date."' WHERE grp_id=".$this->getId()."";
00567 $res = $this->ilias->db->query($q);
00568 }
00569 }
00570
00576 function getExpirationDateTime()
00577 {
00578 $q = "SELECT * FROM grp_data WHERE grp_id='".$this->getId()."'";
00579 $res = $this->ilias->db->query($q);
00580 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00581 $datetime = $row["expiration"];
00582 $date = ilFormat::fdateDB2dateDE($datetime);
00583 $time = substr($row["expiration"], -8);
00584 $datetime = array(0=>$date, 1=>$time);
00585
00586 return $datetime;
00587 }
00588
00589 function getExpirationTimestamp()
00590 {
00591 $query = "SELECT * FROM grp_data WHERE grp_id = '".$this->getId()."'";
00592
00593 $res = $this->ilias->db->query($query);
00594 $row = $res->fetchRow(DB_FETCHMODE_ASSOC);
00595 $datetime = $row["expiration"];
00596
00597 return ($timest = ilFormat::datetime2unixTS($datetime)) ? $timest : 0;
00598 }
00599
00600
00601 function registrationPossible()
00602 {
00603 $datetime = $this->getExpirationDateTime();
00604 $today_date = ilFormat::getDateDE();
00605 $today_time = date("H:i:s");
00606
00607 $ts_exp_date = ilFormat::dateDE2timestamp($datetime[0]);
00608 $ts_today_date = ilFormat::dateDE2timestamp($today_date);
00609
00610 $ts_exp_time = substr($datetime[1], 0, 2).
00611 substr($datetime[1], 3, 2).
00612 substr($datetime[1], 6, 2);
00613
00614 $ts_today_time = substr($today_time, 0, 2).
00615 substr($today_time, 3, 2).
00616 substr($today_time, 6, 2);
00617
00618
00619 if ($ts_exp_date == 0)
00620 {
00621 return true;
00622 }
00623
00624 if ($ts_today_date < $ts_exp_date)
00625 {
00626 return true;
00627 }
00628 elseif (($ts_today_date == $ts_exp_date) and (strcmp($ts_exp_time,$ts_today_time) >= 0))
00629 {
00630 return true;
00631 }
00632 else
00633 {
00634 return false;
00635 }
00636 }
00637
00656 function __setGroupStatus($a_grpStatus)
00657 {
00658 global $rbacadmin, $rbacreview, $rbacsystem;
00659
00660
00661 $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
00662
00663
00664 $arr_parentRoles = $rbacreview->getParentRoleIds($this->getRefId());
00665 $arr_relevantParentRoleIds = array_diff(array_keys($arr_parentRoles),$this->getDefaultGroupRoles());
00666
00667
00668 if ($a_grpStatus == 0 || $a_grpStatus == 1)
00669 {
00670 if ($a_grpStatus == 0)
00671 {
00672 $template_id = $this->getGrpStatusOpenTemplateId();
00673 } else {
00674 $template_id = $this->getGrpStatusClosedTemplateId();
00675 }
00676
00677 $template_ops = $rbacreview->getOperationsOfRole($template_id, 'grp', ROLE_FOLDER_ID);
00678
00679 foreach ($arr_relevantParentRoleIds as $parentRole)
00680 {
00681 if ($rbacreview->isProtected($arr_parentRoles[$parentRole]['parent'],$parentRole))
00682 {
00683 continue;
00684 }
00685
00686 $granted_permissions = array();
00687
00688
00689
00690 $rbacadmin->deleteLocalRole($parentRole,$rolf_data["child"]);
00691
00692
00693
00694
00695
00696
00697 $current_ops = $rbacreview->getRoleOperationsOnObject($parentRole, $this->getRefId());
00698 $rbacadmin->revokePermission($this->getRefId(), $parentRole);
00699 foreach ($template_ops as $template_op)
00700 {
00701 if (in_array($template_op,$current_ops))
00702 {
00703 array_push($granted_permissions,$template_op);
00704 }
00705 }
00706 if (!empty($granted_permissions))
00707 {
00708 $rbacadmin->grantPermission($parentRole, $granted_permissions, $this->getRefId());
00709 }
00710
00711
00712
00713
00714
00715 $rbacadmin->copyRolePermissionIntersection(
00716 $template_id, ROLE_FOLDER_ID,
00717 $parentRole, $arr_parentRoles[$parentRole]['parent'],
00718 $rolf_data["child"], $parentRole
00719 );
00720 $rbacadmin->assignRoleToFolder($parentRole,$rolf_data["child"],"false");
00721 }
00722 }
00723 }
00724
00730 function getGroupStatus()
00731 {
00732 global $rbacsystem,$rbacreview;
00733
00734 $role_folder = $rbacreview->getRoleFolderOfObject($this->getRefId());
00735 $local_roles = $rbacreview->getRolesOfRoleFolder($role_folder["ref_id"]);
00736
00737
00738 $rolf_data = $rbacreview->getRoleFolderOfObject($this->getRefId());
00739
00740 $arr_globalRoles = array_diff($local_roles, $this->getDefaultGroupRoles());
00741
00742
00743 foreach ($arr_globalRoles as $globalRole)
00744 {
00745 $ops_of_role = $rbacreview->getOperationsOfRole($globalRole,"grp", ROLE_FOLDER_ID);
00746
00747 if ($rbacsystem->checkPermission($this->getRefId(), $globalRole ,"join"))
00748 {
00749 return 0;
00750 }
00751 }
00752
00753 return 1;
00754 }
00755
00762 function getMemberRoles($a_user_id)
00763 {
00764 global $rbacadmin, $rbacreview,$ilBench;
00765
00766 $ilBench->start("Group", "getMemberRoles");
00767
00768 $arr_assignedRoles = array();
00769
00770 $arr_assignedRoles = array_intersect($rbacreview->assignedRoles($a_user_id),$this->getLocalGroupRoles());
00771
00772 $ilBench->stop("Group", "getMemberRoles");
00773
00774 return $arr_assignedRoles;
00775 }
00776
00783 function getMemberRolesTitle($a_user_id)
00784 {
00785 global $ilDB,$ilBench;
00786
00787 include_once ('class.ilObjRole.php');
00788
00789 $ilBench->start("Group", "getMemberRolesTitle");
00790
00791 $str_member_roles ="";
00792
00793 $q = "SELECT title ".
00794 "FROM object_data ".
00795 "LEFT JOIN rbac_ua ON object_data.obj_id=rbac_ua.rol_id ".
00796 "WHERE object_data.type = 'role' ".
00797 "AND rbac_ua.usr_id = ".$ilDB->quote($a_user_id)." ".
00798 "AND rbac_ua.rol_id IN (".implode(',',$this->getLocalGroupRoles()).")";
00799
00800 $r = $ilDB->query($q);
00801
00802 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
00803 {
00804
00805 $str_member_roles .= ilObjRole::_getTranslation($row["title"]).", ";
00806 }
00807
00808 $ilBench->stop("Group", "getMemberRolesTitle");
00809
00810 return substr($str_member_roles,0,-2);
00811 }
00812
00819 function setMemberStatus($a_user_id, $a_member_role)
00820 {
00821 if (isset($a_user_id) && isset($a_member_role))
00822 {
00823 $this->removeMember($a_user_id);
00824 $this->addMember($a_user_id, $a_member_role);
00825 }
00826 }
00827
00834 function isMember($a_userId = "")
00835 {
00836 if (strlen($a_userId) == 0)
00837 {
00838 $user_id = $this->ilias->account->getId();
00839 }
00840 else
00841 {
00842 $user_id = $a_userId;
00843 }
00844
00845 if ($this->getType() == "grp")
00846 {
00847 $arr_members = $this->getGroupMemberIds();
00848
00849 if (in_array($user_id, $arr_members))
00850 {
00851 return true;
00852 }
00853 else
00854 {
00855 return false;
00856 }
00857 }
00858 }
00859
00866 function isAdmin($a_userId)
00867 {
00868 global $rbacreview;
00869
00870 $grp_Roles = $this->getDefaultGroupRoles();
00871
00872 if (in_array($a_userId,$rbacreview->assignedUsers($grp_Roles["grp_admin_role"])))
00873 {
00874 return true;
00875 }
00876 else
00877 {
00878 return false;
00879 }
00880 }
00881
00890 function ilClone($a_parent_ref)
00891 {
00892 global $rbacadmin;
00893
00894
00895 $new_ref_id = parent::ilClone($a_parent_ref);
00896
00897
00898 $groupObj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00899
00900
00901 for ($n = 1;$n < 99;$n++)
00902 {
00903 $groupname_copy = $groupObj->getTitle()."_(copy_".$n.")";
00904
00905 if (!ilUtil::groupNameExists($groupname_copy))
00906 {
00907 $groupObj->setTitle($groupname_copy);
00908 $groupObj->update();
00909 break;
00910 }
00911 }
00912
00913
00914 $roles = $groupObj->initDefaultRoles();
00915
00916
00917 $rbacadmin->assignUser($roles[0], $groupObj->getOwner(), "n");
00918 ilObjUser::updateActiveRoles($groupObj->getOwner());
00919
00920
00921 unset($groupObj);
00922 unset($rfoldObj);
00923 unset($roleObj);
00924
00925
00926 return $new_ref_id;
00927 }
00928
00937 function delete()
00938 {
00939
00940 if (!parent::delete())
00941 {
00942 return false;
00943 }
00944
00945 $query = "DELETE FROM grp_data WHERE grp_id=".$this->getId();
00946 $this->ilias->db->query($query);
00947
00948 return true;
00949 }
00950
00956 function initDefaultRoles()
00957 {
00958 global $rbacadmin, $rbacreview;
00959
00960
00961 $rfoldObj =& $this->createRoleFolder();
00962
00963
00964
00965 $roleObj = $rfoldObj->createRole("il_grp_admin_".$this->getRefId(),"Groupadmin of group obj_no.".$this->getId());
00966 $this->m_roleAdminId = $roleObj->getId();
00967
00968
00969 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_admin'";
00970 $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
00971 $rbacadmin->copyRolePermission($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
00972
00973
00974 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
00975 $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
00976
00977
00978
00979
00980
00981
00982
00983 $roleObj = $rfoldObj->createRole("il_grp_member_".$this->getRefId(),"Groupmember of group obj_no.".$this->getId());
00984 $this->m_roleMemberId = $roleObj->getId();
00985
00986
00987 $q = "SELECT obj_id FROM object_data WHERE type='rolt' AND title='il_grp_member'";
00988 $r = $this->ilias->db->getRow($q, DB_FETCHMODE_OBJECT);
00989 $rbacadmin->copyRolePermission($r->obj_id,ROLE_FOLDER_ID,$rfoldObj->getRefId(),$roleObj->getId());
00990
00991
00992 $ops = $rbacreview->getOperationsOfRole($roleObj->getId(),"grp",$rfoldObj->getRefId());
00993 $rbacadmin->grantPermission($roleObj->getId(),$ops,$this->getRefId());
00994
00995
00996
00997
00998
00999 unset($rfoldObj);
01000 unset($roleObj);
01001
01002 $roles[] = $this->m_roleAdminId;
01003 $roles[] = $this->m_roleMemberId;
01004
01005
01006
01007
01008 $this->__setGroupStatus($_POST["group_status"]);
01009
01010 return $roles ? $roles : array();
01011 }
01012
01023 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
01024 {
01025 global $tree;
01026
01027 $parent_id = (int) $tree->getParentId($a_node_id);
01028
01029 if ($parent_id != 0)
01030 {
01031 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01032 $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
01033 }
01034
01035 return true;
01036 }
01037
01038
01039 function exportXML()
01040 {
01041 include_once 'classes/class.ilGroupXMLWriter.php';
01042
01043 $xml_writer = new ilGroupXMLWriter($this);
01044 $xml_writer->start();
01045
01046 $xml = $xml_writer->getXML();
01047
01048 $name = time().'__'.$this->ilias->getSetting('inst_id').'__grp_'.$this->getId();
01049
01050 $this->__initFileObject();
01051
01052 $this->file_obj->addGroupDirectory();
01053 $this->file_obj->addDirectory($name);
01054 $this->file_obj->writeToFile($xml,$name.'/'.$name.'.xml');
01055 $this->file_obj->zipFile($name,$name.'.zip');
01056 $this->file_obj->deleteDirectory($name);
01057
01058 return true;
01059 }
01060
01061 function deleteExportFiles($a_files)
01062 {
01063 $this->__initFileObject();
01064
01065 foreach($a_files as $file)
01066 {
01067 $this->file_obj->deleteFile($file);
01068 }
01069 return true;
01070 }
01071
01072 function downloadExportFile($file)
01073 {
01074 $this->__initFileObject();
01075
01076 if($abs_name = $this->file_obj->getExportFile($file))
01077 {
01078 ilUtil::deliverFile($abs_name,$file);
01079
01080 }
01081 return false;
01082 }
01083
01092 function _importFromXMLString($xml,$parent_id)
01093 {
01094 include_once 'classes/class.ilGroupImportParser.php';
01095
01096 $import_parser = new ilGroupImportParser($xml,$parent_id);
01097
01098 return $import_parser->startParsing();
01099 }
01100
01108 function _importFromFile($file,$parent_id)
01109 {
01110 global $lng;
01111
01112 include_once 'classes/class.ilFileDataGroup.php';
01113
01114 $file_obj = new ilFileDataGroup(null);
01115 $file_obj->addImportDirectory();
01116 $file_obj->createImportFile($_FILES["xmldoc"]["tmp_name"],$_FILES['xmldoc']['name']);
01117 $file_obj->unpackImportFile();
01118
01119 if(!$file_obj->validateImportFile())
01120 {
01121 return false;
01122 }
01123 return ilObjGroup::_importFromXMLString(file_get_contents($file_obj->getImportFile()),$parent_id);
01124 }
01125
01134 function _search(&$a_search_obj)
01135 {
01136 global $ilBench;
01137
01138
01139
01140 $where_condition = $a_search_obj->getWhereCondition("like",array("title","description"));
01141 $in = $a_search_obj->getInStatement("ore.ref_id");
01142
01143 $query = "SELECT ore.ref_id AS ref_id FROM object_data AS od, object_reference AS ore ".
01144 $where_condition." ".
01145 $in." ".
01146 "AND od.obj_id = ore.obj_id ".
01147 "AND od.type = 'grp' ";
01148
01149 $ilBench->start("Search", "ilObjGroup_search");
01150 $res = $a_search_obj->ilias->db->query($query);
01151 $ilBench->stop("Search", "ilObjGroup_search");
01152
01153 $counter = 0;
01154
01155 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01156 {
01157 $result_data[$counter++]["id"] = $row->ref_id;
01158 #$result_data[$counter]["link"] = "group.php?cmd=view&ref_id=".$row->ref_id;
01159 #$result_data[$counter++]["target"] = "";
01160 }
01161
01162 return $result_data ? $result_data : array();
01163 }
01164
01173 function _getLinkToObject($a_id)
01174 {
01175 return array("repository.php?ref_id=".$a_id."&set_mode=flat&cmdClass=ilobjgroupgui","");
01176 }
01177
01178 function _lookupIdByTitle($a_title)
01179 {
01180 global $ilDB;
01181
01182 $query = "SELECT * FROM object_data WHERE title = '".$a_title."' AND type = 'grp'";
01183 $res = $ilDB->query($query);
01184 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01185 {
01186 return $row->obj_id;
01187 }
01188 return 0;
01189 }
01190
01191
01192 function isUserRegistered($a_user_id = 0)
01193 {
01194 global $rbacsystem;
01195
01196
01197
01198
01199
01200
01201
01202 if (!$this->isMember() or !$rbacsystem->checkAccess("join", $this->ref_id))
01203 {
01204 return false;
01205 }
01206
01207 return true;
01208 }
01209
01210 function _isMember($a_user_id,$a_ref_id)
01211 {
01212 global $rbacreview;
01213
01214 $rolf = $rbacreview->getRoleFolderOfObject($a_ref_id);
01215 $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
01216 $user_roles = $rbacreview->assignedRoles($a_user_id);
01217
01218 if (!array_intersect($local_roles,$user_roles))
01219 {
01220 return false;
01221 }
01222
01223 return true;
01224 }
01225
01226
01227 function __initFileObject()
01228 {
01229 if($this->file_obj)
01230 {
01231 return $this->file_obj;
01232 }
01233 else
01234 {
01235 include_once 'classes/class.ilFileDataGroup.php';
01236
01237 return $this->file_obj = new ilFileDataGroup($this);
01238 }
01239 }
01240
01241 function _goto($a_target)
01242 {
01243 global $ilAccess, $ilErr, $lng;
01244
01245 if ($ilAccess->checkAccess("read", "", $a_target))
01246 {
01247 $_GET["cmd"] = "frameset";
01248 $_GET["ref_id"] = $a_target;
01249 }
01250 else
01251 {
01252 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
01253 }
01254 }
01255
01256 }
01257 ?>