fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [17255] prepare for custom code outside tree


From: sigurdne
Subject: [Fmsystem-commits] [17255] prepare for custom code outside tree
Date: Wed, 1 Nov 2017 15:28:13 -0400 (EDT)

Revision: 17255
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=17255
Author:   sigurdne
Date:     2017-11-01 15:28:13 -0400 (Wed, 01 Nov 2017)
Log Message:
-----------
prepare for custom code outside tree

Added Paths:
-----------
    thirdparty/PE_custom/BK_EBF/property/inc/custom/default/El_anlegg_LRS

Copied: thirdparty/PE_custom/BK_EBF/property/inc/custom/default/El_anlegg_LRS 
(from rev 17218, trunk/property/inc/export/default/El_anlegg_LRS)
===================================================================
--- thirdparty/PE_custom/BK_EBF/property/inc/custom/default/El_anlegg_LRS       
                        (rev 0)
+++ thirdparty/PE_custom/BK_EBF/property/inc/custom/default/El_anlegg_LRS       
2017-11-01 19:28:13 UTC (rev 17255)
@@ -0,0 +1,365 @@
+<?php
+       /**
+        * phpGroupWare - property: a Facilities Management System.
+        *
+        * @author Sigurd Nes <address@hidden>
+        * @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software 
Foundation, Inc. http://www.fsf.org/
+        * This file is part of phpGroupWare.
+        *
+        * phpGroupWare is free software; you can redistribute it and/or modify
+        * it under the terms of the GNU General Public License as published by
+        * the Free Software Foundation; either version 2 of the License, or
+        * (at your option) any later version.
+        *
+        * phpGroupWare is distributed in the hope that it will be useful,
+        * but WITHOUT ANY WARRANTY; without even the implied warranty of
+        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+        * GNU General Public License for more details.
+        *
+        * You should have received a copy of the GNU General Public License
+        * along with phpGroupWare; if not, write to the Free Software
+        * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
02110-1301  USA
+        *
+        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+        * @internal Development of this application was funded by 
http://www.bergen.kommune.no/bbb_/ekstern/
+        * @package property
+        * @subpackage export
+        * @version $Id$
+        */
+       /**
+        * Description
+        * @package property
+        */
+       phpgw::import_class('phpgwapi.datetime');
+
+       class export_conv
+       {
+
+               //var $fil_katalog='c:/temp'; //On windows use 
"//computername/share/filename" or "\\\\computername\share\filename" to check 
files on network shares.
+
+               var $debug = false;
+               protected $connection = false;
+               protected $receipt = array();
+               protected $type = '211';
+
+               function __construct()
+               {
+                       $GLOBALS['phpgw_info']['flags']['currentapp'] = 
'property';
+                       $this->db = & $GLOBALS['phpgw']->db;
+                       $this->join = & $this->db->join;
+
+                       $this->config = CreateObject('admin.soconfig', 
$GLOBALS['phpgw']->locations->get_id('property', '.invoice'));
+               }
+
+               protected function get_xmldata()
+               {
+                       $sql = "SELECT * FROM fm_entity_1_11 WHERE 
auto_kontering = 1 AND category = 2";//kun fellesmålere som er merket med 
autokontering
+
+                       $this->db->query($sql, __LINE__, __FILE__);
+                       $anlegg = array();
+
+                       $TreeID = $this->type;
+                       $PeriodFrom = date('Ym');
+                       $PeriodTo = 209912;
+
+                       $memory = xmlwriter_open_memory();
+                       xmlwriter_set_indent($memory, true);
+                       xmlwriter_start_document($memory, '1.0', 'UTF-8');
+                       xmlwriter_start_element($memory, 'TreeListe');
+                       xmlwriter_write_attribute($memory, 'TreeID', $TreeID);
+                       xmlwriter_write_attribute($memory, 'xmlns:xsi', 
'http://www.w3.org/2001/XMLSchema-instance');
+                       xmlwriter_write_attribute($memory, 
'xsi:noNamespaceSchemaLocation', 'TreeListe.xsd');
+
+                       while ($this->db->next_record())
+                       {
+                               xmlwriter_start_element($memory, 'Tree');
+                               xmlwriter_write_element($memory, 'ID', 'TJ');
+                               xmlwriter_write_element($memory, 'Verdi', 
substr($this->db->f('maalepunkt_id'), -8));
+                               xmlwriter_write_element($memory, 'Beskrivelse', 
$this->db->f('address'));
+                               xmlwriter_write_element($memory, 'Firma', 'BB');
+                               xmlwriter_write_element($memory, 'PeriodeFra', 
$PeriodFrom);
+                               xmlwriter_write_element($memory, 'PeriodeTil', 
$PeriodTo);
+                               xmlwriter_write_element($memory, 'Status', 'N');
+                               xmlwriter_start_element($memory, 
'BegrepsLister');
+                               xmlwriter_start_element($memory, 
'BegrepsListe');
+                               xmlwriter_write_attribute($memory, 'Prosent', 
100);
+                               xmlwriter_start_element($memory, 'Begrep');
+                               xmlwriter_write_comment($memory, 'Firma');
+                               xmlwriter_write_element($memory, 'ID', 'A3');
+                               xmlwriter_write_element($memory, 'Verdi', 'BB');
+                               xmlwriter_end_element($memory);
+                               xmlwriter_start_element($memory, 'Begrep');
+                               xmlwriter_write_comment($memory, 'Art');
+                               xmlwriter_write_element($memory, 'ID', 'A0');
+                               xmlwriter_write_element($memory, 'Verdi', 
'12304121');
+                               xmlwriter_end_element($memory);
+                               xmlwriter_start_element($memory, 'Begrep');
+                               xmlwriter_write_comment($memory, 'Asvar');
+                               xmlwriter_write_element($memory, 'ID', 'C1');
+                               xmlwriter_write_element($memory, 'Verdi', 45);
+                               xmlwriter_end_element($memory);
+                               xmlwriter_start_element($memory, 'Begrep');
+                               xmlwriter_write_comment($memory, 'Tjeneste');
+                               xmlwriter_write_element($memory, 'ID', 'TJE');
+                               xmlwriter_write_element($memory, 'Verdi', '');
+                               xmlwriter_end_element($memory);
+                               xmlwriter_start_element($memory, 'Begrep');
+                               xmlwriter_write_comment($memory, 'Objekt');
+                               xmlwriter_write_element($memory, 'ID', 'F0');
+                               xmlwriter_write_element($memory, 'Verdi', 
$this->db->f('loc1'));
+                               xmlwriter_end_element($memory);
+                               xmlwriter_start_element($memory, 'Begrep');
+                               xmlwriter_write_comment($memory, 'Prosjekt');
+                               xmlwriter_write_element($memory, 'ID', 'B0');
+                               xmlwriter_write_element($memory, 'Verdi', '');
+                               xmlwriter_end_element($memory);
+                               xmlwriter_start_element($memory, 'Begrep');
+                               xmlwriter_write_comment($memory, 'Fagkode');
+                               xmlwriter_write_element($memory, 'ID', 'B1');
+                               xmlwriter_write_element($memory, 'Verdi', 
'999');
+                               xmlwriter_end_element($memory);
+                               xmlwriter_start_element($memory, 'Begrep');
+                               xmlwriter_write_comment($memory, 'AV');
+                               xmlwriter_write_element($memory, 'ID', 'AV');
+                               xmlwriter_write_element($memory, 'Verdi', '');
+                               xmlwriter_end_element($memory);
+                               xmlwriter_end_element($memory);
+                               xmlwriter_end_element($memory);
+                               xmlwriter_end_element($memory);
+                       }
+                       xmlwriter_end_element($memory);
+                       $xml = xmlwriter_output_memory($memory, true);
+
+                       if ($this->debug)
+                       {
+                               header('Content-type: text/xml');
+                               echo $xml;
+                               die();
+                       }
+
+                       return $xml;
+               }
+
+               protected function log_end()
+               {
+                       $msgbox_data = 
$GLOBALS['phpgw']->common->msgbox_data($this->receipt);
+
+                       $insert_values = array
+                               (
+                               0,
+                               date($this->db->datetime_format()),
+                               'El_anlegg_LRS',
+                               implode(',', (array_keys($msgbox_data)))
+                       );
+
+                       $insert_values = 
$this->db->validate_insert($insert_values);
+
+                       $sql = "INSERT INTO fm_cron_log 
(cron,cron_date,process,message) "
+                               . "VALUES ($insert_values)";
+                       $this->db->query($sql, __LINE__, __FILE__);
+               }
+
+               public function overfor( $download )
+               {
+
+//                     $download = 'on';
+//                     $download = False;
+//                     $this->debug=True;
+                       //Bestem filnavn
+                       $Filnavn = $this->LagFilnavn();
+
+                       if (!$Filnavn)
+                       {
+                               $message = 'LagFilnavn: Filnavn er i bruk';
+                               $receipt['error'][] = array('msg' => $message);
+                               $this->log_end();
+                               return;
+                       }
+
+                       //Test om filen kan opprettes og skrives til
+                       if (@fopen($Filnavn, "wb"))
+                       {
+                               unlink($Filnavn);
+                       }
+                       else
+                       {
+                               $message = 'kan ikke lagre til fil: ' . 
$Filnavn . '<br>';
+                               $receipt['error'][] = array('msg' => $message);
+                               if (!$this->debug)
+                               {
+                                       $this->log_end();
+                               }
+                       }
+
+                       //Velg ut alle anlegg som skal overføres
+                       $xmldata = $this->get_xmldata();
+
+                       if ($xmldata)
+                       {
+                               $this->transfer_anlegg($xmldata, $Filnavn, 
$download);
+                       }
+
+                       if ($this->connection)
+                       {
+                               switch 
($this->config->config_data['common']['method'])
+                               {
+                                       case 'ftp';
+                                               ftp_quit($this->connection);
+                                               break;
+                                       case 'ssh';
+                                               ssh2_exec($this->connection, 
'exit');
+                                               break;
+                               }
+                       }
+                       //Lagre melding
+                       if ($download == 'on')
+                       {
+                               $this->log_end();
+                       }
+
+                       return $receipt;
+               }
+
+               protected function LagFilnavn()
+               {
+                       $timestamp = date('YmdHi', 
phpgwapi_datetime::user_localtime());
+                       $fil_katalog = 
$this->config->config_data['export']['path'];
+
+                       $Filnavn = $fil_katalog . 
"/konteringstre_{$this->type}_{$timestamp}.xml";
+
+                       //Sjekk om filen eksisterer
+                       if (file_exists($Filnavn))
+                       {
+                               unlink($Filnavn);
+                       }
+
+                       return $Filnavn;
+               }
+
+               protected function transfer_anlegg( $xmldata, $Filnavn, 
$download )
+               {
+                       if ($download == 'on' && !$this->debug)
+                       {
+                               $file_written = false;
+                               $fp = fopen($Filnavn, "wb");
+                               fwrite($fp, $xmldata);
+
+                               if (fclose($fp))
+                               {
+                                       $file_written = true;
+                               }
+
+                               if ($file_written && 
($this->config->config_data['common']['method'] != 'ftp' && 
$this->config->config_data['common']['method'] != 'ssh'))
+                               {
+                                       $transfer_ok = true;
+                               }
+                               else if ($file_written)
+                               {
+                                       $transfer_ok = 
$this->transfer($xmldata, $Filnavn);
+                               }
+
+                               if ($transfer_ok)
+                               {
+                                       $message = "El Anlegg er overført, fil: 
{$Filnavn}";
+                                       phpgwapi_cache::message_set($message, 
'message');
+                               }
+                               else
+                               {
+                                       $message = 'Noe gikk galt med 
overføring av El Anlegg';
+                                       phpgwapi_cache::message_set($message, 
'error');
+                               }
+                       }
+                       else
+                       {
+                               header('Content-type: text/xml');
+                               echo $xmldata;
+                               die();
+                       }
+               }
+
+               protected function transfer( $xmldata, $Filnavn )
+               {
+                       $transfer_ok = false;
+                       if ($this->config->config_data['common']['method'] == 
'ftp' || $this->config->config_data['common']['method'] == 'ssh')
+                       {
+                               if (!$connection = $this->connection)
+                               {
+                                       $connection = $this->phpftp_connect();
+                               }
+
+                               $basedir = 
$this->config->config_data['export']['remote_basedir'];
+                               if ($basedir)
+                               {
+                                       $remote_file = $basedir . '/' . 
basename($Filnavn);
+                               }
+                               else
+                               {
+                                       $remote_file = basename($Filnavn);
+                               }
+
+                               switch 
($this->config->config_data['common']['method'])
+                               {
+                                       case 'ftp';
+                                               $transfer_ok = 
ftp_put($connection, $remote_file, $Filnavn, FTP_BINARY);
+                                               break;
+                                       case 'ssh';
+                                               $sftp = ssh2_sftp($connection);
+                                               $stream = 
@fopen("ssh2.sftp://$sftp$remote_file";, 'w');
+                                               $data_to_send = 
@file_get_contents($Filnavn);
+                                               fwrite($stream, $data_to_send);
+                                               $transfer_ok = @fclose($stream);
+                                               break;
+                                       default:
+                                               $transfer_ok = false;
+                               }
+
+                               if (!$transfer_ok)
+                               {
+                                       unlink($Filnavn);
+                               }
+                       }
+                       return $transfer_ok;
+               }
+
+               protected function phpftp_connect()
+               {
+                       $server = $this->config->config_data['common']['host'];
+                       $user = $this->config->config_data['common']['user'];
+                       $password = 
$this->config->config_data['common']['password'];
+                       $port = 22;
+
+                       switch ($this->config->config_data['common']['method'])
+                       {
+                               case 'ftp';
+                                       if ($connection = ftp_connect($server))
+                                       {
+                                               ftp_login($connection, $user, 
$password);
+                                       }
+                                       break;
+                               case 'ssh';
+                                       if (!function_exists("ssh2_connect"))
+                                       {
+                                               die("function ssh2_connect 
doesn't exist");
+                                       }
+                                       if (!($connection = 
ssh2_connect("$server", $port)))
+                                       {
+                                               $message = "fail: unable to 
establish connection";
+                                               _debug_array($message);
+                                               //$receipt['error'][]= 
array('msg' => $message);
+                                       }
+                                       else
+                                       {
+                                               // try to authenticate with 
username root, password secretpassword
+                                               if 
(!ssh2_auth_password($connection, $user, $password))
+                                               {
+                                                       $message = "fail: 
unable to authenticate";
+                                                       _debug_array($message);
+                                                       //$receipt['error'][]= 
array('msg' => $message);
+                                               }
+                                       }
+                                       break;
+                       }
+                       $this->connection = $connection;
+                       return $connection;
+               }
+       }
\ No newline at end of file


Property changes on: 
thirdparty/PE_custom/BK_EBF/property/inc/custom/default/El_anlegg_LRS
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Revision Author Id
\ No newline at end of property
Added: svn:mergeinfo
## -0,0 +1,3 ##
+/branches/dev-syncromind/property/inc/export/default/El_anlegg_LRS:13653
+/branches/dev-syncromind-2/property/inc/export/default/El_anlegg_LRS:14933-16846
+/branches/stavangerkommune/property/inc/export/default/El_anlegg_LRS:12743-12875,12986
\ No newline at end of property



reply via email to

[Prev in Thread] Current Thread [Next in Thread]