fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [10388] property: condition survey


From: Sigurd Nes
Subject: [Fmsystem-commits] [10388] property: condition survey
Date: Tue, 30 Oct 2012 15:04:08 +0000

Revision: 10388
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10388
Author:   sigurdne
Date:     2012-10-30 15:04:08 +0000 (Tue, 30 Oct 2012)
Log Message:
-----------
property: condition survey

Modified Paths:
--------------
    trunk/property/inc/class.menu.inc.php

Added Paths:
-----------
    trunk/property/inc/class.bocondition_survey.inc.php
    trunk/property/inc/class.socondition_survey.inc.php
    trunk/property/inc/class.uicondition_survey.inc.php

Added: trunk/property/inc/class.bocondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.bocondition_survey.inc.php                         
(rev 0)
+++ trunk/property/inc/class.bocondition_survey.inc.php 2012-10-30 15:04:08 UTC 
(rev 10388)
@@ -0,0 +1,198 @@
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003,2004,2005,2006,2007,2008,2009 Free 
Software Foundation, Inc. http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare 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.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @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: class.bocondition survey.inc.php 9684 2012-06-27 
14:19:11Z sigurdne $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class property_bocondition_survey
+       {
+               var $start;
+               var $query;
+               var $filter;
+               var $sort;
+               var $order;
+               var $cat_id;
+               var $location_info = array();
+               var $appname;
+               var $allrows;
+               public $acl_location = '.project.bocondition_survey';
+
+               function __construct($session=false)
+               {
+                       $this->so                       = 
CreateObject('property.socondition_survey');
+                       $this->custom           = & $this->so->custom;
+                       $this->bocommon         = 
CreateObject('property.bocommon');
+
+                       $start                          = 
phpgw::get_var('start', 'int', 'REQUEST', 0);
+                       $query                          = 
phpgw::get_var('query');
+                       $sort                           = 
phpgw::get_var('sort');
+                       $order                          = 
phpgw::get_var('order');
+                       $filter                         = 
phpgw::get_var('filter', 'int');
+                       $cat_id                         = 
phpgw::get_var('cat_id', 'int');
+                       $allrows                        = 
phpgw::get_var('allrows', 'bool');
+                       $appname                        = 
phpgw::get_var('appname', 'string');
+
+                       if($appname)
+                       {
+                               $this->appname          = $appname;
+                               $this->so->appname      = $appname;
+                       }
+
+                       $type                           = 
phpgw::get_var('type');
+                       $type_id                        = 
phpgw::get_var('type_id', 'int', 'REQUEST', 0);
+                       $this->type             = $type;
+                       $this->type_id          = $type_id;
+
+                       if ($session)
+                       {
+                               $this->read_sessiondata($type);
+                               $this->use_session = true;
+                       }
+
+                       $this->start            = $start ? $start : 0;
+                       $this->query            = isset($_REQUEST['query']) ? 
$query : $this->query;
+                       $this->sort                     = 
isset($_REQUEST['sort']) ? $sort : $this->sort;
+                       $this->order            = isset($_REQUEST['order']) && 
$_REQUEST['order'] ? $order : $this->order;
+                       $this->filter           = isset($_REQUEST['filter']) ? 
$filter : $this->filter;
+                       $this->cat_id           = isset($_REQUEST['cat_id'])  ? 
$cat_id :  $this->cat_id;
+                       $this->allrows          = isset($allrows) ? $allrows : 
false;
+
+
+               }
+
+               public function save_sessiondata($data)
+               {
+                       if ($this->use_session)
+                       {
+                               
$GLOBALS['phpgw']->session->appsession('session_data',$this->acl_location,$data);
+                       }
+               }
+
+               function read_sessiondata($type)
+               {
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data',$this->acl_location);
+
+                       //              _debug_array($data);
+
+                       $this->start    = $data['start'];
+                       $this->query    = $data['query'];
+                       $this->filter   = $data['filter'];
+                       $this->sort             = $data['sort'];
+                       $this->order    = $data['order'];
+                       $this->cat_id   = $data['cat_id'];
+                       $this->allrows  = $data['allrows'];
+               }
+
+               function column_list($selected='',$allrows='')
+               {
+                       if(!$selected)
+                       {
+                               $selected = 
$GLOBALS['phpgw_info']['user']['preferences']['property']["columns_{$this->acl_location}"];
+                       }
+
+                       $filter = array('list' => ''); // translates to "list 
IS NULL"
+                       $columns = 
$this->custom->find('property',$this->acl_location, 0, '','','',true, false, 
$filter);
+                       
$column_list=$this->bocommon->select_multi_list($selected,$columns);
+
+                       return $column_list;
+               }
+
+               public function read($filter = array())
+               {
+                       if (! $filter )
+                       {
+                               foreach ( $this->location_info['fields'] as 
$field )
+                               {
+                                       if (isset($field['filter']) && 
$field['filter'])
+                                       {
+                                               $filter[$field['name']] = 
phpgw::get_var($field['name']);
+                                       }
+                               }
+                       }
+
+                       $values = $this->so->read(array('start' => 
$this->start,'query' => $this->query,'sort' => $this->sort,'order' => 
$this->order,
+                               'allrows'=>$this->allrows),$filter);
+
+                       $this->total_records = $this->so->total_records;
+                       $this->uicols = $this->so->uicols;
+
+                       return $values;
+               }
+
+               public function read_single($data=array())
+               {
+                       $custom_fields = false;
+                       
if($GLOBALS['phpgw']->locations->get_attrib_table('property', 
$this->acl_location))
+                       {
+                               $custom_fields = true;
+                               $values = array();
+                               $values['attributes'] = 
$this->custom->find('property', $this->acl_location, 0, '', 'ASC', 
'attrib_sort', true, true);
+                       }
+
+                       if(isset($data['id']) && $data['id'])
+                       {
+                               $values = $this->so->read_single($data, 
$values);
+                       }
+                       if($custom_fields)
+                       {
+                               $values = $this->custom->prepare($values, 
'property',$this->acl_location, $data['view']);
+                       }
+                       return $values;
+               }
+
+               public function save($data,$action='',$values_attribute = 
array())
+               {
+                       if(is_array($values_attribute))
+                       {
+                               $values_attribute = 
$this->custom->convert_attribute_save($values_attribute);
+                       }
+
+                       if ($action=='edit')
+                       {
+                               if ($data['id'] != '')
+                               {
+
+                                       $receipt = 
$this->so->edit($data,$values_attribute);
+                               }
+                       }
+                       else
+                       {
+                               $receipt = 
$this->so->add($data,$values_attribute);
+                       }
+
+                       return $receipt;
+               }
+
+               public function delete($id)
+               {
+                       $this->so->delete($id);
+               }
+       }

Modified: trunk/property/inc/class.menu.inc.php
===================================================================
--- trunk/property/inc/class.menu.inc.php       2012-10-30 14:49:37 UTC (rev 
10387)
+++ trunk/property/inc/class.menu.inc.php       2012-10-30 15:04:08 UTC (rev 
10388)
@@ -790,6 +790,12 @@
                                                                'text'  => 
lang('Workorder'),
                                                                'image'         
=> array('property', 'project_workorder')
                                                        ),
+                                                       'condition_survey'      
=> array
+                                                       (
+                                                               'url'   => 
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'property.uicondition_survey.index')),
+                                                               'text'  => 
lang('condition survey'),
+                                                               'image'         
=> array('property', 'project_request')
+                                                       ),
                                                        'request'       => array
                                                        (
                                                                'url'   => 
$GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'property.uirequest.index')),

Added: trunk/property/inc/class.socondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.socondition_survey.inc.php                         
(rev 0)
+++ trunk/property/inc/class.socondition_survey.inc.php 2012-10-30 15:04:08 UTC 
(rev 10388)
@@ -0,0 +1,337 @@
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2003,2004,2005,2006,2007 Free Software 
Foundation, Inc. http://www.fsf.org/
+       * This file is part of phpGroupWare.
+       *
+       * phpGroupWare 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.
+       *
+       * phpGroupWare is distributed in the hope that it will be useful,
+       * but WITHOUT ANY WARRANTY; without even the implied warranty of
+       * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       * GNU General Public License for more details.
+       *
+       * You should have received a copy of the GNU General Public License
+       * along with phpGroupWare; if not, write to the Free Software
+       * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 
 USA
+       *
+       * @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: class.socustom.inc.php 8281 2011-12-13 09:24:03Z 
sigurdne $
+       */
+
+       /**
+        * Description
+        * @package property
+        */
+
+       class property_socondition_survey
+       {
+               function __construct()
+               {
+                       $this->account  = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                       $this->db               = & $GLOBALS['phpgw']->db;
+                       $this->join             = & $this->db->join;
+                       $this->like             = & $this->db->like;
+               }
+
+               function read($data)
+               {
+                       if(is_array($data))
+                       {
+                               $start  = 
(isset($data['start'])?$data['start']:0);
+                               $filter = 
(isset($data['filter'])?$data['filter']:'none');
+                               $query = 
(isset($data['query'])?$data['query']:'');
+                               $sort = 
(isset($data['sort'])?$data['sort']:'DESC');
+                               $order = 
(isset($data['order'])?$data['order']:'');
+                               $cat_id = 
(isset($data['cat_id'])?$data['cat_id']:0);
+                               $allrows                = 
(isset($data['allrows'])?$data['allrows']:'');
+                       }
+
+                       if ($order)
+                       {
+                               $ordermethod = " order by $order $sort";
+                       }
+                       else
+                       {
+                               $ordermethod = ' order by id DESC';
+                       }
+
+                       $where = 'WHERE';
+                       if ($cat_id > 0)
+                       {
+                               $filtermethod .= " $where category='$cat_id' ";
+                               $where = 'AND';
+                       }
+
+                       if($query)
+                       {
+                               $query                  = 
$this->db->db_addslashes($query);
+                               $querymethod    = " $where name $this->like 
'%$query%'";
+                       }
+
+                       $sql = "SELECT * FROM fm_custom $filtermethod 
$querymethod";
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       $this->total_records = $this->db->num_rows();
+
+                       if(!$allrows)
+                       {
+                               $this->db->limit_query($sql . 
$ordermethod,$start,__LINE__,__FILE__);
+                       }
+                       else
+                       {
+                               $this->db->query($sql . 
$ordermethod,__LINE__,__FILE__);
+                       }
+
+                       while ($this->db->next_record())
+                       {
+                               $customs[] = array
+                                       (
+                                               'custom_id'             => 
$this->db->f('id'),
+                                               'name'                  => 
stripslashes($this->db->f('name')),
+                                               'entry_date'    => 
$this->db->f('entry_date'),
+                                               'user'                  => 
$GLOBALS['phpgw']->accounts->id2name($this->db->f('user_id'))
+                                       );
+                       }
+                       return $customs;
+               }
+
+               function read_single($custom_id)
+               {
+                       $custom_id = (int) $custom_id;
+                       $this->db->query("SELECT * from fm_custom where 
id={$custom_id}",__LINE__,__FILE__);
+
+                       $custom = array();
+                       if ($this->db->next_record())
+                       {
+                               $custom = array
+                                       (
+                                               'id'                    => 
(int)$this->db->f('id'),
+                                               'name'                  => 
$this->db->f('name', true),
+                                               'sql_text'              => 
$this->db->f('sql_text', true),
+                                               'entry_date'    => 
$this->db->f('entry_date'),
+                                               'cols'                  => 
$this->read_cols($custom_id)
+                                       );
+                       }
+
+                       return $custom;
+               }
+
+               function read_cols($custom_id)
+               {
+                       $custom_id = (int) $custom_id;
+                       $sql = "SELECT * FROM fm_custom_cols WHERE 
custom_id={$custom_id} ORDER by sorting";
+                       $this->db->query($sql);
+
+                       $cols = array();
+                       while ($this->db->next_record())
+                       {
+                               $cols[] = array
+                                       (
+                                               'id'    => $this->db->f('id'),
+                                               'name'  => $this->db->f('name'),
+                                               'descr' => 
$this->db->f('descr', true),
+                                               'sorting'=> 
$this->db->f('sorting')
+                                       );
+
+                       }
+                       return $cols;
+               }
+
+               function read_custom_name($custom_id)
+               {
+                       $custom_id = (int) $custom_id;
+                       $this->db->query("SELECT name FROM fm_custom where 
id={$custom_id}",__LINE__,__FILE__);
+                       $this->db->next_record();
+                       return $this->db->f('name', true);
+               }
+
+               function add($custom)
+               {
+                       $custom['name'] = 
$this->db->db_addslashes($custom['name']);
+                       $custom['sql_text'] = 
$this->db->db_addslashes(htmlspecialchars_decode($custom['sql_text']));
+
+                       $this->db->transaction_begin();
+
+                       $id = $this->db->next_id('fm_custom');
+
+                       $this->db->query("INSERT INTO fm_custom 
(id,entry_date,sql_text,name,user_id) "
+                               . "VALUES ($id,'" . time() . "','" . 
$custom['sql_text'] . "','" . $custom['name'] . "'," . $this->account . 
")",__LINE__,__FILE__);
+
+                       $receipt['custom_id']= $id;
+
+
+                       $this->db->transaction_commit();
+
+                       $receipt['message'][] = array('msg'=>lang('custom %1 
has been saved',$receipt['custom_id']));
+                       return $receipt;
+               }
+
+               function edit($custom)
+               {
+                       $custom['name'] = 
$this->db->db_addslashes($custom['name']);
+                       $custom['sql_text'] = 
$this->db->db_addslashes(htmlspecialchars_decode($custom['sql_text']));
+
+                       $this->db->query("UPDATE fm_custom set 
sql_text='{$custom['sql_text']}', entry_date='" . time() . "', 
name='{$custom['name']}' WHERE id=" . (int) 
$custom['custom_id'],__LINE__,__FILE__);
+
+                       if($custom['new_name'])
+                       {
+                               $column_id = 
$this->db->next_id('fm_custom_cols', array('custom_id'=>$custom['custom_id']));
+
+                               $sql = "SELECT max(sorting) as max_sort FROM 
fm_custom_cols WHERE custom_id=" . $custom['custom_id'];
+                               $this->db->query($sql);
+                               $this->db->next_record();
+                               $sorting        = $this->db->f('max_sort')+1;
+
+                               $values= array(
+                                       $custom['custom_id'],
+                                       $column_id,
+                                       $custom['new_name'],
+                                       
$this->db->db_addslashes($custom['new_descr']),
+                                       $sorting
+                               );
+
+                               $values = $this->db->validate_insert($values);
+
+                               $this->db->query("INSERT INTO fm_custom_cols 
(custom_id,id,name,descr,sorting) "
+                                       . "VALUES ($values)");
+                       }
+
+
+                       if($custom['delete_cols'])
+                       {
+                               for ($i=0;$i<count($custom['delete_cols']);$i++)
+                               {
+
+                                       $sql = "SELECT sorting FROM 
fm_custom_cols where custom_id=" . $custom['custom_id'] . " AND id=" . 
$custom['delete_cols'][$i];
+                                       $this->db->query($sql);
+                                       $this->db->next_record();
+                                       $sorting        = 
$this->db->f('sorting');
+                                       $sql2 = "SELECT max(sorting) as 
max_sort FROM fm_custom_cols";
+                                       $this->db->query($sql2);
+                                       $this->db->next_record();
+                                       $max_sort       = 
$this->db->f('max_sort');
+
+                                       if($max_sort>$sorting)
+                                       {
+                                               $sql = "UPDATE fm_custom_cols 
set sorting=sorting-1 WHERE sorting > $sorting AND custom_id=" . 
$custom['custom_id'];
+                                               $this->db->query($sql);
+                                       }
+
+
+                                       $this->db->query("DELETE FROM 
fm_custom_cols WHERE  custom_id=" . $custom['custom_id']  ." AND id=" . 
$custom['delete_cols'][$i]);
+                               }
+                       }
+
+                       $receipt['custom_id']= $custom['custom_id'];
+                       $receipt['message'][] = array('msg'=>lang('custom %1 
has been edited',$custom['custom_id']));
+                       return $receipt;
+               }
+
+               function resort($data)
+               {
+                       //html_print_r($data);
+                       if(is_array($data))
+                       {
+                               $resort = 
(isset($data['resort'])?$data['resort']:'up');
+                               $custom_id = 
(isset($data['id'])?$data['custom_id']:'');
+                               $id = (isset($data['id'])?$data['id']:'');
+                       }
+
+                       $sql = "SELECT sorting FROM fm_custom_cols WHERE 
custom_id = $custom_id AND id=$id";
+                       $this->db->query($sql);
+                       $this->db->next_record();
+                       $sorting        = $this->db->f('sorting');
+                       $sql = "SELECT max(sorting) as max_sort FROM 
fm_custom_cols WHERE custom_id = $custom_id";
+                       $this->db->query($sql);
+                       $this->db->next_record();
+                       $max_sort       = $this->db->f('max_sort');
+                       switch($resort)
+                       {
+                               case 'up':
+                                       if($sorting>1)
+                                       {
+                                               $sql = "UPDATE fm_custom_cols 
set sorting=$sorting WHERE custom_id = $custom_id AND sorting =" . ($sorting-1);
+                                               $this->db->query($sql);
+                                               $sql = "UPDATE fm_custom_cols 
set sorting=" . ($sorting-1) ." WHERE custom_id = $custom_id AND id=$id";
+                                               $this->db->query($sql);
+                                       }
+                                       break;
+                               case 'down':
+                                       if($max_sort > $sorting)
+                                       {
+                                               $sql = "UPDATE fm_custom_cols 
set sorting=$sorting WHERE custom_id = $custom_id AND sorting =" . ($sorting+1);
+                                               $this->db->query($sql);
+                                               $sql = "UPDATE fm_custom_cols 
set sorting=" . ($sorting+1) ." WHERE custom_id = $custom_id AND id=$id";
+                                               $this->db->query($sql);
+                                       }
+                                       break;
+                               default:
+                                       return;
+                                       break;
+                       }
+               }
+
+               function read_custom($data)
+               {
+                       $start          = isset($data['start']) && 
$data['start'] ? $data['start'] : 0;
+                       $filter         = isset($data['filter']) && 
$data['filter'] ? $data['filter'] : 'none';
+                       $query          = isset($data['query']) ? 
$data['query'] : '';
+                       $sort           = isset($data['sort']) && $data['sort'] 
? $data['sort'] : 'DESC';
+                       $order          = isset($data['order']) ? 
$data['order'] : '';
+                       $allrows        = isset($data['allrows']) ? 
$data['allrows'] : '';
+                       $custom_id      = isset($data['custom_id']) && 
$data['custom_id'] ? (int)$data['custom_id'] : 0;
+
+                       $this->db->query("SELECT sql_text FROM fm_custom where 
id={$custom_id}",__LINE__,__FILE__);
+                       $this->db->next_record();
+                       $sql = $this->db->f('sql_text', true);
+
+                       $uicols = $this->read_cols($custom_id);
+                       $this->uicols = $uicols;
+
+                       //FIXME:
+                       $ordermethod = '';
+
+                       $this->db->query($sql,__LINE__,__FILE__);
+                       $this->total_records = $this->db->num_rows();
+
+                       if(!$allrows)
+                       {
+                               $this->db->limit_query($sql . 
$ordermethod,$start,__LINE__,__FILE__);
+                       }
+                       else
+                       {
+                               $this->db->query($sql . 
$ordermethod,__LINE__,__FILE__);
+                       }
+
+                       $n=count($uicols);
+                       $j=0;
+                       while ($this->db->next_record())
+                       {
+                               for ($i=0;$i<$n;$i++)
+                               {
+                                       $custom[$j][$uicols[$i]['name']] = 
$this->db->f($uicols[$i]['name']);
+                                       $custom[$j]['grants'] = 
(int)$grants[$this->db->f('user_id')];
+                               }
+                               $j++;
+                       }
+
+                       //_debug_array($custom);
+                       return $custom;
+               }
+
+               function delete($custom_id)
+               {
+                       $custom_id = (int) $custom_id;
+                       $this->db->query("DELETE FROM fm_custom WHERE 
id={$custom_id}",__LINE__,__FILE__);
+                       $this->db->query("DELETE FROM fm_custom_cols WHERE 
custom_id={$custom_id}",__LINE__,__FILE__);
+               }
+       }

Added: trunk/property/inc/class.uicondition_survey.inc.php
===================================================================
--- trunk/property/inc/class.uicondition_survey.inc.php                         
(rev 0)
+++ trunk/property/inc/class.uicondition_survey.inc.php 2012-10-30 15:04:08 UTC 
(rev 10388)
@@ -0,0 +1,391 @@
+<?php
+
+       /**
+        * phpGroupWare - logistic: a part of a Facilities Management System.
+        *
+        * @author Sigurd Nes <address@hidden>
+        * @copyright Copyright (C) 2012 Free Software Foundation, Inc. 
http://www.fsf.org/
+        * This file is part of phpGroupWare.
+        *
+        * phpGroupWare 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.
+        *
+        * phpGroupWare is distributed in the hope that it will be useful,
+        * but WITHOUT ANY WARRANTY; without even the implied warranty of
+        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+        * GNU General Public License for more details.
+        *
+        * You should have received a copy of the GNU General Public License
+        * along with phpGroupWare; if not, write to the Free Software
+        * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
02110-1301  USA
+        *
+        * @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/
+        * @package property
+        * @subpackage logistic
+        * @version $Id: class.uiproject.inc.php 10300 2012-10-23 07:16:54Z 
vator $
+        */
+       phpgw::import_class('phpgwapi.uicommon');
+       phpgw::import_class('phpgwapi.jquery');
+
+       class property_uicondition_survey extends phpgwapi_uicommon
+       {
+
+               private $bo;
+               public $public_functions = array(
+                       'query' => true,
+                       'index' => true,
+                       'view' => true,
+                       'add' => true,
+                       'edit' => true,
+                       'save' => true
+               );
+
+               public function __construct()
+               {
+                       parent::__construct();
+
+                       $this->bo                                       = 
CreateObject('property.bocondition_survey');
+                       $this->bocommon                         = & 
$this->bo->bocommon;
+                       $this->acl                                      = & 
$GLOBALS['phpgw']->acl;
+                       $this->acl_location                     = 
$this->bo->acl_location;
+                       $this->acl_read                         = 
$this->acl->check($this->acl_location, PHPGW_ACL_READ, 'property');
+                       $this->acl_add                          = 
$this->acl->check($this->acl_location, PHPGW_ACL_ADD, 'property');
+                       $this->acl_edit                         = 
$this->acl->check($this->acl_location, PHPGW_ACL_EDIT, 'property');
+                       $this->acl_delete                       = 
$this->acl->check($this->acl_location, PHPGW_ACL_DELETE, 'property');
+                       $this->acl_manage                       = 
$this->acl->check($this->acl_location, 16, 'property');
+
+                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
"property::condition_survey";
+               }
+
+               public function index()
+               {
+                       if (phpgw::get_var('phpgw_return_as') == 'json')
+                       {
+                               return $this->query();
+                       }
+
+                       self::add_javascript('phpgwapi', 'yahoo', 
'datatable.js');
+                       phpgwapi_yui::load_widget('datatable');
+                       phpgwapi_yui::load_widget('paginator');
+
+                       $survey_type_array = array();
+
+                       $data = array(
+                               'datatable_name'        => lang('condition 
survey'),
+                               'form' => array(
+                                       'toolbar' => array(
+                                               'item' => array(
+                                                       array('type' => 
'filter',
+                                                               'name' => 
'project_type',
+                                                               'text' => 
lang('Project_type') . ':',
+                                                               'list' => 
$survey_type_array,
+                                                       ),
+                                                       array('type' => 'text',
+                                                               'text' => 
lang('search'),
+                                                               'name' => 
'query'
+                                                       ),
+                                                       array(
+                                                               'type' => 
'submit',
+                                                               'name' => 
'search',
+                                                               'value' => 
lang('Search')
+                                                       ),
+                                                       array(
+                                                               'type' => 
'link',
+                                                               'value' => 
lang('t_new_project'),
+                                                               'href' => 
self::link(array('menuaction' => 'property.uicondition_survey.add')),
+                                                               'class' => 
'new_item'
+                                                       ),
+                                               ),
+                                       ),
+                               ),
+                               'datatable' => array(
+                                       'source' => 
self::link(array('menuaction' => 'property.uicondition_survey.index', 
'phpgw_return_as' => 'json')),
+                                       'field' => array(
+                                               array(
+                                                       'key' => 'name',
+                                                       'label' => 
lang('Project name'),
+                                                       'sortable' => true
+                                               ),
+                                               array(
+                                                       'key' => 'id',
+                                                       'label' => lang('ID'),
+                                                       'sortable' => true,
+                                                       'formatter' => 
'YAHOO.portico.formatLink'
+                                               ),
+                                               array(
+                                                       'key' => 'description',
+                                                       'label' => 
lang('Project description'),
+                                                       'sortable' => false,
+                                                       'editor' => 'new 
YAHOO.widget.TextboxCellEditor({disableBtns:true})'
+                                               ),
+                                               array(
+                                                       'key' => 
'project_type_label',
+                                                       'label' => 
lang('Project type'),
+                                                       'sortable' => false
+                                               ),
+                                               array(
+                                                       'key' => 'link',
+                                                       'hidden' => true
+                                               )
+                                       )
+                               ),
+                       );
+
+                       $parameters = array
+                               (
+                                       'parameter' => array
+                                       (
+                                               array
+                                               (
+                                                       'name'          => 
'project_id',
+                                                       'source'        => 'id'
+                                               ),
+                                       )
+                               );
+
+                       $data['datatable']['actions'][] = array
+                                       (
+                                               'my_name'               => 
'new_activity',
+                                               'text'                  => 
lang('t_new_activity'),
+                                               'action'                => 
$GLOBALS['phpgw']->link('/index.php',array
+                                               (
+                                                       'menuaction'    => 
'logistic.uiactivity.edit'
+                                               )),
+                                               'parameters'    => 
json_encode($parameters)
+                                       );
+
+                       self::render_template_xsl('datatable_common', $data);
+               }
+
+
+               public function query()
+               {
+                       $params = array(
+                               'start' => phpgw::get_var('startIndex', 'int', 
'REQUEST', 0),
+                               'results' => phpgw::get_var('results', 'int', 
'REQUEST', null),
+                               'query' => phpgw::get_var('query'),
+                               'sort' => phpgw::get_var('sort'),
+                               'dir' => phpgw::get_var('dir'),
+                               'filters' => $filters
+                       );
+
+                       if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0)
+                       {
+                               $user_rows_per_page = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+                       }
+                       else
+                       {
+                               $user_rows_per_page = 10;
+                       }
+                       // YUI variables for paging and sorting
+                       $start_index = phpgw::get_var('startIndex', 'int');
+                       $num_of_objects = phpgw::get_var('results', 'int', 
'GET', $user_rows_per_page);
+                       $sort_field = phpgw::get_var('sort');
+                       $sort_ascending = phpgw::get_var('dir') == 'desc' ? 
false : true;
+                       // Form variables
+                       $search_for = phpgw::get_var('query');
+                       $search_type = phpgw::get_var('search_option');
+                       // Create an empty result set
+                       $result_objects = array();
+                       $result_count = 0;
+
+                       //Retrieve a project identifier and load corresponding 
project
+                       $project_id = phpgw::get_var('project_id');
+
+                       $exp_param = phpgw::get_var('export');
+                       $export = false;
+                       if (isset($exp_param))
+                       {
+                               $export = true;
+                               $num_of_objects = null;
+                       }
+
+                       //Retrieve the type of query and perform type specific 
logic
+                       $query_type = phpgw::get_var('type');
+                       //var_dump($query_type);
+                       switch ($query_type)
+                       {
+                               case 'project_type':
+                                       phpgwapi_cache::session_set('logistic', 
'project_type_query', $search_for);
+                                       $search_type = 'project_type';
+                                       $result_objects = 
$this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, 
$search_for, $search_type, $filters);
+                                       $object_count = 
$this->so->get_count($search_for, $search_type, $filters);
+                                       break;
+                               default: // ... all composites, filters (active 
and vacant)
+                                       phpgwapi_cache::session_set('logistic', 
'project_query', $search_for);
+                                       $filters = array('project_type' => 
phpgw::get_var('project_type'));
+                                       $result_objects = 
$this->so->get($start_index, $num_of_objects, $sort_field, $sort_ascending, 
$search_for, $search_type, $filters);
+                                       $object_count = 
$this->so->get_count($search_for, $search_type, $filters);
+                                       break;
+                       }
+                       //var_dump($result_objects);
+                       //Create an empty row set
+                       $rows = array();
+                       foreach ($result_objects as $result)
+                       {
+                               if (isset($result))
+                               {
+                                       $rows[] = $result->serialize();
+                               }
+                       }
+
+                       // ... add result data
+                       $result_data = array('results' => $rows);
+
+                       $result_data['total_records'] = $object_count;
+                       $result_data['start'] = $params['start'];
+                       $result_data['sort'] = $params['sort'];
+                       $result_data['dir'] = $params['dir'];
+
+                       $editable = phpgw::get_var('editable') == 'true' ? true 
: false;
+
+                       if (!$export)
+                       {
+                               //Add action column to each row in result table
+                               if ($search_type && $search_type == 
'project_type')
+                               {
+                                       array_walk(
+                                                                       
$result_data['results'], array($this, '_add_links'), 
"property.uicondition_survey.view_project_type");
+                               }
+                               else
+                               {
+                                       array_walk(
+                                                                       
$result_data['results'], array($this, '_add_links'), 
"property.uicondition_survey.view");
+                               }
+                       }
+                       return $this->yui_results($result_data);
+               }
+
+
+               public function view()
+               {
+                       $project_id = phpgw::get_var('id');
+                       if (isset($_POST['edit_project']))
+                       {
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'property.uicondition_survey.edit', 'id' => $project_id));
+                       }
+                       else if (isset($_POST['new_activity']))
+                       {
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'logistic.uiactivity.edit', 'project_id' => $project_id));
+                       }
+                       else
+                       {
+                               if ($project_id && is_numeric($project_id))
+                               {
+                                       $project = 
$this->so->get_single($project_id);
+                               }
+
+                               $project_array = $project->toArray();
+
+                               $data = array
+                                       (
+                                       'value_id' => !empty($project) ? 
$project->get_id() : 0,
+                                       'project' => $project,
+                                       'view' => 'view_project'
+                               );
+
+                               $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('logistic') . '::' . lang('Project');
+                               
self::render_template_xsl(array('project/project_item'), $data);
+                       }
+               }
+
+               public function add()
+               {
+                       $this->edit();
+               }
+
+               public function edit($mode = 'edit')
+               {
+                       $id     = phpgw::get_var('id', 'int');
+
+                       if(!$this->acl_add && !$this->acl_edit)
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',array('menuaction'=> 
'property.uicondition_survey.view', 'id'=> $id));
+                       }
+
+                       if($mode == 'view')
+                       {
+                               if( !$this->acl_read)
+                               {
+                                       $this->bocommon->no_access();
+                                       return;
+                               }
+                       }
+                       else
+                       {
+                               if(!$this->acl_add && !$this->acl_edit)
+                               {
+                                       $this->bocommon->no_access();
+                                       return;
+                               }
+                       }
+
+
+
+                       $project_id = phpgw::get_var('id');
+                       if ($project_id && is_numeric($project_id))
+                       {
+                               $project = $this->so->get_single($project_id);
+                       }
+                       else
+                       {
+                               if($project == null)
+                               {
+                                       $project = new logistic_project();      
+                               }
+                       }
+
+                       $project_types = $this->so->get_project_types();
+                       foreach ($project_types as &$p_type)
+                       {
+                               if ($project->get_project_type_id() == 
$p_type['id'])
+                               {
+                                       $p_type['selected'] = 1;
+                               }
+                       }
+                       
+                       $data = array
+                       (
+                               'project' => $project,
+                               'options' => $project_types,
+                               'editable' => true
+                       );
+
+                       $this->use_yui_editor('description');
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('logistic') . '::' . lang('Project type');
+                       
+                       phpgwapi_jquery::load_widget('core');
+                       self::add_javascript('logistic', 'logistic', 
'project.js');
+                       
self::render_template_xsl(array('project/project_item'), $data);
+               }
+               
+               public function save()
+               {
+                       $project_id = phpgw::get_var('id');
+                       
+                       if ($project_id && is_numeric($project_id))
+                       {
+                               $project = $this->so->get_single($project_id);
+                       }
+                       else
+                       {
+                               $project = new logistic_project();
+                       }
+                       
+                       $project->populate();
+                       
+                       if( $project->validate() )
+                       {
+                               $project_id = $this->so->store($project);
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'property.uicondition_survey.view', 'id' => 
$project_id)); 
+                       }
+                       else
+                       {
+                               $this->edit( $project );
+                       }
+               }
+       }
+




reply via email to

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