fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [6870] Merge 6852:6869 from trunk


From: Sigurd Nes
Subject: [Fmsystem-commits] [6870] Merge 6852:6869 from trunk
Date: Thu, 27 Jan 2011 10:32:12 +0000

Revision: 6870
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6870
Author:   sigurdne
Date:     2011-01-27 10:32:11 +0000 (Thu, 27 Jan 2011)
Log Message:
-----------
Merge 6852:6869 from trunk

Added Paths:
-----------
    branches/Version-1_0-branch/property/organize_pdf_BKB.php

Property Changed:
----------------
    branches/Version-1_0-branch/


Property changes on: branches/Version-1_0-branch
___________________________________________________________________
Modified: svn:mergeinfo
   - 
/trunk:6439-6441,6443,6445-6447,6449-6464,6466-6468,6470-6474,6476-6477,6479-6480,6483-6488,6490-6491,6493-6494,6496-6501,6503-6504,6506,6508,6510-6511,6513,6515-6516,6518,6520-6524,6526-6528,6533-6534,6536-6541,6543-6565,6567,6569,6571-6576,6578,6580-6586,6588-6596,6598-6600,6602-6604,6606-6607,6609-6611,6613-6625,6629-6639,6641-6643,6645-6646,6648,6650-6654,6656-6659,6661-6663,6665-6666,6668-6669,6672-6673,6675,6677-6678,6680,6682-6686,6688-6717,6719,6721-6722,6724-6728,6730,6732-6734,6736-6739,6741,6743,6745-6746,6748-6756,6758-6762,6764,6766-6788,6790,6792-6798,6800-6814,6816-6819,6821-6822,6824-6826,6828-6837,6839,6841,6843-6849,6851
   + 
/trunk:6439-6441,6443,6445-6447,6449-6464,6466-6468,6470-6474,6476-6477,6479-6480,6483-6488,6490-6491,6493-6494,6496-6501,6503-6504,6506,6508,6510-6511,6513,6515-6516,6518,6520-6524,6526-6528,6533-6534,6536-6541,6543-6565,6567,6569,6571-6576,6578,6580-6586,6588-6596,6598-6600,6602-6604,6606-6607,6609-6611,6613-6625,6629-6639,6641-6643,6645-6646,6648,6650-6654,6656-6659,6661-6663,6665-6666,6668-6669,6672-6673,6675,6677-6678,6680,6682-6686,6688-6717,6719,6721-6722,6724-6728,6730,6732-6734,6736-6739,6741,6743,6745-6746,6748-6756,6758-6762,6764,6766-6788,6790,6792-6798,6800-6814,6816-6819,6821-6822,6824-6826,6828-6837,6839,6841,6843-6849,6851,6853-6869

Copied: branches/Version-1_0-branch/property/organize_pdf_BKB.php (from rev 
6869, trunk/property/organize_pdf_BKB.php)
===================================================================
--- branches/Version-1_0-branch/property/organize_pdf_BKB.php                   
        (rev 0)
+++ branches/Version-1_0-branch/property/organize_pdf_BKB.php   2011-01-27 
10:32:11 UTC (rev 6870)
@@ -0,0 +1,424 @@
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2010 Free Software Foundation, Inc. 
http://www.fsf.org/
+       * @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 custom
+       * @version $Id$
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+
+       $GLOBALS['phpgw_info']['flags'] = array
+       (
+               'currentapp'    => 'property'
+       );
+
+       include_once('../header.inc.php');
+
+
+       if ( isset($GLOBALS['phpgw_info']['user']['apps']['admin']) )
+       {
+               $organize = new organize_pdf_bkb();
+               $organize->pre_run();
+       }
+       else
+       {
+               echo 'go away';
+       }
+
+       class organize_pdf_bkb
+       {
+               /* In Admin->Property->Async servises:
+               *  Name: property.custom_functions.index
+               *  Data: function=organize_pdf,dir=C:/path/to/pdfs
+               */
+
+               protected $dir = '/opt/BK_Branntegninger_pdf';
+//             protected $suffix = 'dwg';
+               protected $suffix = 'pdf';
+               protected $bypass = true; // bypass location check (only for 
debugging)
+               protected $cat_id = 17;
+               protected $function_name = 'organize_pdf_BBE';
+
+               function __construct()
+               {
+                       $this->bocommon         = 
CreateObject('property.bocommon');
+                       $this->vfs                      = 
CreateObject('phpgwapi.vfs');
+                       $this->rootdir          = $this->vfs->basedir;
+                       $this->fakebase         = $this->vfs->fakebase = 
'/property';
+                       $this->db           = & $GLOBALS['phpgw']->db;
+               }
+
+               function pre_run()
+               {
+                       $confirm        = get_var('confirm',array('POST'));
+                       $execute        = get_var('execute',array('GET'));
+                       if(get_var('dir',array('GET')))
+                       {
+                               $this->dir = urldecode 
(get_var('dir',array('GET')));
+                       }
+                       if(get_var('suffix',array('GET')))
+                       {
+                               $this->suffix = get_var('suffix',array('GET'));
+                       }
+
+                       if(!$execute)
+                       {
+                               $dry_run=True;
+                       }
+
+                       if ($confirm)
+                       {
+                               $this->execute($dry_run,$cron);
+                       }
+                       else
+                       {
+                               $this->confirm($execute=False);
+                       }
+               }
+
+               function confirm($execute='',$done='')
+               {
+
+                       $link_data = array
+                       (
+                               'execute'       => $execute,
+                               'dir'           => $this->dir,
+                               'suffix'        => $this->suffix,
+                       );
+
+                       $lang_confirm_msg = '';
+                       if(!$done)
+                       {
+                               if(!$execute)
+                               {
+                                       $lang_confirm_msg       = 'Gå videre 
for å se hva som blir lagt til';
+                               }
+                               else
+                               {
+                                       $lang_confirm_msg       = 'Vil du 
virkelig utføre denne operasjonen';
+                               }
+                       }
+
+                       $lang_yes                       = lang('yes');
+
+                       
$GLOBALS['phpgw']->xslttpl->add_file(array('confirm_custom'));
+
+                       $msgbox_data = 
$this->bocommon->msgbox_data($this->receipt);
+
+                       $data = array
+                       (
+                               'msgbox_data'                   => 
$GLOBALS['phpgw']->common->msgbox($msgbox_data),
+                               'done_action'                   => 
$GLOBALS['phpgw']->link('organize_pdf_BKB.php'),
+                               'run_action'                    => 
$GLOBALS['phpgw']->link('organize_pdf_BKB.php',$link_data),
+                               'message'                               => 
$this->receipt['message'],
+                               'lang_confirm_msg'              => 
$lang_confirm_msg,
+                               'lang_yes'                              => 
$lang_yes,
+                               'lang_yes_statustext'   => 'Organisere 
tegninger i register og på disk',
+                               'lang_no_statustext'    => 'tilbake',
+                               'lang_no'                               => 
lang('no'),
+                               'lang_done'                             => 
'Avbryt',
+                               'lang_done_statustext'  => 'tilbake'
+                       );
+
+                       $appname                = 'Organisere tegninger';
+                       $function_msg   = 'Organisere tegninger i register og 
på disk';
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('property') . ' - ' . $appname . ': ' . $function_msg;
+                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('confirm' => $data));
+                       $GLOBALS['phpgw']->xslttpl->pp();
+               }
+
+               function execute($dry_run='',$cron='')
+               {
+                       set_time_limit(1000);
+
+                       if(!is_dir("{$this->dir}/archive"))
+                       {
+                               if(!mkdir("{$this->dir}/archive"))
+                               {
+                                       
$this->receipt['error'][]=array('msg'=>lang('failed to create directory') . " 
:{$this->dir}/archive");
+                                       $this->confirm('',true);
+                                       return;
+                               }
+                       }
+
+                       $file_list = $this->get_files();
+
+                       if($dry_run)
+                       {
+                               $this->confirm($execute=True);
+                               _debug_array($file_list);
+                       }
+                       else
+                       {
+                               if ($file_list && isset($file_list['valid']))
+                               {
+                                       foreach($file_list['valid'] as 
$file_entry)
+                                       {
+                                               
$this->create_dir($file_entry['location_code']);
+                                               $this->copy_file($file_entry);
+                                       }
+                               }
+                               if(!$cron)
+                               {
+                                       
$this->confirm($execute=false,$done=true);
+                               }
+
+                               $msgbox_data = 
$this->bocommon->msgbox_data($this->receipt);
+
+                               $insert_values= array
+                               (
+                                       $cron,
+                                       date($this->bocommon->datetimeformat),
+                                       $this->function_name,
+                                       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__);
+                       }
+               }
+
+               function get_files()
+               {
+                       $myfilearray = array();
+
+                       if(!is_dir($this->dir))
+                       {
+                               return $myfilearray;
+                       }
+                       $dir = new DirectoryIterator($this->dir); 
+
+                       if ( is_object($dir) )
+                       {
+                               foreach ( $dir as $file )
+                               {
+                                       if ( $file->isDot()
+                                               || !$file->isFile()
+                                               || !$file->isReadable()
+                                               || strcasecmp( end( explode( 
".", $file->getPathname() ) ), $this->suffix ) != 0 )
+                                       {
+                                               continue;
+                                       }
+                                       $file_name = $file->getFilename();
+
+                                       
if($this->check_old_building($file_name))
+                                       {
+                                               $myfilearray['valid'][] = array
+                                               (
+                                                       'last_modified'=> 
$file->getMTime(),
+                                                       'file_name'=> 
$file_name,
+                                                       'file_path'=> (string) 
"{$this->dir}/{$file_name}",
+                                                       'tips_bygg'=> 
substr($file_name, 0, 6),
+                                                       'loc1'=>  
$this->get_loc(substr($file_name, 0, 6)),
+                                                       'loc2'=>  $this->loc2,
+                                                       'location_code' => 
$this->location_code,
+                                                       'cat_id'        => 
$this->cat_id,
+                                                       'new_file_name' 
=>str_replace(' Model (1)', '', $this->loc1 . $this->loc2 . (substr($file_name, 
6, (strlen($file_name)-6)))),
+                                               );
+                                       }
+                                       else
+                                       {
+                                               $myfilearray['rejected'][] = 
array
+                                               (
+                                                       'file_name' => 
$file_name,
+                                                       'strlen'        => 
strlen($file_name),
+                                                       'building'      => 
$this->check_old_building($file_name)
+                                               );
+                                       }
+                               }
+                       }
+
+                       return $myfilearray;
+               }
+
+               function get_loc($file)
+               {
+                       $tips_bygg = substr($file, 0, 6);
+                       
+                       $sql = "SELECT loc1,loc2  FROM fm_location2 WHERE 
tips_bygg= '$tips_bygg'";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       $this->db->next_record();
+                       $this->loc1 = $this->db->f('loc1');
+                       $this->loc2 = $this->db->f('loc2');
+                       $this->location_code = $this->db->f('loc1') . '-' 
.$this->db->f('loc2');
+                       return $this->db->f('loc1');
+               }
+
+
+               function check_old_building($file)
+               {
+                       $tips_bygg = substr($file, 0, 6);
+                       
+                       $sql = "SELECT count(*) as cnt FROM fm_location2 WHERE 
tips_bygg= '$tips_bygg'";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       $this->db->next_record();
+                       if($this->db->f('cnt'))
+                       {
+                               return True;
+                       }
+               }
+               function check_building($file)
+               {
+                       $loc1 = substr($file, 0, 4);
+                       $loc2 = substr($file, 4, 2);
+                       $sql = "SELECT count(*) as cnt FROM fm_location2 WHERE 
loc1= '$loc1' AND loc2= '$loc2'";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       $this->db->next_record();
+                       return !!$this->db->f('cnt');
+               }
+
+               function create_dir($location_code='')
+               {
+                       $this->vfs->override_acl = 1;
+
+                       $dir = "{$this->fakebase}/document/{$location_code}";
+
+                       if(!$this->vfs->file_exists(array(
+                                       'string' => $dir,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $dir,
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$this->receipt['error'][]=array('msg'=>lang('failed to create directory') . " 
:{$dir}");
+                               }
+                               else
+                               {
+                                       
$this->receipt['message'][]=array('msg'=>lang('directory created') . " 
:{$dir}");
+                               }
+                       }
+
+
+                       $dir = 
"{$this->fakebase}/document/{$location_code}/{$this->cat_id}";
+                       if(!$this->vfs->file_exists(array(
+                                       'string' => $dir,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $dir,
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$this->receipt['error'][]=array('msg'=>lang('failed to create directory') . " 
:{$dir}");
+                               }
+                               else
+                               {
+                                       
$this->receipt['message'][]=array('msg'=>lang('directory created') . " 
:{$dir}");
+                               }
+                       }
+
+
+                       $this->vfs->override_acl = 0;
+               }
+
+               function copy_file($values)
+               {
+                       $to_new_file = 
"{$this->fakebase}/document/{$values['location_code']}/{$this->cat_id}/{$values['new_file_name']}";
+
+                       $from_file = $values['file_path'];
+
+                       $this->db->transaction_begin();
+
+                       $this->vfs->override_acl = 1;
+
+
+                       if($this->vfs->file_exists(array(
+                                       'string' => $to_new_file,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               
$this->receipt['error'][]=array('msg'=>lang('File %1 already 
exists!',$values['new_file_name']));
+                       }
+                       else
+                       {
+                               if(!$this->vfs->cp (array (
+                                       'from'  => $from_file,
+                                       'to'    => $to_new_file,
+                                       'relatives'     => array 
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
+                               {
+                                       
$this->receipt['error'][]=array('msg'=>lang('Failed to copy file !') . 
$values['new_file_name']);
+                               }
+                               else
+                               {
+                                       $address = 
$this->get_address($values['loc1'],$values['loc2'],$values['loc3']);
+
+                                       $values['title'] = 'Branntegning - pdf';
+                                       
+                                       $insert_values= array(
+                                               $values['new_file_name'],
+                                               $values['title'],
+                                               'public',
+                                               $values['cat_id'],
+                                               time(),
+                                               $values['last_modified'],
+                                               1,
+                                               6,
+                                               2,
+                                               $values['location_code'],
+                                               $address,
+                                               $values['branch_id'],
+                                               $values['vendor_id'],
+                                               6,
+                                               $values['loc1'],
+                                               $values['loc2']
+                                               );
+
+                                       $insert_values  = 
$this->db->validate_insert($insert_values);
+
+                                       $sql = "INSERT INTO fm_document 
(document_name,title,access,category,entry_date,document_date,version,coordinator,status,"
+                                               . 
"location_code,address,branch_id,vendor_id,user_id,loc1,loc2) "
+                                               . "VALUES ($insert_values)";
+
+                                       
$this->db->query($sql,__LINE__,__FILE__);
+                                       
+                                       $ok = rename($from_file, 
"{$this->dir}/archive/{$values['file_name']}");
+
+                                       
$this->receipt['message'][]=array('msg'=>lang('File %1 
copied!',$values['new_file_name']));
+                                       
$this->receipt['message'][]=array('msg'=>lang('File %1 moved!',$from_file));
+                               }
+                       }
+
+                       $this->db->transaction_commit();
+                       $this->vfs->override_acl = 0;
+               }
+
+               function get_address($loc1='',$loc2='')
+               {
+                       if ($loc3)
+                       {
+                               $sql = "SELECT loc3_name as address FROM 
fm_location3 WHERE loc1='$loc1' AND loc2='$loc2' AND loc3='$loc3'";
+                       }
+                       else
+                       {
+                               $sql = "SELECT loc2_name as address FROM 
fm_location2 WHERE loc1='$loc1' AND loc2='$loc2'";
+                       }
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       $this->db->next_record();
+                       return $this->db->f('address');
+               }
+       }




reply via email to

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