Merge pull request #3 in KWA/mobile-device-management from feature/KMP-2-pop-up-webapp-dialog-with-additional to master

* commit 'b1e0b39c8e257a2aa4b7fadc91c750d07509547d':
  Pop-up webapp dialog with additional device info
This commit is contained in:
Mayank Dabhi
2017-01-06 11:53:41 +01:00
8 changed files with 440 additions and 24 deletions

View File

@ -1,6 +1,7 @@
<?php
require_once(BASE_PATH . 'server/includes/core/class.encryptionstore.php');
require_once('zpushprops.php');
/**
* PluginMDMModule Module
@ -11,6 +12,11 @@ class PluginMDMModule extends Module
private $username = '';
private $password = '';
// content data
const FOLDERUUID = 1;
const FOLDERTYPE = 2;
const FOLDERBACKENDID = 5;
/**
* Constructor
* @param int $id unique id.
@ -155,21 +161,7 @@ class PluginMDMModule extends Module
$rawData = $this->getDevices();
foreach($rawData as $device){
$device = $device->data;
$item = array();
$item['entryid'] = $device['deviceid'];
$item['changed'] = $device['changed'];
$item['deviceos'] = $device['deviceos'];
$item['devicefriendlyname'] = $device['devicefriendlyname'];
$item['devicetype'] = $device['devicetype'];
$item['devicemodel'] = $device['devicemodel'];
$item['hierarchyuuid'] = $device['hierarchyuuid'];
$item['firstsynctime'] = $device['firstsynctime'];
$item['lastupdatetime'] = $device['lastupdatetime'];
$item['wipestatus'] = $device['wipestatus'];
$item['useragent'] = $device['useragent'];
$item['domain'] = $device['domain'];
array_push($items, array('props' => $item));
array_push($items, array('props' => $this->getDeviceProps($device->data)));
}
$data['page']['start'] = 0;
$data['page']['rowcount'] = count($rawData);
@ -205,5 +197,125 @@ class PluginMDMModule extends Module
}
}
}
/**
* Function which is use to get device properties.
*
* @param array $device array of device properties
* @return array
*/
function getDeviceProps($device)
{
$item = array();
$propsList = ['devicetype', 'deviceos', 'devicefriendlyname', 'useragent', 'asversion', 'firstsynctime',
'lastsynctime', 'lastupdatetime', 'wipestatus', 'policyname', 'koeversion', 'koebuild', 'koebuilddate'];
$item['entryid'] = $device['deviceid'];
foreach ($propsList as $prop) {
if (isset($device[$prop])) {
$item[$prop] = $device[$prop];
}
}
$item = array_merge($item, $this->getSyncFoldersProps($device));
return $item;
}
/**
* Function which is use to gather some statistics about synchronized folders.
* @param array $device array of device props
* @return array $syncFoldersProps has list of properties related to synchronized folders
*/
function getSyncFoldersProps($device)
{
$contentData = $device['contentdata'];
$folders = array_keys($contentData);
$synchedFolderTypes = array();
$synchronizedData = '';
$synchronizedFolders = 0;
$hierarchyCache = isset($device['hierarchycache']) ? $device['hierarchycache'] : false;
foreach ($folders as $folderid) {
if (isset($contentData[$folderid][self::FOLDERUUID]) || isset($device['hierarchyuuid'])) {
$type = $contentData[$folderid][self::FOLDERTYPE];
$name = "unknown";
if ($hierarchyCache) {
if (array_key_exists($folderid, $hierarchyCache->cacheById)) {
$folder = $hierarchyCache->cacheById[$folderid];
} else {
$folder = $hierarchyCache->cacheByIdOld[$folderid];
}
if ($folder) {
$name = $folder->displayname;
}
}
$folderType = $this->getSyncFolderType($type, $name);
if (!isset($synchedFolderTypes[$folderType])) {
$synchedFolderTypes[$folderType] = 0;
}
$synchedFolderTypes[$folderType]++;
}
}
foreach ($synchedFolderTypes as $key => $value) {
$synchronizedData = $synchronizedData . $key;
$synchronizedFolders += $value;
if ($value > 1) {
$synchronizedData = $synchronizedData . "(" . $value . ") ";
} else {
$synchronizedData = $synchronizedData . " ";
}
}
$syncFoldersProps = array();
$syncFoldersProps["totalfolders"] = count($folders);
$syncFoldersProps["shortfolderids"] = $device['hasfolderidmapping'] ? dgettext('plugin_mdm', "Yes") : dgettext('plugin_mdm', "No") ;
$syncFoldersProps['synchronizedfolders'] = $synchronizedFolders;
$syncFoldersProps['synchronizeddata'] = $synchronizedData;
return $syncFoldersProps;
}
/**
* Function which is use to get general type like Mail,Calendar,Contacts,etc. from folder type.
* @param int $type foldertype for a folder already known to the mobile
* @param string $name folder name
* @return string general folder type
*/
function getSyncFolderType($type, $name)
{
$folderType = '';
switch ($type) {
case SYNC_FOLDER_TYPE_APPOINTMENT:
case SYNC_FOLDER_TYPE_USER_APPOINTMENT:
if (KOE_GAB_NAME != "" && $name == KOE_GAB_NAME) {
$folderType = "GAB";
} else {
$folderType = "Calendars";
}
break;
case SYNC_FOLDER_TYPE_CONTACT:
case SYNC_FOLDER_TYPE_USER_CONTACT:
$folderType = "Contacts";
break;
case SYNC_FOLDER_TYPE_TASK:
case SYNC_FOLDER_TYPE_USER_TASK:
$folderType = "Tasks";
break;
case SYNC_FOLDER_TYPE_NOTE:
case SYNC_FOLDER_TYPE_USER_NOTE:
$folderType = "Notes";
break;
default:
$folderType = "Emails";
break;
}
return $folderType;
}
};
?>

26
php/zpushprops.php Normal file
View File

@ -0,0 +1,26 @@
<?php
// Folder Properties
define("SYNC_FOLDER_TYPE_OTHER", 1);
define("SYNC_FOLDER_TYPE_INBOX", 2);
define("SYNC_FOLDER_TYPE_DRAFTS", 3);
define("SYNC_FOLDER_TYPE_WASTEBASKET", 4);
define("SYNC_FOLDER_TYPE_SENTMAIL", 5);
define("SYNC_FOLDER_TYPE_OUTBOX", 6);
define("SYNC_FOLDER_TYPE_TASK", 7);
define("SYNC_FOLDER_TYPE_APPOINTMENT", 8);
define("SYNC_FOLDER_TYPE_CONTACT", 9);
define("SYNC_FOLDER_TYPE_NOTE", 10);
define("SYNC_FOLDER_TYPE_JOURNAL", 11);
define("SYNC_FOLDER_TYPE_USER_MAIL", 12);
define("SYNC_FOLDER_TYPE_USER_APPOINTMENT", 13);
define("SYNC_FOLDER_TYPE_USER_CONTACT", 14);
define("SYNC_FOLDER_TYPE_USER_TASK", 15);
define("SYNC_FOLDER_TYPE_USER_JOURNAL", 16);
define("SYNC_FOLDER_TYPE_USER_NOTE", 17);
define("SYNC_FOLDER_TYPE_UNKNOWN", 18);
define("SYNC_FOLDER_TYPE_RECIPIENT_CACHE", 19);
define("SYNC_FOLDER_TYPE_DUMMY", 999999);
// Other constant
define('KOE_GAB_NAME', 'Z-Push-KOE-GAB');
?>