inc/toolkit.inc.php
changeset 29 e1c60f72d494
parent 23 4abaed69febd
child 32 0c2497c1ac01
equal deleted inserted replaced
28:a73ac0ba0401 29:e1c60f72d494
    86 
    86 
    87 /*
    87 /*
    88  * Display the alphabetic option: [0-9] [a] [b] .. [z]
    88  * Display the alphabetic option: [0-9] [a] [b] .. [z]
    89  */
    89  */
    90 
    90 
    91 function show_letters($letterstart,$doms)
    91 function show_letters($letterstart,$userid=true)
    92 {
    92 {
    93    foreach ($doms as $dom) {
    93         echo _('Show zones beginning with:') . "<br>";
    94       if (is_numeric($dom["name"][0])) {
    94 
    95          $letter_taken["0"] = 1;
    95 	$letter = "[[:digit:]]";
    96       } else {
    96 	if ($letterstart == "0")
    97          $letter_taken[$dom["name"][0]] = 1;
    97 	{
    98       }
    98 		echo "[ <span class=\"lettertaken\">0-9</span> ] ";
    99    }
    99 	}
   100 
   100 	elseif (zone_letter_start($letter,$userid))
   101    echo _('Show zones beginning with:') . "<br>";
   101 	{
   102    if ($letterstart == 1) {
   102 		echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=0\">0-9</a> ] ";
   103       echo "[ <b>0-9</b> ] ";
   103 	}
   104    } elseif ($letter_taken["0"] != 1) {
   104 	else
   105       echo "[ 0-9 ] ";
   105 	{
   106    } else {
   106 		echo "[ <span class=\"letternotavailble\">0-9</span> ] ";
   107       echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=1\">0-9</a> ] ";
   107 	}
   108    }
   108 
   109    
   109         foreach (range('a','z') as $letter)
   110    foreach (range('a','z') as $letter) {
   110         {
   111       if ($letterstart === $letter) {
   111                 if ($letter == $letterstart)
   112          echo "[ <span class=\"lettertaken\">".$letter."</span> ] ";
   112                 {
   113       } elseif ($letter_taken[$letter] != 1) {
   113                         echo "[ <span class=\"lettertaken\">".$letter."</span> ] ";
   114          echo "[ <span class=\"letternotavailble\">".$letter."</span> ] ";
   114                 }
   115       } else {
   115                 elseif (zone_letter_start($letter,$userid))
   116           echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=".$letter."\">".$letter."</a> ] ";
   116                 {
   117       }
   117                         echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?letter=".$letter."\">".$letter."</a> ] ";
   118    }
   118                 }
       
   119                 else
       
   120                 {
       
   121                         echo "[ <span class=\"letternotavailble\">".$letter."</span> ] ";
       
   122                 }
       
   123         }
       
   124 }
       
   125 
       
   126 function zone_letter_start($letter,$userid=true)
       
   127 {
       
   128         global $db;
       
   129         $sqlq = "SELECT domains.id AS domain_id,
       
   130         zones.owner,
       
   131         records.id,
       
   132         domains.name AS domainname
       
   133         FROM domains
       
   134         LEFT JOIN zones ON domains.id=zones.domain_id 
       
   135         LEFT JOIN records ON records.domain_id=domains.id
       
   136         WHERE 1";
       
   137         if((!level(5) || !$userid) && !level(10) && !level(5))
       
   138         {
       
   139                 $sqlq .= " AND zones.owner=".$_SESSION["userid"];
       
   140         }
       
   141         $sqlq .= " AND substring(domains.name,1,1) REGEXP '^".$letter."' LIMIT 1";
       
   142         $result = $db->query($sqlq);
       
   143         $numrows = $result->numRows();
       
   144         if ( $numrows == "1" ) 
       
   145         {
       
   146                 return 1;
       
   147         }
       
   148         else
       
   149         {
       
   150                 return 0;
       
   151         }
   119 }
   152 }
   120 
   153 
   121 /*
   154 /*
   122  * Print a nice useraimed error.
   155  * Print a nice useraimed error.
   123  */
   156  */