File: modifydnsrecord.php

package info (click to toggle)
ipplan 4.92a-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,256 kB
  • ctags: 11,121
  • sloc: php: 44,277; sh: 387; perl: 257; xml: 97; makefile: 57; sql: 32
file content (718 lines) | stat: -rwxr-xr-x 26,652 bytes parent folder | download
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
<?php

// IPplan v4.92a
// Aug 24, 2001
//
// Modified by Tony D. Koehn February 2003
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

require_once("../ipplanlib.php");
require_once("../adodb/adodb.inc.php");
require_once("../class.dbflib.php");
require_once("../layout/class.layout");
require_once("../auth.php");
require_once("../class.xptlib.php");

define("FQDNHNAMEREGEX", '/^(([\w][\w\-\.]*)\.)?([\w][\w\-]+)(\.([\w][\w\.]*))?\.?$/');

$auth = new SQLAuthenticator(REALM, REALMERROR);

// And now perform the authentication
$grps=$auth->authenticate();

// set language
isset($_COOKIE["ipplanLanguage"]) && myLanguage($_COOKIE['ipplanLanguage']);

//setdefault("window",array("bgcolor"=>"white"));
//setdefault("table",array("cellpadding"=>"0"));
//setdefault("text",array("size"=>"2"));

$title=my_("Zone Domain DNS Records");
newhtml($p);
$w=myheading($p, $title, true);

// explicitly cast variables as security measure against SQL injection
list($action, $domain, $cust, $host, $recordtype, $iphostname, $sortorder, $descrip, $expr, $block, $ipplanParanoid) = myRegister("S:action S:domain I:cust S:host S:recordtype S:iphostname S:sortorder S:descrip S:expr I:block I:ipplanParanoid");

// save the last customer used
// must set path else Netscape gets confused!
setcookie("ipplanCustomer","$cust",time() + 10000000, "/");

$formerror="";
if ($action=="delete") {
    if (is_array($dataid)) {
        foreach($dataid as $key => $value) {
            $dataid[$key]=floor($value);
        }
    }
    else {
        $dataid=array(0=>$dataid);
    }
    // user hit submit without selecting anything!
    if (empty($dataid[0])) {
        $action="";
    }
}
else {
    $dataid=isset($dataid) ? floor($dataid) : 0;
}

// basic sequence is connect, search, interpret search
// result, close connection
$ds=new IPplanDbf() or myError($w,$p, my_("Could not connect to database"));

// CHECK Actions First

// ##################### Start OF DELETE ##############################
if ($action=="delete") {
    if (!$dom_id=$ds->ds->GetOne("SELECT data_id
                FROM fwdzone
                WHERE customer=$cust AND domain=".$ds->ds->qstr($domain))) {
        myError($w,$p, my_("Could not find the zone - possibly deleted by another user"));
    }

    // check if user belongs to customer admin group
    $result=$ds->GetCustomerGrp($cust);
    // can only be one row - does not matter if nothing is 
    // found as array search will return false
    $row = $result->FetchRow();
    if (!in_array($row["admingrp"], $grps)) {
        myError($w,$p, my_("You may not delete dns records as you are not a member of the customers admin group"));
    } 

    // Log the Transaction.
    $ds->DbfTransactionStart();
    foreach ($dataid as $value) {
        // missing records will just get ignored
        if ($row=$ds->ds->GetRow("SELECT recidx, error_message, ip_hostname, host
            FROM fwdzonerec 
            WHERE customer=$cust AND recidx=".$value )) {

            // update IP record if deleting auto A record
            if ($row["error_message"]=="A") {
                // found a subnet? Maybe it has been deleted!
                if ($result=$ds->GetBaseFromIp(inet_aton($row["ip_hostname"]), $cust)) {
                    $row1 = $result->FetchRow();
                    $baseindex=$row1["baseindex"];

                    $ds->ds->Execute("UPDATE ipaddr
                            SET hname=".$ds->ds->qstr($row["host"])."
                            WHERE baseindex=$baseindex AND ipaddr=".inet_aton($row["ip_hostname"]));
                    insert($w,textbr(sprintf(my_("IP record %s updated in subnet '%s' due to deletion of auto created A record"), $row["ip_hostname"], $row1["descrip"])));
                }
            }
            $result = &$ds->ds->Execute("DELETE FROM fwdzonerec 
                    WHERE customer=$cust AND recidx=$value") and
            $ds->ds->Execute("UPDATE fwdzone 
                    SET error_message=".$ds->ds->qstr("E").",
                    lastmod=".$ds->ds->DBTimeStamp(time()).
                    " WHERE customer=$cust AND data_id=".$dom_id) and 
            $ds->AuditLog(array("event"=>120, "action"=>"delete zone record", "cust"=>$cust,
                            "user"=>getAuthUsername(), "id"=>$value));
        }
    }

    $ds->DbfTransactionEnd();

    if ($result) {
        $ds->DbfTransactionEnd();
        insert($w,textbr(my_("Domain DNS Record Deleted.")));
        $zone="";
    } else {
        $ds->DbfTransactionRollback();
        $formerror .= my_("DNS Record could not be deleted.")."\n";
    }
}
// ##################### END OF DELETE ##############################

// ##################### START OF RENUMBER ##############################
else if ($action=="renumber") {
    // check if user belongs to customer admin group
    $result=$ds->GetCustomerGrp($cust);
    // can only be one row - does not matter if nothing is 
    // found as array search will return false
    $row = $result->FetchRow();
    if (!in_array($row["admingrp"], $grps)) {
        myError($w,$p, my_("You may not delete dns records as you are not a member of the customers admin group"));
    } 

    // could do this in one hit, but requires funky update syntax only available in mysql 4.x
    // need to be able to use ORDER BY in update
    //
    // set @t1=0;
    // update fwdzonerec set sortorder=@t1:=@t1+5 where customer=1 and data_id=73 order by sortorder;

    // Log the Transaction.
    $ds->DbfTransactionStart();
    $result = &$ds->ds->Execute("SELECT fwdzonerec.recidx, fwdzonerec.sortorder 
            FROM fwdzone, fwdzonerec
            WHERE fwdzone.customer=$cust AND 
            fwdzone.domain=".$ds->ds->qstr($domain)." AND
            fwdzone.data_id=fwdzonerec.data_id
            ORDER by fwdzonerec.sortorder");

    // ok, now get all records and renumber
    if ($result) {
        $i=5;
        while($row = $result->FetchRow()) {
            $recidx=$row["recidx"];
            $result1 = &$ds->ds->Execute("UPDATE fwdzonerec
                    SET sortorder=$i
                    WHERE recidx=$recidx");
            $i=$i+5;
        }
        $ds->AuditLog(array("event"=>123, "action"=>"renumber zone record", "cust"=>$cust,
                    "user"=>getAuthUsername(), "domain"=>$domain));
        $ds->DbfTransactionEnd();
        insert($w,textbr(my_("Domain Records Renumbered.")));
    }
    else {
        $ds->DbfTransactionRollback();
        $formerror .= my_("DNS Records could not be renumbered.")."\n";
    }

}
// ##################### END OF RENUMBER ##############################

// ##################### Start OF Add ##############################
if ($action=="add" or $action=="edit") {
    $updateiprec=0;
    // check if user belongs to customer admin group
    $result=$ds->GetCustomerGrp($cust);
    // can only be one row - does not matter if nothing is 
    // found as array search will return false
    $row = $result->FetchRow();
    if (!in_array($row["admingrp"], $grps)) {
        myError($w,$p, my_("You may not add a record as you are not a member of the customers admin group"));
    } 

    // convert shortcuts to FQDN
    if ($host === "@") {
        $formerror .= my_("Bind @ shortcut converted to Fully Qualified Domain Name (FQDN)")."\n";
        $host=$domain.".";
    }
    /*
    if ($host === "*") {
        $formerror .= my_("Bind * shortcut converted to Fully Qualified Domain
                Name (FQDN)")."\n";
        $host="*.".$domain.".";
    } */

    // Error Checks
    if (strpos($host, "_") or strpos($iphostname, "_")) {
        myError($w,$p, my_("Invalid IP/ Hostname"));
    }
    if ($recordtype=="MX") {   // MX could have no hostname
        if ($host and !preg_match(FQDNHNAMEREGEX, $host)) {
            myError($w,$p, my_("Invalid hostname"));
        }
    } else {
        if (!$host)
            myError($w,$p, my_("Host may not be blank"));
        if (!preg_match(FQDNHNAMEREGEX, $host))
            myError($w,$p, my_("Invalid hostname"));
    }
    if (!$recordtype)
        myError($w,$p, my_("Record Type may not be blank."));
    if (!$sortorder or $sortorder < 1)
        $sortorder=9999;
    if (!$iphostname)
        myError($w,$p, my_("IP / Hostname may not be blank."));
    if ($recordtype=="MX" or $recordtype=="AFSDB") {
        // format should be "preference hostname"                     added AFSDB by Jp 060711
        list($preference, $iphost) = explode(" ", $iphostname, 2);
        // is it correct format?
        if (is_numeric($preference) and $preference >= 0) {
            if (!preg_match(FQDNHNAMEREGEX, $iphost)) {
                myError($w,$p, my_("Invalid IP/ Hostname"));
            }
        }
        // no just a hostname? then add a default preference of 10.
        else {
            if (!preg_match(FQDNHNAMEREGEX, $iphostname)) {
                myError($w,$p, my_("Invalid IP/ Hostname"));
            }
            $iphostname="10 ".$iphostname;
        }
    } else if ($recordtype=="TXT") {
      // this can be any text string.
    } else if ($recordtype=="KEY") {
       // this can be any text string.
    } else if ($recordtype=="SRV") {
       // 060711 Jp format should be "priority weight port target_host"
        list($priority, $weight, $port, $iphost) = explode(" ", $iphostname, 4);
        // is it correct format?
        if (is_numeric($priority) and is_numeric($weight) and is_numeric($port)
                   and $priority >= 0        and $weight >= 0        and $port >= 0 ) {
            if (!preg_match(FQDNHNAMEREGEX, $iphost)) {
                myError($w,$p, my_("Invalid IP/ Hostname"));
            }
        }
        // no just an invalid SRV record ?
        else {
               myError($w,$p, my_("Invalid SRV type record.   Usage: SRV <priority> <weight> <port> <target_host>"));
             }

    } else {
        if (!preg_match('/^(([\w][\w\-\.]*)\.)?([\w][\w\-]+)(\.([\w][\w\.]*))?\.?$/', $iphostname)) {
            myError($w,$p, my_("Invalid IP/ Hostname"));
        }
    }
    // add . after record - don't understand thinking here? User should determine if
    // qualified or not?
    /*
       if(preg_match("/[a-z]/i",$iphostname) && substr($iphostname,-1) != '.') {
       $iphostname .= '.';
       }
     */
    // iphostname must be IP address
    if ($recordtype=="A" and testIP($iphostname))
        myError($w,$p, my_("For A type, IP / Hostname must be an IP address"));
    // need to check for valid host
    if ($recordtype=="CNAME" or $recordtype=="NS") {
        if (!preg_match(FQDNHNAMEREGEX, $iphostname))
            myError($w,$p, my_("Invalid IP/ Hostname"));
    }

    // everything looks ok, now check that there are no duplicates
    // could use database key for this, but would require huge indexes

    // cannot check much else as records could be outside of this zone
    // bind has no issues with CNAME's or MX records pointing to non-existent
    // records, so don't bother checking those either
    $result = &$ds->ds->Execute("SELECT customer 
                                FROM fwdzonerec 
                                WHERE customer=$cust AND data_id=$zoneid AND
            host=".$ds->ds->qstr($host)." AND
            recordtype=".$ds->ds->qstr($recordtype)." AND 
            ip_hostname=".$ds->ds->qstr($iphostname));

    $recs=$result->PO_RecordCount("fwdzonerec", "customer=$cust AND data_id=$zoneid AND
            host=".$ds->ds->qstr($host)." AND
            recordtype=".$ds->ds->qstr($recordtype)." AND 
            ip_hostname=".$ds->ds->qstr($iphostname));
    if($recs > 0) {
        myError($w,$p, my_("Cannot create duplicate records"));
    }

    // check if there is only one A record for this customer across all its domains
    // then update ipaddr record
    if ($recordtype=="A") {
        // cannot do a simple three way join on ipaddr, base and fwdzonerec as the
        // field types are different
        $result = &$ds->ds->Execute("SELECT ip_hostname 
                FROM fwdzonerec 
                WHERE customer=$cust AND
                recordtype=".$ds->ds->qstr("A")." AND 
                ip_hostname=".$ds->ds->qstr($iphostname));

        $recs=$result->PO_RecordCount("fwdzonerec", "customer=$cust AND
                recordtype=".$ds->ds->qstr("A")." AND 
                ip_hostname=".$ds->ds->qstr($iphostname));
        if($recs == 1) {
            $updateiprec=1;
        }
    }

    
}

// ##################### START OF Add ##############################
if ($action=="add") {

    if (!$dom_id=$ds->ds->GetOne("SELECT data_id
                FROM fwdzone
                WHERE customer=$cust AND data_id=$zoneid")) {
        myError($w,$p, my_("Could not find the zone - possibly deleted by another user"));
    }

    // Add to DB here.
    // Log the Transaction.
    $ds->DbfTransactionStart();

    // do update of ip record with hostname as part of transaction
    if ($updateiprec) {
        $fqdn=substr($host, -1, 1) == "." ? substr($host, 0, -1) : "$host.$domain";
        $result=$ds->GetBaseFromIP(inet_aton($iphostname), $cust);
        if ($row=$result->FetchRow()) {
            $baseindex=$row["baseindex"];
            $ds->ModifyIP(array(inet_aton($iphostname)), $baseindex, "", "", "", "", "", $fqdn, "");
            // not really an error, but a warning?
            $formerror .= my_("Subnet IP record updated with hostname: ")."$fqdn\n";
        }
    }

    $result = &$ds->ds->Execute("INSERT into fwdzonerec 
            (customer, data_id, sortorder, lastmod, host, 
             recordtype, userid, ip_hostname) ".
            "VALUES ($cust, $zoneid, ". $sortorder.",".
            $ds->ds->DBTimeStamp(time()).",".
            $ds->ds->qstr($host).",".
            $ds->ds->qstr($recordtype).",".
            $ds->ds->qstr(getAuthUsername()).",".
            $ds->ds->qstr($iphostname).")" ) and
        $ds->ds->Execute("UPDATE fwdzone 
            SET error_message=".$ds->ds->qstr("E").",
            lastmod=".$ds->ds->DBTimeStamp(time()).
            " WHERE customer=$cust AND data_id=".$dom_id) and
        $ds->AuditLog(array("event"=>121, "action"=>"add zone record", "cust"=>$cust,
                    "user"=>getAuthUsername(), "domain"=>$domain, "host"=>$host,
                    "recordtype"=>$recordtype, "iphostname"=>$iphostname));

    if ($result) {
        $ds->DbfTransactionEnd();
        insert($w,textbr(my_("Host record added.")));
        $zone="";
    } else {
        $ds->DbfTransactionRollback();
        $formerror .= my_("Host record could not be added.")."\n";
    }
}
// ##################### END OF Add ##############################

// ##################### Start OF Edit ##############################
if ($action=="edit") {

    if (!$ds->ds->GetOne("SELECT recidx FROM fwdzonerec WHERE customer=$cust AND recidx=".$dataid )) {
        myError($w,$p, my_("Could not find the record - possibly deleted by another user"));
    }
    $dom_id=$ds->ds->GetOne("SELECT data_id
                FROM fwdzone
                WHERE customer=$cust AND domain=".$ds->ds->qstr($domain));

    // Updated DB here.
    // Log the Transaction.
    $ds->DbfTransactionStart();

    // do update of ip record with hostname as part of transaction
    if ($updateiprec) {
        $fqdn=substr($host, -1, 1) == "." ? substr($host,0, -1) : "$host.$domain";
        $result=$ds->GetBaseFromIP(inet_aton($iphostname), $cust);
        if ($row=$result->FetchRow()) {
            $baseindex=$row["baseindex"];
            $ds->ModifyIP(array(inet_aton($iphostname)), $baseindex, "", "", "", "", "", $fqdn, "");
            // not really an error, but a warning?
            $formerror .= my_("Subnet IP record updated with hostname: ")."$fqdn\n";
        }
    }

    $result = &$ds->ds->Execute("UPDATE fwdzonerec SET sortorder=".$sortorder.
            ", host=".$ds->ds->qstr($host).
            ", lastmod=".$ds->ds->DBTimeStamp(time()).
            ", recordtype=".$ds->ds->qstr($recordtype).
            ", userid=".$ds->ds->qstr(getAuthUsername()).
            ", ip_hostname=".$ds->ds->qstr($iphostname).
            " WHERE customer=$cust AND recidx=".$dataid ) and
        $ds->ds->Execute("UPDATE fwdzone 
            SET error_message=".$ds->ds->qstr("E").",
            lastmod=".$ds->ds->DBTimeStamp(time()).
            " WHERE customer=$cust AND data_id=".$dom_id) and
        $ds->AuditLog(array("event"=>122, "action"=>"modified zone record", "cust"=>$cust,
                    "user"=>getAuthUsername(), "domain"=>$domain, "host"=>$host,
                    "recordtype"=>$recordtype, "iphostname"=>$iphostname));

    if ($result) {
        $ds->DbfTransactionEnd();
        insert($w,textbr(my_("Host Record Modified")));
        $zone="";
    }
    else {
        $ds->DbfTransactionRollback();
        $formerror .= my_("Host record could not be modifed. Try again.")."\n";
    }
}
// ##################### END OF Edit ##############################

myError($w,$p, $formerror, FALSE);

insert($w,heading(3, "$title."));
insert($w,textbr(my_("Maintain forward zone domain records.")));


// start form
insert($w, $f1 = form(array("name"=>"THISFORM",
                            "method"=>"post",
                            "action"=>$_SERVER["PHP_SELF"])));

// ugly kludge with global variable!
$displayall=FALSE;
$cust=myCustomerDropDown($ds, $f1, $cust, $grps) or myError($w,$p, my_("No customers"));

//
// Get a List of Domains from the fwdzone table.
//

$result = &$ds->ds->Execute("SELECT domain, data_id FROM fwdzone 
                            WHERE customer=$cust AND 
                            slaveonly=".$ds->ds->qstr("N")."
                            ORDER BY domain");
if (!$result) {
   myError($w,$p, my_("No domains found. Create some domains and try again."));
}

insert($w, $f2 = form(array("name"=>"DomainSelect", 
                            "method"=>"post", 
                            "action"=>"modifydnsrecord.php?cust=".$cust)));

insert($f2,textbrbr(my_("Domain")));
insert($f2,span(my_("Master domains only"), array("class"=>"textSmall")));
insert($f2,block("<SELECT NAME='domain' ONCHANGE='submit()'>"."\n"));
$cnt=0;
while($row = $result->FetchRow()) {
   $data=$row["domain"];
   $cnt++;
   // set domain to first record if domain has not been selected prviously
   if ($cnt==1 and empty($domain)) {
        $domain=$data;
   }
   // save data_id for later for the "Add" button
   if ($data==$domain) {
       $zoneid=$row["data_id"];
       insert($f2,block("<OPTION VALUE= '".$data."' SELECTED>".$data."\n"));
   }
   else {
       insert($f2,block("<OPTION VALUE= '".$data."'>".$data."\n"));
   }
} 
insert($f2,block("</SELECT>\n"));
insert($f2,generic("br"));
//insert($f2,submit(array("value"=>my_("Select Domain"))));

// Now Setup Page...
// get info from base table

if ($domain) {
    $result = &$ds->ds->Execute("SELECT data_id FROM fwdzone
    WHERE customer=$cust AND domain='$domain'");
    $row = $result->FetchRow();
    $zoneid=$row["data_id"];

    // what is the additional search SQL?
    $search=$ds->mySearchSql("host", $expr, $descrip);
    $sqllastmod = $ds->ds->SQLDate("M d Y H:i:s", 'lastmod');
    $result = &$ds->ds->Execute("SELECT recidx, data_id, host, recordtype, ip_hostname, 
                error_message, sortorder, customer, $sqllastmod AS lastmod, userid
            FROM fwdzonerec
            WHERE customer=$cust AND data_id=$zoneid
            $search
            ORDER by sortorder");

    $arr=$_GET;
    $arr["domain"]=$domain;
    $arr["cust"]=$cust;
    $arr["action"]="";
    $srch = new mySearch($w, $arr, $descrip, "descrip");
    $srch->legend=my_("Refine Search on Host");
    $srch->expr=$expr;
    $srch->expr_disp=TRUE;
    $srch->Search();  // draw the sucker!

}

$totcnt=0;
$vars="";
// fastforward till first record if not first block of data
while ($block and $totcnt < $block*MAXTABLESIZE and
       $row = $result->FetchRow()) {
    $vars=DisplayBlock($w, $row, $totcnt, "&domain=".urlencode($domain)."&cust=".$cust.
            "&expr=$expr&descrip=".urlencode($descrip), "sortorder");
    $totcnt++;
}
insert($w,block("<p>"));
insert($w,textb($domain));

insert($w, $f = form(array("name"=>"deleterecords",
                           "method"=>"post",
                           "action"=>$_SERVER["PHP_SELF"])));

// create a table
insert($f,$t = table(array("cols"=>"7",
                           "class"=>"outputtable")));
// draw heading
setdefault("cell",array("class"=>"heading"));
insert($t,$c = cell());
if (!empty($vars))
    insert($c,anchor($vars, "<<"));
insert($c,text(my_("Sort-Order")));
insert($t,$c = cell());
insert($c,text(my_("Host")));
insert($t,$c = cell());
insert($c,text(my_("Record Type")));
insert($t,$c = cell());
insert($c,text(my_("IP/Hostname")));
insert($t,$c = cell());
insert($c,text(my_("Last modified")));
insert($t,$c = cell());
insert($c,text(my_("Changed by")));
insert($t,$ck = cell());
insert($ck,text(my_("Action")));

//capture data for the export view functionality
$export = new exportForm();
$export->addRow(array("sort_order", "host", "record_type", "ip_hostname", "last_modified", "changed_by"));
$export->saveRow();

$cnt=0;
while($row = $result->FetchRow()) {
setdefault("cell",array("class"=>color_flip_flop()));
    $export->addRow(NULL);

    $temphost=$row["host"];
    $tempiphostname=$row["ip_hostname"];

/*
    if ($row["recordtype"]=="MX") {
        $tempiphostname=$temphost . " " . $tempiphostname;
        $temphost="";
    }
    if ($row["recordtype"]=="@") {
        $temphost="";
    }
    */
    insert($t,$c = cell());
    insert($c,text($row["sortorder"]));
    $export->addCell($row["sortorder"]);
    
    insert($t,$c = cell());
    insert($c,text($temphost));
    $export->addCell($temphost);
    
    insert($t,$c = cell());
    insert($c,text($row["recordtype"]));
    $export->addCell($row["recordtype"]);
    
    // auto created record?
    if ($row["error_message"]=="A") {
        insert($c,block(" <small><i>"));
        insert($c,textbr(my_("Auto record")));
        insert($c,block("</small></i>"));
    }

    insert($t,$c = cell());
    insert($c,text($tempiphostname));
    $export->addCell($tempiphostname);
    
    insert($t,$c = cell());
    insert($c,block("<small>"));
    insert($c,block($result->UserTimeStamp($row["lastmod"], "M d Y H:i:s")));
    insert($c,block("</small>"));
    $export->addCell($row["lastmod"]);
    
    insert($t,$c = cell());
    insert($c,text($row["userid"]));
    $export->addCell($row["userid"]);
    
    $export->saveRow();
    
    insert($t,$c = cell());
    insert($c,block("<small>"));
    insert($c,checkbox(array("name"=>"dataid[]",
                      "value"=>$row["recidx"]), ""));

    insert($c,anchor($_SERVER["PHP_SELF"]."?cust=$cust&dataid=".$row["recidx"]."&action=delete&domain=".urlencode($domain), my_("Delete Record"),
                $ipplanParanoid ? array("onclick"=>"return confirm('".my_("Are you sure?")."')") : FALSE));
    insert($c,block(" | "));
    insert($c,anchor("modifydnsrecordform.php?cust=$cust&dataid=".$row["recidx"].
                "&action=edit".
                "&domain=".urlencode($domain).
                "&sortorder=".$row["sortorder"].
                "&host=".urlencode($row["host"]).
                "&recordtype=".$row["recordtype"].
                "&iphostname=".urlencode($row["ip_hostname"]), my_("Edit Record")));
    insert($c,block("</small>"));

    if ($totcnt % MAXTABLESIZE == MAXTABLESIZE-1)
        break;
    $cnt++;
    $totcnt++;
}

insert($w,block("<p>"));

if ($cnt) {
   // save customer name for actual post of data
   insert($f,hidden(array("name"=>"cust",
                           "value"=>"$cust")));
   insert($f,hidden(array("name"=>"domain",
                           "value"=>"$domain")));
   insert($f,hidden(array("name"=>"action",
                           "value"=>"delete")));

// code to select all buttons on form named swiptosend
// checkbox array variable is named baseindex[]
        insert($f,block('
<script language="JavaScript" type="text/javascript">
<!--
function checkAll(val) {
   al=document.deleterecords;
   len = al.elements.length;
   var i=0;
   for( i=0 ; i<len ; i++) {
      if (al.elements[i].name==\'dataid[]\') {
         al.elements[i].checked=val;
      }
   }
}
//-->
</script>
'));

   insert($f,anchor("javascript:checkAll(1)", my_("Check all")));
   insert($f,block(" | "));
   insert($f,anchor("javascript:checkAll(0)", my_("Clear all")));

   insert($f,block("<p>"));
   insert($f,submit(array("value"=>my_("Delete multiple"))));
}

$vars="";
$printed=0;
while ($row = $result->FetchRow()) {
    $totcnt++;
    $vars=DisplayBlock($w, $row, $totcnt, "&domain=".urlencode($domain)."&cust=".$cust.
            "&expr=$expr&descrip=".urlencode($descrip), "sortorder" );
    if (!empty($vars) and !$printed) {
        insert($ck,anchor($vars, ">>"));
        $printed=1;
    }
}

if ($domain) {
   insert($w, $f = form(array("method"=>"post", "action"=>"modifydnsrecordform.php?cust=$cust&action=add&domain=".urlencode($domain)."&zoneid=".$zoneid)));
   insert($f,submit(array("value"=>my_("Add a Host"))));
}

if (!$cnt) {
   myError($w,$p, my_("No Records found.  Please choose a domain and try again."));
}
// if there are some records, give option to renumber
else {
    insert($f,anchor($_SERVER["PHP_SELF"]."?cust=$cust&action=renumber&domain=".urlencode($domain)."&block=$block", my_("Renumber SortOrder"),
                $ipplanParanoid ? array("onclick"=>"return confirm('".my_("Are you sure?")."')") : FALSE));
}
   
$result->Close();

// create the export view form
$expression = $export->translateExpr($expr);
$export->setInfo(array(array("customer_ID", "customer_description", "search_criterion", "search_expression"),
                       array($cust, $ds->getCustomerDescrip($cust), $expression, $descrip)));
$export->createExportForm($w, NULL);

printhtml($p);

?>