home *** CD-ROM | disk | FTP | other *** search
Text File | 2004-03-08 | 31.8 KB | 1,269 lines |
- <?php
- /*
- Copyright Intermesh 2003
- Author: Merijn Schering <mschering@intermesh.nl>
- Version: 1.0 Release date: 08 July 2003
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2 of the License, or (at your
- option) any later version.
- */
-
- class color_selector
- {
- var $colors = array();
-
- function add_color($color_code)
- {
- $this->colors[] = $color_code;
- }
-
- function print_color_selector($name, $selected_color)
- {
- global $GO_THEME;
-
- if (!in_array($selected_color, $this->colors))
- {
- $selected_color = $this->colors[0];
- }
- echo '<input type="hidden" name="'.$name.'" value="'.$selected_color.'" />';
-
-
- echo '<table border="0"><tr>';
-
- while ($color_code = array_shift($this->colors))
- {
- echo '<td id="'.$name.'_'.$color_code.'" style="background-color: #'.$color_code.'; border: 1px solid #aaa;"><a href="javascript:select_background_'.$name.'(\''.$color_code.'\');"><img border="0" height="16" width="16" src="'.$GO_THEME->images['blank'].'" /></a></td>';
- }
- echo '</tr></table>';
-
- echo "
- <script type=\"text/javascript\" language=\"javascript\">
- function select_background_".$name."(color)
- {
- active_table_cell = get_object('".$name."_'+document.forms[0].".$name.".value);
- table_cell = get_object('".$name."_'+color);
- active_table_cell.style.border = '1px solid #aaa';
- table_cell.style.border = '2px solid black';
- document.forms[0].".$name.".value = color;
-
- }
- select_background_".$name."('".$selected_color."');
- </script>";
-
- }
- }
- class date_picker
- {
-
- function get_header()
- {
- global $GO_CONFIG, $jscalendar_language_name;
-
- $jscalendar_language_name = $jscalendar_language_name != '' ? $jscalendar_language_name : 'calendar-en.js';
- $headers = '<script type="text/javascript" src="'.$GO_CONFIG->control_url.'jscalendar/calendar.js"></script>';
- $headers .= '<script type="text/javascript" src="'.$GO_CONFIG->control_url.'jscalendar/lang/'.$jscalendar_language_name.'"></script>';
- $headers .= '<script type="text/javascript" src="'.$GO_CONFIG->control_url.'jscalendar/calendar-setup.js"></script>';
-
- return $headers;
- }
-
- function print_date_picker($name, $date_format, $set_date='', $flat_div_id='', $flat_callbackfunction='')
- {
- $date_format = $this->convert_date_format($date_format);
-
- if ($flat_div_id == '')
- {
- echo '<input class="textbox" type="text" id="'.$name.'-input" name="'.$name.'" value="'.$set_date.'" /><input type="button" id="'.$name.'_button" value="..." />';
- }
-
- echo '<script type="text/javascript">
- var calendar = Calendar.setup(
- {
- firstDay : '.$_SESSION['GO_SESSION']['first_weekday'].',
- inputField : "'.$name.'-input",
- ifFormat : "'.$date_format.'",';
-
- if ($set_date != '')
- {
- echo '
- date : "'.str_replace('-','/',$set_date).'",
- ';
- }
-
- if ($flat_div_id != '')
- {
-
- echo 'flat : "'.$flat_div_id.'",
- flatCallback : '.$flat_callbackfunction;
- }else
- {
- echo 'button : "'.$name.'_button"';
- }
-
- echo '
- });
-
- </script>';
-
-
- }
-
- function convert_date_format($php_date_format)
- {
- /*
- %a abbreviated weekday name
- %A full weekday name
- %b abbreviated month name
- %B full month name
- %C century number
- %d the day of the month ( 00 .. 31 )
- %e the day of the month ( 0 .. 31 )
- %H hour ( 00 .. 23 )
- %I hour ( 01 .. 12 )
- %j day of the year ( 000 .. 366 )
- %k hour ( 0 .. 23 )
- %l hour ( 1 .. 12 )
- %m month ( 01 .. 12 )
- %M minute ( 00 .. 59 )
- %n a newline character
- %p \x{201C}PM\x{201D} or \x{201C}AM\x{201D}
- %P \x{201C}pm\x{201D} or \x{201C}am\x{201D}
- %S second ( 00 .. 59 )
- %s number of seconds since Epoch (since Jan 01 1970 00:00:00 UTC)
- %t a tab character
- %U, %W, %V the week number
- %u the day of the week ( 1 .. 7, 1 = MON )
- %w the day of the week ( 0 .. 6, 0 = SUN )
- %y year without the century ( 00 .. 99 )
- %Y year including the century ( ex. 1979 )
- %% a literal % character
- */
-
-
- $cal_format[] = '%e';
- $php_format[] = 'j';
-
- $cal_format[] = '%d';
- $php_format[] = 'd';
-
- $cal_format[] = '%H';
- $php_format[] = 'H';
-
- $cal_format[] = '%I';
- $php_format[] = 'G';
-
- $cal_format[] = '%k';
- $php_format[] = 'h';
-
- $cal_format[] = '%l';
- $php_format[] = 'g';
-
- $cal_format[] = '%P';
- $php_format[] = 'a';
-
- $cal_format[] = '%Y';
- $php_format[] = 'Y';
-
- $cal_format[] = '%y';
- $php_format[] = 'y';
-
- $cal_format[] = '%m';
- $php_format[] = 'm';
-
- for ($i=0;$i<count($php_format);$i++)
- {
- $php_date_format = str_replace($php_format[$i], $cal_format[$i], $php_date_format);
- }
- return $php_date_format;
- }
-
-
- }
- class button
- {
- function button($text, $action, $size='100')
- {
- echo '<input type="button" class="button" style="width: '.$size.'px;" value="'.$text.'" onclick="'.$action.'" onmouseover="javascript:this.className=\'button_mo\';" onmouseout="javascript:this.className=\'button\';" />';
- }
- }
-
- class checkbox
- {
- function checkbox($name, $value, $text, $checked=false, $disabled=false, $attributes='')
- {
- $id = uniqid(time());
- $checked = $checked ? ' checked' : '';
-
- $disabled_str = $disabled ? ' disabled' : '';
- $checkbox = '<input id="'.$id.'" type="checkbox" name="'.$name.'" value="'.$value.'"'.$checked.$disabled_str.' '.$attributes.' />';
-
- if ($text != '')
- {
- if ($disabled)
- {
- echo $checkbox.'<span style="color: #7d7d7d">'.$text.'</span>';
- }else
- {
- echo $checkbox.'<a href="javascript:check_checkbox(\''.$id.'\')">'.$text.'</a>';
- }
- }else
- {
- echo $checkbox;
- }
- }
- }
-
- class radio_list
- {
- var $group;
- var $selected;
-
- function radio_list($group, $selected='')
- {
- $this->group = $group;
- $this->selected = $selected;
- }
-
- function add_option($name, $value, $text, $disabled=false, $attributes='')
- {
- if ($this->selected == $value)
- {
- $selected = ' checked';
- }else
- {
- $selected = '';
- }
-
- $disabled = $disabled ? ' disabled' : '';
- $radio = '<input id="'.$name.'" type="radio" name="'.$this->group.'" value="'.$value.'"'.$selected.$disabled.' '.$attributes.' />';
-
- if ($text != '')
- {
- if ($disabled == ' disabled')
- {
- echo $radio.'<span style="color: #7d7d7d">'.$text.'</span>';
- }else
- {
- echo $radio.'<a href="javascript:select_radio(\''.$name.'\')">'.$text.'</a>';
- }
- }else
- {
- echo $radio;
- }
- }
- }
-
- class acl
- {
- var $form_name;
- var $acl_id;
- var $read_only;
- var $selected_groups_name;
- var $selected_users_name;
-
- function acl($acl_id)
- {
- global $GO_SECURITY;
-
- $task = isset($_POST['task']) ? $_POST['task'] : '';
-
- if ($acl_id > 0)
- {
- $this->acl_id = $acl_id;
- //$this->read_only = $read_only == 'true' ? true : false;
- $this->read_only = !$GO_SECURITY->user_owns_acl($GO_SECURITY->user_id, $acl_id);
- $this->form_name = 'acl_control_'.$acl_id;
- $this->selected_groups_name = "selected_groups_".$acl_id;
- $this->selected_users_name = "selected_users_".$acl_id;
-
- if ($_SERVER['REQUEST_METHOD'] == "POST")
- {
- switch($task)
- {
- case 'delete_users':
- $this->delete_users();
- break;
-
- case 'delete_groups':
- $this->delete_groups();
- break;
-
- case 'save_add_groups':
- $this->add_groups();
- break;
-
- case 'save_add_users':
- $this->add_users();
- break;
- }
- }
- switch($task)
- {
- case "add_groups":
- $this->print_user_groups();
- break;
-
- case "add_users":
- $this->print_users();
- break;
-
- default:
- $this->print_acl();
- break;
- }
-
- }else
- {
- die('<b>Fatal error:</b> acl id not set');
- }
- }
-
- function print_users()
- {
- global $GO_SECURITY, $GO_CONFIG, $cmdAdd, $cmdCancel, $cmdShowAll,
- $strFirstName,
- $strLastName,
- $strEmail,
- $strCompany,
- $strDepartment,
- $strFunction,
- $strAddress,
- $strCity,
- $strZip,
- $strCountry,
- $strState,
- $strCountry,
- $strWorkAddress,
- $strWorkZip,
- $strWorkCity,
- $strWorkState,
- $strWorkCountry,
- $cmdSearch;
-
- echo '<form name="'.$this->form_name.'" method="post" action="'.$_SERVER['PHP_SELF'].'">';
- echo '<input type="hidden" name="task" value="search" />';
- echo '<input type="hidden" name="acl_id" value="'.$this->acl_id.'" />';
- //echo '<input type="hidden" name="read_only" value="'.$this->read_only.'" />';
-
- echo '<table border="0" cellpadding="0" cellspacing="3"><tr><td>';
-
- $_COOKIE['user_search_field'] = isset($_COOKIE['user_search_field']) ? $_COOKIE['user_search_field'] : 'first_name';
- $search_field = isset($_POST['search_field']) ? $_POST['search_field'] : $_COOKIE['user_search_field'];
-
- $dropbox = new dropbox();
- $dropbox->add_value('first_name', $strFirstName);
- $dropbox->add_value('last_name', $strLastName);
- $dropbox->add_value('email', $strEmail);
- $dropbox->add_value('company', $strCompany);
- $dropbox->add_value('department',$strDepartment);
- $dropbox->add_value('function',$strFunction);
- $dropbox->add_value('address',$strAddress);
- $dropbox->add_value('city', $strCity);
- $dropbox->add_value('zip',$strZip);
- $dropbox->add_value('state',$strState);
- $dropbox->add_value('country', $strCountry);
- $dropbox->add_value('work_address',$strWorkAddress);
- $dropbox->add_value('work_cip',$strWorkZip);
- $dropbox->add_value('work_city',$strWorkCity);
- $dropbox->add_value('work_state',$strWorkState);
- $dropbox->add_value('work_country',$strWorkCountry);
- $dropbox->print_dropbox('search_field', $search_field);
-
- echo '</td><td><input type="text" name="query" size="31" maxlength="255" class="textbox" value="';
- if (isset($_POST['query'])) echo $_POST['query'];
- echo '"></td></tr>';
- echo '<tr><td colspan="2">';
- echo '<table><tr><td>';
- $button = new button($cmdSearch, 'javascript:search()');
- echo '</td><td>';
- $button = new button($cmdShowAll, "javascript:document.".$this->form_name.".query.value='';search()");
- echo '</td><td>';
- $button = new button($cmdCancel, 'javascript:return_to_acl()');
- echo '</td></tr></table>';
- echo '</td></tr></table>';
-
-
- if (isset($_POST['query']))
- {
- require_once($GO_CONFIG->class_path."users.class.inc");
- $users = new users();
- if ($_POST['query'] != '')
- {
- $users->search('%'.$_POST['query'].'%', $search_field, $GO_SECURITY->user_id);
- }else
- {
- $users->get_authorized_users($GO_SECURITY->user_id);
- }
-
- echo '<select name="'.$this->selected_users_name.'[]" multiple="true" style="width: 250px;height: 100px;" class="textbox">';
-
- while ($users->next_record())
- {
- $middle_name = $users->f('middle_name') == '' ? '' : $users->f('middle_name').' ';
- $name = $users->f('first_name').' '.$middle_name.$users->f('last_name');
- echo '<option value="'.$users->f('id').'">'.$name.'</option>';
- }
- echo '</select>';
- echo '<table><tr><td>';
- $button = new button($cmdAdd, 'javascript:add_users()');
- echo '</td></tr></table>';
- }
-
- echo '<script type="text/javascript">
-
- function search()
- {
- document.'.$this->form_name.'.task.value="add_users";
- document.'.$this->form_name.'.submit();
- }
- function add_users()
- {
- document.'.$this->form_name.'.task.value="save_add_users";
- document.'.$this->form_name.'.submit();
- }
-
- function return_to_acl()
- {
- document.'.$this->form_name.'.task.value="";
- document.'.$this->form_name.'.submit();
- }
-
- var nav4 = window.Event ? true : false;
- function processkeypress(e)
- {
- if(nav4)
- {
- var whichCode = e.which;
- }else
- {
- var whichCode = event.keyCode;
- }
-
- if (whichCode == 13)
- {
- search();
- return true;
- }
- }
- if (window.Event) //if Navigator 4.X
- {
- document.captureEvents(Event.KEYPRESS)
- }
- document.onkeypress = processkeypress;
- document.forms[0].query.focus();
- </script>
- ';
-
- echo '</form>';
- }
-
- function print_user_groups()
- {
- global $GO_SECURITY, $GO_CONFIG, $cmdAdd, $cmdCancel;
- //print all groups
- require_once($GO_CONFIG->class_path."groups.class.inc");
- $groups = new groups();
-
- echo '<form name="'.$this->form_name.'" method="post" action="'.$_SERVER['PHP_SELF'].'">';
- echo '<input type="hidden" name="task" value="" />';
- echo '<input type="hidden" name="acl_id" value="'.$this->acl_id.'" />';
- echo '<input type="hidden" name="read_only" value="'.$this->read_only.'" />';
-
- echo '<select name="'.$this->selected_groups_name.'[]" multiple="true" style="width: 250px;height: 100px;" class="textbox">';
- $groups->get_authorised_groups($GO_SECURITY->user_id);
- while ($groups->next_record())
- {
- echo '<option value="'.$groups->f('id').'">'.$groups->f('name').'</option>';
- }
- echo '</select>';
- echo '<table><tr><td>';
- $button = new button($cmdAdd, 'javascript:add_groups()');
- echo '</td><td>';
- $button = new button($cmdCancel, 'javascript:return_to_acl()');
- echo '</td></tr></table>';
-
- echo '</form>';
-
- echo '<script type="text/javascript">
-
- function add_groups()
- {
- document.'.$this->form_name.'.task.value="save_add_groups";
- document.'.$this->form_name.'.submit();
- }
-
- function return_to_acl()
- {
- document.'.$this->form_name.'.task.value="";
- document.'.$this->form_name.'.submit();
- }
- </script>
- ';
- }
-
- function print_groups_in_acl()
- {
- global $GO_SECURITY, $cmdAdd, $cmdDelete;
-
- $disabled = $this->read_only ? 'disabled' : '';
-
- echo '<select name="'.$this->selected_groups_name.'[]" multiple="true" style="width: 250px;height: 100px;" class="textbox" '.$disabled.'>';
- $GO_SECURITY->get_groups_in_acl($this->acl_id);
- while ($GO_SECURITY->next_record())
- {
- echo '<option value="'.$GO_SECURITY->f('id').'">'.$GO_SECURITY->f('name').'</option>';
- }
- echo '</select>';
- if (!$this->read_only)
- {
- echo '<table><tr><td>';
- $button = new button($cmdAdd, 'javacript:add_groups()');
- echo '</td><td>';
- $button = new button($cmdDelete, 'javascript:delete_groups(document.forms[0].'.$this->selected_groups_name.')');
- echo '</td></tr></table>';
- }
- }
-
- function print_users_in_acl()
- {
- global $GO_SECURITY, $cmdAdd, $cmdDelete;
-
- $disabled = $this->read_only ? 'disabled' : '';
-
- $GO_SECURITY->get_users_in_acl($this->acl_id);
- echo '<select name="'.$this->selected_users_name.'[]" multiple="true" style="width: 250px;height: 100px;" class="textbox" '.$disabled.'>';
-
- while ($GO_SECURITY->next_record())
- {
- if ( $GO_SECURITY->f("first_name") ) {
- $middle_name = $GO_SECURITY->f('middle_name') == '' ? '' : $GO_SECURITY->f('middle_name').' ';
- $name = $GO_SECURITY->f('first_name').' '.$middle_name.$GO_SECURITY->f('last_name');
- echo '<option value="'.$GO_SECURITY->f('id').'">'.$name.'</option>';
- } else {
- require_once($GO_CONFIG->class_path.'profiles.class.inc');
- $profiles = new profiles();
- if ($profile = $profiles->get_profile($GO_SECURITY->f('user_id'))) {
- $middle_name = $profile["middle_name"] == '' ? '' : $profile["middle_name"].' ';
- $name = $profile["first_name"].' '.$middle_name.$profile["last_name"];
- echo '<option value="'.$GO_SECURITY->f('user_id').'">'.$name.'</option>';
- }
- }
- }
- echo '</select>';
- if (!$this->read_only)
- {
- echo '<table><tr><td>';
- $button = new button($cmdAdd, 'javascript:add_users()');
- echo '</td><td>';
- $button = new button($cmdDelete, 'javascript:delete_users(document.forms[0].'.$this->selected_users_name.')');
- echo '</td></tr></table>';
- }
- }
-
- function print_acl()
- {
- echo '<script type="text/javascript">
- function add_groups()
- {
- document.'.$this->form_name.'.task.value="add_groups";
- document.'.$this->form_name.'.submit();
- }
-
- function add_users()
- {
- document.'.$this->form_name.'.task.value="add_users";
- document.'.$this->form_name.'.submit();
- }
- function delete_groups()
- {
- document.'.$this->form_name.'.task.value="delete_groups";
- document.'.$this->form_name.'.submit();
- }
-
- function delete_users()
- {
- document.'.$this->form_name.'.task.value="delete_users";
- document.'.$this->form_name.'.submit();
- }
- </script>
- ';
- global $acl_control_auth_groups, $acl_control_auth_users;
- echo '<form name="'.$this->form_name.'" method="post" action="'.$_SERVER['PHP_SELF'].'">';
- echo '<input type="hidden" name="task" value="" />';
- echo '<input type="hidden" name="acl_id" value="'.$this->acl_id.'" />';
- echo '<input type="hidden" name="read_only" value="'.$this->read_only.'" />';
- echo '<h3>'.$acl_control_auth_groups.'</h3>';
- $this->print_groups_in_acl();
- echo '<br />';
- echo '<h3>'.$acl_control_auth_users.'</h3>';
- $this->print_users_in_acl();
- echo '</form>';
- }
-
- function delete_groups()
- {
- global $GO_SECURITY;
-
- $selected_groups = isset($_POST[$this->selected_groups_name]) ? $_POST[$this->selected_groups_name] : array();
-
- for ($i=0;$i<count($selected_groups);$i++)
- {
- $GO_SECURITY->delete_group_from_acl($selected_groups[$i],$this->acl_id);
- }
- }
-
- function delete_users()
- {
- global $GO_SECURITY;
-
- $selected_users = isset($_POST[$this->selected_users_name]) ? $_POST[$this->selected_users_name] : array();
-
- for ($i=0;$i<count($selected_users);$i++)
- {
- if ($selected_users[$i] != $GO_SECURITY->user_id)
- {
- $GO_SECURITY->delete_user_from_acl($selected_users[$i],$this->acl_id);
- }
- }
- }
-
- function add_groups()
- {
- global $GO_SECURITY;
-
- $selected_groups = isset($_POST[$this->selected_groups_name]) ? $_POST[$this->selected_groups_name] : array();
-
- for ($i=0;$i<count($selected_groups);$i++)
- {
- if (!$GO_SECURITY->group_in_acl($selected_groups[$i], $this->acl_id))
- {
- $GO_SECURITY->add_group_to_acl($selected_groups[$i],$this->acl_id);
- }
- }
- }
-
- function add_users()
- {
- global $GO_SECURITY;
-
- $selected_users = isset($_POST[$this->selected_users_name]) ? $_POST[$this->selected_users_name] : array();
-
- for ($i=0;$i<count($selected_users);$i++)
- {
- if (!$GO_SECURITY->user_in_acl($selected_users[$i], $this->acl_id))
- {
- $GO_SECURITY->add_user_to_acl($selected_users[$i],$this->acl_id);
- }
- }
- }
- }
- class statusbar
- {
- var $usage_color = "#0000CC";
- var $background_color = "#f1f1f1";
- var $border_color = "#000000";
- var $width = "250";
- var $height = "10";
- var $info_text;
- var $turn_red_point = 0;
-
- function print_bar($usage, $limit)
- {
- if ($limit != 0)
- {
- $percentage = ($usage/$limit)*100;
- $usage_width = number_format(($usage/$limit)*$this->width);
- $remaining_width = $this->width - $usage_width;
- }else
- {
- $usage_width= 0;
- $remaining_width = $this->width;
- }
- if ($this->turn_red_point > 0 && $percentage >= $this->turn_red_point)
- {
- $this->usage_color = '#FF0000';
- }
-
- echo '<table border="0" cellpadding="1" cellspacing="0">';
- echo '<tr><td bgcolor="'.$this->border_color.'">';
- echo '<table border="0" cellpadding="0" cellspacing="0" width="250">';
- echo '<tr><td height="'.$this->height.'" bgcolor="'.$this->usage_color.'" width="'.$usage_width.'"></td>';
- echo '<td height="'.$this->height.'" bgcolor="'.$this->background_color.'" width="'.$remaining_width.'"></td></tr>';
- echo '</table></td></tr>';
- echo '</table><table border="0" cellpadding="1" cellspacing="0">';
- echo '<tr><td class="small" height="20">'.number_format($percentage).'% '.$this->info_text.'</td></tr>';
- echo '</table>';
- }
-
- }
-
- class dropbox
- {
- var $value=array();
- var $text=array();
- var $optgroup;
-
- function add_value($value, $text)
- {
- if ($text != '')
- {
- $this->value[] = $value;
- $this->text[] = $text;
- return true;
- }else
- {
- return false;
- }
- }
-
- function is_in_dropbox($value)
- {
- return in_array($value, $this->value);
- }
-
- function add_optgroup($name)
- {
- $this->optgroup[count($this->value)] = $name;
- }
-
- function add_sql_data($sql_object, $value, $text)
- {
- global $$sql_object;
-
- while ($$sql_object->next_record())
- {
- $this->value[] = $$sql_object->f($value);
- $this->text[] = $$sql_object->f($text);
- }
- }
-
- function add_arrays($value, $text)
- {
- if (is_array($this->value))
- {
- $this->value = array_merge($this->value, $value);
- $this->text = array_merge($this->text, $text);
- }else
- {
- $this->value = $value;
- $this->text = $text;
- }
- return true;
- }
-
- function count_options()
- {
- return count($this->value);
- }
-
- function print_dropbox($name, $selected_field='', $attributes='', $multiple=false, $size='10')
- {
- $multiple_str = $multiple ? ' multiple="true" size="'.$size.'"' : '';
-
- $optgroup_open = false;
- echo '<select name="'.$name.'" class="textbox"'.$multiple_str.' '.$attributes.'>';
-
- for ($i=0;$i<count($this->value);$i++)
- {
- if(isset($this->optgroup[$i]))
- {
- if ($optgroup_open == true)
- {
- echo '</optgroup>';
- }else
- {
- $optgroup_open = true;
- }
- echo '<optgroup label="'.$this->optgroup[$i].'">';
- }
-
- if ($this->text[$i] != '')
- {
- echo '<option value="'.$this->value[$i].'"';
-
- if ($multiple)
- {
- if (in_array($this->value[$i], $selected_field))
- {
- echo ' selected';
- }
- }else
- {
- if ($this->value[$i] == $selected_field)
- {
- echo ' selected';
- }
- }
- echo '>';
- echo $this->text[$i];
- echo '</option>';
- }
- }
- if ($optgroup_open == true)
- {
- echo '</optgroup>';
- }
- echo '</select>';
- }
- }
-
- class htmlarea
- {
- var $buttons = array();
- var $fonts = array();
- var $pagestyle = '';
- var $header = '';
- var $name;
- var $rows;
- var $width;
-
- function get_styles($style)
- {
- $styles = array();
- $style_name = '';
- $in_style = false;
-
- $style = str_replace("\r", '', $style);
- $style = str_replace("\n", '', $style);
- $style = str_replace(' ', '', $style);
- for ($i=0; $i<strlen($style); $i++)
- {
- $char = $style[$i];
-
- if ($char == '{' || $char == ',')
- {
- $in_style = false;
- if (trim($style_name) != '')
- {
- $styles[] = $style_name;
- }
- $style_name = '';
- }elseif($char == '.')
- {
- if ($style_name != '')
- {
- $style_name = '';
- $in_style = false;
- }else
- {
- $in_style = true;
- }
- }elseif($char == ':')
- {
- $style_name = '';
- $in_style = false;
- }elseif($char == '}')
- {
- $in_style = false;
- $style_name = '';
- }else
- {
- if ($in_style)
- {
- $style_name .= $char;
- }
- }
- }
-
- return $styles;
- }
-
-
- function register_dropdown($id, $tooltip, $options, $context, $action, $refresh)
- {
- $button['code'] = '
- config.registerDropdown({
- id: "'.$id.'",
- tooltip: "'.$tooltip.'",
- options: {';
- $option_count = count($options);
- for($i=0;$i<$option_count;$i++)
- {
- if ($i!=0)
- {
- $button['code'] .= ',';
- }
- $button['code'] .= '"'.$options[$i]['text'].'":"'.$options[$i]['value'].'"';
- }
-
- $button['code'] .= '},
- context : "'.$context.'",
- action: '.$action.',
- refresh: '.$refresh.'
- });';
- $button['id'] = $id;
- $this->buttons[] = $button;
- }
-
- function add_button($id, $tooltip, $image, $textmode, $action)
- {
- $button['code'] = '
- config.registerButton("'.$id.'", "'.$tooltip.'", "'.$image.'", '.$textmode.', '.$action.');
- ';
- $button['id'] = $id;
- $this->buttons[] = $button;
- }
-
- function add_font($name, $family)
- {
- $font['name'] = $name;
- $font['family'] = $family;
- $this->fonts[] = $font;
- }
-
- function get_header($name, $width='600px', $height='400px', $rows='20', $pagestyle='', $config_options='')
- {
- global $GO_CONFIG, $htmlarea_language_name;
- $this->width = 0;
- $this->name = $name;
- $this->rows = $rows;
-
- $this->pagestyle = $pagestyle == '' ? $this->pagestyle : $pagestyle;
-
- $editor_url = $GO_CONFIG->control_url.'htmlarea/';
- $header = '
- <script type="text/javascript">
- _editor_url = "'.$editor_url.'";
- _editor_lang = "'.$htmlarea_language_name.'";
- </script>
- <script type="text/javascript" src="'.$GO_CONFIG->control_url.'htmlarea/htmlarea.js"></script>
- <!-- load the plugins -->
- <script type="text/javascript">
- HTMLArea.loadPlugin("CSS");
-
- var editor = null;
-
- function initEditor()
- {
- editor = new HTMLArea("'.$name.'");
- config = editor.config;
- ';
-
-
- if ($width <= 0)
- {
- $width=substr($width,1);
- $header .= '
-
- config.width = 630;
- if (parseInt(navigator.appVersion)>3)
- {
- if (navigator.appName=="Netscape")
- {
- config.width= window.innerWidth-'.$width.';
- }
- if (navigator.appName.indexOf("Microsoft")!=-1)
- {
- config.width = document.body.offsetWidth-'.$width.'-20;
- }
- if (config.width < 200)
- {
- config.width = 200;
- }
- }
- ';
- }else
- {
- $header .= 'config.width = "'.$width.'";';
- }
-
- if ($height <= 0)
- {
- $height=substr($height,1);
- $header .= '
- config.height = 460;
-
- if (parseInt(navigator.appVersion)>3)
- {
- if (navigator.appName=="Netscape")
- {
- config.height = window.innerHeight-'.$height.';
- }
- if (navigator.appName.indexOf("Microsoft")!=-1)
- {
- config.height = document.body.offsetHeight-'.$height.'-20;
- }
-
- if (config.height < 200)
- {
- config.height = 200;
- }
- }
- ';
- }else
- {
- $header .= 'config.height = "'.$height.'";';
- }
-
- $header .= '
- // enable creation of a status bar?
- config.statusBar = false;
-
- // the next parameter specifies whether the toolbar should be included
- // in the size or not.
- config.sizeIncludesToolbar = true;
-
- config.pageStyle = "'.addslashes($this->pagestyle).'";';
-
- $header .= $config_options;
-
- //add buttons
- $first=true;
- $push = 'config.toolbar.push([';
- while ($button = array_shift($this->buttons))
- {
- $header .= $button['code'];
- if ($first)
- {
- $first=false;
- $push .= "'".$button['id']."'";
- }else
- {
- $push .= ",'".$button['id']."'";
- }
- }
- $push .= ']);';
-
- $header .= $push;
-
- if ($combos = $this->generate_combos())
- {
- $header .= 'editor.registerPlugin(CSS, '.$combos.');';
- }
-
- $header .= '
- setTimeout(function(){editor.generate();}, 500);
- window.onresize = resize_editor;
- }
-
- function editor_insertHTML(html) {
- editor.insertHTML(html);
- }
-
- function editor_insertImage(src)
- {
- alert(src);
- var img = new Image();
- img.src=src;
- img.border=0;
- img.align="absmiddle";
- img.vspace=0;
- img.hspace=0;
- editor._insertImage(img);
- }
-
- function resize_editor()
- {
- var newHeight;
- var newWidth;
-
- if (parseInt(navigator.appVersion)>3)
- {
- if (navigator.appName=="Netscape")
- {
- newHeight = window.innerHeight-'.$height.'-100;
- newWidth = window.innerWidth-'.$width.'-10;
- }
- if (navigator.appName.indexOf("Microsoft")!=-1)
- {
- newHeight = document.body.offsetHeight - editor._toolbar.offsetHeight - '.$height.'-20;
- newWidth = document.body.offsetWidth-'.$width.'-20;
-
- }
-
- }
- if (newHeight < 200) { newHeight = 200; }
- if (newWidth < 200) { newWidth = 200; }
-
-
- if (editor.config.statusBar) {
- newHeight -= editor._statusBar.offsetHeight;
- }
-
- editor._textArea.style.height = editor._iframe.style.height = newHeight + "px";
- editor._textArea.style.width = editor._iframe.style.width = newWidth + "px";
-
- }
-
- </script>
- ';
-
- return $header;
- }
-
- function generate_combos()
- {
- $styles = $this->get_styles($this->pagestyle);
-
- if (count($styles) > 0)
- {
- $combos = '
- {
- combos : [
- { label: "Syntax:",
-
- options: {"CSS":""';
-
- for ($i=0;$i<count($styles);$i++)
- {
- $combos .= ', "'.$styles[$i].'":"'.$styles[$i].'"';
- }
-
- $combos .= '}
- }
- ]
- }';
- return $combos;
- }else
- {
- return false;
- }
- }
-
- function print_htmlarea($value)
- {
- echo '<textarea id="'.$this->name.'" style="width: '.$this->width.'" name="'.$this->name.'", rows="'.$this->rows.'">'.$value.'</textarea>';
- }
-
- function htmlarea()
- {
- }
- }
-
- class tabtable
- {
- var $tabs = array();
- var $docs = array();
- var $id;
- var $width;
- var $height;
- var $tabwidth;
- //arguments are extra vars that are passed in the links from the tabs
- var $arguments;
- var $submit_form;
- var $active_tab;
- var $form_name;
-
- //css classes
-
- var $css_tab = 'Tab';
- var $css_active_tab = 'Activetab';
- var $css_table = 'tabtable';
- var $css_tab_background = 'TabBackground';
-
- //constructor sets basic propertiesz
- function tabtable($id, $title, $width='400', $height='400', $tabwidth='120', $arguments='', $submit_form=false, $align='left', $valign='top', $form_name='forms[0]')
- {
- $this->id = $id;
- $this->title = $title;
- $this->width = $width;
- $this->height = $height;
- $this->tabwidth = $tabwidth;
- $this->submit_form = $submit_form;
- $this->arguments = $arguments;
- $this->align=$align;
- $this->valign=$valign;
- $this->form_name=$form_name;
-
- $active_tab_ref = $this->id;
- $this->active_tab = isset($_REQUEST[$active_tab_ref]) ? $_REQUEST[$active_tab_ref] : 0;
- }
-
- function set_classnames($table, $tab, $active_tab, $tab_background)
- {
- $this->css_table= $table;
- $this->css_tab= $tab;
- $this->css_active_tab = $active_tab;
- $this->css_tab_background = $tab_background;
- }
-
- //hint: Id could be a document to include
- function add_tab($id, $name)
- {
- $this->tabs[] = $name;
- $this->docs[] = $id;
- }
-
- //set the active tab manually call this before the print_head() function
- function set_active_tab($index)
- {
- if (isset($this->tabs[$index]))
- {
- $this->active_tab = $index;
- return true;
- }else
- {
- return false;
- }
- }
-
- /*last three functions should be called in this order
- $tabtable->print_head();
- require($tabtable->get_active_tab_id());
- $tabtable->print_foot();
- */
- function print_head()
- {
- $active_tab_ref = $this->id;
- echo '
- <script type="text/javascript">
- function change_tab(activetab)
- {
- document.'.$this->form_name.'.action.value = document.forms[0].action.value+"'.$this->arguments.'";
- document.'.$this->form_name.'.'.$active_tab_ref.'.value = activetab;
- document.'.$this->form_name.'.submit();
- }
- </script>
- ';
- echo '<input type="hidden" name="'.$active_tab_ref.'" value="'.$this->active_tab.'" />';
- echo '<table border="0" cellpadding="0" cellspacing="0" id="'.$this->css_table.'" width="'.$this->width.'">';
- echo '<tr><th colspan="99">'.$this->title.'</th></tr>';
- $tab_count = count($this->tabs);
- $remaining_width= $this->width - ($tab_count * $this->tabwidth);
- if ($tab_count > 0)
- {
- echo '<tr><td class="'.$this->css_tab_background.'"><table border="0" cellpadding="0" cellspacing="0"><tr>';
- //draw tabs and select the active doc
- for ($i=0;$i<$tab_count;$i++)
- {
- if ($i == $this->active_tab)
- {
- echo '<td align="center" class="'.$this->css_active_tab.'" width="'.$this->tabwidth.'" nowrap>'.$this->tabs[$i].'</td>';
- }else
- {
- if ($this->submit_form)
- {
- echo '<td align="center" class="'.$this->css_tab.'" width="'.$this->tabwidth.'" nowrap><a class="Tab" href="javascript:change_tab('.$i.')">'.$this->tabs[$i].'</a></td>';
- }else
- {
- echo '<td align="center" class="'.$this->css_tab.'" width="'.$this->tabwidth.'" nowrap><a class="Tab" href="'.$_SERVER['PHP_SELF'].'?'.$active_tab_ref.'='.$i.$this->arguments.'">'.$this->tabs[$i].'</a></td>';
- }
- }
- }
- echo '</tr></table></td></tr>';
- }
- echo '<tr><td colspan="99" cellpadding="10" cellspacing="0" height="'.$this->height.'" valign="'.$this->valign.'" width="100%" align="'.$this->align.'" style="padding: 10px;">';
-
- }
-
- function get_active_tab_id()
- {
- if (isset($this->docs[$this->active_tab]))
- {
- return $this->docs[$this->active_tab];
- }else
- {
- return false;
- }
- }
-
- function print_foot()
- {
- echo '</td></tr></table></td></tr></table>';
- }
- }
-
- ?>
-