MP_AbandonedFieldsTemplate

Class MP_AbondenedFieldsTemplate


Source Source

File: mortgage-platform/Inc/MP_AbandonedFieldsTemplate.php

class MP_AbandonedFieldsTemplate {

	/**
	 * Get forms and display them.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @param array $forms forms
	 *
	 * @return string
	 */
	public function get_forms( $forms ) {
		$pages = array();

		foreach ( $forms as $form ) {
			$pages[]['page']                      = $form;
			$pages[ count( $pages ) - 1 ]['stat'] = '';
		}

		$js_content = '';
		foreach ( $pages as $item ) {
			if ( isset( $item['page'] ) && ! ( empty( $item['page'] ) ) ) {

				$data_info = $this->get_form_data( $item['page'] );

				if ( '' === $data_info['info'] ) {
					echo "<br><p style='font-weight: bold;'>" . esc_html__( 'No forms are listed. Notice: forms will not appear until after they have been loaded at least once.', 'mortgage_platform' ) . '</p>';
					return;
				}
				if ( 0 === $this->get_form_count_valid_fields( $data_info['reject_fields'] ) ) {
					continue;
				}
				if ( 'adminbarsearch' === $item['page'] ) {
					continue;
				}

				$form_data   = $this->get_form_data( $item['page'] );
				$form_key    = $form_data['detail'][0];
				$js_content .= $this->create_replace_content( $form_key . '__frm' );
				$name        = $item['page'];
				if ( ! empty( $form_data['detail'][3] ) ) {
					$name = $form_data['detail'][3];
				}

				echo '<li class="clearfix">
	                    <div class="tab_infos">
	                        <b><span class="btn_all"  style="cursor:pointer;margin-right:20px;float:left;" " onClick="javascript:jQuery(\'#sub_info_' . esc_attr( $item['page'] ) . '\').toggleClass(\'active closed\');">+</span><p style="float:left;" id="' . esc_attr( $form_key ) . '__frm">
	                        ' . esc_attr( $name ) . '</p><span style="margin-left:10px;font-size:10px;color:blue;"><a href="' . esc_attr( $form_data['detail'][6] ) . '">' . esc_attr( $form_data['detail'][6] ) . '</a></span></b>
	                        <span>' . esc_attr( $item['stat'] ) . '</span>
	                         <div id="sub_info_' . esc_attr( $item['page'] ) . '" class="closed"><br><br>';

				$data = $this->get_form_data( $item['page'] );

				$view_count   = $data['stats'][2];
				$edit_count   = $data['stats'][1];
				$submit_count = $data['stats'][0];

				$reject_count = $edit_count - $submit_count;
				$all_data     = $edit_count + $submit_count;

				$edit_proz         = floor( ( 100 * $edit_count ) / $view_count );
				$unused_proz       = 0;
				$submit_proz_total = 0;
				$submit_proz       = 0;
				$not_submit_proz   = 0;
				$reject_proz       = 0;
				if ( 0 !== $edit_count ) {
					$submit_proz       = floor( ( 100 * $submit_count ) / $edit_count );
					$unused_proz       = 100 - $edit_proz;
					$submit_proz_total = floor( ( 100 * $submit_count ) / $view_count );
					$not_submit_proz   = 100 - $submit_proz;
					$reject_proz       = floor( ( 100 * $reject_count ) / $edit_count );}

					$this->get_template( $view_count, $unused_proz, $edit_proz, $edit_count, $not_submit_proz, $submit_proz, $submit_count, $submit_proz_total, $form_key );

				foreach ( $data['reject_fields'] as $itemx ) {

					if ( '' === $itemx[0] ) {
						continue;
					}
					$length = 0;
					if ( 0 !== $reject_count ) {
						$length = ( 493 * $itemx[1] ) / $reject_count;
					}
					$val = 0 !== $itemx[1] ? $itemx[1] : '';
					$txt = '' !== $itemx[2] ? $itemx[2] : $itemx[0];
					if ( 493 === $length ) {
						$val = '';
					}

					$js_content .= $this->create_replace_content( $form_key . '__frm__' . $itemx[0] . '__ctrl' );

					echo '<tr>
                            <td width="200"  style="vertical-align: middle;">
                                <span class="tab_info"><p id="' . esc_attr( $form_key ) . '__frm__' . esc_attr( $itemx[0] ) . '__ctrl">' . esc_attr( $txt ) . '</p></span>
                            </td>
                            <td>
                                <div style="width:500px;height:26px;border:1px solid #d4d4ca;margin:3px;">
                                    <div class="inp_bar" style="width:' . esc_attr( $length ) . 'px;float:left;">
                                    </div><p class="behind_bar"> ' . esc_attr( $val ) . '</p>
                                </div>
                            </td>
                        </tr>';
				}
				echo '</table></td></tr></table>';
				echo '</div></div><div class="tab_btn"></div></li>';
			}
		}
		$js_value = 'jQuery(document).ready(function($){' . PHP_EOL . "\t" . $js_content . PHP_EOL . ' });';

		return $js_value;

	}


	/**
	 * Get data from form.
	 *
	 * @param string $name name
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return array
	 */
	public function get_form_data( $name ) {
		$data                  = array();
		$data['reject_fields'] = get_option( MortgagePlatform::$prefix . $name . '_reject' );
		$data['info']          = get_option( MortgagePlatform::$prefix . $name . '_info' );
		$data['stats']         = get_option( MortgagePlatform::$prefix . $name . '_stats' );
		$data['detail']        = get_option( MortgagePlatform::$prefix . $name . '_detail' );

		return $data;
	}


	/**
	 * Get count valid fields of form.
	 *
	 * @param object $data form data
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return int
	 */
	public function get_form_count_valid_fields( $data ) {
		if ( 0 === count( $data ) ) {
			return 0;
		}

		$val = 0;
		foreach ( $data as $field ) {
			if ( '' !== $field[0] ) {
				$val = 1;
			}
		}

		return $val;
	}


	/**
	 * Create replace content script.
	 *
	 * @param string $data data
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string
	 */
	public function create_replace_content( $data ) {
		$nonce   = wp_create_nonce( MortgagePlatform::$prefix . 'abandoned_fields' );
		$content = '$("#' . $data . '").editInPlace({
        url: ajaxurl,
        action: "ajax_change_abandoned_fields",
        abandonednonce: "' . $nonce . '",
        params: "key="+(this).name,
        show_buttons: true,
        value_required: true,
        success: function(data){
        console.log(data);

        }
    });' . PHP_EOL . "\t";

		return $content;
	}


	/**
	 * Get template report of form.
	 *
	 * @param int $view_count view count
	 * @param int $unused_proz unused proz
	 * @param int $edit_proz edit proz
	 * @param int $edit_count edit count
	 * @param int $not_submit_proz not submit proz
	 * @param int $submit_proz submit proz
	 * @param int $submit_count submin count
	 * @param int $submit_proz_total submit proz total
	 *
	 * @since 1.0.0
	 * @access public
	 */
	public function get_template( $view_count, $unused_proz, $edit_proz, $edit_count, $not_submit_proz, $submit_proz, $submit_count, $submit_proz_total ) {
		?>
			<table style="border:5px solid #eaeae2;width:100%;padding:5px;">
				<tr style=" width:940px; height:30px;background-color: #eaeae2;">
					<td>
						<span class="tab_header_big" style="margin-left:20px;margin-top:20px;"><?php esc_html_e( 'Stats', 'mortgage_platform' ); ?></span>
					</td>
					<td>
						<span class="tab_header_big" style="margin-left:20px;margin-top:20px;"><?php esc_html_e( 'Rejected fields', 'mortgage_platform' ); ?></span>
					</td>
				</tr>
				<tr style="width:940px;">
					<td style="width:250px;vertical-align: top;padding:5px;background: rgb(249,249,249); /* Old browsers */
					background: -moz-linear-gradient(top, rgba(249,249,249,1) 0%, rgba(249,249,249,1) 50%, rgba(229,229,229,1) 100%); /* FF3.6+ */
					background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(249,249,249,1)), color-stop(50%,rgba(249,249,249,1)), color-stop(100%,rgba(229,229,229,1))); /* Chrome,Safari4+ */
					background: -webkit-linear-gradient(top, rgba(249,249,249,1) 0%,rgba(249,249,249,1) 50%,rgba(229,229,229,1) 100%); /* Chrome10+,Safari5.1+ */
					background: -o-linear-gradient(top, rgba(249,249,249,1) 0%,rgba(249,249,249,1) 50%,rgba(229,229,229,1) 100%); /* Opera 11.10+ */
					background: -ms-linear-gradient(top, rgba(249,249,249,1) 0%,rgba(249,249,249,1) 50%,rgba(229,229,229,1) 100%); /* IE10+ */
					background: linear-gradient(to bottom, rgba(249,249,249,1) 0%,rgba(249,249,249,1) 50%,rgba(229,229,229,1) 100%); /* W3C */
					filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f9f9f9', endColorstr='#e5e5e5',GradientType=0 ); /* IE6-9 */">
						<table>
							<tr>
								<td>
									<table style="width:250px;">
										<tr>
											<td colspan="2" style="text-align: center;">
												<table>
													<tr>
														<td style="width:170px;text-align: center;vertical-align: middle;">
															<div class="view_box"><?php echo esc_attr( $view_count ); ?> <?php esc_html_e( 'Visitors', 'mortgage_platform' ); ?></div>
														</td>
														<td style="vertical-align: top;text-align: left">
															<span style="font-weight:bold;color:red;"><?php echo esc_attr( $unused_proz ) . ' %'; ?></span>
															<?php esc_html_e( 'left the page without editing.', 'mortgage_platform' ); ?>
														</td>
													</tr>
													<tr>
														<td style="padding-left: 80px;vertical-align: top;text-align: left;">
															<?php esc_html_e( 'Form used:', 'mortgage_platform' ); ?>
														</td>
														<td style="vertical-align: top;text-align: left;">
															<span style="font-weight:bold;color:green;"><?php echo esc_attr( $edit_proz ) . ' %'; ?></span><br>
														</td>
													</tr>
													<tr>
														<td colspan="2">&nbsp;</td>
													</tr>
													<tr>
														<td style="width:170px;text-align: center;vertical-align: middle;">
															<div class="view_box_small"><?php echo esc_attr( $edit_count ); ?> <?php esc_html_e( 'Editors', 'mortgage_platform' ); ?></div>
														</td>
														<td style="vertical-align: top;text-align: left">
															<span style="font-weight:bold;color:red;"><?php echo esc_attr( $not_submit_proz ) . ' %'; ?></span>
															<?php esc_html_e( 'do not submit the form', 'mortgage_platform' ); ?>
														</td>
													</tr>
													<tr>
														<td style="padding-left: 80px;vertical-align: top;text-align: left;">
															<?php esc_html_e( 'Form submitted:', 'mortgage_platform' ); ?>
														</td>
														<td style="vertical-align: top;text-align: left;">
															<span style="font-weight:bold;color:green;"><?php echo esc_attr( $submit_proz ) . ' %'; ?></span><br>
														</td>
													</tr>
													<tr>
														<td colspan="2">&nbsp;</td>
													</tr>
													<tr>
														<td style="width:170px;text-align: center;vertical-align: middle;">
															<div class="view_box_green"> <?php echo esc_attr( $submit_count ); ?> <?php esc_html_e( 'Submitter', 'mortgage_platform' ); ?></div>
														</td>
														<td style="vertical-align: top;text-align: left">

														</td>
													</tr>
													<tr>
														<td style="padding-left: 100px;vertical-align: top;text-align: left;">
															&nbsp;
														</td>
														<td style="vertical-align: top;text-align: left;">

														</td>
													</tr>
													<tr>
														<td style="vertical-align: top;text-align: center;">
															<span style="color:#168611;font-size:26px;font-weight:bold;"><?php echo esc_attr( $submit_proz_total ) . ' %'; ?></span>
														</td>
														<td style="vertical-align: top;text-align: left;">
															<?php esc_html_e( 'Specifies how many visitors have submitted the form.', 'mortgage_platform' ); ?>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</td>
							</tr>
						</table>
					</td>
					<td style="background-color: #fdfdfd;border-left:1px solid #dcdcdc; vertical-align: top;">
							<table style="text-align:left;margin-top:20px;margin-left:30px;margin-right:40px;margin-bottom:20px;">
		<?php
	}


	/**
	 * Get Reject.
	 *
	 * @param string $name name
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return mixed|void
	 */
	public function get_form_reject( $name ) {
		$item = get_option( MortgagePlatform::$prefix . $name . '_reject' );
		return $item;
	}


	/**
	 * Set Reject.
	 *
	 * @param array $value value
	 * @param string $name name
	 *
	 * @since 1.0.0
	 * @access public
	 */
	public function set_form_reject( $value, $name ) {
		update_option( MortgagePlatform::$prefix . $name . '_reject', $value );
	}


	/**
	 * Change Control Name.
	 *
	 * @param string $form form
	 * @param string $field field
	 * @param string $title title
	 *
	 * @since 1.0.0
	 * @access public
	 */
	public function change_control_name( $form, $field, $title ) {

		$fields = $this->get_form_reject( $form );
		$index  = 0;
		foreach ( $fields as $value ) {
			if ( $value[0] === $field ) {
				$fields[ $index ][2] = $title;
				break;
			}
			$index++;
		}

		$this->set_form_reject( $fields, $form );
	}


	/**
	 * Get Detail.
	 *
	 * @param string $name name
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return mixed|void
	 */
	public function get_form_info( $name ) {
		$item = get_option( MortgagePlatform::$prefix . $name . '_detail' );
		return $item;
	}


	/**
	 * Set Detail.
	 *
	 * @param string $value value
	 * @param string $name name
	 *
	 * @since 1.0.0
	 * @access public
	 */
	public function set_form_info( $value, $name ) {
		update_option( MortgagePlatform::$prefix . $name . '_detail', $value );
	}


	/**
	 * Change Title Form.
	 *
	 * @param string $form form
	 * @param string $title title
	 *
	 * @since 1.0.0
	 * @access public
	 */
	public function change_form_title( $form, $title ) {

		$fields    = $this->get_form_info( $form );
		$fields[3] = $title;

		$this->set_form_info( $fields, $form );
	}

}

Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.