673 function get_domains_from_userid($id) |
673 function get_domains_from_userid($id) |
674 { |
674 { |
675 global $db; |
675 global $db; |
676 if (is_numeric($id)) |
676 if (is_numeric($id)) |
677 { |
677 { |
678 $result = $db->query("SELECT domains.id AS domain_id, domains.name AS name FROM domains LEFT JOIN zones ON domains.id=zones.domain_id WHERE owner=$id"); |
678 $a_zones = array(); |
679 |
679 |
680 $ret = array(); |
680 // Check for zones the user has full access for (the |
681 |
681 // user is owner of the zone. |
682 // Put all the information in a big array. |
682 |
683 while ($r = $result->fetchRow()) |
683 $res_full = $db->query("SELECT |
684 { |
684 domains.id AS domain_id, |
685 $ret[] = array( |
685 domains.name AS name |
|
686 FROM domains |
|
687 LEFT JOIN zones ON domains.id=zones.domain_id |
|
688 WHERE owner=$id"); |
|
689 |
|
690 // Process the output. |
|
691 |
|
692 $numrows = $res_full->numRows(); |
|
693 $i=1; |
|
694 if ($numrows > 0) |
|
695 { |
|
696 $andnot=" AND NOT domains.id IN ("; |
|
697 while($r = $res_full->fetchRow()) { |
|
698 |
|
699 // Create array of zone id's and name's the owner |
|
700 // has full access to. |
|
701 |
|
702 $a_zones[] = array( |
|
703 "id" => $r["domain_id"], |
|
704 "name" => $r["name"], |
|
705 "partial" => "0" |
|
706 ); |
|
707 |
|
708 // Create AND NOT for query of zones the user has |
|
709 // only partial access to. In that query we just |
|
710 // want to see the zones he has not full access to |
|
711 // as well. |
|
712 |
|
713 $andnot.=$r["domain_id"]; |
|
714 if ($i < $numrows) { |
|
715 $andnot.=","; |
|
716 $i++; |
|
717 } |
|
718 |
|
719 } |
|
720 $andnot.=")"; |
|
721 } |
|
722 else |
|
723 { |
|
724 $andnot=""; |
|
725 } |
|
726 |
|
727 // Check for zones the user has partial access only to. |
|
728 |
|
729 $res_partial = $db->query("SELECT DISTINCT |
|
730 records.domain_id, |
|
731 domains.name |
|
732 FROM records, record_owners, domains |
|
733 WHERE record_owners.user_id = '".$id."' |
|
734 AND records.id = record_owners.record_id |
|
735 AND domains.id = records.domain_id |
|
736 ".$andnot.";"); |
|
737 |
|
738 // Add these zones to the array as well. |
|
739 |
|
740 while ($r = $res_partial->fetchRow()) |
|
741 { |
|
742 $a_zones[] = array( |
686 "id" => $r["domain_id"], |
743 "id" => $r["domain_id"], |
687 "name" => $r["name"] |
744 "name" => $r["name"], |
|
745 "partial" => "1" |
688 ); |
746 ); |
689 } |
747 } |
690 return $ret; |
748 |
|
749 return $a_zones; |
691 } |
750 } |
692 else |
751 else |
693 { |
752 { |
694 error(sprintf(ERR_INV_ARGC, "get_domains_from_userid", "This is not a valid userid: $id")); |
753 error(sprintf(ERR_INV_ARGC, "get_domains_from_userid", "This is not a valid userid: $id")); |
695 } |
754 } |