Esempio n. 1
0
 /**
  * Overwrites the parent method. This method combines messages with the same
  * content and prepares them for sending them as a mail with multiple 
  * recepients instead of one mail for each recipient.
  * The actual sending task is done bulkSend().
  * 
  * @global object $user
  * 
  * @param string $rec_user_id  user_id of recipient
  * @param string $snd_user_id  user_id of sender
  * @param string $message      the message
  * @param string $subject      subject for the message
  * @param string $message_id   the message_id in the database
  */
 function sendingEmail($rec_user_id, $snd_user_id, $message, $subject, $message_id)
 {
     global $user;
     $db4 = new DB_Seminar("SELECT user_id, Email FROM auth_user_md5 WHERE user_id = '{$rec_user_id}';");
     $db4->next_record();
     if ($to = $db4->f("Email")) {
         $rec_fullname = 'Sie';
         setTempLanguage($db4->f("user_id"));
         if (empty($this->bulk_mail[md5($message)][getenv('LANG')])) {
             $title = "[Stud.IP - " . $GLOBALS['UNI_NAME_CLEAN'] . "] " . stripslashes(kill_format(str_replace(array("\r", "\n"), '', $subject)));
             if ($snd_user_id != "____%system%____") {
                 $snd_fullname = get_fullname($snd_user_id);
                 $db4->query("SELECT Email FROM auth_user_md5 WHERE user_id = '{$user->id}'");
                 $db4->next_record();
                 $reply_to = $db4->f("Email");
             }
             $template = $GLOBALS['template_factory']->open('mail/text');
             $template->set_attribute('message', kill_format(stripslashes($message)));
             $template->set_attribute('rec_fullname', $rec_fullname);
             $mailmessage = $template->render();
             $template = $GLOBALS['template_factory']->open('mail/html');
             $template->set_attribute('lang', getUserLanguagePath($rec_user_id));
             $template->set_attribute('message', stripslashes($message));
             $template->set_attribute('rec_fullname', $rec_fullname);
             $mailhtml = $template->render();
             $this->bulk_mail[md5($message)][getenv('LANG')] = array('text' => $mailmessage, 'html' => $mailhtml, 'title' => $title, 'reply_to' => $reply_to, 'message_id' => $message_id, 'users' => array());
         }
         $this->bulk_mail[md5($message)][getenv('LANG')]['users'][$db4->f('user_id')] = $to;
         restoreLanguage();
     }
 }
Esempio n. 2
0
function first_decision($userid) {
    $vis_cmd = Request::option('vis_cmd');
    $vis_state = Request::option('vis_state');
    $user_language = getUserLanguagePath($userid);

    if ($vis_cmd == "apply" && ($vis_state == "global" || $vis_state == "yes" || $vis_state == "no")) {
        $query = "UPDATE auth_user_md5 SET visible = ? WHERE user_id = ?";
        $statement = DBManager::get()->prepare($query);
        $statement->execute(array($vis_state, $userid));
        return;
    }

    $query = "SELECT visible FROM auth_user_md5 WHERE user_id = ?";
    $statement = DBManager::get()->prepare($query);
    $statement->execute(array($userid));
    $visiblity = $statement->fetchColumn();

    if ($visiblity != 'unknown') {
        return;
    }

    PageLayout::setTitle(_('Bitte wählen Sie Ihren Sichtbarkeitsstatus aus!'));
    PageLayout::setTabNavigation(NULL);

    // avoid recursion when loading the header
    $GLOBALS['USER_VISIBILITY_CHECK'] = false;

    $template = $GLOBALS['template_factory']->open("../locale/$user_language/LC_HELP/visibility_decision.php");
    $template->set_layout('layouts/base_without_infobox');

    echo $template->render();
    page_close();
    die;
}
Esempio n. 3
0
 /**
  *
  * @param $rec_user_id
  * @param $snd_user_id
  * @param $message
  * @param $subject
  * @param $message_id
  */
 function sendingEmail($rec_user_id, $snd_user_id, $message, $subject, $message_id)
 {
     $receiver = User::find($rec_user_id);
     $to = $receiver->Email;
     // do not try to send mails to users without a mail address
     if (!$to) {
         return;
     }
     $rec_fullname = $receiver->getFullName();
     setTempLanguage($rec_user_id);
     $title = "[Stud.IP - " . $GLOBALS['UNI_NAME_CLEAN'] . "] " . kill_format(str_replace(array("\r", "\n"), '', $subject));
     if ($snd_user_id != "____%system%____") {
         $sender = User::find($snd_user_id);
         $snd_fullname = $sender->getFullName();
         $reply_to = $sender->Email;
     }
     $template = $GLOBALS['template_factory']->open('mail/text');
     $template->set_attribute('message', kill_format($message));
     $template->set_attribute('rec_fullname', $rec_fullname);
     $mailmessage = $template->render();
     $template = $GLOBALS['template_factory']->open('mail/html');
     $template->set_attribute('lang', getUserLanguagePath($rec_user_id));
     $template->set_attribute('message', $message);
     $template->set_attribute('rec_fullname', $rec_fullname);
     $mailhtml = $template->render();
     restoreLanguage();
     // Now, let us send the message
     $mail = new StudipMail();
     $mail->setSubject($title)->addRecipient($to, $rec_fullname)->setReplyToEmail('')->setBodyText($mailmessage);
     if (strlen($reply_to)) {
         $mail->setSenderEmail($reply_to)->setSenderName($snd_fullname);
     }
     $user_cfg = UserConfig::get($rec_user_id);
     if ($user_cfg->getValue('MAIL_AS_HTML')) {
         $mail->setBodyHtml($mailhtml);
     }
     if ($GLOBALS['ENABLE_EMAIL_ATTACHMENTS']) {
         foreach (get_message_attachments($message_id) as $attachment) {
             $mail->addStudipAttachment($attachment['dokument_id']);
         }
     }
     if (!get_config("MAILQUEUE_ENABLE")) {
         $mail->send();
     } else {
         MailQueueEntry::add($mail, $message_id, $rec_user_id);
     }
 }
Esempio n. 4
0
 /**
  * Imports a line of the table into the Stud.IP database if the check returns no errors.
  * @param array $line : array of fields
  * @return array : array('found' => true|false, 'errors' => "Error message", 'pk' => "primary key")
  */
 public function importLine($line)
 {
     $plugin = $this->getPlugin();
     $classname = $this['import_type'];
     if (!$classname) {
         return array();
     }
     $data = $this->getMappedData($line);
     $pk = $this->getPrimaryKey($data);
     //Last chance to quit:
     $error = $this->checkLine($line, $data, $pk);
     $output = array();
     $object = new $classname($pk);
     if (!$object->isNew()) {
         $output['found'] = true;
         $output['pk'] = $pk;
         foreach ((array) $this['tabledata']['ignoreonupdate'] as $fieldname) {
             unset($data[$fieldname]);
         }
     } else {
         $output['found'] = false;
     }
     foreach ($data as $fieldname => $value) {
         if ($value !== false && in_array($fieldname, $this->getTargetFields())) {
             $object[$fieldname] = $value;
             if ($classname === "User" && $fieldname === "password") {
                 $object[$fieldname] = UserManagement::getPwdHasher()->HashPassword($value);
             }
         }
     }
     if (method_exists($object, "getFullName")) {
         $error['name'] = $output['name'] = $object->getFullName();
     } elseif ($object->isField("name")) {
         $error['name'] = $output['name'] = $object['name'];
     } elseif ($object->isField("title")) {
         $error['name'] = $output['name'] = $object['title'];
     }
     if ($error && $error['errors']) {
         //exit here to have the name of the object in the log
         return $error;
     }
     if ($plugin) {
         $plugin->beforeUpdate($object, $line, $data);
     }
     $object->store();
     $output['pk'] = (array) $object->getId();
     //Dynamic special fields:
     switch ($classname) {
         case "Course":
             //fleximport_dozenten
             foreach ($data['fleximport_dozenten'] as $dozent_id) {
                 $seminar = new Seminar($object->getId());
                 $seminar->addMember($dozent_id, 'dozent');
             }
             //fleximport_related_institutes
             if (!$data['fleximport_related_institutes']) {
                 $data['fleximport_related_institutes'] = array($object['institut_id']);
             } else {
                 if (!in_array($object['institut_id'], $data['fleximport_related_institutes'])) {
                     $data['fleximport_related_institutes'][] = $object['institut_id'];
                 }
             }
             foreach ($data['fleximport_related_institutes'] as $institut_id) {
                 $insert = DBManager::get()->prepare("\n                        INSERT IGNORE INTO seminar_inst\n                        SET seminar_id = :seminar_id,\n                            institut_id = :institut_id\n                    ");
                 $insert->execute(array('seminar_id' => $object->getId(), 'institut_id' => $institut_id));
             }
             if ($this['tabledata']['simplematching']["fleximport_course_userdomains"]['column'] || in_array("fleximport_course_userdomains", $this->fieldsToBeDynamicallyMapped())) {
                 $statement = DBManager::get()->prepare("\n                        SELECT userdomain_id\n                        FROM seminar_userdomains\n                        WHERE seminar_id = ?\n                    ");
                 $statement->execute(array($object->getId()));
                 $olddomains = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
                 foreach (array_diff($data['fleximport_user_inst'], $olddomains) as $to_add) {
                     $domain = new UserDomain($to_add);
                     $domain->addSeminar($object->getId());
                 }
                 foreach (array_diff($olddomains, $data['fleximport_user_inst']) as $to_remove) {
                     $domain = new UserDomain($to_remove);
                     $domain->removeSeminar($object->getId());
                 }
             }
             break;
         case "User":
             if ($this['tabledata']['simplematching']["fleximport_user_inst"]['column'] || in_array("fleximport_user_inst", $this->fieldsToBeDynamicallyMapped())) {
                 if ($object['perms'] !== "root") {
                     foreach ($data['fleximport_user_inst'] as $institut_id) {
                         $member = new InstituteMember(array($object->getId(), $institut_id));
                         $member['inst_perms'] = $object['perms'];
                         $member->store();
                     }
                 }
             }
             if ($this['tabledata']['simplematching']["fleximport_userdomains"]['column'] || in_array("fleximport_userdomains", $this->fieldsToBeDynamicallyMapped())) {
                 $olddomains = UserDomain::getUserDomainsForUser($object->getId());
                 foreach ($olddomains as $olddomain) {
                     if (!in_array($olddomain->getID(), (array) $data['fleximport_userdomains'])) {
                         $olddomain->removeUser($object->getId());
                     }
                 }
                 foreach ($data['fleximport_userdomains'] as $userdomain) {
                     $domain = new UserDomain($userdomain);
                     $domain->addUser($object->getId());
                 }
                 AutoInsert::instance()->saveUser($object->getId());
                 foreach ($data['fleximport_userdomains'] as $domain_id) {
                     if (!in_array($domain_id, $olddomains)) {
                         $welcome = FleximportConfig::get("USERDOMAIN_WELCOME_" . $domain_id);
                         if ($welcome) {
                             foreach ($object->toArray() as $field => $value) {
                                 $welcome = str_replace("{{" . $field . "}}", $value, $welcome);
                             }
                             foreach ($line as $field => $value) {
                                 $welcome = str_replace("{{" . $field . "}}", $value, $welcome);
                             }
                             if (strpos($welcome, "\n") === false) {
                                 $subject = _("Willkommen!");
                             } else {
                                 $subject = strstr($welcome, "\n", true);
                                 $welcome = substr($welcome, strpos($welcome, "\n") + 1);
                             }
                             $messaging = new messaging();
                             $count = $messaging->insert_message($welcome, $object->username, '____%system%____', null, null, null, null, $subject, true, 'normal');
                         }
                     }
                 }
             }
             if ($this['tabledata']['simplematching']["fleximport_expiration_date"]['column'] || in_array("fleximport_expiration_date", $this->fieldsToBeDynamicallyMapped())) {
                 if ($data['fleximport_expiration_date']) {
                     UserConfig::get($object->getId())->store("EXPIRATION_DATE", $data['fleximport_expiration_date']);
                 } else {
                     UserConfig::get($object->getId())->delete("EXPIRATION_DATE");
                 }
             }
             if ($output['found'] === false && $data['fleximport_welcome_message'] !== "none") {
                 $user_language = getUserLanguagePath($object->getId());
                 setTempLanguage(false, $user_language);
                 if ($data['fleximport_welcome_message'] && FleximportConfig::get($data['fleximport_welcome_message'])) {
                     $message = FleximportConfig::get($data['fleximport_welcome_message']);
                     foreach ($data as $field => $value) {
                         $message = str_replace("{{" . $field . "}}", $value, $message);
                     }
                     foreach ($line as $field => $value) {
                         if (!in_array($field, $data)) {
                             $message = str_replace("{{" . $field . "}}", $value, $message);
                         }
                     }
                     if (strpos($message, "\n") === false) {
                         $subject = dgettext($user_language, "Anmeldung Stud.IP-System");
                     } else {
                         $subject = strstr($message, "\n", true);
                         $message = substr($message, strpos($message, "\n") + 1);
                     }
                 } else {
                     $Zeit = date("H:i:s, d.m.Y", time());
                     $this->user_data = array('auth_user_md5.username' => $object['username'], 'auth_user_md5.perms' => $object['perms'], 'auth_user_md5.Vorname' => $object['vorname'], 'auth_user_md5.Nachname' => $object['nachname'], 'auth_user_md5.Email' => $object['email']);
                     $password = $data['password'];
                     //this is the not hashed password in cleartext
                     include "locale/{$user_language}/LC_MAILS/create_mail.inc.php";
                     $message = $mailbody;
                 }
                 if ($message) {
                     $mail = new StudipMail();
                     $mail->addRecipient($object['email'], $object->getFullName());
                     $mail->setSubject($subject);
                     $mail->setBodyText($message);
                     $mail->setBodyHtml(formatReady($message));
                     if (Config::get()->MAILQUEUE_ENABLE) {
                         MailQueueEntry::add($mail);
                     } else {
                         $mail->send();
                     }
                 }
                 restoreLanguage();
             }
             break;
     }
     //Datafields:
     $datafields = array();
     switch ($classname) {
         case "Course":
             $datafields = Datafield::findBySQL("object_type = 'sem'");
             break;
         case "User":
             $datafields = Datafield::findBySQL("object_type = 'user'");
             break;
         case "CourseMember":
             $datafields = Datafield::findBySQL("object_type = 'usersemdata'");
             break;
     }
     foreach ($datafields as $datafield) {
         $fieldname = $datafield['name'];
         if (isset($data[$fieldname])) {
             $entry = new DatafieldEntryModel(array($datafield->getId(), $object->getId(), ""));
             $entry['content'] = $data[$fieldname];
             $entry->store();
         }
     }
     if ($classname === "Course") {
         if ($this['tabledata']['simplematching']["fleximport_studyarea"]['column'] || in_array("fleximport_studyarea", $this->fieldsToBeDynamicallyMapped())) {
             //Studienbereiche:
             $remove = DBManager::get()->prepare("\n                    DELETE FROM seminar_sem_tree\n                    WHERE seminar_id = :seminar_id\n                ");
             $remove->execute(array('seminar_id' => $object->getId()));
             if ($GLOBALS['SEM_CLASS'][$GLOBALS['SEM_TYPE'][$data['status']]['class']]['bereiche']) {
                 foreach ($data['fleximport_studyarea'] as $sem_tree_id) {
                     $insert = DBManager::get()->prepare("\n                            INSERT IGNORE INTO seminar_sem_tree\n                            SET sem_tree_id = :sem_tree_id,\n                                seminar_id = :seminar_id\n                        ");
                     $insert->execute(array('sem_tree_id' => $sem_tree_id, 'seminar_id' => $object->getId()));
                 }
             }
         }
         if ($this['tabledata']['simplematching']["fleximport_locked"]['column'] || in_array("fleximport_locked", $this->fieldsToBeDynamicallyMapped())) {
             //Lock or unlock course
             if ($data['fleximport_locked']) {
                 CourseSet::addCourseToSet(CourseSet::getGlobalLockedAdmissionSetId(), $object->getId());
             } elseif (in_array($data['fleximport_locked'], array("0", 0)) && $data['fleximport_locked'] !== "") {
                 CourseSet::removeCourseFromSet(CourseSet::getGlobalLockedAdmissionSetId(), $object->getId());
             }
         }
         $folder_exist = DBManager::get()->prepare("\n                SELECT 1 FROM folder WHERE range_id = ?\n            ");
         $folder_exist->execute(array($object->getId()));
         if (!$folder_exist->fetch()) {
             $insert_folder = DBManager::get()->prepare("\n                    INSERT IGNORE INTO folder\n                    SET folder_id = MD5(CONCAT(:seminar_id, 'allgemeine_dateien')),\n                    range_id = :seminar_id,\n                    user_id = :user_id,\n                    name = :name,\n                    description = :description,\n                    mkdate = UNIX_TIMESTAMP(),\n                    chdate = UNIX_TIMESTAMP()\n                ");
             $insert_folder->execute(array('seminar_id' => $object->getId(), 'user_id' => $GLOBALS['user']->id, 'name' => _("Allgemeiner Dateiordner"), 'description' => _("Ablage für allgemeine Ordner und Dokumente der Veranstaltung")));
         }
     }
     if ($plugin && !$object->isNew()) {
         $plugin->afterUpdate($object, $line);
     }
     return $output;
 }
Esempio n. 5
0
 function getAllNotifications($user_id = NULL)
 {
     if (is_null($user_id)) {
         $user_id = $GLOBALS['user']->id;
     }
     $my_sem = array();
     $query = "SELECT s.Seminar_id, s.Name, s.chdate, s.start_time, s.modules, s.status as sem_status, su.status,s.admission_prelim, su.notification, IFNULL(visitdate, :threshold) AS visitdate " . "FROM seminar_user su " . "LEFT JOIN seminare s USING (Seminar_id) " . "LEFT JOIN object_user_visits ouv ON (ouv.object_id = su.Seminar_id AND ouv.user_id = :user_id AND ouv.type = 'sem') " . "WHERE su.user_id = :user_id AND su.status != 'user' AND su.notification <> 0";
     if (get_config('DEPUTIES_ENABLE')) {
         $query .= " UNION SELECT s.Seminar_id, CONCAT(s.Name, ' [Vertretung]') as Name, s.chdate, s.start_time, s.modules, s.status as sem_status, 'dozent' as status, s.admission_prelim, d.notification, IFNULL(visitdate, :threshold) AS visitdate " . "FROM deputies d " . "LEFT JOIN seminare s ON (d.range_id = s.Seminar_id) " . "LEFT JOIN object_user_visits ouv ON (ouv.object_id = d.range_id AND ouv.user_id = :user_id AND ouv.type = 'sem') " . "WHERE d.user_id = :user_id AND d.notification <> 0";
     }
     $statement = DBManager::get()->prepare($query);
     $statement->bindValue(':user_id', $user_id);
     $statement->bindValue(':threshold', ($threshold = Config::get()->NEW_INDICATOR_THRESHOLD) ? strtotime("-{$threshold} days 0:00:00") : 0);
     $statement->execute();
     while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
         $seminar_id = $row['Seminar_id'];
         $modules = $this->getLocalModules($seminar_id, 'sem', $row['modules'], $row['sem_status']);
         $modulesInt = array_sum($modules);
         //korrigiert wg. SemClass::isSlotMandatory() Kram
         $my_sem[$seminar_id] = array('name' => $row['Name'], 'chdate' => $row['chdate'], 'start_time' => $row['start_time'], 'modules' => $modules, 'modulesInt' => $modulesInt, 'visitdate' => $row['visitdate'], 'obj_type' => 'sem', 'notification' => $row['notification'], 'sem_status' => $row['sem_status'], 'status' => $row['status'], 'prelim' => $row['admission_prelim']);
         unset($seminar_id);
         unset($modules);
         unset($modulesInt);
     }
     $m_enabled_modules = $this->getGlobalEnabledNotificationModules('sem');
     $m_extended = 0;
     foreach ($this->registered_notification_modules as $m_data) {
         $m_extended += pow(2, $m_data['id']);
     }
     get_my_obj_values($my_sem, $user_id);
     $news = array();
     foreach ($my_sem as $seminar_id => $s_data) {
         $m_notification = $s_data['modulesInt'] + $m_extended & $s_data['notification'];
         $n_data = array();
         foreach ($m_enabled_modules as $m_name => $m_data) {
             if ($this->isBit($m_notification, $m_data['id'])) {
                 if ($m_name != 'plugins') {
                     $data = $this->getModuleText($m_name, $seminar_id, $s_data, 'sem');
                     if ($data) {
                         $n_data[] = $data;
                     }
                 } else {
                     $sem_class = $GLOBALS['SEM_CLASS'][$GLOBALS['SEM_TYPE'][$s_data['sem_status']]["class"]];
                     if (is_object($sem_class)) {
                         foreach (PluginEngine::getPlugins('StandardPlugin', $seminar_id) as $plugin) {
                             if (!$sem_class->isSlotModule($plugin)) {
                                 $data = $this->getPluginText($plugin, $seminar_id, $s_data, 'plugins');
                                 if ($data) {
                                     $n_data[] = $data;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (count($n_data)) {
             $news[$s_data['name']] = $n_data;
         }
     }
     if (count($news)) {
         $template = $GLOBALS['template_factory']->open('mail/notification_html');
         $template->set_attribute('lang', getUserLanguagePath($user_id));
         $template->set_attribute('news', $news);
         $template_text = $GLOBALS['template_factory']->open('mail/notification_text');
         $template_text->set_attribute('news', $news);
         return array('text' => $template_text->render(), 'html' => $template->render());
     } else {
         return FALSE;
     }
 }
Esempio n. 6
0
 /**
  * Change an existing user password
  *
  * @param string $password
  * @return bool change successful?
  */
 function changePassword($password)
 {
     global $perm;
     $this->user_data['auth_user_md5.password'] = self::getPwdHasher()->HashPassword($password);
     $this->storeToDatabase();
     $this->msg .= "msg§" . _("Das Passwort wurde neu gesetzt.") . "§";
     // include language-specific subject and mailbody
     $user_language = getUserLanguagePath($this->user_data['auth_user_md5.user_id']);
     $Zeit = date("H:i:s, d.m.Y", time());
     include "locale/{$user_language}/LC_MAILS/password_mail.inc.php";
     // send mail
     StudipMail::sendMessage($this->user_data['auth_user_md5.Email'], $subject, $mailbody);
     return TRUE;
 }
Esempio n. 7
0
    function setPassword () {

        // Can we reach the email?
        if (!$this->checkMail($this->user_data['auth_user_md5.Email'])) {
            return FALSE;
        }

        $password = $this->generate_password(6);
        $this->user_data['auth_user_md5.password'] = self::getPwdHasher()->HashPassword($password);

        if (!$this->storeToDatabase()) {
            $this->msg .= "error§" . _("Die Änderung konnte nicht in die Datenbank geschrieben werden.") . "§";
            return FALSE;
        }

        $this->msg .= "msg§" . sprintf(_("Passwort von Benutzer \"%s\" neu gesetzt."), $this->user_data['auth_user_md5.username']) . "§";

        // include language-specific subject and mailbody
        $user_language = getUserLanguagePath($this->user_data['auth_user_md5.user_id']);
        include("locale/$user_language/LC_MAILS/password_mail.inc.php");

        // send mail
        StudipMail::sendMessage($this->user_data['auth_user_md5.Email'], $subject, $mailbody);

        log_event("USER_NEWPWD",$this->user_data['auth_user_md5.user_id']);
        return TRUE;

    }