PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/class/class.install.php

http://freshdns.googlecode.com/
PHP | 112 lines | 97 code | 15 blank | 0 comment | 1 complexity | d5b95fbb038ca723d3a3958f3903dd8b MD5 | raw file
  1<?
  2class install 
  3{
  4	private $database;
  5	
  6	function __construct($database)
  7	{
  8		$this->database = $database;
  9	}
 10	
 11	function pdns_sql ()
 12	{
 13		$query = array();
 14		$query[] = "CREATE TABLE IF NOT EXISTS domains (
 15		 id		 INT auto_increment,
 16		 name		 VARCHAR(255) NOT NULL,
 17		 master		 VARCHAR(20) DEFAULT NULL,
 18		 last_check	 INT DEFAULT NULL,
 19		 type		 VARCHAR(6) NOT NULL,
 20		 notified_serial INT DEFAULT NULL, 
 21		 account         VARCHAR(40) DEFAULT NULL,
 22		 primary key (id)
 23		)type=InnoDB;";
 24		
 25		$query[] = "CREATE UNIQUE INDEX name_index ON domains(name);";
 26		
 27		$query[] = "CREATE TABLE IF NOT EXISTS records (
 28		  id              INT auto_increment,
 29		  domain_id       INT DEFAULT NULL,
 30		  name            VARCHAR(255) DEFAULT NULL,
 31		  type            VARCHAR(6) DEFAULT NULL,
 32		  content         VARCHAR(255) DEFAULT NULL,
 33		  ttl             INT DEFAULT NULL,
 34		  prio            INT DEFAULT NULL,
 35		  change_date     INT DEFAULT NULL,
 36		  primary key(id)
 37		)type=InnoDB;";
 38		
 39		$query[] = "CREATE INDEX rec_name_index ON records(name);";
 40		$query[] = "CREATE INDEX nametype_index ON records(name,type);";
 41		$query[] = "CREATE INDEX domain_id ON records(domain_id);";
 42		
 43		$query[] = "CREATE TABLE IF NOT EXISTS supermasters (
 44		  ip VARCHAR(25) NOT NULL, 
 45		  nameserver VARCHAR(255) NOT NULL, 
 46		  account VARCHAR(40) DEFAULT NULL
 47		);";
 48		
 49		foreach($query AS $Q)
 50		{
 51			@$this->database->query_master($Q);
 52		}
 53	}
 54	
 55	function padmin_sql ()
 56	{
 57		$query = array();
 58		
 59		$query[] = "CREATE TABLE IF NOT EXISTS `record_owners` (
 60		  `id` int(11) NOT NULL auto_increment,
 61		  `user_id` int(11) NOT NULL default '0',
 62		  `record_id` int(11) NOT NULL default '0',
 63		  PRIMARY KEY  (`id`)
 64		) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
 65		
 66		$query[] = "CREATE TABLE IF NOT EXISTS `users` (
 67		  `id` int(11) NOT NULL auto_increment,
 68		  `username` varchar(16) NOT NULL default '',
 69		  `password` varchar(34) NOT NULL default '',
 70		  `fullname` varchar(255) NOT NULL default '',
 71		  `email` varchar(255) NOT NULL default '',
 72		  `description` text NOT NULL,
 73		  `level` tinyint(3) NOT NULL default '0',
 74		  `active` tinyint(1) NOT NULL default '0',
 75		  PRIMARY KEY  (`id`)
 76		) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
 77		
 78		$query[] = "CREATE TABLE IF NOT EXISTS `zones` (
 79		  `id` int(11) NOT NULL auto_increment,
 80		  `domain_id` int(11) NOT NULL default '0',
 81		  `owner` int(11) NOT NULL default '0',
 82		  `comment` text,
 83		  PRIMARY KEY  (`id`)
 84		) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
 85		
 86		foreach($query AS $Q)
 87		{
 88			$this->database->query_master($Q) or die ($this->database->error());
 89		}
 90	}
 91	
 92	function zonelessdomains ()
 93	{
 94		$query = "SELECT d.id FROM domains d
 95		LEFT OUTER JOIN zones z ON z.domain_id=d.id;";
 96		$query = $this->database->query_master($query) or die ($this->database->error());
 97		
 98		if($this->database->num_rows($query)==0)
 99		{
100			return '';
101		}else
102		{
103			while($record=$this->database->fetch_array($query))
104			{
105				$return[] = $record;
106			}
107		
108			return $return;
109		}
110	}
111}
112?>