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, 1.2 oppdater_utgaatt_ob


From: ceb
Subject: [Phpgroupware-cvs] property/inc/custom cron.php, 1.2 oppdater_utgaatt_objekt.php, 1.2 organize_drawing.php, 1.2
Date: Thu, 24 Feb 2005 14:36:33 -0000

Update of property/inc/custom

Added Files:
     Branch: MAIN
            cron.php lines: +59 -0
            oppdater_utgaatt_objekt.php lines: +207 -0
            organize_drawing.php lines: +449 -0

Log Message:
committed prop-18-branch version to head

====================================================
Index: cron.php
#!/usr/bin/php -q
<?php
        /**
        * phpGroupWare - property
        * address@hidden http://www.phpgroupware.org}
        *
        * Property: a Facilities Management System.
        *
        * Copyright 2000 - 2003 Free Software Foundation, Inc
        * This program is part of the GNU project, see address@hidden 
http://www.gnu.org/}
        *
        * This program is free software; you can redistribute it and/or modify 
it
        * under the terms of the GNU General Public License as published by the
        * Free Software Foundation; either version 2 of the License, or (at your
        * option) any later version.
        *
        * To contact the author write to address@hidden mailto:address@hidden 
Sigurd Nes}
        * @author Sigurd Nes
        * @package property
        * @subpackage admin
        * @version $Id: cron.php,v 1.2 2005/01/13 17:00:04 ceb Exp $
        */

        /**
         * Description
         * @package property
         * 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: oppdater_utgaatt_objekt.php
<?php
        /**
        * phpGroupWare - property
        * address@hidden http://www.phpgroupware.org}
        *
        * Property: a Facilities Management System.
        *
        * Copyright 2000 - 2003 Free Software Foundation, Inc
        * This program is part of the GNU project, see address@hidden 
http://www.gnu.org/}
        *
        * This program is free software; you can redistribute it and/or modify 
it
        * under the terms of the GNU General Public License as published by the
        * Free Software Foundation; either version 2 of the License, or (at your
        * option) any later version.
        *
        * To contact the author write to address@hidden mailto:address@hidden 
Sigurd Nes}
        * @author Sigurd Nes
        * @package property
        * @subpackage custom
        * @version $Id: oppdater_utgaatt_objekt.php,v 1.2 2005/01/13 17:00:04 
ceb 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->transaction_begin();

                        $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'));
                                        }
                                }

                                $j=0;
                                for ($i=0; $i<count($update); $i++)
                                {

                                        $sql = "SELECT status  FROM 
$parent_table WHERE location_code= '" . $update[$i]['location_code'] ."'";

                                        
$this->db->query($sql,__LINE__,__FILE__);
                                        $this->db->next_record();

                                        if($this->db->f('status')!=2)
                                        {
                                                $j++;
                                                $this->db->query("UPDATE 
fm_location" . ($type_id-1). " set     status= 2  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);
                        }

                        $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: organize_drawing.php
<?php
        /**
        * phpGroupWare - property
        * address@hidden http://www.phpgroupware.org}
        *
        * Property: a Facilities Management System.
        *
        * Copyright 2000 - 2003 Free Software Foundation, Inc
        * This program is part of the GNU project, see address@hidden 
http://www.gnu.org/}
        *
        * This program is free software; you can redistribute it and/or modify 
it
        * under the terms of the GNU General Public License as published by the
        * Free Software Foundation; either version 2 of the License, or (at your
        * option) any later version.
        *
        * To contact the author write to address@hidden mailto:address@hidden 
Sigurd Nes}
        * @author Sigurd Nes
        * @package property
        * @subpackage custom
        * @version $Id: organize_drawing.php,v 1.2 2005/01/13 17:00:04 ceb 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]