• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

course/classes/class.ilCourseMembers.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00035 class ilCourseMembers
00036 {
00037         var $course_obj;
00038         var $ilErr;
00039         var $ilDB;
00040         var $lng;
00041 
00042         var $member_data;
00043         var $subscribers;
00044 
00045         function ilCourseMembers(&$course_obj)
00046         {
00047                 global $ilErr,$lng,$ilDB;
00048 
00049                 $this->STATUS_NOTIFY = 1;
00050                 $this->STATUS_NO_NOTIFY = 2;
00051                 $this->STATUS_BLOCKED = 3;
00052                 $this->STATUS_UNBLOCKED = 4;
00053 
00054                 $this->NOTIFY_DISMISS_SUBSCRIBER = 1;
00055                 $this->NOTIFY_ACCEPT_SUBSCRIBER = 2;
00056                 $this->NOTIFY_DISMISS_MEMBER = 3;
00057                 $this->NOTIFY_BLOCK_MEMBER = 4;
00058                 $this->NOTIFY_UNBLOCK_MEMBER = 5;
00059                 $this->NOTIFY_ACCEPT_USER = 6;
00060                 $this->NOTIFY_ADMINS = 7;
00061                 $this->NOTIFY_STATUS_CHANGED = 8;
00062                 $this->NOTIFY_SUBSCRIPTION_REQUEST = 9;
00063 
00064 
00065                 $this->ROLE_ADMIN = 1;
00066                 $this->ROLE_MEMBER = 2;
00067                 $this->ROLE_TUTOR = 3;
00068 
00069                 $this->ilErr =& $ilErr;
00070                 $this->ilDB =& $ilDB;
00071                 $this->db =& $ilDB;
00072 
00073                 $this->lng =& $lng;
00074                 $this->lng->loadLanguageModule("search");
00075 
00076                 $this->course_obj =& $course_obj;
00077 
00078                 $this->__purgeDeleted();
00079 
00080         }
00081 
00082         function addDesktopItem($a_usr_id)
00083         {
00084                 $user_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id);
00085 
00086                 if(!$user_obj->isDesktopItem($this->course_obj->getRefId(),'crs'))
00087                 {
00088                         $user_obj->addDesktopItem($this->course_obj->getRefId(),'crs');
00089                 }
00090                 unset($user_obj);
00091 
00092                 return true;
00093         }
00094         function dropDesktopItem($a_usr_id)
00095         {
00096                 $user_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id);
00097 
00098                 if($user_obj->isDesktopItem($this->course_obj->getRefId(),'crs'))
00099                 {
00100                         $user_obj->dropDesktopItem($this->course_obj->getRefId(),'crs');
00101                 }
00102                 unset($user_obj);
00103 
00104                 return true;
00105         }
00106 
00107         function add(&$user_obj,$a_role,$a_status = 0,$a_passed = 0)
00108         {
00109                 global $rbacadmin;
00110 
00111                 switch($a_role)
00112                 {
00113                         case $this->ROLE_MEMBER:
00114                                 if($a_status and ($a_status == $this->STATUS_BLOCKED or $a_status == $this->STATUS_UNBLOCKED))
00115                                 {
00116                                         $status = $a_status;
00117                                 }
00118                                 else if($a_status)
00119                                 {
00120                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00121                                 }
00122                                 else
00123                                 {
00124                                         $status = $this->__getDefaultMemberStatus();
00125                                 }
00126                                 $role = $this->course_obj->getDefaultMemberRole();
00127                                 $passed = $a_passed;
00128 
00129                                 $this->addDesktopItem($user_obj->getId());
00130                                 break;
00131 
00132                         case $this->ROLE_ADMIN:
00133                                 if($a_status and ($a_status == $this->STATUS_NOTIFY or $a_status == $this->STATUS_NO_NOTIFY))
00134                                 {
00135                                         $status = $a_status;
00136                                 }
00137                                 else if($a_status)
00138                                 {
00139                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00140                                 }
00141                                 else
00142                                 {
00143                                         $status = $this->__getDefaultAdminStatus();
00144                                 }
00145                                 $role = $this->course_obj->getDefaultAdminRole();
00146                                 $passed = $a_passed;
00147                                 $this->addDesktopItem($user_obj->getId());
00148                                 break;
00149 
00150                         case $this->ROLE_TUTOR:
00151                                 if($a_status and ($a_status == $this->STATUS_NOTIFY or $a_status == $this->STATUS_NO_NOTIFY))
00152                                 {
00153                                         $status = $a_status;
00154                                 }
00155                                 else if($a_status)
00156                                 {
00157                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00158                                 }
00159                                 else
00160                                 {
00161                                         $status = $this->__getDefaultTutorStatus();
00162                                 }
00163                                 $role = $this->course_obj->getDefaultTutorRole();
00164                                 $passed = $a_passed;
00165                                 $this->addDesktopItem($user_obj->getId());
00166                                 break;
00167                                 
00168                 }
00169                 // 1. create entry
00170                 $this->__createMemberEntry($user_obj->getId(),$a_role,$status,$passed);
00171 
00172                 $rbacadmin->assignUser($role,$user_obj->getId());
00173                 ilObjUser::updateActiveRoles($user_obj->getId());
00174 
00175                 return true;
00176         }
00177 
00178         function update($a_usr_id,$a_role,$a_status,$a_passed)
00179         {
00180                 global $rbacadmin;
00181 
00182                 $this->__read($a_usr_id);
00183 
00184                 switch($a_role)
00185                 {
00186                         case $this->ROLE_ADMIN:
00187                                 if($a_status != $this->STATUS_NOTIFY and $a_status != $this->STATUS_NO_NOTIFY)
00188                                 {
00189                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00190                                 }
00191                                 break;
00192 
00193                         case $this->ROLE_TUTOR:
00194                                 if($a_status != $this->STATUS_NOTIFY and $a_status != $this->STATUS_NO_NOTIFY)
00195                                 {
00196                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00197                                 }
00198                                 break;
00199 
00200                         case $this->ROLE_MEMBER:
00201                                 if($a_status != $this->STATUS_BLOCKED and $a_status != $this->STATUS_UNBLOCKED)
00202                                 {
00203                                         $this->ilErr->raiseError($this->lng->txt("crs_status_not_allowed",$this->ilErr->MESSAGE));
00204                                 }
00205                                 $this->addDesktopItem($a_usr_id);
00206                                 break;
00207                                 
00208                         default:
00209                                 $this->ilErr->raiseError($this->lng->txt("crs_role_not_allowed",$this->ilErr->MESSAGE));
00210                                 break;
00211                 }
00212 
00213                 // UPDATE RBAC ROLES
00214 
00215                 // deassign old roles
00216                 switch($this->member_data["role"])
00217                 {
00218                         case $this->ROLE_ADMIN:
00219                                 $rbacadmin->deassignUser($this->course_obj->getDefaultAdminRole(),$a_usr_id);
00220                                 break;
00221 
00222                         case $this->ROLE_TUTOR:
00223                                 $rbacadmin->deassignUser($this->course_obj->getDefaultTutorRole(),$a_usr_id);
00224                                 break;
00225 
00226                         case $this->ROLE_MEMBER:
00227                                 $rbacadmin->deassignUser($this->course_obj->getDefaultMemberRole(),$a_usr_id);
00228                                 break;
00229                 }
00230                 // assign new role
00231                 switch($a_role)
00232                 {
00233                         case $this->ROLE_ADMIN:
00234                                 $rbacadmin->assignUser($this->course_obj->getDefaultAdminRole(),$a_usr_id);
00235                                 break;
00236 
00237                         case $this->ROLE_TUTOR:
00238                                 $rbacadmin->assignUser($this->course_obj->getDefaultTutorRole(),$a_usr_id);
00239                                 break;
00240                                 
00241                         case $this->ROLE_MEMBER:
00242                                 if($a_status != $this->STATUS_BLOCKED)
00243                                 {
00244                                         $rbacadmin->assignUser($this->course_obj->getDefaultMemberRole(),$a_usr_id);
00245                                 }
00246                                 break;
00247                 }
00248 
00249                 // Update active roles
00250                 ilObjUser::updateActiveRoles($a_usr_id);
00251 
00252                 $query = "UPDATE crs_members ".
00253                         "SET role = '".$a_role."', ".
00254                         "status = '".$a_status."', ".
00255                         "passed = '".$a_passed."' ".
00256                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00257                         "AND usr_id = '".$a_usr_id."'";
00258                 $res = $this->ilDB->query($query);
00259 
00260                 return true;
00261         }
00262 
00263 
00264         function deleteAllEntries()
00265         {
00266                 $query = "DELETE FROM crs_members ".
00267                         "WHERE obj_id = '".$this->course_obj->getId()."'";
00268 
00269                 $this->ilDB->query($query);
00270 
00271                 $query = "DELETE FROM crs_subscribers ".
00272                         "WHERE obj_id = '".$this->course_obj->getId()."'";
00273 
00274                 $this->ilDB->query($query);
00275 
00276                 return true;
00277         }
00278 
00279         function deleteMembers($a_usr_ids)
00280         {
00281                 if(!is_array($a_usr_ids) or !count($a_usr_ids))
00282                 {
00283                         $this->course_obj->setMessage("");
00284                         $this->course_obj->appendMessage($this->lng->txt("no_usr_ids_given"));
00285                         
00286                         return false;
00287                 }
00288                 foreach($a_usr_ids as $id)
00289                 {
00290                         if(!$this->delete($id))
00291                         {
00292                                 $this->course_obj->appendMessage($this->lng->txt("error_delete_member"));
00293                                         
00294                                 return false;
00295                         }
00296                 }
00297                 return true;
00298         }
00299 
00300         function delete($a_usr_id)
00301         {
00302                 global $rbacadmin;
00303 
00304                 if(!$this->__read($a_usr_id))
00305                 {
00306                         return true;
00307                 }
00308 
00309                 switch($this->member_data["role"])
00310                 {
00311                         case $this->ROLE_ADMIN:
00312                                 $role = $this->course_obj->getDefaultAdminRole();
00313                                 break;
00314 
00315 
00316                         case $this->ROLE_TUTOR:
00317                                 $role = $this->course_obj->getDefaultTutorRole();
00318                                 break;
00319                                 
00320                         case $this->ROLE_MEMBER:
00321                                 $role = $this->course_obj->getDefaultMemberRole();
00322                                 break;
00323                 }
00324 
00325                 $this->dropDesktopItem($a_usr_id);
00326                 $rbacadmin->deassignUser($role,$a_usr_id);
00327                 ilObjUser::updateActiveRoles($a_usr_id);
00328 
00329                 
00330                 $query = "DELETE FROM crs_members ".
00331                         "WHERE usr_id = '".$a_usr_id."' ".
00332                         "AND obj_id = '".$this->course_obj->getId()."'";
00333 
00334                 $res = $this->ilDB->query($query);
00335 
00336                 return true;
00337         }
00338 
00339 
00340         /* 
00341          * Delete user entries called from ilObjUser->delete() 
00342          */
00343         function _deleteUser($a_usr_id)
00344         {
00345                 global $ilDB;
00346 
00347                 $query = "DELETE FROM crs_members WHERE usr_id = '".$a_usr_id."'";
00348                 $ilDB->query($query);
00349 
00350                 $query = "DELETE FROM crs_subscribers WHERE usr_id = '".$a_usr_id."'";
00351                 $ilDB->query($query);
00352 
00353                 include_once './course/classes/class.ilCourseWaitingList.php';
00354                 ilCourseWaitingList::_deleteUser($a_usr_id);
00355         }
00356                 
00357         function getAssignedUsers()
00358         {
00359                 // ALL MEMBERS AND ADMINS
00360                 return array_merge($this->getMembers(),$this->getAdmins(),$this->getTutors());
00361         }
00362         function getUserData($a_usr_id)
00363         {
00364                 if(!$this->__read($a_usr_id))
00365                 {
00366                         return $a_usr_id;
00367                 }
00368                 return $this->member_data;
00369         }
00370 
00371         function getCountMembers()
00372         {
00373                 return count($this->getMembers(false));
00374         }
00375 
00376         function getMembers($a_all = true)
00377         {
00378                 $query = "SELECT cs.usr_id FROM crs_members as cs ".
00379                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00380                         "AND role = '".$this->ROLE_MEMBER."'";
00381 
00382                 if(!$a_all)
00383                 {
00384                         $query .= " AND status = '".$this->STATUS_UNBLOCKED."'";
00385                 }
00386 
00387                 $res = $this->ilDB->query($query);
00388                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00389                 {
00390                         $usr_ids[] = $row->usr_id;
00391                 }
00392                 return $usr_ids ? $usr_ids : array();
00393         }
00394         function getAdmins()
00395         {
00396                 $query = "SELECT cs.usr_id FROM crs_members as cs ".
00397                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00398                         "AND role = '".$this->ROLE_ADMIN."'";
00399 
00400                 $res = $this->ilDB->query($query);
00401                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00402                 {
00403                         $usr_ids[] = $row->usr_id;
00404                 }
00405                 return $usr_ids ? $usr_ids : array();
00406         }
00407         function getTutors()
00408         {
00409                 $query = "SELECT cs.usr_id FROM crs_members as cs ".
00410                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00411                         "AND role = '".$this->ROLE_TUTOR."'";
00412 
00413                 $res = $this->ilDB->query($query);
00414                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00415                 {
00416                         $usr_ids[] = $row->usr_id;
00417                 }
00418                 return $usr_ids ? $usr_ids : array();
00419         }
00420 
00421         function isAdmin($a_usr_id)
00422         {
00423                 $this->__read($a_usr_id);
00424 
00425                 return $this->member_data["role"] == $this->ROLE_ADMIN ? true : false;
00426         }
00427         function isMember($a_usr_id)
00428         {
00429                 $this->__read($a_usr_id);
00430 
00431                 return $this->member_data["role"] == $this->ROLE_MEMBER ? true : false;
00432         }
00433         function isTutor($a_usr_id)
00434         {
00435                 $this->__read($a_usr_id);
00436 
00437                 return $this->member_data["role"] == $this->ROLE_TUTOR ? true : false;
00438         }
00439         function isAssigned($a_usr_id)
00440         {
00441                 return $this->isAdmin($a_usr_id) || $this->isMember($a_usr_id) || $this->isTutor($a_usr_id);
00442         }
00443         function isBlocked($a_usr_id)
00444         {
00445                 $this->__read($a_usr_id);
00446                 
00447                 return $this->member_data["status"] == $this->STATUS_BLOCKED ? true : false;
00448         }
00455         function _isBlocked($a_obj_id,$a_usr_id)
00456         {
00457                 global $ilDB;
00458 
00459                 $query = "SELECT * FROM crs_members ".
00460                         "WHERE usr_id = '".$a_usr_id."' ".
00461                         "AND obj_id = '".$a_obj_id."'";
00462 
00463                 $res = $ilDB->query($query);
00464                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00465                 {
00466                         return $row->status == 3 ? true : false;
00467                 }
00468                 return false;
00469         }
00470         
00471 
00472         function hasAccess($a_usr_id)
00473         {
00474                 global $rbacsystem;
00475 
00476                 #if($rbacsystem->checkAccess('write',$this->course_obj->getRefId()))
00477                 #{
00478                 #       return true;
00479                 #}
00480 
00481                 return $this->isAssigned($a_usr_id) && !$this->isBlocked($a_usr_id) ? true : false;
00482         }
00483 
00484         function getCountPassed()
00485         {
00486                 $query = "SELECT * FROM crs_members ".
00487                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00488                         "AND passed = 1";
00489 
00490                 $res = $this->ilDB->query($query);
00491                 
00492                 return $res->numRows() ? $res->numRows() : 0;
00493         }
00494 
00495         function checkLastAdmin($a_usr_ids)
00496         {
00497                 foreach($this->getAdmins() as $admin_id)
00498                 {
00499                         if(!in_array($admin_id,$a_usr_ids))
00500                         {
00501                                 return true;
00502                         }
00503                 }
00504                 return false;
00505         }
00506 
00507         // METHODS FOR NEW REGISTRATIONS
00508         function getSubscribers()
00509         {
00510                 $this->__readSubscribers();
00511 
00512                 return $this->subscribers;
00513         }
00514 
00515         function getCountSubscribers()
00516         {
00517                 return count($this->getSubscribers());
00518         }
00519 
00520         function getSubscriberData($a_usr_id)
00521         {
00522                 return $this->__readSubscriberData($a_usr_id);
00523         }
00524         
00525 
00526 
00527         function assignSubscribers($a_usr_ids)
00528         {
00529                 if(!is_array($a_usr_ids) or !count($a_usr_ids))
00530                 {
00531                         return false;
00532                 }
00533                 foreach($a_usr_ids as $id)
00534                 {
00535                         if(!$this->assignSubscriber($id))
00536                         {
00537                                 return false;
00538                         }
00539                 }
00540                 return true;
00541         }
00542 
00543         function assignSubscriber($a_usr_id,$a_role = 0,$a_status = 0)
00544         {
00545                 $a_role = $a_role ? $a_role : $this->ROLE_MEMBER;
00546                 $a_status = $a_status ? $a_status : $this->STATUS_UNBLOCKED;
00547 
00548                 $this->course_obj->setMessage("");
00549 
00550 
00551                 if(!$this->isSubscriber($a_usr_id))
00552                 {
00553                         $this->course_obj->appendMessage($this->lng->txt("crs_user_notsubscribed"));
00554 
00555                         return false;
00556                 }
00557                 if($this->isAssigned($a_usr_id))
00558                 {
00559                         $tmp_obj = ilObjectFactory::getInstanceByObjId($a_usr_id);
00560                         $this->course_obj->appendMessage($tmp_obj->getLogin().": ".$this->lng->txt("crs_user_already_assigned"));
00561                         
00562                         return false;
00563                 }
00564 
00565                 if(!$tmp_obj =& ilObjectFactory::getInstanceByObjId($a_usr_id))
00566                 {
00567                         $this->course_obj->appendMessage($this->lng->txt("crs_user_not_exists"));
00568 
00569                         return false;
00570                 }
00571 
00572                 $this->add($tmp_obj,$a_role,$a_status);
00573                 $this->deleteSubscriber($a_usr_id);
00574 
00575                 return true;
00576         }
00577 
00578         function autoFillSubscribers()
00579         {
00580                 $this->__readSubscribers();
00581 
00582                 $counter = 0;
00583                 foreach($this->subscribers as $subscriber)
00584                 {
00585                         if($this->course_obj->getSubscriptionMaxMembers() and
00586                            $this->course_obj->getSubscriptionMaxMembers() <= $this->getCountMembers())
00587                         {
00588                                 return $counter;
00589                         }
00590                         if(!$this->assignSubscriber($subscriber))
00591                         {
00592                                 continue;
00593                         }
00594                         else
00595                         {
00596                                 $this->sendNotification($this->NOTIFY_ACCEPT_SUBSCRIBER,$subscriber);
00597                         }
00598                         ++$counter;
00599                 }
00600                 
00601                 return $counter;
00602         }
00603 
00604         function addSubscriber($a_usr_id)
00605         {
00606                 $query = "INSERT INTO crs_subscribers ".
00607                         " VALUES ('".$a_usr_id."','".$this->course_obj->getId()."','".time()."')";
00608 
00609                 $res = $this->ilDB->query($query);
00610 
00611                 return true;
00612         }
00613 
00614         function updateSubscriptionTime($a_usr_id,$a_subtime)
00615         {
00616                 $query = "UPDATE crs_subscribers ".
00617                         "SET sub_time = '".ilUtil::prepareDBString($a_subtime)."' ".
00618                         "WHERE usr_id = '".ilUtil::prepareDBString($a_usr_id)."' ".
00619                         "AND obj_id = '".$this->course_obj->getId()."'";
00620 
00621                 $this->db->query($query);
00622 
00623                 return true;
00624         }
00625 
00626         function deleteSubscriber($a_usr_id)
00627         {
00628                 $query = "DELETE FROM crs_subscribers ".
00629                         "WHERE usr_id = '".$a_usr_id."' ".
00630                         "AND obj_id = '".$this->course_obj->getId()."'";
00631 
00632                 $res = $this->ilDB->query($query);
00633 
00634                 return true;
00635         }
00636 
00637         function deleteSubscribers($a_usr_ids)
00638         {
00639                 if(!is_array($a_usr_ids) or !count($a_usr_ids))
00640                 {
00641                         $this->course_obj->setMessage("");
00642                         $this->course_obj->appendMessage($this->lng->txt("no_usr_ids_given"));
00643                         
00644                         return false;
00645                 }
00646                 foreach($a_usr_ids as $id)
00647                 {
00648                         if(!$this->deleteSubscriber($id))
00649                         {
00650                                 $this->course_obj->appendMessage($this->lng->txt("error_delete_subscriber"));
00651                                         
00652                                 return false;
00653                         }
00654                 }
00655                 return true;
00656         }
00657         function isSubscriber($a_usr_id)
00658         {
00659                 $query = "SELECT * FROM crs_subscribers ".
00660                         "WHERE usr_id = '".$a_usr_id."' ".
00661                         "AND obj_id = '".$this->course_obj->getId()."'";
00662 
00663                 $res = $this->ilDB->query($query);
00664 
00665                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00666                 {
00667                         return true;
00668                 }
00669                 return false;
00670         }
00671 
00672         /*
00673          * Static method
00674          */
00675         function _isSubscriber($a_obj_id,$a_usr_id)
00676         {
00677                 global $ilDB;
00678 
00679                 $query = "SELECT * FROM crs_subscribers ".
00680                         "WHERE usr_id = '".$a_usr_id."' ".
00681                         "AND obj_id = '".$a_obj_id."'";
00682 
00683                 $res = $ilDB->query($query);
00684 
00685                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00686                 {
00687                         return true;
00688                 }
00689                 return false;
00690         }
00691 
00692         function sendNotification($a_type, $a_usr_id)
00693         {
00694                 $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id,false);
00695 
00696                 $link = ("\n\n".$this->lng->txt('crs_mail_permanent_link'));
00697                 $link .= ("\n\n".ILIAS_HTTP_PATH."/goto.php?target=crs_".$this->course_obj->getRefId()."&client_id=".CLIENT_ID);
00698                 
00699 
00700                 switch($a_type)
00701                 {
00702                         case $this->NOTIFY_DISMISS_SUBSCRIBER:
00703                                 $subject = $this->lng->txt("crs_reject_subscriber");
00704                                 $body = $this->lng->txt("crs_reject_subscriber_body");
00705                                 break;
00706                                 
00707                         case $this->NOTIFY_ACCEPT_SUBSCRIBER:
00708                                 $subject = $this->lng->txt("crs_accept_subscriber");
00709                                 $body = $this->lng->txt("crs_accept_subscriber_body");
00710                                 $body .= $link;
00711                                 break;
00712                         case $this->NOTIFY_DISMISS_MEMBER:
00713                                 $subject = $this->lng->txt("crs_dismiss_member");
00714                                 $body = $this->lng->txt("crs_dismiss_member_body");
00715                                 break;
00716                         case $this->NOTIFY_BLOCK_MEMBER:
00717                                 $subject = $this->lng->txt("crs_blocked_member");
00718                                 $body = $this->lng->txt("crs_blocked_member_body");
00719                                 break;
00720                         case $this->NOTIFY_UNBLOCK_MEMBER:
00721                                 $subject = $this->lng->txt("crs_unblocked_member");
00722                                 $body = $this->lng->txt("crs_unblocked_member_body");
00723                                 $body .= $link;
00724                                 break;
00725                         case $this->NOTIFY_ACCEPT_USER:
00726                                 $subject = $this->lng->txt("crs_added_member");
00727                                 $body = $this->lng->txt("crs_added_member_body");
00728                                 $body .= $link;
00729                                 break;
00730                         case $this->NOTIFY_STATUS_CHANGED:
00731                                 $subject = $this->lng->txt("crs_status_changed");
00732                                 $body = $this->__buildStatusBody($tmp_user);
00733                                 $body .= $link;
00734                                 break;
00735 
00736                         case $this->NOTIFY_SUBSCRIPTION_REQUEST:
00737                                 $this->sendSubscriptionRequestToAdmins($a_usr_id);
00738                                 return true;
00739                                 break;
00740 
00741                         case $this->NOTIFY_ADMINS:
00742                                 $this->sendNotificationToAdmins($a_usr_id);
00743 
00744                                 return true;
00745                                 break;
00746                 }
00747                 $subject = sprintf($subject, $this->course_obj->getTitle());
00748                 $body = sprintf($body, $this->course_obj->getTitle());
00749 
00750                 include_once("./classes/class.ilFormatMail.php");
00751 
00752                 $mail = new ilFormatMail($_SESSION["AccountId"]);
00753                 $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('normal'));
00754 
00755                 unset($tmp_user);
00756                 return true;
00757         }
00758 
00759         function sendNotificationToAdmins($a_usr_id)
00760         {
00761                 if(!$this->course_obj->getSubscriptionNotify())
00762                 {
00763                         return true;
00764                 }
00765 
00766 
00767                 include_once("./classes/class.ilFormatMail.php");
00768 
00769                 $mail =& new ilFormatMail($a_usr_id);
00770                 $subject = sprintf($this->lng->txt("crs_new_subscription"),$this->course_obj->getTitle());
00771                 $body = sprintf($this->lng->txt("crs_new_subscription_body"),$this->course_obj->getTitle());
00772 
00773                 $query = "SELECT usr_id FROM crs_members ".
00774                         "WHERE status = '".$this->STATUS_NOTIFY."' ".
00775                         "AND obj_id = '".$this->course_obj->getId()."'";
00776 
00777                 $res = $this->ilDB->query($query);
00778                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00779                 {
00780                         $tmp_user =& ilObjectFactory::getInstanceByObjId($row->usr_id,false);
00781 
00782                         $message = $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('normal'));
00783                         unset($tmp_user);
00784                 }
00785                 unset($mail);
00786 
00787                 return true;
00788         }
00789         function sendSubscriptionRequestToAdmins($a_usr_id)
00790         {
00791                 if(!$this->course_obj->getSubscriptionNotify())
00792                 {
00793                         return true;
00794                 }
00795 
00796 
00797                 include_once("./classes/class.ilFormatMail.php");
00798 
00799                 $mail =& new ilFormatMail($a_usr_id);
00800                 $subject = sprintf($this->lng->txt("crs_new_subscription_request"),$this->course_obj->getTitle());
00801                 $body = sprintf($this->lng->txt("crs_new_subscription_request_body"),$this->course_obj->getTitle());
00802                 $body .= ("\n\n".$this->lng->txt('crs_new_subscription_request_body2'));
00803                 $body .= ("\n\n".ILIAS_HTTP_PATH."/goto.php?target=crs_".$this->course_obj->getRefId()."&client_id=".CLIENT_ID);
00804 
00805                 $query = "SELECT usr_id FROM crs_members ".
00806                         "WHERE status = '".$this->STATUS_NOTIFY."' ".
00807                         "AND obj_id = '".$this->course_obj->getId()."'";
00808 
00809                 $res = $this->ilDB->query($query);
00810                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00811                 {
00812                         $tmp_user =& ilObjectFactory::getInstanceByObjId($row->usr_id,false);
00813                         $message = $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('normal'));
00814                         unset($tmp_user);
00815                 }
00816                 unset($mail);
00817 
00818                 return true;
00819         }
00820         function sendUnsubscribeNotificationToAdmins($a_usr_id)
00821         {
00822                 if(!$this->course_obj->getSubscriptionNotify())
00823                 {
00824                         return true;
00825                 }
00826 
00827                 include_once("./classes/class.ilFormatMail.php");
00828 
00829                 $mail =& new ilFormatMail($a_usr_id);
00830                 $subject = sprintf($this->lng->txt("crs_cancel_subscription"), $this->course_obj->getTitle());
00831                 $body = sprintf($this->lng->txt("crs_cancel_subscription_body"), $this->course_obj->getTitle());
00832 
00833                 $query = "SELECT usr_id FROM crs_members ".
00834                         "WHERE status = '".$this->STATUS_NOTIFY."' ".
00835                         "AND obj_id = '".$this->course_obj->getId()."'";
00836 
00837                 $res = $this->ilDB->query($query);
00838                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00839                 {
00840                         $tmp_user =& ilObjectFactory::getInstanceByObjId($row->usr_id,false);
00841 
00842                         $message = $mail->sendMail($tmp_user->getLogin(),'','',$subject,$body,array(),array('normal'));
00843                         unset($tmp_user);
00844                 }
00845                 unset($mail);
00846 
00847                 return true;
00848         }
00849 
00850         // PRIVATE METHODS
00851         function __getDefaultAdminStatus()
00852         {
00853                 return $this->STATUS_NOTIFY;
00854         }
00855         function __getDefaultMemberStatus()
00856         {
00857                 return $this->STATUS_UNBLOCKED;
00858         }
00859         function __getDefaultTutorStatus()
00860         {
00861                 return $this->STATUS_NO_NOTIFY;
00862         }
00863 
00864         function __createMemberEntry($a_usr_id,$a_role,$a_status,$a_passed)
00865         {
00866                 $query = "INSERT INTO crs_members ".
00867                         "SET usr_id = '".$a_usr_id."', ".
00868                         "obj_id = '".$this->course_obj->getId()."', ".
00869                         "status = '".$a_status."', ".
00870                         "role = '".$a_role."', ".
00871                         "passed = '".$a_passed."'";
00872 
00873                 $res = $this->ilDB->query($query);
00874 
00875                 return true;
00876         }
00877 
00878         function __read($a_usr_id)
00879         {
00880                 if(!ilObjUser::_lookupLogin($a_usr_id))
00881                 {
00882                         return false;
00883                 }
00884 
00885                 $query = "SELECT * FROM crs_members ".
00886                         "WHERE usr_id = '".$a_usr_id."' ".
00887                         "AND obj_id = '".$this->course_obj->getId()."'";
00888 
00889                 $res = $this->ilDB->query($query);
00890 
00891                 $this->member_data = array();
00892                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00893                 {
00894                         $this->member_data["usr_id"]    = $row->usr_id;
00895                         $this->member_data["role"]              = $row->role;
00896                         $this->member_data["status"]    = $row->status;
00897                         $this->member_data['passed']    = $row->passed;
00898                 }
00899                 return true;
00900         }
00901 
00902 
00903         function __readSubscribers()
00904         {
00905                 $this->subscribers = array();
00906 
00907                 $query = "SELECT usr_id FROM crs_subscribers ".
00908                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00909                         "ORDER BY sub_time ";
00910 
00911                 $res = $this->ilDB->query($query);
00912                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00913                 {
00914                         // DELETE SUBSCRIPTION IF USER HAS BEEN DELETED
00915                         if(!ilObjectFactory::getInstanceByObjId($a_usr_id,false))
00916                         {
00917                                 $this->deleteSubscriber($a_usr_id);
00918                         }
00919                         $this->subscribers[] = $row->usr_id;
00920                 }
00921                 return true;
00922         }
00923 
00924         function __readSubscriberData($a_usr_id)
00925         {
00926                 $query = "SELECT * FROM crs_subscribers ".
00927                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
00928                         "AND usr_id = '".$a_usr_id."'";
00929 
00930                 $res = $this->ilDB->query($query);
00931                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00932                 {
00933                         $data["time"] = $row->sub_time;
00934                         $data["usr_id"] = $row->usr_id;
00935                 }
00936                 return $data ? $data : array();
00937         }
00938 
00939         function _hasPassed($a_obj_id,$a_usr_id)
00940         {
00941                 global $ilDB;
00942 
00943                 $query = "SELECT * FROM crs_members ".
00944                         "WHERE obj_id = '".$a_obj_id."' ".
00945                         "AND usr_id = '".$a_usr_id."' ".
00946                         "AND passed = 1";
00947 
00948                 
00949                 $res = $ilDB->query($query);
00950                 
00951                 return $res->numRows() ? true : false;
00952         }
00953 
00954         function _setPassed($a_obj_id,$a_usr_id)
00955         {
00956                 global $ilDB;
00957 
00958                 if(!ilCourseMembers::_hasPassed($a_obj_id,$a_usr_id))
00959                 {
00960                         $query = "UPDATE crs_members ".
00961                                 "SET passed = 1 WHERE usr_id = '".$a_usr_id."' ".
00962                                 "AND obj_id = '".$a_obj_id."'";
00963                         
00964                         $ilDB->query($query);
00965                         
00966                         return true;
00967                 }
00968                 return false;
00969         }
00970 
00971         function _updatePassed($a_obj_id,$a_usr_id,$a_passed)
00972         {
00973                 global $ilDB;
00974 
00975                 $query = "UPDATE crs_members ".
00976                         "SET passed = '".(int) $a_passed."' ".
00977                         "WHERE obj_id = '".(int) $a_obj_id."' ".
00978                         "AND usr_id = '".(int) $a_usr_id."'";
00979 
00980                 $ilDB->query($query);
00981         }
00982 
00983         function _updateStatus($a_obj_id,$a_usr_id,$a_status)
00984         {
00985                 global $ilDB;
00986 
00987                 $query = "UPDATE crs_members ".
00988                         "SET status = '".(int) $a_status."' ".
00989                         "WHERE obj_id = '".(int) $a_obj_id."' ".
00990                         "AND usr_id = '".(int) $a_usr_id."'";
00991 
00992                 $ilDB->query($query);
00993         }               
00994 
00995 
00996         function __buildStatusBody(&$user_obj)
00997         {
00998                 $this->__read($user_obj->getId());
00999 
01000                 $body = $this->lng->txt('crs_status_changed_body').':<br />';
01001                 $body .= $this->lng->txt('login').': '.$user_obj->getLogin().'<br />';
01002                 $body .= $this->lng->txt('role').': ';
01003 
01004                 switch($this->member_data['role'])
01005                 {
01006                         case $this->ROLE_MEMBER:
01007                                 $body .= $this->lng->txt('crs_member').'<br />';
01008                                 break;
01009 
01010                         case $this->ROLE_TUTOR:
01011                                 $body .= $this->lng->txt('crs_tutor').'<br />';
01012                                 break;
01013 
01014                         case $this->ROLE_ADMIN:
01015                                 $body .= $this->lng->txt('crs_admin').'<br />';
01016                                 break;
01017                 }
01018                 $body .= $this->lng->txt('status').': ';
01019                 switch($this->member_data['status'])
01020                 {
01021                         case $this->STATUS_NOTIFY:
01022                                 $body .= $this->lng->txt("crs_notify").'<br />';
01023                                 break;
01024 
01025                         case $this->STATUS_NO_NOTIFY:
01026                                 $body .= $this->lng->txt("crs_no_notify").'<br />';
01027                                 break;
01028 
01029                         case $this->STATUS_BLOCKED:
01030                                 $body .= $this->lng->txt("crs_blocked").'<br />';
01031                                 break;
01032 
01033                         case $this->STATUS_UNBLOCKED:
01034                                 $body .= $this->lng->txt("crs_unblocked").'<br />';
01035                                 break;
01036                 }
01037                 $passed = $this->member_data['passed'] ? $this->lng->txt('yes') : $this->lng->txt('no');
01038                 $body .= $this->lng->txt('crs_passed').': '.$passed.'<br />';
01039 
01040                 return $body;
01041         }
01042 
01051         function _isMember($a_usr_id,$a_course_id,$a_field = '')
01052         {
01053                 global $ilUser,$ilDB;
01054 
01055                 // get specific user data
01056                 $tmp_user =& ilObjectFactory::getInstanceByObjId($a_usr_id);
01057                 switch($a_field)
01058                 {
01059                         case 'login':
01060                                 $and = "AND login = '".$tmp_user->getLogin()."' ";
01061                                 break;
01062                         case 'email':
01063                                 $and = "AND email = '".$tmp_user->getEmail()."' ";
01064                                 break;
01065                         case 'matriculation':
01066                                 $and = "AND matriculation = '".$tmp_user->getMatriculation()."' ";
01067                                 break;
01068 
01069                         default:
01070                                 $and = "AND cm.usr_id = '".$a_usr_id."'";
01071                                 break;
01072                 }
01073 
01074                 // check if entry exists
01075                 $query = "SELECT * FROM crs_members as cm, usr_data as ud ".
01076                         "WHERE cm.usr_id = ud.usr_id ".
01077                         "AND cm.obj_id = '".$a_course_id."' ".
01078                         $and;
01079 
01080 
01081                 $res = $ilDB->query($query);
01082 
01083                 return $res->numRows() ? true : false;
01084         }
01085 
01086         function _getMembers($a_obj_id)
01087         {
01088                 global $ilDB;
01089                 // In the moment all users that have entries in crs_members
01090                 
01091                 $query = "SELECT DISTINCT(crs_members.usr_id) AS usr_id FROM crs_members JOIN usr_data ".
01092                         "WHERE crs_members.usr_id = usr_data.usr_id ".
01093                         "AND obj_id = '".$a_obj_id."'";
01094 
01095                 $res = $ilDB->query($query);
01096                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01097                 {
01098                         $usr_ids[] = $row->usr_id;
01099                 }
01100                 return $usr_ids ? $usr_ids : array();
01101         }
01102 
01103         function __purgeDeleted()
01104         {
01105                 global $ilDB;
01106 
01107                 $query = "SELECT cs.usr_id as id FROM crs_members as cs ".
01108                         "LEFT JOIN usr_data as ud ".
01109                         "ON cs.usr_id = ud.usr_id ".
01110                         "WHERE obj_id = '".$this->course_obj->getId()."' ".
01111                         "AND ud.usr_id IS NULL";
01112 
01113                 $res = $ilDB->query($query);
01114                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01115                 {
01116                         $query = "DELETE FROM crs_members ".
01117                                 "WHERE usr_id = '".$row->id."'";
01118                         $ilDB->query($query);
01119                 }
01120         }
01121 
01122 
01123 }
01124 ?>

Generated on Fri Dec 13 2013 13:52:10 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1