Saturday, November 29, 2014

Occupation's of Indian Professionals-Indian Professions

This is a dropdown list of professions of indians... Obviously they are different from professions in other countries at least in the names used...

<tr>
<td>Father's Occupation</td>
<td>
<select name="dropdown1">
<option value="Null" selected>Select an Occupation</option>
<option value="Business Person/Trader">Business Person/Trader</option>
<option value="Chartered Accountant">Chartered Accountant</option>
<option value="School/College/University Teacher">School/College/University Teacher</option>
<option value="Self-Employed">Self-Employed</option>
<option value="Doctor">Doctor</option>
<option value="Engineer">Engineer</option>
<option value="Farmer">Farmer</option>
<option value="Bank Employee">Bank Employee</option>
<option value="Government Service">Government Service</option>
<option value="House Wife">House Wife</option>
<option value="Journalist">Journalist</option>
<option value="Labour">Labour</option>
<option value="Lawyer">Lawyer</option>
<option value="Artist/Media/Entertainment">Artist/Media /Entertainment</option>
<option value="Police">Police</option>
<option value="Private Service">Private Service</option>
<option value="Retired">Retired</option>
<option value="Army/Navy/Airforce">Army/Navy/Airforce</option>
<option value="Official">Official</option>
<option value="Unemployed">Unemployed</option>
<option value="Others">Others</option>
</select>
</td>
</tr>

Most of the time we need to select one option based on the option posted in the database already. So this code will be useful:

<?php  $occupation=array('Select','Business Person-Trader','Chartered Accountant','School-College-University Teacher','Self-Employed','Doctor',
'Engineer','Farmer','Bank Employee','Government Service','House Wife','Journalist','Labour','Lawyer','Artist-Media-Entertainment',
'Police','Private Service','Retired','Army-Navy-Airforce','Official','Unemployed','Others','Reporter');
        $year=array('1990','1991','1992','1993','1994','1995','1996','1997','1998',
'1999','2000','2001','2002','2003','2004','2005','2006',
'2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017',
'2018','2019');
        $relation=array('Aunty/Uncle','PG Tenant','Close Relative','Family Friend','Others');
?>

followed by for fathers occupation:(where $row2[6] is fetched from the database)

<label for="focc">Father's Occupation</label>
<select name="focc" id="focc" value='<?php echo $row2[6];?>'>
<?php

for($i=0;$i<count($occupation);$i++)
{
if($occupation[$i]==$row2[6]) $sel="selected"; else $sel=" ";
echo "<option value='".$occupation[$i]."' ".$sel.">".$occupation[$i]."</option>";
}
?>
</select>

Sunday, November 23, 2014

Checkbox handling in PhP for entering absentees

The interface that i showed earlier is quite rudimentary and we need something more sophisticated. Something like making a student absent on any day any hour using a single interface. So i experimented with a checkbox input.

We separated out the database access credentials and wrote a config.php file
---------------------------------
<?php
 $username="root";
$password="cec123";
$database="cec";
 ?>

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

Then we wrote a simple1.html file which takes in details like semester number branch and section.
Looks like this:
-----------------------------------------------------------------------------------------------
<html>
<form name="formName" action="accessdbase2.php">
<input type="radio" name="sem" value="1">1
<input type="radio" name="sem" value="2">2
<input type="radio" name="sem" value="3">3
<input type="radio" name="sem" value="4">4
<input type="radio" name="sem" value="5">5
<input type="radio" name="sem" value="6">6
<input type="radio" name="sem" value="7">7
<input type="radio" name="sem" value="8">8
<select name="dept">
  <option value="cs">cs</option>
  <option value="ec">ec</option>
  <option value="is">is</option>
  <option value="me">me</option>
  <option value="cv">cv</option>
</select>
<input type="radio" name="sec" value="a">a
<input type="radio" name="sec" value="b">b
<input type="submit" value="Submit">
</form>
</html>
 ----------------------------------------------------------------------------------
This html page submits to accessdbase2.php
-----------------------------------------------------------------------------------
<html>

<h1>Hello!</h1>
<form name="formName" action="accessdbase3.php" method="post" style="width:800px;">
<table border="1">
<tr><td>USN-Student Name</td><td>1</td><td>2</td><tr>
<?php
ob_start();
require("config.php");
ob_end_clean();

$req=$_REQUEST['sem'];
$req2=$_REQUEST['dept'];
$req3=$_REQUEST['sec'];
$con=mysqli_connect("localhost",$username,$password,$database);

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$query="SELECT * FROM students WHERE sem='$req' AND dept='$req2' AND sec='$req3'";

$result = mysqli_query($con,$query);

while($row = mysqli_fetch_array($result))
  {
  echo "<tr><td> ";echo"{$row['USN']}-{$row['student_name']} </td> <td><input name='attend1[]' type='checkbox' checked value='{$row['USN']}'></td><td><input name='attend2[]' type='checkbox' value='{$row['USN']}'></td></tr>";
  }

mysqli_close($con);
?>

</table>
<input type="submit" name="submit" id="submit" value="Submit">
</form>
</html>
 ----------------------------------------------------------------------------------------------

This accessdbase2.php looks like this:
 It Submits to the accessdbase3.php which looks like this:

----------------------------------------------------------------------------------------------
Here is accessdbase3.php code:(Which illustrates handling checkboxes)
----------------------------------------------------------------------------------------------
 <?php
ob_start();
require("config.php");
ob_end_clean();
$absentees = $_POST['attend1'];
  if(empty($absentees))
  {
    echo("You didn't select any absentees.");
  }
  else
  {
    $N = count($absentees);

    echo("You selected $N absentee(s): ");
    for($i=0; $i < $N; $i++)
    {
      echo($absentees[$i] . " ");
    }
  }
?>
-------------------------------------------------------------------------------------------------

Thanks... your best wishes are with us.

Php and javascript in a multi select box to move students into absentee list

The second task was also quite simple as you may be wondering. We needed to have a box in which student USN and names appear and another box into which we needed to transfer these students. Google helped us out again.

We have the following php script...
------------------------------------------------------
<html>
<script language="JavaScript"><!--
function populateForm() {
    for (var Current=0;Current < document.formName.selectName1.options.length;Current++) {
        if (document.formName.selectName1.options[Current].selected) {
            var defaultSelected = true, selected = true;
            var optionName = new Option(document.formName.selectName1.options[Current].value, document.formName.selectName1.options[Current].text, defaultSelected, selected)
            if (replacedfirst)
                var length = document.formName.selectName2.length;
            else
                var length = 0;
            document.formName.selectName2.options[length] = optionName;
            replacedfirst = true;
        }
    }
}
var replacedfirst = false;
</script>
<form name="formName" onSubmit="return false;">
<select name="selectName1" multiple size="3">
</select>
<input type="button" value="Enter" onClick="populateForm()">
<select name="selectName2" multiple size="3">
<option value="">          
</select>
</form>
</html>
----------------------------------------------

The following was the output:
As you may see the interface is quite simple and elegant. A faculty is required to make a list of students who are absent and submit it to the database. Where php comes in this you may be wondering. It comes when you query the database to populate the student list in the first box. I will soon post the code for that too.

Saturday, November 22, 2014

Php script to access database and display values

The first task we faced was to flex our muscles and access mysql database and to display the values in the form of a table.

We found out from google and wrote this program:

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'cec123';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT USN,student_name FROM students';

mysql_select_db('cec');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
    echo "USN :{$row['USN']}  <br> ".
         "Student Name {$row['student_name']} <br> ";
}
echo "Fetched data successfully!!!!!!!!!\n";
mysql_close($conn);
?>

The output of this program thrilled us. It was a start which we desperately needed.
In the browser
Here it was:
USN :1ce10cs001
Student Name Mukesh
USN :1ce10cs002
Student Name Suresh
USN :1ce10cs003
Student Name Ravi
USN :1ce11ec003
Student Name Satish
USN :1ce11ec002
Student Name Sunil
USN :1ce11ec001
Student Name Sowmya
Fetched data successfully!!!!!!!!!

Attendance Module for Automation at City Engineering College







The automation project on attendance started in our college by the active involvement and support of Dr. S. Balaji and my colleague Vivekavardhana Reddy. Also present in the team were me, Ramesh Babu along with Nallamma and Suma Manjunath. We as a team worked under the guidance of Balaji sir. We developed a small webpage to enter every days attendance into a database.


Every faculty had to write on a slip the student USN's who were absent on a particular day on a particular hour. Information in these slips were to be entered into a database using this interface on the same day.


Our webpage is almost ready except for minor changes in looks or features.






We intend to publish this package to the open source community so that it could be used by other colleges. I still need to figure out how to publish software as a package/application.

Final modification to our project was to make it work on the mobile so that the faculty can enter the attendance in his tablet or handheld. We also have capability to send sms to parents everyday about the attendance of their sons/daughters.

Key Takeaways:

If you go through these pages you will get an idea of creating a website of your own or a similar website for an ERP package. Alternatively you could get involved and help us in developing this package further.

Learnings:
Looking back at the project and its complexities if i were given another chance to develop this package what were the things i would have done differently?
1) Low entry barriers: An ERP package for educational institutions is surprisingly simple to develop. Although several features like accounting package or interface to our website with it is still lacking, we were quite capable of doing that.
2) Using the wrong model: I see that we kept learning the language and the database interfacing as we developed the code. At some point in time after learning enough, we should have taken a decision to refurbish the software entirely. i.e discarded the entire code and started from scratch with a new design. We kept on modifying legacy code iteratively. We should have gone back to the design board and think big. "See now we have learn't something useful. Lets make something big and useful out of it". It requires audacity and courage to venture afresh. We knew our software would not be 100% success. We should have tried to take failure in our stride and achieve 100% reliable code. In software projects the pain of developing software and the experience is what remains with you. Your code might not be with you after some time but if given another opportunity you know you can do it again and much better.
3) Faulty database schema: Our initial database schema was incapable of handling new requirements. We had to go back to design and develop a new database schema(it never occurred). Instead of discussing the disagreements openly we kept skirting the issues until it blew out of proportion. We consoled ourselves that ours was a project to learn something. We did not intend to develop production level code. At-least we thought so. But the expectation was for a package which would satisfy all requirements.
4) Inadequate testing: We should have devoted some time to discuss future problems that may arise and to keep an eye on the scope of the project. Lack of rigorous testing can also be counted as one of the drawbacks in our package. There were many anxious moments and considering inadequate manpower we were handicapped.
5) Job Security: We were teachers basically and somehow we thought our jobs would not go away if we fail.