<?php
/**************************************************************************
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.
@Authors: Ryan Thompson(hide@address.com)
***************************************************************************/
class contacts
{
var $months;
var $lang_file;
var $service_name;
function msg($message, $service = 'ct')
{
GLOBAL $O, $lang;
return $lang->get_msg($message, $service);
}
function nav_buttons()
{
$navigation .= "<input type=\"submit\" name=\"list_contacts\" value=\"". $this->msg('list_contacts') ."\"
class=\"button1\" onClick=\"window.location='index.php'\">";
$navigation .= "<input type=\"submit\" name=\"add_contact\" value=\"". $this->msg('add_contact') ."\"
class=\"button1\" onClick=\"window.location='add_contact.php'\">";
return $navigation;
}
function delete($data)
{
GLOBAL $O, $db;
if(count($data) > 0)
{
foreach($data as $key=>$value)
{
//echo $key;
$sql = "DELETE FROM o_contacts WHERE address_id='$value'";
$db->query($sql);
}
return TRUE;
} else {
$O->error->get_message(12000);
}
}
function get_filters()
{
GLOBAL $O;
$letters = array('All','#','A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$i = 0;
$filters = NULL;
while($i < count($letters))
{
$link = $_SERVER['PHP_SELF'] ."?filter=$letters[$i]";
$title = "[". $letters[$i] ."] ";
$filters .= $O->create_link($link ,$title, 'filter');
$i++;
}
return $filters;
}
function add($data)
{
GLOBAL $O, $db, $user, $error;
if(strlen($data['firstname']) == 0)
{
$error->get_message(12001);
} elseif(strlen($data['lastname']) == 0)
{
$error->get_message(12002);
} else {
$fields = "user_id, title, firstname, lastname,address1,address2, city, postal_code, province,
phone, cell, fax, email, website, company, department, country";
$values = "'{$user->user_id}','$data[title]','$data[firstname]','$data[lastname]','$data[address]',
'$data[address2]','$data[city]','$data[postal_code]','$data[province]',
'$data[phone]','$data[cell]','$data[fax]','$data[email_address]','$data[website]','$data[company]',
'$data[department]','{$data['country']}'";
//PGSQL doesn't like having NULL date fields. This prevents errors if the birthday isn't filled in.
if($data['birthday_year'] != '' && $data['birthday_day'] != '' && $data['birthday_month'] != '')
{
$birthday = $data['birthday_year'] ."-". $data['birthday_month'] ."-". $data['birthday_day'];
$fields .= ", birthday";
$values .= ",'$birthday'";
}
$sql = "INSERT INTO o_contacts ($fields) VALUES ($values)";
$db->query($sql);
}
}
function edit($data)
{
GLOBAL $O, $db;
$birthday = $data['birthday_year'].$data['birthday_month'].$data['birthday_day'];
$sql = "UPDATE o_contacts SET title='$data[title]',firstname='$data[firstname]',middlename='$data[middlename]',
lastname='$data[lastname]',job_title='$data[job_title]',address1='$data[address]',address2='$data[address2]',
city='$data[city]',country='$data[country]',province='$data[province]',postal_code='$data[postal_code]',
birthday='$birthday',phone='$data[phone]',fax='$data[fax]',cell='$data[cell]',email='$data[email_address]',
website='$data[website]',company='$data[company]',department='$data[department]',notes='$data[notes]'
WHERE address_id='$_GET[id]'";
$db->query($sql);
}
}