phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] addressbook/inc class.uicategorize_contacts.inc.php,


From: Jonathan Rivera <address@hidden>
Subject: [Phpgroupware-cvs] addressbook/inc class.uicategorize_contacts.inc.php, NONE, 1.1.2.1
Date: Thu, 27 Nov 2003 19:07:35 +0000

Update of /cvsroot/phpgroupware/addressbook/inc
In directory subversions:/tmp/cvs-serv10912/addressbook/inc

Added Files:
      Tag: Version-0_9_16-branch
        class.uicategorize_contacts.inc.php 
Log Message:
You can categorize many contacts in short time, this form use the widget list 
object


--- NEW FILE: class.uicategorize_contacts.inc.php ---
<?php
  /**************************************************************************\
  * phpGroupWare - uicategorize_contacts                                     *
  * http://www.phpgroupware.org                                              *
  * This program is part of the GNU project, see http://www.gnu.org/         *
  *                                                                          *
  * Copyright 2003 Free Software Foundation, Inc.                            *
  *                                                                          *
  * Originally Written by Jonathan Alberto Rivera Gomez - jarg at co.com.mx  *
  * Current Maintained by Jonathan Alberto Rivera Gomez - jarg at co.com.mx  *
  * --------------------------------------------                             *
  * Development of this application was funded by http://www.sogrp.com       *
  * --------------------------------------------                             *
  *  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 uicategorize_contacts
        {
                var $public_functions = array(
                        'index' => True,
                        'java_script' => True
                        );
                
                function uicategorize_contacts()
                {
                        $this->template = &$GLOBALS['phpgw']->template;
                        $this->lists = CreateObject('addressbook.widget_lists', 
'Categories', 'categorize_contacts_form');
                        $this->cat = CreateObject('phpgwapi.categories');
                        $this->contacts = CreateObject('phpgwapi.contacts');
                }
                
                function index()
                {
                        $selected_cat = get_var('all_cats');

                        $this->template->set_file(array('manage_cats_t' => 
'categorize_contacts.tpl'));
                        
                        $cats = 
$this->cat->return_array('all','','','','',True);
                        $categories[-1] = 'Select one...';
                        foreach($cats as $key => $data)
                        {
                                $categories[$data['id']] = $data['name'];
                        }

                        $persons_by_cat=array();
                        $criteria = $this->contacts->criteria_for_index('6', 
PHPGW_CONTACTS_ALL, $selected_cat);
                        $persons = 
$this->contacts->get_persons(array('person_id', 
'per_full_name'),'','','','','',$criteria);
                        if(is_array($persons))
                        {
                                foreach($persons as $key => $data)
                                {
                                        $persons_by_cat[$data['person_id']] = 
$data['per_full_name'];
                                }
                        }

                        $criteria = $this->contacts->criteria_for_index('6', 
PHPGW_CONTACTS_ALL, PHPGW_CONTACTS_CATEGORIES_ALL);
                        $persons = 
$this->contacts->get_persons(array('person_id', 
'per_full_name'),'','','','','',$criteria);
                        if(is_array($persons))
                        {
                                foreach($persons as $key => $data)
                                {
                                        
if(!array_key_exists($data['person_id'], $persons_by_cat))
                                        {
                                                
$persons_data[$data['person_id']] = $data['per_full_name'];
                                        }
                                }
                        }
                        
                        $this->lists->set_left_combo('Category', 'all_cats', 
$categories, $selected_cat, True);
                        $this->lists->set_all_option_list('All Persons', 
'person_all[]', $persons_data);
                        $this->lists->set_selected_option_list('Current 
Persons', 'person_current[]', $persons_by_cat);
                        $list_widget = $this->lists->get_widget();
                        $onsubjs = $this->lists->get_onsubmit_js_string();

                        if(get_var('cancel'))
                        {
                                Header('Location: '
                                       . 
$GLOBALS['phpgw']->link('/admin/index.php'));
                        }
                        
                        if(get_var('save'))
                        {
                                $persons = $this->lists->get_resul_list();
                                $this->save_categories_by_person($selected_cat, 
$persons);
                                Header('Location: '
                                       . 
$GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uicategorize_contacts.index'));
                        }

                        $GLOBALS['phpgw']->common->phpgw_header();
                        echo parse_navbar();

                        $this->template->set_var('action', 
$GLOBALS['phpgw']->link('/index.php','menuaction=addressbook.uicategorize_contacts.index'));
                        $this->template->set_var('form_name', 
'categorize_contacts_form');
                        $this->template->set_var('onsubjs', $onsubjs);
                        $this->template->set_var('widget_lists', $list_widget);
                        $this->template->pfp('out', 'manage_cats_t');
                }

                function save_categories_by_person($selected_cat, 
$persons=array())
                {
                        $delete = $persons['delete'];
                        $insert = $persons['insert'];
                        $edit = $persons['edit'];
                        
                        if($selected_cat==-1)
                        {
                                return;
                        }
                        
                        foreach($delete as $person_id)
                        {
                                $cats = 
$this->contacts->get_cats_by_person($person_id);
                                foreach($cats as $key => $value)
                                {
                                        if($value == '' || 
$value==$selected_cat)
                                        {
                                                unset($cats[$key]);
                                        }
                                }
                                $this->contacts->edit_category($person_id, 
$cats, PHPGW_SQL_RUN_SQL);
                        }

                        foreach($insert as $person_id)
                        {
                                $cats = 
$this->contacts->get_cats_by_person($person_id);
                                $cats[] = $selected_cat;
                                foreach($cats as $key => $value)
                                {
                                        if($value == '')
                                        {
                                                unset($cats[$key]);
                                        }
                                }
                                $this->contacts->edit_category($person_id, 
$cats, PHPGW_SQL_RUN_SQL);
                        }
                        
                }
                
                function java_script()
                {
                        return $this->lists->java_script();
                }
        }
?>





reply via email to

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