[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] CVS: phpgroupware/addbook/inc class.addbook_contacts.
From: |
Ralf Becker <address@hidden> |
Subject: |
[Phpgroupware-cvs] CVS: phpgroupware/addbook/inc class.addbook_contacts.inc.php,NONE,1.1 class.addbook_nextmatchs.inc.php,NONE,1.1 class.boaddbook.inc.php,NONE,1.1 class.functions.inc.php,NONE,1.1 class.generic.inc.php,NONE,1.1 class.org.inc.php,NONE,1.1 class.person.inc.php,NONE,1.1 class.prefs.inc.php,NONE,1.1 class.soaddbook.inc.php,NONE,1.1 class.uiaddbook.inc.php,NONE,1.1 hook_admin.inc.php,NONE,1.1 hook_deleteaccount.inc.php,NONE,1.1 hook_preferences.inc.php,NONE,1.1 |
Date: |
Mon, 06 May 2002 11:53:43 -0400 |
Update of /cvsroot/phpgroupware/phpgroupware/addbook/inc
In directory subversions:/tmp/cvs-serv19727
Added Files:
class.addbook_contacts.inc.php
class.addbook_nextmatchs.inc.php class.boaddbook.inc.php
class.functions.inc.php class.generic.inc.php
class.org.inc.php class.person.inc.php class.prefs.inc.php
class.soaddbook.inc.php class.uiaddbook.inc.php
hook_admin.inc.php hook_deleteaccount.inc.php
hook_preferences.inc.php
Log Message:
initial import of address@hidden's new addressbook
--- NEW FILE ---
<?php
/**************************************************************************\
* phpGroupWare Application - addbook
*
* http://www.phpgroupware.org
*
* Written by Heiko Schwarzenberg <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 addbook_contacts
{
var $person='phpgw_addbook_person_main';
var $org='phpgw_addbook_org_main';
var $meta='phpgw_addbook_meta';
var $address='phpgw_addbook_address';
var $ocontact='phpgw_addbook_ocontacts';
var $pcontact='phpgw_addbook_pcontacts';
var $contacts='phpgw_addbook_contacts';
var $relation='phpgw_addbook_relation';
var $grants = '';
function addbook_contacts($useacl=True)
{
//maps the names used in the preferences to the real
field names in the db
$this->map_fields = array(
'p_title' => 'title',
'p_first_name' => 'first_name',
'p_last_name' => 'last_name',
'p_middle' => 'middle',
'p_birthday' => 'birthday',
'p_gender' => 'gender',
'p_job' => 'job',
'p_organization'=> 'organization',
'p_street' => 'street',
'p_po_box' => 'po_box',
'p_postal_code' => 'postal_code',
'p_city' => 'city',
'p_state' => 'state',
'p_country' => 'country',
'p_pemail' => 'p_email',
'p_bemail' => 'b_email',
'p_pphone' => 'p_phone',
'p_bphone' => 'b_phone',
'p_fax' => 'fax',
'p_mobile' => 'mobile',
'o_name' => 'name',
'o_belongs_to' => 'belongs_to',
'o_street' => 'street',
'o_po_box' => 'po_box',
'o_postal_code' => 'postal_code',
'o_city' => 'city',
'o_state' => 'state',
'o_country' => 'country',
'o_email' => 'email',
'o_phone' => 'phone',
'o_fax' => 'fax',
'o_www' => 'www'
);
$this->default_map_fields = array(
'p_first_name' => 'first_name',
'p_last_name' => 'last_name',
'p_organization'=> 'organization',
'p_bemail' => 'b_email',
'p_bphone' => 'b_phone',
'o_name' => 'name',
'o_email' => 'email',
'o_phone' => 'phone'
);
$this->real_names = array(
'title' => $GLOBALS['phpgw']->lang('Title'),
'first_name' => $GLOBALS['phpgw']->lang('First
name'),
'last_name' => $GLOBALS['phpgw']->lang('Last
name'),
'middle' => $GLOBALS['phpgw']->lang('Middle'),
'birthday' =>
$GLOBALS['phpgw']->lang('Birthday'),
'gender' => $GLOBALS['phpgw']->lang('Gender'),
'notes' => $GLOBALS['phpgw']->lang('Notes'),
'job' => $GLOBALS['phpgw']->lang('Job'),
'organization' =>
$GLOBALS['phpgw']->lang('Organization'),
'street' => $GLOBALS['phpgw']->lang('Street'),
'po_box' => $GLOBALS['phpgw']->lang('Po box'),
'postal_code' =>
$GLOBALS['phpgw']->lang('Postal code'),
'city' => $GLOBALS['phpgw']->lang('City'),
'state' => $GLOBALS['phpgw']->lang('State'),
'country' => $GLOBALS['phpgw']->lang('Country'),
'p_title' => $GLOBALS['phpgw']->lang('Title'),
'p_first_name' =>
$GLOBALS['phpgw']->lang('First name'),
'p_last_name' => $GLOBALS['phpgw']->lang('Last
name'),
'p_middle' =>
$GLOBALS['phpgw']->lang('Middle'),
'p_birthday' =>
$GLOBALS['phpgw']->lang('Birthday'),
'p_gender' => $GLOBALS['phpgw']->lang('Gender'),
'p_job' => $GLOBALS['phpgw']->lang('Job'),
'p_organization' =>
$GLOBALS['phpgw']->lang('Organization'),
'p_street' => $GLOBALS['phpgw']->lang('Street'),
'p_po_box' => $GLOBALS['phpgw']->lang('Po box'),
'p_postal_code' =>
$GLOBALS['phpgw']->lang('Postal code'),
'p_city' => $GLOBALS['phpgw']->lang('City'),
'p_state' => $GLOBALS['phpgw']->lang('State'),
'p_country' =>
$GLOBALS['phpgw']->lang('Country'),
'o_street' => $GLOBALS['phpgw']->lang('Street'),
'o_po_box' => $GLOBALS['phpgw']->lang('Po box'),
'o_postal_code' =>
$GLOBALS['phpgw']->lang('Postal code'),
'o_city' => $GLOBALS['phpgw']->lang('City'),
'o_state' => $GLOBALS['phpgw']->lang('State'),
'o_country' =>
$GLOBALS['phpgw']->lang('Country'),
'name' => $GLOBALS['phpgw']->lang('Name'),
'o_name' => $GLOBALS['phpgw']->lang('Name'),
'o_belongs_to' =>
$GLOBALS['phpgw']->lang('Department of'),
'belongs_to' =>
$GLOBALS['phpgw']->lang('Department of'),
'owner' => $GLOBALS['phpgw']->lang('Owner'),
'created' => $GLOBALS['phpgw']->lang('Created'),
'modifier' =>
$GLOBALS['phpgw']->lang('Modifier'),
'modified' =>
$GLOBALS['phpgw']->lang('Modified'),
'access' => $GLOBALS['phpgw']->lang('Access'),
'b_phone' => $GLOBALS['phpgw']->lang('Business
Phone'),
'p_phone' => $GLOBALS['phpgw']->lang('Private
Phone'),
'b_email' => $GLOBALS['phpgw']->lang('Business
Email'),
'p_email' => $GLOBALS['phpgw']->lang('Private
Email'),
'mobile' => $GLOBALS['phpgw']->lang('Mobile
Phone'),
'phone' => $GLOBALS['phpgw']->lang('Phone'),
'fax' => $GLOBALS['phpgw']->lang('Fax'),
'email' => $GLOBALS['phpgw']->lang('Email'),
'www' => $GLOBALS['phpgw']->lang('Homepage')
);
if($useacl)
{
$this->grants =
$GLOBALS['phpgw']->acl->get_grants('addbook');
}
$GLOBALS['phpgw']->nextmatchs =
CreateObject('phpgwapi.nextmatchs');
$this->db = $GLOBALS['phpgw']->db;
$this->db2 = $this->db;
$this->stock_contact_categories = $this -> categories();
}
//returns all data for the given id as an array
//target: 'person || 'org'
function read_single_entry($id, $target)
{
$entry = array();
if($target == 'person')
{
$sql = 'SELECT a.*, b.*, c.job, c.org_link';
$sql.= ' FROM phpgw_addbook_person_main as a,
phpgw_addbook_address as b, phpgw_addbook_relation as c';
$sql.= ' WHERE a.id = '.$id;
$sql.= ' AND a.id = b.id';
$sql.= ' AND a.id = c.id';
$this->db->query($sql);
$this->db->next_record();
$entry['main']['id'] = $this->db->f('id');
$entry['main']['title'] = $this->db->f('title');
$entry['main']['last_name'] =
$this->db->f('last_name');
$entry['main']['middle'] =
$this->db->f('middle');
$entry['main']['first_name'] =
$this->db->f('first_name');
$entry['main']['initials'] =
$this->db->f('initials');
$entry['main']['birthday'] =
$this->db->f('birthday');
$entry['main']['gender'] =
$this->db->f('gender');
$entry['main']['notes'] = $this->db->f('notes');
$entry['address']['street'] =
$this->db->f('street');
$entry['address']['po_box'] =
$this->db->f('po_box');
$entry['address']['city'] =
$this->db->f('city');
$entry['address']['postal_code'] =
$this->db->f('postal_code');
$entry['address']['state'] =
$this->db->f('state');
$entry['address']['country'] =
$this->db->f('country');
$entry['rel']['job'] = $this->db->f('job');
$entry['rel']['org_link'] =
$this->db->f('org_link');
$entry['rel']['organization'] =
$this->get_org_name($entry['rel']['org_link']);
$sql = 'SELECT * FROM phpgw_addbook_pcontacts';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
$this->db->next_record();
$entry['contacts']['b_phone'] =
$this->db->f('b_phone');
$entry['contacts']['p_phone'] =
$this->db->f('p_phone');
$entry['contacts']['b_email'] =
$this->db->f('b_email');
$entry['contacts']['p_email'] =
$this->db->f('p_email');
$entry['contacts']['mobile'] =
$this->db->f('mobile');
$entry['contacts']['fax'] = $this->db->f('fax');
$entry['contacts']['pref'] =
$this->db->f('pref');
}
else
{
$sql = 'SELECT a.*, b.*';
$sql.= ' FROM phpgw_addbook_org_main as a,
phpgw_addbook_address as b';
$sql.= ' WHERE a.id = '.$id;
$sql.= ' AND a.id = b.id';
$this->db->query($sql);
$this->db->next_record();
$entry['main']['name'] = $this->db->f('name');
$entry['main']['id'] = $this->db->f('id');
$entry['main']['belongs_to'] =
$this->db->f('belongs_to_id');
$entry['main']['notes'] = $this->db->f('notes');
$entry['address']['street'] =
$this->db->f('street');
$entry['address']['po_box'] =
$this->db->f('po_box');
$entry['address']['city'] =
$this->db->f('city');
$entry['address']['postal_code'] =
$this->db->f('postal_code');
$entry['address']['state'] =
$this->db->f('state');
$entry['address']['country'] =
$this->db->f('country');
$sql = 'SELECT * FROM phpgw_addbook_ocontacts';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
$this->db->next_record();
$entry['contacts']['phone'] =
$this->db->f('phone');
$entry['contacts']['fax'] = $this->db->f('fax');
$entry['contacts']['email'] =
$this->db->f('email');
$entry['contacts']['www'] = $this->db->f('www');
$entry['contacts']['pref'] =
$this->db->f('pref');
$entry['departments'] =
$this->get_departments($id);
}
$sql = 'SELECT * FROM phpgw_addbook_meta';
$sql.= ' WHERE id='.$id;
$this->db->query($sql);
$this->db->next_record();
$entry['meta']['owner'] = $this->db->f('owner');
$entry['meta']['created'] = $this->db->f('created');
$entry['meta']['modifier'] = $this->db->f('modifier');
$entry['meta']['modified'] = $this->db->f('modified');
$entry['meta']['access'] = $this->db->f('access');
$entry['meta']['category'] = $this->db->f('cat_id');
$entry['meta']['lid'] = $this->db->f('lid');
$entry['meta']['tid'] = $this->db->f('tlid');
//get the additional contacts beside the standard ones
$entry['extra'] = $this->get_extra_contacts($id,
$target);
if($target == 'org')
{
$entry['employees'] = $this->get_employees($id);
}
return $entry;
}
function read_all_entries($target, $category='', $order='ASC',
$order_by = '', $start=0)
{
if($GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] &&
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] > 0)
{
$limit =
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
}
else
{
$limit = 15;
}
if($target == 'person')
{
if($order_by == '')
{
$order_by = 'last_name';
}
if($category != 0)
{
$sql = 'SELECT person.*, relation.*,
address.*, meta.* ';
$sql.= 'FROM phpgw_addbook_person_main
as person, phpgw_addbook_meta as meta, phpgw_addbook_address as address,
phpgw_addbook_relation as relation';
$sql.= ' WHERE meta.cat_id =
'.$category.' AND person.id = meta.id';
$sql.= ' AND person.id = address.id';
$sql.= ' AND person.id = relation.id';
$sql.= " ORDER BY $order_by $order";
}
else
{
$sql = 'SELECT person.*, address.*,
relation.job, relation.org_link, meta.owner';
$sql.= ' FROM phpgw_addbook_person_main
as person, phpgw_addbook_address as address, phpgw_addbook_meta as meta,
phpgw_addbook_relation as relation';
$sql.= ' WHERE person.id = address.id';
$sql.= ' AND person.id = relation.id';
$sql.= ' AND person.id = meta.id';
$sql.= " ORDER BY $order_by $order";
}
$this->db->query($sql);
$total = $this->db->num_rows();
$this->db->limit_query($sql, $start, '', '',
$limit);
$current = $this->db->num_rows();
while($this->db->next_record())
{
//return only the entries that are
permitted to read
$owner = $this->db->f('owner');
if($this->check_perms($this->grants[$owner],PHPGW_ACL_READ) || $owner ==
$GLOBALS['phpgw_info']['user']['account_id'])
{
$entries[] = array(
'id' =>
$this->db->f('id'),
'owner' => $owner,
'title' =>
$this->db->f('title'),
'last_name' =>
$this->db->f('last_name'),
'middle' =>
$this->db->f('middle'),
'first_name' =>
$this->db->f('first_name'),
'initials' =>
$this->db->f('initials'),
'birthday' =>
$this->db->f('birthday'),
'gender' =>
$this->db->f('gender'),
'job' =>
$this->db->f('job'),
'street' =>
$this->db->f('street'),
'postal_code' =>
$this->db->f('postal_code'),
'po_box' =>
$this->db->f('po_box'),
'city' =>
$this->db->f('city'),
'state' =>
$this->db->f('state'),
'country' =>
$this->db->f('country'),
'organization' =>
$this->get_org_name($this->db->f('org_link'))
);
}
}
}
else
{
if($order_by == '')
{
$order_by = 'name';
}
if($category != 0)
{
$sql = 'SELECT org.*, address.*,
meta.owner ';
$sql.= ' FROM phpgw_addbook_org_main as
org, phpgw_addbook_address as address, phpgw_addbook_meta as meta ';
$sql.= ' WHERE (meta.cat_id =
'.$category.' AND org.id = meta.id)';
$sql.= ' AND org.id=address.id';
$sql.= " ORDER BY org.$order_by $order";
}
else
{
$sql = 'SELECT org.*, address.*,
meta.owner';
$sql.= ' FROM phpgw_addbook_org_main as
org, phpgw_addbook_address as address, phpgw_addbook_meta as meta';
$sql.= ' WHERE org.id = address.id';
$sql.= ' AND org.id = meta.id';
$sql.= " ORDER BY org.$order_by $order";
}
$this->db->query($sql);
$total = $this->db->num_rows();
$this->db->limit_query($sql, $start, '', '',
$limit);
$current = $this->db->num_rows();
while($this->db->next_record())
{
//return only the entries that are
permitted to read
$owner = $this->db->f('owner');
if($this->check_perms($this->grants[$owner],PHPGW_ACL_READ) || $owner ==
$GLOBALS['phpgw_info']['user']['account_id'])
{
$entries[] = array(
'id' =>
$this->db->f('id'),
'owner' => $owner,
'name' =>
$this->db->f('name'),
'belongs_to' =>
$this->get_org_name($this->db->f('belongs_to_id')),
'street' =>
$this->db->f('street'),
'postal_code' =>
$this->db->f('postal_code'),
'po_box' =>
$this->db->f('po_box'),
'city' =>
$this->db->f('city'),
'state' =>
$this->db->f('state'),
'country' =>
$this->db->f('country')
);
}
}
}
//now go through this array an add the contacts for
each person || org
for($i=0; $i < count($entries); $i++)
{
$contacts =
$this->get_contacts($entries[$i]['id'], $target);
while(list($key, $value) = each ($contacts))
{
$entries[$i][$key] = $value;
}
}
//get the extra contacts
for($i=0; $i < count($entries); $i++)
{
$entries[$i]['extra'] =
$this->get_extra_contacts($entries[$i]['id'], $target);
}
return array(
'data' => $entries,
'current' => $current,
'total' => $total
);
}
//returns all person_id's for the specified org_id as an array
function get_employees($id)
{
$sql = 'SELECT relation.id, person.last_name,
person.first_name';
$sql.= ' FROM phpgw_addbook_relation as relation,
phpgw_addbook_person_main as person';
$sql.= ' WHERE org_link = '.$id;
$sql.= ' AND person.id = relation.id';
$this->db->query($sql);
$employees = array();
while($this->db->next_record())
{
$employees[]= array(
'id' => $this->db->f('id'),
'name' => $this->db->f('first_name').'
'.$this->db->f('last_name')
);
}
return $employees;
}
function get_departments($id)
{
$sql = 'SELECT id, name from phpgw_addbook_org_main ';
$sql.= 'WHERE belongs_to_id = '.$id;
$this->db2->query($sql);
$departments = array();
while($this->db2->next_record())
{
$departments[]= array(
'id' => $this->db2->f('id'),
'name' => $this->db2->f('name')
);
}
return $departments;
}
//returns the correspomding org_name to the given org_id
function get_org_name($org_link)
{
$sql = 'SELECT org.name FROM phpgw_addbook_org_main as
org';
$sql.= ' WHERE org.id = '.$org_link;
$this->db2->query($sql);
$this->db2->next_record();
return $this->db2->f(0);
}
function get_contacts($id, $target)
{
$target = substr($target, 0,1);
$sql = 'SELECT * FROM
phpgw_addbook_'.$target.'contacts';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
$this->db->next_record();
$pref = $this->db->f('pref');
if($target == 'p')
{
$contacts = array(
'b_phone' =>
$this->db->f('b_phone'),
'p_phone' =>
$this->db->f('p_phone'),
'b_email' =>
$this->db->f('b_email'),
'p_email' =>
$this->db->f('p_email'),
'mobile' =>
$this->db->f('mobile'),
'fax' => $this->db->f('fax'),
'pref' => $this->db->f("$pref")
);
}
else
{
$contacts = array(
'phone' => $this->db->f('phone'),
'fax' => $this->db->f('fax'),
'email' => $this->db->f('email'),
'www' => $this->db->f('www'),
'pref' => $this->db->f("$pref")
);
}
return $contacts;
}
//returns all extra contacts from 'id' as an array
//target: 'person || 'org
function get_extra_contacts($id, $target)
{
$sql = 'SELECT * FROM phpgw_addbook_contacts';
$sql.= ' WHERE id = '.$id;
@$this->db->query($sql);
while($this->db->next_record())
{
$category_id =
intval($this->db->f('contact_category_id'));
//gets the name of the category out of the
stock->..array
$category_name =
$this->stock_contact_categories[$category_id];
$contacts[] = array(
'contact_id' =>
$this->db->f('contact_id'),
'contact' => $this->db->f('contact'),
'category_id'=>
$this->db->f('contact_category_id'),
'category_name'=> $category_name,
);
}
return $contacts;
}
//returns an array in the form
stock_contact_categories['contact_category_id']='category'
function categories()
{
$sql = 'SELECT * FROM phpgw_addbook_contact_cat';
$this->db->query($sql);
$stock_contact_categories = array();
while($this->db->next_record())
{
$stock_contact_categories[$this->db->f('contact_category_id')] =
$this->db->f('category_name');
}
return $stock_contact_categories;
}
function check_perms($has, $needed)
{
return (!!($has & $needed) == True);
}
}
?>
--- NEW FILE ---
<?php
/**************************************************************************\
* phpGroupWare API - next
*
* This file written by Joseph Engo <address@hidden> *
* Handles limiting number of rows displayed
*
* Copyright (C) 2000, 2001 Joseph Engo
*
*
-------------------------------------------------------------------------*
* 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
*
\**************************************************************************/
//adjust the phpgwapi.nextmatchs to the addbook needs
//16.04.2002 heiko
class addbook_nextmatchs extends nextmatchs
{
var $maxmatches;
var $action;
var $template;
/*!
@function show_tpl
@abstract ?
@param $sn ?
@param $start ?
@param $total ?
@param $extra ?
@param $twidth ?
@param $bgtheme ?
@param $search_obj ?
@param $filter_obj ?
@param $showsearch ?
*/
function show_tpl($target,
$start=0,$total,$twidth,$bgtheme,$search_obj=0,$filter_obj=1,$showsearch=1,$yours=0,$cat_id=0,
$cat_field='')
{
$debug=0;
if($debug)
{
echo "<br>targe:$target";
echo "<br>start:$localstart";
echo "<br>total:$total";
echo "<br>search_obj:$search_obj";
echo "<br>filter_obj:$filter_obj";
echo "<br>showsearch:$showsearch";
echo "<br>yours:$yours";
}
//first modify some defaults of the orignial constructor
$this->template = CreateObject('phpgwapi.Template',
$GLOBALS['phpgw']->common->get_tpl_dir('addbook'));
$this->template->set_file(array(
'_nextmatchs' => 'addbook_nextmatchs.tpl'
));
$this->bo = CreateObject('addbook.boaddbook');
$this->template->set_block('_nextmatchs','nextmatchs');
$this->template->set_block('_nextmatchs','filter');
$this->template->set_block('_nextmatchs','form');
$this->template->set_block('_nextmatchs','icon');
$this->template->set_block('_nextmatchs','link');
$this->template->set_block('_nextmatchs','search');
$this->template->set_block('_nextmatchs','cats');
$this->template->set_block('_nextmatchs','search_filter');
$this->template->set_block('_nextmatchs','cats_search_filter');
$cats = CreateObject('phpgwapi.categories');
$url_params = array(
$target.'start' => $start
);
$var = array(
'form_action' => (''),
'lang_category' => lang('Category'),
'lang_all' => lang('All'),
'lang_select' => lang('Select'),
'cat_field' => $cat_field,
'categories' =>
$cats->formated_list('select','all',$cat_id,'True'),
'filter' => $target.'filter',
'start' => $target.'start',
'order' => $target.'order',
'sort' => $target.'sort',
'qfield' => $target.'qfield',
'query' => $target.'query',
'filter_value' => $filter,
'qfield_value' => $qfield,
'start_value' => $start,
'order_value' => $order,
'sort_value' => $sort,
'query_value' =>
urlencode(stripslashes($GLOBALS['query'])),
'table_width' => $twidth,
'th_bg' =>
$GLOBALS['phpgw_info']['theme']['th_bg'],
'left' =>
$this->left($start,$total,$extra, $target),
'search' =>
($showsearch?$this->search($search_obj):''),
'filter' =>
($filter_obj?$this->filter($filter_obj,$yours):''),
'right' =>
$this->right($start,$total,$extra, $target)
);
$this->template->set_var($var);
$this->template->parse('cats','cats');
$this->template->parse('cats_search_filter_data','cats_search_filter');
return $this->template->fp('out','nextmatchs');
}
function left($start,$total,$extradata = '', $target)
{
global $filter, $qfield, $order, $sort;
$extravars = Array(
'order' => $order,
'filter' => $filter,
'q_field' => $qfield,
'sort' => $sort,
'query' =>
urlencode(stripslashes($GLOBALS['query']))
);
$extravars = $this->split_extras($extravars,$extradata);
$ret_str = '';
if (($start != 0) &&
($start > $this->maxmatches))
{
$extravars['start'] = 0;
$ret_str .=
$this->set_link('left','first.gif',$scriptname,lang('First page'),$extravars,
$target);
}
else
{
$ret_str .=
$this->set_icon('left','first-grey.gif',lang('First page'));
}
if ($start != 0)
{
// Changing the sorting order screaws up the
starting number
if (($start - $this->maxmatches) < 0)
{
$extravars['start'] = 0;
}
else
{
$extravars['start'] = ($start -
$this->maxmatches);
}
$ret_str .=
$this->set_link('left','left.gif',$scriptname,lang('Previous page'),$extravars,
$target);
}
else
{
$ret_str .=
$this->set_icon('left','left-grey.gif',lang('Previous page'));
}
return $ret_str;
} /* left() */
/*!
@function right
@abstract ?
@param $scriptname ?
@param $start ?
@param $total ?
@param $extradate ?
*/
function right($start,$total,$extradata = '', $target)
{
global $filter, $qfield, $order, $sort;
$extravars = Array(
'order' => $order,
'filter' => $filter,
'q_field' => $qfield,
'sort' => $sort,
'query' =>
urlencode(stripslashes($GLOBALS['query']))
);
$extravars = $this->split_extras($extravars,$extradata);
$ret_str = '';
if (($total > $this->maxmatches) &&
($total > $start + $this->maxmatches))
{
$extravars['start'] = ($start +
$this->maxmatches);
$ret_str .=
$this->set_link('right','right.gif',$scriptname,lang('Next page'),$extravars,
$target);
}
else
{
$ret_str .=
$this->set_icon('right','right-grey.gif',lang('Next page'));
}
if (($start != $total - $this->maxmatches) &&
(($total - $this->maxmatches) > ($start +
$this->maxmatches)))
{
$extravars['start'] = ($total -
$this->maxmatches);
$ret_str .=
$this->set_link('right','last.gif',$scriptname,lang('Last page'),$extravars,
$target);
}
else
{
$ret_str .=
$this->set_icon('right','last-grey.gif',lang('Last page'));
}
return $ret_str;
} /* right() */
function set_link($align,$img,$link,$alt,$extravars, $target)
{
$hidden = '';
while(list($var,$value) = each($extravars))
{
if((is_int($value) && $value == 0) || $value)
{
// if(is_int($value))
// {
// $param = intval($value);
// }
// else
// {
$param = '"'.$value.'"';
// }
$hidden .= ' <input type="hidden"
name="'.$target.$var.'" value='.$param.'>'."\n";
}
}
$border = 0;
$var = Array(
'align' => $align,
'action' => '',
'form_name' => $img,
'hidden' =>
substr($hidden,0,strlen($hidden)-1),
'img' =>
$GLOBALS['phpgw']->common->image('phpgwapi',$img),
'label' => $alt,
'border' => $border,
'start' => $extravars['start']
);
$this->template->set_var($var);
return $this->template->fp('out','form');
}
} // End of nextmatchs class
?>
***** Error reading new file: [Errno 2] No such file or directory:
'class.boaddbook.inc.php'
--- NEW FILE ---
<?php
/**************************************************************************\
* phpGroupWare Application - addbook
*
* http://www.phpgroupware.org
*
* Written by Heiko Schwarzenberg <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 functions
{
var $public_functions = array(
'confirm' => True,
'del' => True
);
function functions()
{
$this->db = $GLOBALS['phpgw']->db;
$this->uiaddbook = CreateObject('addbook.uiaddbook');
}
function session_get_output($mode, $already_contacts)
{
if(!is_array($already_contacts))
{
$contact_data ="\n".'<input type=hidden
name="already_contacts[nr]" value="0">';
return $contact_data;
}
for($i=1; $i<= $already_contacts['nr']; $i++)
{
$tr_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color);
$contact_data .="\n".'<tr
bgcolor=\''.$tr_color.'\'>';
$contact_data .="\n".'<td align=\'left\'
width=\'40%\'><input type=text size=\'30\'
name=\'already_contacts[contact_'.$i.']\'
value=\''.$already_contacts['contact_'.$i].'\'>';
$box_contact =
$this->uiaddbook->get_box('phpgw_addbook_contact_cat', 'contact_category_id',
'category_name', 'already_contacts[contact_category_'.$i.']',
$already_contacts['contact_category_'.$i]);
$contact_data .="\n".'<td align=\'left\'
width=\'20%\'>'.$box_contact.'</td>';
$contact_data .="\n".'<td align=\'center\'
width=\'10%\'><input type=\'checkbox\'
name=\'already_contacts[delete_'.$i.']\'></td></tr>';
}
$contact_data .="\n".'<input type=hidden
name="already_contacts[nr]" value="'.$already_contacts['nr'].'">';
return $contact_data;
}
function session_add($input, $already_contacts)
{
if(!is_array($already_contacts))
{
$already_contacts = array();
}
$i = $already_contacts['nr'];
$i++;
$already_contacts['contact_category_'.$i] =
$input['contact_category'];
$already_contacts['contact_'.$i] = $input['contact'];
$already_contacts['nr'] = $i;
return $already_contacts;
}
function session_update($already_contacts)
{
$tmp = array();
$nr = 0;
for($i=0; $i <= $already_contacts['nr']; $i++)
{
if($already_contacts['contact_'.$i] != '' &&
$already_contacts['delete_'.$i] != 'on')
{
$nr++;
$tmp['contact_category_'.$nr] =
$already_contacts['contact_category_'.$i];
$tmp['contact_'.$nr] =
$already_contacts['contact_'.$i];
}
}
$tmp['nr'] = $nr;
return $tmp;
}
function get_next_id()
{
$GLOBALS['phpgw']->db->query("SELECT MAX(id) AS id FROM
phpgw_addbook_org_main");
$GLOBALS['phpgw']->db->next_record();
$org_id = $GLOBALS['phpgw']->db->f('id');
$GLOBALS['phpgw']->db->query("SELECT MAX(id) AS id FROM
phpgw_addbook_person_main");
$GLOBALS['phpgw']->db->next_record();
$person_id = $GLOBALS['phpgw']->db->f('id');
if($org_id > $person_id)
{
return $org_id + 1;
}
else
{
return $person_id + 1;
}
}
function get_current_id($table='', $column='')
{
if($table == '' || $column == '')
{
return 0;
}
$this->db->query("SELECT MAX($column) AS id FROM
$table");
$this->db->next_record();
return ($this->db->f('id'));
}
//asks if an entry really shall be deleted
function confirm()
{
$id = $GLOBALS['HTTP_GET_VARS']['id'];
$target = $GLOBALS['HTTP_GET_VARS']['target'];
$url_params = array(
'menuaction'=> 'addbook.functions.del',
'id' => $id,
'target' => $target
);
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
$this->template = CreateObject('phpgwapi.Template',
$GLOBALS['phpgw']->common->get_tpl_dir('addbook'));
$this->template->set_file(array('confirm' =>
'confirm.tpl'));
$this->template->set_var('lang_confirm', lang('Do you
really want to delete this entry?'));
$this->template->set_var('lang_no', lang('No'));
$this->template->set_var('lang_yes', lang('Yes'));
$this->template->set_var('action_url',
$GLOBALS['phpgw']->link('/index.php', $url_params));
$this->template->parse("out","confirm");
$this->template->p("out");
}
//del an whole entry (person||org)
//including all relating data in other tables
function del()
{
$id = $GLOBALS['HTTP_GET_VARS']['id'];
$target = $GLOBALS['HTTP_GET_VARS']['target'];
//TODO: Transaktion commit
$sql = 'DELETE FROM phpgw_addbook_'.$target.'_main';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
$sql = 'DELETE FROM phpgw_addbook_address';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
$sql = 'DELETE FROM phpgw_addbook_'.substr($target, 0,
1).'contacts';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
$sql = 'DELETE FROM phpgw_addbook_contacts';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
if($target == 'person')
{
$sql = 'DELETE FROM phpgw_addbook_relation';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
}
$sql = 'DELETE FROM phpgw_addbook_meta';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
Header('Location: ' .
$GLOBALS['phpgw']->link('/addbook/index.php'));
}
}
?>
--- NEW FILE ---
<?php
/**************************************************************************\
* phpGroupWare Application - addbook
*
* http://www.phpgroupware.org
*
* Written by Heiko Schwarzenberg <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 generic
{
var $template;
var $grants = '';
var $public_functions = array(
'index' => True,
'get_box' => True,
'view' => True,
'leave' => True,
'set_color' => True,
'preferences' => True,
'save_preferences' => True,
'edit_categories' => True,
'main' => True,
'del' => True,
'confirm' => True
);
//var $session_contact=array();
function generic()
{
$this->grants =
$GLOBALS['phpgw']->acl->get_grants('addbook');
$this->template = CreateObject('phpgwapi.Template',
$GLOBALS['phpgw']->common->get_tpl_dir('addbook'));
$this->categories = CreateObject('phpgwapi.categories');
$this->so = CreateObject('addbook.soaddbook');
$this->contacts =
CreateObject('addbook.addbook_contacts');
$this->prefs =
$GLOBALS['phpgw_info']['user']['preferences']['addbook'];
$this->cats = CreateObject('phpgwapi.categories');
$this->nextmatchs =
CreateObject('addbook.addbook_nextmatchs');
$this->font = "<font face='arial, helvetica' size='1'>";
$this->font1 = "<font face='arial, helvetica'
size='2'>";
$this->db = $GLOBALS['phpgw']->db;
$this->bo = CreateObject('addbook.boaddbook',True);
$this->functions = CreateObject('addbook.functions');
$this->_set_sessiondata();
}
function _set_sessiondata()
{
$this->start = $this->bo->start;
$this->query = $this->bo->query;
$this->sort = $this->bo->sort;
$this->oorder = $this->bo->oorder;
$this->porder = $this->bo->porder;
$this->filter = $this->bo->filter;
$this->pcat_id = $this->bo->pcat_id;
$this->ocat_id = $this->bo->ocat_id;
$this->contact_type = $this->bo->contact_type;
}
function save_sessiondata()
{
$data = array(
'start' => $this->start,
'query' => $this->query,
'sort' => $this->sort,
'oorder' => $this->oorder,
'porder' => $this->porder,
'filter' => $this->filter,
'ocat_id' => $this->ocat_id,
'pcat_id' => $this->pcat_id,
'contact_type' => $this->contact_type
);
$this->bo->save_sessiondata($data);
}
//returns the column-names that shall be displayed and pack
them into a table
//returns also the real field_names
//target is p(erson) or o(rg)
//if there are no preferences set, it returns a default set of
columns
function get_columns($target, $order = '', $order_by = '')
{
$fields = array();
if($this->prefs)
{
reset($this->contacts->map_fields);
while(list($key, $value) = each
($this->contacts->map_fields))
{
if($this->prefs[$key])
{
$fields[] = array(
'pref_name' => $key,
'field_name' =>$value
);
}
}
}
else
{
reset($this->contacts->default_map_fields);
while(list($key, $value) = each
($this->contacts->default_map_fields))
{
$fields[] = array(
'pref_name' => $key,
'field_name' =>$value
);
}
}
reset($fields);
switch ($order) {
case 'ASC':
$order = 'DESC';
break;
case 'DESC':
$order = 'ASC';
break;
case '':
$order = 'ASC';
break;
}
while (list($foo, $value) = each($fields))
{
if (substr($value['pref_name'], 0, 1) ==
$target )
{
$columns_to_display[] =
$value['field_name'];
}
}
$width = round(100/count($columns_to_display));
for($i = 0; $i<count($columns_to_display); $i++)
{
$field =
$this->contacts->real_names[$columns_to_display[$i]];
$cols .= '<td
width=\''.$width.'%\'>'.$this->font;
//allow sorting only for name
if($columns_to_display[$i] == 'first_name' ||
$columns_to_display[$i] == 'last_name' || $columns_to_display[$i] == 'name')
{
$url_params= array(
'target' =>
$target,
substr($target, 0,
1).'order_by' => $columns_to_display[$i],
substr($target, 0, 1).'order'
=> $order
);
$cols .= '<a
href=\''.$GLOBALS['phpgw']->link('/addbook/index.php', $url_params).'\'>';
$cols .= $field;
$cols .= "</a></font>\n </td>";
}
else
{
$cols .= $field.'</font></td>';
}
$cols .= "\n";
}
return array('cols' => $cols, 'columns_to_display' =>
$columns_to_display);
}
//returns the data for the user-defined fields in table-format
function get_data($entries, $columns_to_display, $target)
{
while(@list($foo, $entry) = each($entries))
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$data.="<tr bgcolor=".$row_color.">";
reset($columns_to_display);
while(list($foo, $value) = each
($columns_to_display))
{
$data.='<td>'.$this->font.$entry[$value].'</font></td>';
}
$url_params= array(
'menuaction' =>
'addbook.generic.view',
'id' => $entry['id'],
'target' => $target
);
$data.="<td width='20'><a
href='".$GLOBALS['phpgw']->link('/index.php',
$url_params)."'>".$this->font.lang('view')."</font></a></td>\n";
$myowner = $entry['owner'];
if($this->contacts->check_perms($this->contacts->grants[$myowner],PHPGW_ACL_EDIT)
|| $myowner == $GLOBALS['phpgw_info']['user']['account_id'])
{
$url_params= array(
'menuaction' =>
'addbook.generic.main',
'id' => $entry['id'],
'target' => $target,
'mode' => 'edit'
);
$edit = '<a
href=\''.$GLOBALS['phpgw']->link('/index.php',
$url_params).'\'>'.$this->font.lang('edit').'</font></a>';
}
else
{
$edit = ' ';
}
$data.='<td width=\'20\'>'.$edit."</td>\n";
$data.="</tr>\n";
}
$this->db->free();
return $data;
}
function index()
{
$this->pstart = $GLOBALS['HTTP_POST_VARS']['pstart'];
$this->ostart = $GLOBALS['HTTP_POST_VARS']['ostart'];
$this->porder_by =
$GLOBALS['HTTP_GET_VARS']['porder_by'];
if(!$this->pstart)
{
$this->pstart = 0;
}
if(!$this->ostart)
{
$this->ostart = 0;
}
$person_selected='';
$org_selected='';
$all_selected='';
//first the persons
$coldata = $this->get_columns('p', $this->porder,
$this->porder_by);
$columns_to_display = $coldata['columns_to_display'];
$width = 100/(count($columns_to_display) + 1).'%';
$cols = $coldata['cols'];
$colspan1 = count($columns_to_display) + 1;
$pentries = $this->contacts->read_all_entries('person',
$this->pcat_id, $this->porder, $this->porder_by, $this->pstart, $this->pquery);
$person_data = '<tr><td> </td></tr>';
$person_data.= '<tr bgcolor=\'#{th_bg}\'><td
colspan=>'.$this->font1.$GLOBALS['phpgw']->lang('Persons').'</font>';
$person_data.=
'<br><b>['.$this->font.$this->pstart.'-'.($this->pstart+$pentries['current']).'/'.$pentries['total'].']</font></b></td>';
$search_filter = $this->nextmatchs->show_tpl(
'p', $this->pstart, $pentries['total'],
'75%',$GLOBALS['phpgw_info']['theme']['th_bg'],1,0,1,1,$this->pcat_id,
'pcat_id');
$person_data.= '<td
colspan=\''.$colspan1.'\'>'.$search_filter.'</td></tr>';
$person_data.= "<tr bgcolor='#ffffff'>".$cols."<td
colspan='2'> </td></tr>";
$person_data.=$this->get_data($pentries['data'],
$columns_to_display, 'person');
//the same for organizations
$coldata = $this->get_columns('o', $this->oorder,
$this->oorder_by);
$columns_to_display = $coldata['columns_to_display'];
$cols = $coldata['cols'];
$colspan2 = count($columns_to_display) + 1;
$oentries = $this->contacts->read_all_entries('org',
$this->ocat_id, $this->oorder, $this->oorder_by, $this->ostart, $this->oquery);
$org_data = '<tr><td> </td></tr>';
$org_data.= '<tr
bgcolor=\'#{th_bg}\'><td>'.$this->font1.$GLOBALS['phpgw']->lang('Organizations').'</font>';
$org_data.=
'<br><b>['.$this->font.$this->ostart.'-'.($this->ostart+$oentries['current']).'/'.$oentries['total'].']</font></b></td>';
$search_filter = $this->nextmatchs->show_tpl(
'o', $this->ostart,
$oentries['total'],'75%',$GLOBALS['phpgw_info']['theme']['th_bg'],1,0,1,1,$this->ocat_id,
'ocat_id' );
$org_data.= '<td
colspan=\''.$colspan2.'\'>'.$search_filter.'</td></tr>';
$org_data.= "<tr bgcolor='#ffffff'>".$cols."<td
colspan='2'> </td></tr>";
$org_data.=$this->get_data($oentries['data'],
$columns_to_display, 'org');
if(isset($this->contact_type))
{
if($this->contact_type == 'person')
{
$person_selected = 'selected';
$table_data = $person_data;
}
else if($this->contact_type == 'org')
{
$org_selected = 'selected';
$table_data = $org_data;
}
}
if(!isset($this->contact_type) ||
$this->contact_type=='all')
{
$all_selected = 'selected';
$table_data = $person_data;
$table_data.= "\n<tr><td> </td></tr>\n";
$table_data.= $org_data;
}
$box_contact_type.= "<option value='all'
".$all_selected.">".$GLOBALS['phpgw']->lang('all')."</option>\n";
$box_contact_type.= "<option value='person'
".$person_selected.">".$GLOBALS['phpgw']->lang('Person')."</option>\n";
$box_contact_type.= "<option value='org'
".$org_selected.">".$GLOBALS['phpgw']->lang('Organization')."</option>\n";
//$GLOBALS['phpgw']->common->phpgw_header();
//echo parse_navbar();
$this->template->set_file(array('index' =>
'index.tpl'));
$var = array(
'headline' => 'Addbook',
'search_filter' => $search_filter,
'box_contact_type' => $box_contact_type,
'colspan' => $colspan1,
'lang_all' => lang('All'),
'add_person_url' =>
$GLOBALS['phpgw']->link('/index.php',
'menuaction=addbook.generic.main&mode=add&target=person'),
'add_org_url' =>
$GLOBALS['phpgw']->link('/index.php',
'menuaction=addbook.generic.main&mode=add&target=org'),
'table_data' => $table_data,
'lang_category' => lang('Category'),
'add_person' => lang('add person'),
'add_org' => lang('add organization'),
'th_bg' =>
$GLOBALS['phpgw_info']['theme']['th_bg'],
'th_font' =>
$GLOBALS['phpgw_info']['theme']['font'],
'th_text' =>
$GLOBALS['phpgw_info']['theme']['th_text']
);
$this->template->set_var($var);
$this->template->parse('out','index', true);
$this->template->p('out');
$GLOBALS['phpgw']->common->phpgw_footer();
}
function view()
{
$id = $GLOBALS['HTTP_GET_VARS']['id'];
//nedded for compatibility with addressbook for infolog
$GLOBALS['ab_id'] = $id;
$target = $GLOBALS['HTTP_GET_VARS']['target'];
$this->contacts =
CreateObject('addbook.addbook_contacts');
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
$entry = $this->contacts->read_single_entry($id,
$target);
$this->template->set_file(array('show' => 'show.tpl'));
while (@list($key, $value) = each($entry['main']))
{
if($value!= '' && $value != '0' && $key !=
'contacts' && $key != 'id' && $key != 'private' && $key != 'employees' && $key
!= 'category')
{
if($key == 'belongs_to' && $value != 0)
{
$temp = '<a
href=\''.$GLOBALS['phpgw']->link('/index.php',
'menuaction=addbook.generic.view&id='.$value.'&target=org').'\'>';
$temp.=
$this->contacts->get_org_name($value).'</a>';
$value = $temp;
unset($temp);
}
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$table_data.="<tr
bgcolor='#$row_color'><td
width='200'>$this->font<b>".$this->contacts->real_names[$key]."</b></font></td>\n";
$table_data.="<td colspan='3'
align='left'>".$this->font.$value."</font></td></tr>\n";
}
}
//get the job and organization
if($entry['rel']['job'] != '')
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$table_data.="<tr bgcolor='#$row_color'><td
width='200'>".$this->font.'<b>'.lang('Job')."</b></font></td>\n";
$table_data.="<td colspan='3'
align='left'>".$this->font.$entry['rel']['job']."</font></td></tr>\n";
}
if($entry['rel']['organization'] != '')
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$table_data.= "<tr bgcolor='#$row_color'><td
width='200'>".$this->font.'<b>'.lang('Organization')."</b></font></td>\n";
$table_data.= "<td colspan='3'
align='left'>\n<a href='".$GLOBALS['phpgw']->link('/index.php',
'menuaction=addbook.generic.view&id='.$entry['rel']['org_link'].'&target=org')."'>\n";
$table_data.=
$this->font.$entry['rel']['organization']."</font>\n</a></td></tr>\n";
}
//get the address
while(@list($key, $value) = each($entry['address']))
{
//if($value != '' && count($value) > 1)
if($value != '')
{
if($key == 'country')
{
$country =
CreateObject('phpgwapi.country');
$value =
$country->get_full_name($value);
}
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$table_data.="<tr
bgcolor='#$row_color'><td
width='200'>".$this->font.'<b>'.ucfirst($this->contacts->real_names[$key])."</b></font></td>\n";
$table_data.="<td colspan='3'
align='left'>".$this->font.$value."</font></td></tr>\n";
}
}
//and now get the contacts
while(@list($key, $value) = each($entry['contacts']))
{
if($value != '' && $key != 'pref')
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$table_data.='<tr
bgcolor='.$row_color.'><td
width=\'200\'>'.$this->font.'<b>'.ucfirst($this->contacts->real_names[$key]).'</b></font></td>';
$table_data.='<td colspan=\'3\'
align=\'left\'>'.$this->font.$value.'</font></td></tr>';
}
}
//and now get the additional contacts
while(@list($foo, $value) = each($entry['extra']))
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$table_data.='<tr bgcolor='.$row_color.'><td
width=\'200\'>'.$this->font.'<b>'.ucfirst(lang($value['category_name'])).'</b></font></td>';
$table_data.='<td colspan=\'3\'
align=\'left\'>'.$this->font.$value['contact'].'</font></td></tr>';
}
//if $target == org and some employees exist,
//get all the employees and add them to $table_data
if($target == 'org' && count($entry['employees']) > 0)
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$table_data.= '<tr><td
colspan=\'4\'> </td></tr>'."\n";
$table_data.= '<tr
bgcolor=\''.$row_color.'\'><td colspan=\'4\'
align=\'center\'>'.$this->font.'<b>'.lang('Employees').'</b></font></td></tr>'."\n";
for($i=0; $i<count($entry['employees']); $i++)
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$employee_data .= '<tr
bgcolor=\''.$row_color.'\'><td colspan=\'3\'
align=\'center\'>'.$this->font.$entry['employees'][$i]['name'].'</font></td>'."\n";
$employee_data .= '<td><a
href=\''.$GLOBALS['phpgw']->link('/index.php',
'menuaction=addbook.generic.view&id='.$entry['employees'][$i]['id'].'&target=person').'\'>';
$employee_data .=
$this->font.lang('view').'</font></a></td></tr>'."\n";
}
$table_data.= $employee_data;
}
//get the departments (sub-organizations)
if($target == 'org' && count($entry['departments']) > 0)
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$table_data.= '<tr><td
colspan=\'3\'> </td></tr>'."\n";
$table_data.= '<tr
bgcolor=\''.$row_color.'\'><td colspan=\'3\'
align=\'center\'>'.$this->font.'<b>'.lang('Departments').'</b></font></td></tr>'."\n";
for($i=0; $i<count($entry['departments']); $i++)
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$departments_data .= '<tr
bgcolor=\''.$row_color.'\'><td colspan=\'2\'
align=\'center\'>'.$this->font.$entry['departments'][$i]['name'].'</font></td>'."\n";
$departments_data .= '<td><a
href=\''.$GLOBALS['phpgw']->link('/index.php',
'menuaction=addbook.generic.view&id='.$entry['departments'][$i]['id'].'&target=org').'\'>';
$departments_data .=
$this->font.lang('view').'</font></a></td></tr>'."\n";
}
$table_data.= $departments_data;
}
//show meta information only when button was pressed
if($GLOBALS['HTTP_POST_VARS']['meta'])
{
$meta_data = '<tr><td
colspan=\'4\'> </td></tr>'."\n";
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$meta_data.= '<tr
bgcolor=\'#'.$row_color.'\'><td colspan=\'4\'
align=\'center\'><b>'.$this->font.lang('Meta
Information').'</font></b></td></tr>'."\n";
while(list($key, $value) = each($entry['meta']))
{
if(($key == 'owner' || $key ==
'modifier') && $value != 0)
{
$value =
$GLOBALS['phpgw']->common->grab_owner_name($value);
}
else if($key == 'category')
{
$tmp =
$this->categories->return_single($value);
$value = $tmp[0]['name'];
}
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$meta_data .= '<tr
bgcolor=\''.$row_color.'\'><td><b>'.$this->font.ucfirst(lang($key)).'</font></b></td>'."\n";
$meta_data .= '<td
colspan=\'3\'>'.$this->font.$value.'</font></td></tr>'."\n";
}
$table_data.= $meta_data;
$this->template->set_var('lang_meta',
$GLOBALS['phpgw']->lang('hide meta-data'));
}
else
{
$this->template->set_var('lang_meta',
$GLOBALS['phpgw']->lang('show meta-data'));
$this->template->set_var('meta', 'meta');
}
$this->template->set_var('table_data', $table_data);
$this->template->set_var('delete_url',
$GLOBALS['phpgw']->link('/index.php', $url_params));
$owner = $entry['meta']['owner'];
if($this->contacts->check_perms($this->contacts->grants[$owner],PHPGW_ACL_EDIT)
|| $owner == $GLOBALS['phpgw_info']['user']['account_id'])
{
//show edit button
$url_params= array(
'menuaction'=> 'addbook.generic.main',
'id' => $id,
'mode' => 'edit',
'target' => $target
);
$buttons = '<form name=\'edit_form\'
action=\''.$GLOBALS['phpgw']->link('/index.php', $url_params).'\'
method=\'post\'>';
$buttons.= '<td align=\'right\'>';
$buttons.= '<input type=\'hidden\'
name=\'mode\' value=\'edit\'>';
$buttons.= '<input type=submit value=\'edit\'>';
$buttons.= '</td></form>';
}
else
{
$buttons = '<td> </td>';
}
if($this->contacts->check_perms($this->contacts->grants[$owner],PHPGW_ACL_DELETE)
|| $owner == $GLOBALS['phpgw_info']['user']['account_id'])
{
//show delete button
$url_params= array(
'menuaction'=>
'addbook.functions.confirm',
'id' => $id,
'target' => $target
);
$buttons.= '<form name=\'delete_form\'
action=\''.$GLOBALS['phpgw']->link('/index.php', $url_params).'\'
method=\'post\'>';
$buttons.= '<td align=\'right\'>';
$buttons.= '<input type=submit
value=\'delete\'>';
$buttons.= '</td></form>';
}
else
{
$buttons.= '<td> </td>';
}
$this->template->set_var('buttons', $buttons);
$this->template->set_var('cancel_url',
$GLOBALS['phpgw']->link('/addbook/index.php'));
$this->template->set_var('th_bg',
$GLOBALS['phpgw_info']['theme']['th_bg']);
$this->template->set_var('lang_back',
$GLOBALS['phpgw']->lang('back'));
$this->template->pfp("out","show");
//$this->template->parse("out","show");
$GLOBALS['phpgw']->hooks->process('addressbook_view');
}
function get_meta($id='', $target='')
{
if($id !='' && $target != '')
{
$sql = 'SELECT * FROM phpgw_addbook_meta';
$sql.= ' WHERE '.$target.'_id = '.$id;
$this->db->query($sql);
$this->db->next_record();
$modified = $this->db->f('modified');
if($modied == '')
{
$modified = $this->db->f('created');
}
$temp = array(
'owner' => $this->db->f('created_by'),
'modified' => $modified
);
return $temp;
}
return;
}
function map_to_array($input, $target)
{
if ($input == '')
{
return;
}
$tmp = array();
if($target == 'person')
{
$tmp = array();
$tmp['main']['title'] = $input['title'];
$tmp['main']['first_name'] =
$input['first_name'];
$tmp['main']['middle'] = $input['middle'];
$tmp['main']['last_name'] = $input['last_name'];
$tmp['main']['day'] = $input['day'];
$tmp['main']['month'] = $input['month'];
$tmp['main']['year'] = $input['year'];
$tmp['main']['day'] = $input['day'];
$tmp['main']['gender'] = $input['gender'];
$tmp['rel']['job'] = $input['job'];
$tmp['rel']['org_link'] = $input['org_link'];
$tmp['contacts']['b_phone'] = $input['b_phone'];
$tmp['contacts']['p_phone'] = $input['p_phone'];
$tmp['contacts']['b_email'] = $input['b_email'];
$tmp['contacts']['p_email'] = $input['p_email'];
$tmp['contacts']['mobile'] = $input['mobile'];
$tmp['contacts']['fax'] = $input['fax'];
}
else
{
$tmp['main']['name'] = $input['name'];
$tmp['main']['belongs_to'] =
$input['belongs_to'];
$tmp['main']['middle'] = $input['middle'];
$tmp['main']['last_name'] = $input['last_name'];
$tmp['contacts']['phone'] = $input['phone'];
$tmp['contacts']['fax'] = $input['fax'];
$tmp['contacts']['email'] = $input['email'];
$tmp['contacts']['www'] = $input['www'];
}
$tmp['main']['notes'] = $input['notes'];
$tmp['address']['street'] = $input['street'];
$tmp['address']['postal_code'] = $input['postal_code'];
$tmp['address']['po_box'] = $input['po_box'];
$tmp['address']['city'] = $input['city'];
$tmp['address']['state'] = $input['state'];
$tmp['address']['country'] = $input['country'];
$tmp['contacts']['pref'] = $input['pref'];
$tmp['contact'] = $input['contact'];
$tmp['contact_category'] = $input['contact_category'];
$tmp['meta']['access'] = $input['access'];
$tmp['meta']['category'] = $input['category'];
return $tmp;
}
function main()
{
$mode = $GLOBALS['HTTP_GET_VARS']['mode'];
$target = $GLOBALS['HTTP_GET_VARS']['target'];
$input = $GLOBALS['HTTP_POST_VARS'][$target];
//map to 2d-array
//1d-array is used in forms for php3-compatibility
$input = $this->map_to_array($input, $target);
$this->already_contacts =
$GLOBALS['HTTP_POST_VARS']['already_contacts'];
$id = $GLOBALS['HTTP_GET_VARS']['id'];
//input is empty if edit is startet the first time
//then, input comes from the database
if($input == '' && $mode == 'edit')
{
$input =
$this->contacts->read_single_entry($id, $target);
$tmp = array();
if($target == 'person')
{
$input['main']['day']=
intval(substr($input['birthday'], 8));
$input['main']['month']=
intval(substr($input['birthday'], 5, 2));
$input['main']['year']=
intval(substr($input['birthday'], 0, 4));
}
$nr=0;
while(@list($foo, $value) = each
($input['extra']))
{
$nr++;
$tmp['contact_category_'.$nr] =
$value['category_id'];
$tmp['contact_'.$nr] =
$value['contact'];
}
$tmp['nr'] = $nr;
$this->already_contacts = $tmp;
}
if($target == 'person')
{
$this->addbook_obj =
CreateObject('addbook.person');
}
else if($target == 'org')
{
$this->addbook_obj =
CreateObject('addbook.org');
}
if($GLOBALS['HTTP_POST_VARS']['cancel'])
{
Header('Location: ' .
$GLOBALS['phpgw']->link('/addbook/index.php'));
}
else if($GLOBALS['HTTP_POST_VARS']['delete'])
{
$url_params= array(
'menuaction'=>
'addbook.functions.confirm',
'id' => $id,
'target' => $target
);
Header('Location:
'.$GLOBALS['phpgw']->link('/index.php', $url_params));
}
//if a new contact like email shall be added
if($GLOBALS['HTTP_POST_VARS']['add_contact'] &&
$input['contact'] != '')
{
$this->already_contacts =
$this->functions->session_add($input, $this->already_contacts);
}
if($GLOBALS['HTTP_POST_VARS']['delete_contact'])
{
$this->already_contacts =
$this->functions->session_update($this->already_contacts);
}
//there are two modes: add means adding a new entry
//edit means editing an already existing entry
//if button save is clicked
if($GLOBALS['HTTP_POST_VARS']['save'])
{
if($mode == 'add')
{
$this->addbook_obj->add($input,
$this->already_contacts);
}
else if($mode == 'edit')
{
$this->addbook_obj->update($input,
$this->already_contacts, $id);
}
}
//session_get_output creates the table-formatted output
of the already existing contacts for this entry
$contact_data =
$this->functions->session_get_output($mode, $this->already_contacts);
//because the variables in person || org differ from
each other there are two different templates
//addbook_obj refers to the person || org object
$this->addbook_obj->render_template($input,
$contact_data, $mode, $id);
}
}
?>
--- NEW FILE ---
<?php
/**************************************************************************\
* phpGroupWare Application - addbook
*
* http://www.phpgroupware.org
*
* Written by Heiko Schwarzenberg <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 org
{
function org()
{
$GLOBALS['phpgw']->country =
CreateObject('phpgwapi.country');
$this->template = CreateObject('phpgwapi.Template',
$GLOBALS['phpgw']->common->get_tpl_dir('addbook'));
$this->font= '<font face=\'arial, helvetica\'
size=\'-1\'>';
$GLOBALS['phpgw']->nextmatchs =
CreateObject('phpgwapi.nextmatchs');
$this->contacts =
CreateObject('addbook.addbook_contacts');
$this->cats = CreateObject('phpgwapi.categories');
$this->uiaddbook = CreateObject('addbook.uiaddbook');
$this->functions = CreateObject('addbook.functions');
$this->db = $GLOBALS['phpgw']->db;
}
function add($org, $already_contacts)
{
//user has to fill at least org_name
if($org['main']['name'] != '')
{
$account_lid =
$GLOBALS['phpgw_info']['user']['account_lid'];
$account_id =
$GLOBALS['phpgw_info']['user']['account_id'];
$access = 'public' ;
if($org['meta']['access'] == 'on')
{
$access = 'private';
}
$id = $this->functions->get_next_id();
$sql = 'INSERT INTO phpgw_addbook_org_main(id,
name, notes, belongs_to_id)';
$sql.= ' VALUES
('.$id.',\''.$org['main']['name'].'\',\''.$org['main']['notes'].'\',\''.$org['main']['belongs_to'].'\')';
$this->db->query($sql);
$sql = 'INSERT INTO phpgw_addbook_address (id,
street, po_box, postal_code, city, state, country)';
$sql.= ' VALUES
('.$id.',\''.$org['address']['street'].'\',\''.$org['address']['po_box'].'\',\''.$org['address']['postal_code'].'\',\''.$org['address']['city'].'\',\''.$org['address']['state'].'\',\''.$org['address']['country'].'\')';
$this->db->query($sql);
$sql = 'INSERT INTO phpgw_addbook_ocontacts
(id, phone, fax, email, www, pref)';
$sql.= ' VALUES
('.$id.',\''.$org['contacts']['phone'].'\',\''.$org['contacts']['fax'].'\',\''.$org['contacts']['email'].'\',\''.$org['contacts']['www'].'\',
\''. $org['contacts']['pref'].'\')';
')';
$this->db->query($sql);
if($already_contacts['nr'] > 0)
{
for($i=1; $i<= $already_contacts['nr'];
$i++)
{
$sql = 'INSERT INTO
phpgw_addbook_contacts (id, contact_category_id, contact)';
$sql.= 'VALUES
('.$id.','.(int)$already_contacts['contact_category_'.$i].',\''.$already_contacts['contact_'.$i].
'\')';
$GLOBALS['phpgw']->db->query($sql);
}
}
$sql = 'INSERT INTO phpgw_addbook_meta(id,
owner, created, modifier, modified, access, cat_id, lid, tid)';
$sql.= ' VALUES ('.$id.','.$account_id.',
NOW(), NULL, NULL, \''.$access.'\', \''.$org['meta']['category'].'\',
\''.$account_lid.'\', \'\')';
$this->db->query($sql);
Header('Location: ' .
$GLOBALS['phpgw']->link('/addbook/index.php'));
}
}
function update($org, $already_contacts, $id)
{
//user has to fill at least first_name
if($org['main']['name'] != '')
{
$account_lid =
$GLOBALS['phpgw_info']['user']['account_lid'];
$account_id =
$GLOBALS['phpgw_info']['user']['account_id'];
$access = 'public' ;
if($org['meta']['access'] == 'on')
{
$access = 'private';
}
$sql = 'UPDATE phpgw_addbook_org_main SET ';
$sql.= 'name = \''.$org['main']['name'].'\', ';
$sql.= 'notes = \''.$org['main']['notes'].'\',
';
$sql.= 'belongs_to_id =
\''.$org['main']['belongs_to'].'\'';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
}
$sql = 'UPDATE phpgw_addbook_address SET ';
$sql.= 'street = \''.$org['address']['street'].'\', ';
$sql.= 'po_box = \''.$org['address']['po_box'].'\', ';
$sql.= 'postal_code =
\''.$org['address']['postal_code'].'\', ';
$sql.= 'city = \''.$org['address']['city'].'\', ';
$sql.= 'state = \''.$org['address']['state'].'\', ';
$sql.= 'country = \''.$org['address']['country'].'\' ';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
$sql = 'UPDATE phpgw_addbook_ocontacts SET ';
$sql.= 'phone = \''.$org['contacts']['phone'].'\', ';
$sql.= 'fax = \''.$org['contacts']['fax'].'\', ';
$sql.= 'email = \''.$org['contacts']['email'].'\', ';
$sql.= 'www = \''.$org['contacts']['www'].'\', ';
$sql.= 'pref = \''.$org['contacts']['pref'].'\' ';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
//update the contacts for this id
//easiest way is to delete all the old ones for this id
//and insert the new ones
$sql = 'DELETE FROM phpgw_addbook_contacts';
$sql.= ' WHERE id='.$id;
$this->db->query($sql);
if($already_contacts['nr'] > 0)
{
for($i=1; $i<= $already_contacts['nr'];
$i++)
{
$sql = 'INSERT INTO
phpgw_addbook_contacts (id, contact_category_id, contact)';
$sql.= 'VALUES
('.$id.','.(int)$already_contacts['contact_category_'.$i].',\''.$already_contacts['contact_'.$i].
'\')';
$GLOBALS['phpgw']->db->query($sql);
}
}
//update meta information for this entry
$sql = 'UPDATE phpgw_addbook_meta SET ';
$sql.= 'modifier = \''.$account_id.'\', ';
$sql.= 'modified = NOW(), ';
$sql.= 'access = \''.$access.'\', ';
$sql.= 'cat_id = \''.$org['meta']['category'].'\',';
$sql.= 'lid = \''.$account_lid.'\',';
$sql.= 'tid = \'\'';
$sql.= ' WHERE id = '.$id;
$this->db->query($sql);
Header('Location: ' .
$GLOBALS['phpgw']->link('/index.php',
"menuaction=addbook.generic.view&id=$id&target=org"));
}
function render_template($org, $contact_data, $mode, $id)
{
while(@list($field, $value) = each($org['main']))
{
if($field != '')
{
$this->template->set_var($field,
$value);
}
}
while(@list($field, $value) = each($org['address']))
{
if($field != '')
{
$this->template->set_var($field,
$value);
}
}
while(@list($field, $value) = each($org['contacts']))
{
if($field != '')
{
$this->template->set_var($field,
$value);
}
}
while(@list($field, $value) = each($org['meta']))
{
if($field != '')
{
$this->template->set_var($field,
$value);
}
}
$private = '' ;
if($org['meta']['access'] == 'private')
{
$private = 'checked';
}
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
$this->template->set_file(array('add_org' =>
'add_org.tpl'));
$s = CreateObject('phpgwapi.sbox');
$box_contact =
$this->uiaddbook->get_box('phpgw_addbook_contact_cat', 'contact_category_id',
'category_name', 'org[contact_category]');
$box_organization =
$this->uiaddbook->get_box('phpgw_addbook_org_main', 'id', 'name',
'org[belongs_to]', $org['main']['belongs_to'], $org['main']['id']);
if($mode == 'edit')
{
$owner = $org['meta']['owner'];
if($this->contacts->check_perms($this->contacts->grants[$owner],PHPGW_ACL_DELETE)
|| $owner == $GLOBALS['phpgw_info']['user']['account_id'])
{
$buttons = '<td><input type=\'submit\'
name=\'save\' value=\''.lang('Save').'\'></td>';
$buttons.= '<td colspan=\'4\'
align=\'right\'>';
$buttons.= '<input type=submit
name=\'delete\' value=\''.lang('Delete').'\'>';
$buttons.= '</td></form>';
}
else
{
$buttons = '<td colspan=\'5\'><input
type=\'submit\' name=\'save\' value=\''.lang('Save').'\'></td>';
}
}
else
{
$buttons = '<td colspan=\'5\'><input
type=\'submit\' name=\'save\' value=\''.lang('add').'\'></td>';
}
$this->template->set_var('lang_cancel',lang('cancel'));
$this->template->set_var('buttons', $buttons);
$this->template->set_var('already_contacts_url',$GLOBALS['phpgw']->link('/index.php',
"menuaction=addbook.generic.main&mode=$mode"));
$this->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',
"menuaction=addbook.generic.main&action=save&mode=$mode&id=$id&target=org"));
$this->template->set_var('cancel_url',$GLOBALS['phpgw']->link('/index.php',
'menuaction=addbook.generic.leave'));
$this->template->set_var('row_on',
$GLOBALS['phpgw_info']['theme']['row_on']);
$this->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);
$this->template->set_var('th_bg',
$GLOBALS['phpgw_info']['theme']['th_bg']);
$check = $org['contacts']['pref'].'_checked';
$this->template->set_var($check, 'checked');
$this->template->set_var('id', $id);
$this->template->set_var('cancel_url',$GLOBALS['phpgw']->link('/index.php',
'menuaction=addbook.generic.leave'));
$this->template->set_var('lang_add_organization',lang('add organization'));
$this->template->set_var('lang_company',lang('Company'));
$this->template->set_var('lang_notes',lang('Notes'));
$this->template->set_var('lang_street',lang('Street'));
$this->template->set_var('lang_po_box',lang('po box'));
$this->template->set_var('lang_postal_code',lang('Postal code'));
$this->template->set_var('lang_city',lang('City'));
$this->template->set_var('lang_state',lang('Region'));
$this->template->set_var('lang_country',lang('Country'));
$this->template->set_var('country',$GLOBALS['phpgw']->country->form_select($country,'org[country]'));
$this->template->set_var('lang_add',lang($mode));
$this->template->set_var('lang_add_contact',lang('add'));
$this->template->set_var('lang_reset',lang('clear'));
$this->template->set_var('lang_contact',lang('contact'));
$this->template->set_var('lang_belongs_to',lang('Department of'));
$this->template->set_var('lang_phone',lang('Phone'));
$this->template->set_var('lang_fax',lang('Fax'));
$this->template->set_var('lang_email',lang('Email'));
$this->template->set_var('lang_www',lang('Homepage'));
$this->template->set_var('lang_category',lang('category'));
$this->template->set_var('contact_cat', $box_contact);
$this->template->set_var('already_contacts',
$contact_data);
$this->template->set_var('organizations',
$box_organization);
$this->template->set_var('lang_head_contact', lang('add
extra contacts here'));
$this->template->set_var('lang_preferred',lang('preferred'));
$this->template->set_var('box_categories',$this->cats->formated_list('select','all',
$org['meta']['category'],'True'));
$this->template->set_var('lang_private',lang('private'));
$this->template->set_var('lang_delete',lang('delete'));
$this->template->set_var('private', $private);
$this->template->parse('out','add_org',false);
$this->template->set_var('lang_delete',lang('delete'));
$this->template->set_var('mode', 'add');
$this->template->pfp('out', 'add_org');
}
}
?>
--- NEW FILE ---
<?php
/**************************************************************************\
* phpGroupWare Application - addbook
*
* http://www.phpgroupware.org
*
* Written by Heiko Schwarzenberg <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 person
{
function person()
{
$GLOBALS['phpgw']->country =
CreateObject('phpgwapi.country');
$this->template = CreateObject('phpgwapi.Template',
$GLOBALS['phpgw']->common->get_tpl_dir('addbook'));
$this->template->set_file(array('add_person' =>
'add_person.tpl'));
$this->font= '<font face=\'arial, helvetica\'
size=\'-1\'>';
$GLOBALS['phpgw']->nextmatchs =
CreateObject('phpgwapi.nextmatchs');
$this->contacts =
CreateObject('addbook.addbook_contacts');
$this->cats = CreateObject('phpgwapi.categories');
$this->uiaddbook = CreateObject('addbook.uiaddbook');
$this->functions = CreateObject('addbook.functions');
}
function add($input, $already_contacts)
{
//user has to fill at least first_name
if($input['main']['first_name'] != '' ||
$input['main']['last_name'] != '')
{
$birthday =
$input['main']['year']."-".$input['main']['month']."-".$input['main']['day'];
if($birthday == '--')
{
$birthday = '';
}
$account_id =
$GLOBALS['phpgw_info']['user']['account_id'];
$account_lid =
$GLOBALS['phpgw_info']['user']['account_lid'];
$access = 'public' ;
if($input['meta']['access'] == 'on')
{
$access = 'private';
}
$id = $this->functions->get_next_id();
$sql = 'INSERT INTO
phpgw_addbook_person_main(id, title, last_name, middle, first_name, birthday,
gender, notes)';
$sql.= ' VALUES
('.$id.',\''.$input['main']['title'].'\',\''.$input['main']['last_name'].'\',\''.$input['main']['middle'].'\',\''.$input['main']['first_name'].'\',\''.$birthday.'\',\''.$input['main']['gender'].'\',
\''.$input['main']['notes'].'\')';
$GLOBALS['phpgw']->db->query($sql);
$sql = 'INSERT INTO phpgw_addbook_relation(id,
job, org_link)';
$sql.= ' VALUES
('.$id.',\''.$input['rel']['job'].'\',\''.$input['rel']['org_link'].'\')';
$GLOBALS['phpgw']->db->query($sql);
$sql = 'INSERT INTO phpgw_addbook_address (id,
street, po_box, postal_code, city, state, country)';
$sql.= ' VALUES
('.$id.',\''.$input['address']['street'].'\',\''.$input['address']['po_box'].'\',\''.$input['address']['postal_code'].'\',\''.$input['address']['city'].'\',\''.$input['address']['state'].'\',\''.$input['address']['country'].'\')';
')';
$GLOBALS['phpgw']->db->query($sql);
$sql = 'INSERT INTO phpgw_addbook_pcontacts
(id, b_phone, p_phone, b_email, p_email, mobile, fax, pref)';
$sql.= ' VALUES
('.$id.',\''.$input['contacts']['b_phone'].'\',\''.$input['contacts']['p_phone'].'\',\''.$input['contacts']['b_email'].'\',\''.$input['contacts']['p_email'].'\',\''.$input['contacts']['mobile'].'\',\''.$input['contacts']['fax'].'\',\''.$input['contacts']['pref'].'\')';
')';
$GLOBALS['phpgw']->db->query($sql);
if($already_contacts['nr'] > 0)
{
for($i=1; $i<= $already_contacts['nr'];
$i++)
{
$sql = 'INSERT INTO
phpgw_addbook_contacts (id, contact_category_id, contact)';
$sql.= 'VALUES
('.$id.','.(int)$already_contacts['contact_category_'.$i].',\''.$already_contacts['contact_'.$i].
'\')';
$GLOBALS['phpgw']->db->query($sql);
}
}
$sql = 'INSERT INTO phpgw_addbook_meta(id,
owner, created, modifier, modified, access, cat_id, lid, tid)';
$sql.= ' VALUES('.$id.','.$account_id.', NOW(),
NULL, NULL, \''.$access.'\', \''.$input['meta']['category'].'\',
\''.$account_lid.'\', \'\')';
$GLOBALS['phpgw']->db->query($sql);
Header('Location: ' .
$GLOBALS['phpgw']->link('/addbook/index.php'));
}
}
function update($input, $already_contacts, $id)
{
//user has to fill at least first_name
if($input['main']['first_name'] != '' ||
$input['main']['last_name'] != '')
{
$birthday =
$input['main']['year']."-".$input['main']['month']."-".$input['main']['day'];
if($birthday == '--')
{
$birthday = '';
}
$account_lid =
$GLOBALS['phpgw_info']['user']['account_lid'];
$account_id =
$GLOBALS['phpgw_info']['user']['account_id'];
$sql = 'UPDATE phpgw_addbook_person_main SET ';
$sql.= 'title =
\''.$input['main']['title'].'\', ';
$sql.= 'last_name =
\''.$input['main']['last_name'].'\', ';
$sql.= 'middle =
\''.$input['main']['middle'].'\',';
$sql.= 'first_name =
\''.$input['main']['first_name'].'\', ';
$sql.= 'birthday = \''.$birthday.'\', ';
$sql.= 'gender =
\''.$input['main']['gender'].'\', ';
$sql.= 'notes =
\''.$input['main']['notes'].'\'';
$sql.= ' WHERE id = '.$id;
$GLOBALS['phpgw']->db->query($sql);
$sql = 'UPDATE phpgw_addbook_relation SET ';
$sql.= 'org_link =
\''.$input['rel']['org_link'].'\', ';
$sql.= 'job = \''. $input['rel']['job'].'\'';
$sql.= ' WHERE id = '.$id;
$GLOBALS['phpgw']->db->query($sql);
$sql = 'UPDATE phpgw_addbook_address SET ';
$sql.= 'street =
\''.$input['address']['street'].'\', ';
$sql.= 'po_box =
\''.$input['address']['po_box'].'\', ';
$sql.= 'postal_code =
\''.$input['address']['postal_code'].'\', ';
$sql.= 'city =
\''.$input['address']['city'].'\', ';
$sql.= 'state = \''.$input
['address']['state'].'\', ';
$sql.= 'country =
\''.$input['address']['country'].'\' ';
$sql.= ' WHERE id = '.$id;
$GLOBALS['phpgw']->db->query($sql);
$sql = 'UPDATE phpgw_addbook_pcontacts SET ';
$sql.= 'b_phone =
\''.$input['contacts']['b_phone'].'\', ';
$sql.= 'p_phone =
\''.$input['contacts']['p_phone'].'\', ';
$sql.= 'b_email =
\''.$input['contacts']['b_email'].'\', ';
$sql.= 'p_email =
\''.$input['contacts']['p_email'].'\', ';
$sql.= 'mobile =
\''.$input['contacts']['mobile'].'\', ';
$sql.= 'fax =
\''.$input['contacts']['fax'].'\', ';
$sql.= 'pref =
\''.$input['contacts']['pref'].'\' ';
$sql.= ' WHERE id = '.$id;
$GLOBALS['phpgw']->db->query($sql);
//update the contacts for this id
//easiest way is to delete all the old ones for
this id
//and insert the new ones
$sql = 'DELETE FROM phpgw_addbook_contacts';
$sql.= ' WHERE id='.$id;
$GLOBALS['phpgw']->db->query($sql);
for($i=1; $i <= $already_contacts['nr']; $i++)
{
$sql = 'INSERT INTO
phpgw_addbook_contacts (id, contact_category_id, contact)';
$sql.= 'VALUES
('.$id.','.(int)$already_contacts['contact_category_'.$i].',\''.$already_contacts['contact_'.$i].'\')';
$GLOBALS['phpgw']->db->query($sql);
}
$access = 'public' ;
if($input['meta']['access'] == 'on')
{
$access = 'private';
}
//update meta information for this entry
$sql = 'UPDATE phpgw_addbook_meta SET ';
$sql.= 'modifier = \''.$account_id.'\', ';
$sql.= 'modified = NOW(), ';
$sql.= 'access = \''.$access.'\', ';
$sql.= 'cat_id =
\''.$input['meta']['category'].'\', ';
$sql.= 'lid = \''.$account_lid.'\', ';
$sql.= 'tid = \'\'';
$sql.= ' WHERE id = '.$id;
$GLOBALS['phpgw']->db->query($sql);
Header('Location: ' .
$GLOBALS['phpgw']->link('/index.php',
"menuaction=addbook.generic.view&id=$id&target=person"));
}
}
function render_template($input, $contact_data, $mode, $id)
{
if($input['main']['gender']== 'male')
{
$male_checked = 'checked';
$female_checked = '';
}
else
{
$male_checked = '';
$female_checked = 'checked';
}
$access = '' ;
if($input['meta']['access'] == 'on')
{
$access = 'checked';
}
if($mode == 'edit')
{
$owner = $input['meta']['owner'];
if($this->contacts->check_perms($this->contacts->grants[$owner],PHPGW_ACL_DELETE)
|| $owner == $GLOBALS['phpgw_info']['user']['account_id'])
{
$buttons = '<td><input type=\'submit\'
name=\'save\' value=\''.lang('Save').'\'></td>';
$buttons.= '<td colspan=\'4\'
align=\'right\'>';
$buttons.= '<input type=submit
name=\'delete\' value=\''.lang('Delete').'\'>';
$buttons.= '</td></form>';
}
else
{
$buttons = '<td colspan=\'5\'><input
type=\'submit\' name=\'save\' value=\''.lang('Save').'\'></td>';
}
}
else
{
$buttons = '<td colspan=\'5\'><input
type=\'submit\' name=\'save\' value=\''.lang('add').'\'></td>';
}
$this->template->set_var('buttons', $buttons);
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
$this->template->set_file(array('add_person' =>
'add_person.tpl'));
$s = CreateObject('phpgwapi.sbox');
$sbox_day = $s->getDays('person[day]',
$input['main']['day']);
$sbox_month = $this->uiaddbook->month('person[month]',
$input['main']['month']);
$sbox_year = $s->getYears('person[year]',
$input['main']['year'], '1900', '2001');
$box_contact =
$this->uiaddbook->get_box('phpgw_addbook_contact_cat', 'contact_category_id',
'category_name', 'person[contact_category]');
$box_organization =
$this->uiaddbook->get_box('phpgw_addbook_org_main', 'id', 'name',
'person[org_link]', $input['rel']['org_link']);
$check = $input['contacts']['pref'].'_checked';
$var = array(
'title' => $input['main']['title'],
'first_name' => $input['main']['first_name'],
'middle' => $input['main']['middle'],
'last_name' => $input['main']['last_name'],
'notes' => $input['main']['notes'],
'b_phone' => $input['contacts']['b_phone'],
'p_phone' => $input['contacts']['p_phone'],
'b_email' => $input['contacts']['b_email'],
'p_email' => $input['contacts']['p_email'],
'mobile' => $input['contacts']['mobile'],
'fax' => $input['contacts']['fax'],
'street' => $input['address']['street'],
'postal_code' =>
$input['address']['postal_code'],
'po_box' => $input['address']['po_box'],
'city' => $input['address']['city'],
'state' => $input['address']['state'],
'job' => $input['rel']['job'],
'sbox_day' => $sbox_day,
'sbox_month' => $sbox_month,
'sbox_year' => $sbox_year,
'lang_cancel'=> lang('cancel'),
$check => 'checked',
'already_contacts_url' =>
$GLOBALS['phpgw']->link('/index.php',
"menuaction=addbook.generic.main&mode=$mode"),
'action_url' =>
$GLOBALS['phpgw']->link('/index.php',
"menuaction=addbook.generic.main&action=save&mode=$mode&id=$id&target=person"),
'cancel_url' =>
$GLOBALS['phpgw']->link('/index.php', 'menuaction=addbook.generic.leave'),
'row_on' =>
$GLOBALS['phpgw_info']['theme']['row_on'],
'row_off' =>
$GLOBALS['phpgw_info']['theme']['row_off'],
'lang_add_person' => lang('add
person'),
'th_bg' =>
$GLOBALS['phpgw_info']['theme']['th_bg'],
'lang_title' => lang('title'),
'lang_firstname' =>
lang('firstname'),
'lang_middle' => lang('middle'),
'lang_lastname' => lang('lastname'),
'lang_birthday' => lang('birthday'),
'lang_gender' => lang('gender'),
'lang_notes' => lang('notes'),
'female_checked'=> $female_checked,
'male_checked' => $male_checked,
'lang_female' => lang('female'),
'lang_male' => lang('male'),
'lang_street' => lang('street'),
'lang_po_box' => lang('po box'),
'lang_postal_code' => lang('postal
code'),
'lang_city' => lang('city'),
'lang_state' => lang('state'),
'lang_country' => lang('country'),
'country' =>
$GLOBALS['phpgw']->country->form_select($country, 'person[country]'),
'lang_head_organization' =>
lang('choose the organization this person belongs to'),
'lang_organization' =>
lang('organization'),
'lang_job' => lang('job'),
'organizations' => $box_organization,
'lang_b_phone' => lang('business phone'),
'lang_b_email' => lang('business email'),
'lang_p_email' => lang('private email'),
'lang_p_phone' => lang('private phone'),
'lang_mobile' => lang('mobile phone'),
'lang_fax' => lang('fax'),
'lang_head_contact' => lang('add extra
contacts here'),
'lang_contact' => lang('contact'),
'lang_category' => lang('category'),
'contact_cat' => $box_contact,
'already_contacts' => $contact_data,
'lang_private' => lang('private'),
'private' => $access,
'lang_category' => lang('Category'),
'box_categories' =>
$this->cats->formated_list('select','all',$input['meta']['category'],'True'),
'lang_preferred' =>
lang('preferred'),
'lang_delete' => lang('delete'),
'lang_business' => lang('at work'),
'lang_add' => lang($mode),
'lang_add_contact' => lang('add'),
'lang_reset'=>lang('clear'),
'mode'=> $mode
);
$this->template->set_var($var);
$this->template->pfp('out', 'add_person');
}
/*function del_()
{
$id = $GLOBALS['HTTP_GET_VARS']['id'];
$this->del_entry_($id, 'person');
}*/
}
?>
--- NEW FILE ---
<?php
/**************************************************************************\
* phpGroupWare Application - addbook
*
* http://www.phpgroupware.org
*
* Written by Heiko Schwarzenberg <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 prefs
{
var $public_functions = array(
'show_prefs' => True,
'save_prefs' => True,
'migrate' => True,
'edit_categories' => True
);
function prefs()
{
$this->grants =
$GLOBALS['phpgw']->acl->get_grants('addbook');
$this->template = CreateObject('phpgwapi.Template',
$GLOBALS['phpgw']->common->get_tpl_dir('addbook'));
$this->categories = CreateObject('phpgwapi.categories');
$this->contacts =
CreateObject('addbook.addbook_contacts');
$this->prefs =
$GLOBALS['phpgw_info']['user']['preferences']['addbook'];
$this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
$this->db = $GLOBALS['phpgw']->db;
$this->db2 = $this->db;
$this->functions = CreateObject('addbook.functions');
}
function show_prefs()
{
$submit = $GLOBALS['HTTP_POST_VARS']['submit'];
$p_prefs = $GLOBALS['HTTP_POST_VARS']['p_prefs'];
$o_prefs = $GLOBALS['HTTP_POST_VARS']['o_prefs'];
$qfields = $this->contacts->map_fields;
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
if($submit)
{
$totalerrors = 0;
//persons
if (!count($p_prefs))
{
$errors[$totalerrors++] = lang('You
must select at least 1 column for persons to display');
}
if (!count($o_prefs))
{
$errors[$totalerrors++] = lang('You
must select at least 1 column for organizations to display');
}
if($totalerrors == 0)
{
$prefs = array_merge($p_prefs,
$o_prefs);
@reset($qfields);
$this->save_prefs($prefs, $qfields,
$fcat_id);
}
if ($totalerrors)
{
echo '<p><center>' .
$GLOBALS['phpgw']->common->error_list($errors) . '</center>';
}
}
$this->template->set_file(array('preferences' =>
'preferences.tpl'));
$GLOBALS['phpgw']->preferences->read_repository();
@reset($qfields);
while (list($col, $descr) = each($qfields))
{
/* yank the *'s prior to testing for a valid
column description */
$coltest = ereg_replace('\*','',$col);
if ($coltest)
{
if
($GLOBALS['phpgw_info']['user']['preferences']['addbook'][$col] == 'on')
{
$this->template->set_var($col.'_checked',' checked');
}
else
{
$this->template->set_var($col.'_checked','');
}
}
}
$this->template->set_var('lang_addbook_prefs', 'Addbook
'.lang('Preferences'));
$this->template->set_var('lang_fields',lang('Fields to
show in address list'));
$this->template->set_var('action_url',
$GLOBALS['phpgw']->link('/index.php', 'menuaction=addbook.prefs.show_prefs'));
$this->template->set_var('lang_person',lang('Person'));
$this->template->set_var('lang_organization',lang('Organization'));
$this->template->set_var('lang_title',lang('Title'));
$this->template->set_var('lang_first_name',lang('First
Name'));
$this->template->set_var('lang_middle',lang('Middle'));
$this->template->set_var('lang_last_name',lang('Last
Name'));
$this->template->set_var('lang_birthday',lang('birthday'));
$this->template->set_var('lang_gender',lang('Gender'));
$this->template->set_var('lang_street',lang('Street'));
$this->template->set_var('lang_p_email',lang('Home
Email'));
$this->template->set_var('lang_b_email',lang('Business
Email'));
$this->template->set_var('lang_b_phone',lang('Business
Phone'));
$this->template->set_var('lang_p_phone',lang('Home
Phone'));
$this->template->set_var('lang_mobile',lang('Mobile
Phone'));
$this->template->set_var('lang_number',lang('Number'));
$this->template->set_var('lang_postal_code',lang('Postal Code'));
$this->template->set_var('lang_po_box',lang('PO Box'));
$this->template->set_var('lang_city',lang('City'));
$this->template->set_var('lang_state',lang('Region'));
$this->template->set_var('lang_country',lang('Country'));
$this->template->set_var('lang_contact',lang('Preferred
Contact'));
$this->template->set_var('lang_job',lang('Job'));
$this->template->set_var('lang_name',lang('Name'));
$this->template->set_var('lang_email',lang('Email'));
$this->template->set_var('lang_fax',lang('Fax'));
$this->template->set_var('lang_phone',lang('Phone'));
$this->template->set_var('lang_www',lang('Homepage'));
$this->template->set_var('lang_parent_organization',lang('Parent
Organization'));
$this->template->set_var('lang_submit',lang('submit'));
$this->template->set_var('th_bg',
$GLOBALS['phpgw_info']['theme']['th_bg']);
$this->template->set_var('th_text',$GLOBALS['phpgw_info']['theme']['th_text']);
$this->template->set_var('row_on',
$GLOBALS['phpgw_info']['theme']['row_on']);
$this->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);
$this->template->pparse('out','preferences');
}
function save_prefs($prefs, $qfields, $fcat_id)
{
$GLOBALS['phpgw']->preferences->read_repository();
if (is_array($prefs))
{
reset($qfields);
while (list($pref,$x) = each($qfields))
{
if ($prefs[$pref] == 'on')
{
$GLOBALS['phpgw']->preferences->add('addbook',$pref,'on');
}
else
{
$GLOBALS['phpgw']->preferences->delete('addbook',$pref);
}
}
}
//doesnt work yet
if($fcat_id)
{
$GLOBALS['phpgw']->preferences->delete('addbook','default_category');
$GLOBALS['phpgw']->preferences->add('addbook','default_category',$fcat_id);
}
unset($prefs);
$GLOBALS['phpgw']->preferences->save_repository(True);
Header('Location: ' .
$GLOBALS['phpgw']->link('/index.php','menuaction=addbook.prefs.show_prefs'));
}
//accesses through administration
//can add custom contact-categories
function edit_categories()
{
$id = $GLOBALS['HTTP_GET_VARS']['id'];
$category_name =
$GLOBALS['HTTP_POST_VARS']['category_name'];
if(isset($id))
{
$sql = 'DELETE FROM phpgw_addbook_contact_cat';
$sql.= ' WHERE contact_category_id='.$id;
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
}
if($category_name != '')
{
$sql = ' INSERT INTO phpgw_addbook_contact_cat
(category_name)';
$sql.= ' VALUES (\''.$category_name.'\')';
$GLOBALS['phpgw']->db->query($sql,__LINE__,__FILE__);
}
$categories = $this->contacts->categories();
while(list($id, $name) = each ($categories))
{
$row_color =
$GLOBALS['phpgw']->nextmatchs->alternate_row_color($row_color);
$url_params= array(
'menuaction' =>
'addbook.prefs.edit_categories',
'id' => $id
);
$table_data.='<tr
bgcolor=\''.$row_color.'\'><td align="center">'.$name.'</td>';
$table_data.='<td><a
href=\''.$GLOBALS['phpgw']->link('/index.php',
$url_params).'\'>'.$GLOBALS['phpgw']->lang('delete').'</td></tr>';
}
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
$this->template->set_file(array('contact_categories' =>
'edit_categories.tpl'));
$this->template->set_var('table_data', $table_data);
$this->template->set_var('lang_add',
$GLOBALS['phpgw']->lang('add'));
$this->template->set_var('lang_cancel',
$GLOBALS['phpgw']->lang('cancel'));
$this->template->set_var('add_url',
$GLOBALS['phpgw']->link('/index.php',
'menuaction=addbook.prefs.edit_categories'));
$this->template->set_var('cancel_url',
$GLOBALS['phpgw']->link('/preferences/index.php'));
$this->template->parse("out","contact_categories");
$this->template->p("out");
}
function quoted_values($cols)
{
if ($cols == '') return '';
if (!is_array($cols)) $cols = array($cols);
reset($cols);
while (list($nul,$col) = each($cols))
{
if ($sql) $sql .= ',';
switch($col)
{
case '0':
case 'NULL':
$sql .= $col;
break;
case 'cat_id': // DOES NOT
WORK FOR MULTIPLE CAT'S
$sql .= (int)
$this->db->f($col);
break;
default:
$sql .= '\'' .
$this->db->db_addslashes($this->db->f($col)) . '\'';
}
}
return $sql;
}
function write($id,$cols2tables,$line,$file)
{
reset ($cols2tables);
while (list($table,$cols) = each($cols2tables))
{
$sql = "INSERT INTO phpgw_addbook_$table VALUES
($id,".$this->quoted_values($cols) . ')';
$this->db2->query($sql,$line,$file);
}
}
//gets all data from the old addressbook and put it into the
new one
function migrate()
{
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
if($GLOBALS['HTTP_POST_VARS']['migrate_ok'])
{
echo '<p>deleting all rows from the addbook
databases !!!</p>';
$dbs =
array('address','contact_cat','contacts','meta','ocontacts','org_main','pcontacts','person_main','relation');
while (list($nul,$db) = each($dbs))
{
$this->db->query("delete from
phpgw_addbook_$db",__LINE__,__FILE__);
}
$unique_extra = array();//('notes' =>
'note','cat_id' => 'cat_id'); // cols to check beside org_name for orga
identity
// array() = check only org_name
$migrate_persons = array(
'person_main' => array(
'n_prefix',
'n_family',
'n_middle',
'n_given',
'NULL',
'bday',
'NULL',
'note',
'cat_id'
),
'address' => array(
'adr_two_street',
'adr_two_postalcode',
'NULL',
'adr_two_locality',
'adr_two_region',
'adr_two_countryname'
),
'pcontacts' => array(
'tel_work',
'tel_home',
'email',
'email_home',
'tel_cell',
'tel_fax',
'tel_prefer'
)
);
$migrate_orgas = array(
'org_main' => array(
'org_name',
'note',
0,
'cat_id'
),
'address' => array(
'adr_one_street',
'adr_one_postalcode',
NULL,
'adr_one_locality',
'adr_one_region',
'adr_one_countryname'
),
'ocontacts' => array(
'tel_work',
'tel_fax',
'email',
'url',
'tel_prefer'
)
);
$migrate_meta = array(
'meta' =>array(
'zeit',
'owner',
'zeit',
0,
'access',
0,
'lid',
'tid'
)
);
//===============================================================================
// add organisation information
// start with those without a person
echo '<p>add organisation information ...';
$sql = 'SELECT *,now() as zeit FROM
phpgw_addressbook '.
"WHERE org_name <> '' and
n_family = '' and n_given = ''";
$this->db->query($sql,__LINE__,__FILE__);
$anz = 0;
while($this->db->next_record())
{
$this->write($this->db->f('id'),$migrate_orgas+$migrate_meta,__LINE__,__FILE__);
//echo $this->db->f('org_name').':
'.$this->db->f('n_family').', '.$this->db->f('n_given').'<br>';
++$anz;
}
$sql = 'SELECT *,now() as zeit FROM
phpgw_addressbook '.
"WHERE org_name <> '' and
(n_family <> '' or n_given <> '')".
'GROUP BY org_name';
if (is_array($unique_extra) &&
count($unique_extra))
{
$sql .= ',' .
implode(',',$unique_extra);
}
$this->db->query($sql,__LINE__,__FILE__);
//$i= $this->functions->get_next_id();
$this->db2->query('SELECT MAX(id) as max FROM
phpgw_addressbook',__LINE__,__FILE__);
$this->db2->next_record();
$i = $this->db2->f('max') + 1;
while($this->db->next_record())
{
$this->write($i++,$migrate_orgas+$migrate_meta,__LINE__,__FILE__);
//echo $this->db->f('org_name').':
'.$this->db->f('n_family').', '.$this->db->f('n_given').'<br>';
++$anz;
}
echo " $anz OK";
//===============================================================================
//add person information
echo '<p>add person information ...';
$sql = 'SELECT *,now() as zeit FROM
phpgw_addressbook ';
$sql.= "WHERE n_family <> '' or n_given <> ''";
$this->db->query($sql,__LINE__,__FILE__);
$anz = 0;
while($this->db->next_record())
{
$this->write($this->db->f('id'),$migrate_persons+$migrate_meta,__LINE__,__FILE__);
//echo
'<br>'.$this->db->f('org_name').': '.$this->db->f('n_family').',
'.$this->db->f('n_given').': ';
if ($this->db->f('org_name') == '')
{
$this->write($this->db->f('id'),array('relation' =>
array('title','0')),__LINE__,__FILE__);
}
else
{
$sql = 'SELECT id FROM
phpgw_addbook_org_main '.
'WHERE
name='.$this->quoted_values('org_name');
reset($unique_extra);
while (list($neu,$alt) =
each($unique_extra))
{
$sql .= " AND $neu=" .
$this->quoted_values($alt);
}
$this->db2->query($sql,__LINE__,__FILE__);
if (!$this->db2->next_record())
{
// Error Orga not found
}
$sql = 'INSERT INTO
phpgw_addbook_relation VALUES ('.$this->db->f('id').
','.$this->quoted_values('title').','.$this->db2->f('id').')';
$this->db2->query($sql,__LINE__,__FILE__);
}
$anz++;
}
echo " $anz Ok";
//===============================================================================
echo "<br><br>migration successful!";
}
else
{
$this->template->set_file(array('migrate_tpl'
=> 'migrate.tpl'));
$this->template->set_var('lang_descr', lang('Do
you want to migrate your addressbook-data to addbook? <br>No data will be
deleted in addressbook.'));
$this->template->set_var('action_url',
$GLOBALS['phpgw']->link('/index.php', 'menuaction=addbook.prefs.migrate'));
$this->template->set_var('cancel_url',
$GLOBALS['phpgw']->link('/admin/index.php'));
$this->template->set_var('lang_migrate',
lang('Migrate'));
$this->template->set_var('lang_cancel',
lang('Cancel'));
$this->template->parse("out","migrate_tpl");
$this->template->p("out");
}
}
}
?>
--- NEW FILE ---
<?php
/**************************************************************************\
* phpGroupWare - addbook
*
* http://www.phpgroupware.org
*
* Written by heiko 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.
*
\**************************************************************************/
//TODO: xml-rpc doesnt work yet
class soaddbook
{
var $contacts;
var $rights;
var $grants;
var $owner;
function soaddbook()
{
if(!isset($GLOBALS['owner']))
{
$GLOBALS['owner'] = 0;
}
$owner = $GLOBALS['owner'];
$this->contacts =
CreateObject('addbook.addbook_contacts');
$grants = $this->contacts->grants;
/* _debug_array($GLOBALS['phpgw_info']); */
/* _debug_array($grants); */
if(!isset($owner) || !$owner)
{
$owner =
$GLOBALS['phpgw_info']['user']['account_id'];
/* echo $owner; */
$rights = PHPGW_ACL_READ + PHPGW_ACL_ADD +
PHPGW_ACL_EDIT + PHPGW_ACL_DELETE + 16;
/* echo $rights; */
}
else
{
if($grants[$owner])
{
$rights = $grants[$owner];
if (!($rights & PHPGW_ACL_READ))
{
$owner =
$GLOBALS['phpgw_info']['user']['account_id'];
$rights = PHPGW_ACL_READ +
PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE + 16;
}
}
}
$this->rights = $rights;
$this->grants = $grants;
$this->owner = $owner;
}
}
?>
--- NEW FILE ---
<?php
/**************************************************************************\
* phpGroupWare Application - addbook
*
* http://www.phpgroupware.org
*
* Written by Heiko Schwarzenberg <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 uiaddbook
{
function get_box($table='', $column1='', $column2='', $name='',
$selected='', $self_id='')
{
$sql="SELECT * FROM $table";
$GLOBALS['phpgw']->db->query($sql);
$out='<option
value=\'\'>'.$GLOBALS['phpgw']->lang('select').'</option>'."\n";
while($GLOBALS['phpgw']->db->next_record())
{
//select box must'n contain the id itself
if($GLOBALS['phpgw']->db->f("$column1") !=
$self_id)
{
$preselect = '';
if($GLOBALS['phpgw']->db->f("$column1")
== $selected)
{
$preselect = 'selected';
}
$out.='<option
value=\''.$GLOBALS['phpgw']->db->f($column1).'\'
'.$preselect.'>'.$GLOBALS['phpgw']->db->f($column2).'</option>'."\n";
}
}
Return '<select
name=\''.$name.'\'>'."\n".$out."\n".'</select>'."\n";
}
function month($name, $selected=0)
{
$out = '';
for($i=0;$i<13;$i++)
{
$out .= '<option
value="'.($i?$i:'').'"'.($selected!=$i?'':'
selected').'>'.($i?$i:'').'</option>'."\n";
}
return '<select
name="'.$name.'">'."\n".$out.'</select>'."\n";
}
}
?>
***** Error reading new file: [Errno 2] No such file or directory:
'hook_admin.inc.php'
***** Error reading new file: [Errno 2] No such file or directory:
'hook_deleteaccount.inc.php'
***** Error reading new file: [Errno 2] No such file or directory:
'hook_preferences.inc.php'
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] CVS: phpgroupware/addbook/inc class.addbook_contacts.inc.php,NONE,1.1 class.addbook_nextmatchs.inc.php,NONE,1.1 class.boaddbook.inc.php,NONE,1.1 class.functions.inc.php,NONE,1.1 class.generic.inc.php,NONE,1.1 class.org.inc.php,NONE,1.1 class.person.inc.php,NONE,1.1 class.prefs.inc.php,NONE,1.1 class.soaddbook.inc.php,NONE,1.1 class.uiaddbook.inc.php,NONE,1.1 hook_admin.inc.php,NONE,1.1 hook_deleteaccount.inc.php,NONE,1.1 hook_preferences.inc.php,NONE,1.1,
Ralf Becker <address@hidden> <=
- Prev by Date:
[Phpgroupware-cvs] CVS: phpgroupware/addbook README,NONE,1.1 index.php,NONE,1.1 readme,NONE,1.1
- Next by Date:
[Phpgroupware-cvs] CVS: phpgroupware/addbook/phpgwapi README,NONE,1.1 class.contacts.inc.php,NONE,1.1 class.contacts1_sql.inc.php,NONE,1.1
- Previous by thread:
[Phpgroupware-cvs] CVS: phpgroupware/addbook README,NONE,1.1 index.php,NONE,1.1 readme,NONE,1.1
- Next by thread:
[Phpgroupware-cvs] CVS: phpgroupware/addbook/phpgwapi README,NONE,1.1 class.contacts.inc.php,NONE,1.1 class.contacts1_sql.inc.php,NONE,1.1
- Index(es):