| 1 | <?php |
|---|
| 2 | require_once(WCF_DIR.'lib/acp/form/ACPForm.class.php'); |
|---|
| 3 | require_once(WCF_DIR.'lib/data/user/UserEditor.class.php'); |
|---|
| 4 | require_once(WCF_DIR.'lib/data/user/group/Group.class.php'); |
|---|
| 5 | require_once(WCF_DIR.'lib/system/exception/IllegalLinkException.class.php'); |
|---|
| 6 | require_once(WCF_DIR.'lib/data/InstantMessage/IM.class.php'); |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | * Shows the send IM to group form. |
|---|
| 10 | * |
|---|
| 11 | * @author Robert "Tatzelwurm" Hempel |
|---|
| 12 | * @copyright 2007/2008 INSIDE das Hörspiel |
|---|
| 13 | * @license GNU LGPL http://www.gnu.org/licenses/lgpl.txt |
|---|
| 14 | * @package de.inside.wcf.instantMessenger |
|---|
| 15 | * |
|---|
| 16 | */ |
|---|
| 17 | class UserIMForm extends ACPForm { |
|---|
| 18 | public $templateName = 'userIM'; |
|---|
| 19 | public $neededPermissions = 'admin.user.canIMUser'; |
|---|
| 20 | |
|---|
| 21 | public $userIDs = ''; |
|---|
| 22 | public $groupIDs = array(); |
|---|
| 23 | public $subject = ''; |
|---|
| 24 | public $text = ''; |
|---|
| 25 | public $from = ''; |
|---|
| 26 | public $users = array(); |
|---|
| 27 | public $groups = array(); |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * @see Page::readParameters() |
|---|
| 31 | */ |
|---|
| 32 | public function readParameters() { |
|---|
| 33 | if (!INSTANTMESSENGER_AKTIV) { |
|---|
| 34 | require_once(WCF_DIR.'lib/system/exception/NamedUserException.class.php'); |
|---|
| 35 | throw new NamedUserException(WCF::getLanguage()->get('wcf.instantmessenger.inactiv')); |
|---|
| 36 | |
|---|
| 37 | } |
|---|
| 38 | parent::readParameters(); |
|---|
| 39 | $this->activeMenuItem = ('wcf.acp.menu.link.group.im'); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * @see Form::readFormParameters() |
|---|
| 44 | */ |
|---|
| 45 | public function readFormParameters() { |
|---|
| 46 | parent::readFormParameters(); |
|---|
| 47 | |
|---|
| 48 | if (isset($_POST['groupIDs']) && is_array($_POST['groupIDs'])) $this->groupIDs = ArrayUtil::toIntegerArray($_POST['groupIDs']); |
|---|
| 49 | if (isset($_POST['subject'])) $this->subject = StringUtil::trim($_POST['subject']); |
|---|
| 50 | if (isset($_POST['text'])) $this->text = StringUtil::trim($_POST['text']); |
|---|
| 51 | if (isset($_POST['from'])) $this->from = StringUtil::trim($_POST['from']); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | /** |
|---|
| 55 | * @see Form::validate() |
|---|
| 56 | */ |
|---|
| 57 | public function validate() { |
|---|
| 58 | parent::validate(); |
|---|
| 59 | |
|---|
| 60 | if (!count($this->groupIDs)) { |
|---|
| 61 | throw new UserInputException('groupIDs'); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | if (empty($this->subject)) { |
|---|
| 65 | throw new UserInputException('subject'); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | if (empty($this->text)) { |
|---|
| 69 | throw new UserInputException('text'); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | if (empty($this->from)) { |
|---|
| 73 | throw new UserInputException('from'); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | /** |
|---|
| 78 | * @see Form::save() |
|---|
| 79 | */ |
|---|
| 80 | public function save() { |
|---|
| 81 | parent::save(); |
|---|
| 82 | |
|---|
| 83 | // save config in session |
|---|
| 84 | $userIMData = WCF::getSession()->getVar('userIMData'); |
|---|
| 85 | if ($userIMData === null) $userIMData = array(); |
|---|
| 86 | $imID = count($userIMData); |
|---|
| 87 | $userIMData[$imID] = array( |
|---|
| 88 | 'groupIDs' => implode(',', $this->groupIDs), |
|---|
| 89 | 'subject' => $this->subject, |
|---|
| 90 | 'text' => $this->text, |
|---|
| 91 | 'from' => $this->from |
|---|
| 92 | ); |
|---|
| 93 | WCF::getSession()->register('userIMData', $userIMData); |
|---|
| 94 | $this->saved(); |
|---|
| 95 | |
|---|
| 96 | // show worker template |
|---|
| 97 | WCF::getTPL()->assign(array( |
|---|
| 98 | 'pageTitle' => WCF::getLanguage()->get('wcf.acp.user.sendIM.group'), |
|---|
| 99 | 'url' => 'index.php?action=UserIM&imID='.$imID.'&packageID='.PACKAGE_ID.SID_ARG_2ND_NOT_ENCODED |
|---|
| 100 | )); |
|---|
| 101 | WCF::getTPL()->display('worker'); |
|---|
| 102 | exit; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * @see Page::assignVariables() |
|---|
| 107 | */ |
|---|
| 108 | public function readData() { |
|---|
| 109 | parent::readData(); |
|---|
| 110 | |
|---|
| 111 | $this->groups = Group::getAccessibleGroups(array(), array(Group::GUESTS, Group::EVERYONE)); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | /** |
|---|
| 115 | * @see Page::assignVariables() |
|---|
| 116 | */ |
|---|
| 117 | public function assignVariables() { |
|---|
| 118 | parent::assignVariables(); |
|---|
| 119 | WCF::getTPL()->assign(array( |
|---|
| 120 | 'groups' => $this->groups, |
|---|
| 121 | 'groupIDs' => $this->groupIDs, |
|---|
| 122 | 'subject' => $this->subject, |
|---|
| 123 | 'text' => $this->text, |
|---|
| 124 | 'from' => $this->from = WCF::getUser()->username, |
|---|
| 125 | )); |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | ?> |
|---|