phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] property/inc/custom cron.php lag_lang_filer.php...


From: Sigurd Nes
Subject: [Phpgroupware-cvs] property/inc/custom cron.php lag_lang_filer.php...
Date: Wed, 04 Jan 2006 08:01:12 +0000

CVSROOT:        /sources/phpgroupware
Module name:    property
Branch:         
Changes by:     Sigurd Nes <address@hidden>     06/01/04 08:01:12

Modified files:
        inc/custom     : cron.php lag_lang_filer.php 
                         oppdater_utgaatt_objekt.php 
                         organize_drawing.php 

Log message:
        

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/custom/cron.php.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/custom/lag_lang_filer.php.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/custom/oppdater_utgaatt_objekt.php.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/phpgroupware/property/inc/custom/organize_drawing.php.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: property/inc/custom/cron.php
diff -u property/inc/custom/cron.php:1.5 property/inc/custom/cron.php:1.6
--- property/inc/custom/cron.php:1.5    Thu May 12 21:26:27 2005
+++ property/inc/custom/cron.php        Wed Jan  4 08:01:12 2006
@@ -1,49 +1,49 @@
-#!/usr/bin/php -q
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 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 admin
-       * @version $Id: cron.php,v 1.5 2005/05/12 21:26:27 sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * example cron : /usr/local/bin/php -q 
/var/www/html/phpgroupware/property/inc/custom/cron.php default 
oppdater_namssakstatus_pr_leietaker
-        */
-
-       $path_to_phpgroupware = dirname(__FILE__) . '/../../..';        // need 
to be adapted if this script is moved somewhere else
-       $_GET['domain'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 
'default';
-
-
-       if(!$function = $_SERVER['argv'][2])
-
-       {
-               echo date('Y/m/d H:i:s ') . " Nothing to execute\n";
-               return;
-       }
-
-//     echo $function;
-
-       $GLOBALS['phpgw_info']['flags'] = array(
-               'currentapp' => 'login',
-               'noapi'      => True            // this stops header.inc.php to 
include phpgwapi/inc/function.inc.php
-       );
-       include($path_to_phpgroupware.'/header.inc.php');
-       unset($GLOBALS['phpgw_info']['flags']['noapi']);
-
-       $db_type = $GLOBALS['phpgw_domain'][$_GET['domain']]['db_type'];
-
-       $GLOBALS['phpgw_info']['server']['sessions_type'] = 'db';
-
-       include(PHPGW_API_INC.'/functions.inc.php');
-
-       $num = ExecMethod('property.custom_functions.index',array('function' => 
$function,'enabled'=>1));
-       // echo date('Y/m/d H:i:s ').$_GET['domain'].': '.($num ? "$num job(s) 
executed" : 'Nothing to execute')."\n";
-
-       $GLOBALS['phpgw']->common->phpgw_exit();
+#!/usr/bin/php -q
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 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 admin
+       * @version $Id: cron.php,v 1.6 2006/01/04 08:01:12 sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * example cron : /usr/local/bin/php -q 
/var/www/html/phpgroupware/property/inc/custom/cron.php default 
oppdater_namssakstatus_pr_leietaker
+        */
+
+       $path_to_phpgroupware = dirname(__FILE__) . '/../../..';        // need 
to be adapted if this script is moved somewhere else
+       $_GET['domain'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : 
'default';
+
+
+       if(!$function = $_SERVER['argv'][2])
+
+       {
+               echo date('Y/m/d H:i:s ') . " Nothing to execute\n";
+               return;
+       }
+
+//     echo $function;
+
+       $GLOBALS['phpgw_info']['flags'] = array(
+               'currentapp' => 'login',
+               'noapi'      => True            // this stops header.inc.php to 
include phpgwapi/inc/function.inc.php
+       );
+       include($path_to_phpgroupware.'/header.inc.php');
+       unset($GLOBALS['phpgw_info']['flags']['noapi']);
+
+       $db_type = $GLOBALS['phpgw_domain'][$_GET['domain']]['db_type'];
+
+       $GLOBALS['phpgw_info']['server']['sessions_type'] = 'db';
+
+       include(PHPGW_API_INC.'/functions.inc.php');
+
+       $num = ExecMethod('property.custom_functions.index',array('function' => 
$function,'enabled'=>1));
+       // echo date('Y/m/d H:i:s ').$_GET['domain'].': '.($num ? "$num job(s) 
executed" : 'Nothing to execute')."\n";
+
+       $GLOBALS['phpgw']->common->phpgw_exit();
Index: property/inc/custom/lag_lang_filer.php
diff -u property/inc/custom/lag_lang_filer.php:1.3 
property/inc/custom/lag_lang_filer.php:1.4
--- property/inc/custom/lag_lang_filer.php:1.3  Thu May 12 21:26:27 2005
+++ property/inc/custom/lag_lang_filer.php      Wed Jan  4 08:01:12 2006
@@ -1,134 +1,134 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 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: lag_lang_filer.php,v 1.3 2005/05/12 21:26:27 sigurdne 
Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class lag_lang_filer
-       {
-               var     $function_name = 'lag_lang_filer';
-
-               function lag_lang_filer()
-               {
-                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->bocommon                 = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->db                               = 
$GLOBALS['phpgw']->db;
-               }
-
-               function pre_run($data='')
-               {
-                       if($data['enabled']==1)
-                       {
-                               $confirm        = True;
-                               $cron           = True;
-                       }
-                       else
-                       {
-                               $confirm        = 
get_var('confirm',array('POST'));
-                               $execute        = 
get_var('execute',array('GET'));
-                       }
-
-                       if ($confirm)
-                       {
-                               $this->execute($cron);
-                       }
-                       else
-                       {
-                               $this->confirm($execute=False);
-                       }
-               }
-
-
-               function confirm($execute='')
-               {
-                       $link_data = array
-                       (
-                               'menuaction' => 
$this->currentapp.'.custom_functions.index',
-                               'function'      =>$this->function_name,
-                               'execute'       => $execute,
-                       );
-
-
-                       if(!$execute)
-                       {
-                               $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('/admin/index.php'),
-                               'run_action'                    => 
$GLOBALS['phpgw']->link('/index.php',$link_data),
-                               'message'                               => 
$this->receipt['message'],
-                               'lang_confirm_msg'              => 
$lang_confirm_msg,
-                               'lang_yes'                              => 
$lang_yes,
-                               'lang_yes_statustext'   => 'lag_lang_filer fra 
database',
-                               'lang_no_statustext'    => 'tilbake',
-                               'lang_no'                               => 
lang('no'),
-                               'lang_done'                             => 
'Avbryt',
-                               'lang_done_statustext'  => 'tilbake'
-                       );
-
-                       $appname                = lang('location');
-                       $function_msg   = 'lag_lang_filer';
-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang($this->currentapp) . ' - ' . $appname . ': ' . $function_msg;
-                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('confirm' => $data));
-                       $GLOBALS['phpgw']->xslttpl->pp();
-               }
-
-               function execute($cron='')
-               {
-
-                       $sql = "SELECT * from phpgw_lang WHERE app_name = 
'property' AND lang='no' ORDER BY message_id ASC";
-
-                       $this->db->query($sql,__LINE__,__FILE__);
-
-                       $i=0;
-                       while ($this->db->next_record())
-                       {
-                                       $str.=$this->db->f('message_id') ."\t";
-                                       $str.=$this->db->f('app_name') ."\t";
-                                       $str.=$this->db->f('lang') ."\t";
-                                       $str.=$this->db->f('content') ."\n";
-                                       $i++;
-                       }
-
-_debug_array($str);
-/*                        $filename= 'phpgw_no_lang';
-
-                               $size=strlen($str);
-
-                               $browser = CreateObject('phpgwapi.browser');
-                               
$browser->content_header($filename,'application/txt',$size);
-
-                               echo $str;
-*/
-
-                       $this->receipt['message'][]=array('msg'=> $i . ' 
tekster lagt til');
-
-                       if(!$cron)
-                       {
-                               $this->confirm($execute=False);
-                       }
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 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: lag_lang_filer.php,v 1.4 2006/01/04 08:01:12 sigurdne 
Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class lag_lang_filer
+       {
+               var     $function_name = 'lag_lang_filer';
+
+               function lag_lang_filer()
+               {
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->bocommon                 = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->db                               = 
$GLOBALS['phpgw']->db;
+               }
+
+               function pre_run($data='')
+               {
+                       if($data['enabled']==1)
+                       {
+                               $confirm        = True;
+                               $cron           = True;
+                       }
+                       else
+                       {
+                               $confirm        = 
get_var('confirm',array('POST'));
+                               $execute        = 
get_var('execute',array('GET'));
+                       }
+
+                       if ($confirm)
+                       {
+                               $this->execute($cron);
+                       }
+                       else
+                       {
+                               $this->confirm($execute=False);
+                       }
+               }
+
+
+               function confirm($execute='')
+               {
+                       $link_data = array
+                       (
+                               'menuaction' => 
$this->currentapp.'.custom_functions.index',
+                               'function'      =>$this->function_name,
+                               'execute'       => $execute,
+                       );
+
+
+                       if(!$execute)
+                       {
+                               $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('/admin/index.php'),
+                               'run_action'                    => 
$GLOBALS['phpgw']->link('/index.php',$link_data),
+                               'message'                               => 
$this->receipt['message'],
+                               'lang_confirm_msg'              => 
$lang_confirm_msg,
+                               'lang_yes'                              => 
$lang_yes,
+                               'lang_yes_statustext'   => 'lag_lang_filer fra 
database',
+                               'lang_no_statustext'    => 'tilbake',
+                               'lang_no'                               => 
lang('no'),
+                               'lang_done'                             => 
'Avbryt',
+                               'lang_done_statustext'  => 'tilbake'
+                       );
+
+                       $appname                = lang('location');
+                       $function_msg   = 'lag_lang_filer';
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang($this->currentapp) . ' - ' . $appname . ': ' . $function_msg;
+                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('confirm' => $data));
+                       $GLOBALS['phpgw']->xslttpl->pp();
+               }
+
+               function execute($cron='')
+               {
+
+                       $sql = "SELECT * from phpgw_lang WHERE app_name = 
'property' AND lang='no' ORDER BY message_id ASC";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+
+                       $i=0;
+                       while ($this->db->next_record())
+                       {
+                                       $str.=$this->db->f('message_id') ."\t";
+                                       $str.=$this->db->f('app_name') ."\t";
+                                       $str.=$this->db->f('lang') ."\t";
+                                       $str.=$this->db->f('content') ."\n";
+                                       $i++;
+                       }
+
+_debug_array($str);
+/*                        $filename= 'phpgw_no_lang';
+
+                               $size=strlen($str);
+
+                               $browser = CreateObject('phpgwapi.browser');
+                               
$browser->content_header($filename,'application/txt',$size);
+
+                               echo $str;
+*/
+
+                       $this->receipt['message'][]=array('msg'=> $i . ' 
tekster lagt til');
+
+                       if(!$cron)
+                       {
+                               $this->confirm($execute=False);
+                       }
+               }
+       }
+?>
Index: property/inc/custom/oppdater_utgaatt_objekt.php
diff -u property/inc/custom/oppdater_utgaatt_objekt.php:1.6 
property/inc/custom/oppdater_utgaatt_objekt.php:1.7
--- property/inc/custom/oppdater_utgaatt_objekt.php:1.6 Wed May 25 07:49:20 2005
+++ property/inc/custom/oppdater_utgaatt_objekt.php     Wed Jan  4 08:01:12 2006
@@ -1,225 +1,225 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 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: oppdater_utgaatt_objekt.php,v 1.6 2005/05/25 07:49:20 
sigurdne Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class oppdater_utgaatt_objekt
-       {
-               var     $function_name = 'oppdater_utgaatt_objekt';
-
-               function oppdater_utgaatt_objekt()
-               {
-                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $this->bocommon                 = 
CreateObject($this->currentapp.'.bocommon');
-                       $this->db                               = 
$GLOBALS['phpgw']->db;
-                       $this->db2                              = $this->db;
-                       $this->soadmin_location = 
CreateObject($this->currentapp.'.soadmin_location');
-
-                       $this->join                             = 
$this->bocommon->join;
-                       $this->left_join                = 
$this->bocommon->left_join;
-               }
-
-               function pre_run($data='')
-               {
-                       if($data['enabled']==1)
-                       {
-                               $confirm        = True;
-                               $cron           = True;
-                       }
-                       else
-                       {
-                               $confirm        = 
get_var('confirm',array('POST'));
-                               $execute        = 
get_var('execute',array('GET'));
-                       }
-
-                       if ($confirm)
-                       {
-                               $this->execute($cron);
-                       }
-                       else
-                       {
-                               $this->confirm($execute=False);
-                       }
-               }
-
-
-               function confirm($execute='')
-               {
-                       $link_data = array
-                       (
-                               'menuaction' => 
$this->currentapp.'.custom_functions.index',
-                               'function'      =>$this->function_name,
-                               'execute'       => $execute,
-                       );
-
-
-                       if(!$execute)
-                       {
-                               $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('/admin/index.php'),
-                               'run_action'                    => 
$GLOBALS['phpgw']->link('/index.php',$link_data),
-                               'message'                               => 
$this->receipt['message'],
-                               'lang_confirm_msg'              => 
$lang_confirm_msg,
-                               'lang_yes'                              => 
$lang_yes,
-                               'lang_yes_statustext'   => lang('Update the 
category to not active based on if there is only nonactive apartments'),
-                               'lang_no_statustext'    => 'tilbake',
-                               'lang_no'                               => 
lang('no'),
-                               'lang_done'                             => 
'Avbryt',
-                               'lang_done_statustext'  => 'tilbake'
-                       );
-
-                       $appname                = lang('location');
-                       $function_msg   = lang('Update the not active category 
for locations');
-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang($this->currentapp) . ' - ' . $appname . ': ' . $function_msg;
-                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('confirm' => $data));
-                       $GLOBALS['phpgw']->xslttpl->pp();
-               }
-
-               function execute($cron='')
-               {
-                       $location_types = 
$this->soadmin_location->select_location_type();
-
-                       $m= count($location_types);
-
-
-                       $this->db->query("UPDATE fm_location" . $m. " set       
status= 2  WHERE category=99",__LINE__,__FILE__);
-
-                       for ($type_id=$m; $type_id>1; $type_id--)
-                       {
-                               $parent_table = 'fm_location' . ($type_id-1);
-
-                               $joinmethod .= " $this->join $parent_table";
-
-                               $paranthesis .='(';
-
-                               $on = 'ON';
-                               for ($i=($type_id-1); $i>0; $i--)
-                               {
-                                       $joinmethod .= " $on (fm_location" . 
($type_id) .".loc" . ($i). ' = '.$parent_table . ".loc" . ($i) . ")";
-                                       $on = 'AND';
-                                       if($i==1)
-                                       {
-                                               $joinmethod .= ")";
-                                       }
-                               }
-
-                               $sql = "SELECT $parent_table.location_code 
,count(*) as count_99  FROM $paranthesis fm_location$type_id $joinmethod where 
fm_location$type_id.status=2 group by $parent_table.location_code ";
-                               $this->db->query($sql,__LINE__,__FILE__);
-
-                               while ($this->db->next_record())
-                               {
-                                       
$outdated[$this->db->f('location_code')]['count_99']=$this->db->f('count_99');
-                               }
-
-                               $sql = "SELECT $parent_table.location_code 
,count(*) as count_all  FROM $paranthesis fm_location$type_id $joinmethod group 
by $parent_table.location_code ";
-                               $this->db->query($sql,__LINE__,__FILE__);
-                               while ($this->db->next_record())
-                               {
-                                       if( 
$outdated[$this->db->f('location_code')]['count_99']==$this->db->f('count_all'))
-                                       {
-                                               $update[]=array('location_code' 
=> $this->db->f('location_code'));
-                                       }
-                               }
-
-                               $metadata = 
$this->db->metadata('fm_location'.($type_id-1));
-                               $j=0;
-                               for ($i=0; $i<count($update); $i++)
-                               {
-                                       $this->db->transaction_begin();
-
-                                       $sql = "SELECT category FROM 
$parent_table WHERE location_code= '" . $update[$i]['location_code'] ."'";
-
-                                       
$this->db->query($sql,__LINE__,__FILE__);
-                                       $this->db->next_record();
-
-                                       if($this->db->f('category')!=99)
-                                       {
-                                               $sql = "SELECT * from 
$parent_table WHERE location_code ='" . $update[$i]['location_code'] . "'";
-                                               
$this->db->query($sql,__LINE__,__FILE__);
-                                               $this->db->next_record();
-
-                                               for ($k=0; $k<count($metadata); 
$k++)
-                                               {
-                                                       $cols[] = 
$metadata[$k]['name'];
-                                                       $vals[] = 
$this->db->f($metadata[$k]['name']);
-                                               }
-
-                                               $cols[] = 'exp_date';
-                                               $vals[] = 
date($this->bocommon->datetimeformat,time());
-
-                                               $cols   =implode(",", $cols);
-                                               $vals = 
$this->bocommon->validate_db_insert($vals);
-
-                                               $sql = "INSERT INTO 
fm_location" . ($type_id-1) ."_history ($cols) VALUES ($vals)";
-                                               
$this->db->query($sql,__LINE__,__FILE__);
-                                               unset($cols);
-                                               unset($vals);
-
-                                               $j++;
-                                               $this->db->query("UPDATE 
fm_location" . ($type_id-1). " set     status= 2, category=99, change_type=2  
WHERE location_code= '" . $update[$i]['location_code'] ."'",__LINE__,__FILE__);
-                                               if($type_id == 2)
-                                               {
-                                                       
$this->db->query("UPDATE fm_location1 set kostra_id = NULL  WHERE 
location_code= '" . $update[$i]['location_code'] ."'",__LINE__,__FILE__);
-                                               }
-                                       }
-                               }
-
-                               
$this->receipt['message'][]=array('msg'=>lang('%1 location %2 has been updated 
to not active of %3 already not 
active',$j,$location_types[($type_id-2)]['descr'],count($update)));
-
-                               $log_msg .= lang('%1 location %2 has been 
updated to not active of %3 already not 
active',$j,$location_types[($type_id-2)]['descr'],count($update));
-                               unset($outdated);
-                               unset($update);
-                               unset($joinmethod);
-                               unset($paranthesis);
-                               unset($metadata);
-                               $this->db->transaction_commit();
-                       }
-
-
-                       if(!$cron)
-                       {
-                               $this->confirm($execute=False);
-                       }
-
-                       $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->bocommon->validate_db_insert($insert_values);
-
-                       $sql = "INSERT INTO fm_cron_log 
(cron,cron_date,process,message) "
-                                       . "VALUES ($insert_values)";
-                       $this->db->query($sql,__LINE__,__FILE__);
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 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: oppdater_utgaatt_objekt.php,v 1.7 2006/01/04 08:01:12 
sigurdne Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class oppdater_utgaatt_objekt
+       {
+               var     $function_name = 'oppdater_utgaatt_objekt';
+
+               function oppdater_utgaatt_objekt()
+               {
+                       $this->currentapp               = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $this->bocommon                 = 
CreateObject($this->currentapp.'.bocommon');
+                       $this->db                               = 
$GLOBALS['phpgw']->db;
+                       $this->db2                              = $this->db;
+                       $this->soadmin_location = 
CreateObject($this->currentapp.'.soadmin_location');
+
+                       $this->join                             = 
$this->bocommon->join;
+                       $this->left_join                = 
$this->bocommon->left_join;
+               }
+
+               function pre_run($data='')
+               {
+                       if($data['enabled']==1)
+                       {
+                               $confirm        = True;
+                               $cron           = True;
+                       }
+                       else
+                       {
+                               $confirm        = 
get_var('confirm',array('POST'));
+                               $execute        = 
get_var('execute',array('GET'));
+                       }
+
+                       if ($confirm)
+                       {
+                               $this->execute($cron);
+                       }
+                       else
+                       {
+                               $this->confirm($execute=False);
+                       }
+               }
+
+
+               function confirm($execute='')
+               {
+                       $link_data = array
+                       (
+                               'menuaction' => 
$this->currentapp.'.custom_functions.index',
+                               'function'      =>$this->function_name,
+                               'execute'       => $execute,
+                       );
+
+
+                       if(!$execute)
+                       {
+                               $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('/admin/index.php'),
+                               'run_action'                    => 
$GLOBALS['phpgw']->link('/index.php',$link_data),
+                               'message'                               => 
$this->receipt['message'],
+                               'lang_confirm_msg'              => 
$lang_confirm_msg,
+                               'lang_yes'                              => 
$lang_yes,
+                               'lang_yes_statustext'   => lang('Update the 
category to not active based on if there is only nonactive apartments'),
+                               'lang_no_statustext'    => 'tilbake',
+                               'lang_no'                               => 
lang('no'),
+                               'lang_done'                             => 
'Avbryt',
+                               'lang_done_statustext'  => 'tilbake'
+                       );
+
+                       $appname                = lang('location');
+                       $function_msg   = lang('Update the not active category 
for locations');
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang($this->currentapp) . ' - ' . $appname . ': ' . $function_msg;
+                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('confirm' => $data));
+                       $GLOBALS['phpgw']->xslttpl->pp();
+               }
+
+               function execute($cron='')
+               {
+                       $location_types = 
$this->soadmin_location->select_location_type();
+
+                       $m= count($location_types);
+
+
+                       $this->db->query("UPDATE fm_location" . $m. " set       
status= 2  WHERE category=99",__LINE__,__FILE__);
+
+                       for ($type_id=$m; $type_id>1; $type_id--)
+                       {
+                               $parent_table = 'fm_location' . ($type_id-1);
+
+                               $joinmethod .= " $this->join $parent_table";
+
+                               $paranthesis .='(';
+
+                               $on = 'ON';
+                               for ($i=($type_id-1); $i>0; $i--)
+                               {
+                                       $joinmethod .= " $on (fm_location" . 
($type_id) .".loc" . ($i). ' = '.$parent_table . ".loc" . ($i) . ")";
+                                       $on = 'AND';
+                                       if($i==1)
+                                       {
+                                               $joinmethod .= ")";
+                                       }
+                               }
+
+                               $sql = "SELECT $parent_table.location_code 
,count(*) as count_99  FROM $paranthesis fm_location$type_id $joinmethod where 
fm_location$type_id.status=2 group by $parent_table.location_code ";
+                               $this->db->query($sql,__LINE__,__FILE__);
+
+                               while ($this->db->next_record())
+                               {
+                                       
$outdated[$this->db->f('location_code')]['count_99']=$this->db->f('count_99');
+                               }
+
+                               $sql = "SELECT $parent_table.location_code 
,count(*) as count_all  FROM $paranthesis fm_location$type_id $joinmethod group 
by $parent_table.location_code ";
+                               $this->db->query($sql,__LINE__,__FILE__);
+                               while ($this->db->next_record())
+                               {
+                                       if( 
$outdated[$this->db->f('location_code')]['count_99']==$this->db->f('count_all'))
+                                       {
+                                               $update[]=array('location_code' 
=> $this->db->f('location_code'));
+                                       }
+                               }
+
+                               $metadata = 
$this->db->metadata('fm_location'.($type_id-1));
+                               $j=0;
+                               for ($i=0; $i<count($update); $i++)
+                               {
+                                       $this->db->transaction_begin();
+
+                                       $sql = "SELECT category FROM 
$parent_table WHERE location_code= '" . $update[$i]['location_code'] ."'";
+
+                                       
$this->db->query($sql,__LINE__,__FILE__);
+                                       $this->db->next_record();
+
+                                       if($this->db->f('category')!=99)
+                                       {
+                                               $sql = "SELECT * from 
$parent_table WHERE location_code ='" . $update[$i]['location_code'] . "'";
+                                               
$this->db->query($sql,__LINE__,__FILE__);
+                                               $this->db->next_record();
+
+                                               for ($k=0; $k<count($metadata); 
$k++)
+                                               {
+                                                       $cols[] = 
$metadata[$k]['name'];
+                                                       $vals[] = 
$this->db->f($metadata[$k]['name']);
+                                               }
+
+                                               $cols[] = 'exp_date';
+                                               $vals[] = 
date($this->bocommon->datetimeformat,time());
+
+                                               $cols   =implode(",", $cols);
+                                               $vals = 
$this->bocommon->validate_db_insert($vals);
+
+                                               $sql = "INSERT INTO 
fm_location" . ($type_id-1) ."_history ($cols) VALUES ($vals)";
+                                               
$this->db->query($sql,__LINE__,__FILE__);
+                                               unset($cols);
+                                               unset($vals);
+
+                                               $j++;
+                                               $this->db->query("UPDATE 
fm_location" . ($type_id-1). " set     status= 2, category=99, change_type=2  
WHERE location_code= '" . $update[$i]['location_code'] ."'",__LINE__,__FILE__);
+                                               if($type_id == 2)
+                                               {
+                                                       
$this->db->query("UPDATE fm_location1 set kostra_id = NULL  WHERE 
location_code= '" . $update[$i]['location_code'] ."'",__LINE__,__FILE__);
+                                               }
+                                       }
+                               }
+
+                               
$this->receipt['message'][]=array('msg'=>lang('%1 location %2 has been updated 
to not active of %3 already not 
active',$j,$location_types[($type_id-2)]['descr'],count($update)));
+
+                               $log_msg .= lang('%1 location %2 has been 
updated to not active of %3 already not 
active',$j,$location_types[($type_id-2)]['descr'],count($update));
+                               unset($outdated);
+                               unset($update);
+                               unset($joinmethod);
+                               unset($paranthesis);
+                               unset($metadata);
+                               $this->db->transaction_commit();
+                       }
+
+
+                       if(!$cron)
+                       {
+                               $this->confirm($execute=False);
+                       }
+
+                       $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->bocommon->validate_db_insert($insert_values);
+
+                       $sql = "INSERT INTO fm_cron_log 
(cron,cron_date,process,message) "
+                                       . "VALUES ($insert_values)";
+                       $this->db->query($sql,__LINE__,__FILE__);
+               }
+       }
+?>
Index: property/inc/custom/organize_drawing.php
diff -u property/inc/custom/organize_drawing.php:1.4 
property/inc/custom/organize_drawing.php:1.5
--- property/inc/custom/organize_drawing.php:1.4        Thu May 12 21:26:27 2005
+++ property/inc/custom/organize_drawing.php    Wed Jan  4 08:01:12 2006
@@ -1,440 +1,440 @@
-<?php
-       /**
-       * phpGroupWare - property: a Facilities Management System.
-       *
-       * @author Sigurd Nes <address@hidden>
-       * @copyright Copyright (C) 2003-2005 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: organize_drawing.php,v 1.4 2005/05/12 21:26:27 sigurdne 
Exp $
-       */
-
-       /**
-        * Description
-        * @package property
-        */
-
-       class organize_drawing
-       {
-               /* In Admin->Property->Async servises:
-               *  Name: property.custom_functions.index
-               *  Data: function=organize_drawing,dir=C:/path/to/drawings
-               */
-
-               var     $dir = '/mnt/filer2/Tegninger';
-               var     $suffix = 'dwg';
-               var $bypass = False; // bypass location check (only for 
debugging)
-               var     $function_name = 'organize_drawing';
-
-               function organize_drawing()
-               {
-                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
-                       $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;
-
-               }
-
-               function pre_run($data='')
-               {
-
-                       if($data['enabled']==1)
-                       {
-                               $confirm                = True;
-                               $execute                = True;
-                               $cron                   = True;
-                               if($data['suffix'])
-                               {
-                                       $this->suffix = $data['suffix'];
-                               }
-                               if($data['dir'])
-                               {
-                                       $this->dir = $data['dir'];
-                               }
-                       }
-                       else
-                       {
-                               $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
-                       (
-                               'menuaction' => 
$this->currentapp.'.custom_functions.index',
-                               'function'      => $this->function_name,
-                               'execute'       => $execute,
-                               'dir'           => $this->dir,
-                               'suffix'        => $this->suffix,
-                       );
-
-                       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('/admin/index.php'),
-                               'run_action'                    => 
$GLOBALS['phpgw']->link('/index.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($this->currentapp) . ' - ' . $appname . ': ' . $function_msg;
-                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('confirm' => $data));
-                       $GLOBALS['phpgw']->xslttpl->pp();
-               }
-
-               function execute($dry_run='',$cron='')
-               {
-
-                       $file_list = $this->get_files();
-
-                       if($dry_run)
-                       {
-                               $this->confirm($execute=True);
-                               _debug_array($file_list);
-                       }
-                       else
-                       {
-                               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]);
-                                       }
-                               }
-                               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->bocommon->validate_db_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()
-               {
-                       $drawing_branch=array(
-                       'a' => 'arkitekt'
-                       );
-
-                       $category=array(
-                       'plan' => 2,
-                       'snitt' => 3,
-                       'fasade' => 4
-                       );
-
-                       $branch_id_array=array(
-                       'arkitekt' => 13
-                       );
-
-                       $dir_handle = @opendir($this->dir);
-
-                       $i=0; $myfilearray = '';
-                       while ($file = @readdir($dir_handle))
-                       {
-                               if ((strtolower(substr($file, -3, 3)) == 
$this->suffix) && 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);
-                               $etasje = '';
-                               $loc3 = '';
-                               $nr = '';
-                               $direction = '';
-
-                               $type = $this->get_type($myfilearray[$i]);
-                               switch($type)
-                               {
-                                       case 'plan':
-                                               $etasje = 
substr($myfilearray[$i],13,2);
-                                               $loc3 = 
substr($myfilearray[$i],10,2);
-                                               $location_code = $loc1 . '-' . 
$loc2 . '-' . $loc3;
-                                               break;
-                                       case 'snitt':
-                                               $location_code = $loc1 . '-' . 
$loc2;
-                                               $nr = 
substr($myfilearray[$i],-8,3);
-                                               break;
-                                       case 'fasade':
-                                               $location_code = $loc1 . '-' . 
$loc2;
-                                               $direction = 
substr($myfilearray[$i],11,2);
-                                               $nr = 
substr($myfilearray[$i],-8,3);
-                                               break;
-                               }
-
-
-                               $branch = 
$drawing_branch[strtolower(substr($myfilearray[$i],-5,1))];
-
-                               if ($this->check_building($loc1,$loc2) && $type 
&& $branch)
-                               {
-                                       $file_list[] = array
-                                       (
-                                               'file_name'     => $fname,
-                                               'loc1'          => $loc1,
-                                               'loc2'          => $loc2,
-                                               'loc3'          => $loc3,
-                                               'type'          => $type,
-                                               'nr'            => $nr,
-                                               'etasje'        => $etasje,
-                                               'branch'        => $branch,
-                                               'branch_id' => 
$branch_id_array[$branch],
-                                               'category_id'   => 
$category[$type],
-                                               'direction'     => $direction,
-                                               'location_code' => 
$location_code,
-                                       );
-                               }
-                       }
-
-                       return $file_list;
-               }
-
-
-               function get_type($filename='')
-               {
-                       $drawing_type=array(
-                       'p' => 'plan',
-                       'f' => 'fasade',
-                       's' => 'snitt'
-                       );
-
-                       for ($i=10;$i<strlen($filename);$i++)
-                       {
-                               $type = 
$drawing_type[strtolower(substr($filename,$i,1))];
-                               if($type)
-                               {
-                                       return $type;
-                               }
-                       }
-               }
-
-               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(
-                                       'string' => $this->fakebase . SEP . 
'document' . SEP . $loc1,
-                                       'relatives' => Array(RELATIVE_NONE)
-                               )))
-                       {
-                               $this->vfs->override_acl = 1;
-
-                               if(!$this->vfs->mkdir (array(
-                                    'string' => $this->fakebase. SEP . 
'document' . SEP . $loc1,
-                                    'relatives' => array(
-                                         RELATIVE_NONE
-                                    )
-                               )))
-                               {
-                                       
$this->receipt['error'][]=array('msg'=>lang('failed to create directory') . ' 
:'. $this->fakebase. SEP . 'document' . SEP . $loc1);
-                               }
-                               else
-                               {
-                                       
$this->receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document' . SEP . $loc1);
-                               }
-                               $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'];
-                       $this->vfs->override_acl = 1;
-
-
-//_debug_array($to_file);
-                       if($this->vfs->file_exists(array(
-                                       'string' => $to_file,
-                                       'relatives' => Array(RELATIVE_NONE)
-                               )))
-                       {
-                               
$this->receipt['error'][]=array('msg'=>lang('File %1 already 
exists!',$values['file_name']));
-                       }
-                       else
-                       {
-
-                               if(!$this->vfs->cp (array (
-                                       'from'  => $from_file,
-                                       'to'    => $to_file,
-                                       'relatives'     => array 
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
-                               {
-                                       
$this->receipt['error'][]=array('msg'=>lang('Failed to copy file !') . 
$values['file_name']);
-                               }
-                               else
-                               {
-                                       $address = 
$this->get_address($values['loc1'],$values['loc2'],$values['loc3']);
-
-                                       switch($values['type'])
-                                       {
-                                               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;
-                                       }
-
-                                       $insert_values= array(
-                                               $values['file_name'],
-                                               $values['title'],
-                                               'public',
-                                               $values['category_id'],
-                                               time(),
-                                               $values['values_date'],
-                                               $values['version'],
-                                               $values['coordinator'],
-                                               $values['status'],
-                                               $values['location_code'],
-                                               $address,
-                                               $values['branch_id'],
-                                               $values['vendor_id'],
-                                               $this->account,
-                                               $values['loc1'],
-                                               $values['loc2'],
-                                               $values['loc3'],
-                                               );
-
-                                       $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) "
-                                               . "VALUES ($insert_values)";
-
-                                       
$this->db->query($sql,__LINE__,__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');
-               }
-       }
-?>
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003-2005 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: organize_drawing.php,v 1.5 2006/01/04 08:01:12 sigurdne 
Exp $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class organize_drawing
+       {
+               /* In Admin->Property->Async servises:
+               *  Name: property.custom_functions.index
+               *  Data: function=organize_drawing,dir=C:/path/to/drawings
+               */
+
+               var     $dir = '/mnt/filer2/Tegninger';
+               var     $suffix = 'dwg';
+               var $bypass = False; // bypass location check (only for 
debugging)
+               var     $function_name = 'organize_drawing';
+
+               function organize_drawing()
+               {
+                       $this->currentapp       = 
$GLOBALS['phpgw_info']['flags']['currentapp'];
+                       $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;
+
+               }
+
+               function pre_run($data='')
+               {
+
+                       if($data['enabled']==1)
+                       {
+                               $confirm                = True;
+                               $execute                = True;
+                               $cron                   = True;
+                               if($data['suffix'])
+                               {
+                                       $this->suffix = $data['suffix'];
+                               }
+                               if($data['dir'])
+                               {
+                                       $this->dir = $data['dir'];
+                               }
+                       }
+                       else
+                       {
+                               $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
+                       (
+                               'menuaction' => 
$this->currentapp.'.custom_functions.index',
+                               'function'      => $this->function_name,
+                               'execute'       => $execute,
+                               'dir'           => $this->dir,
+                               'suffix'        => $this->suffix,
+                       );
+
+                       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('/admin/index.php'),
+                               'run_action'                    => 
$GLOBALS['phpgw']->link('/index.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($this->currentapp) . ' - ' . $appname . ': ' . $function_msg;
+                       
$GLOBALS['phpgw']->xslttpl->set_var('phpgw',array('confirm' => $data));
+                       $GLOBALS['phpgw']->xslttpl->pp();
+               }
+
+               function execute($dry_run='',$cron='')
+               {
+
+                       $file_list = $this->get_files();
+
+                       if($dry_run)
+                       {
+                               $this->confirm($execute=True);
+                               _debug_array($file_list);
+                       }
+                       else
+                       {
+                               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]);
+                                       }
+                               }
+                               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->bocommon->validate_db_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()
+               {
+                       $drawing_branch=array(
+                       'a' => 'arkitekt'
+                       );
+
+                       $category=array(
+                       'plan' => 2,
+                       'snitt' => 3,
+                       'fasade' => 4
+                       );
+
+                       $branch_id_array=array(
+                       'arkitekt' => 13
+                       );
+
+                       $dir_handle = @opendir($this->dir);
+
+                       $i=0; $myfilearray = '';
+                       while ($file = @readdir($dir_handle))
+                       {
+                               if ((strtolower(substr($file, -3, 3)) == 
$this->suffix) && 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);
+                               $etasje = '';
+                               $loc3 = '';
+                               $nr = '';
+                               $direction = '';
+
+                               $type = $this->get_type($myfilearray[$i]);
+                               switch($type)
+                               {
+                                       case 'plan':
+                                               $etasje = 
substr($myfilearray[$i],13,2);
+                                               $loc3 = 
substr($myfilearray[$i],10,2);
+                                               $location_code = $loc1 . '-' . 
$loc2 . '-' . $loc3;
+                                               break;
+                                       case 'snitt':
+                                               $location_code = $loc1 . '-' . 
$loc2;
+                                               $nr = 
substr($myfilearray[$i],-8,3);
+                                               break;
+                                       case 'fasade':
+                                               $location_code = $loc1 . '-' . 
$loc2;
+                                               $direction = 
substr($myfilearray[$i],11,2);
+                                               $nr = 
substr($myfilearray[$i],-8,3);
+                                               break;
+                               }
+
+
+                               $branch = 
$drawing_branch[strtolower(substr($myfilearray[$i],-5,1))];
+
+                               if ($this->check_building($loc1,$loc2) && $type 
&& $branch)
+                               {
+                                       $file_list[] = array
+                                       (
+                                               'file_name'     => $fname,
+                                               'loc1'          => $loc1,
+                                               'loc2'          => $loc2,
+                                               'loc3'          => $loc3,
+                                               'type'          => $type,
+                                               'nr'            => $nr,
+                                               'etasje'        => $etasje,
+                                               'branch'        => $branch,
+                                               'branch_id' => 
$branch_id_array[$branch],
+                                               'category_id'   => 
$category[$type],
+                                               'direction'     => $direction,
+                                               'location_code' => 
$location_code,
+                                       );
+                               }
+                       }
+
+                       return $file_list;
+               }
+
+
+               function get_type($filename='')
+               {
+                       $drawing_type=array(
+                       'p' => 'plan',
+                       'f' => 'fasade',
+                       's' => 'snitt'
+                       );
+
+                       for ($i=10;$i<strlen($filename);$i++)
+                       {
+                               $type = 
$drawing_type[strtolower(substr($filename,$i,1))];
+                               if($type)
+                               {
+                                       return $type;
+                               }
+                       }
+               }
+
+               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(
+                                       'string' => $this->fakebase . SEP . 
'document' . SEP . $loc1,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               $this->vfs->override_acl = 1;
+
+                               if(!$this->vfs->mkdir (array(
+                                    'string' => $this->fakebase. SEP . 
'document' . SEP . $loc1,
+                                    'relatives' => array(
+                                         RELATIVE_NONE
+                                    )
+                               )))
+                               {
+                                       
$this->receipt['error'][]=array('msg'=>lang('failed to create directory') . ' 
:'. $this->fakebase. SEP . 'document' . SEP . $loc1);
+                               }
+                               else
+                               {
+                                       
$this->receipt['message'][]=array('msg'=>lang('directory created') . ' :'. 
$this->fakebase. SEP . 'document' . SEP . $loc1);
+                               }
+                               $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'];
+                       $this->vfs->override_acl = 1;
+
+
+//_debug_array($to_file);
+                       if($this->vfs->file_exists(array(
+                                       'string' => $to_file,
+                                       'relatives' => Array(RELATIVE_NONE)
+                               )))
+                       {
+                               
$this->receipt['error'][]=array('msg'=>lang('File %1 already 
exists!',$values['file_name']));
+                       }
+                       else
+                       {
+
+                               if(!$this->vfs->cp (array (
+                                       'from'  => $from_file,
+                                       'to'    => $to_file,
+                                       'relatives'     => array 
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL))))
+                               {
+                                       
$this->receipt['error'][]=array('msg'=>lang('Failed to copy file !') . 
$values['file_name']);
+                               }
+                               else
+                               {
+                                       $address = 
$this->get_address($values['loc1'],$values['loc2'],$values['loc3']);
+
+                                       switch($values['type'])
+                                       {
+                                               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;
+                                       }
+
+                                       $insert_values= array(
+                                               $values['file_name'],
+                                               $values['title'],
+                                               'public',
+                                               $values['category_id'],
+                                               time(),
+                                               $values['values_date'],
+                                               $values['version'],
+                                               $values['coordinator'],
+                                               $values['status'],
+                                               $values['location_code'],
+                                               $address,
+                                               $values['branch_id'],
+                                               $values['vendor_id'],
+                                               $this->account,
+                                               $values['loc1'],
+                                               $values['loc2'],
+                                               $values['loc3'],
+                                               );
+
+                                       $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) "
+                                               . "VALUES ($insert_values)";
+
+                                       
$this->db->query($sql,__LINE__,__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');
+               }
+       }
+?>




reply via email to

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