Esempio n. 1
0
 public static function deliver(Module_PM $module, GWF_PM $pm)
 {
     if (false === ($pmo = GWF_PMOptions::getPMOptions($pm->getReceiver()))) {
         return 0;
     }
     if (!$pmo->isOptionEnabled(GWF_PMOptions::EMAIL_ON_PM)) {
         return 0;
     }
     $sender = $pm->getSender();
     $receiver = $pm->getReceiver();
     if ('' === ($rec = $receiver->getValidMail())) {
         return 0;
     }
     $sendername = $sender->getID() !== '0' ? $sender->display('user_name') : GWF_HTML::langUser($receiver, 'guest');
     $email = new GWF_Mail();
     $email->setSender($module->cfgEmailSender());
     $email->setReceiver($rec);
     $email->setSubject($module->langUser($receiver, 'mail_subj', array($sendername)));
     $autofolder = sprintf('index.php?mo=PM&me=AutoFolder&pmid=%s&uid=%s&token=%s', $pm->getID(), $receiver->getID(), $pm->getHashcode());
     $autofolder = Common::getAbsoluteURL($autofolder);
     $autofolder = GWF_HTML::anchor($autofolder, $autofolder);
     $delete = sprintf('index.php?mo=PM&me=Delete&pmid=%s&uid=%s&token=%s', $pm->getID(), $receiver->getID(), $pm->getHashcode());
     $delete = Common::getAbsoluteURL($delete);
     $delete = GWF_HTML::anchor($delete, $delete);
     $email->setBody($module->langUser($receiver, 'mail_body', array($receiver->displayUsername(), $sendername, $pm->display('pm_title'), $pm->display('pm_message'), $autofolder, $delete)));
     if (false === $email->sendToUser($receiver)) {
         return -4;
     }
     return 1;
 }
Esempio n. 2
0
 private function onEdit()
 {
     $form = $this->getForm();
     if (false !== ($errors = $form->validate($this->module))) {
         return $errors . $this->templateEdit();
     }
     $data = array('pm_title' => $form->getVar('title'), 'pm_message' => $form->getVar('message'));
     if (false === $this->pm->saveVars($data)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false !== ($pm2 = $this->pm->getOtherPM())) {
         if (false === $pm2->saveVars($data)) {
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
         }
     }
     return $this->module->message('msg_edited') . $this->module->requestMethodB('Overview');
 }
Esempio n. 3
0
 private function getTranslated($translate)
 {
     if ($translate === false) {
         return '';
     }
     $text = $this->pm->displayMessage();
     if (false !== ($back = GWF_GTranslate::translate($text, 'auto', GWF_Language::getCurrentISO()))) {
         return $back;
     }
     return '';
 }
Esempio n. 4
0
 private function onDelete($id, $token, $uid)
 {
     if (false === ($pm = GWF_PM::getByID($id))) {
         return $this->module->error('err_pm');
     }
     if ($token != $pm->getHashcode()) {
         echo $pm->getHashcode();
         return $this->module->error('err_pm');
     }
     if (false === ($user = GWF_User::getByID($uid))) {
         return GWF_HTML::err('ERR_UNKNOWN_USER');
     }
     if (false === $pm->markDeleted($user)) {
         return $this->module->error('err_del_twice');
     }
     return $this->module->message('msg_deleted', array('1'));
 }
Esempio n. 5
0
 private function onRestore($ids)
 {
     if (!is_array($ids)) {
         return '';
         #$this->module->error('err_delete');
     }
     $user = GWF_Session::getUser();
     $count = 0;
     foreach ($ids as $id => $stub) {
         if (false === ($pm = GWF_PM::getByID($id))) {
             continue;
         }
         if (false === $pm->canRead($user)) {
             continue;
         }
         if (false === $pm->markDeleted($user, false)) {
             continue;
         }
         $count++;
     }
     $this->sanitize();
     return $this->module->message('msg_restored', array($count));
 }
Esempio n. 6
0
 /**
  * Put all your PMs into auto-folders.
  * @return string
  */
 private function onAutoFolder()
 {
     $user = GWF_Session::getUser();
     $userid = GWF_Session::getUserID();
     if (false === ($pmo = GWF_PMOptions::getPMOptions($user))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (0 >= ($peak = $pmo->getAutoFolderValue())) {
         return $this->module->message('msg_auto_folder_off');
     }
     $del = GWF_PM::OWNER_DELETED;
     # count pm from and to user.
     $conditions = "(pm_owner={$userid} AND pm_options&{$del}=0)";
     $db = gdo_db();
     $pms = GDO::table('GWF_PM');
     $sorted = array();
     if (false === ($result = $pms->select('*', $conditions))) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     # Sort By UID
     while (false !== ($row = $db->fetchAssoc($result))) {
         $pm = new GWF_PM($row);
         $other_user = $pm->getOtherUser($user);
         $other_uid = $other_user->getID();
         if (!isset($sorted[$other_uid])) {
             $sorted[$other_uid] = array();
         }
         $sorted[$other_uid][] = $pm;
     }
     $db->free($result);
     $back = '';
     foreach ($sorted as $uid => $pms) {
         if (count($pms) < $peak) {
             continue;
         }
         $other_user = $pms[0]->getOtherUser($user);
         $foldername = $other_user->getVar('user_name');
         # Create the folder if not exists.
         if (false === ($folder = GWF_PMFolder::getByName($foldername, $user))) {
             $folder = GWF_PMFolder::fakeFolder($user->getID(), $foldername);
             if (false === $folder->insert()) {
                 return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
             }
             $back .= $this->module->message('msg_auto_folder_created', array($other_user->displayUsername()));
         }
         $moved = 0;
         foreach ($pms as $pm) {
             if (false !== $pm->move($user, $folder)) {
                 $moved++;
             }
         }
         if ($moved > 0) {
             $back .= $this->module->message('msg_auto_folder_moved', array($moved, $other_user->displayUsername()));
         }
     }
     return $back . $this->module->message('msg_auto_folder_done');
 }
Esempio n. 7
0
 private function send()
 {
     $form = $this->getForm();
     if (false !== ($error = $form->validate($this->module))) {
         return $error . $this->templateSend();
     }
     # Get reply to field
     if (false !== ($otherid = Common::getGetInt('reply', false))) {
     } elseif (false !== ($otherid = Common::getGetInt('quote', false))) {
     }
     $parent1 = $parent2 = 0;
     if ($otherid !== false) {
         if (false !== ($otherpm = GWF_PM::getByID($otherid))) {
             $parent1 = $otherpm->getID();
             if (false !== ($p2 = $otherpm->getOtherPM())) {
                 $parent2 = $p2;
             }
         }
     }
     $result = $this->module->deliver($this->user->getID(), $this->getReceiver()->getID(), $form->getVar('title'), $form->getVar('message'), $parent1, $parent2);
     $mail = '';
     switch ($result) {
         case '1':
             return $this->module->message('msg_mail_sent', array($this->getReceiver()->display('user_name')));
         case '0':
             break;
         case '-4':
             return GWF_HTML::err('ERR_MAIL_SENT');
         default:
             return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__ . ' - Code: ' . $result));
     }
     return $mail . $this->module->message('msg_sent');
 }
Esempio n. 8
0
while (false !== ($row = $db->fetchAssoc($result))) {
    $o = (int) $row['pm_options'];
    # Sender
    $from_opts = $o & 0x4;
    # smileys
    //	$from_opts |= $o&0x01 ? GWF_PM::READ : 0; # other read
    $from_opts |= GWF_PM::READ;
    # I probably have read what i wrote :)
    $from_opts |= $o & 0x10 ? GWF_PM::OWNER_DELETED : 0;
    # sender deleted
    $from_opts |= $o & 0x20 ? GWF_PM::OTHER_DELETED : 0;
    # reciever deleted
    //	var_dump($o);
    //	var_dump($from_opts);
    $from = new GWF_PM(array('pm_id' => '0', 'pm_date' => $row['pm_date'], 'pm_owner' => $row['pm_from'], 'pm_folder' => $row['pm_from_folder'], 'pm_parent' => $row['pm_in_reply'], 'pm_to' => $row['pm_to'], 'pm_from' => $row['pm_from'], 'pm_otherid' => 0, 'pm_title' => $row['pm_title'], 'pm_message' => $row['pm_message'], 'pm_options' => $from_opts));
    $from->insert();
    $to_opts = 0;
    $to_opts |= $o & 0x1 ? GWF_PM::READ : 0;
    # meme read
    $to_opts |= $o & 0x4;
    # smileys
    $to_opts |= $o & 0x20 ? GWF_PM::OWNER_DELETED : 0;
    # sender deleted
    $to_opts |= $o & 0x10 ? GWF_PM::OTHER_DELETED : 0;
    # reciever deleted
    $to = new GWF_PM(array('pm_id' => '0', 'pm_date' => $row['pm_date'], 'pm_owner' => $row['pm_to'], 'pm_folder' => $row['pm_to_folder'], 'pm_parent' => $row['pm_in_reply'], 'pm_to' => $row['pm_to'], 'pm_from' => $row['pm_from'], 'pm_otherid' => $from->getID(), 'pm_title' => $row['pm_title'], 'pm_message' => $row['pm_message'], 'pm_options' => $to_opts));
    $to->insert();
    $from->saveVar('pm_otherid', $to->getID());
}
$db->free($result);
$db->dropTable($tmp_name);
Esempio n. 9
0
 public function deliver($from, $to, $title, $message, $parent1 = 0, $parent2 = 0)
 {
     require_once 'GWF_PM.php';
     $pm1 = GWF_PM::fakePM($from, $to, $title, $message, $from, GWF_PM::OUTBOX, $parent1);
     $pm1->setOption(GWF_PM::READ, true);
     if (false === $pm1->insert()) {
         return -1;
     }
     $pm2 = GWF_PM::fakePM($from, $to, $title, $message, $to, GWF_PM::INBOX, $parent2, $pm1->getID());
     $pm2->setOption(GWF_PM::OTHER_READ, true);
     if (false === $pm2->insert()) {
         return -2;
     }
     if (false === $pm1->saveVar('pm_otherid', $pm2->getID())) {
         return -3;
     }
     if (false === GWF_Counter::increaseCount('gwf3_pms_sent', 1)) {
         return -4;
     }
     if (!$this->cfgEmailOnPM()) {
         return 0;
     }
     $this->includeClass('GWF_EMailOnPM');
     return GWF_EMailOnPM::deliver($this, $pm2);
 }
Esempio n. 10
0
 private function onMove($ids = NULL)
 {
     $ids = Common::getPost('pm');
     if (!is_array($ids)) {
         return '';
     }
     $user = GWF_Session::getUser();
     if (false === ($folder = GWF_PMFolder::getByID(Common::getPost('folders')))) {
         return $this->module->error('err_folder');
     }
     if ($folder->getVar('pmf_uid') !== $user->getID()) {
         return $this->module->error('err_folder');
     }
     $count = 0;
     foreach ($ids as $id => $stub) {
         if (false === ($pm = GWF_PM::getByID($id))) {
             continue;
         }
         if (false === $pm->canRead($user)) {
             continue;
         }
         if (false === $pm->move($user, $folder)) {
             continue;
         }
         $count++;
     }
     $this->sanitize();
     return $this->module->message('msg_moved', array($count));
 }