|
|
@@ -31,7 +31,7 @@ class TableAcl {
|
|
|
private $_fields = array();
|
|
|
private $_types = array();
|
|
|
private $_virtualFieldsIdList = array();
|
|
|
- private $_sourceLoaded = false;
|
|
|
+ private $_schemaLoaded = false;
|
|
|
|
|
|
public function __construct($zasobID) {
|
|
|
$this->_zasobID = $zasobID;
|
|
|
@@ -350,6 +350,244 @@ class TableAcl {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param $taskPerm - 'C', 'W'
|
|
|
+ */
|
|
|
+ public function getFormItem($taskPerm, $fieldID, $fName, $fValue, $params = array(), $record = null) {
|
|
|
+ $out = '';
|
|
|
+ if (!$this->isAllowed($fieldID, $taskPerm, $record)) {
|
|
|
+ if ($taskPerm == 'R') throw new Exception("Brak uprawnień do odczytu");
|
|
|
+ else if ($taskPerm == 'W') throw new Exception("Brak uprawnień do zapisu");
|
|
|
+ else throw new Exception("Brak uprawnień do tego pola ({$taskPerm})");
|
|
|
+ }
|
|
|
+
|
|
|
+ $colName = $this->_fields[$fieldID]['name'];
|
|
|
+ if ($colName == 'ID') return;
|
|
|
+
|
|
|
+ $colType = $this->getFieldTypeById($fieldID);
|
|
|
+ if (!$colType) throw new Exception("Error - unknown type");
|
|
|
+
|
|
|
+ $item = array();
|
|
|
+ $item['htmlType'] = '';
|
|
|
+ $item['rawColType'] = $colType;
|
|
|
+ return $item;
|
|
|
+
|
|
|
+ $html = new stdClass();
|
|
|
+ $html->_params = array();
|
|
|
+ $html->tag = 'input';
|
|
|
+ $html->cnt = '';
|
|
|
+ $html->attrs = array();
|
|
|
+ $html->attrs['id'] = $fName;
|
|
|
+ $html->attrs['name'] = $fName;
|
|
|
+ $html->attrs['type'] = 'text';
|
|
|
+ $html->attrs['value'] = htmlspecialchars($fValue);
|
|
|
+ if (isset($params['tabindex'])) {
|
|
|
+ $html->attrs['tabindex'] = $params['tabindex'];
|
|
|
+ }
|
|
|
+ if (!$this->hasFieldPerm($fieldID, $taskPerm)) {
|
|
|
+ $html->attrs['disabled'] = 'disabled';
|
|
|
+ }
|
|
|
+ $maxGrid = V::get('maxGrid', 10, $params);
|
|
|
+
|
|
|
+ if (substr($colType['type'], 0, 3) == 'int'
|
|
|
+ || substr($colType['type'], 0, 7) == 'tinyint'
|
|
|
+ || substr($colType['type'], 0, 8) == 'smallint'
|
|
|
+ || substr($colType['type'], 0, 6) == 'bigint'
|
|
|
+ ) {
|
|
|
+ //$h->Type_value = (int)str_replace(array(' ','(',')'), '', substr($h->Type, 4));
|
|
|
+ $html->attrs['type'] = 'number';
|
|
|
+ $html->attrs['class'][] = 'input-small';
|
|
|
+ }
|
|
|
+ else if (substr($colType['type'], 0, 6) == 'double') {
|
|
|
+ $html->attrs['type'] = 'text';
|
|
|
+ $html->attrs['class'][] = 'input-small';
|
|
|
+ }
|
|
|
+ else if (substr($colType['type'], 0, 7) == 'decimal') {
|
|
|
+ $html->attrs['type'] = 'text';
|
|
|
+ $html->attrs['class'][] = 'input-small';
|
|
|
+ }
|
|
|
+ else if (substr($colType['type'], 0, 7) == 'varchar'
|
|
|
+ || substr($colType['type'], 0, 4) == 'char'
|
|
|
+ ) {
|
|
|
+ //$h->Type_value = (int)str_replace(array(' ','(',')'), '', substr($h->Type, 8));
|
|
|
+ $html->attrs['type'] = 'text';
|
|
|
+ $maxLength = (int)str_replace(array(' ','(',')'), '', substr($colType['type'], strpos($colType['type'], '(') + 1, -1));
|
|
|
+ if ($maxLength > 0) {
|
|
|
+ $html->attrs['maxlength'] = $maxLength;
|
|
|
+ }
|
|
|
+ $valLength = strlen($fValue);
|
|
|
+ if (isset($params['widthClass'])) {
|
|
|
+ if ($params['widthClass'] == 'inside-modal') {
|
|
|
+ $html->attrs['style'] = 'width:98%;';
|
|
|
+ } else {
|
|
|
+ $html->attrs['style'] = 'width:98%;';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ /*
|
|
|
+ if ($maxLength < 11) {
|
|
|
+ $html->attrs['class'][] = 'span2';
|
|
|
+ } else if ($maxLength < 31) {
|
|
|
+ $html->attrs['class'][] = 'span5';
|
|
|
+ } else if ($maxLength < 51) {
|
|
|
+ $html->attrs['class'][] = (8 <= $maxGrid)? 'span8' : "span{$maxGrid}";
|
|
|
+ } else if ($maxLength < 101) {
|
|
|
+ $html->attrs['class'][] = (10 <= $maxGrid)? 'span10' : "span{$maxGrid}";
|
|
|
+ } else {
|
|
|
+ $html->attrs['class'][] = (12 <= $maxGrid)? 'span12' : "span{$maxGrid}";
|
|
|
+ }
|
|
|
+ */
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($maxLength > 255) {// Fix for long varchar - use textarea
|
|
|
+ $html->tag = 'textarea';
|
|
|
+ $html->cnt = htmlspecialchars($fValue);
|
|
|
+ $html->attrs['rows'] = '3';
|
|
|
+ unset($html->attrs['type']);
|
|
|
+ unset($html->attrs['value']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (substr($colType['type'], 0, 4) == 'date') {
|
|
|
+ $testDatePicker = true;
|
|
|
+ if ($testDatePicker) {
|
|
|
+ $html->attrs['type'] = 'text';
|
|
|
+ $html->_params[] = 'date';
|
|
|
+ if (substr($colType['type'], 0, 8) == 'datetime') {
|
|
|
+ $html->attrs['class'][] = 'se_type-datetime';// datetimepicker';
|
|
|
+ $html->attrs['data-format'] = 'yyyy-MM-dd hh:mm';
|
|
|
+ $html->attrs['maxlength'] = 19;
|
|
|
+ } else {
|
|
|
+ $html->attrs['class'][] = 'se_type-date';// datetimepicker';
|
|
|
+ $html->attrs['maxlength'] = 10;
|
|
|
+ }
|
|
|
+ if (substr($html->attrs['value'], 0, 10) == '0000-00-00') {
|
|
|
+ $html->attrs['value'] = '';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $html->attrs['type'] = 'date';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ($colType['type'] == 'time') {
|
|
|
+ $testDatePicker = true;
|
|
|
+ if ($testDatePicker) {
|
|
|
+ $html->attrs['type'] = 'text';
|
|
|
+ $html->_params[] = 'time';
|
|
|
+ $html->attrs['class'][] = 'se_type-time';// datetimepicker';
|
|
|
+ $html->attrs['data-format'] = 'hh:mm:ss';
|
|
|
+ $html->attrs['maxlength'] = 8;
|
|
|
+ if (substr($html->attrs['value'], 0, 8) == '00:00:00') {
|
|
|
+ $html->attrs['value'] = '';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $html->attrs['type'] = 'time';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (substr($colType['type'], 0, 4) == 'enum') {
|
|
|
+ unset($html->attrs['type']);
|
|
|
+ unset($html->attrs['value']);
|
|
|
+ $html->tag = 'select';
|
|
|
+
|
|
|
+ $values = explode(',', str_replace(array('(',')',"'",'"'), '', substr($colType['type'], 5)));
|
|
|
+ $selValue = $fValue;
|
|
|
+ if (empty($selValue) && $selValue !== '0' && !empty($colType['default'])) {
|
|
|
+ if ($taskPerm == 'C') {
|
|
|
+ $selValue = $colType['default'];
|
|
|
+ } else if ($taskPerm == 'W' && $this->isAllowed($fieldID, 'R', $record)) {
|
|
|
+ $selValue = $colType['default'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $html->cnt .= '<option value="">' . "" . '</option>';
|
|
|
+ if (!empty($selValue) && !in_array($selValue, $values)) {
|
|
|
+ $html->cnt .= '<option value="' . $selValue . '" selected="selected">' . $selValue . '</option>';
|
|
|
+ }
|
|
|
+ foreach ($values as $val) {
|
|
|
+ $sel = ($selValue == $val)? ' selected="selected"' : '';
|
|
|
+ $html->cnt .= '<option value="' . $val . '"' . $sel . '>' . $val . '</option>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (substr($colType['type'], 0, 4) == 'text'
|
|
|
+ || substr($colType['type'], 0, 8) == 'tinytext'
|
|
|
+ || substr($colType['type'], 0, 10) == 'mediumtext'
|
|
|
+ || substr($colType['type'], 0, 8) == 'longtext'
|
|
|
+ ) {
|
|
|
+ $html->tag = 'textarea';
|
|
|
+ $html->cnt = htmlspecialchars($fValue);
|
|
|
+ if (isset($params['widthClass'])) {
|
|
|
+ if ($params['widthClass'] == 'inside-modal') {
|
|
|
+ $html->attrs['style'] = 'width:98%;';
|
|
|
+ } else {
|
|
|
+ $html->attrs['style'] = 'width:98%;';
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //$html->attrs['class'][] = (8 <= $maxGrid)? 'span8' : "span{$maxGrid}";
|
|
|
+ }
|
|
|
+ $html->attrs['rows'] = '3';
|
|
|
+ unset($html->attrs['type']);
|
|
|
+ unset($html->attrs['value']);
|
|
|
+ }
|
|
|
+ else if ('polygon' == $colType['type']) { return '...'; }// Wielokąt
|
|
|
+ else if ('multipolygon' == $colType['type']) { return '...'; }// Zbiór wielokątów
|
|
|
+ else if ('linestring' == $colType['type']) { return '...'; }// Krzywa z interpolacji liniowej pomiędzy punktami
|
|
|
+ else if ('point' == $colType['type']) { return '...'; }// Punkt w przestrzeni 2-wymiarowej
|
|
|
+ else if ('geometry' == $colType['type']) { return '...'; }// Typy, które mogą przechowywać geometrię dowolnego typu
|
|
|
+ else if ('multipoint' == $colType['type']) { return '...'; }// Zbiór punktów
|
|
|
+ else if ('multilinestring' == $colType['type']) { return '...'; }// Zbiór krzywych z interpolacji liniowej pomiędzy punktami
|
|
|
+ else if ('geometrycollection' == $colType['type']) { return '...'; }// Zbiór obiektów geometrycznych dowolnego typu
|
|
|
+ else throw new Exception("unknown Type '{$colType['type']}'");
|
|
|
+
|
|
|
+ $html->attrs['class'][] = 'form-control';
|
|
|
+
|
|
|
+ $attrsOut = array();
|
|
|
+ foreach ($html->attrs as $k => $v) {
|
|
|
+ if (is_array($v)) $v = implode(' ', $v);
|
|
|
+ $attrsOut[] = "{$k}=\"{$v}\"";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (in_array($html->tag, array('select', 'textarea'))) {
|
|
|
+ $out .= '<' . $html->tag . '' . (($attrsOut)? ' ' . implode(' ', $attrsOut) : '') . '>';
|
|
|
+ $out .= $html->cnt;
|
|
|
+ $out .= '</' . $html->tag . '>';
|
|
|
+ } else {
|
|
|
+ $out .= '<' . $html->tag . '' . (($attrsOut)? ' ' . implode(' ', $attrsOut) : '') . ' />';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (in_array('date', $html->_params)) {
|
|
|
+ $out = '<div class="input-group">' . $out . '<span class="input-group-addon">
|
|
|
+ <span class="glyphicon glyphicon-calendar"></span>
|
|
|
+ </span>
|
|
|
+ </div>';
|
|
|
+ }
|
|
|
+ else if (in_array('time', $html->_params)) {
|
|
|
+ $out = '<div class="input-group">' . $out . '<span class="input-group-addon">
|
|
|
+ <span class="glyphicon glyphicon-time"></span>
|
|
|
+ </span>
|
|
|
+ </div>';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (true == V::get('appendBack', '', $params)
|
|
|
+ && !in_array('date', $html->_params)
|
|
|
+ && !in_array('time', $html->_params)
|
|
|
+ ) {
|
|
|
+ if ($html->tag == 'input' && $taskPerm == 'W') {
|
|
|
+ $out = '<div class="input-group show-last-value">' . $out . '<span class="input-group-addon button-appendBack" title="' . htmlspecialchars($fValue) . '"><span class="glyphicon glyphicon-arrow-left"></span></span></div>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Lib::loadClass('Typespecial');
|
|
|
+ $typeSpecial = Typespecial::getInstance($fieldID, $colName);
|
|
|
+ if ($typeSpecial) {
|
|
|
+ throw new Exception("TODO: TypeSpecial");
|
|
|
+ $tsParams = array();
|
|
|
+ $tsValue = V::get('typespecialValue', '', $params);
|
|
|
+ if (!empty($tsValue)) {
|
|
|
+ $tsParams['typespecialValue'] = $tsValue;
|
|
|
+ }
|
|
|
+ $out .= ' ' . $typeSpecial->showFormItem($this->_zasobID, $fName, $fValue, $tsParams, $record);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $out;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param $taskPerm - 'C', 'W'
|
|
|
*/
|
|
|
@@ -685,40 +923,20 @@ class TableAcl {
|
|
|
return $_cache[$idTable];
|
|
|
}
|
|
|
|
|
|
- public function loadSources() {
|
|
|
- if ($this->_sourceLoaded) return;
|
|
|
+ public function loadSchema() {
|
|
|
+ if ($this->_schemaLoaded) return;
|
|
|
$srvName = $_SERVER['SERVER_NAME'];
|
|
|
- $srvCleanName = str_replace(array(".", "-"), '_', $srvName);
|
|
|
- $tblLowerName = strtolower($this->_name);
|
|
|
- $sourceName = ($this->_db == DB::getPDO()->getZasobId())? 'default_db' : "p5_{$this->_db}";
|
|
|
- DBG::_('DBG_SCH', '>1', "srvCleanName", $srvCleanName, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- DBG::_('DBG_SCH', '>1', "tblLowerName", $tblLowerName, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- DBG::_('DBG_SCH', '>1', "sourceName", $sourceName, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- // TODO: fetch form widgets from file config
|
|
|
- // "schema/gui/core/{$sourceName}.{$tblLowerName}.php";
|
|
|
- // class Schema_Core_{$sourceName}_{$tblLowerName};
|
|
|
- // TODO: override by company file config
|
|
|
- // "schema/gui/{$srvCleanName}/{$sourceName}.{$tblLowerName}.php";
|
|
|
- // class Schema_{$srvCleanName}_{$sourceName}_{$tblLowerName};
|
|
|
- $pathCoreClass = APP_PATH_SCHEMA . "/gui/core/{$sourceName}.{$tblLowerName}.php";
|
|
|
- $coreClassName = "Schema_Core_{$sourceName}_{$tblLowerName}";
|
|
|
- if (file_exists($pathCoreClass)) {
|
|
|
- require_once $pathCoreClass;
|
|
|
- if (!class_exists($coreClassName)) throw new Exception("Config error for schema core class {$sourceName}:{$tblLowerName}");
|
|
|
- $this->_coreSource = new $coreClassName();
|
|
|
- }
|
|
|
- $pathCompanyClass = APP_PATH_SCHEMA . "/gui/company/{$srvCleanName}/{$sourceName}.{$tblLowerName}.php";
|
|
|
- $companyClassName = "Schema_{$srvCleanName}_{$sourceName}_{$tblLowerName}";
|
|
|
- if (file_exists($pathCompanyClass)) {
|
|
|
- require_once $pathCompanyClass;
|
|
|
- if (!class_exists($companyClassName)) throw new Exception("Config error for schema company class {$sourceName}:{$tblLowerName}");
|
|
|
- $this->_companySource = new $companyClassName();
|
|
|
- }
|
|
|
- $this->_sourceLoaded = true;
|
|
|
+ try {
|
|
|
+ $this->_schemaClass = Schema_TableFactory::build($this->_name, $this->_db, $srvName);
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DBG::_('DBG_SCH', '>1', "Exception in Schema_TableFactory::build", $e->getMessage(), __CLASS__, __FUNCTION__, __LINE__);
|
|
|
+ // TODO: hide only not found, else re-throw
|
|
|
+ }
|
|
|
+ $this->_schemaLoaded = true;
|
|
|
}
|
|
|
|
|
|
public function init($force = false) {
|
|
|
- $this->loadSources();
|
|
|
+ $this->loadSchema();
|
|
|
if (empty($this->_fields)) {
|
|
|
$this->_types = array();// clear _types @see $this->isInitialized
|
|
|
$userAcl = User::getAcl();
|
|
|
@@ -747,8 +965,7 @@ class TableAcl {
|
|
|
$this->_sortEnumFields();
|
|
|
$this->_fixProjectType();
|
|
|
|
|
|
- if ($this->_coreSource) $this->_types = $this->_coreSource->fixTypes($this->_types);
|
|
|
- if ($this->_companySource) $this->_types = $this->_companySource->fixTypes($this->_types);
|
|
|
+ if ($this->_schemaClass) $this->_types = $this->_schemaClass->fixTypes($this->_types);
|
|
|
//DBG::_(true, true, "this->_types", $this->_types, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
|
|
|
$fieldIds = array_keys($this->_fields);
|