1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once('common.inc.php'); |
4
|
|
|
|
5
|
|
|
use Battis\BootstrapSmarty\NotificationMessage; |
6
|
|
|
use smtech\StMarksSmarty\StMarksSmarty; |
7
|
|
|
|
8
|
|
|
$toolbox->getSmarty()->enable(StMarksSmarty::MODULE_DATEPICKER); |
9
|
|
|
|
10
|
|
|
define('STEP_INSTRUCTIONS', 1); |
11
|
|
|
define('STEP_SELECT', 2); |
12
|
|
|
define('STEP_ARCHIVE', 3); |
13
|
|
|
|
14
|
|
|
$step = (empty($_REQUEST['step']) ? STEP_INSTRUCTIONS : $_REQUEST['step']); |
15
|
|
|
switch ($step) { |
16
|
|
|
case STEP_SELECT: |
17
|
|
|
try { |
18
|
|
|
$users = $toolbox->api_get('accounts/1/users', array('search_term' => $_REQUEST['user'])); |
19
|
|
|
} catch (Exception $e) { |
20
|
|
|
$toolbox->exceptionErrorMessage($e); |
21
|
|
|
$toolbox->smarty_assign('user', $_REQUEST['user']); |
22
|
|
|
$step = STEP_INSTRUCTIONS; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
if ($step == STEP_SELECT) { |
26
|
|
|
$toolbox->smarty_assign('users', $users); |
27
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_ARCHIVE)); |
28
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/select.tpl'); |
29
|
|
|
break; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/* flow into STEP_ARCHIVE */ |
33
|
|
|
|
34
|
|
|
case STEP_ARCHIVE: |
35
|
|
|
if ($step == STEP_ARCHIVE) { |
36
|
|
|
try { |
37
|
|
|
$cutoff = strtotime((empty($_REQUEST['cutoff']) ? 'now' : $_REQUEST['cutoff'])); |
38
|
|
|
$conversations = $toolbox->api_get( |
39
|
|
|
'conversations', |
40
|
|
|
array( |
41
|
|
|
'as_user_id' => $_REQUEST['user'] |
42
|
|
|
) |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$archived = array(); |
46
|
|
|
$unarchived = array(); |
47
|
|
|
foreach ($conversations as $conversation) { |
48
|
|
|
if (strtotime($conversation['last_message_at']) < $cutoff) { |
49
|
|
|
try { |
50
|
|
|
$archived[] = $conversation['id']; |
51
|
|
|
$toolbox->api_put( |
52
|
|
|
"conversations/{$conversation['id']}", |
53
|
|
|
array( |
54
|
|
|
'conversation[workflow_state]' => 'archived', |
55
|
|
|
'as_user_id' => $_REQUEST['user'] |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
} catch (Exception $e) { |
59
|
|
|
$toolbox->exceptionErrorMessage($e); |
60
|
|
|
} |
61
|
|
|
} else { |
62
|
|
|
$unarchived[] = $conversation['id']; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} catch (Exception $e) { |
66
|
|
|
$toolbox->exceptionErrorMessage($e); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$toolbox->smarty_addMessage( |
70
|
|
|
'Inbox Archived', |
71
|
|
|
count($archived) . ' conversations archived (IDs ' . implode(', ', $archived) . ') and ' . count($unarchived) . ' conversations left unarchived (IDs ' . implode(', ', $unarchived) . ').', |
72
|
|
|
NotificationMessage::GOOD |
|
|
|
|
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/* flow into STEP_INSTRUCTIONS */ |
77
|
|
|
|
78
|
|
|
case STEP_INSTRUCTIONS: |
79
|
|
|
default: |
80
|
|
|
$toolbox->smarty_assign('formHidden', array('step' => STEP_SELECT)); |
81
|
|
|
$toolbox->smarty_display(basename(__FILE__, '.php') . '/instructions.tpl'); |
82
|
|
|
} |
83
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.