1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | global $template, $page; |
---|
5 | |
---|
6 | $piwecard = get_plugin_data($plugin_id); |
---|
7 | |
---|
8 | $query = 'SELECT DISTINCT ecard_id, sender_name, sender_email, title, message, image, date_creation, date_validity FROM '.PIWECARD_TABLE; |
---|
9 | |
---|
10 | if (isset($_POST['ecard_form_filter_submit'])) { |
---|
11 | switch ($_POST['ecard_status']) { |
---|
12 | case 'valid': |
---|
13 | $query .= ' WHERE date_validity >= NOW() OR date_validity IS NULL'; |
---|
14 | break; |
---|
15 | case 'invalid': |
---|
16 | $query .= ' WHERE date_validity < NOW() AND date_validity IS NOT NULL'; |
---|
17 | break; |
---|
18 | default: |
---|
19 | break; |
---|
20 | } |
---|
21 | |
---|
22 | switch ($_POST['ecard_sort_by']) { |
---|
23 | case 'date': |
---|
24 | $query .= ' ORDER BY date_creation'; |
---|
25 | break; |
---|
26 | case 'title': |
---|
27 | $query .= ' ORDER BY title'; |
---|
28 | break; |
---|
29 | case 'sender': |
---|
30 | $query .= ' ORDER BY sender_name'; |
---|
31 | break; |
---|
32 | case 'recipient': |
---|
33 | $query .= ' ORDER BY recipient_name'; |
---|
34 | break; |
---|
35 | case 'validity': |
---|
36 | $query .= ' ORDER BY date_validity'; |
---|
37 | break; |
---|
38 | default: |
---|
39 | $query .= ' ORDER BY date_creation'; |
---|
40 | break; |
---|
41 | } |
---|
42 | |
---|
43 | switch ($_POST['ecard_sort_order']) { |
---|
44 | case 'asc': |
---|
45 | $query .= ' ASC'; |
---|
46 | break; |
---|
47 | case 'desc': |
---|
48 | $query .= ' DESC'; |
---|
49 | break; |
---|
50 | default: |
---|
51 | $query .= ' ASC'; |
---|
52 | break; |
---|
53 | } |
---|
54 | $template->assign('ecard_filter', array( |
---|
55 | 'status' => $_POST['ecard_status'], |
---|
56 | 'sort_by' => $_POST['ecard_sort_by'], |
---|
57 | 'sort_order' => $_POST['ecard_sort_order'], |
---|
58 | ) |
---|
59 | ); |
---|
60 | |
---|
61 | if (intval($_POST['ecard_nb_ecard_page']) == 0) |
---|
62 | $piwecard->config['nb_ecard_page'] = 1; |
---|
63 | else |
---|
64 | $piwecard->config['nb_ecard_page'] = intval($_POST['ecard_nb_ecard_page']); |
---|
65 | $piwecard->set_config(); |
---|
66 | } |
---|
67 | |
---|
68 | if (isset($_POST['delete_selected_submit'])) { |
---|
69 | if (isset($_POST['ecard_to_delete_sure']) && $_POST['ecard_to_delete_sure'] == '1') { |
---|
70 | if (isset($_POST['ecard_to_delete'])) { |
---|
71 | foreach ($_POST['ecard_to_delete'] as $ecard_id) { |
---|
72 | $piwecard->delete_ecard($ecard_id); |
---|
73 | } |
---|
74 | array_push($page['infos'], l10n('piwecard_deleted')); |
---|
75 | } |
---|
76 | if (isset($_POST['ecard_delete_invalid']) && $_POST['ecard_delete_invalid'] == '1') { |
---|
77 | $piwecard->delete_allinvalid_ecard(); |
---|
78 | array_push($page['infos'], l10n('piwecard_invalid_deleted')); |
---|
79 | } |
---|
80 | } else { |
---|
81 | array_push($page['errors'], l10n('You need to confirm deletion')); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | $start = (isset($_GET['start']) ? intval($_GET['start']) : 0); |
---|
86 | if ($start > $piwecard->get_nb_ecard()) |
---|
87 | $start = 0; |
---|
88 | if ($start != 0 AND $piwecard->get_nb_ecard() <= $piwecard->config['nb_ecard_page']) |
---|
89 | $start = 0; |
---|
90 | |
---|
91 | //Create the navigation bar (for more than 1 page) |
---|
92 | $management_url = PIWECARD_ADMIN.'-management'; |
---|
93 | $ecard_navbar = array(); |
---|
94 | $ecard_navbar = create_navigation_bar($management_url, $piwecard->get_nb_ecard(), $start, $piwecard->config['nb_ecard_page']); |
---|
95 | |
---|
96 | //DB Query |
---|
97 | if (strpos($query, 'ORDER BY') === FALSE) { |
---|
98 | $query .= ' ORDER by date_creation ASC'; |
---|
99 | } |
---|
100 | |
---|
101 | $query .= ' LIMIT '.$start.','.$piwecard->config['nb_ecard_page'].';'; |
---|
102 | $result = pwg_query($query); |
---|
103 | |
---|
104 | while($file = pwg_db_fetch_assoc($result)) { |
---|
105 | //Recipients |
---|
106 | $recipients = array(); |
---|
107 | $query2 = 'SELECT recipient_name, recipient_email FROM '.PIWECARD_TABLE.' WHERE ecard_id="'.$file['ecard_id'].'";'; |
---|
108 | $result2 = pwg_query($query2); |
---|
109 | |
---|
110 | while($row = pwg_db_fetch_assoc($result2)) { |
---|
111 | array_push($recipients, array( |
---|
112 | 'name' => $row['recipient_name'], |
---|
113 | 'email' => $row['recipient_email'], |
---|
114 | ) |
---|
115 | ); |
---|
116 | } |
---|
117 | |
---|
118 | $ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$file['ecard_id']); |
---|
119 | |
---|
120 | // Check if the ecard is valid |
---|
121 | $valid = $piwecard->is_valid($file['ecard_id']); |
---|
122 | |
---|
123 | $template->append('ecard_files',array( |
---|
124 | 'id' => $file['ecard_id'], |
---|
125 | 'title' => $file['title'], |
---|
126 | 'url' => $ecard_url, |
---|
127 | 'sender_name' => $file['sender_name'], |
---|
128 | 'sender_email' => $file['sender_email'], |
---|
129 | 'recipients' => $recipients, |
---|
130 | 'date_creation' => strftime('%d/%m/%y %H:%M', strtotime($file['date_creation'])), |
---|
131 | 'date_validity' => (isset($file['date_validity'])) ? strftime('%d/%m/%y %H:%M', strtotime($file['date_validity'])) : l10n('piwecard_nolimit'), |
---|
132 | 'valid' => $valid, |
---|
133 | )); |
---|
134 | } |
---|
135 | |
---|
136 | $nb_ecards_valid_total = sprintf(l10n('piwecard_nb_ecard_valid_total'), $piwecard->get_nb_valid_ecard(), $piwecard->get_nb_ecard()); |
---|
137 | |
---|
138 | $query = 'SELECT COUNT(DISTINCT sender_email) AS nb_senders, COUNT(DISTINCT recipient_email) AS nb_recipients FROM '.PIWECARD_TABLE.' ORDER BY date_creation;'; |
---|
139 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
140 | $nb_distinct_senders_total = (empty($result['nb_senders']) ? 0 : $result['nb_senders']); |
---|
141 | $nb_distinct_recipients_total = (empty($result['nb_recipients']) ? 0 : $result['nb_recipients']); |
---|
142 | |
---|
143 | $nb_distinct_senders_recipients_total = sprintf(l10n('piwecard_nb_sender_recipient_total'), $nb_distinct_senders_total, $nb_distinct_recipients_total); |
---|
144 | |
---|
145 | $template->assign('nb_ecards_valid_total', $nb_ecards_valid_total); |
---|
146 | $template->assign('nb_distinct_senders_recipients_total', $nb_distinct_senders_recipients_total); |
---|
147 | $template->assign('ecard_nb_ecard_page', $piwecard->config['nb_ecard_page']); |
---|
148 | $template->assign('navbar', $ecard_navbar); |
---|
149 | |
---|
150 | $template->set_filename('plugin_admin_management', dirname(__FILE__) . '/template/admin_management.tpl'); |
---|
151 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_management'); |
---|