initial activesync device management pref screen.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 29 Apr 2010 18:45:01 +0000 (14:45 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 29 Apr 2010 18:45:38 +0000 (14:45 -0400)
horde/lib/Prefs/Ui.php
horde/templates/prefs/activesync.html [new file with mode: 0644]

index 9b344bf..34bf60e 100644 (file)
@@ -136,6 +136,9 @@ class Horde_Prefs_Ui
 
         case 'syncmlmanagement':
             return $this->_syncmlManagement($ui);
+
+        case 'activesyncmanagement':
+            return $this->_activesyncManagement($ui);
         }
 
         return '';
@@ -162,6 +165,10 @@ class Horde_Prefs_Ui
         case 'syncmlmanagement':
             $this->_updateSyncmlManagement($ui);
             break;
+
+        case 'activesyncmanagement':
+            $this->_updateActiveSyncManagement($ui);
+            break;
         }
 
         return false;
@@ -373,12 +380,58 @@ class Horde_Prefs_Ui
                 );
             }
         }
-        $t->set('devices', $devices);
+        $t->set('devices', $partners);
 
         return $t->fetch(HORDE_TEMPLATES . '/prefs/syncml.html');
     }
 
     /**
+     * Create code for ActiveSync management.
+     *
+     * @param Horde_Core_Prefs_Ui $ui  The UI object.
+     *
+     * @return string HTML UI code.
+     */
+    protected function _activesyncManagement($ui)
+    {
+        if (!empty($GLOBALS['conf']['activesync']['enabled'])) {
+            $state_params = $GLOBALS['conf']['activesync']['state']['params'];
+            $state_params['db'] = $GLOBALS['injector']->getInstance('Horde_Db_Adapter_Base');
+            $stateMachine = new Horde_ActiveSync_State_History($state_params);
+        } else {
+            return _("ActiveSync not activated.");
+        }
+
+        $t = $GLOBALS['injector']->createInstance('Horde_Template');
+        $t->setOption('gettext', true);
+        $devices = $stateMachine->listDevices(Horde_Auth::getAuth());
+        $devs = array();
+        $reseturl = $ui->selfUrl()->add('reset', 1);
+        $i = 1;
+        foreach ($devices as $device) {
+            $device['class'] = fmod($i++, 2) ? 'rowOdd' : 'rowEven';
+            $device['reset'] = $reseturl;
+            $device['ts'] = strftime($GLOBALS['prefs']->getValue('date_format') . ' %H:%M', $stateMachine->getLastSyncTimestamp($device['device_id']));
+            switch ($device['device_rwstatus']) {
+            case Horde_ActiveSync::RWSTATUS_PENDING:
+                $status = '<span class="notice">Wipe is pending</span>';
+                break;
+            case Horde_ActiveSync::RWSTATUS_WIPED:
+                $status = '<span class="notice">Device is wiped</span>';
+                break;
+            default:
+                $status = 'Device is partnered';
+            }
+            $device['status'] = $status . '<br />Device id: ' . $device['device_id'] . '<br />User Agent: ' . $device['device_agent'];
+            $devs[] = $device;
+        }
+
+        $t->set('devices', $devs);
+
+        return $t->fetch(HORDE_TEMPLATES . '/prefs/activesync.html');
+    }
+
+    /**
      * Update category related preferences.
      *
      * @param Horde_Core_Prefs_Ui $ui  The UI object.
@@ -506,4 +559,22 @@ class Horde_Prefs_Ui
         }
     }
 
+    /**
+     * Update ActiveSync actions
+     *
+     * @param Horde_Core_Prefs_Ui $ui  The UI object.
+     */
+     protected function _updateActiveSyncManagement($ui)
+     {
+        $state_params = $GLOBALS['conf']['activesync']['state']['params'];
+        $state_params['db'] = $GLOBALS['injector']->getInstance('Horde_Db_Adapter_Base');
+        $stateMachine = new Horde_ActiveSync_State_History($state_params);
+        if ($ui->vars->wipe) {
+            $stateMachine->setDeviceRWStatus($ui->vars->wipe, Horde_ActiveSync::RWSTATUS_PENDING);
+            $GLOBALS['notification']->push(sprintf(_("A Remote Wipe for device id %s has been initiated. The device will be wiped durint the next SYNC request."), $ui->vars->wipe));
+        } elseif ($ui->vars->reset) {
+            // @TODO
+            //$stateMachine->removeState();
+        }
+     }
 }
diff --git a/horde/templates/prefs/activesync.html b/horde/templates/prefs/activesync.html
new file mode 100644 (file)
index 0000000..d4e5d6a
--- /dev/null
@@ -0,0 +1,32 @@
+<div class="smallheader">
+ <gettext>Device Management</gettext>
+</div>
+
+<if:devices>
+<table class="horde-table striped">
+ <tr>
+     <th><gettext>Select for wipe</gettext></th>
+     <th><gettext>Device</gettext></th>
+     <th><gettext>Last Sync Time</gettext></th>
+     <th><gettext>Status</gettext></th>
+ </tr>
+<loop:devices>
+ <tr class="<tag:devices.class />">
+  <td><input type="radio" name="wipe" value="<tag:devices.device_id />" /></td>
+  <td><tag:devices.device_type /></td>
+  <td><tag:devices.ts /></td>
+  <td><tag:devices.status /></td>
+ </tr>
+</loop:devices>
+</table>
+<else:devices>
+<p>
+ <em><gettext>None</gettext></em>
+</p>
+</else:devices></if:devices>
+<p><strong>NOTE: WIPING A DEVICE MAY RESET IT TO FACTORY DEFAULTS. PLEASE MAKE SURE YOU REALLY WANT TO DO THIS BEFORE REQUESTING A WIPE</strong></p>
+
+<div class="smallheader">
+ <gettext>State Management</gettext>
+</div>
+<p><gettext>Reset all device state. This will cause your devices to resyncronize all items.</gettext><a class="button" href="<tag:reset />"><gettext>Reset</gettext></a>
\ No newline at end of file