|
|
@@ -128,13 +128,19 @@ class Ahmes_Reklamacje {
|
|
|
}
|
|
|
|
|
|
private function getKoresp($id_koresp) {
|
|
|
- $koresp = null;
|
|
|
$db = DB::getDB();
|
|
|
if (!$db) return false;
|
|
|
$koresp = $db->get_by_id('IN7_DZIENNIK_KORESP', $id_koresp);
|
|
|
return $koresp;
|
|
|
}
|
|
|
|
|
|
+ private function getProblem($id_problem) {
|
|
|
+ $db = DB::getDB();
|
|
|
+ if (!$db) return false;
|
|
|
+ $problem = $db->get_by_id('PROBLEMS', $id_problem);
|
|
|
+ return $problem;
|
|
|
+ }
|
|
|
+
|
|
|
private function checkKorespUsed($id_koresp) {
|
|
|
$db = DB::getDB();
|
|
|
if (!$db) return false;
|
|
|
@@ -152,6 +158,10 @@ class Ahmes_Reklamacje {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ private function checkProblem($problem) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
private function taskCreateProblem($id_koresp) {
|
|
|
$koresp = $this->getKoresp($id_koresp);
|
|
|
if (!$koresp) {
|
|
|
@@ -200,6 +210,7 @@ class Ahmes_Reklamacje {
|
|
|
}
|
|
|
if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
|
|
|
|
|
|
+ $sqlObj->ID_KORESP_IN = $koresp->ID;
|
|
|
$retID = $db->ADD_NEW_OBJ($tblName, $sqlObj);
|
|
|
|
|
|
if ($retID > 0) {
|
|
|
@@ -334,18 +345,197 @@ jQuery(document).ready(function(){
|
|
|
}
|
|
|
|
|
|
private function taskCreateKorespOut($id_problem) {
|
|
|
+ $problem = $this->getProblem($id_problem);
|
|
|
+ if (!$problem) {
|
|
|
+ $this->renderError("Brak dostępu do problemu lub problem nie istnieje");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$this->checkProblem($problem)) {
|
|
|
+ $this->renderError("Problem nie może zostać użyty");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if ('1' == V::get('frm_sent', '', $_POST)) {
|
|
|
- $this->saveCreateKorespOutForm($id_problem, $_POST);
|
|
|
+ $frmSaved = $this->saveCreateKorespOutForm($problem, $_POST);
|
|
|
+ if ($frmSaved) return;
|
|
|
}
|
|
|
- $this->renderCreateKorespOutForm($id_problem);
|
|
|
+ $this->renderCreateKorespOutForm($problem);
|
|
|
}
|
|
|
|
|
|
- public function renderCreateKorespOutForm($id_problem) {
|
|
|
- echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: render frm('.$id_problem.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_POST);echo'</pre>';
|
|
|
+ public function renderCreateKorespOutForm($problem) {
|
|
|
+ $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'] = $problem->Osoba;
|
|
|
+
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+
|
|
|
+ $problFldsList = $this->_acl->getFields();
|
|
|
+ $problFldsList = array_filter($problFldsList, function($fld) {
|
|
|
+ $problFldsName = array();
|
|
|
+ $problFldsName[] = 'ID';
|
|
|
+ $problFldsName[] = 'Osoba';
|
|
|
+ $problFldsName[] = 'nazwa_jedn';
|
|
|
+ $problFldsName[] = 'miejscowosc';
|
|
|
+ $problFldsName[] = 'data_nad_pism';
|
|
|
+ $problFldsName[] = 'data_wpl_pism';
|
|
|
+ $problFldsName[] = 'data_real';
|
|
|
+ $problFldsName[] = 'A_PROBLEM_DESC_HTML';
|
|
|
+ if (in_array($fld['name'], $problFldsName)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
+ Lib::loadClass('SE_Layout');
|
|
|
+ ?>
|
|
|
+ <div class="container AjaxFrmHorizontalEdit">
|
|
|
+ <form class="form-horizontal" action="" method="post">
|
|
|
+ <input type="hidden" name="frm_sent" value="1">
|
|
|
+ <fieldset>
|
|
|
+ <legend>Dodaj korespondencję na podstawie problemu nr <?php echo $problem->ID; ?></legend>
|
|
|
+
|
|
|
+ <blockquote>
|
|
|
+ <?php foreach ($problFldsList as $fldId => $vFld) : ?>
|
|
|
+ <p><small><b><?php echo $vFld['label']; ?>: </b> <?php echo $problem->{$vFld['name']}; ?></small></p>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </blockquote>
|
|
|
+ <?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
|
|
|
+ <?php if ($this->_korespAcl->isAllowed($kID, 'C')) : ?>
|
|
|
+ <div class="control-group">
|
|
|
+ <label class="control-label" for="<?php echo "f{$kID}"; ?>"><?php echo $vCol['label']; ?>
|
|
|
+ <i class="icon-info-sign frm-help" data-toggle="popover" data-trigger="hover" title="" data-content="<?php echo htmlspecialchars($vCol['opis']); ?>" data-original-title="<?php echo "[{$kID}] {$vCol['name']}"; ?>"></i>
|
|
|
+ <?php $perms = $this->_korespAcl->getFieldPerms($kID); SE_Layout::hotKeyDBG($perms); ?>
|
|
|
+ </label>
|
|
|
+ <div class="controls">
|
|
|
+ <?php
|
|
|
+ $fieldParams = array('appendBack'=>true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8);
|
|
|
+ echo $this->_korespAcl->showFormItem('C', $kID, "f{$kID}", $cols[$kID], $fieldParams);
|
|
|
+ ?>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <?php endif; ?>
|
|
|
+ <?php endforeach; ?>
|
|
|
+
|
|
|
+ <div class="control-group">
|
|
|
+ <div class="controls">
|
|
|
+ <button type="submit" class="btn btn-primary" tabindex="<?php echo (++$tabindex); ?>">Dodaj rekord</button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ </fieldset>
|
|
|
+ </form>
|
|
|
+ </div>
|
|
|
+
|
|
|
+<script>
|
|
|
+jQuery(document).ready(function(){
|
|
|
+ jQuery('textarea').autosize();
|
|
|
+
|
|
|
+ jQuery('.frm-help').popover({trigger:'hover'});
|
|
|
+});
|
|
|
+</script>
|
|
|
+ <?php
|
|
|
}
|
|
|
|
|
|
- public function saveCreateKorespOutForm($id_problem, $args) {
|
|
|
- echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: save('.$id_problem.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo'</pre>';
|
|
|
+ public function saveCreateKorespOutForm($problem, $args) {
|
|
|
+ $DBG = ('1' == V::get('DBG', '', $_REQUEST));
|
|
|
+
|
|
|
+ if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: save('.$problem->ID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo'</pre>';}
|
|
|
+ if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">acl (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_korespAcl);echo'</pre>';}
|
|
|
+ $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'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">fields (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($fields);echo'</pre>';}
|
|
|
+ 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'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
|
|
|
+
|
|
|
+ $retID = $db->ADD_NEW_OBJ($tblName, $sqlObj);
|
|
|
+
|
|
|
+ if ($retID > 0) {
|
|
|
+ ?>
|
|
|
+ <div class="alert alert-success">
|
|
|
+ Utworzono pomyślnie rekord Nr <?php echo $retID; ?>
|
|
|
+ </div>
|
|
|
+ <?php
|
|
|
+
|
|
|
+ $dbProblemId = $this->_acl->getDB();
|
|
|
+ $dbProblem = DB::getDB($dbProblemId);
|
|
|
+ $tblProblemName = $this->_acl->getName();
|
|
|
+ $sqlProblemObj = new stdClass();
|
|
|
+ $sqlProblemObj->ID = $problem->ID;
|
|
|
+ $sqlProblemObj->ID_KORESP_OUT = $retID;
|
|
|
+ // TODO: ? $sqlProblemObj->data real "data realizacji" defautl today - date('Y-m-d')
|
|
|
+ $affectes = $dbProblem->UPDATE_OBJ($tblProblemName, $sqlProblemObj);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ ?>
|
|
|
+ <div class="alert alert-error">
|
|
|
+ Wystąpił błąd podczas tworzenia rekordu
|
|
|
+ <?php
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ echo implode('<br>', $outArr);
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+ </div>
|
|
|
+ <?php
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
public function ___sendAjaxCreateSave($args) {
|