неділя, 7 листопада 2010 р.

Drupal main parts

Module

A module is software (code) that extends Drupal features and/or functionality. Core modules are those included with the main download of Drupal.

User, Permission, Role

Every visitor to site, whether they have an account and log in or visit the site anonymously, is considered a user to Drupal. Each user has a numeric user ID, and non-anonymous users also have a user name and an email address.

Node

A node in Drupal is the generic term for a piece of content on web site.

Also there are: Comment, Taxonomy, Database, Path, Theme, Region, Block, Menu.

пʼятниця, 5 листопада 2010 р.

Sajax

Sajax is a tool to make programming websites using the Ajax framework — also known as XMLHTTPRequest or remote scripting — as easy as possible. Sajax makes it easy to call ASP, Cold Fusion, Io, Lua, Perl, PHP, Python or Ruby functions from your webpages via JavaScript without performing a browser refresh

четвер, 4 листопада 2010 р.

Paginating

It is famous function for pagination. CSS allows display links in more convenient form.
.page {
    border:1px solid #BFBFBF;
    font-weight: bold;
    margin:2px;
padding:3px 5px;
text-decoration:none;
}

a.page:link {color:#505050;}    /* unvisited link */
a.page:visited {color:#505050;} /* visited link */
a.page:hover {border-color:black;color:#2554C7;}   /* mouse over link */
function pagination($total_pages,$page){

    global $webpage;

    $pagination = '<div class="page_numbers">';
                   
    if($total_pages!=1){
   
        //the total links visible
         
        $max_links=10;
       
       
        //$max links_marker is the top of the loop
        //$h is the start
       
        $max_links_marker = $max_links+1;           
        $h=1;           
       
       
        //$link_block is the block of links on the page
        //When this is an integer we need a new block of links
                 
        $link_block=(($page-1)/$max_links);
       
        //if the page is greater than the top of th loop and link block
        //is an integer
       
        if(($page>=$max_links_marker)&&(is_int($link_block))){
       
                //reset the top of the loop to a new link block
       
            $max_links_marker=$page+$max_links;
           
                //and set the bottom of the loop        
           
            $h=$max_links_marker-$max_links;
            $prev=$h-1;                                                                   
        }
       
            //if not an integer we are still within a link block
       
        elseif(($page>=$max_links_marker)&&(!is_int($link_block))){
           
                //round up the link block
           
            $round_up=ceil($link_block);
                   
            $new_top_link = $round_up*$max_links;
           
                //and set the top of the loop to the top link
           
            $max_links_marker=$new_top_link+1;
           
                //and the bottom of the loop to the top - max links
           
            $h=$max_links_marker-$max_links;
            $prev=$h-1;                           
        }
       
          //if greater than total pages then set the top of the loop to
          // total_pages
       
        if($max_links_marker>$total_pages){
            $max_links_marker=$total_pages+1;
        }
       
            //first and prev buttons
       
        if($page>'1'){
            $pagination.='<a class="page" href="'.$webpage.'?page=1">First</a>
            <a class="page" href="'.$webpage.'?page='.($page-1).'">Prev</a>';
        }
       
            //provide a link to the previous block of links
       
       
        $prev_start = $h-$max_links;
        $prev_end = $h-1;
        if($prev_start <=1){
            $prev_start=1;
        }
        $prev_block = "Pages $prev_start to $prev_end";
       
        if($page>$max_links){
            $pagination.='<a class="page" href="'.$webpage.'?page='.$prev.'">'.$prev_block.'</a>';
        }
       
            //loop through the results
           
        for ($i=$h;$i<$max_links_marker;$i++){
            if($i==$page){
                $pagination.= '<a class="current">'.$i.'</a>';
            }
            else{
                $pagination.= '<a class="page" href="'.$webpage.'?page='.$i.'">'.$i.'</a>';
            }
        }
            //provide a link to the next block o links
       
        $next_start = $max_links_marker;
        $next_end = $max_links_marker+$max_links;
        if($next_end >=$total_pages){
            $next_end=$total_pages;
        }
        $next_block = "Pages $next_start to $next_end";
        if($total_pages>$max_links_marker-1){
            $pagination.='<a class="page" href="'.$webpage.'?page='.$max_links_marker.'">'.$next_block.'</a>';
        }
       
          //link to next and last pages
       
       
        if(($page >="1")&&($page!=$total_pages)){
            $pagination.='<a class="page" href="'.$webpage.'?page='.($page+1).'">Next</a>
                  <a class="page" href="'.$webpage.'?page='.$total_pages.'">Last</a>';
        }
    }
   
    //if one page of results
   
    else{
      $pagination.='<a class="page" href="" class="current">1</a>';
    }
    $pagination.='
        </div>';
   
    return($pagination);
}

вівторок, 2 листопада 2010 р.

Control IP against subnet

For developing web interface for control network with near 100 computers was need validate IP address of server against subnet .
The base of this function I found in internet, so only add control if  IP iscorrect:
function checkIpAgainstNetwork($ip,$network,&$error){
    //first need found Classe and Subnet
    $errore="";
    $connect = connectDB_connection_link($connect);
    $query_net=" select class,subnet from network where nome='".$network."'";
    $res1 = mysqli_query($connect,$query_net);
    $row = mysqli_fetch_assoc($res1);
    $class=$row["class"];
    $subnet=$row["subnet"];
    disconnectDB($connect);
    //ok, now need found first and last host ip
    $dqs=array(0=>$class,1=>$subnet);
    $dq_host=$dqs[0];
    $bin_nmask=dqtobin($dqs[1]);
    $bin_wmask=binnmtowm($bin_nmask);

    if (ereg("0",rtrim($bin_nmask, "0"))) { 
        $bin_wmask=dqtobin($dqs[1]);
        $bin_nmask=binwmtonm($bin_wmask);

        if (ereg("0",rtrim($bin_nmask, "0"))){
            $errore .= "Invalid subnet.<br>";
        }
    }
    $cdr_nmask=bintocdr($bin_nmask);

    //Check for valid $dq_host
    if(! ereg('^0.',$dq_host)){
        foreach( explode(".",$dq_host) as $octet ){
            if($octet > 255){
                $errore .= "Invalid IP Address";
            }

        }
    }

    $bin_host=dqtobin($dq_host);

    $bin_bcast=(str_pad(substr($bin_host,0,$cdr_nmask),32,1));

    $bin_net=(str_pad(substr($bin_host,0,$cdr_nmask),32,0));
    $bin_first=(str_pad(substr($bin_net,0,31),32,1));
    $bin_last=(str_pad(substr($bin_bcast,0,31),32,0));

    $dec_last=bintodq($bin_last);
    $dec_first=bintodq($bin_first);
    //now need check each octet to be not less than first and not more than last
   
    $array_octet_ip=explode(".",$ip);
    $array_octet_first=explode(".",$dec_first);
    $array_octet_last=explode(".",$dec_last);

    if (($array_octet_ip[0]<$array_octet_first[0]) or ($array_octet_ip[0]>$array_octet_last[0])){
        $errore .= "IP is not valid. Range is   $dec_first a $dec_last";
    }
    else if (($array_octet_ip[1]<$array_octet_first[1]) or ($array_octet_ip[1]>$array_octet_last[1])){
        $errore .= "IP is not valid. Range is   $dec_first a $dec_last";
    }
    else if (($array_octet_ip[2]<$array_octet_first[2]) or ($array_octet_ip[2]>$array_octet_last[2])){
        $errore .= "IP is not valid. Range is   $dec_first a $dec_last";
    }
    else if (($array_octet_ip[3]<$array_octet_first[3]) or ($array_octet_ip[3]>$array_octet_last[3])){
        $errore .= "IP is not valid. Range is   $dec_first a $dec_last";
    }

    if ($errore<>""){
        return false;
    }else{
        return true;
    }
}

First post

This is my first post. this blog dedicated some tricks in programming that are needed to make a work.