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

Services/Mail/classes/class.ilMailSearchGroupsGUI.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 ilMailSearchGroupsGUI
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 = "showMyGroups";
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"] == "mygroups")
00080                 {
00081                         if (is_array($_POST["search_grp"]))
00082                         {
00083                                 $this->mailGroups();
00084                         }
00085                         else
00086                         {
00087                                 ilUtil::sendInfo($lng->txt("mail_select_group"));
00088                                 $this->showMyGroups();
00089                         }
00090                 }
00091                 else if ($_GET["view"] == "grp_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->showMyGroups();
00106                 }
00107         }
00108 
00109         function mailGroups()
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_grp"] as $grp_id)
00133                 {
00134                         $ref_ids = ilObject::_getAllReferences($grp_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_grp_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                 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
00163         }
00164 
00165         function mailMembers()
00166         {
00167                 $members = array();
00168 
00169                 if (!is_array($this->umail->getSavedData()))
00170                 {
00171                         $this->umail->savePostData(
00172                                 $ilUser->getId(),
00173                                 array(),
00174                                 "",
00175                                 "",
00176                                 "",
00177                                 "",
00178                                 "",
00179                                 "",
00180                                 "",
00181                                 ""
00182                         );
00183                 }
00184         
00185                 foreach ($_POST["search_members"] as $member)
00186                 {
00187                         $login = ilObjUser::_lookupLogin($member);
00188                         array_push($members, $login);
00189                 }
00190                 $mail_data = $this->umail->appendSearchResult($members,"to");
00191 
00192                 $this->umail->savePostData(
00193                         $mail_data["user_id"],
00194                         $mail_data["attachments"],
00195                         $mail_data["rcp_to"],
00196                         $mail_data["rcp_cc"],
00197                         $mail_data["rcp_bcc"],
00198                         $mail_data["m_type"],
00199                         $mail_data["m_email"],
00200                         $mail_data["m_subject"],
00201                         $mail_data["m_message"],
00202                         $mail_data["use_placeholders"]
00203                 );
00204         
00205                 ilUtil::redirect("ilias.php?baseClass=ilMailGUI&type=search_res");
00206         }
00207 
00211         public function adoptMembers()
00212         {
00213                 global $lng;
00214 
00215                 if (is_array($_POST["search_members"]))
00216                 {
00217                         $members = array();
00218                 
00219                         foreach ($_POST["search_members"] as $member)
00220                         {
00221                                 $login = ilObjUser::_lookupLogin($member);
00222         
00223                                 if (!$this->abook->checkEntry($login))
00224                                 {
00225                                         $name = ilObjUser::_lookupName($member);
00226                                         $email = '';
00227                                         if(ilObjUser::_lookupPref((int)$member, 'public_email') == 'y')
00228                                         {
00229                                                 $email = ilObjUser::_lookupEmail($member);      
00230                                         }
00231                                         $this->abook->addEntry(
00232                                                 $login,
00233                                                 $name["firstname"],
00234                                                 $name["lastname"],
00235                                                 $email
00236                                         );
00237                                 }
00238                         }
00239                         ilUtil::sendInfo($lng->txt("mail_members_added_addressbook"));
00240                 }
00241                 else
00242                 {
00243                         ilUtil::sendInfo($lng->txt("mail_select_one_entry"));
00244                 }
00245 
00246                 $this->showMembers();
00247         }
00248         
00252         function cancel()
00253         {
00254                 if ($_GET["view"] == "mygroups" &&
00255                         $_GET["ref"] == "mail")
00256                 {
00257                         $this->ctrl->returnToParent($this);     
00258                 }
00259                 else
00260                 {
00261                         $this->showMyGroups();
00262                 }
00263         }
00264         
00268         public function showMyGroups()
00269         {
00270                 global $lng, $ilUser, $ilObjDataCache;
00271 
00272                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook_search.html", "Services/Mail");
00273                 $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
00274                 
00275                 $_GET["view"] = "mygroups";
00276 
00277                 $this->ctrl->setParameter($this, "cmd", "post");
00278                 $this->ctrl->setParameter($this, "view", "mygroups");
00279                 if ($_GET["ref"] != "") $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
00280                 if (is_array($_POST["search_grp"])) $this->ctrl->setParameter($this, "search_grp", implode(",", $_POST["search_grp"]));
00281                 $this->tpl->setVariable("ACTION", $this->ctrl->getLinkTarget($this));
00282                 $this->ctrl->clearParameters($this);
00283 
00284                 $lng->loadLanguageModule('crs');
00285         
00286                 $user = new ilObjUser($ilUser->getId());
00287                 $grp_ids = $user->getGroupMemberships();
00288         
00289                 $counter = 0;
00290                 if (is_array($grp_ids) &&
00291                                         count($grp_ids) > 0)
00292                 {
00293                                 
00294                         $this->tpl->setVariable("GRP_TXT_GROUPS",$lng->txt("mail_my_groups"));
00295                         $this->tpl->setVariable("GRP_TXT_NO_MEMBERS",$lng->txt("grp_count_members"));
00296                 
00297                         foreach($grp_ids as $grp_id) 
00298                         {
00299 /*                              $ref_ids = ilObject::_getAllReferences($grp_id);
00300                                 $ref_id = current($ref_ids);
00301 
00302                                 $group_obj = new ilObjGroup($ref_id); 
00303                                 $grp_members = $group_obj->getCountMembers();*/
00304                                 $grp_members = ilObjGroup::_getMembers($grp_id);
00305 
00306                                 $this->tpl->setCurrentBlock("loop_grp");
00307                                 $this->tpl->setVariable("LOOP_GRP_CSSROW",++$counter%2 ? 'tblrow1' : 'tblrow2');
00308                                 $this->tpl->setVariable("LOOP_GRP_ID",$grp_id);
00309                                 $this->tpl->setVariable("LOOP_GRP_NAME",$ilObjDataCache->lookupTitle($grp_id));
00310                                 $this->tpl->setVariable("LOOP_GRP_NO_MEMBERS",count($grp_members));
00311                                 $this->tpl->parseCurrentBlock();
00312                         }
00313         
00314                         $this->tpl->setVariable("BUTTON_MAIL",$lng->txt("mail_members"));
00315                         $this->tpl->setVariable("BUTTON_LIST",$lng->txt("mail_list_members"));
00316                 }
00317         
00318                 if ($counter == 0)
00319                 {
00320                         $this->tpl->setCurrentBlock("grp_not_found");
00321                         $this->tpl->setVariable("TXT_GRP_NOT_FOUND",$lng->txt("mail_search_groups_not_found"));
00322                         $this->tpl->parseCurrentBlock();
00323 
00324                         $this->tpl->touchBlock("entries_not_found");
00325                 }
00326                 else
00327                 {
00328                         $this->tpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
00329                 }
00330                 if ($_GET["ref"] == "mail") $this->tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
00331 
00332                 $this->tpl->show();
00333         }
00334 
00338         public function showMembers()
00339         {
00340                 global $lng, $ilUser;
00341 
00342                 if ($_GET["search_grp"] != "")
00343                 {
00344                         $_POST["search_grp"] = explode(",", $_GET["search_grp"]);
00345                 }
00346 
00347                 if (!is_array($_POST["search_grp"]) ||
00348                         count($_POST["search_grp"]) == 0)
00349                 {
00350                         ilUtil::sendInfo($lng->txt("mail_select_group"));
00351                         $this->showMyGroups();
00352                 }
00353                 else
00354                 {
00355                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.mail_addressbook_search.html", "Services/Mail");
00356                         $this->tpl->setVariable("HEADER", $this->lng->txt("mail"));
00357                 
00358                         $this->ctrl->setParameter($this, "cmd", "post");
00359                         $this->ctrl->setParameter($this, "view", "grp_members");
00360                         if ($_GET["ref"] != "") $this->ctrl->setParameter($this, "ref", $_GET["ref"]);
00361                         if (is_array($_POST["search_grp"])) $this->ctrl->setParameter($this, "search_grp", implode(",", $_POST["search_grp"]));
00362                         $this->tpl->setVariable("ACTION", $this->ctrl->getLinkTarget($this));
00363                         $this->ctrl->clearParameters($this);
00364 
00365                         $lng->loadLanguageModule('crs');
00366         
00367                         $this->tpl->setCurrentBlock("members_group");
00368                         $this->tpl->setVariable("MEMBERS_TXT_GROUP",$lng->txt("obj_grp"));
00369                         $this->tpl->parseCurrentBlock();
00370                         $this->tpl->setVariable("MEMBERS_TXT_LOGIN",$lng->txt("login"));
00371                         $this->tpl->setVariable("MEMBERS_TXT_NAME",$lng->txt("name"));
00372                         $this->tpl->setVariable("MEMBERS_TXT_IN_ADDRESSBOOK",$lng->txt("mail_in_addressbook"));
00373         
00374                         $counter = 0;
00375                         foreach($_POST["search_grp"] as $grp_id) 
00376                         {
00377                                 $ref_ids = ilObject::_getAllReferences($grp_id);
00378                                 $ref_id = current($ref_ids);
00379 
00380                                 if (is_object($group_obj = ilObjectFactory::getInstanceByRefId($ref_id,false)))
00381                                 {
00382                                         $grp_members = $group_obj->getGroupMemberData($group_obj->getGroupMemberIds());
00383                                         
00384                                         foreach ($grp_members as $member)
00385                                         {
00386                                                 $this->tpl->setCurrentBlock("loop_members");
00387                                                 $this->tpl->setVariable("LOOP_MEMBERS_CSSROW",++$counter%2 ? 'tblrow1' : 'tblrow2');
00388                                                 $this->tpl->setVariable("LOOP_MEMBERS_ID",$member["id"]);
00389                                                 $this->tpl->setVariable("LOOP_MEMBERS_LOGIN",$member["login"]);
00390                                                 if(ilObjUser::_lookupPref($member['id'], 'public_profile') == 'y')
00391                                                 {
00392                                                         $this->tpl->setVariable('LOOP_MEMBERS_NAME', $member['lastname'].', '.$member['firstname']);
00393                                                 }
00394                                                 $this->tpl->setVariable("LOOP_MEMBERS_CRS_GRP",$group_obj->getTitle());
00395                                                 $this->tpl->setVariable("LOOP_MEMBERS_IN_ADDRESSBOOK", $this->abook->checkEntryByLogin($member["login"]) ? $lng->txt("yes") : $lng->txt("no"));
00396                                                 $this->tpl->parseCurrentBlock();
00397                                         }
00398                                 }
00399                         }
00400                                                 
00401                         if ($counter == 0)
00402                         {
00403                                 $this->tpl->setCurrentBlock("members_not_found");
00404                                 $this->tpl->setVariable("TXT_MEMBERS_NOT_FOUND",$lng->txt("mail_search_members_not_found"));
00405                                 $this->tpl->parseCurrentBlock();
00406                         
00407                                 $this->tpl->touchBlock("entries_not_found");
00408                         }
00409                         else
00410                         {
00411                                 $this->tpl->setVariable("BUTTON_MAIL",$lng->txt("grp_mem_send_mail"));
00412                                 $this->tpl->setVariable("BUTTON_ADOPT",$lng->txt("mail_into_addressbook"));
00413 
00414                                 $this->tpl->setVariable("TXT_MARKED_ENTRIES",$lng->txt("marked_entries"));
00415                         }
00416 
00417                         $this->tpl->setVariable("BUTTON_CANCEL",$lng->txt("cancel"));
00418 
00419                         $this->tpl->show();
00420                 }
00421         }
00422 
00423 }
00424 
00425 ?>

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