Exporting email addresses now working
authorAlexander Ebert <ebert@woltlab.com>
Thu, 15 Sep 2011 12:49:49 +0000 (14:49 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 15 Sep 2011 12:49:49 +0000 (14:49 +0200)
wcfsetup/install/files/acp/templates/userEmailAddressExport.tpl
wcfsetup/install/files/lib/acp/form/UserEmailAddressExportForm.class.php

index 7ed69575e4a2281fe10914ddf6cb04f85287122b..796813fdaaeae5891e78054be36b8e76836d0030 100644 (file)
@@ -2,17 +2,9 @@
 
 <script type="text/javascript">
        //<![CDATA[
-       function setFileType(newType) {
-               switch (newType) {
-                       case 'csv':
-                               showOptions('separatorDiv', 'textSeparatorDiv');
-                               break;
-                       case 'xml':
-                               hideOptions('separatorDiv', 'textSeparatorDiv');
-                               break;
-               }
-       }
-       onloadEvents.push(function() { setFileType('{@$fileType}'); });
+       $(function() {
+               new WCF.ACP.Options();
+       });
        //]]>
 </script>
 
@@ -24,7 +16,6 @@
 </header>
 
 <form method="post" action="index.php?form=UserEmailAddressExport">
-
        <div class="border content">
                <fieldset>
                        <legend>{lang}wcf.acp.user.exportEmailAddress.markedUsers{/lang}</legend>
@@ -47,8 +38,8 @@
                                                
                                                <dl>
                                                        <dd><!-- ToDo: Definition List -->
-                                                               <li><label><input type="radio" onclick="if (IS_SAFARI) setFileType('csv')" onfocus="setFileType('csv')" name="fileType" value="csv" {if $fileType == 'csv'}checked="checked" {/if}/> {lang}wcf.acp.user.exportEmailAddress.fileType.csv{/lang}</label></li>
-                                                               <li><label><input type="radio" onclick="if (IS_SAFARI) setFileType('xml')" onfocus="setFileType('xml')" name="fileType" value="xml" {if $fileType == 'xml'}checked="checked" {/if}/> {lang}wcf.acp.user.exportEmailAddress.fileType.xml{/lang}</label></li>
+                                                               <li><label><input type="radio" class="enablesOptions" data-disableOptions="[ ]" data-enableOptions="[ 'separatorDiv', 'textSeparatorDiv' ]" name="fileType" value="csv" {if $fileType == 'csv'}checked="checked" {/if}/> {lang}wcf.acp.user.exportEmailAddress.fileType.csv{/lang}</label></li>
+                                                               <li><label><input type="radio" class="enablesOptions" data-disableOptions="[ 'separatorDiv', 'textSeparatorDiv' ]" data-enableOptions="[ ]" name="fileType" value="xml" {if $fileType == 'xml'}checked="checked" {/if}/> {lang}wcf.acp.user.exportEmailAddress.fileType.xml{/lang}</label></li>
                                                        </dd>
                                                </dl>
                                        </fieldset>
@@ -76,7 +67,6 @@
                <input type="reset" value="{lang}wcf.global.button.reset{/lang}" accesskey="r" />
                <input type="submit" value="{lang}wcf.global.button.submit{/lang}" accesskey="s" />
                {@SID_INPUT_TAG}
-               <input type="hidden" name="userIDs" value="{@$userIDs}" />
        </div>
 </form>
 
index 3bd5cda46b55eb319d6a4dfdb5634a156759a8cd..8e3dd35a5b11aea48a4d8526240b3b2c0164ad25 100755 (executable)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\acp\form;
 use wcf\data\user\User;
+use wcf\system\clipboard\ClipboardHandler;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\WCF;
@@ -28,6 +29,33 @@ class UserEmailAddressExportForm extends ACPForm {
        public $textSeparator = '"'; 
        public $users = array();
        
+       /**
+        * clipboard item type id
+        * @var integer
+        */
+       protected $typeID = null;
+       
+       /**
+        * @see wcf\page\IPage::readParameters()
+        */
+       public function readParameters() {
+               parent::readParameters();
+               
+               // get type id
+               $this->typeID = ClipboardHandler::getInstance()->getTypeID('com.woltlab.wcf.user');
+               if ($this->typeID === null) {
+                       throw new SystemException("clipboard item type 'com.woltlab.wcf.user' is unknown.");
+               }
+               
+               // get user ids
+               $users = ClipboardHandler::getInstance()->getMarkedItems($this->typeID);
+               if (!isset($users['com.woltlab.wcf.user']) || empty($users['com.woltlab.wcf.user'])) throw new IllegalLinkException();
+               
+               // load users
+               $this->userIDs = array_keys($users['com.woltlab.wcf.user']);
+               $this->users = $users['com.woltlab.wcf.user'];
+       }
+       
        /**
         * @see wcf\form\IForm::readFormParameters()
         */
@@ -35,20 +63,10 @@ class UserEmailAddressExportForm extends ACPForm {
                parent::readFormParameters();
                
                if (isset($_POST['fileType']) && $_POST['fileType'] == 'xml') $this->fileType = $_POST['fileType'];
-               if (isset($_POST['userIDs'])) $this->userIDs = ArrayUtil::toIntegerArray(explode(',', $_POST['userIDs']));
                if (isset($_POST['separator'])) $this->separator = $_POST['separator'];
                if (isset($_POST['textSeparator'])) $this->textSeparator = $_POST['textSeparator'];
        }
        
-       /**
-        * @see wcf\form\IForm::validate()
-        */
-       public function validate() {
-               parent::validate();
-               
-               if (empty($this->userIDs)) throw new IllegalLinkException();
-       }
-       
        /**
         * @see wcf\form\IForm::save()
         */
@@ -83,7 +101,7 @@ class UserEmailAddressExportForm extends ACPForm {
                $statement->execute($conditions->getParameters());
                
                $i = 0;
-               while ($row = WCF::getDB()->fetchArray($result)) {
+               while ($row = $statement->fetchArray()) {
                        if ($this->fileType == 'xml') echo "<address><![CDATA[".StringUtil::escapeCDATA($row['email'])."]]></address>\n";
                        else echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
                        $i++;
@@ -93,26 +111,12 @@ class UserEmailAddressExportForm extends ACPForm {
                        echo "</addresses>";
                }
                
-               // TODO: Implement unmarkAll()
-               //UserEditor::unmarkAll();
                $this->saved();
-               exit;
-       }
-       
-       /**
-        * @see wcf\page\IPage::readData()
-        */
-       public function readData() {
-               parent::readData();
                
-               if (!count($_POST)) {
-                       // get marked user ids
-                       $markedUsers = WCF::getSession()->getVar('markedUsers');
-                       if (is_array($markedUsers)) $this->userIDs = implode(',', $markedUsers);
-                       if (empty($this->userIDs)) throw new IllegalLinkException();
-               }
+               // remove items
+               ClipboardHandler::getInstance()->removeItems($this->typeID);
                
-               $this->users = User::getUsers($this->userIDs);
+               exit;
        }
        
        /**
@@ -123,7 +127,6 @@ class UserEmailAddressExportForm extends ACPForm {
                
                WCF::getTPL()->assign(array(
                        'users' => $this->users,
-                       'userIDs' => $this->userIDs,
                        'separator' => $this->separator,
                        'textSeparator' => $this->textSeparator,
                        'fileType' => $this->fileType