AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / docs / themes / default / updater / patch_create_edit.tmpl.php
1 <?php\r
2 /************************************************************************/\r
3 /* AContent                                                             */\r
4 /************************************************************************/\r
5 /* Copyright (c) 2010                                                   */\r
6 /* Inclusive Design Institute                                           */\r
7 /*                                                                      */\r
8 /* This program is free software. You can redistribute it and/or        */\r
9 /* modify it under the terms of the GNU General Public License          */\r
10 /* as published by the Free Software Foundation.                        */\r
11 /************************************************************************/\r
12 \r
13 require ('include/json.inc.php');\r
14 require (TR_INCLUDE_PATH.'header.inc.php');\r
15 ?>\r
16 \r
17 \r
18 <form enctype="multipart/form-data" action='<?php echo $this->url; ?>' method="post" name="form" target="messageIFrame">\r
19 \r
20 <div class="input-form">\r
21 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('create_edit_update'); ?></legend>\r
22 \r
23 <iframe id="messageIFrame" name="messageIFrame" src='' style='width:1px;height:1px;border:0' onload="show_message()"></iframe>\r
24 <div id="messageDIV"></div>\r
25         <table class="form-data">\r
26                 <tr>\r
27                         <td colspan="2" align="left"><?php echo _AT('required_field_text') ;?></td>\r
28                 </tr>\r
29 \r
30                 <tr>\r
31                         <th align="left" style="width: 25%">\r
32                                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="system_patch_id"><?php echo _AT('system_update_id'); ?>:</label><br />\r
33                         </th>\r
34                         <td align="left"><input id="system_patch_id" name="system_patch_id" type="text" maxlength="100" size="30" value="<?php echo $this->patch_row['system_patch_id']; ?>" /></td>\r
35                 </tr>\r
36                 \r
37                 <tr><th align="left" colspan="2"><small>&middot; <?php echo _AT('contain_only'); ?></small></th></tr>\r
38 \r
39                 <tr>\r
40                         <th align="left"><span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="transformable_version_to_apply"><?php echo _AT('transformable_version_to_apply'); ?>:</label></th>\r
41                         <td align="left"><input id="transformable_version_to_apply" name="transformable_version_to_apply" type="text" maxlength="100" size="30" value="<?php echo $this->patch_row['applied_version']; ?>" /></td>\r
42                 </tr>\r
43 \r
44                 <tr>\r
45                         <th align="left"><label for="description"><?php echo _AT('description'); ?>:</label></th>\r
46                         <td align="left"><textarea id="description" name="description" cols="40" rows="4"><?php echo $this->patch_row['description']; ?></textarea></td>\r
47                 </tr>\r
48 \r
49                 <tr>\r
50                         <th align="left"><label for="sql_statement"><?php echo _AT('sql_statement'); ?>:</label></th>\r
51                         <td align="left"><textarea id="sql_statement" name="sql_statement" cols="40" rows="8"><?php echo $this->patch_row['sql_statement']; ?></textarea></td>\r
52                 </tr>\r
53         </table>\r
54         \r
55         <h2><label for="dependent_patches"><?php echo _AT('dependent_updates'); ?></label></h2><br/>\r
56         \r
57         <table id="dependent_patches" class="data" rules="rows" style="width:50%">\r
58                 <thead>\r
59                 <tr>\r
60                         <th><label for="dependent_patch"><?php echo _AT('dependent_update_id'); ?></label></th>\r
61                 </tr>\r
62                 </thead>\r
63         \r
64                 <tfoot>\r
65                 <tr>\r
66                         <td><input type="button" name="add_dependent_patch" value="<?php echo _AT('add_dependent_update'); ?>" onclick="add_dependent()" /></td>\r
67                 </tr>\r
68                 </tfoot>\r
69 \r
70                 <tbody>\r
71 <?php\r
72 // when edit existing patch\r
73 if (is_array($this->dependent_rows))  \r
74 {\r
75         $num_of_dependents = count($this->dependent_rows);\r
76         foreach ($this->dependent_rows as $row_patch_dependent)\r
77         {\r
78         ?>\r
79                         <tr>\r
80                                 <td><input id="dependent_patch" name="dependent_patch[]" value="<?php echo $row_patch_dependent['dependent_patch_id']; ?>" type="text" maxlength="100" size="100" style="max-width:100%; display:block" /></td>\r
81                         </tr>\r
82         <?php\r
83         }\r
84 }\r
85 \r
86 // when creating new patch\r
87 if ($num_of_dependents == 0)\r
88 {\r
89 ?>\r
90                 <tr>\r
91                         <td><input id="dependent_patch" name="dependent_patch[]" type="text" maxlength="100" size="100" style="max-width:95%; display:block" /></td>\r
92                 </tr>\r
93 <?php\r
94 }\r
95 ?>\r
96                 </tbody>\r
97         </table>\r
98         \r
99         \r
100         <h2><label for="filesDiv"><?php echo _AT('files'); ?></label></h2>\r
101         <small>&middot; <?php echo _AT('relative_directory'); ?></small>\r
102 \r
103         <div id="filesDiv" class="row">\r
104         </div>\r
105 \r
106         <div class="row"  style="float:left">\r
107                 <input type="button" name="add_a_file" value="<?php echo _AT('add_a_file'); ?>" onclick="add_file()" />\r
108         </div>\r
109         \r
110         <br /><br />\r
111         \r
112         <div>\r
113                 <input type="submit" name="create" value=" <?php echo _AT('create_update'); ?> " accesskey="c" />\r
114                 <input type="submit" name="save" value=" <?php echo _AT('save'); ?> " accesskey="s" onclick="document.form.target=''; "/>\r
115                 <input type="button" name="cancel" value=" <?php echo _AT('cancel'); ?> " onclick="location.href='updater/myown_patches.php'" />\r
116         </div>\r
117         \r
118 </fieldset>\r
119 </div>\r
120 </form>\r
121 \r
122 <script language="JavaScript" type="text/javascript">\r
123 //<!--\r
124 \r
125 myescape = function(/*string*/ str) {\r
126     return str.replace(/(['"\.*+?^${}()|[\]\/\\])/g, "\\$1").replace(/\n/g, '\\n');\r
127 }\r
128 \r
129 function show_message()\r
130 {\r
131         var messageDIV = document.getElementById("messageDIV"); \r
132         var i = document.getElementById("messageIFrame"); \r
133         \r
134   if (i.contentDocument) {\r
135       var d = i.contentDocument;\r
136   } else if (i.contentWindow) {\r
137       var d = i.contentWindow.document;\r
138   } else {\r
139       var d = window.frames[id].document;\r
140   }     \r
141         messageDIV.innerHTML = d.body.innerHTML;\r
142 }\r
143 \r
144 function add_dependent() {\r
145   var dependentPatchesTable = document.getElementById("dependent_patches").tBodies[0];\r
146   var dependentPatch = dependentPatchesTable.rows[dependentPatchesTable.rows.length - 1].cloneNode(true);\r
147   dependentPatchesTable.appendChild(dependentPatch);\r
148   dependentPatch.cells[0].firstChild.value='';\r
149   \r
150   var dependents = document.form["dependent_patch[]"];\r
151   dependents[dependents.length - 1].focus();\r
152     //  document.form['dependent_patch['+ pos +']'].focus();\r
153 }\r
154 \r
155 var num_of_files = 0;\r
156 function add_file(filedata) {\r
157         var newDiv = document.createElement("div");\r
158         \r
159         newDiv.innerHTML = ACTION_HTML_TEMPLATE.replace(/\{1\}/g, num_of_files);\r
160         document.getElementById("filesDiv").appendChild(newDiv);\r
161         \r
162         document.form['rb_action[' +num_of_files +']'][0].focus();\r
163         \r
164         if(filedata) {\r
165                 var srcElement = null;\r
166 \r
167                 if(filedata.action=="add") {\r
168                         // set focus on radio button "add"\r
169                         document.form['rb_action[' +num_of_files +']'][0].checked = true;\r
170                         document.form['rb_action[' +num_of_files +']'][0].focus();\r
171 \r
172                         // set value\r
173                         srcElement = document.form['rb_action[' +num_of_files +']'][0];\r
174                         document.form['add_filename[' +num_of_files +']'].value = filedata.name;\r
175                         document.form['add_dir[' +num_of_files +']'].value = filedata.location;\r
176                         \r
177                         // set uploaded file\r
178                         if (filedata.uploaded_file != "")\r
179                         {\r
180                                 document.form['add_uploaded_file[' +num_of_files +']'].value = filedata.uploaded_file;\r
181                                 var tables = newDiv.getElementsByTagName('TABLE');\r
182                                 tables[0].rows[2].style.display='';    // display the row of uploaded file\r
183                                 tables[0].rows[2].cells[1].innerHTML=filedata.uploaded_file;    // display uploaded file name\r
184                                 tables[0].rows[3].cells[0].innerHTML='<?php echo _AT("replace_file"); ?>';    // change label from "upload file" to "replace file"\r
185                         }\r
186                         \r
187                         // set uploaded file\r
188                 } else if(filedata.action=="alter") {\r
189                         document.form['rb_action[' +num_of_files +']'][1].checked = true;\r
190                         document.form['rb_action[' +num_of_files +']'][1].focus();\r
191 \r
192                         srcElement = document.form['rb_action[' +num_of_files +']'][1];\r
193                         document.form['alter_filename[' +num_of_files +']'].value = filedata.name;\r
194                         document.form['alter_dir[' +num_of_files +']'].value = filedata.location;\r
195                         document.form['alter_code_from[' +num_of_files +']'].value = filedata.code_from;\r
196                         document.form['alter_code_to[' +num_of_files +']'].value = filedata.code_to;\r
197                 } else if(filedata.action=="delete") {\r
198                         document.form['rb_action[' +num_of_files +']'][2].checked = true;\r
199                         document.form['rb_action[' +num_of_files +']'][2].focus();\r
200 \r
201                         srcElement = document.form['rb_action[' +num_of_files +']'][2];\r
202                         document.form['delete_filename[' +num_of_files +']'].value = filedata.name;\r
203                         document.form['delete_dir[' +num_of_files +']'].value = filedata.location;\r
204                 } if(filedata.action=="overwrite") {\r
205                         document.form['rb_action[' +num_of_files +']'][3].checked = true;\r
206                         document.form['rb_action[' +num_of_files +']'][3].focus();\r
207 \r
208                         srcElement = document.form['rb_action[' +num_of_files +']'][3];\r
209                         document.form['overwrite_filename[' +num_of_files +']'].value = filedata.name;\r
210                         document.form['overwrite_dir[' +num_of_files +']'].value = filedata.location;\r
211 \r
212                         // set uploaded file\r
213                         if (filedata.uploaded_file != "")\r
214                         {\r
215                                 document.form['overwrite_uploaded_file[' +num_of_files +']'].value = filedata.uploaded_file;\r
216                                 var tables = newDiv.getElementsByTagName('TABLE');\r
217                                 tables[3].rows[2].style.display='';    // display the row of uploaded file\r
218                                 tables[3].rows[2].cells[1].innerHTML=filedata.uploaded_file;    // display uploaded file name\r
219                                 tables[3].rows[3].cells[0].innerHTML='<?php echo _AT("replace_file"); ?>';    // change label from "upload file" to "replace file"\r
220                         }\r
221                         \r
222                 }\r
223                 \r
224                 show_content({srcElement:srcElement});\r
225         }\r
226 \r
227         num_of_files++;\r
228 }\r
229 \r
230 function del_file(evt) {\r
231         var target =(evt.srcElement)?evt.srcElement:evt.currentTarget;\r
232         var div =  target.parentNode.parentNode ;\r
233         div.parentNode.removeChild(div);\r
234 }\r
235 \r
236 function show_content(evt) {\r
237         var target =(evt.srcElement)?evt.srcElement:evt.currentTarget;\r
238         var tables = target.parentNode.parentNode.getElementsByTagName('TABLE');\r
239         tables[0].style.display='none';\r
240         tables[1].style.display='none';\r
241         tables[2].style.display='none';\r
242         tables[3].style.display='none';\r
243         if(target.value == 'add') tables[0].style.display='';\r
244         if(target.value == 'alter') tables[1].style.display='';\r
245         if(target.value == 'delete') tables[2].style.display='';\r
246         if(target.value == 'overwrite') tables[3].style.display='';\r
247 }\r
248 \r
249 var ACTION_HTML_TEMPLATE = ' \\r
250 <div style="border-width:thin; border-style:solid; padding: 5px 5px 5px 5px; margin:5px 5px 5px 5px"> \\r
251         <div style="float:left">Action:  \\r
252                 <input type="radio" name="rb_action[{1}]" value="add" id="add[{1}]" checked onclick="show_content(event);" /><label for="add[{1}]"><?php echo addslashes(_AT("add")); ?></label> \\r
253                 <input type="radio" name="rb_action[{1}]" value="alter" id="alter[{1}]" onclick="show_content(event);" /><label for="alter[{1}]"><?php echo addslashes(_AT("alter")); ?></label> \\r
254                 <input type="radio" name="rb_action[{1}]" value="delete" id="delete[{1}]" onclick="show_content(event);" /><label for="delete[{1}]"><?php echo addslashes(_AT("delete")); ?></label> \\r
255                 <input type="radio" name="rb_action[{1}]" value="overwrite" id="overwrite[{1}]" onclick="show_content(event);" /><label for="overwrite[{1}]"><?php echo addslashes(_AT("overwrite")); ?></label> \\r
256         </div> \\r
257         <br /><br /> \\r
258         <div> \\r
259         <table style="display:" width="95%"> \\r
260                 <tr> \\r
261                         <td width="150px"><?php echo addslashes(_AT("file_name")); ?></td> \\r
262                         <td><input name="add_filename[{1}]" type="text"  /></td> \\r
263                 </tr> \\r
264                 <tr> \\r
265                         <td><?php echo addslashes(_AT("directory")); ?></td> \\r
266                         <td><input name="add_dir[{1}]" type="text"  /></td> \\r
267                 </tr> \\r
268                 <tr style="display: none"> \\r
269                         <td><?php echo addslashes(_AT("file")); ?></td> \\r
270                         <td></td> \\r
271                         <td><INPUT TYPE="hidden" NAME="add_uploaded_file[{1}]" SIZE="40" style="max-width:95%" /></td> \\r
272                 </tr> \\r
273                 <tr> \\r
274                         <td><?php echo addslashes(_AT("upload_file")); ?></td> \\r
275                         <td><INPUT TYPE="file" NAME="add_upload_file[{1}]" SIZE="40" style="max-width:95%" /></td> \\r
276                 </tr> \\r
277         </table> \\r
278         <table style="display: none" width="95%"> \\r
279                 <tr> \\r
280                         <td width="150px"><?php echo addslashes(_AT("file_name")); ?></td> \\r
281                         <td><input name="alter_filename[{1}]" type="text" maxlength="100" size="100" /></td> \\r
282                 </tr> \\r
283                 <tr> \\r
284                         <td><?php echo addslashes(_AT("directory")); ?></td> \\r
285                         <td><input name="alter_dir[{1}]" type="text" maxlength="100" size="100" style="max-width:95%" /></td> \\r
286                 </tr> \\r
287                 <tr> \\r
288                         <td><?php echo addslashes(_AT("code_to_replace_from")); ?></td> \\r
289                         <td><textarea name="alter_code_from[{1}]" rows="5" cols="120" style="max-width:95%"></textarea></td> \\r
290                 </tr> \\r
291                 <tr> \\r
292                         <td><?php echo addslashes(_AT("code_to_replace_to")); ?></td> \\r
293                         <td><textarea name="alter_code_to[{1}]" rows="5" cols="120" style="max-width:95%"></textarea></td> \\r
294                 </tr> \\r
295         </table> \\r
296         <table style="display: none" width="95%"> \\r
297                 <tr> \\r
298                         <td width="150px"><?php echo addslashes(_AT("file_name")); ?></td> \\r
299                         <td><input name="delete_filename[{1}]" type="text" maxlength="100" size="100" /></td> \\r
300                 </tr> \\r
301                 <tr> \\r
302                         <td><?php echo addslashes(_AT("directory")); ?></td> \\r
303                         <td><input name="delete_dir[{1}]" type="text" maxlength="100" size="100" /></td> \\r
304                 </tr> \\r
305         </table> \\r
306         <table style="display: none" width="95%"> \\r
307                 <tr> \\r
308                         <td width="150px"><?php echo addslashes(_AT("file_name")); ?></td> \\r
309                         <td><input name="overwrite_filename[{1}]" type="text" /></td> \\r
310                 </tr> \\r
311                 <tr> \\r
312                         <td><?php echo addslashes(_AT("directory")); ?></td> \\r
313                         <td><input name="overwrite_dir[{1}]" type="text" maxlength="100" size="100" /></td> \\r
314                 </tr> \\r
315                 <tr id="overwrite_uploaded_file" style="display:none"> \\r
316                         <td><?php echo addslashes(_AT("file")); ?></td> \\r
317                         <td></td> \\r
318                         <td><INPUT type="hidden" NAME="overwrite_uploaded_file[{1}]" SIZE="40" style="max-width:95%" /></td> \\r
319                 </tr> \\r
320                 <tr> \\r
321                         <td><?php echo addslashes(_AT("upload_file")); ?></td> \\r
322                         <td><INPUT TYPE="file" NAME="overwrite_upload_file[{1}]" SIZE="40" style="max-width:95%" /></td> \\r
323                 </tr> \\r
324         </table> \\r
325         </div> \\r
326         <div style="float:left"> \\r
327                 <input type="button" value="<?php echo addslashes(_AT("delete_this_file")); ?>" onclick="del_file(event)" /> \\r
328         </div> \\r
329         <br /><br /> \\r
330 </div> \\r
331 ';\r
332 \r
333 var patch_files = <?php echo json_encode_result($this->file_rows); ?>;\r
334 \r
335 window.onload = function() {\r
336         for(var i=0; i < patch_files.length; i++) {\r
337                 add_file(patch_files[i]);\r
338         }\r
339 }\r
340 //-->\r
341 </script>\r
342         \r
343 <?php require (TR_INCLUDE_PATH.'footer.inc.php'); ?>\r