1 Replies - 3665 Views - Last Post: 16 June 2010 - 03:35 AM

#1 xmodz   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 38
  • Joined: 07-March 10

Integrating jQuery into PHP class output

Posted 16 June 2010 - 12:37 AM

Hi guys, I'm very new to jQuery but i really wish i could understand it too. Anyway after looking at the cool effects that jQuery could give i decided to try and put up a notification bar plugin (jNotify) from jQuery site so that everytime the visitor has done using my simulation app the status bar would appear displaying a PHP generated message from the class i constructed.

here's my code for the interface:
<?php

if(isset($_POST['count'])){
	if($_POST['count'] == 1){
	
	$sesId = $class->getId();
	$userIp = $class->getIp();
	$userName = $class->getUser();
	$modType = $_POST['type'];
	$sesExp = time()+604800;
	$timeStamp = time();		
	
	$sqlSd = "INSERT INTO tb_tracker VALUES(NULL, '$sesId', '$userIp', '$modType', '$sesExp', CURRENT_TIMESTAMP)";
	$rsSd = mysql_query($sqlSd);	
	if($rsSd){
		}
		
	$sqlUd = "INSERT INTO tb_track_user VALUES(NULL, '$sesId', '$userIp', '$userName', $timeStamp)";
	$rsUd = mysql_query($sqlUd);	
	if($rsUd){
		}
?>
<div id="Notification">
    </div>
    <div id="StatusBar" style="height: 20px;">
    </div>
<script type="text/javascript">
        $(document).ready(function() {
            $('#StatusBar').jnotifyInitialize({
                oneAtTime: true
                });
            $('#addStatusBarMessage').click(function() {
                $('#StatusBar').jnotifyAddMessage({
                    text: '<?php $class->doLogic(); ?>',
                    permanent: false,
                    showIcon: false
                });
            });
        });
</script>
         </div>
    </div>
<?php 
	}
} 
?>


and this is for the PHP class code:
<?php
		$modifier = ($dataKred >= ($dataDep - 1) && $dataKred <= ($dataDep + 1));
		
		if(($dataDep < $dataKred) && ($dataDep == 0)){
			$this->kreditLogic();
			}
			elseif(($dataDep < $dataKred) && !$modifier){
				$this->kreditLogic();
				}
		if(($dataKred < $dataDep) && ($dataKred == 0)){
			$this->depositLogic();
			}
			elseif(($dataKred < $dataDep) && !$modifier){
				$this->depositLogic();
				}
		if(isset($dataDep)){
			if($dataDep != 0){
				if(isset($dataKred)){
					if($dataKred != 0){
						if ($dataKred >= ($dataDep - 1) && $dataKred <= ($dataDep + 1)){
							$this->b2bLogic();							
						}
					}
				}
			}
		}
	}

//core kredit logic processor	
	function kreditLogic(){

		$amount = $_POST['txtAmount'];
		$trim = array(",", ".00");
		$amount = str_replace($trim, "", $amount);
		
		switch($amount){
		
			case $amount <= 2000000:
			$msg = "A";
			echo $msg;
			break;
		
			case $amount <= 5000000:
			$msg = "B";
			echo $msg;
			break;
	
			case $amount <= 10000000:
			$msg = "C";
			echo $msg;
			break;
				
			case $amount <= 50000000:
			$msg = "D";
			echo $msg;
			break;
		
			case $amount <= 100000000:
			$msg = "E";
			echo $msg;
			break;
			
			default:
			break;
		}
	}
	
//core b2b kredit logic processor	
	function b2bLogic(){

		$amount = $_POST['txtAmount'];
		$trim = array(",", ".00");
		$amount = str_replace($trim, "", $amount);
		
		switch($amount){
		
			case $amount <= 2000000:
			$msg = "F";
			echo $msg;
			break;
		
			case $amount <= 5000000:
			$msg = "G";
			echo $msg;
			break;
	
			case $amount <= 10000000:
			$msg = "H";
			echo $msg;
			break;
				
			case $amount <= 50000000:
			$msg = "I";
			echo $msg;
			break;
		
			case $amount <= 100000000:
			$msg = "J";
			echo $msg;
			break;
			
			default:
			break;
		}
	}
//core deposito logic processor	
	function depositLogic(){

		$amount = $_POST['txtAmount'];
		$trim = array(",", ".00");
		$amount = str_replace($trim, "", $amount);
		
		switch($amount){
		
			case $amount <= 2000000:
			$msg = "K";
			echo $msg;
			break;
		
			case $amount <= 5000000:
			$msg = "L";
			echo $msg;
			break;
	
			case $amount <= 10000000:
			$msg = "M";
			echo $msg;
			break;
				
			case $amount <= 50000000:
			$msg = "N";
			echo $msg;
			break;
		
			case $amount <= 100000000:
			$msg = "O";
			echo $msg;
			break;
			
			default:
			break;
		}
	}
}
?>


and here's the jQuery Engine code

(function(jQuery) {
    jQuery.fn.jnotifyInitialize = function(options) {
        var element = this;

        var defaults = {
            oneAtTime: false,
            appendType: 'append'
        };

        var options = jQuery.extend({}, defaults, options);

        this.addClass('notify-wrapper');

        if (options.oneAtTime)
            this.addClass('notify-wrapper-oneattime');

        if (options.appendType == 'prepend' && options.oneAtTime == false)
            this.addClass('notify-wrapper-prepend');

        return this;
    };
    jQuery.fn.jnotifyAddMessage = function(options) {

        var notifyWrapper = this;

        if (notifyWrapper.hasClass('notify-wrapper')) {

            var defaults = {
                text: '',
                type: 'message',
                showIcon: true,
                permanent: false,
                disappearTime: 5000
            };

            var options = jQuery.extend({}, defaults, options);
            var styleClass;
            var iconClass;

            switch (options.type) {
                case 'message':
                    {
                        styleClass = 'ui-state-highlight';
                        iconClass = 'ui-icon-info';
                    }
                    break;
                case 'error':
                    {
                        styleClass = 'ui-state-error';
                        iconClass = 'ui-icon-alert';
                    }
                    break;
                default:
                    {
                        styleClass = 'ui-state-highlight';
                        iconClass = 'ui-icon-info';
                    }
                    break;
            }

            if (notifyWrapper.hasClass('notify-wrapper-oneattime')) {
                this.children().remove();
            }

            var notifyItemWrapper = jQuery('<div class="jnotify-item-wrapper"></div>');
            var notifyItem = jQuery('<div class="ui-corner-all jnotify-item"></div>')
                                    .addClass(styleClass);

            if (notifyWrapper.hasClass('notify-wrapper-prepend'))
                notifyItem.prependTo(notifyWrapper);
            else
                notifyItem.appendTo(notifyWrapper);

            notifyItem.wrap(notifyItemWrapper);

            if (options.showIcon)
                jQuery('<span class="ui-icon" style="float:left; margin-right: .3em;" />')
                                    .addClass(iconClass)
                                    .appendTo(notifyItem);

            jQuery('<span></span>').html(options.text).appendTo(notifyItem);
            jQuery('<div class="jnotify-item-close"><span class="ui-icon ui-icon-circle-close"/></div>')
                                    .prependTo(notifyItem)
                                    .click(function() { remove(notifyItem) });

            // IEsucks
            if (navigator.userAgent.match(/MSIE (\d+\.\d+);/)) {
                notifyWrapper.css({ top: document.documentElement.scrollTop });
                //http://groups.google.com/group/jquery-dev/browse_thread/thread/ba38e6474e3e9a41
                notifyWrapper.removeClass('IEsucks');
            }
            // ------

            if (!options.permanent) {
                setTimeout(function() { remove(notifyItem); }, options.disappearTime);
            }
        }

        function remove(obj) {
            obj.animate({ opacity: '0' }, 600, function() {
                obj.parent().animate({ height: '0px' }, 300,
                      function() {
                          obj.parent().remove();
                          // IEsucks
                          if (navigator.userAgent.match(/MSIE (\d+\.\d+);/)) {
                              //http://groups.google.com/group/jquery-dev/browse_thread/thread/ba38e6474e3e9a41
                              obj.parent().parent().removeClass('IEsucks');
                          }
                          // -------
                      });
            });
        }
    };
})(jQuery);


I have the feeling that the jQuery works fine however the status bar only appeared like less than a second when actually it was sposed to stick around for 5 seconds. I hope someone can shed some light into this. thanks in advance for looking at my prob. :helpsmilie:

Is This A Good Question/Topic? 0
  • +

Replies To: Integrating jQuery into PHP class output

#2 xmodz   User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 38
  • Joined: 07-March 10

Re: Integrating jQuery into PHP class output

Posted 16 June 2010 - 03:35 AM

Problem solved...

well after 4 hours of tinkering at last i've found the solution, it was to change the event trigger from .click(function() to .ready(function()

:look:

This post has been edited by xmodz: 16 June 2010 - 03:36 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1