/** * check permission validation using current system settings * * @param string $perms the permission boolean expression */ function perm_chck($perms = '') { $CI =& get_instance(); // if the user is admin then the result would be TRUE if ($CI->ion_auth->is_admin()) { return TRUE; } $perm_vars = perm_array(); $perms = str_replace(array_keys($perm_vars['boolVars']), array_values($perm_vars['boolVars']), $perms); $vars_reg = implode('|', array_keys($perm_vars['vars'])); $matches = array(); // regular expression to ckeck is the permission string // is in the wanted form or not .... i know it's a little missy // it will extract the valid regex to matches array preg_match("/(?:(?(3)\\s*\\b(and|or|not)\\b\\s+)(?:(not)\\s+)?({$vars_reg}|0|1)\\s*([<>]=?|!?=)\\s*(\\d+(?:\\.\\d*)?|\\.\\d+|'[^']*'))+/", $perms, $matches); $matches = @$matches[0]; //no matches found (BAD OR EMPTY $perm) if (empty($matches)) { return FALSE; } // replace operators with valid operators like = with == $matches = str_replace(array_keys($perm_vars['opers']), array_values($perm_vars['opers']), $matches); // replace variables with it's values $matches = str_replace(array_keys($perm_vars['vars']), array_values($perm_vars['vars']), $matches); // evaluate the expression to get a boolean value $result = FALSE; eval('$result= (' . $matches . ');'); return $result; }
/** * a permission field auto grow textarea */ function permission($NAME = '', $value = '', $attr = array()) { add_dojo("dijit.form.Textarea"); $ci =& get_instance(); $ci->load->helper('perm'); $p_arr = perm_array(); $t_text = "<b>Boolean variables : </b>" . implode('|', array_keys($p_arr['boolVars'])) . "<br><b>Variables : </b>" . implode('|', array_keys($p_arr['vars'])); $value = form_prep($value); $id_g = 'p' . microtime(); $attr = $this->attribute($attr, 'id', $id_g, FALSE); $id_g = $attr['id']; $text = $this->textarea($NAME, $value, $attr) . $this->tooltip($id_g, $t_text); return $text; }
/** * create a permission textarea using dojo * and add a tooltip with the variables/booleans/operators * that could be used in the expression * * @param string $NAME field name * @param string $value field current value * @param array/object/string $attr attribute to be added to the field * @return string HTML tag of the field */ public function permission($NAME = '', $value = '', $attr = array()) { theme_add('dijit.form.Textarea'); $ci =& get_instance(); $ci->load->helper('perm'); $p_arr = perm_array(); $t_text = '<b>' . lang('system_boolean_vars') . ' : </b>' . implode('|', array_keys($p_arr['boolVars'])) . '<br><b>' . lang('system_vars') . ' : </b>' . implode('|', array_keys($p_arr['vars'])); $value = form_prep($value); $id_g = 'p' . microtime(); $this->attribute($attr, 'id', $id_g, FALSE); $id_g = $attr['id']; $text = $this->textarea($NAME, $value, $attr) . $this->tooltip($id_g, $t_text); return $text; }