Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
search_and_replace.php
1 <?php
25 require_once dirname(__FILE__).'/../../../../core/include/init.inc';
26 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
27 require_once SQ_FUDGE_PATH.'/var_serialise/var_serialise.inc';
28 
29 $_GET['name'] = array_get_index($_GET, 'name', '');
30 
31 ?>
32 
33 <html style="width: 370px; height: 280px;">
34 
35  <head>
36  <title>Search and Replace</title>
37  <script type="text/javascript" src="../../core/popup.js"></script>
38  <script type="text/javascript" src="<?php echo sq_web_path('fudge').'/var_serialise/var_serialise.js' ?>"></script>
39  <script type="text/javascript" src="<?php echo sq_web_path('lib').'/html_form/html_form.js' ?>"></script>
40  <script type="text/javascript" src="<?php echo sq_web_path('lib').'/js/general.js' ?>"></script>
41 
42  <script type="text/javascript">
43 
44  function getFocus() {
45  setTimeout('self.focus()',100);
46  };
47 
48  function Init() {
49  __dlg_init("SearchAndReplace");
50  setTimeout('self.focus()',100);
51  };
52 
53  function onOK(action_type) {
54 
55  var search_str = document.getElementById("search_str").value;
56  var replace_str = document.getElementById("replace_str").value;
57 
58  if (document.getElementById("rep_type4").checked) {
59  var confirm_str = "WARNING!\nUnlike other match options, regular expression replacement will be applied to the actual html content, therefore appearance of the content may be affected and also the action cannot be undone.\nAre you sure you want to apply the replacement?";
60  } else {
61  var confirm_str = "WARNING!\nAll the occurance of the search string will be replaced and the action cannot be undone.\nAre you sure you want to apply the replacement?";
62  }
63 
64  if ((action_type != "replace_all" && action_type != "replace_selection") || confirm(confirm_str)) {
65  var parameter_types = new Array();
66 
67  parameter_types.push(action_type);
68  parameter_types.push(search_str);
69  parameter_types.push(replace_str);
70 
71  var i = 0;
72  while (document.getElementById("rep_type"+i) != null) {
73  parameter_types.push(document.getElementById("rep_type"+i++).checked);
74  }
75 
76  getFocus();
77  __dlg_close("SearchAndReplace", parameter_types, false);
78  return true;
79  }
80  return false;
81  };
82 
83  function enableButtons() {
84 
85  if (document.getElementById("search_str").value != '') {
86  // Replace/Search text by text feature is not available for regular expression search
87  if (!document.getElementById("rep_type4").checked) {
88  document.getElementById("search_previous").disabled = false;
89  document.getElementById("search_next").disabled = false;
90  document.getElementById("replace_current").disabled = false;
91  } else {
92  document.getElementById("search_previous").disabled = true;
93  document.getElementById("search_next").disabled = true;
94  document.getElementById("replace_current").disabled = true;
95  }
96 
97  document.getElementById("replace_all").disabled = false;
98  document.getElementById("replace_selection").disabled = false;
99 
100  } else {
101  document.getElementById("search_previous").disabled = true;
102  document.getElementById("search_next").disabled = true;
103  document.getElementById("replace_current").disabled = true;
104  document.getElementById("replace_all").disabled = true;
105  document.getElementById("replace_selection").disabled = true;
106  }
107  };
108 
109  function fixMatchTypeCheckboxes(type) {
110  match_types = Array('1', '2', '3', '4');
111 
112  if (document.getElementById("rep_type"+type).checked) {
113  for(index in match_types) {
114  rep_type = match_types[index];
115  if (rep_type != type) document.getElementById("rep_type"+rep_type).checked = false;
116  }
117 
118  }//end if
119 
120  enableButtons();
121  };
122 
123  function onCancel() {
124  __dlg_close("SearchAndReplace", null);
125  return false;
126  };
127 
128  </script>
129 
130  <style type="text/css">
131  html, body {
132  background: #FCFCFC;
133  color: #000000;
134  font: 11px Tahoma,Verdana,sans-serif;
135  margin: 0px;
136  padding: 0px;
137  padding: 5px;
138  }
139 
140  table {
141  font: 11px Tahoma,Verdana,sans-serif;
142  }
143 
144  /* main popup title */
145  .title {
146  background: #402F48;
147  color: #FFFFFF;
148  font-weight: bold;
149  font-size: 120%;
150  padding: 3px 10px;
151  margin-bottom: 10px;
152  border-bottom: 1px solid black;
153  letter-spacing: 4px;
154  }
155 
156  /* fieldset styles */
157  fieldset {
158  padding: 0px 10px 5px 5px;
159  border-color: #725B7D;
160  }
161 
162  .fl { width: 9em; float: left; padding: 2px 5px; text-align: right; }
163  .fr { width: 7em; float: left; padding: 2px 5px; text-align: right; }
164 
165  /* form and form fields */
166  form { padding: 0px; margin: 0px; }
167 
168  select, input, button {
169  font: 11px Tahoma,Verdana,sans-serif;
170  }
171 
172  button {
173  width: 110px;
174  }
175  </style>
176  </head>
177 
178  <body onload="Init()">
179 
180  <div class="title">Search And Replace</div>
181 
182  <form action="" method="get" name="Form1">
183  <table border="0" width="100%">
184 
185  <tr>
186  <td>
187  <fieldset>
188  <legend><b>Search and replace string</b></legend>
189  <table style="width:100%">
190  <tr>
191  <td>Search string</td>
192  <td><input type="text" name="search_str" id="search_str" size="45" onkeyup="enableButtons()">
193  </tr>
194  <tr>
195  <td>Replace string</td>
196  <td><input type="text" name="replace_str" id="replace_str" size="45">
197  </tr>
198  </table>
199  </fieldset>
200  </td>
201  </tr>
202 
203  <tr>
204  <td>
205  <fieldset>
206  <legend><b>Replace options</b></legend>
207  <table style="width:100%">
208  <tr>
209  <td>
210  <input type="checkbox" name="rep_type0" id="rep_type0" />
211  <label for="rep_type0"> Match case</label><br/>
212 
213  <input type="checkbox" name="rep_type1" id="rep_type1" onClick="fixMatchTypeCheckboxes('1')" />
214  <label for="rep_type1"> Match the whole word</label><br/>
215 
216  <input type="checkbox" name="rep_type2" id="rep_type2" onClick="fixMatchTypeCheckboxes('2')" />
217  <label for="rep_type2"> Match beginning of the word</label><br/>
218 
219  <input type="checkbox" name="rep_type3" id="rep_type3" onClick="fixMatchTypeCheckboxes('3')" />
220  <label for="rep_type2"> Match end of the word</label><br/>
221 
222  <input type="checkbox" name="rep_type4" id="rep_type4" onClick="fixMatchTypeCheckboxes('4')" />
223  <label for="rep_type3"> Regular expression match</label><br/>
224 
225  </td>
226  </tr>
227  </table>
228  </fieldset>
229  </td>
230  </tr>
231  </table>
232 
233  <div style="text-align: center;">
234 
235  <button type="button" disabled id="search_next" name="search_next" onclick="if (!onOK('search_next')) return;">Search Next</button>&nbsp;&nbsp;
236  <button type="button" disabled id="search_previous" name="search_previous" onclick="if (!onOK('search_previous')) return;">Search Previous</button>&nbsp;&nbsp;
237  <button type="button" disabled id="replace_current" name="replace_current" onclick="if (!onOK('replace_current')) return;">Replace</button><br />
238  <button type="button" disabled id="replace_all" name="replace_all" onclick="if (!onOK('replace_all')) return;">Replace All</button>&nbsp;&nbsp;
239  <button type="button" disabled id="replace_selection" name="replace_selection" onclick="if (!onOK('replace_selection')) return;">In Selection</button>&nbsp;&nbsp;
240 
241  <button type="button" name="cancel" onclick="window.close();">Cancel</button>
242  </div>
243  </form>
244  </body>
245 </html>