public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/builder/recordsform.php
/**
		 * Method called when form details are being saved to a normal table.
		 *
		 * @param Array $formValues The list of details being saved.
		 *
		 * @return Integer The ID of the newly saved record, or false if something went wrong.
		 */
Method called when form details are being saved to a normal table.
@param Array $formValues The list of details being saved.

@return Integer The ID of the newly saved record, or false if something went wrong.
Method called when form details are being saved to a normal table . @param Array $formValues The list of details being saved . @return Integer The ID of the newly saved record or false if something went wrong .
protected function handleSaveMainDetails( $formValues ) {
			if ( ! $this->primaryKey || ! $this->tableName ) {
				$this->messages = $this->showMessage( 'handleSave(): Nothing could be saved, as the table name and primary key details are invalid.', true );
				return false;
			}
			global $wpdb;
			$wpdb->show_errors();
						$this->alreadyExists = false;
						$this->primaryKeyValue = $this->formObj->getArrayValue( $formValues, $this->primaryKey );
			if ( $this->primaryKeyValue ) {
				$details = getRecordDetails( $this->tableName, $this->primaryKey, $this->primaryKeyValue );
				if ( ! empty( $details ) ) {
					$this->alreadyExists = true;
				}
			}
			if ( $this->alreadyExists ) {
				$SQL = arrayToSQLUpdate( $this->tableName, $formValues, $this->primaryKey );
				$wpdb->query( $SQL );
				$this->messages = $this->showMessage( $this->msg_record_updated );
				$this->recordDetails = getRecordDetails( $this->tableName, $this->primaryKey, $this->primaryKeyValue, ARRAY_A );
				if ( $this->fn_record_updated && function_exists( $this->fn_record_updated ) ) {
					call_user_func( $this->fn_record_updated, $this->recordDetails );
				}
				return $this->primaryKeyValue;
			} else {
				unset( $formValues[ $this->primaryKey ] );
				$SQL = arrayToSQLInsert( $this->tableName, $formValues );
				$wpdb->query( $SQL );
				$this->primaryKeyValue = $wpdb->insert_id;
				$this->messages = $this->showMessage( $this->msg_record_created );
				$this->recordDetails = getRecordDetails( $this->tableName, $this->primaryKey, $this->primaryKeyValue, ARRAY_A );
				$this->formObj->setDefaultValues( $this->recordDetails );
				if ( $this->fn_record_created && function_exists( $this->fn_record_created ) ) {
					call_user_func( $this->fn_record_created, $this->recordDetails );
				}
				return $this->primaryKeyValue;
			}
		}
protected function handleSaveMainDetails ( $ formValues ) { if ( ! $ this -> primaryKey || ! $ this -> tableName ) { $ this -> messages = $ this -> showMessage ( 'handleSave(): Nothing could be saved, as the table name and primary key details are invalid.' , true ) ; return false ; } global $ wpdb ; $ wpdb -> show_errors ( ) ; $ this -> alreadyExists = false ; $ this -> primaryKeyValue = $ this -> formObj -> getArrayValue ( $ formValues , $ this -> primaryKey ) ; if ( $ this -> primaryKeyValue ) { $ details = getRecordDetails ( $ this -> tableName , $ this -> primaryKey , $ this -> primaryKeyValue ) ; if ( ! empty ( $ details ) ) { $ this -> alreadyExists = true ; } } if ( $ this -> alreadyExists ) { $ SQL = arrayToSQLUpdate ( $ this -> tableName , $ formValues , $ this -> primaryKey ) ; $ wpdb -> query ( $ SQL ) ; $ this -> messages = $ this -> showMessage ( $ this -> msg_record_updated ) ; $ this -> recordDetails = getRecordDetails ( $ this -> tableName , $ this -> primaryKey , $ this -> primaryKeyValue , ARRAY_A ) ; if ( $ this -> fn_record_updated && function_exists ( $ this -> fn_record_updated ) ) { call_user_func ( $ this -> fn_record_updated , $ this -> recordDetails ) ; } return $ this -> primaryKeyValue ; } else { unset ( $ formValues [ $ this -> primaryKey ] ) ; $ SQL = arrayToSQLInsert ( $ this -> tableName , $ formValues ) ; $ wpdb -> query ( $ SQL ) ; $ this -> primaryKeyValue = $ wpdb -> insert_id ; $ this -> messages = $ this -> showMessage ( $ this -> msg_record_created ) ; $ this -> recordDetails = getRecordDetails ( $ this -> tableName , $ this -> primaryKey , $ this -> primaryKeyValue , ARRAY_A ) ; $ this -> formObj -> setDefaultValues ( $ this -> recordDetails ) ; if ( $ this -> fn_record_created && function_exists ( $ this -> fn_record_created ) ) { call_user_func ( $ this -> fn_record_created , $ this -> recordDetails ) ; } return $ this -> primaryKeyValue ; } }
Method called when form details are being saved to a normal table.
Method called when form details are being saved to a normal table .
// Have we already got this entry in the database?
 // Check #1 - See if we've got a primary key for it?
 // Check #2 - See if the record exists already // Record already exists, so updated it... // Update the locally stored details // Function called when record has been updated. // ID of existign record // Ensure that primary key is not set when creating a new one, to ensure non-dup // of IDs // Create new record... // ...then get the newly inserted ID so that we can update, without inserting again. // DJH 2013-12-03 - Moved to below //$this->formObj->setDefaultValues(array($this->primaryKey => $this->primaryKeyValue)); // Update the locally stored details // DJH 2013-12-03 - Added to use the stored details in the form. // Function called when record has been created. // Newly inserted ID.