|
|
@@ -0,0 +1,338 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+/**
|
|
|
+ * @param $_GET['task']
|
|
|
+ * @param $_GET['id_koresp']
|
|
|
+ * @param $_GET['id_problem']
|
|
|
+ *
|
|
|
+ * if $_GET['task'] == 'create_problem'
|
|
|
+ * @require $_GET['id_koresp']
|
|
|
+ *
|
|
|
+ * if $_GET['task'] == 'create_koresp_out'
|
|
|
+ * @require $_GET['id_problem']
|
|
|
+ *
|
|
|
+ */
|
|
|
+function AHMES_REKLAMACJE() {
|
|
|
+ Lib::loadClass('ProcesHelper');
|
|
|
+ $tblProblemsId = ProcesHelper::getZasobTableID('PROBLEMS');
|
|
|
+ $tblKorespId = ProcesHelper::getZasobTableID('IN7_DZIENNIK_KORESP');
|
|
|
+
|
|
|
+ Lib::loadClass('ProcesHelper');
|
|
|
+
|
|
|
+ $zasobObj = ProcesHelper::getZasobTableInfo($tblProblemsId);
|
|
|
+ if (!$zasobObj) {
|
|
|
+ echo '<div class="alert alert-error">' . "Zasob TABELA ID={$tblProblemsId} nie istnieje" . '</div>';
|
|
|
+ //echo UserActivity::showSimpleList();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $korespObj = ProcesHelper::getZasobTableInfo($tblKorespId);
|
|
|
+ if (!$korespObj) {
|
|
|
+ echo '<div class="alert alert-error">' . "Zasob TABELA ID={$tblKorespId} nie istnieje" . '</div>';
|
|
|
+ //echo UserActivity::showSimpleList();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //UserActivity::add($tblProblemsId);
|
|
|
+
|
|
|
+ $userAcl = User::getAcl();
|
|
|
+ $userAcl->fetchGroups();
|
|
|
+
|
|
|
+ if (!$userAcl->hasTableAcl($zasobObj->ID)) {
|
|
|
+ echo '<div class="alert alert-error">' . "Brak uprawnień do tabeli ID={$zasobObj->ID}" . '</div>';
|
|
|
+ //echo UserActivity::showSimpleList();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$userAcl->hasTableAcl($korespObj->ID)) {
|
|
|
+ echo '<div class="alert alert-error">' . "Brak uprawnień do tabeli Korespondencja (ID={$korespObj->ID})" . '</div>';
|
|
|
+ //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);
|
|
|
+
|
|
|
+ $tbl = new Ahmes_Reklamacje($tblAcl, $korespAcl, $_GET);
|
|
|
+ echo $tbl->render();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+class Ahmes_Reklamacje {
|
|
|
+
|
|
|
+ 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->_zasobID = $tblAcl->getID();
|
|
|
+ Lib::loadClass('Data_Source');
|
|
|
+ $this->_dataSource = new Data_Source($tblAcl->getDB());
|
|
|
+ $this->_dataSource->setTable($tblAcl->getName());
|
|
|
+ $realFieldList = $tblAcl->getRealFieldList();
|
|
|
+ $this->_dataSource->setCols($realFieldList);
|
|
|
+ $this->_dataSource->setColTypes($tblAcl->getTypes());
|
|
|
+ $this->_dataSource->setVirtualCols($tblAcl->getVirtualFieldList());
|
|
|
+ $this->_dataSource->setFieldGroupWrite('A_ADM_COMPANY', $tblAcl->hasFieldType('A_ADM_COMPANY'));
|
|
|
+ $this->_dataSource->setFieldGroupRead('A_CLASSIFIED', $tblAcl->hasFieldType('A_CLASSIFIED'));
|
|
|
+ $this->_dataSource->setAccessFltrAllowed(!$tblAcl->hasSuperAccessPerms());
|
|
|
+ $this->_htmlID = 'Ahmes_Reklamacje';
|
|
|
+
|
|
|
+ $adminFields = array('A_RECORD_CREATE_DATE', 'A_RECORD_CREATE_AUTHOR', 'A_RECORD_UPDATE_DATE', 'A_RECORD_UPDATE_AUTHOR');
|
|
|
+ foreach ($adminFields as $vAdmFld) {
|
|
|
+ if (!in_array($vAdmFld, $realFieldList) && $tblAcl->hasFieldType($vAdmFld)) {
|
|
|
+ $this->_dataSource->addCol($vAdmFld);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function render() {
|
|
|
+ Lib::loadClass('SE_Layout');
|
|
|
+ SE_Layout::menu();
|
|
|
+ $task = V::get('task', '', $this->_args);
|
|
|
+ switch ($task) {
|
|
|
+ case 'create_problem':
|
|
|
+ $id_koresp = V::get('id_koresp', '', $this->_args);
|
|
|
+ if (!$id_koresp) {
|
|
|
+ echo '<div class="alert alert-error">' . "Brak numeru z dziennika pism!" . '</div>';
|
|
|
+ } else {
|
|
|
+ $this->taskCreateProblem($id_koresp);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'create_koresp_out':
|
|
|
+ $id_problem = V::get('id_problem', '', $this->_args);
|
|
|
+ if (!$id_problem) {
|
|
|
+ echo '<div class="alert alert-error">' . "Brak numeru z dziennika pism!" . '</div>';
|
|
|
+ } else {
|
|
|
+ $this->taskCreateKorespOut($id_problem);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ echo '<div class="alert alert-error">' . "Brak zadania do wykonania!" . '</div>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function renderError($msg) {
|
|
|
+ echo '<div class="alert alert-error">' . $msg . '</div>';
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 checkKorespUsed($id_koresp) {
|
|
|
+ $db = DB::getDB();
|
|
|
+ if (!$db) return false;
|
|
|
+
|
|
|
+ $sql = "select count(1) as cnt
|
|
|
+ from `{$this->_tbl}` as p
|
|
|
+ where p.`ID_KORESP_IN`='{$id_koresp}'
|
|
|
+ ";
|
|
|
+ $res = $db->query($sql);
|
|
|
+ if ($r = $db->fetch($res)) {
|
|
|
+ if ($r->cnt > 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function taskCreateProblem($id_koresp) {
|
|
|
+ $koresp = $this->getKoresp($id_koresp);
|
|
|
+ if (!$koresp) {
|
|
|
+ $this->renderError("Brak dostępu do korespondecji lub korespondencja nie istnieje");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->checkKorespUsed($id_koresp)) {
|
|
|
+ $this->renderError("Korespondecja została już przypisana do problemu");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ('1' == V::get('frm_sent', '', $_POST)) {
|
|
|
+ $this->saveCreateProblemForm($id_koresp, $_POST);
|
|
|
+ }
|
|
|
+ $this->renderCreateProblemForm($id_koresp);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function saveCreateProblemForm($id_koresp, $args) {
|
|
|
+ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: save('.$id_koresp.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo'</pre>';
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * @from TableAjax::sendAjaxCreate($args)
|
|
|
+ */
|
|
|
+ public function renderCreateProblemForm($id_koresp) {
|
|
|
+ $DBG = ('1' == V::get('DBG', '', $_REQUEST));
|
|
|
+
|
|
|
+ $cols = array();
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $fieldsList = $this->_acl->getFields();
|
|
|
+ foreach ($fieldsList as $kID => $vCol) {
|
|
|
+ $defaultValue = '';
|
|
|
+ if ($vCol['name'] == 'ID') {
|
|
|
+ unset($fieldsList[$kID]);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($forceFilterInit[$vCol['name']])) {
|
|
|
+ $defaultValue = $forceFilterInit[$vCol['name']];
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: read from session cache
|
|
|
+ $cols[$kID] = V::get("f{$kID}", $defaultValue, $_POST);
|
|
|
+
|
|
|
+ $fieldsList[$kID]['label'] = (!empty($vCol['label']))? $vCol['label'] : $vCol['name'];
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 nowy Problem/Reklamację na podstawie pisma nr <?php echo $id_koresp; ?></legend>
|
|
|
+
|
|
|
+ <?php $tabindex = 0; foreach ($fieldsList as $kID => $vCol) : ?>
|
|
|
+ <?php if ($this->_acl->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->_acl->getFieldPerms($kID); SE_Layout::hotKeyDBG($perms); ?>
|
|
|
+ </label>
|
|
|
+ <div class="controls">
|
|
|
+ <?php
|
|
|
+ $fieldParams = array('appendBack'=>true, 'tabindex'=>(++$tabindex), 'maxGrid'=>8);
|
|
|
+ echo $this->_acl->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
|
|
|
+ }
|
|
|
+
|
|
|
+ private function taskCreateKorespOut($id_problem) {
|
|
|
+ if ('1' == V::get('frm_sent', '', $_POST)) {
|
|
|
+ $this->saveCreateKorespOutForm($id_problem, $_POST);
|
|
|
+ }
|
|
|
+ $this->renderCreateKorespOutForm($id_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_koresp.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($_POST);echo'</pre>';
|
|
|
+ }
|
|
|
+
|
|
|
+ public function saveCreateKorespOutForm($id_problem, $args) {
|
|
|
+ echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: save('.$id_koresp.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($args);echo'</pre>';
|
|
|
+ }
|
|
|
+
|
|
|
+ public function ___sendAjaxCreateSave($args) {
|
|
|
+ header("Content-type: application/json");
|
|
|
+ $DBG = ('1' == V::get('DBG', '', $_REQUEST));
|
|
|
+ sleep(1);// TODO: RMME DBG loading
|
|
|
+
|
|
|
+ if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">TODO: save ID(' . $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->_acl);echo'</pre>';}
|
|
|
+ $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'<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->_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'<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);
|
|
|
+
|
|
|
+ $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('<br>', $outArr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ echo json_encode($retJson);
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|