. */ require_once('CF7DBPlugin.php'); require_once('CFDBView.php'); require_once('ExportToHtmlTable.php'); class CFDBViewWhatsInDB extends CFDBView { function display(&$plugin) { if ($plugin == null) { $plugin = new CF7DBPlugin; } echo '
'; $canEdit = $plugin->canUserDoRoleOption('CanChangeSubmitData'); $this->pageHeader($plugin); global $wpdb; $tableName = $plugin->getSubmitsTableName(); $useDataTables = $plugin->getOption('UseDataTablesJS', 'true', true) == 'true'; $tableHtmlId = 'cf2dbtable'; // Identify which forms have data in the database $formsList = $plugin->getForms(); if (count($formsList) == 0) { echo htmlspecialchars(__('No form submissions in the database', 'contact-form-7-to-database-extension')); return; } $page = 1; if (isset($_REQUEST['dbpage'])) { $page = $this->getRequestParam('dbpage'); } $currSelection = null; if (isset($_REQUEST['form_name'])) { $currSelection = $this->getRequestParam('form_name'); } else if (isset($_REQUEST['form'])) { $currSelection = $this->getRequestParam('form'); } if ($currSelection) { $currSelection = stripslashes($currSelection); $currSelection = htmlspecialchars_decode($currSelection, ENT_QUOTES); } $currSelectionEscaped = htmlspecialchars($currSelection, ENT_QUOTES, 'UTF-8'); // If there is only one form in the DB, select that by default if (!$currSelection && count($formsList) == 1) { $currSelection = $formsList[0]; // Bug fix: Need to set this so the Editor plugin can reference it $_REQUEST['form_name'] = $formsList[0]; } if ($currSelection) { // Check for delete operation if (isset($_POST['cfdbdel']) && $canEdit && wp_verify_nonce($_REQUEST['_wpnonce'])) { if (isset($_POST['submit_time'])) { $submitTime = $_POST['submit_time']; $wpdb->query( $wpdb->prepare( "delete from `$tableName` where `form_name` = '%s' and `submit_time` = %F", $currSelection, $submitTime)); } else if (isset($_POST['all'])) { $wpdb->query( $wpdb->prepare( "delete from `$tableName` where `form_name` = '%s'", $currSelection)); } else { foreach ($_POST as $name => $value) { // checkboxes if ($value == 'row') { // Dots and spaces in variable names are converted to underscores. For example becomes $_REQUEST["a_b"]. // http://www.php.net/manual/en/language.variables.external.php // We are expecting a time value like '1300728460.6626' but will instead get '1300728460_6626' // so we need to put the '.' back in before going to the DB. $name = str_replace('_', '.', $name); $wpdb->query( $wpdb->prepare( "delete from `$tableName` where `form_name` = '%s' and `submit_time` = %F", $currSelection, $name)); } } } } else if (isset($_POST['delete_wpcf7']) && $canEdit && wp_verify_nonce($_REQUEST['_wpnonce'])) { $plugin->delete_wpcf7_fields($currSelection); $plugin->add_wpcf7_noSaveFields(); } } // Form selection drop-down list $pluginDirUrl = $plugin->getPluginDirUrl(); ?>

getShortCodeBuilderPageSlug() . '">' . __('Advanced Export', 'contact-form-7-to-database-extension') . '' ?>
getDataTableTranslationUrl(); // Work out the datatable menu for number or rows shown $maxVisible = $plugin->getOption('MaxVisibleRows', -1); if (!is_numeric($maxVisible)) { $maxVisible = -1; } $menuJS = $this->createDatatableLengthMenuJavascriptString($maxVisible); $sScrollX = $plugin->getOption('HorizontalScroll', 'true', true) == 'true' ? '"100%"' : '""'; ?>
getDBRowCount($currSelection); $maxRows = $plugin->getOption('MaxRows', '100', true); $startRow = $this->paginationDiv($plugin, $dbRowCount, $maxRows, $page); ?>
> div { max-height: 100px; min-width:75px; overflow: auto; font-size: small;}"; // don't let cells get too tall } $exporter->export($currSelection, $options); ?>
getOption('ShowQuery', 'false', true)) { ?>

getPivotQuery($currSelection); ?>
'; // cfdb-admin } /** * @param $plugin CF7DBPlugin * @param $totalRows integer * @param $rowsPerPage integer * @param $page integer * @return integer $startRow */ protected function paginationDiv($plugin, $totalRows, $rowsPerPage, $page) { $nextLabel = __('next »', 'contact-form-7-to-database-extension'); $prevLabel = __('« prev', 'contact-form-7-to-database-extension'); echo ''; // echo ''; if (!$page || $page < 1) $page = 1; //default to 1. $startRow = ($totalRows == 0) ? 1 : $rowsPerPage * ($page - 1) + 1; $endRow = min($startRow + $rowsPerPage - 1, $totalRows); if ($endRow <= 0) { $startRow = $endRow = 0; } echo ''; printf(__('Returned entries %s to %s of %s entries in the database', 'contact-form-7-to-database-extension'), $startRow, $endRow, $totalRows); echo ''; if ($endRow == 0) { return $startRow; } echo '
'; $numPages = ($rowsPerPage > 0) ? ceil($totalRows / $rowsPerPage) : 1; $adjacents = 3; /* Setup page vars for display. */ $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = $numPages; $lpm1 = $lastpage - 1; //last page minus 1 /* Now we apply our rules and draw the pagination object. We're actually saving the code to a variable in case we want to draw it more than once. */ if ($lastpage > 1) { echo "
"; //previous button if ($page > 1) echo $this->paginateLink($prev, $prevLabel); else echo "$prevLabel"; if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) echo "$counter"; else echo $this->paginateLink($counter, $counter); } } elseif ($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if ($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) echo "$counter"; else echo $this->paginateLink($counter, $counter); } echo '...'; echo $this->paginateLink($lpm1, $lpm1); echo $this->paginateLink($lastpage, $lastpage); } //in middle; hide some front and some back elseif ($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { echo $this->paginateLink(1, 1); echo $this->paginateLink(2, 2); echo '...'; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) echo "$counter"; else echo $this->paginateLink($counter, $counter); } echo '...'; echo $this->paginateLink($lpm1, $lpm1); echo $this->paginateLink($lastpage, $lastpage); } //close to end; only hide early pages else { echo $this->paginateLink(1, 1); echo $this->paginateLink(2, 2); echo '...'; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) echo "$counter"; else echo $this->paginateLink($counter, $counter); } } } //next button if ($page < $counter - 1) echo $this->paginateLink($next, $nextLabel); else echo "$nextLabel"; echo "
\n"; } // Next script is to hide the WP "Thank You" footer which can overlap the CFDB table. ?> '; return $startRow; } protected function paginateLink($page, $label) { return "$label"; } /** * Create aLengthMenu javascript string for databatable * @param $maxVisible * @return string */ protected function createDatatableLengthMenuJavascriptString($maxVisible) { $numRowsMenu = array(); $found = $maxVisible == -1; foreach (array(1, 2, 3, 4, 5, 10, 25, 50, 100) as $entry) { if ($found) { $numRowsMenu[] = $entry; } else { if ($maxVisible == $entry) { $found = true; } else if ($maxVisible < $entry) { $numRowsMenu[] = $maxVisible; $found = true; } $numRowsMenu[] = $entry; } } if (!$found) { $numRowsMenu[] = $maxVisible; } $numRowsMenu[] = -1; $menuJS1 = '[['; $menuJS2 = ', ['; foreach ($numRowsMenu as $val) { $menuJS1 .= $val . ','; if ($val == -1) { $val = '"' . __('All', 'contact-form-7-to-database-extension') . '"'; } $menuJS2 .= $val . ','; } $menuJS1 = substr($menuJS1, 0, -1) . ']'; $menuJS2 = substr($menuJS2, 0, -1) . ']]'; return $menuJS1 . $menuJS2; } }