home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / classes / .#controls.class.inc.1.71 next >
Text File  |  2004-03-08  |  33KB  |  1,269 lines

  1. <?php
  2. /*
  3. Copyright Intermesh 2003
  4. Author: Merijn Schering <mschering@intermesh.nl>
  5. Version: 1.0 Release date: 08 July 2003
  6.  
  7. This program is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.
  11. */
  12.  
  13. class color_selector
  14. {
  15.     var $colors = array();
  16.  
  17.     function add_color($color_code)
  18.     {
  19.         $this->colors[] = $color_code;
  20.     }
  21.  
  22.     function print_color_selector($name, $selected_color)
  23.     {
  24.         global $GO_THEME;
  25.  
  26.         if (!in_array($selected_color, $this->colors))
  27.         {
  28.             $selected_color = $this->colors[0];
  29.         }
  30.         echo '<input type="hidden" name="'.$name.'" value="'.$selected_color.'" />';
  31.  
  32.  
  33.         echo '<table border="0"><tr>';
  34.  
  35.         while ($color_code = array_shift($this->colors))
  36.         {
  37.             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>';
  38.         }
  39.         echo '</tr></table>';
  40.  
  41.         echo "
  42.         <script type=\"text/javascript\" language=\"javascript\">
  43.         function select_background_".$name."(color)
  44.         {
  45.             active_table_cell = get_object('".$name."_'+document.forms[0].".$name.".value);
  46.             table_cell = get_object('".$name."_'+color);
  47.             active_table_cell.style.border = '1px solid #aaa';
  48.             table_cell.style.border = '2px solid black';
  49.             document.forms[0].".$name.".value = color;
  50.  
  51.         }
  52.         select_background_".$name."('".$selected_color."');
  53.         </script>";
  54.  
  55.     }
  56. }
  57. class date_picker
  58. {
  59.  
  60.     function get_header()
  61.     {
  62.         global $GO_CONFIG, $jscalendar_language_name;
  63.  
  64.         $jscalendar_language_name = $jscalendar_language_name != '' ? $jscalendar_language_name : 'calendar-en.js';
  65.         $headers  = '<script type="text/javascript" src="'.$GO_CONFIG->control_url.'jscalendar/calendar.js"></script>';
  66.         $headers .= '<script type="text/javascript" src="'.$GO_CONFIG->control_url.'jscalendar/lang/'.$jscalendar_language_name.'"></script>';
  67.         $headers .= '<script type="text/javascript" src="'.$GO_CONFIG->control_url.'jscalendar/calendar-setup.js"></script>';
  68.  
  69.         return $headers;
  70.     }
  71.  
  72.     function print_date_picker($name, $date_format, $set_date='', $flat_div_id='', $flat_callbackfunction='')
  73.     {
  74.         $date_format = $this->convert_date_format($date_format);
  75.  
  76.         if ($flat_div_id == '')
  77.         {
  78.             echo '<input class="textbox" type="text" id="'.$name.'-input" name="'.$name.'" value="'.$set_date.'" /><input type="button" id="'.$name.'_button" value="..." />';
  79.         }
  80.  
  81.         echo '<script type="text/javascript">
  82.         var calendar = Calendar.setup(
  83.             {
  84.                   firstDay  : '.$_SESSION['GO_SESSION']['first_weekday'].',
  85.                   inputField  : "'.$name.'-input",
  86.                   ifFormat    : "'.$date_format.'",';
  87.  
  88.                   if ($set_date != '')
  89.                   {
  90.                       echo '
  91.                       date :  "'.str_replace('-','/',$set_date).'",
  92.                       ';
  93.                     }
  94.  
  95.         if ($flat_div_id != '')
  96.         {
  97.  
  98.             echo 'flat         : "'.$flat_div_id.'",
  99.                   flatCallback : '.$flat_callbackfunction;
  100.         }else
  101.         {
  102.             echo 'button      : "'.$name.'_button"';
  103.         }
  104.  
  105.         echo '
  106.             });
  107.  
  108.         </script>';
  109.  
  110.  
  111.     }
  112.  
  113.     function convert_date_format($php_date_format)
  114.     {
  115.         /*
  116.         %a     abbreviated weekday name
  117.         %A     full weekday name
  118.         %b     abbreviated month name
  119.         %B     full month name
  120.         %C     century number
  121.         %d     the day of the month ( 00 .. 31 )
  122.         %e     the day of the month ( 0 .. 31 )
  123.         %H     hour ( 00 .. 23 )
  124.         %I     hour ( 01 .. 12 )
  125.         %j     day of the year ( 000 .. 366 )
  126.         %k     hour ( 0 .. 23 )
  127.         %l     hour ( 1 .. 12 )
  128.         %m     month ( 01 .. 12 )
  129.         %M     minute ( 00 .. 59 )
  130.         %n     a newline character
  131.         %p     \x{201C}PM\x{201D} or \x{201C}AM\x{201D}
  132.         %P     \x{201C}pm\x{201D} or \x{201C}am\x{201D}
  133.         %S     second ( 00 .. 59 )
  134.         %s     number of seconds since Epoch (since Jan 01 1970 00:00:00 UTC)
  135.         %t     a tab character
  136.         %U, %W, %V     the week number
  137.         %u     the day of the week ( 1 .. 7, 1 = MON )
  138.         %w     the day of the week ( 0 .. 6, 0 = SUN )
  139.         %y     year without the century ( 00 .. 99 )
  140.         %Y     year including the century ( ex. 1979 )
  141.         %%     a literal % character
  142.         */
  143.  
  144.  
  145.         $cal_format[] = '%e';
  146.         $php_format[] = 'j';
  147.  
  148.         $cal_format[] = '%d';
  149.         $php_format[] = 'd';
  150.  
  151.         $cal_format[] = '%H';
  152.         $php_format[] = 'H';
  153.  
  154.         $cal_format[] = '%I';
  155.         $php_format[] = 'G';
  156.  
  157.         $cal_format[] = '%k';
  158.         $php_format[] = 'h';
  159.  
  160.         $cal_format[] = '%l';
  161.         $php_format[] = 'g';
  162.  
  163.         $cal_format[] = '%P';
  164.         $php_format[] = 'a';
  165.  
  166.         $cal_format[] = '%Y';
  167.         $php_format[] = 'Y';
  168.  
  169.         $cal_format[] = '%y';
  170.         $php_format[] = 'y';
  171.  
  172.         $cal_format[] = '%m';
  173.         $php_format[] = 'm';
  174.  
  175.         for ($i=0;$i<count($php_format);$i++)
  176.         {
  177.             $php_date_format = str_replace($php_format[$i], $cal_format[$i], $php_date_format);
  178.         }
  179.         return $php_date_format;
  180.     }
  181.  
  182.  
  183. }
  184. class button
  185. {
  186.     function button($text, $action, $size='100')
  187.     {
  188.         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\';" />';
  189.     }
  190. }
  191.  
  192. class checkbox
  193. {
  194.     function checkbox($name, $value, $text, $checked=false, $disabled=false, $attributes='')
  195.     {
  196.         $id = uniqid(time());
  197.         $checked = $checked ? ' checked' : '';
  198.  
  199.         $disabled_str = $disabled ? ' disabled' : '';
  200.         $checkbox = '<input id="'.$id.'" type="checkbox" name="'.$name.'" value="'.$value.'"'.$checked.$disabled_str.' '.$attributes.' />';
  201.  
  202.         if ($text != '')
  203.         {
  204.             if ($disabled)
  205.             {
  206.                 echo $checkbox.'<span style="color: #7d7d7d">'.$text.'</span>';
  207.             }else
  208.             {
  209.                 echo $checkbox.'<a href="javascript:check_checkbox(\''.$id.'\')">'.$text.'</a>';
  210.             }
  211.         }else
  212.         {
  213.             echo $checkbox;
  214.         }
  215.     }
  216. }
  217.  
  218. class radio_list
  219. {
  220.     var $group;
  221.     var $selected;
  222.  
  223.     function radio_list($group, $selected='')
  224.     {
  225.         $this->group = $group;
  226.         $this->selected = $selected;
  227.     }
  228.  
  229.     function add_option($name, $value, $text, $disabled=false, $attributes='')
  230.     {
  231.         if ($this->selected == $value)
  232.         {
  233.             $selected = ' checked';
  234.         }else
  235.         {
  236.             $selected = '';
  237.         }
  238.  
  239.         $disabled = $disabled ? ' disabled' : '';
  240.         $radio = '<input id="'.$name.'" type="radio" name="'.$this->group.'" value="'.$value.'"'.$selected.$disabled.' '.$attributes.' />';
  241.  
  242.         if ($text != '')
  243.         {
  244.             if ($disabled == ' disabled')
  245.             {
  246.                 echo $radio.'<span style="color: #7d7d7d">'.$text.'</span>';
  247.             }else
  248.             {
  249.                 echo $radio.'<a href="javascript:select_radio(\''.$name.'\')">'.$text.'</a>';
  250.             }
  251.         }else
  252.         {
  253.             echo $radio;
  254.         }
  255.     }
  256. }
  257.  
  258. class acl
  259. {
  260.     var $form_name;
  261.     var $acl_id;
  262.     var $read_only;
  263.     var $selected_groups_name;
  264.     var $selected_users_name;
  265.  
  266.     function acl($acl_id)
  267.     {
  268.         global $GO_SECURITY;
  269.  
  270.         $task = isset($_POST['task']) ? $_POST['task'] : '';
  271.  
  272.         if ($acl_id > 0)
  273.         {
  274.             $this->acl_id = $acl_id;
  275.             //$this->read_only = $read_only == 'true' ? true : false;
  276.             $this->read_only = !$GO_SECURITY->user_owns_acl($GO_SECURITY->user_id, $acl_id);
  277.             $this->form_name = 'acl_control_'.$acl_id;
  278.             $this->selected_groups_name = "selected_groups_".$acl_id;
  279.             $this->selected_users_name = "selected_users_".$acl_id;
  280.  
  281.             if ($_SERVER['REQUEST_METHOD'] == "POST")
  282.             {
  283.                 switch($task)
  284.                 {
  285.                     case 'delete_users':
  286.                         $this->delete_users();
  287.                     break;
  288.  
  289.                     case 'delete_groups':
  290.                         $this->delete_groups();
  291.                     break;
  292.  
  293.                     case 'save_add_groups':
  294.                         $this->add_groups();
  295.                     break;
  296.  
  297.                     case 'save_add_users':
  298.                         $this->add_users();
  299.                     break;
  300.                 }
  301.             }
  302.             switch($task)
  303.             {
  304.                 case "add_groups":
  305.                     $this->print_user_groups();
  306.                 break;
  307.  
  308.                 case "add_users":
  309.                     $this->print_users();
  310.                 break;
  311.  
  312.                 default:
  313.                     $this->print_acl();
  314.                 break;
  315.             }
  316.  
  317.         }else
  318.         {
  319.             die('<b>Fatal error:</b> acl id not set');
  320.         }
  321.     }
  322.  
  323.     function print_users()
  324.     {
  325.         global $GO_SECURITY, $GO_CONFIG, $cmdAdd, $cmdCancel, $cmdShowAll,
  326.         $strFirstName,
  327.         $strLastName,
  328.         $strEmail,
  329.         $strCompany,
  330.         $strDepartment,
  331.         $strFunction,
  332.         $strAddress,
  333.         $strCity,
  334.         $strZip,
  335.         $strCountry,
  336.         $strState,
  337.         $strCountry,
  338.         $strWorkAddress,
  339.         $strWorkZip,
  340.         $strWorkCity,
  341.         $strWorkState,
  342.         $strWorkCountry,
  343.         $cmdSearch;
  344.  
  345.         echo '<form name="'.$this->form_name.'" method="post" action="'.$_SERVER['PHP_SELF'].'">';
  346.         echo '<input type="hidden" name="task" value="search" />';
  347.         echo '<input type="hidden" name="acl_id" value="'.$this->acl_id.'" />';
  348.         //echo '<input type="hidden" name="read_only" value="'.$this->read_only.'" />';
  349.  
  350.         echo '<table border="0" cellpadding="0" cellspacing="3"><tr><td>';
  351.  
  352.         $_COOKIE['user_search_field'] = isset($_COOKIE['user_search_field']) ? $_COOKIE['user_search_field'] : 'first_name';
  353.         $search_field = isset($_POST['search_field']) ? $_POST['search_field'] : $_COOKIE['user_search_field'];
  354.  
  355.         $dropbox = new dropbox();
  356.         $dropbox->add_value('first_name', $strFirstName);
  357.         $dropbox->add_value('last_name', $strLastName);
  358.         $dropbox->add_value('email', $strEmail);
  359.         $dropbox->add_value('company', $strCompany);
  360.         $dropbox->add_value('department',$strDepartment);
  361.         $dropbox->add_value('function',$strFunction);
  362.         $dropbox->add_value('address',$strAddress);
  363.         $dropbox->add_value('city', $strCity);
  364.         $dropbox->add_value('zip',$strZip);
  365.         $dropbox->add_value('state',$strState);
  366.         $dropbox->add_value('country', $strCountry);
  367.         $dropbox->add_value('work_address',$strWorkAddress);
  368.         $dropbox->add_value('work_cip',$strWorkZip);
  369.         $dropbox->add_value('work_city',$strWorkCity);
  370.         $dropbox->add_value('work_state',$strWorkState);
  371.         $dropbox->add_value('work_country',$strWorkCountry);
  372.         $dropbox->print_dropbox('search_field', $search_field);
  373.  
  374.         echo '</td><td><input type="text" name="query" size="31" maxlength="255" class="textbox" value="';
  375.         if (isset($_POST['query'])) echo $_POST['query'];
  376.         echo '"></td></tr>';
  377.         echo '<tr><td colspan="2">';
  378.         echo '<table><tr><td>';
  379.         $button = new button($cmdSearch, 'javascript:search()');
  380.         echo '</td><td>';
  381.         $button = new button($cmdShowAll, "javascript:document.".$this->form_name.".query.value='';search()");
  382.         echo '</td><td>';
  383.         $button = new button($cmdCancel, 'javascript:return_to_acl()');
  384.         echo '</td></tr></table>';
  385.         echo '</td></tr></table>';
  386.  
  387.  
  388.         if (isset($_POST['query']))
  389.         {
  390.             require_once($GO_CONFIG->class_path."users.class.inc");
  391.             $users = new users();
  392.             if ($_POST['query'] != '')
  393.             {
  394.                 $users->search('%'.$_POST['query'].'%', $search_field, $GO_SECURITY->user_id);
  395.             }else
  396.             {
  397.                 $users->get_authorized_users($GO_SECURITY->user_id);
  398.             }
  399.  
  400.             echo '<select name="'.$this->selected_users_name.'[]" multiple="true" style="width: 250px;height: 100px;" class="textbox">';
  401.  
  402.             while ($users->next_record())
  403.             {
  404.                 $middle_name = $users->f('middle_name') == '' ? '' : $users->f('middle_name').' ';
  405.                 $name = $users->f('first_name').' '.$middle_name.$users->f('last_name');
  406.                 echo '<option value="'.$users->f('id').'">'.$name.'</option>';
  407.             }
  408.             echo '</select>';
  409.             echo '<table><tr><td>';
  410.             $button = new button($cmdAdd, 'javascript:add_users()');
  411.             echo '</td></tr></table>';
  412.         }
  413.  
  414.         echo '<script type="text/javascript">
  415.  
  416.         function search()
  417.         {
  418.             document.'.$this->form_name.'.task.value="add_users";
  419.             document.'.$this->form_name.'.submit();
  420.         }
  421.         function add_users()
  422.         {
  423.             document.'.$this->form_name.'.task.value="save_add_users";
  424.             document.'.$this->form_name.'.submit();
  425.         }
  426.  
  427.         function return_to_acl()
  428.         {
  429.             document.'.$this->form_name.'.task.value="";
  430.             document.'.$this->form_name.'.submit();
  431.         }
  432.  
  433.         var nav4 = window.Event ? true : false;
  434.         function processkeypress(e)
  435.         {
  436.             if(nav4)
  437.             {
  438.                 var whichCode = e.which;
  439.             }else
  440.              {
  441.                 var whichCode = event.keyCode;
  442.             }
  443.  
  444.             if (whichCode == 13)
  445.             {
  446.                 search();
  447.                 return true;
  448.             }
  449.         }
  450.         if (window.Event) //if Navigator 4.X
  451.         {
  452.             document.captureEvents(Event.KEYPRESS)
  453.         }
  454.         document.onkeypress = processkeypress;
  455.         document.forms[0].query.focus();
  456.         </script>
  457.         ';
  458.  
  459.         echo '</form>';
  460.     }
  461.  
  462.     function print_user_groups()
  463.     {
  464.         global $GO_SECURITY, $GO_CONFIG, $cmdAdd, $cmdCancel;
  465.         //print all groups
  466.         require_once($GO_CONFIG->class_path."groups.class.inc");
  467.         $groups = new groups();
  468.  
  469.         echo '<form name="'.$this->form_name.'" method="post" action="'.$_SERVER['PHP_SELF'].'">';
  470.         echo '<input type="hidden" name="task" value="" />';
  471.         echo '<input type="hidden" name="acl_id" value="'.$this->acl_id.'" />';
  472.         echo '<input type="hidden" name="read_only" value="'.$this->read_only.'" />';
  473.  
  474.         echo '<select name="'.$this->selected_groups_name.'[]" multiple="true" style="width: 250px;height: 100px;" class="textbox">';
  475.         $groups->get_authorised_groups($GO_SECURITY->user_id);
  476.         while ($groups->next_record())
  477.         {
  478.             echo '<option value="'.$groups->f('id').'">'.$groups->f('name').'</option>';
  479.         }
  480.         echo '</select>';
  481.         echo '<table><tr><td>';
  482.         $button = new button($cmdAdd, 'javascript:add_groups()');
  483.         echo '</td><td>';
  484.         $button = new button($cmdCancel, 'javascript:return_to_acl()');
  485.         echo '</td></tr></table>';
  486.  
  487.         echo '</form>';
  488.  
  489.         echo '<script type="text/javascript">
  490.  
  491.         function add_groups()
  492.         {
  493.             document.'.$this->form_name.'.task.value="save_add_groups";
  494.             document.'.$this->form_name.'.submit();
  495.         }
  496.  
  497.         function return_to_acl()
  498.         {
  499.             document.'.$this->form_name.'.task.value="";
  500.             document.'.$this->form_name.'.submit();
  501.         }
  502.         </script>
  503.         ';
  504.     }
  505.  
  506.     function print_groups_in_acl()
  507.     {
  508.         global $GO_SECURITY, $cmdAdd, $cmdDelete;
  509.  
  510.         $disabled = $this->read_only ? 'disabled' : '';
  511.  
  512.         echo '<select name="'.$this->selected_groups_name.'[]" multiple="true" style="width: 250px;height: 100px;" class="textbox" '.$disabled.'>';
  513.         $GO_SECURITY->get_groups_in_acl($this->acl_id);
  514.         while ($GO_SECURITY->next_record())
  515.         {
  516.             echo '<option value="'.$GO_SECURITY->f('id').'">'.$GO_SECURITY->f('name').'</option>';
  517.         }
  518.         echo '</select>';
  519.         if (!$this->read_only)
  520.         {
  521.             echo '<table><tr><td>';
  522.             $button = new button($cmdAdd, 'javacript:add_groups()');
  523.             echo '</td><td>';
  524.             $button = new button($cmdDelete, 'javascript:delete_groups(document.forms[0].'.$this->selected_groups_name.')');
  525.             echo '</td></tr></table>';
  526.         }
  527.     }
  528.  
  529.     function print_users_in_acl()
  530.     {
  531.         global $GO_SECURITY, $cmdAdd, $cmdDelete;
  532.  
  533.         $disabled = $this->read_only ? 'disabled' : '';
  534.  
  535.         $GO_SECURITY->get_users_in_acl($this->acl_id);
  536.         echo '<select name="'.$this->selected_users_name.'[]" multiple="true" style="width: 250px;height: 100px;" class="textbox" '.$disabled.'>';
  537.  
  538.         while ($GO_SECURITY->next_record())
  539.         {
  540.             if ( $GO_SECURITY->f("first_name") ) {
  541.                 $middle_name = $GO_SECURITY->f('middle_name') == '' ? '' : $GO_SECURITY->f('middle_name').' ';
  542.                 $name = $GO_SECURITY->f('first_name').' '.$middle_name.$GO_SECURITY->f('last_name');
  543.                 echo '<option value="'.$GO_SECURITY->f('id').'">'.$name.'</option>';
  544.             } else {
  545.                 require_once($GO_CONFIG->class_path.'profiles.class.inc');
  546.                 $profiles = new profiles();
  547.                 if ($profile = $profiles->get_profile($GO_SECURITY->f('user_id'))) {
  548.                     $middle_name = $profile["middle_name"] == '' ? '' : $profile["middle_name"].' ';
  549.                     $name = $profile["first_name"].' '.$middle_name.$profile["last_name"];
  550.                     echo '<option value="'.$GO_SECURITY->f('user_id').'">'.$name.'</option>';
  551.                 }
  552.             }
  553.         }
  554.         echo '</select>';
  555.         if (!$this->read_only)
  556.         {
  557.             echo '<table><tr><td>';
  558.             $button = new button($cmdAdd, 'javascript:add_users()');
  559.             echo '</td><td>';
  560.             $button = new button($cmdDelete, 'javascript:delete_users(document.forms[0].'.$this->selected_users_name.')');
  561.             echo '</td></tr></table>';
  562.         }
  563.     }
  564.  
  565.     function print_acl()
  566.     {
  567.         echo '<script type="text/javascript">
  568.         function add_groups()
  569.         {
  570.             document.'.$this->form_name.'.task.value="add_groups";
  571.             document.'.$this->form_name.'.submit();
  572.         }
  573.  
  574.         function add_users()
  575.         {
  576.             document.'.$this->form_name.'.task.value="add_users";
  577.             document.'.$this->form_name.'.submit();
  578.         }
  579.         function delete_groups()
  580.         {
  581.             document.'.$this->form_name.'.task.value="delete_groups";
  582.             document.'.$this->form_name.'.submit();
  583.         }
  584.  
  585.         function delete_users()
  586.         {
  587.             document.'.$this->form_name.'.task.value="delete_users";
  588.             document.'.$this->form_name.'.submit();
  589.         }
  590.         </script>
  591.         ';
  592.         global $acl_control_auth_groups, $acl_control_auth_users;
  593.         echo '<form name="'.$this->form_name.'" method="post" action="'.$_SERVER['PHP_SELF'].'">';
  594.         echo '<input type="hidden" name="task" value="" />';
  595.         echo '<input type="hidden" name="acl_id" value="'.$this->acl_id.'" />';
  596.         echo '<input type="hidden" name="read_only" value="'.$this->read_only.'" />';
  597.         echo '<h3>'.$acl_control_auth_groups.'</h3>';
  598.         $this->print_groups_in_acl();
  599.         echo '<br />';
  600.         echo '<h3>'.$acl_control_auth_users.'</h3>';
  601.         $this->print_users_in_acl();
  602.         echo '</form>';
  603.     }
  604.  
  605.     function delete_groups()
  606.     {
  607.         global $GO_SECURITY;
  608.  
  609.         $selected_groups = isset($_POST[$this->selected_groups_name]) ? $_POST[$this->selected_groups_name] : array();
  610.  
  611.         for ($i=0;$i<count($selected_groups);$i++)
  612.         {
  613.             $GO_SECURITY->delete_group_from_acl($selected_groups[$i],$this->acl_id);
  614.         }
  615.     }
  616.  
  617.     function delete_users()
  618.     {
  619.         global $GO_SECURITY;
  620.  
  621.         $selected_users = isset($_POST[$this->selected_users_name]) ? $_POST[$this->selected_users_name] : array();
  622.  
  623.         for ($i=0;$i<count($selected_users);$i++)
  624.         {
  625.             if ($selected_users[$i] != $GO_SECURITY->user_id)
  626.             {
  627.                 $GO_SECURITY->delete_user_from_acl($selected_users[$i],$this->acl_id);
  628.             }
  629.         }
  630.     }
  631.  
  632.     function add_groups()
  633.     {
  634.         global $GO_SECURITY;
  635.  
  636.         $selected_groups = isset($_POST[$this->selected_groups_name]) ? $_POST[$this->selected_groups_name] : array();
  637.  
  638.         for ($i=0;$i<count($selected_groups);$i++)
  639.         {
  640.             if (!$GO_SECURITY->group_in_acl($selected_groups[$i], $this->acl_id))
  641.             {
  642.                 $GO_SECURITY->add_group_to_acl($selected_groups[$i],$this->acl_id);
  643.             }
  644.         }
  645.     }
  646.  
  647.     function add_users()
  648.     {
  649.         global $GO_SECURITY;
  650.  
  651.         $selected_users = isset($_POST[$this->selected_users_name]) ? $_POST[$this->selected_users_name] : array();
  652.  
  653.         for ($i=0;$i<count($selected_users);$i++)
  654.         {
  655.             if (!$GO_SECURITY->user_in_acl($selected_users[$i], $this->acl_id))
  656.             {
  657.                 $GO_SECURITY->add_user_to_acl($selected_users[$i],$this->acl_id);
  658.             }
  659.         }
  660.     }
  661. }
  662. class statusbar
  663. {
  664.     var $usage_color = "#0000CC";
  665.     var $background_color = "#f1f1f1";
  666.     var $border_color = "#000000";
  667.     var $width = "250";
  668.     var $height = "10";
  669.     var $info_text;
  670.     var $turn_red_point = 0;
  671.  
  672.     function print_bar($usage, $limit)
  673.     {
  674.         if ($limit != 0)
  675.         {
  676.                 $percentage = ($usage/$limit)*100;
  677.                 $usage_width = number_format(($usage/$limit)*$this->width);
  678.                 $remaining_width = $this->width - $usage_width;
  679.         }else
  680.         {
  681.                 $usage_width= 0;
  682.                 $remaining_width = $this->width;
  683.         }
  684.         if ($this->turn_red_point > 0 && $percentage >= $this->turn_red_point)
  685.         {
  686.             $this->usage_color = '#FF0000';
  687.         }
  688.  
  689.         echo '<table border="0" cellpadding="1" cellspacing="0">';
  690.         echo '<tr><td bgcolor="'.$this->border_color.'">';
  691.         echo '<table border="0" cellpadding="0" cellspacing="0" width="250">';
  692.         echo '<tr><td height="'.$this->height.'" bgcolor="'.$this->usage_color.'" width="'.$usage_width.'"></td>';
  693.         echo '<td height="'.$this->height.'" bgcolor="'.$this->background_color.'" width="'.$remaining_width.'"></td></tr>';
  694.         echo '</table></td></tr>';
  695.         echo '</table><table border="0" cellpadding="1" cellspacing="0">';
  696.         echo '<tr><td class="small" height="20">'.number_format($percentage).'% '.$this->info_text.'</td></tr>';
  697.         echo '</table>';
  698.     }
  699.  
  700. }
  701.  
  702. class dropbox
  703. {
  704.     var $value=array();
  705.     var $text=array();
  706.     var $optgroup;
  707.  
  708.     function add_value($value, $text)
  709.     {
  710.         if ($text != '')
  711.         {
  712.             $this->value[] = $value;
  713.             $this->text[] = $text;
  714.             return true;
  715.         }else
  716.         {
  717.             return false;
  718.         }
  719.     }
  720.  
  721.     function is_in_dropbox($value)
  722.     {
  723.         return in_array($value, $this->value);
  724.     }
  725.  
  726.     function add_optgroup($name)
  727.     {
  728.         $this->optgroup[count($this->value)] = $name;
  729.     }
  730.  
  731.     function add_sql_data($sql_object, $value, $text)
  732.     {
  733.         global $$sql_object;
  734.  
  735.         while ($$sql_object->next_record())
  736.         {
  737.             $this->value[] = $$sql_object->f($value);
  738.             $this->text[] = $$sql_object->f($text);
  739.         }
  740.     }
  741.  
  742.     function add_arrays($value, $text)
  743.     {
  744.         if (is_array($this->value))
  745.         {
  746.             $this->value = array_merge($this->value, $value);
  747.             $this->text = array_merge($this->text, $text);
  748.         }else
  749.         {
  750.             $this->value = $value;
  751.             $this->text = $text;
  752.         }
  753.         return true;
  754.     }
  755.  
  756.     function count_options()
  757.     {
  758.         return count($this->value);
  759.     }
  760.  
  761.     function print_dropbox($name, $selected_field='', $attributes='', $multiple=false, $size='10')
  762.     {
  763.         $multiple_str = $multiple ? ' multiple="true" size="'.$size.'"' : '';
  764.  
  765.         $optgroup_open = false;
  766.         echo '<select name="'.$name.'" class="textbox"'.$multiple_str.' '.$attributes.'>';
  767.  
  768.         for ($i=0;$i<count($this->value);$i++)
  769.         {
  770.             if(isset($this->optgroup[$i]))
  771.             {
  772.                 if ($optgroup_open == true)
  773.                 {
  774.                     echo '</optgroup>';
  775.                 }else
  776.                 {
  777.                     $optgroup_open = true;
  778.                 }
  779.                 echo '<optgroup label="'.$this->optgroup[$i].'">';
  780.             }
  781.  
  782.             if ($this->text[$i] != '')
  783.             {
  784.                 echo '<option value="'.$this->value[$i].'"';
  785.  
  786.                 if ($multiple)
  787.                 {
  788.                     if (in_array($this->value[$i], $selected_field))
  789.                     {
  790.                         echo ' selected';
  791.                     }
  792.                 }else
  793.                 {
  794.                     if ($this->value[$i] == $selected_field)
  795.                     {
  796.                         echo ' selected';
  797.                     }
  798.                 }
  799.                 echo '>';
  800.                 echo $this->text[$i];
  801.                 echo '</option>';
  802.             }
  803.         }
  804.         if ($optgroup_open == true)
  805.         {
  806.             echo '</optgroup>';
  807.         }
  808.         echo '</select>';
  809.     }
  810. }
  811.  
  812. class htmlarea
  813. {
  814.     var $buttons = array();
  815.     var $fonts = array();
  816.     var $pagestyle = '';
  817.     var $header = '';
  818.     var $name;
  819.     var $rows;
  820.     var $width;
  821.  
  822.     function get_styles($style)
  823.     {
  824.         $styles = array();
  825.         $style_name = '';
  826.         $in_style = false;
  827.  
  828.         $style = str_replace("\r", '', $style);
  829.         $style = str_replace("\n", '', $style);
  830.         $style = str_replace(' ', '', $style);
  831.         for ($i=0; $i<strlen($style); $i++)
  832.         {
  833.             $char = $style[$i];
  834.  
  835.             if ($char == '{' || $char == ',')
  836.             {
  837.                 $in_style = false;
  838.                 if (trim($style_name) != '')
  839.                 {
  840.                     $styles[] = $style_name;
  841.                 }
  842.                 $style_name = '';
  843.             }elseif($char == '.')
  844.             {
  845.                 if ($style_name != '')
  846.                 {
  847.                     $style_name = '';
  848.                     $in_style = false;
  849.                 }else
  850.                 {
  851.                     $in_style = true;
  852.                 }
  853.             }elseif($char == ':')
  854.             {
  855.                 $style_name = '';
  856.                 $in_style = false;
  857.             }elseif($char == '}')
  858.             {
  859.                 $in_style = false;
  860.                 $style_name = '';
  861.             }else
  862.             {
  863.                 if ($in_style)
  864.                 {
  865.                     $style_name .= $char;
  866.                 }
  867.             }
  868.         }
  869.  
  870.         return $styles;
  871.     }
  872.  
  873.  
  874.     function register_dropdown($id, $tooltip, $options, $context, $action, $refresh)
  875.     {
  876.         $button['code'] = '
  877.         config.registerDropdown({
  878.             id: "'.$id.'",
  879.             tooltip: "'.$tooltip.'",
  880.             options: {';
  881.             $option_count = count($options);
  882.             for($i=0;$i<$option_count;$i++)
  883.             {
  884.                 if ($i!=0)
  885.                 {
  886.                     $button['code'] .= ',';
  887.                 }
  888.                 $button['code'] .= '"'.$options[$i]['text'].'":"'.$options[$i]['value'].'"';
  889.             }
  890.  
  891.             $button['code'] .= '},
  892.             context : "'.$context.'",
  893.             action: '.$action.',
  894.             refresh: '.$refresh.'
  895.         });';
  896.         $button['id'] = $id;
  897.         $this->buttons[] = $button;
  898.     }
  899.  
  900.     function add_button($id, $tooltip, $image, $textmode, $action)
  901.     {
  902.         $button['code'] =  '
  903.         config.registerButton("'.$id.'",  "'.$tooltip.'", "'.$image.'", '.$textmode.', '.$action.');
  904.         ';
  905.         $button['id'] = $id;
  906.         $this->buttons[] = $button;
  907.     }
  908.  
  909.     function add_font($name, $family)
  910.     {
  911.         $font['name']  = $name;
  912.         $font['family']  = $family;
  913.         $this->fonts[] = $font;
  914.     }
  915.  
  916.     function get_header($name, $width='600px', $height='400px', $rows='20', $pagestyle='', $config_options='')
  917.     {
  918.         global $GO_CONFIG, $htmlarea_language_name;
  919.         $this->width = 0;
  920.         $this->name = $name;
  921.         $this->rows = $rows;
  922.  
  923.         $this->pagestyle = $pagestyle == '' ? $this->pagestyle : $pagestyle;
  924.  
  925.         $editor_url = $GO_CONFIG->control_url.'htmlarea/';
  926.         $header = '
  927.         <script type="text/javascript">
  928.         _editor_url = "'.$editor_url.'";
  929.         _editor_lang = "'.$htmlarea_language_name.'";
  930.         </script>
  931.         <script type="text/javascript" src="'.$GO_CONFIG->control_url.'htmlarea/htmlarea.js"></script>
  932.         <!-- load the plugins -->
  933.         <script type="text/javascript">
  934.         HTMLArea.loadPlugin("CSS");
  935.  
  936.         var editor = null;
  937.  
  938.         function initEditor()
  939.         {
  940.             editor = new HTMLArea("'.$name.'");
  941.             config = editor.config;
  942.             ';
  943.  
  944.  
  945.             if ($width <= 0)
  946.             {
  947.                 $width=substr($width,1);
  948.                 $header .= '
  949.  
  950.                 config.width = 630;
  951.                 if (parseInt(navigator.appVersion)>3)
  952.                 {
  953.                     if (navigator.appName=="Netscape")
  954.                     {
  955.                         config.width= window.innerWidth-'.$width.';
  956.                     }
  957.                     if (navigator.appName.indexOf("Microsoft")!=-1)
  958.                     {
  959.                         config.width = document.body.offsetWidth-'.$width.'-20;
  960.                     }
  961.                     if (config.width < 200)
  962.                     {
  963.                         config.width = 200;
  964.                     }
  965.                 }
  966.                 ';
  967.             }else
  968.             {
  969.                 $header .= 'config.width = "'.$width.'";';
  970.             }
  971.  
  972.             if ($height <= 0)
  973.             {
  974.                 $height=substr($height,1);
  975.                 $header .= '
  976.                 config.height = 460;
  977.  
  978.                 if (parseInt(navigator.appVersion)>3)
  979.                 {
  980.                     if (navigator.appName=="Netscape")
  981.                     {
  982.                         config.height = window.innerHeight-'.$height.';
  983.                     }
  984.                     if (navigator.appName.indexOf("Microsoft")!=-1)
  985.                     {
  986.                         config.height = document.body.offsetHeight-'.$height.'-20;
  987.                     }
  988.  
  989.                     if (config.height < 200)
  990.                     {
  991.                         config.height = 200;
  992.                     }
  993.                 }
  994.                 ';
  995.             }else
  996.             {
  997.                 $header .= 'config.height = "'.$height.'";';
  998.             }
  999.  
  1000.             $header .= '
  1001.             // enable creation of a status bar?
  1002.             config.statusBar = false;
  1003.  
  1004.             // the next parameter specifies whether the toolbar should be included
  1005.             // in the size or not.
  1006.             config.sizeIncludesToolbar = true;
  1007.  
  1008.             config.pageStyle = "'.addslashes($this->pagestyle).'";';
  1009.  
  1010.             $header .= $config_options;
  1011.  
  1012.             //add buttons
  1013.             $first=true;
  1014.             $push = 'config.toolbar.push([';
  1015.             while ($button = array_shift($this->buttons))
  1016.             {
  1017.                 $header .= $button['code'];
  1018.                 if ($first)
  1019.                 {
  1020.                     $first=false;
  1021.                     $push .= "'".$button['id']."'";
  1022.                 }else
  1023.                 {
  1024.                     $push .= ",'".$button['id']."'";
  1025.                 }
  1026.             }
  1027.             $push .= ']);';
  1028.  
  1029.             $header .= $push;
  1030.  
  1031.             if ($combos = $this->generate_combos())
  1032.             {
  1033.                 $header .= 'editor.registerPlugin(CSS, '.$combos.');';
  1034.             }
  1035.  
  1036.             $header .= '
  1037.             setTimeout(function(){editor.generate();}, 500);
  1038.             window.onresize = resize_editor;
  1039.         }
  1040.  
  1041.         function editor_insertHTML(html) {
  1042.             editor.insertHTML(html);
  1043.         }
  1044.  
  1045.         function editor_insertImage(src)
  1046.         {
  1047.             alert(src);
  1048.             var img = new Image();
  1049.             img.src=src;
  1050.             img.border=0;
  1051.             img.align="absmiddle";
  1052.             img.vspace=0;
  1053.             img.hspace=0;
  1054.             editor._insertImage(img);
  1055.         }
  1056.  
  1057.         function resize_editor()
  1058.         {
  1059.             var newHeight;
  1060.             var newWidth;
  1061.  
  1062.             if (parseInt(navigator.appVersion)>3)
  1063.             {
  1064.                 if (navigator.appName=="Netscape")
  1065.                 {
  1066.                     newHeight = window.innerHeight-'.$height.'-100;
  1067.                     newWidth = window.innerWidth-'.$width.'-10;
  1068.                 }
  1069.                 if (navigator.appName.indexOf("Microsoft")!=-1)
  1070.                 {
  1071.                     newHeight = document.body.offsetHeight - editor._toolbar.offsetHeight - '.$height.'-20;
  1072.                     newWidth = document.body.offsetWidth-'.$width.'-20;
  1073.  
  1074.                 }
  1075.  
  1076.             }
  1077.             if (newHeight < 200) { newHeight = 200; }
  1078.             if (newWidth < 200) { newWidth = 200; }
  1079.  
  1080.  
  1081.             if (editor.config.statusBar) {
  1082.                 newHeight -= editor._statusBar.offsetHeight;
  1083.             }
  1084.  
  1085.             editor._textArea.style.height = editor._iframe.style.height = newHeight + "px";
  1086.             editor._textArea.style.width = editor._iframe.style.width = newWidth + "px";
  1087.  
  1088.         }
  1089.  
  1090.         </script>
  1091.         ';
  1092.  
  1093.         return $header;
  1094.     }
  1095.  
  1096.     function generate_combos()
  1097.     {
  1098.         $styles = $this->get_styles($this->pagestyle);
  1099.  
  1100.         if (count($styles) > 0)
  1101.         {
  1102.             $combos = '
  1103.             {
  1104.                 combos : [
  1105.                   { label: "Syntax:",
  1106.  
  1107.                     options: {"CSS":""';
  1108.  
  1109.             for ($i=0;$i<count($styles);$i++)
  1110.             {
  1111.                 $combos .= ', "'.$styles[$i].'":"'.$styles[$i].'"';
  1112.             }
  1113.  
  1114.             $combos .= '}
  1115.                   }
  1116.                 ]
  1117.             }';
  1118.             return $combos;
  1119.         }else
  1120.         {
  1121.             return false;
  1122.         }
  1123.     }
  1124.  
  1125.     function print_htmlarea($value)
  1126.     {
  1127.         echo '<textarea id="'.$this->name.'" style="width: '.$this->width.'" name="'.$this->name.'", rows="'.$this->rows.'">'.$value.'</textarea>';
  1128.     }
  1129.  
  1130.     function htmlarea()
  1131.     {
  1132.     }
  1133. }
  1134.  
  1135. class tabtable
  1136. {
  1137.     var $tabs = array();
  1138.     var $docs = array();
  1139.     var $id;
  1140.     var $width;
  1141.     var $height;
  1142.     var $tabwidth;
  1143.     //arguments are extra vars that are passed in the links from the tabs
  1144.     var $arguments;
  1145.     var $submit_form;
  1146.     var $active_tab;
  1147.     var $form_name;
  1148.  
  1149.     //css classes
  1150.  
  1151.     var $css_tab = 'Tab';
  1152.     var $css_active_tab = 'Activetab';
  1153.     var $css_table = 'tabtable';
  1154.     var $css_tab_background = 'TabBackground';
  1155.  
  1156.     //constructor sets basic propertiesz
  1157.     function tabtable($id, $title, $width='400', $height='400', $tabwidth='120', $arguments='', $submit_form=false, $align='left', $valign='top', $form_name='forms[0]')
  1158.     {
  1159.         $this->id = $id;
  1160.         $this->title = $title;
  1161.         $this->width = $width;
  1162.         $this->height = $height;
  1163.         $this->tabwidth = $tabwidth;
  1164.         $this->submit_form = $submit_form;
  1165.         $this->arguments = $arguments;
  1166.         $this->align=$align;
  1167.         $this->valign=$valign;
  1168.         $this->form_name=$form_name;
  1169.  
  1170.         $active_tab_ref = $this->id;
  1171.         $this->active_tab = isset($_REQUEST[$active_tab_ref]) ? $_REQUEST[$active_tab_ref] : 0;
  1172.     }
  1173.  
  1174.     function set_classnames($table, $tab, $active_tab, $tab_background)
  1175.     {
  1176.         $this->css_table= $table;
  1177.         $this->css_tab= $tab;
  1178.         $this->css_active_tab = $active_tab;
  1179.         $this->css_tab_background = $tab_background;
  1180.     }
  1181.  
  1182.     //hint: Id could be a document to include
  1183.     function add_tab($id, $name)
  1184.     {
  1185.         $this->tabs[] = $name;
  1186.         $this->docs[] = $id;
  1187.     }
  1188.  
  1189.     //set the active tab manually call this before the print_head() function
  1190.     function set_active_tab($index)
  1191.     {
  1192.         if (isset($this->tabs[$index]))
  1193.         {
  1194.             $this->active_tab = $index;
  1195.             return true;
  1196.         }else
  1197.         {
  1198.             return false;
  1199.         }
  1200.     }
  1201.  
  1202.     /*last three functions should be called in this order
  1203.     $tabtable->print_head();
  1204.     require($tabtable->get_active_tab_id());
  1205.     $tabtable->print_foot();
  1206.     */
  1207.     function print_head()
  1208.     {
  1209.         $active_tab_ref = $this->id;
  1210.         echo '
  1211.         <script type="text/javascript">
  1212.         function change_tab(activetab)
  1213.         {
  1214.             document.'.$this->form_name.'.action.value = document.forms[0].action.value+"'.$this->arguments.'";
  1215.             document.'.$this->form_name.'.'.$active_tab_ref.'.value = activetab;
  1216.             document.'.$this->form_name.'.submit();
  1217.         }
  1218.         </script>
  1219.         ';
  1220.         echo '<input type="hidden" name="'.$active_tab_ref.'" value="'.$this->active_tab.'" />';
  1221.         echo '<table border="0" cellpadding="0" cellspacing="0" id="'.$this->css_table.'" width="'.$this->width.'">';
  1222.         echo '<tr><th colspan="99">'.$this->title.'</th></tr>';
  1223.         $tab_count = count($this->tabs);
  1224.         $remaining_width= $this->width - ($tab_count * $this->tabwidth);
  1225.         if ($tab_count > 0)
  1226.         {
  1227.             echo '<tr><td class="'.$this->css_tab_background.'"><table border="0" cellpadding="0" cellspacing="0"><tr>';
  1228.             //draw tabs and select the active doc
  1229.             for ($i=0;$i<$tab_count;$i++)
  1230.             {
  1231.                 if ($i == $this->active_tab)
  1232.                 {
  1233.                     echo '<td align="center" class="'.$this->css_active_tab.'" width="'.$this->tabwidth.'" nowrap>'.$this->tabs[$i].'</td>';
  1234.                 }else
  1235.                 {
  1236.                     if ($this->submit_form)
  1237.                     {
  1238.                         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>';
  1239.                     }else
  1240.                     {
  1241.                         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>';
  1242.                     }
  1243.                 }
  1244.             }
  1245.             echo '</tr></table></td></tr>';
  1246.         }
  1247.         echo '<tr><td colspan="99" cellpadding="10" cellspacing="0" height="'.$this->height.'" valign="'.$this->valign.'" width="100%" align="'.$this->align.'" style="padding: 10px;">';
  1248.  
  1249.     }
  1250.  
  1251.     function get_active_tab_id()
  1252.     {
  1253.         if (isset($this->docs[$this->active_tab]))
  1254.         {
  1255.             return $this->docs[$this->active_tab];
  1256.         }else
  1257.         {
  1258.             return false;
  1259.         }
  1260.     }
  1261.  
  1262.     function print_foot()
  1263.     {
  1264.         echo '</td></tr></table></td></tr></table>';
  1265.     }
  1266. }
  1267.  
  1268. ?>
  1269.