inc/toolkit.inc.php
changeset 82 c255196bc447
parent 79 0c0aa144356a
child 90 d7bee09d98fe
equal deleted inserted replaced
81:c72d6d51f3d3 82:c255196bc447
    18  *  You should have received a copy of the GNU General Public License
    18  *  You should have received a copy of the GNU General Public License
    19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    20  */
    20  */
    21 
    21 
    22 session_start();
    22 session_start();
    23 
       
    24 
    23 
    25 
    24 
    26 if(!@include_once("config.inc.php"))
    25 if(!@include_once("config.inc.php"))
    27 {
    26 {
    28 	error( _('You have to create a config.inc.php!') );
    27 	error( _('You have to create a config.inc.php!') );
    77 require_once("i18n.inc.php");
    76 require_once("i18n.inc.php");
    78 require_once("users.inc.php");
    77 require_once("users.inc.php");
    79 require_once("dns.inc.php");
    78 require_once("dns.inc.php");
    80 require_once("record.inc.php");
    79 require_once("record.inc.php");
    81 
    80 
       
    81 $db = dbConnect();
       
    82 doAuthenticate();
       
    83 
    82 
    84 
    83 /*************
    85 /*************
    84  * Functions *
    86  * Functions *
    85  *************/
    87  *************/
    86 
    88 
    90 
    92 
    91 function show_pages($amount,$rowamount,$id='')
    93 function show_pages($amount,$rowamount,$id='')
    92 {
    94 {
    93    if ($amount > $rowamount) {
    95    if ($amount > $rowamount) {
    94       if (!isset($_GET["start"])) $_GET["start"]=1;
    96       if (!isset($_GET["start"])) $_GET["start"]=1;
    95       echo _('Show page') . "<br>";
    97       echo _('Show page') . ":<br>";
    96       for ($i=1;$i<=ceil($amount / $rowamount);$i++) {
    98       for ($i=1;$i<=ceil($amount / $rowamount);$i++) {
    97          if ($_GET["start"] == $i) {
    99          if ($_GET["start"] == $i) {
    98             echo "[ <b>".$i."</b> ] ";
   100             echo "[ <b>".$i."</b> ] ";
    99          } else {
   101          } else {
   100             echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?start=".$i;
   102             echo "[ <a href=\"".$_SERVER["PHP_SELF"]."?start=".$i;
   109  * Display the alphabetic option: [0-9] [a] [b] .. [z]
   111  * Display the alphabetic option: [0-9] [a] [b] .. [z]
   110  */
   112  */
   111 
   113 
   112 function show_letters($letterstart,$userid=true)
   114 function show_letters($letterstart,$userid=true)
   113 {
   115 {
   114         echo _('Show zones beginning with:') . "<br>";
   116         echo _('Show zones beginning with') . ":<br>";
   115 
   117 
   116 	$letter = "[[:digit:]]";
   118 	$letter = "[[:digit:]]";
   117 	if ($letterstart == "1")
   119 	if ($letterstart == "1")
   118 	{
   120 	{
   119 		echo "[ <span class=\"lettertaken\">0-9</span> ] ";
   121 		echo "[ <span class=\"lettertaken\">0-9</span> ] ";
   146 
   148 
   147 function zone_letter_start($letter,$userid=true)
   149 function zone_letter_start($letter,$userid=true)
   148 {
   150 {
   149         global $db;
   151         global $db;
   150 	global $sql_regexp;
   152 	global $sql_regexp;
   151         $sqlq = "SELECT domains.id AS domain_id,
   153         $query = "SELECT 
   152         zones.owner,
   154 			domains.id AS domain_id,
   153         records.id,
   155 			zones.owner,
   154         domains.name AS domainname
   156 			records.id,
   155         FROM domains
   157 			domains.name AS domainname
   156         LEFT JOIN zones ON domains.id=zones.domain_id 
   158 			FROM domains
   157         LEFT JOIN records ON records.domain_id=domains.id
   159 			LEFT JOIN zones ON domains.id=zones.domain_id 
   158         WHERE 1=1";
   160 			LEFT JOIN records ON records.domain_id=domains.id
   159         if((!level(5) || !$userid) && !level(10) && !level(5))
   161 			AND substring(domains.name,1,1) ".$sql_regexp." ".$db->quote("^".$letter);
   160         {
   162 	$db->setLimit(1);
   161 		// First select the zones for which we have ownership on one or more records.
   163         $result = $db->query($query);
   162 		$query = 'SELECT records.domain_id FROM records, record_owners WHERE user_id = '.$db->quote($_SESSION['userid']).' AND records.id = record_owners.record_id';
       
   163 		$result = $db->query($query);
       
   164 		$zones = array();
       
   165 		if (!PEAR::isError($result)) {
       
   166 			$zones = $result->fetchCol();
       
   167 		}
       
   168 	
       
   169                 $sqlq .= " AND (zones.owner=".$db->quote($_SESSION["userid"]);
       
   170 		if (count($zones) > 0) {
       
   171 			$sqlq .= ' OR zones.domain_id IN ('.implode(',', $zones).') '; 
       
   172 
       
   173 		}
       
   174 		$sqlq .= ')';
       
   175         }
       
   176         $sqlq .= " AND substring(domains.name,1,1) ".$sql_regexp." ".$db->quote("^".$letter);
       
   177 		$db->setLimit(1);
       
   178         $result = $db->query($sqlq);
       
   179         $numrows = $result->numRows();
   164         $numrows = $result->numRows();
   180         if ( $numrows == "1" ) 
   165         if ( $numrows == "1" ) {
   181         {
       
   182                 return 1;
   166                 return 1;
   183         }
   167         } else {
   184         else
       
   185         {
       
   186                 return 0;
   168                 return 0;
   187         }
   169         }
   188 }
   170 }
   189 
   171 
   190 /*
   172 function error($msg) {
   191  * Print a nice useraimed error.
   173 	if ($msg) {
   192  */
   174 		echo "     <div class=\"error\">Error: " . $msg . "</div>\n";
   193 function error($msg)
   175 	} else {
   194 {
   176 		echo "     <div class=\"error\">" . _('An unknown error has occurred.') . "</div>\n"; 
   195 	// General function for printing critical errors.
   177 	}
   196 	if ($msg)
   178 }
   197 	{
   179 
   198 		include_once("header.inc.php");
   180 function success($msg) {
   199 	?>
   181 	if ($msg) {
   200 	<p><?php echo _('Oops! An error occured!'); ?></p>
   182 		echo "     <div class=\"success\">" . $msg . "</div>\n";
   201 	<p><?php echo nl2br($msg) ?></p>
   183 	} else {
   202 	<?php
   184 		echo "     <div class=\"success\">" . _('Something has been successfully performed. What exactly, however, will remain a mystery.') . "</div>\n"; 
   203 		include_once("footer.inc.php");
   185 	}
   204 		die();
   186 }
   205 	}
   187 
   206 	else
       
   207 	{
       
   208 		include_once("footer.inc.php");
       
   209 		die("No error specified!");
       
   210 	}
       
   211 }
       
   212 
   188 
   213 /*
   189 /*
   214  * Something has been done nicely, display a message and a back button.
   190  * Something has been done nicely, display a message and a back button.
   215  */
   191  */
   216 function message($msg)
   192 function message($msg)
   266 		header("Location: $arg$add".time());
   242 		header("Location: $arg$add".time());
   267 		exit;
   243 		exit;
   268 	}
   244 	}
   269 }
   245 }
   270 
   246 
   271 function level($l)
       
   272 {
       
   273 	if ($_SESSION["level"] >= $l)
       
   274 	{
       
   275 		return 1;
       
   276 	}
       
   277 	else
       
   278 	{
       
   279 		return 0;
       
   280 	}
       
   281 }
       
   282 
       
   283 function xs($zoneid)
       
   284 {
       
   285 	global $db;
       
   286 	if (is_numeric($zoneid) && is_numeric($_SESSION["level"]))
       
   287 	{
       
   288 		$result = $db->query("SELECT id FROM zones WHERE owner=".$db->quote($_SESSION["userid"])." AND domain_id=".$db->quote($zoneid));
       
   289 		$db->setLimit(1);
       
   290 		$result_extra = $db->query("SELECT record_owners.id FROM record_owners,records WHERE record_owners.user_id=".$db->quote($_SESSION["userid"])." AND records.domain_id = ".$db->quote($zoneid)." AND records.id = record_owners.record_id");
       
   291 
       
   292                 if ($result->numRows() == 1 || $_SESSION["level"] >= 5)
       
   293                 {
       
   294 			$_SESSION[$zoneid."_ispartial"] = 0;
       
   295 			return true;
       
   296 		}
       
   297 		elseif ($result_extra->numRows() == 1)
       
   298 		{
       
   299 			$_SESSION[$zoneid."_ispartial"] = 1;
       
   300 			return true;
       
   301 		}
       
   302 		else
       
   303 		{
       
   304 			return false;
       
   305 		}
       
   306 	}
       
   307 	else
       
   308 	{
       
   309         	return false;
       
   310         }
       
   311 }
       
   312 
   247 
   313 function get_status($res)
   248 function get_status($res)
   314 {
   249 {
   315 	if ($res == '0')
   250 	if ($res == '0')
   316 	{
   251 	{
   342 	{
   277 	{
   343 		return false;
   278 		return false;
   344 	}
   279 	}
   345 	return true;
   280 	return true;
   346 }
   281 }
       
   282 
       
   283 
       
   284 function v_num($string) {
       
   285 	if (!eregi("^[0-9]+$", $string)) { 
       
   286 		return false ;
       
   287 	} else {
       
   288 		return true ;
       
   289 	}
       
   290 }
       
   291 
       
   292 function debug_r($array) {
       
   293 	echo "<pre style=\"border: 2px solid blue;\">\n";
       
   294 	print_r($array);
       
   295 	echo "</pre>\n";
       
   296 }
       
   297 
   347 ?>
   298 ?>