$value) { if ($_POST['structureanalyticalpart'][$key] != '') { $tmp[$key]['ecmsyntheticaccounts_id'] = $return_id; $tmp[$key]['position'] = $key; $tmp[$key]['value'] = $_POST['structureanalyticalpart'][$key]; } } $this->saveStructureanAlyticalList($tmp); $analyticalList = explode(',', $_POST ['tableAnalyticalAccounts_rowOrder']); $analytical_array = array(); foreach ($analyticalList as $value) { if ($_POST ['tableAnalyticalAccounts_code_' . $value] != '') { $analytical_array [$value] ['code'] = $_POST ['tableAnalyticalAccounts_code_' . $value]; $analytical_array [$value] ['name'] = $_POST ['tableAnalyticalAccounts_name_' . $value]; } } $this->saveAnaliticalList($analytical_array); } function saveStructureanAlyticalList($pl) { global $current_user; $exists = array(); if ($this->id != '') { $GLOBALS['db']->query("DELETE FROM ecmsyntheticaccounts_structureanalyticalpart WHERE ecmsyntheticaccounts_id='" . $this->id . "'"); } foreach ($pl as $p) { if (!isset($p['ecmsyntheticaccounts_id']) || $p['ecmsyntheticaccounts_id'] == '') continue; $id = create_guid(); $t = array( $id, //id $this->id, //document id $p['position'], //user id $p['value'], //date accepted ); $q = "INSERT INTO ecmsyntheticaccounts_structureanalyticalpart VALUES ('" . implode("','", $t) . "')"; $GLOBALS['db']->query($q); $exists[] = $id; } } function showStructureanAlyticalList($array = false) { $json = getJSONobj(); if (isset($this->id) && $this->id != '') { $query = "SELECT * FROM ecmsyntheticaccounts_structureanalyticalpart WHERE ecmsyntheticaccounts_id='" . $this->id . "' ORDER BY position"; $r = $this->db->query($query); $return_array = array(); if ($r) { while ($w = $this->db->fetchByAssoc($r)) { $new = array(); $new['ecmsyntheticaccounts_id'] = $w['ecmsyntheticaccounts_id']; $new['position'] = $w['position']; $new['value'] = $w['value']; $return_array [] = $new; } return $array ? $return_array : $return_array; } } return $array ? false : '[]'; } function saveAnaliticalList($pl) { $exists = array(); if ($this->id != '') { $GLOBALS ['db']->query("DELETE FROM ecmsyntheticaccounts_analyticalaccounts WHERE ecmsyntheticaccount_id='" . $this->id . "'"); } foreach ($pl as $p) { // insert new record $id = create_guid(); $t = array( $id, $this->id, addslashes($p ['code']), addslashes($p ['name']) ); $q = "INSERT INTO ecmsyntheticaccounts_analyticalaccounts VALUES ('" . implode("','", $t) . "')"; $GLOBALS ['db']->query($q); $exists [] = $id; } } function getAnaliticalList($array = false) { if (isset($this->id) && $this->id != '') { $query = "SELECT code, name FROM ecmsyntheticaccounts_analyticalaccounts WHERE ecmsyntheticaccount_id='" . $this->id . "' ORDER BY code DESC"; $r = $this->db->query($query); $return_array = array(); if ($r) { while ($row = $this->db->fetchByAssoc($r)) { $a_json_row ['code'] = $row ['code']; $a_json_row ['name'] = $row ['name']; $return_array [] = $a_json_row; } $json = getJSONobj(); return $array ? $return_array : $return_array; } } return $array ? false : '[]'; } } ?>