Wyślij koresp. * [6960] (ALIAS DO [6929]) DANE ID_MNP * [6961] (ALIAS DO [6962]) PARAM_IN ADD_KORESP_OUT_LINK in MNP * */ function AHMES_MNP() { Lib::loadClass('ProcesHelper'); $tblMnpId = ProcesHelper::getZasobTableID('MNP'); $tblKorespId = ProcesHelper::getZasobTableID('IN7_DZIENNIK_KORESP'); Lib::loadClass('ProcesHelper'); $zasobObj = ProcesHelper::getZasobTableInfo($tblMnpId); if (!$zasobObj) { echo '
' . "Zasob TABELA ID={$tblMnpId} nie istnieje" . '
'; //echo UserActivity::showSimpleList(); return; } $korespObj = ProcesHelper::getZasobTableInfo($tblKorespId); if (!$korespObj) { echo '
' . "Zasob TABELA ID={$tblKorespId} nie istnieje" . '
'; //echo UserActivity::showSimpleList(); return; } //UserActivity::add($tblMnpId); $userAcl = User::getAcl(); $userAcl->fetchGroups(); if (!$userAcl->hasTableAcl($zasobObj->ID)) { echo '
' . "Brak uprawnień do tabeli ID={$zasobObj->ID}" . '
'; //echo UserActivity::showSimpleList(); return; } if (!$userAcl->hasTableAcl($korespObj->ID)) { echo '
' . "Brak uprawnień do tabeli Korespondencja (ID={$korespObj->ID})" . '
'; //echo UserActivity::showSimpleList(); return; } $tblAcl = $userAcl->getTableAcl($zasobObj->ID); $korespAcl = $userAcl->getTableAcl($korespObj->ID); $forceTblAclInit = ('1' == V::get('_force', '', $_GET)); $tblAcl->init($forceTblAclInit); $korespAcl->init($forceTblAclInit); $module = new Ahmes_Mnp($tblAcl, $korespAcl, $_GET); $module->run(); } class Ahmes_Mnp { private $_args = null; private $_tbl = null; private $_acl = null; private $_zasobID = null; private $_dataSource = null; private $_htmlID = ''; public function __construct($tblAcl, $korespAcl, $args) { $this->_args = $args; $this->_tbl = $tblAcl->getName(); $this->_acl = $tblAcl; $this->_korespAcl = $korespAcl; $this->_zasobID = $tblAcl->getID(); Lib::loadClass('Data_Source'); $this->_dataSource = $tblAcl->getDataSource(); $this->_htmlID = 'Ahmes_Mnp'; } public function run() { Lib::loadClass('SE_Layout'); SE_Layout::menu(); $task = V::get('task', '', $this->_args); switch ($task) { case 'create_koresp_out': $id_mnp = V::get('id_mnp', '', $this->_args); if (!$id_mnp) { echo '
' . "Brak numeru z dziennika pism!" . '
'; } else { $this->taskCreateKorespOut($id_mnp); } break; default: echo '
' . "Brak zadania do wykonania!" . '
'; } } private function renderError($msg) { echo '
' . $msg . '
'; } private function getMnp($id_mnp) { $db = DB::getDB(); if (!$db) return false; $mnp = $db->get_by_id('MNP', $id_mnp); return $mnp; } private function checkMnp($mnp) { return true; } private function taskCreateKorespOut($id_mnp) { $mnp = $this->getMnp($id_mnp); if (!$mnp) { $this->renderError("Brak dostępu do mnp lub rekord nie istnieje"); return; } if (!$this->checkMnp($mnp)) { $this->renderError("Mnp nie może zostać użyty"); return; } if ('1' == V::get('frm_sent', '', $_POST)) { $frmSaved = $this->saveCreateKorespOutForm($mnp, $_POST); if ($frmSaved) return; } $this->renderCreateKorespOutForm($mnp); } public function renderCreateKorespOutForm($mnp) { $DBG = ('1' == V::get('DBG', '', $_REQUEST)); $forceFilterInit = array(); foreach ($this->_args as $k => $v) { if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix $fldName = substr($k, 3); $forceFilterInit[$fldName] = $v; } } $forceFilterInit['K_TYP_KORESP'] = 'OUT'; $forceFilterInit['K_DATA_OTRZYMANEJ_KORESP'] = date('Y-m-d'); $forceFilterInit['K_OD_KOGO'] = $mnp->Klient_name; $forceFilterInit['OD_KOGO_ADRES'] = $mnp->Klient_address; $fieldsList = $this->_korespAcl->getFields(); $fieldsList = array_filter($fieldsList, function($vCol) { return ($vCol['name'] != 'ID'); }); $fieldsList = array_map(function($vCol) { $vCol['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name']; return $vCol; }, $fieldsList); $cols = array(); foreach ($fieldsList as $kID => $vCol) { $defaultValue = ''; if (!empty($forceFilterInit[$vCol['name']])) { $defaultValue = $forceFilterInit[$vCol['name']]; } // TODO: read from session cache $cols[$kID] = V::get("f{$kID}", $defaultValue, $_POST); } $mnpFldsList = $this->_acl->getFields(); $mnpFldsList = array_filter($mnpFldsList, function($fld) { $mnpFldsName = array(); $mnpFldsName[] = 'ID'; $mnpFldsName[] = 'DataZgloszenia'; $mnpFldsName[] = 'dla_kogo'; $mnpFldsName[] = 'Klient_name'; $mnpFldsName[] = 'Klient_address'; $mnpFldsName[] = 'Klient_mail'; $mnpFldsName[] = 'Klient_tel'; $mnpFldsName[] = 'data_real'; $mnpFldsName[] = 'uwagi'; if (in_array($fld['name'], $mnpFldsName)) { return true; } return false; }); Lib::loadClass('SE_Layout'); ?>
Dodaj korespondencję na podstawie MNP nr ID; ?>
$vFld) : ?>

: {$vFld['name']}; ?>

$vCol) : ?> _korespAcl->isAllowed($kID, 'C')) : ?>
true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8); echo $this->_korespAcl->showFormItem('C', $kID, "f{$kID}", $cols[$kID], $fieldParams); ?>
TODO: save('.$mnp->ID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo'';} if($DBG){echo'
acl (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_korespAcl);echo'
';} $dbID = $this->_korespAcl->getDB(); $db = DB::getDB($dbID); if (!$db) return false; $tblName = $this->_korespAcl->getName(); $sqlObj = new stdClass(); $fields = $this->_korespAcl->getFields(); if($DBG){echo'
fields (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fields);echo'
';} foreach ($fields as $kID => $vField) { if (!$this->_korespAcl->isAllowed($kID, 'C')) { 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->_korespAcl->fixEmptyValueFromUser($kID); } } } if($DBG){echo'
 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'
';} $retID = $db->ADD_NEW_OBJ($tblName, $sqlObj); if ($retID > 0) { ?>
Utworzono pomyślnie rekord Nr
Wystąpił błąd podczas tworzenia rekordu has_errors()) { $outArr = array(); $errorsSql = $db->get_errors(); foreach ($errorsSql as $vErr) { if (substr($vErr, 0, 18) == 'SQL QUERY FAILED: ') { $vErr = substr($vErr, 18); // Duplicate entry '123456-1' for key 'P_NIP' if (substr($vErr, 0, 16) == 'Duplicate entry ') { } } $outArr[] = $vErr; } echo implode('
', $outArr); } ?>
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'); echo '{"type":"ERROR", "msg": "' . "Błąd połączenia z bazą danych!" . '"}'; exit; } $tblName = $this->_acl->getName(); $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, 'C')) { 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); } } } if($DBG){echo'
 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'
';} $retID = $db->ADD_NEW_OBJ($tblName, $sqlObj); $retJson = new stdClass(); $retJson->type = ''; $retJson->msg = ''; if ($retID > 0) { $retJson->type = 'SUCCESS'; $retJson->msg = "Utworzono pomyślnie rekord: ID = {$retID}"; $retJson->id = $retID; } else { header('HTTP/1.0 404 Not Found'); $retJson->type = 'ERROR'; $retJson->msg = ""; if ($db->has_errors()) { $outArr = array(); $errorsSql = $db->get_errors(); foreach ($errorsSql as $vErr) { if (substr($vErr, 0, 18) == 'SQL QUERY FAILED: ') { $vErr = substr($vErr, 18); // Duplicate entry '123456-1' for key 'P_NIP' if (substr($vErr, 0, 16) == 'Duplicate entry ') { } } $outArr[] = $vErr; } $retJson->msg .= implode('
', $outArr); } } echo json_encode($retJson); exit; } }