public static function GetMenu($group = '', $level = 1) { $group = strtolower($group); if (!isset(self::$items[$group])) { return ''; } $level = $level - 1; array_sort_subkey(self::$items[$group], 'pos'); $lastWasBlank = true; $items = array(); foreach (self::$items[$group] as $item) { if (empty($item['url']) && $lastWasBlank) { continue; } $attrs = $item['attr']; if (isset($attrs['class'])) { $attrs['class'] .= ' ' . strtolower($item['id']); } else { $attrs['class'] = strtolower($item['id']); } $attrs = BuildAttrString($attrs); $ret = '<li ' . $attrs . '>'; if (!empty($item['url'])) { $ret .= '<a href="' . $item['url'] . '" title="' . $item['text'] . '">' . $item['text'] . '</a>'; } else { $ret .= ' '; } if ($level !== 0) { $ret .= self::GetMenu($item['id'], $level); } $ret .= '</li>'; $items[] = $ret; $lastWasBlank = empty($item['url']); } if (!$items) { return ''; } $ret = '<ul class="u-menu ' . $group . '">' . implode('', $items) . '</ul>'; return $ret; }
static function drti_func($fieldName, $inputType, $defaultValue = '', $possibleValues = NULL, $attributes = NULL, $noSubmit = FALSE) { if (!is_array($attributes)) { $attributes = array(); } if (isset($attributes['class'])) { $attributes['class'] .= ' ckEditReplace'; } else { $attributes['class'] = 'ckEditReplace'; } if (!isset($attributes['data-toolbar'])) { if ($inputType == itRICHTEXT) { $attributes['data-toolbar'] = 'Basic'; } } if (isset($attributes['contenteditable'])) { $attributes['class'] = str_replace(array('inputtype-html', 'inputtype'), '', $attributes['class']); $attr = BuildAttrString($attributes); return '<div' . $attr . '>' . $defaultValue . '</div>'; } return utopia::DrawInput($fieldName, itTEXTAREA, $defaultValue, $possibleValues, $attributes, $noSubmit); }
public function GetCellData($fieldName, $row, $url = '', $inputTypeOverride = NULL, $valuesOverride = NULL) { if (is_array($row) && array_key_exists('__module__', $row) && $row['__module__'] != get_class($this)) { $obj = utopia::GetInstance($row['__module__']); return $obj->GetCellData($fieldName, $row, $url, $inputTypeOverride, $valuesOverride); } $pkVal = NULL; if (is_array($row)) { if ($this->UNION_MODULE) { $pkField = '__module_pk__'; } else { $pkField = $this->GetPrimaryKey(); } $pkVal = $row[$pkField]; } // echo "// start PP for $fieldName ".(is_array($row) && array_key_exists($fieldName,$row) ? $row[$fieldName] : '')."\n"; $value = ''; if (isset($row[$fieldName])) { $value = $row[$fieldName]; } if ($value === '' && isset($this->fields[$fieldName]) && preg_match('/^\'(.+?)\'/', $this->fields[$fieldName]['field'], $match)) { $value = $match[1]; } $value = $this->PreProcess($fieldName, $value, $row); $fieldData = array(); if (isset($this->fields[$fieldName])) { $fieldData = $this->fields[$fieldName]; } if (!$fieldData && strpos($fieldName, ':') !== FALSE) { list($vname) = explode(':', $fieldName); if (isset($this->fields[$vname])) { $fieldData = $this->fields[$vname]; } } $attr = array(); $styles = $this->FieldStyles_Get($fieldName, $row); if ($styles) { $attr['style'] = $styles; } $inputType = !is_null($inputTypeOverride) ? $inputTypeOverride : (isset($fieldData['inputtype']) ? $fieldData['inputtype'] : itNONE); if ($inputType !== itNONE && ($inputTypeOverride || $row !== NULL && $this->flag_is_set(ALLOW_EDIT, $fieldName) || $row === NULL && $this->flag_is_set(ALLOW_ADD, $fieldName))) { if ($inputType === itFILE) { $ret = ''; if (!$value) { $ret .= '<span class="icon-document-delete uDesaturate"></span>'; $ret .= '<span class="icon-document-view uDesaturate"></span>'; $ret .= '<span class="icon-document-download uDesaturate"></span>'; } else { $id = $this->CreateSqlField($fieldName, $pkVal); $ret .= '<a title="Delete File" href="#" name="' . $id . '" class="uf icon-document-delete"></a>'; $link = uBlob::GetLink(get_class($this), $fieldName, $pkVal, $row[$fieldName . '_filename']); $ret .= '<a title="View File" target="_blank" href="' . $link . '" class="icon-document-view"></a>'; $ret .= '<a title="Download File" href="' . $link . '?attach=attachment" class="icon-document-download"></a>'; } $ret .= '<span title="Upload File" class="icon-document-upload">' . $this->DrawSqlInput($fieldName, $value, $pkVal, $attr, $inputType, $valuesOverride) . '</span>'; } else { if ($pkVal === NULL) { // set a placeholder based on the default value for new records $dv = $this->GetDefaultValue($fieldName); $vals = $valuesOverride; if (!$vals) { $vals = $this->GetValues($fieldName, $pkVal); } if ($dv && $vals && isset($vals[$dv])) { $dv = $vals[$dv]; } if (!$value) { $value = $dv; } $attr['placeholder'] = $value; } $ret = $this->DrawSqlInput($fieldName, $value, $pkVal, $attr, $inputType, $valuesOverride); } } else { $vals = $valuesOverride; if (!$vals) { $vals = $this->GetValues($fieldName); } if (isset($vals[$value])) { $value = $vals[$value]; } $ret = ''; if ($url && !$this->GetFieldProperty($fieldName, 'nolink')) { if ($this->GetFieldProperty($fieldName, 'button')) { $attr['class'] = isset($attr['class']) ? $attr['class'] . ' btn' : 'btn'; } $attrStr = BuildAttrString($attr); $ret = "<a{$attrStr} href=\"{$url}\">{$value}</a>"; } else { $attrStr = BuildAttrString($attr); $ret = $value; if ($attrStr) { $ret = "<span{$attrStr}>{$value}</span>"; } } } return $ret; }
function CreateButton($btnText, $attrs = NULL) { if (!is_array($attrs)) { $attrs = array(); } if (array_key_exists('class', $attrs)) { $attrs['class'] .= ' btn'; } else { $attrs['class'] = 'btn'; } $attrStr = BuildAttrString($attrs); return "<a {$attrStr}>{$btnText}</a>"; //return "<input type=\"button\" value=\"$btnText\"$attrStr />"; }
static function DrawInput($fieldName, $inputType, $defaultValue = '', $possibleValues = NULL, $attributes = NULL, $noSubmit = FALSE) { $out = ''; if ($attributes === NULL) { $attributes = array(); } // $defaultValue = str_replace(DEFAULT_CURRENCY_HTML,DEFAULT_CURRENCY,$defaultValue); // $defaultValue = str_replace(DEFAULT_CURRENCY,DEFAULT_CURRENCY_HTML,$defaultValue); // if (!isset($attributes['id'])) $attributes['id'] = $fieldName; // if(!isset($attributes['name']) && !$noSubmit) $attributes['name'] = $fieldName; $attributes['name'] = $fieldName; if (isset($attributes['class'])) { $attributes['class'] .= ' inputtype inputtype-' . $inputType; } else { $attributes['class'] = 'inputtype inputtype-' . $inputType; } $defaultValue = utopia::jsonTryDecode($defaultValue); $attr = BuildAttrString($attributes); if (isset(self::$customInputs[$inputType])) { return call_user_func_array(self::$customInputs[$inputType], array($fieldName, $inputType, $defaultValue, $possibleValues, $attributes, $noSubmit)); } switch ($inputType) { case itNONE: $out .= $defaultValue; break; case itBUTTON: if (isset($attributes['class'])) { $attributes['class'] .= ' btn'; } else { $attributes['class'] = 'btn'; } $attributes['class'] .= ' btn-' . $inputType; $attributes['class'] = str_replace('inputtype ', '', $attributes['class']); $attr = BuildAttrString($attributes); $out .= '<button' . $attr . '>' . $defaultValue . '</button>'; break; case itSUBMIT: if (isset($attributes['class'])) { $attributes['class'] .= ' btn'; } else { $attributes['class'] = 'btn'; } $attributes['class'] .= ' btn-' . $inputType; $attributes['class'] = str_replace('inputtype ', '', $attributes['class']); $attr = BuildAttrString($attributes); $out .= '<input' . $attr . ' type="submit" value="' . $defaultValue . '"/>'; break; case itRESET: if (isset($attributes['class'])) { $attributes['class'] .= ' btn'; } else { $attributes['class'] = 'btn'; } $attributes['class'] .= ' btn-' . $inputType; $attributes['class'] = str_replace('inputtype ', '', $attributes['class']); $attr = BuildAttrString($attributes); $out .= '<input' . $attr . ' type="reset" value="' . $defaultValue . '"/>'; break; case itCHECKBOX: if (is_array($possibleValues)) { $at = array(); if (isset($attributes['styles'])) { $at['styles'] = $attributes['styles']; } $at = BuildAttrString($at); if (!preg_match('/^usql\\-/', $fieldName)) { $attributes['name'] = $attributes['name'] . '[]'; $attr = BuildAttrString($attributes); } $out .= '<span' . $at . ' class="inputtype inputtype-checkboxlist">'; foreach ($possibleValues as $key => $val) { $checked = (string) $key === $defaultValue || is_array($defaultValue) && in_array($key, $defaultValue) ? ' checked="checked"' : ''; $val = htmlentities($val, ENT_COMPAT, CHARSET_ENCODING); $out .= "<label><input{$attr} type=\"checkbox\"{$checked} value=\"{$key}\"/>{$val}</label>"; } $out .= '</span>'; } else { $checked = $defaultValue == 1 ? ' checked="checked"' : ''; $out .= "<input{$attr} type=\"checkbox\"{$checked} value=\"1\"/>"; } break; case itOPTION: if (!is_array($possibleValues)) { ErrorLog('Option field specified but no possible values found'); return ''; } $count = 0; $defaultExists = false; foreach ($possibleValues as $key => $val) { $count++; $attributes['id'] = "{$fieldName}-{$count}"; $attr = BuildAttrString($attributes); $checked = $key == $defaultValue || is_array($defaultValue) && in_array($key, $defaultValue) ? ' checked="checked"' : ''; if ($checked != '') { $defaultExists = true; } $out .= "<input type=\"radio\" {$attr} value=\"{$key}\"{$checked}/>{$val}<br/>"; } if (!$defaultExists && $defaultValue != '') { $out .= "<input type=\"radio\" {$attr} value=\"{$val}\" checked=\"true\">{$defaultValue}"; } break; case itPASSWORD: case itPLAINPASSWORD: $out .= "<input type=\"password\" {$attr} value=\"\"/>"; break; case itTEXT: $defaultValue = str_replace('"', '"', $defaultValue); $out .= "<input type=\"text\" {$attr} value=\"{$defaultValue}\"/>"; break; case itTEXTAREA: //sanitise value. if (!utopia::SanitiseValue($defaultValue, 'string') && !utopia::SanitiseValue($defaultValue, 'NULL')) { $defaultValue = 'Value has been sanitised: ' . var_export($defaultValue, true); } $defaultValue = htmlentities($defaultValue, ENT_COMPAT, CHARSET_ENCODING); $out .= "<textarea {$attr}>{$defaultValue}</textarea>"; break; case itCOMBO: if (empty($possibleValues)) { $possibleValues = array(); } $out .= "<select {$attr}>"; if (!isset($possibleValues[''])) { // blank value does not exist. if (isset($attributes['placeholder']) && $attributes['placeholder'] && !isset($possibleValues[$attributes['placeholder']])) { $blankVal = $attributes['placeholder']; } else { $blankVal = ' '; } $possibleValues = array('' => $blankVal) + $possibleValues; } else { // blank value exists, ensure it is at the top. $v = $possibleValues['']; unset($possibleValues['']); $possibleValues = array('' => $v) + $possibleValues; } $defaultExists = false; if (is_array($possibleValues)) { foreach ($possibleValues as $key => $val) { if ($val === false) { continue; } $selected = ''; if ($defaultValue !== '' && (is_array($defaultValue) && in_array($key, $defaultValue) || (string) $key === (string) $defaultValue)) { $defaultExists = true; $selected = ' selected="selected"'; } $valOutput = $key !== $val ? " value=\"{$key}\"" : ''; $out .= "<option{$valOutput}{$selected}>{$val}</option>"; } } if (!$defaultExists && $defaultValue) { $out .= "<optgroup label=\"No longer available\"><option selected=\"selected\">{$defaultValue}</option></optgroup>"; } $out .= "</select>"; break; case itLISTBOX: if (!is_array($possibleValues)) { ErrorLog('Listbox field specified but no possible values found'); return ''; } $out .= "<select size=5 {$attr}><option value=\"\"></option>"; foreach ($possibleValues as $name => $val) { if (empty($val)) { continue; } $selected = $val == $defaultValue || is_array($defaultValue) && in_array($val, $defaultValue) ? ' selected="selected"' : ''; $out .= "<option value=\"{$val}\"{$selected}>{$name}</option>"; } $out .= "</select>"; break; case itFILE: //$defaultValue = htmlentities($defaultValue,ENT_QUOTES,CHARSET_ENCODING); //$defaultValue = htmlentities($defaultValue); $out .= "<input type=\"file\" {$attr}/>"; break; case itDATE: //$formattedVal = ($defaultValue === SQL_FORMAT_EMPTY_TIMESTAMP) || ($defaultValue === SQL_FORMAT_EMPTY_DATE) || ($defaultValue === NULL) || ($defaultValue === '') ? '' : $defaultValue;//date('d/m/Y',strptime($defaultValue,'d/m/Y')); $formattedVal = $defaultValue; $out .= "<input type=\"text\" {$attr} value=\"{$formattedVal}\"/>"; break; default: $defaultValue = str_replace('"', '"', $defaultValue); $out .= "<input type=\"{$inputType}\" {$attr} value=\"{$defaultValue}\"/>"; break; } return $out; }