Esempio n. 1
0
 /**
  * Returns the mailbox address of a role.
  *
  * Example 1: Mailbox address for an ILIAS reserved role name
  * ----------------------------------------------------------
  * The il_crs_member_345 role of the course object "English Course 1" is 
  * returned as one of the following mailbox addresses:
  *
  * a)   Course Member <#member@[English Course 1]>
  * b)   Course Member <#il_crs_member_345@[English Course 1]>
  * c)   Course Member <#il_crs_member_345>
  *
  * Address a) is returned, if the title of the object is unique, and
  * if there is only one local role with the substring "member" defined for
  * the object.
  *
  * Address b) is returned, if the title of the object is unique, but 
  * there is more than one local role with the substring "member" in its title.
  *
  * Address c) is returned, if the title of the course object is not unique.
  *
  *
  * Example 2: Mailbox address for a manually defined role name
  * -----------------------------------------------------------
  * The "Admin" role of the category object "Courses" is 
  * returned as one of the following mailbox addresses:
  *
  * a)   Course Administrator <#Admin@Courses>
  * b)   Course Administrator <#Admin>
  * c)   Course Adminstrator <#il_role_34211>
  *
  * Address a) is returned, if the title of the object is unique, and
  * if there is only one local role with the substring "Admin" defined for
  * the course object.
  *
  * Address b) is returned, if the title of the object is not unique, but 
  * the role title is unique.
  *
  * Address c) is returned, if neither the role title nor the title of the
  * course object is unique. 
  *
  *
  * Example 3: Mailbox address for a manually defined role title that can
  *            contains special characters in the local-part of a 
  *            mailbox address
  * --------------------------------------------------------------------
  * The "Author Courses" role of the category object "Courses" is 
  * returned as one of the following mailbox addresses:
  *
  * a)   "#Author Courses"@Courses
  * b)   Author Courses <#il_role_34234>
  *
  * Address a) is returned, if the title of the role is unique.
  *
  * Address b) is returned, if neither the role title nor the title of the
  * course object is unique, or if the role title contains a quote or a
  * backslash.
  *
  *
  * @param int a role id
  * @param boolean is_localize whether mailbox addresses should be localized
  * @return	String mailbox address or null, if role does not exist.
  * @todo refactor rolf
  */
 function getRoleMailboxAddress($a_role_id, $is_localize = true)
 {
     global $log, $lng, $ilDB;
     include_once "Services/Mail/classes/class.ilMail.php";
     if (ilMail::_usePearMail()) {
         // Retrieve the role title and the object title.
         $query = "SELECT rdat.title role_title,odat.title object_title, " . " oref.ref_id object_ref " . "FROM object_data rdat " . "JOIN rbac_fa fa ON fa.rol_id = rdat.obj_id " . "JOIN tree rtree ON rtree.child = fa.parent " . "JOIN object_reference oref ON oref.ref_id = rtree.parent " . "JOIN object_data odat ON odat.obj_id = oref.obj_id " . "WHERE rdat.obj_id = " . $this->ilDB->quote($a_role_id, 'integer') . " " . "AND fa.assign = 'y' ";
         $r = $ilDB->query($query);
         if (!($row = $ilDB->fetchObject($r))) {
             //$log->write('class.ilRbacReview->getMailboxAddress('.$a_role_id.'): error role does not exist');
             return null;
             // role does not exist
         }
         $object_title = $row->object_title;
         $object_ref = $row->object_ref;
         $role_title = $row->role_title;
         // In a perfect world, we could use the object_title in the
         // domain part of the mailbox address, and the role title
         // with prefix '#' in the local part of the mailbox address.
         $domain = $object_title;
         $local_part = $role_title;
         // Determine if the object title is unique
         $q = "SELECT COUNT(DISTINCT dat.obj_id) count " . "FROM object_data dat " . "JOIN object_reference ref ON ref.obj_id = dat.obj_id " . "JOIN tree ON tree.child = ref.ref_id " . "WHERE title = " . $this->ilDB->quote($object_title, 'text') . " " . "AND tree.tree = 1 ";
         $r = $this->ilDB->query($q);
         $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
         // If the object title is not unique, we get rid of the domain.
         if ($row->count > 1) {
             $domain = null;
         }
         // If the domain contains illegal characters, we get rid of it.
         //if (domain != null && preg_match('/[\[\]\\]|[\x00-\x1f]/',$domain))
         // Fix for Mantis Bug: 7429 sending mail fails because of brakets
         // Fix for Mantis Bug: 9978 sending mail fails because of semicolon
         if ($domain != null && preg_match('/[\\[\\]\\]|[\\x00-\\x1f]|[\\x28-\\x29]|[;]/', $domain)) {
             $domain = null;
         }
         // If the domain contains special characters, we put square
         //   brackets around it.
         if ($domain != null && (preg_match('/[()<>@,;:\\".\\[\\]]/', $domain) || preg_match('/[^\\x21-\\x8f]/', $domain))) {
             $domain = '[' . $domain . ']';
         }
         // If the role title is one of the ILIAS reserved role titles,
         //     we can use a shorthand version of it for the local part
         //     of the mailbox address.
         if (strpos($role_title, 'il_') === 0 && $domain != null) {
             $unambiguous_role_title = $role_title;
             $pos = strpos($role_title, '_', 3) + 1;
             $local_part = substr($role_title, $pos, strrpos($role_title, '_') - $pos);
         } else {
             $unambiguous_role_title = 'il_role_' . $a_role_id;
         }
         // Determine if the local part is unique. If we don't have a
         // domain, the local part must be unique within the whole repositry.
         // If we do have a domain, the local part must be unique for that
         // domain.
         if ($domain == null) {
             $q = "SELECT COUNT(DISTINCT dat.obj_id) count " . "FROM object_data dat " . "JOIN object_reference ref ON ref.obj_id = dat.obj_id " . "JOIN tree ON tree.child = ref.ref_id " . "WHERE title = " . $this->ilDB->quote($local_part, 'text') . " " . "AND tree.tree = 1 ";
         } else {
             $q = "SELECT COUNT(rd.obj_id) count " . "FROM object_data rd " . "JOIN rbac_fa fa ON rd.obj_id = fa.rol_id " . "JOIN tree t ON t.child = fa.parent " . "WHERE fa.assign = 'y' " . "AND t.parent = " . $this->ilDB->quote($object_ref, 'integer') . " " . "AND rd.title LIKE " . $this->ilDB->quote('%' . preg_replace('/([_%])/', '\\\\$1', $local_part) . '%', 'text') . " ";
         }
         $r = $this->ilDB->query($q);
         $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
         // if the local_part is not unique, we use the unambiguous role title
         //   instead for the local part of the mailbox address
         if ($row->count > 1) {
             $local_part = $unambiguous_role_title;
         }
         $use_phrase = true;
         // If the local part contains illegal characters, we use
         //     the unambiguous role title instead.
         if (preg_match('/[\\"\\x00-\\x1f]/', $local_part)) {
             $local_part = $unambiguous_role_title;
         } else {
             if (!preg_match('/^[\\x00-\\x7E]+$/i', $local_part)) {
                 // 2013-12-05: According to #12283, we do not accept umlauts in the local part
                 $local_part = $unambiguous_role_title;
                 $use_phrase = false;
             }
         }
         // Add a "#" prefix to the local part
         $local_part = '#' . $local_part;
         // Put quotes around the role title, if needed
         if (preg_match('/[()<>@,;:.\\[\\]\\x20]/', $local_part)) {
             $local_part = '"' . $local_part . '"';
         }
         $mailbox = $domain == null ? $local_part : $local_part . '@' . $domain;
         if ($is_localize) {
             if (substr($role_title, 0, 3) == 'il_') {
                 $phrase = $lng->txt(substr($role_title, 0, strrpos($role_title, '_')));
             } else {
                 $phrase = $role_title;
             }
             if ($use_phrase) {
                 // make phrase RFC 822 conformant:
                 // - strip excessive whitespace
                 // - strip special characters
                 $phrase = preg_replace('/\\s\\s+/', ' ', $phrase);
                 $phrase = preg_replace('/[()<>@,;:\\".\\[\\]]/', '', $phrase);
                 $mailbox = $phrase . ' <' . $mailbox . '>';
             }
         }
         require_once './Services/PEAR/lib/Mail/RFC822.php';
         $obj = new Mail_RFC822($mailbox, 'ilias');
         if (@$obj->parseAddressList() instanceof PEAR_Error) {
             $q = "SELECT title " . "FROM object_data " . "WHERE obj_id = " . $this->ilDB->quote($a_role_id, 'integer');
             $r = $this->ilDB->query($q);
             if ($row = $r->fetchRow(DB_FETCHMODE_OBJECT)) {
                 return '#' . $row->title;
             } else {
                 return null;
             }
         }
         return $mailbox;
     } else {
         $q = "SELECT title " . "FROM object_data " . "WHERE obj_id = " . $this->ilDB->quote($a_role_id, 'integer');
         $r = $this->ilDB->query($q);
         if ($row = $r->fetchRow(DB_FETCHMODE_OBJECT)) {
             return '#' . $row->title;
         } else {
             return null;
         }
     }
 }
 /**
  *
  * @param <type> $a_recipients
  */
 private function validatePear($a_recipients)
 {
     if (ilMail::_usePearMail()) {
         $this->setUsePear(true);
         $tmp_names = $this->explodeRecipients($a_recipients, true);
         if (is_a($tmp_names, 'PEAR_Error')) {
             $this->setUsePear(false);
         }
     } else {
         $this->setUsePear(false);
     }
 }
Esempio n. 3
0
 function mailMembersObject()
 {
     global $rbacreview, $ilErr, $ilAccess, $ilObjDataCache, $ilias;
     include_once './Services/AccessControl/classes/class.ilObjRole.php';
     $this->lng->loadLanguageModule('mail');
     if (!isset($_GET['returned_from_mail'])) {
         ilUtil::sendInfo($this->lng->txt('mail_select_recipients'));
     }
     $is_admin = (bool) $ilAccess->checkAccess("write", "", $this->object->getRefId());
     if (!$is_admin && $this->object->getMailToMembersType() != ilCourseConstants::MAIL_ALLOWED_ALL) {
         $ilErr->raiseError($this->lng->txt("msg_no_perm_read"), $ilErr->MESSAGE);
     }
     $this->setSubTabs('members');
     $this->tabs_gui->setTabActive('members');
     $this->tabs_gui->setSubTabActive('mail_members');
     $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail_members.html', 'Services/Contact');
     require_once 'Services/Mail/classes/class.ilMailFormCall.php';
     $this->tpl->setVariable("MAILACTION", ilMailFormCall::getLinkTarget($this, 'membersGallery', array(), array('type' => 'role', 'sig' => $this->createMailSignature())));
     $this->tpl->setVariable("SELECT_ACTION", 'ilias.php?baseClass=ilmailgui&view=my_courses&search_crs=' . $this->object->getId());
     $this->tpl->setVariable("MAIL_SELECTED", $this->lng->txt('send_mail_selected'));
     $this->tpl->setVariable("MAIL_MEMBERS", $this->lng->txt('send_mail_members'));
     $this->tpl->setVariable("MAIL_TUTOR", $this->lng->txt('send_mail_tutors'));
     $this->tpl->setVariable("MAIL_ADMIN", $this->lng->txt('send_mail_admins'));
     $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath('arrow_downright.svg'));
     $this->tpl->setVariable("OK", $this->lng->txt('next'));
     // Display roles with user friendly mailbox addresses
     $role_ids = $rbacreview->getRolesOfRoleFolder($this->object->getRefId(), false);
     // Sort by relevance
     $sorted_role_ids = array();
     $counter = 3;
     foreach ($role_ids as $role_id) {
         switch (substr(ilObject::_lookupTitle($role_id), 0, 8)) {
             case 'il_crs_a':
                 $sorted_role_ids[2] = $role_id;
                 break;
             case 'il_crs_t':
                 $sorted_role_ids[1] = $role_id;
                 break;
             case 'il_crs_m':
                 $sorted_role_ids[0] = $role_id;
                 break;
             default:
                 $sorted_role_ids[$counter++] = $role_id;
                 break;
         }
     }
     ksort($sorted_role_ids, SORT_NUMERIC);
     foreach ((array) $sorted_role_ids as $role_id) {
         $this->tpl->setCurrentBlock("mailbox_row");
         $role_addr = $rbacreview->getRoleMailboxAddress($role_id);
         // check if role title is unique. if not force use pear mail for roles
         $ids_for_role_title = ilObject::_getIdsForTitle(ilObject::_lookupTitle($role_id), 'role');
         if (count($ids_for_role_title) >= 2) {
             $ilias->setSetting('pear_mail_enable', 1);
         }
         $this->tpl->setVariable("CHECK_MAILBOX", ilUtil::formCheckbox(1, 'roles[]', htmlspecialchars($role_addr)));
         if (ilMail::_usePearMail() && substr($role_addr, 0, 4) != '#il_') {
             // if pear mail is enabled, mailbox addresses are already localized in the language of the user
             $this->tpl->setVariable("MAILBOX", $role_addr);
         } else {
             // if pear mail is not enabled, we need to localize mailbox addresses in the language of the user
             $this->tpl->setVariable("MAILBOX", ilObjRole::_getTranslation($ilObjDataCache->lookupTitle($role_id)) . " (" . $role_addr . ")");
         }
         $this->tpl->parseCurrentBlock();
     }
 }
 public function mailMembersObject()
 {
     global $rbacreview, $ilObjDataCache;
     include_once 'Services/AccessControl/classes/class.ilObjRole.php';
     $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail_members.html', 'Services/Contact');
     $this->__setSubTabs('members');
     include_once "./Services/Link/classes/class.ilLink.php";
     $link_to_seminar = ilLink::_getLink($this->object->getRefId());
     include_once 'Services/Mail/classes/class.ilMail.php';
     require_once 'Services/Mail/classes/class.ilMailFormCall.php';
     $this->tpl->setVariable("MAILACTION", ilMailFormCall::getLinkTarget($this, 'mailMembers', array(), array('type' => 'role')));
     $this->tpl->setVariable('ADDITIONAL_MESSAGE_TEXT', $link_to_seminar);
     $this->tpl->setVariable('IMG_ARROW', ilUtil::getImagePath('arrow_downright.png'));
     $this->tpl->setVariable('OK', $this->lng->txt('ok'));
     $role_folder = $rbacreview->getRoleFolderOfObject($this->object->getRefId());
     $role_ids = $rbacreview->getRolesOfRoleFolder($role_folder['ref_id'], false);
     foreach ($role_ids as $role_id) {
         $this->tpl->setCurrentBlock('mailbox_row');
         $role_addr = $rbacreview->getRoleMailboxAddress($role_id);
         $this->tpl->setVariable('CHECK_MAILBOX', ilUtil::formCheckbox(1, 'roles[]', htmlspecialchars($role_addr)));
         if (ilMail::_usePearMail()) {
             // if pear mail is enabled, mailbox addresses are already localized in the language of the user
             $this->tpl->setVariable('MAILBOX', $role_addr);
         } else {
             // if pear mail is not enabled, we need to localize mailbox addresses in the language of the user
             $this->tpl->setVariable('MAILBOX', ilObjRole::_getTranslation($ilObjDataCache->lookupTitle($role_id)) . ' (' . $role_addr . ')');
         }
         $this->tpl->parseCurrentBlock();
     }
 }
 /**
  * Form for mail to group members
  */
 function mailMembersObject()
 {
     global $rbacreview, $ilObjDataCache, $ilias;
     include_once './Services/AccessControl/classes/class.ilObjRole.php';
     $this->lng->loadLanguageModule('mail');
     if (!isset($_GET['returned_from_mail'])) {
         ilUtil::sendInfo($this->lng->txt('mail_select_recipients'));
     }
     $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.mail_members.html', 'Services/Contact');
     $this->setSubTabs('members');
     $this->tabs_gui->setTabActive('members');
     require_once 'Services/Mail/classes/class.ilMailFormCall.php';
     $this->tpl->setVariable("MAILACTION", ilMailFormCall::getLinkTarget($this, 'mailMembers', array(), array('type' => 'role', 'sig' => $this->createMailSignature())));
     $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath('arrow_downright.png'));
     $this->tpl->setVariable("TXT_MARKED_ENTRIES", $this->lng->txt('marked_entries'));
     $this->tpl->setVariable("OK", $this->lng->txt('next'));
     // Get role mailbox addresses
     $role_folder = $rbacreview->getRoleFolderOfObject($this->object->getRefId());
     $role_ids = $rbacreview->getRolesOfRoleFolder($role_folder['ref_id'], false);
     $role_addrs = array();
     // Sort by relevance
     $sorted_role_ids = array();
     $counter = 2;
     foreach ($role_ids as $role_id) {
         switch (substr(ilObject::_lookupTitle($role_id), 0, 8)) {
             case 'il_grp_a':
                 $sorted_role_ids[1] = $role_id;
                 break;
             case 'il_grp_m':
                 $sorted_role_ids[0] = $role_id;
                 break;
             default:
                 $sorted_role_ids[$counter++] = $role_id;
                 break;
         }
     }
     ksort($sorted_role_ids, SORT_NUMERIC);
     foreach ((array) $sorted_role_ids as $role_id) {
         $this->tpl->setCurrentBlock("mailbox_row");
         $role_addr = $rbacreview->getRoleMailboxAddress($role_id);
         // check if role title is unique. if not force use pear mail for roles
         $ids_for_role_title = ilObject::_getIdsForTitle(ilObject::_lookupTitle($role_id), 'role');
         if (count($ids_for_role_title) >= 2) {
             $ilias->setSetting('pear_mail_enable', 1);
         }
         $this->tpl->setVariable("CHECK_MAILBOX", ilUtil::formCheckbox(1, 'roles[]', htmlspecialchars($role_addr)));
         if (ilMail::_usePearMail()) {
             // if pear mail is enabled, mailbox addresses are already localized in the language of the user
             $this->tpl->setVariable("MAILBOX", $role_addr);
         } else {
             // if pear mail is not enabled, we need to localize mailbox addresses in the language of the user
             $this->tpl->setVariable("MAILBOX", ilObjRole::_getTranslation($ilObjDataCache->lookupTitle($role_id)) . " (" . $role_addr . ")");
         }
         $this->tpl->parseCurrentBlock();
     }
 }