|
From: <dts...@us...> - 2003-05-31 07:36:47
|
Update of /cvsroot/phpwebsite-comm/modules/contacts/class
In directory sc8-pr-cvs1:/tmp/cvs-serv26427/class
Modified Files:
Address.php Contact.php Manager.php
Log Message:
Lots of work for addresses
Index: Address.php
===================================================================
RCS file: /cvsroot/phpwebsite-comm/modules/contacts/class/Address.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Address.php 28 May 2003 18:01:11 -0000 1.1
--- Address.php 31 May 2003 07:36:44 -0000 1.2
***************
*** 7,10 ****
--- 7,366 ----
class CONTACTS_Address extends PHPWS_Item {
+ /**
+ * The contact id of the address
+ *
+ * @var integer
+ * @access private
+ */
+ var $_contact_id = NULL;
+
+
+ /**
+ * The address type of the address
+ *
+ * @var integer
+ * @access private
+ */
+ var $_type_id = NULL;
+
+
+ /**
+ * The street address lines of the address
+ *
+ * @var string
+ * @access private
+ */
+ var $_street1 = NULL;
+ var $_street2 = NULL;
+
+
+ /**
+ * The city of the address
+ *
+ * @var string
+ * @access private
+ */
+ var $_city = NULL;
+
+
+ /**
+ * The state or province of the address
+ *
+ * @var string
+ * @access private
+ */
+ var $_stateprov = NULL;
+
+
+ /**
+ * The postal or zip code of the address
+ *
+ * @var string
+ * @access private
+ */
+ var $_postalcode = NULL;
+
+
+ /**
+ * The country id of the address
+ *
+ * @var string
+ * @access private
+ */
+ var $_country_id = NULL;
+
+
+ /**
+ * The country object of the address
+ *
+ * @var CONTACTS_Country
+ * @access private
+ */
+ var $_country = NULL;
+
+
+ /**
+ * The address type object of the address
+ *
+ * @var CONTACTS_AddressType
+ * @access private
+ */
+ var $_address_type = NULL;
+
+
+ /**
+ * Array of address types objects
+ *
+ * @var array
+ * @access private
+ */
+ var $address_types = array();
+
+
+ /**
+ * Array of country objects
+ *
+ * @var array
+ * @access private
+ */
+ var $countries = array();
+
+
+ function CONTACTS_Address($ADDRESS_ID = NULL) {
+ /* These vars are excluded on commit() */
+ $exclude = array("_country","_address_type","address_types","countries");
+ $this->addExclude($exclude);
+
+ $this->setTable("mod_contacts_addresses");
+
+ if(isset($ADDRESS_ID)) {
+ $this->setId($ADDRESS_ID);
+ $this->init();
+ //$this->_country = new CONTACTS_Country($this->_country_id);
+ //$this->_address_type = new CONTACTS_AddressType($this->_type_id);
+ } else {
+ $this->_contact_id = $_REQUEST["CONTACTS_contact_id"];
+ }
+
+ }// END FUNC CONTACTS_Address
+
+
+ function _view() {
+ $tags = array();
+
+ if(!is_null($this->getId()) && (($_SESSION["OBJ_user"]->username == $this->getOwner()) || $_SESSION["OBJ_user"]->allow_access("contacts","edit_contacts"))) {
+ $tags["EDIT"] = "<a href=\"index.php?module=contacts&CONTACTS_MAN_OP=editaddress&CONTACTS_address_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Edit") . "</a>";
+ $tags["DELETE"] = "<a href=\"index.php?module=contacts&CONTACTS_MAN_OP=deleteaddress&CONTACTS_address_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Delete") . "</a>";
+ }
+
+ $this->_country = new CONTACTS_Country($this->_country_id);
+ $this->_address_type = new CONTACTS_AddressType($this->_type_id);
+
+ $tags["TYPE"] = $this->_address_type->_name;
+ $tags["STREET1"] = $this->_street1;
+ $tags["STREET2"] = $this->_street2;
+ $tags["CITY"] = $this->_city;
+ $tags["STATEPROV"] = $this->_stateprov;
+ $tags["POSTALCODE"] = $this->_postalcode;
+ $tags["COUNTRY"] = $this->_country->_country;
+
+ $tags["TYPE_TEXT"] = $_SESSION["translate"]->it("Type");
+ $tags["STREET_TEXT"] = $_SESSION["translate"]->it("Street");
+ $tags["CITY_TEXT"] = $_SESSION["translate"]->it("City");
+ $tags["STATEPROV_TEXT"] = $_SESSION["translate"]->it("State/Province");
+ $tags["POSTALCODE_TEXT"] = $_SESSION["translate"]->it("Zip/Postal Code");
+ $tags["COUNTRY_TEXT"] = $_SESSION["translate"]->it("Country");
+
+ return $GLOBALS["core"]->processTemplate($tags, "contacts", "view_address.tpl");
+ }
+
+
+ function _edit() {
+
+ if(($_SESSION["OBJ_user"]->username != $this->getOwner()) && !$_SESSION["OBJ_user"]->allow_access("contacts","edit_contacts")) {
+ $message = $_SESSION["translate"]->it("Access to edit address was denied due to lack of proper permissions.");
+ $error = new PHPWS_Error("contacts", "CONTACTS_Address::_edit()", $message, "exit", 1);
+ $error->message();
+ return FALSE;
+ }
+
+ // Get address types
+ $result = $GLOBALS["core"]->sqlSelect("mod_contacts_addresstypes", NULL, NULL, "name");
+ foreach ($result as $row)
+ $this->address_types[$row["id"]] = $row["name"];
+
+ // Get countries
+ $result = $GLOBALS["core"]->sqlSelect("mod_contacts_countries", NULL, NULL, "country");
+ foreach ($result as $row)
+ $this->countries[$row["id"]] = $row["country"];
+
+
+ /* Create form */
+ $form = new EZform("CONTACTS_Address_edit");
+
+ /* Address Type */
+ $form->add("Address_type_id", "select", $this->address_types);
+ $form->setMatch("Address_type_id", $this->_type_id);
+ $form->setTab("Address_type_id", 1);
+
+ /* Street Address */
+ $form->add("Address_street1", "text", $this->_street1);
+ $form->setSize("Address_street1", 33);
+ $form->setTab("Address_street1", 2);
+
+ $form->add("Address_street2", "text", $this->_street2);
+ $form->setSize("Address_street2", 33);
+ $form->setTab("Address_street2", 3);
+
+ /* City */
+ $form->add("Address_city", "text", $this->_city);
+ $form->setSize("Address_city", 33);
+ $form->setTab("Address_city", 4);
+
+ /* State */
+ $form->add("Address_stateprov", "text", $this->_stateprov);
+ $form->setSize("Address_stateprov", 5);
+ $form->setTab("Address_stateprov", 5);
+
+ /* Postal Code */
+ $form->add("Address_postalcode", "text", $this->_postalcode);
+ $form->setSize("Address_postalcode", 10);
+ $form->setTab("Address_postalcode", 6);
+
+ /* Country */
+ $form->add("Address_country_id", "select", $this->countries);
+ $form->setMatch("Address_country_id", $this->_country_id);
+ $form->setTab("Address_country_id", 7);
+
+ /* Save Button */
+ $form->add("Address_save", "submit", $_SESSION["translate"]->it("Save"));
+ $form->setTab("Address_save", 13);
+
+ /* Module Information */
+ $form->add("Address_contact_id", "hidden", $this->_contact_id);
+ $form->add("module", "hidden", "contacts");
+ $form->add("CONTACTS_Address_OP", "hidden", "save");
+
+ $tags = array();
+ $tags = $form->getTemplate();
+
+ $tags["TYPE_TEXT"] = $_SESSION["translate"]->it("Type");
+ $tags["STREET_TEXT"] = $_SESSION["translate"]->it("Street");
+ $tags["CITY_TEXT"] = $_SESSION["translate"]->it("City");
+ $tags["STATEPROV_TEXT"] = $_SESSION["translate"]->it("State/Province");
+ $tags["POSTALCODE_TEXT"] = $_SESSION["translate"]->it("Zip/Postal Code");
+ $tags["COUNTRY_TEXT"] = $_SESSION["translate"]->it("Country");
+
+
+ return $GLOBALS["core"]->processTemplate($tags, "contacts", "edit_address.tpl");
+
+ }// END FUNC _edit
+
+
+ function _save() {
+ if(($_SESSION["OBJ_user"]->username != $this->getOwner()) && !$_SESSION["OBJ_user"]->allow_access("contacts","edit_contacts")) {
+ $message = $_SESSION["translate"]->it("Access to save address was denied due to lack of proper permissions.");
+ $error = new PHPWS_Error("contacts", "CONTACTS_Address::_save()", $message, "exit", 1);
+ $error->message();
+ return FALSE;
+ }
+
+ if(isset($_REQUEST["Address_type_id"]))
+ $this->_type_id = $_REQUEST["Address_type_id"];
+
+ if(isset($_REQUEST["Address_street1"]))
+ $this->_street1 = $_REQUEST["Address_street1"];
+
+ if(isset($_REQUEST["Address_street2"]))
+ $this->_street2 = $_REQUEST["Address_street2"];
+
+ if(isset($_REQUEST["Address_city"]))
+ $this->_city = $_REQUEST["Address_city"];
+
+ if(isset($_REQUEST["Address_stateprov"]))
+ $this->_stateprov = $_REQUEST["Address_stateprov"];
+
+ if(isset($_REQUEST["Address_postalcode"]))
+ $this->_postalcode = $_REQUEST["Address_postalcode"];
+
+ if(isset($_REQUEST["Address_country_id"]))
+ $this->_country_id = $_REQUEST["Address_country_id"];
+
+ $this->setLabel("$this->_street1 $this->_street2 $this->_city, $this->_stateprov");
+
+
+ $error = $this->commit();
+
+ if(PHPWS_Error::isError($error)) {
+ $message = $_SESSION["translate"]->it("The address could not be saved to the database.");
+ $error = new PHPWS_Error("contacts", $message, "continue", 0);
+ $error->message("CNT_contacts");
+
+ $_REQUEST["CONTACTS_Address_OP"] = "edit";
+ $this->action();
+ return;
+ } else {
+ $GLOBALS["CNT_contacts"]["content"] .= $_SESSION["translate"]->it("The address was successfully saved.") . "<br />\n";
+ // Probably need to pass some IDs in or something
+ $_REQUEST["CONTACTS_Contact_OP"] = "viewaddresses";
+ $_SESSION["CONTACTS_Manager"]->contact->action();
+ }
+ }// END FUNC _save
+
+
+ function _delete() {
+ if(!$_SESSION["OBJ_user"]->allow_access("contacts", "delete_contacts")) {
+ $message = $_SESSION["translate"]->it("Access to delete address was denied due to lack of proper permissions.");
+ $error = new PHPWS_Error("contacts", "CONTACTS_Address::_delete()", $message, "exit", 1);
+ $error->message();
+ return FALSE;
+ }
+
+ if(isset($_REQUEST["Address_yes"])) {
+ $this->kill();
+ $message = $_SESSION["translate"]->it("The address [var1] was successfully deleted from the database.", "<b><i>" . $this->getLabel() . "</i></b>");
+ $_SESSION["CONTACTS_Manager"]->message = new PHPWS_Message($message, "CNT_contacts");
+ $_REQUEST["CONTACTS_Contact_OP"] = "viewaddresses";
+ $_SESSION["CONTACTS_Manager"]->contact->action();
+
+ } elseif(isset($_REQUEST["Address_no"])) {
+ $message = $_SESSION["translate"]->it("No address was deleted from the database.");
+ $_SESSION["CONTACTS_Manager"]->message = new PHPWS_Message($message, "CNT_contacts");
+ $_SESSION["CONTACTS_Manager"]->action();
+ $_REQUEST["CONTACTS_Contact_OP"] = "viewaddresses";
+ $_SESSION["CONTACTS_Manager"]->contact->action();
+
+ } else {
+ $title = $_SESSION["translate"]->it("Delete Address Confirmation");
+
+ $form = new EZform("CONTACTS_Address_delete");
+ $form->add("module", "hidden", "contacts");
+ $form->add("CONTACTS_Address_OP", "hidden", "delete");
+
+ $form->add("Address_yes", "submit", $_SESSION["translate"]->it("Yes"));
+ $form->add("Address_no", "submit", $_SESSION["translate"]->it("No"));
+
+ $tags = array();
+ $tags = $form->getTemplate();
+ $tags["MESSAGE"] = $_SESSION["translate"]->it("Are you sure you want to delete this address?");
+
+ $content = $GLOBALS["core"]->processTemplate($tags, "contacts", "delete_address.tpl");
+ $_SESSION["OBJ_layout"]->popbox($title, $content, NULL, "CNT_contacts");
+ }
+
+ }// END FUNC _delete
+
+
+ function action() {
+ switch($_REQUEST["CONTACTS_Address_OP"]) {
+ case "view":
+ $content = $this->_view();
+ break;
+
+ case "edit":
+ $title = $_SESSION["translate"]->it("Edit Address Information");
+ $GLOBALS["CNT_contacts"]["title"] = $title;
+ $content = $this->_edit();
+ break;
+
+ case "save":
+ $this->_save();
+ break;
+
+ case "delete":
+ $this->_delete();
+ break;
+
+ default:
+ $title = "NO OP";
+ $content = "This function is not yet implemented.";
+ }
+
+ if(isset($content)) {
+ $GLOBALS["CNT_contacts"]["content"] .= $content;
+ }
+ }// END FUNC action
+
+
}// END CLASS CONTACTS_Address
Index: Contact.php
===================================================================
RCS file: /cvsroot/phpwebsite-comm/modules/contacts/class/Contact.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Contact.php 30 May 2003 13:49:00 -0000 1.6
--- Contact.php 31 May 2003 07:36:44 -0000 1.7
***************
*** 116,124 ****
function CONTACTS_Contact($CONTACT_ID = NULL) {
/* These vars are excluded on commit() */
! // $exclude = array();
! // $this->addExclude($exclude);
$this->setTable("mod_contacts_contacts");
--- 116,142 ----
+ /**
+ * Array of phones for this contact
+ *
+ * @var array
+ * @access private
+ */
+ var $_phones = array();
+
+
+ /**
+ * Array of addresses for this contact
+ *
+ * @var array
+ * @access private
+ */
+ var $_addresses = array();
+
+
function CONTACTS_Contact($CONTACT_ID = NULL) {
/* These vars are excluded on commit() */
! $exclude = array("_phones","_addresses");
! $this->addExclude($exclude);
$this->setTable("mod_contacts_contacts");
***************
*** 127,130 ****
--- 145,160 ----
$this->setId($CONTACT_ID);
$this->init();
+
+ /*
+ $sql = "SELECT id FROM " $GLOBALS["core"]->tbl_prefix . "mod_contacts_phones WHERE contact_id=" . $this->getId();
+ $results = $GLOBALS["core"]->getCol($sql);
+ foreach ($results as $phoneid)
+ $this->phones[$phoneid] = new CONTACTS_Phone($phoneid);
+
+ $sql = "SELECT id FROM " $GLOBALS["core"]->tbl_prefix . "mod_contacts_addresses WHERE contact_id=" . $this->getId();
+ $results = $GLOBALS["core"]->getCol($sql);
+ foreach ($results as $addressid)
+ $this->phones[$addressid] = new CONTACTS_Phone($addressid);
+ */
} else {
// Find contact owned by this username
***************
*** 141,144 ****
--- 171,198 ----
}// END FUNC CONTACTS_Contact
+
+ function _showtabs() {
+ $editmode = TRUE;
+ if(($_SESSION["OBJ_user"]->username != $this->getOwner()) && !$_SESSION["OBJ_user"]->allow_access("contacts","edit_contacts")) {
+ $editmode = FALSE;
+ }
+
+ $links = array();
+ if(!is_null($this->getId())) {
+ if($editmode) {
+ $links[] = "<a href=\"index.php?module=contacts&CONTACTS_MAN_OP=edit&CONTACTS_contact_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Edit Basic Info") . "</a>";
+ $links[] = "<a href=\"index.php?module=contacts&CONTACTS_Contact_OP=viewphones&CONTACTS_contact_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Edit Phone Numbers") . "</a>";
+ $links[] = "<a href=\"index.php?module=contacts&CONTACTS_Contact_OP=viewaddresses&CONTACTS_contact_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Edit Addresses") . "</a>";
+ } else {
+ $links[] = "<a href=\"index.php?module=contacts&CONTACTS_MAN_OP=view&CONTACTS_contact_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("View Basic Info") . "</a>";
+ $links[] = "<a href=\"index.php?module=contacts&CONTACTS_Contact_OP=viewphones&CONTACTS_contact_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("View Phone Numbers") . "</a>";
+ $links[] = "<a href=\"index.php?module=contacts&CONTACTS_Contact_OP=viewaddresses&CONTACTS_contact_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("View Addresses") . "</a>";
+ }
+ }
+ $menu = "<div align=\"right\">" . implode(" | ", $links) . "</div><br />";
+
+ return $menu;
+ }// END FUNC _showtabls
+
function _edit() {
***************
*** 155,158 ****
--- 209,213 ----
+
/* Create form */
$form = new EZform("CONTACTS_Contact_edit");
***************
*** 344,352 ****
function action() {
switch($_REQUEST["CONTACTS_Contact_OP"]) {
case "edit":
$title = $_SESSION["translate"]->it("Edit Contact Information");
! $content = $this->_edit();
break;
--- 399,432 ----
+ function _viewphones() {
+ $sql = "SELECT id FROM " . $GLOBALS["core"]->tbl_prefix . "mod_contacts_phones WHERE contact_id=" . $this->getId();
+ $results = $GLOBALS["core"]->getCol($sql);
+ foreach ($results as $phoneid)
+ $this->phones[$phoneid] = new CONTACTS_Phone($phoneid);
+ }// END FUNC _viewphones
+
+
+ function _viewaddresses() {
+ $content = "";
+ if(($_SESSION["OBJ_user"]->username == $this->getOwner()) || $_SESSION["OBJ_user"]->allow_access("contacts","edit_contacts")) {
+ $content .= "<a href=\"index.php?module=contacts&CONTACTS_MAN_OP=newaddress&CONTACTS_contact_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Add New Address") . "</a>";
+ }
+
+ $sql = "SELECT id FROM " . $GLOBALS["core"]->tbl_prefix . "mod_contacts_addresses WHERE contact_id=" . $this->getId();
+ $results = $GLOBALS["core"]->getCol($sql);
+ foreach ($results as $addressid) {
+ $address = new CONTACTS_Address($addressid);
+ $content .= $address->_view() . "<br />";
+ }
+
+ return $content;
+ }// END FUNC _viewaddresses
+
+
function action() {
switch($_REQUEST["CONTACTS_Contact_OP"]) {
case "edit":
$title = $_SESSION["translate"]->it("Edit Contact Information");
! $content = $this->_showtabs() . $this->_edit();
break;
***************
*** 357,360 ****
--- 437,450 ----
case "delete":
$this->_delete();
+ break;
+
+ case "viewphones":
+ $title = $_SESSION["translate"]->it("Contact Telephone Information");
+ $content = $this->_showtabs() . $this->_viewphones();
+ break;
+
+ case "viewaddresses":
+ $title = $_SESSION["translate"]->it("Contact Address Information");
+ $content = $this->_showtabs() . $this->_viewaddresses();
break;
Index: Manager.php
===================================================================
RCS file: /cvsroot/phpwebsite-comm/modules/contacts/class/Manager.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** Manager.php 29 May 2003 17:46:55 -0000 1.6
--- Manager.php 31 May 2003 07:36:44 -0000 1.7
***************
*** 11,14 ****
--- 11,16 ----
var $phonetype = NULL;
var $addresstype = NULL;
+ var $phone = NULL;
+ var $address = NULL;
var $message = NULL;
***************
*** 81,92 ****
- /*
- function _new() {
- $this->contact = new CONTACTS_Contact;
- $_REQUEST["CONTACTS_Contact_OP"] = "edit";
- }// END FUNC _new
- */
-
-
function _edit() {
$this->contact = new CONTACTS_Contact($_REQUEST["PHPWS_MAN_ITEMS"][0]);
--- 83,86 ----
***************
*** 149,152 ****
--- 143,164 ----
+ function _newAddress() {
+ $this->address = new CONTACTS_Address;
+ $_REQUEST["CONTACTS_Address_OP"] = "edit";
+ }// END FUNC _newAddress
+
+
+ function _editAddress() {
+ $this->address= new CONTACTS_Address($_REQUEST["CONTACTS_address_id"]);
+ $_REQUEST["CONTACTS_Address_OP"] = "edit";
+ }// END FUNC _editAddress
+
+
+ function _deleteAddress() {
+ $this->address= new CONTACTS_Address($_REQUEST["CONTACTS_address_id"]);
+ $_REQUEST["CONTACTS_Address_OP"] = "delete";
+ }// END FUNC _editAddress
+
+
function action() {
if(PHPWS_Message::isMessage($this->message))
***************
*** 208,211 ****
--- 220,239 ----
case "deleteaddresstypes":
$this->_deleteAddressType();
+ break;
+
+ case "newaddress":
+ $this->_newAddress();
+ break;
+
+ case "editaddress":
+ $this->_editAddress();
+ break;
+
+ case "deleteaddress":
+ $this->_deleteAddress();
+ break;
+
+ case "newphone":
+ $this->_newPhone();
break;
|