query() public method

More information can be found on the codex page.
Since: 0.71
public query ( string $query ) : integer | false
$query string Database query
return integer | false Number of rows affected/selected or false on error
 public function query($query, $parameters = array())
 {
     if (!empty($parameters)) {
         $query = str_replace('?', '%s', $query);
         $query = $this->wpdb->prepare($query, $parameters);
     }
     return $this->wpdb->query($query);
 }
 public function remove_db_tables()
 {
     $table = $this->wpdb->prefix . 'icl_string_pages';
     $this->wpdb->query('DROP TABLE IF EXISTS ' . $table);
     $table = $this->wpdb->prefix . 'icl_string_urls';
     $this->wpdb->query('DROP TABLE IF EXISTS ' . $table);
 }
 public function launchkey_cron()
 {
     $table_name = $this->wpdb->prefix . 'launchkey_sso_sessions';
     $dt = new DateTime("- 1 hour");
     $dt->setTimezone(new DateTimeZone("UTC"));
     $this->wpdb->query($this->wpdb->prepare("DELETE FROM {$table_name} WHERE seen < %s", $dt->format("Y-m-d H:i:s")));
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function query($sql)
 {
     $sql = $this->_prepareSql($sql);
     $result = $this->_db->query($sql);
     $this->_checkError();
     return $result;
 }
 /**
  * Performs an SQL query assigning all terms to their correct language equivalent if it exists.
  * This should only be run after the previous functionality in here has finished.
  * Afterwards the term counts are recalculated globally, since term assignments bypassing the WordPress Core,
  * will not trigger any sort of update on those.
  */
 private function reassign_terms()
 {
     $update_query = $this->wpdb->prepare("UPDATE {$this->wpdb->term_relationships} AS o,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS ic,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS iw,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS ip,\n\t\t\t\t\t{$this->wpdb->posts} AS p\n\t\t\t\t\t\tSET o.term_taxonomy_id = ic.element_id\n\t\t\t\t\t\tWHERE ic.trid = iw.trid\n\t\t\t\t\t\t\tAND ic.element_type = iw.element_type\n\t\t\t\t\t\t\tAND iw.element_id = o.term_taxonomy_id\n\t\t\t\t\t\t\tAND ic.language_code = ip.language_code\n\t\t\t\t\t\t\tAND ip.element_type = CONCAT('post_', p.post_type)\n\t\t\t\t\t\t\tAND ip.element_id = p.ID\n\t\t\t\t\t\t\tAND o.object_id = p.ID\n\t\t\t\t\t\t\tAND o.term_taxonomy_id != ic.element_id\n\t\t\t\t\t\t\tAND iw.element_type = %s", 'tax_' . $this->taxonomy);
     $rows_affected = $this->wpdb->query($update_query);
     if ($rows_affected) {
         $term_ids = $this->wpdb->get_col($this->wpdb->prepare("SELECT term_taxonomy_id FROM {$this->wpdb->term_taxonomy} WHERE taxonomy = %s", $this->taxonomy));
         // Do not run the count update on taxonomies that are not actually registered as proper taxonomy objects, e.g. WooCommerce Product Attributes.
         $taxonomy_object = $this->sitepress->get_wp_api()->get_taxonomy($this->taxonomy);
         if ($taxonomy_object && isset($taxonomy_object->object_type)) {
             $this->sitepress->get_wp_api()->wp_update_term_count($term_ids, $this->taxonomy);
         }
     }
 }
Example #6
0
 public function tearDown()
 {
     // Remove test tables.
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 0');
     $this->wpdb->query('DROP TABLE `test_types`');
     $this->wpdb->query('DROP TABLE `test_table`');
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 1');
     // Uninstall
     if (!defined('WP_UNINSTALL_PLUGIN')) {
         define('WP_UNINSTALL_PLUGIN', 'tabulate/tabulate.php');
     }
     require __DIR__ . '/../uninstall.php';
     parent::tearDown();
 }
 private function persist()
 {
     foreach (array_chunk($this->data, self::INSERT_CHUNK_SIZE) as $chunk) {
         $query = "INSERT IGNORE INTO {$this->wpdb->prefix}icl_strings " . '(`language`, `context`, `gettext_context`, `domain_name_context_md5`, `name`, `value`, `status`) VALUES ';
         $i = 0;
         foreach ($chunk as $string) {
             if ($i > 0) {
                 $query .= ',';
             }
             $query .= $this->wpdb->prepare("('%s', '%s', '%s', '%s', '%s', '%s', %d)", $this->get_source_lang($string['name'], $string['domain']), $string['domain'], $string['gettext_context'], md5($string['domain'] . $string['name'] . $string['gettext_context']), $string['name'], $string['value'], ICL_TM_NOT_TRANSLATED);
             $i++;
         }
         $this->wpdb->query($query);
     }
 }
Example #8
0
 /**
  * Perform a MySQL database query, using current database connection.
  *
  * @see wpdb::query()
  *
  * @param string $query Database query
  * @return int|false Number of rows affected/selected or false on error
  */
 function query($query)
 {
     if (!$this->ready) {
         if (isset($this->check_current_query)) {
             // This property was introduced in WP 4.2
             $this->check_current_query = true;
         }
         return false;
     }
     if ($this->show_errors) {
         $this->hide_errors();
     }
     $result = parent::query($query);
     if (!SAVEQUERIES) {
         return $result;
     }
     $i = $this->num_queries - 1;
     $this->queries[$i]['trace'] = new QM_Backtrace(array('ignore_items' => 1));
     if ($this->last_error) {
         $this->queries[$i]['result'] = new WP_Error('qmdb', $this->last_error);
     } else {
         $this->queries[$i]['result'] = $result;
     }
     return $result;
 }
Example #9
0
 /**
  * Update or insert a license.
  *
  * @param Wslm_ProductLicense|array $license
  * @return Wslm_ProductLicense
  */
 public function saveLicense($license)
 {
     if (is_array($license)) {
         $license = new Wslm_ProductLicense($license);
     }
     $data = $license->getData();
     //The license object might have some virtual or computed fields that don't exist in the DB.
     //If we try to update/insert those, we'll get an SQL error. So lets filter the data array
     //to ensure only valid fields are included in the query.
     $licenseDbFields = array('license_id', 'license_key', 'product_id', 'product_slug', 'customer_id', 'status', 'issued_on', 'expires_on', 'max_sites');
     $licenseDbFields = apply_filters('wslm_license_db_fields', $licenseDbFields);
     $data = array_intersect_key($data, array_flip($licenseDbFields));
     if (is_numeric($data['expires_on'])) {
         $data['expires_on'] = date('Y-m-d H:i:s', $data['expires_on']);
     }
     if ($license->get('license_id') === null) {
         //wpdb converts null values to "0" which is not what we want.
         //When inserting, we can simply strip them and let the DB fill in the blanks with NULLs.
         $data = array_filter($data, __CLASS__ . '::isNotNull');
         $this->wpdb->insert($this->tablePrefix . 'licenses', $data);
         $license['license_id'] = $this->wpdb->insert_id;
     } else {
         //When updating, we need to check for nulls and treat them differently,
         //so we can't use $wpdb->update here.
         $query = "UPDATE {$this->tablePrefix}licenses SET ";
         $expressions = array();
         foreach ($data as $field => $value) {
             $expressions[] = $field . ' = ' . ($value === null ? 'NULL' : $this->wpdb->prepare('%s', $value));
         }
         $query .= implode(', ', $expressions);
         $query .= ' WHERE license_id = ' . absint($license['license_id']);
         $this->wpdb->query($query);
     }
     return $license;
 }
Example #10
0
 public function tearDown()
 {
     // Remove test tables.
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 0');
     $this->wpdb->query('DROP TABLE IF EXISTS `test_types`');
     $this->wpdb->query('DROP TABLE IF EXISTS `test_table`');
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 1');
     $ct = new \WordPress\Tabulate\DB\ChangeTracker($this->wpdb);
     $ct->close_changeset();
     // Uninstall
     if (!defined('WP_UNINSTALL_PLUGIN')) {
         define('WP_UNINSTALL_PLUGIN', 'tabulate/tabulate.php');
     }
     require __DIR__ . '/../uninstall.php';
     parent::tearDown();
 }
Example #11
0
 /**
  * Save entity to database.
  *
  * @return int|false
  */
 public function save()
 {
     // Prepare query data.
     $set = array();
     $values = array();
     foreach ($this->values as $field => $value) {
         if ($field == 'id') {
             continue;
         }
         if ($value === null) {
             $set[] = sprintf('`%s` = NULL', $field);
         } else {
             $set[] = sprintf('`%s` = %s', $field, $this->formats[$field]);
             $values[] = $value;
         }
     }
     // Run query.
     if ($this->values['id']) {
         $res = $this->wpdb->query($this->wpdb->prepare(sprintf('UPDATE `%s` SET %s WHERE `id` = %d', $this->table_name, implode(', ', $set), $this->values['id']), $values));
     } else {
         $res = $this->wpdb->query($this->wpdb->prepare(sprintf('INSERT INTO `%s` SET %s', $this->table_name, implode(', ', $set)), $values));
         if ($res) {
             $this->values['id'] = $this->wpdb->insert_id;
         }
     }
     return $res;
 }
Example #12
0
	/**
	 * Delete all content from model's table
	 * @return PMAI_Model
	 */
	public function truncateTable() {
		if (FALSE !== $this->wpdb->query("TRUNCATE $this->table")) {
			return $this;
		} else {
			throw new Exception($this->wpdb->last_error);
		}
	}
 function toggle()
 {
     if (!$this->id) {
         return false;
     }
     $this->dirty = true;
     return $this->db->query(sprintf('UPDATE %s SET active = NOT active WHERE id = %d', MEMBERSHIP_TABLE_COMMUNICATIONS, $this->id));
 }
 /**
  * Delete relationships.
  *
  * @param int $site_1
  * @param int $site_2 Optional. If left out, all relations will be deleted.
  * @return int
  */
 public function delete_relation($site_1, $site_2 = 0)
 {
     $site_1 = (int) $site_1;
     $site_2 = (int) $site_2;
     $sql = "DELETE FROM {$this->link_table_name} WHERE (`site_1` = {$site_1} OR `site_2` = {$site_1})";
     if (0 < $site_2) {
         $sql .= " AND (`site_1` = {$site_2} OR `site_2` = {$site_2})";
     }
     return (int) $this->wpdb->query($sql);
 }
Example #15
0
 /**
  * Insert default content into the given table.
  *
  * @param Mlp_Db_Schema_Interface $db_info Table information.
  * @param array                   $columns Table columns.
  *
  * @return int|bool
  */
 private function insert_default(Mlp_Db_Schema_Interface $db_info, array $columns)
 {
     $table = $db_info->get_table_name();
     // Bail if the table already exists
     if ($this->wpdb->query("SHOW TABLES LIKE '{$table}'")) {
         return 0;
     }
     $content = $db_info->get_default_content();
     if (empty($content)) {
         return 0;
     }
     $to_remove = $db_info->get_autofilled_keys();
     foreach ($to_remove as $remove_key) {
         unset($columns[$remove_key]);
     }
     $keys = join(",", array_keys($columns));
     $sql = "INSERT INTO {$table} ( {$keys} ) VALUES " . $content;
     return $this->wpdb->query($sql);
 }
 function reset_pro_translation_configuration()
 {
     $translation_service_name = $this->TranslationProxy->get_current_service_name();
     $this->sitepress->set_setting('content_translation_languages_setup', false);
     $this->sitepress->set_setting('content_translation_setup_complete', false);
     $this->sitepress->set_setting('content_translation_setup_wizard_step', false);
     $this->sitepress->set_setting('translator_choice', false);
     $this->sitepress->set_setting('icl_lang_status', false);
     $this->sitepress->set_setting('icl_balance', false);
     $this->sitepress->set_setting('icl_support_ticket_id', false);
     $this->sitepress->set_setting('icl_current_session', false);
     $this->sitepress->set_setting('last_get_translator_status_call', false);
     $this->sitepress->set_setting('last_icl_reminder_fetch', false);
     $this->sitepress->set_setting('icl_account_email', false);
     $this->sitepress->set_setting('translators_management_info', false);
     $this->sitepress->set_setting('site_id', false);
     $this->sitepress->set_setting('access_key', false);
     $this->sitepress->set_setting('ts_site_id', false);
     $this->sitepress->set_setting('ts_access_key', false);
     if (class_exists('TranslationProxy_Basket')) {
         //Cleaning the basket
         TranslationProxy_Basket::delete_all_items_from_basket();
     }
     $sql_for_remote_rids = $this->wpdb->prepare("FROM {$this->wpdb->prefix}icl_translation_status\n\t\t\t\t\t\t\t\t \t\t\t\tWHERE translation_service != 'local'\n\t\t\t\t\t\t\t\t \t\t\t\t\tAND translation_service != 0\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND status IN ( %d, %d )", ICL_TM_WAITING_FOR_TRANSLATOR, ICL_TM_IN_PROGRESS);
     //Delete all translation service jobs with status "waiting for translator" or "in progress"
     $this->wpdb->query("DELETE FROM {$this->wpdb->prefix}icl_translate_job WHERE rid IN (SELECT rid {$sql_for_remote_rids})");
     //Delete all translation statuses with status "waiting for translator" or "in progress"
     $this->wpdb->query("DELETE {$sql_for_remote_rids}");
     //Cleaning up Translation Proxy settings
     $this->sitepress->set_setting('icl_html_status', false);
     $this->sitepress->set_setting('language_pairs', false);
     if (!$this->TranslationProxy->has_preferred_translation_service()) {
         $this->sitepress->set_setting('translation_service', false);
         $this->sitepress->set_setting('icl_translation_projects', false);
     }
     $this->sitepress->save_settings();
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_core_status");
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_content_status");
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_string_status");
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_node");
     $this->wpdb->query("TRUNCATE TABLE {$this->wpdb->prefix}icl_reminders");
     if ($this->TranslationProxy->has_preferred_translation_service() && $translation_service_name) {
         $confirm_message = 'The translation process with %1$s was reset.';
     } elseif ($translation_service_name) {
         $confirm_message = 'Your site was successfully disconnected from %1$s. Go to the translators tab to connect a new %1$s account or use a different translation service.';
     } else {
         $confirm_message = 'PRO translation has been reset.';
     }
     $response = sprintf(__($confirm_message, 'wpml-translation-management'), $translation_service_name);
     return $response;
 }
 /**
  * Performs cached delete query
  *
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since 1.0.0
  */
 private function performDeleteQuery()
 {
     if (!empty($this->delete)) {
         $query = '';
         $query = 'DELETE FROM ' . $this->tableName . 'WHERE ';
         foreach ($this->delete as $k => $v) {
             $query .= ' (pid1 = ' . $v['pid1'] . ' AND pid2 = ' . $v['pid2'] . ') ';
             $query .= 'OR (pid1 = ' . $v['pid2'] . ' AND pid2 = ' . $v['pid1'] . ') OR';
         }
         if (!empty($query)) {
             $query = rtrim($query, "OR");
             $this->db->query($query . ';');
         }
     }
 }
Example #18
0
 function insertorupdate($table, $query)
 {
     $fields = array_keys($query);
     $formatted_fields = array();
     foreach ($fields as $field) {
         $form = '%s';
         $formatted_fields[] = $form;
     }
     $sql = "INSERT INTO `{$table}` (`" . implode('`,`', $fields) . "`) VALUES ('" . implode("','", $formatted_fields) . "')";
     $sql .= " ON DUPLICATE KEY UPDATE ";
     $dup = array();
     foreach ($fields as $field) {
         $dup[] = "`" . $field . "` = VALUES(`" . $field . "`)";
     }
     $sql .= implode(',', $dup);
     return $this->db->query($this->db->prepare($sql, $query));
 }
Example #19
0
    /**
     * Remove entries older than a week in the IP log.
     */
    public function rotateIPLog()
    {
        // default to weekly
        $interval = 'FLOOR(UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 7 day)) / 86400)';
        switch (wfConfig::get('email_summary_interval', 'weekly')) {
            case 'biweekly':
                $interval = 'FLOOR(UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 14 day)) / 86400)';
                break;
            case 'monthly':
                $interval = 'FLOOR(UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 1 month)) / 86400)';
                break;
        }
        $this->db->query(<<<SQL
DELETE FROM {$this->db->base_prefix}wfBlockedIPLog
WHERE unixday < {$interval}
SQL
);
    }
 /**
  * Insert default content into the given table.
  *
  * @param Mlp_Db_Schema_Interface $db_info Table information.
  * @param array                   $columns Table columns.
  *
  * @return int|bool
  */
 private function insert_default(Mlp_Db_Schema_Interface $db_info, array $columns)
 {
     $table = $db_info->get_table_name();
     // Bail if the table is not empty
     $temp = $this->wpdb->query("SELECT 1 FROM {$table} LIMIT 1");
     if ($temp) {
         return 0;
     }
     $content = $db_info->get_default_content();
     if (empty($content)) {
         return 0;
     }
     $to_remove = $db_info->get_autofilled_keys();
     foreach ($to_remove as $remove_key) {
         unset($columns[$remove_key]);
     }
     $keys = join(",", array_keys($columns));
     $sql = "INSERT INTO {$table} ({$keys}) VALUES {$content};";
     return $this->wpdb->query($sql);
 }
Example #21
0
 /**
  * Perform a MySQL database query, using current database connection.
  *
  * @see wpdb::query()
  *
  * @param string $query Database query
  * @return int|false Number of rows affected/selected or false on error
  */
 function query($query)
 {
     if (!$this->ready) {
         return false;
     }
     if ($this->show_errors) {
         $this->hide_errors();
     }
     $result = parent::query($query);
     if (!SAVEQUERIES) {
         return $result;
     }
     $i = $this->num_queries - 1;
     $this->queries[$i]['trace'] = new QM_Backtrace();
     if ($this->last_error) {
         $this->queries[$i]['result'] = new WP_Error('qmdb', $this->last_error);
     } else {
         $this->queries[$i]['result'] = $result;
     }
     return $result;
 }
Example #22
0
 /**
  * Upgrade routine
  * - Creates log table on plugin activation
  * - Migrates table structure on updates
  */
 public function upgrade()
 {
     $log_db_version = get_option(self::OPTION_DB_VERSION, 0);
     // only run upgrade routine when database version is lower than code version
     if (version_compare(self::DB_VERSION, $log_db_version, '<=')) {
         return;
     }
     global $charset_collate;
     // don't show errors as this would mess with plugin activation
     $this->db->hide_errors();
     // Create table if it does not exist
     $sql = "\n\t\tCREATE TABLE IF NOT EXISTS {$this->table_name} (\n        ID BIGINT(20) NOT NULL AUTO_INCREMENT,\n        email VARCHAR(255) NOT NULL,\n        list_ids VARCHAR(255) NOT NULL,\n        method VARCHAR(255) NOT NULL,\n        type VARCHAR(255) NOT NULL,\n        success TINYINT(1) DEFAULT 1,\n\t\tdata TEXT NULL,\n        related_object_ID BIGINT(20) NULL,\n        url VARCHAR(255) DEFAULT '',\n        datetime timestamp DEFAULT CURRENT_TIMESTAMP,\n        PRIMARY KEY  (ID)\n\t\t) {$charset_collate}";
     $this->db->query($sql);
     // update to v1.0.4
     if (version_compare($log_db_version, '1.0.4', '<=')) {
         // change 'sign-up_form' in 'sign-up-form';
         $this->db->query("UPDATE `{$this->table_name}` SET `signup_type` = 'sign-up-form' WHERE `signup_type` = 'sign-up_form'");
     }
     // update to v1.1
     if (version_compare($log_db_version, '1.1', '<=')) {
         // merge columns `form_ID` and `comment_ID` into `related_object_ID`
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `form_ID` `related_object_ID` BIGINT(20)");
         $this->db->query("UPDATE `{$this->table_name}` SET `related_object_ID` = `comment_ID` WHERE `related_object_ID` = 0 AND `comment_ID` > 0 ");
         $this->db->query("ALTER TABLE `{$this->table_name}` DROP COLUMN `comment_ID`");
         // add 'success' column
         $this->db->query("ALTER TABLE `{$this->table_name}` ADD COLUMN `success` TINYINT(1) DEFAULT 1");
         // rename columns
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `signup_method` `method` VARCHAR(255)");
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `signup_type` `type` VARCHAR(255)");
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `merge_vars` `data` TEXT");
         // alter datatype of `datetime`
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `datetime` `datetime` timestamp DEFAULT CURRENT_TIMESTAMP");
         // change `sign-up-form` to just `form`
         $this->db->query("UPDATE `{$this->table_name}` SET `type` = 'form' WHERE `type` = 'sign-up-form'");
     }
     $this->db->show_errors();
     update_option(self::OPTION_DB_VERSION, self::DB_VERSION);
 }
 /**
  * Update mlp_multilingual_linked table and set type to "post" if empty
  *
  * @param Mlp_Db_Schema_Interface $linked
  * @return void
  */
 private function update_type_column(Mlp_Db_Schema_Interface $linked)
 {
     $table = $linked->get_table_name();
     $this->wpdb->query('UPDATE ' . $table . ' set ml_type = "post" WHERE ml_type != "term"');
 }
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
$queryText = $_REQUEST['query'];
$start = 0;
$column = $_REQUEST['sort'];
$callback = $_REQUEST['callback'];
$department = $_REQUEST['node'];
$direction = $_REQUEST['dir'];
if (!$direction) {
    $direction = 'asc';
}
if (!$department) {
    $column = 'column';
}
$end = $start + limit;
$SQL = "select distinct department from extia order by department asc";
$numRecords = $wpdb->query($SQL);
$records = $wpdb->get_results($SQL);
while (list($num, $record) = each($records)) {
    $SQL = "select count(id) count from extia where department = '" . $record->department . "'order by department asc";
    $wpdb->query($SQL);
    $rows = $wpdb->get_results($SQL);
    $record->numEmployees = $rows[0]->count;
}
if ($callback) {
    print $callback . "(";
}
print json_encode($records);
if ($callback) {
    print ");";
}
#}
Example #25
0
 /**
  * @see wpdb::query()
  */
 function query($query)
 {
     // write operations may need to invalidate the cache
     if (preg_match('/^\\s*(create|alter|truncate|drop|insert|delete|update|replace)\\s/i', $query)) {
         // do not reset the cache if this query is on the whitelist
         $invalidate_cache = true;
         foreach (self::$CACHE_WRITE_WHITELIST as $item) {
             if (strpos($query, $item) !== false) {
                 $invalidate_cache = false;
                 break;
             }
         }
         if ($invalidate_cache) {
             $this->set_cache_info('last_reset_query', $query);
             $this->reset_cache();
         }
     }
     return parent::query($query);
 }
require_once "{$root}/wp-includes/wp-db.php";
require_once "{$root}/wp-includes/functions.php";
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
$start = 0;
$callback = $_REQUEST['callback'];
$direction = $_REQUEST['dir'];
$end = $start + limit;
//
//
//    $SQL = "select count(id) total from extia";
//    $wpdb->query($SQL);
//    $records =  $wpdb->get_results($SQL);
//
//    $total = $records[0]->total;
$SQL = "select DATE_FORMAT(datehired, '%Y') datehired  from extia order by datehired asc limit 1";
$wpdb->query($SQL);
$records = $wpdb->get_results($SQL);
$companyEpoch = $startyear = $records[0]->datehired;
$SQL = "select DATE_FORMAT(datehired, '%Y') datehired  from extia order by datehired desc limit 1";
$wpdb->query($SQL);
$records = $wpdb->get_results($SQL);
$endyear = $records[0]->datehired;
//    $firstyear;
//    $firstyear->total = 1;
//    $firstyear->year = 1999;
//    $startyear = 1998;
//    $newHireData = array(0=>$firstyear);
$newHireData = array();
while ($startyear <= $endyear) {
    $plusone = $startyear + 1;
    $SQL = "select count(id) newhires from extia where datehired between '{$startyear}-01-01 00:00:00' and '{$plusone}-01-01 00:00:00'";
 public function save_db($counter, $id)
 {
     global $wpdb;
     $current_user = wp_get_current_user();
     $chgnac = TRUE;
     $all_files = array();
     $paypal = array();
     $paypal['item_name'] = array();
     $paypal['quantity'] = array();
     $paypal['amount'] = array();
     $is_amount = false;
     $paypal['on_os'] = array();
     $total = 0;
     $form_currency = '$';
     $currency_code = array('USD', 'EUR', 'GBP', 'JPY', 'CAD', 'MXN', 'HKD', 'HUF', 'NOK', 'NZD', 'SGD', 'SEK', 'PLN', 'AUD', 'DKK', 'CHF', 'CZK', 'ILS', 'BRL', 'TWD', 'MYR', 'PHP', 'THB');
     $currency_sign = array('$', '&#8364;', '&#163;', '&#165;', 'C$', 'Mex$', 'HK$', 'Ft', 'kr', 'NZ$', 'S$', 'kr', 'zl', 'A$', 'kr', 'CHF', 'Kc', '&#8362;', 'R$', 'NT$', 'RM', '&#8369;', '&#xe3f;');
     $form = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "formmaker WHERE id= %d", $id));
     $id_old = $id;
     if (!$form->form_front) {
         $id = '';
     }
     if ($form->payment_currency) {
         $form_currency = $currency_sign[array_search($form->payment_currency, $currency_code)];
     }
     $old = false;
     if (isset($form->form)) {
         $old = true;
     }
     $label_id = array();
     $label_label = array();
     $label_type = array();
     $disabled_fields = explode(',', isset($_REQUEST["disabled_fields" . $id]) ? $_REQUEST["disabled_fields" . $id] : "");
     $disabled_fields = array_slice($disabled_fields, 0, count($disabled_fields) - 1);
     if ($old == false || $old == true && $form->form == '') {
         $label_all = explode('#****#', $form->label_order_current);
     } else {
         $label_all = explode('#****#', $form->label_order);
     }
     $label_all = array_slice($label_all, 0, count($label_all) - 1);
     foreach ($label_all as $key => $label_each) {
         $label_id_each = explode('#**id**#', $label_each);
         array_push($label_id, $label_id_each[0]);
         $label_order_each = explode('#**label**#', $label_id_each[1]);
         array_push($label_label, $label_order_each[0]);
         array_push($label_type, $label_order_each[1]);
     }
     $max = $wpdb->get_var("SELECT MAX( group_id ) FROM " . $wpdb->prefix . "formmaker_submits");
     $fvals = array();
     if ($old == FALSE || $old == TRUE && $form->form == '') {
         foreach ($label_type as $key => $type) {
             $value = '';
             if ($type == "type_submit_reset" or $type == "type_map" or $type == "type_editor" or $type == "type_captcha" or $type == "type_recaptcha" or $type == "type_button" or $type == "type_paypal_total" or $type == "type_send_copy") {
                 continue;
             }
             $i = $label_id[$key];
             if (!in_array($i, $disabled_fields)) {
                 switch ($type) {
                     case 'type_text':
                     case 'type_password':
                     case 'type_textarea':
                     case "type_submitter_mail":
                     case "type_date":
                     case "type_own_select":
                     case "type_country":
                     case "type_number":
                         $value = isset($_POST['wdform_' . $i . "_element" . $id]) ? esc_html($_POST['wdform_' . $i . "_element" . $id]) : "";
                         break;
                     case "type_wdeditor":
                         $value = isset($_POST['wdform_' . $i . '_wd_editor' . $id]) ? esc_html($_POST['wdform_' . $i . '_wd_editor' . $id]) : "";
                         break;
                     case "type_mark_map":
                         $value = (isset($_POST['wdform_' . $i . "_long" . $id]) ? $_POST['wdform_' . $i . "_long" . $id] : "") . '***map***' . (isset($_POST['wdform_' . $i . "_lat" . $id]) ? $_POST['wdform_' . $i . "_lat" . $id] : "");
                         break;
                     case "type_date_fields":
                         $value = (isset($_POST['wdform_' . $i . "_day" . $id]) ? $_POST['wdform_' . $i . "_day" . $id] : "") . '-' . (isset($_POST['wdform_' . $i . "_month" . $id]) ? $_POST['wdform_' . $i . "_month" . $id] : "") . '-' . (isset($_POST['wdform_' . $i . "_year" . $id]) ? $_POST['wdform_' . $i . "_year" . $id] : "");
                         break;
                     case "type_time":
                         $ss = isset($_POST['wdform_' . $i . "_ss" . $id]) ? $_POST['wdform_' . $i . "_ss" . $id] : NULL;
                         if (isset($ss)) {
                             $value = (isset($_POST['wdform_' . $i . "_hh" . $id]) ? $_POST['wdform_' . $i . "_hh" . $id] : "") . ':' . (isset($_POST['wdform_' . $i . "_mm" . $id]) ? $_POST['wdform_' . $i . "_mm" . $id] : "") . ':' . (isset($_POST['wdform_' . $i . "_ss" . $id]) ? $_POST['wdform_' . $i . "_ss" . $id] : "");
                         } else {
                             $value = (isset($_POST['wdform_' . $i . "_hh" . $id]) ? $_POST['wdform_' . $i . "_hh" . $id] : "") . ':' . (isset($_POST['wdform_' . $i . "_mm" . $id]) ? $_POST['wdform_' . $i . "_mm" . $id] : "");
                         }
                         $am_pm = isset($_POST['wdform_' . $i . "_am_pm" . $id]) ? $_POST['wdform_' . $i . "_am_pm" . $id] : NULL;
                         if (isset($am_pm)) {
                             $value = $value . ' ' . $am_pm;
                         }
                         break;
                     case "type_phone":
                         $value = (isset($_POST['wdform_' . $i . "_element_first" . $id]) ? $_POST['wdform_' . $i . "_element_first" . $id] : "") . ' ' . (isset($_POST['wdform_' . $i . "_element_last" . $id]) ? $_POST['wdform_' . $i . "_element_last" . $id] : "");
                         break;
                     case "type_name":
                         $element_title = isset($_POST['wdform_' . $i . "_element_title" . $id]) ? esc_html($_POST['wdform_' . $i . "_element_title" . $id]) : NULL;
                         if (isset($element_title)) {
                             $value = (isset($_POST['wdform_' . $i . "_element_title" . $id]) ? esc_html($_POST['wdform_' . $i . "_element_title" . $id]) : "") . '@@@' . (isset($_POST['wdform_' . $i . "_element_first" . $id]) ? esc_html($_POST['wdform_' . $i . "_element_first" . $id]) : "") . '@@@' . (isset($_POST['wdform_' . $i . "_element_last" . $id]) ? esc_html($_POST['wdform_' . $i . "_element_last" . $id]) : "") . '@@@' . (isset($_POST['wdform_' . $i . "_element_middle" . $id]) ? esc_html($_POST['wdform_' . $i . "_element_middle" . $id]) : "");
                         } else {
                             $value = (isset($_POST['wdform_' . $i . "_element_first" . $id]) ? esc_html($_POST['wdform_' . $i . "_element_first" . $id]) : "") . '@@@' . (isset($_POST['wdform_' . $i . "_element_last" . $id]) ? esc_html($_POST['wdform_' . $i . "_element_last" . $id]) : "");
                         }
                         break;
                     case 'type_address':
                         $value = '*#*#*#';
                         $element = isset($_POST['wdform_' . $i . "_street1" . $id]) ? esc_html($_POST['wdform_' . $i . "_street1" . $id]) : NULL;
                         if (isset($element)) {
                             $value = $element;
                             break;
                         }
                         $element = isset($_POST['wdform_' . $i . "_street2" . $id]) ? esc_html($_POST['wdform_' . $i . "_street2" . $id]) : NULL;
                         if (isset($element)) {
                             $value = $element;
                             break;
                         }
                         $element = isset($_POST['wdform_' . $i . "_city" . $id]) ? esc_html($_POST['wdform_' . $i . "_city" . $id]) : NULL;
                         if (isset($element)) {
                             $value = $element;
                             break;
                         }
                         $element = isset($_POST['wdform_' . $i . "_state" . $id]) ? esc_html($_POST['wdform_' . $i . "_state" . $id]) : NULL;
                         if (isset($element)) {
                             $value = $element;
                             break;
                         }
                         $element = isset($_POST['wdform_' . $i . "_postal" . $id]) ? esc_html($_POST['wdform_' . $i . "_postal" . $id]) : NULL;
                         if (isset($element)) {
                             $value = $element;
                             break;
                         }
                         $element = isset($_POST['wdform_' . $i . "_country" . $id]) ? esc_html($_POST['wdform_' . $i . "_country" . $id]) : NULL;
                         if (isset($element)) {
                             $value = $element;
                             break;
                         }
                         break;
                     case "type_hidden":
                         $value = isset($_POST[$label_order_original[$key]]) ? esc_html($_POST[$label_order_original[$key]]) : "";
                         break;
                     case "type_radio":
                         $element = isset($_POST['wdform_' . $i . "_other_input" . $id]) ? $_POST['wdform_' . $i . "_other_input" . $id] : NULL;
                         if (isset($element)) {
                             $value = $element;
                             break;
                         }
                         $value = isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : "";
                         break;
                     case "type_checkbox":
                         $start = -1;
                         $value = '';
                         for ($j = 0; $j < 100; $j++) {
                             $element = isset($_POST['wdform_' . $i . "_element" . $id . $j]) ? $_POST['wdform_' . $i . "_element" . $id . $j] : NULL;
                             if (isset($element)) {
                                 $start = $j;
                                 break;
                             }
                         }
                         $other_element_id = -1;
                         $is_other = isset($_POST['wdform_' . $i . "_allow_other" . $id]) ? $_POST['wdform_' . $i . "_allow_other" . $id] : "";
                         if ($is_other == "yes") {
                             $other_element_id = isset($_POST['wdform_' . $i . "_allow_other_num" . $id]) ? $_POST['wdform_' . $i . "_allow_other_num" . $id] : "";
                         }
                         if ($start != -1) {
                             for ($j = $start; $j < 100; $j++) {
                                 $element = isset($_POST['wdform_' . $i . "_element" . $id . $j]) ? $_POST['wdform_' . $i . "_element" . $id . $j] : NULL;
                                 if (isset($element)) {
                                     if ($j == $other_element_id) {
                                         $value = $value . (isset($_POST['wdform_' . $i . "_other_input" . $id]) ? $_POST['wdform_' . $i . "_other_input" . $id] : "") . '***br***';
                                     } else {
                                         $value = $value . (isset($_POST['wdform_' . $i . "_element" . $id . $j]) ? $_POST['wdform_' . $i . "_element" . $id . $j] : "") . '***br***';
                                     }
                                 }
                             }
                         }
                         break;
                     case "type_paypal_price":
                         $value = isset($_POST['wdform_' . $i . "_element_dollars" . $id]) ? $_POST['wdform_' . $i . "_element_dollars" . $id] : 0;
                         $value = (int) preg_replace('/\\D/', '', $value);
                         if (isset($_POST['wdform_' . $i . "_element_cents" . $id])) {
                             $value = $value . '.' . preg_replace('/\\D/', '', $_POST['wdform_' . $i . "_element_cents" . $id]);
                         }
                         $total += (double) $value;
                         $paypal_option = array();
                         if ($value != 0) {
                             $quantity = isset($_POST['wdform_' . $i . "_element_quantity" . $id]) ? $_POST['wdform_' . $i . "_element_quantity" . $id] : 1;
                             array_push($paypal['item_name'], $label_label[$key]);
                             array_push($paypal['quantity'], $quantity);
                             array_push($paypal['amount'], $value);
                             $is_amount = true;
                             array_push($paypal['on_os'], $paypal_option);
                         }
                         $value = $value . $form_currency;
                         break;
                     case "type_paypal_select":
                         if (isset($_POST['wdform_' . $i . "_element_label" . $id]) && $_POST['wdform_' . $i . "_element" . $id] != '') {
                             $value = $_POST['wdform_' . $i . "_element_label" . $id] . ' : ' . (isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : "") . $form_currency;
                         } else {
                             $value = '';
                         }
                         $quantity = isset($_POST['wdform_' . $i . "_element_quantity" . $id]) ? $_POST['wdform_' . $i . "_element_quantity" . $id] : 1;
                         $total += (double) (isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : 0) * $quantity;
                         array_push($paypal['item_name'], $label_label[$key] . ' ' . (isset($_POST['wdform_' . $i . "_element_label" . $id]) ? $_POST['wdform_' . $i . "_element_label" . $id] : ""));
                         array_push($paypal['quantity'], $quantity);
                         array_push($paypal['amount'], isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : "");
                         if (isset($_POST['wdform_' . $i . "_element" . $id]) && $_POST['wdform_' . $i . "_element" . $id] != 0) {
                             $is_amount = true;
                         }
                         $element_quantity = isset($_POST['wdform_' . $i . "_element_quantity" . $id]) ? $_POST['wdform_' . $i . "_element_quantity" . $id] : NULL;
                         if (isset($element_quantity) && $value != '') {
                             $value .= '***br***' . (isset($_POST['wdform_' . $i . "_element_quantity_label" . $id]) ? $_POST['wdform_' . $i . "_element_quantity_label" . $id] : "") . ': ' . $_POST['wdform_' . $i . "_element_quantity" . $id] . '***quantity***';
                         }
                         $paypal_option = array();
                         $paypal_option['on'] = array();
                         $paypal_option['os'] = array();
                         for ($k = 0; $k < 50; $k++) {
                             $temp_val = isset($_POST['wdform_' . $i . "_property" . $id . $k]) ? $_POST['wdform_' . $i . "_property" . $id . $k] : NULL;
                             if (isset($temp_val) && $value != '') {
                                 array_push($paypal_option['on'], isset($_POST['wdform_' . $i . "_element_property_label" . $id . $k]) ? $_POST['wdform_' . $i . "_element_property_label" . $id . $k] : "");
                                 array_push($paypal_option['os'], isset($_POST['wdform_' . $i . "_property" . $id . $k]) ? $_POST['wdform_' . $i . "_property" . $id . $k] : "");
                                 $value .= '***br***' . (isset($_POST['wdform_' . $i . "_element_property_label" . $id . $k]) ? $_POST['wdform_' . $i . "_element_property_label" . $id . $k] : "") . ': ' . (isset($_POST['wdform_' . $i . "_property" . $id . $k]) ? $_POST['wdform_' . $i . "_property" . $id . $k] : "") . '***property***';
                             }
                         }
                         array_push($paypal['on_os'], $paypal_option);
                         break;
                     case "type_paypal_radio":
                         if (isset($_POST['wdform_' . $i . "_element_label" . $id])) {
                             $value = $_POST['wdform_' . $i . "_element_label" . $id] . ' : ' . (isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : "") . $form_currency;
                         } else {
                             $value = '';
                         }
                         $quantity = isset($_POST['wdform_' . $i . "_element_quantity" . $id]) ? $_POST['wdform_' . $i . "_element_quantity" . $id] : 1;
                         $total += (double) (isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : 0) * $quantity;
                         array_push($paypal['item_name'], $label_label[$key] . ' ' . (isset($_POST['wdform_' . $i . "_element_label" . $id]) ? $_POST['wdform_' . $i . "_element_label" . $id] : ""));
                         array_push($paypal['quantity'], $quantity);
                         array_push($paypal['amount'], isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : 0);
                         if (isset($_POST['wdform_' . $i . "_element" . $id]) && $_POST['wdform_' . $i . "_element" . $id] != 0) {
                             $is_amount = true;
                         }
                         $element_quantity = isset($_POST['wdform_' . $i . "_element_quantity" . $id]) ? $_POST['wdform_' . $i . "_element_quantity" . $id] : NULL;
                         if (isset($element_quantity) && $value != '') {
                             $value .= '***br***' . (isset($_POST['wdform_' . $i . "_element_quantity_label" . $id]) ? $_POST['wdform_' . $i . "_element_quantity_label" . $id] : "") . ': ' . $_POST['wdform_' . $i . "_element_quantity" . $id] . '***quantity***';
                         }
                         $paypal_option = array();
                         $paypal_option['on'] = array();
                         $paypal_option['os'] = array();
                         for ($k = 0; $k < 50; $k++) {
                             $temp_val = isset($_POST['wdform_' . $i . "_property" . $id . $k]) ? $_POST['wdform_' . $i . "_property" . $id . $k] : NULL;
                             if (isset($temp_val) && $value != '') {
                                 array_push($paypal_option['on'], isset($_POST['wdform_' . $i . "_element_property_label" . $id . $k]) ? $_POST['wdform_' . $i . "_element_property_label" . $id . $k] : "");
                                 array_push($paypal_option['os'], $_POST['wdform_' . $i . "_property" . $id . $k]);
                                 $value .= '***br***' . (isset($_POST['wdform_' . $i . "_element_property_label" . $id . $k]) ? $_POST['wdform_' . $i . "_element_property_label" . $id . $k] : "") . ': ' . $_POST['wdform_' . $i . "_property" . $id . $k] . '***property***';
                             }
                         }
                         array_push($paypal['on_os'], $paypal_option);
                         break;
                     case "type_paypal_shipping":
                         if (isset($_POST['wdform_' . $i . "_element_label" . $id])) {
                             $value = $_POST['wdform_' . $i . "_element_label" . $id] . ' : ' . (isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : "") . $form_currency;
                         } else {
                             $value = '';
                         }
                         $value = (isset($_POST['wdform_' . $i . "_element_label" . $id]) ? $_POST['wdform_' . $i . "_element_label" . $id] : "") . ' - ' . (isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : "") . $form_currency;
                         $paypal['shipping'] = isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : "";
                         break;
                     case "type_paypal_checkbox":
                         $start = -1;
                         $value = '';
                         for ($j = 0; $j < 100; $j++) {
                             $element = isset($_POST['wdform_' . $i . "_element" . $id . $j]) ? $_POST['wdform_' . $i . "_element" . $id . $j] : NULL;
                             if (isset($element)) {
                                 $start = $j;
                                 break;
                             }
                         }
                         $other_element_id = -1;
                         $is_other = isset($_POST['wdform_' . $i . "_allow_other" . $id]) ? $_POST['wdform_' . $i . "_allow_other" . $id] : "";
                         if ($is_other == "yes") {
                             $other_element_id = isset($_POST['wdform_' . $i . "_allow_other_num" . $id]) ? $_POST['wdform_' . $i . "_allow_other_num" . $id] : "";
                         }
                         if ($start != -1) {
                             for ($j = $start; $j < 100; $j++) {
                                 $element = isset($_POST['wdform_' . $i . "_element" . $id . $j]) ? $_POST['wdform_' . $i . "_element" . $id . $j] : NULL;
                                 if (isset($element)) {
                                     if ($j == $other_element_id) {
                                         $value = $value . (isset($_POST['wdform_' . $i . "_other_input" . $id]) ? $_POST['wdform_' . $i . "_other_input" . $id] : "") . '***br***';
                                     } else {
                                         $value = $value . (isset($_POST['wdform_' . $i . "_element" . $id . $j . "_label"]) ? $_POST['wdform_' . $i . "_element" . $id . $j . "_label"] : "") . ' - ' . (isset($_POST['wdform_' . $i . "_element" . $id . $j]) && $_POST['wdform_' . $i . "_element" . $id . $j] == '' ? '0' : (isset($_POST['wdform_' . $i . "_element" . $id . $j]) ? $_POST['wdform_' . $i . "_element" . $id . $j] : "")) . $form_currency . '***br***';
                                         $quantity = isset($_POST['wdform_' . $i . "_element_quantity" . $id]) && $_POST['wdform_' . $i . "_element_quantity" . $id] >= 1 ? $_POST['wdform_' . $i . "_element_quantity" . $id] : 1;
                                         $total += (double) (isset($_POST['wdform_' . $i . "_element" . $id . $j]) ? $_POST['wdform_' . $i . "_element" . $id . $j] : 0) * (double) $quantity;
                                         array_push($paypal['item_name'], $label_label[$key] . ' ' . (isset($_POST['wdform_' . $i . "_element" . $id . $j . "_label"]) ? $_POST['wdform_' . $i . "_element" . $id . $j . "_label"] : ""));
                                         array_push($paypal['quantity'], $quantity);
                                         array_push($paypal['amount'], isset($_POST['wdform_' . $i . "_element" . $id . $j]) ? $_POST['wdform_' . $i . "_element" . $id . $j] == '' ? '0' : $_POST['wdform_' . $i . "_element" . $id . $j] : "");
                                         if (isset($_POST['wdform_' . $i . "_element" . $id . $j]) && $_POST['wdform_' . $i . "_element" . $id . $j] != 0) {
                                             $is_amount = TRUE;
                                         }
                                         $paypal_option = array();
                                         $paypal_option['on'] = array();
                                         $paypal_option['os'] = array();
                                         for ($k = 0; $k < 50; $k++) {
                                             $temp_val = isset($_POST['wdform_' . $i . "_property" . $id . $k]) ? $_POST['wdform_' . $i . "_property" . $id . $k] : NULL;
                                             if (isset($temp_val)) {
                                                 array_push($paypal_option['on'], isset($_POST['wdform_' . $i . "_element_property_label" . $id . $k]) ? $_POST['wdform_' . $i . "_element_property_label" . $id . $k] : "");
                                                 array_push($paypal_option['os'], $_POST['wdform_' . $i . "_property" . $id . $k]);
                                             }
                                         }
                                         array_push($paypal['on_os'], $paypal_option);
                                     }
                                 }
                             }
                             $element_quantity = isset($_POST['wdform_' . $i . "_element_quantity" . $id]) ? $_POST['wdform_' . $i . "_element_quantity" . $id] : NULL;
                             if (isset($element_quantity)) {
                                 $value .= (isset($_POST['wdform_' . $i . "_element_quantity_label" . $id]) ? $_POST['wdform_' . $i . "_element_quantity_label" . $id] : "") . ': ' . $_POST['wdform_' . $i . "_element_quantity" . $id] . '***quantity***';
                             }
                             for ($k = 0; $k < 50; $k++) {
                                 $temp_val = isset($_POST['wdform_' . $i . "_property" . $id . $k]) ? $_POST['wdform_' . $i . "_property" . $id . $k] : NULL;
                                 if (isset($temp_val)) {
                                     $value .= '***br***' . (isset($_POST['wdform_' . $i . "_element_property_label" . $id . $k]) ? $_POST['wdform_' . $i . "_element_property_label" . $id . $k] : "") . ': ' . $_POST['wdform_' . $i . "_property" . $id . $k] . '***property***';
                                 }
                             }
                         }
                         break;
                     case "type_star_rating":
                         if (isset($_POST['wdform_' . $i . "_selected_star_amount" . $id]) && $_POST['wdform_' . $i . "_selected_star_amount" . $id] == "") {
                             $selected_star_amount = 0;
                         } else {
                             $selected_star_amount = isset($_POST['wdform_' . $i . "_selected_star_amount" . $id]) ? $_POST['wdform_' . $i . "_selected_star_amount" . $id] : 0;
                         }
                         $value = $selected_star_amount . '/' . (isset($_POST['wdform_' . $i . "_star_amount" . $id]) ? $_POST['wdform_' . $i . "_star_amount" . $id] : "");
                         break;
                     case "type_scale_rating":
                         $value = (isset($_POST['wdform_' . $i . "_scale_radio" . $id]) ? $_POST['wdform_' . $i . "_scale_radio" . $id] : 0) . '/' . (isset($_POST['wdform_' . $i . "_scale_amount" . $id]) ? $_POST['wdform_' . $i . "_scale_amount" . $id] : "");
                         break;
                     case "type_spinner":
                         $value = isset($_POST['wdform_' . $i . "_element" . $id]) ? $_POST['wdform_' . $i . "_element" . $id] : "";
                         break;
                     case "type_slider":
                         $value = isset($_POST['wdform_' . $i . "_slider_value" . $id]) ? $_POST['wdform_' . $i . "_slider_value" . $id] : "";
                         break;
                     case "type_range":
                         $value = (isset($_POST['wdform_' . $i . "_element" . $id . '0']) ? $_POST['wdform_' . $i . "_element" . $id . '0'] : "") . '-' . (isset($_POST['wdform_' . $i . "_element" . $id . '1']) ? $_POST['wdform_' . $i . "_element" . $id . '1'] : "");
                         break;
                     case "type_grading":
                         $value = "";
                         $items = explode(":", isset($_POST['wdform_' . $i . "_hidden_item" . $id]) ? $_POST['wdform_' . $i . "_hidden_item" . $id] : "");
                         for ($k = 0; $k < sizeof($items) - 1; $k++) {
                             $value .= (isset($_POST['wdform_' . $i . "_element" . $id . '_' . $k]) ? $_POST['wdform_' . $i . "_element" . $id . '_' . $k] : "") . ':';
                         }
                         $value .= (isset($_POST['wdform_' . $i . "_hidden_item" . $id]) ? $_POST['wdform_' . $i . "_hidden_item" . $id] : "") . '***grading***';
                         break;
                     case "type_matrix":
                         $rows_of_matrix = explode("***", isset($_POST['wdform_' . $i . "_hidden_row" . $id]) ? $_POST['wdform_' . $i . "_hidden_row" . $id] : "");
                         $rows_count = sizeof($rows_of_matrix) - 1;
                         $column_of_matrix = explode("***", isset($_POST['wdform_' . $i . "_hidden_column" . $id]) ? $_POST['wdform_' . $i . "_hidden_column" . $id] : "");
                         $columns_count = sizeof($column_of_matrix) - 1;
                         if (isset($_POST['wdform_' . $i . "_input_type" . $id]) && $_POST['wdform_' . $i . "_input_type" . $id] == "radio") {
                             $input_value = "";
                             for ($k = 1; $k <= $rows_count; $k++) {
                                 $input_value .= (isset($_POST['wdform_' . $i . "_input_element" . $id . $k]) ? $_POST['wdform_' . $i . "_input_element" . $id . $k] : 0) . "***";
                             }
                         }
                         if (isset($_POST['wdform_' . $i . "_input_type" . $id]) && $_POST['wdform_' . $i . "_input_type" . $id] == "checkbox") {
                             $input_value = "";
                             for ($k = 1; $k <= $rows_count; $k++) {
                                 for ($j = 1; $j <= $columns_count; $j++) {
                                     $input_value .= (isset($_POST['wdform_' . $i . "_input_element" . $id . $k . '_' . $j]) ? $_POST['wdform_' . $i . "_input_element" . $id . $k . '_' . $j] : 0) . "***";
                                 }
                             }
                         }
                         if (isset($_POST['wdform_' . $i . "_input_type" . $id]) && $_POST['wdform_' . $i . "_input_type" . $id] == "text") {
                             $input_value = "";
                             for ($k = 1; $k <= $rows_count; $k++) {
                                 for ($j = 1; $j <= $columns_count; $j++) {
                                     $input_value .= (isset($_POST['wdform_' . $i . "_input_element" . $id . $k . '_' . $j]) ? esc_html($_POST['wdform_' . $i . "_input_element" . $id . $k . '_' . $j]) : "") . "***";
                                 }
                             }
                         }
                         if (isset($_POST['wdform_' . $i . "_input_type" . $id]) && $_POST['wdform_' . $i . "_input_type" . $id] == "select") {
                             $input_value = "";
                             for ($k = 1; $k <= $rows_count; $k++) {
                                 for ($j = 1; $j <= $columns_count; $j++) {
                                     $input_value .= (isset($_POST['wdform_' . $i . "_select_yes_no" . $id . $k . '_' . $j]) ? $_POST['wdform_' . $i . "_select_yes_no" . $id . $k . '_' . $j] : "") . "***";
                                 }
                             }
                         }
                         $value = $rows_count . (isset($_POST['wdform_' . $i . "_hidden_row" . $id]) ? $_POST['wdform_' . $i . "_hidden_row" . $id] : "") . '***' . $columns_count . (isset($_POST['wdform_' . $i . "_hidden_column" . $id]) ? $_POST['wdform_' . $i . "_hidden_column" . $id] : "") . '***' . (isset($_POST['wdform_' . $i . "_input_type" . $id]) ? $_POST['wdform_' . $i . "_input_type" . $id] : "") . '***' . $input_value . '***matrix***';
                         break;
                 }
                 if ($type == "type_address") {
                     if ($value == '*#*#*#') {
                         continue;
                     }
                 }
                 if ($type == "type_text" or $type == "type_password" or $type == "type_textarea" or $type == "type_name" or $type == "type_submitter_mail" or $type == "type_number" or $type == "type_phone") {
                     $untilupload = $form->form_fields;
                     $untilupload = substr($untilupload, strpos($untilupload, $i . '*:*id*:*' . $type), -1);
                     $untilupload = substr($untilupload, 0, strpos($untilupload, '*:*new_field*:'));
                     $untilupload = explode('*:*w_required*:*', $untilupload);
                     $untilupload = $untilupload[1];
                     $untilupload = explode('*:*w_unique*:*', $untilupload);
                     $unique_element = $untilupload[0];
                     if ($unique_element == 'yes') {
                         $unique = $wpdb->get_col($wpdb->prepare("SELECT id FROM " . $wpdb->prefix . "formmaker_submits WHERE form_id= %d  and element_label= %s and element_value= %s", $id, $i, addslashes($value)));
                         if ($unique) {
                             echo "<script> alert('" . addslashes(__('This field %s requires a unique entry and this value was already submitted.', 'form_maker')) . "'.replace('%s','" . $label_label[$key] . "'));</script>";
                             return array($max + 1);
                         }
                     }
                 }
                 $save_or_no = TRUE;
                 $fvals['{' . $i . '}'] = str_replace(array("***map***", "*@@url@@*", "@@@@@@@@@", "@@@", "***grading***", "***br***"), array(" ", "", " ", " ", " ", ", "), addslashes($value));
                 if ($form->savedb) {
                     $save_or_no = $wpdb->insert($wpdb->prefix . "formmaker_submits", array('form_id' => $id, 'element_label' => $i, 'element_value' => stripslashes($value), 'group_id' => $max + 1, 'date' => date('Y-m-d H:i:s'), 'ip' => $_SERVER['REMOTE_ADDR'], 'user_id_wd' => $current_user->ID), array('%d', '%s', '%s', '%d', '%s', '%s', '%d'));
                 }
                 if (!$save_or_no) {
                     return FALSE;
                 }
                 $chgnac = FALSE;
             }
         }
     } else {
         foreach ($label_type as $key => $type) {
             $value = '';
             if ($type == "type_submit_reset" or $type == "type_map" or $type == "type_editor" or $type == "type_captcha" or $type == "type_recaptcha" or $type == "type_button" or $type == "type_paypal_total") {
                 continue;
             }
             $i = $label_id[$key];
             if ($type != "type_address") {
                 $deleted = isset($_POST[$i . "_type" . $id]) ? $_POST[$i . "_type" . $id] : NULL;
                 if (!isset($deleted)) {
                     break;
                 }
             }
             if ($type == 'type_paypal_total') {
                 continue;
             }
             switch ($type) {
                 case 'type_text':
                 case 'type_password':
                 case 'type_textarea':
                 case "type_submitter_mail":
                 case "type_date":
                 case "type_own_select":
                 case "type_country":
                 case "type_number":
                     $value = isset($_POST[$i . "_element" . $id]) ? esc_html($_POST[$i . "_element" . $id]) : "";
                     break;
                 case "type_mark_map":
                     $value = (isset($_POST[$i . "_long" . $id]) ? $_POST[$i . "_long" . $id] : "") . '***map***' . (isset($_POST[$i . "_lat" . $id]) ? $_POST[$i . "_lat" . $id] : "");
                     break;
                 case "type_date_fields":
                     $value = (isset($_POST[$i . "_day" . $id]) ? $_POST[$i . "_day" . $id] : "") . '-' . (isset($_POST[$i . "_month" . $id]) ? $_POST[$i . "_month" . $id] : "") . '-' . (isset($_POST[$i . "_year" . $id]) ? $_POST[$i . "_year" . $id] : "");
                     break;
                 case "type_time":
                     $ss = isset($_POST[$i . "_ss" . $id]) ? $_POST[$i . "_ss" . $id] : NULL;
                     if (isset($ss)) {
                         $value = (isset($_POST[$i . "_hh" . $id]) ? $_POST[$i . "_hh" . $id] : "") . ':' . (isset($_POST[$i . "_mm" . $id]) ? $_POST[$i . "_mm" . $id] : "") . ':' . $ss;
                     } else {
                         $value = (isset($_POST[$i . "_hh" . $id]) ? $_POST[$i . "_hh" . $id] : "") . ':' . (isset($_POST[$i . "_mm" . $id]) ? $_POST[$i . "_mm" . $id] : "");
                     }
                     $am_pm = isset($_POST[$i . "_am_pm" . $id]) ? $_POST[$i . "_am_pm" . $id] : NULL;
                     if (isset($am_pm)) {
                         $value = $value . ' ' . $am_pm;
                     }
                     break;
                 case "type_phone":
                     $value = (isset($_POST[$i . "_element_first" . $id]) ? $_POST[$i . "_element_first" . $id] : "") . ' ' . (isset($_POST[$i . "_element_last" . $id]) ? $_POST[$i . "_element_last" . $id] : "");
                     break;
                 case "type_name":
                     $element_title = isset($_POST[$i . "_element_title" . $id]) ? esc_html($_POST[$i . "_element_title" . $id]) : NULL;
                     if (isset($element_title)) {
                         $value = $element_title . ' ' . (isset($_POST[$i . "_element_first" . $id]) ? esc_html($_POST[$i . "_element_first" . $id]) : "") . ' ' . (isset($_POST[$i . "_element_last" . $id]) ? esc_html($_POST[$i . "_element_last" . $id]) : "") . ' ' . (isset($_POST[$i . "_element_middle" . $id]) ? esc_html($_POST[$i . "_element_middle" . $id]) : "");
                     } else {
                         $value = (isset($_POST[$i . "_element_first" . $id]) ? esc_html($_POST[$i . "_element_first" . $id]) : "") . ' ' . (isset($_POST[$i . "_element_last" . $id]) ? esc_html($_POST[$i . "_element_last" . $id]) : "");
                     }
                     break;
                 case 'type_address':
                     $value = '*#*#*#';
                     if (isset($_POST[$i . "_street1" . $id])) {
                         $value = esc_html($_POST[$i . "_street1" . $id]);
                         break;
                     }
                     if (isset($_POST[$i . "_street2" . $id])) {
                         $value = esc_html($_POST[$i . "_street2" . $id]);
                         break;
                     }
                     if (isset($_POST[$i . "_city" . $id])) {
                         $value = esc_html($_POST[$i . "_city" . $id]);
                         break;
                     }
                     if (isset($_POST[$i . "_state" . $id])) {
                         $value = esc_html($_POST[$i . "_state" . $id]);
                         break;
                     }
                     if (isset($_POST[$i . "_postal" . $id])) {
                         $value = esc_html($_POST[$i . "_postal" . $id]);
                         break;
                     }
                     if (isset($_POST[$i . "_country" . $id])) {
                         $value = esc_html($_POST[$i . "_country" . $id]);
                         break;
                     }
                     break;
                 case "type_hidden":
                     $value = isset($_POST[$label_label[$key]]) ? $_POST[$label_label[$key]] : "";
                     break;
                 case "type_radio":
                     $element = isset($_POST[$i . "_other_input" . $id]) ? $_POST[$i . "_other_input" . $id] : NULL;
                     if (isset($element)) {
                         $value = $element;
                         break;
                     }
                     $value = isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : "";
                     break;
                 case "type_checkbox":
                     $start = -1;
                     $value = '';
                     for ($j = 0; $j < 100; $j++) {
                         if (isset($_POST[$i . "_element" . $id . $j])) {
                             $start = $j;
                             break;
                         }
                     }
                     $other_element_id = -1;
                     $is_other = isset($_POST[$i . "_allow_other" . $id]) ? $_POST[$i . "_allow_other" . $id] : "";
                     if ($is_other == "yes") {
                         $other_element_id = isset($_POST[$i . "_allow_other_num" . $id]) ? $_POST[$i . "_allow_other_num" . $id] : "";
                     }
                     if ($start != -1) {
                         for ($j = $start; $j < 100; $j++) {
                             if (isset($_POST[$i . "_element" . $id . $j])) {
                                 if ($j == $other_element_id) {
                                     $value = $value . (isset($_POST[$i . "_other_input" . $id]) ? $_POST[$i . "_other_input" . $id] : "") . '***br***';
                                 } else {
                                     $value = $value . $_POST[$i . "_element" . $id . $j] . '***br***';
                                 }
                             }
                         }
                     }
                     break;
                 case "type_paypal_price":
                     $value = 0;
                     if (isset($_POST[$i . "_element_dollars" . $id])) {
                         $value = $_POST[$i . "_element_dollars" . $id];
                     }
                     $value = (int) preg_replace('/\\D/', '', $value);
                     if (isset($_POST[$i . "_element_cents" . $id])) {
                         $value = $value . '.' . preg_replace('/\\D/', '', $_POST[$i . "_element_cents" . $id]);
                     }
                     $total += (double) $value;
                     $paypal_option = array();
                     if ($value != 0) {
                         array_push($paypal['item_name'], $label_label[$key]);
                         $quantity = isset($_POST[$i . "_element_quantity" . $id]) && $_POST[$i . "_element_quantity" . $id] >= 1 ? $_POST[$i . "_element_quantity" . $id] : 1;
                         array_push($paypal['quantity'], $quantity);
                         array_push($paypal['amount'], $value);
                         $is_amount = true;
                         array_push($paypal['on_os'], $paypal_option);
                     }
                     $value = $value . $form_currency;
                     break;
                 case "type_paypal_select":
                     $value = '';
                     $value = (isset($_POST[$i . "_element_label" . $id]) ? $_POST[$i . "_element_label" . $id] : "") . ' : ' . (isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : "") . $form_currency;
                     $quantity = isset($_POST[$i . "_element_quantity" . $id]) && $_POST[$i . "_element_quantity" . $id] >= 1 ? $_POST[$i . "_element_quantity" . $id] : 1;
                     $total += (double) (isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : 0) * (double) $quantity;
                     array_push($paypal['item_name'], $label_label[$key] . ' ' . (isset($_POST[$i . "_element_label" . $id]) ? $_POST[$i . "_element_label" . $id] : ""));
                     array_push($paypal['quantity'], $quantity);
                     array_push($paypal['amount'], isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : "");
                     if (isset($_POST[$i . "_element" . $id]) && $_POST[$i . "_element" . $id] != 0) {
                         $is_amount = true;
                     }
                     $element_quantity_label = isset($_POST[$i . "_element_quantity_label" . $id]) ? $_POST[$i . "_element_quantity_label" . $id] : NULL;
                     if (isset($element_quantity_label)) {
                         $value .= '***br***' . $element_quantity_label . ': ' . $quantity;
                     }
                     $paypal_option = array();
                     $paypal_option['on'] = array();
                     $paypal_option['os'] = array();
                     for ($k = 0; $k < 50; $k++) {
                         $temp_val = isset($_POST[$i . "_element_property_value" . $id . $k]) ? $_POST[$i . "_element_property_value" . $id . $k] : NULL;
                         if (isset($temp_val)) {
                             array_push($paypal_option['on'], isset($_POST[$i . "_element_property_label" . $id . $k]) ? $_POST[$i . "_element_property_label" . $id . $k] : "");
                             array_push($paypal_option['os'], $temp_val);
                             $value .= '***br***' . (isset($_POST[$i . "_element_property_label" . $id . $k]) ? $_POST[$i . "_element_property_label" . $id . $k] : "") . ': ' . $temp_val;
                         }
                     }
                     array_push($paypal['on_os'], $paypal_option);
                     break;
                 case "type_paypal_radio":
                     $value = '';
                     if (isset($_POST[$i . "_element_label" . $id]) && $_POST[$i . "_element_label" . $id] != '') {
                         $value = $_POST[$i . "_element_label" . $id] . ' - ' . (isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : "") . $form_currency;
                         $quantity = isset($_POST[$i . "_element_quantity" . $id]) && $_POST[$i . "_element_quantity" . $id] >= 1 ? $_POST[$i . "_element_quantity" . $id] : 1;
                         $total += (double) (isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : 0) * (double) $quantity;
                         array_push($paypal['item_name'], $label_label[$key] . ' ' . $_POST[$i . "_element_label" . $id]);
                         array_push($paypal['quantity'], $quantity);
                         array_push($paypal['amount'], isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : "");
                         if (isset($_POST[$i . "_element" . $id]) && $_POST[$i . "_element" . $id] != 0) {
                             $is_amount = true;
                         }
                         $element_quantity_label = isset($_POST[$i . "_element_quantity_label" . $id]) ? $_POST[$i . "_element_quantity_label" . $id] : NULL;
                         if (isset($element_quantity_label)) {
                             $value .= '***br***' . $element_quantity_label . ': ' . $quantity;
                         }
                         $paypal_option = array();
                         $paypal_option['on'] = array();
                         $paypal_option['os'] = array();
                         for ($k = 0; $k < 50; $k++) {
                             $temp_val = isset($_POST[$i . "_element_property_value" . $id . $k]) ? $_POST[$i . "_element_property_value" . $id . $k] : NULL;
                             if (isset($temp_val)) {
                                 array_push($paypal_option['on'], isset($_POST[$i . "_element_property_label" . $id . $k]) ? $_POST[$i . "_element_property_label" . $id . $k] : "");
                                 array_push($paypal_option['os'], $temp_val);
                                 $value .= '***br***' . (isset($_POST[$i . "_element_property_label" . $id . $k]) ? $_POST[$i . "_element_property_label" . $id . $k] : "") . ': ' . $temp_val;
                             }
                         }
                         array_push($paypal['on_os'], $paypal_option);
                     }
                     break;
                 case "type_paypal_shipping":
                     $value = '';
                     if (isset($_POST[$i . "_element_label" . $id]) && $_POST[$i . "_element_label" . $id] != '') {
                         $value = $_POST[$i . "_element_label" . $id] . ' - ' . (isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : "") . $form_currency;
                         $paypal['shipping'] = isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : "";
                     }
                     break;
                 case "type_paypal_checkbox":
                     $start = -1;
                     $value = '';
                     for ($j = 0; $j < 100; $j++) {
                         if (isset($_POST[$i . "_element" . $id . $j])) {
                             $start = $j;
                             break;
                         }
                     }
                     $other_element_id = -1;
                     $is_other = isset($_POST[$i . "_allow_other" . $id]) ? $_POST[$i . "_allow_other" . $id] : "";
                     if ($is_other == "yes") {
                         $other_element_id = isset($_POST[$i . "_allow_other_num" . $id]) ? $_POST[$i . "_allow_other_num" . $id] : "";
                     }
                     if ($start != -1) {
                         for ($j = $start; $j < 100; $j++) {
                             if (isset($_POST[$i . "_element" . $id . $j])) {
                                 if ($j == $other_element_id) {
                                     $value = $value . (isset($_POST[$i . "_other_input" . $id]) ? $_POST[$i . "_other_input" . $id] : "") . '***br***';
                                 } else {
                                     $value = $value . (isset($_POST[$i . "_element" . $id . $j . "_label"]) ? $_POST[$i . "_element" . $id . $j . "_label"] : "") . ' - ' . ($_POST[$i . "_element" . $id . $j] == '' ? '0' : $_POST[$i . "_element" . $id . $j]) . $form_currency . '***br***';
                                     $quantity = isset($_POST[$i . "_element_quantity" . $id]) && $_POST[$i . "_element_quantity" . $id] >= 1 ? $_POST[$i . "_element_quantity" . $id] : 1;
                                     $total += (double) (isset($_POST[$i . "_element" . $id . $j]) ? $_POST[$i . "_element" . $id . $j] : 0) * (double) $quantity;
                                     array_push($paypal['item_name'], $label_label[$key] . ' ' . (isset($_POST[$i . "_element" . $id . $j . "_label"]) ? $_POST[$i . "_element" . $id . $j . "_label"] : ""));
                                     array_push($paypal['quantity'], $quantity);
                                     array_push($paypal['amount'], $_POST[$i . "_element" . $id . $j] == '' ? '0' : $_POST[$i . "_element" . $id . $j]);
                                     if (isset($_POST[$i . "_element" . $id . $j]) && $_POST[$i . "_element" . $id . $j] != 0) {
                                         $is_amount = TRUE;
                                     }
                                     $paypal_option = array();
                                     $paypal_option['on'] = array();
                                     $paypal_option['os'] = array();
                                     for ($k = 0; $k < 50; $k++) {
                                         $temp_val = isset($_POST[$i . "_element_property_value" . $id . $k]) ? $_POST[$i . "_element_property_value" . $id . $k] : NULL;
                                         if (isset($temp_val)) {
                                             array_push($paypal_option['on'], isset($_POST[$i . "_element_property_label" . $id . $k]) ? $_POST[$i . "_element_property_label" . $id . $k] : "");
                                             array_push($paypal_option['os'], $temp_val);
                                         }
                                     }
                                     array_push($paypal['on_os'], $paypal_option);
                                 }
                             }
                         }
                         $element_quantity_label = isset($_POST[$i . "_element_quantity_label" . $id]) ? $_POST[$i . "_element_quantity_label" . $id] : NULL;
                         $quantity = isset($_POST[$i . "_element_quantity" . $id]) && $_POST[$i . "_element_quantity" . $id] >= 1 ? $_POST[$i . "_element_quantity" . $id] : 1;
                         if (isset($element_quantity_label)) {
                             $value .= $element_quantity_label . ': ' . $quantity . '***br***';
                         }
                         for ($k = 0; $k < 50; $k++) {
                             $temp_val = isset($_POST[$i . "_element_property_value" . $id . $k]) ? $_POST[$i . "_element_property_value" . $id . $k] : NULL;
                             if (isset($temp_val)) {
                                 $value .= (isset($_POST[$i . "_element_property_label" . $id . $k]) ? $_POST[$i . "_element_property_label" . $id . $k] : "") . ': ' . $temp_val . '***br***';
                             }
                         }
                     }
                     break;
                 case "type_star_rating":
                     if (isset($_POST[$i . "_selected_star_amount" . $id]) && $_POST[$i . "_selected_star_amount" . $id] != "") {
                         $selected_star_amount = $_POST[$i . "_selected_star_amount" . $id];
                     } else {
                         $selected_star_amount = 0;
                     }
                     $value = (isset($_POST[$i . "_star_amount" . $id]) ? $_POST[$i . "_star_amount" . $id] : '') . '***' . $selected_star_amount . '***' . (isset($_POST[$i . "_star_color" . $id]) ? $_POST[$i . "_star_color" . $id] : '') . '***star_rating***';
                     break;
                 case "type_scale_rating":
                     $value = (isset($_POST[$i . "_scale_radio" . $id]) ? $_POST[$i . "_scale_radio" . $id] : 0) . '/' . (isset($_POST[$i . "_scale_amount" . $id]) ? $_POST[$i . "_scale_amount" . $id] : '');
                     break;
                 case "type_spinner":
                     $value = isset($_POST[$i . "_element" . $id]) ? $_POST[$i . "_element" . $id] : '';
                     break;
                 case "type_slider":
                     $value = isset($_POST[$i . "_slider_value" . $id]) ? $_POST[$i . "_slider_value" . $id] : '';
                     break;
                 case "type_range":
                     $value = (isset($_POST[$i . "_element" . $id . '0']) ? $_POST[$i . "_element" . $id . '0'] : '') . '-' . (isset($_POST[$i . "_element" . $id . '1']) ? $_POST[$i . "_element" . $id . '1'] : '');
                     break;
                 case "type_grading":
                     $value = "";
                     if (isset($_POST[$i . "_hidden_item" . $id])) {
                         $items = explode(":", $_POST[$i . "_hidden_item" . $id]);
                         for ($k = 0; $k < sizeof($items) - 1; $k++) {
                             if (isset($_POST[$i . "_element" . $id . $k])) {
                                 $value .= $_POST[$i . "_element" . $id . $k] . ':';
                             }
                         }
                         $value .= $_POST[$i . "_hidden_item" . $id] . '***grading***';
                     }
                     break;
                 case "type_matrix":
                     $rows_of_matrix = explode("***", isset($_POST[$i . "_hidden_row" . $id]) ? $_POST[$i . "_hidden_row" . $id] : "");
                     $rows_count = sizeof($rows_of_matrix) - 1;
                     $column_of_matrix = explode("***", isset($_POST[$i . "_hidden_column" . $id]) ? $_POST[$i . "_hidden_column" . $id] : "");
                     $columns_count = sizeof($column_of_matrix) - 1;
                     $row_ids = explode(",", substr(isset($_POST[$i . "_row_ids" . $id]) ? $_POST[$i . "_row_ids" . $id] : "", 0, -1));
                     $column_ids = explode(",", substr(isset($_POST[$i . "_column_ids" . $id]) ? $_POST[$i . "_column_ids" . $id] : "", 0, -1));
                     if (isset($_POST[$i . "_input_type" . $id]) && $_POST[$i . "_input_type" . $id] == "radio") {
                         $input_value = "";
                         foreach ($row_ids as $row_id) {
                             $input_value .= (isset($_POST[$i . "_input_element" . $id . $row_id]) ? $_POST[$i . "_input_element" . $id . $row_id] : 0) . "***";
                         }
                     }
                     if (isset($_POST[$i . "_input_type" . $id]) && $_POST[$i . "_input_type" . $id] == "checkbox") {
                         $input_value = "";
                         foreach ($row_ids as $row_id) {
                             foreach ($column_ids as $column_id) {
                                 $input_value .= (isset($_POST[$i . "_input_element" . $id . $row_id . '_' . $column_id]) ? $_POST[$i . "_input_element" . $id . $row_id . '_' . $column_id] : 0) . "***";
                             }
                         }
                     }
                     if (isset($_POST[$i . "_input_type" . $id]) && $_POST[$i . "_input_type" . $id] == "text") {
                         $input_value = "";
                         foreach ($row_ids as $row_id) {
                             foreach ($column_ids as $column_id) {
                                 $input_value .= (isset($_POST[$i . "_input_element" . $id . $row_id . '_' . $column_id]) ? esc_html($_POST[$i . "_input_element" . $id . $row_id . '_' . $column_id]) : "") . "***";
                             }
                         }
                     }
                     if (isset($_POST[$i . "_input_type" . $id]) && $_POST[$i . "_input_type" . $id] == "select") {
                         $input_value = "";
                         foreach ($row_ids as $row_id) {
                             foreach ($column_ids as $column_id) {
                                 $input_value .= (isset($_POST[$i . "_select_yes_no" . $id . $row_id . '_' . $column_id]) ? $_POST[$i . "_select_yes_no" . $id . $row_id . '_' . $column_id] : "") . "***";
                             }
                         }
                     }
                     $value = $rows_count . '***' . (isset($_POST[$i . "_hidden_row" . $id]) ? $_POST[$i . "_hidden_row" . $id] : "") . $columns_count . '***' . (isset($_POST[$i . "_hidden_column" . $id]) ? $_POST[$i . "_hidden_column" . $id] : "") . (isset($_POST[$i . "_input_type" . $id]) ? $_POST[$i . "_input_type" . $id] : "") . '***' . $input_value . '***matrix***';
                     break;
             }
             if ($type == "type_address") {
                 if ($value == '*#*#*#') {
                     // break; ?????????????????????????????????????????????????????
                     continue;
                 }
             }
             $unique_element = isset($_POST[$i . "_unique" . $id]) ? $_POST[$i . "_unique" . $id] : "";
             if ($unique_element == 'yes') {
                 $unique = $wpdb->get_col($wpdb->prepare("SELECT id FROM " . $wpdb->prefix . "formmaker_submits WHERE form_id= %d  and element_label= %s and element_value= %s", $id_old, $i, addslashes($value)));
                 if ($unique) {
                     echo "<script> alert('" . addslashes(__('This field %s requires a unique entry and this value was already submitted.', 'form_maker')) . "'.replace('%s','" . $label_label[$key] . "'));</script>";
                     return array($max + 1);
                 }
             }
             $ip = $_SERVER['REMOTE_ADDR'];
             $r = $wpdb->prefix . "formmaker_submits";
             $save_or_no = $wpdb->insert($r, array('form_id' => $id_old, 'element_label' => $i, 'element_value' => stripslashes($value), 'group_id' => $max + 1, 'date' => date('Y-m-d H:i:s'), 'ip' => $ip, 'user_id_wd' => $current_user->ID), array('%d', '%s', '%s', '%d', '%s', '%s', '%d'));
             if (!$save_or_no) {
                 return FALSE;
             }
             $chgnac = FALSE;
         }
     }
     $queries = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "formmaker_query WHERE form_id=%d", (int) $id));
     if ($queries) {
         foreach ($queries as $query) {
             $temp = explode('***wdfcon_typewdf***', $query->details);
             $con_type = $temp[0];
             $temp = explode('***wdfcon_methodwdf***', $temp[1]);
             $con_method = $temp[0];
             $temp = explode('***wdftablewdf***', $temp[1]);
             $table_cur = $temp[0];
             $temp = explode('***wdfhostwdf***', $temp[1]);
             $host = $temp[0];
             $temp = explode('***wdfportwdf***', $temp[1]);
             $port = $temp[0];
             $temp = explode('***wdfusernamewdf***', $temp[1]);
             $username = $temp[0];
             $temp = explode('***wdfpasswordwdf***', $temp[1]);
             $password = $temp[0];
             $temp = explode('***wdfdatabasewdf***', $temp[1]);
             $database = $temp[0];
             $query = str_replace(array_keys($fvals), $fvals, $query->query);
             if ($con_type == 'remote') {
                 $wpdb_temp = new wpdb($username, $password, $database, $host);
                 $wpdb_temp->query($query);
             } else {
                 $wpdb->query($query);
             }
         }
         // $wpdb= new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
     }
     $str = '';
     if ($form->paypal_mode) {
         if ($paypal['item_name']) {
             if ($is_amount) {
                 $tax = $form->tax;
                 $currency = $form->payment_currency;
                 $business = $form->paypal_email;
                 $ip = $_SERVER['REMOTE_ADDR'];
                 $total2 = round($total, 2);
                 $save_or_no = $wpdb->insert($wpdb->prefix . "formmaker_submits", array('form_id' => $id, 'element_label' => 'item_total', 'element_value' => $total2 . $form_currency, 'group_id' => $max + 1, 'date' => date('Y-m-d H:i:s'), 'ip' => $ip, 'user_id_wd' => $current_user->ID), array('%d', '%s', '%s', '%d', '%s', '%s', '%d'));
                 if (!$save_or_no) {
                     return false;
                 }
                 $total = $total + $total * $tax / 100;
                 if (isset($paypal['shipping'])) {
                     $total = $total + $paypal['shipping'];
                 }
                 $total = round($total, 2);
                 $save_or_no = $wpdb->insert($wpdb->prefix . "formmaker_submits", array('form_id' => $id, 'element_label' => 'total', 'element_value' => $total . $form_currency, 'group_id' => $max + 1, 'date' => date('Y-m-d H:i:s'), 'ip' => $ip, 'user_id_wd' => $current_user->ID), array('%d', '%s', '%s', '%d', '%s', '%s', '%d'));
                 if (!$save_or_no) {
                     return false;
                 }
                 $save_or_no = $wpdb->insert($wpdb->prefix . "formmaker_submits", array('form_id' => $id, 'element_label' => '0', 'element_value' => 'In progress', 'group_id' => $max + 1, 'date' => date('Y-m-d H:i:s'), 'ip' => $ip, 'user_id_wd' => $current_user->ID), array('%d', '%s', '%s', '%d', '%s', '%s', '%d'));
                 if (!$save_or_no) {
                     return false;
                 }
                 $str = '';
                 if ($form->checkout_mode == "production") {
                     $str .= "https://www.paypal.com/cgi-bin/webscr?";
                 } else {
                     $str .= "https://www.sandbox.paypal.com/cgi-bin/webscr?";
                 }
                 $str .= "currency_code=" . $currency;
                 $str .= "&business=" . urlencode($business);
                 $str .= "&cmd=" . "_cart";
                 $str .= "&notify_url=" . admin_url('admin-ajax.php?action=checkpaypal%26form_id=' . $id . '%26group_id=' . ($max + 1));
                 $str .= "&upload=" . "1";
                 $str .= "&charset=UTF-8";
                 if (isset($paypal['shipping'])) {
                     $str = $str . "&shipping_1=" . $paypal['shipping'];
                     //	$str=$str."&weight_cart=".$paypal['shipping'];
                     //	$str=$str."&shipping2=3".$paypal['shipping'];
                     $str = $str . "&no_shipping=2";
                 }
                 $i = 0;
                 foreach ($paypal['item_name'] as $pkey => $pitem_name) {
                     if ($paypal['amount'][$pkey]) {
                         $i++;
                         $str = $str . "&item_name_" . $i . "=" . urlencode($pitem_name);
                         $str = $str . "&amount_" . $i . "=" . $paypal['amount'][$pkey];
                         $str = $str . "&quantity_" . $i . "=" . $paypal['quantity'][$pkey];
                         if ($tax) {
                             $str = $str . "&tax_rate_" . $i . "=" . $tax;
                         }
                         if ($paypal['on_os'][$pkey]) {
                             foreach ($paypal['on_os'][$pkey]['on'] as $on_os_key => $on_item_name) {
                                 $str = $str . "&on" . $on_os_key . "_" . $i . "=" . $on_item_name;
                                 $str = $str . "&os" . $on_os_key . "_" . $i . "=" . $paypal['on_os'][$pkey]['os'][$on_os_key];
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($chgnac) {
         global $wpdb;
         if ($form->submit_text_type != 4) {
             $_SESSION['massage_after_submit' . $id] = addslashes(addslashes(__('Nothing was submitted.', 'form_maker')));
         }
         $_SESSION['error_or_no' . $id] = 1;
         $_SESSION['form_submit_type' . $id] = $form->submit_text_type . "," . $form->id;
         wp_redirect($_SERVER["REQUEST_URI"]);
         exit;
     }
     return array($all_files, $str);
 }
 @($keyost_defaulthelptopicsetting = $_REQUEST['keyost_defaulthelptopicsetting']);
 @($keyost_contactfilestatus = $_REQUEST['keyost_contactfilestatus'] == "on" ? '1' : '0');
 $config = array('host' => $host, 'database' => $database, 'username' => $username, 'password' => $password, 'keyost_prefix' => $keyost_prefix, 'keyost_version' => $keyost_version, 'keyost_usercloseticket' => $keyost_usercloseticket, 'supportpage' => $supportpage, 'contactticketpage' => $contactticketpage, 'thankyoupage' => $thankyoupage, 'googlesecretkey' => $googlesecretkey, 'googlesitekey' => $googlesitekey, 'keyost_departmentsetting' => $keyost_departmentsetting, 'keyost_defaultdepartmentsetting' => $keyost_defaultdepartmentsetting, 'keyost_helptopicsetting' => $keyost_helptopicsetting, 'keyost_defaulthelptopicsetting' => $keyost_defaulthelptopicsetting, 'keyost_contactfilestatus' => $keyost_contactfilestatus);
 if ($_REQUEST['host'] == "" || $_REQUEST['database'] == "" || $_REQUEST['username'] == "" || $_REQUEST['supportpage'] == "") {
     echo '<div id="failed"><b>' . __("Error:", 'key4ce-osticket-bridge') . '</b>' . __("All fields are required below for the database...", 'key4ce-osticket-bridge') . '</div><div style="clear: both"></div>';
 } else {
     $current_user = wp_get_current_user();
     global $wpdb;
     $osticketpagecheck = $wpdb->get_var("SELECT count(*) as no FROM {$wpdb->posts} WHERE post_content='[addosticket]' AND post_status='publish'");
     if ($osticketpagecheck == 0) {
         wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $current_user->ID, 'post_name' => $supportpage, 'post_title' => $supportpage, 'post_content' => '[addosticket]', 'post_status' => 'publish', 'post_type' => 'page'));
     }
     $contactticketpagecheck = $wpdb->get_var("SELECT count(*) as no FROM {$wpdb->posts} WHERE `post_content` LIKE '%[addoscontact]%' AND post_status='publish'");
     if ($contactticketpagecheck <= 0) {
         wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $current_user->ID, 'post_name' => get_the_title($contactticketpage), 'post_title' => get_the_title($contactticketpage), 'post_content' => '[addoscontact]', 'post_status' => 'publish', 'post_type' => 'page'));
     }
     update_option('os_ticket_config', $config);
     $config = get_option('os_ticket_config');
     extract($config);
     $ost_wpdb = new wpdb($username, $password, $database, $host);
     $ticket_cdata = $keyost_prefix . 'ticket__cdata';
     $crt_cdata = "CREATE TABLE IF NOT EXISTS {$ticket_cdata} (\r            `ticket_id` int(11) unsigned NOT NULL DEFAULT '0',\r            `subject` mediumtext,\r            `priority` mediumtext,\r            PRIMARY KEY (`ticket_id`)\r            ) ENGINE=InnoDB DEFAULT CHARSET=utf8";
     $ost_wpdb->query($crt_cdata);
     global $ost;
     $ticket_cdata = $keyost_prefix . "ticket__cdata";
     $osinstall = "osTicket Installed!";
     $osticid = 1;
     $prior = 2;
     $result1 = $ost_wpdb->get_results("SELECT ticket_id FROM {$ticket_cdata} WHERE subject = '" . $osinstall . "'");
     if (count($result1) > 0) {
         $row = current($result1);
 /**
  * Check if there are any registered relations for the source blog.
  *
  * @param  int $source_blog_id
  * @return boolean
  */
 private function has_related_blogs($source_blog_id)
 {
     $sql = "SELECT `ml_id` FROM {$this->link_table} WHERE `ml_blogid` = {$source_blog_id} LIMIT 2";
     return 2 == $this->wpdb->query($sql);
 }
Example #30
0
 public function remove_active_payment($sub_id, $level_order, $stamp)
 {
     $subscription = Membership_Plugin::factory()->get_subscription($sub_id);
     $level = $subscription->get_level_at_position($level_order);
     return $this->_wpdb->query(sprintf("DELETE FROM %s WHERE member_id = %d AND sub_id = %d AND level_id = %d AND level_order = %d AND paymentmade = %d", MEMBERSHIP_TABLE_MEMBER_PAYMENTS, $this->ID, $sub_id, $level->id, $level_order, $stamp));
 }