update() public method

wpdb::update( 'table', array( 'column' => 'foo', 'field' => 'bar' ), array( 'ID' => 1 ) ) wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) )
See also: wpdb::prepare()
See also: wpdb::$field_types
See also: wp_set_wpdb_vars()
Since: 2.5.0
public update ( string $table, array $data, array $where, array | string $format = null, array | string $where_format = null ) : integer | false
$table string table name
$data array Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
$where array A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
$format array | string Optional. An array of formats to be mapped to each of the values in $data. If string, that format will be used for all of the values in $data. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
$where_format array | string Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings.
return integer | false The number of rows updated, or false on error.
Example #1
0
 /**
  * Update taxonomy meta
  *
  * @param int $term_id
  * @param string $key
  * @param mixed $value
  * @return int
  */
 public function update($term_id, $key, $value)
 {
     $old_value = $this->get($term_id, $key);
     if ($old_value === false) {
         return $this->_add($term_id, $key, $value);
     }
     if ($old_value === $value) {
         return true;
     }
     wp_cache_set($this->_get_cache_key($term_id, $key), $value, 'taxonomy-meta');
     return $this->_db->update($this->_table, ['meta_value' => maybe_serialize($value)], ['term_id' => $term_id, 'meta_key' => $key]);
 }
Example #2
0
 /**
  * Saves a ruleset to database.
  *
  * @param array $rulesetData The data to save.
  * @param int $rulesetId Primary key of ruleset if it already exists.
  * @return bool|int Id of saved rule on success or false on error.
  */
 public function saveRuleset($rulesetData, $rulesetId = 0)
 {
     if (empty($rulesetData)) {
         return false;
     }
     if (!empty($rulesetId)) {
         $updateResult = $this->wpdb->update($this->wpdb->rulesets, $rulesetData, array('id' => $rulesetId), array('%s', '%d', '%s', '%d', '%d', '%s', '%s', '%d', '%s'), array('%d'));
         return $updateResult === false ? false : $rulesetId;
     } else {
         $this->wpdb->insert($this->wpdb->rulesets, $rulesetData, array('%s', '%d', '%s', '%d', '%d', '%s', '%s', '%d', '%s'));
         $rulesetId = $this->wpdb->insert_id;
         return empty($rulesetId) ? false : $rulesetId;
     }
 }
Example #3
0
 public function move_subscription($fromsub_id, $tosub_id, $tolevel_id, $to_order)
 {
     if (!apply_filters('pre_membership_move_subscription', true, $fromsub_id, $tosub_id, $tolevel_id, $to_order, $this->ID)) {
         return false;
     }
     membership_debug_log(sprintf(__('MEMBER: Moving subscription from %d to %d', 'membership'), $fromsub_id, $tosub_id));
     $factory = Membership_Plugin::factory();
     // Check if existing level matches new one but it is a serial or indefinite level
     $subscription = $factory->get_subscription($tosub_id);
     $nextlevel = $subscription->get_next_level($tolevel_id, $to_order);
     if (!$this->on_level($tolevel_id, true, $to_order) || $this->on_level($tolevel_id, true, $to_order) && ($nextlevel->sub_type == 'serial' || $nextlevel->sub_type == 'indefinite') && $this->on_sub($fromsub_id)) {
         membership_debug_log(sprintf(__('MEMBER: New level to move to %d on order %d', 'membership'), $tolevel_id, $to_order));
         // Get the level for this subscription before removing it
         $fromlevel_id = $this->get_level_for_sub($fromsub_id);
         // grab the level information for this position
         $subscription = $factory->get_subscription($tosub_id);
         $level = $subscription->get_level_at($tolevel_id, $to_order);
         if ($level) {
             $period = 'days';
             $now = current_time('mysql');
             $start = strtotime($now);
             switch ($level->level_period_unit) {
                 case 'd':
                     $period = 'days';
                     break;
                 case 'w':
                     $period = 'weeks';
                     break;
                 case 'm':
                     $period = 'months';
                     break;
                 case 'y':
                     $period = 'years';
                     break;
             }
             //subscription start and end date
             $start_sub = $tosub_id == $fromsub_id ? get_user_meta($this->ID, 'start_current_' . $fromsub_id, true) : $start;
             $expires_sub = $this->get_subscription_expire_date($subscription, $tolevel_id, $fromsub_id, $fromlevel_id);
             //level end date
             $expires = gmdate('Y-m-d H:i:s', strtotime('+' . $level->level_period . ' ' . $period, $start));
             // Update users start and expiry meta
             delete_user_meta($this->ID, 'start_current_' . $fromsub_id);
             delete_user_meta($this->ID, 'expire_current_' . $fromsub_id);
             delete_user_meta($this->ID, 'sent_msgs_' . $fromsub_id);
             // get the gateway and then remove it from the usermeta
             $gateway = get_user_meta($this->ID, 'using_gateway_' . $fromsub_id, true);
             delete_user_meta($this->ID, 'using_gateway_' . $fromsub_id);
             update_user_meta($this->ID, 'start_current_' . $tosub_id, $start_sub);
             update_user_meta($this->ID, 'expire_current_' . $tosub_id, $expires_sub);
             update_user_meta($this->ID, 'using_gateway_' . $tosub_id, $gateway);
             $this->_wpdb->update(MEMBERSHIP_TABLE_RELATIONS, array('sub_id' => $tosub_id, 'level_id' => $tolevel_id, 'updateddate' => $now, 'expirydate' => $expires, 'order_instance' => $level->level_order), array('sub_id' => $fromsub_id, 'user_id' => $this->ID));
             // Update the associated role
             $this->set_role(Membership_Model_Level::get_associated_role($level->level_id));
             membership_debug_log(sprintf(__('MEMBER: Completed move to %d on order %d on sub %d', 'membership'), $tolevel_id, $to_order, $tosub_id));
             do_action('membership_move_subscription', $fromsub_id, $fromlevel_id, $tosub_id, $tolevel_id, $to_order, $this->ID);
         }
     } else {
         membership_debug_log(sprintf(__('MEMBER: Already on level %d on order %d', 'membership'), $tolevel_id, $to_order));
     }
 }
 /**
  * Update the data for a particular form.
  *
  * @author Jeremy Pry
  *
  * @param int   $form_id The form ID to update.
  * @param array $data    The form data to update.
  *
  * @return bool Whether the form was successfully updated.
  */
 public function update_form($form_id, $data)
 {
     // Prepare the data for the database.
     $data['id'] = $form_id;
     $save_data = $this->prepare_data_for_db($data);
     $formats = $this->get_format_array($save_data);
     return (bool) $this->wpdb->update($this->prefixed_table_name, $save_data, array('id' => $form_id), $formats, '%d');
 }
Example #5
0
 /**
  * Records transaction into database.
  *
  * @access protected
  * @param type $user_id
  * @param type $sub_id
  * @param type $amount
  * @param type $currency
  * @param type $timestamp
  * @param type $paypal_ID
  * @param type $status
  * @param type $note
  */
 protected function _record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $paypal_ID, $status, $note)
 {
     $data = array('transaction_subscription_ID' => $sub_id, 'transaction_user_ID' => $user_id, 'transaction_paypal_ID' => $paypal_ID, 'transaction_stamp' => $timestamp, 'transaction_currency' => $currency, 'transaction_status' => $status, 'transaction_total_amount' => (int) round($amount * 100), 'transaction_note' => $note, 'transaction_gateway' => $this->gateway);
     $existing_id = $this->db->get_var($this->db->prepare("SELECT transaction_ID FROM " . MEMBERSHIP_TABLE_SUBSCRIPTION_TRANSACTION . " WHERE transaction_paypal_ID = %s LIMIT 1", $paypal_ID));
     if (!empty($existing_id)) {
         $this->db->update(MEMBERSHIP_TABLE_SUBSCRIPTION_TRANSACTION, $data, array('transaction_ID' => $existing_id));
     } else {
         $this->db->insert(MEMBERSHIP_TABLE_SUBSCRIPTION_TRANSACTION, $data);
     }
 }
Example #6
0
 function update()
 {
     $this->dirty = true;
     if ($this->id < 0) {
         $this->add();
     } else {
         $this->db->update(MEMBERSHIP_TABLE_SUBSCRIPTIONS, array('sub_name' => trim(filter_input(INPUT_POST, 'sub_name')), 'sub_description' => trim(filter_input(INPUT_POST, 'sub_description')), 'sub_pricetext' => trim(filter_input(INPUT_POST, 'sub_pricetext')), 'order_num' => filter_input(INPUT_POST, 'sub_order_num', FILTER_VALIDATE_INT)), array('id' => $this->id), array('%s', '%s', '%s', '%d'), array('%d'));
         // Remove the existing rules for this subscription level
         $this->db->delete(MEMBERSHIP_TABLE_SUBSCRIPTION_LEVELS, array('sub_id' => $this->id), array('%d'));
         if (!empty($_POST['level-order'])) {
             $levels = explode(',', $_POST['level-order']);
             $count = 1;
             foreach ((array) $levels as $level) {
                 if (!empty($level)) {
                     // Check if the rule has any information for it.
                     if (isset($_POST['levelmode'][$level])) {
                         $levelmode = esc_attr($_POST['levelmode'][$level]);
                     } else {
                         continue;
                     }
                     if (isset($_POST['levelperiod'][$level])) {
                         $levelperiod = esc_attr($_POST['levelperiod'][$level]);
                     } else {
                         $levelperiod = '';
                     }
                     if (isset($_POST['levelperiodunit'][$level])) {
                         $levelperiodunit = esc_attr($_POST['levelperiodunit'][$level]);
                     } else {
                         $levelperiodunit = '';
                     }
                     if (isset($_POST['levelprice'][$level])) {
                         $levelprice = floatval(esc_attr($_POST['levelprice'][$level]));
                     } else {
                         $levelprice = '';
                     }
                     if (isset($_POST['levelcurrency'][$level])) {
                         $levelcurrency = esc_attr($_POST['levelcurrency'][$level]);
                     } else {
                         $levelcurrency = '';
                     }
                     // Calculate the level id
                     $lev = explode('-', $level);
                     if ($lev[0] == 'level') {
                         $level_id = (int) $lev[1];
                         // write it to the database
                         $this->db->insert(MEMBERSHIP_TABLE_SUBSCRIPTION_LEVELS, array("sub_id" => $this->id, "level_period" => $levelperiod, "sub_type" => $levelmode, "level_price" => $levelprice, "level_currency" => $levelcurrency, "level_order" => $count++, "level_id" => $level_id, "level_period_unit" => $levelperiodunit));
                     }
                 }
             }
         }
         do_action('membership_subscription_update', $this->id);
     }
     return true;
     // for now
 }
 /**
  * Attach upload to a post.
  *
  * @since 2.1.0
  *
  * @param int $post_ID Post ID.
  * @param string $post_content Post Content for attachment.
  */
 public function attach_uploads($post_ID, $post_content)
 {
     // find any unattached files
     $attachments = $this->db->get_results("SELECT ID, guid FROM {$this->db->posts} WHERE post_parent = '0' AND post_type = 'attachment'");
     if (is_array($attachments)) {
         foreach ($attachments as $file) {
             if (!empty($file->guid) && strpos($post_content, $file->guid) !== false) {
                 $this->db->update($this->db->posts, array('post_parent' => $post_ID), array('ID' => $file->ID));
             }
         }
     }
 }
 /**
  * Upgrades all the existing forms in the database to include the new fields and settings offered by the latest plugin version.
  *
  * @param array $default_fields An array containing the default form fields and their settings.
  * @param array $default_settings An array containing the default form settings.
  * @param array $default_emails An array containing the default emails.
  * @param array $default_custom_field An array containing the default custom field settings.
  * @param array $post_type The post type for which we want to upgrade the forms.
  **/
 public function upgrade_forms($default_fields, $default_settings, $default_emails, $default_custom_field, $post_type)
 {
     $forms = $this->get_forms(1, 1000, $post_type);
     if (is_array($forms) && count($forms)) {
         foreach ($forms as $key => $form) {
             $form_fields = $this->unserialize($form['fields']);
             $form_settings = $this->unserialize($form['settings']);
             $form_emails = $this->unserialize($form['emails']);
             $upgraded_fields = wpfepp_update_form_fields($form_fields, $default_fields, $default_custom_field);
             $upgraded_settings = wpfepp_update_array($form_settings, $default_settings);
             $upgraded_emails = wpfepp_update_array($form_emails, $default_emails);
             $this->db->update($this->table_name, array('fields' => $this->serialize($upgraded_fields), 'settings' => $this->serialize($upgraded_settings), 'emails' => $this->serialize($upgraded_emails)), array('id' => $form['id']));
         }
     }
 }
 function update()
 {
     switch ($_POST['periodtype']) {
         case 'd':
             $time = strtotime('+' . $_POST['periodunit'] . ' days') - time();
             break;
         case 'm':
             $time = strtotime('+' . $_POST['periodunit'] . ' months') - time();
             break;
         case 'y':
             $time = strtotime('+' . $_POST['periodunit'] . ' years') - time();
             break;
     }
     $periodstamp = $_POST['periodprepost'] == 'pre' ? -$time : $time;
     if ('join' == $_POST['periodprepost'] || 'exp' == $_POST['periodprepost']) {
         $periodstamp = 0;
     }
     $updates = array("periodunit" => $_POST['periodunit'], "periodtype" => $_POST['periodtype'], "periodprepost" => $_POST['periodprepost'], "subject" => $_POST['subject'], "message" => stripslashes($_POST['message']), "periodstamp" => $periodstamp, "sub_id" => $_POST['subscription_id']);
     return $this->db->update(MEMBERSHIP_TABLE_COMMUNICATIONS, $updates, array("id" => $this->id));
 }
Example #10
0
 /**
  * Saves data into the database.
  *
  * @since 2.0.0
  *
  * @param array $data The data to insert into database.
  *
  * @return bool
  * @throws Exception
  */
 public function save($data)
 {
     $time = current_time('mysql');
     // Only save leads if the user has the option checked.
     $option = get_option('optin_monster');
     if (!isset($option['leads']) || isset($option['leads']) && !$option['leads']) {
         throw new Exception(__('The user has chosen not to store leads locally.', 'optin-monster'));
     }
     // Make sure the required fieds exist in the passed data array.
     foreach ($this->required_fields as $key => $value) {
         if (!array_key_exists($value, $data)) {
             throw new Exception(sprintf(__('A value for %s must be passed in the $data array.', 'optin-monster'), $value));
         }
     }
     // Ensure that the lead does not already exist in the DB.
     $exists = $this->find_where('lead_email', $data['lead_email']);
     if (!empty($exists)) {
         throw new Exception(__('The lead already exists in the database.', 'optin-monster'));
     }
     // Add the date modified to the data array
     $data['date_modified'] = $time;
     // If an 'id' is passed, we're going to update the record, else insert.
     if (isset($data['id'])) {
         $id = $data['id'];
         unset($data['id']);
         if (false == $this->db->update($this->table, $data, array('lead_id', $id))) {
             throw new Exception(__('There was an error updating the lead.', 'optin-monster'));
         } else {
             return true;
         }
     } else {
         // This is a new record, so we'll insert the date added.
         $data['date_added'] = $time;
         if (false == $this->db->insert($this->table, $data)) {
             throw new Exception(__('There was an error inserting the lead.', 'optin-monster'));
         } else {
             return true;
         }
     }
 }
 /**
  * Load the localization
  *
  * @since 0.1
  * @uses load_plugin_textdomain, plugin_basename
  * @param Mlp_Db_Schema_Interface $languages
  * @return void
  */
 private function import_active_languages(Mlp_Db_Schema_Interface $languages)
 {
     // get active languages
     $mlp_settings = get_site_option('inpsyde_multilingual');
     if (empty($mlp_settings)) {
         return;
     }
     $table = $languages->get_table_name();
     $sql = 'SELECT ID FROM ' . $table . 'WHERE wp_locale = %s OR iso_639_1 = %s';
     foreach ($mlp_settings as $mlp_site) {
         $text = $mlp_site['text'] != '' ? $mlp_site['text'] : $mlp_site['lang'];
         $query = $this->wpdb->prepare($sql, $mlp_site['lang'], $mlp_site['lang']);
         $lang_id = $this->wpdb->get_var($query);
         // language not found -> insert
         if (empty($lang_id)) {
             // @todo add custom name
             $this->wpdb->insert($table, array('english_name' => $text, 'wp_locale' => $mlp_site['lang'], 'http_name' => str_replace('_', '-', $mlp_site['lang'])));
         } else {
             $this->wpdb->update($table, array('priority' => 10), array('ID' => $lang_id));
         }
     }
 }
 /**
  * Delete duplicate database entries.
  *
  * @param array  $relations Content relations
  * @param string $type      Content type.
  *
  * @return int
  */
 private function clean_up_duplicated_translation_ids(array $relations, $type)
 {
     $result = (int) $this->wpdb->update($this->link_table, array('ml_source_blogid' => $relations[0]['ml_source_blogid'], 'ml_source_elementid' => $relations[0]['ml_source_elementid']), array('ml_source_blogid' => $relations[1]['ml_source_blogid'], 'ml_source_elementid' => $relations[1]['ml_source_elementid'], 'ml_type' => $type), array('%d', '%d'), array('%d', '%d', '%s'));
     do_action('mlp_debug', current_filter() . '/' . __METHOD__ . '/' . __LINE__ . " - {$this->wpdb->last_query}");
     return $result;
 }
function cron_statusUpdate($lead_id, $status, $message)
{
    $wpdb = new wpdb('tpocom_dash', 'w2P!9A-Si0', 'tpocom_dash', 'localhost');
    $table_name = TemplateData::get_tpl_docs_table_name();
    $values = array("cron_status" => $status, "cron_desc" => $message);
    $return = $wpdb->update($table_name, $values, array("lead_id" => $lead_id), array("%d", "%s"), array("%d"));
    return true;
}
    		$meta->area[2] != $r->post_area3 , 
    		$meta->area[3] != $r->post_area4 , 
    		$meta->you[0] != $r->post_you1 , 
    		$meta->you[1] != $r->post_you2 , 
    		$meta->you[2] != $r->post_you3 , 
    		$meta->you[3] != $r->post_you4 , 
    		$meta->tannichi != $r->post_tannichi , 
    		$meta->rank != $r->post_rank , 
    		$is_event_days
    	);
    */
    //カスタムフィールドの値をwp_postsに登録する(検索でINTERNAL ERRORが出ており、SQLを高速化するため)
    //DBの情報と違う場合にはアップデートを行う
    if ($is_today != $r->is_today || $is_now_month != $r->is_now_month || !$meta->tannichi && $meta->event_start != $r->post_event_start && (!empty($meta->event_start) || !empty($r->post_event_start)) || !$meta->tannichi && $meta->event_end != $r->post_event_end && (!empty($meta->event_end) || !empty($r->post_event_end)) || $meta->category != $r->post_category || $meta->theme[0] != $r->post_theme1 || $meta->theme[1] != $r->post_theme2 || $meta->theme[2] != $r->post_theme3 || $meta->theme[3] != $r->post_theme4 || $meta->theme[4] != $r->post_theme5 || $meta->area[0] != $r->post_area1 || $meta->area[1] != $r->post_area2 || $meta->area[2] != $r->post_area3 || $meta->area[3] != $r->post_area4 || $meta->you[0] != $r->post_you1 || $meta->you[1] != $r->post_you2 || $meta->you[2] != $r->post_you3 || $meta->you[3] != $r->post_you4 || $meta->tannichi != $r->post_tannichi || $meta->rank != $r->post_rank || $is_event_days) {
        //UPDATE
        $update_result = $db->update('wp_posts', array('is_today' => $is_today, 'is_now_month' => $is_now_month, 'post_event_start' => event_value_between($meta->event_start, $meta->tannichi), 'post_event_end' => event_value_between($meta->event_end, $meta->tannichi), 'post_event_day1' => event_value_tannichi($meta_tannichi_days[0], $meta->tannichi), 'post_event_day2' => event_value_tannichi($meta_tannichi_days[1], $meta->tannichi), 'post_event_day3' => event_value_tannichi($meta_tannichi_days[2], $meta->tannichi), 'post_event_day4' => event_value_tannichi($meta_tannichi_days[3], $meta->tannichi), 'post_event_day5' => event_value_tannichi($meta_tannichi_days[4], $meta->tannichi), 'post_category' => $meta->category, 'post_theme1' => $meta->theme[0], 'post_theme2' => $meta->theme[1], 'post_theme3' => $meta->theme[2], 'post_theme4' => $meta->theme[3], 'post_theme5' => $meta->theme[4], 'post_area1' => $meta->area[0], 'post_area2' => $meta->area[1], 'post_area3' => $meta->area[2], 'post_area4' => $meta->area[3], 'post_you1' => $meta->you[0], 'post_you2' => $meta->you[1], 'post_you3' => $meta->you[2], 'post_you4' => $meta->you[3], 'post_tannichi' => $meta->tannichi, 'post_rank' => $meta->rank), array('ID' => $r->ID));
    }
}
if (defined('SAVEQUERIES')) {
    //var_dump($db->queries);
}
function event_value_between($value, $tannnichi = false)
{
    if ($tannnichi) {
        return 0;
    }
    return $value;
}
function event_value_tannichi($value, $tannnichi = false)
{
    if (!$tannnichi) {
 /**
  * Update the admin email option.
  *
  * We cannot use update_option(), because that would trigger a
  * confirmation email to the new address.
  *
  * @param  string $admin_email
  * @return void
  */
 private function update_admin_email($admin_email)
 {
     $this->wpdb->update($this->wpdb->options, array('option_value' => $admin_email), array('option_name' => 'admin_email'));
 }
Example #16
0
 /**
  * Update a row in the table
  *
  * @see wpdb::update()
  */
 public function updateRow($data, $where, $format = null, $where_format = null)
 {
     return $this->db->update($this->schema->table_name, $data, $where, $format, $where_format);
 }
Example #17
0
<h2>Manually Edit Users</h2>
<p>Just in case you need to manually edit or add users</p>

<?php 
require_once SC_USER_DIR . "/library/sc_user_misc.class.php";
$misc = new sc_user_misc();
$scdb = new wpdb(DB_USER, DB_PASSWORD, "uolttorg_sc_data", DB_HOST);
if ($misc->get_post("save") == "Update User") {
    $scdb->update('lttname', array('sc1' => $misc->get_post("sc1"), 'forum' => $misc->get_post("forum"), 'sc2' => $misc->get_post("sc2"), 'rank' => $misc->get_post("rank"), 'role' => $misc->get_post("role"), 'member' => $misc->get_post("member")), array('nameUID' => $misc->get_post("nameUID")));
    // push to RucDoc
    $userdata = array('sc1' => $misc->get_post("sc1"), 'forum' => $misc->get_post("forum"), 'sc2' => $misc->get_post("sc2"), 'rank' => $misc->get_post("rank"), 'role' => $misc->get_post("role"), 'member' => $misc->get_post("member"));
    $url = "http://insanemaths.com/api/api.php?action=update_user&user_id=" . $misc->get_post("nameUID") . "&data=" . str_replace(" ", "+", json_encode($userdata));
    file_get_contents($url);
    // update ship info
    $add = array();
    $remove = array();
    $current = $misc->get_user_ships($misc->get_post('nameUID'));
    for ($i = 0; $i < sizeof($_POST['ships']); $i++) {
        if (!in_array($_POST['ships'][$i], $current)) {
            $add[] = $_POST['ships'][$i];
        }
    }
    for ($i = 0; $i < sizeof($current); $i++) {
        if (!in_array($current[$i], $_POST['ships'])) {
            $remove[] = $current[$i];
        }
    }
    $misc->update_user_ships($misc->get_post('nameUID'), $add, $remove);
}
?>
Example #18
0
/**
* Diese Funktion holt alle Quiz-Ergebnisse aller User. 
* Danach werden alle, die bestanden haben, aber nicht 100% erreicht haben, auf 100% gesetzt, inkl. der richtigen Antworten
* (die on-thy-fly aus der DB geholt werden)
* @author GW
* Die Fremdfunktion WPCW_quizzes_getAllQuizzesForCourse($course_value) wird benutzt, sie gehört zu Courseware 
*/
function erase_progress()
{
    $strk = "";
    $strk = "<h2>Alle bestandenen Quiz-Ergebnisse auf 100% ändern</h2>";
    require_once '../wp-config.php';
    include_once '../wp-content/plugins/wp-courseware/lib/common.inc.php';
    include_once '../wp-content/plugins/wp-courseware/lib/constants.inc.php';
    include_once '../wp-content/plugins/wp-courseware/lib/email_defaults.inc.php';
    if (!defined('ABSPATH')) {
        define('ABSPATH', dirname(__FILE__) . '/');
    }
    $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    // "Richtige" Tabelle mit der Backup-Tabelle überschreiben, wenn Haken gesetzt
    if ($_REQUEST['restore_backup'] == 1) {
        require_once '../wp-admin/includes/upgrade.php';
        $sql = "DROP TABLE wp13_wpcw_user_progress_quizzes";
        $wpdb->query($sql);
        $sql = "CREATE TABLE wp13_wpcw_user_progress_quizzes LIKE wp13_wpcw_user_progress_quizzes_backup";
        $wpdb->query($sql);
        $sql = "INSERT INTO wp13_wpcw_user_progress_quizzes SELECT * FROM wp13_wpcw_user_progress_quizzes_backup";
        $wpdb->query($sql);
        echo "wp13_wpcw_user_progress_quizzes_backup aus Backup wiederhergestellt";
    }
    $strk .= "<form name=\"form1\" method=\"post\" action=\"" . $_SERVER['REQUEST_URI'] . "\">";
    $str .= "<p>1.) Welche Courses gibt es?</p>";
    //$strk .= "<p>1.) Welche Courses gibt es?</p>";
    $courses = $wpdb->get_col("\n\t            SELECT * \n\t            FROM wp13_wpcw_courses\n\t            ORDER BY course_id;\n\t        ");
    foreach ($courses as $course_key => $course_value) {
        $str .= "Course " . $course_value . "<br>";
    }
    $str .= "<p>2.) Alle Courses durchgehe und seine Quizze holen</p>";
    //$strk .= "<p>2.) Alle Courses durchgehe und seine Quizze holen</p>";
    foreach ($courses as $course_key => $course_value) {
        $str .= "<h3>Course " . $course_value . "</h3>";
        $str .= "<table class = \"quiz\">";
        $str .= "<tr class=\"quiz\"><td class=\"separator_course\" class=\"quiz\">Start Course " . $course_value . "</td></tr>";
        $quizzes = WPCW_quizzes_getAllQuizzesForCourse($course_value);
        $fez1 = 0;
        foreach ($quizzes as $quiz_key => $quiz_value) {
            $fez1++;
            $str .= "<tr><td class=\"separator_quiz\">Start Quiz ID " . $quiz_value->quiz_id . "</td></tr>";
            $str .= "<tr><td class=\"separator_quiz\" colspan=2 style=\"font-weight: bold;\">" . $fez1 . ".) Quiz ID: " . $quiz_value->quiz_id . " - " . $quiz_value->quiz_title . "</td></tr>";
            $str .= "<tr><td class=\"separator_quiz\" colspan=2>QuizPassMark: " . $quiz_value->quiz_pass_mark . "</td></tr>";
            $str .= "<tr><td>  </td></tr>";
            $quizIDListForSQL = "(" . $quiz_value->quiz_id . ")";
            $sql = "SELECT * \n\t                FROM wp13_wpcw_user_progress_quizzes\n\t                WHERE user_id = " . $userID . " \n\t                AND quiz_id = " . $quiz_value->quiz_id . " \n\t                ORDER BY quiz_completed_date;\n\t                ";
            $sql = "SELECT * \n\t                FROM wp13_wpcw_user_progress_quizzes\n\t                WHERE quiz_id = " . $quiz_value->quiz_id . " \n\t                ORDER BY quiz_completed_date;\n\t                ";
            //$str .= $sql;
            $results = $wpdb->get_results($sql);
            //echo "<pre>";var_dump($results);echo "</pre>";
            $str .= "<tr><td><table><tr><td>Results for: ";
            if ($results == NULL) {
                $str .= "keine</td></tr></table></td></tr>";
            } else {
                $str .= "<tr><td><table><tr><td>";
                $fez2 = 0;
                foreach ($results as $result_key => $result_value) {
                    $update = "";
                    $fez2++;
                    $strk .= "Kurs " . $course_value . " - Quiz " . $quiz_value->quiz_id . " - User " . $result_value->user_id;
                    //var_dump($result_value);
                    $str .= "<tr><td><br></td></tr>";
                    $str .= "<tr><td class=\"separator_attempt\">Start User " . $result_value->user_id . " Attempt " . $result_value->quiz_attempt_id . "</td></tr>";
                    $strk .= " - Attempt " . $result_value->quiz_attempt_id;
                    $str .= "<tr><td class=\"separator_attempt\" colspan=2 style=\"font-weight: bold;\">" . $fez2 . ".) Attempt on : " . $result_value->quiz_completed_date . " - " . $quiz_value->quiz_title . "</td></tr>";
                    $str .= "<tr><td class=\"separator_attempt\" colspan=2>Grade: " . $result_value->quiz_grade . "</td></tr>";
                    $str .= "<tr><td>  </td></tr>";
                    //$str .= "Data: ".$result_value->quiz_data."<br>";
                    $data_seri = $result_value->quiz_data;
                    $data_unseri = unserialize($data_seri);
                    $strk .= " - Braucht " . $quiz_value->quiz_pass_mark . " % - Hat: " . $result_value->quiz_grade . "% ";
                    if ($result_value->quiz_grade == 100) {
                        $str .= "<tr><td style=\"background: #aca;\">Bestanden mit 100%  - keine Änderung nötig-> Braucht " . $quiz_value->quiz_pass_mark . " % - Hat erreicht: " . $result_value->quiz_grade . "%</td></tr>";
                        $strk .= "<span style=\"background: #aca;\">Bestanden mit 100% - keine Änderung nötig</span>";
                    } elseif ($result_value->quiz_grade >= $quiz_value->quiz_pass_mark) {
                        $str .= "<tr><td style=\"background: #caa;\">Bestanden, aber nicht mit 100% - Änderung nötig -> Braucht " . $quiz_value->quiz_pass_mark . " % - Hat erreicht: " . $result_value->quiz_grade . "%</td></tr>";
                        $strk .= "<span style=\"background: #caa;\">Bestanden, aber nicht mit 100% - Änderung nötig</span>";
                        // Jetzt Änderung
                        foreach ($data_unseri as $data_unseri_key => $data_unseri_value) {
                            //$str .= "data_unseri_value ". $data_unseri_key . " - " . $data_unseri_value . "<br>";
                            //$str .= "<pre>";var_dump($data_unseri_key); $str .= "</pre>";
                            $str .= "<tr><td style=\"background: #eee;\">their_answer: " . $data_unseri[$data_unseri_key]["their_answer"] . " - correct: " . $data_unseri[$data_unseri_key]["correct"];
                            if ($data_unseri[$data_unseri_key]["their_answer"] != $data_unseri[$data_unseri_key]["correct"]) {
                                $str .= " <span style=\"background:red; color:white;\">FALSCH. Also kopieren</span> ";
                                $data_unseri[$data_unseri_key]["their_answer"] = $data_unseri[$data_unseri_key]["correct"];
                                $str .= "their_answer: " . $data_unseri[$data_unseri_key]["their_answer"] . " - correct: " . $data_unseri[$data_unseri_key]["correct"];
                                $str .= "<br>";
                                /*
                                $sql = "SELECT question_data_answers
                                        FROM wp13_wpcw_quizzes_questions
                                        WHERE question_id = ".$data_unseri_key;     
                                
                                        $str .= $sql;
                                
                                $tar_result = $wpdb->get_results($sql);
                                $tar_result = $tar_result[0];
                                //$tar_result = unserialize($tar_result[0]);
                                $tar_result = $tar_result->question_data_answers;
                                $tar_result = unserialize($tar_result);
                                foreach ($tar_result AS $tar_result_key => $tar_result_value)   
                                    {
                                    $tar_result_value = $tar_result_value["answer"];
                                    $tar_result_value = md5($tar_result_value);
                                    echo "<pre>";var_dump ($tar_result_value);echo "</pre>";
                                    }
                                */
                                $sql = "SELECT question_correct_answer\n\t                                        FROM wp13_wpcw_quizzes_questions\n\t                                        WHERE question_id = " . $data_unseri_key;
                                $qca_result = $wpdb->get_row($sql);
                                //$qca_result = $qca_result[0];
                                //$qca_result = unserialize($qca_result[0]);
                                //$qca_result = $qca_result->question_data_answers;
                                //$qca_result = unserialize($qca_result);
                                //echo "<pre>";var_dump ($qca_result);echo "</pre>";
                                /*
                                foreach ($tar_result AS $qca_result_key => $qca_result_value)   
                                    {
                                    $qca_result_value = $qca_result_value["answer"];
                                    $qca_result_value = md5($qca_result_value);
                                    echo "<pre>";var_dump ($qca_result_value);echo "</pre>";
                                    }
                                */
                                //$str .= $sql;
                                $data_unseri[$data_unseri_key]["question_correct_answer"] = $qca_result->question_correct_answer;
                                $str .= "question_correct_answer: " . $data_unseri[$data_unseri_key]["question_correct_answer"] . " - correct: " . $qca_result->question_correct_answer;
                                $str .= "<br>";
                                $data_unseri[$data_unseri_key]["got_right"] = "yes";
                                $str .= "got_right: " . $data_unseri[$data_unseri_key]["got_right"];
                                $echo_reseri = 1;
                                $data_reseri = serialize($data_unseri);
                                // Hier jetzt Schreibvorgang in DB
                                // Herkömmliches UPDATE:
                                $update = "UPDATE wp13_wpcw_user_progress_quizzes SET \n\t                                           quiz_data = '" . $data_reseri . "',\n\t                                           quiz_correct_questions = " . $result_value->quiz_question_total . ", \n\t                                           quiz_grade = 100.00 \n\t                                           WHERE quiz_id = " . $quiz_value->quiz_id . "  \n\t                                           AND user_id = " . $result_value->user_id . " \n\t                                           AND quiz_attempt_id = " . $result_value->quiz_attempt_id;
                                $update_action = 0;
                                if ($_POST['cleanup_now'] == "yes" && $_REQUEST['restore_backup'] != 1) {
                                    //$strk .= "<br><tr><td>".$update."</td></tr>";
                                    $wpdb->update('wp13_wpcw_user_progress_quizzes', array('quiz_data' => $data_reseri, 'quiz_correct_questions' => $result_value->quiz_question_total, 'quiz_grade' => '100.00'), array('quiz_id' => $quiz_value->quiz_id, 'user_id' => $result_value->user_id, 'quiz_attempt_id' => $result_value->quiz_attempt_id));
                                    // quiz_completion_time_seconds = 0 ??? notwendig?
                                    $update_action = 1;
                                }
                                // Ende Schreibvorgang
                            } else {
                                $str .= " <span style=\"background:green; color:white;\">RICHTIG</span>.";
                                $echo_reseri = 0;
                                $data_reseri = serialize($data_unseri);
                            }
                            $str .= "</td></tr>";
                        }
                        // Ende Änderung
                        if ($update_action == 1) {
                            $strk .= " <span style=\"background: #f5c34c;\">OK, geändert</span>";
                        }
                    } else {
                        $str .= "<tr><td style=\"background: #aca;\">Nicht bestanden - keine Änderung nötig. Braucht " . $quiz_value->quiz_pass_mark . " % - Hat erreicht: " . $result_value->quiz_grade . "%</td></tr>";
                        $strk .= "<span style=\"background: #aca;\">Nicht bestanden - keine Änderung nötig</span>";
                    }
                    $str .= "<tr><td> </td></tr>";
                    //if ($echo_reseri==1) $str .= "<tr><td>".$data_reseri."</td></tr>";
                    $strk .= "<br>";
                    $str .= "<tr><td class=\"separator_attempt\">Ende User " . $result_value->user_id . " Attempt " . $fez2 . "</td></tr>";
                }
                $str .= "</td></tr></table></td></tr>";
            }
            $str .= "<tr><td class=\"separator_quiz\">Ende Quiz ID " . $course_value . "</td></tr><tr><td><br></td></tr>";
        }
        $str .= "<tr><td class=\"separator_course\">Ende Course " . $course_value . "</td></tr>";
        // Ende Course
        $str .= "</table><br>";
    }
    $strk .= "<input type=\"hidden\" id=\"cleanup_now\" name=\"cleanup_now\" value=\"yes\" />";
    $strk .= "<input type=\"checkbox\" id=\"restore_backup\" name=\"restore_backup\" value=\"1\" />Backup wiederherstellen (zum Testen)";
    $strk .= "<input type=\"submit\" value=\"Jetzt bereinigen\" />";
    $strk .= "<input name=\"action\" value=\"insert\" type=\"hidden\" />";
    $strk .= "</form>";
    echo $strk . "<br><br>";
    //echo $str;
}
 $title_name = $_POST['title_name'];
 //SMTP Setting Changes Post Variables Start Here Added By Pratik Maniar
 $smtp_status = $_POST['smtp_status'];
 $smtp_username = $_POST['smtp_username'];
 $smtp_password = $_POST['smtp_password'];
 $smtp_host = $_POST['smtp_host'];
 $smtp_port = $_POST['smtp_port'];
 //SMTP Setting Changes Post Variables End Here Added By Pratik Maniar
 $max_open_tickets = $_POST['max_open_tickets'];
 $reply_sep = $_POST['reply_sep'];
 $hidename = @$_POST['hidename'];
 $os_admin_email = @$_POST['admin_email'];
 $admin_fname = @$_POST['admin_fname'];
 $admin_lname = @$_POST['admin_lname'];
 $adfullname = @$_POST['adname'];
 $ost_wpdb->update($config_table, array('value' => $online), array('id' => $id_isonline), array('%d'));
 $ost_wpdb->update($config_table, array('value' => $title_name), array('id' => $id_helptitle), array('%s'));
 //SMTP Setting Changes Query Start Here Added By Pratik Maniar
 $ost_wpdb->update($config_table, array('value' => $smtp_status), array('id' => $id_smtp_status), array('%s'));
 $ost_wpdb->update($config_table, array('value' => $smtp_username), array('id' => $id_smtp_username), array('%s'));
 $ost_wpdb->update($config_table, array('value' => $smtp_password), array('id' => $id_smtp_password), array('%s'));
 $ost_wpdb->update($config_table, array('value' => $smtp_host), array('id' => $id_smtp_host), array('%s'));
 $ost_wpdb->update($config_table, array('value' => $smtp_port), array('id' => $id_smtp_port), array('%s'));
 //SMTP Setting Changes Query End Here Added By Pratik Maniar
 $ost_wpdb->update($config_table, array('value' => $max_open_tickets), array('id' => $id_maxopen), array('%d'));
 $ost_wpdb->update($config_table, array('value' => $os_admin_email), array('id' => $id_ademail), array('%s'));
 $ost_wpdb->update($config_table, array('value' => $reply_sep), array('id' => $id_replysep), array('%s'));
 $ost_wpdb->update($config_table, array('value' => $hidename), array('id' => $id_hidename), array('%d'));
 $ost_wpdb->update($staff_table, array('firstname' => $admin_fname), array('staff_id' => 1), array('%s'));
 $ost_wpdb->update($staff_table, array('lastname' => $admin_lname), array('staff_id' => 1), array('%s'));
 $ost_wpdb->update($ost_user, array('name' => $adfullname), array('id' => 1), array('%s'));
Example #20
0
            if (empty($v)) {
                echo '<div class="error notice"><p>Please set the "' . $k . '" field!</p></div>';
                $err_c++;
            }
        }
        if ($err_c == 0) {
            $scdb->insert("ships", $_POST);
        }
    } elseif ($_POST['add_edit_ship'] != "add" && $_POST['add_edit_ship'] != "") {
        $data = array();
        foreach ($_POST as $k => $v) {
            if ($v != "" && $k != "add_edit_ship") {
                $data[$k] = $v;
            }
        }
        $scdb->update("ships", $data, array("shipname" => $_POST['add_edit_ship']));
        unset($_POST['add_edit_ship']);
    }
}
?>

<form action="" method="POST">
  <input type="button" class="button button-primary" value="Add/Edit Ship" onclick="hideAddTable()">
  <br><br>
  <table id="new_ship">
    <tr>
      <td>Add/Edit Ship:</td>
      <td>
        <select name="add_edit_ship">
          <option value="add">Add Ship</option>
          <?php 
Example #21
-1
 protected function _update()
 {
     if (($result = $this->_wpdb->update($this->_table(), $this->_fields, array($this->_pk => $this->{$this->_pk}))) === FALSE) {
         echo 'false';
         return FALSE;
     }
     return TRUE;
 }