2 * phpGACL - Generic Access Control List
3 * Copyright (C) 2002,2003 Mike Benoit
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * For questions, help, comments, discussion, etc., please join the
20 * phpGACL mailing list. http://sourceforge.net/mail/?group_id=57103
22 * You may contact the author of phpGACL by e-mail at:
25 * The latest version of phpGACL can be obtained from:
26 * http://phpgacl.sourceforge.net/
30 var selectedTab = null;
32 //Function to totally clear a select box.
33 function depopulate(form_element) {
34 if (form_element.options.length > 0) {
35 form_element.innerHTML = '';
39 //Populates a select box based off the value of "parent" select box.
40 function populate(parent_form_element, child_form_element, src_array) {
41 //alert('Parent: ' + parent_form_element);
42 //alert('Child: ' + child_form_element);
44 if (parent_form_element.selectedIndex >= 0) {
45 //Grab the current selected value from the parent
46 parent_id = parent_form_element.options[parent_form_element.selectedIndex].value;
48 //Clear the child form element
49 depopulate(child_form_element);
51 //Populate child form element
52 if (options[src_array][parent_id]) {
53 for (i=0; i < options[src_array][parent_id].length; i++) {
54 child_form_element.options[i] = new Option(options[src_array][parent_id][i][1], options[src_array][parent_id][i][0]);
60 //Select an item by "copying" it from one select box to another
61 function select_item(parent_form_element, src_form_element, dst_form_element) {
62 //alert('Src: ' + src_form_element);
63 //alert('Dst: ' + dst_form_element);
65 //Copy it over to the dst element
66 for (i=0; i < src_form_element.options.length; i++) {
67 if (src_form_element.options[i].selected) {
68 //Check to see if duplicate entries exist.
69 for (n=0; n < dst_form_element.options.length; n++) {
70 if ( parent_form_element.options[parent_form_element.selectedIndex].value + '^' + src_form_element.options[i].value == dst_form_element.options[n].value) {
75 //Only add if its not a duplicate entry.
77 //Grab the current selected value from the parent
78 src_id = src_form_element.options[i].value;
79 src_text = src_form_element.options[i].text;
81 src_section_id = parent_form_element.options[parent_form_element.selectedIndex].value;
82 src_section_text = parent_form_element.options[parent_form_element.selectedIndex].text;
84 options_length = dst_form_element.options.length;
85 dst_form_element.options[options_length] = new Option(src_section_text + ' > ' + src_text, src_section_id + '^' + src_id);
86 dst_form_element.options[options_length].selected = true;
94 //Used for moving items to and from the selected combo box.
95 function deselect_item(form_element) {
96 //alert('Src: ' + src_form_element);
97 //alert('Dst: ' + dst_form_element);
99 //Copy it over to the dst element
100 for (i=0; i < form_element.options.length; i++) {
101 if (form_element.options[i].selected) {
102 form_element.options[i] = null;
108 //Used to unselect all items in a combo box
109 function unselect_all(form_element) {
110 for (i=0; i < form_element.options.length; i++) {
111 form_element.options[i].selected = false;
115 function select_all(select_box) {
116 for (i=0; i < select_box.options.length; i++) {
117 select_box.options[i].selected = true;
121 function edit_link(link, parent_id) {
122 alert('edit_aco.php?section_id=' + parent_id + '&return_page={$return_page}')
125 function toggleObject(objectID) {
126 if(document.getElementById) {
127 if(document.getElementById(objectID).className == 'hide') {
128 showObject(objectID);
130 hideObject(objectID);
135 function showObject(objectID) {
136 if(document.getElementById) {
137 document.getElementById(objectID).className = 'show';
141 function hideObject(objectID) {
142 if(document.getElementById) {
143 document.getElementById(objectID).className = 'hide';
147 function showTab(objectID) {
148 if(document.getElementById) {
149 if(selectedObject != objectID) {
150 document.getElementById(objectID).className = 'tabon';
151 selectedTab = objectID;
157 if(document.getElementById) {
159 document.getElementById(selectedTab).className = 'taboff';
164 function checkAll(checkbox) {
165 for (i=0; i<checkbox.form.elements.length; i++) {
166 if (checkbox.form.elements[i].type == checkbox.type) {
167 checkbox.form.elements[i].checked = checkbox.checked;
174 * Sets a Cookie with the given name and value.
176 * name Name of the cookie
177 * value Value of the cookie
178 * [expires] Expiration date of the cookie (default: end of current session)
179 * [path] Path where the cookie is valid (default: path of calling document)
180 * [domain] Domain where the cookie is valid
181 * (default: domain of calling document)
182 * [secure] Boolean value indicating if the cookie transmission requires a
183 * secure transmission
185 function setCookie(name, value, expires, path, domain, secure) {
186 document.cookie= name + "=" + escape(value) +
187 ((expires) ? "; expires=" + expires.toGMTString() : "") +
188 ((path) ? "; path=" + path : "") +
189 ((domain) ? "; domain=" + domain : "") +
190 ((secure) ? "; secure" : "");
194 * Gets the value of the specified cookie.
196 * name Name of the desired cookie.
198 * Returns a string containing value of specified cookie,
199 * or null if cookie does not exist.
201 function getCookie(name) {
202 var dc = document.cookie;
203 var prefix = name + "=";
204 var begin = dc.indexOf("; " + prefix);
206 begin = dc.indexOf(prefix);
207 if (begin != 0) return null;
211 var end = document.cookie.indexOf(";", begin);
215 return unescape(dc.substring(begin + prefix.length, end));
219 * Deletes the specified cookie.
221 * name name of the cookie
222 * [path] path of the cookie (must be same as path used to create cookie)
223 * [domain] domain of the cookie (must be same as domain used to create cookie)
225 function deleteCookie(name, path, domain) {
226 if (getCookie(name)) {
227 document.cookie = name + "=" +
228 ((path) ? "; path=" + path : "") +
229 ((domain) ? "; domain=" + domain : "") +
230 "; expires=Thu, 01-Jan-70 00:00:01 GMT";