[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/inc/cron import_from_scanner.php
From: |
Sigurd Nes |
Subject: |
[Phpgroupware-cvs] property/inc/cron import_from_scanner.php |
Date: |
Sat, 06 Oct 2007 17:11:48 +0000 |
CVSROOT: /sources/phpgroupware
Module name: property
Changes by: Sigurd Nes <sigurdne> 07/10/06 17:11:48
Modified files:
inc/cron : import_from_scanner.php
Log message:
more work on scanner integration
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/property/inc/cron/import_from_scanner.php?cvsroot=phpgroupware&r1=1.1&r2=1.2
Patches:
Index: import_from_scanner.php
===================================================================
RCS file: /sources/phpgroupware/property/inc/cron/import_from_scanner.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- import_from_scanner.php 4 Oct 2007 14:01:19 -0000 1.1
+++ import_from_scanner.php 6 Oct 2007 17:11:48 -0000 1.2
@@ -24,7 +24,7 @@
* @internal Development of this application was funded by
http://www.bergen.kommune.no/bbb_/ekstern/
* @package property
* @subpackage custom
- * @version $Id: import_from_scanner.php,v 1.1 2007/10/04 14:01:19
sigurdne Exp $
+ * @version $Id: import_from_scanner.php,v 1.2 2007/10/06 17:11:48
sigurdne Exp $
*/
/**
@@ -36,7 +36,7 @@
{
/* In Admin->Property->Async servises:
* Name: property.custom_functions.index
- * Data: function=import_from_scanner,dir=C:/path/to/drawings
+ * Data:
function=import_from_scanner,dir=C:/path/to/scanned_images
*/
var $dir = '/home/sn5607/test';
@@ -82,7 +82,7 @@
else
{
$confirm =
get_var('confirm',array('POST'));
- $execute =
get_var('execute',array('GET'));
+ $execute =
true;//get_var('execute',array('GET'));
if(get_var('dir',array('GET')))
{
$this->dir = urldecode
(get_var('dir',array('GET')));
@@ -160,7 +160,6 @@
function execute($dry_run='',$cron='')
{
-
$file_list = $this->get_files();
if($dry_run)
@@ -174,70 +173,87 @@
if (isset($file_list) && is_array($file_list))
{
$this->botts =
CreateObject($this->currentapp.'.botts');
+ $this->bolocation =
CreateObject($this->currentapp.'.bolocation');
foreach($file_list as $file_entry)
{
$file_entry['user_id'] =
$this->get_user_id($file_entry['user']);
-_debug_array($file_entry);die();
- if($file_entry['type'] ==
'Reklamasjon')
- {
-
if($file_entry['target'] && $this->find_ticket($file_entry['target']))
+ if($file_entry['type'] ==
'Dokumentasjon')
{
-
- }
- else
- {
-
$values['details'] = $file_entry['descr'];
-
$values['assignedto']=
(isset($GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['assigntodefault'])?$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['assigntodefault']:'');
-
$values['group_id']=
(isset($GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['groupdefault'])?$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['groupdefault']:'');
-
$values['cat_id'] =
(isset($GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['tts_category'])?$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['tts_category']:'');
-
if($values['location_code'] = $this->get_location_code($file_entry['target']))
{
-
$receipt = $this->botts->add($values);
+
$this->bolocation->initiate_ui_location(array('type_id' => -1,'tenant' =>
True));
-
$to_file = $this->fakebase. SEP . 'fmticket' . SEP . $receipt['id'] . SEP .
$file_entry['file_name'] . $this->suffix;
+ $insert_record
= $GLOBALS['phpgw']->session->appsession('insert_record',$this->currentapp);
-
if($this->botts->vfs->file_exists(array(
-
'string' => $to_file,
-
'relatives' => Array(RELATIVE_NONE)
-
)))
- {
-
$receipt['error'][]=array('msg'=>lang('This file already exists !'));
- }
- else
+ $values =
$this->bolocation->read_single($values['location_code'],array('tenant_id'=>'lookup'));
+ for ($i=0;
$i<count($insert_record['location']); $i++)
{
-
$this->botts->create_document_dir($receipt['id']);
-
$this->botts->vfs->override_acl = 1;
-
-
if(!$this->botts->vfs->cp (array (
-
'from' => $this->dir . SEP . $file_entry['file_name'] . $this->suffix,
-
'to' => $to_file,
-
'relatives' => array (RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
+
if($values[$insert_record['location'][$i]])
{
-
$receipt['error'][]=array('msg'=>lang('Failed to upload file !'));
-
}
-
$this->botts->vfs->override_acl = 0;
+
$values['location'][$insert_record['location'][$i]]=
$values[$insert_record['location'][$i]];
}
}
+
+
$values['category_id'] = '';
+
$values['values_date'] = time();
+
$values['version'] = '1';
+
$values['coordinator'] = '';
+
$values['status'] = '1';
+
$values['branch_id'] = '';
+
$values['vendor_id'] = '';
+
$values['user_id'] = $file_entry['user_id'];
+
$values['file_name'] = $file_entry['file_name'];
+
$values['title'] = $file_entry['descr'];
+
$this->create_loc1_dir($values['loc1']);
+
$this->copy_files($values);
}
+
}
+
+ if($file_entry['type'] ==
'Reklamasjon')
+ {
+
if($file_entry['target'] && $this->find_ticket($file_entry['target']))
+ {
+
$this->add_file_to_ticket($file_entry['target'],$file_entry['file_name']);
}
+ else
+ {
+
if($values['location_code'] = $this->get_location_code($file_entry['target']))
+ {
+
$this->bolocation->initiate_ui_location(array('type_id' => -1,'tenant' =>
True));
- $loc1_list = array_keys($loc1_list);
+
$insert_record =
$GLOBALS['phpgw']->session->appsession('insert_record',$this->currentapp);
- for ($i=0;$i<count($loc1_list);$i++)
+ $values
=
$this->bolocation->read_single($values['location_code'],array('tenant_id'=>'lookup'));
+ for
($i=0; $i<count($insert_record['location']); $i++)
+ {
+
if($values[$insert_record['location'][$i]])
{
- //
$this->create_loc1_dir($loc1_list[$i]);
+
$values['location'][$insert_record['location'][$i]]=
$values[$insert_record['location'][$i]];
}
+ }
+
+
$values['details'] = $file_entry['descr'];
+
$values['subject'] = $file_entry['descr'];
+
$values['assignedto'] =
(isset($GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['assigntodefault'])?$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['assigntodefault']:'');
+
$values['group_id'] =
(isset($GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['groupdefault'])?$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['groupdefault']:'');
+
$values['cat_id'] =
(isset($GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['tts_category'])?$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['tts_category']:'');
+
$values['priority'] =
(isset($GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['prioritydefault'])?$GLOBALS['phpgw_info']['user']['preferences'][$this->currentapp]['prioritydefault']:'');
- for ($i=0;$i<count($file_list);$i++)
+
$receipt = $this->botts->add($values);
+
$this->add_file_to_ticket($receipt['id'],$file_entry['file_name']);
+ }
+ else
{
- //
$this->copy_files($file_list[$i]);
+
$this->receipt['error'][]=array('msg'=>lang('Location is missing !'));
+ }
+ }
+ }
}
}
-die();
+//die();
if(!$cron)
{
$this->confirm($execute=false,$done=True);
@@ -307,29 +323,42 @@
return $file_list;
}
- function get_type($filename='')
+ function add_file_to_ticket($id,$file_name)
{
- $drawing_type=array(
- 'p' => 'plan',
- 'f' => 'fasade',
- 's' => 'snitt'
- );
+ $to_file = $this->fakebase. SEP . 'fmticket' .
SEP . $id . SEP . $file_name . $this->suffix;
- for ($i=10;$i<strlen($filename);$i++)
+ if($this->botts->vfs->file_exists(array(
+ 'string' => $to_file,
+ 'relatives' => Array(RELATIVE_NONE)
+ )))
{
- $type =
$drawing_type[strtolower(substr($filename,$i,1))];
- if($type)
+
$this->receipt['error'][]=array('msg'=>lang('This file already exists !'));
+ }
+ else
{
- return $type;
+ $this->botts->create_document_dir($id);
+ $this->botts->vfs->override_acl = 1;
+
+ if(!$this->botts->vfs->cp (array (
+ 'from' => $this->dir . SEP .
$file_name . $this->suffix,
+ 'to' => $to_file,
+ 'relatives' => array
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
+ {
+
$this->receipt['error'][]=array('msg'=>lang('Failed to upload file !'));
}
+ $this->vfs->override_acl = 0;
}
}
function find_ticket($id='')
{
+ if(!ctype_digit($id))
+ {
+ return False;
+ }
+ else
+ {
$sql = "SELECT count(*) FROM fm_tts_tickets WHERE
id='$id'";
-
-//_debug_array($sql);
$this->db->query($sql,__LINE__,__FILE__);
$this->db->next_record();
if($this->db->f(0))
@@ -337,13 +366,13 @@
return True;
}
}
+ }
function get_user_id($account_lastname = '')
{
$account_lastname =
$account_lastname?$account_lastname:$this->default_user_last_name;
$sql = "SELECT account_id FROM phpgw_accounts WHERE
account_lastname='$account_lastname'";
-//_debug_array($sql);
$this->db->query($sql,__LINE__,__FILE__);
$this->db->next_record();
if($this->db->f('account_id'))
@@ -361,7 +390,7 @@
if(strpos($target,'.'))
{
$location = explode('.', $target);
- $sql = "SELECT_ location_code FROM fm_location4
WHERE loc1= '{$location[0]}' AND loc4= '{$location[1]}'";
+ $sql = "SELECT location_code FROM fm_location4
WHERE loc1= '{$location[0]}' AND loc4= '{$location[1]}'";
}
else
{
@@ -376,25 +405,6 @@
}
- function check_building($loc1='',$loc2='')
- {
- $sql = "SELECT count(*) FROM fm_location2 WHERE loc1=
'$loc1' AND loc2= '$loc2'";
-
-//_debug_array($sql);
- $this->db->query($sql,__LINE__,__FILE__);
- $this->db->next_record();
- if($this->db->f(0))
- {
- return True;
- }
-
- if($this->bypass)
- {
- return True;
- }
-
- }
-
function create_loc1_dir($loc1='')
{
if(!$this->vfs->file_exists(array(
@@ -419,17 +429,14 @@
}
$this->vfs->override_acl = 0;
}
-
-// return $this->receipt;
}
function copy_files($values)
{
$to_file = $this->fakebase . SEP . 'document' . SEP .
$values['loc1'] . SEP . $values['file_name'];
- $from_file = $this->dir . SEP . $values['file_name'];
+ $from_file = $this->dir . SEP . $values['file_name'] .
$this->suffix;
$this->vfs->override_acl = 1;
-
//_debug_array($to_file);
if($this->vfs->file_exists(array(
'string' => $to_file,
@@ -450,19 +457,14 @@
}
else
{
- $address =
$this->get_address($values['loc1'],$values['loc2'],$values['loc3']);
+ if($ticket['street_name'])
+ {
+ $address =
$this->db->db_addslashes($values['street_name'] . ' ' .
$values['street_number']);
+ }
- switch($values['type'])
+ if(!$address)
{
- case 'plan':
- $values['title'] =
$this->db->db_addslashes($values['branch'] . ', ' .$values['type'] . ', etasje:
' . $values['etasje']);
- break;
- case 'snitt':
- $values['title'] =
$this->db->db_addslashes($values['branch'] . ', ' . $values['type'] . ' nr: ' .
$values['nr']);
- break;
- case 'fasade':
- $values['title'] =
$this->db->db_addslashes($values['branch'] . ', ' . $values['type'] . ' nr: ' .
$values['nr'] . ' retning: ' . $values['direction']);
- break;
+ $address =
$this->db->db_addslashes($values['location_name']);
}
$insert_values= array(
@@ -483,41 +485,24 @@
$values['loc1'],
$values['loc2'],
$values['loc3'],
+ $values['loc4'],
);
$insert_values =
$this->bocommon->validate_db_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,loc3) "
+ .
"location_code,address,branch_id,vendor_id,user_id,loc1,loc2,loc3,loc4) "
. "VALUES ($insert_values)";
$this->db->query($sql,__LINE__,__FILE__);
- unlink($from_file);
+ // unlink($from_file);
$this->receipt['message'][]=array('msg'=>lang('File %1
copied!',$values['file_name']));
$this->receipt['message'][]=array('msg'=>lang('File %1 deleted!',$from_file));
}
}
-
$this->vfs->override_acl = 0;
-// return $this->receipt;
- }
-
- function get_address($loc1='',$loc2='',$loc3='')
- {
- 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');
}
}
?>