phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] CVS: phpgwapi/inc class.bojsaddressbook.inc.php, 1.1.


From: Dave Hall <address@hidden>
Subject: [Phpgroupware-cvs] CVS: phpgwapi/inc class.bojsaddressbook.inc.php, 1.1.2.1, 1.1.2.2 class.uijsaddressbook.inc.php, 1.1.2.1, 1.1.2.2
Date: Sat, 13 Sep 2003 03:11:45 -0400

Update of /cvsroot/phpgroupware/phpgwapi/inc
In directory subversions:/tmp/cvs-serv30010

Modified Files:
      Tag: Version-0_9_16-branch
        class.bojsaddressbook.inc.php class.uijsaddressbook.inc.php 
Log Message:
fix jsaddressbook

Index: class.bojsaddressbook.inc.php
===================================================================
RCS file: 
/cvsroot/phpgroupware/phpgwapi/inc/Attic/class.bojsaddressbook.inc.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** class.bojsaddressbook.inc.php       8 Sep 2003 13:26:38 -0000       1.1.2.1
--- class.bojsaddressbook.inc.php       13 Sep 2003 07:11:42 -0000      1.1.2.2
***************
*** 1,459 ****
! <?php
! /**************************************************************************\
!  * phpGroupWare - Todo list                                                 *
!  * http://www.phpgroupware.org                                              *
!  * Written by Alex Borges <address@hidden>                          *
!  * Low Level Design also by    Dave Hall address@hidden                       
   *
!  * UI Design and market research by Gerardo Ramirez address@hidden
!  *-----------------------------------------------                          *
!  *  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.                                              *
!  \**************************************************************************/
! 
! /*!
!   @class bojsaddressbiij
!   @abstract logic for the javascript addressbook is here
!   @author Lex 
!   @ discussion  Understand that
!   this is my first attempt to a bo,ui pair of objects
!   that will do the job. I turned to do this because
!   this thingie has to be available for use by all the
!   phpgw 0.9.14 apps.
!   My approach is to use abstraction as much as possible.
!   This class will handle all data. DATA you hear? 
!   This means that the state of the abstraction we call
!   the cool addressbook chooser is here.... THE STATE!
!   Nothing webish about this file. This file will no receive
!   ever variables from HTTP_POST or GET. That is for the UI class
!   to handle. This class has methods that receive parameters so you 
!   can use it from anyware.
!  */
!        class bojsaddressbook
!       {
!               //@param $contacts phpgwapi contacts object
!               var $contacts;
!               //@param destboxes array that has the state of the three 
possible destination boxes
!               //this thing will have the title of the destination boxes and 
their content
!               //this class is session cache enabled. When you solicit the 
content of 
!               //this boxes this class may get it from cache if it thinks its 
necesary
!               //the boxes are named toselectbox,ccselectbox  and 
bccselectbox. 
!               var $destboxes;
!               //@param contactquery this is an array that holds the parameters
!               //to make a query for  the contacts class. The contact class 
takes
!               //as parameters: integers: start,offset. The cols array that 
has the fields that should be returned.
!               //The query string that returns whatever matches the given 
string for the fields provided
!               //the filter string to match against non contact fields. The 
sort boolean and the extra sort_by parameter
!               //to sort by a given field.
!               var $contactquery;
!               //@param queryresult its the array with actual user data that 
we have gotten from contacts
!               var $queryresults;
!               //@param cachestate Its an internal var to tell us if we should 
expire the cache
!               var $cachestate="dirty";
!               var $debug = False;
!               //@param result Which has an array of results from querying the 
contacts backend.
!               var $result;
!               //@param mass_query_cols Is an array that tells the backends 
which fields to get from the
!               //contacts backend for FULL QUERIES. Full queries are made upon 
construction of this
!               //object. They are different from single queries in that full 
queries are supposed to get
!               //A list of contacts, each having their own fields given by 
this array.
!               var $mass_query_cols = array (
!                               'title'     => 'title',
!                               'n_given'    => 'n_given',
!                               'n_family'   => 'n_family',
!                               'email'      => 'email',
!                               'org_name' => 'org_name',
!                               'email_home'  => 'email_home'
!                               );
!               //@param single_query_cols This array is similar to the one 
above except this is for
!               //SINGLE QUERIES. This queries happen when you call the 
get_userdata method to get
!               //the record of a single entry in the contacts backend
!               //To add a field to fetch back from userdata
!               //u need to add the field u want here
!               //Also, in class.uijsaddressbook there is a translation array 
that has
!               //the names of each field in english. Use it to decide what 
values to add here
!               var $single_query_cols =  array (
!                               'title'     => 'title',
!                               'n_given'    => 'n_given',
!                               'n_family'   => 'n_family',
!                               'org_name' => 'org_name',
!                               'tel_work' => 'tel_work',
!                               'cat_id'  => 'cat_id'
!                               );
!               //@param use_session Not used at the moment
!               var $use_session=true;
! 
!               //@function bojsaddressbook 
!               //@abstract This class's contructor
!               //@param contactquery Its a query array in the form explained 
as:
!               //      order: Must be equal to the order in which you want the 
query...ASC or DESC
!               //      categories: Must have the categories string as 
constrained by the categories class
!               //                  ,1,2 or 1,2 are valid strings to say, 
category number 1 and 2
!               //      filter: This is a whole parameter in itself, will 
explain bellow in the parse_contactquery discussion
!               //      query: Freestyle query to match against any fields in a 
mass query
!               //      sort:  The field to sort by.... n_give will sort by 
name, for example
!               //      directory_uid: This field may be empty but, if it has a 
number in it
!               //      we will search in the contacts owned by the user whose 
uid matches this value
!               //@param queryresults UNUSED, might use it for caching state 
purposes later on
!               //@discussion 
!               //This function checks its cache. All parameters are optional. 
If called with no parameters
!               //the class will assume all that it needs is in the cache and 
will get it from there
!               //If a contactquery value is supplied, the class will desregard 
its cache and go fetch the whole
!               //query again. 
!               //To be truth, its actually quite stupid and we should be using 
more intelligence to decide
!               //if the cache is stale.... for example, caching the result 
form parse_contactquery and
!               //compare it with what results from parsing the incoming 
contactquery. If its the same,
!               //we shouldnt refetch.
!               function bojsaddressbook($contactquery="",$queryresults="")
!               {
!                       $this->contactsobject=CreateObject('phpgwapi.contacts');
!                       //the idea is that here, right here, nowhere else, do 
we decide what to keep
!                       //from the cache and what to go and query again
!                               $data=$this->read_sessiondata();
!                               if(is_array($contactquery))
!                               {
!                                       
$this->parse_contactquery($contactquery);
!                                       
$data['result']=$this->contactsobject->read($this->contactquery['start'],$this->contactquery['offset'],
!                                                       
$this->mass_query_cols,$this->contactquery['query'],
!                                                       
$this->contactquery['filter'],
!                                                       
$this->contactquery['sort'],
!                                                       $this->sortby);
!                                       $this->save_sessiondata($data);
!                               }
! 
!                               $this->result=$data['result'];
! 
!               }
!               //@function parse_contactquery 
!               //@param contactquery As described in the constructor's param
!               //@abstract Parses an incoming contactquery into what the 
contacts backend
!               //likes to see in a query
!               //@discussion This ignores the start and offset parameters as 
they are somehow
!               //obsolete in this version. Its strange, i know, but maybe we 
will want to optimize
!               //later what we want to fetch from the contacts backend by this 
parameters so all other
!               //functions respect and think that thisone builds the start and 
offset
!               function parse_contactquery($contactquery)
!               {
!                       $notfirsttime=False;
! //                    while(list($k,$v)=each($contactquery))
!                       foreach ($contactquery as $k => $v)
!                       {
!                               switch($k)
!                               {
!                                       case 'filter':
!                                               {
!                                                       switch($v)
!                                                       {
! 
!                                                               case 'none':
!                                                                       {
!                                                                               
$this->contactquery['filter']=$this->contactquery['filter'].
!                                                                               
        ($notfirsttime ? "," :"")."tid=n";
!                                                                               
$notfirsttime=True;
!                                                                               
break;
!                                                                       }
!                                                               case 
'user_only':
!                                                                       {
!                                                                               
$this->contactquery['filter']=$this->contactquery['filter'].
!                                                                               
        ($notfirsttime ? "," :"").
!                                                                               
        'owner='.$GLOBALS['phpgw_info']['user']['account_id'];
!                                                                               
$notfirsttime=True;
!                                                                               
break;
!                                                                       }
!                                                               case 
'directory':
!                                                                       {
!                                                                               
if(!$contactquery['directory_uid'])
!                                                                               
{
! 
!                                                                               
        $this->contactquery['filter']=$this->contactquery['filter'].
!                                                                               
                ($notfirsttime ? "," :"")."tid=p";
!                                                                               
}
!                                                                               
else
!                                                                               
{
!                                                                               
         $this->contactquery['filter']=$this->contactquery['filter'].
!                                                                               
                      ($notfirsttime ? "," :"")."owner=".
!                                                                               
                      $contactquery['directory_uid'];
!                                                                               
}
!                                                                               
$notfirsttime=True;
!                                                                               
break;
!                                                                       }
!                                                               case 'private':
!                                                                       {
!                                                                               
$this->contactquery['filter']=$this->contactquery['filter'].
!                                                                               
        ($notfirsttime ? "," :"").'owner='.
!                                                                               
        $GLOBALS['phpgw_info']['user']['account_id'].
!                                                                               
        ',access=private';
!                                                                               
$notfirsttime=True;
!                                                                               
break;
!                                                                       }
!                                                       }
!                                                       $notfirsttime=false;
!                                                       break;
!                                               }
!                                       case 'categories':
!                                               {
!                                                       if($v)
!                                                       {
!                                                               
$this->contactquery['filter']=$this->contactquery['filter'].
!                                                                               
 ($notfirsttime ? "," :"")."cat_id=".$v;
!                                                       $notfirsttime=true;
!                                                       }
!                                                       break;
!                                               }
!                                       case 'query':
!                                               {
!                                                       if($v)
!                                                       {
!                                                               
$this->contactquery['query']=$v;
!                                                       }
!                                               }
!                                                       
!                               }//end switch
!                       }//end while
!               //      print "<BR> built query";
!               //      print_r($this->contactquery);
!               }//end function
!               
!               //@function forget_query
!               //@discussion
!               //Causes the class to forget its query cache. This does not 
forget the destination boxes, only
!               //the mass query
!               function forget_query()
!               {
!                               $this->save_sessiondata("");
!               }
!               //@function recordinfo
!               //@param addy_id The record's id in the contacts backend
!               //@abstract Gets the record info descirbed by the 
single_query_cols array
!               //@discussion This returns an array of field=>value that 
actually has
!               //the whole record for the given id. As u can see, the values 
it gets back are
!               //given by the single_query_cols attribute which u can change 
to get more data
!               function recordinfo($addy_id)
!               {
!                       $entry = 
$this->contactsobject->read("","",$this->single_query_cols,"","id=$addy_id");
!                       if(!$entry[0])
!                       {
!                               return false;
!                       }
!                       return $entry[0];       
!               }
!               //@function save_destboxes
!               //@param destboxes The array of destbox arrays that we want 
saveed in the cache
!               //@discussion This function saves the destboxes into the cache
!               function save_destboxes($destboxes)
!               {
!                       
!                       $this->save_sessiondata($destboxes,"destboxes");
!               }
!               //@function get_destboxes
!               //@abstract Function to get the destination boxes... .this 
parameter should exlusively be gotten this way
!               //@discussion This function sees if we have any destboxes 
present in the destboxes attribute
!               //if we do, it returns that, if we dont, it gets them from 
cache.
!               
!               function get_destboxes()
!               {
!                       if(!is_array($this->destboxes) || 
(count($this->destboxes)<1) )
!                       {
!                               
$this->destboxes=$this->read_sessiondata("destboxes");
!                       }
!                       if(is_array($this->destboxes))
!                       {
!                               return $this->destboxes;
!                       }
!                       
!                       return false;
!               }
!               //@function forget_destbox
!               //@param destboxname The name of the destbox which serves as 
key to the destboxes array
!               //@abstract Will unset the live destbox corresponding to 
destboxname
!               //@discussion 
!               //Note that this function will not forget the destbox from the 
cache... i thought it
!               //a bit unneded for the particular application since i wanted 
this function to 
!               //iterate through the destboxes array and unset them one by 
one. This means that
!               //thisone only operates on real, already in memory (not in 
cache) destboxes.
!               //For the cache to reflect this change, you need to 
$obj->save_destboxes($this->destboxes)
!               //after calling this.
!               function  forget_destbox($destboxname)
!               {
!                       $this->get_destboxes();
!                       if(is_array($this->destboxes[$destboxname]))  
!                       {
!                               unset($this->destboxes[$destboxname]); 
!                               return $this->destboxes;
!                       }  
!                       return false;
!                       
!               }
!               //@function forget_destboxes
!               //@abstract Will forget all the destboxes, then save the 
changes to the cache
!               
!               function forget_destboxes()
!               {
!                       if($this->get_destboxes())
!                       {
!                               $destboxesnames=array_keys($this->destboxes);
!                               foreach($destboxesnames as $name)
!                               {
!                                       $this->forget_destbox($name);
!                               }
!                               $this->set_destboxes($this->destboxes);
!                       }
!               }
!               //@function set_destboxes
!               //@param aryboxes The new destboxes array
!               //@param deleted An array of booleans with keys similar to the 
destboxes array
!               //If a given destination box has a true entry here, it will be 
removed in the cache
!               //@abstract This functions saves in cache the destination boxes 
values
!               //@discussion Note that this function can be mistaken by the 
save_destboxes function.
!               //Different thigs completely. This one takes an array of 
destboxes. The keys to this array
!               // are the destboxes names. Inside each array, there are uid => 
name pairs. Note the absence
!               //of an email field. The incoming aryboxes have NO email field 
whatsoever.
!               //What we do here, is try and find the corresponding email 
fields either in cache or directly
!               //in our mass query cache and set that field correctly to save 
it in cache
!               //This function is redundant, inneficient and dead slow. Not to 
say complex and unreadable
!               //Please change this please please please.
!               //Previous disclaimer said, it works now, and will release this 
way.
!               function set_destboxes($aryboxes,$deleted='')
!               {
!                       //print_r($aryboxes);
! //                    print "<br> SAVed DESTBOXES <br>";
!                       //We get our own destboxes from the cache
!                       $saveddestboxes=$this->get_destboxes();
!                       $GLOBALS['debug_timer_start']=perfgetmicrotime();
! //                    print_r($saveddestboxes);
!                       
!                       $found=false;
!                       //We iterate into each box
!                       //while(list($ak,$li)=each($aryboxes))
!                       
!                       foreach($aryboxes as $ak => $li)
!                       {
! //                            print $ak." ".$li."<BR>";
! //                            print_r($li);
! //                            print "<br>";
!                               //We make shure this box has an array in it
!                               if($aryboxes[$ak])
!                               {
!                                       //We iterate into the incoming box to 
search
!                                       //for its values in the cache
!                               //      
while(list($numary,$ary)=each($aryboxes[$ak]))
!                                       foreach($aryboxes[$ak] as $numary => 
$ary)
!                                       {
! //                                            print "<br> Iterating aryboxes 
$numary";        
! //                                            print_r($ary);
!                                               list($id,$name)=each($ary);
!                                               //Look for this record in the 
cached destboxes
!                                               
if(is_array($saveddestboxes[$ak]))
!                                               {
!                                                       //Well, we found that 
we have this destboxed cached so
!                                                       //now we will iterate 
through that
!                                                       
//while(list($numarysave,$arysave)=each($saveddestboxes[$ak]))
!                                                       
foreach($saveddestboxes[$ak] as $numarysave => $arysave)
!                                                       {
!                                                               //We will try 
and get each addressbook key
!                                                               //out of the 
cached destbox
!                                                               
list($sid,$sname)=each($arysave);
!                                                               
! //                                                            print "<br> 
Iterating destboxes $id -> $name / $sid $sname";    
!                                                               //So we can 
compare it and set the email field in it
!                                                               if($id==$sid)
!                                                               {
! //                                                                    print 
"<br> found $id in $ak";
! //                                                                    print 
"<br> seting mail to $arysave[email]";
!                                                                       
$ary['email']=$arysave['email'];
!                                                                       
$aryboxes[$ak][$numary]=$ary;
!                                                                       
!                                                                       
$found=true;
!                                                               }
! 
!                                                       }
!                                                       
reset($saveddestboxes[$ak]);
!                                               }
!                                               //couldnt find it in saved 
destboxes, lookfor ir in result
!                                               //This redundant POSH makes me 
angry....
!                                               //Now we look into our names 
cache...im not shure why, if i 
!                                               //try and evade this search 
when i find it in the cache, 
!                                               //it all goes borken
!                                               //We iterate into the query 
cache
!                                       //      
while(list($num,$record)=each($this->result))
!                                               foreach($this->result as $num 
=> $record)
!                                               {
! //                                                    print "<br> Iterating 
results $id   ---> $name <br>$record[id]---> $record[email]";
!                                                       //Found what we are 
looking for
!                                                       if($id == $record["id"])
!                                                       {
!                                                               //Set the mail 
record to what it should be
! //                                                            print "<br> 
seting mail to $record[email] <br>";
!                                                               
$ary['email']=($record["email"] ? $record["email"] : $record["home_email"]);
!                                                               
$aryboxes[$ak][$numary]=$ary;
!                                                               
$retboxes[$ak][$id]['email']= $ary['email'];
!                                                               
$retboxes[$ak][$id]['name']= $name;
!                                                               
!                                                       }
!                                               }
!                                               reset($this->result);
!                                               $found=false;
!                                       }
! 
!                               }
!                               elseif(!$deleted[$ak])
!                               {
! //                                    print "<br>Saving $ak from destination 
data $deleted[$ak]<br>";
! //                                    print_r($deleted);
!                                       //Delete the destboxes that need 
deletion
!                                       $aryboxes[$ak]=$saveddestboxes[$ak];
!                               }
!                       }
! //                    print "<br>modified<br>";
! //                            print_r($aryboxes);
!                               reset($aryboxes);
!                       //Save the resulting destboxes
!                       $GLOBALS['debug_timer_stop']=perfgetmicrotime();
! //                    print("<BR><B>Set destboxes in ". 
($GLOBALS['debug_timer_stop'] - $GLOBALS['debug_timer_start']) . " seconds.");
!                       $this->save_destboxes($aryboxes);
!                       //We return what we couldnt find in cache so the caller 
can evaluate
!                       //if he needs to refresh his info...
!                       return $retboxes; 
!                       
!               }
!               //@function save_sessiondata
!               //@param data The data to be saved
!               //@param location An extra string to save data in diferent 
locations
!               //@abstract Saves the data into the app session cache
!               //@discussion
!               //If you pass it no location, it will save into jsbook_data
!               //If you do, it will save into jsbook_data_location
!               //This is important cause we sometimes only need the destboxes 
and not
!               //the whole queries so we only get what we need
!               function save_sessiondata($data,$location="")
!               {
!                       if ($this->use_session)
!                       {
!                               
$GLOBALS['phpgw']->session->appsession('session_data',"jsbook_data".($location 
? '_'.$location :""),$data);
!                       }
!                       if($this->debug)
!                       {
!                               echo '<br>Saving: ';
!                               _debug_array($data);
!                       }
!               }
!               //@function read_sessiondata
!               //@param location
!               //@abstract gets data out of the appsesion cache
!               //@discussion
!               //The location field behaves like the one described in 
save_sessiondata
! 
!               function read_sessiondata($location="")
!               {
!                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','jsbook_data'.($location 
? '_'.$location :""));
!                       if($this->debug)
!                       {
!                               echo '<br>Read: ';
!                               _debug_array($data);
!                       }
!                       return $data;
!               }
!               
!       }
! ?>
--- 1,519 ----
! <?php
! /**************************************************************************\
!  * phpGroupWare - Todo list                                                 *
!  * http://www.phpgroupware.org                                              *
!  * Written by Alex Borges <address@hidden>                          *
!  * Low Level Design also by    Dave Hall address@hidden                       
   *
!  * UI Design and market research by Gerardo Ramirez address@hidden
!  *-----------------------------------------------                          *
!  *  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.                                              *
!  \**************************************************************************/
! 
! /*!
!   @class bojsaddressbiij
!   @abstract logic for the javascript addressbook is here
!   @author Lex 
!   @ discussion  Understand that
!   this is my first attempt to a bo,ui pair of objects
!   that will do the job. I turned to do this because
!   this thingie has to be available for use by all the
!   phpgw 0.9.14 apps.
!   My approach is to use abstraction as much as possible.
!   This class will handle all data. DATA you hear? 
!   This means that the state of the abstraction we call
!   the cool addressbook chooser is here.... THE STATE!
!   Nothing webish about this file. This file will no receive
!   ever variables from HTTP_POST or GET. That is for the UI class
!   to handle. This class has methods that receive parameters so you 
!   can use it from anyware.
!  */
! 
!        class bojsaddressbook
!       {
!               var $soaddressbook;
!               //@param $contacts phpgwapi contacts object
!               var $contacts;
!               //@param destboxes array that has the state of the three 
possible destination boxes
!               //this thing will have the title of the destination boxes and 
their content
!               //this class is session cache enabled. When you solicit the 
content of 
!               //this boxes this class may get it from cache if it thinks its 
necesary
!               //the boxes are named toselectbox,ccselectbox  and 
bccselectbox. 
!               var $destboxes;
!               //@param contactquery this is an array that holds the parameters
!               //to make a query for  the contacts class. The contact class 
takes
!               //as parameters: integers: start,offset. The cols array that 
has the fields that should be returned.
!               //The query string that returns whatever matches the given 
string for the fields provided
!               //the filter string to match against non contact fields. The 
sort boolean and the extra sort_by parameter
!               //to sort by a given field.
!               var $contactquery;
!               //@param queryresult its the array with actual user data that 
we have gotten from contacts
!               var $queryresults;
!               //@param cachestate Its an internal var to tell us if we should 
expire the cache
!               var $cachestate="dirty";
!               var $debug = False;
!               //@param result Which has an array of results from querying the 
contacts backend.
!               var $result;
!               //@param mass_query_cols Is an array that tells the backends 
which fields to get from the
!               //contacts backend for FULL QUERIES. Full queries are made upon 
construction of this
!               //object. They are different from single queries in that full 
queries are supposed to get
!               //A list of contacts, each having their own fields given by 
this array.
!               var $mass_query_cols = array (
!                               'per_title'     => 'per_title',
!                               'per_first_name'    => 'per_first_name',
!                               'per_last_name'   => 'per_last_name',
!                               'org_name' => 'org_name',
!                               'contact_id'  => 'contact_id'
!                               );
!               //@param single_query_cols This array is similar to the one 
above except this is for
!               //SINGLE QUERIES. This queries happen when you call the 
get_userdata method to get
!               //the record of a single entry in the contacts backend
!               //To add a field to fetch back from userdata
!               //u need to add the field u want here
!               //Also, in class.uijsaddressbook there is a translation array 
that has
!               //the names of each field in english. Use it to decide what 
values to add here
!               var $single_query_cols =  array (
!                               'per_title'     => 'per_title',
!                               'per_first_name'    => 'per_first_name',
!                               'per_last_name'   => 'per_last_name',
!                               'org_name' => 'org_name',
!                               'contact_id'  => 'contact_id'
!                               
!                               );
!               var $commtypes= array(
!                               'work email' => 'work email'
!                               );
!               //@param use_session Not used at the moment
!               var $use_session=true;
!               var $filters;
! 
!               //@function bojsaddressbook 
!               //@abstract This class's contructor
!               //@param contactquery Its a query array in the form explained 
as:
!               //      order: Must be equal to the order in which you want the 
query...ASC or DESC
!               //      categories: Must have the categories string as 
constrained by the categories class
!               //                  ,1,2 or 1,2 are valid strings to say, 
category number 1 and 2
!               //      filter: This is a whole parameter in itself, will 
explain bellow in the parse_contactquery discussion
!               //      query: Freestyle query to match against any fields in a 
mass query
!               //      sort:  The field to sort by.... n_give will sort by 
name, for example
!               //      directory_uid: This field may be empty but, if it has a 
number in it
!               //      we will search in the contacts owned by the user whose 
uid matches this value
!               //@param queryresults UNUSED, might use it for caching state 
purposes later on
!               //@discussion 
!               //This function checks its cache. All parameters are optional. 
If called with no parameters
!               //the class will assume all that it needs is in the cache and 
will get it from there
!               //If a contactquery value is supplied, the class will desregard 
its cache and go fetch the whole
!               //query again. 
!               //To be truth, its actually quite stupid and we should be using 
more intelligence to decide
!               //if the cache is stale.... for example, caching the result 
form parse_contactquery and
!               //compare it with what results from parsing the incoming 
contactquery. If its the same,
!               //we shouldnt refetch.
!               function bojsaddressbook($contactquery="",$queryresults="")
!               {
!                       $this->contactsobject=CreateObject('phpgwapi.contacts');
! 
!                       $this->grants = 
$GLOBALS['phpgw']->acl->get_grants('addressbook');
!                       if(!isset($GLOBALS['owner']))
!                       {
!                               $GLOBALS['owner'] = 0;
!                       }
! 
!                       $this->owner = $GLOBALS['owner'];
! 
!                       if(!isset($this->owner) || !$this->owner)
!                       {
!                               $this->owner = 
$GLOBALS['phpgw_info']['user']['account_id'];
!                               /* echo $this->owner; */
!                               $this->rights = PHPGW_ACL_READ + PHPGW_ACL_ADD 
+ PHPGW_ACL_EDIT + PHPGW_ACL_DELETE + 16;
!                               /* echo $rights; */
!                       }
!                       else
!                       {
!                               if($this->grants[$this->owner])
!                               {
!                                       $this->rights = 
$this->grants[$this->owner];
!                                       if (!($this->rights & PHPGW_ACL_READ))
!                                       {
!                                               $this->owner = 
$GLOBALS['phpgw_info']['user']['account_id'];
!                                               $this->rights = PHPGW_ACL_READ 
+ PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE + 16;
!                                       }
!                               }
!                       }
! 
!                       //the idea is that here, right here, nowhere else, do 
we decide what to keep
!                       //from the cache and what to go and query again
!                               $data=$this->read_sessiondata();
!                               if(is_array($contactquery))
!                               {
!                                       
$this->parse_contactquery($contactquery);
!                                       if(is_array($this->filters))
!                                       {
! //                                            print '<BR><B>NORMAL 
QUERY</B><BR>';
!                                               
$data['result']=$this->contactsobject->get_persons(
!                                                               
$this->mass_query_cols,'','','','',
!                                                               $this->filters
!                                                               );
!                                       }
!                                       elseif($this->filters == 'directory')
!                                       {
! //                                            print '<BR><B>DIRECTORY 
QUERY</B><BR>';
!                                               
$data['result']=$this->contactsobject->get_system_contacts($this->mass_query_cols);
!                                       }
!                                       if(count($data['result']) > 1)
!                                       {
!                                               foreach ($data['result'] as $id)
!                                               {
!                                                       $contacts[] = 
$id['contact_id'];
!                                               }
!                                               //                              
        print '<BR><B>Fed to comm_contact'.var_export($contacts).'</B><BR>';
! 
!                                               $entries_comm = 
$this->contactsobject->get_comm_contact_data($contacts, $this->commtypes);
! 
!                                               
$data['result']=$this->merge_emails_to_results($data['result'],$entries_comm);
!                                               //print '<BR><B>entries 
com'.var_export($entries_comm).'</B><br>';
!                                       }
!                                       
! //                                    print '<B><BR>DATA<BR></B>';
! //                                    print_r($data);
!                                       $this->save_sessiondata($data);
!                               }
! 
! 
!                               $this->result=$data['result'];
! 
!               }
!               function merge_emails_to_results($result,$entries_comm)
!               {
!                       reset($result);
!                       while(list($rk,$rv)=each($result))
!                       {
!                               while (list($ek,$ev)=each($entries_comm))
!                               {
!                                       //macth comtype <-> contact
!                                       
if(($ev['comm_contact_id']==$rv['contact_id']) && 
$ev['comm_description']=='work email')
!                                       {
! //                                            print '<BR><B>Done merge for 
'."$rv[email]=$ev[comm_data]".'</B><BR>';
!                                               $rv['email']=$ev['comm_data'];
!                                               $ret[$rk]=$rv;
!                                       }
!                               }
!                               reset($entries_comm);
!                       }
!                       return $ret;    
!               }
!               //@function parse_contactquery 
!               //@param contactquery As described in the constructor's param
!               //@abstract Parses an incoming contactquery into what the 
contacts backend
!               //likes to see in a query
!               //@discussion This ignores the start and offset parameters as 
they are somehow
!               //obsolete in this version. Its strange, i know, but maybe we 
will want to optimize
!               //later what we want to fetch from the contacts backend by this 
parameters so all other
!               //functions respect and think that thisone builds the start and 
offset
!                function parse_contactquery($contactquery)
!               {
!                       $notfirsttime=False;
! //                    while(list($k,$v)=each($contactquery))
!               //      print '<BR><B>Contactyquery</B><BR>';
!               //      print_r($contactquery);
!                       foreach ($contactquery as $k => $v)
!                       {
!                               switch($k)
!                               {
!                                       case 'filter':
!                                               {
!                                                       switch($v)
!                                                       {
! 
!                                                               case 'none':
!                                                                       {
!                                                                               
$this->filters = array('owner' => array_keys(array_keys($this->grants)));
!                                                                       }
!                                                               case 
'user_only':
!                                                                       {
!                                                                               
$this->filters= array('owner' => $GLOBALS['phpgw_info']['user']['account_id']);
!                                                                               
break;
!                                                                       }
!                                                               case 
'directory':
!                                                                       {
!                                                                               
$this->filters='directory';
!                                                                               
$notfirsttime=True;
!                                                                               
break;
!                                                                       }
!                                                               case 'private':
!                                                                       {
!                                                                               
$this->filters=array(
!                                                                               
'owner' => $GLOBALS['phpgw_info']['user']['account_id'],
!                                                                               
'access' => 'private');
!                                                                               
break;
!                                                                       }
!                                                               case 
'directory':
!                                                                       {
!  
!                                                                               
$notfirsttime=True;
!                                                                               
break;
!                                                                       }
!                                                       }
!                                                       $notfirsttime=false;
!                                                       break;
!                                               }
!                                       case 'categories':
!                                               {
!                                                       if($v)
!                                                       {
!                                                       $notfirsttime=true;
!                                                       }
!                                                       break;
!                                               }
!                                       case 'query':
!                                               {
!                                                       if($v)
!                                                       {
!                                                       }
!                                               }
!                                                       
!                               }//end switch
!                       }//end while
! //                    print "<BR> built query";
! //                    print_r($this->filters);
!               }//end function
!               
!               //@function forget_query
!               //@discussion
!               //Causes the class to forget its query cache. This does not 
forget the destination boxes, only
!               //the mass query
!               function forget_query()
!               {
!                               $this->save_sessiondata("");
!               }
!               //@function recordinfo
!               //@param addy_id The record's id in the contacts backend
!               //@abstract Gets the record info descirbed by the 
single_query_cols array
!               //@discussion This returns an array of field=>value that 
actually has
!               //the whole record for the given id. As u can see, the values 
it gets back are
!               //given by the single_query_cols attribute which u can change 
to get more data
!               function recordinfo($addy_id)
!               {
!                       $entry = $this->contactsobject->get_persons(
!                       $this->single_query_cols,"",array("contact_id" => 
"$addy_id"));
!                       if(!$entry[0])
!                       {
!                               return false;
!                       }
!                       return $entry[0];       
!               }
!               //@function save_destboxes
!               //@param destboxes The array of destbox arrays that we want 
saveed in the cache
!               //@discussion This function saves the destboxes into the cache
!               function save_destboxes($destboxes)
!               {
!                       
!                       $this->save_sessiondata($destboxes,"destboxes");
!               }
!               //@function get_destboxes
!               //@abstract Function to get the destination boxes... .this 
parameter should exlusively be gotten this way
!               //@discussion This function sees if we have any destboxes 
present in the destboxes attribute
!               //if we do, it returns that, if we dont, it gets them from 
cache.
!               
!               function get_destboxes()
!               {
!                       if(!is_array($this->destboxes) || 
(count($this->destboxes)<1) )
!                       {
!                               
$this->destboxes=$this->read_sessiondata("destboxes");
!                       }
!                       if(is_array($this->destboxes))
!                       {
!                               return $this->destboxes;
!                       }
!                       
!                       return false;
!               }
!               //@function forget_destbox
!               //@param destboxname The name of the destbox which serves as 
key to the destboxes array
!               //@abstract Will unset the live destbox corresponding to 
destboxname
!               //@discussion 
!               //Note that this function will not forget the destbox from the 
cache... i thought it
!               //a bit unneded for the particular application since i wanted 
this function to 
!               //iterate through the destboxes array and unset them one by 
one. This means that
!               //thisone only operates on real, already in memory (not in 
cache) destboxes.
!               //For the cache to reflect this change, you need to 
$obj->save_destboxes($this->destboxes)
!               //after calling this.
!               function  forget_destbox($destboxname)
!               {
!                       $this->get_destboxes();
!                       if(is_array($this->destboxes[$destboxname]))  
!                       {
!                               unset($this->destboxes[$destboxname]); 
!                               return $this->destboxes;
!                       }  
!                       return false;
!                       
!               }
!               //@function forget_destboxes
!               //@abstract Will forget all the destboxes, then save the 
changes to the cache
!               
!               function forget_destboxes()
!               {
!                       if($this->get_destboxes())
!                       {
!                               $destboxesnames=array_keys($this->destboxes);
!                               foreach($destboxesnames as $name)
!                               {
!                                       $this->forget_destbox($name);
!                               }
!                               $this->set_destboxes($this->destboxes);
!                       }
!               }
!               //@function set_destboxes
!               //@param aryboxes The new destboxes array
!               //@param deleted An array of booleans with keys similar to the 
destboxes array
!               //If a given destination box has a true entry here, it will be 
removed in the cache
!               //@abstract This functions saves in cache the destination boxes 
values
!               //@discussion Note that this function can be mistaken by the 
save_destboxes function.
!               //Different thigs completely. This one takes an array of 
destboxes. The keys to this array
!               // are the destboxes names. Inside each array, there are uid => 
name pairs. Note the absence
!               //of an email field. The incoming aryboxes have NO email field 
whatsoever.
!               //What we do here, is try and find the corresponding email 
fields either in cache or directly
!               //in our mass query cache and set that field correctly to save 
it in cache
!               //This function is redundant, inneficient and dead slow. Not to 
say complex and unreadable
!               //Please change this please please please.
!               //Previous disclaimer said, it works now, and will release this 
way.
!               function set_destboxes($aryboxes,$deleted='')
!               {
!                       //print_r($aryboxes);
! //                    print "<br> SAVed DESTBOXES <br>";
!                       //We get our own destboxes from the cache
!                       $saveddestboxes=$this->get_destboxes();
!                       $GLOBALS['debug_timer_start']=perfgetmicrotime();
! //                    print_r($saveddestboxes);
!                       
!                       $found=false;
!                       //We iterate into each box
!                       while(list($ak,$li)=each($aryboxes))
!                       {
! //                            print $ak." ".$li."<BR>";
! //                            print_r($li);
! //                            print "<br>";
!                               //We make shure this box has an array in it
!                               if($aryboxes[$ak])
!                               {
!                                       //We iterate into the incoming box to 
search
!                                       //for its values in the cache
!                                       
while(list($numary,$ary)=each($aryboxes[$ak]))
!                                       {
! //                                            print "<br> Iterating aryboxes 
$numary";        
! //                                            print_r($ary);
!                                               list($id,$name)=each($ary);
!                                               //Look for this record in the 
cached destboxes
!                                               
if(is_array($saveddestboxes[$ak]))
!                                               {
!                                                       //Well, we found that 
we have this destboxed cached so
!                                                       //now we will iterate 
through that
!                                                       
while(list($numarysave,$arysave)=each($saveddestboxes[$ak]))
!                                                       {
!                                                               //We will try 
and get each addressbook key
!                                                               //out of the 
cached destbox
!                                                               
list($sid,$sname)=each($arysave);
!                                                               
! //                                                            print "<br> 
Iterating destboxes $id -> $name / $sid $sname";    
!                                                               //So we can 
compare it and set the email field in it
!                                                               if($id==$sid)
!                                                               {
! //                                                                    print 
"<br> found $id in $ak";
! //                                                                    print 
"<br> seting mail to $arysave[email]";
!                                                                       
$ary['email']=$arysave['email'];
!                                                                       
$aryboxes[$ak][$numary]=$ary;
!                                                                       
!                                                                       
$found=true;
!                                                               }
! 
!                                                       }
!                                                       
reset($saveddestboxes[$ak]);
!                                               }
!                                               //couldnt find it in saved 
destboxes, lookfor ir in result
!                                               //This redundant POSH makes me 
angry....
!                                               //Now we look into our names 
cache...im not shure why, if i 
!                                               //try and evade this search 
when i find it in the cache, 
!                                               //it all goes borken
!                                               //We iterate into the query 
cache
!                                               
while(list($num,$record)=each($this->result))
!                                               {
! //                                                    print "<br> Iterating 
results $id   ---> $name <br>$record[id]---> $record[email]";
!                                                       //Found what we are 
looking for
!                                                       if($id == 
$record["contact_id"])
!                                                       {
!                                                               //Set the mail 
record to what it should be
! //                                                            print "<br> 
seting mail to $record[email] <br>";
!                                                               
$ary['email']=($record["email"] ? $record["email"] : $record["home_email"]);
!                                                               
$aryboxes[$ak][$numary]=$ary;
!                                                               
$retboxes[$ak][$id]['email']= $ary['email'];
!                                                               
$retboxes[$ak][$id]['name']= $name;
!                                                               
!                                                       }
!                                               }
!                                               reset($this->result);
!                                               $found=false;
!                                       }
! 
!                               }
!                               elseif(!$deleted[$ak])
!                               {
! //                                    print "<br>Saving $ak from destination 
data $deleted[$ak]<br>";
! //                                    print_r($deleted);
!                                       //Delete the destboxes that need 
deletion
!                                       $aryboxes[$ak]=$saveddestboxes[$ak];
!                               }
!                       }
! //                    print "<br>modified<br>";
! //                            print_r($aryboxes);
!                               reset($aryboxes);
!                       //Save the resulting destboxes
!                       $GLOBALS['debug_timer_stop']=perfgetmicrotime();
! //                    print("<BR><B>Set destboxes in ". 
($GLOBALS['debug_timer_stop'] - $GLOBALS['debug_timer_start']) . " seconds.");
!                       $this->save_destboxes($aryboxes);
!                       //We return what we couldnt find in cache so the caller 
can evaluate
!                       //if he needs to refresh his info...
!                       return $retboxes; 
!                       
!               }
!               //@function save_sessiondata
!               //@param data The data to be saved
!               //@param location An extra string to save data in diferent 
locations
!               //@abstract Saves the data into the app session cache
!               //@discussion
!               //If you pass it no location, it will save into jsbook_data
!               //If you do, it will save into jsbook_data_location
!               //This is important cause we sometimes only need the destboxes 
and not
!               //the whole queries so we only get what we need
!               function save_sessiondata($data,$location="")
!               {
!                       if ($this->use_session)
!                       {
!                               
$GLOBALS['phpgw']->session->appsession('session_data',"jsbook_".($location ? 
'_'.$location :""),$data);
!                       }
!                       if($this->debug)
!                       {
!                               echo '<br>Saving: ';
!                               _debug_array($data);
!                       }
!               }
!               //@function read_sessiondata
!               //@param location
!               //@abstract gets data out of the appsesion cache
!               //@discussion
!               //The location field behaves like the one described in 
save_sessiondata
! 
!               function read_sessiondata($location="")
!               {
!                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data','jsbook_'.($location ? 
'_'.$location :""));
!                       if($this->debug)
!                       {
!                               echo '<br>Read: ';
!                               _debug_array($data);
!                       }
!                       return $data;
!               }
!               
!       }
! ?>

Index: class.uijsaddressbook.inc.php
===================================================================
RCS file: 
/cvsroot/phpgroupware/phpgwapi/inc/Attic/class.uijsaddressbook.inc.php,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** class.uijsaddressbook.inc.php       8 Sep 2003 13:26:38 -0000       1.1.2.1
--- class.uijsaddressbook.inc.php       13 Sep 2003 07:11:42 -0000      1.1.2.2
***************
*** 1,1052 ****
! <?php
!       
/**************************************************************************\
!       * phpGroupWare -  Addressbook Chooser                                   
             *
!       * http://www.phpgroupware.org                                           
   *
!         * Written by Alex Borges <address@hidden>                          *
!       * Inherited some code from the addressbook.php file
!       * Low Level Design also by    Dave Hall address@hidden                  
        *
!       * UI Design and market research by Gerardo Ramirez address@hidden
!       *-----------------------------------------------                        
  *
!       *  This program is free software; you can redistribute it and/or modify 
it *
[...2076 lines suppressed...]
!               //As you can see, its prepared to accept some js in its
!               //innerstring parameter to be inserted in the middle of script 
tags
!               //Also, it accepts a string that is supposed to be the 
javascript call to the frameset function
!               //that tells the js framework we have outputed the data it 
queried for.
!               function final_js($innerstring,$functioncall)
!               {
!                       $retstr="<html>
!                               <head>
!                               <script language=\"javascript\">";
!                                       
!                       $close="</script>
!                               </head>
!                               <body onLoad=\"$functioncall\">
!                               </body>
!                               </html>";
!                       return $retstr.''.$innerstring.''.$close;
!                                       
!               }
!       }
! ?>





reply via email to

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