Overview

Packages

  • Horde
    • Block
  • None
  • Ulaform

Classes

  • Ulaform
  • Ulaform_Action
  • Ulaform_Action_Mailto
  • Ulaform_Action_Sql
  • Ulaform_Api
  • Ulaform_Driver
  • Ulaform_Driver_Sql
  • Ulaform_Exception
  • Ulaform_Factory_Action
  • Ulaform_Factory_Driver
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Ulaform:: class providing some support functions to the Ulaform module.
  4:  *
  5:  * Copyright 2001-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
  9:  *
 10:  * @author  Marko Djukic <marko@oblo.com>
 11:  * @author  Brent J. Nordquist <bjn@horde.org>
 12:  * @since   Ulaform 0.1
 13:  * @package Ulaform
 14:  */
 15: class Ulaform {
 16: 
 17:     static public function getActionInfo($action)
 18:     {
 19:         static $info = array();
 20:         if (isset($info[$action])) {
 21:             return $info[$action];
 22:         }
 23: 
 24:         $class = 'Ulaform_Action_' . $action;
 25:         $info[$action] = call_user_func(array($class, 'getInfo'));
 26: 
 27:         return $info[$action];
 28:     }
 29: 
 30:     static public function getActionParams($action)
 31:     {
 32:         static $params = array();
 33:         if (isset($params[$action])) {
 34:             return $params[$action];
 35:         }
 36: 
 37:         $class = 'Ulaform_Action_' . $action;
 38:         $params[$action] = call_user_func(array($class, 'getParams'));
 39: 
 40:         return $params[$action];
 41:     }
 42: 
 43:     /**
 44:      * Fetch the available field types from the Horde_Form classes.
 45:      *
 46:      * @return array  The available field types.
 47:      */
 48:     static public function getFieldTypes()
 49:     {
 50:         static $available_fields = array();
 51:         if (!empty($available_fields)) {
 52:             return $available_fields;
 53:         }
 54: 
 55:         /* Fetch the field type information from the Horde_Form classes. */
 56:         $fields = self::getFieldTypesArray();
 57: 
 58:         /* Strip out the name element from the array. */
 59:         foreach ($fields as $field_type => $info) {
 60:             $available_fields[$field_type] = $info['name'];
 61:         }
 62: 
 63:         /* Sort for display purposes. */
 64:         asort($available_fields);
 65: 
 66:         return $available_fields;
 67:     }
 68: 
 69:     /**
 70:      * Fetch the full array for the field types, with params.
 71:      *
 72:      * @return array  The full field types array.
 73:      */
 74:     static public function getFieldTypesArray()
 75:     {
 76:         static $fields_array = array();
 77:         if (!empty($fields_array)) {
 78:             return $fields_array;
 79:         }
 80: 
 81:         /* Fetch all declared classes. */
 82:         $classes = get_declared_classes();
 83: 
 84:         /* Filter for the Horde_Form_Type classes. */
 85:         foreach ($classes as $class) {
 86:             if (strtolower(substr($class, 0, 16)) == 'horde_form_type_') {
 87:                 $field_type = substr($class, 16);
 88:                 /* Don't bother including the types that cannot be handled
 89:                    usefully by ulaform. */
 90:                 if ($field_type == 'invalid') {
 91:                     continue;
 92:                 }
 93:                 $fields_array[$field_type] = @call_user_func(array('Horde_Form_Type_' . $field_type, 'about'));
 94:             }
 95:         }
 96: 
 97:         return $fields_array;
 98:     }
 99: 
100:     static public function getFieldParams($field_type)
101:     {
102:         $fields = self::getFieldTypesArray();
103: 
104:         /* Return null if there are no params for this field type. */
105:         if (!isset($fields[$field_type]['params'])) {
106:             return array();
107:         }
108: 
109:         return $fields[$field_type]['params'];
110:     }
111: 
112:     static public function getStringlistArray($string)
113:     {
114:         $string = str_replace("'", "\'", $string);
115:         $values = explode(',', $string);
116: 
117:         foreach ($values as $value) {
118:             $value = trim($value);
119:             $value_array[$value] = $value;
120:         }
121: 
122:         return $value_array;
123:     }
124: 
125:     /**
126:      * This function does the permission checking when using Ulaform.
127:      *
128:      * @param mixed  $in          A form_id or an array of form_id's to check
129:      *                            permission on.
130:      * @param string $filter      What type of check to do.
131:      * @param string $permission  What type of permission to check for.
132:      * @param string $key         The array key to use for checking.
133:      *
134:      * @return mixed  Depending on the type of check, either return a boolean
135:      *                to indicate permission for that form, or a filtered out
136:      *                array of form_id's.
137:      */
138:     static public function checkPermissions($in, $filter, $permission = Horde_Perms::READ, $key = null)
139:     {
140:         static $permsCache;
141: 
142:         $admin = $GLOBALS['registry']->isAdmin();
143:         /* Horde admin is always authorised. */
144:         if ($admin) {
145:             return $in;
146:         }
147: 
148:         $out = array();
149:         $userID = $GLOBALS['registry']->getAuth();
150:         switch ($filter) {
151:         /* Check permissions for a single form or for an array of forms. */
152:         case 'form':
153:             if (is_array($in)) {
154:                 $id = serialize($in);
155:             } else {
156:                 $id = $in;
157:                 $in = array($in);
158:             }
159: 
160:             if (isset($permsCache[$id][$permission])) {
161:                 return $permsCache[$id][$permission];
162:             }
163: 
164:             foreach ($in as $form_id => $form) {
165:                 if (!is_null($key)) {
166:                     $form_id = $form[$key];
167:                 }
168:                 if ($GLOBALS['perms']->hasPermission('ulaform:forms:' . $form_id, $userID, $permission)) {
169:                     /* Cache and set into the $out array. */
170:                     $permsCache[$form_id][$permission] = true;
171:                     $out[$form_id] = $form;
172:                 }
173:             }
174:             $permsCache[$id][$permission] = $out;
175:             break;
176: 
177:         default:
178:             /* For now default everything to false */
179:             $out = false;
180:         }
181: 
182:         return $out;
183:     }
184: 
185: }
186: 
API documentation generated by ApiGen