root/modules/branches/2.4/featurecodeadmin/page.featurecodeadmin.php

Revision 5359, 7.6 kB (checked in by p_lindheimer, 4 years ago)

#2461 - I think this will fix the reported localization issue but I don't have any translations that would exercise this and there has been no feedback provided per the request on the ticket.

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php
2 // Original Copyright (C) 2006 Niklas Larsson
3 // Re-written 20060331, Rob Thomas <xrobau@gmail.com>
4 //
5 //This program is free software; you can redistribute it and/or
6 //modify it under the terms of the GNU General Public License
7 //as published by the Free Software Foundation; either version 2
8 //of the License, or (at your option) any later version.
9 //
10 //This program is distributed in the hope that it will be useful,
11 //but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //GNU General Public License for more details.
14
15 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
16 $dispnum = "featurecodeadmin"; //used for switch on config.php
17
18 //if submitting form, update database
19 switch ($action) {
20   case "save":
21     featurecodeadmin_update($_REQUEST);
22     needreload();
23   break;
24 }
25
26 $featurecodes = featurecodes_getAllFeaturesDetailed();
27 ?>
28
29 </div>
30
31 <div class="content">
32   <form autocomplete="off" name="frmAdmin" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return frmAdmin_onsubmit();">
33   <input type="hidden" name="display" value="<?php echo $dispnum?>">
34   <input type="hidden" name="action" value="save">
35
36   <?php
37       $exten_conflict_arr = array();
38       $conflict_url = array();
39       $exten_arr = array();
40       foreach ($featurecodes as $result) {
41         if (($result['featureenabled'] == 1) && ($result['moduleenabled'] == 1)) {
42           $exten_arr[] = ($result['customcode'] != '')?$result['customcode']:$result['defaultcode'];
43         }
44       }
45       $usage_arr = framework_check_extension_usage($exten_arr);
46       unset($usage_arr['featurecodeadmin']);
47       if (!empty($usage_arr)) {
48         $conflict_url = framework_display_extension_usage_alert($usage_arr,false,false);
49       }
50       if (!empty($conflict_url)) {
51         $str = "You have feature code conflicts with extension numbers in other modules. This will result in unexpected and broken behavior.";
52         echo "<script>javascript:alert('$str')</script>";
53         echo "<h4>"._("Feature Code Conflicts with other Extensions")."</h4>";
54         echo implode('<br .>',$conflict_url);
55
56         // Create hash of conflicting extensions
57         //
58         foreach ($usage_arr as $module_name => $details) {
59           foreach (array_keys($details) as $exten_conflict) {
60             $exten_conflict_arr[$exten_conflict] = true;
61           }
62         }
63
64         // Now check for conflicts within featurecodes page
65         //
66         $unique_exten_arr = array_unique($exten_arr);
67         $feature_conflict_arr = array_diff_assoc($exten_arr, $unique_exten_arr);
68         foreach ($feature_conflict_arr as $value) {
69           $exten_conflict_arr[$value] = true;
70         }
71       }
72   ?>
73   <table>
74   <tr><td colspan="4"><h3><?php echo _("Feature Code Admin"); ?><hr></h3></td></tr>
75   <tr>
76     <td colspan="2">&nbsp;</td>
77     <td align="center"><b><?php echo _("Use"); ?><br><?php echo _("Default"); ?>?</b></td>
78     <td align="center"><b><?php echo _("Feature"); ?><br><?php echo _("Status"); ?></b></td>
79   </tr>
80   <?php
81   $currentmodule = "(none)";
82   foreach($featurecodes as $item) {
83
84     // change domains to get the translations from each module
85     //
86     bindtextdomain($item['modulename'],"modules/".$item['modulename']."./i18n");
87     $moduledesc = isset($item['moduledescription'])?gettext($item['moduledescription']):null;
88     $featuredesc = gettext($item['featuredescription']);
89     bindtextdomain($dispnum,"modules/".$dispnum."./i18n");
90
91     $moduleena = ($item['moduleenabled'] == 1 ? true : false);
92     $featureid = $item['modulename'] . '#' . $item['featurename'];
93     $featureena = ($item['featureenabled'] == 1 ? true : false);
94     $featurecodedefault = (isset($item['defaultcode']) ? $item['defaultcode'] : '');
95     $featurecodecustom = (isset($item['customcode']) ? $item['customcode'] : '');
96
97     $thiscode = ($featurecodecustom != '') ? $featurecodecustom : $featurecodedefault;
98     
99     if ($currentmodule != $moduledesc) {
100       $currentmodule = $moduledesc;
101       ?>
102       <tr>
103         <td colspan="4">
104           <h4>
105           <?php echo $currentmodule; ?>
106           <?php if ($moduleena == false) {?>
107           <i>(<?php echo _("Disabled"); ?>)</i>
108           <?php } ?>
109           </h4>
110         </td>
111       </tr>
112       <?php
113     }
114     ?> 
115     <tr>
116     <?php
117       if (array_key_exists($thiscode, $exten_conflict_arr)) {
118         $style = "style='color:red'";
119         $background = "style='background:red'";
120         $strong = "<strong>";
121         $endstrong = "</strong>";
122       } else {
123         $style = "";
124         $background = "";
125         $strong = "";
126         $endstrong = "";
127       }
128     ?>
129       <td <?php echo $style ?>>
130         <?php echo $strong.$featuredesc.$endstrong; ?>
131       </td>
132       <td>
133         <input type="text" name="custom#<?php echo $featureid; ?>" value="<?php echo $featurecodecustom; ?>" <?php echo $background; ?> size="4">
134       </td>
135       <td align="center">
136         <input type="checkbox" onclick="usedefault_onclick(this);" name="usedefault_<?php echo $featureid; ?>"<?php if ($featurecodecustom == '') echo "checked"; ?>>
137         <input type="hidden" name="default_<?php echo $featureid; ?>" value="<?php echo $featurecodedefault; ?>">
138         <input type="hidden" name="origcustom_<?php echo $featureid; ?>" value="<?php echo $featurecodecustom; ?>">
139       </td>
140       <td>
141         <select name="ena#<?php echo $featureid; ?>">
142         <option <?php if ($featureena == true) echo ("selected "); ?>value="1"><?php echo _("Enabled"); ?></option>
143         <option <?php if ($featureena == false) echo ("selected "); ?>value="0"><?php echo _("Disabled"); ?></option>
144         </select>
145       </td>
146     </tr>
147     <?php
148   }
149  ?>
150   <tr>
151     <td colspan="4"><br><h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td>   
152   </tr>
153   </table>
154
155   <script language="javascript">
156   <!--
157  
158   var theForm = document.frmAdmin;
159  
160   callallusedefaults();
161  
162   // call the onclick function for all the Use Default boxes
163   function callallusedefaults() {
164     for (var i=0; i<theForm.elements.length; i++) {
165       var theFld = theForm.elements[i];
166       if (theFld.name.substring(0,11) == "usedefault_") {
167         usedefault_onclick(theFld);
168       }
169     }
170   }
171    
172   // disabled the custom code box if using default and also puts the default number in the box
173   function usedefault_onclick(chk) {
174     var featureid = chk.name.substring(11);
175     if (chk.checked) {
176       theForm.elements['origcustom_' + featureid].value = theForm.elements['custom#' + featureid].value;     
177       theForm.elements['custom#' + featureid].value = theForm.elements['default_' + featureid].value;
178     } else {
179       theForm.elements['custom#' + featureid].value = theForm.elements['origcustom_' + featureid].value;
180     }
181     theForm.elements['custom#' + featureid].readOnly = chk.checked;
182   }
183  
184   // form validation
185   function frmAdmin_onsubmit() {
186     var msgErrorMissingFC = "<?php echo _("Please enter a Feature Code or check Use Default for all Enabled Feature Codes"); ?>";
187     var msgErrorDuplicateFC = "<?php echo _("Feature Codes have been duplicated"); ?>";
188     var msgErrorProceedOK = "<?php echo _("Are you sure you wish to proceed?"); ?>";
189    
190     for (var i=0; i<theForm.elements.length; i++) {
191       var theFld = theForm.elements[i];
192       if (theFld.name.substring(0,7) == "custom#") {
193         var featureid = theFld.name.substring(7);
194         // check that every non default has a custom code
195         if (!theForm.elements['usedefault_' + featureid].checked && theForm.elements['ena#' + featureid].value == 1) {
196           defaultEmptyOK = false;
197           if (!isDialDigits(theFld.value))
198             return warnInvalid(theFld, msgErrorMissingFC);
199            
200           if (isDuplicated(theFld.name, theFld.value))
201             return confirm(msgErrorDuplicateFC+".  "+msgErrorProceedOK);
202         }
203       }
204     }
205    
206    
207     return true;
208   }
209
210   function isDuplicated(firstfldname, firstfc) {
211     for (var i=0; i<theForm.elements.length; i++) {
212       var theFld = theForm.elements[i];
213       if (theFld.name.substring(0,7) == "custom#" && theFld.name != firstfldname) {
214         if (theFld.value == firstfc)
215           return true;
216       }
217     }
218   }
219  
220   //-->
221   </script>
222  
223   </form>
Note: See TracBrowser for help on using the browser.