From: <dts...@us...> - 2003-06-01 18:25:27
|
Update of /cvsroot/phpwebsite-comm/modules/contacts/class In directory sc8-pr-cvs1:/tmp/cvs-serv28238/class Modified Files: Address.php Contact.php Manager.php Phone.php Log Message: Got phones and contact viewing working Index: Address.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/contacts/class/Address.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Address.php 31 May 2003 07:36:44 -0000 1.2 --- Address.php 1 Jun 2003 18:25:22 -0000 1.3 *************** *** 126,133 **** ! 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>"; --- 126,133 ---- ! function _view($editmode = FALSE) { $tags = array(); ! if($editmode && (!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>"; *************** *** 137,141 **** $this->_address_type = new CONTACTS_AddressType($this->_type_id); ! $tags["TYPE"] = $this->_address_type->_name; $tags["STREET1"] = $this->_street1; $tags["STREET2"] = $this->_street2; --- 137,141 ---- $this->_address_type = new CONTACTS_AddressType($this->_type_id); ! $tags["TYPE"] = $this->_address_type->_name;; $tags["STREET1"] = $this->_street1; $tags["STREET2"] = $this->_street2; Index: Contact.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/contacts/class/Contact.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Contact.php 31 May 2003 07:36:44 -0000 1.7 --- Contact.php 1 Jun 2003 18:25:22 -0000 1.8 *************** *** 182,187 **** 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>"; --- 182,187 ---- 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=editphones&CONTACTS_contact_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Edit Phone Numbers") . "</a>"; ! $links[] = "<a href=\"index.php?module=contacts&CONTACTS_Contact_OP=editaddresses&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>"; *************** *** 195,198 **** --- 195,228 ---- }// END FUNC _showtabls + + function _view() { + $tags = array(); + $tags["PREFIX"] = $this->_prefix; + $tags["SURNAME"] = $this->_surname; + $tags["GIVENNAME"] = $this->_givenname; + $tags["MIDDLENAME"] = $this->_middlename; + $tags["SUFFIX"] = $this->_suffix; + $tags["EMAIL"] = $this->_email; + $tags["WEBSITE"] = $this->_website; + if(!empty($this->_birthday)) + $tags["BIRTHDAY"] = $this->_birthday; + if(!empty($this->_anniversary)) + $tags["ANNIVERSARY"] = $this->_anniversary; + $tags["ORGANIZATION"] = $this->_organization; + $tags["ORGUNIT"] = $this->_orgunit; + $tags["TITLE"] = $this->_title; + + $tags["NAME_TEXT"] = $_SESSION["translate"]->it("Name"); + $tags["EMAIL_TEXT"] = $_SESSION["translate"]->it("Email"); + $tags["WEBSITE_TEXT"] = $_SESSION["translate"]->it("Website"); + $tags["BIRTHDAY_TEXT"] = $_SESSION["translate"]->it("Birthday"); + $tags["ANNIVERSARY_TEXT"] = $_SESSION["translate"]->it("Anniversary"); + $tags["ORGANIZATION_TEXT"] = $_SESSION["translate"]->it("Organization"); + $tags["ORGUNIT_TEXT"] = $_SESSION["translate"]->it("Organization Unit"); + $tags["TITLE_TEXT"] = $_SESSION["translate"]->it("Title"); + + return $GLOBALS["core"]->processTemplate($tags, "contacts", "view_contacts.tpl"); + }// END FUNC _view + function _edit() { *************** *** 399,414 **** ! 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>"; } --- 429,453 ---- ! function _viewphones($editmode = FALSE) { ! $content = "<br /><b>" . $_SESSION["translate"]->it("Telephone Information") . ":</b><br />"; ! if($editmode && (($_SESSION["OBJ_user"]->username == $this->getOwner()) || $_SESSION["OBJ_user"]->allow_access("contacts","edit_contacts"))) { ! $content .= "<a href=\"index.php?module=contacts&CONTACTS_MAN_OP=newphone&CONTACTS_contact_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Add New Phone Number") . "</a><br /><br />"; ! } ! $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) { ! $phone = new CONTACTS_Phone($phoneid); ! $content .= $phone->_view($editmode) . "<br />"; ! } ! ! return $content; }// END FUNC _viewphones ! function _viewaddresses($editmode = FALSE) { ! $content = "<br /><b>" . $_SESSION["translate"]->it("Address Information") . ":</b><br />"; ! if($editmode && (($_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><br /><br />"; } *************** *** 417,421 **** foreach ($results as $addressid) { $address = new CONTACTS_Address($addressid); ! $content .= $address->_view() . "<br />"; } --- 456,460 ---- foreach ($results as $addressid) { $address = new CONTACTS_Address($addressid); ! $content .= $address->_view($editmode) . "<br />"; } *************** *** 426,429 **** --- 465,473 ---- function action() { switch($_REQUEST["CONTACTS_Contact_OP"]) { + case "view": + $title = $_SESSION["translate"]->it("View Contact Information"); + $content = $this->_showtabs() . $this->_view() . $this->_viewphones() . $this->_viewaddresses(); + break; + case "edit": $title = $_SESSION["translate"]->it("Edit Contact Information"); *************** *** 447,450 **** --- 491,504 ---- $title = $_SESSION["translate"]->it("Contact Address Information"); $content = $this->_showtabs() . $this->_viewaddresses(); + break; + + case "editphones": + $title = $_SESSION["translate"]->it("Contact Telephone Information"); + $content = $this->_showtabs() . $this->_viewphones(TRUE); + break; + + case "editaddresses": + $title = $_SESSION["translate"]->it("Contact Address Information"); + $content = $this->_showtabs() . $this->_viewaddresses(TRUE); break; Index: Manager.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/contacts/class/Manager.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Manager.php 31 May 2003 07:36:44 -0000 1.7 --- Manager.php 1 Jun 2003 18:25:22 -0000 1.8 *************** *** 77,82 **** ! function _view($id) { ! $this->contact = new CONTACTS_Contact($id[0]); $_REQUEST["CONTACTS_Contact_OP"] = "view"; }// END FUNC _view --- 77,82 ---- ! function _view() { ! $this->contact = new CONTACTS_Contact($_REQUEST["PHPWS_MAN_ITEMS"][0]); $_REQUEST["CONTACTS_Contact_OP"] = "view"; }// END FUNC _view *************** *** 161,164 **** --- 161,182 ---- + function _newPhone() { + $this->phone = new CONTACTS_Phone; + $_REQUEST["CONTACTS_Phone_OP"] = "edit"; + }// END FUNC _newPhone + + + function _editPhone() { + $this->phone= new CONTACTS_Phone($_REQUEST["CONTACTS_phone_id"]); + $_REQUEST["CONTACTS_Phone_OP"] = "edit"; + }// END FUNC _editPhone + + + function _deletePhone() { + $this->phone= new CONTACTS_Phone($_REQUEST["CONTACTS_phone_id"]); + $_REQUEST["CONTACTS_Phone_OP"] = "delete"; + }// END FUNC _editPhone + + function action() { if(PHPWS_Message::isMessage($this->message)) *************** *** 236,239 **** --- 254,265 ---- case "newphone": $this->_newPhone(); + break; + + case "editphone": + $this->_editPhone(); + break; + + case "deletephone": + $this->_deletePhone(); break; Index: Phone.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/contacts/class/Phone.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Phone.php 28 May 2003 18:01:11 -0000 1.1 --- Phone.php 1 Jun 2003 18:25:22 -0000 1.2 *************** *** 7,10 **** --- 7,250 ---- class CONTACTS_Phone extends PHPWS_Item { + /** + * The contact id of the phone + * + * @var integer + * @access private + */ + var $_contact_id = NULL; + + + /** + * The phone type of the phone + * + * @var integer + * @access private + */ + var $_type_id = NULL; + + + /** + * The phone number + * + * @var string + * @access private + */ + var $_phonenumber = NULL; + + + /** + * The phone type object of the phone + * + * @var CONTACTS_PhoneType + * @access private + */ + var $_phone_type = NULL; + + + /** + * Array of phone type objects + * + * @var array + * @access private + */ + var $phone_types = array(); + + + function CONTACTS_Phone($PHONE_ID = NULL) { + /* These vars are excluded on commit() */ + $exclude = array("_phone_type","phone_types"); + $this->addExclude($exclude); + + $this->setTable("mod_contacts_phones"); + + if(isset($PHONE_ID)) { + $this->setId($PHONE_ID); + $this->init(); + //$this->_phone_type = new CONTACTS_PhoneType($this->_type_id); + } else { + $this->_contact_id = $_REQUEST["CONTACTS_contact_id"]; + } + + }// END FUNC CONTACTS_Phone + + + function _view($editmode = FALSE) { + $tags = array(); + + if($editmode && (!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=editphone&CONTACTS_phone_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Edit") . "</a>"; + $tags["DELETE"] = "<a href=\"index.php?module=contacts&CONTACTS_MAN_OP=deletephone&CONTACTS_phone_id=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Delete") . "</a>"; + } + + $this->_phone_type = new CONTACTS_PhoneType($this->_type_id); + + $tags["TYPE"] = $this->_phone_type->_name; + $tags["PHONENUMBER"] = $this->_phonenumber; + + $tags["TYPE_TEXT"] = $_SESSION["translate"]->it("Type"); + $tags["PHONENUMBER_TEXT"] = $_SESSION["translate"]->it("Number"); + + return $GLOBALS["core"]->processTemplate($tags, "contacts", "view_phone.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 phone was denied due to lack of proper permissions."); + $error = new PHPWS_Error("contacts", "CONTACTS_Phone::_edit()", $message, "exit", 1); + $error->message(); + return FALSE; + } + + // Get phone types + $result = $GLOBALS["core"]->sqlSelect("mod_contacts_phonetypes", NULL, NULL, "name"); + foreach ($result as $row) + $this->phone_types[$row["id"]] = $row["name"]; + + /* Create form */ + $form = new EZform("CONTACTS_Phone_edit"); + + /* Phone Type */ + $form->add("Phone_type_id", "select", $this->phone_types); + $form->setMatch("Phone_type_id", $this->_type_id); + $form->setTab("Phone_type_id", 1); + + /* Phone Number */ + $form->add("Phone_phonenumber", "text", $this->_phonenumber); + $form->setSize("Phone_phonenumber", 33); + $form->setTab("Phone_phonenumber", 2); + + + /* Save Button */ + $form->add("Phone_save", "submit", $_SESSION["translate"]->it("Save")); + $form->setTab("Phone_save", 3); + + /* Module Information */ + $form->add("Phone_contact_id", "hidden", $this->_contact_id); + $form->add("module", "hidden", "contacts"); + $form->add("CONTACTS_Phone_OP", "hidden", "save"); + + $tags = array(); + $tags = $form->getTemplate(); + + $tags["TYPE_TEXT"] = $_SESSION["translate"]->it("Type"); + $tags["PHONENUMBER_TEXT"] = $_SESSION["translate"]->it("Number"); + + return $GLOBALS["core"]->processTemplate($tags, "contacts", "edit_phone.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 phone was denied due to lack of proper permissions."); + $error = new PHPWS_Error("contacts", "CONTACTS_Phone::_save()", $message, "exit", 1); + $error->message(); + return FALSE; + } + + if(isset($_REQUEST["Phone_type_id"])) + $this->_type_id = $_REQUEST["Phone_type_id"]; + + if(isset($_REQUEST["Phone_phonenumber"])) + $this->_phonenumber = $_REQUEST["Phone_phonenumber"]; + + $this->setLabel("$this->_phonenumber"); + + $error = $this->commit(); + + if(PHPWS_Error::isError($error)) { + $message = $_SESSION["translate"]->it("The phone could not be saved to the database."); + $error = new PHPWS_Error("contacts", $message, "continue", 0); + $error->message("CNT_contacts"); + + $_REQUEST["CONTACTS_Phone_OP"] = "edit"; + $this->action(); + return; + } else { + $GLOBALS["CNT_contacts"]["content"] .= $_SESSION["translate"]->it("The phone was successfully saved.") . "<br />\n"; + // Probably need to pass some IDs in or something + $_REQUEST["CONTACTS_Contact_OP"] = "viewphones"; + $_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 phone was denied due to lack of proper permissions."); + $error = new PHPWS_Error("contacts", "CONTACTS_Phone::_delete()", $message, "exit", 1); + $error->message(); + return FALSE; + } + + if(isset($_REQUEST["Phone_yes"])) { + $this->kill(); + $message = $_SESSION["translate"]->it("The phone [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"] = "viewphones"; + $_SESSION["CONTACTS_Manager"]->contact->action(); + + } elseif(isset($_REQUEST["Phone_no"])) { + $message = $_SESSION["translate"]->it("No phone was deleted from the database."); + $_SESSION["CONTACTS_Manager"]->message = new PHPWS_Message($message, "CNT_contacts"); + $_SESSION["CONTACTS_Manager"]->action(); + $_REQUEST["CONTACTS_Contact_OP"] = "viewphones"; + $_SESSION["CONTACTS_Manager"]->contact->action(); + + } else { + $title = $_SESSION["translate"]->it("Delete Phone Confirmation"); + + $form = new EZform("CONTACTS_Phone_delete"); + $form->add("module", "hidden", "contacts"); + $form->add("CONTACTS_Phone_OP", "hidden", "delete"); + + $form->add("Phone_yes", "submit", $_SESSION["translate"]->it("Yes")); + $form->add("Phone_no", "submit", $_SESSION["translate"]->it("No")); + + $tags = array(); + $tags = $form->getTemplate(); + $tags["MESSAGE"] = $_SESSION["translate"]->it("Are you sure you want to delete this phone?"); + + $content = $GLOBALS["core"]->processTemplate($tags, "contacts", "delete_phone.tpl"); + $_SESSION["OBJ_layout"]->popbox($title, $content, NULL, "CNT_contacts"); + } + + }// END FUNC _delete + + + function action() { + switch($_REQUEST["CONTACTS_Phone_OP"]) { + case "view": + $content = $this->_view(); + break; + + case "edit": + $title = $_SESSION["translate"]->it("Edit Phone 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_Phone |