Output/Permissions.php

Go to the documentation of this file.
00001 <?php
00003 // {{{ license
00004 
00005 // +----------------------------------------------------------------------+
00006 // | FastFrame Application Framework                                      |
00007 // +----------------------------------------------------------------------+
00008 // | Copyright (c) 2002-2006 The Codejanitor Group                        |
00009 // +----------------------------------------------------------------------+
00010 // | This source file is subject to the GNU Lesser Public License (LGPL), |
00011 // | that is bundled with this package in the file LICENSE, and is        |
00012 // | available at through the world-wide-web at                           |
00013 // | http://www.fsf.org/copyleft/lesser.html                              |
00014 // | If you did not receive a copy of the LGPL and are unable to          |
00015 // | obtain it through the world-wide-web, you can get it by writing the  |
00016 // | Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
00017 // | MA 02111-1307, USA.                                                  |
00018 // +----------------------------------------------------------------------+
00019 // | Authors: Jason Rust <jrust@codejanitor.com>                          |
00020 // +----------------------------------------------------------------------+
00021 
00022 // }}}
00023 // {{{ requires 
00024 
00025 require_once dirname(__FILE__) . '/../Model/Permissions.php';
00026 
00027 // }}}
00028 // {{{ class FF_Output_Permissions
00029 
00040 // }}}
00041 class FF_Output_Permissions {
00042     // {{{ properties
00043 
00048     var $o_output;
00049 
00054     var $o_registry;
00055 
00060     var $o_perms;
00061 
00062     // }}}
00063     // {{{ constructor
00064 
00071     function FF_Output_Permissions()
00072     {
00073         $this->o_output =& FF_Output::factory();
00074         $this->o_registry =& FF_Registry::singleton();
00075         $this->o_perms =& new FF_Model_Permissions(); 
00076     }
00077 
00078     // }}}
00079     // {{{ getObjectPermsHelp()
00080 
00087     function getObjectPermsHelp()
00088     {
00089         return _('Permissions allow you to restrict access to this object.  If you want all users to have a certain permission check the "All Users" checkbox.  If you want to restrict the object to certain users or groups of users then uncheck "All Users" and assign groups or users to this object.');
00090     }
00091 
00092     // }}}
00093     // {{{ getObjectPermsDisplay()
00094 
00111     function getObjectPermsSelect($in_objectId, $in_module, $in_perms, &$in_form, $in_desc = array())
00112     {
00113         $a_desc = $in_desc;
00114         $a_desc += array(PERMS_READ => _('Read & Display'), PERMS_EDIT => _('Edit'), 
00115                 PERMS_ADD => _('Add'), PERMS_DELETE => _('Delete'));
00116         $s_formName = $in_form->getAttribute('name');
00117         $s_html = '';
00118         $this->o_output->addScriptFile($this->o_registry->getRootFile('multipleSelectTransfer.js', 'javascript', FASTFRAME_WEBPATH));
00119         $this->renderHidePermsJs($s_formName);
00120         $a_availableGroups = $this->o_perms->getAllGroups();
00121         $o_dataAccess =& FF_DataAccess::factory('Profile', 'profile');
00122         $a_availableProfiles = $o_dataAccess->getAllProfiles();
00123         $tmp_js = array();
00124         $tmp_js2 = ''; 
00125         foreach ($in_perms as $s_perm) {
00126             $tmp_divId = 'perms_div_' . $s_perm;
00127             $tmp_checkboxName = 'perms_public_' . $s_perm;
00128             $tmp_js2 .= $tmp_toggle = 'togglePermsDiv("' . $tmp_divId . '", "' . $tmp_checkboxName . '");';
00129             $o_checkbox =& HTML_QuickForm::createElement('checkbox', $tmp_checkboxName, null, null, 
00130                     array('onclick' => $tmp_toggle)); 
00131             $o_checkbox->setChecked($this->o_perms->isObjectPublic($in_objectId, $in_module, $s_perm));
00132             $s_html .= '<div style="font-weight: bold; padding-bottom: 5px; padding-top: 5px;">' . $a_desc[$s_perm] . '</div>
00133                         <div style="margin: 2px 0 2px 0; font-weight: bold;">' . $o_checkbox->toHtml() . ' ' . _('All Users') . '</div>
00134                         <div id="' . $tmp_divId . '">';
00135             if ($s_perm != PERMS_ADD) {
00136                 $tmp_checkboxName = 'perms_creator_' . $s_perm;
00137                 $o_checkbox =& HTML_QuickForm::createElement('checkbox', $tmp_checkboxName);
00138                 $o_checkbox->setChecked($this->o_perms->doesObjectHaveCreatorPerm($in_objectId, $in_module, $s_perm));
00139                 $tmp_desc = isset($a_desc[PERMS_TYPE_CREATOR]) ? $a_desc[PERMS_TYPE_CREATOR] : _('Creator');
00140                 $s_html .= '<div style="font-weight: bold;">' . $o_checkbox->toHtml() . ' ' . $tmp_desc . '</div>';
00141             }
00142 
00143             foreach (array('groups', 'users') as $s_type) {
00144                 $tmp_availName = 'perms_avail_' . $s_perm . '_' . $s_type;
00145                 $tmp_chosenName = 'perms_chosen_' . $s_perm . '_' . $s_type;
00146                 $tmp_js[] = $tmp_chosenName;
00147                 if ($s_type == 'groups') {
00148                     $a_chosen = array_flip($this->o_perms->getObjectUserIds($in_objectId, $in_module, $s_perm, true));
00149                     $a_available = $a_availableGroups;
00150                     $s_availDesc = _('Available Groups');
00151                     $s_chosenDesc = _('Chosen Groups');
00152                 }
00153                 else {
00154                     $a_chosen = array_flip($this->o_perms->getObjectUserIds($in_objectId, $in_module, $s_perm, false));
00155                     $a_available = $a_availableProfiles;
00156                     $s_availDesc = _('Available Users');
00157                     $s_chosenDesc = _('Chosen Users');
00158                 }
00159 
00160                 if (count($a_available) == 0) {
00161                     $a_available['tmp_filler'] = ' ';
00162                 }
00163 
00164                 if (count($a_chosen) == 0) {
00165                     $a_chosen['tmp_filler'] = ' ';
00166                 }
00167                 else {
00168                     // Exclude the chosen ones from the available ones
00169                     foreach (array_keys($a_chosen) as $tmp_id) {
00170                         if (isset($a_available[$tmp_id])) {
00171                             $a_chosen[$tmp_id] = $a_available[$tmp_id];
00172                             unset($a_available[$tmp_id]);
00173                         }
00174                         // The perm is no longer available
00175                         else {
00176                             unset($a_chosen[$tmp_id]);
00177                         }
00178                     }
00179                 }
00180 
00181                 $o_addBut =& HTML_QuickForm::createElement('button', $tmp_availName . 'add', '-->', 
00182                         array('style' => 'font-family: Courier; font-weight: bold;', 
00183                             'onclick' => 'copyToList("' . $tmp_availName . '", "' . $tmp_chosenName . '", "' . $s_formName . '");'));
00184                 $o_removeBut =& HTML_QuickForm::createElement('button', $tmp_chosenName . 'remove', '<--', 
00185                         array('style' => 'font-family: Courier; font-weight: bold;', 
00186                             'onclick' => 'copyToList("' . $tmp_chosenName . '", "' . $tmp_availName . '", "' . $s_formName . '");'));
00187                 $o_availSel =& HTML_QuickForm::createElement('select', $tmp_availName, null, $a_available,
00188                         array('multiple' => true, 'size' => 5, 'style' => 'min-width: 100px;'));
00189                 $o_chosenSel =& HTML_QuickForm::createElement('select', $tmp_chosenName, null, $a_chosen, 
00190                         array('multiple' => true, 'size' => 5, 'style' => 'min-width: 100px;'));
00191                 $s_html .= '<div style="float: left; text-align: center;">' .
00192                     $s_availDesc . '<br />' . $o_availSel->toHtml() .
00193                     '</div>' . 
00194                     '<div style="float: left; padding-top: 15px; margin: 5px; text-align: center;">' .
00195                     $o_addBut->toHtml() . '<br /><br />' .
00196                     $o_removeBut->toHtml() . '</div>' .
00197                     '<div style="float: left; text-align: center;">' .
00198                     $s_chosenDesc . '<br />' . $o_chosenSel->toHtml() .
00199                     '</div><div style="clear: both; height: 5px;"></div>';
00200             }
00201 
00202             $s_html .= '</div>';
00203         }
00204 
00205         $this->o_output->o_tpl->append('javascript', '<script language="JavaScript" type="text/javascript">
00206                 Event.observe(window, "load", function () { addSelectChosen(["' . implode('","', $tmp_js) . '"], "' . $s_formName . '"); ' . $tmp_js2 . '}, false);
00207                 </script>');
00208         return $s_html;
00209     }
00210 
00211     // }}}
00212     // {{{ renderHidePermsJs()
00213     
00223     function renderHidePermsJs($in_formName)
00224     {
00225         ob_start();
00226         ?>
00227         <script language="JavaScript" type="text/javascript">
00228         <!--
00229         // {{{ togglePermsDiv()
00230 
00232         function togglePermsDiv(in_div, in_checkbox)
00233         {
00234             if (document.getElementById) {
00235                 var tmp_style = document.forms['<?php echo $in_formName; ?>'][in_checkbox].checked ? 'none' : 'block';
00236                 document.getElementById(in_div).style.display = tmp_style;
00237             }
00238         } 
00239 
00240         // }}}
00241         //-->
00242         </script>
00243         <?php
00244         $this->o_output->o_tpl->append('javascript', ob_get_contents());
00245         ob_end_clean();
00246     }
00247     
00248     // }}}
00249 }
00250 ?>

Generated on Fri Jun 23 11:38:17 2006 for FastFrame by  doxygen 1.4.4