[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] property/inc/custom/organize_drawing.php, 1.1.2.3
From: |
nomail |
Subject: |
[Phpgroupware-cvs] property/inc/custom/organize_drawing.php, 1.1.2.3 |
Date: |
Sat, 6 Nov 2004 23:09:34 +0100 |
Update of /property/inc/custom
Modified Files:
Branch: proposed-0_9_18-branch
organize_drawing.php
date: 2004/11/06 22:09:34; author: sigurdne; state: Exp; lines: +186 -4
Log Message:
no message
=====================================================================
Index: property/inc/custom/organize_drawing.php
diff -u property/inc/custom/organize_drawing.php:1.1.2.2
property/inc/custom/organize_drawing.php:1.1.2.3
--- property/inc/custom/organize_drawing.php:1.1.2.2 Fri Nov 5 20:42:16 2004
+++ property/inc/custom/organize_drawing.php Sat Nov 6 22:09:34 2004
@@ -5,7 +5,11 @@
function organize_drawing()
{
$this->currentapp =
$GLOBALS['phpgw_info']['flags']['currentapp'];
- $this->bocommon =
CreateObject($this->currentapp.'.bocommon');
+ $this->bocommon =
CreateObject($this->currentapp.'.bocommon');
+ $this->vfs =
CreateObject('phpgwapi.vfs');
+ $this->rootdir = $this->vfs->basedir;
+ $this->fakebase = $this->vfs->fakebase;
+ $this->db = $GLOBALS['phpgw']->db;
}
@@ -66,10 +70,188 @@
function execute()
{
- $debug = get_var('debug',array('POST','GET'));
- _debug_array($_GET);
- _debug_array($debug);
+ $file_list = $this->get_files();
+
+// _debug_array($file_list);
+
+ if (isSet($file_list) AND is_array($file_list))
+ {
+ foreach($file_list as $file_entry)
+ {
+ $loc1_list[$file_entry['loc1']] = True;
+ }
+
+ $loc1_list = array_keys($loc1_list);
+
+ for ($i=0;$i<count($loc1_list);$i++)
+ {
+ $this->create_loc1_dir($loc1_list[$i]);
+ }
+
+ for ($i=0;$i<count($file_list);$i++)
+ {
+ $this->copy_files($file_list[$i]);
+ }
+ }
+ }
+
+ function get_files()
+ {
+ $drawing_type=array(
+ 'p' => 'plan',
+ 'P' => 'plan',
+ 's' => 'snitt',
+ 'S' => 'snitt',
+ );
+
+ $drawing_branch=array(
+ 'a' => 'arkitekt',
+ 'A' => 'arkitekt',
+ );
+
+ $this->dir = 'C:\cygwin\var\www\phpw_files\Tegninger';
+ $dir_handle = @opendir($this->dir);
+
+ $i=0; $myfilearray = '';
+ while ($file = readdir($dir_handle))
+ {
+ if ((substr($file, 0, 1) != '.') &&
is_file($this->dir . SEP . $file) )
+ {
+ $myfilearray[$i] = $file;
+ $i++;
+ }
+ }
+ closedir($dir_handle);
+ sort($myfilearray);
+
+ for ($i=0;$i<count($myfilearray);$i++)
+ {
+ $fname = $myfilearray[$i];
+ $loc1 = substr($myfilearray[$i],4,4);
+ $loc2 = substr($myfilearray[$i],8,2);
+ $type =
$drawing_type[substr($myfilearray[$i],12,1)];
+
+ if ($type=='plan')
+ {
+ $etasje = substr($myfilearray[$i],13,2);
+ $loc3 = substr($myfilearray[$i],10,2);
+ $location_code = $loc1 . '-' . $loc2 .
'-' . $loc3;
+ }
+ else
+ {
+ unset($etasje);
+ unset($loc3);
+ $type =
$drawing_type[substr($myfilearray[$i],10,1)];
+ $location_code = $loc1 . '-' . $loc2;
+ }
+
+ $branch =
$drawing_branch[substr($myfilearray[$i],-5,1)];
+
+// if ($this->check_building($loc1,$loc2))
+ {
+ $file_list[] = array
+ (
+ 'file_name' => $fname,
+ 'loc1' => $loc1,
+ 'loc2' => $loc2,
+ 'loc3' => $loc3,
+ 'type' => $type,
+ 'etasje' => $etasje,
+ 'branch' => $branch,
+ 'location_code' =>
$location_code,
+ );
+ }
+ }
+
+ return $file_list;
+ }
+
+ 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;
+ }
+ return True;
+
+ }
+
+ function create_loc1_dir($loc1='')
+ {
+ if(!$this->vfs->file_exists(array(
+ 'string' => $this->fakebase . SEP .
'drawing' . SEP . $loc1,
+ 'relatives' => Array(RELATIVE_NONE)
+ )))
+ {
+ $this->vfs->override_acl = 1;
+
+ if(!$this->vfs->mkdir (array(
+ 'string' => $this->fakebase. SEP .
'drawing' . SEP . $loc1,
+ 'relatives' => array(
+ RELATIVE_NONE
+ )
+ )))
+ {
+
$receipt['error'][]=array('msg'=>lang('failed to create directory') . ' :'.
$this->fakebase. SEP . 'drawing' . SEP . $loc1);
+ }
+ else
+ {
+
$receipt['message'][]=array('msg'=>lang('directory created') . ' :'.
$this->fakebase. SEP . 'drawing' . SEP . $loc1);
+ }
+ $this->vfs->override_acl = 0;
+ }
+
+ return $receipt;
+ }
+
+ function copy_files($values)
+ {
+ $to_file = $this->fakebase . SEP . 'drawing' . SEP .
$values['loc1'] . SEP . $values['file_name'];
+ $from_file = $this->dir . SEP . $values['file_name'];
+ $this->vfs->override_acl = 1;
+
+//_debug_array($to_file);
+ if(!$this->vfs->cp (array (
+ 'from' => $from_file,
+ 'to' => $to_file,
+ 'relatives' => array
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
+ {
+ $receipt['error'][]=array('msg'=>lang('Failed
to copy file !') . $values['file_name']);
+ }
+ else
+ {
+ $this->db->query("INSERT INTO fm_drawing
(drawing_name,title,access,category,entry_date,drawing_date,version,coordinator,status,"
+ .
"descr,location_code,floor_id,address,branch_id,vendor_id,user_id $cols) "
+ . "VALUES ('"
+ . $values['file_name']. "','"
+ . $values['file_name']. "','"
+ . "public','"
+ . $values['cat_id']. "','"
+ . time() . "','"
+ . $values['values_date']. "','"
+ . $values['version']. "','"
+ . $values['coordinator']. "','"
+ . $values['status']. "','"
+ . $values['descr']. "','"
+ . $values['location_code']. "','"
+ . $values['floor_id'] . "','"
+ . $address . "','"
+ . $values['branch_id']. "','"
+ . $values['vendor_id']. "','"
+ . $this->account. "' $vals)",__LINE__,__FILE__);
+ }
+
+ $this->vfs->override_acl = 0;
+
+
+ return $receipt;
}
+
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] property/inc/custom/organize_drawing.php, 1.1.2.3,
nomail <=