Tuesday, 26 August 2014

JQM Phonegap Database login , php and home page

login.html:

<!DOCTYPE html> 
<html>
<head>
<meta charset="utf-8">
<title> Mobile Web App</title>
<link href="jquery-mobile/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css"/>
<script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>

<script src="jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<link rel="stylesheet" href="css/validate.css" />
<link rel="stylesheet" href="kphome.css" />
<script type="text/javascript" src="cordova-2.6.0.js"></script>

<script type="text/javascript">    

            $(document).bind("mobileinit", function()    // script for page flickering
        {    
                $.mobile.defaultPageTransition = 'none';
                $.mobile.defaultDialogTransition = 'none';
          
        });
            
            </script> 
            
<script type="text/javascript">    
            

var url="http://192.168.1.36:9090/hrms/";


document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady()                          // device functionality
{
Dplatform=device.platform;
OSveriosn=device.version;
UUID= device.uuid;
alert('UUID'+UUID+'name'+OSveriosn+'OS'+Dplatform);
deviceinfo='OS: '+Dplatform+'Versionname: '+OSveriosn+'UUID: '+UUID;
alert(deviceinfo);
getDeviceLocation();
//alert("GEO:"+geo);


document.addEventListener("backbutton", Backbutton,false);
//msgloadingimage();
UUID=device.uuid;
//alert(UUID);
   sessionStorage.setItem('uuid',UUID);   
ApplicationVersionName="1.0";

/* if(navigator.network.connection.type==Connection.NONE || navigator.network.connection.type=="unknown" || navigator.network.connection.type==Connection.UNKNOWN)

{
        alert("Check Internet Connectivity");
       
        }
else{ */        
   
 $.ajax({
 url: url+"ANDROID_versionname.php",
 type:"POST",
 data:{"version":ApplicationVersionName}, 
 timeout: 5000,
 success: function(data) {
 if(data==10)
 {
 
 }
 else if(data==20)
 {
 alert("Please update the Current version 1.1");
 navigator.app.exitApp();  
 }
 
   },error:function(x, t, m)                      //notification API
       {   
           if(t==="timeout") {  navigator.notification.alert("Your Data connection is too slow", alertCallback,  "Alert");   } 
           
           else {  navigator.notification.alert("Check Internet Connectivity", alertCallback,  "Alert");           }
       }

}); 
       // }
 


} 


function alertCallback()
{}

 function Backbutton(){
 if($.mobile.activePage.is("#index")){
  
navigator.notification.confirm('Do you want to exit', onConfirm,'Alert');               
     } 
     
     function onConfirm(button) 
     {
      if(button==1)
      {
       //  e.preventDefault();                  
            navigator.app.exitApp();
      }
      else
      {
      }
     }
 }


function  getDeviceLocation() {                  // geolocation API
//alert('a');
        navigator.geolocation.getCurrentPosition(showPosition, showError, { enableHighAccuracy: true } );
   }

function showPosition(position) {
alert('b');
         alert("Latitude: " + position.coords.latitude + "Longitude: " + position.coords.longitude);    
 geo="Latitude: " + position.coords.latitude + "Longitude: " + position.coords.longitude;
        // geo1=geo.val();
         alert(geo);
        
 }

//5.Create a function to handle the error.

 function showError(error) {

       alert("Errorcode: "    + error.code    + 
                "Errormessage: "+ error.message );
   }
function AlertHandler()
{
       // Codes 
navigator.notification.alert('This is an alert message', AlertHandler, 'Message', 'Exit');
   }
function loginvalidate()
 {
//alert("s");
        
var x=document.forms["loginn"]["username"].value;       
      
      if(x==null || x=="")
      {
navigator.notification.alert("Username cannot be left blank", alertCallback,  "Alert");      
          return false;  
       }

var x=document.forms["loginn"]["password"].value;         
      
      if(x==null || x=="")
      {
navigator.notification.alert("Password cannot be left blank", alertCallback,  "Alert");                                 
          return false;  
       }
    
      else
      {
          
          return true;
      }
 
 }   
 
function help()
{
navigator.notification.alert("Credentials identifies your organization at kp. Your organization may not be on our mobile application support.Please write/check with your Mobile HRMS for your Organization enrolment and the company Details", alertCallback,  "Alert"); 
}

function passingcode()                        // AJAX jquery Database connectivity
    {
//var url="http://http://192.168.1.36:9090//hrms/";
alert("passcode")
// $.mobile.loading( 'show' );

        var validate=loginvalidate();
        if(validate==true){
            
    var username= $("#username").val().toString(); //document.getElementById('compcode').value;
    var password= $("#password").val().toString(); 
    datavalue="username="+username+"&password="+password;
    alert(datavalue)
    $.ajax({
    url: url+"kp_login.php",
    type:"POST",
    data:datavalue,
    timeout: 5000,
    success: function(data) {   
   //  alert('c');
     
  data=jQuery.parseJSON(data);
  alert(data);
 
  if(data.status==1){
 
  / // db maintanance
 
  sessionStorage.clear();  // storage session info clear
  sessionStorage.setItem('dbname',data.dbname);
sessionStorage.setItem('dbserver',data.dbserver);
//sessionStorage.setItem('logo',data.logo);
sessionStorage.setItem('dbuserid',data.dbuserid);        
sessionStorage.setItem('dbpass',data.dbpass);

//sessionStorage.setItem('uid',username);//empcode
sessionStorage.setItem('url',url);
//sessionStorage.setItem('name',data.name);
//sessionStorage.setItem('companyid',compcode);
sessionStorage.setItem('empid',data.empid);
$.mobile.showPageLoadingMsg();
               window.location='kphome.html';
               //sessionStorage.clear(); do not pass data 
               
  navigator.notification.alert("Login success", alertCallback,  "Alert");
  sessionStorage.setItem('url',url);
  // alert("Login success");
  $.mobile.showPageLoadingMsg();
  window.location="kphome.html";
  //$.mobile.pageLoading;
   }
   else if(data==2)
   {
  navigator.notification.alert("Invalid Username", alertCallback,  "Alert");     
  //alert("Invalid username");
  $('#username').val('');
  $('#password').val('');
  }
 
      },error: function(){
  alert('Network activity error');
  }
  });
        }else{
       
        $.mobile.hidePageLoadingMsg();
          //  $.mobile.loading( 'hide' );
        }
   }

</script>

</head> 
<body> 

<div data-role="page" id="index"><!-- index page -->

<div data-role="header"  data-theme="b" style="background: url(images/bg5.png) repeat-x;">
     <div align="center"><img src="images/icon.png" a style="vertical-align:bottom;height:40px;text-align:center;">
  <span>MOBILE HRMS</span></div>
    </div><!-- /header -->

<div data-role="content" class="pagecontent" >
 
            <div class="inset" >
            <div align="center">  <h3 style="color:#08298A;"> MEMBER LOGIN </h3></div>
            <br>
            <hr size="1px" align="left">
            <!-- <form name="kp_login" method="get"  onSubmit="return loginvalidate();" or add to login function function call action="javascipt:kp_login();"> -->
            <form id="Login" method="post" name="loginn" action="javascript:passingcode()">
            
            <p> USER NAME :<img src="images/Help.png" align="right" style="vertical-align:right;" onclick="help()" /> </p>
            <input type="text" name="username" id="username" value="" autocomplete="off" placeholder="User Name" data-clear-btn="true" min="3" maxlength="10"/>
            <p> PASS WORD : </p>
            <input type="password" data-clear-btn="true" name="password" id="password" autocomplete="off" value=""placeholder="Pass Word" min="3" maxlength="8"/>
          
            <div data-role="fieldcontain">
             <input type="submit" name="login" value="Sign In"  /> 
            </div>
        </form>
            <br />
            <hr size="1px">
            <div data-role="fieldcontain" align="justify">
            <a  href="kp_newreg.html" rel="external" data-role="button"  data-inline="true" data-theme="a">New Registration</a>
      <a  href="kp_forgotpass.html" rel="external" data-role="button"  data-inline="true" data-theme="a">Forgot Password?</a>
     
            </div>
            </div>
        </div>
</div><!-- /content -->
    
    <div data-role="footer" data-position="fixed"  style="background: url(images/bg5.png) repeat-x;overflow:hidden;">
    <h4> Tech</h4>
    
</div><!-- /footer -->
</div><!-- /index page -->

</body>
</html>

kp_login.php:

<?php 
//session_start();
$username =$_POST["username"]; //Storing username in $username variable.
$password =$_POST["password"]; //Storing password in $password variable.
include("kp_dbconn.php"); //including config.php in our file
$row=array();
$qry = mysql_query("select firstname from persons where firstname = '$username' and lastname = '$password'") or die (mysql_error());

{ 
 if(mysql_affected_rows()>0){


$empdetail =mysql_query("select * from corpratedetails where empid = '$username'") or die(mysql_error());// select here image of emp and amp logo
if($empdetail==true)


//$row = mysql_fetch_array($empdetail);

  //echo $row[];
 $row['status']=1;$row['empid']=$username; $row['dbname']='test'; $row['dbserver']='localhost'; $row['dbuserid']='root';
  $row['dbpass']=' ';

echo json_encode($row);
}
else{

echo 2;
echo "username and password wrong";
}
}
   

?>


kphome.html:

<!DOCTYPE html> 
<html>
<head>
<meta charset="utf-8">
<title> Mobile Web App</title>
<link href="jquery-mobile/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css"/>
<script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
<script src="json2.js" type="text/javascript"></script>

<script type="text/javascript" src="cordova-2.6.0.js"></script>
<link rel="stylesheet" href="kphome.css" />
<script type="text/javascript">    
            $(document).bind("mobileinit", function()
        {    
                $.mobile.defaultPageTransition = 'none';
                $.mobile.defaultDialogTransition = 'none';
          
        });
</script>  
<script>
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() { 
url=sessionStorage.getItem('url');

document.addEventListener("backbutton", Backbutton , false);
}


function Backbutton() 
{
//alert('a')
$.mobile.showPageLoadingMsg();
window.location="index.html";
$.mobile.hidePageLoadingMsg();
}
function back_button()
{
navigator.notification.alert("Use logout", alertCallback,  "Alert"); 
/* $.mobile.showPageLoadingMsg();
window.location="index.html";
$.mobile.hidePageLoadingMsg(); */
}
function alertCallback()
{}
function logout()
{
navigator.notification.confirm('Do you want to logout', onConfirm,'Alert');

}


function onConfirm(button) 
{
if(button==1)
{
$.mobile.showPageLoadingMsg();
window.location="index.html";
sessionStorage.clear();
}
else
{

}
}

</script>
</head> 
<body> 

<div data-role="page" id="kphomepage">
<div data-role="header"  data-theme="b" style="background: url(images/bg5.png) repeat-x;">
    <h1 style="color:#FFF">Mobile HRMS</h1>
    
    <!--<a href="#" data-icon="gear" class="ui-btn-right">Options</a>-->
   <!-- <div data-role="navbar" >
        <ul>
            <li><a  href="#page3" style="color:#fff;background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#bdbdbd), to(#000));;border-color:#fff;border-left-color:#fff;border-right-color:#fff;" class="ui-btn-active">Attendence System</a></li>
            <li><a href="#page4"style="color:#fff;background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#bdbdbd), to(#000));;border-color:#fff;border-left-color:#fff;border-right-color:#fff;">Corporate Directory</a></li>
            <li><a href="#page5"style="color:#fff;background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#bdbdbd), to(#000));;border-color:#fff;border-left-color:#fff;border-right-color:#fff;">List of Holidays</a></li>
        </ul>
    </div>--><!-- /navbar -->
</div><!-- /header -->

<div data-role="content" class="pagecontent" >
    <div class="backlogobutton" >
    
    
    <!-- <a href="javascript:back_button()" rel="external"  data-theme="b" data-inline="true" style="float:left; margin-top:0px;" >
<img id="home_icon" alt="home"  style="width:20px;  height:20px; " src="images/2.png"> </a> -->

    <img src="images/kp.gif" id='helplogo' >   
 
  <a href="javascript:logout()"  title="Logout" rel="external"  data-theme="b" data-inline="true" style="float:right;margin-top:0px; " >
<img id="logout_icon" alt="logout"  style="width:35px;  height:35px;vertical-align: center " src="images/logout.png"  > </a>
<br>

   
    
    </div>
     <div class="inset" >
<ul data-role="listview" data-inset="true">
        <li><a href="kpattendence.html" rel="external">Attendance Management</a></li>
<li><a href="kp_corp_add.html" rel="external" >Corporate Directory</a></li>
            <li><a href="kp_listofholidays.html" rel="external" >List of Holidays</a></li>
            <li><a href="kp_timsheet.html" rel="external">Time sheet</a></li>
<li><a href="kp_payslip.html" rel="external">Pay slip</a></li>
            <li><a href="kp_helpdesk.html" rel="external">Help Desk</a></li>
            <!--<li><a href="#page8">Help Desk</a></li>
            
<li><a href="#page10">Page ten</a></li>-->
</ul>
</div>
    </div>
<!--<div data-role="footer" data-position="fixed" style="background: url(images/bg5.png) repeat-x;";>
<h4>kp Tech</h4>
</div>-->
    
    <div data-role="footer" data-position="fixed"  style="background: url(images/bg5.png) repeat-x;overflow:hidden;">
    <h3 align="center">@kp</h3>
    <!--<div data-role="navbar">
        <ul>
            <li><a  href="#page3" style="color:#fff;background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#000), to(#bdbdbd));border-color:#fff;border-left-color:#fff;border-right-color:#fff;" class="ui-btn-active">Time Sheet</a></li>
            <li><a  href="#page3" style="color:#fff;background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#000), to(#bdbdbd));border-color:#fff;border-left-color:#fff;border-right-color:#fff;" class="ui-btn-active">Pay Slip</a></li>
            <li><a  href="#page3" style="color:#fff;background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#000), to(#bdbdbd));border-color:#fff;border-left-color:#fff;border-right-color:#fff;" class="ui-btn-active">Help Desk</a></li>
        </ul>-->
    </div><!-- /navbar -->
</div><!-- /footer -->
</div>




</body>

</html>

Friday, 22 August 2014

Multiple version of jquery in the same Page

jQuery in no-conflict mode. "No conflict" mode is the typical solution to get jQuery working on a page with other frameworks like prototype, and can be also be used here as it essentially namespaces each version of jQuery which you load.
<script src="jQuery1.3.js"></script>
<script>
    jq13 = jQuery.noConflict(true);
</script>

<!-- original author's jquery version -->
<script src="jQuery1.2.3.js"></script>
<script src="jQuery1.3.js"></script>
<script>
    jq13 = jQuery.noConflict(true);
</script>
<script src="jQuery1.3.1.js"></script>
<script>
    jq131 = jQuery.noConflict(true);
</script>

<!-- original author's jquery version -->
<script src="jQuery1.2.3.js"></script>
The variables jq13 and jq131 would each be used for the version-specific features you require.
It's important that the jQuery used by the original developer is loaded last - the original developer likely wrote their code under the assumption that $() would be using their jQuery version. If you load another version after theirs, the $ will be "grabbed" by the last version you load, which would mean the original developer's code running on the latest library version, rendering the noConflicts somewhat redundant!
Why do conflicts happen? Conflicts typically happen because many JavaScript Libraries/Frameworks use the same shortcut name which is the dollar symbol $. Then if they have the same named functions the browser gets confused!
How do we prevent conflicts? Well, to prevent conflicts i recommend aliasing the jQuery namespace (ie by using example 3 above). Then when you call $.noConflict() to avoid namespace difficulties (as the $ shortcut is no longer available) we are forcing it to wrtie jQuery each time it is required.
1
2
3
4
5
6
7
8
9
10
jQuery.noConflict(); // Reverts '$' variable back to other JS libraries
jQuery(document).ready( function(){
         //do jQuery stuff when DOM is ready with no conflicts
   }); 
 
//or the self executing function way
 jQuery.noConflict();
 (function($) {
    // code using $ as alias to jQuery
})(jQuery);

Web services SOAP ,REST

What is a Web service?

A web service is a method of communication between two electronic devices over the World Wide Web.

W3C defines web service as a “software system designed to support interoperable machine-to-machine interaction over a network.
It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a
manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction
with other Web-related standards

What is SOAP?

SOAP is a protocol specification for exchanging structured information in the implementation of Web Services.
It uses XML for the message format. It is independent of the transport protocol (could be HTTP, FTP, TCP, UDP, or named pipes).
SOAP based services strictly define the format of messages passed back and forth. A SOAP message contains the data,
the action to perform on it, the headers, and the error details in case of failure. Security is provided by WS-Security standards and is end-to-end.
 It supports identity through intermediaries, not just point to point (SSL).

SOAP provides a mechanism for services to describe themselves to clients (WSDL), and to advertise their existence (UDDI).
 SOAP also provides reliable messaging (WS-ReliableMessaging), that is a successful retry logic built in and provides end to end reliability
 through soap intermediaries.

What is REST?

Representational State Transfer (REST) is an architecture style for designing networked applications, that

Involves clients and servers sending request and responses respectively.
Request and response are built around the transfer of representations of resources.
(e.g. request JSON representation of User)
REST recognises everything a resource (e.g. User, Lottery, etc.) and each resource implements a standard uniform interface (typically HTTP interface),
resources have name and addresses (URIs), each resource has one or more representation (like JSON or XML) and resource representations move
 across the network usually over HTTP.

RESTful web APIs (or RESTful web service) is a web API implemented using HTTP and principles of REST. RESTful API separates
 user interface concerns from data storage concerns. It improves portability of interface across multiple platforms and simplifies
server components by making them stateless. Each request from client contains all the state information and server does not hold client
context in the session.

SOAP vs REST?

One of the major benefits of SOAP is that you have a WSDL service description. You can pretty much discover the service automatically and
 generate a useable client proxy from that service description (generate the service calls, the necessary data types for the methods and so forth).
 Note that with version 2.0, WSDL supports all HTTP verbs and can be used to document RESTful services as well, but there is a less verbose
 alternative in WADL (Web Application Description Language) for that purpose.

With RESTful services, message security is provided by the transport protocol (HTTPS), and is point-to-point only.
 It doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying.
 SOAP has successful/retry logic built in and provides end-to-end reliability even through SOAP intermediaries.

One of the major benefits of RESTful API is that it is flexible for data representation, for example you could serialize your data in either XML
or JSON format. RESTful APIs are cleaner or easier to understand because they add an element of using standardised URIs and gives
 importance to HTTP verb used (i.e. GET, POST, PUT and DELETE).

RESTful services are also lightweight, that is they don’t have a lot of extra xml markup. To invoke RESTful API all you need is a
 browser or HTTP stack and pretty much every device or machine connected to a network has that.

Finally, which ever architecture you choose make sure its easy for developers to access it, and well documented.

GET vs POST

The GET Method
Note that query strings (name/value pairs) is sent in the URL of a GET request:
/test/demo_form.asp?name1=value1&name2=value2
Some other notes on GET requests:
  • GET requests can be cached
  • GET requests remain in the browser history
  • GET requests can be bookmarked
  • GET requests should never be used when dealing with sensitive data
  • GET requests have length restrictions
  • GET requests should be used only to retrieve data


The POST Method
Note that query strings (name/value pairs) is sent in the HTTP message body of a POST request:
POST /test/demo_form.asp HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2
Some other notes on POST requests:
  • POST requests are never cached
  • POST requests do not remain in the browser history
  • POST requests cannot be bookmarked
  • POST requests have no restrictions on data length


Compare GET vs. POST
The following table compares the two HTTP methods: GET and POST.


Redux vs Redux Toolkit vs React Context

  These are often confused. Feature Redux Redux Toolkit Context API Purpose State management Simplifies Redux Shares values in Rea...