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

cron/classes/class.ilCronForumNotification.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 
00034 class ilCronForumNotification
00035 {
00036         function ilCronForumNotification()
00037         {
00038                 global $ilLog,$ilDB;
00039 
00040                 $this->log =& $ilLog;
00041                 $this->db =& $ilDB;
00042         }
00043 
00044         function sendNotifications()
00045         {
00046                 global $ilias, $ilUser, $rbacsystem, $lng;
00047 
00048                 include_once "./classes/class.ilObjForum.php";
00049                 include_once "./classes/class.ilMail.php";
00050                 include_once "./classes/class.ilObjUser.php";
00051                 include_once "./classes/class.ilLanguage.php";
00052 
00053                 $forumObj = new ilObjForum($_GET["ref_id"]);
00054                 $frm =& $forumObj->Forum;
00055 
00056                 if(!($lastDate = $ilias->getSetting("cron_forum_notification_last_date")))
00057                 {
00058                         $lastDate = "0000-00-00 00:00:00";
00059                 }
00060 
00061                 $q = "SELECT frm_threads.thr_subject AS thr_subject, frm_data.top_name AS top_name, frm_data.top_frm_fk AS obj_id, frm_notification.user_id AS user_id, frm_posts.* FROM frm_notification, frm_posts, frm_threads, frm_data WHERE ";
00062                 $q .= "frm_posts.pos_date >= '" . $lastDate . "' AND ";
00063                 $q .= "frm_posts.pos_thr_fk = frm_threads.thr_pk AND ";
00064                 $q .= "frm_threads.thr_pk = frm_notification.thread_id AND ";
00065                 $q .= "frm_data.top_pk >= frm_threads.thr_top_fk ";
00066                 $q .= "ORDER BY frm_posts.pos_date ASC";
00067                 $res = $this->db->query($q);
00068                 if (!DB::isError($res) &&
00069                         is_object($res) &&
00070                         $res->numRows() > 0)
00071                 {
00072                         while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00073                         {
00074                                 if ($row["pos_usr_id"] != $row["user_id"])
00075                                 {
00076                                         // GET AUTHOR OF NEW POST
00077                                         $tmp_user =& new ilObjUser($row["pos_usr_id"]);
00078                                         $row["pos_usr_name"] = $tmp_user->getLogin();
00079 
00080                                         // GET USER WHO WANTS TO BE INFORMED ABOUT NEW POSTS
00081                                         $tmp_user =& new ilObjUser($row["user_id"]);
00082         
00083                                         if (is_array($obj_data = ilObject::_getAllReferences($row["obj_id"])))
00084                                         {
00085                                                 foreach($obj_data as $ref_id)
00086                                                 {
00087                                                         if ($rbacsystem->checkAccessOfUser($row["user_id"], "read", $ref_id))
00088                                                         {
00089                                                                 $row["ref_id"] = $ref_id;
00090                                                                 break;
00091                                                         }
00092                                                 }
00093                                         }
00094         
00095                                         if ($row["ref_id"] != "")
00096                                         {
00097                                                 // SEND NOTIFICATIONS BY E-MAIL
00098                                                 $lng =& new ilLanguage($tmp_user->getLanguage());
00099                                                 $lng->loadLanguageModule("forum");
00100                                                 $frm->setLanguage($lng);
00101                                                 $tmp_mail_obj = new ilMail($row["pos_usr_id"]);
00102                                                 $message = $tmp_mail_obj->sendMail($tmp_user->getLogin(),"","",
00103                                                                                                                    $frm->formatNotificationSubject(),
00104                                                                                                                    $frm->formatNotification($row, 1),
00105                                                                                                                    array(),array("normal"));
00106                                                 unset($tmp_mail_obj);
00107                                         }
00108         
00109                                         unset($tmp_user);
00110                                 }
00111                         }
00112                 }
00113 
00114                 $ilias->setSetting("cron_forum_notification_last_date", date("Y-m-d H:i:s"));
00115 
00116                 return true;
00117         }
00118 }
00119 ?>

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