10) die("-->Dossier invalide [$p_database_id]"); $noalyss_user = (defined("noalyss_user")) ? noalyss_user : phpcompta_user; $password = (defined("noalyss_password")) ? noalyss_password : phpcompta_password; $port = (defined("noalyss_psql_port")) ? noalyss_psql_port : phpcompta_psql_port; $host = (!defined("noalyss_psql_host")) ? '127.0.0.1' : noalyss_psql_host; if (defined("MULTI") && MULTI == "0") { $l_dossier = dbname; } else { if ($p_database_id == 0) { /* connect to the repository */ $l_dossier = sprintf("%saccount_repository", strtolower(domaine)); } else if ($p_type == 'dos') { /* connect to a folder (dossier) */ $l_dossier = sprintf("%sdossier%d", strtolower(domaine), $p_database_id); } else if ($p_type == 'mod') { /* connect to a template (modele) */ $l_dossier = sprintf("%smod%d", strtolower(domaine), $p_database_id); } else if ($p_type == 'template') { $l_dossier = 'template1'; } else { throw new Exception('Connection invalide'); } } parent::__construct($noalyss_user, $password, $l_dossier, $host, $port); $this->exec_sql('set search_path to public,pg_catalog;'); if ($this->exist_schema('comptaproc')) { $this->exec_sql('set search_path to public,comptaproc,pg_catalog;'); } $this->exec_sql('set DateStyle to ISO, MDY;'); $this->ret=true; $this->is_open=true; } function __toString(): string { return "DatabaseCore[db=" . var_export($this->db,true) . ", ret=" .var_export( $this->ret,true) . ", is_open=" . $this->is_open . ", sql=" . $this->sql . ", array=" . var_export($this->array,true) . ",dbname = ".$this->get_dbname() . "]"; } /*** * \brief Save a "piece justificative" , the name must be a receipt * * \param $seq jr_grpt_id * \return $oid of the lob file if success * null if a error occurs * */ function save_receipt($seq) { /** * pj is the $_FILES key */ $oid = $this->upload('pj'); if ($oid == false) { return false; } // Remove old document $ret = $this->exec_sql("select jr_pj from jrn where jr_grpt_id=$1" ,[$seq]); if (pg_num_rows($ret) != 0) { $r = pg_fetch_array($ret, 0); $old_oid = $r['jr_pj']; if (strlen($old_oid??"") != 0) $this->lo_unlink( $old_oid); } // Load new document $this->exec_sql("update jrn set jr_pj=$1 , jr_pj_name=$2, jr_pj_type=$3 where jr_grpt_id=$4", array($oid, $_FILES['pj']['name'], $_FILES['pj']['type'], $seq)); if ( $_FILES['pj']['type'] == 'text/xml' || $_FILES['pj']['type'] == 'application/xml' ) { } return $oid; } /** * \brief Get version of a database, the content of the * table version * * \return version number * */ function get_version() { $Res = $this->get_value("select max(val) from version"); return $Res; } /** * \brief loop to apply all the path to a folder or a template * Upgrade check if the folder $p_name needs to be upgrade thanks the variable DBVERSION * and run all the SQL script named upgradeX.sql from the folder noalyss/include/sql/patch * until X equal DBVERSION-1 * * \param $p_name database name * */ function apply_patch($p_name) { if (!$this->exist_table('version')) { echo _('Base de donnée vide'); return; } $MaxVersion = DBVERSION - 1; $succeed = ""; echo ''; } /** * return the name of the database with the domain name * @param $p_id of the folder WITHOUT the domain name * @param $p_type dos for folder mod for template * @return formatted name */ function format_name($p_id, $p_type) { switch ($p_type) { case 'dos': $sys_name = sprintf("%sdossier%d", strtolower(domaine), $p_id); break; case 'mod': $sys_name = sprintf("%smod%d", strtolower(domaine), $p_id); break; default: echo_error(__FILE__ . " format_name invalid type " . $p_type, __LINE__); throw new Exception(__FILE__ . " format_name invalid type " . $p_type . __LINE__); } return $sys_name; } }