home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 April
/
CMCD0404.ISO
/
Software
/
Freeware
/
Programare
/
groupoffice-com-2.01
/
modules
/
addressbook
/
select.php
< prev
next >
Wrap
PHP Script
|
2004-03-08
|
19KB
|
552 lines
<?php
/*
Copyright Intermesh 2003
Author: Merijn Schering <mschering@intermesh.nl>
Version: 1.0 Release date: 08 July 2003
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.
*/
require("../../Group-Office.php");
$GO_SECURITY->authenticate();
require($GO_LANGUAGE->get_language_file('contacts'));
$GO_FIELD = isset($_REQUEST['GO_FIELD']) ? $_REQUEST['GO_FIELD'] : '';
$GO_HANDLER = isset($_REQUEST['GO_HANDLER']) ? $_REQUEST['GO_HANDLER'] : '';
$post_action = isset($_REQUEST['post_action']) ? $_REQUEST['post_action'] : '';
if ($post_action == 'search')
{
if (isset($_REQUEST['search_type']))
{
SetCookie("ab_search_type",$_REQUEST['search_type'],time()+3600*24*365,"/","",0);
$_COOKIE['ab_search_type'] = $_REQUEST['search_type'];
if ($_REQUEST['search_type'] == 'companies')
{
SetCookie("ab_search_companies_field",$_REQUEST['search_field'],time()+3600*24*365,"/","",0);
$_COOKIE['ab_search_companies_field'] = $_REQUEST['search_field'];
}else
{
SetCookie("ab_search_contacts_field",$_REQUEST['search_field'],time()+3600*24*365,"/","",0);
$_COOKIE['ab_search_contacts_field'] = $_REQUEST['search_field'];
}
}
if (isset($_REQUEST['search_addressbook_id']))
{
SetCookie("ab_search_addressbook_id",$_REQUEST['search_addressbook_id'],time()+3600*24*365,"/","",0);
$_COOKIE['ab_search_addressbook_id'] = $_REQUEST['search_addressbook_id'];
}
}
$pass_value = isset($_REQUEST['pass_value']) ? $_REQUEST['pass_value'] : 'email';
$multiselect = (isset($_REQUEST['multiselect']) && $_REQUEST['multiselect'] == 'true') ? true : false;
$require_email_address = (isset($_REQUEST['require_email_address']) && $_REQUEST['require_email_address'] == 'true') ? true : false;
$show_users = (isset($_REQUEST['show_users']) && $_REQUEST['show_users'] == 'true') ? true : false;
$show_contacts = (isset($_REQUEST['show_contacts']) && $_REQUEST['show_contacts'] == 'true') ? true : false;
$show_companies = (isset($_REQUEST['show_companies']) && $_REQUEST['show_companies'] == 'true') ? true : false;
if ($show_contacts || $show_companies)
{
$GO_MODULES->authenticate('addressbook');
}
$_COOKIE['ab_search_type'] = isset($_COOKIE['ab_search_type']) ? $_COOKIE['ab_search_type'] : 'contacts';
$search_type = isset($_POST['search_type']) ? $_POST['search_type'] : $_COOKIE['ab_search_type'];
$page_title = $contacts_select;
require($GO_THEME->theme_path."header.inc");
require($GO_CONFIG->class_path."addressbook.class.inc");
$ab1 = new addressbook();
$ab2 = new addressbook();
if ($search_type != 'users')
{
$addressbook_id = isset($_REQUEST['addressbook_id']) ? $_REQUEST['addressbook_id'] : $ab1->get_default_addressbook($GO_SECURITY->user_id);
if (!$addressbook_id)
{
$addressbook_id = $ab1->add_addressbook($GO_SECURITY->user_id, $_SESSION['GO_SESSION']['name']);
}
$addressbook = $ab1->get_addressbook($addressbook_id);
}
?>
<script type="text/javascript" language="javascript">
var nav4 = window.Event ? true : false;
function processkeypress(e)
{
if(nav4)
{
var whichCode = e.which;
}else
{
var whichCode = event.keyCode;
}
if (whichCode == 13)
{
search();
return true;
}
}
if (window.Event) //if Navigator 4.X
{
document.captureEvents(Event.KEYPRESS)
}
document.onkeypress = processkeypress;
function search()
{
document.select.action = "<?php echo $_SERVER['PHP_SELF']; ?>";
document.select.post_action.value = 'search';
document.select.submit();
}
function item_click(id, check_box)
{
var item = get_object(id);
if (item)
{
if (check_box.checked)
{
item.className = 'Table2';
}else
{
item.className = 'Table1';
}
}
}
function invert_selection()
{
for (var i=0;i<document.forms[0].elements.length;i++)
{
if(document.forms[0].elements[i].type == 'checkbox' && document.forms[0].elements[i].name != 'dummy')
{
document.forms[0].elements[i].checked = !(document.forms[0].elements[i].checked);
item_click(document.forms[0].elements[i]);
}
}
}
function change_addressbook()
{
document.select.action = "<?php echo $_SERVER['PHP_SELF']; ?>";
document.select.submit();
}
function _click(clicked_value, clicked_type)
{
document.select.clicked_type.value=clicked_type;
document.select.clicked_value.value=clicked_value;
document.select.submit();
}
function letter_click(letter)
{
document.select.action = "<?php echo $_SERVER['PHP_SELF']; ?>";
document.select.post_action.value = 'search';
document.select.task.value='show_letter';
document.select.query.value=letter;
document.select.submit();
}
</script>
<form method="post" name="select" action="<?php echo $GO_HANDLER; ?>">
<input type="hidden" value="<?php echo $newdirection; ?>" name="newdirection" />
<?php
if ($multiselect)
{
echo '<input type="hidden" value="true" name="multiselect" />';
}
if($require_email_address)
{
echo '<input type="hidden" value="true" name="require_email_address" />';
}
if($show_users)
{
echo '<input type="hidden" value="true" name="show_users" />';
$types_used[] = 'users';
}
if($show_contacts)
{
echo '<input type="hidden" value="true" name="show_contacts" />';
$types_used[] = 'contacts';
}
if($show_companies)
{
$types_used[]='companies';
echo '<input type="hidden" value="true" name="show_companies" />';
}
$search_type = in_array($search_type, $types_used) ? $search_type : $types_used[0];
?>
<input type="hidden" name="pass_value" value="<?php echo $pass_value; ?>" />
<input type="hidden" name="post_action" />
<input type="hidden" name="task" />
<input type="hidden" name="GO_FIELD" value="<?php echo $_REQUEST['GO_FIELD']; ?>" />
<input type="hidden" name="GO_HANDLER" value="<?php echo $_REQUEST['GO_HANDLER']; ?>" />
<input type="hidden" name="clicked_value" />
<input type="hidden" name="clicked_type" />
<?php
echo '<table border="0" cellpadding="5" cellspacing="0" width="100%">';
$contacts = isset($_POST['contacts']) ? $_POST['contacts'] : array();
$users = isset($_POST['users']) ? $_POST['users'] : array();
$companies = isset($_POST['companies']) ? $_POST['companies'] : array();
if (isset($_REQUEST['address_string']))
{
$addresses = cut_address($_REQUEST['address_string'],$charset);
}else
{
$addresses = isset($_POST['addresses']) ? $_POST['addresses'] : array();;
}
if ($pass_value == 'email')
{
$addresses = array_merge($addresses, $contacts, $users, $companies);
}
?>
<table border="0" cellpadding="0" cellspacing="3">
<tr height="30">
<td nowrap>
<h2>
<a href="javascript:letter_click('A')">A</a>
<a href="javascript:letter_click('B')">B</a>
<a href="javascript:letter_click('C')">C</a>
<a href="javascript:letter_click('D')">D</a>
<a href="javascript:letter_click('E')">E</a>
<a href="javascript:letter_click('F')">F</a>
<a href="javascript:letter_click('G')">G</a>
<a href="javascript:letter_click('H')">H</a>
<a href="javascript:letter_click('I')">I</a>
<a href="javascript:letter_click('J')">J</a>
<a href="javascript:letter_click('K')">K</a>
<a href="javascript:letter_click('L')">L</a>
<a href="javascript:letter_click('M')">M</a>
<a href="javascript:letter_click('N')">N</a>
<a href="javascript:letter_click('O')">O</a>
<a href="javascript:letter_click('P')">P</a>
<a href="javascript:letter_click('Q')">Q</a>
<a href="javascript:letter_click('R')">R</a>
<a href="javascript:letter_click('S')">S</a>
<a href="javascript:letter_click('T')">T</a>
<a href="javascript:letter_click('U')">U</a>
<a href="javascript:letter_click('V')">V</a>
<a href="javascript:letter_click('W')">W</a>
<a href="javascript:letter_click('X')">X</a>
<a href="javascript:letter_click('Y')">Y</a>
<a href="javascript:letter_click('Z')">Z</a>
</h2>
</td>
</tr>
<tr>
<td>
<?php
echo '<table border="0"><tr><td>'.$ab_search_for.':</td><td><table border="0" cellpadding="0" cellspacing="0"><tr><td>';
$_COOKIE['ab_search_field'] = isset($_COOKIE['ab_search_field']) ? $_COOKIE['ab_search_field'] : 'first_name';
$search_field = isset($_POST['search_field']) ? $_POST['search_field'] : $_COOKIE['ab_search_field'];
$_COOKIE['ab_search_companies_field'] = isset($_COOKIE['ab_search_companies_field']) ? $_COOKIE['ab_search_companies_field'] : 'name';
$_COOKIE['ab_search_contacts_field'] = isset($_COOKIE['ab_search_contacts_field']) ? $_COOKIE['ab_search_contacts_field'] : 'first_name';
$search_field = ($search_type == 'contacts' || $search_type == 'users') ? $_COOKIE['ab_search_contacts_field'] : $_COOKIE['ab_search_companies_field'];
$dropbox = new dropbox();
if ($show_users)
{
$dropbox->add_value('users', $contacts_members);
}
if ($show_contacts)
{
$dropbox->add_value('contacts', $contacts_contacts);
}
if ($show_companies)
{
$dropbox->add_value('companies', $ab_companies);
}
$dropbox->print_dropbox('search_type', $search_type, 'onchange="javascript:change_addressbook()"');
echo '</td>';
$_COOKIE['ab_search_addressbook_id'] = isset($_COOKIE['ab_search_addressbook_id']) ? $_COOKIE['ab_search_addressbook_id'] : '0';
$search_addressbook_id = isset($_REQUEST['search_addressbook_id']) ? $_REQUEST['search_addressbook_id'] : $_COOKIE['ab_search_addressbook_id'];
if ($search_type != 'users' && $ab1->get_subscribed_addressbooks($GO_SECURITY->user_id) > 1)
{
$subscribed_addressbooks = new dropbox();
$subscribed_addressbooks->add_value('0', $ab_all_your_addressbooks);
while ($ab1->next_record())
{
$subscribed_addressbooks->add_value($ab1->f('id'), $ab1->f('name'));
}
echo '<td>'.$ab_search_in.' </td><td>';
$subscribed_addressbooks->print_dropbox('search_addressbook_id', $search_addressbook_id);
echo '</td>';
}else
{
echo '<input type="hidden" name="search_addressbook_id" value="'.$search_addressbook_id.'" />';
}
$_COOKIE['ab_search_companies_field'] = isset($_COOKIE['ab_search_companies_field']) ? $_COOKIE['ab_search_companies_field'] : 'name';
$_COOKIE['ab_search_contacts_field'] = isset($_COOKIE['ab_search_contacts_field']) ? $_COOKIE['ab_search_contacts_field'] : 'first_name';
$search_field = ($search_type == 'contacts' || $search_type == 'users') ? $_COOKIE['ab_search_contacts_field'] : $_COOKIE['ab_search_companies_field'];
$dropbox = new dropbox();
if ($search_type == 'companies')
{
$dropbox->add_value('name', $strName);
$dropbox->add_value('email', $strEmail);
$dropbox->add_value('address',$strAddress);
$dropbox->add_value('city', $strCity);
$dropbox->add_value('zip',$strZip);
$dropbox->add_value('state',$strState);
$dropbox->add_value('country', $strCountry);
}else
{
$dropbox->add_value('first_name', $strFirstName);
$dropbox->add_value('last_name', $strLastName);
$dropbox->add_value('email', $strEmail);
$dropbox->add_value('department',$strDepartment);
$dropbox->add_value('function',$strFunction);
$dropbox->add_value('address',$strAddress);
$dropbox->add_value('city', $strCity);
$dropbox->add_value('zip',$strZip);
$dropbox->add_value('state',$strState);
$dropbox->add_value('country', $strCountry);
$dropbox->add_value('comment', $ab_comment);
}
echo '<td>'.$ab_search_on.' </td><td>';
$dropbox->print_dropbox('search_field', $search_field);
echo '</td></tr></table></td></tr>';
?>
<tr>
<td><?php echo $ab_search_keyword; ?>:</td>
<td colspan="3"><input type="text" name="query" size="31" maxlength="255" class="textbox" value="<?php if (isset($_POST['query'])) echo $_POST['query']; ?>">
<?php
$button = new button($cmdSearch, "javascript:search()");
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<?php
if ($post_action == 'search')
{
if ($_POST['task'] == 'show_letter')
{
$query = $_POST['query'].'%';
}else
{
$query = '%'.$_POST['query'].'%';
}
if ($search_type == 'contacts' || $search_type == 'users')
{
if ($search_type == 'users')
{
$click_type = 'user';
$array_name = 'users[]';
require_once($GO_CONFIG->class_path.'users.class.inc');
$ab1 = new users();
$ab1->search($query, $search_field, $GO_SECURITY->user_id);
}else
{
$click_type = 'contact';
$array_name = 'contacts[]';
$ab1->search_contacts($GO_SECURITY->user_id, $query, $search_field, $search_addressbook_id);
}
$count = 0;
$search_results = '';
while ($ab1->next_record())
{
if ((!$require_email_address || $ab1->f("email") != '') && (($search_type == 'users' && $GO_SECURITY->has_permission($GO_SECURITY->user_id, $ab1->f('acl_id'))) || ($search_type != 'users' && ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $ab1->f('acl_read')) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $ab1->f('acl_write'))))))
{
$class="Table1";
$check = "";
if ($pass_value == 'email')
{
if ($ab1->f("email") != "")
{
$key = array_search($ab1->f("email"), $addresses);
}else
{
$key = false;
}
if (is_int($key))
{
unset($addresses[$key]);
$check = "checked";
$class = "Table2";
}
}elseif($search_type == 'users')
{
$key = array_search($ab1->f($pass_value), $users);
if (is_int($key))
{
unset($users[$key]);
$check = "checked";
$class = "Table2";
}
}elseif($search_type == 'contracts')
{
$key = array_search($ab1->f($pass_value), $contacts);
if (is_int($key))
{
unset($contacts[$key]);
$check = "checked";
$class = "Table2";
}
}
$search_results .= "<tr id=\"".$ab1->f('id')."\" class=\"".$class."\" height=\"20\"><td> </td>\n";
if ($multiselect)
{
$search_results .= '<td><input onclick="javascript:item_click('.$ab1->f("id").', this);" type="checkbox" name="'.$array_name.'" value="'.$ab1->f($pass_value).'" '.$check.' /></td>';
}
if ($search_type != 'users' && $ab1->f('color') != '')
{
$style = ' style="color: '.$ab1->f('color').';"';
}else
{
$style = '';
}
$middle_name = $ab1->f('middle_name') == '' ? '' : $ab1->f('middle_name').' ';
$name = $ab1->f('first_name').' '.$middle_name.$ab1->f('last_name');
$search_results .= '<td><a'.$style.' href="javascript:_click(\''.$ab1->f($pass_value).'\', \''.$click_type.'\');" class="normal">'.$name.'</a> </td>';
$search_results .= "<td>".mail_to(empty_to_stripe($ab1->f("email")))." </td>\n";
$search_results .= "</tr>\n";
$search_results .= '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
$count++;
}
}
echo '<tr><td><h2>'.$count.' '.$contacts_results.'</h2>';
echo '<tr><td>';
if ($count > 0)
{
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
echo '<tr>';
echo '<td class="TableHead2" colspan="2"> </td>';
echo '<td class="TableHead2">'.$strName.'</td>';
echo '<td class="TableHead2">'.$strEmail.'</td>';
echo '</tr>';
echo $search_results;
echo '</table>';
}
}else
{
$ab1->search_companies($GO_SECURITY->user_id, $query, $search_field, $search_addressbook_id);
$count = 0;
$search_results = '';
while ($ab1->next_record())
{
if ((!$require_email_address || $ab1->f("email") != '') && (($GO_SECURITY->has_permission($GO_SECURITY->user_id, $ab1->f('acl_read')) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $ab1->f('acl_write')))))
{
$count++;
$class="Table1";
$check = "";
if ($pass_value == 'email')
{
if ($ab1->f("email") != "")
{
$key = array_search($ab1->f("email"), $addresses);
}else
{
$key = false;
}
if (is_int($key))
{
unset($addresses[$key]);
$check = "checked";
$class = "Table2";
}
}else
{
$key = array_search($ab1->f($pass_value), $companies);
if (is_int($key))
{
unset($companies[$key]);
$check = "checked";
$class = "Table2";
}
}
$search_results .= "<tr id=\"".$ab1->f('id')."\" class=\"".$class."\" height=\"20\">\n";
if ($multiselect)
{
$search_results .= '<td><input onclick="javascript:item_click('.$ab1->f("id").', this);" type="checkbox" name="companies[]" value="'.$ab1->f($pass_value).'" '.$check.' /></td>';
}
$search_results .= '<td><a href="javascript:_click(\''.$ab1->f($pass_value).'\', \'company\');" class="normal">'.$ab1->f('name').'</a> </td>';
$search_results .= "<td>".mail_to(empty_to_stripe($ab1->f("email")), empty_to_stripe($ab1->f("email")),'normal',true, $ab1->f("id"))." </td>\n";
$search_results .= "</tr>\n";
$search_results .= '<tr><td colspan="99" height="1"><img src="'.$GO_THEME->images['cccccc'].'" border="0" height="1" width="100%" /></td></tr>';
}
}
$result_str = ($count == 1) ? $count.' '.$contacts_result : $count.' '.$contacts_results;
echo '<br /><h2>'.$result_str.'</h2>';
if ($count > 0)
{
echo '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
echo '<tr>';
echo '<td class="TableHead2" width="16"><input type="checkbox" name="dummy" value="dummy" onclick="javascript:invert_selection()" /></td>';
echo '<td class="TableHead2">'.$strName.'</td>';
echo '<td class="TableHead2">'.$strEmail.'</td>';
echo '</tr>';
echo $search_results;
echo '</table>';
}
}
}
echo '<table border="0" width="100%"><tr><td align="center"><br />';
if($multiselect && ($post_action == 'search' && $count > 0))
{
$button = new button($cmdAdd,'javascript:document.forms[0].submit()');
echo ' ';
}
$button = new button($cmdCancel,'javascript:window.close();');
echo '</td></tr></table>';
while($address = array_pop($addresses))
{
echo '<input type="hidden" name="addresses[]" value="'.$address.'" />';
}
echo '</form>';
echo '<script type="text/javascript">document.select.query.focus();</script>';
require($GO_THEME->theme_path."footer.inc");
?>