Added primary_contact field to database and added to contacts list and edit.
authorChuck Scott <cscott@gaslightmedia.com>
Mon, 25 Jul 2016 19:06:01 +0000 (15:06 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Mon, 25 Jul 2016 19:06:01 +0000 (15:06 -0400)
classes/data/dataContacts.php
index.php
setup/databaseScripts/create_database_V0.0.2.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php
setup/databaseScripts/drop_database_V0.0.2.sql [new file with mode: 0644]
setup/databaseScripts/update_database_V0.0.2.sql [new file with mode: 0644]
setup/permissions.php
views/admin/contacts/edit.html
views/admin/contacts/index.html

index c1272f3..03ca442 100644 (file)
@@ -138,6 +138,14 @@ class GlmDataContacts extends GlmDataAbstract
                 'use' => 'a'
             ),
 
+            // Primary Contact Flag
+            'primary_contact' => array (
+                'field' => 'primary_contact',
+                'type' => 'checkbox',
+                'default' => false,
+                'use' => 'a'
+            ),
+
             // First Name
             'fname' => array (
                 'field' => 'fname',
@@ -314,7 +322,7 @@ class GlmDataContacts extends GlmDataAbstract
                 'use'      => 'a'
             ),
 
-            // Alternate Phone
+            // Alternate Phone, get, edit
             'alt_phone' => array(
                 'field'    => 'alt_phone',
                 'type'     => 'phone',
@@ -453,6 +461,14 @@ class GlmDataContacts extends GlmDataAbstract
 
         }
 
+        // Only run these tests for insert and update
+        if ($this->postProcess && $_REQUEST['option'] == 'submit') {
+            if ($r['primary_contact']) {
+                $this->wpdb->query("UPDATE ".$this->table." SET primary_contact = false where id != ".$r['id'].";");
+            }
+
+        }
+
         return $r;
     }
 
@@ -562,6 +578,7 @@ class GlmDataContacts extends GlmDataAbstract
         $this->fields = array(
             'id' => $savedFields['id'],
             'active' => $savedFields['active'],
+            'primary_contact' => $savedFields['primary_contact'],
             'access' => $savedFields['access'],
             'contact_type' => $savedFields['contact_type'],
             'fname' => $savedFields['fname'],
index 6099787..94e835f 100644 (file)
--- a/index.php
+++ b/index.php
@@ -34,7 +34,7 @@
  *  version nunmber of that release for the DB version.
  */
 define('GLM_MEMBERS_CONTACTS_PLUGIN_VERSION', '1.0.11');
-define('GLM_MEMBERS_CONTACTS_PLUGIN_DB_VERSION', '0.0.1');
+define('GLM_MEMBERS_CONTACTS_PLUGIN_DB_VERSION', '0.0.2');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
 define('GLM_MEMBERS_CONTACTS_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '1.0.58');
diff --git a/setup/databaseScripts/create_database_V0.0.2.sql b/setup/databaseScripts/create_database_V0.0.2.sql
new file mode 100644 (file)
index 0000000..7ebc255
--- /dev/null
@@ -0,0 +1,57 @@
+-- Gaslight Media Members Database 
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 0.0.2
+-- Database Creation Script - Contacts Add-On
+-- 
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+-- 
+-- **** BE SURE TO ALSO UPDATE drop_database_Vxxx.sql FILE WHEN CHANGING TABLES ****
+-- 
+
+-- Contacts - used by various entities
+CREATE TABLE {prefix}contacts (
+  id INT NOT NULL AUTO_INCREMENT,
+  active BOOLEAN NULL,                      -- Contact is active flag
+  access INT NULL,                          -- Access type - See access table in plugin.ini
+  primary_contact BOOLEAN NULL,             -- Contact is the "Primary Contact" for mailings to entity (ref_type/ref_dest)
+  fname TINYTEXT NULL,                      -- First name of contact
+  lname TINYTEXT NULL,                      -- Last name of contact
+  contact_type INT NULL,                    -- Contact type - see contact_type table (individual, role, ...)
+  contact_role INT NULL,                    -- Contact WordPress user Role
+  org TINYTEXT NULL,                        -- Organization name
+  title TINYTEXT NULL,                      -- Title/Position
+  descr TEXT NULL,                          -- Description of position/responsibilities - Displayed
+  image TINYTEXT NULL,                      -- Image
+  addr1 TINYTEXT NULL,                      -- Address line 1 - Address is for contact, not necessarily for organization
+  addr2 TINYTEXT NULL,                      -- Address line 2 
+  city INT NULL,                            -- Pointer to city in cities table
+  state TINYTEXT NULL,                      -- Two character state code - matches states.ini entries
+  country TINYTEXT NULL,                    -- Two character country code - matches countries.ini entries 
+  zip TINYTEXT NULL,                        -- ZIP/Postal Code     
+  lat FLOAT NULL,                           -- Latitude of contact location
+  lon FLOAT NULL,                           -- Longitude of contact location
+  url TINYTEXT NULL,                        -- URL to information regarding this contact
+  office_phone TINYTEXT NULL,               -- Office phone number
+  home_phone TINYTEXT NULL,                 -- Home phone number - or after-hours phone number
+  mobile_phone TINYTEXT NULL,               -- Mobile phone number
+  alt_phone TINYTEXT NULL,                  -- An alternate phone number
+  fax TINYTEXT NULL,                        -- FAX number (do people still use these?) 
+  email TINYTEXT NULL,                      -- E-Mail address
+  alt_email TINYTEXT NULL,                  -- Alternate E-Mail address - Also used to log-in 
+  username TINYTEXT NULL,                   -- Optional username to use for login
+  password TINYTEXT NULL,                   -- Encrypted password
+  notes TEXT NULL,                          -- Notes - Not displayed on front-end
+  create_time TIMESTAMP NULL,               -- Create date/time
+  modify_time TIMESTAMP NULL,               -- Last modified date/time
+  ref_type INT NULL,                        -- Type of entity this contact is associated with                        
+  ref_dest INT NULL,                        -- Pointer to the specific entity of ref_type this contact is associated with
+  PRIMARY KEY (id),
+  INDEX(fname(20)),
+  INDEX(lname(20)),
+  INDEX(city),
+  INDEX(zip(10)),
+  INDEX(lat),
+  INDEX(lon),
+  INDEX(email(20))
+);
index 7009d41..6c142f5 100644 (file)
@@ -28,6 +28,7 @@
  */
 $glmMembersContactsDbVersions = array(
     '0.0.1' => array('version' => '0.0.1', 'tables' => 1, 'date' => '4/15/2016'),
+    '0.0.2' => array('version' => '0.0.2', 'tables' => 1, 'date' => '7/25/2016')
 );
 
 
diff --git a/setup/databaseScripts/drop_database_V0.0.2.sql b/setup/databaseScripts/drop_database_V0.0.2.sql
new file mode 100644 (file)
index 0000000..4803a0c
--- /dev/null
@@ -0,0 +1,10 @@
+-- Gaslight Media Contacts Database 
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 0.0.2
+-- Database Deletion Script
+-- Note: Tables with DELETE CASCADE must appear before referenced table
+
+DROP TABLE IF EXISTS
+    {prefix}contacts
+;
+
diff --git a/setup/databaseScripts/update_database_V0.0.2.sql b/setup/databaseScripts/update_database_V0.0.2.sql
new file mode 100644 (file)
index 0000000..6e333e1
--- /dev/null
@@ -0,0 +1,20 @@
+-- Gaslight Media Members Database  - Contacts Add-On
+-- File Created: 12/09/14 15:27:15
+-- Database Version: 0.0.2
+-- Database Update From Previous Version Script
+-- 
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashses
+
+-- Add primary_contact field
+ALTER TABLE {prefix}contacts ADD COLUMN primary_contact BOOLEAN;
+
+----
+
+-- Update primary_contacts to default all current entries to false
+UPDATE {prefix}contacts SET primary_contact = false;
+
+
+
+
+
index 8173f77..0b180f1 100644 (file)
@@ -189,7 +189,15 @@ add_filter('glm_members_permit_admin_member_contacts_view_contact',
     }
 );
 
-// glm-member-db, view/member/contacts.html, Edit Contact data
+// glm-member-db, view/admin/contacts/edit.html, Set as Primary Contact
+add_filter('glm_members_permit_admin_member_contacts_set_as_primary',
+    function($permit) {
+        if (!$permit) { return false; }
+        return current_user_can('glm_members_edit_any_member');
+    }
+);
+
+// glm-member-db, views/member/contacts.html, Edit Contact data
 add_filter('glm_members_permit_admin_member_contacts_edit_contact',
     function($permit) {
         if (!$permit) { return false; }
index 20a353e..983d972 100644 (file)
                         <input type="checkbox" name="active" {if $contactInfo.fieldData.active.value} checked{/if}>
                     </td>
                 </tr>
+                <tr>
+                    <th>Primary Contact:</th>
+                    <td>
+            {if apply_filters('glm_members_permit_admin_member_contacts_set_as_primary', true)}                
+                        <input type="checkbox" name="primary_contact" {if $contactInfo.fieldData.primary_contact.value} checked{/if}> (Only one contact at a time may be the primary contact. If there is another primary contact, it will be deselected.)
+            {else}
+                        {$contactInfo.fieldData.primary_contact.name}
+            {/if}
+                    </td>
+                </tr>
             {if $option != 'create'}
                 <tr>
                     <th>Created:</th>
index 60eb773..ca6c64b 100644 (file)
@@ -44,6 +44,7 @@
                 <tr>
                     <th>Name</th>
                     <th>Active</th>
+                    <th>Primary</th>
                     <th>Type</th>
                     <th>Access</th>
                     <th>User</th>
@@ -62,6 +63,7 @@
             {/if}
                     </td>
                     <td class="glm-shrink">{$c.active.name}</td>
+                    <td class="glm-shrink">{if $c.primary_contact.value}Yes{/if}</td>
                     <td>{$c.contact_type.name}</td>
                     <td class="glm-shrink">{$c.access.name}</td>
                     <td class="glm-nowrap">{$c.username}</td>