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

Services/Mail/classes/class.ilMailSearchCoursesGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 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 require_once './Services/User/classes/class.ilObjUser.php';
00025 require_once "Services/Mail/classes/class.ilMailbox.php";
00026 require_once "Services/Mail/classes/class.ilFormatMail.php";
00027 require_once "Services/Mail/classes/class.ilAddressbook.php";
00028 
00035 class ilMailSearchCoursesGUI
00036 {
00037         private $tpl = null;
00038         private $ctrl = null;
00039         private $lng = null;
00040         
00041         private $umail = null;
00042         private $abook = null;
00043 
00044         public function __construct()
00045         {
00046                 global $tpl, $ilCtrl, $lng, $ilUser;
00047 
00048                 $this->tpl = $tpl;
00049                 $this->ctrl = $ilCtrl;
00050                 $this->lng = $lng;
00051                 
00052                 $this->ctrl->saveParameter($this, "mobj_id");
00053 
00054                 $this->umail = new ilFormatMail($ilUser->getId());
00055                 $this->abook = new ilAddressbook($ilUser->getId());
00056         }
00057 
00058         public function executeCommand()
00059         {
00060                 $forward_class = $this->ctrl->getNextClass($this);
00061                 switch($forward_class)
00062                 {
00063                         default:
00064                                 if (!($cmd = $this->ctrl->getCmd()))
00065                                 {
00066                                         $cmd = "showMyCourses";
00067                                 }
00068 
00069                                 $this->$cmd();
00070                                 break;
00071                 }
00072                 return true;
00073         }
00074 
00075         function mail()
00076         {
00077                 global $ilUser, $lng;
00078 
00079                 if ($_GET["view"] == "mycourses")
00080                 {
00081                         if (is_array($_POST["search_crs"]))
00082                         {
00083                                 $this->mailCourses();
00084                         }
00085                         else
00086                         {
00087                                 ilUtil::sendInfo($lng->txt("mail_select_course"));
00088                                 $this->showMyCourses();
00089                         }
00090                 }
00091                 else if ($_GET["view"] == "crs_members")
00092                 {
00093                         if (is_array($_POST["search_members"]))
00094                         {
00095                                 $this->mailMembers();
00096                         }
00097                         else
00098                         {
00099                                 ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
00100                                 $this->showMembers();
00101                         }
00102                 }
00103                 else
00104                 {
00105                         $this->showMyCourses();
00106                 }
00107         }
00108 
00109         function mailCourses()
00110         {
00111                 global $ilUser, $lng, $rbacreview;
00112 
00113                 $members = array();
00114 
00115                 if (!is_array($this->umail->getSavedData()))
00116                 {
00117                         $this->umail->savePostData(
00118                                 $ilUser->getId(),
00119                                 array(),
00120                                 "",
00121                                 "",
00122                                 "",
00123                                 "",
00124                                 "",
00125                                 "",
00126                                 "",
00127                                 ""
00128                         );
00129                 }
00130                 
00131                 require_once 'classes/class.ilObject.php';
00132                 foreach ($_POST["search_crs"] as $crs_id)
00133                 {
00134                         $ref_ids = ilObject::_getAllReferences($crs_id);
00135                         foreach ($ref_ids as $ref_id)
00136                         {
00137                                 $roles = $rbacreview->getAssignableChildRoles($ref_id);
00138                                 foreach ($roles as $role)
00139                                 {
00140                                         if (substr($role['title'],0,14) == 'il_crs_member_')
00141                                         {
00142                                                 array_push($members, $rbacreview->getRoleMailboxAddress($role['obj_id']));
00143                                         }
00144                                 }
00145                         }
00146                 }
00147                 $mail_data = $this->umail->appendSearchResult($members,"to");
00148 
00149                 $this->umail->savePostData(
00150                         $mail_data["user_id"],
00151                         $mail_data["attachments"],
00152                         $mail_data["rcp_to"],
00153                         $mail_data["rcp_cc"],
00154                         $mail_data["rcp_bcc"],
00155                         $mail_data["m_type"],
00156                         $mail_data["m_email"],
00157                         $mail_data["m_subject"],
00158                         $mail_data["m_message"],
00159                         $mail_data["use_placeholders"]
00160                 );
00161 
00162                 #$this->ctrl->returnToParent($this);
00163                 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
00164         }
00165 
00166         function mailMembers()
00167         {
00168                 $members = array();
00169 
00170                 if (!is_array($this->umail->getSavedData()))
00171                 {
00172                         $this->umail->savePostData(
00173                                 $ilUser->getId(),
00174                                 array(),
00175                                 "",
00176                                 "",
00177                                 "",
00178                                 "",
00179                                 "",
00180                                 "",
00181                                 "",
00182                                 ""
00183                         );
00184                 }
00185         
00186                 foreach ($_POST["search_members"] as $member)
00187                 {
00188                         $login = ilObjUser::_lookupLogin($member);
00189                         array_push($members, $login);
00190                 }
00191                 $mail_data = $this->umail->appendSearchResult($members,"to");
00192 
00193                 $this->umail->savePostData(
00194                         $mail_data["user_id"],
00195                         $mail_data["attachments"],
00196                         $mail_data["rcp_to"],
00197                         $mail_data["rcp_cc"],
00198                         $mail_data["rcp_bcc"],
00199                         $mail_data["m_type"],
00200                         $mail_data["m_email"],
00201                         $mail_data["m_subject"],
00202                         $mail_data["m_message"],
00203                         $mail_data["use_placeholders"]
00204                 );
00205 
00206                 #$this->ctrl->returnToParent($this);
00207                 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
00208         }
00209 
00213         public function adoptMembers()
00214         {
00215                 global $lng;
00216 
00217                 if (is_array($_POST["search_members"]))
00218                 {
00219                         $members = array();
00220                 
00221                         foreach ($_POST["search_members"] as $member)
00222                         {
00223                                 $login = ilObjUser::_lookupLogin($member);
00224         
00225                                 if (!$this->abook->checkEntry($login))
00226                                 {
00227                                         $name = ilObjUser::_lookupName($member);
00228                                         $email = '';
00229                                         if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
00230                                         {
00231                                                 $email = ilObjUser::_lookupEmail($member);      
00232                                         }
00233                                         $this->abook->addEntry(
00234                                                 $login,
00235                                                 $name["firstname"],
00236                                                 $name["lastname"],
00237                                                 $email
00238                                         );
00239                                 }
00240                         }
00241                         ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
00242                 }
00243                 else
00244                 {
00245                         ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
00246                 }
00247 
00248                 $this->showMembers();
00249         }
00250         
00254         function cancel()
00255         {
00256                 if ($_GET["view"] == "mycourses" &&
00257                         $_GET["ref"] == "mail")
00258                 {
00259                         $this->ctrl->returnToParent($this);     
00260                 }
00261                 else
00262                 {
00263                         $this->showMyCourses();
00264                 }
00265         }
00266         
00270         public function showMyCourses()
00271         {
00272                 global $lng, $ilUser, $ilObjDataCache;
00273 
00274                 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
00275 
00276                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook_search.html", "Services/Mail");
00277                 $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
00278                 
00279                 $_GET["view"] = "mycourses";
00280 
00281                 $this->ctrl->setParameter($this, "cmd", "post");
00282                 $this->ctrl->setParameter($this, "view", "mycourses");
00283                 if ($_GET["ref"] != "") $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
00284                 if (is_array($_POST["search_crs"])) $this->ctrl->setParameter($this, "search_crs", implode(",", $_POST["search_crs"]));
00285                 $this->tpl->setVariable("ACTION", $this->ctrl->getLinkTarget($this));
00286                 $this->ctrl->clearParameters($this);
00287 
00288                 $lng->loadLanguageModule('crs');
00289         
00290                 $user = new ilObjUser($ilUser->getId());
00291                 $crs_ids = $user->getCourseMemberships();
00292         
00293                 $counter = 0;
00294                 if (is_array($crs_ids) &&
00295                                         count($crs_ids) > 0)
00296                 {                               
00297                         $num_courses_hidden_members = 0;
00298                                 
00299                         $this->tpl->setVariable("CRS_TXT_COURSES",$lng->txt("mail_my_courses"));
00300                         $this->tpl->setVariable("CRS_TXT_NO_MEMBERS",$lng->txt("crs_count_members"));
00301                 
00302                         foreach($crs_ids as $crs_id) 
00303                         {
00304                                 $members_obj = ilCourseParticipants::_getInstanceByObjId($crs_id);
00305                                 $crs_members = $members_obj->getParticipants();
00306                                 
00307                                 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
00308                                 if((int)$oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
00309                                 {
00310                                         ++$num_courses_hidden_members;
00311                                         
00312                                         $this->tpl->setCurrentBlock('caption_asterisk');
00313                                         $this->tpl->touchBlock('caption_asterisk');
00314                                         $this->tpl->parseCurrentBlock();
00315                                 }
00316                                 unset($oTmpCrs);
00317         
00318                                 $this->tpl->setCurrentBlock("loop_crs");
00319                                 $this->tpl->setVariable("LOOP_CRS_CSSROW",++$counter%2 ? 'tblrow1' : 'tblrow2');
00320                                 $this->tpl->setVariable("LOOP_CRS_ID",$crs_id);
00321                                 $this->tpl->setVariable("LOOP_CRS_NAME",$ilObjDataCache->lookupTitle($crs_id));
00322                                 $this->tpl->setVariable("LOOP_CRS_NO_MEMBERS",count($crs_members));
00323                                 $this->tpl->parseCurrentBlock();
00324                         }
00325                         
00326                         if($num_courses_hidden_members > 0)
00327                         {
00328                                 $this->tpl->setCurrentBlock('caption_block');
00329                                 $this->tpl->setVariable('TXT_LIST_MEMBERS_NOT_AVAILABLE', $this->lng->txt('mail_crs_list_members_not_available'));
00330                                 $this->tpl->parseCurrentBlock();
00331                         }
00332         
00333                         $this->tpl->setVariable("BUTTON_MAIL",$lng->txt("mail_members"));
00334                         $this->tpl->setVariable("BUTTON_LIST",$lng->txt("mail_list_members"));
00335                 }
00336         
00337                 if ($counter == 0)
00338                 {
00339                         $this->tpl->setCurrentBlock("crs_not_found");
00340                         $this->tpl->setVariable("TXT_CRS_NOT_FOUND",$lng->txt("mail_search_courses_not_found"));
00341                         $this->tpl->parseCurrentBlock();
00342 
00343                         $this->tpl->touchBlock("entries_not_found");
00344                 }
00345                 else
00346                 {
00347                         $this->tpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
00348                 }
00349                 if ($_GET["ref"] == "mail") $this->tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
00350 
00351                 $this->tpl->show();
00352         }
00353 
00357         public function showMembers()
00358         {
00359                 global $lng, $ilUser, $ilObjDataCache;
00360 
00361                 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
00362 
00363                 if ($_GET["search_crs"] != "")
00364                 {
00365                         $_POST["search_crs"] = explode(",", $_GET["search_crs"]);
00366                         $_GET["search_crs"] = "";
00367                 }
00368                 else if ($_SESSION["search_crs"] != "")
00369                 {
00370                         $_POST["search_crs"] = explode(",", $_SESSION["search_crs"]);
00371                         $_SESSION["search_crs"] = "";
00372                 } 
00373 
00374                 if (!is_array($_POST["search_crs"]) ||
00375                         count($_POST["search_crs"]) == 0)
00376                 {
00377                         ilUtil::sendInfo($lng->txt("mail_select_course"));
00378                         $this->showMyCourses();
00379                 }
00380                 else
00381                 {
00382                         foreach($_POST['search_crs'] as $crs_id) 
00383                         {
00384                                 $oTmpCrs = ilObjectFactory::getInstanceByObjId($crs_id);
00385                                 if($oTmpCrs->getShowMembers() == $oTmpCrs->SHOW_MEMBERS_DISABLED)
00386                                 {
00387                                         unset($_POST['search_crs']);
00388                                         ilUtil::sendInfo($lng->txt('mail_crs_list_members_not_available_for_at_least_one_crs'));
00389                                         return $this->showMyCourses();
00390                                 }
00391                                 unset($oTmpCrs);
00392                         }
00393                         
00394                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook_search.html", "Services/Mail");
00395                         $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
00396                 
00397                         $this->ctrl->setParameter($this, "cmd", "post");
00398                         $this->ctrl->setParameter($this, "view", "crs_members");
00399                         if ($_GET["ref"] != "") $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
00400                         if (is_array($_POST["search_crs"])) $this->ctrl->setParameter($this, "search_crs", implode(",", $_POST["search_crs"]));
00401                         $this->tpl->setVariable("ACTION", $this->ctrl->getLinkTarget($this));
00402                         $this->ctrl->clearParameters($this);
00403 
00404                         $lng->loadLanguageModule('crs');
00405         
00406                         $this->tpl->setCurrentBlock("members_course");
00407                         $this->tpl->setVariable("MEMBERS_TXT_COURSE",$lng->txt("course"));
00408                         $this->tpl->parseCurrentBlock();
00409                         $this->tpl->setVariable("MEMBERS_TXT_LOGIN",$lng->txt("login"));
00410                         $this->tpl->setVariable("MEMBERS_TXT_NAME",$lng->txt("name"));
00411                         $this->tpl->setVariable("MEMBERS_TXT_IN_ADDRESSBOOK",$lng->txt("mail_in_addressbook"));
00412         
00413                         $counter = 0;
00414                         foreach($_POST["search_crs"] as $crs_id) 
00415                         {
00416                                 $members_obj = ilCourseParticipants::_getinstanceByObjId($crs_id);
00417                                 $tmp_members = $members_obj->getParticipants();
00418                                 $course_members[$crs_id] = ilUtil::_sortIds($tmp_members,'usr_data','lastname','usr_id');
00419         
00420                                 foreach ($course_members[$crs_id] as $member)
00421                                 {
00422                                         $name = ilObjUser::_lookupName($member);
00423                                         $login = ilObjUser::_lookupLogin($member);
00424         
00425                                         $this->tpl->setCurrentBlock("loop_members");
00426                                         $this->tpl->setVariable("LOOP_MEMBERS_CSSROW",++$counter%2 ? 'tblrow1' : 'tblrow2');
00427                                         $this->tpl->setVariable("LOOP_MEMBERS_ID",$member);
00428                                         $this->tpl->setVariable("LOOP_MEMBERS_LOGIN",$login);
00429                                         if(ilObjUser::_lookupPref($member, 'public_profile') == 'y')
00430                                         {
00431                                                 $this->tpl->setVariable('LOOP_MEMBERS_NAME', $name['lastname'].', '.$name['firstname']);
00432                                         }
00433                                         $this->tpl->setVariable("LOOP_MEMBERS_CRS_GRP",$ilObjDataCache->lookupTitle($crs_id));
00434                                         $this->tpl->setVariable("LOOP_MEMBERS_IN_ADDRESSBOOK", $this->abook->checkEntryByLogin($login) ? $lng->txt("yes") : $lng->txt("no"));
00435                                         $this->tpl->parseCurrentBlock();
00436                                 }
00437                         }
00438                         
00439                         if ($counter == 0)
00440                         {
00441                                 $this->tpl->setCurrentBlock("members_not_found");
00442                                 $this->tpl->setVariable("TXT_MEMBERS_NOT_FOUND",$lng->txt("mail_search_members_not_found"));
00443                                 $this->tpl->parseCurrentBlock();
00444                         
00445                                 $this->tpl->touchBlock("entries_not_found");
00446                         }
00447                         else
00448                         {
00449                                 $this->tpl->setVariable("BUTTON_MAIL",$lng->txt("grp_mem_send_mail"));
00450                                 $this->tpl->setVariable("BUTTON_ADOPT",$lng->txt("mail_into_addressbook"));
00451 
00452                                 $this->tpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
00453                         }
00454 
00455                         $this->tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
00456 
00457                         $this->tpl->show();
00458                 }
00459         }
00460 
00461 }
00462 
00463 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1