Example #1
0
 function prepare_items()
 {
     //
     global $wpdb;
     $tTableNameSg = getCallRecordTableName();
     $tQuerySg = "SELECT * FROM {$tTableNameSg}";
     // Setup of ordering.
     // (At present we don't use the GET params for this, but maybe in the future)
     $tOrderBySg = !empty($_GET["orderby"]) ? esc_sql($_GET["orderby"]) : 'DESC';
     $tOrderSg = !empty($_GET["order"]) ? esc_sql($_GET["order"]) : DatabaseAttributes::id;
     if (!empty($tOrderBySg) && !empty($tOrderSg)) {
         $tQuerySg .= ' ORDER BY ' . $tOrderSg . ' ' . $tOrderBySg;
     }
     $tTotalNrOfItemsNr = $wpdb->query($tQuerySg);
     $tNumberOfItemsPerPageNr = Constants::record_rows_display_max;
     $tPagedSg = '';
     if (isset($_GET["paged"])) {
         $tPagedSg = $_GET["paged"];
     }
     if (empty($tPagedSg) === false) {
         if (is_numeric($tPagedSg) === false) {
             handleError("Page number contained non-numeric characters, possible SQL injection attempt");
         }
     }
     // Limiting the range of results returned.
     // (We don't want to display all the rows one a single page)
     // Documenation for MySQL "LIMIT":
     // http://www.w3schools.com/php/php_mysql_select_limit.asp
     if (empty($tPagedSg) || !is_numeric($tPagedSg) || $tPagedSg <= 0) {
         $tPagedSg = 1;
     }
     $tTotalNrOfPagesNr = ceil($tTotalNrOfItemsNr / $tNumberOfItemsPerPageNr);
     if (!empty($tPagedSg) && !empty($tNumberOfItemsPerPageNr)) {
         $tNumberOfItemsOffsetNr = ($tPagedSg - 1) * $tNumberOfItemsPerPageNr;
         $tQuerySg .= ' LIMIT ' . (int) $tNumberOfItemsPerPageNr . ' OFFSET ' . (int) $tNumberOfItemsOffsetNr;
     }
     $this->set_pagination_args(array("total_items" => $tTotalNrOfItemsNr, "total_pages" => $tTotalNrOfPagesNr, "per_page" => $tNumberOfItemsPerPageNr));
     // Updating the data available for this class; this data will later be
     // rendered for the user
     $tColumnsAr = $this->get_columns();
     $this->_column_headers = array($tColumnsAr, array(), array());
     $this->items = $wpdb->get_results($tQuerySg);
 }
Example #2
0
function isFirstCall($iCallerIdNr)
{
    global $wpdb;
    $tTableNameSg = getCallRecordTableName();
    $tCallerIdColNameSg = DatabaseAttributes::caller_id;
    $tQuerySg = "SELECT * FROM {$tTableNameSg} WHERE {$tCallerIdColNameSg}='{$iCallerIdNr}'";
    //exec query and get an array of matching rows
    $tResultMix = $wpdb->get_results($tQuerySg, ARRAY_N);
    if ($tResultMix != false && count($tResultMix) > 0) {
        return false;
    } else {
        return true;
    }
}