Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
dom_edit.inc.php
Go to the documentation of this file.
1 <?php
2 require_once("../class/config.php");
3 include_once("head.php");
4 
5 # Function to create/edit subdomain
6 # Take the values of the subdomain in arguments
7 
8 function sub_domains_edit($domain, $sub_domain_id=false) {
9  global $admin, $err, $oldid, $isedit;
10 
11 $dom=new m_dom();
12 $dom->lock();
13 if (!$r=$dom->get_domain_all($domain)) {
14  $error=$err->errstr();
15 }
16 /*
17 if (! empty($sub)) {
18  if (!$sd=$dom->get_sub_domain_all($domain,$sub,$type,$value)) {
19  $error=$err->errstr();
20  }
21 }
22 */
23 $sd=$dom->get_sub_domain_all($sub_domain_id);
24 
25 $type=$sd['type'];
26 $sub=$sd['name'];
27 
28 $dom->unlock();
29 ?>
30 
31 <form action="dom_subdoedit.php" method="post" name="main" id="main">
32  <table border="0">
33  <tr>
34  <td>
35  <input type="hidden" name="domain" value="<?php ehe($domain) ?>" />
36  <input type="hidden" name="sub_domain_id" value="<?php echo $sub_domain_id ?>" />
37  <input type="hidden" name="action" value="add" />
38  <?php
39  if ($isedit) {
40  __("Edit a subdomain:");
41  } else {
42  __("Create a subdomain:");
43  }
44 ?></td><td>
45 <input type="text" class="int" name="sub" style="text-align:right" value="<?php ehe($sub); ?>" size="22" id="sub" /><span class="int" id="newsubname">.<?php echo $domain; ?></span></td>
46  </tr>
47  <?php
48  $first_advanced=true;
49  foreach($dom->domains_type_lst() as $dt) {
50  // If this type is disabled AND it's not the type in use here, continue
51  if ( $dt['enable'] == 'NONE' && strtoupper($type)!=strtoupper($dt['name'])) continue ;
52  // If this type is only for ADMIN and i'm not an admin, continue (oldid is to check if we are an admin who take user identity)
53  if (( $dt['enable'] == 'ADMIN') && (! $admin->enabled and ! intval($oldid))) continue;
54 
55  if ( (! $r['dns'] ) and ($dt['need_dns']) ) continue;
56  $targval=(strtoupper($type)==strtoupper($dt['name']))?$sd['dest']:'';
57 
58  if ($dt['advanced']) {
59  $lst_advanced[]=$dt['name'];
60  if ($first_advanced) {
61  $first_advanced=false;
62  echo "<tr><td colspan=\"2\" class=\"advdom\"></td></tr>";
63  echo "<tr id='domtype_show' onClick=\"domtype_advanced_show();\"><td colspan='2'><a href=\"javascript:domtype_advanced_show();\"><b>+ "; __("Show advanced options"); echo "</b></a></td></tr>";
64  echo "<tr id='domtype_hide' onClick=\"domtype_advanced_hide();\" style='display:none'><td colspan='2'><a href=\"javascript:domtype_advanced_hide();\"><b>- "; __("Hide advanced options"); echo "</b></a></td></tr>";
65  echo "<tr><td colspan=\"2\" class=\"advdom\"></td></tr>";
66  }
67  }
68  ?>
69  <tr id="tr_<?php echo $dt['name']; ?>">
70  <td>
71  <input type="radio" id="r_<?php echo $dt['name']?>" class="inc" name="type" value="<?php echo $dt['name']; ?>" <?php cbox(strtoupper($type)==strtoupper($dt['name'])); ?> OnClick="getElementById('t_<?php echo $dt['name']?>').focus();"/>
72  <label for="r_<?php echo $dt['name']?>"><?php __($dt['description']); ?></label>
73  </td>
74  <td>
75  <?php
76 
77  switch ($dt['target']) {
78  case "NONE":
79  default:
80  break;
81  case "DIRECTORY": ?>
82  <input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval); ?>" size="28" onKeyPress="getElementById('r_<?php echo $dt['name']?>').checked=true;" />
83  <?php display_browser( $targval , "main.t_".$dt['name'] ); ?>
84  <?php
85  break;
86  case "URL": ?>
87  <input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe( (empty($targval)?'http://':$targval) ); ?>" size="50" onKeyPress="getElementById('r_<?php echo $dt['name']?>').checked=true;" />
88  <small><?php __("(enter an URL here)"); ?></small><?php
89  break;;
90  case 'IP':?>
91  <input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval); ?>" size="16" onKeyPress="getElementById('r_<?php echo $dt['name']?>').checked=true;" />
92  <small><?php __("(enter an IPv4 address, for example 192.168.1.2)"); ?></small><?php
93  break;
94  case 'IPV6':?>
95  <input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval); ?>" size="32" onKeyPress="getElementById('r_<?php echo $dt['name']?>').checked=true;" />
96  <small><?php __("(enter an IPv6 address, for example 2001:0910::0)"); ?></small><?php
97  break;
98  case 'TXT':?>
99  <input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval);?>" size="32" onKeyPress="getElementById('r_<?php echo $dt['name']?>').checked=true;" />
100  <small><?php __("(enter a TXT content for this domain)"); ?></small><?php
101  break;
102  case 'DOMAIN':?>
103  <input type="text" class="int" name="t_<?php echo $dt['name']?>" id="t_<?php echo $dt['name']?>" value="<?php ehe($targval);?>" size="32" onKeyPress="getElementById('r_<?php echo $dt['name']?>').checked=true;" />
104  <small><?php __("(enter a domain name or subdomain)"); ?></small><?php
105  break;
106  } // switch ?>
107  </td>
108  </tr>
109  <?php } // foreach ?>
110 
111  <tr class="trbtn">
112  <td colspan="2"><input type="submit" class="inb ok" name="add" onclick='return check_type_selected();' value="<?php
113  if ($isedit) {
114  __("Edit this subdomain");
115 } else {
116  __("Add this subdomain");
117 }
118 ?>" /></td>
119  </tr>
120  </table>
121 </form>
122 
123 <script type="text/javascript">
124 
125 function check_type_selected() {
126  if ( $('input[name=type]:radio:checked').val() ) {
127  // there is a value
128  var ll = $('input[name=type]:radio:checked').val();
129  var tt = $('#t_'+ll);
130  if ( tt.length == 0 ) {
131  // this element do not exist, so OK
132  return true;
133  }
134  if ( tt.val() == '' ) {
135  alert("<?php __("Missing value for this sub-domain"); ?>");
136  return false;
137  }
138 
139  return true;
140  }
141  alert("<?php __("Please select a type for this sub-domain"); ?>");
142  return false;
143 }
144 
145 function domtype_advanced_hide() {
146  <?php foreach ($lst_advanced as $adv) echo "$(\"#tr_$adv\").hide();\n"?>
147  $("#domtype_show").show();
148  $("#domtype_hide").hide();
149 }
150 function domtype_advanced_show() {
151  <?php foreach ($lst_advanced as $adv) echo "$(\"#tr_$adv\").show();\n"?>
152  $("#domtype_show").hide();
153  $("#domtype_hide").show();
154 }
155 
156 <?php if (isset($type) && in_array($type, $lst_advanced) ) { // if it's an edit of an advanced option, we need to show the advanced options ?>
157  domtype_advanced_show();
158 <?php } else { ?>
159  domtype_advanced_hide();
160 <?php } // if advanced ?>
161 
162 </script>
163 <?php
164 } // sub_domains_edit
165 ?>
166