From f07fd0041de3d5ee6a0b03f38fb5a15b034b61d3 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 28 May 2001 19:48:31 +0000 Subject: [PATCH] newly created --- phpgwapi/inc/class.sbox2.inc.php | 252 +++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 phpgwapi/inc/class.sbox2.inc.php diff --git a/phpgwapi/inc/class.sbox2.inc.php b/phpgwapi/inc/class.sbox2.inc.php new file mode 100644 index 0000000000..61e79766d8 --- /dev/null +++ b/phpgwapi/inc/class.sbox2.inc.php @@ -0,0 +1,252 @@ + * + * Class for creating select boxes for addresse, projects, array items, ... * + * Copyright (C) 2000, 2001 Dan Kuykendall * + * -------------------------------------------------------------------------* + * This library is part of the phpGroupWare API * + * http://www.phpgroupware.org/api * + * ------------------------------------------------------------------------ * + * This library is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as published by * + * the Free Software Foundation; either version 2.1 of the License, * + * or any later version. * + * This library 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 Lesser General Public License for more details. * + * You should have received a copy of the GNU Lesser General Public License * + * along with this library; if not, write to the Free Software Foundation, * + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + \**************************************************************************/ + + /* $Id$ */ + + class sbox2 { + + /* + * Function: search for an id of an db-entry, eg. an address + * Parameter: $name base name for all template-vars and of the submitted vars (not to conflict with other template-var-names !!!) + * $lang_name titel of the field + * $prompt for the JavaScript prompt() + * $id_name id of previosly selected entry + * $content from id (eg. 'company: lastname, givenname' for address $id) if $id != 0, or + * array with searchresult (id's as key), if array is empty if search was unsucsessful + * Returns: array with vars to set in temaplate, the vars are: + * {doSearchFkt} Javascript Funktion, place somewhere in Template (before rest of the vars) + * {$name.'_title} button with titel $lang_name (if JS) or just $lang_name + * {$name} content of $id if != 0, or lang('use Button to search for').$lang_name + * {$name.'_nojs} searchfield + button if we have no JavaScript, else empty + * + * To use call $template->set_var(getIdSearch( ... )); + * the template should look like {doSeachFkt} {XXX_title}{XXX}{XXX_nojs} (XXX is content of $name) + * In the submitted page the vars $query_XXX and $id_XXX are set according to what is selected, see getAddress as Example + */ + + function getId($name,$lang_name,$prompt,$id_name,$content='') { + // echo "

getId('$name','$lang_name','$prompt',$id_name,'$content') ="; + global $phpgw; + + $ret['doSearchFkt'] = +''; + + $ret[$name.'_title'] = +'\n". +""; + + if (is_array($content)) { // result from search + if (!count($content)) { // search was unsuccsessful + $ret[$name] = lang('no entries found, try again ...'); + } else { + $ret[$name] = "'; + } + } else { + if ($id_name) { + $ret[$name] = $content . "\n"; + } else { + $ret[$name] = ''.lang('use Button to search for').' '.$lang_name.''; + } + } + + $ret[$name.'_nojs'] = +""; + + // print_r($ret); + + return $ret; + } + + function addr2name( $addr ) { + global $phpgw; + $name = $addr['n_family']; + if ($addr['n_given']) + $name .= ', '.$addr['n_given']; + else + if ($addr['n_prefix']) + $name .= ', '.$addr['n_prefix']; + if ($addr['org_name']) + $name = $addr['org_name'].': '.$name; + return $phpgw->strip_html($name); + } + + /* + * Function Allows you to show and select an address from the addressbook (works with and without javascript !!!) + * Parameters $name string with basename of all variables (not to conflict with the name other template or submitted vars !!!) + * $id_name id of the address for edit or 0 if none selected so far + * $query_name have to be called $query_XXX, the search pattern after the submit, has to be passed back to the function + * On Submit $id_XXX contains the selected address (if != 0) + * $query_XXX search pattern if the search button is pressed by the user, or '' if regular submit + * Returns array with vars to set for the template, set with: $template->set_var( getAddress( ... )); (see getId( )) + * + * Note As query's for an address are submitted, you have to check $query_XXX if it is a search or a regular submit (!$query_string) + */ + + function getAddress( $name,$id_name,$query_name,$title='') { + // echo "

getAddress('$name',$id_name,'$query_name','$title')

"; + global $phpgw; + + if ($id_name || $query_name) { + $contacts = createobject('phpgwapi.contacts'); + + if ($query_name) { + $addrs = $contacts->read( 0,0,'',$query_name,'','DESC','org_name,n_family,n_given' ); + $content = array( ); + while ($addrs && list( $key,$addr ) = each( $addrs )) { + $content[$addr['id']] = $this->addr2name( $addr ); + } + } else { + list( $addr ) = $contacts->read_single_entry( $id_name ); + if (count($addr)) { + $content = $this->addr2name( $addr ); + } + } + } + if (!$title) $title = lang('Addressbook'); + + return $this->getId($name,$title,lang('Pattern for Search in Addressbook'),$id_name,$content); + } + + /* + * Function Allows you to show and select an project from the projects-app (works with and without javascript !!!) + * Parameters $name string with basename of all variables (not to conflict with the name other template or submitted vars !!!) + * $id_name id of the project for edit or 0 if none selected so far + * $query_name have to be called $query_XXX, the search pattern after the submit, has to be passed back to the function + * On Submit $id_XXX contains the selected address (if != 0) + * $query_XXX search pattern if the search button is pressed by the user, or '' if regular submit + * Returns array with vars to set for the template, set with: $template->set_var( getProject( ... )); (see getId( )) + * + * Note As query's for an address are submitted, you have to check $query_XXX if it is a search or a regular submit (!$query_string) + */ + + function getProject( $name,$id_name,$query_name,$title='' ) { + echo "

getProject('$name',$id_name,'$query_name','$title')

"; + global $phpgw; + + if ($id_name || $query_name) { + $projects = createobject('projects.projects'); + if ($query_name) { + $projs = $projects->read_projects( 0,0,$query_name,'','','','',0 ); + $content = array(); + while ($projs && list( $key,$proj ) = each( $projs )) { + $content[$proj['id']] = $proj['title']; + } + } else { + list( $proj ) = $projects->read_single_project( $id_name ); + if (count($proj)) { + $content = $proj['title']; + // $customer_id = $proj['customer']; + } + } + } + if (!$title) $title = lang('Project'); + + return $this->getId($name,$title,lang('Pattern for Search in Projects'),$id_name,$content); + } + + /* + * Function: Allows to show and select one item from an array + * Parameters: $name string with name of the submitted var which holds the key of the selected item form array + * $key key of already selected item from $arr + * $arr array with items to select, eg. $arr = array ( 'y' => 'yes','n' => 'no','m' => 'maybe'); + * $no_lang if !$no_lang send items through lang() + * On submit $XXX is the key of the selected item (XXX is the content of $name) + * Returns: string to set for a template or to echo into html page + */ + + function getArrayItem($name, $key, $arr=0,$no_lang=0) { // should be in class common.sbox + if (!is_array($arr)) + $arr = array('no','yes'); + + $out = "\n"; + + return $out; + } + + function accountInfo($id,$account_data=0) { + global $phpgw; + + if (!$id) return ' '; + + if (!is_array($account_data)) { + $accounts = createobject('phpgwapi.accounts',$id); + $accounts->db = $phpgw->db; + $accounts->read_repository(); + $account_data = $accounts->data; + } + if ($this->longnames) + return $account_data['firstname'].' '.$account_data['lastname']; + + return $account_data['account_lid']; + } + + /* + * Function: Allows to select one accountname + * Parameters: $name string with name of the submitted var, which holds the account_id or 0 after submit + * $id account_id of already selected account + * $id2text($id,$acct_data) fkt that translates account_id $id in text to show + */ + + function getAccount($name,$id) { + global $phpgw; + $accounts = createobject('phpgwapi.accounts'); + $accounts->db = $phpgw->db; + $accs = $accounts->get_list('accounts'); + + $aarr = Array(lang('not assigned')); + while ($a = current($accs)) { + $aarr[$a['account_id']] = $this->accountInfo($a['account_id'],$a); + next($accs); + } + return $this->getArrayItem($name,$selected,$aarr,1); + } + }