Pages

Friday, January 21, 2011

Ul li current list notify

Ul li current list notify
--------------------------------
<ul>
    <li onclick="chgProductSize()"><span style="background-color: rgb(0, 120, 255); width: 6px; height: 6px;">&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li onclick="chgProductSize()"><span style="background-color: rgb(255, 0, 120); width: 6px; height: 6px;">&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li onclick="chgProductSize()"><span style="background-color: rgb(255, 0, 0); width: 6px; height: 6px;">&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li onclick="chgProductSize()" class="mpd_selct"><span style="background-color: rgb(255, 255, 255); width: 6px; height: 6px;">&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
    <li onclick="chgProductSize()" class="border0"><span style="background-color: rgb(0, 209, 5); width: 6px; height: 6px;">&nbsp;&nbsp;&nbsp;&nbsp;</span></li>
</ul>

js
--------

function chgProductSize()
{
    $('ul li').click( function(){
        $('.mpd_selct').removeClass('mpd_selct');
        $(this).addClass('mpd_selct');
        return false;    }
}

Tuesday, January 11, 2011

JS Validations

// JavaScript Document

// returns true if the string is empty
function isEmpty(str){
  return (str == null) || (str.length == 0);
}
// returns true if the string is a valid email
function isEmail(str){
  if(isEmpty(str)) return false;
  //var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
  var re=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  return re.test(str);
}
// returns true if the string only contains characters A-Z or a-z
function isAlpha(str){
  var re = /^(([A-Za-z])+)$/;
  return re.test(str);
  //if (re.test(str)) return false;
  //return true;
}
// returns true if the string only contains characters 0-9
function isNumeric(str){
  var re = /[\D]/g
  if (re.test(str)) return false;
  return true;
}


function isFloat( strValue ) {
    /************************************************
    DESCRIPTION: Validates that a string contains only
        valid integer number.
     PARAMETERS:
       strValue - String to be tested for validity
     RETURNS:
       True if valid, otherwise false.
    **************************************************/
      var objRegExp  = /(^\d{0,5}(\.\d{1,2})?$)|(^-?\d\d*$)/;
    //var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
        //check for integer characters
      return objRegExp.test(strValue);
    }




// returns true if the string only contains characters A-Z, a-z or 0-9
function isAlphaNumeric(str){
  var re = /[^a-zA-Z0-9]/g
  if (re.test(str)) return false;
  return true;
}
// returns true if the string's length equals "len"
function isLength(str, len){
  return str.length == len;
}
// returns true if the string's length is between "min" and "max"
function isLengthBetween(str, min, max){
  return (str.length >= min)&&(str.length <= max);
}
// returns true if the string is a US phone number formatted as...
// (000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
function isPhoneNumber(str){
  var re = /^\(?[0-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
  return re.test(str);
}
// returns true if the string is a valid date formatted as...
// mm dd yyyy, mm/dd/yyyy, mm.dd.yyyy, mm-dd-yyyy
function isDate(str){
  var re = /^(\d{1,2})[\s\.\/-](\d{1,2})[\s\.\/-](\d{4})$/
  if (!re.test(str)) return false;
  var result = str.match(re);
  var m = parseInt(result[1]);
  var d = parseInt(result[2]);
  var y = parseInt(result[3]);
  if(m < 1 || m > 12 || y < 1900 || y > 2100) return false;
  if(m == 2){
          var days = ((y % 4) == 0) ? 29 : 28;
  }else if(m == 4 || m == 6 || m == 9 || m == 11){
          var days = 30;
  }else{
          var days = 31;
  }
  return (d >= 1 && d <= days);
}
// returns true if "str1" is the same as the "str2"
function isMatch(str1, str2){
  return str1 == str2;
}
// returns true if the string contains only whitespace
// cannot check a password type input for whitespace
function isWhitespace(str){ // NOT USED IN FORM VALIDATION
  var re = /[\S]/g
  if (re.test(str)) return false;
  return true;
}
// removes any whitespace from the string and returns the result
// the value of "replacement" will be used to replace the whitespace (optional)
function stripWhitespace(str, replacement){// NOT USED IN FORM VALIDATION
  if (replacement == null) replacement = '';
  var result = str;
  var re = /\s/g
  if(str.search(re) != -1){
    result = str.replace(re, replacement);
  }
  return result;
}
function trim(text){
    return text.replace(/^\s+|\s+$/g,"");
}


// validate the form
function validateForm(f, preCheck){
  var errors = '';
  if(preCheck != null) errors += preCheck;
  var i,e,t,n,v;
  for(i=0; i < f.elements.length; i++){
    e = f.elements[i];
    if(e.optional) continue;
    t = e.type;
    n = e.name;
    v = e.value;
    if(t == 'text' || t == 'password' || t == 'textarea'){
      if(isEmpty(v)){
        errors += n+' cannot be empty.\n'; continue;
      }
      if(v == e.defaultValue){
        errors += n+' cannot use the default value.\n'; continue;
      }
      if(e.isAlpha){
        if(!isAlpha(v)){
          errors += n+' can only contain characters A-Z a-z.\n'; continue;
        }
      }
      if(e.isNumeric){
        if(!isNumeric(v)){
          errors += n+' can only contain characters 0-9.\n'; continue;
        }
      }
      if(e.isAlphaNumeric){
        if(!isAlphaNumeric(v)){
          errors += n+' can only contain characters A-Z a-z 0-9.\n'; continue;
        }
      }
      if(e.isEmail){
        if(!isEmail(v)){
          errors += v+' is not a valid email.\n'; continue;
        }
      }
      if(e.isLength != null){
        var len = e.isLength;
        if(!isLength(v,len)){
          errors += n+' must contain only '+len+' characters.\n'; continue;
        }
      }
      if(e.isLengthBetween != null){
        var min = e.isLengthBetween[0];
        var max = e.isLengthBetween[1];
        if(!isLengthBetween(v,min,max)){
          errors += n+' cannot contain less than '+min+' or more than '+max+' characters.\n'; continue;
        }
      }
      if(e.isPhoneNumber){
        if(!isPhoneNumber(v)){
          errors += v+' is not a valid US phone number.\n'; continue;
        }
      }
      if(e.isDate){
        if(!isDate(v)){
          errors += v+' is not a valid date.\n'; continue;
        }
      }
      if(e.isMatch != null){
        if(!isMatch(v, e.isMatch)){
          errors += n+' does not match.\n'; continue;
        }
      }
    }
    if(t.indexOf('select') != -1){
      if(isEmpty(e.options[e.selectedIndex].value)){
        errors += n+' needs an option selected.\n'; continue;
      }
    }
    if(t == 'file'){
      if(isEmpty(v)){
        errors += n+' needs a file to upload.\n'; continue;
      }
    }
  }
  if(errors != '') alert(errors);
  return errors == '';
}

/*
The following elements are not validated...

button   type="button"
checkbox type="checkbox"
hidden   type="hidden"
radio    type="radio"
reset    type="reset"
submit   type="submit"

All elements are assumed required and will only be validated for an
empty value or defaultValue unless specified by the following properties.

isEmail = true;          // valid email address
isAlpha = true;          // A-Z a-z characters only
isNumeric = true;        // 0-9 characters only
isAlphaNumeric = true;   // A-Z a-z 0-9 characters only
isLength = number;       // must be exact length
isLengthBetween = array; // [lowNumber, highNumber] must be between lowNumber and highNumber
isPhoneNumber = true;    // valid US phone number. See "isPhoneNumber()" comments for the formatting rules
isDate = true;           // valid date. See "isDate()" comments for the formatting rules
isMatch = string;        // must match string
optional = true;         // element will not be validated
*/

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// --------------------------------------------------
// ||||||||||||||||||||||||||||||||||||||||||||||||||

// All of the previous JavaScript is coded to process
// any form and should be kept in an external file if
// multiple forms are being processed.

// This function configures the previous
// form validation code for this form.
function configureValidation(f){
  f.firstname.isAlphaNumeric = true;
  f.lastname.isAlphaNumeric = true;
  f.email.isEmail = true;
  f.phone.isPhoneNumber = true;
  f.birthday.isDate = true;
  f.password1.isLengthBetween = [4,255];
  f.password2.isMatch = f.password1.value;
  f.comments.optional = true;
  var preCheck = (!f.infohtml.checked && !f.infocss.checked && !f.infojs.checked) ? 'select at least one checkbox.\n' : null;
  return validateForm(f, preCheck);
}

Friday, January 7, 2011

Model -Zend framework query executing

Model -Zend framework query executing
--------------------------------------------
function getpostionlist($teamid){
        $odb = Zend_Db_Table::getDefaultAdapter();
           $stmt = $odb->query("select plps_abbr,plps_sprt_id,plps_position_name from plg_player_position where plps_sprt_id=$teamid and plps_status=1");
        $rs = $stmt->fetchAll();
        $stmt->closeCursor();
        return $rs;
      }

Jquery reference-XML Data reading

Jquery reference-XML Data reading
---------------------------------------------
.js File

$.ajax({
    type : "POST",
    url     : g_site_path+"/team/check-team-name",
    data : vData,
    dataType : 'xml',
    success: function( xml ){
    
    $(xml).find('response').each(function(){

    var status = $(this).find('status').text();
        var teamurl = $(this).find('teamurl').text();


    });

       }
   });

Controller.php File
-------------------

 public function checkTeamNameAction()
     {
          $this->_helper->layout()->disableLayout();
         $this->_helper->viewRenderer->setNoRender(true);
         $oTeam = new Team();
         $fname=""; $uname="";
         $param=$this->_request->getPost();
       
            $team_name = $param['team_name'];
            $teamAvailbility =  $oTeam->getByName($team_name);
             $cnt = count($teamAvailbility);
            if ( $cnt > 0 ){
                $xml = $this->suggestteamname($team_name,$fname,$uname);
            }else{
                $xml = '<status>1</status>';
                $xml .='<teamurl>'.$team_name.'</teamurl>';
                $xml .='<teamname>'.$team_name.'</teamname>';
            }
           
           
            echo Common::showXml($xml);   
        }

Monday, January 3, 2011

Zend framework with json

How to use Json
------------

Controller
--------------------------
$return['plyrAvalFlag']=$res['plyrAval'];
$return['plyrUsrid']=$res['plyrUserid'];
$return['prntUserid']=$res['prntUserid'];

$this->_helper->json($return);

Js
-------------------------------
$.ajax({
   
    type : "POST",
    url: g_site_path+'/teamregister/teamupdateform',
    data : $('#frmTeamstepone,#frmPlayerReg,#frmParentReg,#frmParenttwoReg').serialize(),
    dataType: "json",
    success: function(data) {
                 
    $('#hidPlyrAvalFlag').val(data.plyrAvalFlag)
    $('#hidplyrUsrid').val(data.plyrUsrid)
    $('#hidprntUsrid').val(data.prntUserid)
   
    });
}

Sunday, January 2, 2011

Zend Framework-Pagination

controller
-----------------------------------------

//For pagination with result
        $result= $oFrd->getfriendslist($user_id,$friend_key);
        $page=$this->_getParam('page',1);
       
        if($this->getRequest()->getParam('pageno'))
        $page=$this->getRequest()->getParam('pageno');
       
        $paginator = Zend_Paginator::factory($result);
        $paginator->setItemCountPerPage(15);
        $paginator->setCurrentPageNumber($page);
   
        $this->view->paginator=$paginator;
         $this->view->totCount=count($result);


Views
-----------------------------------------

<?= $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml',array('type'=>'myfriends')); ?>

<div class="mygrid_add_friend" style="height: 550px;clear: both;" id="mygrid_add_friend">
            <?php       
     if($this->totCount > 0)
        {
            foreach($this->paginator as $friends_values)
            {
                 if($friends_values['Friend_Request_Flag']){   
                ?>
                <div class="mygrid_add_friend_man" style="padding:3px">
                    <?php if($friends_values['user_image']!=""): ?>
                <span class="floatl"><img height="75px" src="<? echo $this->urls()->manMedia(); ?><?=$friends_values['user_image'];?>" /></span>
                  <?php else: ?>
                 <span ><img src="<? echo $this->urls()->images(); ?>man_blue_acc.gif" /></span>
                 <?php endif; ?>
                    <b  title="<?=$friends_values['user_fname'];?>"><?=$this->cutstring($friends_values['user_fname'],12,true);?>
                     </b>
                <b  title="<?=$friends_values['user_lname'];?>"><?=$this->cutstring($friends_values['user_lname'],12,true);?>
                     </b>   
               
                    <div style="height:50px" >                       
                        <em><a href="javascript:;" onclick="removefriend(<?=$this->user_id?>,<?=$friends_values['user_id']?>)"><img src="<? echo $this->urls()->images(); ?>btn_removeFriedns.gif" alt="" border="0"/></a></em>
                                    
                    </div>
            </div>
            <?php           
              }
            }
        }
        else
        {
          echo "<p align='center'>No Friends</p>";
        }
            ?>
           
        </div>


Application/scripts/pagination.phtml
--------------------------------------------
<?php
//pagination for my friends and search
 if($this->type=='myfriends')
 {
?>
<div class="pagination" style="width:100%">
    <div style="float:left;width:28%">
    </div>
    <div style="float:right;width:auto;">
        <!-- First page link -->
        <?php if (isset($this->previous)): ?>
              <a href="javascript:;" onclick="return moveNextPage('<?=$this->first;?>')">&lt;&lt; First</a> 
        <?php else: ?>
                <span class="disabled">&lt;&lt;First</span> 
        <?php endif; ?>
   
        <!-- Previous page link -->
   
        <?php if (isset($this->previous)): ?>
              <a href="javascript:;" onclick="return moveNextPage('<?=$this->previous;?>')">&lt;&lt; Previous</a> 
        <?php else: ?>
            <span class="disabled">&lt;&lt; Previous</span> 
        <?php endif; ?>
      
        <!-- Numbered page links -->
        <?php
        $totItems  = $this->totalItemCount;
        $curentPagelastItem  = $this->currentItemCount;       
       
        if($curentPagelastItem<$this->itemCountPerPage)
        {
           $totcount = $this->itemCountPerPage * ($this->current-1);       
           $endItem = $totcount + $curentPagelastItem;
           $startItem = $totcount+1;
        }
        else
        {
            $endItem   = $this->itemCountPerPage * $this->current;           
            $startItem = ($endItem+1)-$this->itemCountPerPage;
        }
           ?>
          <span class="disabled">&nbsp;<?php echo $startItem." - ".$endItem." of ".$totItems;?>&nbsp;</span>
        <!-- Next page link -->
        <?php if (isset($this->next)): ?>
               <a href="javascript:;" onclick="return moveNextPage('<?=$this->next;?>')">Next &gt;&gt;</a> 
        <?php else: ?>
             <span class="disabled">Next  &gt;&gt; </span> 
        <?php endif; ?>
        <!-- Last page link -->
        <?php if (isset($this->next)): ?>
              <a href="javascript:;" onclick="return moveNextPage('<?=$this->last;?>')">Last&gt;&gt;</a>  &nbsp;&nbsp;
        <?php else: ?>
            <span class="disabled">Last  &gt;&gt; &nbsp;&nbsp;</span>
        <?php endif; ?>
   
    </div>
 </div>
 <?php }else if($this->type=='allfriends'){ ?>

 <div class="floatr">
  <!-- Numbered page links -->
  <?php
        $totItems  = $this->totalItemCount;
        $curentPagelastItem  = $this->currentItemCount;       
       
        if($curentPagelastItem<$this->itemCountPerPage)
        {
           $totcount = $this->itemCountPerPage * ($this->current-1);       
           $endItem = $totcount + $curentPagelastItem;
           $startItem = $totcount+1;
        }
        else
        {
            $endItem   = $this->itemCountPerPage * $this->current;           
            $startItem = ($endItem+1)-$this->itemCountPerPage;
        }
    ?>
     <span>&nbsp;<?php echo $startItem." - ".$endItem." of ".$totItems;?>&nbsp;</span>
    <div class="add_friend_arrow_a">
   
       <!-- First page link -->
        <?php if (isset($this->previous)): ?>
        <a href="javascript:;" onclick="return moveNextPage('<?=$this->previous;?>')">
        <img border="0" class="fl" src="<? echo $this->urls()->images(); ?>left_play_icon.gif"></a>
        <?php else: ?>
        <a href="javascript:;"><img border="0" class="fl" src="<? echo $this->urls()->images(); ?>left_play_icon.gif"></a>
        <?php endif; ?>
       
        <!-- Next page link -->
         <?php if (isset($this->next)): ?>
        <a href="javascript:;" onclick="return moveNextPage('<?=$this->next;?>')">
        <img border="0" class="fr" src="<? echo $this->urls()->images(); ?>right_play_icon.gif"></a>
        <?php else: ?>
        <img border="0" class="fr" src="<? echo $this->urls()->images(); ?>right_play_icon.gif"></a>
        <?php endif; ?>
    </div>
 </div>
                                 

 <?php }else if($this->type=='friends_suggestion'){ ?>
 <div class="floatr">
    <div class="add_friend_arrow_a">
   
       <!-- First page link -->
        <?php if (isset($this->previous)): ?>
        <a href="javascript:;" onclick="return moveNextPage('<?=$this->previous;?>')">
        <img border="0" class="fl" src="<? echo $this->urls()->images(); ?>left_play_icon.gif"></a>
        <?php else: ?>
        <a href="javascript:;"><img border="0" class="fl" src="<? echo $this->urls()->images(); ?>left_play_icon.gif"></a>
        <?php endif; ?>
       
        <!-- Next page link -->
         <?php if (isset($this->next)): ?>
        <a href="javascript:;" onclick="return moveNextPage('<?=$this->next;?>')">
        <img border="0" class="fr" src="<? echo $this->urls()->images(); ?>right_play_icon.gif"></a>
        <?php else: ?>
        <img border="0" class="fr" src="<? echo $this->urls()->images(); ?>right_play_icon.gif"></a>
        <?php endif; ?>
    </div>
 </div>
 <?php } ?>



Scripts->js
----------------------------------------------------------
//js funcctions for pagination
function moveNextPage(pageNo)
{
    var page=$('#page').val()
    if(page=='friends')
    {       
        friends_pagination(pageNo)
    }
    else if(page=='allfriends')
    {       
        friends_search_pagination(pageNo)
    }
    else if(page=='friends_suggestion')
    {       
        friends_sugestion_pagination(pageNo)
    }
   
}

---------------------------------------------------

function friends_pagination(pageNo)
{   
    var friend=trim(document.getElementById('friends_test').value);
    if(friend=='')
     friend="''"   
   
    if(pageNo!='')
    {
        $.ajax({
                type : "POST",
                url: g_site_path+'/account/friendslist',
                data :'friend='+friend+'&pageno='+pageNo+'&rand='+Math.random(),
                dataType: "html",
                success: function(html) {
                    $('#friends').html(html)
                }
        });
    }
}


/ajax pagination/friendslist->controller
-----------------------------------------------
//For pagination with result
        $result= $oFrd->getfriendslist($user_id,$friend_key);
        $page=$this->_getParam('page',1);
       
        if($this->getRequest()->getParam('pageno'))
        $page=$this->getRequest()->getParam('pageno');
       
        $paginator = Zend_Paginator::factory($result);
        $paginator->setItemCountPerPage(15);
        $paginator->setCurrentPageNumber($page);
       
   
        $this->view->paginator=$paginator;
         $this->view->totCount=count($result);