Friday 29 April 2022

Pre Populate jquery Token input textbox with PhP MySQLi Resultset

Tokeninput is a jQuery plugin that allows users to select multiple items from a predefined list. 
  • Download jquery token input plugin from https://loopj.com/jquery-tokeninput/
  • Extract the zip file and put jquery.tokeninput.js and token-input.css in the application root folder.
  • Download the latest version of jquery.min.js
SQL

CREATE TABLE `user` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(40) DEFAULT NULL,
  `designation` varchar(50) DEFAULT NULL,
  `email` varchar(40) DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `user` (`id`, `name`, `designation`, `email`) VALUES
(1, 'User1', 'Senior Manager', 'user1@gm.com'),
(2, 'User2', 'Head of IT', 'aru@rrg.com');

PhP Code

<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Token input Demo</title>
<meta charset="utf-8">
<link
href="https://fonts.googleapis.com/css?family=Lato:400,700,300|Open+Sans:400,300,600,700"
rel="stylesheet" />
<link href="css/bootstrap.min.css?ver=3.3.5" rel="stylesheet" />
<link href="css/token-input.css" rel="stylesheet" />
</head>
<?php
error_reporting(0);
$con = mysqli_connect("localhost", "root", "", "rgcbres_accounts");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
<script src="js/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="js/jquery.tokeninput.js"></script>
<script>
    $(document).ready(function () {
    $("#nameinput").tokenInput("tget-users.php", {       
    });
});
</script>
<body>
<div id="content" class="site-content">
<div class="container">
<h4>Token Input Demo</h4>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"
id="searchform" enctype="multipart/form-data">
<div class="col-sm-12">
<div class="form-group">
<label class="control-label col-sm-3" for="scst">Name <font
style="color: red;">*</font></label>
<div class="col-sm-6">
<div class="input-group">
<input type="text" id="nameinput" name="nameinput" required=""
class="form-control" placeholder="" />
</div>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="col-sm-6">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-default" name="Submit"
value="Submit">
</div>
</div>
</div>
</form>
<?php
if ($_POST['Submit']) {
    if (trim($_POST['nameinput']) != "") {
        $selected_name_arr = array();
        $selected_nameinput = $_POST['nameinput'];
        $selected_name_arr = explode(',', $selected_nameinput);       
        ?>  
            <div class="col-sm-12">
<form class="form-horizontal" id="saveform" action="#" method="post"
enctype="multipart/form-data">
<table id="editableTable" class="table table-bordered">
<thead>
<tr>
<td style="width: 5%;"><b>SL.No.</b></td>
<td style="background-color: #f0ad4e; width: 15%;"><b> Name </b></td>
<td style="background-color: #f0ad4e; width: 20%;"><b>
Designation </b></td>
<td style="background-color: #f0ad4e; width: 20%;"><b> Email </b></td>
</tr>
</thead>
<tbody>     
            <?php
        $sql = "SELECT * FROM user WHERE id IN (" . implode(',', $selected_name_arr) . ")";
        $result = $con->query($sql);
        $sino = 1;
        if ($result->num_rows > 0) {
            // output data of each row
            while ($row = $result->fetch_assoc()) {
                ?>
                    <tr>
<td><?php echo $sino; ?>                
<td><?php echo $row[name]; ?></td>
<td><?php echo $row[designation]; ?></td>
<td><?php echo $row[email]; ?></td>
</tr>
                 <?php
                $sino ++;
            }
        }
        ?>
            </tbody>
</table>
</div>
</form>           
            <?php
    }
}
?>
</div>
</div>
</body>
</html>


tget-users.php

<?php 
$con = mysqli_connect("localhost", "root", "", "rgcbres_accounts");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$users_arr = array();
$searchTerm = $_GET['q'];
     $query = $con->query("SELECT id,name FROM user  WHERE name LIKE '".$searchTerm."%' ORDER BY name ASC  LIMIT 15");  
    if($query->num_rows > 0){
        while($row = $query->fetch_assoc()){
            $users_arr[] = $row;
        }
    }    
    echo json_encode($users_arr);
?>     
    






Distributed Systems

 Distributed Systems

  • Consists of multiple computers and software components that communicate through a computer network. 
  • Can consist of any number of possible configurations, such as mainframes, workstations, personal computers, and so on. 
  • The computers interact with each other and share the resources of the system to achieve a common goal
Advantages of Distributed Systems 
  1. Reliability (fault tolerance) 
    • The important advantage of distributed computing system is reliability. If some of the machines within the system crash, the rest of the computers remain unaffected and work does not stop. 
  2. Scalability 
    • In distributed computing the system can easily be expanded by adding more machines as needed. 
  3. Sharing of Resources 
    • Shared data is essential to many applications such as banking, reservation system. As data or resources are shared in distributed system, other resources can be also shared (e.g. expensive printers).
  4. Flexibility 
    • As the system is very flexible, it is very easy to install, implement and debug new services. 
  5. Speed 
    • A distributed computing system can have more computing power and it's speed makes it different than other systems. 
  6. Open system 
    • As it is open system, every service is equally accessible to every client i.e. local or remote. 
  7. Performance 
    • The collection of processors in the system can provide higher performance (and better price/performance ratio) than a centralized computer. 
Disadvantages of Distributed Systems 
  1. Troubleshooting 
    • Troubleshooting and diagnosing problems. 
  2. Software 
    • Less software support is the main disadvantage of distributed computing system. 
  3. Networking 
    • The network infrastructure can create several problems such as transmission problem, overloading, loss of messages.
  4. Security 
    • Easy access in distributed computing system increases the risk of security and sharing of data generates the problem of data security

Wednesday 27 April 2022

Platform as a service (PaaS)

Platform as a service (PaaS) 

  • The PaaS model provides the tools within an environment needed to create applications that can run in a Software as a Service model 
  • PaaS is application middleware offered as a service to developers, integrators, and architects. 
  • Development and Operation teams use PaaS to design, build, and deliver customized applications or information services. 
  • Instead of relying on standardized SaaS, teams using PaaS have more control over solution architecture, quality of service, user experience, data models, identity, integration, and business logic.
  • In PaaS you are given a toolkit to work with, a virtual machine to run your software on, and it is up to you to design the software and its user-facing interface in a way that is appropriate to your needs.
  • So PaaS systems range from full-blown developer platforms like Windows Azure to systems like Drupal, Squarespace, Wolf, and others where the tools are modules that are very well developed and require almost no coding.
  • PaaS solution will ensure the availability of the application despite downtime of the underlying virtual machine by automatically creating a new instance of the application on a new virtual machine when the machine goes down.
  • PaaS systems can be used to host a variety of cloud services
    • Online portal-based applications like Facebook that need to scale to thousands of users 
    • Startup who wants to host their new application in a Software-as-a-Service model 
    • Can also be used for massively parallel computations 
    • Enterprises can deploy their Line-of-Business applications in the cloud, taking advantage of the scale and availability while still maintaining security and privacy of data
PaaS examples 

Windows Azure 
Google App Engine 
Hadoop platform 
Drupal 
Wolf Frameworks 
Force.com 

Amazon Web Services (AWS)

AWS is Amazon’s umbrella description of all of their web-based technology services.  Main services include:

  • Compute 
  • Storage
  • Database
  • Deployment & Management 
  • Application Services 
  • Networking 
  • Content Delivery

Category

Service

Compute

  • Amazon Elastic Compute Cloud (Amazon EC2)
  • Amazon Elastic MapReduce (Amazon EMR)
  • Auto scaling
  • Elastic Load Balancing

Storage

  • Amazon Simple Storage Service (Amazon S3) Amazon Glacier
  • AWS Storage Gateway
  • AWS Import/Export

Content Delivery

  • Amazon CloudFront

Database

  • Amazon Relational Database Service (Amazon RDS)
  • Amazon DynamoDB
  • Amazon ElastiCache

Deployment & Management

  • AWS Identity and Access Management (IAM) Amazon CloudWatch
  • AWS Elastic Beanstalk
  • AWS CloudFormation

Application Services

  • Amazon Simple Queue Service (SQS)
  • Amazon Simple Notification Service (Amazon SNS)
  • Amazon Simple Email Service (Amazon SES)
  • Amazon CloudSearch

Networking

  • Amazon Virtual Private Cloud (Amazon VPC)
  • Amazon Route 53
  • AWS Direct Connect

Tuesday 26 April 2022

SaaS (Software as a Service)

 SaaS - Definition

  • The most complete cloud computing service model is one in which the computing hardware and software, as well as the solution itself, are provided by a vendor as a complete service offering.
  • SaaS is a model where an application is hosted on a remote data center and provided as a service to customers across the internet.
  • In this model the provider takes care of all software development, maintenance and upgrades.
  • Salesforce.com is a common and popular example of a CRM SaaS application.  
Is it customizable?
  • Many people believe that SaaS software is not customizable, and in many SaaS applications this is indeed the case. eg: user-centric application like office suite 
  • Many other SaaS solutions expose Application Programming Interfaces (API) to developers to allow them to create custom composite applications eg: Salesforce.com, Quicken.com, etc 
So, SaaS does not necessarily mean that the software is static or monolithic.

SaaS characteristics
  • The software is available over the Internet globally through a browser on demand 
  • The typical license is subscription-based or usage-based and is billed on a recurring basis 
  • The software and the service are monitored and maintained by the vendor, regardless of where all the different software components are running 
  • Reduced distribution, maintenance costs and minimal end
  • user system costs generally make SaaS applications cheaper to use than their shrink-wrapped versions 
  • Such applications feature automated upgrades, updates, and patch management and much faster rollout of changes 
  • SaaS applications often have a much lower barrier to entry than their locally installed competitors, a known recurring cost, and they scale on demand 
  • All users have the same version of the software, so each user's software is compatible with another's 
  • SaaS supports multiple users and provides a shared data model through a single-instance, multi-tenancy model
SaaS - Pros
  • No large upfront costs - usually free trials 
  • Anywhere, anytime, anyone - mobility 
  • Stay focused on business processes 
  • Change software to an Operating Expense instead of a Capital Purchase, making better accounting and budgeting sense. 
  • Create a consistent application environment for all users 
  • No concerns for cross platform support 
  • Easy Access 
  • Reduced piracy of your software
  • Lower Cost: 
    • For an affordable monthly subscription; 
    • Implementation fees are significantly lower 
  • Continuous Technology Enhancements
SaaS - Cons 
  • Initial time needed for licensing and agreements 
    • Trust, or the lack thereof, is the number one factor blocking the adoption of software as a service (SaaS). 
    • Centralized control
    • Possible erosion of customer privacy 
  • Absence of disconnected use 
  • Not suited to high volume data entry
  • Broadband risk
SaaS ?? 

Imagine a system 
  • where you don't have to buy new hardware or update software 
  • where you pay nothing or pay as much as you use 
  • where everything is done as a service: Infrastructure, computing, storage and usage 
  • where you don't worry about your resources spent on Infrastructure security and operational security  where you cut your IT spending 
  • where you have freedom of usage from anywhere with internet connectivity 
  • which is eco-friendly 
Example SaaS applications 
  1. Salesforce.com 
  2. Google Apps 
    • Gmail, Google Groups, Google Calendar, Talk, Docs, etc 
    • Google Apps Marketplace (Google apps for both free and for a fee) 
  3. Microsoft Office 365 
    • Office 365 is a subscription-based online office and software plus services suite which offers access to various services and software built around the Microsoft Office platform
Which applications are suitable?

Any application can be deployed in this way. However communications over the Internet are not as fast as local connections - so leave any high volume data entry applications on your internal LAN or WAN. All the rest can go on the Internet under a SaaS approach.

Myths 
  • SaaS is still relatively new and untested 
  • SaaS is just another version of the failed ASP and hosting models of the past and will suffer the same fate as its predecessors 
  • SaaS only relieves companies of the upfront costs of traditional software licenses 
  • SaaS is only for small and mid-sized businesses and will not be accepted by large-scale organizations
  • SaaS only applies to applications such as CRM and Salesforce automation 
  • SaaS will only have a minor impact on the software industry and will fade over time 
  • It will be easy for the established software vendors to offer SaaS and dominate this market 
  • SaaS is only for corporate users
Traditional packaged Software Vs SaaS

Traditional packaged Software

Saas

Designed for customers to install, manage and maintain

Designed from the outset up for delivery as Internet-based services

Architect solutions to be run by an individual company in a dedicated instantiation of the software

Designed to run thousands of different customers on a single code

Infrequent, major upgrades every 18-24 months, sold individually to each installed base customer

Frequent, "digestible" upgrades every 3-6 months to minimize customer disruption and enhance satisfaction

Version control

Version control

Upgrade fee

- do -

Fixing a problem for individual customer

Fixing a problem for one customer fixes it for everyone

Monday 25 April 2022

Export mysqli resultset as excel with nested table in PhP

 <?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$con = mysqli_connect("localhost", "root", "", "tablename");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$output = '';
$stmt3 = $con->prepare("SELECT id,registrationid,name,email,mobile,nationality,state,district,gender from adv33");
$stmt3->execute();
$stmt3->bind_result($id, $registrationid, $name, $email, $mobile, $nationality, $state, $district, $gender);
$stmt3->store_result();
if ($stmt3->num_rows > 0) {
    $output .= '
    <table border="1">
                    <tr>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Mobile</th>                      
                        <th>Nationality</th>
                        <th>State</th>
                        <th>District</th>
                        <th>Gender</th>                                            
                    </tr>
  ';
    while ($stmt3->fetch()) {
        $output .= '
                    <tr>                         
                         <td>' . $name . '</td>
                         <td>' . $email . '</td>
                         <td>' . $mobile . '</td>                         
                         <td>' . $nationality . '</td>
                         <td>' . $state . '</td>
                         <td>' . $district . '</td>
                         <td>' . $gender . '</td>                         
                    </tr>';
        $output .= '                  
         <table border="1">
         <tr>
         <td><b>Post</b></td>
         <td><b>Company</b></td>         
           <td><b>From Date</b></td>
            <td><b>To Date</b></td>
            <td><b>Scale of Pay</b></td>          
   ';
        $stmt4 = $con->prepare("SELECT slno,email,post,company,fromdate,todate,scale FROM adv33exp  where email ='$registrationid'");
        $stmt4->execute();
        /* bind result variables */
        $stmt4->bind_result($slno, $email, $post, $company, $fromdate, $todate, $scale);
        $stmt4->store_result();
        if ($stmt4->num_rows > 0) {
            /* fetch value */
            while ($stmt4->fetch()) {
                $output .= '
                     <tr>
                         <td>' . $post . '</td>
                         <td>' . $company . '</td>                        
                         <td>' . $fromdate . '</td>
                         <td>' . $todate . '</td>
                         <td>' . $scale . '</td>                         
                    </tr>
                ';
            }
        }
    }
    $output .= '</table>';
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=Applicants.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    echo $output;
}
?>

Sunday 24 April 2022

How to get hidden field value in jquery?

JS Code 

<script>

      $(document).ready(function(){   

        var userid = $('#userid').val();

    }

</script>

HTML Code

<input type="hidden" name="userid" id="userid" value="8"/>   

Saturday 23 April 2022

Software Development: Iterative and Evolutionary Development

Iterative and Evolutionary Development

  • Involves early programming and testing of a partial system, in repeating cycles.
  • Relies on short quick development steps (or iterations), feedback and adaptation to clarify the requirements and design so successively enlarging and refining a system. 
  • Normally assumes that the development starts before all requirements are defined in detail, feedback is used to clarify and improve the evolving specifications.
  • Each iteration will include requirements, analysis, design, implementation, and test. 
  • Iterative feedback and evolution leads towards the desired system. The requirements and design instability lowers over time.

Current research demonstrates that iterative methods are associated with higher success and productivity rates, and lower defect levels.

Timeboxing

A key idea is that iterations are timeboxed, or fixed in length.

  • Most iterative methods recommend in iteration length between 2 – 6 weeks.
  • If it seems that it will be difficult to meet the deadline, the recommended response is to de-scope

De-scoping: removing tasks or requirements from the iteration, and including them in a future iteration, rather than slipping the completion date.

Iterative and Evolutionary Development (also known as iterative and inceremental development; spiral development and evolutionary development)

Build-Feedback-Adapt Cycles

In complex changing systems, feedback and adaptation are key ingredients for success:

  • Feedback from early development, programmers trying to read specifications, and client demos: to refine the requirements.
  • Feedback from tests and developers : to refine the design and models.
  • Feedback from the progress of the team tackling early features : to refine the schedule and estimates.

Benefits of Iterative development 

  • Less project failure, better productivity, and lower defect rates 
  • Early rather than late mitigation of high risks 
  • Early visible progress 
  • Early feedback, user engagement, and adaptation 
  • Managed complexity: the team is not overwhelmed by “analysis paralysis” or very long and complex steps 
  • The learning within an iteration can be methodically used to improve the development process itself, iteration by iteration. 

The Unified Process is a popular iterative software development process. 

Why a new methodology?

Process-oriented methods:

  • Requirements of a project are completely frozen before the design and development process commences.
  • Not always feasible
  • Need for flexible, adaptable and agile methods, which allow the developers to make late changes in specifications.

Waterfall (Sequential) Lifecycle

  • Promotes big up-front “speculative” requirements and design steps before programming.
  • Historically promoted due to belief or hearsay rather than statistically significant evidence.
  • Success/failure studies show that the waterfall has high failure rates.

Why the waterfall lifecycle fails?

The key false assumption:

  • The specifications are predictable and stable and can be correctly defined at the start, with low change rates.
  • But change is a constant on software projects.
  • A typical software project experienced a 25% change.

  

Friday 22 April 2022

Add dynamic rows in html table with Add, Edit, Delete feature in PHP and MySQLi

dynamic-table.php

<!DOCTYPE html>
<html lang="en-US">
<head>
<title> Dynamic Table in PhP</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700,300|Open+Sans:400,300,600,700" rel="stylesheet" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
<link href="../css/bootstrap.min.css?ver=3.3.5" rel="stylesheet" />
<link href="../css/font-awesome.min.css?ver=4.6.3" rel="stylesheet" />
<link rel="stylesheet" href="css/dataTables.bootstrap.min.css" />
</head>
<body>
<script src="../js/jquery-3.5.1.min.js"></script>
<script src="../js/jquery.dataTables.min.js"></script>
<script src="../js/bootstrap.min.js?ver=3.3.5"></script>
<script src="../js/jquery-ui.js"></script>
<script>
      $(document).ready(function(){
       $("#fromdate").datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy'                          
             
            });
        $("#todate").datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: 'dd/mm/yy'                          
             
            });
  var employeeData = $('#employeeList').DataTable({
"processing":true,
"serverSide":true,
"bFilter":false,
"bSort" : false ,
"bPaginate": false,
"bInfo" : false,
"order":[],
"ajax":{
url:"action.php",
type:"POST",
data:{action:'listEmployee'},
dataType:"json"
}
});
$('#addEmployee').click(function(){
$('#employeeModal').modal('show');
$('#employeeForm')[0].reset();
$('.modal-title').html("<i class='fa fa-plus'></i> Add Employment Details");
$('#action').val('addEmployee');
$('#save').val('Add');
});
$("#employeeList").on('click', '.update', function(){
var empId = $(this).attr("id");
var action = 'getEmployee';
$.ajax({
url:'action.php',
method:"POST",
data:{empId:empId, action:action},
dataType:"json",
success:function(data){
$('#employeeModal').modal('show');
$('#empId').val(data.id);
$('#post').val(data.post);
$('#company').val(data.company);
$('#type').val(data.type);
$('#fromdate').val(data.fromdate);
$('#todate').val(data.todate);
$('#scale').val(data.scale);
$('#gross').val(data.gross);
$('.modal-title').html("<i class='fa fa-plus'></i> Edit Employee");
$('#action').val('updateEmployee');
$('#save').val('Save');
}
})
});
$("#employeeModal").on('submit','#employeeForm', function(event){
event.preventDefault();
$('#save').attr('disabled','disabled');
var formData = $(this).serialize();
$.ajax({
url:"action.php",
method:"POST",
data:formData,
success:function(data){
$('#employeeForm')[0].reset();
$('#employeeModal').modal('hide');
$('#save').attr('disabled', false);
employeeData.ajax.reload();
}
})
});
$("#employeeList").on('click', '.delete', function(){
var empId = $(this).attr("id");
var action = "empDelete";
if(confirm("Are you sure you want to delete this employee?")) {
$.ajax({
url:"action.php",
method:"POST",
data:{empId:empId, action:action},
success:function(data) {
employeeData.ajax.reload();
}
})
} else {
return false;
}
});
});
</script>
<div id="content" class="site-content">
<div class="container">
<div class="row">
<div class="col-md-12 padding-bottom-20">
<div class="row row-margin">
<div class="col-md-12">
<div class="container">
<div id="payment" style="display: block;">
<div style="overflow-x: auto;">
<div class="col-lg-10 col-md-10 col-sm-9 col-xs-12">   
<div class="panel-heading">
<div class="row">
<div class="col-md-10">
<h3 class="panel-title"></h3>
</div>
<div class="col-md-2" align="right">
<button type="button" name="add" id="addEmployee" class="btn btn-success btn-xs" style="font-size: 15px;padding: 10%;">Add New Row</button>
</div>
</div>
</div>
<table id="employeeList" class="table table-bordered table-striped" style="width:100%;">
        <thead>
<tr>
<th>Post held</th>
<th>Department/ Institute/ Company</th>
<th>Permanent/ Temporary/ Contract</th>
<th>From Date</th>
<th>To Date</th>
<th>Scale of pay</th>
<th>Gross Amount</th>
<th></th>
<th></th>
</tr>
</table>
</div>
<div id="employeeModal" class="modal fade">
    <div class="modal-dialog">
    <form method="post" id="employeeForm">
    <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><i class="fa fa-plus"></i> Edit Employment Details</h4>
    </div>
    <div class="modal-body">
<div class="form-group"
<label for="post" class="control-label">Post held</label>
<input type="text" class="form-control" id="post" name="post" placeholder="Post held" required>
</div>
<div class="form-group">
<label for="company" class="control-label">Department/ Institute/ Company</label>
<input type="text" class="form-control" id="company" name="company" placeholder="Department/ Institute/ Company">
</div>    
<div class="form-group">
<label for="type" class="control-label">Permanent/ Temporary/ Contract</label>
<input type="text" class="form-control"  id="type" name="type" placeholder="Permanent/ Temporary/ Contract" required="required">
</div>  
<div class="form-group">
<label for="fromdate" class="control-label">From Date [dd/mm/yyyy]</label>
<input type="text" class="form-control"  id="fromdate" name="fromdate" placeholder="From Date" autocomplete="off" readonly="readonly" required="required" ></textarea>
</div>
<div class="form-group">
<label for="todate" class="control-label">To Date [dd/mm/yyyy]</label>
<input type="text" class="form-control" id="todate" name="todate" placeholder="To Date" autocomplete="off" readonly="readonly" required="required" >
</div>
<div class="form-group">
<label for="scale" class="control-label">Scale of pay</label>
<input type="text" class="form-control" id="scale" name="scale" placeholder="Scale of pay" required="required" >
</div>
<div class="form-group">
<label for="gross" class="control-label">Gross Amount</label>
<input type="text" class="form-control" id="gross" name="gross" placeholder="Gross Amount" required="required" >
</div>
    </div>
    <div class="modal-footer">
    <input type="hidden" name="empId" id="empId" />
    <input type="hidden" name="userid" id="userid" value="12"/>   
    <input type="hidden" name="action" id="action" value="" />
    <input type="submit" name="save" id="save" class="btn btn-info" value="Save" />
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
    </div>
    </form>
    </div>
    </div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- .col-md-9 --></div>
<!-- .row --></div>
<!-- .container --></div>

action.php

<?php
include('Employee.php');
$emp = new Employee();
if(!empty($_POST['action']) && $_POST['action'] == 'listEmployee') {
$emp->employeeList();
}
if(!empty($_POST['action']) && $_POST['action'] == 'addEmployee') {
$emp->addEmployee();
}
if(!empty($_POST['action']) && $_POST['action'] == 'getEmployee') {
$emp->getEmployee();
}
if(!empty($_POST['action']) && $_POST['action'] == 'updateEmployee') {
$emp->updateEmployee();
}
if(!empty($_POST['action']) && $_POST['action'] == 'empDelete') {
$emp->deleteEmployee();
}
?>

Config.php

<?php
class dbConfig {
    protected $serverName;
    protected $userName;
    protected $password;
    protected $dbName;
    function dbConfig() {
        $this -> serverName = 'localhost';
        $this -> userName = 'root';
        $this -> password = "";
        $this -> dbName = "employee";
    }
}
?>

Employee.php

<?php require('config.php'); class Employee extends Dbconfig { protected $hostName; protected $userName; protected $password; protected $dbName; private $empTable = 'employment'; private $dbConnect = false; public function __construct(){ if(!$this->dbConnect){ $database = new dbConfig(); $this -> hostName = $database -> serverName; $this -> userName = $database -> userName; $this -> password = $database ->password; $this -> dbName = $database -> dbName; $conn = new mysqli($this->hostName, $this->userName, $this->password, $this->dbName); if($conn->connect_error){ die("Error failed to connect to MySQL: " . $conn->connect_error); } else{ $this->dbConnect = $conn; } } } public function employeeList(){ $sqlQuery = "SELECT * FROM ".$this->empTable." "; $result = mysqli_query($this->dbConnect, $sqlQuery); $employeeData = array(); while( $employee = mysqli_fetch_assoc($result) ) { $empRows = array(); $empRows[] = $employee['post']; $empRows[] = $employee['company']; $empRows[] = $employee['type']; $empRows[] = $employee['fromdate']; $empRows[] = $employee['todate']; $empRows[] = $employee['scale']; $empRows[] = $employee['gross']; $empRows[] = '<button type="button" name="update" id="'.$employee["id"].'" class="btn btn-warning btn-xs update">Update</button>'; $empRows[] = '<button type="button" name="delete" id="'.$employee["id"].'" class="btn btn-danger btn-xs delete" >Delete</button>'; $employeeData[] = $empRows; } $output = array( "draw" => intval($_POST["draw"]), "data" => $employeeData ); echo json_encode($output); } public function getEmployee(){ if($_POST["empId"]) { $sqlQuery = " SELECT * FROM ".$this->empTable." WHERE id = '".$_POST["empId"]."'"; $result = mysqli_query($this->dbConnect, $sqlQuery); $row = mysqli_fetch_array($result, MYSQLI_ASSOC); echo json_encode($row); } } public function updateEmployee(){ if($_POST['empId']) { $updateQuery = "UPDATE ".$this->empTable." SET userid = '".$_POST["userid"]."', post = '".$_POST["post"]."', company = '".$_POST["company"]."', type = '".$_POST["type"]."', fromdate = '".$_POST["fromdate"]."' , todate = '".$_POST["todate"]."' , scale = '".$_POST["scale"]."', gross = '".$_POST["gross"]."' WHERE id ='".$_POST["empId"]."'"; $isUpdated = mysqli_query($this->dbConnect, $updateQuery); } } public function addEmployee(){ $insertQuery = "INSERT INTO ".$this->empTable." (userid, post, company, type, fromdate, todate,scale, gross) VALUES ('".$_POST["userid"]."','".$_POST["post"]."', '".$_POST["company"]."', '".$_POST["type"]."', '".$_POST["fromdate"]."', '".$_POST["todate"]."', '".$_POST["scale"]."', '".$_POST["gross"]."')"; $isUpdated = mysqli_query($this->dbConnect, $insertQuery); } public function deleteEmployee(){ if($_POST["empId"]) { $sqlDelete = " DELETE FROM ".$this->empTable." WHERE id = '".$_POST["empId"]."'"; mysqli_query($this->dbConnect, $sqlDelete); } } } ?>

employee.sql

CREATE TABLE `employment` (
  `id` int(10) NOT NULL,
  `userid` int(10) DEFAULT NULL,
  `post` varchar(100) DEFAULT NULL,
  `company` varchar(100) DEFAULT NULL,
  `type` varchar(25) DEFAULT NULL,
  `fromdate` varchar(25) DEFAULT NULL,
  `todate` varchar(25) DEFAULT NULL,
  `scale` varchar(50) DEFAULT NULL,
  `gross` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


Thursday 21 April 2022

Unified Process (UP) Best Practices

  • Get high risk and high value requirements first
  • Constant user feedback and engagement
  • Early cohesive core architecture
  • Test early, often, and realistically
  • Apply use cases where needed
  • Do some visual modeling with UML
  • Manage requirements and scope creep
  • Manage change requests and configuration

How to persist the selected value of the select box after form submit?

 <?php
if ($_POST['submit']) {
    if ($_POST['srf'] != "") {
        $srf = $_POST['srf'];
    } else {
        $srfErr = "This field is required.";
    }
}
?>
<form method="post">
<select name="srf" id="srf" class="form-control">
<option value="">Select</option>
<option <?php if (isset($srf) && $srf=="1") echo "selected";?>>1</option>
<option <?php if (isset($srf) && $srf=="2") echo "selected";?>>2</option>
<option <?php if (isset($srf) && $srf=="3") echo "selected";?>>3</option>
</select> <?php if($srfErr!= ""){ ?>
        <p><b><?php echo $srfErr;  ?></b></p>
</div>
    <?php }?>
<input type="submit" name="submit" value="submit" />
</form>

Unified Process Phases

Inception

  • Inception is not a requirements phase; rather a feasibility phase, where just enough investigation is done to support a decision to continue or stop. –
  • The life-cycle objectives of the project are stated, so that the needs of every stakeholder are considered. Scope and boundary conditions, acceptance criteria and some requirements are established.
  • Approximate vision, business case, scope, vague estimates.

Inception - Activities

  •  Formulate the scope of the project: Needs of every stakeholder, scope, boundary conditions and acceptance criteria established.
  •  Plan and prepare the business case: Define risk mitigation strategy, develop an initial project plan and identify known cost, schedule, and profitability trade-offs.
  • Synthesize candidate architecture: Candidate architecture is picked from various potential architectures
  • Prepare the project environment

Inception - Exit criteria

  • An initial business case containing at least a clear formulation of the product vision - the core requirements - in terms of functionality, scope, performance, capacity, technology base.
  • Success criteria (example: revenue projection).
  • An initial risk assessment.
  • An estimate of the resources required to complete the elaboration phase.

Elaboration

  • An analysis is done to determine the risks, stability of vision of what the product is to become, stability of architecture and expenditure of resources. 
  • Refined vision, iterative implementation of core architecture, resolution of high risks, identification of most requirements and scope, more realistic estimates

Elaboration - Entry criteria

  • The products and artifacts described in the exit criteria of the previous phase. 
  • The plan approved by the project management, and funding authority, and the resources required for the elaboration phase have been allocated

Elaboration - Activities

  • Define the architecture: Project plan is defined. The process, infrastructure and development environment are described. 
  • Validate the architecture.  
  • Baseline the architecture: To provide a stable basis for the bulk of the design and implementation effort in the construction phase.

Elaboration - Exit criteria 
  • A detailed software development plan, with an updated risk assessment, a management plan, a staffing plan, a phase plan showing the number and contents of the iteration , an iteration plan, and a test plan
  • The development environment and other tools 
  • A baseline vision, in the form of a set of evaluation criteria for the final product.
  • A domain analysis model, sufficient to be able to call the corresponding architecture ‘complete’. 
  • An executable architecture baseline. 

Construction 

  • The Construction phase is a manufacturing process. It emphasizes managing resources and controlling operations to optimize costs, schedules and quality. This phase is broken into several iterations. 
  •  Iterative implementation of the remaining lower risk and easier elements, and preparation for deployment. 

Construction - Entry criteria 
  • The product and artifacts of the previous iteration. The iteration plan must state the iteration specific goals
  • Risks being mitigated during this iteration. 
  • Defects being fixed during the iteration. 

Construction - Activities 
  • Develop and test components: Components required satisfying the use cases, scenarios, and other functionality for the iteration are built. Unit and integration tests are done on Components. 
  • Manage resources and control process. 
  • Assess the iteration: Satisfaction of the goal of iteration is determined.

Construction - Exit Criteria 
  • The same products and artifacts, updated, plus
  • A release description document, which captures the results of an iteration 
  • Test cases and results of the tests conducted on the products
  • An iteration plan, detailing the next iteration 
  • Objective measurable evaluation criteria for assessing the results of the next iteration(s).  

Transition 

  • The transition phase is the phase where the product is put in the hands of its end users. It involves issues of marketing, packaging, installing, configuring, supporting the user. community, making corrections, etc. 
  • Beta tests, deployment. 

Transition - Entry criteria
  • The product and artifacts of the previous iteration, and in particular a software product sufficiently mature to be put into the hands of its users.

Transition - Activities  
  • Test the product deliverable in a customer environment. 
  • Fine tune the product based upon customer feedback 
  • Deliver the final product to the end user 
  • Finalize end-user support material.

Transition - Exit criteria 
  • An update of some of the previous documents, as necessary, the plan being replaced by a “post-mortem” analysis of the performance of the project relative to its original and revised success criteria; 
  • A brief inventory of the organization’s new assets as a result this cycle.