made sorting method persistant using session management
[squirrelmail.git] / src / move_messages.php
1 <?php
2 session_start();
3
4 if (!isset($config_php))
5 include("../config/config.php");
6 if (!isset($strings_php))
7 include("../functions/strings.php");
8 if (!isset($page_header_php))
9 include("../functions/page_header.php");
10 if (!isset($display_messages_php))
11 include("../functions/display_messages.php");
12 if (!isset($imap_php))
13 include("../functions/imap.php");
14
15 include("../src/load_prefs.php");
16
17 // echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
18
19 function putSelectedMessagesIntoString($msg) {
20 $j = 0;
21 $i = 0;
22 $firstLoop = true;
23
24 // If they have selected nothing msg is size one still, but will
25 // be an infinite loop because we never increment j. so check to
26 // see if msg[0] is set or not to fix this.
27 while (($j < count($msg)) && ($msg[0])) {
28 if ($msg[$i]) {
29 if ($firstLoop != true)
30 $selectedMessages .= "&";
31 else
32 $firstLoop = false;
33
34 $selectedMessages .= "selMsg[$j]=$msg[$i]";
35
36 $j++;
37 }
38 $i++;
39 }
40 }
41
42 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
43 sqimap_mailbox_select($imapConnection, $mailbox);
44
45 // If the delete button was pressed, the moveButton variable will not be set.
46 if (!$moveButton) {
47 if (is_array($msg) == 1) {
48 // Marks the selected messages ad 'Deleted'
49 $j = 0;
50 $i = 0;
51
52 // If they have selected nothing msg is size one still, but will be an infinite
53 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
54 while ($j < count($msg)) {
55 if ($msg[$i]) {
56 sqimap_messages_delete($imapConnection, $msg[$i], $msg[$i], $mailbox);
57 $j++;
58 }
59 $i++;
60 }
61 if ($auto_expunge)
62 sqimap_mailbox_expunge($imapConnection, $mailbox);
63
64 if ($auto_forward) {
65 header ("Location: right_main.php");
66 } else {
67 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
68 displayPageHeader($color, $mailbox);
69 messages_deleted_message($mailbox, $sort, $startMessage, $color);
70 }
71 } else {
72 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
73 displayPageHeader($color, $mailbox);
74 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
75 }
76 } else { // Move messages
77 // lets check to see if they selected any messages
78 if (is_array($msg) == 1) {
79 $j = 0;
80 $i = 0;
81
82 // If they have selected nothing msg is size one still, but will be an infinite
83 // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
84 while ($j < count($msg)) {
85 if ($msg[$i]) {
86 /** check if they would like to move it to the trash folder or not */
87 sqimap_messages_copy($imapConnection, $msg[$i], $msg[$i], $targetMailbox);
88 sqimap_messages_flag($imapConnection, $msg[$i], $msg[$i], "Deleted");
89 $j++;
90 }
91 $i++;
92 }
93 if ($auto_expunge == true)
94 sqimap_mailbox_expunge($imapConnection, $mailbox);
95
96 if ($auto_forward) {
97 header ("Location: right_main.php");
98 } else {
99 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
100 displayPageHeader($color, $mailbox);
101 messages_moved_message($mailbox, $sort, $startMessage, $color);
102 }
103 } else {
104 echo "<HTML><BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
105 displayPageHeader($color, $mailbox);
106 error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
107 }
108 }
109
110 // Log out this session
111 sqimap_logout($imapConnection);
112
113 ?>
114 </BODY></HTML>