fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [8294] more on notify


From: Sigurd Nes
Subject: [Fmsystem-commits] [8294] more on notify
Date: Wed, 14 Dec 2011 18:24:41 +0000

Revision: 8294
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=8294
Author:   sigurdne
Date:     2011-12-14 18:24:40 +0000 (Wed, 14 Dec 2011)
Log Message:
-----------
more on notify

Added Paths:
-----------
    trunk/property/inc/class.notify.inc.php
    trunk/property/js/yahoo/notify.js

Added: trunk/property/inc/class.notify.inc.php
===================================================================
--- trunk/property/inc/class.notify.inc.php                             (rev 0)
+++ trunk/property/inc/class.notify.inc.php     2011-12-14 18:24:40 UTC (rev 
8294)
@@ -0,0 +1,292 @@
+<?php
+       /**
+       * phpGroupWare - property: a Facilities Management System.
+       *
+       * @author Sigurd Nes <address@hidden>
+       * @copyright Copyright (C) 2008 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 phpgroupware
+       * @subpackage property
+       * @category core
+       * @version $Id$
+       */
+
+       /*
+          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.
+
+          This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
+       /**
+        * interlink - handles information of relations of items across 
locations.
+        *
+        * @package phpgroupware
+        * @subpackage property
+        * @category core
+        */
+
+       class property_notify
+       {
+               /**
+               * @var object $_db Database connection
+               */
+               protected $_db;
+               
+               protected $account;
+
+               var $public_functions = array
+               (
+                       'update_data'   => true,
+               );
+               
+               /**
+                * Constructor
+                *
+                */
+
+               function __construct()
+               {
+                       $this->_db              = & $GLOBALS['phpgw']->db;
+                       $this->_join    = & $this->_db->join;
+                       $this->account  = 
$GLOBALS['phpgw_info']['user']['account_id'];
+               }
+
+               /**
+                * Get list of contacts to notify at location item
+                *
+                * @param array $data location_id and location_item_id
+                * @return array content.
+                */
+
+               public function read($data = array())
+               {
+                       $location_id = (int) $data['location_id'];
+                       $location_item_id = (int) $data['location_item_id'];
+                       
+                       $sql = "SELECT phpgw_notification.id, 
phpgw_notification.contact_id,phpgw_notification.user_id,"
+                       . " 
phpgw_notification.is_active,phpgw_notification.entry_date,phpgw_notification.notification_method,"
+                       . " first_name, last_name"
+                       . " FROM phpgw_notification"
+                       . " {$this->_join} phpgw_contact_person ON 
phpgw_notification.contact_id = phpgw_contact_person.person_id"
+                       . " WHERE location_id = {$location_id} AND 
location_item_id = {$location_item_id}";
+                       $this->_db->query($sql,__LINE__,__FILE__);
+//_debug_array($sql);
+                       $values         = array();
+                       $dateformat = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
+                       $lang_yes       = lang('yes');
+                       $lang_no        = lang('no');
+
+                       while ($this->_db->next_record())
+                       {
+                               $values[] = array
+                               (
+                                       'id'                                    
=> $this->_db->f('id'),
+                                       'location_id'                   => 
$location_id,
+                                       'location_item_id'              => 
$location_item_id,
+                                       'contact_id'                    => 
$this->_db->f('contact_id'),
+                                       'is_active'                             
=> $this->_db->f('is_active') ? $lang_yes : $lang_no,
+                                       'notification_method'   => 
$this->_db->f('notification_method',true),
+                                       'user_id'                               
=> $this->_db->f('user_id'),
+                                       'entry_date'                    => 
$GLOBALS['phpgw']->common->show_date($this->_db->f('entry_date'),$dateformat),
+                                       'first_name'                    => 
$this->_db->f('first_name',true),
+                                       'last_name'                             
=> $this->_db->f('last_name', true)
+                               );
+                       }
+                       return $values;
+               }
+
+               /**
+                * Get definition for an inline YUI table
+                *
+                * @param array $data location and the number of preceding 
tables in the same page
+                * @return array table def data and prepared content.
+                */
+
+               public function get_yui_table_def($data = array())
+               {
+//_debug_array($data);die();
+                       if(!isset($data['location_id']) || 
!isset($data['location_item_id']))
+                       {
+                               throw new 
Exception("property_notify::get_yui_table_def - Missing location info in 
input");
+                       }       
+
+                       if(!isset($data['count']))
+                       {
+                               throw new 
Exception("property_notify::get_yui_table_def - Missing count in input");       
              
+                       }       
+
+                       $content = $this->read($data);
+
+                       $count = (int)$data['count'];
+                       $datavalues = array
+                       (
+                               'name'                                  => 
"{$count}",
+                               'values'                                => 
json_encode($content),
+                               'total_records'                 => 
count($content),
+                               'edit_action'                   => 
json_encode($GLOBALS['phpgw']->link('/index.php',array('menuaction'=> 
'addressbook.uiaddressbook.view_person'))),
+                               'is_paginator'                  => 1,
+                               'footer'                                => 0
+                       );
+
+                       $column_defs = array
+                       (
+                               'name'          => "{$count}",
+                               'values'        =>      json_encode(array(      
array('key' => 'id','hidden' => true),
+                                                                               
                        array('key' => 
'contact_id','label'=>lang('id'),'sortable'=>false,'resizeable'=>true,'formatter'=>'YAHOO.widget.DataTable.formatLink_notify'),
+                                                                               
                        array('key' => 'first_name','label'=>lang('first 
name'),'sortable'=>true,'resizeable'=>true),
+                                                                               
                        array('key' => 'last_name','label'=>lang('last 
name'),'sortable'=>true,'resizeable'=>true),
+                                                                               
                        array('key' => 
'notification_method','label'=>lang('method'),'sortable'=>true,'resizeable'=>true),
+                                                                               
                        array('key' => 'is_active','label'=>lang('is 
active'),'sortable'=>true,'resizeable'=>true),
+                                                                               
                        array('key' => 
'entry_date','label'=>lang('entry_date'),'sortable'=>true,'resizeable'=>true),
+                                                                               
                        array('key' => 'select','label'=> lang('select'), 
'sortable'=>false,'resizeable'=>false,'formatter'=>'myFormatterCheck_notify','width'=>30)
+                                                                               
                        ))
+                       );
+
+                       $buttons = array
+                       (
+                               'name'   => "{$count}",
+                               'values'  => json_encode(array(
+                                       array('id' 
=>'values[check_all]','type'=>'buttons', 'value'=>'Receipt', 'label'=> 
lang('check all'), 'funct'=> 'check_all_notify' , 'classname'=> 'actionButton', 
'value_hidden'=>""),
+                                       array('id' 
=>'values[delete_receipt]','type'=>'buttons', 'value'=>'Delete Receipt', 
'label'=> lang('Delete receipt'), 'funct'=> 'onActionsClick_notify' , 
'classname'=> 'actionButton', 'value_hidden'=>""),
+                                       array('id' 
=>'values[enable_alarm]','type'=>'buttons', 'value'=>'Enable', 'label'=> 
lang('enable'), 'funct'=> 'onActionsClick_notify' , 'classname'=> 
'actionButton', 'value_hidden'=>""),
+                                       array('id' 
=>'values[disable_alarm]','type'=>'buttons', 'value'=>'Disable', 
'label'=>lang('disable'), 'funct'=> 'onActionsClick_notify' , 'classname'=> 
'actionButton', 'value_hidden'=>""),
+                               ))
+                       );
+
+
+                       $GLOBALS['phpgw']->js->validate_file( 'yahoo', 
'notify', 'property' );
+
+                       $code = <<<JS
+       YAHOO.widget.DataTable.formatLink_notify = function(elCell, oRecord, 
oColumn, oData)
+       {
+               elCell.innerHTML = "<a 
href="+datatable[{$count}][0]["edit_action"]+"&ab_id="+oData+">" + oData + 
"</a>";
+       };
+
+       this.refresh_notify_contact=function()
+       {
+               if(document.getElementById('notify_contact').value)
+               {
+                       base_java_url['contact_id'] = 
document.getElementById('notify_contact').value;
+               }
+
+               if(document.getElementById('notify_contact').value != 
notify_contact)
+               {
+                       base_java_url['action'] = 'refresh_notify_contact';
+                       execute_async(myDataTable_{$count});
+                       notify_contact = 
document.getElementById('notify_contact').value;
+               }
+       }
+
+       this.onActionsClick_notify=function()
+       {
+               flag = false;
+               //clean hidden buttons actions
+               cleanValuesHiddenActionsButtons();
+
+               //validate ckecks true
+               array_checks = 
YAHOO.util.Dom.getElementsByClassName('mychecks');
+               for ( var i in array_checks )
+               {
+                       if(array_checks[i].checked)
+                       {
+                               flag = true;
+                               break;
+                       }
+               }
+
+               if(flag)
+               {
+                       //asign value to hidden
+                       YAHOO.util.Dom.get("hd_"+this.get("id")).value = 
this.get("value");
+
+                       formObject = document.body.getElementsByTagName('form');
+                       YAHOO.util.Connect.setForm(formObject[0]);//First form
+                       base_java_url['action'] = 'refresh_notify_contact';
+                       execute_async(myDataTable_{$count});
+               }
+       }
+
+
+JS;
+                       $GLOBALS['phpgw']->js->add_code($namespace, $code);
+
+                       return array('datavalues' => $datavalues, 'column_defs' 
=> $column_defs, 'buttons' => $buttons);
+               }
+
+
+               public function update_data()
+               {
+                       $action = phpgw::get_var('action', 'string', 'GET');
+                       switch($action)
+                       {
+                               case 'refresh_notify_contact':
+                                       return $this->refresh_notify_contact();
+                                       break;
+                               default:
+                       }
+               }
+
+               function refresh_notify_contact()
+               {
+                       $location_id            = 
(int)phpgw::get_var('location_id', 'int');
+                       $location_item_id       = 
(int)phpgw::get_var('location_item_id', 'int');
+                       $contact_id                     = 
(int)phpgw::get_var('contact_id', 'int');
+
+                       $location_info = 
$GLOBALS['phpgw']->locations->get_name($location_id);
+
+                       if( 
!$GLOBALS['phpgw']->acl->check($location_info['location'], PHPGW_ACL_READ, 
$location_info['appname']))
+                       {
+                               return;
+                       }
+
+                       if($location_id && $location_item_id && $contact_id)
+                       {
+                               $sql = "SELECT id FROM phpgw_notification WHERE 
location_id = {$location_id} AND location_item_id = {$location_item_id} AND 
contact_id = {$contact_id}";
+                               $this->_db->query($sql,__LINE__,__FILE__);
+                               if(!$this->_db->next_record())
+                               {
+                                       $values_insert = array
+                                       (
+                                               'location_id'                   
=> $location_id,
+                                               'location_item_id'              
=> $location_item_id,
+                                               'contact_id'                    
=> $contact_id,
+                                               'is_active'                     
        => 1,
+                                               'entry_date'                    
=> time(),
+                                               'user_id'                       
        => $this->account,
+                                               'notification_method'   => 
'email'
+                                       );
+                                       
+                                       $this->_db->query("INSERT INTO 
phpgw_notification (" . implode(',',array_keys($values_insert)) . ') VALUES ('
+                                        . 
$this->_db->validate_insert(array_values($values_insert)) . 
')',__LINE__,__FILE__);
+                               }
+                       }
+
+                       $content = $this->read(array('location_id'=> 
$location_id,'location_item_id'=> $location_item_id));
+
+                       if( phpgw::get_var('phpgw_return_as') == 'json' )
+                       {
+
+                               if(count($content))
+                               {
+                                       return json_encode($content);
+                               }
+                               else
+                               {
+                                       return "";
+                               }
+                       }
+                       return $content;
+               }
+
+
+       }

Added: trunk/property/js/yahoo/notify.js
===================================================================
--- trunk/property/js/yahoo/notify.js                           (rev 0)
+++ trunk/property/js/yahoo/notify.js   2011-12-14 18:24:40 UTC (rev 8294)
@@ -0,0 +1,114 @@
+var d;
+var notify_contact = 0;
+
+var Button_0_0, Button_0_1, Button_0_2;
+//var tableYUI;
+
+/********************************************************************************/
+       this.cleanValuesHiddenActionsButtons=function()
+       {
+       //      YAHOO.util.Dom.get('hd_values[set_receipt]').value = '';
+               YAHOO.util.Dom.get('hd_values[delete_receipt]').value = '';
+               YAHOO.util.Dom.get('hd_values[enable_alarm]').value = '';
+               YAHOO.util.Dom.get('hd_values[disable_alarm]').value = '';
+       }
+
+
+/* This one is added dynamically from php-class 
property_notify::get_yui_table_def()
+       YAHOO.widget.DataTable.formatLink_notify = function(elCell, oRecord, 
oColumn, oData)
+       {
+               elCell.innerHTML = "<a 
href="+datatable[0][0]["edit_action"]+"&ab_id="+oData+">" + oData + "</a>";
+       };
+*/
+
+       var FormatterRight_notify = function(elCell, oRecord, oColumn, oData)
+       {
+               elCell.innerHTML = "<div align=\"right\">"+oData+"</div>";
+       }       
+       
+
+       var myFormatterCheck_notify = function(elCell, oRecord, oColumn, oData)
+       {
+               elCell.innerHTML = "<center><input type=\"checkbox\" 
class=\"mychecks\"  value=\"\" 
name=\"values[notify]["+oRecord.getData('id')+"]\"/></center>";
+       }
+
+       check_all_notify = function()
+       {
+               var myclass = 'mychecks';
+               controls = YAHOO.util.Dom.getElementsByClassName(myclass);
+               for(i=0;i<controls.length;i++)
+               {
+                       if(!controls[i].disabled)
+                       {
+                               //for class=transfer_idClass, they have to be 
interchanged
+                               if(myclass=="mychecks")
+                               {
+                                       if(controls[i].checked)
+                                       {
+                                               controls[i].checked = false;
+                                       }
+                                       else
+                                       {
+                                               controls[i].checked = true;
+                                       }
+                               }
+                               //for the rest, always id checked
+                               else
+                               {
+                                       controls[i].checked = true;
+                               }
+                       }
+               }
+       }
+
+
+ 
/********************************************************************************/
+
+       this.notify_contact_lookup = function()
+       {
+               var oArgs = 
{menuaction:'property.uilookup.addressbook',column:'notify_contact'};
+               var strURL = phpGWLink('index.php', oArgs);
+               
Window1=window.open(strURL,"Search","left=50,top=100,width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");
+       }               
+
+/* This one is added dynamically from php-class 
property_notify::get_yui_table_def()
+       this.refresh_notify_contact=function()
+       {
+               if(document.getElementById('notify_contact').value)
+               {
+                       base_java_url['contact_id'] = 
document.getElementById('notify_contact').value;
+               }
+
+               if(document.getElementById('notify_contact').value != 
notify_contact)
+               {
+                       base_java_url['action'] = 'refresh_notify_contact';
+                       execute_async(myDataTable_3);
+                       notify_contact = 
document.getElementById('notify_contact').value;
+               }
+       }
+*/
+       this.onDOMAttrModified = function(e)
+       {
+               var attr = e.attrName || e.propertyName
+               var target = e.target || e.srcElement;
+               if (attr.toLowerCase() == 'notify_contact')
+               {
+                       refresh_notify_contact();
+               }
+       }
+
+       YAHOO.util.Event.addListener(window, "load", function()
+       {
+               d = document.getElementById('notify_contact');
+               if(d)
+               {
+                       if (d.attachEvent)
+                       {
+                               d.attachEvent('onpropertychange', 
onDOMAttrModified, false);
+                       }
+                       else
+                       {
+                               d.addEventListener('DOMAttrModified', 
onDOMAttrModified, false);
+                       }
+               }
+       });




reply via email to

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