Wednesday, July 8, 2015

What are namespaces?

Namespacing does for functions and classes what scope does for variables. It allows you to use the same function or class name in different parts of the same program without causing a name collision.
In simple terms, think of a namespace as a person's surname. If there are two people named "John" you can use their surnames to tell them apart.

The Scenario

Suppose you write an application that uses a function named output(). Your output() function takes all of the HTML code on your page and sends it to the user.
Later on your application gets bigger and you want to add new features. You add a library that allows you to generate RSS feeds. This library also uses a function named output() to output the final feed.
When you call output(), how does PHP know whether to use your output() function or the RSS library's output() function? It doesn't. Unless you're using namespaces.

Example

How do we solve having two output() functions? Simple. We stick each output() function in its own namespace.
That would look something like this:
namespace MyProject;

function output() {
    # Output HTML page
    echo 'HTML!';
}

namespace RSSLibrary;

function output(){
    # Output RSS feed
    echo 'RSS!';
}
Later when we want to use the different functions, we'd use:
\MyProject\output();
\RSSLibrary\output();
Or we can declare that we're in one of the namespaces and then we can just call that namespace's output():
namespace MyProject;

output(); # Output HTML page
\RSSLibrary\output();

No Namespaces?

If we didn't have namespaces we'd have to (potentially) change a lot of code any time we added a library, or come up with tedious prefixes to make our function names unique. With namespaces, we can avoid the headache of naming collisions when mixing third-party code with our own projects.

Wednesday, July 1, 2015

Disabling a whole form with jQuery

// add the class "disabled" to the form
$("form.disabled").find("input:not(:disabled), select:not(:disabled), textarea:not(:disabled)").prop("disabled",true);

Tuesday, May 19, 2015

Dynamic Drag’n Drop With jQuery And PHP

how the drag'n drop & saving the new positions to the database was working".
Drag'n drop generally looks hard-to-apply but it is definitely not by using JavaScript frameworks. Here is, how it is done by using jQuery & jQuery UI:
jQuery Drag'n DropjQuery Drag'n Drop Demo
Download Link: Click Here to Download

The Database:

We create a simple database as below:
jQuery Drag'n Drop Database
The most important column in the database is recordListingID which shows us the order of the records.
This feature can be applied to any table by adding such a column to it.

The HTML:

We'll be using an unordered list that is generated from a PHP query that lists the items according to the recordListingID value mentioned above.
<div id="contentLeft">
 <ul>
  <li id="recordsArray_&lt;?php echo $row['recordID']; ?&gt;">&nbsp;</li>
 </ul>
</div>

The JavaScript:

We will be using jQuery UI's sortable plugin.
 <script type="text/javascript">
$(document).ready(function(){ 

 $(function() {
  $("#contentLeft ul").sortable({ opacity: 0.6, cursor: 'move', update: function() {
   var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
   $.post("updateDB.php", order, function(theResponse){
    $("#contentRight").html(theResponse);
   });
  }
  });
 });

});
</script>
We made the unordered list inside #contentLeft a sortable item, used theserialize function of jQuery to create the array and posted it to updateDB.php.

The PHP:

After posting the array of "new order of the items" to updateDB.php, we must run a query to update our database that will reflect the last positions of every item:
<?php
require("db.php");

$action = mysql_real_escape_string($_POST['action']);
$updateRecordsArray  = $_POST['recordsArray'];

if ($action == "updateRecordsListings"){

 $listingCounter = 1;
 foreach ($updateRecordsArray as $recordIDValue) {

  $query = "UPDATE records SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
  mysql_query($query) or die('Error, insert query failed');
  $listingCounter = $listingCounter + 1;
 }

 echo '<pre>';
 print_r($updateRecordsArray);
 echo '</pre>';
 echo 'If you refresh the page, you will see that records will stay just as you modified.';
}
?>

You can see that this is the easiest part. We handled the array as$updateRecordsArray and used it inside a for each statement.
With a new variable named $listingCounter, while the for each statement runs, we have updated the values of recordListingID column of every item in the database with $listingCounter values. And that's it.
Download Link: Click Here to Download

Monday, May 18, 2015

Filtering date values which are greater or less than a value in DHTMLX

Here is an implementation of a date range filter in a grid, the filter is applied by adding '#daterange_filter' to the relevant column in the attachHeader function call.

Note the date format for the calendar popups and the column is MM/DD/YYYY


dhtmlXGridObject.prototype._in_header_daterange_filter=function(a,b){
                        
      a.innerHTML="<div style='width:100%; margin:0 auto; text-align: left'>From:<input type='text' id='datefrom' style='width:80px;font-size:8pt;font-family:Tahoma;-moz-user-select:text;'><br>To:<input type='text' id='dateto' style='width:80px;font-size:8pt;font-family:Tahoma;-moz-user-select:text;'></div>";
   
      a.onclick=a.onmousedown=function(a){
         return(a||event).cancelBubble=!0
      };
      
      a.onselectstart=function(){
         return event.cancelBubble=!0
      };
            
      datefrom = getChildElement(a.firstChild,"datefrom");
      dateto = getChildElement(a.firstChild,"dateto");
      
      myCalendar = new dhtmlXCalendarObject([datefrom , dateto])
      myCalendar.setDateFormat("%m/%d/%Y");      //Date format MM/DD/YYY
      
      myCalendar.attachEvent("onClick",function(date){
           mygrid.filterByAll();
      })

      this.makeFilter(datefrom ,b);
      this.makeFilter(dateto ,b);
            
      datefrom._filter=function(){
         var a=this.value;
         return a==""?"":function(b){
            
            aDate = parseDate(a)
            bDate = parseDate(b)   
            return aDate <= bDate ;
            
         }
      }
      
      dateto._filter=function(){

         var a=this.value;
         return a==""?"":function(b){
            aDate = parseDate(a)
            bDate = parseDate(b)   
            return aDate >= bDate 
         }      
      }

      this._filters_ready()      
      
   };
   
   // parse a date in mm/dd/yyyy format
   function parseDate(input) {
     var parts = input.split('/');
   
     // new Date(year, month [, day [, hours[, minutes[, seconds[, ms]]]]])    
     return new Date(parts[2], parts[0]-1, parts[1]).getTime(); // Date format MM/DD/YYY
   }

   function getChildElement(element,id) {

      for (i=0;i<element.childNodes.length;i++)
      {
         if (element.childNodes[i].id == id)
            return element.childNodes[i];
      }
   
      return null
   }

Friday, May 15, 2015

Final Year Project Topics and Ideas

PHP Final Year Project Titles and Ideas:
Virtual Exam Controller
Dynamic College Information System & Online Examination
Ultimate Online Jobsite with Intelli Search Engine
Matrimonial and Marriage Information Services Implementation
Online Wedding Tracker, A service Providing Application for a Marriage from A to Z Options
Online Shopping with Shopping Cart
Online Auction with Featured Shopping Cart
For details please visit this link: http://final-year-projects.in/php-project-topics-ideas


ASP.Net Final Year Project Titles and Ideas:
Online Music download Store
Computer Store Management System
Job Portal
Library Management system
Online banking
Product Distributor Software
College Website
Dispensary Management System
Attendance Management System
Courier Management Service
E-Bazaar
For details please visit this link: http://final-year-projects.in/asp-net-project-topics-ideas

Monday, May 11, 2015

JQuery Validation for Array of Input Elements

Sometimes we need to validate an array of input elements: For example –
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<form name="signupForm" class="cmxform" id="signupForm" method="get" action="">
<select name="category[]" id="cat_1">
<option value="">Select One</option>
<option value="1">aa</option>
<option value="2">bb</option>
<option value="3">cc</option>
<option value="4">dd</option>
</select>
 
<select name="category[]" id="cat_2">
<option value="">Select One</option>
<option value="5">ee</option>
<option value="6">ff</option>
<option value="7">gg</option>
<option value="8">hh</option>
</select>
 
<select name="category[]" id="cat_3">
<option value="">Select One</option>
<option value="9">ii</option>
<option value="10">jj</option>
<option value="11">kk</option>
<option value="12">ll</option>
</select>
 
<input class="submit" type="submit" value="Submit">
</form>
Now we will use jquery validation plugin jquery.validate.js for validating the form. The condition will be that user will have to choose category from each dropdown. The script for validation will be as below –
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript">
$().ready(function() {
// validate the comment form when it is submitted
$("#signupForm").validate({
rules: {
"category[]": "required"
},
messages: {
"category[]": "Please select category",
}
});
});
</script>
Now the problem is that the readymade jquery.validate.js only validates the first element of category[]. So, we need to modify it a little bit.
In jquery.validate.js, we can find a function named checkForm, we have to modify it as below:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
checkForm: function() {
this.prepareForm();
for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
if (this.findByName( elements[i].name ).length != undefined && this.findByName( elements[i].name ).length > 1) {
for (var cnt = 0; cnt < this.findByName( elements[i].name ).length; cnt++) {
this.check( this.findByName( elements[i].name )[cnt] );
}
} else {
this.check( elements[i] );
}
}
return this.valid();
}

How to change the PHP version for subfolders or subdomains

  How to change the PHP version for subfolders or subdomains Setting a specific PHP version for a specific websites, subfolders or subdomain...