_tbl = $tblAcl->getName();
$this->_acl = $tblAcl;
$this->_zasobID = $tblAcl->getID();
Lib::loadClass('Data_Tree_Source');
$this->_dataSource = new Data_Tree_Source($tblAcl->getDB());
$this->_dataSource->setTable($tblAcl->getName());
$this->_dataSource->setCols($tblAcl->getRealFieldList());
$this->_dataSource->setVirtualCols($tblAcl->getVirtualFieldList());
// TODO: mv to config or Zasoby (ALIAS?)
switch ($tblAcl->getName()) {
case 'IN7_MK_BAZA_DYSTRYBUCJI':
$this->_dataSource->setParentIdField('P_ID');
$this->_dataSource->setNameField('ID');//M_DIST_DESC
break;
case 'CRM_LISTA_ZASOBOW':
$this->_dataSource->setParentIdField('PARENT_ID');
$this->_dataSource->setNameField('ID');// 'DESC_PL'
$this->_dataSource->setSortField('SORT_PRIO');
break;
case 'CRM_PROCES':
$this->_dataSource->setParentIdField('PARENT_ID');
$this->_dataSource->setNameField('ID');
$this->_dataSource->setSortField('SORT_PRIO');
break;
default:
}
$hash = V::get('_hash', '', $_GET);
$this->_htmlID = ($hash)? $hash : $this->_tbl . '-Tree';//uniqid($this->_tbl);
// TODO: load filters and state: table, edit, add, etc.
// TODO: save this data in Workspace 1, 2, 3, etc.
}
public function renderRootNode() {
?>
0
_acl->getVisibleFieldList();
$fieldList = array();
foreach ($visibleCols as $fieldID => $col) {
if ($col == 'ID') {// || $col == $this->_dataSource->getParentIdField()) {
continue;
}
$fieldList[] = $col;
}
?>
name; ?>
_dataSource->hasSortField()) : ?>
data); ?>
_dataSource->isValidTree()) {
$msg = "Błąd nie można wyświetlić drzewa dla tej tabeli";
$msg = '' . $msg . '
';
$msg = '' . $msg . '
';
return $msg;
}
$visibleCols = $this->_acl->getVisibleFieldList();
$fieldList = array();
foreach ($visibleCols as $fieldID => $col) {
if ($col == 'ID') {// || $col == $this->_dataSource->getParentIdField()) {
continue;
}
$fieldList[] = $col;
}
$nodes = $this->_dataSource->getTreeNodes(0, array('order_by'=>'SORT_PRIO'));
$pInitList = array();
$forceFilterInit = array();
ob_start();
// class="TreeAjax table table-striped table-hover table-bordered table-condensed"
?>
_dataSource->hasSortField()) : ?>
renderRootNode(); ?>
renderNode($node); ?>
_dataSource->getTreeNodes($id, $params);
if (!empty($nodes)) {
ob_start();
?>
renderNode($node); ?>
_dataSource->moveTreeNode($id, $p_id);
if ($moved) {
$node = $this->_dataSource->getTreeNode($id);
$this->renderNode($node);
} else {
header("HTTP/1.0 404 Not Found");
echo "Nie udało się przenieść {$id} pod {$p_id}";
}
exit;
}
private function sendAjaxNode($id, $args) {
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
header("Content-type: text/html");
$node = $this->_dataSource->getTreeNode($id);
if ($node) {
$this->renderNode($node);
} else {
header("HTTP/1.0 404 Not Found");
echo "Rekord {$id} nie istnieje";
}
exit;
}
private function sendAjaxMoveSort($id, $beforeId, $afterId, $args) {
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
header("Content-type: text/html");
$moved = false;
if ($beforeId > 0) {
$moved = $this->_dataSource->moveTreeNodeSortBefore($id, $beforeId);
} else if ($afterId > 0) {
$moved = $this->_dataSource->moveTreeNodeSortAfter($id, $afterId);
}
if ($moved) {
$node = $this->_dataSource->getTreeNode($id);
$this->renderNode($node);
} else {
header("HTTP/1.0 404 Not Found");
echo "Nie udało się przenieść {$id} pod {$p_id}";
}
exit;
}
/**
* ajax url: &_task=EDIT_INLINE
* @param $rowID - $_GET['ID']
* @param $fieldName - $_GET['col']
*/
private function sendAjaxEditInline($rowID, $fieldName, $args) {
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
header("Content-type: text/plain");
die('TODO: L.' . __LINE__);
$fieldID = $this->_acl->getFieldIdByName($fieldName);
if (!$fieldID) {
echo "404: No field by name ({$fieldName})";
exit;
}
if ($DBG) echo "fieldID: {$fieldID}\n";
$row = $this->_dataSource->getItem($rowID);
if (!$row) {
echo "404: No item ID({$rowID})";
exit;
}
if (!$this->_acl->isAllowed($fieldID, 'R', $row)) {
if ($DBG) echo " R not allowed\n";
} else {
if ($DBG) echo " R allowed\n";
}
if (!$this->_acl->isAllowed($fieldID, 'W', $row)) {
if ($DBG) echo " W not allowed\n";
} else {
if ($DBG) echo " W allowed\n";
}
$fieldVal = '';
if ($this->_acl->isAllowed($fieldID, 'R', $row)) {
$fieldVal = V::get($fieldName, $fieldVal, $row);
}
$fieldVal = V::get("f{$fieldID}", $fieldVal, $_POST);
$vCol = $this->_acl->getField($fieldID);
$vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
$tsValues = array();
Lib::loadClass('Typespecial');
$typeSpecial = Typespecial::getInstance($fieldID, $vCol['name']);
if ($typeSpecial) {
if($DBG){echo'Typespecial('.$fieldID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo' ';}
$specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $row->ID, $fieldName, V::get($fieldName, $fieldVal, $row));
if($DBG){echo'Typespecial('.$fieldID.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo' ';}
if (!empty($specialValues)) {
$tsValues[$row->ID] = implode(' ', $specialValues);
}
}
?>
" class="AjaxTableEdit-label">
">
'inside-modal', 'maxGrid'=>6);
if (!empty($tsValues[$row->ID])) {
$fieldParams['typespecialValue'] = $tsValues[$row->ID];
}
$vDefault = $this->_dataSource->getColDefault($fieldName);
if (!empty($vDefault)) {
$fieldParams['default'] = $vDefault;
}
echo $this->_acl->showFormItem('W', $fieldID, "f{$fieldID}", $fieldVal, $fieldParams, $row);
if ($typeSpecial) {
echo '
';
}
exit;
}
private function sendAjaxEditInlineSave($rowID, $fieldName, $args) {
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
sleep(1);// TODO: RMME DBG loading
die('TODO: L.' . __LINE__);
if($DBG){echo'TODO: save ID(' . $id . ') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo' ';}
if($DBG){echo'acl (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_acl);echo' ';}
$dbID = $this->_acl->getDB();
$db = DB::getDB($dbID);
if (!$db) {
header('HTTP/1.0 406 Not Acceptable');
exit;
}
$tblName = $this->_acl->getName();
$fieldID = $this->_acl->getFieldIdByName($fieldName);
if (!$fieldID) {
header('HTTP/1.0 404 Not Found');
echo "404: No field by name ({$fieldName})";
exit;
}
$row = $this->_dataSource->getItem($rowID);
if (!$row) {
header('HTTP/1.0 404 Not Found');
echo "404: No item ID({$rowID})";
exit;
}
if (!$this->_acl->isAllowed($fieldID, 'W', $row)) {
header('HTTP/1.0 403 Forbidden');
echo "403: field not allowed to Write ({$fieldName})";
exit;
} else {
if ($DBG) echo " Write allowed\n";
}
$sqlObj = new stdClass();
if (array_key_exists("f{$fieldID}", $args)) {
$sqlObj->{$fieldName} = $args["f{$fieldID}"];
if (empty($args["f{$fieldID}"]) && strlen($args["f{$fieldID}"]) == 0) {// fix bug in input type date and value="0000-00-00"
$sqlObj->{$fieldName} = $this->_acl->fixEmptyValueFromUser($fieldID);
}
}
else {
if ($DBG) echo " TODO: field value not set\n";
}
$sqlObj->ID = $rowID;
if($DBG){echo'E('.$tblName.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo' ';}
$ret = $db->UPDATE_OBJ($tblName, $sqlObj);
if ($ret > 0) {
echo '';
echo "Rekord zapisany pomyślnie";//"Record saved successfully";
echo '
';
} else if ($ret == 0) {
echo '';
echo "Nie wprowadzono żadnych zmian";
if ($db->has_errors()) {
//echo'
db errors: (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($db->get_errors());echo' ';
}
echo '
';
} else {
echo '';
echo '
' . "Wystąpiły błędy!" . ' ';
if ($db->has_errors()) {
$errors = $db->get_errors();
echo implode(' ', $errors);
}
echo '';
}
exit;
}
private function sendAjaxEdit($id, $args) {
header("Content-type: text/plain");
$DBG = ('1' == V::get('DBG', '', $_REQUEST));
$cols = array();
$record = $this->_dataSource->getItem($id);
if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
echo '';
echo "Brak dostępu do rekordu";// TODO: more info - reason
echo '
';
return;
}
$fieldsList = $this->_acl->getFields();
foreach ($fieldsList as $kID => $vCol) {
if ($vCol['name'] == 'ID') {
unset($fieldsList[$kID]);
continue;
}
$cols[$kID] = '';
if ($this->_acl->isAllowed($kID, 'R', $record)) {
$cols[$kID] = V::get($vCol['name'], '', $record);
}
$cols[$kID] = V::get("f{$kID}", $cols[$kID], $_POST);
$fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : str_replace('_', ' ', $vCol['name']);
}
$tsValues = array();
if($DBG){echo'fieldsList (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fieldsList);echo' ';}
if (!empty($fieldsList)) {
Lib::loadClass('Typespecial');
foreach ($fieldsList as $vColID => $vCol) {
$typeSpecial = Typespecial::getInstance($vColID, $vCol['name']);
if ($typeSpecial) {
if($DBG){echo'Typespecial('.$vColID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($typeSpecial);echo' ';}
$colValue = V::get($vCol['name'], '', $record);
if($DBG){echo'V::get('.$vCol['name'].', "", $record) (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($colValue);echo' ';}
$specialValues = $typeSpecial->getEditSelectedValuesByIds($this->_zasobID, $record->ID, $vCol['name'], $colValue);
if($DBG){echo'Typespecial('.$vColID.') specialValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($specialValues);echo' ';}
if (!empty($specialValues)) {
$tsValues[$vColID] = implode(' ', $specialValues);
}
}
}
}
if($DBG){echo'tsValues (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($tsValues);echo' ';}
$rowFunctionsOut = '';// TODO: $this->_showRowFunctions($record->ID, array('edit', 'cp'), true);
?>
TODO: save ID(' . $id . ') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo'';}
if($DBG){echo'acl (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_acl);echo' ';}
$dbID = $this->_acl->getDB();
$db = DB::getDB($dbID);
if (!$db) {
header('HTTP/1.0 406 Not Acceptable');
exit;
}
$tblName = $this->_acl->getName();
$record = $db->get_by_id($tblName, $id);
if (!$this->_acl->canWriteRecord($record) && !$this->_acl->hasPermSuperWrite()) {
echo '';
echo "Brak dostępu do rekordu";// TODO: more info - reason
echo '
';
}
$sqlObj = new stdClass();
$fields = $this->_acl->getFields();
if($DBG){echo'fields (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fields);echo' ';}
foreach ($fields as $kID => $vField) {
if (!$this->_acl->isAllowed($kID, 'W', $record)) {
continue;
}
if (array_key_exists("f{$kID}", $args)) {
$sqlObj->{$vField['name']} = $args["f{$kID}"];
if (empty($args["f{$kID}"]) && strlen($args["f{$kID}"]) == 0) {// fix bug in input type date and value="0000-00-00"
$sqlObj->{$vField['name']} = $this->_acl->fixEmptyValueFromUser($kID);
}
}
}
$sqlObj->ID = $id;
if($DBG){echo' (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo' ';}
$ret = $db->UPDATE_OBJ($tblName, $sqlObj);
if ($ret > 0) {
echo '';
echo "Rekord zapisany pomyślnie";//"Record saved successfully";
echo '
';
} else if ($ret == 0) {
echo '';
echo "Nie wprowadzono żadnych zmian";
echo '
';
} else {
header('HTTP/1.0 404 Not Found');
echo '';
echo '
' . "Wystąpiły błędy!" . ' ';
if ($db->has_errors()) {
$errors = $db->get_errors();
echo implode(' ', $errors);
}
echo '';
}
exit;
}
public function ajaxTask($task) {
switch ($task) {
case 'CHILDREN': {
$id = V::get('ID', 0, $_REQUEST, 'int');
if ($id > 0) {
$this->sendAjaxChildren($id, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'ROOT_NODES': {
$this->sendAjaxChildren(0, $_REQUEST);
break;
}
case 'ADD': {
echo 'TODO: L.' . __LINE__;
break;
}
case 'MOVE': {
$id = V::get('ID', 0, $_REQUEST, 'int');
$p_id = V::get('MOVE_TO_ID', 0, $_REQUEST, 'int');
if ($id > 0 && $p_id > 0) {
$this->sendAjaxMove($id, $p_id, $_REQUEST);
} else {
header("HTTP/1.0 404 Not Found");
echo 'Błędne parametry';
exit;
}
break;
}
case 'MOVE_SORT': {
$id = V::get('ID', 0, $_REQUEST, 'int');
$beforeId = V::get('before', 0, $_REQUEST, 'int');
$afterId = V::get('after', 0, $_REQUEST, 'int');
if ($id > 0 && ($beforeId > 0 || $afterId > 0)) {
$this->sendAjaxMoveSort($id, $beforeId, $afterId, $_REQUEST);
} else {
header("HTTP/1.0 404 Not Found");
echo 'Błędne parametry';
exit;
}
break;
}
case 'NODE': {
$id = V::get('ID', 0, $_REQUEST, 'int');
if ($id > 0) {
$this->sendAjaxNode($id, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'EDIT': { // &_task=EDIT&ID=510
$id = V::get('ID', 0, $_REQUEST, 'int');
if ($id > 0) {
$this->sendAjaxEdit($id, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'EDIT_SAVE': {
$id = V::get('ID', 0, $_REQUEST, 'int');
if ($id > 0) {
$this->sendAjaxEditSave($id, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'EDIT_INLINE': {
$id = V::get('ID', 0, $_REQUEST, 'int');
$col = V::get('col', '', $_REQUEST);
if ($id > 0 && !empty($col)) {
$this->sendAjaxEditInline($id, $col, $_REQUEST);
} else {
echo '404';
}
break;
}
case 'EDIT_INLINE_SAVE': {
$id = V::get('ID', 0, $_REQUEST, 'int');
$col = V::get('col', '', $_REQUEST);
if ($id > 0 && !empty($col)) {
$this->sendAjaxEditInlineSave($id, $col, $_REQUEST);
} else {
echo '404';
}
break;
}
default:
//$this->sendAjaxData($_REQUEST);
}
}
}