function mailqueue__show_mailqueue($experiment_id = "", $limit = -1) { global $lang, $color, $options, $proceed; if ($proceed) { $pars = array(); if ($limit == -1 && $experiment_id && isset($options['mailqueue_experiment_number_of_entries_per_page']) && $options['mailqueue_experiment_number_of_entries_per_page']) { $limit = $options['mailqueue_experiment_number_of_entries_per_page']; } elseif ($limit == -1 && isset($options['mailqueue_number_of_entries_per_page']) && $options['mailqueue_number_of_entries_per_page']) { $limit = $options['mailqueue_number_of_entries_per_page']; } else { $limit = 100; } if (isset($_REQUEST['os']) && $_REQUEST['os'] > 0) { $offset = $_REQUEST['os']; } else { $offset = 0; } if ($experiment_id) { $equery = " AND experiment_id=:experiment_id "; $pars[':experiment_id'] = $experiment_id; } else { $equery = ""; } if (isset($_REQUEST['deleteall']) && $_REQUEST['deleteall']) { $dall = true; } else { $dall = false; } if (isset($_REQUEST['deleteallonpage']) && $_REQUEST['deleteallonpage']) { $dallpage = true; } else { $dallpage = false; } if (isset($_REQUEST['deletesel']) && $_REQUEST['deletesel']) { $dsel = true; } else { $dsel = false; } } if ($proceed) { if ($dall || $dallpage || $dsel) { if ($experiment_id) { $allow = check_allow('mailqueue_edit_experiment', 'experiment_mailqueue_show?experiment_id=' . $experiment_id); } else { $allow = check_allow('mailqueue_edit_all', 'mailqueue_show.php'); } $where_clause = " WHERE mail_id IS NOT NULL " . $equery; $ok = false; if ($dall) { $ok = true; } if ($dallpage) { $tallids = array(); if (isset($_REQUEST['allids']) && trim($_REQUEST['allids'])) { $tallids = explode(",", trim($_REQUEST['allids'])); } if (count($tallids) > 0) { $i = 0; $parnames = array(); foreach ($tallids as $id) { $i++; $tparname = ':mailid' . $i; $parnames[] = $tparname; $pars[$tparname] = $id; } $where_clause .= " AND mail_id IN (" . implode(",", $parnames) . ") "; $ok = true; } else { message(lang('error__mailqueue_delete_no_emails_selected')); $ok = false; } } if ($dsel) { $dids = array(); if (isset($_REQUEST['del']) && is_array($_REQUEST['del'])) { foreach ($_REQUEST['del'] as $k => $v) { if ($v == 'y') { $dids[] = $k; } } } if (count($dids) > 0) { $i = 0; $parnames = array(); foreach ($dids as $id) { $i++; $tparname = ':mailid' . $i; $parnames[] = $tparname; $pars[$tparname] = $id; } $where_clause .= " AND mail_id IN (" . implode(",", $parnames) . ") "; $ok = true; } else { message(lang('error__mailqueue_delete_no_emails_selected')); $ok = false; } } if ($ok) { $query = "DELETE FROM " . table('mail_queue') . $where_clause; //echo $query; $done = or_query($query, $pars); $number = pdo_num_rows($done); message($number . ' ' . lang('xxx_emails_deleted_from_queue')); if ($experiment_id) { if ($number > 0) { log__admin("mailqueue_delete_entries", "Experiment: " . $experiment_id . ", Count: " . $number); } } else { if ($number > 0) { log__admin("mailqueue_delete_entries", "Count: " . $number); } } } if ($experiment_id) { redirect("admin/experiment_mailqueue_show.php?experiment_id=" . $experiment_id); } else { redirect("admin/mailqueue_show.php"); } } } if ($proceed) { $pars = array(); if ($experiment_id) { $equery = " AND experiment_id=:experiment_id "; $pars[':experiment_id'] = $experiment_id; } else { $equery = ""; } $pars[':offset'] = $offset; $pars[':limit'] = $limit; $query = "SELECT * FROM " . table('mail_queue') . "\n WHERE mail_id IS NOT NULL " . $equery . " ORDER BY timestamp DESC\n LIMIT :offset , :limit"; $result = or_query($query, $pars); $num_rows = pdo_num_rows($result); if ($experiment_id && check_allow('mailqueue_edit_experiment')) { echo '<FORM action="experiment_mailqueue_show.php" method="POST"> <INPUT type="hidden" name="experiment_id" value="' . $experiment_id . '">'; } elseif (check_allow('mailqueue_edit_all')) { echo '<FORM action="mailqueue_show.php" method="POST">'; } echo '<TABLE width=90% border=0> <TR><TD width=50%>'; //echo '<FONT class="small">'.lang('query').': '.$query.'</FONT><BR><BR>'; echo ' </TD> <TD align=right width=50%>'; if (check_allow('mailqueue_edit_all')) { echo ' <TABLE width="100%" border="0"> <TR><TD width="33%" align="right"> <input class="button" type=submit name="deleteall" value="' . lang('delete_all') . '"> </TD><TD width="33%" align="right"> <input class="button" type=submit name="deleteallonpage" value="' . lang('delete_all_on_page') . '"> </TD><TD width="33%" align="right"> <input class="button" type=submit name="deletesel" value="' . lang('delete_selected') . '"> </TD></TR> </TABLE> '; } echo '</TD></TR></TABLE>'; if ($offset > 0) { echo '[' . log__link('os=' . ($offset - $limit)) . lang('previous') . '</A>]'; } else { echo '[' . lang('previous') . ']'; } echo ' '; if ($num_rows >= $limit) { echo '[' . log__link('os=' . ($offset + $limit)) . lang('next') . '</A>]'; } else { echo '[' . lang('next') . ']'; } echo '<TABLE class="or_listtable" style="width: 90%;"><thead>'; // header echo ' <thead> <TR style="background: ' . $color['list_header_background'] . '; color: ' . $color['list_header_textcolor'] . ';"> <TD>' . lang('id') . '</TD> <TD>' . lang('date_and_time') . '</TD> <TD>' . lang('email_type') . '</TD> <TD>' . lang('email_recipient') . '</TD> <TD>' . lang('reference') . '</TD> <TD>' . lang('error') . '</TD>'; if (check_allow('mailqueue_edit_all')) { echo '<TD> ' . lang('select_all') . ' <INPUT id="selall" type="checkbox" name="selall" value="y"> <script language="JavaScript"> $("#selall").change(function() { if (this.checked) { $("input[name*=\'del[\']").each(function() { this.checked = true; }); } else { $("input[name*=\'del[\']").each(function() { this.checked = false; }); } }); </script> </TD>'; } echo ' </TR> </thead> <tbody> '; $shade = false; $ids = array(); $experiment_ids = array(); $entries = array(); while ($line = pdo_fetch_assoc($result)) { $ids[] = $line['mail_id']; if ($line['experiment_id']) { $experiment_ids[] = $line['experiment_id']; } $entries[] = $line; } $experiments = experiment__load_experiments_for_ids($experiment_ids); foreach ($entries as $line) { echo '<TR'; if ($shade) { $shade = false; } else { $shade = true; } if ($shade) { echo ' bgcolor="' . $color['list_shade1'] . '"'; } else { echo ' bgcolor="' . $color['list_shade2'] . '"'; } echo '> <TD>' . $line['mail_id'] . '</TD> <TD>' . ortime__format($line['timestamp'], 'hide_second:false', lang('lang')) . '</TD> <TD>' . $line['mail_type'] . '</TD> <TD>' . $line['mail_recipient'] . '</TD> <TD>'; $reference = array(); if ($line['experiment_id']) { $reference[] = 'Experiment: <A HREF="experiment_show.php?experiment_id=' . $line['experiment_id'] . '">' . $experiments[$line['experiment_id']]['experiment_name'] . '</A>'; } if ($line['session_id']) { $reference[] = 'Session: <A HREF="session_edit.php?session_id=' . $line['session_id'] . '">' . $line['session_id'] . '</A>'; } if ($line['bulk_id']) { $reference[] = 'Bulk email: ' . $line['bulk_id']; } echo implode('<BR>', $reference); echo '</TD> <TD>' . $line['error'] . '</TD>'; if (check_allow('mailqueue_edit_all')) { echo '<TD><INPUT type="checkbox" name="del[' . $line['mail_id'] . ']" value="y"></TD'; } echo '</TR>'; } echo '</tbody></TABLE>'; if (check_allow('mailqueue_edit_all')) { echo '<INPUT type="hidden" name="allids" value="' . implode(",", $ids) . '">'; echo '</FORM>'; } return $num_rows; } }
function log__show_log($log) { global $limit; if (!$limit) { $limit = 50; } if (isset($_REQUEST['os']) && $_REQUEST['os'] > 0) { $offset = $_REQUEST['os']; } else { $offset = 0; } global $lang, $color; $pars = array(); if (isset($_REQUEST['action']) && $_REQUEST['action']) { $aquery = " AND action=:action "; $pars[':action'] = $_REQUEST['action']; } else { $aquery = ""; } if (isset($_REQUEST['id']) && $_REQUEST['id']) { $idquery = " AND id=:id "; $pars[':id'] = $_REQUEST['id']; } else { $idquery = ""; } if (isset($_REQUEST['target']) && $_REQUEST['target']) { $tquery = " AND target LIKE :target "; $pars[':target'] = '%' . $_REQUEST['target'] . '%'; } else { $tquery = ""; } $logtable = table('participants_log'); switch ($log) { case "participant_actions": $logtable = table('participants_log'); $secondtable = " LEFT JOIN " . table('participants') . " ON id=participant_id "; break; case "experimenter_actions": $logtable = table('admin_log'); $secondtable = " LEFT JOIN " . table('admin') . " ON id=admin_id "; break; case "regular_tasks": $logtable = table('cron_log'); $secondtable = " LEFT JOIN " . table('admin') . " ON id=admin_id "; break; } if (isset($_REQUEST['delete']) && $_REQUEST['delete'] && isset($_REQUEST['days']) && $_REQUEST['days']) { $allow = check_allow('log_file_' . $log . '_delete', 'statistics_show_log.php?log=' . $log); if (isset($_REQUEST['days']) && $_REQUEST['days'] == "all") { $where_clause = ""; } else { $now = time(); $dsec = (int) $_REQUEST['days'] * 24 * 60 * 60; $dtime = $now - $dsec; $where_clause = " WHERE timestamp < " . $dtime; } $query = "DELETE FROM " . $logtable . $where_clause; $done = or_query($query); $number = pdo_num_rows($done); message($number . ' ' . lang('xxx_log_entries_deleted')); if ($number > 0) { log__admin("log_delete_entries", "log:" . $log . "\ndays:" . $_REQUEST['days']); } redirect("admin/statistics_show_log.php?log=" . $log); } $pars[':offset'] = $offset; $pars[':limit'] = $limit; $query = "SELECT * FROM " . $logtable . $secondtable . "\n WHERE id IS NOT NULL " . $aquery . $idquery . $tquery . " ORDER BY timestamp DESC\n LIMIT :offset , :limit "; $result = or_query($query, $pars); $num_rows = pdo_num_rows($result); echo '<TABLE width=80% border=0> <TR><TD width=50%>'; //echo '<FONT class="small">'.lang('query').': '.$query.'</FONT><BR><BR>'; echo '</TD> <TD align=right width=50%>'; if (check_allow('log_file_' . $log . '_delete')) { echo ' <FORM action="statistics_show_log.php"> <INPUT type=hidden name="log" value="' . $log . '"> ' . lang('delete_log_entries_older_than') . ' <select name="days"> <option value="all">' . lang('all_entries') . '</option>'; $ddays = array(1, 7, 30, 90, 180, 360); if (isset($_REQUEST['days']) && $_REQUEST['days']) { $selected = $_REQUEST['days']; } else { $selected = 90; } foreach ($ddays as $day) { echo '<option value="' . $day . '"'; if ($day == $selected) { echo ' SELECTED'; } echo '>' . $day . ' '; if ($day == 1) { echo lang('day'); } else { echo lang('days'); } echo '</option> '; } echo ' </select><input type=submit name="delete" value="' . lang('delete') . '">'; } echo '</TD></TR></TABLE>'; if ($offset > 0) { echo '[' . log__link('os=' . ($offset - $limit)) . lang('previous') . '</A>]'; } else { echo '[' . lang('previous') . ']'; } echo ' '; if ($num_rows >= $limit) { echo '[' . log__link('os=' . ($offset + $limit)) . lang('next') . '</A>]'; } else { echo '[' . lang('next') . ']'; } echo '<TABLE class="or_listtable" style="width: 90%;">'; // header echo '<thead> <TR style="background: ' . $color['list_header_background'] . '; color: ' . $color['list_header_textcolor'] . ';"> <TD> ' . lang('date_and_time') . ' </TD> <TD>'; if ($log == 'participant_actions') { echo lang('lastname') . ', ' . lang('firstname'); } elseif ($log == 'experimenter_actions' || $log == 'regular_tasks') { echo lang('experimenter'); } if (isset($_REQUEST['id']) && $_REQUEST['id']) { echo ' ' . log__link('id=', 'os=0') . '<FONT class="small">[' . lang('unrestrict') . ']</FONT></A>'; } echo ' </TD><TD>' . lang('action'); if (isset($_REQUEST['action']) && $_REQUEST['action']) { echo ' ' . log__link('action=', 'os=0') . '<FONT class="small">[' . lang('unrestrict') . ']</FONT></A>'; } echo ' </TD><TD>' . lang('target'); if (isset($_REQUEST['target']) && $_REQUEST['target']) { echo ' ' . log__link('target=', 'os=0') . '<FONT class="small">[' . lang('unrestrict') . ']</FONT></A>'; } echo ' </TD></TR> </thead> <tbody>'; $shade = false; while ($line = pdo_fetch_assoc($result)) { echo '<tr class="small"'; if ($shade) { echo ' bgcolor="' . $color['list_shade1'] . '"'; } else { echo 'bgcolor="' . $color['list_shade2'] . '"'; } echo '> <TD>' . ortime__format($line['timestamp'], 'hide_seconds:false', lang('lang')) . '</TD> <TD>'; if ($log == 'participant_actions') { if ($line['participant_id']) { echo $line['lname'] . ', ' . $line['fname'] . ' <A HREF="participants_edit.php?participant_id=' . $line['participant_id'] . '"><FONT class="small">[' . lang('edit') . ']</FONT></A>'; } else { echo $line['id']; } } elseif ($log == 'experimenter_actions' || $log == 'regular_tasks') { echo $line['adminname']; } if (!isset($_REQUEST['id']) || $_REQUEST['id'] != $line['id']) { echo ' ' . log__restrict_link('id', $line['id']); } echo ' </TD><TD>' . $line['action']; if (!isset($_REQUEST['action']) || $_REQUEST['action'] != $line['action']) { echo ' ' . log__restrict_link('action', $line['action']); } echo ' </TD><TD>' . nl2br(stripslashes($line['target'])); if (!isset($_REQUEST['target']) || $_REQUEST['target'] != $line['target'] && $log != 'regular_tasks') { echo ' ' . log__restrict_link('target', $line['target']); } echo ' </TD></TR>'; if ($shade) { $shade = false; } else { $shade = true; } } echo '</tbody></TABLE>'; return $num_rows; }